0000-raspberry-pi.patch 4.0 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325383263832738328383293833038331383323833338334383353833638337383383833938340383413834238343383443834538346383473834838349383503835138352383533835438355383563835738358383593836038361383623836338364383653836638367383683836938370383713837238373383743837538376383773837838379383803838138382383833838438385383863838738388383893839038391383923839338394383953839638397383983839938400384013840238403384043840538406384073840838409384103841138412384133841438415384163841738418384193842038421384223842338424384253842638427384283842938430384313843238433384343843538436384373843838439384403844138442384433844438445384463844738448384493845038451384523845338454384553845638457384583845938460384613846238463384643846538466384673846838469384703847138472384733847438475384763847738478384793848038481384823848338484384853848638487384883848938490384913849238493384943849538496384973849838499385003850138502385033850438505385063850738508385093851038511385123851338514385153851638517385183851938520385213852238523385243852538526385273852838529385303853138532385333853438535385363853738538385393854038541385423854338544385453854638547385483854938550385513855238553385543855538556385573855838559385603856138562385633856438565385663856738568385693857038571385723857338574385753857638577385783857938580385813858238583385843858538586385873858838589385903859138592385933859438595385963859738598385993860038601386023860338604386053860638607386083860938610386113861238613386143861538616386173861838619386203862138622386233862438625386263862738628386293863038631386323863338634386353863638637386383863938640386413864238643386443864538646386473864838649386503865138652386533865438655386563865738658386593866038661386623866338664386653866638667386683866938670386713867238673386743867538676386773867838679386803868138682386833868438685386863868738688386893869038691386923869338694386953869638697386983869938700387013870238703387043870538706387073870838709387103871138712387133871438715387163871738718387193872038721387223872338724387253872638727387283872938730387313873238733387343873538736387373873838739387403874138742387433874438745387463874738748387493875038751387523875338754387553875638757387583875938760387613876238763387643876538766387673876838769387703877138772387733877438775387763877738778387793878038781387823878338784387853878638787387883878938790387913879238793387943879538796387973879838799388003880138802388033880438805388063880738808388093881038811388123881338814388153881638817388183881938820388213882238823388243882538826388273882838829388303883138832388333883438835388363883738838388393884038841388423884338844388453884638847388483884938850388513885238853388543885538856388573885838859388603886138862388633886438865388663886738868388693887038871388723887338874388753887638877388783887938880388813888238883388843888538886388873888838889388903889138892388933889438895388963889738898388993890038901389023890338904389053890638907389083890938910389113891238913389143891538916389173891838919389203892138922389233892438925389263892738928389293893038931389323893338934389353893638937389383893938940389413894238943389443894538946389473894838949389503895138952389533895438955389563895738958389593896038961389623896338964389653896638967389683896938970389713897238973389743897538976389773897838979389803898138982389833898438985389863898738988389893899038991389923899338994389953899638997389983899939000390013900239003390043900539006390073900839009390103901139012390133901439015390163901739018390193902039021390223902339024390253902639027390283902939030390313903239033390343903539036390373903839039390403904139042390433904439045390463904739048390493905039051390523905339054390553905639057390583905939060390613906239063390643906539066390673906839069390703907139072390733907439075390763907739078390793908039081390823908339084390853908639087390883908939090390913909239093390943909539096390973909839099391003910139102391033910439105391063910739108391093911039111391123911339114391153911639117391183911939120391213912239123391243912539126391273912839129391303913139132391333913439135391363913739138391393914039141391423914339144391453914639147391483914939150391513915239153391543915539156391573915839159391603916139162391633916439165391663916739168391693917039171391723917339174391753917639177391783917939180391813918239183391843918539186391873918839189391903919139192391933919439195391963919739198391993920039201392023920339204392053920639207392083920939210392113921239213392143921539216392173921839219392203922139222392233922439225392263922739228392293923039231392323923339234392353923639237392383923939240392413924239243392443924539246392473924839249392503925139252392533925439255392563925739258392593926039261392623926339264392653926639267392683926939270392713927239273392743927539276392773927839279392803928139282392833928439285392863928739288392893929039291392923929339294392953929639297392983929939300393013930239303393043930539306393073930839309393103931139312393133931439315393163931739318393193932039321393223932339324393253932639327393283932939330393313933239333393343933539336393373933839339393403934139342393433934439345393463934739348393493935039351393523935339354393553935639357393583935939360393613936239363393643936539366393673936839369393703937139372393733937439375393763937739378393793938039381393823938339384393853938639387393883938939390393913939239393393943939539396393973939839399394003940139402394033940439405394063940739408394093941039411394123941339414394153941639417394183941939420394213942239423394243942539426394273942839429394303943139432394333943439435394363943739438394393944039441394423944339444394453944639447394483944939450394513945239453394543945539456394573945839459394603946139462394633946439465394663946739468394693947039471394723947339474394753947639477394783947939480394813948239483394843948539486394873948839489394903949139492394933949439495394963949739498394993950039501395023950339504395053950639507395083950939510395113951239513395143951539516395173951839519395203952139522395233952439525395263952739528395293953039531395323953339534395353953639537395383953939540395413954239543395443954539546395473954839549395503955139552395533955439555395563955739558395593956039561395623956339564395653956639567395683956939570395713957239573395743957539576395773957839579395803958139582395833958439585395863958739588395893959039591395923959339594395953959639597395983959939600396013960239603396043960539606396073960839609396103961139612396133961439615396163961739618396193962039621396223962339624396253962639627396283962939630396313963239633396343963539636396373963839639396403964139642396433964439645396463964739648396493965039651396523965339654396553965639657396583965939660396613966239663396643966539666396673966839669396703967139672396733967439675396763967739678396793968039681396823968339684396853968639687396883968939690396913969239693396943969539696396973969839699397003970139702397033970439705397063970739708397093971039711397123971339714397153971639717397183971939720397213972239723397243972539726397273972839729397303973139732397333973439735397363973739738397393974039741397423974339744397453974639747397483974939750397513975239753397543975539756397573975839759397603976139762397633976439765397663976739768397693977039771397723977339774397753977639777397783977939780397813978239783397843978539786397873978839789397903979139792397933979439795397963979739798397993980039801398023980339804398053980639807398083980939810398113981239813398143981539816398173981839819398203982139822398233982439825398263982739828398293983039831398323983339834398353983639837398383983939840398413984239843398443984539846398473984839849398503985139852398533985439855398563985739858398593986039861398623986339864398653986639867398683986939870398713987239873398743987539876398773987839879398803988139882398833988439885398863988739888398893989039891398923989339894398953989639897398983989939900399013990239903399043990539906399073990839909399103991139912399133991439915399163991739918399193992039921399223992339924399253992639927399283992939930399313993239933399343993539936399373993839939399403994139942399433994439945399463994739948399493995039951399523995339954399553995639957399583995939960399613996239963399643996539966399673996839969399703997139972399733997439975399763997739978399793998039981399823998339984399853998639987399883998939990399913999239993399943999539996399973999839999400004000140002400034000440005400064000740008400094001040011400124001340014400154001640017400184001940020400214002240023400244002540026400274002840029400304003140032400334003440035400364003740038400394004040041400424004340044400454004640047400484004940050400514005240053400544005540056400574005840059400604006140062400634006440065400664006740068400694007040071400724007340074400754007640077400784007940080400814008240083400844008540086400874008840089400904009140092400934009440095400964009740098400994010040101401024010340104401054010640107401084010940110401114011240113401144011540116401174011840119401204012140122401234012440125401264012740128401294013040131401324013340134401354013640137401384013940140401414014240143401444014540146401474014840149401504015140152401534015440155401564015740158401594016040161401624016340164401654016640167401684016940170401714017240173401744017540176401774017840179401804018140182401834018440185401864018740188401894019040191401924019340194401954019640197401984019940200402014020240203402044020540206402074020840209402104021140212402134021440215402164021740218402194022040221402224022340224402254022640227402284022940230402314023240233402344023540236402374023840239402404024140242402434024440245402464024740248402494025040251402524025340254402554025640257402584025940260402614026240263402644026540266402674026840269402704027140272402734027440275402764027740278402794028040281402824028340284402854028640287402884028940290402914029240293402944029540296402974029840299403004030140302403034030440305403064030740308403094031040311403124031340314403154031640317403184031940320403214032240323403244032540326403274032840329403304033140332403334033440335403364033740338403394034040341403424034340344403454034640347403484034940350403514035240353403544035540356403574035840359403604036140362403634036440365403664036740368403694037040371403724037340374403754037640377403784037940380403814038240383403844038540386403874038840389403904039140392403934039440395403964039740398403994040040401404024040340404404054040640407404084040940410404114041240413404144041540416404174041840419404204042140422404234042440425404264042740428404294043040431404324043340434404354043640437404384043940440404414044240443404444044540446404474044840449404504045140452404534045440455404564045740458404594046040461404624046340464404654046640467404684046940470404714047240473404744047540476404774047840479404804048140482404834048440485404864048740488404894049040491404924049340494404954049640497404984049940500405014050240503405044050540506405074050840509405104051140512405134051440515405164051740518405194052040521405224052340524405254052640527405284052940530405314053240533405344053540536405374053840539405404054140542405434054440545405464054740548405494055040551405524055340554405554055640557405584055940560405614056240563405644056540566405674056840569405704057140572405734057440575405764057740578405794058040581405824058340584405854058640587405884058940590405914059240593405944059540596405974059840599406004060140602406034060440605406064060740608406094061040611406124061340614406154061640617406184061940620406214062240623406244062540626406274062840629406304063140632406334063440635406364063740638406394064040641406424064340644406454064640647406484064940650406514065240653406544065540656406574065840659406604066140662406634066440665406664066740668406694067040671406724067340674406754067640677406784067940680406814068240683406844068540686406874068840689406904069140692406934069440695406964069740698406994070040701407024070340704407054070640707407084070940710407114071240713407144071540716407174071840719407204072140722407234072440725407264072740728407294073040731407324073340734407354073640737407384073940740407414074240743407444074540746407474074840749407504075140752407534075440755407564075740758407594076040761407624076340764407654076640767407684076940770407714077240773407744077540776407774077840779407804078140782407834078440785407864078740788407894079040791407924079340794407954079640797407984079940800408014080240803408044080540806408074080840809408104081140812408134081440815408164081740818408194082040821408224082340824408254082640827408284082940830408314083240833408344083540836408374083840839408404084140842408434084440845408464084740848408494085040851408524085340854408554085640857408584085940860408614086240863408644086540866408674086840869408704087140872408734087440875408764087740878408794088040881408824088340884408854088640887408884088940890408914089240893408944089540896408974089840899409004090140902409034090440905409064090740908409094091040911409124091340914409154091640917409184091940920409214092240923409244092540926409274092840929409304093140932409334093440935409364093740938409394094040941409424094340944409454094640947409484094940950409514095240953409544095540956409574095840959409604096140962409634096440965409664096740968409694097040971409724097340974409754097640977409784097940980409814098240983409844098540986409874098840989409904099140992409934099440995409964099740998409994100041001410024100341004410054100641007410084100941010410114101241013410144101541016410174101841019410204102141022410234102441025410264102741028410294103041031410324103341034410354103641037410384103941040410414104241043410444104541046410474104841049410504105141052410534105441055410564105741058410594106041061410624106341064410654106641067410684106941070410714107241073410744107541076410774107841079410804108141082410834108441085410864108741088410894109041091410924109341094410954109641097410984109941100411014110241103411044110541106411074110841109411104111141112411134111441115411164111741118411194112041121411224112341124411254112641127411284112941130411314113241133411344113541136411374113841139411404114141142411434114441145411464114741148411494115041151411524115341154411554115641157411584115941160411614116241163411644116541166411674116841169411704117141172411734117441175411764117741178411794118041181411824118341184411854118641187411884118941190411914119241193411944119541196411974119841199412004120141202412034120441205412064120741208412094121041211412124121341214412154121641217412184121941220412214122241223412244122541226412274122841229412304123141232412334123441235412364123741238412394124041241412424124341244412454124641247412484124941250412514125241253412544125541256412574125841259412604126141262412634126441265412664126741268412694127041271412724127341274412754127641277412784127941280412814128241283412844128541286412874128841289412904129141292412934129441295412964129741298412994130041301413024130341304413054130641307413084130941310413114131241313413144131541316413174131841319413204132141322413234132441325413264132741328413294133041331413324133341334413354133641337413384133941340413414134241343413444134541346413474134841349413504135141352413534135441355413564135741358413594136041361413624136341364413654136641367413684136941370413714137241373413744137541376413774137841379413804138141382413834138441385413864138741388413894139041391413924139341394413954139641397413984139941400414014140241403414044140541406414074140841409414104141141412414134141441415414164141741418414194142041421414224142341424414254142641427414284142941430414314143241433414344143541436414374143841439414404144141442414434144441445414464144741448414494145041451414524145341454414554145641457414584145941460414614146241463414644146541466414674146841469414704147141472414734147441475414764147741478414794148041481414824148341484414854148641487414884148941490414914149241493414944149541496414974149841499415004150141502415034150441505415064150741508415094151041511415124151341514415154151641517415184151941520415214152241523415244152541526415274152841529415304153141532415334153441535415364153741538415394154041541415424154341544415454154641547415484154941550415514155241553415544155541556415574155841559415604156141562415634156441565415664156741568415694157041571415724157341574415754157641577415784157941580415814158241583415844158541586415874158841589415904159141592415934159441595415964159741598415994160041601416024160341604416054160641607416084160941610416114161241613416144161541616416174161841619416204162141622416234162441625416264162741628416294163041631416324163341634416354163641637416384163941640416414164241643416444164541646416474164841649416504165141652416534165441655416564165741658416594166041661416624166341664416654166641667416684166941670416714167241673416744167541676416774167841679416804168141682416834168441685416864168741688416894169041691416924169341694416954169641697416984169941700417014170241703417044170541706417074170841709417104171141712417134171441715417164171741718417194172041721417224172341724417254172641727417284172941730417314173241733417344173541736417374173841739417404174141742417434174441745417464174741748417494175041751417524175341754417554175641757417584175941760417614176241763417644176541766417674176841769417704177141772417734177441775417764177741778417794178041781417824178341784417854178641787417884178941790417914179241793417944179541796417974179841799418004180141802418034180441805418064180741808418094181041811418124181341814418154181641817418184181941820418214182241823418244182541826418274182841829418304183141832418334183441835418364183741838418394184041841418424184341844418454184641847418484184941850418514185241853418544185541856418574185841859418604186141862418634186441865418664186741868418694187041871418724187341874418754187641877418784187941880418814188241883418844188541886418874188841889418904189141892418934189441895418964189741898418994190041901419024190341904419054190641907419084190941910419114191241913419144191541916419174191841919419204192141922419234192441925419264192741928419294193041931419324193341934419354193641937419384193941940419414194241943419444194541946419474194841949419504195141952419534195441955419564195741958419594196041961419624196341964419654196641967419684196941970419714197241973419744197541976419774197841979419804198141982419834198441985419864198741988419894199041991419924199341994419954199641997419984199942000420014200242003420044200542006420074200842009420104201142012420134201442015420164201742018420194202042021420224202342024420254202642027420284202942030420314203242033420344203542036420374203842039420404204142042420434204442045420464204742048420494205042051420524205342054420554205642057420584205942060420614206242063420644206542066420674206842069420704207142072420734207442075420764207742078420794208042081420824208342084420854208642087420884208942090420914209242093420944209542096420974209842099421004210142102421034210442105421064210742108421094211042111421124211342114421154211642117421184211942120421214212242123421244212542126421274212842129421304213142132421334213442135421364213742138421394214042141421424214342144421454214642147421484214942150421514215242153421544215542156421574215842159421604216142162421634216442165421664216742168421694217042171421724217342174421754217642177421784217942180421814218242183421844218542186421874218842189421904219142192421934219442195421964219742198421994220042201422024220342204422054220642207422084220942210422114221242213422144221542216422174221842219422204222142222422234222442225422264222742228422294223042231422324223342234422354223642237422384223942240422414224242243422444224542246422474224842249422504225142252422534225442255422564225742258422594226042261422624226342264422654226642267422684226942270422714227242273422744227542276422774227842279422804228142282422834228442285422864228742288422894229042291422924229342294422954229642297422984229942300423014230242303423044230542306423074230842309423104231142312423134231442315423164231742318423194232042321423224232342324423254232642327423284232942330423314233242333423344233542336423374233842339423404234142342423434234442345423464234742348423494235042351423524235342354423554235642357423584235942360423614236242363423644236542366423674236842369423704237142372423734237442375423764237742378423794238042381423824238342384423854238642387423884238942390423914239242393423944239542396423974239842399424004240142402424034240442405424064240742408424094241042411424124241342414424154241642417424184241942420424214242242423424244242542426424274242842429424304243142432424334243442435424364243742438424394244042441424424244342444424454244642447424484244942450424514245242453424544245542456424574245842459424604246142462424634246442465424664246742468424694247042471424724247342474424754247642477424784247942480424814248242483424844248542486424874248842489424904249142492424934249442495424964249742498424994250042501425024250342504425054250642507425084250942510425114251242513425144251542516425174251842519425204252142522425234252442525425264252742528425294253042531425324253342534425354253642537425384253942540425414254242543425444254542546425474254842549425504255142552425534255442555425564255742558425594256042561425624256342564425654256642567425684256942570425714257242573425744257542576425774257842579425804258142582425834258442585425864258742588425894259042591425924259342594425954259642597425984259942600426014260242603426044260542606426074260842609426104261142612426134261442615426164261742618426194262042621426224262342624426254262642627426284262942630426314263242633426344263542636426374263842639426404264142642426434264442645426464264742648426494265042651426524265342654426554265642657426584265942660426614266242663426644266542666426674266842669426704267142672426734267442675426764267742678426794268042681426824268342684426854268642687426884268942690426914269242693426944269542696426974269842699427004270142702427034270442705427064270742708427094271042711427124271342714427154271642717427184271942720427214272242723427244272542726427274272842729427304273142732427334273442735427364273742738427394274042741427424274342744427454274642747427484274942750427514275242753427544275542756427574275842759427604276142762427634276442765427664276742768427694277042771427724277342774427754277642777427784277942780427814278242783427844278542786427874278842789427904279142792427934279442795427964279742798427994280042801428024280342804428054280642807428084280942810428114281242813428144281542816428174281842819428204282142822428234282442825428264282742828428294283042831428324283342834428354283642837428384283942840428414284242843428444284542846428474284842849428504285142852428534285442855428564285742858428594286042861428624286342864428654286642867428684286942870428714287242873428744287542876428774287842879428804288142882428834288442885428864288742888428894289042891428924289342894428954289642897428984289942900429014290242903429044290542906429074290842909429104291142912429134291442915429164291742918429194292042921429224292342924429254292642927429284292942930429314293242933429344293542936429374293842939429404294142942429434294442945429464294742948429494295042951429524295342954429554295642957429584295942960429614296242963429644296542966429674296842969429704297142972429734297442975429764297742978429794298042981429824298342984429854298642987429884298942990429914299242993429944299542996429974299842999430004300143002430034300443005430064300743008430094301043011430124301343014430154301643017430184301943020430214302243023430244302543026430274302843029430304303143032430334303443035430364303743038430394304043041430424304343044430454304643047430484304943050430514305243053430544305543056430574305843059430604306143062430634306443065430664306743068430694307043071430724307343074430754307643077430784307943080430814308243083430844308543086430874308843089430904309143092430934309443095430964309743098430994310043101431024310343104431054310643107431084310943110431114311243113431144311543116431174311843119431204312143122431234312443125431264312743128431294313043131431324313343134431354313643137431384313943140431414314243143431444314543146431474314843149431504315143152431534315443155431564315743158431594316043161431624316343164431654316643167431684316943170431714317243173431744317543176431774317843179431804318143182431834318443185431864318743188431894319043191431924319343194431954319643197431984319943200432014320243203432044320543206432074320843209432104321143212432134321443215432164321743218432194322043221432224322343224432254322643227432284322943230432314323243233432344323543236432374323843239432404324143242432434324443245432464324743248432494325043251432524325343254432554325643257432584325943260432614326243263432644326543266432674326843269432704327143272432734327443275432764327743278432794328043281432824328343284432854328643287432884328943290432914329243293432944329543296432974329843299433004330143302433034330443305433064330743308433094331043311433124331343314433154331643317433184331943320433214332243323433244332543326433274332843329433304333143332433334333443335433364333743338433394334043341433424334343344433454334643347433484334943350433514335243353433544335543356433574335843359433604336143362433634336443365433664336743368433694337043371433724337343374433754337643377433784337943380433814338243383433844338543386433874338843389433904339143392433934339443395433964339743398433994340043401434024340343404434054340643407434084340943410434114341243413434144341543416434174341843419434204342143422434234342443425434264342743428434294343043431434324343343434434354343643437434384343943440434414344243443434444344543446434474344843449434504345143452434534345443455434564345743458434594346043461434624346343464434654346643467434684346943470434714347243473434744347543476434774347843479434804348143482434834348443485434864348743488434894349043491434924349343494434954349643497434984349943500435014350243503435044350543506435074350843509435104351143512435134351443515435164351743518435194352043521435224352343524435254352643527435284352943530435314353243533435344353543536435374353843539435404354143542435434354443545435464354743548435494355043551435524355343554435554355643557435584355943560435614356243563435644356543566435674356843569435704357143572435734357443575435764357743578435794358043581435824358343584435854358643587435884358943590435914359243593435944359543596435974359843599436004360143602436034360443605436064360743608436094361043611436124361343614436154361643617436184361943620436214362243623436244362543626436274362843629436304363143632436334363443635436364363743638436394364043641436424364343644436454364643647436484364943650436514365243653436544365543656436574365843659436604366143662436634366443665436664366743668436694367043671436724367343674436754367643677436784367943680436814368243683436844368543686436874368843689436904369143692436934369443695436964369743698436994370043701437024370343704437054370643707437084370943710437114371243713437144371543716437174371843719437204372143722437234372443725437264372743728437294373043731437324373343734437354373643737437384373943740437414374243743437444374543746437474374843749437504375143752437534375443755437564375743758437594376043761437624376343764437654376643767437684376943770437714377243773437744377543776437774377843779437804378143782437834378443785437864378743788437894379043791437924379343794437954379643797437984379943800438014380243803438044380543806438074380843809438104381143812438134381443815438164381743818438194382043821438224382343824438254382643827438284382943830438314383243833438344383543836438374383843839438404384143842438434384443845438464384743848438494385043851438524385343854438554385643857438584385943860438614386243863438644386543866438674386843869438704387143872438734387443875438764387743878438794388043881438824388343884438854388643887438884388943890438914389243893438944389543896438974389843899439004390143902439034390443905439064390743908439094391043911439124391343914439154391643917439184391943920439214392243923439244392543926439274392843929439304393143932439334393443935439364393743938439394394043941439424394343944439454394643947439484394943950439514395243953439544395543956439574395843959439604396143962439634396443965439664396743968439694397043971439724397343974439754397643977439784397943980439814398243983439844398543986439874398843989439904399143992439934399443995439964399743998439994400044001440024400344004440054400644007440084400944010440114401244013440144401544016440174401844019440204402144022440234402444025440264402744028440294403044031440324403344034440354403644037440384403944040440414404244043440444404544046440474404844049440504405144052440534405444055440564405744058440594406044061440624406344064440654406644067440684406944070440714407244073440744407544076440774407844079440804408144082440834408444085440864408744088440894409044091440924409344094440954409644097440984409944100441014410244103441044410544106441074410844109441104411144112441134411444115441164411744118441194412044121441224412344124441254412644127441284412944130441314413244133441344413544136441374413844139441404414144142441434414444145441464414744148441494415044151441524415344154441554415644157441584415944160441614416244163441644416544166441674416844169441704417144172441734417444175441764417744178441794418044181441824418344184441854418644187441884418944190441914419244193441944419544196441974419844199442004420144202442034420444205442064420744208442094421044211442124421344214442154421644217442184421944220442214422244223442244422544226442274422844229442304423144232442334423444235442364423744238442394424044241442424424344244442454424644247442484424944250442514425244253442544425544256442574425844259442604426144262442634426444265442664426744268442694427044271442724427344274442754427644277442784427944280442814428244283442844428544286442874428844289442904429144292442934429444295442964429744298442994430044301443024430344304443054430644307443084430944310443114431244313443144431544316443174431844319443204432144322443234432444325443264432744328443294433044331443324433344334443354433644337443384433944340443414434244343443444434544346443474434844349443504435144352443534435444355443564435744358443594436044361443624436344364443654436644367443684436944370443714437244373443744437544376443774437844379443804438144382443834438444385443864438744388443894439044391443924439344394443954439644397443984439944400444014440244403444044440544406444074440844409444104441144412444134441444415444164441744418444194442044421444224442344424444254442644427444284442944430444314443244433444344443544436444374443844439444404444144442444434444444445444464444744448444494445044451444524445344454444554445644457444584445944460444614446244463444644446544466444674446844469444704447144472444734447444475444764447744478444794448044481444824448344484444854448644487444884448944490444914449244493444944449544496444974449844499445004450144502445034450444505445064450744508445094451044511445124451344514445154451644517445184451944520445214452244523445244452544526445274452844529445304453144532445334453444535445364453744538445394454044541445424454344544445454454644547445484454944550445514455244553445544455544556445574455844559445604456144562445634456444565445664456744568445694457044571445724457344574445754457644577445784457944580445814458244583445844458544586445874458844589445904459144592445934459444595445964459744598445994460044601446024460344604446054460644607446084460944610446114461244613446144461544616446174461844619446204462144622446234462444625446264462744628446294463044631446324463344634446354463644637446384463944640446414464244643446444464544646446474464844649446504465144652446534465444655446564465744658446594466044661446624466344664446654466644667446684466944670446714467244673446744467544676446774467844679446804468144682446834468444685446864468744688446894469044691446924469344694446954469644697446984469944700447014470244703447044470544706447074470844709447104471144712447134471444715447164471744718447194472044721447224472344724447254472644727447284472944730447314473244733447344473544736447374473844739447404474144742447434474444745447464474744748447494475044751447524475344754447554475644757447584475944760447614476244763447644476544766447674476844769447704477144772447734477444775447764477744778447794478044781447824478344784447854478644787447884478944790447914479244793447944479544796447974479844799448004480144802448034480444805448064480744808448094481044811448124481344814448154481644817448184481944820448214482244823448244482544826448274482844829448304483144832448334483444835448364483744838448394484044841448424484344844448454484644847448484484944850448514485244853448544485544856448574485844859448604486144862448634486444865448664486744868448694487044871448724487344874448754487644877448784487944880448814488244883448844488544886448874488844889448904489144892448934489444895448964489744898448994490044901449024490344904449054490644907449084490944910449114491244913449144491544916449174491844919449204492144922449234492444925449264492744928449294493044931449324493344934449354493644937449384493944940449414494244943449444494544946449474494844949449504495144952449534495444955449564495744958449594496044961449624496344964449654496644967449684496944970449714497244973449744497544976449774497844979449804498144982449834498444985449864498744988449894499044991449924499344994449954499644997449984499945000450014500245003450044500545006450074500845009450104501145012450134501445015450164501745018450194502045021450224502345024450254502645027450284502945030450314503245033450344503545036450374503845039450404504145042450434504445045450464504745048450494505045051450524505345054450554505645057450584505945060450614506245063450644506545066450674506845069450704507145072450734507445075450764507745078450794508045081450824508345084450854508645087450884508945090450914509245093450944509545096450974509845099451004510145102451034510445105451064510745108451094511045111451124511345114451154511645117451184511945120451214512245123451244512545126451274512845129451304513145132451334513445135451364513745138451394514045141451424514345144451454514645147451484514945150451514515245153451544515545156451574515845159451604516145162451634516445165451664516745168451694517045171451724517345174451754517645177451784517945180451814518245183451844518545186451874518845189451904519145192451934519445195451964519745198451994520045201452024520345204452054520645207452084520945210452114521245213452144521545216452174521845219452204522145222452234522445225452264522745228452294523045231452324523345234452354523645237452384523945240452414524245243452444524545246452474524845249452504525145252452534525445255452564525745258452594526045261452624526345264452654526645267452684526945270452714527245273452744527545276452774527845279452804528145282452834528445285452864528745288452894529045291452924529345294452954529645297452984529945300453014530245303453044530545306453074530845309453104531145312453134531445315453164531745318453194532045321453224532345324453254532645327453284532945330453314533245333453344533545336453374533845339453404534145342453434534445345453464534745348453494535045351453524535345354453554535645357453584535945360453614536245363453644536545366453674536845369453704537145372453734537445375453764537745378453794538045381453824538345384453854538645387453884538945390453914539245393453944539545396453974539845399454004540145402454034540445405454064540745408454094541045411454124541345414454154541645417454184541945420454214542245423454244542545426454274542845429454304543145432454334543445435454364543745438454394544045441454424544345444454454544645447454484544945450454514545245453454544545545456454574545845459454604546145462454634546445465454664546745468454694547045471454724547345474454754547645477454784547945480454814548245483454844548545486454874548845489454904549145492454934549445495454964549745498454994550045501455024550345504455054550645507455084550945510455114551245513455144551545516455174551845519455204552145522455234552445525455264552745528455294553045531455324553345534455354553645537455384553945540455414554245543455444554545546455474554845549455504555145552455534555445555455564555745558455594556045561455624556345564455654556645567455684556945570455714557245573455744557545576455774557845579455804558145582455834558445585455864558745588455894559045591455924559345594455954559645597455984559945600456014560245603456044560545606456074560845609456104561145612456134561445615456164561745618456194562045621456224562345624456254562645627456284562945630456314563245633456344563545636456374563845639456404564145642456434564445645456464564745648456494565045651456524565345654456554565645657456584565945660456614566245663456644566545666456674566845669456704567145672456734567445675456764567745678456794568045681456824568345684456854568645687456884568945690456914569245693456944569545696456974569845699457004570145702457034570445705457064570745708457094571045711457124571345714457154571645717457184571945720457214572245723457244572545726457274572845729457304573145732457334573445735457364573745738457394574045741457424574345744457454574645747457484574945750457514575245753457544575545756457574575845759457604576145762457634576445765457664576745768457694577045771457724577345774457754577645777457784577945780457814578245783457844578545786457874578845789457904579145792457934579445795457964579745798457994580045801458024580345804458054580645807458084580945810458114581245813458144581545816458174581845819458204582145822458234582445825458264582745828458294583045831458324583345834458354583645837458384583945840458414584245843458444584545846458474584845849458504585145852458534585445855458564585745858458594586045861458624586345864458654586645867458684586945870458714587245873458744587545876458774587845879458804588145882458834588445885458864588745888458894589045891458924589345894458954589645897458984589945900459014590245903459044590545906459074590845909459104591145912459134591445915459164591745918459194592045921459224592345924459254592645927459284592945930459314593245933459344593545936459374593845939459404594145942459434594445945459464594745948459494595045951459524595345954459554595645957459584595945960459614596245963459644596545966459674596845969459704597145972459734597445975459764597745978459794598045981459824598345984459854598645987459884598945990459914599245993459944599545996459974599845999460004600146002460034600446005460064600746008460094601046011460124601346014460154601646017460184601946020460214602246023460244602546026460274602846029460304603146032460334603446035460364603746038460394604046041460424604346044460454604646047460484604946050460514605246053460544605546056460574605846059460604606146062460634606446065460664606746068460694607046071460724607346074460754607646077460784607946080460814608246083460844608546086460874608846089460904609146092460934609446095460964609746098460994610046101461024610346104461054610646107461084610946110461114611246113461144611546116461174611846119461204612146122461234612446125461264612746128461294613046131461324613346134461354613646137461384613946140461414614246143461444614546146461474614846149461504615146152461534615446155461564615746158461594616046161461624616346164461654616646167461684616946170461714617246173461744617546176461774617846179461804618146182461834618446185461864618746188461894619046191461924619346194461954619646197461984619946200462014620246203462044620546206462074620846209462104621146212462134621446215462164621746218462194622046221462224622346224462254622646227462284622946230462314623246233462344623546236462374623846239462404624146242462434624446245462464624746248462494625046251462524625346254462554625646257462584625946260462614626246263462644626546266462674626846269462704627146272462734627446275462764627746278462794628046281462824628346284462854628646287462884628946290462914629246293462944629546296462974629846299463004630146302463034630446305463064630746308463094631046311463124631346314463154631646317463184631946320463214632246323463244632546326463274632846329463304633146332463334633446335463364633746338463394634046341463424634346344463454634646347463484634946350463514635246353463544635546356463574635846359463604636146362463634636446365463664636746368463694637046371463724637346374463754637646377463784637946380463814638246383463844638546386463874638846389463904639146392463934639446395463964639746398463994640046401464024640346404464054640646407464084640946410464114641246413464144641546416464174641846419464204642146422464234642446425464264642746428464294643046431464324643346434464354643646437464384643946440464414644246443464444644546446464474644846449464504645146452464534645446455464564645746458464594646046461464624646346464464654646646467464684646946470464714647246473464744647546476464774647846479464804648146482464834648446485464864648746488464894649046491464924649346494464954649646497464984649946500465014650246503465044650546506465074650846509465104651146512465134651446515465164651746518465194652046521465224652346524465254652646527465284652946530465314653246533465344653546536465374653846539465404654146542465434654446545465464654746548465494655046551465524655346554465554655646557465584655946560465614656246563465644656546566465674656846569465704657146572465734657446575465764657746578465794658046581465824658346584465854658646587465884658946590465914659246593465944659546596465974659846599466004660146602466034660446605466064660746608466094661046611466124661346614466154661646617466184661946620466214662246623466244662546626466274662846629466304663146632466334663446635466364663746638466394664046641466424664346644466454664646647466484664946650466514665246653466544665546656466574665846659466604666146662466634666446665466664666746668466694667046671466724667346674466754667646677466784667946680466814668246683466844668546686466874668846689466904669146692466934669446695466964669746698466994670046701467024670346704467054670646707467084670946710467114671246713467144671546716467174671846719467204672146722467234672446725467264672746728467294673046731467324673346734467354673646737467384673946740467414674246743467444674546746467474674846749467504675146752467534675446755467564675746758467594676046761467624676346764467654676646767467684676946770467714677246773467744677546776467774677846779467804678146782467834678446785467864678746788467894679046791467924679346794467954679646797467984679946800468014680246803468044680546806468074680846809468104681146812468134681446815468164681746818468194682046821468224682346824468254682646827468284682946830468314683246833468344683546836468374683846839468404684146842468434684446845468464684746848468494685046851468524685346854468554685646857468584685946860468614686246863468644686546866468674686846869468704687146872468734687446875468764687746878468794688046881468824688346884468854688646887468884688946890468914689246893468944689546896468974689846899469004690146902469034690446905469064690746908469094691046911469124691346914469154691646917469184691946920469214692246923469244692546926469274692846929469304693146932469334693446935469364693746938469394694046941469424694346944469454694646947469484694946950469514695246953469544695546956469574695846959469604696146962469634696446965469664696746968469694697046971469724697346974469754697646977469784697946980469814698246983469844698546986469874698846989469904699146992469934699446995469964699746998469994700047001470024700347004470054700647007470084700947010470114701247013470144701547016470174701847019470204702147022470234702447025470264702747028470294703047031470324703347034470354703647037470384703947040470414704247043470444704547046470474704847049470504705147052470534705447055470564705747058470594706047061470624706347064470654706647067470684706947070470714707247073470744707547076470774707847079470804708147082470834708447085470864708747088470894709047091470924709347094470954709647097470984709947100471014710247103471044710547106471074710847109471104711147112471134711447115471164711747118471194712047121471224712347124471254712647127471284712947130471314713247133471344713547136471374713847139471404714147142471434714447145471464714747148471494715047151471524715347154471554715647157471584715947160471614716247163471644716547166471674716847169471704717147172471734717447175471764717747178471794718047181471824718347184471854718647187471884718947190471914719247193471944719547196471974719847199472004720147202472034720447205472064720747208472094721047211472124721347214472154721647217472184721947220472214722247223472244722547226472274722847229472304723147232472334723447235472364723747238472394724047241472424724347244472454724647247472484724947250472514725247253472544725547256472574725847259472604726147262472634726447265472664726747268472694727047271472724727347274472754727647277472784727947280472814728247283472844728547286472874728847289472904729147292472934729447295472964729747298472994730047301473024730347304473054730647307473084730947310473114731247313473144731547316473174731847319473204732147322473234732447325473264732747328473294733047331473324733347334473354733647337473384733947340473414734247343473444734547346473474734847349473504735147352473534735447355473564735747358473594736047361473624736347364473654736647367473684736947370473714737247373473744737547376473774737847379473804738147382473834738447385473864738747388473894739047391473924739347394473954739647397473984739947400474014740247403474044740547406474074740847409474104741147412474134741447415474164741747418474194742047421474224742347424474254742647427474284742947430474314743247433474344743547436474374743847439474404744147442474434744447445474464744747448474494745047451474524745347454474554745647457474584745947460474614746247463474644746547466474674746847469474704747147472474734747447475474764747747478474794748047481474824748347484474854748647487474884748947490474914749247493474944749547496474974749847499475004750147502475034750447505475064750747508475094751047511475124751347514475154751647517475184751947520475214752247523475244752547526475274752847529475304753147532475334753447535475364753747538475394754047541475424754347544475454754647547475484754947550475514755247553475544755547556475574755847559475604756147562475634756447565475664756747568475694757047571475724757347574475754757647577475784757947580475814758247583475844758547586475874758847589475904759147592475934759447595475964759747598475994760047601476024760347604476054760647607476084760947610476114761247613476144761547616476174761847619476204762147622476234762447625476264762747628476294763047631476324763347634476354763647637476384763947640476414764247643476444764547646476474764847649476504765147652476534765447655476564765747658476594766047661476624766347664476654766647667476684766947670476714767247673476744767547676476774767847679476804768147682476834768447685476864768747688476894769047691476924769347694476954769647697476984769947700477014770247703477044770547706477074770847709477104771147712477134771447715477164771747718477194772047721477224772347724477254772647727477284772947730477314773247733477344773547736477374773847739477404774147742477434774447745477464774747748477494775047751477524775347754477554775647757477584775947760477614776247763477644776547766477674776847769477704777147772477734777447775477764777747778477794778047781477824778347784477854778647787477884778947790477914779247793477944779547796477974779847799478004780147802478034780447805478064780747808478094781047811478124781347814478154781647817478184781947820478214782247823478244782547826478274782847829478304783147832478334783447835478364783747838478394784047841478424784347844478454784647847478484784947850478514785247853478544785547856478574785847859478604786147862478634786447865478664786747868478694787047871478724787347874478754787647877478784787947880478814788247883478844788547886478874788847889478904789147892478934789447895478964789747898478994790047901479024790347904479054790647907479084790947910479114791247913479144791547916479174791847919479204792147922479234792447925479264792747928479294793047931479324793347934479354793647937479384793947940479414794247943479444794547946479474794847949479504795147952479534795447955479564795747958479594796047961479624796347964479654796647967479684796947970479714797247973479744797547976479774797847979479804798147982479834798447985479864798747988479894799047991479924799347994479954799647997479984799948000480014800248003480044800548006480074800848009480104801148012480134801448015480164801748018480194802048021480224802348024480254802648027480284802948030480314803248033480344803548036480374803848039480404804148042480434804448045480464804748048480494805048051480524805348054480554805648057480584805948060480614806248063480644806548066480674806848069480704807148072480734807448075480764807748078480794808048081480824808348084480854808648087480884808948090480914809248093480944809548096480974809848099481004810148102481034810448105481064810748108481094811048111481124811348114481154811648117481184811948120481214812248123481244812548126481274812848129481304813148132481334813448135481364813748138481394814048141481424814348144481454814648147481484814948150481514815248153481544815548156481574815848159481604816148162481634816448165481664816748168481694817048171481724817348174481754817648177481784817948180481814818248183481844818548186481874818848189481904819148192481934819448195481964819748198481994820048201482024820348204482054820648207482084820948210482114821248213482144821548216482174821848219482204822148222482234822448225482264822748228482294823048231482324823348234482354823648237482384823948240482414824248243482444824548246482474824848249482504825148252482534825448255482564825748258482594826048261482624826348264482654826648267482684826948270482714827248273482744827548276482774827848279482804828148282482834828448285482864828748288482894829048291482924829348294482954829648297482984829948300483014830248303483044830548306483074830848309483104831148312483134831448315483164831748318483194832048321483224832348324483254832648327483284832948330483314833248333483344833548336483374833848339483404834148342483434834448345483464834748348483494835048351483524835348354483554835648357483584835948360483614836248363483644836548366483674836848369483704837148372483734837448375483764837748378483794838048381483824838348384483854838648387483884838948390483914839248393483944839548396483974839848399484004840148402484034840448405484064840748408484094841048411484124841348414484154841648417484184841948420484214842248423484244842548426484274842848429484304843148432484334843448435484364843748438484394844048441484424844348444484454844648447484484844948450484514845248453484544845548456484574845848459484604846148462484634846448465484664846748468484694847048471484724847348474484754847648477484784847948480484814848248483484844848548486484874848848489484904849148492484934849448495484964849748498484994850048501485024850348504485054850648507485084850948510485114851248513485144851548516485174851848519485204852148522485234852448525485264852748528485294853048531485324853348534485354853648537485384853948540485414854248543485444854548546485474854848549485504855148552485534855448555485564855748558485594856048561485624856348564485654856648567485684856948570485714857248573485744857548576485774857848579485804858148582485834858448585485864858748588485894859048591485924859348594485954859648597485984859948600486014860248603486044860548606486074860848609486104861148612486134861448615486164861748618486194862048621486224862348624486254862648627486284862948630486314863248633486344863548636486374863848639486404864148642486434864448645486464864748648486494865048651486524865348654486554865648657486584865948660486614866248663486644866548666486674866848669486704867148672486734867448675486764867748678486794868048681486824868348684486854868648687486884868948690486914869248693486944869548696486974869848699487004870148702487034870448705487064870748708487094871048711487124871348714487154871648717487184871948720487214872248723487244872548726487274872848729487304873148732487334873448735487364873748738487394874048741487424874348744487454874648747487484874948750487514875248753487544875548756487574875848759487604876148762487634876448765487664876748768487694877048771487724877348774487754877648777487784877948780487814878248783487844878548786487874878848789487904879148792487934879448795487964879748798487994880048801488024880348804488054880648807488084880948810488114881248813488144881548816488174881848819488204882148822488234882448825488264882748828488294883048831488324883348834488354883648837488384883948840488414884248843488444884548846488474884848849488504885148852488534885448855488564885748858488594886048861488624886348864488654886648867488684886948870488714887248873488744887548876488774887848879488804888148882488834888448885488864888748888488894889048891488924889348894488954889648897488984889948900489014890248903489044890548906489074890848909489104891148912489134891448915489164891748918489194892048921489224892348924489254892648927489284892948930489314893248933489344893548936489374893848939489404894148942489434894448945489464894748948489494895048951489524895348954489554895648957489584895948960489614896248963489644896548966489674896848969489704897148972489734897448975489764897748978489794898048981489824898348984489854898648987489884898948990489914899248993489944899548996489974899848999490004900149002490034900449005490064900749008490094901049011490124901349014490154901649017490184901949020490214902249023490244902549026490274902849029490304903149032490334903449035490364903749038490394904049041490424904349044490454904649047490484904949050490514905249053490544905549056490574905849059490604906149062490634906449065490664906749068490694907049071490724907349074490754907649077490784907949080490814908249083490844908549086490874908849089490904909149092490934909449095490964909749098490994910049101491024910349104491054910649107491084910949110491114911249113491144911549116491174911849119491204912149122491234912449125491264912749128491294913049131491324913349134491354913649137491384913949140491414914249143491444914549146491474914849149491504915149152491534915449155491564915749158491594916049161491624916349164491654916649167491684916949170491714917249173491744917549176491774917849179491804918149182491834918449185491864918749188491894919049191491924919349194491954919649197491984919949200492014920249203492044920549206492074920849209492104921149212492134921449215492164921749218492194922049221492224922349224492254922649227492284922949230492314923249233492344923549236492374923849239492404924149242492434924449245492464924749248492494925049251492524925349254492554925649257492584925949260492614926249263492644926549266492674926849269492704927149272492734927449275492764927749278492794928049281492824928349284492854928649287492884928949290492914929249293492944929549296492974929849299493004930149302493034930449305493064930749308493094931049311493124931349314493154931649317493184931949320493214932249323493244932549326493274932849329493304933149332493334933449335493364933749338493394934049341493424934349344493454934649347493484934949350493514935249353493544935549356493574935849359493604936149362493634936449365493664936749368493694937049371493724937349374493754937649377493784937949380493814938249383493844938549386493874938849389493904939149392493934939449395493964939749398493994940049401494024940349404494054940649407494084940949410494114941249413494144941549416494174941849419494204942149422494234942449425494264942749428494294943049431494324943349434494354943649437494384943949440494414944249443494444944549446494474944849449494504945149452494534945449455494564945749458494594946049461494624946349464494654946649467494684946949470494714947249473494744947549476494774947849479494804948149482494834948449485494864948749488494894949049491494924949349494494954949649497494984949949500495014950249503495044950549506495074950849509495104951149512495134951449515495164951749518495194952049521495224952349524495254952649527495284952949530495314953249533495344953549536495374953849539495404954149542495434954449545495464954749548495494955049551495524955349554495554955649557495584955949560495614956249563495644956549566495674956849569495704957149572495734957449575495764957749578495794958049581495824958349584495854958649587495884958949590495914959249593495944959549596495974959849599496004960149602496034960449605496064960749608496094961049611496124961349614496154961649617496184961949620496214962249623496244962549626496274962849629496304963149632496334963449635496364963749638496394964049641496424964349644496454964649647496484964949650496514965249653496544965549656496574965849659496604966149662496634966449665496664966749668496694967049671496724967349674496754967649677496784967949680496814968249683496844968549686496874968849689496904969149692496934969449695496964969749698496994970049701497024970349704497054970649707497084970949710497114971249713497144971549716497174971849719497204972149722497234972449725497264972749728497294973049731497324973349734497354973649737497384973949740497414974249743497444974549746497474974849749497504975149752497534975449755497564975749758497594976049761497624976349764497654976649767497684976949770497714977249773497744977549776497774977849779497804978149782497834978449785497864978749788497894979049791497924979349794497954979649797497984979949800498014980249803498044980549806498074980849809498104981149812498134981449815498164981749818498194982049821498224982349824498254982649827498284982949830498314983249833498344983549836498374983849839498404984149842498434984449845498464984749848498494985049851498524985349854498554985649857498584985949860498614986249863498644986549866498674986849869498704987149872498734987449875498764987749878498794988049881498824988349884498854988649887498884988949890498914989249893498944989549896498974989849899499004990149902499034990449905499064990749908499094991049911499124991349914499154991649917499184991949920499214992249923499244992549926499274992849929499304993149932499334993449935499364993749938499394994049941499424994349944499454994649947499484994949950499514995249953499544995549956499574995849959499604996149962499634996449965499664996749968499694997049971499724997349974499754997649977499784997949980499814998249983499844998549986499874998849989499904999149992499934999449995499964999749998499995000050001500025000350004500055000650007500085000950010500115001250013500145001550016500175001850019500205002150022500235002450025500265002750028500295003050031500325003350034500355003650037500385003950040500415004250043500445004550046500475004850049500505005150052500535005450055500565005750058500595006050061500625006350064500655006650067500685006950070500715007250073500745007550076500775007850079500805008150082500835008450085500865008750088500895009050091500925009350094500955009650097500985009950100501015010250103501045010550106501075010850109501105011150112501135011450115501165011750118501195012050121501225012350124501255012650127501285012950130501315013250133501345013550136501375013850139501405014150142501435014450145501465014750148501495015050151501525015350154501555015650157501585015950160501615016250163501645016550166501675016850169501705017150172501735017450175501765017750178501795018050181501825018350184501855018650187501885018950190501915019250193501945019550196501975019850199502005020150202502035020450205502065020750208502095021050211502125021350214502155021650217502185021950220502215022250223502245022550226502275022850229502305023150232502335023450235502365023750238502395024050241502425024350244502455024650247502485024950250502515025250253502545025550256502575025850259502605026150262502635026450265502665026750268502695027050271502725027350274502755027650277502785027950280502815028250283502845028550286502875028850289502905029150292502935029450295502965029750298502995030050301503025030350304503055030650307503085030950310503115031250313503145031550316503175031850319503205032150322503235032450325503265032750328503295033050331503325033350334503355033650337503385033950340503415034250343503445034550346503475034850349503505035150352503535035450355503565035750358503595036050361503625036350364503655036650367503685036950370503715037250373503745037550376503775037850379503805038150382503835038450385503865038750388503895039050391503925039350394503955039650397503985039950400504015040250403504045040550406504075040850409504105041150412504135041450415504165041750418504195042050421504225042350424504255042650427504285042950430504315043250433504345043550436504375043850439504405044150442504435044450445504465044750448504495045050451504525045350454504555045650457504585045950460504615046250463504645046550466504675046850469504705047150472504735047450475504765047750478504795048050481504825048350484504855048650487504885048950490504915049250493504945049550496504975049850499505005050150502505035050450505505065050750508505095051050511505125051350514505155051650517505185051950520505215052250523505245052550526505275052850529505305053150532505335053450535505365053750538505395054050541505425054350544505455054650547505485054950550505515055250553505545055550556505575055850559505605056150562505635056450565505665056750568505695057050571505725057350574505755057650577505785057950580505815058250583505845058550586505875058850589505905059150592505935059450595505965059750598505995060050601506025060350604506055060650607506085060950610506115061250613506145061550616506175061850619506205062150622506235062450625506265062750628506295063050631506325063350634506355063650637506385063950640506415064250643506445064550646506475064850649506505065150652506535065450655506565065750658506595066050661506625066350664506655066650667506685066950670506715067250673506745067550676506775067850679506805068150682506835068450685506865068750688506895069050691506925069350694506955069650697506985069950700507015070250703507045070550706507075070850709507105071150712507135071450715507165071750718507195072050721507225072350724507255072650727507285072950730507315073250733507345073550736507375073850739507405074150742507435074450745507465074750748507495075050751507525075350754507555075650757507585075950760507615076250763507645076550766507675076850769507705077150772507735077450775507765077750778507795078050781507825078350784507855078650787507885078950790507915079250793507945079550796507975079850799508005080150802508035080450805508065080750808508095081050811508125081350814508155081650817508185081950820508215082250823508245082550826508275082850829508305083150832508335083450835508365083750838508395084050841508425084350844508455084650847508485084950850508515085250853508545085550856508575085850859508605086150862508635086450865508665086750868508695087050871508725087350874508755087650877508785087950880508815088250883508845088550886508875088850889508905089150892508935089450895508965089750898508995090050901509025090350904509055090650907509085090950910509115091250913509145091550916509175091850919509205092150922509235092450925509265092750928509295093050931509325093350934509355093650937509385093950940509415094250943509445094550946509475094850949509505095150952509535095450955509565095750958509595096050961509625096350964509655096650967509685096950970509715097250973509745097550976509775097850979509805098150982509835098450985509865098750988509895099050991509925099350994509955099650997509985099951000510015100251003510045100551006510075100851009510105101151012510135101451015510165101751018510195102051021510225102351024510255102651027510285102951030510315103251033510345103551036510375103851039510405104151042510435104451045510465104751048510495105051051510525105351054510555105651057510585105951060510615106251063510645106551066510675106851069510705107151072510735107451075510765107751078510795108051081510825108351084510855108651087510885108951090510915109251093510945109551096510975109851099511005110151102511035110451105511065110751108511095111051111511125111351114511155111651117511185111951120511215112251123511245112551126511275112851129511305113151132511335113451135511365113751138511395114051141511425114351144511455114651147511485114951150511515115251153511545115551156511575115851159511605116151162511635116451165511665116751168511695117051171511725117351174511755117651177511785117951180511815118251183511845118551186511875118851189511905119151192511935119451195511965119751198511995120051201512025120351204512055120651207512085120951210512115121251213512145121551216512175121851219512205122151222512235122451225512265122751228512295123051231512325123351234512355123651237512385123951240512415124251243512445124551246512475124851249512505125151252512535125451255512565125751258512595126051261512625126351264512655126651267512685126951270512715127251273512745127551276512775127851279512805128151282512835128451285512865128751288512895129051291512925129351294512955129651297512985129951300513015130251303513045130551306513075130851309513105131151312513135131451315513165131751318513195132051321513225132351324513255132651327513285132951330513315133251333513345133551336513375133851339513405134151342513435134451345513465134751348513495135051351513525135351354513555135651357513585135951360513615136251363513645136551366513675136851369513705137151372513735137451375513765137751378513795138051381513825138351384513855138651387513885138951390513915139251393513945139551396513975139851399514005140151402514035140451405514065140751408514095141051411514125141351414514155141651417514185141951420514215142251423514245142551426514275142851429514305143151432514335143451435514365143751438514395144051441514425144351444514455144651447514485144951450514515145251453514545145551456514575145851459514605146151462514635146451465514665146751468514695147051471514725147351474514755147651477514785147951480514815148251483514845148551486514875148851489514905149151492514935149451495514965149751498514995150051501515025150351504515055150651507515085150951510515115151251513515145151551516515175151851519515205152151522515235152451525515265152751528515295153051531515325153351534515355153651537515385153951540515415154251543515445154551546515475154851549515505155151552515535155451555515565155751558515595156051561515625156351564515655156651567515685156951570515715157251573515745157551576515775157851579515805158151582515835158451585515865158751588515895159051591515925159351594515955159651597515985159951600516015160251603516045160551606516075160851609516105161151612516135161451615516165161751618516195162051621516225162351624516255162651627516285162951630516315163251633516345163551636516375163851639516405164151642516435164451645516465164751648516495165051651516525165351654516555165651657516585165951660516615166251663516645166551666516675166851669516705167151672516735167451675516765167751678516795168051681516825168351684516855168651687516885168951690516915169251693516945169551696516975169851699517005170151702517035170451705517065170751708517095171051711517125171351714517155171651717517185171951720517215172251723517245172551726517275172851729517305173151732517335173451735517365173751738517395174051741517425174351744517455174651747517485174951750517515175251753517545175551756517575175851759517605176151762517635176451765517665176751768517695177051771517725177351774517755177651777517785177951780517815178251783517845178551786517875178851789517905179151792517935179451795517965179751798517995180051801518025180351804518055180651807518085180951810518115181251813518145181551816518175181851819518205182151822518235182451825518265182751828518295183051831518325183351834518355183651837518385183951840518415184251843518445184551846518475184851849518505185151852518535185451855518565185751858518595186051861518625186351864518655186651867518685186951870518715187251873518745187551876518775187851879518805188151882518835188451885518865188751888518895189051891518925189351894518955189651897518985189951900519015190251903519045190551906519075190851909519105191151912519135191451915519165191751918519195192051921519225192351924519255192651927519285192951930519315193251933519345193551936519375193851939519405194151942519435194451945519465194751948519495195051951519525195351954519555195651957519585195951960519615196251963519645196551966519675196851969519705197151972519735197451975519765197751978519795198051981519825198351984519855198651987519885198951990519915199251993519945199551996519975199851999520005200152002520035200452005520065200752008520095201052011520125201352014520155201652017520185201952020520215202252023520245202552026520275202852029520305203152032520335203452035520365203752038520395204052041520425204352044520455204652047520485204952050520515205252053520545205552056520575205852059520605206152062520635206452065520665206752068520695207052071520725207352074520755207652077520785207952080520815208252083520845208552086520875208852089520905209152092520935209452095520965209752098520995210052101521025210352104521055210652107521085210952110521115211252113521145211552116521175211852119521205212152122521235212452125521265212752128521295213052131521325213352134521355213652137521385213952140521415214252143521445214552146521475214852149521505215152152521535215452155521565215752158521595216052161521625216352164521655216652167521685216952170521715217252173521745217552176521775217852179521805218152182521835218452185521865218752188521895219052191521925219352194521955219652197521985219952200522015220252203522045220552206522075220852209522105221152212522135221452215522165221752218522195222052221522225222352224522255222652227522285222952230522315223252233522345223552236522375223852239522405224152242522435224452245522465224752248522495225052251522525225352254522555225652257522585225952260522615226252263522645226552266522675226852269522705227152272522735227452275522765227752278522795228052281522825228352284522855228652287522885228952290522915229252293522945229552296522975229852299523005230152302523035230452305523065230752308523095231052311523125231352314523155231652317523185231952320523215232252323523245232552326523275232852329523305233152332523335233452335523365233752338523395234052341523425234352344523455234652347523485234952350523515235252353523545235552356523575235852359523605236152362523635236452365523665236752368523695237052371523725237352374523755237652377523785237952380523815238252383523845238552386523875238852389523905239152392523935239452395523965239752398523995240052401524025240352404524055240652407524085240952410524115241252413524145241552416524175241852419524205242152422524235242452425524265242752428524295243052431524325243352434524355243652437524385243952440524415244252443524445244552446524475244852449524505245152452524535245452455524565245752458524595246052461524625246352464524655246652467524685246952470524715247252473524745247552476524775247852479524805248152482524835248452485524865248752488524895249052491524925249352494524955249652497524985249952500525015250252503525045250552506525075250852509525105251152512525135251452515525165251752518525195252052521525225252352524525255252652527525285252952530525315253252533525345253552536525375253852539525405254152542525435254452545525465254752548525495255052551525525255352554525555255652557525585255952560525615256252563525645256552566525675256852569525705257152572525735257452575525765257752578525795258052581525825258352584525855258652587525885258952590525915259252593525945259552596525975259852599526005260152602526035260452605526065260752608526095261052611526125261352614526155261652617526185261952620526215262252623526245262552626526275262852629526305263152632526335263452635526365263752638526395264052641526425264352644526455264652647526485264952650526515265252653526545265552656526575265852659526605266152662526635266452665526665266752668526695267052671526725267352674526755267652677526785267952680526815268252683526845268552686526875268852689526905269152692526935269452695526965269752698526995270052701527025270352704527055270652707527085270952710527115271252713527145271552716527175271852719527205272152722527235272452725527265272752728527295273052731527325273352734527355273652737527385273952740527415274252743527445274552746527475274852749527505275152752527535275452755527565275752758527595276052761527625276352764527655276652767527685276952770527715277252773527745277552776527775277852779527805278152782527835278452785527865278752788527895279052791527925279352794527955279652797527985279952800528015280252803528045280552806528075280852809528105281152812528135281452815528165281752818528195282052821528225282352824528255282652827528285282952830528315283252833528345283552836528375283852839528405284152842528435284452845528465284752848528495285052851528525285352854528555285652857528585285952860528615286252863528645286552866528675286852869528705287152872528735287452875528765287752878528795288052881528825288352884528855288652887528885288952890528915289252893528945289552896528975289852899529005290152902529035290452905529065290752908529095291052911529125291352914529155291652917529185291952920529215292252923529245292552926529275292852929529305293152932529335293452935529365293752938529395294052941529425294352944529455294652947529485294952950529515295252953529545295552956529575295852959529605296152962529635296452965529665296752968529695297052971529725297352974529755297652977529785297952980529815298252983529845298552986529875298852989529905299152992529935299452995529965299752998529995300053001530025300353004530055300653007530085300953010530115301253013530145301553016530175301853019530205302153022530235302453025530265302753028530295303053031530325303353034530355303653037530385303953040530415304253043530445304553046530475304853049530505305153052530535305453055530565305753058530595306053061530625306353064530655306653067530685306953070530715307253073530745307553076530775307853079530805308153082530835308453085530865308753088530895309053091530925309353094530955309653097530985309953100531015310253103531045310553106531075310853109531105311153112531135311453115531165311753118531195312053121531225312353124531255312653127531285312953130531315313253133531345313553136531375313853139531405314153142531435314453145531465314753148531495315053151531525315353154531555315653157531585315953160531615316253163531645316553166531675316853169531705317153172531735317453175531765317753178531795318053181531825318353184531855318653187531885318953190531915319253193531945319553196531975319853199532005320153202532035320453205532065320753208532095321053211532125321353214532155321653217532185321953220532215322253223532245322553226532275322853229532305323153232532335323453235532365323753238532395324053241532425324353244532455324653247532485324953250532515325253253532545325553256532575325853259532605326153262532635326453265532665326753268532695327053271532725327353274532755327653277532785327953280532815328253283532845328553286532875328853289532905329153292532935329453295532965329753298532995330053301533025330353304533055330653307533085330953310533115331253313533145331553316533175331853319533205332153322533235332453325533265332753328533295333053331533325333353334533355333653337533385333953340533415334253343533445334553346533475334853349533505335153352533535335453355533565335753358533595336053361533625336353364533655336653367533685336953370533715337253373533745337553376533775337853379533805338153382533835338453385533865338753388533895339053391533925339353394533955339653397533985339953400534015340253403534045340553406534075340853409534105341153412534135341453415534165341753418534195342053421534225342353424534255342653427534285342953430534315343253433534345343553436534375343853439534405344153442534435344453445534465344753448534495345053451534525345353454534555345653457534585345953460534615346253463534645346553466534675346853469534705347153472534735347453475534765347753478534795348053481534825348353484534855348653487534885348953490534915349253493534945349553496534975349853499535005350153502535035350453505535065350753508535095351053511535125351353514535155351653517535185351953520535215352253523535245352553526535275352853529535305353153532535335353453535535365353753538535395354053541535425354353544535455354653547535485354953550535515355253553535545355553556535575355853559535605356153562535635356453565535665356753568535695357053571535725357353574535755357653577535785357953580535815358253583535845358553586535875358853589535905359153592535935359453595535965359753598535995360053601536025360353604536055360653607536085360953610536115361253613536145361553616536175361853619536205362153622536235362453625536265362753628536295363053631536325363353634536355363653637536385363953640536415364253643536445364553646536475364853649536505365153652536535365453655536565365753658536595366053661536625366353664536655366653667536685366953670536715367253673536745367553676536775367853679536805368153682536835368453685536865368753688536895369053691536925369353694536955369653697536985369953700537015370253703537045370553706537075370853709537105371153712537135371453715537165371753718537195372053721537225372353724537255372653727537285372953730537315373253733537345373553736537375373853739537405374153742537435374453745537465374753748537495375053751537525375353754537555375653757537585375953760537615376253763537645376553766537675376853769537705377153772537735377453775537765377753778537795378053781537825378353784537855378653787537885378953790537915379253793537945379553796537975379853799538005380153802538035380453805538065380753808538095381053811538125381353814538155381653817538185381953820538215382253823538245382553826538275382853829538305383153832538335383453835538365383753838538395384053841538425384353844538455384653847538485384953850538515385253853538545385553856538575385853859538605386153862538635386453865538665386753868538695387053871538725387353874538755387653877538785387953880538815388253883538845388553886538875388853889538905389153892538935389453895538965389753898538995390053901539025390353904539055390653907539085390953910539115391253913539145391553916539175391853919539205392153922539235392453925539265392753928539295393053931539325393353934539355393653937539385393953940539415394253943539445394553946539475394853949539505395153952539535395453955539565395753958539595396053961539625396353964539655396653967539685396953970539715397253973539745397553976539775397853979539805398153982539835398453985539865398753988539895399053991539925399353994539955399653997539985399954000540015400254003540045400554006540075400854009540105401154012540135401454015540165401754018540195402054021540225402354024540255402654027540285402954030540315403254033540345403554036540375403854039540405404154042540435404454045540465404754048540495405054051540525405354054540555405654057540585405954060540615406254063540645406554066540675406854069540705407154072540735407454075540765407754078540795408054081540825408354084540855408654087540885408954090540915409254093540945409554096540975409854099541005410154102541035410454105541065410754108541095411054111541125411354114541155411654117541185411954120541215412254123541245412554126541275412854129541305413154132541335413454135541365413754138541395414054141541425414354144541455414654147541485414954150541515415254153541545415554156541575415854159541605416154162541635416454165541665416754168541695417054171541725417354174541755417654177541785417954180541815418254183541845418554186541875418854189541905419154192541935419454195541965419754198541995420054201542025420354204542055420654207542085420954210542115421254213542145421554216542175421854219542205422154222542235422454225542265422754228542295423054231542325423354234542355423654237542385423954240542415424254243542445424554246542475424854249542505425154252542535425454255542565425754258542595426054261542625426354264542655426654267542685426954270542715427254273542745427554276542775427854279542805428154282542835428454285542865428754288542895429054291542925429354294542955429654297542985429954300543015430254303543045430554306543075430854309543105431154312543135431454315543165431754318543195432054321543225432354324543255432654327543285432954330543315433254333543345433554336543375433854339543405434154342543435434454345543465434754348543495435054351543525435354354543555435654357543585435954360543615436254363543645436554366543675436854369543705437154372543735437454375543765437754378543795438054381543825438354384543855438654387543885438954390543915439254393543945439554396543975439854399544005440154402544035440454405544065440754408544095441054411544125441354414544155441654417544185441954420544215442254423544245442554426544275442854429544305443154432544335443454435544365443754438544395444054441544425444354444544455444654447544485444954450544515445254453544545445554456544575445854459544605446154462544635446454465544665446754468544695447054471544725447354474544755447654477544785447954480544815448254483544845448554486544875448854489544905449154492544935449454495544965449754498544995450054501545025450354504545055450654507545085450954510545115451254513545145451554516545175451854519545205452154522545235452454525545265452754528545295453054531545325453354534545355453654537545385453954540545415454254543545445454554546545475454854549545505455154552545535455454555545565455754558545595456054561545625456354564545655456654567545685456954570545715457254573545745457554576545775457854579545805458154582545835458454585545865458754588545895459054591545925459354594545955459654597545985459954600546015460254603546045460554606546075460854609546105461154612546135461454615546165461754618546195462054621546225462354624546255462654627546285462954630546315463254633546345463554636546375463854639546405464154642546435464454645546465464754648546495465054651546525465354654546555465654657546585465954660546615466254663546645466554666546675466854669546705467154672546735467454675546765467754678546795468054681546825468354684546855468654687546885468954690546915469254693546945469554696546975469854699547005470154702547035470454705547065470754708547095471054711547125471354714547155471654717547185471954720547215472254723547245472554726547275472854729547305473154732547335473454735547365473754738547395474054741547425474354744547455474654747547485474954750547515475254753547545475554756547575475854759547605476154762547635476454765547665476754768547695477054771547725477354774547755477654777547785477954780547815478254783547845478554786547875478854789547905479154792547935479454795547965479754798547995480054801548025480354804548055480654807548085480954810548115481254813548145481554816548175481854819548205482154822548235482454825548265482754828548295483054831548325483354834548355483654837548385483954840548415484254843548445484554846548475484854849548505485154852548535485454855548565485754858548595486054861548625486354864548655486654867548685486954870548715487254873548745487554876548775487854879548805488154882548835488454885548865488754888548895489054891548925489354894548955489654897548985489954900549015490254903549045490554906549075490854909549105491154912549135491454915549165491754918549195492054921549225492354924549255492654927549285492954930549315493254933549345493554936549375493854939549405494154942549435494454945549465494754948549495495054951549525495354954549555495654957549585495954960549615496254963549645496554966549675496854969549705497154972549735497454975549765497754978549795498054981549825498354984549855498654987549885498954990549915499254993549945499554996549975499854999550005500155002550035500455005550065500755008550095501055011550125501355014550155501655017550185501955020550215502255023550245502555026550275502855029550305503155032550335503455035550365503755038550395504055041550425504355044550455504655047550485504955050550515505255053550545505555056550575505855059550605506155062550635506455065550665506755068550695507055071550725507355074550755507655077550785507955080550815508255083550845508555086550875508855089550905509155092550935509455095550965509755098550995510055101551025510355104551055510655107551085510955110551115511255113551145511555116551175511855119551205512155122551235512455125551265512755128551295513055131551325513355134551355513655137551385513955140551415514255143551445514555146551475514855149551505515155152551535515455155551565515755158551595516055161551625516355164551655516655167551685516955170551715517255173551745517555176551775517855179551805518155182551835518455185551865518755188551895519055191551925519355194551955519655197551985519955200552015520255203552045520555206552075520855209552105521155212552135521455215552165521755218552195522055221552225522355224552255522655227552285522955230552315523255233552345523555236552375523855239552405524155242552435524455245552465524755248552495525055251552525525355254552555525655257552585525955260552615526255263552645526555266552675526855269552705527155272552735527455275552765527755278552795528055281552825528355284552855528655287552885528955290552915529255293552945529555296552975529855299553005530155302553035530455305553065530755308553095531055311553125531355314553155531655317553185531955320553215532255323553245532555326553275532855329553305533155332553335533455335553365533755338553395534055341553425534355344553455534655347553485534955350553515535255353553545535555356553575535855359553605536155362553635536455365553665536755368553695537055371553725537355374553755537655377553785537955380553815538255383553845538555386553875538855389553905539155392553935539455395553965539755398553995540055401554025540355404554055540655407554085540955410554115541255413554145541555416554175541855419554205542155422554235542455425554265542755428554295543055431554325543355434554355543655437554385543955440554415544255443554445544555446554475544855449554505545155452554535545455455554565545755458554595546055461554625546355464554655546655467554685546955470554715547255473554745547555476554775547855479554805548155482554835548455485554865548755488554895549055491554925549355494554955549655497554985549955500555015550255503555045550555506555075550855509555105551155512555135551455515555165551755518555195552055521555225552355524555255552655527555285552955530555315553255533555345553555536555375553855539555405554155542555435554455545555465554755548555495555055551555525555355554555555555655557555585555955560555615556255563555645556555566555675556855569555705557155572555735557455575555765557755578555795558055581555825558355584555855558655587555885558955590555915559255593555945559555596555975559855599556005560155602556035560455605556065560755608556095561055611556125561355614556155561655617556185561955620556215562255623556245562555626556275562855629556305563155632556335563455635556365563755638556395564055641556425564355644556455564655647556485564955650556515565255653556545565555656556575565855659556605566155662556635566455665556665566755668556695567055671556725567355674556755567655677556785567955680556815568255683556845568555686556875568855689556905569155692556935569455695556965569755698556995570055701557025570355704557055570655707557085570955710557115571255713557145571555716557175571855719557205572155722557235572455725557265572755728557295573055731557325573355734557355573655737557385573955740557415574255743557445574555746557475574855749557505575155752557535575455755557565575755758557595576055761557625576355764557655576655767557685576955770557715577255773557745577555776557775577855779557805578155782557835578455785557865578755788557895579055791557925579355794557955579655797557985579955800558015580255803558045580555806558075580855809558105581155812558135581455815558165581755818558195582055821558225582355824558255582655827558285582955830558315583255833558345583555836558375583855839558405584155842558435584455845558465584755848558495585055851558525585355854558555585655857558585585955860558615586255863558645586555866558675586855869558705587155872558735587455875558765587755878558795588055881558825588355884558855588655887558885588955890558915589255893558945589555896558975589855899559005590155902559035590455905559065590755908559095591055911559125591355914559155591655917559185591955920559215592255923559245592555926559275592855929559305593155932559335593455935559365593755938559395594055941559425594355944559455594655947559485594955950559515595255953559545595555956559575595855959559605596155962559635596455965559665596755968559695597055971559725597355974559755597655977559785597955980559815598255983559845598555986559875598855989559905599155992559935599455995559965599755998559995600056001560025600356004560055600656007560085600956010560115601256013560145601556016560175601856019560205602156022560235602456025560265602756028560295603056031560325603356034560355603656037560385603956040560415604256043560445604556046560475604856049560505605156052560535605456055560565605756058560595606056061560625606356064560655606656067560685606956070560715607256073560745607556076560775607856079560805608156082560835608456085560865608756088560895609056091560925609356094560955609656097560985609956100561015610256103561045610556106561075610856109561105611156112561135611456115561165611756118561195612056121561225612356124561255612656127561285612956130561315613256133561345613556136561375613856139561405614156142561435614456145561465614756148561495615056151561525615356154561555615656157561585615956160561615616256163561645616556166561675616856169561705617156172561735617456175561765617756178561795618056181561825618356184561855618656187561885618956190561915619256193561945619556196561975619856199562005620156202562035620456205562065620756208562095621056211562125621356214562155621656217562185621956220562215622256223562245622556226562275622856229562305623156232562335623456235562365623756238562395624056241562425624356244562455624656247562485624956250562515625256253562545625556256562575625856259562605626156262562635626456265562665626756268562695627056271562725627356274562755627656277562785627956280562815628256283562845628556286562875628856289562905629156292562935629456295562965629756298562995630056301563025630356304563055630656307563085630956310563115631256313563145631556316563175631856319563205632156322563235632456325563265632756328563295633056331563325633356334563355633656337563385633956340563415634256343563445634556346563475634856349563505635156352563535635456355563565635756358563595636056361563625636356364563655636656367563685636956370563715637256373563745637556376563775637856379563805638156382563835638456385563865638756388563895639056391563925639356394563955639656397563985639956400564015640256403564045640556406564075640856409564105641156412564135641456415564165641756418564195642056421564225642356424564255642656427564285642956430564315643256433564345643556436564375643856439564405644156442564435644456445564465644756448564495645056451564525645356454564555645656457564585645956460564615646256463564645646556466564675646856469564705647156472564735647456475564765647756478564795648056481564825648356484564855648656487564885648956490564915649256493564945649556496564975649856499565005650156502565035650456505565065650756508565095651056511565125651356514565155651656517565185651956520565215652256523565245652556526565275652856529565305653156532565335653456535565365653756538565395654056541565425654356544565455654656547565485654956550565515655256553565545655556556565575655856559565605656156562565635656456565565665656756568565695657056571565725657356574565755657656577565785657956580565815658256583565845658556586565875658856589565905659156592565935659456595565965659756598565995660056601566025660356604566055660656607566085660956610566115661256613566145661556616566175661856619566205662156622566235662456625566265662756628566295663056631566325663356634566355663656637566385663956640566415664256643566445664556646566475664856649566505665156652566535665456655566565665756658566595666056661566625666356664566655666656667566685666956670566715667256673566745667556676566775667856679566805668156682566835668456685566865668756688566895669056691566925669356694566955669656697566985669956700567015670256703567045670556706567075670856709567105671156712567135671456715567165671756718567195672056721567225672356724567255672656727567285672956730567315673256733567345673556736567375673856739567405674156742567435674456745567465674756748567495675056751567525675356754567555675656757567585675956760567615676256763567645676556766567675676856769567705677156772567735677456775567765677756778567795678056781567825678356784567855678656787567885678956790567915679256793567945679556796567975679856799568005680156802568035680456805568065680756808568095681056811568125681356814568155681656817568185681956820568215682256823568245682556826568275682856829568305683156832568335683456835568365683756838568395684056841568425684356844568455684656847568485684956850568515685256853568545685556856568575685856859568605686156862568635686456865568665686756868568695687056871568725687356874568755687656877568785687956880568815688256883568845688556886568875688856889568905689156892568935689456895568965689756898568995690056901569025690356904569055690656907569085690956910569115691256913569145691556916569175691856919569205692156922569235692456925569265692756928569295693056931569325693356934569355693656937569385693956940569415694256943569445694556946569475694856949569505695156952569535695456955569565695756958569595696056961569625696356964569655696656967569685696956970569715697256973569745697556976569775697856979569805698156982569835698456985569865698756988569895699056991569925699356994569955699656997569985699957000570015700257003570045700557006570075700857009570105701157012570135701457015570165701757018570195702057021570225702357024570255702657027570285702957030570315703257033570345703557036570375703857039570405704157042570435704457045570465704757048570495705057051570525705357054570555705657057570585705957060570615706257063570645706557066570675706857069570705707157072570735707457075570765707757078570795708057081570825708357084570855708657087570885708957090570915709257093570945709557096570975709857099571005710157102571035710457105571065710757108571095711057111571125711357114571155711657117571185711957120571215712257123571245712557126571275712857129571305713157132571335713457135571365713757138571395714057141571425714357144571455714657147571485714957150571515715257153571545715557156571575715857159571605716157162571635716457165571665716757168571695717057171571725717357174571755717657177571785717957180571815718257183571845718557186571875718857189571905719157192571935719457195571965719757198571995720057201572025720357204572055720657207572085720957210572115721257213572145721557216572175721857219572205722157222572235722457225572265722757228572295723057231572325723357234572355723657237572385723957240572415724257243572445724557246572475724857249572505725157252572535725457255572565725757258572595726057261572625726357264572655726657267572685726957270572715727257273572745727557276572775727857279572805728157282572835728457285572865728757288572895729057291572925729357294572955729657297572985729957300573015730257303573045730557306573075730857309573105731157312573135731457315573165731757318573195732057321573225732357324573255732657327573285732957330573315733257333573345733557336573375733857339573405734157342573435734457345573465734757348573495735057351573525735357354573555735657357573585735957360573615736257363573645736557366573675736857369573705737157372573735737457375573765737757378573795738057381573825738357384573855738657387573885738957390573915739257393573945739557396573975739857399574005740157402574035740457405574065740757408574095741057411574125741357414574155741657417574185741957420574215742257423574245742557426574275742857429574305743157432574335743457435574365743757438574395744057441574425744357444574455744657447574485744957450574515745257453574545745557456574575745857459574605746157462574635746457465574665746757468574695747057471574725747357474574755747657477574785747957480574815748257483574845748557486574875748857489574905749157492574935749457495574965749757498574995750057501575025750357504575055750657507575085750957510575115751257513575145751557516575175751857519575205752157522575235752457525575265752757528575295753057531575325753357534575355753657537575385753957540575415754257543575445754557546575475754857549575505755157552575535755457555575565755757558575595756057561575625756357564575655756657567575685756957570575715757257573575745757557576575775757857579575805758157582575835758457585575865758757588575895759057591575925759357594575955759657597575985759957600576015760257603576045760557606576075760857609576105761157612576135761457615576165761757618576195762057621576225762357624576255762657627576285762957630576315763257633576345763557636576375763857639576405764157642576435764457645576465764757648576495765057651576525765357654576555765657657576585765957660576615766257663576645766557666576675766857669576705767157672576735767457675576765767757678576795768057681576825768357684576855768657687576885768957690576915769257693576945769557696576975769857699577005770157702577035770457705577065770757708577095771057711577125771357714577155771657717577185771957720577215772257723577245772557726577275772857729577305773157732577335773457735577365773757738577395774057741577425774357744577455774657747577485774957750577515775257753577545775557756577575775857759577605776157762577635776457765577665776757768577695777057771577725777357774577755777657777577785777957780577815778257783577845778557786577875778857789577905779157792577935779457795577965779757798577995780057801578025780357804578055780657807578085780957810578115781257813578145781557816578175781857819578205782157822578235782457825578265782757828578295783057831578325783357834578355783657837578385783957840578415784257843578445784557846578475784857849578505785157852578535785457855578565785757858578595786057861578625786357864578655786657867578685786957870578715787257873578745787557876578775787857879578805788157882578835788457885578865788757888578895789057891578925789357894578955789657897578985789957900579015790257903579045790557906579075790857909579105791157912579135791457915579165791757918579195792057921579225792357924579255792657927579285792957930579315793257933579345793557936579375793857939579405794157942579435794457945579465794757948579495795057951579525795357954579555795657957579585795957960579615796257963579645796557966579675796857969579705797157972579735797457975579765797757978579795798057981579825798357984579855798657987579885798957990579915799257993579945799557996579975799857999580005800158002580035800458005580065800758008580095801058011580125801358014580155801658017580185801958020580215802258023580245802558026580275802858029580305803158032580335803458035580365803758038580395804058041580425804358044580455804658047580485804958050580515805258053580545805558056580575805858059580605806158062580635806458065580665806758068580695807058071580725807358074580755807658077580785807958080580815808258083580845808558086580875808858089580905809158092580935809458095580965809758098580995810058101581025810358104581055810658107581085810958110581115811258113581145811558116581175811858119581205812158122581235812458125581265812758128581295813058131581325813358134581355813658137581385813958140581415814258143581445814558146581475814858149581505815158152581535815458155581565815758158581595816058161581625816358164581655816658167581685816958170581715817258173581745817558176581775817858179581805818158182581835818458185581865818758188581895819058191581925819358194581955819658197581985819958200582015820258203582045820558206582075820858209582105821158212582135821458215582165821758218582195822058221582225822358224582255822658227582285822958230582315823258233582345823558236582375823858239582405824158242582435824458245582465824758248582495825058251582525825358254582555825658257582585825958260582615826258263582645826558266582675826858269582705827158272582735827458275582765827758278582795828058281582825828358284582855828658287582885828958290582915829258293582945829558296582975829858299583005830158302583035830458305583065830758308583095831058311583125831358314583155831658317583185831958320583215832258323583245832558326583275832858329583305833158332583335833458335583365833758338583395834058341583425834358344583455834658347583485834958350583515835258353583545835558356583575835858359583605836158362583635836458365583665836758368583695837058371583725837358374583755837658377583785837958380583815838258383583845838558386583875838858389583905839158392583935839458395583965839758398583995840058401584025840358404584055840658407584085840958410584115841258413584145841558416584175841858419584205842158422584235842458425584265842758428584295843058431584325843358434584355843658437584385843958440584415844258443584445844558446584475844858449584505845158452584535845458455584565845758458584595846058461584625846358464584655846658467584685846958470584715847258473584745847558476584775847858479584805848158482584835848458485584865848758488584895849058491584925849358494584955849658497584985849958500585015850258503585045850558506585075850858509585105851158512585135851458515585165851758518585195852058521585225852358524585255852658527585285852958530585315853258533585345853558536585375853858539585405854158542585435854458545585465854758548585495855058551585525855358554585555855658557585585855958560585615856258563585645856558566585675856858569585705857158572585735857458575585765857758578585795858058581585825858358584585855858658587585885858958590585915859258593585945859558596585975859858599586005860158602586035860458605586065860758608586095861058611586125861358614586155861658617586185861958620586215862258623586245862558626586275862858629586305863158632586335863458635586365863758638586395864058641586425864358644586455864658647586485864958650586515865258653586545865558656586575865858659586605866158662586635866458665586665866758668586695867058671586725867358674586755867658677586785867958680586815868258683586845868558686586875868858689586905869158692586935869458695586965869758698586995870058701587025870358704587055870658707587085870958710587115871258713587145871558716587175871858719587205872158722587235872458725587265872758728587295873058731587325873358734587355873658737587385873958740587415874258743587445874558746587475874858749587505875158752587535875458755587565875758758587595876058761587625876358764587655876658767587685876958770587715877258773587745877558776587775877858779587805878158782587835878458785587865878758788587895879058791587925879358794587955879658797587985879958800588015880258803588045880558806588075880858809588105881158812588135881458815588165881758818588195882058821588225882358824588255882658827588285882958830588315883258833588345883558836588375883858839588405884158842588435884458845588465884758848588495885058851588525885358854588555885658857588585885958860588615886258863588645886558866588675886858869588705887158872588735887458875588765887758878588795888058881588825888358884588855888658887588885888958890588915889258893588945889558896588975889858899589005890158902589035890458905589065890758908589095891058911589125891358914589155891658917589185891958920589215892258923589245892558926589275892858929589305893158932589335893458935589365893758938589395894058941589425894358944589455894658947589485894958950589515895258953589545895558956589575895858959589605896158962589635896458965589665896758968589695897058971589725897358974589755897658977589785897958980589815898258983589845898558986589875898858989589905899158992589935899458995589965899758998589995900059001590025900359004590055900659007590085900959010590115901259013590145901559016590175901859019590205902159022590235902459025590265902759028590295903059031590325903359034590355903659037590385903959040590415904259043590445904559046590475904859049590505905159052590535905459055590565905759058590595906059061590625906359064590655906659067590685906959070590715907259073590745907559076590775907859079590805908159082590835908459085590865908759088590895909059091590925909359094590955909659097590985909959100591015910259103591045910559106591075910859109591105911159112591135911459115591165911759118591195912059121591225912359124591255912659127591285912959130591315913259133591345913559136591375913859139591405914159142591435914459145591465914759148591495915059151591525915359154591555915659157591585915959160591615916259163591645916559166591675916859169591705917159172591735917459175591765917759178591795918059181591825918359184591855918659187591885918959190591915919259193591945919559196591975919859199592005920159202592035920459205592065920759208592095921059211592125921359214592155921659217592185921959220592215922259223592245922559226592275922859229592305923159232592335923459235592365923759238592395924059241592425924359244592455924659247592485924959250592515925259253592545925559256592575925859259592605926159262592635926459265592665926759268592695927059271592725927359274592755927659277592785927959280592815928259283592845928559286592875928859289592905929159292592935929459295592965929759298592995930059301593025930359304593055930659307593085930959310593115931259313593145931559316593175931859319593205932159322593235932459325593265932759328593295933059331593325933359334593355933659337593385933959340593415934259343593445934559346593475934859349593505935159352593535935459355593565935759358593595936059361593625936359364593655936659367593685936959370593715937259373593745937559376593775937859379593805938159382593835938459385593865938759388593895939059391593925939359394593955939659397593985939959400594015940259403594045940559406594075940859409594105941159412594135941459415594165941759418594195942059421594225942359424594255942659427594285942959430594315943259433594345943559436594375943859439594405944159442594435944459445594465944759448594495945059451594525945359454594555945659457594585945959460594615946259463594645946559466594675946859469594705947159472594735947459475594765947759478594795948059481594825948359484594855948659487594885948959490594915949259493594945949559496594975949859499595005950159502595035950459505595065950759508595095951059511595125951359514595155951659517595185951959520595215952259523595245952559526595275952859529595305953159532595335953459535595365953759538595395954059541595425954359544595455954659547595485954959550595515955259553595545955559556595575955859559595605956159562595635956459565595665956759568595695957059571595725957359574595755957659577595785957959580595815958259583595845958559586595875958859589595905959159592595935959459595595965959759598595995960059601596025960359604596055960659607596085960959610596115961259613596145961559616596175961859619596205962159622596235962459625596265962759628596295963059631596325963359634596355963659637596385963959640596415964259643596445964559646596475964859649596505965159652596535965459655596565965759658596595966059661596625966359664596655966659667596685966959670596715967259673596745967559676596775967859679596805968159682596835968459685596865968759688596895969059691596925969359694596955969659697596985969959700597015970259703597045970559706597075970859709597105971159712597135971459715597165971759718597195972059721597225972359724597255972659727597285972959730597315973259733597345973559736597375973859739597405974159742597435974459745597465974759748597495975059751597525975359754597555975659757597585975959760597615976259763597645976559766597675976859769597705977159772597735977459775597765977759778597795978059781597825978359784597855978659787597885978959790597915979259793597945979559796597975979859799598005980159802598035980459805598065980759808598095981059811598125981359814598155981659817598185981959820598215982259823598245982559826598275982859829598305983159832598335983459835598365983759838598395984059841598425984359844598455984659847598485984959850598515985259853598545985559856598575985859859598605986159862598635986459865598665986759868598695987059871598725987359874598755987659877598785987959880598815988259883598845988559886598875988859889598905989159892598935989459895598965989759898598995990059901599025990359904599055990659907599085990959910599115991259913599145991559916599175991859919599205992159922599235992459925599265992759928599295993059931599325993359934599355993659937599385993959940599415994259943599445994559946599475994859949599505995159952599535995459955599565995759958599595996059961599625996359964599655996659967599685996959970599715997259973599745997559976599775997859979599805998159982599835998459985599865998759988599895999059991599925999359994599955999659997599985999960000600016000260003600046000560006600076000860009600106001160012600136001460015600166001760018600196002060021600226002360024600256002660027600286002960030600316003260033600346003560036600376003860039600406004160042600436004460045600466004760048600496005060051600526005360054600556005660057600586005960060600616006260063600646006560066600676006860069600706007160072600736007460075600766007760078600796008060081600826008360084600856008660087600886008960090600916009260093600946009560096600976009860099601006010160102601036010460105601066010760108601096011060111601126011360114601156011660117601186011960120601216012260123601246012560126601276012860129601306013160132601336013460135601366013760138601396014060141601426014360144601456014660147601486014960150601516015260153601546015560156601576015860159601606016160162601636016460165601666016760168601696017060171601726017360174601756017660177601786017960180601816018260183601846018560186601876018860189601906019160192601936019460195601966019760198601996020060201602026020360204602056020660207602086020960210602116021260213602146021560216602176021860219602206022160222602236022460225602266022760228602296023060231602326023360234602356023660237602386023960240602416024260243602446024560246602476024860249602506025160252602536025460255602566025760258602596026060261602626026360264602656026660267602686026960270602716027260273602746027560276602776027860279602806028160282602836028460285602866028760288602896029060291602926029360294602956029660297602986029960300603016030260303603046030560306603076030860309603106031160312603136031460315603166031760318603196032060321603226032360324603256032660327603286032960330603316033260333603346033560336603376033860339603406034160342603436034460345603466034760348603496035060351603526035360354603556035660357603586035960360603616036260363603646036560366603676036860369603706037160372603736037460375603766037760378603796038060381603826038360384603856038660387603886038960390603916039260393603946039560396603976039860399604006040160402604036040460405604066040760408604096041060411604126041360414604156041660417604186041960420604216042260423604246042560426604276042860429604306043160432604336043460435604366043760438604396044060441604426044360444604456044660447604486044960450604516045260453604546045560456604576045860459604606046160462604636046460465604666046760468604696047060471604726047360474604756047660477604786047960480604816048260483604846048560486604876048860489604906049160492604936049460495604966049760498604996050060501605026050360504605056050660507605086050960510605116051260513605146051560516605176051860519605206052160522605236052460525605266052760528605296053060531605326053360534605356053660537605386053960540605416054260543605446054560546605476054860549605506055160552605536055460555605566055760558605596056060561605626056360564605656056660567605686056960570605716057260573605746057560576605776057860579605806058160582605836058460585605866058760588605896059060591605926059360594605956059660597605986059960600606016060260603606046060560606606076060860609606106061160612606136061460615606166061760618606196062060621606226062360624606256062660627606286062960630606316063260633606346063560636606376063860639606406064160642606436064460645606466064760648606496065060651606526065360654606556065660657606586065960660606616066260663606646066560666606676066860669606706067160672606736067460675606766067760678606796068060681606826068360684606856068660687606886068960690606916069260693606946069560696606976069860699607006070160702607036070460705607066070760708607096071060711607126071360714607156071660717607186071960720607216072260723607246072560726607276072860729607306073160732607336073460735607366073760738607396074060741607426074360744607456074660747607486074960750607516075260753607546075560756607576075860759607606076160762607636076460765607666076760768607696077060771607726077360774607756077660777607786077960780607816078260783607846078560786607876078860789607906079160792607936079460795607966079760798607996080060801608026080360804608056080660807608086080960810608116081260813608146081560816608176081860819608206082160822608236082460825608266082760828608296083060831608326083360834608356083660837608386083960840608416084260843608446084560846608476084860849608506085160852608536085460855608566085760858608596086060861608626086360864608656086660867608686086960870608716087260873608746087560876608776087860879608806088160882608836088460885608866088760888608896089060891608926089360894608956089660897608986089960900609016090260903609046090560906609076090860909609106091160912609136091460915609166091760918609196092060921609226092360924609256092660927609286092960930609316093260933609346093560936609376093860939609406094160942609436094460945609466094760948609496095060951609526095360954609556095660957609586095960960609616096260963609646096560966609676096860969609706097160972609736097460975609766097760978609796098060981609826098360984609856098660987609886098960990609916099260993609946099560996609976099860999610006100161002610036100461005610066100761008610096101061011610126101361014610156101661017610186101961020610216102261023610246102561026610276102861029610306103161032610336103461035610366103761038610396104061041610426104361044610456104661047610486104961050610516105261053610546105561056610576105861059610606106161062610636106461065610666106761068610696107061071610726107361074610756107661077610786107961080610816108261083610846108561086610876108861089610906109161092610936109461095610966109761098610996110061101611026110361104611056110661107611086110961110611116111261113611146111561116611176111861119611206112161122611236112461125611266112761128611296113061131611326113361134611356113661137611386113961140611416114261143611446114561146611476114861149611506115161152611536115461155611566115761158611596116061161611626116361164611656116661167611686116961170611716117261173611746117561176611776117861179611806118161182611836118461185611866118761188611896119061191611926119361194611956119661197611986119961200612016120261203612046120561206612076120861209612106121161212612136121461215612166121761218612196122061221612226122361224612256122661227612286122961230612316123261233612346123561236612376123861239612406124161242612436124461245612466124761248612496125061251612526125361254612556125661257612586125961260612616126261263612646126561266612676126861269612706127161272612736127461275612766127761278612796128061281612826128361284612856128661287612886128961290612916129261293612946129561296612976129861299613006130161302613036130461305613066130761308613096131061311613126131361314613156131661317613186131961320613216132261323613246132561326613276132861329613306133161332613336133461335613366133761338613396134061341613426134361344613456134661347613486134961350613516135261353613546135561356613576135861359613606136161362613636136461365613666136761368613696137061371613726137361374613756137661377613786137961380613816138261383613846138561386613876138861389613906139161392613936139461395613966139761398613996140061401614026140361404614056140661407614086140961410614116141261413614146141561416614176141861419614206142161422614236142461425614266142761428614296143061431614326143361434614356143661437614386143961440614416144261443614446144561446614476144861449614506145161452614536145461455614566145761458614596146061461614626146361464614656146661467614686146961470614716147261473614746147561476614776147861479614806148161482614836148461485614866148761488614896149061491614926149361494614956149661497614986149961500615016150261503615046150561506615076150861509615106151161512615136151461515615166151761518615196152061521615226152361524615256152661527615286152961530615316153261533615346153561536615376153861539615406154161542615436154461545615466154761548615496155061551615526155361554615556155661557615586155961560615616156261563615646156561566615676156861569615706157161572615736157461575615766157761578615796158061581615826158361584615856158661587615886158961590615916159261593615946159561596615976159861599616006160161602616036160461605616066160761608616096161061611616126161361614616156161661617616186161961620616216162261623616246162561626616276162861629616306163161632616336163461635616366163761638616396164061641616426164361644616456164661647616486164961650616516165261653616546165561656616576165861659616606166161662616636166461665616666166761668616696167061671616726167361674616756167661677616786167961680616816168261683616846168561686616876168861689616906169161692616936169461695616966169761698616996170061701617026170361704617056170661707617086170961710617116171261713617146171561716617176171861719617206172161722617236172461725617266172761728617296173061731617326173361734617356173661737617386173961740617416174261743617446174561746617476174861749617506175161752617536175461755617566175761758617596176061761617626176361764617656176661767617686176961770617716177261773617746177561776617776177861779617806178161782617836178461785617866178761788617896179061791617926179361794617956179661797617986179961800618016180261803618046180561806618076180861809618106181161812618136181461815618166181761818618196182061821618226182361824618256182661827618286182961830618316183261833618346183561836618376183861839618406184161842618436184461845618466184761848618496185061851618526185361854618556185661857618586185961860618616186261863618646186561866618676186861869618706187161872618736187461875618766187761878618796188061881618826188361884618856188661887618886188961890618916189261893618946189561896618976189861899619006190161902619036190461905619066190761908619096191061911619126191361914619156191661917619186191961920619216192261923619246192561926619276192861929619306193161932619336193461935619366193761938619396194061941619426194361944619456194661947619486194961950619516195261953619546195561956619576195861959619606196161962619636196461965619666196761968619696197061971619726197361974619756197661977619786197961980619816198261983619846198561986619876198861989619906199161992619936199461995619966199761998619996200062001620026200362004620056200662007620086200962010620116201262013620146201562016620176201862019620206202162022620236202462025620266202762028620296203062031620326203362034620356203662037620386203962040620416204262043620446204562046620476204862049620506205162052620536205462055620566205762058620596206062061620626206362064620656206662067620686206962070620716207262073620746207562076620776207862079620806208162082620836208462085620866208762088620896209062091620926209362094620956209662097620986209962100621016210262103621046210562106621076210862109621106211162112621136211462115621166211762118621196212062121621226212362124621256212662127621286212962130621316213262133621346213562136621376213862139621406214162142621436214462145621466214762148621496215062151621526215362154621556215662157621586215962160621616216262163621646216562166621676216862169621706217162172621736217462175621766217762178621796218062181621826218362184621856218662187621886218962190621916219262193621946219562196621976219862199622006220162202622036220462205622066220762208622096221062211622126221362214622156221662217622186221962220622216222262223622246222562226622276222862229622306223162232622336223462235622366223762238622396224062241622426224362244622456224662247622486224962250622516225262253622546225562256622576225862259622606226162262622636226462265622666226762268622696227062271622726227362274622756227662277622786227962280622816228262283622846228562286622876228862289622906229162292622936229462295622966229762298622996230062301623026230362304623056230662307623086230962310623116231262313623146231562316623176231862319623206232162322623236232462325623266232762328623296233062331623326233362334623356233662337623386233962340623416234262343623446234562346623476234862349623506235162352623536235462355623566235762358623596236062361623626236362364623656236662367623686236962370623716237262373623746237562376623776237862379623806238162382623836238462385623866238762388623896239062391623926239362394623956239662397623986239962400624016240262403624046240562406624076240862409624106241162412624136241462415624166241762418624196242062421624226242362424624256242662427624286242962430624316243262433624346243562436624376243862439624406244162442624436244462445624466244762448624496245062451624526245362454624556245662457624586245962460624616246262463624646246562466624676246862469624706247162472624736247462475624766247762478624796248062481624826248362484624856248662487624886248962490624916249262493624946249562496624976249862499625006250162502625036250462505625066250762508625096251062511625126251362514625156251662517625186251962520625216252262523625246252562526625276252862529625306253162532625336253462535625366253762538625396254062541625426254362544625456254662547625486254962550625516255262553625546255562556625576255862559625606256162562625636256462565625666256762568625696257062571625726257362574625756257662577625786257962580625816258262583625846258562586625876258862589625906259162592625936259462595625966259762598625996260062601626026260362604626056260662607626086260962610626116261262613626146261562616626176261862619626206262162622626236262462625626266262762628626296263062631626326263362634626356263662637626386263962640626416264262643626446264562646626476264862649626506265162652626536265462655626566265762658626596266062661626626266362664626656266662667626686266962670626716267262673626746267562676626776267862679626806268162682626836268462685626866268762688626896269062691626926269362694626956269662697626986269962700627016270262703627046270562706627076270862709627106271162712627136271462715627166271762718627196272062721627226272362724627256272662727627286272962730627316273262733627346273562736627376273862739627406274162742627436274462745627466274762748627496275062751627526275362754627556275662757627586275962760627616276262763627646276562766627676276862769627706277162772627736277462775627766277762778627796278062781627826278362784627856278662787627886278962790627916279262793627946279562796627976279862799628006280162802628036280462805628066280762808628096281062811628126281362814628156281662817628186281962820628216282262823628246282562826628276282862829628306283162832628336283462835628366283762838628396284062841628426284362844628456284662847628486284962850628516285262853628546285562856628576285862859628606286162862628636286462865628666286762868628696287062871628726287362874628756287662877628786287962880628816288262883628846288562886628876288862889628906289162892628936289462895628966289762898628996290062901629026290362904629056290662907629086290962910629116291262913629146291562916629176291862919629206292162922629236292462925629266292762928629296293062931629326293362934629356293662937629386293962940629416294262943629446294562946629476294862949629506295162952629536295462955629566295762958629596296062961629626296362964629656296662967629686296962970629716297262973629746297562976629776297862979629806298162982629836298462985629866298762988629896299062991629926299362994629956299662997629986299963000630016300263003630046300563006630076300863009630106301163012630136301463015630166301763018630196302063021630226302363024630256302663027630286302963030630316303263033630346303563036630376303863039630406304163042630436304463045630466304763048630496305063051630526305363054630556305663057630586305963060630616306263063630646306563066630676306863069630706307163072630736307463075630766307763078630796308063081630826308363084630856308663087630886308963090630916309263093630946309563096630976309863099631006310163102631036310463105631066310763108631096311063111631126311363114631156311663117631186311963120631216312263123631246312563126631276312863129631306313163132631336313463135631366313763138631396314063141631426314363144631456314663147631486314963150631516315263153631546315563156631576315863159631606316163162631636316463165631666316763168631696317063171631726317363174631756317663177631786317963180631816318263183631846318563186631876318863189631906319163192631936319463195631966319763198631996320063201632026320363204632056320663207632086320963210632116321263213632146321563216632176321863219632206322163222632236322463225632266322763228632296323063231632326323363234632356323663237632386323963240632416324263243632446324563246632476324863249632506325163252632536325463255632566325763258632596326063261632626326363264632656326663267632686326963270632716327263273632746327563276632776327863279632806328163282632836328463285632866328763288632896329063291632926329363294632956329663297632986329963300633016330263303633046330563306633076330863309633106331163312633136331463315633166331763318633196332063321633226332363324633256332663327633286332963330633316333263333633346333563336633376333863339633406334163342633436334463345633466334763348633496335063351633526335363354633556335663357633586335963360633616336263363633646336563366633676336863369633706337163372633736337463375633766337763378633796338063381633826338363384633856338663387633886338963390633916339263393633946339563396633976339863399634006340163402634036340463405634066340763408634096341063411634126341363414634156341663417634186341963420634216342263423634246342563426634276342863429634306343163432634336343463435634366343763438634396344063441634426344363444634456344663447634486344963450634516345263453634546345563456634576345863459634606346163462634636346463465634666346763468634696347063471634726347363474634756347663477634786347963480634816348263483634846348563486634876348863489634906349163492634936349463495634966349763498634996350063501635026350363504635056350663507635086350963510635116351263513635146351563516635176351863519635206352163522635236352463525635266352763528635296353063531635326353363534635356353663537635386353963540635416354263543635446354563546635476354863549635506355163552635536355463555635566355763558635596356063561635626356363564635656356663567635686356963570635716357263573635746357563576635776357863579635806358163582635836358463585635866358763588635896359063591635926359363594635956359663597635986359963600636016360263603636046360563606636076360863609636106361163612636136361463615636166361763618636196362063621636226362363624636256362663627636286362963630636316363263633636346363563636636376363863639636406364163642636436364463645636466364763648636496365063651636526365363654636556365663657636586365963660636616366263663636646366563666636676366863669636706367163672636736367463675636766367763678636796368063681636826368363684636856368663687636886368963690636916369263693636946369563696636976369863699637006370163702637036370463705637066370763708637096371063711637126371363714637156371663717637186371963720637216372263723637246372563726637276372863729637306373163732637336373463735637366373763738637396374063741637426374363744637456374663747637486374963750637516375263753637546375563756637576375863759637606376163762637636376463765637666376763768637696377063771637726377363774637756377663777637786377963780637816378263783637846378563786637876378863789637906379163792637936379463795637966379763798637996380063801638026380363804638056380663807638086380963810638116381263813638146381563816638176381863819638206382163822638236382463825638266382763828638296383063831638326383363834638356383663837638386383963840638416384263843638446384563846638476384863849638506385163852638536385463855638566385763858638596386063861638626386363864638656386663867638686386963870638716387263873638746387563876638776387863879638806388163882638836388463885638866388763888638896389063891638926389363894638956389663897638986389963900639016390263903639046390563906639076390863909639106391163912639136391463915639166391763918639196392063921639226392363924639256392663927639286392963930639316393263933639346393563936639376393863939639406394163942639436394463945639466394763948639496395063951639526395363954639556395663957639586395963960639616396263963639646396563966639676396863969639706397163972639736397463975639766397763978639796398063981639826398363984639856398663987639886398963990639916399263993639946399563996639976399863999640006400164002640036400464005640066400764008640096401064011640126401364014640156401664017640186401964020640216402264023640246402564026640276402864029640306403164032640336403464035640366403764038640396404064041640426404364044640456404664047640486404964050640516405264053640546405564056640576405864059640606406164062640636406464065640666406764068640696407064071640726407364074640756407664077640786407964080640816408264083640846408564086640876408864089640906409164092640936409464095640966409764098640996410064101641026410364104641056410664107641086410964110641116411264113641146411564116641176411864119641206412164122641236412464125641266412764128641296413064131641326413364134641356413664137641386413964140641416414264143641446414564146641476414864149641506415164152641536415464155641566415764158641596416064161641626416364164641656416664167641686416964170641716417264173641746417564176641776417864179641806418164182641836418464185641866418764188641896419064191641926419364194641956419664197641986419964200642016420264203642046420564206642076420864209642106421164212642136421464215642166421764218642196422064221642226422364224642256422664227642286422964230642316423264233642346423564236642376423864239642406424164242642436424464245642466424764248642496425064251642526425364254642556425664257642586425964260642616426264263642646426564266642676426864269642706427164272642736427464275642766427764278642796428064281642826428364284642856428664287642886428964290642916429264293642946429564296642976429864299643006430164302643036430464305643066430764308643096431064311643126431364314643156431664317643186431964320643216432264323643246432564326643276432864329643306433164332643336433464335643366433764338643396434064341643426434364344643456434664347643486434964350643516435264353643546435564356643576435864359643606436164362643636436464365643666436764368643696437064371643726437364374643756437664377643786437964380643816438264383643846438564386643876438864389643906439164392643936439464395643966439764398643996440064401644026440364404644056440664407644086440964410644116441264413644146441564416644176441864419644206442164422644236442464425644266442764428644296443064431644326443364434644356443664437644386443964440644416444264443644446444564446644476444864449644506445164452644536445464455644566445764458644596446064461644626446364464644656446664467644686446964470644716447264473644746447564476644776447864479644806448164482644836448464485644866448764488644896449064491644926449364494644956449664497644986449964500645016450264503645046450564506645076450864509645106451164512645136451464515645166451764518645196452064521645226452364524645256452664527645286452964530645316453264533645346453564536645376453864539645406454164542645436454464545645466454764548645496455064551645526455364554645556455664557645586455964560645616456264563645646456564566645676456864569645706457164572645736457464575645766457764578645796458064581645826458364584645856458664587645886458964590645916459264593645946459564596645976459864599646006460164602646036460464605646066460764608646096461064611646126461364614646156461664617646186461964620646216462264623646246462564626646276462864629646306463164632646336463464635646366463764638646396464064641646426464364644646456464664647646486464964650646516465264653646546465564656646576465864659646606466164662646636466464665646666466764668646696467064671646726467364674646756467664677646786467964680646816468264683646846468564686646876468864689646906469164692646936469464695646966469764698646996470064701647026470364704647056470664707647086470964710647116471264713647146471564716647176471864719647206472164722647236472464725647266472764728647296473064731647326473364734647356473664737647386473964740647416474264743647446474564746647476474864749647506475164752647536475464755647566475764758647596476064761647626476364764647656476664767647686476964770647716477264773647746477564776647776477864779647806478164782647836478464785647866478764788647896479064791647926479364794647956479664797647986479964800648016480264803648046480564806648076480864809648106481164812648136481464815648166481764818648196482064821648226482364824648256482664827648286482964830648316483264833648346483564836648376483864839648406484164842648436484464845648466484764848648496485064851648526485364854648556485664857648586485964860648616486264863648646486564866648676486864869648706487164872648736487464875648766487764878648796488064881648826488364884648856488664887648886488964890648916489264893648946489564896648976489864899649006490164902649036490464905649066490764908649096491064911649126491364914649156491664917649186491964920649216492264923649246492564926649276492864929649306493164932649336493464935649366493764938649396494064941649426494364944649456494664947649486494964950649516495264953649546495564956649576495864959649606496164962649636496464965649666496764968649696497064971649726497364974649756497664977649786497964980649816498264983649846498564986649876498864989649906499164992649936499464995649966499764998649996500065001650026500365004650056500665007650086500965010650116501265013650146501565016650176501865019650206502165022650236502465025650266502765028650296503065031650326503365034650356503665037650386503965040650416504265043650446504565046650476504865049650506505165052650536505465055650566505765058650596506065061650626506365064650656506665067650686506965070650716507265073650746507565076650776507865079650806508165082650836508465085650866508765088650896509065091650926509365094650956509665097650986509965100651016510265103651046510565106651076510865109651106511165112651136511465115651166511765118651196512065121651226512365124651256512665127651286512965130651316513265133651346513565136651376513865139651406514165142651436514465145651466514765148651496515065151651526515365154651556515665157651586515965160651616516265163651646516565166651676516865169651706517165172651736517465175651766517765178651796518065181651826518365184651856518665187651886518965190651916519265193651946519565196651976519865199652006520165202652036520465205652066520765208652096521065211652126521365214652156521665217652186521965220652216522265223652246522565226652276522865229652306523165232652336523465235652366523765238652396524065241652426524365244652456524665247652486524965250652516525265253652546525565256652576525865259652606526165262652636526465265652666526765268652696527065271652726527365274652756527665277652786527965280652816528265283652846528565286652876528865289652906529165292652936529465295652966529765298652996530065301653026530365304653056530665307653086530965310653116531265313653146531565316653176531865319653206532165322653236532465325653266532765328653296533065331653326533365334653356533665337653386533965340653416534265343653446534565346653476534865349653506535165352653536535465355653566535765358653596536065361653626536365364653656536665367653686536965370653716537265373653746537565376653776537865379653806538165382653836538465385653866538765388653896539065391653926539365394653956539665397653986539965400654016540265403654046540565406654076540865409654106541165412654136541465415654166541765418654196542065421654226542365424654256542665427654286542965430654316543265433654346543565436654376543865439654406544165442654436544465445654466544765448654496545065451654526545365454654556545665457654586545965460654616546265463654646546565466654676546865469654706547165472654736547465475654766547765478654796548065481654826548365484654856548665487654886548965490654916549265493654946549565496654976549865499655006550165502655036550465505655066550765508655096551065511655126551365514655156551665517655186551965520655216552265523655246552565526655276552865529655306553165532655336553465535655366553765538655396554065541655426554365544655456554665547655486554965550655516555265553655546555565556655576555865559655606556165562655636556465565655666556765568655696557065571655726557365574655756557665577655786557965580655816558265583655846558565586655876558865589655906559165592655936559465595655966559765598655996560065601656026560365604656056560665607656086560965610656116561265613656146561565616656176561865619656206562165622656236562465625656266562765628656296563065631656326563365634656356563665637656386563965640656416564265643656446564565646656476564865649656506565165652656536565465655656566565765658656596566065661656626566365664656656566665667656686566965670656716567265673656746567565676656776567865679656806568165682656836568465685656866568765688656896569065691656926569365694656956569665697656986569965700657016570265703657046570565706657076570865709657106571165712657136571465715657166571765718657196572065721657226572365724657256572665727657286572965730657316573265733657346573565736657376573865739657406574165742657436574465745657466574765748657496575065751657526575365754657556575665757657586575965760657616576265763657646576565766657676576865769657706577165772657736577465775657766577765778657796578065781657826578365784657856578665787657886578965790657916579265793657946579565796657976579865799658006580165802658036580465805658066580765808658096581065811658126581365814658156581665817658186581965820658216582265823658246582565826658276582865829658306583165832658336583465835658366583765838658396584065841658426584365844658456584665847658486584965850658516585265853658546585565856658576585865859658606586165862658636586465865658666586765868658696587065871658726587365874658756587665877658786587965880658816588265883658846588565886658876588865889658906589165892658936589465895658966589765898658996590065901659026590365904659056590665907659086590965910659116591265913659146591565916659176591865919659206592165922659236592465925659266592765928659296593065931659326593365934659356593665937659386593965940659416594265943659446594565946659476594865949659506595165952659536595465955659566595765958659596596065961659626596365964659656596665967659686596965970659716597265973659746597565976659776597865979659806598165982659836598465985659866598765988659896599065991659926599365994659956599665997659986599966000660016600266003660046600566006660076600866009660106601166012660136601466015660166601766018660196602066021660226602366024660256602666027660286602966030660316603266033660346603566036660376603866039660406604166042660436604466045660466604766048660496605066051660526605366054660556605666057660586605966060660616606266063660646606566066660676606866069660706607166072660736607466075660766607766078660796608066081660826608366084660856608666087660886608966090660916609266093660946609566096660976609866099661006610166102661036610466105661066610766108661096611066111661126611366114661156611666117661186611966120661216612266123661246612566126661276612866129661306613166132661336613466135661366613766138661396614066141661426614366144661456614666147661486614966150661516615266153661546615566156661576615866159661606616166162661636616466165661666616766168661696617066171661726617366174661756617666177661786617966180661816618266183661846618566186661876618866189661906619166192661936619466195661966619766198661996620066201662026620366204662056620666207662086620966210662116621266213662146621566216662176621866219662206622166222662236622466225662266622766228662296623066231662326623366234662356623666237662386623966240662416624266243662446624566246662476624866249662506625166252662536625466255662566625766258662596626066261662626626366264662656626666267662686626966270662716627266273662746627566276662776627866279662806628166282662836628466285662866628766288662896629066291662926629366294662956629666297662986629966300663016630266303663046630566306663076630866309663106631166312663136631466315663166631766318663196632066321663226632366324663256632666327663286632966330663316633266333663346633566336663376633866339663406634166342663436634466345663466634766348663496635066351663526635366354663556635666357663586635966360663616636266363663646636566366663676636866369663706637166372663736637466375663766637766378663796638066381663826638366384663856638666387663886638966390663916639266393663946639566396663976639866399664006640166402664036640466405664066640766408664096641066411664126641366414664156641666417664186641966420664216642266423664246642566426664276642866429664306643166432664336643466435664366643766438664396644066441664426644366444664456644666447664486644966450664516645266453664546645566456664576645866459664606646166462664636646466465664666646766468664696647066471664726647366474664756647666477664786647966480664816648266483664846648566486664876648866489664906649166492664936649466495664966649766498664996650066501665026650366504665056650666507665086650966510665116651266513665146651566516665176651866519665206652166522665236652466525665266652766528665296653066531665326653366534665356653666537665386653966540665416654266543665446654566546665476654866549665506655166552665536655466555665566655766558665596656066561665626656366564665656656666567665686656966570665716657266573665746657566576665776657866579665806658166582665836658466585665866658766588665896659066591665926659366594665956659666597665986659966600666016660266603666046660566606666076660866609666106661166612666136661466615666166661766618666196662066621666226662366624666256662666627666286662966630666316663266633666346663566636666376663866639666406664166642666436664466645666466664766648666496665066651666526665366654666556665666657666586665966660666616666266663666646666566666666676666866669666706667166672666736667466675666766667766678666796668066681666826668366684666856668666687666886668966690666916669266693666946669566696666976669866699667006670166702667036670466705667066670766708667096671066711667126671366714667156671666717667186671966720667216672266723667246672566726667276672866729667306673166732667336673466735667366673766738667396674066741667426674366744667456674666747667486674966750667516675266753667546675566756667576675866759667606676166762667636676466765667666676766768667696677066771667726677366774667756677666777667786677966780667816678266783667846678566786667876678866789667906679166792667936679466795667966679766798667996680066801668026680366804668056680666807668086680966810668116681266813668146681566816668176681866819668206682166822668236682466825668266682766828668296683066831668326683366834668356683666837668386683966840668416684266843668446684566846668476684866849668506685166852668536685466855668566685766858668596686066861668626686366864668656686666867668686686966870668716687266873668746687566876668776687866879668806688166882668836688466885668866688766888668896689066891668926689366894668956689666897668986689966900669016690266903669046690566906669076690866909669106691166912669136691466915669166691766918669196692066921669226692366924669256692666927669286692966930669316693266933669346693566936669376693866939669406694166942669436694466945669466694766948669496695066951669526695366954669556695666957669586695966960669616696266963669646696566966669676696866969669706697166972669736697466975669766697766978669796698066981669826698366984669856698666987669886698966990669916699266993669946699566996669976699866999670006700167002670036700467005670066700767008670096701067011670126701367014670156701667017670186701967020670216702267023670246702567026670276702867029670306703167032670336703467035670366703767038670396704067041670426704367044670456704667047670486704967050670516705267053670546705567056670576705867059670606706167062670636706467065670666706767068670696707067071670726707367074670756707667077670786707967080670816708267083670846708567086670876708867089670906709167092670936709467095670966709767098670996710067101671026710367104671056710667107671086710967110671116711267113671146711567116671176711867119671206712167122671236712467125671266712767128671296713067131671326713367134671356713667137671386713967140671416714267143671446714567146671476714867149671506715167152671536715467155671566715767158671596716067161671626716367164671656716667167671686716967170671716717267173671746717567176671776717867179671806718167182671836718467185671866718767188671896719067191671926719367194671956719667197671986719967200672016720267203672046720567206672076720867209672106721167212672136721467215672166721767218672196722067221672226722367224672256722667227672286722967230672316723267233672346723567236672376723867239672406724167242672436724467245672466724767248672496725067251672526725367254672556725667257672586725967260672616726267263672646726567266672676726867269672706727167272672736727467275672766727767278672796728067281672826728367284672856728667287672886728967290672916729267293672946729567296672976729867299673006730167302673036730467305673066730767308673096731067311673126731367314673156731667317673186731967320673216732267323673246732567326673276732867329673306733167332673336733467335673366733767338673396734067341673426734367344673456734667347673486734967350673516735267353673546735567356673576735867359673606736167362673636736467365673666736767368673696737067371673726737367374673756737667377673786737967380673816738267383673846738567386673876738867389673906739167392673936739467395673966739767398673996740067401674026740367404674056740667407674086740967410674116741267413674146741567416674176741867419674206742167422674236742467425674266742767428674296743067431674326743367434674356743667437674386743967440674416744267443674446744567446674476744867449674506745167452674536745467455674566745767458674596746067461674626746367464674656746667467674686746967470674716747267473674746747567476674776747867479674806748167482674836748467485674866748767488674896749067491674926749367494674956749667497674986749967500675016750267503675046750567506675076750867509675106751167512675136751467515675166751767518675196752067521675226752367524675256752667527675286752967530675316753267533675346753567536675376753867539675406754167542675436754467545675466754767548675496755067551675526755367554675556755667557675586755967560675616756267563675646756567566675676756867569675706757167572675736757467575675766757767578675796758067581675826758367584675856758667587675886758967590675916759267593675946759567596675976759867599676006760167602676036760467605676066760767608676096761067611676126761367614676156761667617676186761967620676216762267623676246762567626676276762867629676306763167632676336763467635676366763767638676396764067641676426764367644676456764667647676486764967650676516765267653676546765567656676576765867659676606766167662676636766467665676666766767668676696767067671676726767367674676756767667677676786767967680676816768267683676846768567686676876768867689676906769167692676936769467695676966769767698676996770067701677026770367704677056770667707677086770967710677116771267713677146771567716677176771867719677206772167722677236772467725677266772767728677296773067731677326773367734677356773667737677386773967740677416774267743677446774567746677476774867749677506775167752677536775467755677566775767758677596776067761677626776367764677656776667767677686776967770677716777267773677746777567776677776777867779677806778167782677836778467785677866778767788677896779067791677926779367794677956779667797677986779967800678016780267803678046780567806678076780867809678106781167812678136781467815678166781767818678196782067821678226782367824678256782667827678286782967830678316783267833678346783567836678376783867839678406784167842678436784467845678466784767848678496785067851678526785367854678556785667857678586785967860678616786267863678646786567866678676786867869678706787167872678736787467875678766787767878678796788067881678826788367884678856788667887678886788967890678916789267893678946789567896678976789867899679006790167902679036790467905679066790767908679096791067911679126791367914679156791667917679186791967920679216792267923679246792567926679276792867929679306793167932679336793467935679366793767938679396794067941679426794367944679456794667947679486794967950679516795267953679546795567956679576795867959679606796167962679636796467965679666796767968679696797067971679726797367974679756797667977679786797967980679816798267983679846798567986679876798867989679906799167992679936799467995679966799767998679996800068001680026800368004680056800668007680086800968010680116801268013680146801568016680176801868019680206802168022680236802468025680266802768028680296803068031680326803368034680356803668037680386803968040680416804268043680446804568046680476804868049680506805168052680536805468055680566805768058680596806068061680626806368064680656806668067680686806968070680716807268073680746807568076680776807868079680806808168082680836808468085680866808768088680896809068091680926809368094680956809668097680986809968100681016810268103681046810568106681076810868109681106811168112681136811468115681166811768118681196812068121681226812368124681256812668127681286812968130681316813268133681346813568136681376813868139681406814168142681436814468145681466814768148681496815068151681526815368154681556815668157681586815968160681616816268163681646816568166681676816868169681706817168172681736817468175681766817768178681796818068181681826818368184681856818668187681886818968190681916819268193681946819568196681976819868199682006820168202682036820468205682066820768208682096821068211682126821368214682156821668217682186821968220682216822268223682246822568226682276822868229682306823168232682336823468235682366823768238682396824068241682426824368244682456824668247682486824968250682516825268253682546825568256682576825868259682606826168262682636826468265682666826768268682696827068271682726827368274682756827668277682786827968280682816828268283682846828568286682876828868289682906829168292682936829468295682966829768298682996830068301683026830368304683056830668307683086830968310683116831268313683146831568316683176831868319683206832168322683236832468325683266832768328683296833068331683326833368334683356833668337683386833968340683416834268343683446834568346683476834868349683506835168352683536835468355683566835768358683596836068361683626836368364683656836668367683686836968370683716837268373683746837568376683776837868379683806838168382683836838468385683866838768388683896839068391683926839368394683956839668397683986839968400684016840268403684046840568406684076840868409684106841168412684136841468415684166841768418684196842068421684226842368424684256842668427684286842968430684316843268433684346843568436684376843868439684406844168442684436844468445684466844768448684496845068451684526845368454684556845668457684586845968460684616846268463684646846568466684676846868469684706847168472684736847468475684766847768478684796848068481684826848368484684856848668487684886848968490684916849268493684946849568496684976849868499685006850168502685036850468505685066850768508685096851068511685126851368514685156851668517685186851968520685216852268523685246852568526685276852868529685306853168532685336853468535685366853768538685396854068541685426854368544685456854668547685486854968550685516855268553685546855568556685576855868559685606856168562685636856468565685666856768568685696857068571685726857368574685756857668577685786857968580685816858268583685846858568586685876858868589685906859168592685936859468595685966859768598685996860068601686026860368604686056860668607686086860968610686116861268613686146861568616686176861868619686206862168622686236862468625686266862768628686296863068631686326863368634686356863668637686386863968640686416864268643686446864568646686476864868649686506865168652686536865468655686566865768658686596866068661686626866368664686656866668667686686866968670686716867268673686746867568676686776867868679686806868168682686836868468685686866868768688686896869068691686926869368694686956869668697686986869968700687016870268703687046870568706687076870868709687106871168712687136871468715687166871768718687196872068721687226872368724687256872668727687286872968730687316873268733687346873568736687376873868739687406874168742687436874468745687466874768748687496875068751687526875368754687556875668757687586875968760687616876268763687646876568766687676876868769687706877168772687736877468775687766877768778687796878068781687826878368784687856878668787687886878968790687916879268793687946879568796687976879868799688006880168802688036880468805688066880768808688096881068811688126881368814688156881668817688186881968820688216882268823688246882568826688276882868829688306883168832688336883468835688366883768838688396884068841688426884368844688456884668847688486884968850688516885268853688546885568856688576885868859688606886168862688636886468865688666886768868688696887068871688726887368874688756887668877688786887968880688816888268883688846888568886688876888868889688906889168892688936889468895688966889768898688996890068901689026890368904689056890668907689086890968910689116891268913689146891568916689176891868919689206892168922689236892468925689266892768928689296893068931689326893368934689356893668937689386893968940689416894268943689446894568946689476894868949689506895168952689536895468955689566895768958689596896068961689626896368964689656896668967689686896968970689716897268973689746897568976689776897868979689806898168982689836898468985689866898768988689896899068991689926899368994689956899668997689986899969000690016900269003690046900569006690076900869009690106901169012690136901469015690166901769018690196902069021690226902369024690256902669027690286902969030690316903269033690346903569036690376903869039690406904169042690436904469045690466904769048690496905069051690526905369054690556905669057690586905969060690616906269063690646906569066690676906869069690706907169072690736907469075690766907769078690796908069081690826908369084690856908669087690886908969090690916909269093690946909569096690976909869099691006910169102691036910469105691066910769108691096911069111691126911369114691156911669117691186911969120691216912269123691246912569126691276912869129691306913169132691336913469135691366913769138691396914069141691426914369144691456914669147691486914969150691516915269153691546915569156691576915869159691606916169162691636916469165691666916769168691696917069171691726917369174691756917669177691786917969180691816918269183691846918569186691876918869189691906919169192691936919469195691966919769198691996920069201692026920369204692056920669207692086920969210692116921269213692146921569216692176921869219692206922169222692236922469225692266922769228692296923069231692326923369234692356923669237692386923969240692416924269243692446924569246692476924869249692506925169252692536925469255692566925769258692596926069261692626926369264692656926669267692686926969270692716927269273692746927569276692776927869279692806928169282692836928469285692866928769288692896929069291692926929369294692956929669297692986929969300693016930269303693046930569306693076930869309693106931169312693136931469315693166931769318693196932069321693226932369324693256932669327693286932969330693316933269333693346933569336693376933869339693406934169342693436934469345693466934769348693496935069351693526935369354693556935669357693586935969360693616936269363693646936569366693676936869369693706937169372693736937469375693766937769378693796938069381693826938369384693856938669387693886938969390693916939269393693946939569396693976939869399694006940169402694036940469405694066940769408694096941069411694126941369414694156941669417694186941969420694216942269423694246942569426694276942869429694306943169432694336943469435694366943769438694396944069441694426944369444694456944669447694486944969450694516945269453694546945569456694576945869459694606946169462694636946469465694666946769468694696947069471694726947369474694756947669477694786947969480694816948269483694846948569486694876948869489694906949169492694936949469495694966949769498694996950069501695026950369504695056950669507695086950969510695116951269513695146951569516695176951869519695206952169522695236952469525695266952769528695296953069531695326953369534695356953669537695386953969540695416954269543695446954569546695476954869549695506955169552695536955469555695566955769558695596956069561695626956369564695656956669567695686956969570695716957269573695746957569576695776957869579695806958169582695836958469585695866958769588695896959069591695926959369594695956959669597695986959969600696016960269603696046960569606696076960869609696106961169612696136961469615696166961769618696196962069621696226962369624696256962669627696286962969630696316963269633696346963569636696376963869639696406964169642696436964469645696466964769648696496965069651696526965369654696556965669657696586965969660696616966269663696646966569666696676966869669696706967169672696736967469675696766967769678696796968069681696826968369684696856968669687696886968969690696916969269693696946969569696696976969869699697006970169702697036970469705697066970769708697096971069711697126971369714697156971669717697186971969720697216972269723697246972569726697276972869729697306973169732697336973469735697366973769738697396974069741697426974369744697456974669747697486974969750697516975269753697546975569756697576975869759697606976169762697636976469765697666976769768697696977069771697726977369774697756977669777697786977969780697816978269783697846978569786697876978869789697906979169792697936979469795697966979769798697996980069801698026980369804698056980669807698086980969810698116981269813698146981569816698176981869819698206982169822698236982469825698266982769828698296983069831698326983369834698356983669837698386983969840698416984269843698446984569846698476984869849698506985169852698536985469855698566985769858698596986069861698626986369864698656986669867698686986969870698716987269873698746987569876698776987869879698806988169882698836988469885698866988769888698896989069891698926989369894698956989669897698986989969900699016990269903699046990569906699076990869909699106991169912699136991469915699166991769918699196992069921699226992369924699256992669927699286992969930699316993269933699346993569936699376993869939699406994169942699436994469945699466994769948699496995069951699526995369954699556995669957699586995969960699616996269963699646996569966699676996869969699706997169972699736997469975699766997769978699796998069981699826998369984699856998669987699886998969990699916999269993699946999569996699976999869999700007000170002700037000470005700067000770008700097001070011700127001370014700157001670017700187001970020700217002270023700247002570026700277002870029700307003170032700337003470035700367003770038700397004070041700427004370044700457004670047700487004970050700517005270053700547005570056700577005870059700607006170062700637006470065700667006770068700697007070071700727007370074700757007670077700787007970080700817008270083700847008570086700877008870089700907009170092700937009470095700967009770098700997010070101701027010370104701057010670107701087010970110701117011270113701147011570116701177011870119701207012170122701237012470125701267012770128701297013070131701327013370134701357013670137701387013970140701417014270143701447014570146701477014870149701507015170152701537015470155701567015770158701597016070161701627016370164701657016670167701687016970170701717017270173701747017570176701777017870179701807018170182701837018470185701867018770188701897019070191701927019370194701957019670197701987019970200702017020270203702047020570206702077020870209702107021170212702137021470215702167021770218702197022070221702227022370224702257022670227702287022970230702317023270233702347023570236702377023870239702407024170242702437024470245702467024770248702497025070251702527025370254702557025670257702587025970260702617026270263702647026570266702677026870269702707027170272702737027470275702767027770278702797028070281702827028370284702857028670287702887028970290702917029270293702947029570296702977029870299703007030170302703037030470305703067030770308703097031070311703127031370314703157031670317703187031970320703217032270323703247032570326703277032870329703307033170332703337033470335703367033770338703397034070341703427034370344703457034670347703487034970350703517035270353703547035570356703577035870359703607036170362703637036470365703667036770368703697037070371703727037370374703757037670377703787037970380703817038270383703847038570386703877038870389703907039170392703937039470395703967039770398703997040070401704027040370404704057040670407704087040970410704117041270413704147041570416704177041870419704207042170422704237042470425704267042770428704297043070431704327043370434704357043670437704387043970440704417044270443704447044570446704477044870449704507045170452704537045470455704567045770458704597046070461704627046370464704657046670467704687046970470704717047270473704747047570476704777047870479704807048170482704837048470485704867048770488704897049070491704927049370494704957049670497704987049970500705017050270503705047050570506705077050870509705107051170512705137051470515705167051770518705197052070521705227052370524705257052670527705287052970530705317053270533705347053570536705377053870539705407054170542705437054470545705467054770548705497055070551705527055370554705557055670557705587055970560705617056270563705647056570566705677056870569705707057170572705737057470575705767057770578705797058070581705827058370584705857058670587705887058970590705917059270593705947059570596705977059870599706007060170602706037060470605706067060770608706097061070611706127061370614706157061670617706187061970620706217062270623706247062570626706277062870629706307063170632706337063470635706367063770638706397064070641706427064370644706457064670647706487064970650706517065270653706547065570656706577065870659706607066170662706637066470665706667066770668706697067070671706727067370674706757067670677706787067970680706817068270683706847068570686706877068870689706907069170692706937069470695706967069770698706997070070701707027070370704707057070670707707087070970710707117071270713707147071570716707177071870719707207072170722707237072470725707267072770728707297073070731707327073370734707357073670737707387073970740707417074270743707447074570746707477074870749707507075170752707537075470755707567075770758707597076070761707627076370764707657076670767707687076970770707717077270773707747077570776707777077870779707807078170782707837078470785707867078770788707897079070791707927079370794707957079670797707987079970800708017080270803708047080570806708077080870809708107081170812708137081470815708167081770818708197082070821708227082370824708257082670827708287082970830708317083270833708347083570836708377083870839708407084170842708437084470845708467084770848708497085070851708527085370854708557085670857708587085970860708617086270863708647086570866708677086870869708707087170872708737087470875708767087770878708797088070881708827088370884708857088670887708887088970890708917089270893708947089570896708977089870899709007090170902709037090470905709067090770908709097091070911709127091370914709157091670917709187091970920709217092270923709247092570926709277092870929709307093170932709337093470935709367093770938709397094070941709427094370944709457094670947709487094970950709517095270953709547095570956709577095870959709607096170962709637096470965709667096770968709697097070971709727097370974709757097670977709787097970980709817098270983709847098570986709877098870989709907099170992709937099470995709967099770998709997100071001710027100371004710057100671007710087100971010710117101271013710147101571016710177101871019710207102171022710237102471025710267102771028710297103071031710327103371034710357103671037710387103971040710417104271043710447104571046710477104871049710507105171052710537105471055710567105771058710597106071061710627106371064710657106671067710687106971070710717107271073710747107571076710777107871079710807108171082710837108471085710867108771088710897109071091710927109371094710957109671097710987109971100711017110271103711047110571106711077110871109711107111171112711137111471115711167111771118711197112071121711227112371124711257112671127711287112971130711317113271133711347113571136711377113871139711407114171142711437114471145711467114771148711497115071151711527115371154711557115671157711587115971160711617116271163711647116571166711677116871169711707117171172711737117471175711767117771178711797118071181711827118371184711857118671187711887118971190711917119271193711947119571196711977119871199712007120171202712037120471205712067120771208712097121071211712127121371214712157121671217712187121971220712217122271223712247122571226712277122871229712307123171232712337123471235712367123771238712397124071241712427124371244712457124671247712487124971250712517125271253712547125571256712577125871259712607126171262712637126471265712667126771268712697127071271712727127371274712757127671277712787127971280712817128271283712847128571286712877128871289712907129171292712937129471295712967129771298712997130071301713027130371304713057130671307713087130971310713117131271313713147131571316713177131871319713207132171322713237132471325713267132771328713297133071331713327133371334713357133671337713387133971340713417134271343713447134571346713477134871349713507135171352713537135471355713567135771358713597136071361713627136371364713657136671367713687136971370713717137271373713747137571376713777137871379713807138171382713837138471385713867138771388713897139071391713927139371394713957139671397713987139971400714017140271403714047140571406714077140871409714107141171412714137141471415714167141771418714197142071421714227142371424714257142671427714287142971430714317143271433714347143571436714377143871439714407144171442714437144471445714467144771448714497145071451714527145371454714557145671457714587145971460714617146271463714647146571466714677146871469714707147171472714737147471475714767147771478714797148071481714827148371484714857148671487714887148971490714917149271493714947149571496714977149871499715007150171502715037150471505715067150771508715097151071511715127151371514715157151671517715187151971520715217152271523715247152571526715277152871529715307153171532715337153471535715367153771538715397154071541715427154371544715457154671547715487154971550715517155271553715547155571556715577155871559715607156171562715637156471565715667156771568715697157071571715727157371574715757157671577715787157971580715817158271583715847158571586715877158871589715907159171592715937159471595715967159771598715997160071601716027160371604716057160671607716087160971610716117161271613716147161571616716177161871619716207162171622716237162471625716267162771628716297163071631716327163371634716357163671637716387163971640716417164271643716447164571646716477164871649716507165171652716537165471655716567165771658716597166071661716627166371664716657166671667716687166971670716717167271673716747167571676716777167871679716807168171682716837168471685716867168771688716897169071691716927169371694716957169671697716987169971700717017170271703717047170571706717077170871709717107171171712717137171471715717167171771718717197172071721717227172371724717257172671727717287172971730717317173271733717347173571736717377173871739717407174171742717437174471745717467174771748717497175071751717527175371754717557175671757717587175971760717617176271763717647176571766717677176871769717707177171772717737177471775717767177771778717797178071781717827178371784717857178671787717887178971790717917179271793717947179571796717977179871799718007180171802718037180471805718067180771808718097181071811718127181371814718157181671817718187181971820718217182271823718247182571826718277182871829718307183171832718337183471835718367183771838718397184071841718427184371844718457184671847718487184971850718517185271853718547185571856718577185871859718607186171862718637186471865718667186771868718697187071871718727187371874718757187671877718787187971880718817188271883718847188571886718877188871889718907189171892718937189471895718967189771898718997190071901719027190371904719057190671907719087190971910719117191271913719147191571916719177191871919719207192171922719237192471925719267192771928719297193071931719327193371934719357193671937719387193971940719417194271943719447194571946719477194871949719507195171952719537195471955719567195771958719597196071961719627196371964719657196671967719687196971970719717197271973719747197571976719777197871979719807198171982719837198471985719867198771988719897199071991719927199371994719957199671997719987199972000720017200272003720047200572006720077200872009720107201172012720137201472015720167201772018720197202072021720227202372024720257202672027720287202972030720317203272033720347203572036720377203872039720407204172042720437204472045720467204772048720497205072051720527205372054720557205672057720587205972060720617206272063720647206572066720677206872069720707207172072720737207472075720767207772078720797208072081720827208372084720857208672087720887208972090720917209272093720947209572096720977209872099721007210172102721037210472105721067210772108721097211072111721127211372114721157211672117721187211972120721217212272123721247212572126721277212872129721307213172132721337213472135721367213772138721397214072141721427214372144721457214672147721487214972150721517215272153721547215572156721577215872159721607216172162721637216472165721667216772168721697217072171721727217372174721757217672177721787217972180721817218272183721847218572186721877218872189721907219172192721937219472195721967219772198721997220072201722027220372204722057220672207722087220972210722117221272213722147221572216722177221872219722207222172222722237222472225722267222772228722297223072231722327223372234722357223672237722387223972240722417224272243722447224572246722477224872249722507225172252722537225472255722567225772258722597226072261722627226372264722657226672267722687226972270722717227272273722747227572276722777227872279722807228172282722837228472285722867228772288722897229072291722927229372294722957229672297722987229972300723017230272303723047230572306723077230872309723107231172312723137231472315723167231772318723197232072321723227232372324723257232672327723287232972330723317233272333723347233572336723377233872339723407234172342723437234472345723467234772348723497235072351723527235372354723557235672357723587235972360723617236272363723647236572366723677236872369723707237172372723737237472375723767237772378723797238072381723827238372384723857238672387723887238972390723917239272393723947239572396723977239872399724007240172402724037240472405724067240772408724097241072411724127241372414724157241672417724187241972420724217242272423724247242572426724277242872429724307243172432724337243472435724367243772438724397244072441724427244372444724457244672447724487244972450724517245272453724547245572456724577245872459724607246172462724637246472465724667246772468724697247072471724727247372474724757247672477724787247972480724817248272483724847248572486724877248872489724907249172492724937249472495724967249772498724997250072501725027250372504725057250672507725087250972510725117251272513725147251572516725177251872519725207252172522725237252472525725267252772528725297253072531725327253372534725357253672537725387253972540725417254272543725447254572546725477254872549725507255172552725537255472555725567255772558725597256072561725627256372564725657256672567725687256972570725717257272573725747257572576725777257872579725807258172582725837258472585725867258772588725897259072591725927259372594725957259672597725987259972600726017260272603726047260572606726077260872609726107261172612726137261472615726167261772618726197262072621726227262372624726257262672627726287262972630726317263272633726347263572636726377263872639726407264172642726437264472645726467264772648726497265072651726527265372654726557265672657726587265972660726617266272663726647266572666726677266872669726707267172672726737267472675726767267772678726797268072681726827268372684726857268672687726887268972690726917269272693726947269572696726977269872699727007270172702727037270472705727067270772708727097271072711727127271372714727157271672717727187271972720727217272272723727247272572726727277272872729727307273172732727337273472735727367273772738727397274072741727427274372744727457274672747727487274972750727517275272753727547275572756727577275872759727607276172762727637276472765727667276772768727697277072771727727277372774727757277672777727787277972780727817278272783727847278572786727877278872789727907279172792727937279472795727967279772798727997280072801728027280372804728057280672807728087280972810728117281272813728147281572816728177281872819728207282172822728237282472825728267282772828728297283072831728327283372834728357283672837728387283972840728417284272843728447284572846728477284872849728507285172852728537285472855728567285772858728597286072861728627286372864728657286672867728687286972870728717287272873728747287572876728777287872879728807288172882728837288472885728867288772888728897289072891728927289372894728957289672897728987289972900729017290272903729047290572906729077290872909729107291172912729137291472915729167291772918729197292072921729227292372924729257292672927729287292972930729317293272933729347293572936729377293872939729407294172942729437294472945729467294772948729497295072951729527295372954729557295672957729587295972960729617296272963729647296572966729677296872969729707297172972729737297472975729767297772978729797298072981729827298372984729857298672987729887298972990729917299272993729947299572996729977299872999730007300173002730037300473005730067300773008730097301073011730127301373014730157301673017730187301973020730217302273023730247302573026730277302873029730307303173032730337303473035730367303773038730397304073041730427304373044730457304673047730487304973050730517305273053730547305573056730577305873059730607306173062730637306473065730667306773068730697307073071730727307373074730757307673077730787307973080730817308273083730847308573086730877308873089730907309173092730937309473095730967309773098730997310073101731027310373104731057310673107731087310973110731117311273113731147311573116731177311873119731207312173122731237312473125731267312773128731297313073131731327313373134731357313673137731387313973140731417314273143731447314573146731477314873149731507315173152731537315473155731567315773158731597316073161731627316373164731657316673167731687316973170731717317273173731747317573176731777317873179731807318173182731837318473185731867318773188731897319073191731927319373194731957319673197731987319973200732017320273203732047320573206732077320873209732107321173212732137321473215732167321773218732197322073221732227322373224732257322673227732287322973230732317323273233732347323573236732377323873239732407324173242732437324473245732467324773248732497325073251732527325373254732557325673257732587325973260732617326273263732647326573266732677326873269732707327173272732737327473275732767327773278732797328073281732827328373284732857328673287732887328973290732917329273293732947329573296732977329873299733007330173302733037330473305733067330773308733097331073311733127331373314733157331673317733187331973320733217332273323733247332573326733277332873329733307333173332733337333473335733367333773338733397334073341733427334373344733457334673347733487334973350733517335273353733547335573356733577335873359733607336173362733637336473365733667336773368733697337073371733727337373374733757337673377733787337973380733817338273383733847338573386733877338873389733907339173392733937339473395733967339773398733997340073401734027340373404734057340673407734087340973410734117341273413734147341573416734177341873419734207342173422734237342473425734267342773428734297343073431734327343373434734357343673437734387343973440734417344273443734447344573446734477344873449734507345173452734537345473455734567345773458734597346073461734627346373464734657346673467734687346973470734717347273473734747347573476734777347873479734807348173482734837348473485734867348773488734897349073491734927349373494734957349673497734987349973500735017350273503735047350573506735077350873509735107351173512735137351473515735167351773518735197352073521735227352373524735257352673527735287352973530735317353273533735347353573536735377353873539735407354173542735437354473545735467354773548735497355073551735527355373554735557355673557735587355973560735617356273563735647356573566735677356873569735707357173572735737357473575735767357773578735797358073581735827358373584735857358673587735887358973590735917359273593735947359573596735977359873599736007360173602736037360473605736067360773608736097361073611736127361373614736157361673617736187361973620736217362273623736247362573626736277362873629736307363173632736337363473635736367363773638736397364073641736427364373644736457364673647736487364973650736517365273653736547365573656736577365873659736607366173662736637366473665736667366773668736697367073671736727367373674736757367673677736787367973680736817368273683736847368573686736877368873689736907369173692736937369473695736967369773698736997370073701737027370373704737057370673707737087370973710737117371273713737147371573716737177371873719737207372173722737237372473725737267372773728737297373073731737327373373734737357373673737737387373973740737417374273743737447374573746737477374873749737507375173752737537375473755737567375773758737597376073761737627376373764737657376673767737687376973770737717377273773737747377573776737777377873779737807378173782737837378473785737867378773788737897379073791737927379373794737957379673797737987379973800738017380273803738047380573806738077380873809738107381173812738137381473815738167381773818738197382073821738227382373824738257382673827738287382973830738317383273833738347383573836738377383873839738407384173842738437384473845738467384773848738497385073851738527385373854738557385673857738587385973860738617386273863738647386573866738677386873869738707387173872738737387473875738767387773878738797388073881738827388373884738857388673887738887388973890738917389273893738947389573896738977389873899739007390173902739037390473905739067390773908739097391073911739127391373914739157391673917739187391973920739217392273923739247392573926739277392873929739307393173932739337393473935739367393773938739397394073941739427394373944739457394673947739487394973950739517395273953739547395573956739577395873959739607396173962739637396473965739667396773968739697397073971739727397373974739757397673977739787397973980739817398273983739847398573986739877398873989739907399173992739937399473995739967399773998739997400074001740027400374004740057400674007740087400974010740117401274013740147401574016740177401874019740207402174022740237402474025740267402774028740297403074031740327403374034740357403674037740387403974040740417404274043740447404574046740477404874049740507405174052740537405474055740567405774058740597406074061740627406374064740657406674067740687406974070740717407274073740747407574076740777407874079740807408174082740837408474085740867408774088740897409074091740927409374094740957409674097740987409974100741017410274103741047410574106741077410874109741107411174112741137411474115741167411774118741197412074121741227412374124741257412674127741287412974130741317413274133741347413574136741377413874139741407414174142741437414474145741467414774148741497415074151741527415374154741557415674157741587415974160741617416274163741647416574166741677416874169741707417174172741737417474175741767417774178741797418074181741827418374184741857418674187741887418974190741917419274193741947419574196741977419874199742007420174202742037420474205742067420774208742097421074211742127421374214742157421674217742187421974220742217422274223742247422574226742277422874229742307423174232742337423474235742367423774238742397424074241742427424374244742457424674247742487424974250742517425274253742547425574256742577425874259742607426174262742637426474265742667426774268742697427074271742727427374274742757427674277742787427974280742817428274283742847428574286742877428874289742907429174292742937429474295742967429774298742997430074301743027430374304743057430674307743087430974310743117431274313743147431574316743177431874319743207432174322743237432474325743267432774328743297433074331743327433374334743357433674337743387433974340743417434274343743447434574346743477434874349743507435174352743537435474355743567435774358743597436074361743627436374364743657436674367743687436974370743717437274373743747437574376743777437874379743807438174382743837438474385743867438774388743897439074391743927439374394743957439674397743987439974400744017440274403744047440574406744077440874409744107441174412744137441474415744167441774418744197442074421744227442374424744257442674427744287442974430744317443274433744347443574436744377443874439744407444174442744437444474445744467444774448744497445074451744527445374454744557445674457744587445974460744617446274463744647446574466744677446874469744707447174472744737447474475744767447774478744797448074481744827448374484744857448674487744887448974490744917449274493744947449574496744977449874499745007450174502745037450474505745067450774508745097451074511745127451374514745157451674517745187451974520745217452274523745247452574526745277452874529745307453174532745337453474535745367453774538745397454074541745427454374544745457454674547745487454974550745517455274553745547455574556745577455874559745607456174562745637456474565745667456774568745697457074571745727457374574745757457674577745787457974580745817458274583745847458574586745877458874589745907459174592745937459474595745967459774598745997460074601746027460374604746057460674607746087460974610746117461274613746147461574616746177461874619746207462174622746237462474625746267462774628746297463074631746327463374634746357463674637746387463974640746417464274643746447464574646746477464874649746507465174652746537465474655746567465774658746597466074661746627466374664746657466674667746687466974670746717467274673746747467574676746777467874679746807468174682746837468474685746867468774688746897469074691746927469374694746957469674697746987469974700747017470274703747047470574706747077470874709747107471174712747137471474715747167471774718747197472074721747227472374724747257472674727747287472974730747317473274733747347473574736747377473874739747407474174742747437474474745747467474774748747497475074751747527475374754747557475674757747587475974760747617476274763747647476574766747677476874769747707477174772747737477474775747767477774778747797478074781747827478374784747857478674787747887478974790747917479274793747947479574796747977479874799748007480174802748037480474805748067480774808748097481074811748127481374814748157481674817748187481974820748217482274823748247482574826748277482874829748307483174832748337483474835748367483774838748397484074841748427484374844748457484674847748487484974850748517485274853748547485574856748577485874859748607486174862748637486474865748667486774868748697487074871748727487374874748757487674877748787487974880748817488274883748847488574886748877488874889748907489174892748937489474895748967489774898748997490074901749027490374904749057490674907749087490974910749117491274913749147491574916749177491874919749207492174922749237492474925749267492774928749297493074931749327493374934749357493674937749387493974940749417494274943749447494574946749477494874949749507495174952749537495474955749567495774958749597496074961749627496374964749657496674967749687496974970749717497274973749747497574976749777497874979749807498174982749837498474985749867498774988749897499074991749927499374994749957499674997749987499975000750017500275003750047500575006750077500875009750107501175012750137501475015750167501775018750197502075021750227502375024750257502675027750287502975030750317503275033750347503575036750377503875039750407504175042750437504475045750467504775048750497505075051750527505375054750557505675057750587505975060750617506275063750647506575066750677506875069750707507175072750737507475075750767507775078750797508075081750827508375084750857508675087750887508975090750917509275093750947509575096750977509875099751007510175102751037510475105751067510775108751097511075111751127511375114751157511675117751187511975120751217512275123751247512575126751277512875129751307513175132751337513475135751367513775138751397514075141751427514375144751457514675147751487514975150751517515275153751547515575156751577515875159751607516175162751637516475165751667516775168751697517075171751727517375174751757517675177751787517975180751817518275183751847518575186751877518875189751907519175192751937519475195751967519775198751997520075201752027520375204752057520675207752087520975210752117521275213752147521575216752177521875219752207522175222752237522475225752267522775228752297523075231752327523375234752357523675237752387523975240752417524275243752447524575246752477524875249752507525175252752537525475255752567525775258752597526075261752627526375264752657526675267752687526975270752717527275273752747527575276752777527875279752807528175282752837528475285752867528775288752897529075291752927529375294752957529675297752987529975300753017530275303753047530575306753077530875309753107531175312753137531475315753167531775318753197532075321753227532375324753257532675327753287532975330753317533275333753347533575336753377533875339753407534175342753437534475345753467534775348753497535075351753527535375354753557535675357753587535975360753617536275363753647536575366753677536875369753707537175372753737537475375753767537775378753797538075381753827538375384753857538675387753887538975390753917539275393753947539575396753977539875399754007540175402754037540475405754067540775408754097541075411754127541375414754157541675417754187541975420754217542275423754247542575426754277542875429754307543175432754337543475435754367543775438754397544075441754427544375444754457544675447754487544975450754517545275453754547545575456754577545875459754607546175462754637546475465754667546775468754697547075471754727547375474754757547675477754787547975480754817548275483754847548575486754877548875489754907549175492754937549475495754967549775498754997550075501755027550375504755057550675507755087550975510755117551275513755147551575516755177551875519755207552175522755237552475525755267552775528755297553075531755327553375534755357553675537755387553975540755417554275543755447554575546755477554875549755507555175552755537555475555755567555775558755597556075561755627556375564755657556675567755687556975570755717557275573755747557575576755777557875579755807558175582755837558475585755867558775588755897559075591755927559375594755957559675597755987559975600756017560275603756047560575606756077560875609756107561175612756137561475615756167561775618756197562075621756227562375624756257562675627756287562975630756317563275633756347563575636756377563875639756407564175642756437564475645756467564775648756497565075651756527565375654756557565675657756587565975660756617566275663756647566575666756677566875669756707567175672756737567475675756767567775678756797568075681756827568375684756857568675687756887568975690756917569275693756947569575696756977569875699757007570175702757037570475705757067570775708757097571075711757127571375714757157571675717757187571975720757217572275723757247572575726757277572875729757307573175732757337573475735757367573775738757397574075741757427574375744757457574675747757487574975750757517575275753757547575575756757577575875759757607576175762757637576475765757667576775768757697577075771757727577375774757757577675777757787577975780757817578275783757847578575786757877578875789757907579175792757937579475795757967579775798757997580075801758027580375804758057580675807758087580975810758117581275813758147581575816758177581875819758207582175822758237582475825758267582775828758297583075831758327583375834758357583675837758387583975840758417584275843758447584575846758477584875849758507585175852758537585475855758567585775858758597586075861758627586375864758657586675867758687586975870758717587275873758747587575876758777587875879758807588175882758837588475885758867588775888758897589075891758927589375894758957589675897758987589975900759017590275903759047590575906759077590875909759107591175912759137591475915759167591775918759197592075921759227592375924759257592675927759287592975930759317593275933759347593575936759377593875939759407594175942759437594475945759467594775948759497595075951759527595375954759557595675957759587595975960759617596275963759647596575966759677596875969759707597175972759737597475975759767597775978759797598075981759827598375984759857598675987759887598975990759917599275993759947599575996759977599875999760007600176002760037600476005760067600776008760097601076011760127601376014760157601676017760187601976020760217602276023760247602576026760277602876029760307603176032760337603476035760367603776038760397604076041760427604376044760457604676047760487604976050760517605276053760547605576056760577605876059760607606176062760637606476065760667606776068760697607076071760727607376074760757607676077760787607976080760817608276083760847608576086760877608876089760907609176092760937609476095760967609776098760997610076101761027610376104761057610676107761087610976110761117611276113761147611576116761177611876119761207612176122761237612476125761267612776128761297613076131761327613376134761357613676137761387613976140761417614276143761447614576146761477614876149761507615176152761537615476155761567615776158761597616076161761627616376164761657616676167761687616976170761717617276173761747617576176761777617876179761807618176182761837618476185761867618776188761897619076191761927619376194761957619676197761987619976200762017620276203762047620576206762077620876209762107621176212762137621476215762167621776218762197622076221762227622376224762257622676227762287622976230762317623276233762347623576236762377623876239762407624176242762437624476245762467624776248762497625076251762527625376254762557625676257762587625976260762617626276263762647626576266762677626876269762707627176272762737627476275762767627776278762797628076281762827628376284762857628676287762887628976290762917629276293762947629576296762977629876299763007630176302763037630476305763067630776308763097631076311763127631376314763157631676317763187631976320763217632276323763247632576326763277632876329763307633176332763337633476335763367633776338763397634076341763427634376344763457634676347763487634976350763517635276353763547635576356763577635876359763607636176362763637636476365763667636776368763697637076371763727637376374763757637676377763787637976380763817638276383763847638576386763877638876389763907639176392763937639476395763967639776398763997640076401764027640376404764057640676407764087640976410764117641276413764147641576416764177641876419764207642176422764237642476425764267642776428764297643076431764327643376434764357643676437764387643976440764417644276443764447644576446764477644876449764507645176452764537645476455764567645776458764597646076461764627646376464764657646676467764687646976470764717647276473764747647576476764777647876479764807648176482764837648476485764867648776488764897649076491764927649376494764957649676497764987649976500765017650276503765047650576506765077650876509765107651176512765137651476515765167651776518765197652076521765227652376524765257652676527765287652976530765317653276533765347653576536765377653876539765407654176542765437654476545765467654776548765497655076551765527655376554765557655676557765587655976560765617656276563765647656576566765677656876569765707657176572765737657476575765767657776578765797658076581765827658376584765857658676587765887658976590765917659276593765947659576596765977659876599766007660176602766037660476605766067660776608766097661076611766127661376614766157661676617766187661976620766217662276623766247662576626766277662876629766307663176632766337663476635766367663776638766397664076641766427664376644766457664676647766487664976650766517665276653766547665576656766577665876659766607666176662766637666476665766667666776668766697667076671766727667376674766757667676677766787667976680766817668276683766847668576686766877668876689766907669176692766937669476695766967669776698766997670076701767027670376704767057670676707767087670976710767117671276713767147671576716767177671876719767207672176722767237672476725767267672776728767297673076731767327673376734767357673676737767387673976740767417674276743767447674576746767477674876749767507675176752767537675476755767567675776758767597676076761767627676376764767657676676767767687676976770767717677276773767747677576776767777677876779767807678176782767837678476785767867678776788767897679076791767927679376794767957679676797767987679976800768017680276803768047680576806768077680876809768107681176812768137681476815768167681776818768197682076821768227682376824768257682676827768287682976830768317683276833768347683576836768377683876839768407684176842768437684476845768467684776848768497685076851768527685376854768557685676857768587685976860768617686276863768647686576866768677686876869768707687176872768737687476875768767687776878768797688076881768827688376884768857688676887768887688976890768917689276893768947689576896768977689876899769007690176902769037690476905769067690776908769097691076911769127691376914769157691676917769187691976920769217692276923769247692576926769277692876929769307693176932769337693476935769367693776938769397694076941769427694376944769457694676947769487694976950769517695276953769547695576956769577695876959769607696176962769637696476965769667696776968769697697076971769727697376974769757697676977769787697976980769817698276983769847698576986769877698876989769907699176992769937699476995769967699776998769997700077001770027700377004770057700677007770087700977010770117701277013770147701577016770177701877019770207702177022770237702477025770267702777028770297703077031770327703377034770357703677037770387703977040770417704277043770447704577046770477704877049770507705177052770537705477055770567705777058770597706077061770627706377064770657706677067770687706977070770717707277073770747707577076770777707877079770807708177082770837708477085770867708777088770897709077091770927709377094770957709677097770987709977100771017710277103771047710577106771077710877109771107711177112771137711477115771167711777118771197712077121771227712377124771257712677127771287712977130771317713277133771347713577136771377713877139771407714177142771437714477145771467714777148771497715077151771527715377154771557715677157771587715977160771617716277163771647716577166771677716877169771707717177172771737717477175771767717777178771797718077181771827718377184771857718677187771887718977190771917719277193771947719577196771977719877199772007720177202772037720477205772067720777208772097721077211772127721377214772157721677217772187721977220772217722277223772247722577226772277722877229772307723177232772337723477235772367723777238772397724077241772427724377244772457724677247772487724977250772517725277253772547725577256772577725877259772607726177262772637726477265772667726777268772697727077271772727727377274772757727677277772787727977280772817728277283772847728577286772877728877289772907729177292772937729477295772967729777298772997730077301773027730377304773057730677307773087730977310773117731277313773147731577316773177731877319773207732177322773237732477325773267732777328773297733077331773327733377334773357733677337773387733977340773417734277343773447734577346773477734877349773507735177352773537735477355773567735777358773597736077361773627736377364773657736677367773687736977370773717737277373773747737577376773777737877379773807738177382773837738477385773867738777388773897739077391773927739377394773957739677397773987739977400774017740277403774047740577406774077740877409774107741177412774137741477415774167741777418774197742077421774227742377424774257742677427774287742977430774317743277433774347743577436774377743877439774407744177442774437744477445774467744777448774497745077451774527745377454774557745677457774587745977460774617746277463774647746577466774677746877469774707747177472774737747477475774767747777478774797748077481774827748377484774857748677487774887748977490774917749277493774947749577496774977749877499775007750177502775037750477505775067750777508775097751077511775127751377514775157751677517775187751977520775217752277523775247752577526775277752877529775307753177532775337753477535775367753777538775397754077541775427754377544775457754677547775487754977550775517755277553775547755577556775577755877559775607756177562775637756477565775667756777568775697757077571775727757377574775757757677577775787757977580775817758277583775847758577586775877758877589775907759177592775937759477595775967759777598775997760077601776027760377604776057760677607776087760977610776117761277613776147761577616776177761877619776207762177622776237762477625776267762777628776297763077631776327763377634776357763677637776387763977640776417764277643776447764577646776477764877649776507765177652776537765477655776567765777658776597766077661776627766377664776657766677667776687766977670776717767277673776747767577676776777767877679776807768177682776837768477685776867768777688776897769077691776927769377694776957769677697776987769977700777017770277703777047770577706777077770877709777107771177712777137771477715777167771777718777197772077721777227772377724777257772677727777287772977730777317773277733777347773577736777377773877739777407774177742777437774477745777467774777748777497775077751777527775377754777557775677757777587775977760777617776277763777647776577766777677776877769777707777177772777737777477775777767777777778777797778077781777827778377784777857778677787777887778977790777917779277793777947779577796777977779877799778007780177802778037780477805778067780777808778097781077811778127781377814778157781677817778187781977820778217782277823778247782577826778277782877829778307783177832778337783477835778367783777838778397784077841778427784377844778457784677847778487784977850778517785277853778547785577856778577785877859778607786177862778637786477865778667786777868778697787077871778727787377874778757787677877778787787977880778817788277883778847788577886778877788877889778907789177892778937789477895778967789777898778997790077901779027790377904779057790677907779087790977910779117791277913779147791577916779177791877919779207792177922779237792477925779267792777928779297793077931779327793377934779357793677937779387793977940779417794277943779447794577946779477794877949779507795177952779537795477955779567795777958779597796077961779627796377964779657796677967779687796977970779717797277973779747797577976779777797877979779807798177982779837798477985779867798777988779897799077991779927799377994779957799677997779987799978000780017800278003780047800578006780077800878009780107801178012780137801478015780167801778018780197802078021780227802378024780257802678027780287802978030780317803278033780347803578036780377803878039780407804178042780437804478045780467804778048780497805078051780527805378054780557805678057780587805978060780617806278063780647806578066780677806878069780707807178072780737807478075780767807778078780797808078081780827808378084780857808678087780887808978090780917809278093780947809578096780977809878099781007810178102781037810478105781067810778108781097811078111781127811378114781157811678117781187811978120781217812278123781247812578126781277812878129781307813178132781337813478135781367813778138781397814078141781427814378144781457814678147781487814978150781517815278153781547815578156781577815878159781607816178162781637816478165781667816778168781697817078171781727817378174781757817678177781787817978180781817818278183781847818578186781877818878189781907819178192781937819478195781967819778198781997820078201782027820378204782057820678207782087820978210782117821278213782147821578216782177821878219782207822178222782237822478225782267822778228782297823078231782327823378234782357823678237782387823978240782417824278243782447824578246782477824878249782507825178252782537825478255782567825778258782597826078261782627826378264782657826678267782687826978270782717827278273782747827578276782777827878279782807828178282782837828478285782867828778288782897829078291782927829378294782957829678297782987829978300783017830278303783047830578306783077830878309783107831178312783137831478315783167831778318783197832078321783227832378324783257832678327783287832978330783317833278333783347833578336783377833878339783407834178342783437834478345783467834778348783497835078351783527835378354783557835678357783587835978360783617836278363783647836578366783677836878369783707837178372783737837478375783767837778378783797838078381783827838378384783857838678387783887838978390783917839278393783947839578396783977839878399784007840178402784037840478405784067840778408784097841078411784127841378414784157841678417784187841978420784217842278423784247842578426784277842878429784307843178432784337843478435784367843778438784397844078441784427844378444784457844678447784487844978450784517845278453784547845578456784577845878459784607846178462784637846478465784667846778468784697847078471784727847378474784757847678477784787847978480784817848278483784847848578486784877848878489784907849178492784937849478495784967849778498784997850078501785027850378504785057850678507785087850978510785117851278513785147851578516785177851878519785207852178522785237852478525785267852778528785297853078531785327853378534785357853678537785387853978540785417854278543785447854578546785477854878549785507855178552785537855478555785567855778558785597856078561785627856378564785657856678567785687856978570785717857278573785747857578576785777857878579785807858178582785837858478585785867858778588785897859078591785927859378594785957859678597785987859978600786017860278603786047860578606786077860878609786107861178612786137861478615786167861778618786197862078621786227862378624786257862678627786287862978630786317863278633786347863578636786377863878639786407864178642786437864478645786467864778648786497865078651786527865378654786557865678657786587865978660786617866278663786647866578666786677866878669786707867178672786737867478675786767867778678786797868078681786827868378684786857868678687786887868978690786917869278693786947869578696786977869878699787007870178702787037870478705787067870778708787097871078711787127871378714787157871678717787187871978720787217872278723787247872578726787277872878729787307873178732787337873478735787367873778738787397874078741787427874378744787457874678747787487874978750787517875278753787547875578756787577875878759787607876178762787637876478765787667876778768787697877078771787727877378774787757877678777787787877978780787817878278783787847878578786787877878878789787907879178792787937879478795787967879778798787997880078801788027880378804788057880678807788087880978810788117881278813788147881578816788177881878819788207882178822788237882478825788267882778828788297883078831788327883378834788357883678837788387883978840788417884278843788447884578846788477884878849788507885178852788537885478855788567885778858788597886078861788627886378864788657886678867788687886978870788717887278873788747887578876788777887878879788807888178882788837888478885788867888778888788897889078891788927889378894788957889678897788987889978900789017890278903789047890578906789077890878909789107891178912789137891478915789167891778918789197892078921789227892378924789257892678927789287892978930789317893278933789347893578936789377893878939789407894178942789437894478945789467894778948789497895078951789527895378954789557895678957789587895978960789617896278963789647896578966789677896878969789707897178972789737897478975789767897778978789797898078981789827898378984789857898678987789887898978990789917899278993789947899578996789977899878999790007900179002790037900479005790067900779008790097901079011790127901379014790157901679017790187901979020790217902279023790247902579026790277902879029790307903179032790337903479035790367903779038790397904079041790427904379044790457904679047790487904979050790517905279053790547905579056790577905879059790607906179062790637906479065790667906779068790697907079071790727907379074790757907679077790787907979080790817908279083790847908579086790877908879089790907909179092790937909479095790967909779098790997910079101791027910379104791057910679107791087910979110791117911279113791147911579116791177911879119791207912179122791237912479125791267912779128791297913079131791327913379134791357913679137791387913979140791417914279143791447914579146791477914879149791507915179152791537915479155791567915779158791597916079161791627916379164791657916679167791687916979170791717917279173791747917579176791777917879179791807918179182791837918479185791867918779188791897919079191791927919379194791957919679197791987919979200792017920279203792047920579206792077920879209792107921179212792137921479215792167921779218792197922079221792227922379224792257922679227792287922979230792317923279233792347923579236792377923879239792407924179242792437924479245792467924779248792497925079251792527925379254792557925679257792587925979260792617926279263792647926579266792677926879269792707927179272792737927479275792767927779278792797928079281792827928379284792857928679287792887928979290792917929279293792947929579296792977929879299793007930179302793037930479305793067930779308793097931079311793127931379314793157931679317793187931979320793217932279323793247932579326793277932879329793307933179332793337933479335793367933779338793397934079341793427934379344793457934679347793487934979350793517935279353793547935579356793577935879359793607936179362793637936479365793667936779368793697937079371793727937379374793757937679377793787937979380793817938279383793847938579386793877938879389793907939179392793937939479395793967939779398793997940079401794027940379404794057940679407794087940979410794117941279413794147941579416794177941879419794207942179422794237942479425794267942779428794297943079431794327943379434794357943679437794387943979440794417944279443794447944579446794477944879449794507945179452794537945479455794567945779458794597946079461794627946379464794657946679467794687946979470794717947279473794747947579476794777947879479794807948179482794837948479485794867948779488794897949079491794927949379494794957949679497794987949979500795017950279503795047950579506795077950879509795107951179512795137951479515795167951779518795197952079521795227952379524795257952679527795287952979530795317953279533795347953579536795377953879539795407954179542795437954479545795467954779548795497955079551795527955379554795557955679557795587955979560795617956279563795647956579566795677956879569795707957179572795737957479575795767957779578795797958079581795827958379584795857958679587795887958979590795917959279593795947959579596795977959879599796007960179602796037960479605796067960779608796097961079611796127961379614796157961679617796187961979620796217962279623796247962579626796277962879629796307963179632796337963479635796367963779638796397964079641796427964379644796457964679647796487964979650796517965279653796547965579656796577965879659796607966179662796637966479665796667966779668796697967079671796727967379674796757967679677796787967979680796817968279683796847968579686796877968879689796907969179692796937969479695796967969779698796997970079701797027970379704797057970679707797087970979710797117971279713797147971579716797177971879719797207972179722797237972479725797267972779728797297973079731797327973379734797357973679737797387973979740797417974279743797447974579746797477974879749797507975179752797537975479755797567975779758797597976079761797627976379764797657976679767797687976979770797717977279773797747977579776797777977879779797807978179782797837978479785797867978779788797897979079791797927979379794797957979679797797987979979800798017980279803798047980579806798077980879809798107981179812798137981479815798167981779818798197982079821798227982379824798257982679827798287982979830798317983279833798347983579836798377983879839798407984179842798437984479845798467984779848798497985079851798527985379854798557985679857798587985979860798617986279863798647986579866798677986879869798707987179872798737987479875798767987779878798797988079881798827988379884798857988679887798887988979890798917989279893798947989579896798977989879899799007990179902799037990479905799067990779908799097991079911799127991379914799157991679917799187991979920799217992279923799247992579926799277992879929799307993179932799337993479935799367993779938799397994079941799427994379944799457994679947799487994979950799517995279953799547995579956799577995879959799607996179962799637996479965799667996779968799697997079971799727997379974799757997679977799787997979980799817998279983799847998579986799877998879989799907999179992799937999479995799967999779998799998000080001800028000380004800058000680007800088000980010800118001280013800148001580016800178001880019800208002180022800238002480025800268002780028800298003080031800328003380034800358003680037800388003980040800418004280043800448004580046800478004880049800508005180052800538005480055800568005780058800598006080061800628006380064800658006680067800688006980070800718007280073800748007580076800778007880079800808008180082800838008480085800868008780088800898009080091800928009380094800958009680097800988009980100801018010280103801048010580106801078010880109801108011180112801138011480115801168011780118801198012080121801228012380124801258012680127801288012980130801318013280133801348013580136801378013880139801408014180142801438014480145801468014780148801498015080151801528015380154801558015680157801588015980160801618016280163801648016580166801678016880169801708017180172801738017480175801768017780178801798018080181801828018380184801858018680187801888018980190801918019280193801948019580196801978019880199802008020180202802038020480205802068020780208802098021080211802128021380214802158021680217802188021980220802218022280223802248022580226802278022880229802308023180232802338023480235802368023780238802398024080241802428024380244802458024680247802488024980250802518025280253802548025580256802578025880259802608026180262802638026480265802668026780268802698027080271802728027380274802758027680277802788027980280802818028280283802848028580286802878028880289802908029180292802938029480295802968029780298802998030080301803028030380304803058030680307803088030980310803118031280313803148031580316803178031880319803208032180322803238032480325803268032780328803298033080331803328033380334803358033680337803388033980340803418034280343803448034580346803478034880349803508035180352803538035480355803568035780358803598036080361803628036380364803658036680367803688036980370803718037280373803748037580376803778037880379803808038180382803838038480385803868038780388803898039080391803928039380394803958039680397803988039980400804018040280403804048040580406804078040880409804108041180412804138041480415804168041780418804198042080421804228042380424804258042680427804288042980430804318043280433804348043580436804378043880439804408044180442804438044480445804468044780448804498045080451804528045380454804558045680457804588045980460804618046280463804648046580466804678046880469804708047180472804738047480475804768047780478804798048080481804828048380484804858048680487804888048980490804918049280493804948049580496804978049880499805008050180502805038050480505805068050780508805098051080511805128051380514805158051680517805188051980520805218052280523805248052580526805278052880529805308053180532805338053480535805368053780538805398054080541805428054380544805458054680547805488054980550805518055280553805548055580556805578055880559805608056180562805638056480565805668056780568805698057080571805728057380574805758057680577805788057980580805818058280583805848058580586805878058880589805908059180592805938059480595805968059780598805998060080601806028060380604806058060680607806088060980610806118061280613806148061580616806178061880619806208062180622806238062480625806268062780628806298063080631806328063380634806358063680637806388063980640806418064280643806448064580646806478064880649806508065180652806538065480655806568065780658806598066080661806628066380664806658066680667806688066980670806718067280673806748067580676806778067880679806808068180682806838068480685806868068780688806898069080691806928069380694806958069680697806988069980700807018070280703807048070580706807078070880709807108071180712807138071480715807168071780718807198072080721807228072380724807258072680727807288072980730807318073280733807348073580736807378073880739807408074180742807438074480745807468074780748807498075080751807528075380754807558075680757807588075980760807618076280763807648076580766807678076880769807708077180772807738077480775807768077780778807798078080781807828078380784807858078680787807888078980790807918079280793807948079580796807978079880799808008080180802808038080480805808068080780808808098081080811808128081380814808158081680817808188081980820808218082280823808248082580826808278082880829808308083180832808338083480835808368083780838808398084080841808428084380844808458084680847808488084980850808518085280853808548085580856808578085880859808608086180862808638086480865808668086780868808698087080871808728087380874808758087680877808788087980880808818088280883808848088580886808878088880889808908089180892808938089480895808968089780898808998090080901809028090380904809058090680907809088090980910809118091280913809148091580916809178091880919809208092180922809238092480925809268092780928809298093080931809328093380934809358093680937809388093980940809418094280943809448094580946809478094880949809508095180952809538095480955809568095780958809598096080961809628096380964809658096680967809688096980970809718097280973809748097580976809778097880979809808098180982809838098480985809868098780988809898099080991809928099380994809958099680997809988099981000810018100281003810048100581006810078100881009810108101181012810138101481015810168101781018810198102081021810228102381024810258102681027810288102981030810318103281033810348103581036810378103881039810408104181042810438104481045810468104781048810498105081051810528105381054810558105681057810588105981060810618106281063810648106581066810678106881069810708107181072810738107481075810768107781078810798108081081810828108381084810858108681087810888108981090810918109281093810948109581096810978109881099811008110181102811038110481105811068110781108811098111081111811128111381114811158111681117811188111981120811218112281123811248112581126811278112881129811308113181132811338113481135811368113781138811398114081141811428114381144811458114681147811488114981150811518115281153811548115581156811578115881159811608116181162811638116481165811668116781168811698117081171811728117381174811758117681177811788117981180811818118281183811848118581186811878118881189811908119181192811938119481195811968119781198811998120081201812028120381204812058120681207812088120981210812118121281213812148121581216812178121881219812208122181222812238122481225812268122781228812298123081231812328123381234812358123681237812388123981240812418124281243812448124581246812478124881249812508125181252812538125481255812568125781258812598126081261812628126381264812658126681267812688126981270812718127281273812748127581276812778127881279812808128181282812838128481285812868128781288812898129081291812928129381294812958129681297812988129981300813018130281303813048130581306813078130881309813108131181312813138131481315813168131781318813198132081321813228132381324813258132681327813288132981330813318133281333813348133581336813378133881339813408134181342813438134481345813468134781348813498135081351813528135381354813558135681357813588135981360813618136281363813648136581366813678136881369813708137181372813738137481375813768137781378813798138081381813828138381384813858138681387813888138981390813918139281393813948139581396813978139881399814008140181402814038140481405814068140781408814098141081411814128141381414814158141681417814188141981420814218142281423814248142581426814278142881429814308143181432814338143481435814368143781438814398144081441814428144381444814458144681447814488144981450814518145281453814548145581456814578145881459814608146181462814638146481465814668146781468814698147081471814728147381474814758147681477814788147981480814818148281483814848148581486814878148881489814908149181492814938149481495814968149781498814998150081501815028150381504815058150681507815088150981510815118151281513815148151581516815178151881519815208152181522815238152481525815268152781528815298153081531815328153381534815358153681537815388153981540815418154281543815448154581546815478154881549815508155181552815538155481555815568155781558815598156081561815628156381564815658156681567815688156981570815718157281573815748157581576815778157881579815808158181582815838158481585815868158781588815898159081591815928159381594815958159681597815988159981600816018160281603816048160581606816078160881609816108161181612816138161481615816168161781618816198162081621816228162381624816258162681627816288162981630816318163281633816348163581636816378163881639816408164181642816438164481645816468164781648816498165081651816528165381654816558165681657816588165981660816618166281663816648166581666816678166881669816708167181672816738167481675816768167781678816798168081681816828168381684816858168681687816888168981690816918169281693816948169581696816978169881699817008170181702817038170481705817068170781708817098171081711817128171381714817158171681717817188171981720817218172281723817248172581726817278172881729817308173181732817338173481735817368173781738817398174081741817428174381744817458174681747817488174981750817518175281753817548175581756817578175881759817608176181762817638176481765817668176781768817698177081771817728177381774817758177681777817788177981780817818178281783817848178581786817878178881789817908179181792817938179481795817968179781798817998180081801818028180381804818058180681807818088180981810818118181281813818148181581816818178181881819818208182181822818238182481825818268182781828818298183081831818328183381834818358183681837818388183981840818418184281843818448184581846818478184881849818508185181852818538185481855818568185781858818598186081861818628186381864818658186681867818688186981870818718187281873818748187581876818778187881879818808188181882818838188481885818868188781888818898189081891818928189381894818958189681897818988189981900819018190281903819048190581906819078190881909819108191181912819138191481915819168191781918819198192081921819228192381924819258192681927819288192981930819318193281933819348193581936819378193881939819408194181942819438194481945819468194781948819498195081951819528195381954819558195681957819588195981960819618196281963819648196581966819678196881969819708197181972819738197481975819768197781978819798198081981819828198381984819858198681987819888198981990819918199281993819948199581996819978199881999820008200182002820038200482005820068200782008820098201082011820128201382014820158201682017820188201982020820218202282023820248202582026820278202882029820308203182032820338203482035820368203782038820398204082041820428204382044820458204682047820488204982050820518205282053820548205582056820578205882059820608206182062820638206482065820668206782068820698207082071820728207382074820758207682077820788207982080820818208282083820848208582086820878208882089820908209182092820938209482095820968209782098820998210082101821028210382104821058210682107821088210982110821118211282113821148211582116821178211882119821208212182122821238212482125821268212782128821298213082131821328213382134821358213682137821388213982140821418214282143821448214582146821478214882149821508215182152821538215482155821568215782158821598216082161821628216382164821658216682167821688216982170821718217282173821748217582176821778217882179821808218182182821838218482185821868218782188821898219082191821928219382194821958219682197821988219982200822018220282203822048220582206822078220882209822108221182212822138221482215822168221782218822198222082221822228222382224822258222682227822288222982230822318223282233822348223582236822378223882239822408224182242822438224482245822468224782248822498225082251822528225382254822558225682257822588225982260822618226282263822648226582266822678226882269822708227182272822738227482275822768227782278822798228082281822828228382284822858228682287822888228982290822918229282293822948229582296822978229882299823008230182302823038230482305823068230782308823098231082311823128231382314823158231682317823188231982320823218232282323823248232582326823278232882329823308233182332823338233482335823368233782338823398234082341823428234382344823458234682347823488234982350823518235282353823548235582356823578235882359823608236182362823638236482365823668236782368823698237082371823728237382374823758237682377823788237982380823818238282383823848238582386823878238882389823908239182392823938239482395823968239782398823998240082401824028240382404824058240682407824088240982410824118241282413824148241582416824178241882419824208242182422824238242482425824268242782428824298243082431824328243382434824358243682437824388243982440824418244282443824448244582446824478244882449824508245182452824538245482455824568245782458824598246082461824628246382464824658246682467824688246982470824718247282473824748247582476824778247882479824808248182482824838248482485824868248782488824898249082491824928249382494824958249682497824988249982500825018250282503825048250582506825078250882509825108251182512825138251482515825168251782518825198252082521825228252382524825258252682527825288252982530825318253282533825348253582536825378253882539825408254182542825438254482545825468254782548825498255082551825528255382554825558255682557825588255982560825618256282563825648256582566825678256882569825708257182572825738257482575825768257782578825798258082581825828258382584825858258682587825888258982590825918259282593825948259582596825978259882599826008260182602826038260482605826068260782608826098261082611826128261382614826158261682617826188261982620826218262282623826248262582626826278262882629826308263182632826338263482635826368263782638826398264082641826428264382644826458264682647826488264982650826518265282653826548265582656826578265882659826608266182662826638266482665826668266782668826698267082671826728267382674826758267682677826788267982680826818268282683826848268582686826878268882689826908269182692826938269482695826968269782698826998270082701827028270382704827058270682707827088270982710827118271282713827148271582716827178271882719827208272182722827238272482725827268272782728827298273082731827328273382734827358273682737827388273982740827418274282743827448274582746827478274882749827508275182752827538275482755827568275782758827598276082761827628276382764827658276682767827688276982770827718277282773827748277582776827778277882779827808278182782827838278482785827868278782788827898279082791827928279382794827958279682797827988279982800828018280282803828048280582806828078280882809828108281182812828138281482815828168281782818828198282082821828228282382824828258282682827828288282982830828318283282833828348283582836828378283882839828408284182842828438284482845828468284782848828498285082851828528285382854828558285682857828588285982860828618286282863828648286582866828678286882869828708287182872828738287482875828768287782878828798288082881828828288382884828858288682887828888288982890828918289282893828948289582896828978289882899829008290182902829038290482905829068290782908829098291082911829128291382914829158291682917829188291982920829218292282923829248292582926829278292882929829308293182932829338293482935829368293782938829398294082941829428294382944829458294682947829488294982950829518295282953829548295582956829578295882959829608296182962829638296482965829668296782968829698297082971829728297382974829758297682977829788297982980829818298282983829848298582986829878298882989829908299182992829938299482995829968299782998829998300083001830028300383004830058300683007830088300983010830118301283013830148301583016830178301883019830208302183022830238302483025830268302783028830298303083031830328303383034830358303683037830388303983040830418304283043830448304583046830478304883049830508305183052830538305483055830568305783058830598306083061830628306383064830658306683067830688306983070830718307283073830748307583076830778307883079830808308183082830838308483085830868308783088830898309083091830928309383094830958309683097830988309983100831018310283103831048310583106831078310883109831108311183112831138311483115831168311783118831198312083121831228312383124831258312683127831288312983130831318313283133831348313583136831378313883139831408314183142831438314483145831468314783148831498315083151831528315383154831558315683157831588315983160831618316283163831648316583166831678316883169831708317183172831738317483175831768317783178831798318083181831828318383184831858318683187831888318983190831918319283193831948319583196831978319883199832008320183202832038320483205832068320783208832098321083211832128321383214832158321683217832188321983220832218322283223832248322583226832278322883229832308323183232832338323483235832368323783238832398324083241832428324383244832458324683247832488324983250832518325283253832548325583256832578325883259832608326183262832638326483265832668326783268832698327083271832728327383274832758327683277832788327983280832818328283283832848328583286832878328883289832908329183292832938329483295832968329783298832998330083301833028330383304833058330683307833088330983310833118331283313833148331583316833178331883319833208332183322833238332483325833268332783328833298333083331833328333383334833358333683337833388333983340833418334283343833448334583346833478334883349833508335183352833538335483355833568335783358833598336083361833628336383364833658336683367833688336983370833718337283373833748337583376833778337883379833808338183382833838338483385833868338783388833898339083391833928339383394833958339683397833988339983400834018340283403834048340583406834078340883409834108341183412834138341483415834168341783418834198342083421834228342383424834258342683427834288342983430834318343283433834348343583436834378343883439834408344183442834438344483445834468344783448834498345083451834528345383454834558345683457834588345983460834618346283463834648346583466834678346883469834708347183472834738347483475834768347783478834798348083481834828348383484834858348683487834888348983490834918349283493834948349583496834978349883499835008350183502835038350483505835068350783508835098351083511835128351383514835158351683517835188351983520835218352283523835248352583526835278352883529835308353183532835338353483535835368353783538835398354083541835428354383544835458354683547835488354983550835518355283553835548355583556835578355883559835608356183562835638356483565835668356783568835698357083571835728357383574835758357683577835788357983580835818358283583835848358583586835878358883589835908359183592835938359483595835968359783598835998360083601836028360383604836058360683607836088360983610836118361283613836148361583616836178361883619836208362183622836238362483625836268362783628836298363083631836328363383634836358363683637836388363983640836418364283643836448364583646836478364883649836508365183652836538365483655836568365783658836598366083661836628366383664836658366683667836688366983670836718367283673836748367583676836778367883679836808368183682836838368483685836868368783688836898369083691836928369383694836958369683697836988369983700837018370283703837048370583706837078370883709837108371183712837138371483715837168371783718837198372083721837228372383724837258372683727837288372983730837318373283733837348373583736837378373883739837408374183742837438374483745837468374783748837498375083751837528375383754837558375683757837588375983760837618376283763837648376583766837678376883769837708377183772837738377483775837768377783778837798378083781837828378383784837858378683787837888378983790837918379283793837948379583796837978379883799838008380183802838038380483805838068380783808838098381083811838128381383814838158381683817838188381983820838218382283823838248382583826838278382883829838308383183832838338383483835838368383783838838398384083841838428384383844838458384683847838488384983850838518385283853838548385583856838578385883859838608386183862838638386483865838668386783868838698387083871838728387383874838758387683877838788387983880838818388283883838848388583886838878388883889838908389183892838938389483895838968389783898838998390083901839028390383904839058390683907839088390983910839118391283913839148391583916839178391883919839208392183922839238392483925839268392783928839298393083931839328393383934839358393683937839388393983940839418394283943839448394583946839478394883949839508395183952839538395483955839568395783958839598396083961839628396383964839658396683967839688396983970839718397283973839748397583976839778397883979839808398183982839838398483985839868398783988839898399083991839928399383994839958399683997839988399984000840018400284003840048400584006840078400884009840108401184012840138401484015840168401784018840198402084021840228402384024840258402684027840288402984030840318403284033840348403584036840378403884039840408404184042840438404484045840468404784048840498405084051840528405384054840558405684057840588405984060840618406284063840648406584066840678406884069840708407184072840738407484075840768407784078840798408084081840828408384084840858408684087840888408984090840918409284093840948409584096840978409884099841008410184102841038410484105841068410784108841098411084111841128411384114841158411684117841188411984120841218412284123841248412584126841278412884129841308413184132841338413484135841368413784138841398414084141841428414384144841458414684147841488414984150841518415284153841548415584156841578415884159841608416184162841638416484165841668416784168841698417084171841728417384174841758417684177841788417984180841818418284183841848418584186841878418884189841908419184192841938419484195841968419784198841998420084201842028420384204842058420684207842088420984210842118421284213842148421584216842178421884219842208422184222842238422484225842268422784228842298423084231842328423384234842358423684237842388423984240842418424284243842448424584246842478424884249842508425184252842538425484255842568425784258842598426084261842628426384264842658426684267842688426984270842718427284273842748427584276842778427884279842808428184282842838428484285842868428784288842898429084291842928429384294842958429684297842988429984300843018430284303843048430584306843078430884309843108431184312843138431484315843168431784318843198432084321843228432384324843258432684327843288432984330843318433284333843348433584336843378433884339843408434184342843438434484345843468434784348843498435084351843528435384354843558435684357843588435984360843618436284363843648436584366843678436884369843708437184372843738437484375843768437784378843798438084381843828438384384843858438684387843888438984390843918439284393843948439584396843978439884399844008440184402844038440484405844068440784408844098441084411844128441384414844158441684417844188441984420844218442284423844248442584426844278442884429844308443184432844338443484435844368443784438844398444084441844428444384444844458444684447844488444984450844518445284453844548445584456844578445884459844608446184462844638446484465844668446784468844698447084471844728447384474844758447684477844788447984480844818448284483844848448584486844878448884489844908449184492844938449484495844968449784498844998450084501845028450384504845058450684507845088450984510845118451284513845148451584516845178451884519845208452184522845238452484525845268452784528845298453084531845328453384534845358453684537845388453984540845418454284543845448454584546845478454884549845508455184552845538455484555845568455784558845598456084561845628456384564845658456684567845688456984570845718457284573845748457584576845778457884579845808458184582845838458484585845868458784588845898459084591845928459384594845958459684597845988459984600846018460284603846048460584606846078460884609846108461184612846138461484615846168461784618846198462084621846228462384624846258462684627846288462984630846318463284633846348463584636846378463884639846408464184642846438464484645846468464784648846498465084651846528465384654846558465684657846588465984660846618466284663846648466584666846678466884669846708467184672846738467484675846768467784678846798468084681846828468384684846858468684687846888468984690846918469284693846948469584696846978469884699847008470184702847038470484705847068470784708847098471084711847128471384714847158471684717847188471984720847218472284723847248472584726847278472884729847308473184732847338473484735847368473784738847398474084741847428474384744847458474684747847488474984750847518475284753847548475584756847578475884759847608476184762847638476484765847668476784768847698477084771847728477384774847758477684777847788477984780847818478284783847848478584786847878478884789847908479184792847938479484795847968479784798847998480084801848028480384804848058480684807848088480984810848118481284813848148481584816848178481884819848208482184822848238482484825848268482784828848298483084831848328483384834848358483684837848388483984840848418484284843848448484584846848478484884849848508485184852848538485484855848568485784858848598486084861848628486384864848658486684867848688486984870848718487284873848748487584876848778487884879848808488184882848838488484885848868488784888848898489084891848928489384894848958489684897848988489984900849018490284903849048490584906849078490884909849108491184912849138491484915849168491784918849198492084921849228492384924849258492684927849288492984930849318493284933849348493584936849378493884939849408494184942849438494484945849468494784948849498495084951849528495384954849558495684957849588495984960849618496284963849648496584966849678496884969849708497184972849738497484975849768497784978849798498084981849828498384984849858498684987849888498984990849918499284993849948499584996849978499884999850008500185002850038500485005850068500785008850098501085011850128501385014850158501685017850188501985020850218502285023850248502585026850278502885029850308503185032850338503485035850368503785038850398504085041850428504385044850458504685047850488504985050850518505285053850548505585056850578505885059850608506185062850638506485065850668506785068850698507085071850728507385074850758507685077850788507985080850818508285083850848508585086850878508885089850908509185092850938509485095850968509785098850998510085101851028510385104851058510685107851088510985110851118511285113851148511585116851178511885119851208512185122851238512485125851268512785128851298513085131851328513385134851358513685137851388513985140851418514285143851448514585146851478514885149851508515185152851538515485155851568515785158851598516085161851628516385164851658516685167851688516985170851718517285173851748517585176851778517885179851808518185182851838518485185851868518785188851898519085191851928519385194851958519685197851988519985200852018520285203852048520585206852078520885209852108521185212852138521485215852168521785218852198522085221852228522385224852258522685227852288522985230852318523285233852348523585236852378523885239852408524185242852438524485245852468524785248852498525085251852528525385254852558525685257852588525985260852618526285263852648526585266852678526885269852708527185272852738527485275852768527785278852798528085281852828528385284852858528685287852888528985290852918529285293852948529585296852978529885299853008530185302853038530485305853068530785308853098531085311853128531385314853158531685317853188531985320853218532285323853248532585326853278532885329853308533185332853338533485335853368533785338853398534085341853428534385344853458534685347853488534985350853518535285353853548535585356853578535885359853608536185362853638536485365853668536785368853698537085371853728537385374853758537685377853788537985380853818538285383853848538585386853878538885389853908539185392853938539485395853968539785398853998540085401854028540385404854058540685407854088540985410854118541285413854148541585416854178541885419854208542185422854238542485425854268542785428854298543085431854328543385434854358543685437854388543985440854418544285443854448544585446854478544885449854508545185452854538545485455854568545785458854598546085461854628546385464854658546685467854688546985470854718547285473854748547585476854778547885479854808548185482854838548485485854868548785488854898549085491854928549385494854958549685497854988549985500855018550285503855048550585506855078550885509855108551185512855138551485515855168551785518855198552085521855228552385524855258552685527855288552985530855318553285533855348553585536855378553885539855408554185542855438554485545855468554785548855498555085551855528555385554855558555685557855588555985560855618556285563855648556585566855678556885569855708557185572855738557485575855768557785578855798558085581855828558385584855858558685587855888558985590855918559285593855948559585596855978559885599856008560185602856038560485605856068560785608856098561085611856128561385614856158561685617856188561985620856218562285623856248562585626856278562885629856308563185632856338563485635856368563785638856398564085641856428564385644856458564685647856488564985650856518565285653856548565585656856578565885659856608566185662856638566485665856668566785668856698567085671856728567385674856758567685677856788567985680856818568285683856848568585686856878568885689856908569185692856938569485695856968569785698856998570085701857028570385704857058570685707857088570985710857118571285713857148571585716857178571885719857208572185722857238572485725857268572785728857298573085731857328573385734857358573685737857388573985740857418574285743857448574585746857478574885749857508575185752857538575485755857568575785758857598576085761857628576385764857658576685767857688576985770857718577285773857748577585776857778577885779857808578185782857838578485785857868578785788857898579085791857928579385794857958579685797857988579985800858018580285803858048580585806858078580885809858108581185812858138581485815858168581785818858198582085821858228582385824858258582685827858288582985830858318583285833858348583585836858378583885839858408584185842858438584485845858468584785848858498585085851858528585385854858558585685857858588585985860858618586285863858648586585866858678586885869858708587185872858738587485875858768587785878858798588085881858828588385884858858588685887858888588985890858918589285893858948589585896858978589885899859008590185902859038590485905859068590785908859098591085911859128591385914859158591685917859188591985920859218592285923859248592585926859278592885929859308593185932859338593485935859368593785938859398594085941859428594385944859458594685947859488594985950859518595285953859548595585956859578595885959859608596185962859638596485965859668596785968859698597085971859728597385974859758597685977859788597985980859818598285983859848598585986859878598885989859908599185992859938599485995859968599785998859998600086001860028600386004860058600686007860088600986010860118601286013860148601586016860178601886019860208602186022860238602486025860268602786028860298603086031860328603386034860358603686037860388603986040860418604286043860448604586046860478604886049860508605186052860538605486055860568605786058860598606086061860628606386064860658606686067860688606986070860718607286073860748607586076860778607886079860808608186082860838608486085860868608786088860898609086091860928609386094860958609686097860988609986100861018610286103861048610586106861078610886109861108611186112861138611486115861168611786118861198612086121861228612386124861258612686127861288612986130861318613286133861348613586136861378613886139861408614186142861438614486145861468614786148861498615086151861528615386154861558615686157861588615986160861618616286163861648616586166861678616886169861708617186172861738617486175861768617786178861798618086181861828618386184861858618686187861888618986190861918619286193861948619586196861978619886199862008620186202862038620486205862068620786208862098621086211862128621386214862158621686217862188621986220862218622286223862248622586226862278622886229862308623186232862338623486235862368623786238862398624086241862428624386244862458624686247862488624986250862518625286253862548625586256862578625886259862608626186262862638626486265862668626786268862698627086271862728627386274862758627686277862788627986280862818628286283862848628586286862878628886289862908629186292862938629486295862968629786298862998630086301863028630386304863058630686307863088630986310863118631286313863148631586316863178631886319863208632186322863238632486325863268632786328863298633086331863328633386334863358633686337863388633986340863418634286343863448634586346863478634886349863508635186352863538635486355863568635786358863598636086361863628636386364863658636686367863688636986370863718637286373863748637586376863778637886379863808638186382863838638486385863868638786388863898639086391863928639386394863958639686397863988639986400864018640286403864048640586406864078640886409864108641186412864138641486415864168641786418864198642086421864228642386424864258642686427864288642986430864318643286433864348643586436864378643886439864408644186442864438644486445864468644786448864498645086451864528645386454864558645686457864588645986460864618646286463864648646586466864678646886469864708647186472864738647486475864768647786478864798648086481864828648386484864858648686487864888648986490864918649286493864948649586496864978649886499865008650186502865038650486505865068650786508865098651086511865128651386514865158651686517865188651986520865218652286523865248652586526865278652886529865308653186532865338653486535865368653786538865398654086541865428654386544865458654686547865488654986550865518655286553865548655586556865578655886559865608656186562865638656486565865668656786568865698657086571865728657386574865758657686577865788657986580865818658286583865848658586586865878658886589865908659186592865938659486595865968659786598865998660086601866028660386604866058660686607866088660986610866118661286613866148661586616866178661886619866208662186622866238662486625866268662786628866298663086631866328663386634866358663686637866388663986640866418664286643866448664586646866478664886649866508665186652866538665486655866568665786658866598666086661866628666386664866658666686667866688666986670866718667286673866748667586676866778667886679866808668186682866838668486685866868668786688866898669086691866928669386694866958669686697866988669986700867018670286703867048670586706867078670886709867108671186712867138671486715867168671786718867198672086721867228672386724867258672686727867288672986730867318673286733867348673586736867378673886739867408674186742867438674486745867468674786748867498675086751867528675386754867558675686757867588675986760867618676286763867648676586766867678676886769867708677186772867738677486775867768677786778867798678086781867828678386784867858678686787867888678986790867918679286793867948679586796867978679886799868008680186802868038680486805868068680786808868098681086811868128681386814868158681686817868188681986820868218682286823868248682586826868278682886829868308683186832868338683486835868368683786838868398684086841868428684386844868458684686847868488684986850868518685286853868548685586856868578685886859868608686186862868638686486865868668686786868868698687086871868728687386874868758687686877868788687986880868818688286883868848688586886868878688886889868908689186892868938689486895868968689786898868998690086901869028690386904869058690686907869088690986910869118691286913869148691586916869178691886919869208692186922869238692486925869268692786928869298693086931869328693386934869358693686937869388693986940869418694286943869448694586946869478694886949869508695186952869538695486955869568695786958869598696086961869628696386964869658696686967869688696986970869718697286973869748697586976869778697886979869808698186982869838698486985869868698786988869898699086991869928699386994869958699686997869988699987000870018700287003870048700587006870078700887009870108701187012870138701487015870168701787018870198702087021870228702387024870258702687027870288702987030870318703287033870348703587036870378703887039870408704187042870438704487045870468704787048870498705087051870528705387054870558705687057870588705987060870618706287063870648706587066870678706887069870708707187072870738707487075870768707787078870798708087081870828708387084870858708687087870888708987090870918709287093870948709587096870978709887099871008710187102871038710487105871068710787108871098711087111871128711387114871158711687117871188711987120871218712287123871248712587126871278712887129871308713187132871338713487135871368713787138871398714087141871428714387144871458714687147871488714987150871518715287153871548715587156871578715887159871608716187162871638716487165871668716787168871698717087171871728717387174871758717687177871788717987180871818718287183871848718587186871878718887189871908719187192871938719487195871968719787198871998720087201872028720387204872058720687207872088720987210872118721287213872148721587216872178721887219872208722187222872238722487225872268722787228872298723087231872328723387234872358723687237872388723987240872418724287243872448724587246872478724887249872508725187252872538725487255872568725787258872598726087261872628726387264872658726687267872688726987270872718727287273872748727587276872778727887279872808728187282872838728487285872868728787288872898729087291872928729387294872958729687297872988729987300873018730287303873048730587306873078730887309873108731187312873138731487315873168731787318873198732087321873228732387324873258732687327873288732987330873318733287333873348733587336873378733887339873408734187342873438734487345873468734787348873498735087351873528735387354873558735687357873588735987360873618736287363873648736587366873678736887369873708737187372873738737487375873768737787378873798738087381873828738387384873858738687387873888738987390873918739287393873948739587396873978739887399874008740187402874038740487405874068740787408874098741087411874128741387414874158741687417874188741987420874218742287423874248742587426874278742887429874308743187432874338743487435874368743787438874398744087441874428744387444874458744687447874488744987450874518745287453874548745587456874578745887459874608746187462874638746487465874668746787468874698747087471874728747387474874758747687477874788747987480874818748287483874848748587486874878748887489874908749187492874938749487495874968749787498874998750087501875028750387504875058750687507875088750987510875118751287513875148751587516875178751887519875208752187522875238752487525875268752787528875298753087531875328753387534875358753687537875388753987540875418754287543875448754587546875478754887549875508755187552875538755487555875568755787558875598756087561875628756387564875658756687567875688756987570875718757287573875748757587576875778757887579875808758187582875838758487585875868758787588875898759087591875928759387594875958759687597875988759987600876018760287603876048760587606876078760887609876108761187612876138761487615876168761787618876198762087621876228762387624876258762687627876288762987630876318763287633876348763587636876378763887639876408764187642876438764487645876468764787648876498765087651876528765387654876558765687657876588765987660876618766287663876648766587666876678766887669876708767187672876738767487675876768767787678876798768087681876828768387684876858768687687876888768987690876918769287693876948769587696876978769887699877008770187702877038770487705877068770787708877098771087711877128771387714877158771687717877188771987720877218772287723877248772587726877278772887729877308773187732877338773487735877368773787738877398774087741877428774387744877458774687747877488774987750877518775287753877548775587756877578775887759877608776187762877638776487765877668776787768877698777087771877728777387774877758777687777877788777987780877818778287783877848778587786877878778887789877908779187792877938779487795877968779787798877998780087801878028780387804878058780687807878088780987810878118781287813878148781587816878178781887819878208782187822878238782487825878268782787828878298783087831878328783387834878358783687837878388783987840878418784287843878448784587846878478784887849878508785187852878538785487855878568785787858878598786087861878628786387864878658786687867878688786987870878718787287873878748787587876878778787887879878808788187882878838788487885878868788787888878898789087891878928789387894878958789687897878988789987900879018790287903879048790587906879078790887909879108791187912879138791487915879168791787918879198792087921879228792387924879258792687927879288792987930879318793287933879348793587936879378793887939879408794187942879438794487945879468794787948879498795087951879528795387954879558795687957879588795987960879618796287963879648796587966879678796887969879708797187972879738797487975879768797787978879798798087981879828798387984879858798687987879888798987990879918799287993879948799587996879978799887999880008800188002880038800488005880068800788008880098801088011880128801388014880158801688017880188801988020880218802288023880248802588026880278802888029880308803188032880338803488035880368803788038880398804088041880428804388044880458804688047880488804988050880518805288053880548805588056880578805888059880608806188062880638806488065880668806788068880698807088071880728807388074880758807688077880788807988080880818808288083880848808588086880878808888089880908809188092880938809488095880968809788098880998810088101881028810388104881058810688107881088810988110881118811288113881148811588116881178811888119881208812188122881238812488125881268812788128881298813088131881328813388134881358813688137881388813988140881418814288143881448814588146881478814888149881508815188152881538815488155881568815788158881598816088161881628816388164881658816688167881688816988170881718817288173881748817588176881778817888179881808818188182881838818488185881868818788188881898819088191881928819388194881958819688197881988819988200882018820288203882048820588206882078820888209882108821188212882138821488215882168821788218882198822088221882228822388224882258822688227882288822988230882318823288233882348823588236882378823888239882408824188242882438824488245882468824788248882498825088251882528825388254882558825688257882588825988260882618826288263882648826588266882678826888269882708827188272882738827488275882768827788278882798828088281882828828388284882858828688287882888828988290882918829288293882948829588296882978829888299883008830188302883038830488305883068830788308883098831088311883128831388314883158831688317883188831988320883218832288323883248832588326883278832888329883308833188332883338833488335883368833788338883398834088341883428834388344883458834688347883488834988350883518835288353883548835588356883578835888359883608836188362883638836488365883668836788368883698837088371883728837388374883758837688377883788837988380883818838288383883848838588386883878838888389883908839188392883938839488395883968839788398883998840088401884028840388404884058840688407884088840988410884118841288413884148841588416884178841888419884208842188422884238842488425884268842788428884298843088431884328843388434884358843688437884388843988440884418844288443884448844588446884478844888449884508845188452884538845488455884568845788458884598846088461884628846388464884658846688467884688846988470884718847288473884748847588476884778847888479884808848188482884838848488485884868848788488884898849088491884928849388494884958849688497884988849988500885018850288503885048850588506885078850888509885108851188512885138851488515885168851788518885198852088521885228852388524885258852688527885288852988530885318853288533885348853588536885378853888539885408854188542885438854488545885468854788548885498855088551885528855388554885558855688557885588855988560885618856288563885648856588566885678856888569885708857188572885738857488575885768857788578885798858088581885828858388584885858858688587885888858988590885918859288593885948859588596885978859888599886008860188602886038860488605886068860788608886098861088611886128861388614886158861688617886188861988620886218862288623886248862588626886278862888629886308863188632886338863488635886368863788638886398864088641886428864388644886458864688647886488864988650886518865288653886548865588656886578865888659886608866188662886638866488665886668866788668886698867088671886728867388674886758867688677886788867988680886818868288683886848868588686886878868888689886908869188692886938869488695886968869788698886998870088701887028870388704887058870688707887088870988710887118871288713887148871588716887178871888719887208872188722887238872488725887268872788728887298873088731887328873388734887358873688737887388873988740887418874288743887448874588746887478874888749887508875188752887538875488755887568875788758887598876088761887628876388764887658876688767887688876988770887718877288773887748877588776887778877888779887808878188782887838878488785887868878788788887898879088791887928879388794887958879688797887988879988800888018880288803888048880588806888078880888809888108881188812888138881488815888168881788818888198882088821888228882388824888258882688827888288882988830888318883288833888348883588836888378883888839888408884188842888438884488845888468884788848888498885088851888528885388854888558885688857888588885988860888618886288863888648886588866888678886888869888708887188872888738887488875888768887788878888798888088881888828888388884888858888688887888888888988890888918889288893888948889588896888978889888899889008890188902889038890488905889068890788908889098891088911889128891388914889158891688917889188891988920889218892288923889248892588926889278892888929889308893188932889338893488935889368893788938889398894088941889428894388944889458894688947889488894988950889518895288953889548895588956889578895888959889608896188962889638896488965889668896788968889698897088971889728897388974889758897688977889788897988980889818898288983889848898588986889878898888989889908899188992889938899488995889968899788998889998900089001890028900389004890058900689007890088900989010890118901289013890148901589016890178901889019890208902189022890238902489025890268902789028890298903089031890328903389034890358903689037890388903989040890418904289043890448904589046890478904889049890508905189052890538905489055890568905789058890598906089061890628906389064890658906689067890688906989070890718907289073890748907589076890778907889079890808908189082890838908489085890868908789088890898909089091890928909389094890958909689097890988909989100891018910289103891048910589106891078910889109891108911189112891138911489115891168911789118891198912089121891228912389124891258912689127891288912989130891318913289133891348913589136891378913889139891408914189142891438914489145891468914789148891498915089151891528915389154891558915689157891588915989160891618916289163891648916589166891678916889169891708917189172891738917489175891768917789178891798918089181891828918389184891858918689187891888918989190891918919289193891948919589196891978919889199892008920189202892038920489205892068920789208892098921089211892128921389214892158921689217892188921989220892218922289223892248922589226892278922889229892308923189232892338923489235892368923789238892398924089241892428924389244892458924689247892488924989250892518925289253892548925589256892578925889259892608926189262892638926489265892668926789268892698927089271892728927389274892758927689277892788927989280892818928289283892848928589286892878928889289892908929189292892938929489295892968929789298892998930089301893028930389304893058930689307893088930989310893118931289313893148931589316893178931889319893208932189322893238932489325893268932789328893298933089331893328933389334893358933689337893388933989340893418934289343893448934589346893478934889349893508935189352893538935489355893568935789358893598936089361893628936389364893658936689367893688936989370893718937289373893748937589376893778937889379893808938189382893838938489385893868938789388893898939089391893928939389394893958939689397893988939989400894018940289403894048940589406894078940889409894108941189412894138941489415894168941789418894198942089421894228942389424894258942689427894288942989430894318943289433894348943589436894378943889439894408944189442894438944489445894468944789448894498945089451894528945389454894558945689457894588945989460894618946289463894648946589466894678946889469894708947189472894738947489475894768947789478894798948089481894828948389484894858948689487894888948989490894918949289493894948949589496894978949889499895008950189502895038950489505895068950789508895098951089511895128951389514895158951689517895188951989520895218952289523895248952589526895278952889529895308953189532895338953489535895368953789538895398954089541895428954389544895458954689547895488954989550895518955289553895548955589556895578955889559895608956189562895638956489565895668956789568895698957089571895728957389574895758957689577895788957989580895818958289583895848958589586895878958889589895908959189592895938959489595895968959789598895998960089601896028960389604896058960689607896088960989610896118961289613896148961589616896178961889619896208962189622896238962489625896268962789628896298963089631896328963389634896358963689637896388963989640896418964289643896448964589646896478964889649896508965189652896538965489655896568965789658896598966089661896628966389664896658966689667896688966989670896718967289673896748967589676896778967889679896808968189682896838968489685896868968789688896898969089691896928969389694896958969689697896988969989700897018970289703897048970589706897078970889709897108971189712897138971489715897168971789718897198972089721897228972389724897258972689727897288972989730897318973289733897348973589736897378973889739897408974189742897438974489745897468974789748897498975089751897528975389754897558975689757897588975989760897618976289763897648976589766897678976889769897708977189772897738977489775897768977789778897798978089781897828978389784897858978689787897888978989790897918979289793897948979589796897978979889799898008980189802898038980489805898068980789808898098981089811898128981389814898158981689817898188981989820898218982289823898248982589826898278982889829898308983189832898338983489835898368983789838898398984089841898428984389844898458984689847898488984989850898518985289853898548985589856898578985889859898608986189862898638986489865898668986789868898698987089871898728987389874898758987689877898788987989880898818988289883898848988589886898878988889889898908989189892898938989489895898968989789898898998990089901899028990389904899058990689907899088990989910899118991289913899148991589916899178991889919899208992189922899238992489925899268992789928899298993089931899328993389934899358993689937899388993989940899418994289943899448994589946899478994889949899508995189952899538995489955899568995789958899598996089961899628996389964899658996689967899688996989970899718997289973899748997589976899778997889979899808998189982899838998489985899868998789988899898999089991899928999389994899958999689997899988999990000900019000290003900049000590006900079000890009900109001190012900139001490015900169001790018900199002090021900229002390024900259002690027900289002990030900319003290033900349003590036900379003890039900409004190042900439004490045900469004790048900499005090051900529005390054900559005690057900589005990060900619006290063900649006590066900679006890069900709007190072900739007490075900769007790078900799008090081900829008390084900859008690087900889008990090900919009290093900949009590096900979009890099901009010190102901039010490105901069010790108901099011090111901129011390114901159011690117901189011990120901219012290123901249012590126901279012890129901309013190132901339013490135901369013790138901399014090141901429014390144901459014690147901489014990150901519015290153901549015590156901579015890159901609016190162901639016490165901669016790168901699017090171901729017390174901759017690177901789017990180901819018290183901849018590186901879018890189901909019190192901939019490195901969019790198901999020090201902029020390204902059020690207902089020990210902119021290213902149021590216902179021890219902209022190222902239022490225902269022790228902299023090231902329023390234902359023690237902389023990240902419024290243902449024590246902479024890249902509025190252902539025490255902569025790258902599026090261902629026390264902659026690267902689026990270902719027290273902749027590276902779027890279902809028190282902839028490285902869028790288902899029090291902929029390294902959029690297902989029990300903019030290303903049030590306903079030890309903109031190312903139031490315903169031790318903199032090321903229032390324903259032690327903289032990330903319033290333903349033590336903379033890339903409034190342903439034490345903469034790348903499035090351903529035390354903559035690357903589035990360903619036290363903649036590366903679036890369903709037190372903739037490375903769037790378903799038090381903829038390384903859038690387903889038990390903919039290393903949039590396903979039890399904009040190402904039040490405904069040790408904099041090411904129041390414904159041690417904189041990420904219042290423904249042590426904279042890429904309043190432904339043490435904369043790438904399044090441904429044390444904459044690447904489044990450904519045290453904549045590456904579045890459904609046190462904639046490465904669046790468904699047090471904729047390474904759047690477904789047990480904819048290483904849048590486904879048890489904909049190492904939049490495904969049790498904999050090501905029050390504905059050690507905089050990510905119051290513905149051590516905179051890519905209052190522905239052490525905269052790528905299053090531905329053390534905359053690537905389053990540905419054290543905449054590546905479054890549905509055190552905539055490555905569055790558905599056090561905629056390564905659056690567905689056990570905719057290573905749057590576905779057890579905809058190582905839058490585905869058790588905899059090591905929059390594905959059690597905989059990600906019060290603906049060590606906079060890609906109061190612906139061490615906169061790618906199062090621906229062390624906259062690627906289062990630906319063290633906349063590636906379063890639906409064190642906439064490645906469064790648906499065090651906529065390654906559065690657906589065990660906619066290663906649066590666906679066890669906709067190672906739067490675906769067790678906799068090681906829068390684906859068690687906889068990690906919069290693906949069590696906979069890699907009070190702907039070490705907069070790708907099071090711907129071390714907159071690717907189071990720907219072290723907249072590726907279072890729907309073190732907339073490735907369073790738907399074090741907429074390744907459074690747907489074990750907519075290753907549075590756907579075890759907609076190762907639076490765907669076790768907699077090771907729077390774907759077690777907789077990780907819078290783907849078590786907879078890789907909079190792907939079490795907969079790798907999080090801908029080390804908059080690807908089080990810908119081290813908149081590816908179081890819908209082190822908239082490825908269082790828908299083090831908329083390834908359083690837908389083990840908419084290843908449084590846908479084890849908509085190852908539085490855908569085790858908599086090861908629086390864908659086690867908689086990870908719087290873908749087590876908779087890879908809088190882908839088490885908869088790888908899089090891908929089390894908959089690897908989089990900909019090290903909049090590906909079090890909909109091190912909139091490915909169091790918909199092090921909229092390924909259092690927909289092990930909319093290933909349093590936909379093890939909409094190942909439094490945909469094790948909499095090951909529095390954909559095690957909589095990960909619096290963909649096590966909679096890969909709097190972909739097490975909769097790978909799098090981909829098390984909859098690987909889098990990909919099290993909949099590996909979099890999910009100191002910039100491005910069100791008910099101091011910129101391014910159101691017910189101991020910219102291023910249102591026910279102891029910309103191032910339103491035910369103791038910399104091041910429104391044910459104691047910489104991050910519105291053910549105591056910579105891059910609106191062910639106491065910669106791068910699107091071910729107391074910759107691077910789107991080910819108291083910849108591086910879108891089910909109191092910939109491095910969109791098910999110091101911029110391104911059110691107911089110991110911119111291113911149111591116911179111891119911209112191122911239112491125911269112791128911299113091131911329113391134911359113691137911389113991140911419114291143911449114591146911479114891149911509115191152911539115491155911569115791158911599116091161911629116391164911659116691167911689116991170911719117291173911749117591176911779117891179911809118191182911839118491185911869118791188911899119091191911929119391194911959119691197911989119991200912019120291203912049120591206912079120891209912109121191212912139121491215912169121791218912199122091221912229122391224912259122691227912289122991230912319123291233912349123591236912379123891239912409124191242912439124491245912469124791248912499125091251912529125391254912559125691257912589125991260912619126291263912649126591266912679126891269912709127191272912739127491275912769127791278912799128091281912829128391284912859128691287912889128991290912919129291293912949129591296912979129891299913009130191302913039130491305913069130791308913099131091311913129131391314913159131691317913189131991320913219132291323913249132591326913279132891329913309133191332913339133491335913369133791338913399134091341913429134391344913459134691347913489134991350913519135291353913549135591356913579135891359913609136191362913639136491365913669136791368913699137091371913729137391374913759137691377913789137991380913819138291383913849138591386913879138891389913909139191392913939139491395913969139791398913999140091401914029140391404914059140691407914089140991410914119141291413914149141591416914179141891419914209142191422914239142491425914269142791428914299143091431914329143391434914359143691437914389143991440914419144291443914449144591446914479144891449914509145191452914539145491455914569145791458914599146091461914629146391464914659146691467914689146991470914719147291473914749147591476914779147891479914809148191482914839148491485914869148791488914899149091491914929149391494914959149691497914989149991500915019150291503915049150591506915079150891509915109151191512915139151491515915169151791518915199152091521915229152391524915259152691527915289152991530915319153291533915349153591536915379153891539915409154191542915439154491545915469154791548915499155091551915529155391554915559155691557915589155991560915619156291563915649156591566915679156891569915709157191572915739157491575915769157791578915799158091581915829158391584915859158691587915889158991590915919159291593915949159591596915979159891599916009160191602916039160491605916069160791608916099161091611916129161391614916159161691617916189161991620916219162291623916249162591626916279162891629916309163191632916339163491635916369163791638916399164091641916429164391644916459164691647916489164991650916519165291653916549165591656916579165891659916609166191662916639166491665916669166791668916699167091671916729167391674916759167691677916789167991680916819168291683916849168591686916879168891689916909169191692916939169491695916969169791698916999170091701917029170391704917059170691707917089170991710917119171291713917149171591716917179171891719917209172191722917239172491725917269172791728917299173091731917329173391734917359173691737917389173991740917419174291743917449174591746917479174891749917509175191752917539175491755917569175791758917599176091761917629176391764917659176691767917689176991770917719177291773917749177591776917779177891779917809178191782917839178491785917869178791788917899179091791917929179391794917959179691797917989179991800918019180291803918049180591806918079180891809918109181191812918139181491815918169181791818918199182091821918229182391824918259182691827918289182991830918319183291833918349183591836918379183891839918409184191842918439184491845918469184791848918499185091851918529185391854918559185691857918589185991860918619186291863918649186591866918679186891869918709187191872918739187491875918769187791878918799188091881918829188391884918859188691887918889188991890918919189291893918949189591896918979189891899919009190191902919039190491905919069190791908919099191091911919129191391914919159191691917919189191991920919219192291923919249192591926919279192891929919309193191932919339193491935919369193791938919399194091941919429194391944919459194691947919489194991950919519195291953919549195591956919579195891959919609196191962919639196491965919669196791968919699197091971919729197391974919759197691977919789197991980919819198291983919849198591986919879198891989919909199191992919939199491995919969199791998919999200092001920029200392004920059200692007920089200992010920119201292013920149201592016920179201892019920209202192022920239202492025920269202792028920299203092031920329203392034920359203692037920389203992040920419204292043920449204592046920479204892049920509205192052920539205492055920569205792058920599206092061920629206392064920659206692067920689206992070920719207292073920749207592076920779207892079920809208192082920839208492085920869208792088920899209092091920929209392094920959209692097920989209992100921019210292103921049210592106921079210892109921109211192112921139211492115921169211792118921199212092121921229212392124921259212692127921289212992130921319213292133921349213592136921379213892139921409214192142921439214492145921469214792148921499215092151921529215392154921559215692157921589215992160921619216292163921649216592166921679216892169921709217192172921739217492175921769217792178921799218092181921829218392184921859218692187921889218992190921919219292193921949219592196921979219892199922009220192202922039220492205922069220792208922099221092211922129221392214922159221692217922189221992220922219222292223922249222592226922279222892229922309223192232922339223492235922369223792238922399224092241922429224392244922459224692247922489224992250922519225292253922549225592256922579225892259922609226192262922639226492265922669226792268922699227092271922729227392274922759227692277922789227992280922819228292283922849228592286922879228892289922909229192292922939229492295922969229792298922999230092301923029230392304923059230692307923089230992310923119231292313923149231592316923179231892319923209232192322923239232492325923269232792328923299233092331923329233392334923359233692337923389233992340923419234292343923449234592346923479234892349923509235192352923539235492355923569235792358923599236092361923629236392364923659236692367923689236992370923719237292373923749237592376923779237892379923809238192382923839238492385923869238792388923899239092391923929239392394923959239692397923989239992400924019240292403924049240592406924079240892409924109241192412924139241492415924169241792418924199242092421924229242392424924259242692427924289242992430924319243292433924349243592436924379243892439924409244192442924439244492445924469244792448924499245092451924529245392454924559245692457924589245992460924619246292463924649246592466924679246892469924709247192472924739247492475924769247792478924799248092481924829248392484924859248692487924889248992490924919249292493924949249592496924979249892499925009250192502925039250492505925069250792508925099251092511925129251392514925159251692517925189251992520925219252292523925249252592526925279252892529925309253192532925339253492535925369253792538925399254092541925429254392544925459254692547925489254992550925519255292553925549255592556925579255892559925609256192562925639256492565925669256792568925699257092571925729257392574925759257692577925789257992580925819258292583925849258592586925879258892589925909259192592925939259492595925969259792598925999260092601926029260392604926059260692607926089260992610926119261292613926149261592616926179261892619926209262192622926239262492625926269262792628926299263092631926329263392634926359263692637926389263992640926419264292643926449264592646926479264892649926509265192652926539265492655926569265792658926599266092661926629266392664926659266692667926689266992670926719267292673926749267592676926779267892679926809268192682926839268492685926869268792688926899269092691926929269392694926959269692697926989269992700927019270292703927049270592706927079270892709927109271192712927139271492715927169271792718927199272092721927229272392724927259272692727927289272992730927319273292733927349273592736927379273892739927409274192742927439274492745927469274792748927499275092751927529275392754927559275692757927589275992760927619276292763927649276592766927679276892769927709277192772927739277492775927769277792778927799278092781927829278392784927859278692787927889278992790927919279292793927949279592796927979279892799928009280192802928039280492805928069280792808928099281092811928129281392814928159281692817928189281992820928219282292823928249282592826928279282892829928309283192832928339283492835928369283792838928399284092841928429284392844928459284692847928489284992850928519285292853928549285592856928579285892859928609286192862928639286492865928669286792868928699287092871928729287392874928759287692877928789287992880928819288292883928849288592886928879288892889928909289192892928939289492895928969289792898928999290092901929029290392904929059290692907929089290992910929119291292913929149291592916929179291892919929209292192922929239292492925929269292792928929299293092931929329293392934929359293692937929389293992940929419294292943929449294592946929479294892949929509295192952929539295492955929569295792958929599296092961929629296392964929659296692967929689296992970929719297292973929749297592976929779297892979929809298192982929839298492985929869298792988929899299092991929929299392994929959299692997929989299993000930019300293003930049300593006930079300893009930109301193012930139301493015930169301793018930199302093021930229302393024930259302693027930289302993030930319303293033930349303593036930379303893039930409304193042930439304493045930469304793048930499305093051930529305393054930559305693057930589305993060930619306293063930649306593066930679306893069930709307193072930739307493075930769307793078930799308093081930829308393084930859308693087930889308993090930919309293093930949309593096930979309893099931009310193102931039310493105931069310793108931099311093111931129311393114931159311693117931189311993120931219312293123931249312593126931279312893129931309313193132931339313493135931369313793138931399314093141931429314393144931459314693147931489314993150931519315293153931549315593156931579315893159931609316193162931639316493165931669316793168931699317093171931729317393174931759317693177931789317993180931819318293183931849318593186931879318893189931909319193192931939319493195931969319793198931999320093201932029320393204932059320693207932089320993210932119321293213932149321593216932179321893219932209322193222932239322493225932269322793228932299323093231932329323393234932359323693237932389323993240932419324293243932449324593246932479324893249932509325193252932539325493255932569325793258932599326093261932629326393264932659326693267932689326993270932719327293273932749327593276932779327893279932809328193282932839328493285932869328793288932899329093291932929329393294932959329693297932989329993300933019330293303933049330593306933079330893309933109331193312933139331493315933169331793318933199332093321933229332393324933259332693327933289332993330933319333293333933349333593336933379333893339933409334193342933439334493345933469334793348933499335093351933529335393354933559335693357933589335993360933619336293363933649336593366933679336893369933709337193372933739337493375933769337793378933799338093381933829338393384933859338693387933889338993390933919339293393933949339593396933979339893399934009340193402934039340493405934069340793408934099341093411934129341393414934159341693417934189341993420934219342293423934249342593426934279342893429934309343193432934339343493435934369343793438934399344093441934429344393444934459344693447934489344993450934519345293453934549345593456934579345893459934609346193462934639346493465934669346793468934699347093471934729347393474934759347693477934789347993480934819348293483934849348593486934879348893489934909349193492934939349493495934969349793498934999350093501935029350393504935059350693507935089350993510935119351293513935149351593516935179351893519935209352193522935239352493525935269352793528935299353093531935329353393534935359353693537935389353993540935419354293543935449354593546935479354893549935509355193552935539355493555935569355793558935599356093561935629356393564935659356693567935689356993570935719357293573935749357593576935779357893579935809358193582935839358493585935869358793588935899359093591935929359393594935959359693597935989359993600936019360293603936049360593606936079360893609936109361193612936139361493615936169361793618936199362093621936229362393624936259362693627936289362993630936319363293633936349363593636936379363893639936409364193642936439364493645936469364793648936499365093651936529365393654936559365693657936589365993660936619366293663936649366593666936679366893669936709367193672936739367493675936769367793678936799368093681936829368393684936859368693687936889368993690936919369293693936949369593696936979369893699937009370193702937039370493705937069370793708937099371093711937129371393714937159371693717937189371993720937219372293723937249372593726937279372893729937309373193732937339373493735937369373793738937399374093741937429374393744937459374693747937489374993750937519375293753937549375593756937579375893759937609376193762937639376493765937669376793768937699377093771937729377393774937759377693777937789377993780937819378293783937849378593786937879378893789937909379193792937939379493795937969379793798937999380093801938029380393804938059380693807938089380993810938119381293813938149381593816938179381893819938209382193822938239382493825938269382793828938299383093831938329383393834938359383693837938389383993840938419384293843938449384593846938479384893849938509385193852938539385493855938569385793858938599386093861938629386393864938659386693867938689386993870938719387293873938749387593876938779387893879938809388193882938839388493885938869388793888938899389093891938929389393894938959389693897938989389993900939019390293903939049390593906939079390893909939109391193912939139391493915939169391793918939199392093921939229392393924939259392693927939289392993930939319393293933939349393593936939379393893939939409394193942939439394493945939469394793948939499395093951939529395393954939559395693957939589395993960939619396293963939649396593966939679396893969939709397193972939739397493975939769397793978939799398093981939829398393984939859398693987939889398993990939919399293993939949399593996939979399893999940009400194002940039400494005940069400794008940099401094011940129401394014940159401694017940189401994020940219402294023940249402594026940279402894029940309403194032940339403494035940369403794038940399404094041940429404394044940459404694047940489404994050940519405294053940549405594056940579405894059940609406194062940639406494065940669406794068940699407094071940729407394074940759407694077940789407994080940819408294083940849408594086940879408894089940909409194092940939409494095940969409794098940999410094101941029410394104941059410694107941089410994110941119411294113941149411594116941179411894119941209412194122941239412494125941269412794128941299413094131941329413394134941359413694137941389413994140941419414294143941449414594146941479414894149941509415194152941539415494155941569415794158941599416094161941629416394164941659416694167941689416994170941719417294173941749417594176941779417894179941809418194182941839418494185941869418794188941899419094191941929419394194941959419694197941989419994200942019420294203942049420594206942079420894209942109421194212942139421494215942169421794218942199422094221942229422394224942259422694227942289422994230942319423294233942349423594236942379423894239942409424194242942439424494245942469424794248942499425094251942529425394254942559425694257942589425994260942619426294263942649426594266942679426894269942709427194272942739427494275942769427794278942799428094281942829428394284942859428694287942889428994290942919429294293942949429594296942979429894299943009430194302943039430494305943069430794308943099431094311943129431394314943159431694317943189431994320943219432294323943249432594326943279432894329943309433194332943339433494335943369433794338943399434094341943429434394344943459434694347943489434994350943519435294353943549435594356943579435894359943609436194362943639436494365943669436794368943699437094371943729437394374943759437694377943789437994380943819438294383943849438594386943879438894389943909439194392943939439494395943969439794398943999440094401944029440394404944059440694407944089440994410944119441294413944149441594416944179441894419944209442194422944239442494425944269442794428944299443094431944329443394434944359443694437944389443994440944419444294443944449444594446944479444894449944509445194452944539445494455944569445794458944599446094461944629446394464944659446694467944689446994470944719447294473944749447594476944779447894479944809448194482944839448494485944869448794488944899449094491944929449394494944959449694497944989449994500945019450294503945049450594506945079450894509945109451194512945139451494515945169451794518945199452094521945229452394524945259452694527945289452994530945319453294533945349453594536945379453894539945409454194542945439454494545945469454794548945499455094551945529455394554945559455694557945589455994560945619456294563945649456594566945679456894569945709457194572945739457494575945769457794578945799458094581945829458394584945859458694587945889458994590945919459294593945949459594596945979459894599946009460194602946039460494605946069460794608946099461094611946129461394614946159461694617946189461994620946219462294623946249462594626946279462894629946309463194632946339463494635946369463794638946399464094641946429464394644946459464694647946489464994650946519465294653946549465594656946579465894659946609466194662946639466494665946669466794668946699467094671946729467394674946759467694677946789467994680946819468294683946849468594686946879468894689946909469194692946939469494695946969469794698946999470094701947029470394704947059470694707947089470994710947119471294713947149471594716947179471894719947209472194722947239472494725947269472794728947299473094731947329473394734947359473694737947389473994740947419474294743947449474594746947479474894749947509475194752947539475494755947569475794758947599476094761947629476394764947659476694767947689476994770947719477294773947749477594776947779477894779947809478194782947839478494785947869478794788947899479094791947929479394794947959479694797947989479994800948019480294803948049480594806948079480894809948109481194812948139481494815948169481794818948199482094821948229482394824948259482694827948289482994830948319483294833948349483594836948379483894839948409484194842948439484494845948469484794848948499485094851948529485394854948559485694857948589485994860948619486294863948649486594866948679486894869948709487194872948739487494875948769487794878948799488094881948829488394884948859488694887948889488994890948919489294893948949489594896948979489894899949009490194902949039490494905949069490794908949099491094911949129491394914949159491694917949189491994920949219492294923949249492594926949279492894929949309493194932949339493494935949369493794938949399494094941949429494394944949459494694947949489494994950949519495294953949549495594956949579495894959949609496194962949639496494965949669496794968949699497094971949729497394974949759497694977949789497994980949819498294983949849498594986949879498894989949909499194992949939499494995949969499794998949999500095001950029500395004950059500695007950089500995010950119501295013950149501595016950179501895019950209502195022950239502495025950269502795028950299503095031950329503395034950359503695037950389503995040950419504295043950449504595046950479504895049950509505195052950539505495055950569505795058950599506095061950629506395064950659506695067950689506995070950719507295073950749507595076950779507895079950809508195082950839508495085950869508795088950899509095091950929509395094950959509695097950989509995100951019510295103951049510595106951079510895109951109511195112951139511495115951169511795118951199512095121951229512395124951259512695127951289512995130951319513295133951349513595136951379513895139951409514195142951439514495145951469514795148951499515095151951529515395154951559515695157951589515995160951619516295163951649516595166951679516895169951709517195172951739517495175951769517795178951799518095181951829518395184951859518695187951889518995190951919519295193951949519595196951979519895199952009520195202952039520495205952069520795208952099521095211952129521395214952159521695217952189521995220952219522295223952249522595226952279522895229952309523195232952339523495235952369523795238952399524095241952429524395244952459524695247952489524995250952519525295253952549525595256952579525895259952609526195262952639526495265952669526795268952699527095271952729527395274952759527695277952789527995280952819528295283952849528595286952879528895289952909529195292952939529495295952969529795298952999530095301953029530395304953059530695307953089530995310953119531295313953149531595316953179531895319953209532195322953239532495325953269532795328953299533095331953329533395334953359533695337953389533995340953419534295343953449534595346953479534895349953509535195352953539535495355953569535795358953599536095361953629536395364953659536695367953689536995370953719537295373953749537595376953779537895379953809538195382953839538495385953869538795388953899539095391953929539395394953959539695397953989539995400954019540295403954049540595406954079540895409954109541195412954139541495415954169541795418954199542095421954229542395424954259542695427954289542995430954319543295433954349543595436954379543895439954409544195442954439544495445954469544795448954499545095451954529545395454954559545695457954589545995460954619546295463954649546595466954679546895469954709547195472954739547495475954769547795478954799548095481954829548395484954859548695487954889548995490954919549295493954949549595496954979549895499955009550195502955039550495505955069550795508955099551095511955129551395514955159551695517955189551995520955219552295523955249552595526955279552895529955309553195532955339553495535955369553795538955399554095541955429554395544955459554695547955489554995550955519555295553955549555595556955579555895559955609556195562955639556495565955669556795568955699557095571955729557395574955759557695577955789557995580955819558295583955849558595586955879558895589955909559195592955939559495595955969559795598955999560095601956029560395604956059560695607956089560995610956119561295613956149561595616956179561895619956209562195622956239562495625956269562795628956299563095631956329563395634956359563695637956389563995640956419564295643956449564595646956479564895649956509565195652956539565495655956569565795658956599566095661956629566395664956659566695667956689566995670956719567295673956749567595676956779567895679956809568195682956839568495685956869568795688956899569095691956929569395694956959569695697956989569995700957019570295703957049570595706957079570895709957109571195712957139571495715957169571795718957199572095721957229572395724957259572695727957289572995730957319573295733957349573595736957379573895739957409574195742957439574495745957469574795748957499575095751957529575395754957559575695757957589575995760957619576295763957649576595766957679576895769957709577195772957739577495775957769577795778957799578095781957829578395784957859578695787957889578995790957919579295793957949579595796957979579895799958009580195802958039580495805958069580795808958099581095811958129581395814958159581695817958189581995820958219582295823958249582595826958279582895829958309583195832958339583495835958369583795838958399584095841958429584395844958459584695847958489584995850958519585295853958549585595856958579585895859958609586195862958639586495865958669586795868958699587095871958729587395874958759587695877958789587995880958819588295883958849588595886958879588895889958909589195892958939589495895958969589795898958999590095901959029590395904959059590695907959089590995910959119591295913959149591595916959179591895919959209592195922959239592495925959269592795928959299593095931959329593395934959359593695937959389593995940959419594295943959449594595946959479594895949959509595195952959539595495955959569595795958959599596095961959629596395964959659596695967959689596995970959719597295973959749597595976959779597895979959809598195982959839598495985959869598795988959899599095991959929599395994959959599695997959989599996000960019600296003960049600596006960079600896009960109601196012960139601496015960169601796018960199602096021960229602396024960259602696027960289602996030960319603296033960349603596036960379603896039960409604196042960439604496045960469604796048960499605096051960529605396054960559605696057960589605996060960619606296063960649606596066960679606896069960709607196072960739607496075960769607796078960799608096081960829608396084960859608696087960889608996090960919609296093960949609596096960979609896099961009610196102961039610496105961069610796108961099611096111961129611396114961159611696117961189611996120961219612296123961249612596126961279612896129961309613196132961339613496135961369613796138961399614096141961429614396144961459614696147961489614996150961519615296153961549615596156961579615896159961609616196162961639616496165961669616796168961699617096171961729617396174961759617696177961789617996180961819618296183961849618596186961879618896189961909619196192961939619496195961969619796198961999620096201962029620396204962059620696207962089620996210962119621296213962149621596216962179621896219962209622196222962239622496225962269622796228962299623096231962329623396234962359623696237962389623996240962419624296243962449624596246962479624896249962509625196252962539625496255962569625796258962599626096261962629626396264962659626696267962689626996270962719627296273962749627596276962779627896279962809628196282962839628496285962869628796288962899629096291962929629396294962959629696297962989629996300963019630296303963049630596306963079630896309963109631196312963139631496315963169631796318963199632096321963229632396324963259632696327963289632996330963319633296333963349633596336963379633896339963409634196342963439634496345963469634796348963499635096351963529635396354963559635696357963589635996360963619636296363963649636596366963679636896369963709637196372963739637496375963769637796378963799638096381963829638396384963859638696387963889638996390963919639296393963949639596396963979639896399964009640196402964039640496405964069640796408964099641096411964129641396414964159641696417964189641996420964219642296423964249642596426964279642896429964309643196432964339643496435964369643796438964399644096441964429644396444964459644696447964489644996450964519645296453964549645596456964579645896459964609646196462964639646496465964669646796468964699647096471964729647396474964759647696477964789647996480964819648296483964849648596486964879648896489964909649196492964939649496495964969649796498964999650096501965029650396504965059650696507965089650996510965119651296513965149651596516965179651896519965209652196522965239652496525965269652796528965299653096531965329653396534965359653696537965389653996540965419654296543965449654596546965479654896549965509655196552965539655496555965569655796558965599656096561965629656396564965659656696567965689656996570965719657296573965749657596576965779657896579965809658196582965839658496585965869658796588965899659096591965929659396594965959659696597965989659996600966019660296603966049660596606966079660896609966109661196612966139661496615966169661796618966199662096621966229662396624966259662696627966289662996630966319663296633966349663596636966379663896639966409664196642966439664496645966469664796648966499665096651966529665396654966559665696657966589665996660966619666296663966649666596666966679666896669966709667196672966739667496675966769667796678966799668096681966829668396684966859668696687966889668996690966919669296693966949669596696966979669896699967009670196702967039670496705967069670796708967099671096711967129671396714967159671696717967189671996720967219672296723967249672596726967279672896729967309673196732967339673496735967369673796738967399674096741967429674396744967459674696747967489674996750967519675296753967549675596756967579675896759967609676196762967639676496765967669676796768967699677096771967729677396774967759677696777967789677996780967819678296783967849678596786967879678896789967909679196792967939679496795967969679796798967999680096801968029680396804968059680696807968089680996810968119681296813968149681596816968179681896819968209682196822968239682496825968269682796828968299683096831968329683396834968359683696837968389683996840968419684296843968449684596846968479684896849968509685196852968539685496855968569685796858968599686096861968629686396864968659686696867968689686996870968719687296873968749687596876968779687896879968809688196882968839688496885968869688796888968899689096891968929689396894968959689696897968989689996900969019690296903969049690596906969079690896909969109691196912969139691496915969169691796918969199692096921969229692396924969259692696927969289692996930969319693296933969349693596936969379693896939969409694196942969439694496945969469694796948969499695096951969529695396954969559695696957969589695996960969619696296963969649696596966969679696896969969709697196972969739697496975969769697796978969799698096981969829698396984969859698696987969889698996990969919699296993969949699596996969979699896999970009700197002970039700497005970069700797008970099701097011970129701397014970159701697017970189701997020970219702297023970249702597026970279702897029970309703197032970339703497035970369703797038970399704097041970429704397044970459704697047970489704997050970519705297053970549705597056970579705897059970609706197062970639706497065970669706797068970699707097071970729707397074970759707697077970789707997080970819708297083970849708597086970879708897089970909709197092970939709497095970969709797098970999710097101971029710397104971059710697107971089710997110971119711297113971149711597116971179711897119971209712197122971239712497125971269712797128971299713097131971329713397134971359713697137971389713997140971419714297143971449714597146971479714897149971509715197152971539715497155971569715797158971599716097161971629716397164971659716697167971689716997170971719717297173971749717597176971779717897179971809718197182971839718497185971869718797188971899719097191971929719397194971959719697197971989719997200972019720297203972049720597206972079720897209972109721197212972139721497215972169721797218972199722097221972229722397224972259722697227972289722997230972319723297233972349723597236972379723897239972409724197242972439724497245972469724797248972499725097251972529725397254972559725697257972589725997260972619726297263972649726597266972679726897269972709727197272972739727497275972769727797278972799728097281972829728397284972859728697287972889728997290972919729297293972949729597296972979729897299973009730197302973039730497305973069730797308973099731097311973129731397314973159731697317973189731997320973219732297323973249732597326973279732897329973309733197332973339733497335973369733797338973399734097341973429734397344973459734697347973489734997350973519735297353973549735597356973579735897359973609736197362973639736497365973669736797368973699737097371973729737397374973759737697377973789737997380973819738297383973849738597386973879738897389973909739197392973939739497395973969739797398973999740097401974029740397404974059740697407974089740997410974119741297413974149741597416974179741897419974209742197422974239742497425974269742797428974299743097431974329743397434974359743697437974389743997440974419744297443974449744597446974479744897449974509745197452974539745497455974569745797458974599746097461974629746397464974659746697467974689746997470974719747297473974749747597476974779747897479974809748197482974839748497485974869748797488974899749097491974929749397494974959749697497974989749997500975019750297503975049750597506975079750897509975109751197512975139751497515975169751797518975199752097521975229752397524975259752697527975289752997530975319753297533975349753597536975379753897539975409754197542975439754497545975469754797548975499755097551975529755397554975559755697557975589755997560975619756297563975649756597566975679756897569975709757197572975739757497575975769757797578975799758097581975829758397584975859758697587975889758997590975919759297593975949759597596975979759897599976009760197602976039760497605976069760797608976099761097611976129761397614976159761697617976189761997620976219762297623976249762597626976279762897629976309763197632976339763497635976369763797638976399764097641976429764397644976459764697647976489764997650976519765297653976549765597656976579765897659976609766197662976639766497665976669766797668976699767097671976729767397674976759767697677976789767997680976819768297683976849768597686976879768897689976909769197692976939769497695976969769797698976999770097701977029770397704977059770697707977089770997710977119771297713977149771597716977179771897719977209772197722977239772497725977269772797728977299773097731977329773397734977359773697737977389773997740977419774297743977449774597746977479774897749977509775197752977539775497755977569775797758977599776097761977629776397764977659776697767977689776997770977719777297773977749777597776977779777897779977809778197782977839778497785977869778797788977899779097791977929779397794977959779697797977989779997800978019780297803978049780597806978079780897809978109781197812978139781497815978169781797818978199782097821978229782397824978259782697827978289782997830978319783297833978349783597836978379783897839978409784197842978439784497845978469784797848978499785097851978529785397854978559785697857978589785997860978619786297863978649786597866978679786897869978709787197872978739787497875978769787797878978799788097881978829788397884978859788697887978889788997890978919789297893978949789597896978979789897899979009790197902979039790497905979069790797908979099791097911979129791397914979159791697917979189791997920979219792297923979249792597926979279792897929979309793197932979339793497935979369793797938979399794097941979429794397944979459794697947979489794997950979519795297953979549795597956979579795897959979609796197962979639796497965979669796797968979699797097971979729797397974979759797697977979789797997980979819798297983979849798597986979879798897989979909799197992979939799497995979969799797998979999800098001980029800398004980059800698007980089800998010980119801298013980149801598016980179801898019980209802198022980239802498025980269802798028980299803098031980329803398034980359803698037980389803998040980419804298043980449804598046980479804898049980509805198052980539805498055980569805798058980599806098061980629806398064980659806698067980689806998070980719807298073980749807598076980779807898079980809808198082980839808498085980869808798088980899809098091980929809398094980959809698097980989809998100981019810298103981049810598106981079810898109981109811198112981139811498115981169811798118981199812098121981229812398124981259812698127981289812998130981319813298133981349813598136981379813898139981409814198142981439814498145981469814798148981499815098151981529815398154981559815698157981589815998160981619816298163981649816598166981679816898169981709817198172981739817498175981769817798178981799818098181981829818398184981859818698187981889818998190981919819298193981949819598196981979819898199982009820198202982039820498205982069820798208982099821098211982129821398214982159821698217982189821998220982219822298223982249822598226982279822898229982309823198232982339823498235982369823798238982399824098241982429824398244982459824698247982489824998250982519825298253982549825598256982579825898259982609826198262982639826498265982669826798268982699827098271982729827398274982759827698277982789827998280982819828298283982849828598286982879828898289982909829198292982939829498295982969829798298982999830098301983029830398304983059830698307983089830998310983119831298313983149831598316983179831898319983209832198322983239832498325983269832798328983299833098331983329833398334983359833698337983389833998340983419834298343983449834598346983479834898349983509835198352983539835498355983569835798358983599836098361983629836398364983659836698367983689836998370983719837298373983749837598376983779837898379983809838198382983839838498385983869838798388983899839098391983929839398394983959839698397983989839998400984019840298403984049840598406984079840898409984109841198412984139841498415984169841798418984199842098421984229842398424984259842698427984289842998430984319843298433984349843598436984379843898439984409844198442984439844498445984469844798448984499845098451984529845398454984559845698457984589845998460984619846298463984649846598466984679846898469984709847198472984739847498475984769847798478984799848098481984829848398484984859848698487984889848998490984919849298493984949849598496984979849898499985009850198502985039850498505985069850798508985099851098511985129851398514985159851698517985189851998520985219852298523985249852598526985279852898529985309853198532985339853498535985369853798538985399854098541985429854398544985459854698547985489854998550985519855298553985549855598556985579855898559985609856198562985639856498565985669856798568985699857098571985729857398574985759857698577985789857998580985819858298583985849858598586985879858898589985909859198592985939859498595985969859798598985999860098601986029860398604986059860698607986089860998610986119861298613986149861598616986179861898619986209862198622986239862498625986269862798628986299863098631986329863398634986359863698637986389863998640986419864298643986449864598646986479864898649986509865198652986539865498655986569865798658986599866098661986629866398664986659866698667986689866998670986719867298673986749867598676986779867898679986809868198682986839868498685986869868798688986899869098691986929869398694986959869698697986989869998700987019870298703987049870598706987079870898709987109871198712987139871498715987169871798718987199872098721987229872398724987259872698727987289872998730987319873298733987349873598736987379873898739987409874198742987439874498745987469874798748987499875098751987529875398754987559875698757987589875998760987619876298763987649876598766987679876898769987709877198772987739877498775987769877798778987799878098781987829878398784987859878698787987889878998790987919879298793987949879598796987979879898799988009880198802988039880498805988069880798808988099881098811988129881398814988159881698817988189881998820988219882298823988249882598826988279882898829988309883198832988339883498835988369883798838988399884098841988429884398844988459884698847988489884998850988519885298853988549885598856988579885898859988609886198862988639886498865988669886798868988699887098871988729887398874988759887698877988789887998880988819888298883988849888598886988879888898889988909889198892988939889498895988969889798898988999890098901989029890398904989059890698907989089890998910989119891298913989149891598916989179891898919989209892198922989239892498925989269892798928989299893098931989329893398934989359893698937989389893998940989419894298943989449894598946989479894898949989509895198952989539895498955989569895798958989599896098961989629896398964989659896698967989689896998970989719897298973989749897598976989779897898979989809898198982989839898498985989869898798988989899899098991989929899398994989959899698997989989899999000990019900299003990049900599006990079900899009990109901199012990139901499015990169901799018990199902099021990229902399024990259902699027990289902999030990319903299033990349903599036990379903899039990409904199042990439904499045990469904799048990499905099051990529905399054990559905699057990589905999060990619906299063990649906599066990679906899069990709907199072990739907499075990769907799078990799908099081990829908399084990859908699087990889908999090990919909299093990949909599096990979909899099991009910199102991039910499105991069910799108991099911099111991129911399114991159911699117991189911999120991219912299123991249912599126991279912899129991309913199132991339913499135991369913799138991399914099141991429914399144991459914699147991489914999150991519915299153991549915599156991579915899159991609916199162991639916499165991669916799168991699917099171991729917399174991759917699177991789917999180991819918299183991849918599186991879918899189991909919199192991939919499195991969919799198991999920099201992029920399204992059920699207992089920999210992119921299213992149921599216992179921899219992209922199222992239922499225992269922799228992299923099231992329923399234992359923699237992389923999240992419924299243992449924599246992479924899249992509925199252992539925499255992569925799258992599926099261992629926399264992659926699267992689926999270992719927299273992749927599276992779927899279992809928199282992839928499285992869928799288992899929099291992929929399294992959929699297992989929999300993019930299303993049930599306993079930899309993109931199312993139931499315993169931799318993199932099321993229932399324993259932699327993289932999330993319933299333993349933599336993379933899339993409934199342993439934499345993469934799348993499935099351993529935399354993559935699357993589935999360993619936299363993649936599366993679936899369993709937199372993739937499375993769937799378993799938099381993829938399384993859938699387993889938999390993919939299393993949939599396993979939899399994009940199402994039940499405994069940799408994099941099411994129941399414994159941699417994189941999420994219942299423994249942599426994279942899429994309943199432994339943499435994369943799438994399944099441994429944399444994459944699447994489944999450994519945299453994549945599456994579945899459994609946199462994639946499465994669946799468994699947099471994729947399474994759947699477994789947999480994819948299483994849948599486994879948899489994909949199492994939949499495994969949799498994999950099501995029950399504995059950699507995089950999510995119951299513995149951599516995179951899519995209952199522995239952499525995269952799528995299953099531995329953399534995359953699537995389953999540995419954299543995449954599546995479954899549995509955199552995539955499555995569955799558995599956099561995629956399564995659956699567995689956999570995719957299573995749957599576995779957899579995809958199582995839958499585995869958799588995899959099591995929959399594995959959699597995989959999600996019960299603996049960599606996079960899609996109961199612996139961499615996169961799618996199962099621996229962399624996259962699627996289962999630996319963299633996349963599636996379963899639996409964199642996439964499645996469964799648996499965099651996529965399654996559965699657996589965999660996619966299663996649966599666996679966899669996709967199672996739967499675996769967799678996799968099681996829968399684996859968699687996889968999690996919969299693996949969599696996979969899699997009970199702997039970499705997069970799708997099971099711997129971399714997159971699717997189971999720997219972299723997249972599726997279972899729997309973199732997339973499735997369973799738997399974099741997429974399744997459974699747997489974999750997519975299753997549975599756997579975899759997609976199762997639976499765997669976799768997699977099771997729977399774997759977699777997789977999780997819978299783997849978599786997879978899789997909979199792997939979499795997969979799798997999980099801998029980399804998059980699807998089980999810998119981299813998149981599816998179981899819998209982199822998239982499825998269982799828998299983099831998329983399834998359983699837998389983999840998419984299843998449984599846998479984899849998509985199852998539985499855998569985799858998599986099861998629986399864998659986699867998689986999870998719987299873998749987599876998779987899879998809988199882998839988499885998869988799888998899989099891998929989399894998959989699897998989989999900999019990299903999049990599906999079990899909999109991199912999139991499915999169991799918999199992099921999229992399924999259992699927999289992999930999319993299933999349993599936999379993899939999409994199942999439994499945999469994799948999499995099951999529995399954999559995699957999589995999960999619996299963999649996599966999679996899969999709997199972999739997499975999769997799978999799998099981999829998399984999859998699987999889998999990999919999299993999949999599996999979999899999100000100001100002100003100004100005100006100007100008100009100010100011100012100013100014100015100016100017100018100019100020100021100022100023100024100025100026100027100028100029100030100031100032100033100034100035100036100037100038100039100040100041100042100043100044100045100046100047100048100049100050100051100052100053100054100055100056100057100058100059100060100061100062100063100064100065100066100067100068100069100070100071100072100073100074100075100076100077100078100079100080100081100082100083100084100085100086100087100088100089100090100091100092100093100094100095100096100097100098100099100100100101100102100103100104100105100106100107100108100109100110100111100112100113100114100115100116100117100118100119100120100121100122100123100124100125100126100127100128100129100130100131100132100133100134100135100136100137100138100139100140100141100142100143100144100145100146100147100148100149100150100151100152100153100154100155100156100157100158100159100160100161100162100163100164100165100166100167100168100169100170100171100172100173100174100175100176100177100178100179100180100181100182100183100184100185100186100187100188100189100190100191100192100193100194100195100196100197100198100199100200100201100202100203100204100205100206100207100208100209100210100211100212100213100214100215100216100217100218100219100220100221100222100223100224100225100226100227100228100229100230100231100232100233100234100235100236100237100238100239100240100241100242100243100244100245100246100247100248100249100250100251100252100253100254100255100256100257100258100259100260100261100262100263100264100265100266100267100268100269100270100271100272100273100274100275100276100277100278100279100280100281100282100283100284100285100286100287100288100289100290100291100292100293100294100295100296100297100298100299100300100301100302100303100304100305100306100307100308100309100310100311100312100313100314100315100316100317100318100319100320100321100322100323100324100325100326100327100328100329100330100331100332100333100334100335100336100337100338100339100340100341100342100343100344100345100346100347100348100349100350100351100352100353100354100355100356100357100358100359100360100361100362100363100364100365100366100367100368100369100370100371100372100373100374100375100376100377100378100379100380100381100382100383100384100385100386100387100388100389100390100391100392100393100394100395100396100397100398100399100400100401100402100403100404100405100406100407100408100409100410100411100412100413100414100415100416100417100418100419100420100421100422100423100424100425100426100427100428100429100430100431100432100433100434100435100436100437100438100439100440100441100442100443100444100445100446100447100448100449100450100451100452100453100454100455100456100457100458100459100460100461100462100463100464100465100466100467100468100469100470100471100472100473100474100475100476100477100478100479100480100481100482100483100484100485100486100487100488100489100490100491100492100493100494100495100496100497100498100499100500100501100502100503100504100505100506100507100508100509100510100511100512100513100514100515100516100517100518100519100520100521100522100523100524100525100526100527100528100529100530100531100532100533100534100535100536100537100538100539100540100541100542100543100544100545100546100547100548100549100550100551100552100553100554100555100556100557100558100559100560100561100562100563100564100565100566100567100568100569100570100571100572100573100574100575100576100577100578100579100580100581100582100583100584100585100586100587100588100589100590100591100592100593100594100595100596100597100598100599100600100601100602100603100604100605100606100607100608100609100610100611100612100613100614100615100616100617100618100619100620100621100622100623100624100625100626100627100628100629100630100631100632100633100634100635100636100637100638100639100640100641100642100643100644100645100646100647100648100649100650100651100652100653100654100655100656100657100658100659100660100661100662100663100664100665100666100667100668100669100670100671100672100673100674100675100676100677100678100679100680100681100682100683100684100685100686100687100688100689100690100691100692100693100694100695100696100697100698100699100700100701100702100703100704100705100706100707100708100709100710100711100712100713100714100715100716100717100718100719100720100721100722100723100724100725100726100727100728100729100730100731100732100733100734100735100736100737100738100739100740100741100742100743100744100745100746100747100748100749100750100751100752100753100754100755100756100757100758100759100760100761100762100763100764100765100766100767100768100769100770100771100772100773100774100775100776100777100778100779100780100781100782100783100784100785100786100787100788100789100790100791100792100793100794100795100796100797100798100799100800100801100802100803100804100805100806100807100808100809100810100811100812100813100814100815100816100817100818100819100820100821100822100823100824100825100826100827100828100829100830100831100832100833100834100835100836100837100838100839100840100841100842100843100844100845100846100847100848100849100850100851100852100853100854100855100856100857100858100859100860100861100862100863100864100865100866100867100868100869100870100871100872100873100874100875100876100877100878100879100880100881100882100883100884100885100886100887100888100889100890100891100892100893100894100895100896100897100898100899100900100901100902100903100904100905100906100907100908100909100910100911100912100913100914100915100916100917100918100919100920100921100922100923100924100925100926100927100928100929100930100931100932100933100934100935100936100937100938100939100940100941100942100943100944100945100946100947100948100949100950100951100952100953100954100955100956100957100958100959100960100961100962100963100964100965100966100967100968100969100970100971100972100973100974100975100976100977100978100979100980100981100982100983100984100985100986100987100988100989100990100991100992100993100994100995100996100997100998100999101000101001101002101003101004101005101006101007101008101009101010101011101012101013101014101015101016101017101018101019101020101021101022101023101024101025101026101027101028101029101030101031101032101033101034101035101036101037101038101039101040101041101042101043101044101045101046101047101048101049101050101051101052101053101054101055101056101057101058101059101060101061101062101063101064101065101066101067101068101069101070101071101072101073101074101075101076101077101078101079101080101081101082101083101084101085101086101087101088101089101090101091101092101093101094101095101096101097101098101099101100101101101102101103101104101105101106101107101108101109101110101111101112101113101114101115101116101117101118101119101120101121101122101123101124101125101126101127101128101129101130101131101132101133101134101135101136101137101138101139101140101141101142101143101144101145101146101147101148101149101150101151101152101153101154101155101156101157101158101159101160101161101162101163101164101165101166101167101168101169101170101171101172101173101174101175101176101177101178101179101180101181101182101183101184101185101186101187101188101189101190101191101192101193101194101195101196101197101198101199101200101201101202101203101204101205101206101207101208101209101210101211101212101213101214101215101216101217101218101219101220101221101222101223101224101225101226101227101228101229101230101231101232101233101234101235101236101237101238101239101240101241101242101243101244101245101246101247101248101249101250101251101252101253101254101255101256101257101258101259101260101261101262101263101264101265101266101267101268101269101270101271101272101273101274101275101276101277101278101279101280101281101282101283101284101285101286101287101288101289101290101291101292101293101294101295101296101297101298101299101300101301101302101303101304101305101306101307101308101309101310101311101312101313101314101315101316101317101318101319101320101321101322101323101324101325101326101327101328101329101330101331101332101333101334101335101336101337101338101339101340101341101342101343101344101345101346101347101348101349101350101351101352101353101354101355101356101357101358101359101360101361101362101363101364101365101366101367101368101369101370101371101372101373101374101375101376101377101378101379101380101381101382101383101384101385101386101387101388101389101390101391101392101393101394101395101396101397101398101399101400101401101402101403101404101405101406101407101408101409101410101411101412101413101414101415101416101417101418101419101420101421101422101423101424101425101426101427101428101429101430101431101432101433101434101435101436101437101438101439101440101441101442101443101444101445101446101447101448101449101450101451101452101453101454101455101456101457101458101459101460101461101462101463101464101465101466101467101468101469101470101471101472101473101474101475101476101477101478101479101480101481101482101483101484101485101486101487101488101489101490101491101492101493101494101495101496101497101498101499101500101501101502101503101504101505101506101507101508101509101510101511101512101513101514101515101516101517101518101519101520101521101522101523101524101525101526101527101528101529101530101531101532101533101534101535101536101537101538101539101540101541101542101543101544101545101546101547101548101549101550101551101552101553101554101555101556101557101558101559101560101561101562101563101564101565101566101567101568101569101570101571101572101573101574101575101576101577101578101579101580101581101582101583101584101585101586101587101588101589101590101591101592101593101594101595101596101597101598101599101600101601101602101603101604101605101606101607101608101609101610101611101612101613101614101615101616101617101618101619101620101621101622101623101624101625101626101627101628101629101630101631101632101633101634101635101636101637101638101639101640101641101642101643101644101645101646101647101648101649101650101651101652101653101654101655101656101657101658101659101660101661101662101663101664101665101666101667101668101669101670101671101672101673101674101675101676101677101678101679101680101681101682101683101684101685101686101687101688101689101690101691101692101693101694101695101696101697101698101699101700101701101702101703101704101705101706101707101708101709101710101711101712101713101714101715101716101717101718101719101720101721101722101723101724101725101726101727101728101729101730101731101732101733101734101735101736101737101738101739101740101741101742101743101744101745101746101747101748101749101750101751101752101753101754101755101756101757101758101759101760101761101762101763101764101765101766101767101768101769101770101771101772101773101774101775101776101777101778101779101780101781101782101783101784101785101786101787101788101789101790101791101792101793101794101795101796101797101798101799101800101801101802101803101804101805101806101807101808101809101810101811101812101813101814101815101816101817101818101819101820101821101822101823101824101825101826101827101828101829101830101831101832101833101834101835101836101837101838101839101840101841101842101843101844101845101846101847101848101849101850101851101852101853101854101855101856101857101858101859101860101861101862101863101864101865101866101867101868101869101870101871101872101873101874101875101876101877101878101879101880101881101882101883101884101885101886101887101888101889101890101891101892101893101894101895101896101897101898101899101900101901101902101903101904101905101906101907101908101909101910101911101912101913101914101915101916101917101918101919101920101921101922101923101924101925101926101927101928101929101930101931101932101933101934101935101936101937101938101939101940101941101942101943101944101945101946101947101948101949101950101951101952101953101954101955101956101957101958101959101960101961101962101963101964101965101966101967101968101969101970101971101972101973101974101975101976101977101978101979101980101981101982101983101984101985101986101987101988101989101990101991101992101993101994101995101996101997101998101999102000102001102002102003102004102005102006102007102008102009102010102011102012102013102014102015102016102017102018102019102020102021102022102023102024102025102026102027102028102029102030102031102032102033102034102035102036102037102038102039102040102041102042102043102044102045102046102047102048102049102050102051102052102053102054102055102056102057102058102059102060102061102062102063102064102065102066102067102068102069102070102071102072102073102074102075102076102077102078102079102080102081102082102083102084102085102086102087102088102089102090102091102092102093102094102095102096102097102098102099102100102101102102102103102104102105102106102107102108102109102110102111102112102113102114102115102116102117102118102119102120102121102122102123102124102125102126102127102128102129102130102131102132102133102134102135102136102137102138102139102140102141102142102143102144102145102146102147102148102149102150102151102152102153102154102155102156102157102158102159102160102161102162102163102164102165102166102167102168102169102170102171102172102173102174102175102176102177102178102179102180102181102182102183102184102185102186102187102188102189102190102191102192102193102194102195102196102197102198102199102200102201102202102203102204102205102206102207102208102209102210102211102212102213102214102215102216102217102218102219102220102221102222102223102224102225102226102227102228102229102230102231102232102233102234102235102236102237102238102239102240102241102242102243102244102245102246102247102248102249102250102251102252102253102254102255102256102257102258102259102260102261102262102263102264102265102266102267102268102269102270102271102272102273102274102275102276102277102278102279102280102281102282102283102284102285102286102287102288102289102290102291102292102293102294102295102296102297102298102299102300102301102302102303102304102305102306102307102308102309102310102311102312102313102314102315102316102317102318102319102320102321102322102323102324102325102326102327102328102329102330102331102332102333102334102335102336102337102338102339102340102341102342102343102344102345102346102347102348102349102350102351102352102353102354102355102356102357102358102359102360102361102362102363102364102365102366102367102368102369102370102371102372102373102374102375102376102377102378102379102380102381102382102383102384102385102386102387102388102389102390102391102392102393102394102395102396102397102398102399102400102401102402102403102404102405102406102407102408102409102410102411102412102413102414102415102416102417102418102419102420102421102422102423102424102425102426102427102428102429102430102431102432102433102434102435102436102437102438102439102440102441102442102443102444102445102446102447102448102449102450102451102452102453102454102455102456102457102458102459102460102461102462102463102464102465102466102467102468102469102470102471102472102473102474102475102476102477102478102479102480102481102482102483102484102485102486102487102488102489102490102491102492102493102494102495102496102497102498102499102500102501102502102503102504102505102506102507102508102509102510102511102512102513102514102515102516102517102518102519102520102521102522102523102524102525102526102527102528102529102530102531102532102533102534102535102536102537102538102539102540102541102542102543102544102545102546102547102548102549102550102551102552102553102554102555102556102557102558102559102560102561102562102563102564102565102566102567102568102569102570102571102572102573102574102575102576102577102578102579102580102581102582102583102584102585102586102587102588102589102590102591102592102593102594102595102596102597102598102599102600102601102602102603102604102605102606102607102608102609102610102611102612102613102614102615102616102617102618102619102620102621102622102623102624102625102626102627102628102629102630102631102632102633102634102635102636102637102638102639102640102641102642102643102644102645102646102647102648102649102650102651102652102653102654102655102656102657102658102659102660102661102662102663102664102665102666102667102668102669102670102671102672102673102674102675102676102677102678102679102680102681102682102683102684102685102686102687102688102689102690102691102692102693102694102695102696102697102698102699102700102701102702102703102704102705102706102707102708102709102710102711102712102713102714102715102716102717102718102719102720102721102722102723102724102725102726102727102728102729102730102731102732102733102734102735102736102737102738102739102740102741102742102743102744102745102746102747102748102749102750102751102752102753102754102755102756102757102758102759102760102761102762102763102764102765102766102767102768102769102770102771102772102773102774102775102776102777102778102779102780102781102782102783102784102785102786102787102788102789102790102791102792102793102794102795102796102797102798102799102800102801102802102803102804102805102806102807102808102809102810102811102812102813102814102815102816102817102818102819102820102821102822102823102824102825102826102827102828102829102830102831102832102833102834102835102836102837102838102839102840102841102842102843102844102845102846102847102848102849102850102851102852102853102854102855102856102857102858102859102860102861102862102863102864102865102866102867102868102869102870102871102872102873102874102875102876102877102878102879102880102881102882102883102884102885102886102887102888102889102890102891102892102893102894102895102896102897102898102899102900102901102902102903102904102905102906102907102908102909102910102911102912102913102914102915102916102917102918102919102920102921102922102923102924102925102926102927102928102929102930102931102932102933102934102935102936102937102938102939102940102941102942102943102944102945102946102947102948102949102950102951102952102953102954102955102956102957102958102959102960102961102962102963102964102965102966102967102968102969102970102971102972102973102974102975102976102977102978102979102980102981102982102983102984102985102986102987102988102989102990102991102992102993102994102995102996102997102998102999103000103001103002103003103004103005103006103007103008103009103010103011103012103013103014103015103016103017103018103019103020103021103022103023103024103025103026103027103028103029103030103031103032103033103034103035103036103037103038103039103040103041103042103043103044103045103046103047103048103049103050103051103052103053103054103055103056103057103058103059103060103061103062103063103064103065103066103067103068103069103070103071103072103073103074103075103076103077103078103079103080103081103082103083103084103085103086103087103088103089103090103091103092103093103094103095103096103097103098103099103100103101103102103103103104103105103106103107103108103109103110103111103112103113103114103115103116103117103118103119103120103121103122103123103124103125103126103127103128103129103130103131103132103133103134103135103136103137103138103139103140103141103142103143103144103145103146103147103148103149103150103151103152103153103154103155103156103157103158103159103160103161103162103163103164103165103166103167103168103169103170103171103172103173103174103175103176103177103178103179103180103181103182103183103184103185103186103187103188103189103190103191103192103193103194103195103196103197103198103199103200103201103202103203103204103205103206103207103208103209103210103211103212103213103214103215103216103217103218103219103220103221103222103223103224103225103226103227103228103229103230103231103232103233103234103235103236103237103238103239103240103241103242103243103244103245103246103247103248103249103250103251103252103253103254103255103256103257103258103259103260103261103262103263103264103265103266103267103268103269103270103271103272103273103274103275103276103277103278103279103280103281103282103283103284103285103286103287103288103289103290103291103292103293103294103295103296103297103298103299103300103301103302103303103304103305103306103307103308103309103310103311103312103313103314103315103316103317103318103319103320103321103322103323103324103325103326103327103328103329103330103331103332103333103334103335103336103337103338103339103340103341103342103343103344103345103346103347103348103349103350103351103352103353103354103355103356103357103358103359103360103361103362103363103364103365103366103367103368103369103370103371103372103373103374103375103376103377103378103379103380103381103382103383103384103385103386103387103388103389103390103391103392103393103394103395103396103397103398103399103400103401103402103403103404103405103406103407103408103409103410103411103412103413103414103415103416103417103418103419103420103421103422103423103424103425103426103427103428103429103430103431103432103433103434103435103436103437103438103439103440103441103442103443103444103445103446103447103448103449103450103451103452103453103454103455103456103457103458103459103460103461103462103463103464103465103466103467103468103469103470103471103472103473103474103475103476103477103478103479103480103481103482103483103484103485103486103487103488103489103490103491103492103493103494103495103496103497103498103499103500103501103502103503103504103505103506103507103508103509103510103511103512103513103514103515103516103517103518103519103520103521103522103523103524103525103526103527103528103529103530103531103532103533103534103535103536103537103538103539103540103541103542103543103544103545103546103547103548103549103550103551103552103553103554103555103556103557103558103559103560103561103562103563103564103565103566103567103568103569103570103571103572103573103574103575103576103577103578103579103580103581103582103583103584103585103586103587103588103589103590103591103592103593103594103595103596103597103598103599103600103601103602103603103604103605103606103607103608103609103610103611103612103613103614103615103616103617103618103619103620103621103622103623103624103625103626103627103628103629103630103631103632103633103634103635103636103637103638103639103640103641103642103643103644103645103646103647103648103649103650103651103652103653103654103655103656103657103658103659103660103661103662103663103664103665103666103667103668103669103670103671103672103673103674103675103676103677103678103679103680103681103682103683103684103685103686103687103688103689103690103691103692103693103694103695103696103697103698103699103700103701103702103703103704103705103706103707103708103709103710103711103712103713103714103715103716103717103718103719103720103721103722103723103724103725103726103727103728103729103730103731103732103733103734103735103736103737103738103739103740103741103742103743103744103745103746103747103748103749103750103751103752103753103754103755103756103757103758103759103760103761103762103763103764103765103766103767103768103769103770103771103772103773103774103775103776103777103778103779103780103781103782103783103784103785103786103787103788103789103790103791103792103793103794103795103796103797103798103799103800103801103802103803103804103805103806103807103808103809103810103811103812103813103814103815103816103817103818103819103820103821103822103823103824103825103826103827103828103829103830103831103832103833103834103835103836103837103838103839103840103841103842103843103844103845103846103847103848103849103850103851103852103853103854103855103856103857103858103859103860103861103862103863103864103865103866103867103868103869103870103871103872103873103874103875103876103877103878103879103880103881103882103883103884103885103886103887103888103889103890103891103892103893103894103895103896103897103898103899103900103901103902103903103904103905103906103907103908103909103910103911103912103913103914103915103916103917103918103919103920103921103922103923103924103925103926103927103928103929103930103931103932103933103934103935103936103937103938103939103940103941103942103943103944103945103946103947103948103949103950103951103952103953103954103955103956103957103958103959103960103961103962103963103964103965103966103967103968103969103970103971103972103973103974103975103976103977103978103979103980103981103982103983103984103985103986103987103988103989103990103991103992103993103994103995103996103997103998103999104000104001104002104003104004104005104006104007104008104009104010104011104012104013104014104015104016104017104018104019104020104021104022104023104024104025104026104027104028104029104030104031104032104033104034104035104036104037104038104039104040104041104042104043104044104045104046104047104048104049104050104051104052104053104054104055104056104057104058104059104060104061104062104063104064104065104066104067104068104069104070104071104072104073104074104075104076104077104078104079104080104081104082104083104084104085104086104087104088104089104090104091104092104093104094104095104096104097104098104099104100104101104102104103104104104105104106104107104108104109104110104111104112104113104114104115104116104117104118104119104120104121104122104123104124104125104126104127104128104129104130104131104132104133104134104135104136104137104138104139104140104141104142104143104144104145104146104147104148104149104150104151104152104153104154104155104156104157104158104159104160104161104162104163104164104165104166104167104168104169104170104171104172104173104174104175104176104177104178104179104180104181104182104183104184104185104186104187104188104189104190104191104192104193104194104195104196104197104198104199104200104201104202104203104204104205104206104207104208104209104210104211104212104213104214104215104216104217104218104219104220104221104222104223104224104225104226104227104228104229104230104231104232104233104234104235104236104237104238104239104240104241104242104243104244104245104246104247104248104249104250104251104252104253104254104255104256104257104258104259104260104261104262104263104264104265104266104267104268104269104270104271104272104273104274104275104276104277104278104279104280104281104282104283104284104285104286104287104288104289104290104291104292104293104294104295104296104297104298104299104300104301104302104303104304104305104306104307104308104309104310104311104312104313104314104315104316104317104318104319104320104321104322104323104324104325104326104327104328104329104330104331104332104333104334104335104336104337104338104339104340104341104342104343104344104345104346104347104348104349104350104351104352104353104354104355104356104357104358104359104360104361104362104363104364104365104366104367104368104369104370104371104372104373104374104375104376104377104378104379104380104381104382104383104384104385104386104387104388104389104390104391104392104393104394104395104396104397104398104399104400104401104402104403104404104405104406104407104408104409104410104411104412104413104414104415104416104417104418104419104420104421104422104423104424104425104426104427104428104429104430104431104432104433104434104435104436104437104438104439104440104441104442104443104444104445104446104447104448104449104450104451104452104453104454104455104456104457104458104459104460104461104462104463104464104465104466104467104468104469104470104471104472104473104474104475104476104477104478104479104480104481104482104483104484104485104486104487104488104489104490104491104492104493104494104495104496104497104498104499104500104501104502104503104504104505104506104507104508104509104510104511104512104513104514104515104516104517104518104519104520104521104522104523104524104525104526104527104528104529104530104531104532104533104534104535104536104537104538104539104540104541104542104543104544104545104546104547104548104549104550104551104552104553104554104555104556104557104558104559104560104561104562104563104564104565104566104567104568104569104570104571104572104573104574104575104576104577104578104579104580104581104582104583104584104585104586104587104588104589104590104591104592104593104594104595104596104597104598104599104600104601104602104603104604104605104606104607104608104609104610104611104612104613104614104615104616104617104618104619104620104621104622104623104624104625104626104627104628104629104630104631104632104633104634104635104636104637104638104639104640104641104642104643104644104645104646104647104648104649104650104651104652104653104654104655104656104657104658104659104660104661104662104663104664104665104666104667104668104669104670104671104672104673104674104675104676104677104678104679104680104681104682104683104684104685104686104687104688104689104690104691104692104693104694104695104696104697104698104699104700104701104702104703104704104705104706104707104708104709104710104711104712104713104714104715104716104717104718104719104720104721104722104723104724104725104726104727104728104729104730104731104732104733104734104735104736104737104738104739104740104741104742104743104744104745104746104747104748104749104750104751104752104753104754104755104756104757104758104759104760104761104762104763104764104765104766104767104768104769104770104771104772104773104774104775104776104777104778104779104780104781104782104783104784104785104786104787104788104789104790104791104792104793104794104795104796104797104798104799104800104801104802104803104804104805104806104807104808104809104810104811104812104813104814104815104816104817104818104819104820104821104822104823104824104825104826104827104828104829104830104831104832104833104834104835104836104837104838104839104840104841104842104843104844104845104846104847104848104849104850104851104852104853104854104855104856104857104858104859104860104861104862104863104864104865104866104867104868104869104870104871104872104873104874104875104876104877104878104879104880104881104882104883104884104885104886104887104888104889104890104891104892104893104894104895104896104897104898104899104900104901104902104903104904104905104906104907104908104909104910104911104912104913104914104915104916104917104918104919104920104921104922104923104924104925104926104927104928104929104930104931104932104933104934104935104936104937104938104939104940104941104942104943104944104945104946104947104948104949104950104951104952104953104954104955104956104957104958104959104960104961104962104963104964104965104966104967104968104969104970104971104972104973104974104975104976104977104978104979104980104981104982104983104984104985104986104987104988104989104990104991104992104993104994104995104996104997104998104999105000105001105002105003105004105005105006105007105008105009105010105011105012105013105014105015105016105017105018105019105020105021105022105023105024105025105026105027105028105029105030105031105032105033105034105035105036105037105038105039105040105041105042105043105044105045105046105047105048105049105050105051105052105053105054105055105056105057105058105059105060105061105062105063105064105065105066105067105068105069105070105071105072105073105074105075105076105077105078105079105080105081105082105083105084105085105086105087105088105089105090105091105092105093105094105095105096105097105098105099105100105101105102105103105104105105105106105107105108105109105110105111105112105113105114105115105116105117105118105119105120105121105122105123105124105125105126105127105128105129105130105131105132105133105134105135105136105137105138105139105140105141105142105143105144105145105146105147105148105149105150105151105152105153105154105155105156105157105158105159105160105161105162105163105164105165105166105167105168105169105170105171105172105173105174105175105176105177105178105179105180105181105182105183105184105185105186105187105188105189105190105191105192105193105194105195105196105197105198105199105200105201105202105203105204105205105206105207105208105209105210105211105212105213105214105215105216105217105218105219105220105221105222105223105224105225105226105227105228105229105230105231105232105233105234105235105236105237105238105239105240105241105242105243105244105245105246105247105248105249105250105251105252105253105254105255105256105257105258105259105260105261105262105263105264105265105266105267105268105269105270105271105272105273105274105275105276105277105278105279105280105281105282105283105284105285105286105287105288105289105290105291105292105293105294105295105296105297105298105299105300105301105302105303105304105305105306105307105308105309105310105311105312105313105314105315105316105317105318105319105320105321105322105323105324105325105326105327105328105329105330105331105332105333105334105335105336105337105338105339105340105341105342105343105344105345105346105347105348105349105350105351105352105353105354105355105356105357105358105359105360105361105362105363105364105365105366105367105368105369105370105371105372105373105374105375105376105377105378105379105380105381105382105383105384105385105386105387105388105389105390105391105392105393105394105395105396105397105398105399105400105401105402105403105404105405105406105407105408105409105410105411105412105413105414105415105416105417105418105419105420105421105422105423105424105425105426105427105428105429105430105431105432105433105434105435105436105437105438105439105440105441105442105443105444105445105446105447105448105449105450105451105452105453105454105455105456105457105458105459105460105461105462105463105464105465105466105467105468105469105470105471105472105473105474105475105476105477105478105479105480105481105482105483105484105485105486105487105488105489105490105491105492105493105494105495105496105497105498105499105500105501105502105503105504105505105506105507105508105509105510105511105512105513105514105515105516105517105518105519105520105521105522105523105524105525105526105527105528105529105530105531105532105533105534105535105536105537105538105539105540105541105542105543105544105545105546105547105548105549105550105551105552105553105554105555105556105557105558105559105560105561105562105563105564105565105566105567105568105569105570105571105572105573105574105575105576105577105578105579105580105581105582105583105584105585105586105587105588105589105590105591105592105593105594105595105596105597105598105599105600105601105602105603105604105605105606105607105608105609105610105611105612105613105614105615105616105617105618105619105620105621105622105623105624105625105626105627105628105629105630105631105632105633105634105635105636105637105638105639105640105641105642105643105644105645105646105647105648105649105650105651105652105653105654105655105656105657105658105659105660105661105662105663105664105665105666105667105668105669105670105671105672105673105674105675105676105677105678105679105680105681105682105683105684105685105686105687105688105689105690105691105692105693105694105695105696105697105698105699105700105701105702105703105704105705105706105707105708105709105710105711105712105713105714105715105716105717105718105719105720105721105722105723105724105725105726105727105728105729105730105731105732105733105734105735105736105737105738105739105740105741105742105743105744105745105746105747105748105749105750105751105752105753105754105755105756105757105758105759105760105761105762105763105764105765105766105767105768105769105770105771105772105773105774105775105776105777105778105779105780105781105782105783105784105785105786105787105788105789105790105791105792105793105794105795105796105797105798105799105800105801105802105803105804105805105806105807105808105809105810105811105812105813105814105815105816105817105818105819105820105821105822105823105824105825105826105827105828105829105830105831105832105833105834105835105836105837105838105839105840105841105842105843105844105845105846105847105848105849105850105851105852105853105854105855105856105857105858105859105860105861105862105863105864105865105866105867105868105869105870105871105872105873105874105875105876105877105878105879105880105881105882105883105884105885105886105887105888105889105890105891105892105893105894105895105896105897105898105899105900105901105902105903105904105905105906105907105908105909105910105911105912105913105914105915105916105917105918105919105920105921105922105923105924105925105926105927105928105929105930105931105932105933105934105935105936105937105938105939105940105941105942105943105944105945105946105947105948105949105950105951105952105953105954105955105956105957105958105959105960105961105962105963105964105965105966105967105968105969105970105971105972105973105974105975105976105977105978105979105980105981105982105983105984105985105986105987105988105989105990105991105992105993105994105995105996105997105998105999106000106001106002106003106004106005106006106007106008106009106010106011106012106013106014106015106016106017106018106019106020106021106022106023106024106025106026106027106028106029106030106031106032106033106034106035106036106037106038106039106040106041106042106043106044106045106046106047106048106049106050106051106052106053106054106055106056106057106058106059106060106061106062106063106064106065106066106067106068106069106070106071106072106073106074106075106076106077106078106079106080106081106082106083106084106085106086106087106088106089106090106091106092106093106094106095106096106097106098106099106100106101106102106103106104106105106106106107106108106109106110106111106112106113106114106115106116106117106118106119106120106121106122106123106124106125106126106127106128106129106130106131106132106133106134106135106136106137106138106139106140106141106142106143106144106145106146106147106148106149106150106151106152106153106154106155106156106157106158106159106160106161106162106163106164106165106166106167106168106169106170106171106172106173106174106175106176106177106178106179106180106181106182106183106184106185106186106187106188106189106190106191106192106193106194106195106196106197106198106199106200106201106202106203106204106205106206106207106208106209106210106211106212106213106214106215106216106217106218106219106220106221106222106223106224106225106226106227106228106229106230106231106232106233106234106235106236106237106238106239106240106241106242106243106244106245106246106247106248106249106250106251106252106253106254106255106256106257106258106259106260106261106262106263106264106265106266106267106268106269106270106271106272106273106274106275106276106277106278106279106280106281106282106283106284106285106286106287106288106289106290106291106292106293106294106295106296106297106298106299106300106301106302106303106304106305106306106307106308106309106310106311106312106313106314106315106316106317106318106319106320106321106322106323106324106325106326106327106328106329106330106331106332106333106334106335106336106337106338106339106340106341106342106343106344106345106346106347106348106349106350106351106352106353106354106355106356106357106358106359106360106361106362106363106364106365106366106367106368106369106370106371106372106373106374106375106376106377106378106379106380106381106382106383106384106385106386106387106388106389106390106391106392106393106394106395106396106397106398106399106400106401106402106403106404106405106406106407106408106409106410106411106412106413106414106415106416106417106418106419106420106421106422106423106424106425106426106427106428106429106430106431106432106433106434106435106436106437106438106439106440106441106442106443106444106445106446106447106448106449106450106451106452106453106454106455106456106457106458106459106460106461106462106463106464106465106466106467106468106469106470106471106472106473106474106475106476106477106478106479106480106481106482106483106484106485106486106487106488106489106490106491106492106493106494106495106496106497106498106499106500106501106502106503106504106505106506106507106508106509106510106511106512106513106514106515106516106517106518106519106520106521106522106523106524106525106526106527106528106529106530106531106532106533106534106535106536106537106538106539106540106541106542106543106544106545106546106547106548106549106550106551106552106553106554106555106556106557106558106559106560106561106562106563106564106565106566106567106568106569106570106571106572106573106574106575106576106577106578106579106580106581106582106583106584106585106586106587106588106589106590106591106592106593106594106595106596106597106598106599106600106601106602106603106604106605106606106607106608106609106610106611106612106613106614106615106616106617106618106619106620106621106622106623106624106625106626106627106628106629106630106631106632106633106634106635106636106637106638106639106640106641106642106643106644106645106646106647106648106649106650106651106652106653106654106655106656106657106658106659106660106661106662106663106664106665106666106667106668106669106670106671106672106673106674106675106676106677106678106679106680106681106682106683106684106685106686106687106688106689106690106691106692106693106694106695106696106697106698106699106700106701106702106703106704106705106706106707106708106709106710106711106712106713106714106715106716106717106718106719106720106721106722106723106724106725106726106727106728106729106730106731106732106733106734106735106736106737106738106739106740106741106742106743106744106745106746106747106748106749106750106751106752106753106754106755106756106757106758106759106760106761106762106763106764106765106766106767106768106769106770106771106772106773106774106775106776106777106778106779106780106781106782106783106784106785106786106787106788106789106790106791106792106793106794106795106796106797106798106799106800106801106802106803106804106805106806106807106808106809106810106811106812106813106814106815106816106817106818106819106820106821106822106823106824106825106826106827106828106829106830106831106832106833106834106835106836106837106838106839106840106841106842106843106844106845106846106847106848106849106850106851106852106853106854106855106856106857106858106859106860106861106862106863106864106865106866106867106868106869106870106871106872106873106874106875106876106877106878106879106880106881106882106883106884106885106886106887106888106889106890106891106892106893106894106895106896106897106898106899106900106901106902106903106904106905106906106907106908106909106910106911106912106913106914106915106916106917106918106919106920106921106922106923106924106925106926106927106928106929106930106931106932106933106934106935106936106937106938106939106940106941106942106943106944106945106946106947106948106949106950106951106952106953106954106955106956106957106958106959106960106961106962106963106964106965106966106967106968106969106970106971106972106973106974106975106976106977106978106979106980106981106982106983106984106985106986106987106988106989106990106991106992106993106994106995106996106997106998106999107000107001107002107003107004107005107006107007107008107009107010107011107012107013107014107015107016107017107018107019107020107021107022107023107024107025107026107027107028107029107030107031107032107033107034107035107036107037107038107039107040107041107042107043107044107045107046107047107048107049107050107051107052107053107054107055107056107057107058107059107060107061107062107063107064107065107066107067107068107069107070107071107072107073107074107075107076107077107078107079107080107081107082107083107084107085107086107087107088107089107090107091107092107093107094107095107096107097107098107099107100107101107102107103107104107105107106107107107108107109107110107111107112107113107114107115107116107117107118107119107120107121107122107123107124107125107126107127107128107129107130107131107132107133107134107135107136107137107138107139107140107141107142107143107144107145107146107147107148107149107150107151107152107153107154107155107156107157107158107159107160107161107162107163107164107165107166107167107168107169107170107171107172107173107174107175107176107177107178107179107180107181107182107183107184107185107186107187107188107189107190107191107192107193107194107195107196107197107198107199107200107201107202107203107204107205107206107207107208107209107210107211107212107213107214107215107216107217107218107219107220107221107222107223107224107225107226107227107228107229107230107231107232107233107234107235107236107237107238107239107240107241107242107243107244107245107246107247107248107249107250107251107252107253107254107255107256107257107258107259107260107261107262107263107264107265107266107267107268107269107270107271107272107273107274107275107276107277107278107279107280107281107282107283107284107285107286107287107288107289107290107291107292107293107294107295107296107297107298107299107300107301107302107303107304107305107306107307107308107309107310107311107312107313107314107315107316107317107318107319107320107321107322107323107324107325107326107327107328107329107330107331107332107333107334107335107336107337107338107339107340107341107342107343107344107345107346107347107348107349107350107351107352107353107354107355107356107357107358107359107360107361107362107363107364107365107366107367107368107369107370107371107372107373107374107375107376107377107378107379107380107381107382107383107384107385107386107387107388107389107390107391107392107393107394107395107396107397107398107399107400107401107402107403107404107405107406107407107408107409107410107411107412107413107414107415107416107417107418107419107420107421107422107423107424107425107426107427107428107429107430107431107432107433107434107435107436107437107438107439107440107441107442107443107444107445107446107447107448107449107450107451107452107453107454107455107456107457107458107459107460107461107462107463107464107465107466107467107468107469107470107471107472107473107474107475107476107477107478107479107480107481107482107483107484107485107486107487107488107489107490107491107492107493107494107495107496107497107498107499107500107501107502107503107504107505107506107507107508107509107510107511107512107513107514107515107516107517107518107519107520107521107522107523107524107525107526107527107528107529107530107531107532107533107534107535107536107537107538107539107540107541107542107543107544107545107546107547107548107549107550107551107552107553107554107555107556107557107558107559107560107561107562107563107564107565107566107567107568107569107570107571107572107573107574107575107576107577107578107579107580107581107582107583107584107585107586107587107588107589107590107591107592107593107594107595107596107597107598107599107600107601107602107603107604107605107606107607107608107609107610107611107612107613107614107615107616107617107618107619107620107621107622107623107624107625107626107627107628107629107630107631107632107633107634107635107636107637107638107639107640107641107642107643107644107645107646107647107648107649107650107651107652107653107654107655107656107657107658107659107660107661107662107663107664107665107666107667107668107669107670107671107672107673107674107675107676107677107678107679107680107681107682107683107684107685107686107687107688107689107690107691107692107693107694107695107696107697107698107699107700107701107702107703107704107705107706107707107708107709107710107711107712107713107714107715107716107717107718107719107720107721107722107723107724107725107726107727107728107729107730107731107732107733107734107735107736107737107738107739107740107741107742107743107744107745107746107747107748107749107750107751107752107753107754107755107756107757107758107759107760107761107762107763107764107765107766107767107768107769107770107771107772107773107774107775107776107777107778107779107780107781107782107783107784107785107786107787107788107789107790107791107792107793107794107795107796107797107798107799107800107801107802107803107804107805107806107807107808107809107810107811107812107813107814107815107816107817107818107819107820107821107822107823107824107825107826107827107828107829107830107831107832107833107834107835107836107837107838107839107840107841107842107843107844107845107846107847107848107849107850107851107852107853107854107855107856107857107858107859107860107861107862107863107864107865107866107867107868107869107870107871107872107873107874107875107876107877107878107879107880107881107882107883107884107885107886107887107888107889107890107891107892107893107894107895107896107897107898107899107900107901107902107903107904107905107906107907107908107909107910107911107912107913107914107915107916107917107918107919107920107921107922107923107924107925107926107927107928107929107930107931107932107933107934107935107936107937107938107939107940107941107942107943107944107945107946107947107948107949107950107951107952107953107954107955107956107957107958107959107960107961107962107963107964107965107966107967107968107969107970107971107972107973107974107975107976107977107978107979107980107981107982107983107984107985107986107987107988107989107990107991107992107993107994107995107996107997107998107999108000108001108002108003108004108005108006108007108008108009108010108011108012108013108014108015108016108017108018108019108020108021108022108023108024108025108026108027108028108029108030108031108032108033108034108035108036108037108038108039108040108041108042108043108044108045108046108047108048108049108050108051108052108053108054108055108056108057108058108059108060108061108062108063108064108065108066108067108068108069108070108071108072108073108074108075108076108077108078108079108080108081108082108083108084108085108086108087108088108089108090108091108092108093108094108095108096108097108098108099108100108101108102108103108104108105108106108107108108108109108110108111108112108113108114108115108116108117108118108119108120108121108122108123108124108125108126108127108128108129108130108131108132108133108134108135108136108137108138108139108140108141108142108143108144108145108146108147108148108149108150108151108152108153108154108155108156108157108158108159108160108161108162108163108164108165108166108167108168108169108170108171108172108173108174108175108176108177108178108179108180108181108182108183108184108185108186108187108188108189108190108191108192108193108194108195108196108197108198108199108200108201108202108203108204108205108206108207108208108209108210108211108212108213108214108215108216108217108218108219108220108221108222108223108224108225108226108227108228108229108230108231108232108233108234108235108236108237108238108239108240108241108242108243108244108245108246108247108248108249108250108251108252108253108254108255108256108257108258108259108260108261108262108263108264108265108266108267108268108269108270108271108272108273108274108275108276108277108278108279108280108281108282108283108284108285108286108287108288108289108290108291108292108293108294108295108296108297108298108299108300108301108302108303108304108305108306108307108308108309108310108311108312108313108314108315108316108317108318108319108320108321108322108323108324108325108326108327108328108329108330108331108332108333108334108335108336108337108338108339108340108341108342108343108344108345108346108347108348108349108350108351108352108353108354108355108356108357108358108359108360108361108362108363108364108365108366108367108368108369108370108371108372108373108374108375108376108377108378108379108380108381108382108383108384108385108386108387108388108389108390108391108392108393108394108395108396108397108398108399108400108401108402108403108404108405108406108407108408108409108410108411108412108413108414108415108416108417108418108419108420108421108422108423108424108425108426108427108428108429108430108431108432108433108434108435108436108437108438108439108440108441108442108443108444108445108446108447108448108449108450108451108452108453108454108455108456108457108458108459108460108461108462108463108464108465108466108467108468108469108470108471108472108473108474108475108476108477108478108479108480108481108482108483108484108485108486108487108488108489108490108491108492108493108494108495108496108497108498108499108500108501108502108503108504108505108506108507108508108509108510108511108512108513108514108515108516108517108518108519108520108521108522108523108524108525108526108527108528108529108530108531108532108533108534108535108536108537108538108539108540108541108542108543108544108545108546108547108548108549108550108551108552108553108554108555108556108557108558108559108560108561108562108563108564108565108566108567108568108569108570108571108572108573108574108575108576108577108578108579108580108581108582108583108584108585108586108587108588108589108590108591108592108593108594108595108596108597108598108599108600108601108602108603108604108605108606108607108608108609108610108611108612108613108614108615108616108617108618108619108620108621108622108623108624108625108626108627108628108629108630108631108632108633108634108635108636108637108638108639108640108641108642108643108644108645108646108647108648108649108650108651108652108653108654108655108656108657108658108659108660108661108662108663108664108665108666108667108668108669108670108671108672108673108674108675108676108677108678108679108680108681108682108683108684108685108686108687108688108689108690108691108692108693108694108695108696108697108698108699108700108701108702108703108704108705108706108707108708108709108710108711108712108713108714108715108716108717108718108719108720108721108722108723108724108725108726108727108728108729108730108731108732108733108734108735108736108737108738108739108740108741108742108743108744108745108746108747108748108749108750108751108752108753108754108755108756108757108758108759108760108761108762108763108764108765108766108767108768108769108770108771108772108773108774108775108776108777108778108779108780108781108782108783108784108785108786108787108788108789108790108791108792108793108794108795108796108797108798108799108800108801108802108803108804108805108806108807108808108809108810108811108812108813108814108815108816108817108818108819108820108821108822108823108824108825108826108827108828108829108830108831108832108833108834108835108836108837108838108839108840108841108842108843108844108845108846108847108848108849108850108851108852108853108854108855108856108857108858108859108860108861108862108863108864108865108866108867108868108869108870108871108872108873108874108875108876108877108878108879108880108881108882108883108884108885108886108887108888108889108890108891108892108893108894108895108896108897108898108899108900108901108902108903108904108905108906108907108908108909108910108911108912108913108914108915108916108917108918108919108920108921108922108923108924108925108926108927108928108929108930108931108932108933108934108935108936108937108938108939108940108941108942108943108944108945108946108947108948108949108950108951108952108953108954108955108956108957108958108959108960108961108962108963108964108965108966108967108968108969108970108971108972108973108974108975108976108977108978108979108980108981108982108983108984108985108986108987108988108989108990108991108992108993108994108995108996108997108998108999109000109001109002109003109004109005109006109007109008109009109010109011109012109013109014109015109016109017109018109019109020109021109022109023109024109025109026109027109028109029109030109031109032109033109034109035109036109037109038109039109040109041109042109043109044109045109046109047109048109049109050109051109052109053109054109055109056109057109058109059109060109061109062109063109064109065109066109067109068109069109070109071109072109073109074109075109076109077109078109079109080109081109082109083109084109085109086109087109088109089109090109091109092109093109094109095109096109097109098109099109100109101109102109103109104109105109106109107109108109109109110109111109112109113109114109115109116109117109118109119109120109121109122109123109124109125109126109127109128109129109130109131109132109133109134109135109136109137109138109139109140109141109142109143109144109145109146109147109148109149109150109151109152109153109154109155109156109157109158109159109160109161109162109163109164109165109166109167109168109169109170109171109172109173109174109175109176109177109178109179109180109181109182109183109184109185109186109187109188109189109190109191109192109193109194109195109196109197109198109199109200109201109202109203109204109205109206109207109208109209109210109211109212109213109214109215109216109217109218109219109220109221109222109223109224109225109226109227109228109229109230109231109232109233109234109235109236109237109238109239109240109241109242109243109244109245109246109247109248109249109250109251109252109253109254109255109256109257109258109259109260109261109262109263109264109265109266109267109268109269109270109271109272109273109274109275109276109277109278109279109280109281109282109283109284109285109286109287109288109289109290109291109292109293109294109295109296109297109298109299109300109301109302109303109304109305109306109307109308109309109310109311109312109313109314109315109316109317109318109319109320109321109322109323109324109325109326109327109328109329109330109331109332109333109334109335109336109337109338109339109340109341109342109343109344109345109346109347109348109349109350109351109352109353109354109355109356109357109358109359109360109361109362109363109364109365109366109367109368109369109370109371109372109373109374109375109376109377109378109379109380109381109382109383109384109385109386109387109388109389109390109391109392109393109394109395109396109397109398109399109400109401109402109403109404109405109406109407109408109409109410109411109412109413109414109415109416109417109418109419109420109421109422109423109424109425109426109427109428109429109430109431109432109433109434109435109436109437109438109439109440109441109442109443109444109445109446109447109448109449109450109451109452109453109454109455109456109457109458109459109460109461109462109463109464109465109466109467109468109469109470109471109472109473109474109475109476109477109478109479109480109481109482109483109484109485109486109487109488109489109490109491109492109493109494109495109496109497109498109499109500109501109502109503109504109505109506109507109508109509109510109511109512109513109514109515109516109517109518109519109520109521109522109523109524109525109526109527109528109529109530109531109532109533109534109535109536109537109538109539109540109541109542109543109544109545109546109547109548109549109550109551109552109553109554109555109556109557109558109559109560109561109562109563109564109565109566109567109568109569109570109571109572109573109574109575109576109577109578109579109580109581109582109583109584109585109586109587109588109589109590109591109592109593109594109595109596109597109598109599109600109601109602109603109604109605109606109607109608109609109610109611109612109613109614109615109616109617109618109619109620109621109622109623109624109625109626109627109628109629109630109631109632109633109634109635109636109637109638109639109640109641109642109643109644109645109646109647109648109649109650109651109652109653109654109655109656109657109658109659109660109661109662109663109664109665109666109667109668109669109670109671109672109673109674109675109676109677109678109679109680109681109682109683109684109685109686109687109688109689109690109691109692109693109694109695109696109697109698109699109700109701109702109703109704109705109706109707109708109709109710109711109712109713109714109715109716109717109718109719109720109721109722109723109724109725109726109727109728109729109730109731109732109733109734109735109736109737109738109739109740109741109742109743109744109745109746109747109748109749109750109751109752109753109754109755109756109757109758109759109760109761109762109763109764109765109766109767109768109769109770109771109772109773109774109775109776109777109778109779109780109781109782109783109784109785109786109787109788109789109790109791109792109793109794109795109796109797109798109799109800109801109802109803109804109805109806109807109808109809109810109811109812109813109814109815109816109817109818109819109820109821109822109823109824109825109826109827109828109829109830109831109832109833109834109835109836109837109838109839109840109841109842109843109844109845109846109847109848109849109850109851109852109853109854109855109856109857109858109859109860109861109862109863109864109865109866109867109868109869109870109871109872109873109874109875109876109877109878109879109880109881109882109883109884109885109886109887109888109889109890109891109892109893109894109895109896109897109898109899109900109901109902109903109904109905109906109907109908109909109910109911109912109913109914109915109916109917109918109919109920109921109922109923109924109925109926109927109928109929109930109931109932109933109934109935109936109937109938109939109940109941109942109943109944109945109946109947109948109949109950109951109952109953109954109955109956109957109958109959109960109961109962109963109964109965109966109967109968109969109970109971109972109973109974109975109976109977109978109979109980109981109982109983109984109985109986109987109988109989109990109991109992109993109994109995109996109997109998109999110000110001110002110003110004110005110006110007110008110009110010110011110012110013110014110015110016110017110018110019110020110021110022110023110024110025110026110027110028110029110030110031110032110033110034110035110036110037110038110039110040110041110042110043110044110045110046110047110048110049110050110051110052110053110054110055110056110057110058110059110060110061110062110063110064110065110066110067110068110069110070110071110072110073110074110075110076110077110078110079110080110081110082110083110084110085110086110087110088110089110090110091110092110093110094110095110096110097110098110099110100110101110102110103110104110105110106110107110108110109110110110111110112110113110114110115110116110117110118110119110120110121110122110123110124110125110126110127110128110129110130110131110132110133110134110135110136110137110138110139110140110141110142110143110144110145110146110147110148110149110150110151110152110153110154110155110156110157110158110159110160110161110162110163110164110165110166110167110168110169110170110171110172110173110174110175110176110177110178110179110180110181110182110183110184110185110186110187110188110189110190110191110192110193110194110195110196110197110198110199110200110201110202110203110204110205110206110207110208110209110210110211110212110213110214110215110216110217110218110219110220110221110222110223110224110225110226110227110228110229110230110231110232110233110234110235110236110237110238110239110240110241110242110243110244110245110246110247110248110249110250110251110252110253110254110255110256110257110258110259110260110261110262110263110264110265110266110267110268110269110270110271110272110273110274110275110276110277110278110279110280110281110282110283110284110285110286110287110288110289110290110291110292110293110294110295110296110297110298110299110300110301110302110303110304110305110306110307110308110309110310110311110312110313110314110315110316110317110318110319110320110321110322110323110324110325110326110327110328110329110330110331110332110333110334110335110336110337110338110339110340110341110342110343110344110345110346110347110348110349110350110351110352110353110354110355110356110357110358110359110360110361110362110363110364110365110366110367110368110369110370110371110372110373110374110375110376110377110378110379110380110381110382110383110384110385110386110387110388110389110390110391110392110393110394110395110396110397110398110399110400110401110402110403110404110405110406110407110408110409110410110411110412110413110414110415110416110417110418110419110420110421110422110423110424110425110426110427110428110429110430110431110432110433110434110435110436110437110438110439110440110441110442110443110444110445110446110447110448110449110450110451110452110453110454110455110456110457110458110459110460110461110462110463110464110465110466110467110468110469110470110471110472110473110474110475110476110477110478110479110480110481110482110483110484110485110486110487110488110489110490110491110492110493110494110495110496110497110498110499110500110501110502110503110504110505110506110507110508110509110510110511110512110513110514110515110516110517110518110519110520110521110522110523110524110525110526110527110528110529110530110531110532110533110534110535110536110537110538110539110540110541110542110543110544110545110546110547110548110549110550110551110552110553110554110555110556110557110558110559110560110561110562110563110564110565110566110567110568110569110570110571110572110573110574110575110576110577110578110579110580110581110582110583110584110585110586110587110588110589110590110591110592110593110594110595110596110597110598110599110600110601110602110603110604110605110606110607110608110609110610110611110612110613110614110615110616110617110618110619110620110621110622110623110624110625110626110627110628110629110630110631110632110633110634110635110636110637110638110639110640110641110642110643110644110645110646110647110648110649110650110651110652110653110654110655110656110657110658110659110660110661110662110663110664110665110666110667110668110669110670110671110672110673110674110675110676110677110678110679110680110681110682110683110684110685110686110687110688110689110690110691110692110693110694110695110696110697110698110699110700110701110702110703110704110705110706110707110708110709110710110711110712110713110714110715110716110717110718110719110720110721110722110723110724110725110726110727110728110729110730110731110732110733110734110735110736110737110738110739110740110741110742110743110744110745110746110747110748110749110750110751110752110753110754110755110756110757110758110759110760110761110762110763110764110765110766110767110768110769110770110771110772110773110774110775110776110777110778110779110780110781110782110783110784110785110786110787110788110789110790110791110792110793110794110795110796110797110798110799110800110801110802110803110804110805110806110807110808110809110810110811110812110813110814110815110816110817110818110819110820110821110822110823110824110825110826110827110828110829110830110831110832110833110834110835110836110837110838110839110840110841110842110843110844110845110846110847110848110849110850110851110852110853110854110855110856110857110858110859110860110861110862110863110864110865110866110867110868110869110870110871110872110873110874110875110876110877110878110879110880110881110882110883110884110885110886110887110888110889110890110891110892110893110894110895110896110897110898110899110900110901110902110903110904110905110906110907110908110909110910110911110912110913110914110915110916110917110918110919110920110921110922110923110924110925110926110927110928110929110930110931110932110933110934110935110936110937110938110939110940110941110942110943110944110945110946110947110948110949110950110951110952110953110954110955110956110957110958110959110960110961110962110963110964110965110966110967110968110969110970110971110972110973110974110975110976110977110978110979110980110981110982110983110984110985110986110987110988110989110990110991110992110993110994110995110996110997110998110999111000111001111002111003111004111005111006111007111008111009111010111011111012111013111014111015111016111017111018111019111020111021111022111023111024111025111026111027111028111029111030111031111032111033111034111035111036111037111038111039111040111041111042111043111044111045111046111047111048111049111050111051111052111053111054111055111056111057111058111059111060111061111062111063111064111065111066111067111068111069111070111071111072111073111074111075111076111077111078111079111080111081111082111083111084111085111086111087111088111089111090111091111092111093111094111095111096111097111098111099111100111101111102111103111104111105111106111107111108111109111110111111111112111113111114111115111116111117111118111119111120111121111122111123111124111125111126111127111128111129111130111131111132111133111134111135111136111137111138111139111140111141111142111143111144111145111146111147111148111149111150111151111152111153111154111155111156111157111158111159111160111161111162111163111164111165111166111167111168111169111170111171111172111173111174111175111176111177111178111179111180111181111182111183111184111185111186111187111188111189111190111191111192111193111194111195111196111197111198111199111200111201111202111203111204111205111206111207111208111209111210111211111212111213111214111215111216111217111218111219111220111221111222111223111224111225111226111227111228111229111230111231111232111233111234111235111236111237111238111239111240111241111242111243111244111245111246111247111248111249111250111251111252111253111254111255111256111257111258111259111260111261111262111263111264111265111266111267111268111269111270111271111272111273111274111275111276111277111278111279111280111281111282111283111284111285111286111287111288111289111290111291111292111293111294111295111296111297111298111299111300111301111302111303111304111305111306111307111308111309111310111311111312111313111314111315111316111317111318111319111320111321111322111323111324111325111326111327111328111329111330111331111332111333111334111335111336111337111338111339111340111341111342111343111344111345111346111347111348111349111350111351111352111353111354111355111356111357111358111359111360111361111362111363111364111365111366111367111368111369111370111371111372111373111374111375111376111377111378111379111380111381111382111383111384111385111386111387111388111389111390111391111392111393111394111395111396111397111398111399111400111401111402111403111404111405111406111407111408111409111410111411111412111413111414111415111416111417111418111419111420111421111422111423111424111425111426111427111428111429111430111431111432111433111434111435111436111437111438111439111440111441111442111443111444111445111446111447111448111449111450111451111452111453111454111455111456111457111458111459111460111461111462111463111464111465111466111467111468111469111470111471111472111473111474111475111476111477111478111479111480111481111482111483111484111485111486111487111488111489111490111491111492111493111494111495111496111497111498111499111500111501111502111503111504111505111506111507111508111509111510111511111512111513111514111515111516111517111518111519111520111521111522111523111524111525111526111527111528111529111530111531111532111533111534111535111536111537111538111539111540111541111542111543111544111545111546111547111548111549111550111551111552111553111554111555111556111557111558111559111560111561111562111563111564111565111566111567111568111569111570111571111572111573111574111575111576111577111578111579111580111581111582111583111584111585111586111587111588111589111590111591111592111593111594111595111596111597111598111599111600111601111602111603111604111605111606111607111608111609111610111611111612111613111614111615111616111617111618111619111620111621111622111623111624111625111626111627111628111629111630111631111632111633111634111635111636111637111638111639111640111641111642111643111644111645111646111647111648111649111650111651111652111653111654111655111656111657111658111659111660111661111662111663111664111665111666111667111668111669111670111671111672111673111674111675111676111677111678111679111680111681111682111683111684111685111686111687111688111689111690111691111692111693111694111695111696111697111698111699111700111701111702111703111704111705111706111707111708111709111710111711111712111713111714111715111716111717111718111719111720111721111722111723111724111725111726111727111728111729111730111731111732111733111734111735111736111737111738111739111740111741111742111743111744111745111746111747111748111749111750111751111752111753111754111755111756111757111758111759111760111761111762111763111764111765111766111767111768111769111770111771111772111773111774111775111776111777111778111779111780111781111782111783111784111785111786111787111788111789111790111791111792111793111794111795111796111797111798111799111800111801111802111803111804111805111806111807111808111809111810111811111812111813111814111815111816111817111818111819111820111821111822111823111824111825111826111827111828111829111830111831111832111833111834111835111836111837111838111839111840111841111842111843111844111845111846111847111848111849111850111851111852111853111854111855111856111857111858111859111860111861111862111863111864111865111866111867111868111869111870111871111872111873111874111875111876111877111878111879111880111881111882111883111884111885111886111887111888111889111890111891111892111893111894111895111896111897111898111899111900111901111902111903111904111905111906111907111908111909111910111911111912111913111914111915111916111917111918111919111920111921111922111923111924111925111926111927111928111929111930111931111932111933111934111935111936111937111938111939111940111941111942111943111944111945111946111947111948111949111950111951111952111953111954111955111956111957111958111959111960111961111962111963111964111965111966111967111968111969111970111971111972111973111974111975111976111977111978111979111980111981111982111983111984111985111986111987111988111989111990111991111992111993111994111995111996111997111998111999112000112001112002112003112004112005112006112007112008112009112010112011112012112013112014112015112016112017112018112019112020112021112022112023112024112025112026112027112028112029112030112031112032112033112034112035112036112037112038112039112040112041112042112043112044112045112046112047112048112049112050112051112052112053112054112055112056112057112058112059112060112061112062112063112064112065112066112067112068112069112070112071112072112073112074112075112076112077112078112079112080112081112082112083112084112085112086112087112088112089112090112091112092112093112094112095112096112097112098112099112100112101112102112103112104112105112106112107112108112109112110112111112112112113112114112115112116112117112118112119112120112121112122112123112124112125112126112127112128112129112130112131112132112133112134112135112136112137112138112139112140112141112142112143112144112145112146112147112148112149112150112151112152112153112154112155112156112157112158112159112160112161112162112163112164112165112166112167112168112169112170112171112172112173112174112175112176112177112178112179112180112181112182112183112184112185112186112187112188112189112190112191112192112193112194112195112196112197112198112199112200112201112202112203112204112205112206112207112208112209112210112211112212112213112214112215112216112217112218112219112220112221112222112223112224112225112226112227112228112229112230112231112232112233112234112235112236112237112238112239112240112241112242112243112244112245112246112247112248112249112250112251112252112253112254112255112256112257112258112259112260112261112262112263112264112265112266112267112268112269112270112271112272112273112274112275112276112277112278112279112280112281112282112283112284112285112286112287112288112289112290112291112292112293112294112295112296112297112298112299112300112301112302112303112304112305112306112307112308112309112310112311112312112313112314112315112316112317112318112319112320112321112322112323112324112325112326112327112328112329112330112331112332112333112334112335112336112337112338112339112340112341112342112343112344112345112346112347112348112349112350112351112352112353112354112355112356112357112358112359112360112361112362112363112364112365112366112367112368112369112370112371112372112373112374112375112376112377112378112379112380112381112382112383112384112385112386112387112388112389112390112391112392112393112394112395112396112397112398112399112400112401112402112403112404112405112406112407112408112409112410112411112412112413112414112415112416112417112418112419112420112421112422112423112424112425112426112427112428112429112430112431112432112433112434112435112436112437112438112439112440112441112442112443112444112445112446112447112448112449112450112451112452112453112454112455112456112457112458112459112460112461112462112463112464112465112466112467112468112469112470112471112472112473112474112475112476112477112478112479112480112481112482112483112484112485112486112487112488112489112490112491112492112493112494112495112496112497112498112499112500112501112502112503112504112505112506112507112508112509112510112511112512112513112514112515112516112517112518112519112520112521112522112523112524112525112526112527112528112529112530112531112532112533112534112535112536112537112538112539112540112541112542112543112544112545112546112547112548112549112550112551112552112553112554112555112556112557112558112559112560112561112562112563112564112565112566112567112568112569112570112571112572112573112574112575112576112577112578112579112580112581112582112583112584112585112586112587112588112589112590112591112592112593112594112595112596112597112598112599112600112601112602112603112604112605112606112607112608112609112610112611112612112613112614112615112616112617112618112619112620112621112622112623112624112625112626112627112628112629112630112631112632112633112634112635112636112637112638112639112640112641112642112643112644112645112646112647112648112649112650112651112652112653112654112655112656112657112658112659112660112661112662112663112664112665112666112667112668112669112670112671112672112673112674112675112676112677112678112679112680112681112682112683112684112685112686112687112688112689112690112691112692112693112694112695112696112697112698112699112700112701112702112703112704112705112706112707112708112709112710112711112712112713112714112715112716112717112718112719112720112721112722112723112724112725112726112727112728112729112730112731112732112733112734112735112736112737112738112739112740112741112742112743112744112745112746112747112748112749112750112751112752112753112754112755112756112757112758112759112760112761112762112763112764112765112766112767112768112769112770112771112772112773112774112775112776112777112778112779112780112781112782112783112784112785112786112787112788112789112790112791112792112793112794112795112796112797112798112799112800112801112802112803112804112805112806112807112808112809112810112811112812112813112814112815112816112817112818112819112820112821112822112823112824112825112826112827112828112829112830112831112832112833112834112835112836112837112838112839112840112841112842112843112844112845112846112847112848112849112850112851112852112853112854112855112856112857112858112859112860112861112862112863112864112865112866112867112868112869112870112871112872112873112874112875112876112877112878112879112880112881112882112883112884112885112886112887112888112889112890112891112892112893112894112895112896112897112898112899112900112901112902112903112904112905112906112907112908112909112910112911112912112913112914112915112916112917112918112919112920112921112922112923112924112925112926112927112928112929112930112931112932112933112934112935112936112937112938112939112940112941112942112943112944112945112946112947112948112949112950112951112952112953112954112955112956112957112958112959112960112961112962112963112964112965112966112967112968112969112970112971112972112973112974112975112976112977112978112979112980112981112982112983112984112985112986112987112988112989112990112991112992112993112994112995112996112997112998112999113000113001113002113003113004113005113006113007113008113009113010113011113012113013113014113015113016113017113018113019113020113021113022113023113024113025113026113027113028113029113030113031113032113033113034113035113036113037113038113039113040113041113042113043113044113045113046113047113048113049113050113051113052113053113054113055113056113057113058113059113060113061113062113063113064113065113066113067113068113069113070113071113072113073113074113075113076113077113078113079113080113081113082113083113084113085113086113087113088113089113090113091113092113093113094113095113096113097113098113099113100113101113102113103113104113105113106113107113108113109113110113111113112113113113114113115113116113117113118113119113120113121113122113123113124113125113126113127113128113129113130113131113132113133113134113135113136113137113138113139113140113141113142113143113144113145113146113147113148113149113150113151113152113153113154113155113156113157113158113159113160113161113162113163113164113165113166113167113168113169113170113171113172113173113174113175113176113177113178113179113180113181113182113183113184113185113186113187113188113189113190113191113192113193113194113195113196113197113198113199113200113201113202113203113204113205113206113207113208113209113210113211113212113213113214113215113216113217113218113219113220113221113222113223113224113225113226113227113228113229113230113231113232113233113234113235113236113237113238113239113240113241113242113243113244113245113246113247113248113249113250113251113252113253113254113255113256113257113258113259113260113261113262113263113264113265113266113267113268113269113270113271113272113273113274113275113276113277113278113279113280113281113282113283113284113285113286113287113288113289113290113291113292113293113294113295113296113297113298113299113300113301113302113303113304113305113306113307113308113309113310113311113312113313113314113315113316113317113318113319113320113321113322113323113324113325113326113327113328113329113330113331113332113333113334113335113336113337113338113339113340113341113342113343113344113345113346113347113348113349113350113351113352113353113354113355113356113357113358113359113360113361113362113363113364113365113366113367113368113369113370113371113372113373113374113375113376113377113378113379113380113381113382113383113384113385113386113387113388113389113390113391113392113393113394113395113396113397113398113399113400113401113402113403113404113405113406113407113408113409113410113411113412113413113414113415113416113417113418113419113420113421113422113423113424113425113426113427113428113429113430113431113432113433113434113435113436113437113438113439113440113441113442113443113444113445113446113447113448113449113450113451113452113453113454113455113456113457113458113459113460113461113462113463113464113465113466113467113468113469113470113471113472113473113474113475113476113477113478113479113480113481113482113483113484113485113486113487113488113489113490113491113492113493113494113495113496113497113498113499113500113501113502113503113504113505113506113507113508113509113510113511113512113513113514113515113516113517113518113519113520113521113522113523113524113525113526113527113528113529113530113531113532113533113534113535113536113537113538113539113540113541113542113543113544113545113546113547113548113549113550113551113552113553113554113555113556113557113558113559113560113561113562113563113564113565113566113567113568113569113570113571113572113573113574113575113576113577113578113579113580113581113582113583113584113585113586113587113588113589113590113591113592113593113594113595113596113597113598113599113600113601113602113603113604113605113606113607113608113609113610113611113612113613113614113615113616113617113618113619113620113621113622113623113624113625113626113627113628113629113630113631113632113633113634113635113636113637113638113639113640113641113642113643113644113645113646113647113648113649113650113651113652113653113654113655113656113657113658113659113660113661113662113663113664113665113666113667113668113669113670113671113672113673113674113675113676113677113678113679113680113681113682113683113684113685113686113687113688113689113690113691113692113693113694113695113696113697113698113699113700113701113702113703113704113705113706113707113708113709113710113711113712113713113714113715113716113717113718113719113720113721113722113723113724113725113726113727113728113729113730113731113732113733113734113735113736113737113738113739113740113741113742113743113744113745113746113747113748113749113750113751113752113753113754113755113756113757113758113759113760113761113762113763113764113765113766113767113768113769113770113771113772113773113774113775113776113777113778113779113780113781113782113783113784113785113786113787113788113789113790113791113792113793113794113795113796113797113798113799113800113801113802113803113804113805113806113807113808113809113810113811113812113813113814113815113816113817113818113819113820113821113822113823113824113825113826113827113828113829113830113831113832113833113834113835113836113837113838113839113840113841113842113843113844113845113846113847113848113849113850113851113852113853113854113855113856113857113858113859113860113861113862113863113864113865113866113867113868113869113870113871113872113873113874113875113876113877113878113879113880113881113882113883113884113885113886113887113888113889113890113891113892113893113894113895113896113897113898113899113900113901113902113903113904113905113906113907113908113909113910113911113912113913113914113915113916113917113918113919113920113921113922113923113924113925113926113927113928113929113930113931113932113933113934113935113936113937113938113939113940113941113942113943113944113945113946113947113948113949113950113951113952113953113954113955113956113957113958113959113960113961113962113963113964113965113966113967113968113969113970113971113972113973113974113975113976113977113978113979113980113981113982113983113984113985113986113987113988113989113990113991113992113993113994113995113996113997113998113999114000114001114002114003114004114005114006114007114008114009114010114011114012114013114014114015114016114017114018114019114020114021114022114023114024114025114026114027114028114029114030114031114032114033114034114035114036114037114038114039114040114041114042114043114044114045114046114047114048114049114050114051114052114053114054114055114056114057114058114059114060114061114062114063114064114065114066114067114068114069114070114071114072114073114074114075114076114077114078114079114080114081114082114083114084114085114086114087114088114089114090114091114092114093114094114095114096114097114098114099114100114101114102114103114104114105114106114107114108114109114110114111114112114113114114114115114116114117114118114119114120114121114122114123114124114125114126114127114128114129114130114131114132114133114134114135114136114137114138114139114140114141114142114143114144114145114146114147114148114149114150114151114152114153114154114155114156114157114158114159114160114161114162114163114164114165114166114167114168114169114170114171114172114173114174114175114176114177114178114179114180114181114182114183114184114185114186114187114188114189114190114191114192114193114194114195114196114197114198114199114200114201114202114203114204114205114206114207114208114209114210114211114212114213114214114215114216114217114218114219114220114221114222114223114224114225114226114227114228114229114230114231114232114233114234114235114236114237114238114239114240114241114242114243114244114245114246114247114248114249114250114251114252114253114254114255114256114257114258114259114260114261114262114263114264114265114266114267114268114269114270114271114272114273114274114275114276114277114278114279114280114281114282114283114284114285114286114287114288114289114290114291114292114293114294114295114296114297114298114299114300114301114302114303114304114305114306114307114308114309114310114311114312114313114314114315114316114317114318114319114320114321114322114323114324114325114326114327114328114329114330114331114332114333114334114335114336114337114338114339114340114341114342114343114344114345114346114347114348114349114350114351114352114353114354114355114356114357114358114359114360114361114362114363114364114365114366114367114368114369114370114371114372114373114374114375114376114377114378114379114380114381114382114383114384114385114386114387114388114389114390114391114392114393114394114395114396114397114398114399114400114401114402114403114404114405114406114407114408114409114410114411114412114413114414114415114416114417114418114419114420114421114422114423114424114425114426114427114428114429114430114431114432114433114434114435114436114437114438114439114440114441114442114443114444114445114446114447114448114449114450114451114452114453114454114455114456114457114458114459114460114461114462114463114464114465114466114467114468114469114470114471114472114473114474114475114476114477114478114479114480114481114482114483114484114485114486114487114488114489114490114491114492114493114494114495114496114497114498114499114500114501114502114503114504114505114506114507114508114509114510114511114512114513114514114515114516114517114518114519114520114521114522114523114524114525114526114527114528114529114530114531114532114533114534114535114536114537114538114539114540114541114542114543114544114545114546114547114548114549114550114551114552114553114554114555114556114557114558114559114560114561114562114563114564114565114566114567114568114569114570114571114572114573114574114575114576114577114578114579114580114581114582114583114584114585114586114587114588114589114590114591114592114593114594114595114596114597114598114599114600114601114602114603114604114605114606114607114608114609114610114611114612114613114614114615114616114617114618114619114620114621114622114623114624114625114626114627114628114629114630114631114632114633114634114635114636114637114638114639114640114641114642114643114644114645114646114647114648114649114650114651114652114653114654114655114656114657114658114659114660114661114662114663114664114665114666114667114668114669114670114671114672114673114674114675114676114677114678114679114680114681114682114683114684114685114686114687114688114689114690114691114692114693114694114695114696114697114698114699114700114701114702114703114704114705114706114707114708114709114710114711114712114713114714114715114716114717114718114719114720114721114722114723114724114725114726114727114728114729114730114731114732114733114734114735114736114737114738114739114740114741114742114743114744114745114746114747114748114749114750114751114752114753114754114755114756114757114758114759114760114761114762114763114764114765114766114767114768114769114770114771114772114773114774114775114776114777114778114779114780114781114782114783114784114785114786114787114788114789114790114791114792114793114794114795114796114797114798114799114800114801114802114803114804114805114806114807114808114809114810114811114812114813114814114815114816114817114818114819114820114821114822114823114824114825114826114827114828114829114830114831114832114833114834114835114836114837114838114839114840114841114842114843114844114845114846114847114848114849114850114851114852114853114854114855114856114857114858114859114860114861114862114863114864114865114866114867114868114869114870114871114872114873114874114875114876114877114878114879114880114881114882114883114884114885114886114887114888114889114890114891114892114893114894114895114896114897114898114899114900114901114902114903114904114905114906114907114908114909114910114911114912114913114914114915114916114917114918114919114920114921114922114923114924114925114926114927114928114929114930114931114932114933114934114935114936114937114938114939114940114941114942114943114944114945114946114947114948114949114950114951114952114953114954114955114956114957114958114959114960114961114962114963114964114965114966114967114968114969114970114971114972114973114974114975114976114977114978114979114980114981114982114983114984114985114986114987114988114989114990114991114992114993114994114995114996114997114998114999115000115001115002115003115004115005115006115007115008115009115010115011115012115013115014115015115016115017115018115019115020115021115022115023115024115025115026115027115028115029115030115031115032115033115034115035115036115037115038115039115040115041115042115043115044115045115046115047115048115049115050115051115052115053115054115055115056115057115058115059115060115061115062115063115064115065115066115067115068115069115070115071115072115073115074115075115076115077115078115079115080115081115082115083115084115085115086115087115088115089115090115091115092115093115094115095115096115097115098115099115100115101115102115103115104115105115106115107115108115109115110115111115112115113115114115115115116115117115118115119115120115121115122115123115124115125115126115127115128115129115130115131115132115133115134115135115136115137115138115139115140115141115142115143115144115145115146115147115148115149115150115151115152115153115154115155115156115157115158115159115160115161115162115163115164115165115166115167115168115169115170115171115172115173115174115175115176115177115178115179115180115181115182115183115184115185115186115187115188115189115190115191115192115193115194115195115196115197115198115199115200115201115202115203115204115205115206115207115208115209115210115211115212115213115214115215115216115217115218115219115220115221115222115223115224115225115226115227115228115229115230115231115232115233115234115235115236115237115238115239115240115241115242115243115244115245115246115247115248115249115250115251115252115253115254115255115256115257115258115259115260115261115262115263115264115265115266115267115268115269115270115271115272115273115274115275115276115277115278115279115280115281115282115283115284115285115286115287115288115289115290115291115292115293115294115295115296115297115298115299115300115301115302115303115304115305115306115307115308115309115310115311115312115313115314115315115316115317115318115319115320115321115322115323115324115325115326115327115328115329115330115331115332115333115334115335115336115337115338115339115340115341115342115343115344115345115346115347115348115349115350115351115352115353115354115355115356115357115358115359115360115361115362115363115364115365115366115367115368115369115370115371115372115373115374115375115376115377115378115379115380115381115382115383115384115385115386115387115388115389115390115391115392115393115394115395115396115397115398115399115400115401115402115403115404115405115406115407115408115409115410115411115412115413115414115415115416115417115418115419115420115421115422115423115424115425115426115427115428115429115430115431115432115433115434115435115436115437115438115439115440115441115442115443115444115445115446115447115448115449115450115451115452115453115454115455115456115457115458115459115460115461115462115463115464115465115466115467115468115469115470115471115472115473115474115475115476115477115478115479115480115481115482115483115484115485115486115487115488115489115490115491115492115493115494115495115496115497115498115499115500115501115502115503115504115505115506115507115508115509115510115511115512115513115514115515115516115517115518115519115520115521115522115523115524115525115526115527115528115529115530115531115532115533115534115535115536115537115538115539115540115541115542115543115544115545115546115547115548115549115550115551115552115553115554115555115556115557115558115559115560115561115562115563115564115565115566115567115568115569115570115571115572115573115574115575115576115577115578115579115580115581115582115583115584115585115586115587115588115589115590115591115592115593115594115595115596115597115598115599115600115601115602115603115604115605115606115607115608115609115610115611115612115613115614115615115616115617115618115619115620115621115622115623115624115625115626115627115628115629115630115631115632115633115634115635115636115637115638115639115640115641115642115643115644115645115646115647115648115649115650115651115652115653115654115655115656115657115658115659115660115661115662115663115664115665115666115667115668115669115670115671115672115673115674115675115676115677115678115679115680115681115682115683115684115685115686115687115688115689115690115691115692115693115694115695115696115697115698115699115700115701115702115703115704115705115706115707115708115709115710115711115712115713115714115715115716115717115718115719115720115721115722115723115724115725115726115727115728115729115730115731115732115733115734115735115736115737115738115739115740115741115742115743115744115745115746115747115748115749115750115751115752115753115754115755115756115757115758115759115760115761115762115763115764115765115766115767115768115769115770115771115772115773115774115775115776115777115778115779115780115781115782115783115784115785115786115787115788115789115790115791115792115793115794115795115796115797115798115799115800115801115802115803115804115805115806115807115808115809115810115811115812115813115814115815115816115817115818115819115820115821115822115823115824115825115826115827115828115829115830115831115832115833115834115835115836115837115838115839115840115841115842115843115844115845115846115847115848115849115850115851115852115853115854115855115856115857115858115859115860115861115862115863115864115865115866115867115868115869115870115871115872115873115874115875115876115877115878115879115880115881115882115883115884115885115886115887115888115889115890115891115892115893115894115895115896115897115898115899115900115901115902115903115904115905115906115907115908115909115910115911115912115913115914115915115916115917115918115919115920115921115922115923115924115925115926115927115928115929115930115931115932115933115934115935115936115937115938115939115940115941115942115943115944115945115946115947115948115949115950115951115952115953115954115955115956115957115958115959115960115961115962115963115964115965115966115967115968115969115970115971115972115973115974115975115976115977115978115979115980115981115982115983115984115985115986115987115988115989115990115991115992115993115994115995115996115997115998115999116000116001116002116003116004116005116006116007116008116009116010116011116012116013116014116015116016116017116018116019116020116021116022116023116024116025116026116027116028116029116030116031116032116033116034116035116036116037116038116039116040116041116042116043116044116045116046116047116048116049116050116051116052116053116054116055116056116057116058116059116060116061116062116063116064116065116066116067116068116069116070116071116072116073116074116075116076116077116078116079116080116081116082116083116084116085116086116087116088116089116090116091116092116093116094116095116096116097116098116099116100116101116102116103116104116105116106116107116108116109116110116111116112116113116114116115116116116117116118116119116120116121116122116123116124116125116126116127116128116129116130116131116132116133116134116135116136116137116138116139116140116141116142116143116144116145116146116147116148116149116150116151116152116153116154116155116156116157116158116159116160116161116162116163116164116165116166116167116168116169116170116171116172116173116174116175116176116177116178116179116180116181116182116183116184116185116186116187116188116189116190116191116192116193116194116195116196116197116198116199116200116201116202116203116204116205116206116207116208116209116210116211116212116213116214116215116216116217116218116219116220116221116222116223116224116225116226116227116228116229116230116231116232116233116234116235116236116237116238116239116240116241116242116243116244116245116246116247116248116249116250116251116252116253116254116255116256116257116258116259116260116261116262116263116264116265116266116267116268116269116270116271116272116273116274116275116276116277116278116279116280116281116282116283116284116285116286116287116288116289116290116291116292116293116294116295116296116297116298116299116300116301116302116303116304116305116306116307116308116309116310116311116312116313116314116315116316116317116318116319116320116321116322116323116324116325116326116327116328116329116330116331116332116333116334116335116336116337116338116339116340116341116342116343116344116345116346116347116348116349116350116351116352116353116354116355116356116357116358116359116360116361116362116363116364116365116366116367116368116369116370116371116372116373116374116375116376116377116378116379116380116381116382116383116384116385116386116387116388116389116390116391116392116393116394116395116396116397116398116399116400116401116402116403116404116405116406116407116408116409116410116411116412116413116414116415116416116417116418116419116420116421116422116423116424116425116426116427116428116429116430116431116432116433116434116435116436116437116438116439116440116441116442116443116444116445116446116447116448116449116450116451116452116453116454116455116456116457116458116459116460116461116462116463116464116465116466116467116468116469116470116471116472116473116474116475116476116477116478116479116480116481116482116483116484116485116486116487116488116489116490116491116492116493116494116495116496116497116498116499116500116501116502116503116504116505116506116507116508116509116510116511116512116513116514116515116516116517116518116519116520116521116522116523116524116525116526116527116528116529116530116531116532116533116534116535116536116537116538116539116540116541116542116543116544116545116546116547116548116549116550116551116552116553116554116555116556116557116558116559116560116561116562116563116564116565116566116567116568116569116570116571116572116573116574116575116576116577116578116579116580116581116582116583116584116585116586116587116588116589116590116591116592116593116594116595116596116597116598116599116600116601116602116603116604116605116606116607116608116609116610116611116612116613116614116615116616116617116618116619116620116621116622116623116624116625116626116627116628116629116630116631116632116633116634116635116636116637116638116639116640116641116642116643116644116645116646116647116648116649116650116651116652116653116654116655116656116657116658116659116660116661116662116663116664116665116666116667116668116669116670116671116672116673116674116675116676116677116678116679116680116681116682116683116684116685116686116687116688116689116690116691116692116693116694116695116696116697116698116699116700116701116702116703116704116705116706116707116708116709116710116711116712116713116714116715116716116717116718116719116720116721116722116723116724116725116726116727116728116729116730116731116732116733116734116735116736116737116738116739116740116741116742116743116744116745116746116747116748116749116750116751116752116753116754116755116756116757116758116759116760116761116762116763116764116765116766116767116768116769116770116771116772116773116774116775116776116777116778116779116780116781116782116783116784116785116786116787116788116789116790116791116792116793116794116795116796116797116798116799116800116801116802116803116804116805116806116807116808116809116810116811116812116813116814116815116816116817116818116819116820116821116822116823116824116825116826116827116828116829116830116831116832116833116834116835116836116837116838116839116840116841116842116843116844116845116846116847116848116849116850116851116852116853116854116855116856116857116858116859116860116861116862116863116864116865116866116867116868116869116870116871116872116873116874116875116876116877116878116879116880116881116882116883116884116885116886116887116888116889116890116891116892116893116894116895116896116897116898116899116900116901116902116903116904116905116906116907116908116909116910116911116912116913116914116915116916116917116918116919116920116921116922116923116924116925116926116927116928116929116930116931116932116933116934116935116936116937116938116939116940116941116942116943116944116945116946116947116948116949116950116951116952116953116954116955116956116957116958116959116960116961116962116963116964116965116966116967116968116969116970116971116972116973116974116975116976116977116978116979116980116981116982116983116984116985116986116987116988116989116990116991116992116993116994116995116996116997116998116999117000117001117002117003117004117005117006117007117008117009117010117011117012117013117014117015117016117017117018117019117020117021117022117023117024117025117026117027117028117029117030117031117032117033117034117035117036117037117038117039117040117041117042117043117044117045117046117047117048117049117050117051117052117053117054117055117056117057117058117059117060117061117062117063117064117065117066117067117068117069117070117071117072117073117074117075117076117077117078117079117080117081117082117083117084117085117086117087117088117089117090117091117092117093117094117095117096117097117098117099117100117101117102117103117104117105117106117107117108117109117110117111117112117113117114117115117116117117117118117119117120117121117122117123117124117125117126117127117128117129117130117131117132117133117134117135117136117137117138117139117140117141117142117143117144117145117146117147117148117149117150117151117152117153117154117155117156117157117158117159117160117161117162117163117164117165117166117167117168117169117170117171117172117173117174117175117176117177117178117179117180117181117182117183117184117185117186117187117188117189117190117191117192117193117194117195117196117197117198117199117200117201117202117203117204117205117206117207117208117209117210117211117212117213117214117215117216117217117218117219117220117221117222117223117224117225117226117227117228117229117230117231117232117233117234117235117236117237117238117239117240117241117242117243117244117245117246117247117248117249117250117251117252117253117254117255117256117257117258117259117260117261117262117263117264117265117266117267117268117269117270117271117272117273117274117275117276117277117278117279117280117281117282117283117284117285117286117287117288117289117290117291117292117293117294117295117296117297117298117299117300117301117302117303117304117305117306117307117308117309117310117311117312117313117314117315117316117317117318117319117320117321117322117323117324117325117326117327117328117329117330117331117332117333117334117335117336117337117338117339117340117341117342117343117344117345117346117347117348117349117350117351117352117353117354117355117356117357117358117359117360117361117362117363117364117365117366117367117368117369117370117371117372117373117374117375117376117377117378117379117380117381117382117383117384117385117386117387117388117389117390117391117392117393117394117395117396117397117398117399117400117401117402117403117404117405117406117407117408117409117410117411117412117413117414117415117416117417117418117419117420117421117422117423117424117425117426117427117428117429117430117431117432117433117434117435117436117437117438117439117440117441117442117443117444117445117446117447117448117449117450117451117452117453117454117455117456117457117458117459117460117461117462117463117464117465117466117467117468117469117470117471117472117473117474117475117476117477117478117479117480117481117482117483117484117485117486117487117488117489117490117491117492117493117494117495117496117497117498117499117500117501117502117503117504117505117506117507117508117509117510117511117512117513117514117515117516117517117518117519117520117521117522117523117524117525117526117527117528117529117530117531117532117533117534117535117536117537117538117539117540117541117542117543117544117545117546117547117548117549117550117551117552117553117554117555117556117557117558117559117560117561117562117563117564117565117566117567117568117569117570117571117572117573117574117575117576117577117578117579117580117581117582117583117584117585117586117587117588117589117590117591117592117593117594117595117596117597117598117599117600117601117602117603117604117605117606117607117608117609117610117611117612117613117614117615117616117617117618117619117620117621117622117623117624117625117626117627117628117629117630117631117632117633117634117635117636117637117638117639117640117641117642117643117644117645117646117647117648117649117650117651117652117653117654117655117656117657117658117659117660117661117662117663117664117665117666117667117668117669117670117671117672117673117674117675117676117677117678117679117680117681117682117683117684117685117686117687117688117689117690117691117692117693117694117695117696117697117698117699117700117701117702117703117704117705117706117707117708117709117710117711117712117713117714117715117716117717117718117719117720117721117722117723117724117725117726117727117728117729117730117731117732117733117734117735117736117737117738117739117740117741117742117743117744117745117746117747117748117749117750117751117752117753117754117755117756117757117758117759117760117761117762117763117764117765117766117767117768117769117770117771117772117773117774117775117776117777117778117779117780117781117782117783117784117785117786117787117788117789117790117791117792117793117794117795117796117797117798117799117800117801117802117803117804117805117806117807117808117809117810117811117812117813117814117815117816117817117818117819117820117821117822117823117824117825117826117827117828117829117830117831117832117833117834117835117836117837117838117839117840117841117842117843117844117845117846117847117848117849117850117851117852117853117854117855117856117857117858117859117860117861117862117863117864117865117866117867117868117869117870117871117872117873117874117875117876117877117878117879117880117881117882117883117884117885117886117887117888117889117890117891117892117893117894117895117896117897117898117899117900117901117902117903117904117905117906117907117908117909117910117911117912117913117914117915117916117917117918117919117920117921117922117923117924117925117926117927117928117929117930117931117932117933117934117935117936117937117938117939117940117941117942117943117944117945117946117947117948117949117950117951117952117953117954117955117956117957117958117959117960117961117962117963117964117965117966117967117968117969117970117971117972117973117974117975117976117977117978117979117980117981117982117983117984117985117986117987117988117989117990117991117992117993117994117995117996117997117998117999118000118001118002118003118004118005118006118007118008118009118010118011118012118013118014118015118016118017118018118019118020118021118022118023118024118025118026118027118028118029118030118031118032118033118034118035118036118037118038118039118040118041118042118043118044118045118046118047118048118049118050118051118052118053118054118055118056118057118058118059118060118061118062118063118064118065118066118067118068118069118070118071118072118073118074118075118076118077118078118079118080118081118082118083118084118085118086118087118088118089118090118091118092118093118094118095118096118097118098118099118100118101118102118103118104118105118106118107118108118109118110118111118112118113118114118115118116118117118118118119118120118121118122118123118124118125118126118127118128118129118130118131118132118133118134118135118136118137118138118139118140118141118142118143118144118145118146118147118148118149118150118151118152118153118154118155118156118157118158118159118160118161118162118163118164118165118166118167118168118169118170118171118172118173118174118175118176118177118178118179118180118181118182118183118184118185118186118187118188118189118190118191118192118193118194118195118196118197118198118199118200118201118202118203118204118205118206118207118208118209118210118211118212118213118214118215118216118217118218118219118220118221118222118223118224118225118226118227118228118229118230118231118232118233118234118235118236118237118238118239118240118241118242118243118244118245118246118247118248118249118250118251118252118253118254118255118256118257118258118259118260118261118262118263118264118265118266118267118268118269118270118271118272118273118274118275118276118277118278118279118280118281118282118283118284118285118286118287118288118289118290118291118292118293118294118295118296118297118298118299118300118301118302118303118304118305118306118307118308118309118310118311118312118313118314118315118316118317118318118319118320118321118322118323118324118325118326118327118328118329118330118331118332118333118334118335118336118337118338118339118340118341118342118343118344118345118346118347118348118349118350118351118352118353118354118355118356118357118358118359118360118361118362118363118364118365118366118367118368118369118370118371118372118373118374118375118376118377118378118379118380118381118382118383118384118385118386118387118388118389118390118391118392118393118394118395118396118397118398118399118400118401118402118403118404118405118406118407118408118409118410118411118412118413118414118415118416118417118418118419118420118421118422118423118424118425118426118427118428118429118430118431118432118433118434118435118436118437118438118439118440118441118442118443118444118445118446118447118448118449118450118451118452118453118454118455118456118457118458118459118460118461118462118463118464118465118466118467118468118469118470118471118472118473118474118475118476118477118478118479118480118481118482118483118484118485118486118487118488118489118490118491118492118493118494118495118496118497118498118499118500118501118502118503118504118505118506118507118508118509118510118511118512118513118514118515118516118517118518118519118520118521118522118523118524118525118526118527118528118529118530118531118532118533118534118535118536118537118538118539118540118541118542118543118544118545118546118547118548118549118550118551118552118553118554118555118556118557118558118559118560118561118562118563118564118565118566118567118568118569118570118571118572118573118574118575118576118577118578118579118580118581118582118583118584118585118586118587118588118589118590118591118592118593118594118595118596118597118598118599118600118601118602118603118604118605118606118607118608118609118610118611118612118613118614118615118616118617118618118619118620118621118622118623118624118625118626118627118628118629118630118631118632118633118634118635118636118637118638118639118640118641118642118643118644118645118646118647118648118649118650118651118652118653118654118655118656118657118658118659118660118661118662118663118664118665118666118667118668118669118670118671118672118673118674118675118676118677118678118679118680118681118682118683118684118685118686118687118688118689118690118691118692118693118694118695118696118697118698118699118700118701118702118703118704118705118706118707118708118709118710118711118712118713118714118715118716118717118718118719118720118721118722118723118724118725118726118727118728118729118730118731118732118733118734118735118736118737118738118739118740118741118742118743118744118745118746118747118748118749118750118751118752118753118754118755118756118757118758118759118760118761118762118763118764118765118766118767118768118769118770118771118772118773118774118775118776118777118778118779118780118781118782118783118784118785118786118787118788118789118790118791118792118793118794118795118796118797118798118799118800118801118802118803118804118805118806118807118808118809118810118811118812118813118814118815118816118817118818118819118820118821118822118823118824118825118826118827118828118829118830118831118832118833118834118835118836118837118838118839118840118841118842118843118844118845118846118847118848118849118850118851118852118853118854118855118856118857118858118859118860118861118862118863118864118865118866118867118868118869118870118871118872118873118874118875118876118877118878118879118880118881118882118883118884118885118886118887118888118889118890118891118892118893118894118895118896118897118898118899118900118901118902118903118904118905118906118907118908118909118910118911118912118913118914118915118916118917118918118919118920118921118922118923118924118925118926118927118928118929118930118931118932118933118934118935118936118937118938118939118940118941118942118943118944118945118946118947118948118949118950118951118952118953118954118955118956118957118958118959118960118961118962118963118964118965118966118967118968118969118970118971118972118973118974118975118976118977118978118979118980118981118982118983118984118985118986118987118988118989118990118991118992118993118994118995118996118997118998118999119000119001119002119003119004119005119006119007119008119009119010119011119012119013119014119015119016119017119018119019119020119021119022119023119024119025119026119027119028119029119030119031119032119033119034119035119036119037119038119039119040119041119042119043119044119045119046119047119048119049119050119051119052119053119054119055119056119057119058119059119060119061119062119063119064119065119066119067119068119069119070119071119072119073119074119075119076119077119078119079119080119081119082119083119084119085119086119087119088119089119090119091119092119093119094119095119096119097119098119099119100119101119102119103119104119105119106119107119108119109119110119111119112119113119114119115119116119117119118119119119120119121119122119123119124119125119126119127119128119129119130119131119132119133119134119135119136119137119138119139119140119141119142119143119144119145119146119147119148119149119150119151119152119153119154119155119156119157119158119159119160119161119162119163119164119165119166119167119168119169119170119171119172119173119174119175119176119177119178119179119180119181119182119183119184119185119186119187119188119189119190119191119192119193119194119195119196119197119198119199119200119201119202119203119204119205119206119207119208119209119210119211119212119213119214119215119216119217119218119219119220119221119222119223119224119225119226119227119228119229119230119231119232119233119234119235119236119237119238119239119240119241119242119243119244119245119246119247119248119249119250119251119252119253119254119255119256119257119258119259119260119261119262119263119264119265119266119267119268119269119270119271119272119273119274119275119276119277119278119279119280119281119282119283119284119285119286119287119288119289119290119291119292119293119294119295119296119297119298119299119300119301119302119303119304119305119306119307119308119309119310119311119312119313119314119315119316119317119318119319119320119321119322119323119324119325119326119327119328119329119330119331119332119333119334119335119336119337119338119339119340119341119342119343119344119345119346119347119348119349119350119351119352119353119354119355119356119357119358119359119360119361119362119363119364119365119366119367119368119369119370119371119372119373119374119375119376119377119378119379119380119381119382119383119384119385119386119387119388119389119390119391119392119393119394119395119396119397119398119399119400119401119402119403119404119405119406119407119408119409119410119411119412119413119414119415119416119417119418119419119420119421119422119423119424119425119426119427119428119429119430119431119432119433119434119435119436119437119438119439119440119441119442119443119444119445119446119447119448119449119450119451119452119453119454119455119456119457119458119459119460119461119462119463119464119465119466119467119468119469119470119471119472119473119474119475119476119477119478119479119480119481119482119483119484119485119486119487119488119489119490119491119492119493119494119495119496119497119498119499119500119501119502119503119504119505119506119507119508119509119510119511119512119513119514119515119516119517119518119519119520119521119522119523119524119525119526119527119528119529119530119531119532119533119534119535119536119537119538119539119540119541119542119543119544119545119546119547119548119549119550119551119552119553119554119555119556119557119558119559119560119561119562119563119564119565119566119567119568119569119570119571119572119573119574119575119576119577119578119579119580119581119582119583119584119585119586119587119588119589119590119591119592119593119594119595119596119597119598119599119600119601119602119603119604119605119606119607119608119609119610119611119612119613119614119615119616119617119618119619119620119621119622119623119624119625119626119627119628119629119630119631119632119633119634119635119636119637119638119639119640119641119642119643119644119645119646119647119648119649119650119651119652119653119654119655119656119657119658119659119660119661119662119663119664119665119666119667119668119669119670119671119672119673119674119675119676119677119678119679119680119681119682119683119684119685119686119687119688119689119690119691119692119693119694119695119696119697119698119699119700119701119702119703119704119705119706119707119708119709119710119711119712119713119714119715119716119717119718119719119720119721119722119723119724119725119726119727119728119729119730119731119732119733119734119735119736119737119738119739119740119741119742119743119744119745119746119747119748119749119750119751119752119753119754119755119756119757119758119759119760119761119762119763119764119765119766119767119768119769119770119771119772119773119774119775119776119777119778119779119780119781119782119783119784119785119786119787119788119789119790119791119792119793119794119795119796119797119798119799119800119801119802119803119804119805119806119807119808119809119810119811119812119813119814119815119816119817119818119819119820119821119822119823119824119825119826119827119828119829119830119831119832119833119834119835119836119837119838119839119840119841119842119843119844119845119846119847119848119849119850119851119852119853119854119855119856119857119858119859119860119861119862119863119864119865119866119867119868119869119870119871119872119873119874119875119876119877119878119879119880119881119882119883119884119885119886119887119888119889119890119891119892119893119894119895119896119897119898119899119900119901119902119903119904119905119906119907119908119909119910119911119912119913119914119915119916119917119918119919119920119921119922119923119924119925119926119927119928119929119930119931119932119933119934119935119936119937119938119939119940119941119942119943119944119945119946119947119948119949119950119951119952119953119954119955119956119957119958119959119960119961119962119963119964119965119966119967119968119969119970119971119972119973119974119975119976119977119978119979119980119981119982119983119984119985119986119987119988119989119990119991119992119993119994119995119996119997119998119999120000120001120002120003120004120005120006120007120008120009120010120011120012120013120014120015120016120017120018120019120020120021120022120023120024120025120026120027120028120029120030120031120032120033120034120035120036120037120038120039120040120041120042120043120044120045120046120047120048120049120050120051120052120053120054120055120056120057120058120059120060120061120062120063120064120065120066120067120068120069120070120071120072120073120074120075120076120077120078120079120080120081120082120083120084120085120086120087120088120089120090120091120092120093120094120095120096120097120098120099120100120101120102120103120104120105120106120107120108120109120110120111120112120113120114120115120116120117120118120119120120120121120122120123120124120125120126120127120128120129120130120131120132120133120134120135120136120137120138120139120140120141120142120143120144120145120146120147120148120149120150120151120152120153120154120155120156120157120158120159120160120161120162120163120164120165120166120167120168120169120170120171120172120173120174120175120176120177120178120179120180120181120182120183120184120185120186120187120188120189120190120191120192120193120194120195120196120197120198120199120200120201120202120203120204120205120206120207120208120209120210120211120212120213120214120215120216120217120218120219120220120221120222120223120224120225120226120227120228120229120230120231120232120233120234120235120236120237120238120239120240120241120242120243120244120245120246120247120248120249120250120251120252120253120254120255120256120257120258120259120260120261120262120263120264120265120266120267120268120269120270120271120272120273120274120275120276120277120278120279120280120281120282120283120284120285120286120287120288120289120290120291120292120293120294120295120296120297120298120299120300120301120302120303120304120305120306120307120308120309120310120311120312120313120314120315120316120317120318120319120320120321120322120323120324120325120326120327120328120329120330120331120332120333120334120335120336120337120338120339120340120341120342120343120344120345120346120347120348120349120350120351120352120353120354120355120356120357120358120359120360120361120362120363120364120365120366120367120368120369120370120371120372120373120374120375120376120377120378120379120380120381120382120383120384120385120386120387120388120389120390120391120392120393120394120395120396120397120398120399120400120401120402120403120404120405120406120407120408120409120410120411120412120413120414120415120416120417120418120419120420120421120422120423120424120425120426120427120428120429120430120431120432120433120434120435120436120437120438120439120440120441120442120443120444120445120446120447120448120449120450120451120452120453120454120455120456120457120458120459120460120461120462120463120464120465120466120467120468120469120470120471120472120473120474120475120476120477120478120479120480120481120482120483120484120485120486120487120488120489120490120491120492120493120494120495120496120497120498120499120500120501120502120503120504120505120506120507120508120509120510120511120512120513120514120515120516120517120518120519120520120521120522120523120524120525120526120527120528120529120530120531120532120533120534120535120536120537120538120539120540120541120542120543120544120545120546120547120548120549120550120551120552120553120554120555120556120557120558120559120560120561120562120563120564120565120566120567120568120569120570120571120572120573120574120575120576120577120578120579120580120581120582120583120584120585120586120587120588120589120590120591120592120593120594120595120596120597120598120599120600120601120602120603120604120605120606120607120608120609120610120611120612120613120614120615120616120617120618120619120620120621120622120623120624120625120626120627120628120629120630120631120632120633120634120635120636120637120638120639120640120641120642120643120644120645120646120647120648120649120650120651120652120653120654120655120656120657120658120659120660120661120662120663120664120665120666120667120668120669120670120671120672120673120674120675120676120677120678120679120680120681120682120683120684120685120686120687120688120689120690120691120692120693120694120695120696120697120698120699120700120701120702120703120704120705120706120707120708120709120710120711120712120713120714120715120716120717120718120719120720120721120722120723120724120725120726120727120728120729120730120731120732120733120734120735120736120737120738120739120740120741120742120743120744120745120746120747120748120749120750120751120752120753120754120755120756120757120758120759120760120761120762120763120764120765120766120767120768120769120770120771120772120773120774120775120776120777120778120779120780120781120782120783120784120785120786120787120788120789120790120791120792120793120794120795120796120797120798120799120800120801120802120803120804120805120806120807120808120809120810120811120812120813120814120815120816120817120818120819120820120821120822120823120824120825120826120827120828120829120830120831120832120833120834120835120836120837120838120839120840120841120842120843120844120845120846120847120848120849120850120851120852120853120854120855120856120857120858120859120860120861120862120863120864120865120866120867120868120869120870120871120872120873120874120875120876120877120878120879120880120881120882120883120884120885120886120887120888120889120890120891120892120893120894120895120896120897120898120899120900120901120902120903120904120905120906120907120908120909120910120911120912120913120914120915120916120917120918120919120920120921120922120923120924120925120926120927120928120929120930120931120932120933120934120935120936120937120938120939120940120941120942120943120944120945120946120947120948120949120950120951120952120953120954120955120956120957120958120959120960120961120962120963120964120965120966120967120968120969120970120971120972120973120974120975120976120977120978120979120980120981120982120983120984120985120986120987120988120989120990120991120992120993120994120995120996120997120998120999121000121001121002121003121004121005121006121007121008121009121010121011121012121013121014121015121016121017121018121019121020121021121022121023121024121025121026121027121028121029121030121031121032121033121034121035121036121037121038121039121040121041121042121043121044121045121046121047121048121049121050121051121052121053121054121055121056121057121058121059121060121061121062121063121064121065121066121067121068121069121070121071121072121073121074121075121076121077121078121079121080121081121082121083121084121085121086121087121088121089121090121091121092121093121094121095121096121097121098121099121100121101121102121103121104121105121106121107121108121109121110121111121112121113121114121115121116121117121118121119121120121121121122121123121124121125121126121127121128121129121130121131121132121133121134121135121136121137121138121139121140121141121142121143121144121145121146121147121148121149121150121151121152121153121154121155121156121157121158121159121160121161121162121163121164121165121166121167121168121169121170121171121172121173121174121175121176121177121178121179121180121181121182121183121184121185121186121187121188121189121190121191121192121193121194121195121196121197121198121199121200121201121202121203121204121205121206121207121208121209121210121211121212121213121214121215121216121217121218121219121220121221121222121223121224121225121226121227121228121229121230121231121232121233121234121235121236121237121238121239121240121241121242121243121244121245121246121247121248121249121250121251121252121253121254121255121256121257121258121259121260121261121262121263121264121265121266121267121268121269121270121271121272121273121274121275121276121277121278121279121280121281121282121283121284121285121286121287121288121289121290121291121292121293121294121295121296121297121298121299121300121301121302121303121304121305121306121307121308121309121310121311121312121313121314121315121316121317121318121319121320121321121322121323121324121325121326121327121328121329121330121331121332121333121334121335121336121337121338121339121340121341121342121343121344121345121346121347121348121349121350121351121352121353121354121355121356121357121358121359121360121361121362121363121364121365121366121367121368121369121370121371121372121373121374121375121376121377121378121379121380121381121382121383121384121385121386121387121388121389121390121391121392121393121394121395121396121397121398121399121400121401121402121403121404121405121406121407121408121409121410121411121412121413121414121415121416121417121418121419121420121421121422121423121424121425121426121427121428121429121430121431121432121433121434121435121436121437121438121439121440121441121442121443121444121445121446121447121448121449121450121451121452121453121454121455121456121457121458121459121460121461121462121463121464121465121466121467121468121469121470121471121472121473121474121475121476121477121478121479121480121481121482121483121484121485121486121487121488121489121490121491121492121493121494121495121496121497121498121499121500121501121502121503121504121505121506121507121508121509121510121511121512121513121514121515121516121517121518121519121520121521121522121523121524121525121526121527121528121529121530121531121532121533121534121535121536121537121538121539121540121541121542121543121544121545121546121547121548121549121550121551121552121553121554121555121556121557121558121559121560121561121562121563121564121565121566121567121568121569121570121571121572121573121574121575121576121577121578121579121580121581121582121583121584121585121586121587121588121589121590121591121592121593121594121595121596121597121598121599121600121601121602121603121604121605121606121607121608121609121610121611121612121613121614121615121616121617121618121619121620121621121622121623121624121625121626121627121628121629121630121631121632121633121634121635121636121637121638121639121640121641121642121643121644121645121646121647121648121649121650121651121652121653121654121655121656121657121658121659121660121661121662121663121664121665121666121667121668121669121670121671121672121673121674121675121676121677121678121679121680121681121682121683121684121685121686121687121688121689121690121691121692121693121694121695121696121697121698121699121700121701121702121703121704121705121706121707121708121709121710121711121712121713121714121715121716121717121718121719121720121721121722121723121724121725121726121727121728121729121730121731121732121733121734121735121736121737121738121739121740121741121742121743121744121745121746121747121748121749121750121751121752121753121754121755121756121757121758121759121760121761121762121763121764121765121766121767121768121769121770121771121772121773121774121775121776121777121778121779121780121781121782121783121784121785121786121787121788121789121790121791121792121793121794121795121796121797121798121799121800121801121802121803121804121805121806121807121808121809121810121811121812121813121814121815121816121817121818121819121820121821121822121823121824121825121826121827121828121829121830121831121832121833121834121835121836121837121838121839121840121841121842121843121844121845121846121847121848121849121850121851121852121853121854121855121856121857121858121859121860121861121862121863121864121865121866121867121868121869121870121871121872121873121874121875121876121877121878121879121880121881121882121883121884121885121886121887121888121889121890121891121892121893121894121895121896121897121898121899121900121901121902121903121904121905121906121907121908121909121910121911121912121913121914121915121916121917121918121919121920121921121922121923121924121925121926121927121928121929121930121931121932121933121934121935121936121937121938121939121940121941121942121943121944121945121946121947121948121949121950121951121952121953121954121955121956121957121958121959121960121961121962121963121964121965121966121967121968121969121970121971121972121973121974121975121976121977121978121979121980121981121982121983121984121985121986121987121988121989121990121991121992121993121994121995121996121997121998121999122000122001122002122003122004122005122006122007122008122009122010122011122012122013122014122015122016122017122018122019122020122021122022122023122024122025122026122027122028122029122030122031122032122033122034122035122036122037122038122039122040122041122042122043122044122045122046122047122048122049122050122051122052122053122054122055122056122057122058122059122060122061122062122063122064122065122066122067122068122069122070122071122072122073122074122075122076122077122078122079122080122081122082122083122084122085122086122087122088122089122090122091122092122093122094122095122096122097122098122099122100122101122102122103122104122105122106122107122108122109122110122111122112122113122114122115122116122117122118122119122120122121122122122123122124122125122126122127122128122129122130122131122132122133122134122135122136122137122138122139122140122141122142122143122144122145122146122147122148122149122150122151122152122153122154122155122156122157122158122159122160122161122162122163122164122165122166122167122168122169122170122171122172122173122174122175122176122177122178122179122180122181122182122183122184122185122186122187122188122189122190122191122192122193122194122195122196122197122198122199122200122201122202122203122204122205122206122207122208122209122210122211122212122213122214122215122216122217122218122219122220122221122222122223122224122225122226122227122228122229122230122231122232122233122234122235122236122237122238122239122240122241122242122243122244122245122246122247122248122249122250122251122252122253122254122255122256122257122258122259122260122261122262122263122264122265122266122267122268122269122270122271122272122273122274122275122276122277122278122279122280122281122282122283122284122285122286122287122288122289122290122291122292122293122294122295122296122297122298122299122300122301122302122303122304122305122306122307122308122309122310122311122312122313122314122315122316122317122318122319122320122321122322122323122324122325122326122327122328122329122330122331122332122333122334122335122336122337122338122339122340122341122342122343122344122345122346122347122348122349122350122351122352122353122354122355122356122357122358122359122360122361122362122363122364122365122366122367122368122369122370122371122372122373122374122375122376122377122378122379122380122381122382122383122384122385122386122387122388122389122390122391122392122393122394122395122396122397122398122399122400122401122402122403122404122405122406122407122408122409122410122411122412122413122414122415122416122417122418122419122420122421122422122423122424122425122426122427122428122429122430122431122432122433122434122435122436122437122438122439122440122441122442122443122444122445122446122447122448122449122450122451122452122453122454122455122456122457122458122459122460122461122462122463122464122465122466122467122468122469122470122471122472122473122474122475122476122477122478122479122480122481122482122483122484122485122486122487122488122489122490122491122492122493122494122495122496122497122498122499122500122501122502122503122504122505122506122507122508122509122510122511122512122513122514122515122516122517122518122519122520122521122522122523122524122525122526122527122528122529122530122531122532122533122534122535122536122537122538122539122540122541122542122543122544122545122546122547122548122549122550122551122552122553122554122555122556122557122558122559122560122561122562122563122564122565122566122567122568122569122570122571122572122573122574122575122576122577122578122579122580122581122582122583122584122585122586122587122588122589122590122591122592122593122594122595122596122597122598122599122600122601122602122603122604122605122606122607122608122609122610122611122612122613122614122615122616122617122618122619122620122621122622122623122624122625122626122627122628122629122630122631122632122633122634122635122636122637122638122639122640122641122642122643122644122645122646122647122648122649122650122651122652122653122654122655122656122657122658122659122660122661122662122663122664122665122666122667122668122669122670122671122672122673122674122675122676122677122678122679122680122681122682122683122684122685122686122687122688122689122690122691122692122693122694122695122696122697122698122699122700122701122702122703122704122705122706122707122708122709122710122711122712122713122714122715122716122717122718122719122720122721122722122723122724122725122726122727122728122729122730122731122732122733122734122735122736122737122738122739122740122741122742122743122744122745122746122747122748122749122750122751122752122753122754122755122756122757122758122759122760122761122762122763122764122765122766122767122768122769122770122771122772122773122774122775122776122777122778122779122780122781122782122783122784122785122786122787122788122789122790122791122792122793122794122795122796122797122798122799122800122801122802122803122804122805122806122807122808122809122810122811122812122813122814122815122816122817122818122819122820122821122822122823122824122825122826122827122828122829122830122831122832122833122834122835122836122837122838122839122840122841122842122843122844122845122846122847122848122849122850122851122852122853122854122855122856122857122858122859122860122861122862122863122864122865122866122867122868122869122870122871122872122873122874122875122876122877122878122879122880122881122882122883122884122885122886122887122888122889122890122891122892122893122894122895122896122897122898122899122900122901122902122903122904122905122906122907122908122909122910122911122912122913122914122915122916122917122918122919122920122921122922122923122924122925122926122927122928122929122930122931122932122933122934122935122936122937122938122939122940122941122942122943122944122945122946122947122948122949122950122951122952122953122954122955122956122957122958122959122960122961122962122963122964122965122966122967122968122969122970122971122972122973122974122975122976122977122978122979122980122981122982122983122984122985122986122987122988122989122990122991122992122993122994122995122996122997122998122999123000123001123002123003123004123005123006123007123008123009123010123011123012123013123014123015123016123017123018123019123020123021123022123023123024123025123026123027123028123029123030123031123032123033123034123035123036123037123038123039123040123041123042123043123044123045123046123047123048123049123050123051123052123053123054123055123056123057123058123059123060123061123062123063123064123065123066123067123068123069123070123071123072123073123074123075123076123077123078123079123080123081123082123083123084123085123086123087123088123089123090123091123092123093123094123095123096123097123098123099123100123101123102123103123104123105123106123107123108123109123110123111123112123113123114123115123116123117123118123119123120123121123122123123123124123125123126123127123128123129123130123131123132123133123134123135123136123137123138123139123140123141123142123143123144123145123146123147123148123149123150123151123152123153123154123155123156123157123158123159123160123161123162123163123164123165123166123167123168123169123170123171123172123173123174123175123176123177123178123179123180123181123182123183123184123185123186123187123188123189123190123191123192123193123194123195123196123197123198123199123200123201123202123203123204123205123206123207123208123209123210123211123212123213123214123215123216123217123218123219123220123221123222123223123224123225123226123227123228123229123230123231123232123233123234123235123236123237123238123239123240123241123242123243123244123245123246123247123248123249123250123251123252123253123254123255123256123257123258123259123260123261123262123263123264123265123266123267123268123269123270123271123272123273123274123275123276123277123278123279123280123281123282123283123284123285123286123287123288123289123290123291123292123293123294123295123296123297123298123299123300123301123302123303123304123305123306123307123308123309123310123311123312123313123314123315123316123317123318123319123320123321123322123323123324123325123326123327123328123329123330123331123332123333123334123335123336123337123338123339123340123341123342123343123344123345123346123347123348123349123350123351123352123353123354123355123356123357123358123359123360123361123362123363123364123365123366123367123368123369123370123371123372123373123374123375123376123377123378123379123380123381123382123383123384123385123386123387123388123389123390123391123392123393123394123395123396123397123398123399123400123401123402123403123404123405123406123407123408123409123410123411123412123413123414123415123416123417123418123419123420123421123422123423123424123425123426123427123428123429123430123431123432123433123434123435123436123437123438123439123440123441123442123443123444123445123446123447123448123449123450123451123452123453123454123455123456123457123458123459123460123461123462123463123464123465123466123467123468123469123470123471123472123473123474123475123476123477123478123479123480123481123482123483123484123485123486123487123488123489123490123491123492123493123494123495123496123497123498123499123500123501123502123503123504123505123506123507123508123509123510123511123512123513123514123515123516123517123518123519123520123521123522123523123524123525123526123527123528123529123530123531123532123533123534123535123536123537123538123539123540123541123542123543123544123545123546123547123548123549123550123551123552123553123554123555123556123557123558123559123560123561123562123563123564123565123566123567123568123569123570123571123572123573123574123575123576123577123578123579123580123581123582123583123584123585123586123587123588123589123590123591123592123593123594123595123596123597123598123599123600123601123602123603123604123605123606123607123608123609123610123611123612123613123614123615123616123617123618123619123620123621123622123623123624123625123626123627123628123629123630123631123632123633123634123635123636123637123638123639123640123641123642123643123644123645123646123647123648123649123650123651123652123653123654123655123656123657123658123659123660123661123662123663123664123665123666123667123668123669123670123671123672123673123674123675123676123677123678123679123680123681123682123683123684123685123686123687123688123689123690123691123692123693123694123695123696123697123698123699123700123701123702123703123704123705123706123707123708123709123710123711123712123713123714123715123716123717123718123719123720123721123722123723123724123725123726123727123728123729123730123731123732123733123734123735123736123737123738123739123740123741123742123743123744123745123746123747123748123749123750123751123752123753123754123755123756123757123758123759123760123761123762123763123764123765123766123767123768123769123770123771123772123773123774123775123776123777123778123779123780123781123782123783123784123785123786123787123788123789123790123791123792123793123794123795123796123797123798123799123800123801123802123803123804123805123806123807123808123809123810123811123812123813123814123815123816123817123818123819123820123821123822123823123824123825123826123827123828123829123830123831123832123833123834123835123836123837123838123839123840123841123842123843123844123845123846123847123848123849123850123851123852123853123854123855123856123857123858123859123860123861123862123863123864123865123866123867123868123869123870123871123872123873123874123875123876123877123878123879123880123881123882123883123884123885123886123887123888123889123890123891123892123893123894123895123896123897123898123899123900123901123902123903123904123905123906123907123908123909123910123911123912123913123914123915123916123917123918123919123920123921123922123923123924123925123926123927123928123929123930123931123932123933123934123935123936123937123938123939123940123941123942123943123944123945123946123947123948123949123950123951123952123953123954123955123956123957123958123959123960123961123962123963123964123965123966123967123968123969123970123971123972123973123974123975123976123977123978123979123980123981123982123983123984123985123986123987123988123989123990123991123992123993123994123995123996123997123998123999124000124001124002124003124004124005124006124007124008124009124010124011124012124013124014124015124016124017124018124019124020124021124022124023124024124025124026124027124028124029124030124031124032124033124034124035124036124037124038124039124040124041124042124043124044124045124046124047124048124049124050124051124052124053124054124055124056124057124058124059124060124061124062124063124064124065124066124067124068124069124070124071124072124073124074124075124076124077124078124079124080124081124082124083124084124085124086124087124088124089124090124091124092124093124094124095124096124097124098124099124100124101124102124103124104124105124106124107124108124109124110124111124112124113124114124115124116124117124118124119124120124121124122124123124124124125124126124127124128124129124130124131124132124133124134124135124136124137124138124139124140124141124142124143124144124145124146124147124148124149124150124151124152124153124154124155124156124157124158124159124160124161124162124163124164124165124166124167124168124169124170124171124172124173124174124175124176124177124178124179124180124181124182124183124184124185124186124187124188124189124190124191124192124193124194124195124196124197124198124199124200124201124202124203124204124205124206124207124208124209124210124211124212124213124214124215124216124217124218124219124220124221124222124223124224124225124226124227124228124229124230124231124232124233124234124235124236124237124238124239124240124241124242124243124244124245124246124247124248124249124250124251124252124253124254124255124256124257124258124259124260124261124262124263124264124265124266124267124268124269124270124271124272124273124274124275124276124277124278124279124280124281124282124283124284124285124286124287124288124289124290124291124292124293124294124295124296124297124298124299124300124301124302124303124304124305124306124307124308124309124310124311124312124313124314124315124316124317124318124319124320124321124322124323124324124325124326124327124328124329124330124331124332124333124334124335124336124337124338124339124340124341124342124343124344124345124346124347124348124349124350124351124352124353124354124355124356124357124358124359124360124361124362124363124364124365124366124367124368124369124370124371124372124373124374124375124376124377124378124379124380124381124382124383124384124385124386124387124388124389124390124391124392124393124394124395124396124397124398124399124400124401124402124403124404124405124406124407124408124409124410124411124412124413124414124415124416124417124418124419124420124421124422124423124424124425124426124427124428124429124430124431124432124433124434124435124436124437124438124439124440124441124442124443124444124445124446124447124448124449124450124451124452124453124454124455124456124457124458124459124460124461124462124463124464124465124466124467124468124469124470124471124472124473124474124475124476124477124478124479124480124481124482124483124484124485124486124487124488124489124490124491124492124493124494124495124496124497124498124499124500124501124502124503124504124505124506124507124508124509124510124511124512124513124514124515124516124517124518124519124520124521124522124523124524124525124526124527124528124529124530124531124532124533124534124535124536124537124538124539124540124541124542124543124544124545124546124547124548124549124550124551124552124553124554124555124556124557124558124559124560124561124562124563124564124565124566124567124568124569124570124571124572124573124574124575124576124577124578124579124580124581124582124583124584124585124586124587124588124589124590124591124592124593124594124595124596124597124598124599124600124601124602124603124604124605124606124607124608124609124610124611124612124613124614124615124616124617124618124619124620124621124622124623124624124625124626124627124628124629124630124631124632124633124634124635124636124637124638124639124640124641124642124643124644124645124646124647124648124649124650124651124652124653124654124655124656124657124658124659124660124661124662124663124664124665124666124667124668124669124670124671124672124673124674124675124676124677124678124679124680124681124682124683124684124685124686124687124688124689124690124691124692124693124694124695124696124697124698124699124700124701124702124703124704124705124706124707124708124709124710124711124712124713124714124715124716124717124718124719124720124721124722124723124724124725124726124727124728124729124730124731124732124733124734124735124736124737124738124739124740124741124742124743124744124745124746124747124748124749124750124751124752124753124754124755124756124757124758124759124760124761124762124763124764124765124766124767124768124769124770124771124772124773124774124775124776124777124778124779124780124781124782124783124784124785124786124787124788124789124790124791124792124793124794124795124796124797124798124799124800124801124802124803124804124805124806124807124808124809124810124811124812124813124814124815124816124817124818124819124820124821124822124823124824124825124826124827124828124829124830124831124832124833124834124835124836124837124838124839124840124841124842124843124844124845124846124847124848124849124850124851124852124853124854124855124856124857124858124859124860124861124862124863124864124865124866124867124868124869124870124871124872124873124874124875124876124877124878124879124880124881124882124883124884124885124886124887124888124889124890124891124892124893124894124895124896124897124898124899124900124901124902124903124904124905124906124907124908124909124910124911124912124913124914124915124916124917124918124919124920124921124922124923124924124925124926124927124928124929124930124931124932124933124934124935124936124937124938124939124940124941124942124943124944124945124946124947124948124949124950124951124952124953124954124955124956124957124958124959124960124961124962124963124964124965124966124967124968124969124970124971124972124973124974124975124976124977124978124979124980124981124982124983124984124985124986124987124988124989124990124991124992124993124994124995124996124997124998124999125000125001125002125003125004125005125006125007125008125009125010125011125012125013125014125015125016125017125018125019125020125021125022125023125024125025125026125027125028125029125030125031125032125033125034125035125036125037125038125039125040125041125042125043125044125045125046125047125048125049125050125051125052125053125054125055125056125057125058125059125060125061125062125063125064125065125066125067125068125069125070125071125072125073125074125075125076125077125078125079125080125081125082125083125084125085125086125087125088125089125090125091125092125093125094125095125096125097125098125099125100125101125102125103125104125105125106125107125108125109125110125111125112125113125114125115125116125117125118125119125120125121125122125123125124125125125126125127125128125129125130125131125132125133125134125135125136125137125138125139125140125141125142125143125144125145125146125147125148125149125150125151125152125153125154125155125156125157125158125159125160125161125162125163125164125165125166125167125168125169125170125171125172125173125174125175125176125177125178125179125180125181125182125183125184125185125186125187125188125189125190125191125192125193125194125195125196125197125198125199125200125201125202125203125204125205125206125207125208125209125210125211125212125213125214125215125216125217125218125219125220125221125222125223125224125225125226125227125228125229125230125231125232125233125234125235125236125237125238125239125240125241125242125243125244125245125246125247125248125249125250125251125252125253125254125255125256125257125258125259125260125261125262125263125264125265125266125267125268125269125270125271125272125273125274125275125276125277125278125279125280125281125282125283125284125285125286125287125288125289125290125291125292125293125294125295125296125297125298125299125300125301125302125303125304125305125306125307125308125309125310125311125312125313125314125315125316125317125318125319125320125321125322125323125324125325125326125327125328125329125330125331125332125333125334125335125336125337125338125339125340125341125342125343125344125345125346125347125348125349125350125351125352125353125354125355125356125357125358125359125360125361125362125363125364125365125366125367125368125369125370125371125372125373125374125375125376125377125378125379125380125381125382125383125384125385125386125387125388125389125390125391125392125393125394125395125396125397125398125399125400125401125402125403125404125405125406125407125408125409125410125411125412125413125414125415125416125417125418125419125420125421125422125423125424125425125426125427125428125429125430125431125432125433125434125435125436125437125438125439125440125441125442125443125444125445125446125447125448125449125450125451125452125453125454125455125456125457125458125459125460125461125462125463125464125465125466125467125468125469125470125471125472125473125474125475125476125477125478125479125480125481125482125483125484125485125486125487125488125489125490125491125492125493125494125495125496125497125498125499125500125501125502125503125504125505125506125507125508125509125510125511125512125513125514125515125516125517125518125519125520125521125522125523125524125525125526125527125528125529125530125531125532125533125534125535125536125537125538125539125540125541125542125543125544125545125546125547125548125549125550125551125552125553125554125555125556125557125558125559125560125561125562125563125564125565125566125567125568125569125570125571125572125573125574125575125576125577125578125579125580125581125582125583125584125585125586125587125588125589125590125591125592125593125594125595125596125597125598125599125600125601125602125603125604125605125606125607125608125609125610125611125612125613125614125615125616125617125618125619125620125621125622125623125624125625125626125627125628125629125630125631125632125633125634125635125636125637125638125639125640125641125642125643125644125645125646125647125648125649125650125651125652125653125654125655125656125657125658125659125660125661125662125663125664125665125666125667125668125669125670125671125672125673125674125675125676125677125678125679125680125681125682125683125684125685125686125687125688125689125690125691125692125693125694125695125696125697125698125699125700125701125702125703125704125705125706125707125708125709125710125711125712125713125714125715125716125717125718125719125720125721125722125723125724125725125726125727125728125729125730125731125732125733125734125735125736125737125738125739125740125741125742125743125744125745125746125747125748125749125750125751125752125753125754125755125756125757125758125759125760125761125762125763125764125765125766125767125768125769125770125771125772125773125774125775125776125777125778125779125780125781125782125783125784125785125786125787125788125789125790125791125792125793125794125795125796125797125798125799125800125801125802125803125804125805125806125807125808125809125810125811125812125813125814125815125816125817125818125819125820125821125822125823125824125825125826125827125828125829125830125831125832125833125834125835125836125837125838125839125840125841125842125843125844125845125846125847125848125849125850125851125852125853125854125855125856125857125858125859125860125861125862125863125864125865125866125867125868125869125870125871125872125873125874125875125876125877125878125879125880125881125882125883125884125885125886125887125888125889125890125891125892125893125894125895125896125897125898125899125900125901125902125903125904125905125906125907125908125909125910125911125912125913125914125915125916125917125918125919125920125921125922125923125924125925125926125927125928125929125930125931125932125933125934125935125936125937125938125939125940125941125942125943125944125945125946125947125948125949125950125951125952125953125954125955125956125957125958125959125960125961125962125963125964125965125966125967125968125969125970125971125972125973125974125975125976125977125978125979125980125981125982125983125984125985125986125987125988125989125990125991125992125993125994125995125996125997125998125999126000126001126002126003126004126005126006126007126008126009126010126011126012126013126014126015126016126017126018126019126020126021126022126023126024126025126026126027126028126029126030126031126032126033126034126035126036126037126038126039126040126041126042126043126044126045126046126047126048126049126050126051126052126053126054126055126056126057126058126059126060126061126062126063126064126065126066126067126068126069126070126071126072126073126074126075126076126077126078126079126080126081126082126083126084126085126086126087126088126089126090126091126092126093126094126095126096126097126098126099126100126101126102126103126104126105126106126107126108126109126110126111126112126113126114126115126116126117126118126119126120126121126122126123126124126125126126126127126128126129126130126131126132126133126134126135126136126137126138126139126140126141126142126143126144126145126146126147126148126149126150126151126152126153126154126155126156126157126158126159126160126161126162126163126164126165126166126167126168126169126170126171126172126173126174126175126176126177126178126179126180126181126182126183126184126185126186126187126188126189126190126191126192126193126194126195126196126197126198126199126200126201126202126203126204126205126206126207126208126209126210126211126212126213126214126215126216126217126218126219126220126221126222126223126224126225126226126227126228126229126230126231126232126233126234126235126236126237126238126239126240126241126242126243126244126245126246126247126248126249126250126251126252126253126254126255126256126257126258126259126260126261126262126263126264126265126266126267126268126269126270126271126272126273126274126275126276126277126278126279126280126281126282126283126284126285126286126287126288126289126290126291126292126293126294126295126296126297126298126299126300126301126302126303126304126305126306126307126308126309126310126311126312126313126314126315126316126317126318126319126320126321126322126323126324126325126326126327126328126329126330126331126332126333126334126335126336126337126338126339126340126341126342126343126344126345126346126347126348126349126350126351126352126353126354126355126356126357126358126359126360126361126362126363126364126365126366126367126368126369126370126371126372126373126374126375126376126377126378126379126380126381126382126383126384126385126386126387126388126389126390126391126392126393126394126395126396126397126398126399126400126401126402126403126404126405126406126407126408126409126410126411126412126413126414126415126416126417126418126419126420126421126422126423126424126425126426126427126428126429126430126431126432126433126434126435126436126437126438126439126440126441126442126443126444126445126446126447126448126449126450126451126452126453126454126455126456126457126458126459126460126461126462126463126464126465126466126467126468126469126470126471126472126473126474126475126476126477126478126479126480126481126482126483126484126485126486126487126488126489126490126491126492126493126494126495126496126497126498126499126500126501126502126503126504126505126506126507126508126509126510126511126512126513126514126515126516126517126518126519126520126521126522126523126524126525126526126527126528126529126530126531126532126533126534126535126536126537126538126539126540126541126542126543126544126545126546126547126548126549126550126551126552126553126554126555126556126557126558126559126560126561126562126563126564126565126566126567126568126569126570126571126572126573126574126575126576126577126578126579126580126581126582126583126584126585126586126587126588126589126590126591126592126593126594126595126596126597126598126599126600126601126602126603126604126605126606126607126608126609126610126611126612126613126614126615126616126617126618126619126620126621126622126623126624126625126626126627126628126629126630126631126632126633126634126635126636126637126638126639126640126641126642126643126644126645126646126647126648126649126650126651126652126653126654126655126656126657126658126659126660126661126662126663126664126665126666126667126668126669126670126671126672126673126674126675126676126677126678126679126680126681126682126683126684126685126686126687126688126689126690126691126692126693126694126695126696126697126698126699126700126701126702126703126704126705126706126707126708126709126710126711126712126713126714126715126716126717126718126719126720126721126722126723126724126725126726126727126728126729126730126731126732126733126734126735126736126737126738126739126740126741126742126743126744126745126746126747126748126749126750126751126752126753126754126755126756126757126758126759126760126761126762126763126764126765126766126767126768126769126770126771126772126773126774126775126776126777126778126779126780126781126782126783126784126785126786126787126788126789126790126791126792126793126794126795126796126797126798126799126800126801126802126803126804126805126806126807126808126809126810126811126812126813126814126815126816126817126818126819126820126821126822126823126824126825126826126827126828126829126830126831126832126833126834126835126836126837126838126839126840126841126842126843126844126845126846126847126848126849126850126851126852126853126854126855126856126857126858126859126860126861126862126863126864126865126866126867126868126869126870126871126872126873126874126875126876126877126878126879126880126881126882126883126884126885126886126887126888126889126890126891126892126893126894126895126896126897126898126899126900126901126902126903126904126905126906126907126908126909126910126911126912126913126914126915126916126917126918126919126920126921126922126923126924126925126926126927126928126929126930126931126932126933126934126935126936126937126938126939126940126941126942126943126944126945126946126947126948126949126950126951126952126953126954126955126956126957126958126959126960126961126962126963126964126965126966126967126968126969126970126971126972126973126974126975126976126977126978126979126980126981126982126983126984126985126986126987126988126989126990126991126992126993126994126995126996126997126998126999127000127001127002127003127004127005127006127007127008127009127010127011127012127013127014127015127016127017127018127019127020127021127022127023127024127025127026127027127028127029127030127031127032127033127034127035127036127037127038127039127040127041127042127043127044127045127046127047127048127049127050127051127052127053127054127055127056127057127058127059127060127061127062127063127064127065127066127067127068127069127070127071127072127073127074127075127076127077127078127079127080127081127082127083127084127085127086127087127088127089127090127091127092127093127094127095127096127097127098127099127100127101127102127103127104127105127106127107127108127109127110127111127112127113127114127115127116127117127118127119127120127121127122127123127124127125127126127127127128127129127130127131127132127133127134127135127136127137127138127139127140127141127142127143127144127145127146127147127148127149127150127151127152127153127154127155127156127157127158127159127160127161127162127163127164127165127166127167127168127169127170127171127172127173127174127175127176127177127178127179127180127181127182127183127184127185127186127187127188127189127190127191127192127193127194127195127196127197127198127199127200127201127202127203127204127205127206127207127208127209127210127211127212127213127214127215127216127217127218127219127220127221127222127223127224127225127226127227127228127229127230127231127232127233127234127235127236127237127238127239127240127241127242127243127244127245127246127247127248127249127250127251127252127253127254127255127256127257127258127259127260127261127262127263127264127265127266127267127268127269127270127271127272127273127274127275127276127277127278127279127280127281127282127283127284127285127286127287127288127289127290127291127292127293127294127295127296127297127298127299127300127301127302127303127304127305127306127307127308127309127310127311127312127313127314127315127316127317127318127319127320127321127322127323127324127325127326127327127328127329127330127331127332127333127334127335127336127337127338127339127340127341127342127343127344127345127346127347127348127349127350127351127352127353127354127355127356127357127358127359127360127361127362127363127364127365127366127367127368127369127370127371127372127373127374127375127376127377127378127379127380127381127382127383127384127385127386127387127388127389127390127391127392127393127394127395127396127397127398127399127400127401127402127403127404127405127406127407127408127409127410127411127412127413127414127415127416127417127418127419127420127421127422127423127424127425127426127427127428127429127430127431127432127433127434127435127436127437127438127439127440127441127442127443127444127445127446127447127448127449127450127451127452127453127454127455127456127457127458127459127460127461127462127463127464127465127466127467127468127469127470127471127472127473127474127475127476127477127478127479127480127481127482127483127484127485127486127487127488127489127490127491127492127493127494127495127496127497127498127499127500127501127502127503127504127505127506127507127508127509127510127511127512127513127514127515127516127517127518127519127520127521127522127523127524127525127526127527127528127529127530127531127532127533127534127535127536127537127538127539127540127541127542127543127544127545127546127547127548127549127550127551127552127553127554127555127556127557127558127559127560127561127562127563127564127565127566127567127568127569127570127571127572127573127574127575127576127577127578127579127580127581127582127583127584127585127586127587127588127589127590127591127592127593127594127595127596127597127598127599127600127601127602127603127604127605127606127607127608127609127610127611127612127613127614127615127616127617127618127619127620127621127622127623127624127625127626127627127628127629127630127631127632127633127634127635127636127637127638127639127640127641127642127643127644127645127646127647127648127649127650127651127652127653127654127655127656127657127658127659127660127661127662127663127664127665127666127667127668127669127670127671127672127673127674127675127676127677127678127679127680127681127682127683127684127685127686127687127688127689127690127691127692127693127694127695127696127697127698127699127700127701127702127703127704127705127706127707127708127709127710127711127712127713127714127715127716127717127718127719127720127721127722127723127724127725127726127727127728127729127730127731127732127733127734127735127736127737127738127739127740127741127742127743127744127745127746127747127748127749127750127751127752127753127754127755127756127757127758127759127760127761127762127763127764127765127766127767127768127769127770127771127772127773127774127775127776127777127778127779127780127781127782127783127784127785127786127787127788127789127790127791127792127793127794127795127796127797127798127799127800127801127802127803127804127805127806127807127808127809127810127811127812127813127814127815127816127817127818127819127820127821127822127823127824127825127826127827127828127829127830127831127832127833127834127835127836127837127838127839127840127841127842127843127844127845127846127847127848127849127850127851127852127853127854127855127856127857127858127859127860127861127862127863127864127865127866127867127868127869127870127871127872127873127874127875127876127877127878127879127880127881127882127883127884127885127886127887127888127889127890127891127892127893127894127895127896127897127898127899127900127901127902127903127904127905127906127907127908127909127910127911127912127913127914127915127916127917127918127919127920127921127922127923127924127925127926127927127928127929127930127931127932127933127934127935127936127937127938127939127940127941127942127943127944127945127946127947127948127949127950127951127952127953127954127955127956127957127958127959127960127961127962127963127964127965127966127967127968127969127970127971127972127973127974127975127976127977127978127979127980127981127982127983127984127985127986127987127988127989127990127991127992127993127994127995127996127997127998127999128000128001128002128003128004128005128006128007128008128009128010128011128012128013128014128015128016128017128018128019128020128021128022128023128024128025128026128027128028128029128030128031128032128033128034128035128036128037128038128039128040128041128042128043128044128045128046128047128048128049128050128051128052128053128054128055128056128057128058128059128060128061128062128063128064128065128066128067128068128069128070128071128072128073128074128075128076128077128078128079128080128081128082128083128084128085128086128087128088128089128090128091128092128093128094128095128096128097128098128099128100128101128102128103128104128105128106128107128108128109128110128111128112128113128114128115128116128117128118128119128120128121128122128123128124128125128126128127128128128129128130128131128132128133128134128135128136128137128138128139128140128141128142128143128144128145128146128147128148128149128150128151128152128153128154128155128156128157128158128159128160128161128162128163128164128165128166128167128168128169128170128171128172128173128174128175128176128177128178128179128180128181128182128183128184128185128186128187128188128189128190128191128192128193128194128195128196128197128198128199128200128201128202128203128204128205128206128207128208128209128210128211128212128213128214128215128216128217128218128219128220128221128222128223128224128225128226128227128228128229128230128231128232128233128234128235128236128237128238128239128240128241128242128243128244128245128246128247128248128249128250128251128252128253128254128255128256128257128258128259128260128261128262128263128264128265128266128267128268128269128270128271128272128273128274128275128276128277128278128279128280128281128282128283128284128285128286128287128288128289128290128291128292128293128294128295128296128297128298128299128300128301128302128303128304128305128306128307128308128309128310128311128312128313128314128315128316128317128318128319128320128321128322128323128324128325128326128327128328128329128330128331128332128333128334128335128336128337128338128339128340128341128342128343128344128345128346128347128348128349128350128351128352128353128354128355128356128357128358128359128360128361128362128363128364128365128366128367128368128369128370128371128372128373128374128375128376128377128378128379128380128381128382128383128384128385128386128387128388128389128390128391128392128393128394128395128396128397128398128399128400128401128402128403128404128405128406128407128408128409128410128411128412128413128414128415128416128417128418128419128420128421128422128423128424128425128426128427128428128429128430128431128432128433128434128435128436128437128438128439128440128441128442128443128444128445128446128447128448128449128450128451128452128453128454128455128456128457128458128459128460128461128462128463128464128465128466128467128468128469128470128471128472128473128474128475128476128477128478128479128480128481128482128483128484128485128486128487128488128489128490128491128492128493128494128495128496128497128498128499128500128501128502128503128504128505128506128507128508128509128510128511128512128513128514128515128516128517128518128519128520128521128522128523128524128525128526128527128528128529128530128531128532128533128534128535128536128537128538128539128540128541128542128543128544128545128546128547128548128549128550128551128552128553128554128555128556128557128558128559128560128561128562128563128564128565128566128567128568128569128570128571128572128573128574128575128576128577128578128579128580128581128582128583128584128585128586128587128588128589128590128591128592128593128594128595128596128597128598128599128600128601128602128603128604128605128606128607128608128609128610128611128612128613128614128615128616128617128618128619128620128621128622128623128624128625128626128627128628128629128630128631128632128633128634128635128636128637128638128639128640128641128642128643128644128645128646128647128648128649128650128651128652128653128654128655128656128657128658128659128660128661128662128663128664128665128666128667128668128669128670128671128672128673128674128675128676128677128678128679128680128681128682128683128684128685128686128687128688128689128690128691128692128693128694128695128696128697128698128699128700128701128702128703128704128705128706128707128708128709128710128711128712128713128714128715128716128717128718128719128720128721128722128723128724128725128726128727128728128729128730128731128732128733128734128735128736128737128738128739128740128741128742128743128744128745128746128747128748128749128750128751128752128753128754128755128756128757128758128759128760128761128762128763128764128765128766128767128768128769128770128771128772128773128774128775128776128777128778128779128780128781128782128783128784128785128786128787128788128789128790128791128792128793128794128795128796128797128798128799128800128801128802128803128804128805128806128807128808128809128810128811128812128813128814128815128816128817128818128819128820128821128822128823128824128825128826128827128828128829128830128831128832128833128834128835128836128837128838128839128840128841128842128843128844128845128846128847128848128849128850128851128852128853128854128855128856128857128858128859128860128861128862128863128864128865128866128867128868128869128870128871128872128873128874128875128876128877128878128879128880128881128882128883128884128885128886128887128888128889128890128891128892128893128894128895128896128897128898128899128900128901128902128903128904128905128906128907128908128909128910128911128912128913128914128915128916128917128918128919128920128921128922128923128924128925128926128927128928128929128930128931128932128933128934128935128936128937128938128939128940128941128942128943128944128945128946128947128948128949128950128951128952128953128954128955128956128957128958128959128960128961128962128963128964128965128966128967128968128969128970128971128972128973128974128975128976128977128978128979128980128981128982128983128984128985128986128987128988128989128990128991128992128993128994128995128996128997128998128999129000129001129002129003129004129005129006129007129008129009129010129011129012129013129014129015129016129017129018129019129020129021129022129023129024129025129026129027129028129029129030129031129032129033129034129035129036129037129038129039129040129041129042129043129044129045129046129047129048129049129050129051129052129053129054129055129056129057129058129059129060129061129062129063129064129065129066129067129068129069129070129071129072129073129074129075129076129077129078129079129080129081129082129083129084129085129086129087129088129089129090129091129092129093129094129095129096129097129098129099129100129101129102129103129104129105129106129107129108129109129110129111129112129113129114129115129116129117129118129119129120129121129122129123129124129125129126129127129128129129129130129131129132129133129134129135129136129137129138129139129140129141129142129143129144129145129146129147129148129149129150129151129152129153129154129155129156129157129158129159129160129161129162129163129164129165129166129167129168129169129170129171129172129173129174129175129176129177129178129179129180129181129182129183129184129185129186129187129188129189129190129191129192129193129194129195129196129197129198129199129200129201129202129203129204129205129206129207129208129209129210129211129212129213129214129215129216129217129218129219129220129221129222129223129224129225129226129227129228129229129230129231129232129233129234129235129236129237129238129239129240129241129242129243129244129245129246129247129248129249129250129251129252129253129254129255129256129257129258129259129260129261129262129263129264129265129266129267129268129269129270129271129272129273129274129275129276129277129278129279129280129281129282129283129284129285129286129287129288129289129290129291129292129293129294129295129296129297129298129299129300129301129302129303129304129305129306129307129308129309129310129311129312129313129314129315129316129317129318129319129320129321129322129323129324129325129326129327129328129329129330129331129332129333129334129335129336129337129338129339129340129341129342129343129344129345129346129347129348129349129350129351129352129353129354129355129356129357129358129359129360129361129362129363129364129365129366129367129368129369129370129371129372129373129374129375129376129377129378129379129380129381129382129383129384129385129386129387129388129389129390129391129392129393129394129395129396129397129398129399129400129401129402129403129404129405129406129407129408129409129410129411129412129413129414129415129416129417129418129419129420129421129422129423129424129425129426129427129428129429129430129431129432129433129434129435129436129437129438129439129440129441129442129443129444129445129446129447129448129449129450129451129452129453129454129455129456129457129458129459129460129461129462129463129464129465129466129467129468129469129470129471129472129473129474129475129476129477129478129479129480129481129482129483129484129485129486129487129488129489129490129491129492129493129494129495129496129497129498129499129500129501129502129503129504129505129506129507129508129509129510129511129512129513129514129515129516129517129518129519129520129521129522129523129524129525129526129527129528129529129530129531129532129533129534129535129536129537129538129539129540129541129542129543129544129545129546129547129548129549129550129551129552129553129554129555129556129557129558129559129560129561129562129563129564129565129566129567129568129569129570129571129572129573129574129575129576129577129578129579129580129581129582129583129584129585129586129587129588129589129590129591129592129593129594129595129596129597129598129599129600129601129602129603129604129605129606129607129608129609129610129611129612129613129614129615129616129617129618129619129620129621129622129623129624129625129626129627129628129629129630129631129632129633129634129635129636129637129638129639129640129641129642129643129644129645129646129647129648129649129650129651129652129653129654129655129656129657129658129659129660129661129662129663129664129665129666129667129668129669129670129671129672129673129674129675129676129677129678129679129680129681129682129683129684129685129686129687129688129689129690129691129692129693129694129695129696129697129698129699129700129701129702129703129704129705129706129707129708129709129710129711129712129713129714129715129716129717129718129719129720129721129722129723129724129725129726129727129728129729129730129731129732129733129734129735129736129737129738129739129740129741129742129743129744129745129746129747129748129749129750129751129752129753129754129755129756129757129758129759129760129761129762129763129764129765129766129767129768129769129770129771129772129773129774129775129776129777129778129779129780129781129782129783129784129785129786129787129788129789129790129791129792129793129794129795129796129797129798129799129800129801129802129803129804129805129806129807129808129809129810129811129812129813129814129815129816129817129818129819129820129821129822129823129824129825129826129827129828129829129830129831129832129833129834129835129836129837129838129839129840129841129842129843129844129845129846129847129848129849129850129851129852129853129854129855129856129857129858129859129860129861129862129863129864129865129866129867129868129869129870129871129872129873129874129875129876129877129878129879129880129881129882129883129884129885129886129887129888129889129890129891129892129893129894129895129896129897129898129899129900129901129902129903129904129905129906129907129908129909129910129911129912129913129914129915129916129917129918129919129920129921129922129923129924129925129926129927129928129929129930129931129932129933129934129935129936129937129938129939129940129941129942129943129944129945129946129947129948129949129950129951129952129953129954129955129956129957129958129959129960129961129962129963129964129965129966129967129968129969129970129971129972129973129974129975129976129977129978129979129980129981129982129983129984129985129986129987129988129989129990129991129992129993129994129995129996129997129998129999130000130001130002130003130004130005130006130007130008130009130010130011130012130013130014130015130016130017130018130019130020130021130022130023130024130025130026130027130028130029130030130031130032130033130034130035130036130037130038130039130040130041130042130043130044130045130046130047130048130049130050130051130052130053130054130055130056130057130058130059130060130061130062130063130064130065130066130067130068130069130070130071130072130073130074130075130076130077130078130079130080130081130082130083130084130085130086130087130088130089130090130091130092130093130094130095130096130097130098130099130100130101130102130103130104130105130106130107130108130109130110130111130112130113130114130115130116130117130118130119130120130121130122130123130124130125130126130127130128130129130130130131130132130133130134130135130136130137130138130139130140130141130142130143130144130145130146130147130148130149130150130151130152130153130154130155130156130157130158130159130160130161130162130163130164130165130166130167130168130169130170130171130172130173130174130175130176130177130178130179130180130181130182130183130184130185130186130187130188130189130190130191130192130193130194130195130196130197130198130199130200130201130202130203130204130205130206130207130208130209130210130211130212130213130214130215130216130217130218130219130220130221130222130223130224130225130226130227130228130229130230130231130232130233130234130235130236130237130238130239130240130241130242130243130244130245130246130247130248130249130250130251130252130253130254130255130256130257130258130259130260130261130262130263130264130265130266130267130268130269130270130271130272130273130274130275130276130277130278130279130280130281130282130283130284130285130286130287130288130289130290130291130292130293130294130295130296130297130298130299130300130301130302130303130304130305130306130307130308130309130310130311130312130313130314130315130316130317130318130319130320130321130322130323130324130325130326130327130328130329130330130331130332130333130334130335130336130337130338130339130340130341130342130343130344130345130346130347130348130349130350130351130352130353130354130355130356130357130358130359130360130361130362130363130364130365130366130367130368130369130370130371130372130373130374130375130376130377130378130379130380130381130382130383130384130385130386130387130388130389130390130391130392130393130394130395130396130397130398130399130400130401130402130403130404130405130406130407130408130409130410130411130412130413130414130415130416130417130418130419130420130421130422130423130424130425130426130427130428130429130430130431130432130433130434130435130436130437130438130439130440130441130442130443130444130445130446130447130448130449130450130451130452130453130454130455130456130457130458130459130460130461130462130463130464130465130466130467130468130469130470130471130472130473130474130475130476130477130478130479130480130481130482130483130484130485130486130487130488130489130490130491130492130493130494130495130496130497130498130499130500130501130502130503130504130505130506130507130508130509130510130511130512130513130514130515130516130517130518130519130520130521130522130523130524130525130526130527130528130529130530130531130532130533130534130535130536130537130538130539130540130541130542130543130544130545130546130547130548130549130550130551130552130553130554130555130556130557130558130559130560130561130562130563130564130565130566130567130568130569130570130571130572130573130574130575130576130577130578130579130580130581130582130583130584130585130586130587130588130589130590130591130592130593130594130595130596130597130598130599130600130601130602130603130604130605130606130607130608130609130610130611130612130613130614130615130616130617130618130619130620130621130622130623130624130625130626130627130628130629130630130631130632130633130634130635130636130637130638130639130640130641130642130643130644130645130646130647130648130649130650130651130652130653130654130655130656130657130658130659130660130661130662130663130664130665130666130667130668130669130670130671130672130673130674130675130676130677130678130679130680130681130682130683130684130685130686130687130688130689130690130691130692130693130694130695130696130697130698130699130700130701130702130703130704130705130706130707130708130709130710130711130712130713130714130715130716130717130718130719130720130721130722130723130724130725130726130727130728130729130730130731130732130733130734130735130736130737130738130739130740130741130742130743130744130745130746130747130748130749130750130751130752130753130754130755130756130757130758130759130760130761130762130763130764130765130766130767130768130769130770130771130772130773130774130775130776130777130778130779130780130781130782130783130784130785130786130787130788130789130790130791130792130793130794130795130796130797130798130799130800130801130802130803130804130805130806130807130808130809130810130811130812130813130814130815130816130817130818130819130820130821130822130823130824130825130826130827130828130829130830130831130832130833130834130835130836130837130838130839130840130841130842130843130844130845130846130847130848130849130850130851130852130853130854130855130856130857130858130859130860130861130862130863130864130865130866130867130868130869130870130871130872130873130874130875130876130877130878130879130880130881130882130883130884130885130886130887130888130889130890130891130892130893130894130895130896130897130898130899130900130901130902130903130904130905130906130907130908130909130910130911130912130913130914130915130916130917130918130919130920130921130922130923130924130925130926130927130928130929130930130931130932130933130934130935130936130937130938130939130940130941130942130943130944130945130946130947130948130949130950130951130952130953130954130955130956130957130958130959130960130961130962130963130964130965130966130967130968130969130970130971130972130973130974130975130976130977130978130979130980130981130982130983130984130985130986130987130988130989130990130991130992130993130994130995130996130997130998130999131000131001131002131003131004131005131006131007131008131009131010131011131012131013131014131015131016131017131018131019131020131021131022131023131024131025131026131027131028131029131030131031131032131033131034131035131036131037131038131039131040131041131042131043131044131045131046131047131048131049131050131051131052131053131054131055131056131057131058131059131060131061131062131063131064131065131066131067131068131069131070131071131072131073131074131075131076131077131078131079131080131081131082131083131084131085131086131087131088131089131090131091131092131093131094131095131096131097131098131099131100131101131102131103131104131105131106131107131108131109131110131111131112131113131114131115131116131117131118131119131120131121131122131123131124131125131126131127131128131129131130131131131132131133131134131135131136131137131138131139131140131141131142131143131144131145131146131147131148131149131150131151131152131153131154131155131156131157131158131159131160131161131162131163131164131165131166131167131168131169131170131171131172131173131174131175131176131177131178131179131180131181131182131183131184131185131186131187131188131189131190131191131192131193131194131195131196131197131198131199131200131201131202131203131204131205131206131207131208131209131210131211131212131213131214131215131216131217131218131219131220131221131222131223131224131225131226131227131228131229131230131231131232131233131234131235131236131237131238131239131240131241131242131243131244131245131246131247131248131249131250131251131252131253131254131255131256131257131258131259131260131261131262131263131264131265131266131267131268131269131270131271131272131273131274131275131276131277131278131279131280131281131282131283131284131285131286131287131288131289131290131291131292131293131294131295131296131297131298131299131300131301131302131303131304131305131306131307131308131309131310131311131312131313131314131315131316131317131318131319131320131321131322131323131324131325131326131327131328131329131330131331131332131333131334131335131336131337131338131339131340131341131342131343131344131345131346131347131348131349131350131351131352131353131354131355131356131357131358131359131360131361131362131363131364131365131366131367131368131369131370131371131372131373131374131375131376131377131378131379131380131381131382131383131384131385131386131387131388131389131390131391131392131393131394131395131396131397131398131399131400131401131402131403131404131405131406131407131408131409131410131411131412131413131414131415131416131417131418131419131420131421131422131423131424131425131426131427131428131429131430131431131432131433131434131435131436131437131438131439131440131441131442131443131444131445131446131447131448131449131450131451131452131453131454131455131456131457131458131459131460131461131462131463131464131465131466131467131468131469131470131471131472131473131474131475131476131477131478131479131480131481131482131483131484131485131486131487131488131489131490131491131492131493131494131495131496131497131498131499131500131501131502131503131504131505131506131507131508131509131510131511131512131513131514131515131516131517131518131519131520131521131522131523131524131525131526131527131528131529131530131531131532131533131534131535131536131537131538131539131540131541131542131543131544131545131546131547131548131549131550131551131552131553131554131555131556131557131558131559131560131561131562131563131564131565131566131567131568131569131570131571131572131573131574131575131576131577131578131579131580131581131582131583131584131585131586131587131588131589131590131591131592131593131594131595131596131597131598131599131600131601131602131603131604131605131606131607131608131609131610131611131612131613131614131615131616131617131618131619131620131621131622131623131624131625131626131627131628131629131630131631131632131633131634131635131636131637131638131639131640131641131642131643131644131645131646131647131648131649131650131651131652131653131654131655131656131657131658131659131660131661131662131663131664131665131666131667131668131669131670131671131672131673131674131675131676131677131678131679131680131681131682131683131684131685131686131687131688131689131690131691131692131693131694131695131696131697131698131699131700131701131702131703131704131705131706131707131708131709131710131711131712131713131714131715131716131717131718131719131720131721131722131723131724131725131726131727131728131729131730131731131732131733131734131735131736131737131738131739131740131741131742131743131744131745131746131747131748131749131750131751131752131753131754131755131756131757131758131759131760131761131762131763131764131765131766131767131768131769131770131771131772131773131774131775131776131777131778131779131780131781131782131783131784131785131786131787131788131789131790131791131792131793131794131795131796131797131798131799131800131801131802131803131804131805131806131807131808131809131810131811131812131813131814131815131816131817131818131819131820131821131822131823131824131825131826131827131828131829131830131831131832131833131834131835131836131837131838131839131840131841131842131843131844131845131846131847131848131849131850131851131852131853131854131855131856131857131858131859131860131861131862131863131864131865131866131867131868131869131870131871131872131873131874131875131876131877131878131879131880131881131882131883131884131885131886131887131888131889131890131891131892131893131894131895131896131897131898131899131900131901131902131903131904131905131906131907131908131909131910131911131912131913131914131915131916131917131918131919131920131921131922131923131924131925131926131927131928131929131930131931131932131933131934131935131936131937131938131939131940131941131942131943131944131945131946131947131948131949131950131951131952131953131954131955131956131957131958131959131960131961131962131963131964131965131966131967131968131969131970131971131972131973131974131975131976131977131978131979131980131981131982131983131984131985131986131987131988131989131990131991131992131993131994131995131996131997131998131999132000132001132002132003132004132005132006132007132008132009132010132011132012132013132014132015132016132017132018132019132020132021132022132023132024132025132026132027132028132029132030132031132032132033132034132035132036132037132038132039132040132041132042132043132044132045132046132047132048132049132050132051132052132053132054132055132056132057132058132059132060132061132062132063132064132065132066132067132068132069132070132071132072132073132074132075132076132077132078132079132080132081132082132083132084132085132086132087132088132089132090132091132092132093132094132095132096132097132098132099132100132101132102132103132104132105132106132107132108132109132110132111132112132113132114132115132116132117132118132119132120132121132122132123132124132125132126132127132128132129132130132131132132132133132134132135132136132137132138132139132140132141132142132143132144132145132146132147132148132149132150132151132152132153132154132155132156132157132158132159132160132161132162132163132164132165132166132167132168132169132170132171132172132173132174132175132176132177132178132179132180132181132182132183132184132185132186132187132188132189132190132191132192132193132194132195132196132197132198132199132200132201132202132203132204132205132206132207132208132209132210132211132212132213132214132215132216132217132218132219132220132221132222132223132224132225132226132227132228132229132230132231132232132233132234132235132236132237132238132239132240132241132242132243132244132245132246132247132248132249132250132251132252132253132254132255132256132257132258132259132260132261132262132263132264132265132266132267132268132269132270132271132272132273132274132275132276132277132278132279132280132281132282132283132284132285132286132287132288132289132290132291132292132293132294132295132296132297132298132299132300132301132302132303132304132305132306132307132308132309132310132311132312132313132314132315132316132317132318132319132320132321132322132323132324132325132326132327132328132329132330132331132332132333132334132335132336132337132338132339132340132341132342132343132344132345132346132347132348132349132350132351132352132353132354132355132356132357132358132359132360132361132362132363132364132365132366132367132368132369132370132371132372132373132374132375132376132377132378132379132380132381132382132383132384132385132386132387132388132389132390132391132392132393132394132395132396132397132398132399132400132401132402132403132404132405132406132407132408132409132410132411132412132413132414132415132416132417132418132419132420132421132422132423132424132425132426132427132428132429132430132431132432132433132434132435132436132437132438132439132440132441132442132443132444132445132446132447132448132449132450132451132452132453132454132455132456132457132458132459132460132461132462132463132464132465132466132467132468132469132470132471132472132473132474132475132476132477132478132479132480132481132482132483132484132485132486132487132488132489132490132491132492132493132494132495132496132497132498132499132500132501132502132503132504132505132506132507132508132509132510132511132512132513132514132515132516132517132518132519132520132521132522132523132524132525132526132527132528132529132530132531132532132533132534132535132536132537132538132539132540132541132542132543132544132545132546132547132548132549132550132551132552132553132554132555132556132557132558132559132560132561132562132563132564132565132566132567132568132569132570132571132572132573132574132575132576132577132578132579132580132581132582132583132584132585132586132587132588132589132590132591132592132593132594132595132596132597132598132599132600132601132602132603132604132605132606132607132608132609132610132611132612132613132614132615132616132617132618132619132620132621132622132623132624132625132626132627132628132629132630132631132632132633132634132635132636132637132638132639132640132641132642132643132644132645132646132647132648132649132650132651132652132653132654132655132656132657132658132659132660132661132662132663132664132665132666132667132668132669132670132671132672132673132674132675132676132677132678132679132680132681132682132683132684132685132686132687132688132689132690132691132692132693132694132695132696132697132698132699132700132701132702132703132704132705132706132707132708132709132710132711132712132713132714132715132716132717132718132719132720132721132722132723132724132725132726132727132728132729132730132731132732132733132734132735132736132737132738132739132740132741132742132743132744132745132746132747132748132749132750132751132752132753132754132755132756132757132758132759132760132761132762132763132764132765132766132767132768132769132770132771132772132773132774132775132776132777132778132779132780132781132782132783132784132785132786132787132788132789132790132791132792132793132794132795132796132797132798132799132800132801132802132803132804132805132806132807132808132809132810132811132812132813132814132815132816132817132818132819132820132821132822132823132824132825132826132827132828132829132830132831132832132833132834132835132836132837132838132839132840132841132842132843132844132845132846132847132848132849132850132851132852132853132854132855132856132857132858132859132860132861132862132863132864132865132866132867132868132869132870132871132872132873132874132875132876132877132878132879132880132881132882132883132884132885132886132887132888132889132890132891132892132893132894132895132896132897132898132899132900132901132902132903132904132905132906132907132908132909132910132911132912132913132914132915132916132917132918132919132920132921132922132923132924132925132926132927132928132929132930132931132932132933132934132935132936132937132938132939132940132941132942132943132944132945132946132947132948132949132950132951132952132953132954132955132956132957132958132959132960132961132962132963132964132965132966132967132968132969132970132971132972132973132974132975132976132977132978132979132980132981132982132983132984132985132986132987132988132989132990132991132992132993132994132995132996132997132998132999133000133001133002133003133004133005133006133007133008133009133010133011133012133013133014133015133016133017133018133019133020133021133022133023133024133025133026133027133028133029133030133031133032133033133034133035133036133037133038133039133040133041133042133043133044133045133046133047133048133049133050133051133052133053133054133055133056133057133058133059133060133061133062133063133064133065133066133067133068133069133070133071133072133073133074133075133076133077133078133079133080133081133082133083133084133085133086133087133088133089133090133091133092133093133094133095133096133097133098133099133100133101133102133103133104133105133106133107133108133109133110133111133112133113133114133115133116133117133118133119133120133121133122133123133124133125133126133127133128133129133130133131133132133133133134133135133136133137133138133139133140133141133142133143133144133145133146133147133148133149133150133151133152133153133154133155133156133157133158133159133160133161133162133163133164133165133166133167133168133169133170133171133172133173133174133175133176133177133178133179133180133181133182133183133184133185133186133187133188133189133190133191133192133193133194133195133196133197133198133199133200133201133202133203133204133205133206133207133208133209133210133211133212133213133214133215133216133217133218133219133220133221133222133223133224133225133226133227133228133229133230133231133232133233133234133235133236133237133238133239133240133241133242133243133244133245133246133247133248133249133250133251133252133253133254133255133256133257133258133259133260133261133262133263133264133265133266133267133268133269133270133271133272133273133274133275133276133277133278133279133280133281133282133283133284133285133286133287133288133289133290133291133292133293133294133295133296133297133298133299133300133301133302133303133304133305133306133307133308133309133310133311133312133313133314133315133316133317133318133319133320133321133322133323133324133325133326133327133328133329133330133331133332133333133334133335133336133337133338133339133340133341133342133343133344133345133346133347133348133349133350133351133352133353133354133355133356133357133358133359133360133361133362133363133364133365133366133367133368133369133370133371133372133373133374133375133376133377133378133379133380133381133382133383133384133385133386133387133388133389133390133391133392133393133394133395133396133397133398133399133400133401133402133403133404133405133406133407133408133409133410133411133412133413133414133415133416133417133418133419133420133421133422133423133424133425133426133427133428133429133430133431133432133433133434133435133436133437133438133439133440133441133442133443133444133445133446133447133448133449133450133451133452133453133454133455133456133457133458133459133460133461133462133463133464133465133466133467133468133469133470133471133472133473133474133475133476133477133478133479133480133481133482133483133484133485133486133487133488133489133490133491133492133493133494133495133496133497133498133499133500133501133502133503133504133505133506133507133508133509133510133511133512133513133514133515133516133517133518133519133520133521133522133523133524133525133526133527133528133529133530133531133532133533133534133535133536133537133538133539133540133541133542133543133544133545133546133547133548133549133550133551133552133553133554133555133556133557133558133559133560133561133562133563133564133565133566133567133568133569133570133571133572133573133574133575133576133577133578133579133580133581133582133583133584133585133586133587133588133589133590133591133592133593133594133595133596133597133598133599133600133601133602133603133604133605133606133607133608133609133610133611133612133613133614133615133616133617133618133619133620133621133622133623133624133625133626133627133628133629133630133631133632133633133634133635133636133637133638133639133640133641133642133643133644133645133646133647133648133649133650133651133652133653133654133655133656133657133658133659133660133661133662133663133664133665133666133667133668133669133670133671133672133673133674133675133676133677133678133679133680133681133682133683133684133685133686133687133688133689133690133691133692133693133694133695133696133697133698133699133700133701133702133703133704133705133706133707133708133709133710133711133712133713133714133715133716133717133718133719133720133721133722133723133724133725133726133727133728133729133730133731133732133733133734133735133736133737133738133739133740133741133742133743133744133745133746133747133748133749133750133751133752133753133754133755133756133757133758133759133760133761133762133763133764133765133766133767133768133769133770133771133772133773133774133775133776133777133778133779133780133781133782133783133784133785133786133787133788133789133790133791133792133793133794133795133796133797133798133799133800133801133802133803133804133805133806133807133808133809133810133811133812133813133814133815133816133817133818133819133820133821133822133823133824133825133826133827133828133829133830133831133832133833133834133835133836133837133838133839133840133841133842133843133844133845133846133847133848133849133850133851133852133853133854133855133856133857133858133859133860133861133862133863133864133865133866133867133868133869133870133871133872133873133874133875133876133877133878133879133880133881133882133883133884133885133886133887133888133889133890133891133892133893133894133895133896133897133898133899133900133901133902133903133904133905133906133907133908133909133910133911133912133913133914133915133916133917133918133919133920133921133922133923133924133925133926133927133928133929133930133931133932133933133934133935133936133937133938133939133940133941133942133943133944133945133946133947133948133949133950133951133952133953133954133955133956133957133958133959133960133961133962133963133964133965133966133967133968133969133970133971133972133973133974133975133976133977133978133979133980133981133982133983133984133985133986133987133988133989133990133991133992133993133994133995133996133997133998133999134000134001134002134003134004134005134006134007134008134009134010134011134012134013134014134015134016134017134018134019134020134021134022134023134024134025134026134027134028134029134030134031134032134033134034134035134036134037134038134039134040134041134042134043134044134045134046134047134048134049134050134051134052134053134054134055134056134057134058134059134060134061134062134063134064134065134066134067134068134069134070134071134072134073134074134075134076134077134078134079134080134081134082134083134084134085134086134087134088134089134090134091134092134093134094134095134096134097134098134099134100134101134102134103134104134105134106134107134108134109134110134111134112134113134114134115134116134117134118134119134120134121134122134123134124134125134126134127134128134129134130134131134132134133134134134135134136134137134138134139134140134141134142134143134144134145134146134147134148134149134150134151134152134153134154134155134156134157134158134159134160134161134162134163134164134165134166134167134168134169134170134171134172134173134174134175134176134177134178134179134180134181134182134183134184134185134186134187134188134189134190134191134192134193134194134195134196134197134198134199134200134201134202134203134204134205134206134207134208134209134210134211134212134213134214134215134216134217134218134219134220134221134222134223134224134225134226134227134228134229134230134231134232134233134234134235134236134237134238134239134240134241134242134243134244134245134246134247134248134249134250134251134252134253134254134255134256134257134258134259134260134261134262134263134264134265134266134267134268134269134270134271134272134273134274134275134276134277134278134279134280134281134282134283134284134285134286134287134288134289134290134291134292134293134294134295134296134297134298134299134300134301134302134303134304134305134306134307134308134309134310134311134312134313134314134315134316134317134318134319134320134321134322134323134324134325134326134327134328134329134330134331134332134333134334134335134336134337134338134339134340134341134342134343134344134345134346134347134348134349134350134351134352134353134354134355134356134357134358134359134360134361134362134363134364134365134366134367134368134369134370134371134372134373134374134375134376134377134378134379134380134381134382134383134384134385134386134387134388134389134390134391134392134393134394134395134396134397134398134399134400134401134402134403134404134405134406134407134408134409134410134411134412134413134414134415134416134417134418134419134420134421134422134423134424134425134426134427134428134429134430134431134432134433134434134435134436134437134438134439134440134441134442134443134444134445134446134447134448134449134450134451134452134453134454134455134456134457134458134459134460134461134462134463134464134465134466134467134468134469134470134471134472134473134474134475134476134477134478134479134480134481134482134483134484134485134486134487134488134489134490134491134492134493134494134495134496134497134498134499134500134501134502134503134504134505134506134507134508134509134510134511134512134513134514134515134516134517134518134519134520134521134522134523134524134525134526134527134528134529134530134531134532134533134534134535134536134537134538134539134540134541134542134543134544134545134546134547134548134549134550134551134552134553134554134555134556134557134558134559134560134561134562134563134564134565134566134567134568134569134570134571134572134573134574134575134576134577134578134579134580134581134582134583134584134585134586134587134588134589134590134591134592134593134594134595134596134597134598134599134600134601134602134603134604134605134606134607134608134609134610134611134612134613134614134615134616134617134618134619134620134621134622134623134624134625134626134627134628134629134630134631134632134633134634134635134636134637134638134639134640134641134642134643134644134645134646134647134648134649134650134651134652134653134654134655134656134657134658134659134660134661134662134663134664134665134666134667134668134669134670134671134672134673134674134675134676134677134678134679134680134681134682134683134684134685134686134687134688134689134690134691134692134693134694134695134696134697134698134699134700134701134702134703134704134705134706134707134708134709134710134711134712134713134714134715134716134717134718134719134720134721134722134723134724134725134726134727134728134729134730134731134732134733134734134735134736134737134738134739134740134741134742134743134744134745134746134747134748134749134750134751134752134753134754134755134756134757134758134759134760134761134762134763134764134765134766134767134768134769134770134771134772134773134774134775134776134777134778134779134780134781134782134783134784134785134786134787134788134789134790134791134792134793134794134795134796134797134798134799134800134801134802134803134804134805134806134807134808134809134810134811134812134813134814134815134816134817134818134819134820134821134822134823134824134825134826134827134828134829134830134831134832134833134834134835134836134837134838134839134840134841134842134843134844134845134846134847134848134849134850134851134852134853134854134855134856134857134858134859134860134861134862134863134864134865134866134867134868134869134870134871134872134873134874134875134876134877134878134879134880134881134882134883134884134885134886134887134888134889134890134891134892134893134894134895134896134897134898134899134900134901134902134903134904134905134906134907134908134909134910134911134912134913134914134915134916134917134918134919134920134921134922134923134924134925134926134927134928134929134930134931134932134933134934134935134936134937134938134939134940134941134942134943134944134945134946134947134948134949134950134951134952134953134954134955134956134957134958134959134960134961134962134963134964134965134966134967134968134969134970134971134972134973134974134975134976134977134978134979134980134981134982134983134984134985134986134987134988134989134990134991134992134993134994134995134996134997134998134999135000135001135002135003135004135005135006135007135008135009135010135011135012135013135014135015135016135017135018135019135020135021135022135023135024135025135026135027135028135029135030135031135032135033135034135035135036135037135038135039135040135041135042135043135044135045135046135047135048135049135050135051135052135053135054135055135056135057135058135059135060135061135062135063135064135065135066135067135068135069135070135071135072135073135074135075135076135077135078135079135080135081135082135083135084135085135086135087135088135089135090135091135092135093135094135095135096135097135098135099135100135101135102135103135104135105135106135107135108135109135110135111135112135113135114135115135116135117135118135119135120135121135122135123135124135125135126135127135128135129135130135131135132135133135134135135135136135137135138135139135140135141135142135143135144135145135146135147135148135149135150135151135152135153135154135155135156135157135158135159135160135161135162135163135164135165135166135167135168135169135170135171135172135173135174135175135176135177135178135179135180135181135182135183135184135185135186135187135188135189135190135191135192135193135194135195135196135197135198135199135200135201135202135203135204135205135206135207135208135209135210135211135212135213135214135215135216135217135218135219135220135221135222135223135224135225135226135227135228135229135230135231135232135233135234135235135236135237135238135239135240135241135242135243135244135245135246135247135248135249135250135251135252135253135254135255135256135257135258135259135260135261135262135263135264135265135266135267135268135269135270135271135272135273135274135275135276135277135278135279135280135281135282135283135284135285135286135287135288135289135290135291135292135293135294135295135296135297135298135299135300135301135302135303135304135305135306135307135308135309135310135311135312135313135314135315135316135317135318135319135320135321135322135323135324135325135326135327135328135329135330135331135332135333135334135335135336135337135338135339135340135341135342135343135344135345135346135347135348135349135350135351135352135353135354135355135356135357135358135359135360135361135362135363135364135365135366135367135368135369135370135371135372135373135374135375135376135377135378135379135380135381135382135383135384135385135386135387135388135389135390135391135392135393135394135395135396135397135398135399135400135401135402135403135404135405135406135407135408135409135410135411135412135413135414135415135416135417135418135419135420135421135422135423135424135425135426135427135428135429135430135431135432135433135434135435135436135437135438135439135440135441135442135443135444135445135446135447135448135449135450135451135452135453135454135455135456135457135458135459135460135461135462135463135464135465135466135467135468135469135470135471135472135473135474135475135476135477135478135479135480135481135482135483135484135485135486135487135488135489135490135491135492135493135494135495135496135497135498135499135500135501135502135503135504135505135506135507135508135509135510135511135512135513135514135515135516135517135518135519135520135521135522135523135524135525135526135527135528135529135530135531135532135533135534135535135536135537135538135539135540135541135542135543135544135545135546135547135548135549135550135551135552135553135554135555135556135557135558135559135560135561135562135563135564135565135566135567135568135569135570135571135572135573135574135575135576135577135578135579135580135581135582135583135584135585135586135587135588135589135590135591135592135593135594135595135596135597135598135599135600135601135602135603135604135605135606135607135608135609135610135611135612135613135614135615135616135617135618135619135620135621135622135623135624135625135626135627135628135629135630135631135632135633135634135635135636135637135638135639135640135641135642135643135644135645135646135647135648135649135650135651135652135653135654135655135656135657135658135659135660135661135662135663135664135665135666135667135668135669135670135671135672135673135674135675135676135677135678135679135680135681135682135683135684135685135686135687135688135689135690135691135692135693135694135695135696135697135698135699135700135701135702135703135704135705135706135707135708135709135710135711135712135713135714135715135716135717135718135719135720135721135722135723135724135725135726135727135728135729135730135731135732135733135734135735135736135737135738135739135740135741135742135743135744135745135746135747135748135749135750135751135752135753135754135755135756135757135758135759135760135761135762135763135764135765135766135767135768135769135770135771135772135773135774135775135776135777135778135779135780135781135782135783135784135785135786135787135788135789135790135791135792135793135794135795135796135797135798135799135800135801135802135803135804135805135806135807135808135809135810135811135812135813135814135815135816135817135818135819135820135821135822135823135824135825135826135827135828135829135830135831135832135833135834135835135836135837135838135839135840135841135842135843135844135845135846135847135848135849135850135851135852135853135854135855135856135857135858135859135860135861135862135863135864135865135866135867135868135869135870135871135872135873135874135875135876135877135878135879135880135881135882135883135884135885135886135887135888135889135890135891135892135893135894135895135896135897135898135899135900135901135902135903135904135905135906135907135908135909135910135911135912135913135914135915135916135917135918135919135920135921135922135923135924135925135926135927135928135929135930135931135932135933135934135935135936135937135938135939135940135941135942135943135944135945135946135947135948135949135950135951135952135953135954135955135956135957135958135959135960135961135962135963135964135965135966135967135968135969135970135971135972135973135974135975135976135977135978135979135980135981135982135983135984135985135986135987135988135989135990135991135992135993135994135995135996135997135998135999136000136001136002136003136004136005136006136007136008136009136010136011136012136013136014136015136016136017136018136019136020136021136022136023136024136025136026136027136028136029136030136031136032136033136034136035136036136037136038136039136040136041136042136043136044136045136046136047136048136049136050136051136052136053136054136055136056136057136058136059136060136061136062136063136064136065136066136067136068136069136070136071136072136073136074136075136076136077136078136079136080136081136082136083136084136085136086136087136088136089136090136091136092136093136094136095136096136097136098136099136100136101136102136103136104136105136106136107136108136109136110136111136112136113136114136115136116136117136118136119136120136121136122136123136124136125136126136127136128136129136130136131136132136133136134136135136136136137136138136139136140136141136142136143136144136145136146136147136148136149136150136151136152136153136154136155136156136157136158136159136160136161136162136163136164136165136166136167136168136169136170136171136172136173136174136175136176136177136178136179136180136181136182136183136184136185136186136187136188136189136190136191136192136193136194136195136196136197136198136199136200136201136202136203136204136205136206136207136208136209136210136211136212136213136214136215136216136217136218136219136220136221136222136223136224136225136226136227136228136229136230136231136232136233136234136235136236136237136238136239136240136241136242136243136244136245136246136247136248136249136250136251136252136253136254136255136256136257136258136259136260136261136262136263136264136265136266136267136268136269136270136271136272136273136274136275136276136277136278136279136280136281136282136283136284136285136286136287136288136289136290136291136292136293136294136295136296136297136298136299136300136301136302136303136304136305136306136307136308136309136310136311136312136313136314136315136316136317136318136319136320136321136322136323136324136325136326136327136328136329136330136331136332136333136334136335136336136337136338136339136340136341136342136343136344136345136346136347136348136349136350136351136352136353136354136355136356136357136358136359136360136361136362136363136364136365136366136367136368136369136370136371136372136373136374136375136376136377136378136379136380136381136382136383136384136385136386136387136388136389136390136391136392136393136394136395136396136397136398136399136400136401136402136403136404136405136406136407136408136409136410136411136412136413136414136415136416136417136418136419136420136421136422136423136424136425136426136427136428136429136430136431136432136433136434136435136436136437136438136439136440136441136442136443136444136445136446136447136448136449136450136451136452136453136454136455136456136457136458136459136460136461136462136463136464136465136466136467136468136469136470136471136472136473136474136475136476136477136478136479136480136481136482136483136484136485136486136487136488136489136490136491136492136493136494136495136496136497136498136499136500136501136502136503136504136505136506136507136508136509136510136511136512136513136514136515136516136517136518136519136520136521136522136523136524136525136526136527136528136529136530136531136532136533136534136535136536136537136538136539136540136541136542136543136544136545136546136547136548136549136550136551136552136553136554136555136556136557136558136559136560136561136562136563136564136565136566136567136568136569136570136571136572136573136574136575136576136577136578
  1. diff -Nur linux-3.18.8/arch/arm/boot/dts/bcm2708.dtsi linux-rpi/arch/arm/boot/dts/bcm2708.dtsi
  2. --- linux-3.18.8/arch/arm/boot/dts/bcm2708.dtsi 1970-01-01 01:00:00.000000000 +0100
  3. +++ linux-rpi/arch/arm/boot/dts/bcm2708.dtsi 2015-03-05 14:40:11.021715840 +0100
  4. @@ -0,0 +1,109 @@
  5. +/include/ "skeleton.dtsi"
  6. +
  7. +/ {
  8. + compatible = "brcm,bcm2708";
  9. + model = "BCM2708";
  10. +
  11. + interrupt-parent = <&intc>;
  12. +
  13. + chosen {
  14. + /* No padding required - the boot loader can do that. */
  15. + bootargs = "";
  16. + };
  17. +
  18. + soc: soc {
  19. + compatible = "simple-bus";
  20. + #address-cells = <1>;
  21. + #size-cells = <1>;
  22. + ranges = <0x7e000000 0x20000000 0x01000000>;
  23. +
  24. + intc: interrupt-controller {
  25. + compatible = "brcm,bcm2708-armctrl-ic";
  26. + reg = <0x7e00b200 0x200>;
  27. + interrupt-controller;
  28. + #interrupt-cells = <2>;
  29. + };
  30. +
  31. + gpio: gpio {
  32. + compatible = "brcm,bcm2835-gpio";
  33. + reg = <0x7e200000 0xb4>;
  34. + interrupts = <2 17>, <2 18>;
  35. +
  36. + gpio-controller;
  37. + #gpio-cells = <2>;
  38. +
  39. + interrupt-controller;
  40. + #interrupt-cells = <2>;
  41. + };
  42. +
  43. + i2s: i2s@7e203000 {
  44. + compatible = "brcm,bcm2708-i2s";
  45. + reg = <0x7e203000 0x20>,
  46. + <0x7e101098 0x02>;
  47. +
  48. + //dmas = <&dma 2>,
  49. + // <&dma 3>;
  50. + dma-names = "tx", "rx";
  51. + status = "disabled";
  52. + };
  53. +
  54. + spi0: spi@7e204000 {
  55. + compatible = "brcm,bcm2708-spi";
  56. + reg = <0x7e204000 0x1000>;
  57. + interrupts = <2 22>;
  58. + clocks = <&clk_spi>;
  59. + #address-cells = <1>;
  60. + #size-cells = <0>;
  61. + status = "disabled";
  62. + };
  63. +
  64. + i2c0: i2c@7e205000 {
  65. + compatible = "brcm,bcm2708-i2c";
  66. + reg = <0x7e205000 0x1000>;
  67. + interrupts = <2 21>;
  68. + clocks = <&clk_i2c>;
  69. + #address-cells = <1>;
  70. + #size-cells = <0>;
  71. + status = "disabled";
  72. + };
  73. +
  74. + i2c1: i2c@7e804000 {
  75. + compatible = "brcm,bcm2708-i2c";
  76. + reg = <0x7e804000 0x1000>;
  77. + interrupts = <2 21>;
  78. + clocks = <&clk_i2c>;
  79. + #address-cells = <1>;
  80. + #size-cells = <0>;
  81. + status = "disabled";
  82. + };
  83. +
  84. + leds: leds {
  85. + compatible = "gpio-leds";
  86. + };
  87. +
  88. + arm-pmu {
  89. + compatible = "arm,arm1176-pmu";
  90. + };
  91. + };
  92. +
  93. + clocks {
  94. + compatible = "simple-bus";
  95. + #address-cells = <1>;
  96. + #size-cells = <0>;
  97. +
  98. + clk_i2c: i2c {
  99. + compatible = "fixed-clock";
  100. + reg = <1>;
  101. + #clock-cells = <0>;
  102. + clock-frequency = <250000000>;
  103. + };
  104. +
  105. + clk_spi: clock@2 {
  106. + compatible = "fixed-clock";
  107. + reg = <2>;
  108. + #clock-cells = <0>;
  109. + clock-output-names = "spi";
  110. + clock-frequency = <250000000>;
  111. + };
  112. + };
  113. +};
  114. diff -Nur linux-3.18.8/arch/arm/boot/dts/bcm2708-rpi-b.dts linux-rpi/arch/arm/boot/dts/bcm2708-rpi-b.dts
  115. --- linux-3.18.8/arch/arm/boot/dts/bcm2708-rpi-b.dts 1970-01-01 01:00:00.000000000 +0100
  116. +++ linux-rpi/arch/arm/boot/dts/bcm2708-rpi-b.dts 2015-03-05 14:40:11.021715840 +0100
  117. @@ -0,0 +1,107 @@
  118. +/dts-v1/;
  119. +
  120. +/include/ "bcm2708.dtsi"
  121. +
  122. +/ {
  123. + compatible = "brcm,bcm2708";
  124. + model = "Raspberry Pi Model B";
  125. +
  126. + aliases {
  127. + soc = &soc;
  128. + spi0 = &spi0;
  129. + i2c0 = &i2c0;
  130. + i2c1 = &i2c1;
  131. + i2s = &i2s;
  132. + gpio = &gpio;
  133. + intc = &intc;
  134. + leds = &leds;
  135. + sound = &sound;
  136. + };
  137. +
  138. + sound: sound {
  139. + };
  140. +};
  141. +
  142. +&gpio {
  143. + spi0_pins: spi0_pins {
  144. + brcm,pins = <7 8 9 10 11>;
  145. + brcm,function = <4>; /* alt0 */
  146. + };
  147. +
  148. + i2c0_pins: i2c0 {
  149. + brcm,pins = <0 1>;
  150. + brcm,function = <4>;
  151. + };
  152. +
  153. + i2c1_pins: i2c1 {
  154. + brcm,pins = <2 3>;
  155. + brcm,function = <4>;
  156. + };
  157. +
  158. + i2s_pins: i2s {
  159. + brcm,pins = <28 29 30 31>;
  160. + brcm,function = <4>; /* alt0 */
  161. + };
  162. +};
  163. +
  164. +&spi0 {
  165. + pinctrl-names = "default";
  166. + pinctrl-0 = <&spi0_pins>;
  167. +
  168. + spidev@0{
  169. + compatible = "spidev";
  170. + reg = <0>; /* CE0 */
  171. + #address-cells = <1>;
  172. + #size-cells = <0>;
  173. + spi-max-frequency = <500000>;
  174. + };
  175. +
  176. + spidev@1{
  177. + compatible = "spidev";
  178. + reg = <1>; /* CE1 */
  179. + #address-cells = <1>;
  180. + #size-cells = <0>;
  181. + spi-max-frequency = <500000>;
  182. + };
  183. +};
  184. +
  185. +&i2c0 {
  186. + pinctrl-names = "default";
  187. + pinctrl-0 = <&i2c0_pins>;
  188. + clock-frequency = <100000>;
  189. +};
  190. +
  191. +&i2c1 {
  192. + pinctrl-names = "default";
  193. + pinctrl-0 = <&i2c1_pins>;
  194. + clock-frequency = <100000>;
  195. +};
  196. +
  197. +&i2s {
  198. + #sound-dai-cells = <0>;
  199. + pinctrl-names = "default";
  200. + pinctrl-0 = <&i2s_pins>;
  201. +};
  202. +
  203. +&leds {
  204. + act_led: act {
  205. + label = "led0";
  206. + linux,default-trigger = "mmc0";
  207. + gpios = <&gpio 16 1>;
  208. + };
  209. +};
  210. +
  211. +/ {
  212. + __overrides__ {
  213. + i2s = <&i2s>,"status";
  214. + spi = <&spi0>,"status";
  215. + i2c0 = <&i2c0>,"status";
  216. + i2c1 = <&i2c1>,"status";
  217. + i2c0_baudrate = <&i2c0>,"clock-frequency:0";
  218. + i2c1_baudrate = <&i2c1>,"clock-frequency:0";
  219. +
  220. + act_led_gpio = <&act_led>,"gpios:4";
  221. + act_led_activelow = <&act_led>,"gpios:8";
  222. + act_led_trigger = <&act_led>,"linux,default-trigger";
  223. + };
  224. +};
  225. diff -Nur linux-3.18.8/arch/arm/boot/dts/bcm2708-rpi-b-plus.dts linux-rpi/arch/arm/boot/dts/bcm2708-rpi-b-plus.dts
  226. --- linux-3.18.8/arch/arm/boot/dts/bcm2708-rpi-b-plus.dts 1970-01-01 01:00:00.000000000 +0100
  227. +++ linux-rpi/arch/arm/boot/dts/bcm2708-rpi-b-plus.dts 2015-03-05 14:40:11.021715840 +0100
  228. @@ -0,0 +1,117 @@
  229. +/dts-v1/;
  230. +
  231. +/include/ "bcm2708.dtsi"
  232. +
  233. +/ {
  234. + compatible = "brcm,bcm2708";
  235. + model = "Raspberry Pi Model B+";
  236. +
  237. + aliases {
  238. + soc = &soc;
  239. + spi0 = &spi0;
  240. + i2c0 = &i2c0;
  241. + i2c1 = &i2c1;
  242. + i2s = &i2s;
  243. + gpio = &gpio;
  244. + intc = &intc;
  245. + leds = &leds;
  246. + sound = &sound;
  247. + };
  248. +
  249. + sound: sound {
  250. + };
  251. +};
  252. +
  253. +&gpio {
  254. + spi0_pins: spi0_pins {
  255. + brcm,pins = <7 8 9 10 11>;
  256. + brcm,function = <4>; /* alt0 */
  257. + };
  258. +
  259. + i2c0_pins: i2c0 {
  260. + brcm,pins = <0 1>;
  261. + brcm,function = <4>;
  262. + };
  263. +
  264. + i2c1_pins: i2c1 {
  265. + brcm,pins = <2 3>;
  266. + brcm,function = <4>;
  267. + };
  268. +
  269. + i2s_pins: i2s {
  270. + brcm,pins = <18 19 20 21>;
  271. + brcm,function = <4>; /* alt0 */
  272. + };
  273. +};
  274. +
  275. +&spi0 {
  276. + pinctrl-names = "default";
  277. + pinctrl-0 = <&spi0_pins>;
  278. +
  279. + spidev@0{
  280. + compatible = "spidev";
  281. + reg = <0>; /* CE0 */
  282. + #address-cells = <1>;
  283. + #size-cells = <0>;
  284. + spi-max-frequency = <500000>;
  285. + };
  286. +
  287. + spidev@1{
  288. + compatible = "spidev";
  289. + reg = <1>; /* CE1 */
  290. + #address-cells = <1>;
  291. + #size-cells = <0>;
  292. + spi-max-frequency = <500000>;
  293. + };
  294. +};
  295. +
  296. +&i2c0 {
  297. + pinctrl-names = "default";
  298. + pinctrl-0 = <&i2c0_pins>;
  299. + clock-frequency = <100000>;
  300. +};
  301. +
  302. +&i2c1 {
  303. + pinctrl-names = "default";
  304. + pinctrl-0 = <&i2c1_pins>;
  305. + clock-frequency = <100000>;
  306. +};
  307. +
  308. +&i2s {
  309. + #sound-dai-cells = <0>;
  310. + pinctrl-names = "default";
  311. + pinctrl-0 = <&i2s_pins>;
  312. +};
  313. +
  314. +&leds {
  315. + act_led: act {
  316. + label = "led0";
  317. + linux,default-trigger = "mmc0";
  318. + gpios = <&gpio 47 0>;
  319. + };
  320. +
  321. + pwr_led: pwr {
  322. + label = "led1";
  323. + linux,default-trigger = "input";
  324. + gpios = <&gpio 35 0>;
  325. + };
  326. +};
  327. +
  328. +/ {
  329. + __overrides__ {
  330. + i2s = <&i2s>,"status";
  331. + spi = <&spi0>,"status";
  332. + i2c0 = <&i2c0>,"status";
  333. + i2c1 = <&i2c1>,"status";
  334. + i2c0_baudrate = <&i2c0>,"clock-frequency:0";
  335. + i2c1_baudrate = <&i2c1>,"clock-frequency:0";
  336. +
  337. + act_led_gpio = <&act_led>,"gpios:4";
  338. + act_led_activelow = <&act_led>,"gpios:8";
  339. + act_led_trigger = <&act_led>,"linux,default-trigger";
  340. +
  341. + pwr_led_gpio = <&pwr_led>,"gpios:4";
  342. + pwr_led_activelow = <&pwr_led>,"gpios:8";
  343. + pwr_led_trigger = <&pwr_led>,"linux,default-trigger";
  344. + };
  345. +};
  346. diff -Nur linux-3.18.8/arch/arm/boot/dts/bcm2709.dtsi linux-rpi/arch/arm/boot/dts/bcm2709.dtsi
  347. --- linux-3.18.8/arch/arm/boot/dts/bcm2709.dtsi 1970-01-01 01:00:00.000000000 +0100
  348. +++ linux-rpi/arch/arm/boot/dts/bcm2709.dtsi 2015-03-05 14:40:11.021715840 +0100
  349. @@ -0,0 +1,160 @@
  350. +/include/ "skeleton.dtsi"
  351. +
  352. +/ {
  353. + compatible = "brcm,bcm2709";
  354. + model = "BCM2709";
  355. +
  356. + interrupt-parent = <&intc>;
  357. +
  358. + chosen {
  359. + /* No padding required - the boot loader can do that. */
  360. + bootargs = "";
  361. + };
  362. +
  363. + soc: soc {
  364. + compatible = "simple-bus";
  365. + #address-cells = <1>;
  366. + #size-cells = <1>;
  367. + ranges = <0x7e000000 0x3f000000 0x01000000>;
  368. +
  369. + intc: interrupt-controller {
  370. + compatible = "brcm,bcm2708-armctrl-ic";
  371. + reg = <0x7e00b200 0x200>;
  372. + interrupt-controller;
  373. + #interrupt-cells = <2>;
  374. + };
  375. +
  376. + gpio: gpio {
  377. + compatible = "brcm,bcm2835-gpio";
  378. + reg = <0x7e200000 0xb4>;
  379. + interrupts = <2 17>, <2 18>;
  380. +
  381. + gpio-controller;
  382. + #gpio-cells = <2>;
  383. +
  384. + interrupt-controller;
  385. + #interrupt-cells = <2>;
  386. + };
  387. +
  388. + i2s: i2s@7e203000 {
  389. + compatible = "brcm,bcm2708-i2s";
  390. + reg = <0x7e203000 0x20>,
  391. + <0x7e101098 0x02>;
  392. +
  393. + //dmas = <&dma 2>,
  394. + // <&dma 3>;
  395. + dma-names = "tx", "rx";
  396. + status = "disabled";
  397. + };
  398. +
  399. + spi0: spi@7e204000 {
  400. + compatible = "brcm,bcm2708-spi";
  401. + reg = <0x7e204000 0x1000>;
  402. + interrupts = <2 22>;
  403. + clocks = <&clk_spi>;
  404. + #address-cells = <1>;
  405. + #size-cells = <0>;
  406. + status = "disabled";
  407. + };
  408. +
  409. + i2c0: i2c@7e205000 {
  410. + compatible = "brcm,bcm2708-i2c";
  411. + reg = <0x7e205000 0x1000>;
  412. + interrupts = <2 21>;
  413. + clocks = <&clk_i2c>;
  414. + #address-cells = <1>;
  415. + #size-cells = <0>;
  416. + status = "disabled";
  417. + };
  418. +
  419. + i2c1: i2c@7e804000 {
  420. + compatible = "brcm,bcm2708-i2c";
  421. + reg = <0x7e804000 0x1000>;
  422. + interrupts = <2 21>;
  423. + clocks = <&clk_i2c>;
  424. + #address-cells = <1>;
  425. + #size-cells = <0>;
  426. + status = "disabled";
  427. + };
  428. +
  429. + leds: leds {
  430. + compatible = "gpio-leds";
  431. + };
  432. +
  433. + arm-pmu {
  434. + compatible = "arm,cortex-a7-pmu";
  435. + interrupts = <3 9>;
  436. + };
  437. + };
  438. +
  439. + clocks {
  440. + compatible = "simple-bus";
  441. + #address-cells = <1>;
  442. + #size-cells = <0>;
  443. +
  444. + clk_i2c: i2c {
  445. + compatible = "fixed-clock";
  446. + reg = <1>;
  447. + #clock-cells = <0>;
  448. + clock-frequency = <250000000>;
  449. + };
  450. +
  451. + clk_spi: clock@2 {
  452. + compatible = "fixed-clock";
  453. + reg = <2>;
  454. + #clock-cells = <0>;
  455. + clock-output-names = "spi";
  456. + clock-frequency = <250000000>;
  457. + };
  458. + };
  459. +
  460. + timer {
  461. + compatible = "arm,armv7-timer";
  462. + clock-frequency = <19200000>;
  463. + interrupts = <3 0>, // PHYS_SECURE_PPI
  464. + <3 1>, // PHYS_NONSECURE_PPI
  465. + <3 3>, // VIRT_PPI
  466. + <3 2>; // HYP_PPI
  467. + always-on;
  468. + };
  469. +
  470. + cpus: cpus {
  471. + #address-cells = <1>;
  472. + #size-cells = <0>;
  473. +
  474. + v7_cpu0: cpu@0 {
  475. + device_type = "cpu";
  476. + compatible = "arm,cortex-a7";
  477. + reg = <0xf00>;
  478. + clock-frequency = <800000000>;
  479. + };
  480. +
  481. + v7_cpu1: cpu@1 {
  482. + device_type = "cpu";
  483. + compatible = "arm,cortex-a7";
  484. + reg = <0xf01>;
  485. + clock-frequency = <800000000>;
  486. + };
  487. +
  488. + v7_cpu2: cpu@2 {
  489. + device_type = "cpu";
  490. + compatible = "arm,cortex-a7";
  491. + reg = <0xf02>;
  492. + clock-frequency = <800000000>;
  493. + };
  494. +
  495. + v7_cpu3: cpu@3 {
  496. + device_type = "cpu";
  497. + compatible = "arm,cortex-a7";
  498. + reg = <0xf03>;
  499. + clock-frequency = <800000000>;
  500. + };
  501. + };
  502. +
  503. + __overrides__ {
  504. + arm_freq = <&v7_cpu0>, "clock-frequency:0",
  505. + <&v7_cpu1>, "clock-frequency:0",
  506. + <&v7_cpu2>, "clock-frequency:0",
  507. + <&v7_cpu3>, "clock-frequency:0";
  508. + };
  509. +};
  510. diff -Nur linux-3.18.8/arch/arm/boot/dts/bcm2709-rpi-2-b.dts linux-rpi/arch/arm/boot/dts/bcm2709-rpi-2-b.dts
  511. --- linux-3.18.8/arch/arm/boot/dts/bcm2709-rpi-2-b.dts 1970-01-01 01:00:00.000000000 +0100
  512. +++ linux-rpi/arch/arm/boot/dts/bcm2709-rpi-2-b.dts 2015-03-05 14:40:11.021715840 +0100
  513. @@ -0,0 +1,117 @@
  514. +/dts-v1/;
  515. +
  516. +/include/ "bcm2709.dtsi"
  517. +
  518. +/ {
  519. + compatible = "brcm,bcm2709";
  520. + model = "Raspberry Pi 2 Model B";
  521. +
  522. + aliases {
  523. + soc = &soc;
  524. + spi0 = &spi0;
  525. + i2c0 = &i2c0;
  526. + i2c1 = &i2c1;
  527. + i2s = &i2s;
  528. + gpio = &gpio;
  529. + intc = &intc;
  530. + leds = &leds;
  531. + sound = &sound;
  532. + };
  533. +
  534. + sound: sound {
  535. + };
  536. +};
  537. +
  538. +&gpio {
  539. + spi0_pins: spi0_pins {
  540. + brcm,pins = <7 8 9 10 11>;
  541. + brcm,function = <4>; /* alt0 */
  542. + };
  543. +
  544. + i2c0_pins: i2c0 {
  545. + brcm,pins = <0 1>;
  546. + brcm,function = <4>;
  547. + };
  548. +
  549. + i2c1_pins: i2c1 {
  550. + brcm,pins = <2 3>;
  551. + brcm,function = <4>;
  552. + };
  553. +
  554. + i2s_pins: i2s {
  555. + brcm,pins = <18 19 20 21>;
  556. + brcm,function = <4>; /* alt0 */
  557. + };
  558. +};
  559. +
  560. +&spi0 {
  561. + pinctrl-names = "default";
  562. + pinctrl-0 = <&spi0_pins>;
  563. +
  564. + spidev@0{
  565. + compatible = "spidev";
  566. + reg = <0>; /* CE0 */
  567. + #address-cells = <1>;
  568. + #size-cells = <0>;
  569. + spi-max-frequency = <500000>;
  570. + };
  571. +
  572. + spidev@1{
  573. + compatible = "spidev";
  574. + reg = <1>; /* CE1 */
  575. + #address-cells = <1>;
  576. + #size-cells = <0>;
  577. + spi-max-frequency = <500000>;
  578. + };
  579. +};
  580. +
  581. +&i2c0 {
  582. + pinctrl-names = "default";
  583. + pinctrl-0 = <&i2c0_pins>;
  584. + clock-frequency = <100000>;
  585. +};
  586. +
  587. +&i2c1 {
  588. + pinctrl-names = "default";
  589. + pinctrl-0 = <&i2c1_pins>;
  590. + clock-frequency = <100000>;
  591. +};
  592. +
  593. +&i2s {
  594. + #sound-dai-cells = <0>;
  595. + pinctrl-names = "default";
  596. + pinctrl-0 = <&i2s_pins>;
  597. +};
  598. +
  599. +&leds {
  600. + act_led: act {
  601. + label = "led0";
  602. + linux,default-trigger = "mmc0";
  603. + gpios = <&gpio 47 0>;
  604. + };
  605. +
  606. + pwr_led: pwr {
  607. + label = "led1";
  608. + linux,default-trigger = "input";
  609. + gpios = <&gpio 35 0>;
  610. + };
  611. +};
  612. +
  613. +/ {
  614. + __overrides__ {
  615. + i2s = <&i2s>,"status";
  616. + spi = <&spi0>,"status";
  617. + i2c0 = <&i2c0>,"status";
  618. + i2c1 = <&i2c1>,"status";
  619. + i2c0_baudrate = <&i2c0>,"clock-frequency:0";
  620. + i2c1_baudrate = <&i2c1>,"clock-frequency:0";
  621. +
  622. + act_led_gpio = <&act_led>,"gpios:4";
  623. + act_led_activelow = <&act_led>,"gpios:8";
  624. + act_led_trigger = <&act_led>,"linux,default-trigger";
  625. +
  626. + pwr_led_gpio = <&pwr_led>,"gpios:4";
  627. + pwr_led_activelow = <&pwr_led>,"gpios:8";
  628. + pwr_led_trigger = <&pwr_led>,"linux,default-trigger";
  629. + };
  630. +};
  631. diff -Nur linux-3.18.8/arch/arm/boot/dts/bmp085_i2c-sensor-overlay.dts linux-rpi/arch/arm/boot/dts/bmp085_i2c-sensor-overlay.dts
  632. --- linux-3.18.8/arch/arm/boot/dts/bmp085_i2c-sensor-overlay.dts 1970-01-01 01:00:00.000000000 +0100
  633. +++ linux-rpi/arch/arm/boot/dts/bmp085_i2c-sensor-overlay.dts 2015-03-05 14:40:11.021715840 +0100
  634. @@ -0,0 +1,23 @@
  635. +// Definitions for BMP085/BMP180 digital barometric pressure and temperature sensors from Bosch Sensortec
  636. +/dts-v1/;
  637. +/plugin/;
  638. +
  639. +/ {
  640. + compatible = "brcm,bcm2708";
  641. +
  642. + fragment@0 {
  643. + target = <&i2c1>;
  644. + __overlay__ {
  645. + #address-cells = <1>;
  646. + #size-cells = <0>;
  647. + status = "okay";
  648. +
  649. + bmp085@77 {
  650. + compatible = "bosch,bmp085";
  651. + reg = <0x77>;
  652. + default-oversampling = <3>;
  653. + status = "okay";
  654. + };
  655. + };
  656. + };
  657. +};
  658. diff -Nur linux-3.18.8/arch/arm/boot/dts/ds1307-rtc-overlay.dts linux-rpi/arch/arm/boot/dts/ds1307-rtc-overlay.dts
  659. --- linux-3.18.8/arch/arm/boot/dts/ds1307-rtc-overlay.dts 1970-01-01 01:00:00.000000000 +0100
  660. +++ linux-rpi/arch/arm/boot/dts/ds1307-rtc-overlay.dts 2015-03-05 14:40:11.025715840 +0100
  661. @@ -0,0 +1,22 @@
  662. +// Definitions for DS1307 Real Time Clock
  663. +/dts-v1/;
  664. +/plugin/;
  665. +
  666. +/ {
  667. + compatible = "brcm,bcm2708";
  668. +
  669. + fragment@0 {
  670. + target = <&i2c1>;
  671. + __overlay__ {
  672. + #address-cells = <1>;
  673. + #size-cells = <0>;
  674. + status = "okay";
  675. +
  676. + ds1307@68 {
  677. + compatible = "maxim,ds1307";
  678. + reg = <0x68>;
  679. + status = "okay";
  680. + };
  681. + };
  682. + };
  683. +};
  684. diff -Nur linux-3.18.8/arch/arm/boot/dts/enc28j60-overlay.dts linux-rpi/arch/arm/boot/dts/enc28j60-overlay.dts
  685. --- linux-3.18.8/arch/arm/boot/dts/enc28j60-overlay.dts 1970-01-01 01:00:00.000000000 +0100
  686. +++ linux-rpi/arch/arm/boot/dts/enc28j60-overlay.dts 2015-03-05 14:40:11.025715840 +0100
  687. @@ -0,0 +1,29 @@
  688. +// Overlay for the Microchip ENC28J60 Ethernet Controller
  689. +/dts-v1/;
  690. +/plugin/;
  691. +
  692. +/ {
  693. + compatible = "brcm,bcm2708";
  694. +
  695. + fragment@0 {
  696. + target = <&spi0>;
  697. + __overlay__ {
  698. + /* needed to avoid dtc warning */
  699. + #address-cells = <1>;
  700. + #size-cells = <0>;
  701. +
  702. + status = "okay";
  703. +
  704. + spidev@0{
  705. + status = "disabled";
  706. + };
  707. +
  708. + enc28j60@0{
  709. + compatible = "microchip,enc28j60";
  710. + reg = <0>; /* CE0 */
  711. + spi-max-frequency = <12000000>;
  712. + status = "okay";
  713. + };
  714. + };
  715. + };
  716. +};
  717. diff -Nur linux-3.18.8/arch/arm/boot/dts/hifiberry-amp-overlay.dts linux-rpi/arch/arm/boot/dts/hifiberry-amp-overlay.dts
  718. --- linux-3.18.8/arch/arm/boot/dts/hifiberry-amp-overlay.dts 1970-01-01 01:00:00.000000000 +0100
  719. +++ linux-rpi/arch/arm/boot/dts/hifiberry-amp-overlay.dts 2015-03-05 14:40:11.025715840 +0100
  720. @@ -0,0 +1,39 @@
  721. +// Definitions for HiFiBerry Amp/Amp+
  722. +/dts-v1/;
  723. +/plugin/;
  724. +
  725. +/ {
  726. + compatible = "brcm,bcm2708";
  727. +
  728. + fragment@0 {
  729. + target = <&sound>;
  730. + __overlay__ {
  731. + compatible = "hifiberry,hifiberry-amp";
  732. + i2s-controller = <&i2s>;
  733. + status = "okay";
  734. + };
  735. + };
  736. +
  737. + fragment@1 {
  738. + target = <&i2s>;
  739. + __overlay__ {
  740. + status = "okay";
  741. + };
  742. + };
  743. +
  744. + fragment@2 {
  745. + target = <&i2c1>;
  746. + __overlay__ {
  747. + #address-cells = <1>;
  748. + #size-cells = <0>;
  749. + status = "okay";
  750. +
  751. + tas5713@1b {
  752. + #sound-dai-cells = <0>;
  753. + compatible = "ti,tas5713";
  754. + reg = <0x1b>;
  755. + status = "okay";
  756. + };
  757. + };
  758. + };
  759. +};
  760. diff -Nur linux-3.18.8/arch/arm/boot/dts/hifiberry-dac-overlay.dts linux-rpi/arch/arm/boot/dts/hifiberry-dac-overlay.dts
  761. --- linux-3.18.8/arch/arm/boot/dts/hifiberry-dac-overlay.dts 1970-01-01 01:00:00.000000000 +0100
  762. +++ linux-rpi/arch/arm/boot/dts/hifiberry-dac-overlay.dts 2015-03-05 14:40:11.025715840 +0100
  763. @@ -0,0 +1,34 @@
  764. +// Definitions for HiFiBerry DAC
  765. +/dts-v1/;
  766. +/plugin/;
  767. +
  768. +/ {
  769. + compatible = "brcm,bcm2708";
  770. +
  771. + fragment@0 {
  772. + target = <&sound>;
  773. + __overlay__ {
  774. + compatible = "hifiberry,hifiberry-dac";
  775. + i2s-controller = <&i2s>;
  776. + status = "okay";
  777. + };
  778. + };
  779. +
  780. + fragment@1 {
  781. + target = <&i2s>;
  782. + __overlay__ {
  783. + status = "okay";
  784. + };
  785. + };
  786. +
  787. + fragment@2 {
  788. + target-path = "/";
  789. + __overlay__ {
  790. + pcm5102a-codec {
  791. + #sound-dai-cells = <0>;
  792. + compatible = "ti,pcm5102a";
  793. + status = "okay";
  794. + };
  795. + };
  796. + };
  797. +};
  798. diff -Nur linux-3.18.8/arch/arm/boot/dts/hifiberry-dacplus-overlay.dts linux-rpi/arch/arm/boot/dts/hifiberry-dacplus-overlay.dts
  799. --- linux-3.18.8/arch/arm/boot/dts/hifiberry-dacplus-overlay.dts 1970-01-01 01:00:00.000000000 +0100
  800. +++ linux-rpi/arch/arm/boot/dts/hifiberry-dacplus-overlay.dts 2015-03-05 14:40:11.025715840 +0100
  801. @@ -0,0 +1,39 @@
  802. +// Definitions for HiFiBerry DAC+
  803. +/dts-v1/;
  804. +/plugin/;
  805. +
  806. +/ {
  807. + compatible = "brcm,bcm2708";
  808. +
  809. + fragment@0 {
  810. + target = <&sound>;
  811. + __overlay__ {
  812. + compatible = "hifiberry,hifiberry-dacplus";
  813. + i2s-controller = <&i2s>;
  814. + status = "okay";
  815. + };
  816. + };
  817. +
  818. + fragment@1 {
  819. + target = <&i2s>;
  820. + __overlay__ {
  821. + status = "okay";
  822. + };
  823. + };
  824. +
  825. + fragment@2 {
  826. + target = <&i2c1>;
  827. + __overlay__ {
  828. + #address-cells = <1>;
  829. + #size-cells = <0>;
  830. + status = "okay";
  831. +
  832. + pcm5122@4d {
  833. + #sound-dai-cells = <0>;
  834. + compatible = "ti,pcm5122";
  835. + reg = <0x4d>;
  836. + status = "okay";
  837. + };
  838. + };
  839. + };
  840. +};
  841. diff -Nur linux-3.18.8/arch/arm/boot/dts/hifiberry-digi-overlay.dts linux-rpi/arch/arm/boot/dts/hifiberry-digi-overlay.dts
  842. --- linux-3.18.8/arch/arm/boot/dts/hifiberry-digi-overlay.dts 1970-01-01 01:00:00.000000000 +0100
  843. +++ linux-rpi/arch/arm/boot/dts/hifiberry-digi-overlay.dts 2015-03-05 14:40:11.025715840 +0100
  844. @@ -0,0 +1,39 @@
  845. +// Definitions for HiFiBerry Digi
  846. +/dts-v1/;
  847. +/plugin/;
  848. +
  849. +/ {
  850. + compatible = "brcm,bcm2708";
  851. +
  852. + fragment@0 {
  853. + target = <&sound>;
  854. + __overlay__ {
  855. + compatible = "hifiberry,hifiberry-digi";
  856. + i2s-controller = <&i2s>;
  857. + status = "okay";
  858. + };
  859. + };
  860. +
  861. + fragment@1 {
  862. + target = <&i2s>;
  863. + __overlay__ {
  864. + status = "okay";
  865. + };
  866. + };
  867. +
  868. + fragment@2 {
  869. + target = <&i2c1>;
  870. + __overlay__ {
  871. + #address-cells = <1>;
  872. + #size-cells = <0>;
  873. + status = "okay";
  874. +
  875. + wm8804@3b {
  876. + #sound-dai-cells = <0>;
  877. + compatible = "wlf,wm8804";
  878. + reg = <0x3b>;
  879. + status = "okay";
  880. + };
  881. + };
  882. + };
  883. +};
  884. diff -Nur linux-3.18.8/arch/arm/boot/dts/hy28a-overlay.dts linux-rpi/arch/arm/boot/dts/hy28a-overlay.dts
  885. --- linux-3.18.8/arch/arm/boot/dts/hy28a-overlay.dts 1970-01-01 01:00:00.000000000 +0100
  886. +++ linux-rpi/arch/arm/boot/dts/hy28a-overlay.dts 2015-03-05 14:40:11.025715840 +0100
  887. @@ -0,0 +1,87 @@
  888. +/*
  889. + * Device Tree overlay for HY28A display
  890. + *
  891. + */
  892. +
  893. +/dts-v1/;
  894. +/plugin/;
  895. +
  896. +/ {
  897. + compatible = "brcm,bcm2835", "brcm,bcm2708", "brcm,bcm2709";
  898. +
  899. + fragment@0 {
  900. + target = <&spi0>;
  901. + __overlay__ {
  902. + status = "okay";
  903. +
  904. + spidev@0{
  905. + status = "disabled";
  906. + };
  907. +
  908. + spidev@1{
  909. + status = "disabled";
  910. + };
  911. + };
  912. + };
  913. +
  914. + fragment@1 {
  915. + target = <&gpio>;
  916. + __overlay__ {
  917. + hy28a_pins: hy28a_pins {
  918. + brcm,pins = <17 25 18>;
  919. + brcm,function = <0 1 1>; /* in out out */
  920. + };
  921. + };
  922. + };
  923. +
  924. + fragment@2 {
  925. + target = <&spi0>;
  926. + __overlay__ {
  927. + /* needed to avoid dtc warning */
  928. + #address-cells = <1>;
  929. + #size-cells = <0>;
  930. +
  931. + hy28a: hy28a@0{
  932. + compatible = "ilitek,ili9320";
  933. + reg = <0>;
  934. + pinctrl-names = "default";
  935. + pinctrl-0 = <&hy28a_pins>;
  936. +
  937. + spi-max-frequency = <32000000>;
  938. + spi-cpol;
  939. + spi-cpha;
  940. + rotate = <270>;
  941. + bgr;
  942. + fps = <50>;
  943. + buswidth = <8>;
  944. + startbyte = <0x70>;
  945. + reset-gpios = <&gpio 25 0>;
  946. + led-gpios = <&gpio 18 1>;
  947. + debug = <0>;
  948. + };
  949. +
  950. + hy28a_ts: hy28a-ts@1 {
  951. + compatible = "ti,ads7846";
  952. + reg = <1>;
  953. +
  954. + spi-max-frequency = <2000000>;
  955. + interrupts = <17 2>; /* high-to-low edge triggered */
  956. + interrupt-parent = <&gpio>;
  957. + pendown-gpio = <&gpio 17 0>;
  958. + ti,x-plate-ohms = /bits/ 16 <100>;
  959. + ti,pressure-max = /bits/ 16 <255>;
  960. + };
  961. + };
  962. + };
  963. + __overrides__ {
  964. + speed = <&hy28a>,"spi-max-frequency:0";
  965. + rotate = <&hy28a>,"rotate:0";
  966. + fps = <&hy28a>,"fps:0";
  967. + debug = <&hy28a>,"debug:0";
  968. + xohms = <&hy28a_ts>,"ti,x-plate-ohms;0";
  969. + resetgpio = <&hy28a>,"reset-gpios:4",
  970. + <&hy28a_pins>, "brcm,pins:1";
  971. + ledgpio = <&hy28a>,"led-gpios:4",
  972. + <&hy28a_pins>, "brcm,pins:2";
  973. + };
  974. +};
  975. diff -Nur linux-3.18.8/arch/arm/boot/dts/hy28b-overlay.dts linux-rpi/arch/arm/boot/dts/hy28b-overlay.dts
  976. --- linux-3.18.8/arch/arm/boot/dts/hy28b-overlay.dts 1970-01-01 01:00:00.000000000 +0100
  977. +++ linux-rpi/arch/arm/boot/dts/hy28b-overlay.dts 2015-03-05 14:40:11.025715840 +0100
  978. @@ -0,0 +1,142 @@
  979. +/*
  980. + * Device Tree overlay for HY28b display shield by Texy
  981. + *
  982. + */
  983. +
  984. +/dts-v1/;
  985. +/plugin/;
  986. +
  987. +/ {
  988. + compatible = "brcm,bcm2835", "brcm,bcm2708", "brcm,bcm2709";
  989. +
  990. + fragment@0 {
  991. + target = <&spi0>;
  992. + __overlay__ {
  993. + status = "okay";
  994. +
  995. + spidev@0{
  996. + status = "disabled";
  997. + };
  998. +
  999. + spidev@1{
  1000. + status = "disabled";
  1001. + };
  1002. + };
  1003. + };
  1004. +
  1005. + fragment@1 {
  1006. + target = <&gpio>;
  1007. + __overlay__ {
  1008. + hy28b_pins: hy28b_pins {
  1009. + brcm,pins = <17 25 18>;
  1010. + brcm,function = <0 1 1>; /* in out out */
  1011. + };
  1012. + };
  1013. + };
  1014. +
  1015. + fragment@2 {
  1016. + target = <&spi0>;
  1017. + __overlay__ {
  1018. + /* needed to avoid dtc warning */
  1019. + #address-cells = <1>;
  1020. + #size-cells = <0>;
  1021. +
  1022. + hy28b: hy28b@0{
  1023. + compatible = "ilitek,ili9325";
  1024. + reg = <0>;
  1025. + pinctrl-names = "default";
  1026. + pinctrl-0 = <&hy28b_pins>;
  1027. +
  1028. + spi-max-frequency = <48000000>;
  1029. + spi-cpol;
  1030. + spi-cpha;
  1031. + rotate = <270>;
  1032. + bgr;
  1033. + fps = <50>;
  1034. + buswidth = <8>;
  1035. + startbyte = <0x70>;
  1036. + reset-gpios = <&gpio 25 0>;
  1037. + led-gpios = <&gpio 18 1>;
  1038. +
  1039. + gamma = "04 1F 4 7 7 0 7 7 6 0\n0F 00 1 7 4 0 0 0 6 7";
  1040. +
  1041. + init = <0x10000e7 0x0010
  1042. + 0x1000000 0x0001
  1043. + 0x1000001 0x0100
  1044. + 0x1000002 0x0700
  1045. + 0x1000003 0x1030
  1046. + 0x1000004 0x0000
  1047. + 0x1000008 0x0207
  1048. + 0x1000009 0x0000
  1049. + 0x100000a 0x0000
  1050. + 0x100000c 0x0001
  1051. + 0x100000d 0x0000
  1052. + 0x100000f 0x0000
  1053. + 0x1000010 0x0000
  1054. + 0x1000011 0x0007
  1055. + 0x1000012 0x0000
  1056. + 0x1000013 0x0000
  1057. + 0x2000032
  1058. + 0x1000010 0x1590
  1059. + 0x1000011 0x0227
  1060. + 0x2000032
  1061. + 0x1000012 0x009c
  1062. + 0x2000032
  1063. + 0x1000013 0x1900
  1064. + 0x1000029 0x0023
  1065. + 0x100002b 0x000e
  1066. + 0x2000032
  1067. + 0x1000020 0x0000
  1068. + 0x1000021 0x0000
  1069. + 0x2000032
  1070. + 0x1000050 0x0000
  1071. + 0x1000051 0x00ef
  1072. + 0x1000052 0x0000
  1073. + 0x1000053 0x013f
  1074. + 0x1000060 0xa700
  1075. + 0x1000061 0x0001
  1076. + 0x100006a 0x0000
  1077. + 0x1000080 0x0000
  1078. + 0x1000081 0x0000
  1079. + 0x1000082 0x0000
  1080. + 0x1000083 0x0000
  1081. + 0x1000084 0x0000
  1082. + 0x1000085 0x0000
  1083. + 0x1000090 0x0010
  1084. + 0x1000092 0x0000
  1085. + 0x1000093 0x0003
  1086. + 0x1000095 0x0110
  1087. + 0x1000097 0x0000
  1088. + 0x1000098 0x0000
  1089. + 0x1000007 0x0133
  1090. + 0x1000020 0x0000
  1091. + 0x1000021 0x0000
  1092. + 0x2000064>;
  1093. + debug = <0>;
  1094. + };
  1095. +
  1096. + hy28b_ts: hy28b-ts@1 {
  1097. + compatible = "ti,ads7846";
  1098. + reg = <1>;
  1099. +
  1100. + spi-max-frequency = <2000000>;
  1101. + interrupts = <17 2>; /* high-to-low edge triggered */
  1102. + interrupt-parent = <&gpio>;
  1103. + pendown-gpio = <&gpio 17 0>;
  1104. + ti,x-plate-ohms = /bits/ 16 <100>;
  1105. + ti,pressure-max = /bits/ 16 <255>;
  1106. + };
  1107. + };
  1108. + };
  1109. + __overrides__ {
  1110. + speed = <&hy28b>,"spi-max-frequency:0";
  1111. + rotate = <&hy28b>,"rotate:0";
  1112. + fps = <&hy28b>,"fps:0";
  1113. + debug = <&hy28b>,"debug:0";
  1114. + xohms = <&hy28b_ts>,"ti,x-plate-ohms;0";
  1115. + resetgpio = <&hy28b>,"reset-gpios:4",
  1116. + <&hy28b_pins>, "brcm,pins:1";
  1117. + ledgpio = <&hy28b>,"led-gpios:4",
  1118. + <&hy28b_pins>, "brcm,pins:2";
  1119. + };
  1120. +};
  1121. diff -Nur linux-3.18.8/arch/arm/boot/dts/i2c-rtc-overlay.dts linux-rpi/arch/arm/boot/dts/i2c-rtc-overlay.dts
  1122. --- linux-3.18.8/arch/arm/boot/dts/i2c-rtc-overlay.dts 1970-01-01 01:00:00.000000000 +0100
  1123. +++ linux-rpi/arch/arm/boot/dts/i2c-rtc-overlay.dts 2015-03-05 14:40:11.025715840 +0100
  1124. @@ -0,0 +1,43 @@
  1125. +// Definitions for several I2C based Real Time Clocks
  1126. +/dts-v1/;
  1127. +/plugin/;
  1128. +
  1129. +/ {
  1130. + compatible = "brcm,bcm2708";
  1131. +
  1132. + fragment@0 {
  1133. + target = <&i2c1>;
  1134. + __overlay__ {
  1135. + #address-cells = <1>;
  1136. + #size-cells = <0>;
  1137. + status = "okay";
  1138. +
  1139. + ds1307: ds1307@68 {
  1140. + compatible = "maxim,ds1307";
  1141. + reg = <0x68>;
  1142. + status = "disable";
  1143. + };
  1144. + ds3231: ds3231@68 {
  1145. + compatible = "maxim,ds3231";
  1146. + reg = <0x68>;
  1147. + status = "disable";
  1148. + };
  1149. + pcf2127: pcf2127@51 {
  1150. + compatible = "nxp,pcf2127";
  1151. + reg = <0x51>;
  1152. + status = "disable";
  1153. + };
  1154. + pcf8523: pcf8523@68 {
  1155. + compatible = "nxp,pcf8523";
  1156. + reg = <0x68>;
  1157. + status = "disable";
  1158. + };
  1159. + };
  1160. + };
  1161. + __overrides__ {
  1162. + ds1307 = <&ds1307>,"status";
  1163. + ds3231 = <&ds3231>,"status";
  1164. + pcf2127 = <&pcf2127>,"status";
  1165. + pcf8523 = <&pcf8523>,"status";
  1166. + };
  1167. +};
  1168. diff -Nur linux-3.18.8/arch/arm/boot/dts/iqaudio-dac-overlay.dts linux-rpi/arch/arm/boot/dts/iqaudio-dac-overlay.dts
  1169. --- linux-3.18.8/arch/arm/boot/dts/iqaudio-dac-overlay.dts 1970-01-01 01:00:00.000000000 +0100
  1170. +++ linux-rpi/arch/arm/boot/dts/iqaudio-dac-overlay.dts 2015-03-05 14:40:11.061715840 +0100
  1171. @@ -0,0 +1,39 @@
  1172. +// Definitions for IQaudIO DAC
  1173. +/dts-v1/;
  1174. +/plugin/;
  1175. +
  1176. +/ {
  1177. + compatible = "brcm,bcm2708";
  1178. +
  1179. + fragment@0 {
  1180. + target = <&sound>;
  1181. + __overlay__ {
  1182. + compatible = "iqaudio,iqaudio-dac";
  1183. + i2s-controller = <&i2s>;
  1184. + status = "okay";
  1185. + };
  1186. + };
  1187. +
  1188. + fragment@1 {
  1189. + target = <&i2s>;
  1190. + __overlay__ {
  1191. + status = "okay";
  1192. + };
  1193. + };
  1194. +
  1195. + fragment@2 {
  1196. + target = <&i2c1>;
  1197. + __overlay__ {
  1198. + #address-cells = <1>;
  1199. + #size-cells = <0>;
  1200. + status = "okay";
  1201. +
  1202. + pcm5122@4c {
  1203. + #sound-dai-cells = <0>;
  1204. + compatible = "ti,pcm5122";
  1205. + reg = <0x4c>;
  1206. + status = "okay";
  1207. + };
  1208. + };
  1209. + };
  1210. +};
  1211. diff -Nur linux-3.18.8/arch/arm/boot/dts/iqaudio-dacplus-overlay.dts linux-rpi/arch/arm/boot/dts/iqaudio-dacplus-overlay.dts
  1212. --- linux-3.18.8/arch/arm/boot/dts/iqaudio-dacplus-overlay.dts 1970-01-01 01:00:00.000000000 +0100
  1213. +++ linux-rpi/arch/arm/boot/dts/iqaudio-dacplus-overlay.dts 2015-03-05 14:40:11.061715840 +0100
  1214. @@ -0,0 +1,39 @@
  1215. +// Definitions for IQaudIO DAC+
  1216. +/dts-v1/;
  1217. +/plugin/;
  1218. +
  1219. +/ {
  1220. + compatible = "brcm,bcm2708";
  1221. +
  1222. + fragment@0 {
  1223. + target = <&sound>;
  1224. + __overlay__ {
  1225. + compatible = "iqaudio,iqaudio-dac";
  1226. + i2s-controller = <&i2s>;
  1227. + status = "okay";
  1228. + };
  1229. + };
  1230. +
  1231. + fragment@1 {
  1232. + target = <&i2s>;
  1233. + __overlay__ {
  1234. + status = "okay";
  1235. + };
  1236. + };
  1237. +
  1238. + fragment@2 {
  1239. + target = <&i2c1>;
  1240. + __overlay__ {
  1241. + #address-cells = <1>;
  1242. + #size-cells = <0>;
  1243. + status = "okay";
  1244. +
  1245. + pcm5122@4c {
  1246. + #sound-dai-cells = <0>;
  1247. + compatible = "ti,pcm5122";
  1248. + reg = <0x4c>;
  1249. + status = "okay";
  1250. + };
  1251. + };
  1252. + };
  1253. +};
  1254. diff -Nur linux-3.18.8/arch/arm/boot/dts/lirc-rpi-overlay.dts linux-rpi/arch/arm/boot/dts/lirc-rpi-overlay.dts
  1255. --- linux-3.18.8/arch/arm/boot/dts/lirc-rpi-overlay.dts 1970-01-01 01:00:00.000000000 +0100
  1256. +++ linux-rpi/arch/arm/boot/dts/lirc-rpi-overlay.dts 2015-03-05 14:40:11.065715840 +0100
  1257. @@ -0,0 +1,57 @@
  1258. +// Definitions for lirc-rpi module
  1259. +/dts-v1/;
  1260. +/plugin/;
  1261. +
  1262. +/ {
  1263. + compatible = "brcm,bcm2708";
  1264. +
  1265. + fragment@0 {
  1266. + target-path = "/";
  1267. + __overlay__ {
  1268. + lirc_rpi: lirc_rpi {
  1269. + compatible = "rpi,lirc-rpi";
  1270. + pinctrl-names = "default";
  1271. + pinctrl-0 = <&lirc_pins>;
  1272. + status = "okay";
  1273. +
  1274. + // Override autodetection of IR receiver circuit
  1275. + // (0 = active high, 1 = active low, -1 = no override )
  1276. + rpi,sense = <0xffffffff>;
  1277. +
  1278. + // Software carrier
  1279. + // (0 = off, 1 = on)
  1280. + rpi,softcarrier = <1>;
  1281. +
  1282. + // Invert output
  1283. + // (0 = off, 1 = on)
  1284. + rpi,invert = <0>;
  1285. +
  1286. + // Enable debugging messages
  1287. + // (0 = off, 1 = on)
  1288. + rpi,debug = <0>;
  1289. + };
  1290. + };
  1291. + };
  1292. +
  1293. + fragment@1 {
  1294. + target = <&gpio>;
  1295. + __overlay__ {
  1296. + lirc_pins: lirc_pins {
  1297. + brcm,pins = <17 18>;
  1298. + brcm,function = <1 0>; // out in
  1299. + brcm,pull = <0 1>; // off down
  1300. + };
  1301. + };
  1302. + };
  1303. +
  1304. + __overrides__ {
  1305. + gpio_out_pin = <&lirc_pins>,"brcm,pins:0";
  1306. + gpio_in_pin = <&lirc_pins>,"brcm,pins:4";
  1307. + gpio_in_pull = <&lirc_pins>,"brcm,pull:4";
  1308. +
  1309. + sense = <&lirc_rpi>,"rpi,sense:0";
  1310. + softcarrier = <&lirc_rpi>,"rpi,softcarrier:0";
  1311. + invert = <&lirc_rpi>,"rpi,invert:0";
  1312. + debug = <&lirc_rpi>,"rpi,debug:0";
  1313. + };
  1314. +};
  1315. diff -Nur linux-3.18.8/arch/arm/boot/dts/Makefile linux-rpi/arch/arm/boot/dts/Makefile
  1316. --- linux-3.18.8/arch/arm/boot/dts/Makefile 2015-02-27 02:49:36.000000000 +0100
  1317. +++ linux-rpi/arch/arm/boot/dts/Makefile 2015-03-05 14:40:11.017715840 +0100
  1318. @@ -53,7 +53,41 @@
  1319. dtb-$(CONFIG_ARCH_ATLAS6) += atlas6-evb.dtb
  1320. dtb-$(CONFIG_ARCH_AXXIA) += axm5516-amarillo.dtb
  1321. +
  1322. +# Raspberry Pi
  1323. +ifeq ($(CONFIG_BCM2708_DT),y)
  1324. + RPI_DT_OVERLAYS=y
  1325. +endif
  1326. +ifeq ($(CONFIG_BCM2709_DT),y)
  1327. + RPI_DT_OVERLAYS=y
  1328. +endif
  1329. +dtb-$(CONFIG_BCM2708_DT) += bcm2708-rpi-b.dtb
  1330. +dtb-$(CONFIG_BCM2708_DT) += bcm2708-rpi-b-plus.dtb
  1331. +dtb-$(CONFIG_BCM2709_DT) += bcm2709-rpi-2-b.dtb
  1332. +dtb-$(RPI_DT_OVERLAYS) += bmp085_i2c-sensor-overlay.dtb
  1333. +dtb-$(RPI_DT_OVERLAYS) += ds1307-rtc-overlay.dtb
  1334. +dtb-$(RPI_DT_OVERLAYS) += enc28j60-overlay.dtb
  1335. +dtb-$(RPI_DT_OVERLAYS) += i2c-rtc-overlay.dtb
  1336. +dtb-$(RPI_DT_OVERLAYS) += hifiberry-dac-overlay.dtb
  1337. +dtb-$(RPI_DT_OVERLAYS) += hifiberry-dacplus-overlay.dtb
  1338. +dtb-$(RPI_DT_OVERLAYS) += hifiberry-digi-overlay.dtb
  1339. +dtb-$(RPI_DT_OVERLAYS) += hifiberry-amp-overlay.dtb
  1340. +dtb-$(RPI_DT_OVERLAYS) += hy28a-overlay.dtb
  1341. +dtb-$(RPI_DT_OVERLAYS) += hy28b-overlay.dtb
  1342. +dtb-$(RPI_DT_OVERLAYS) += iqaudio-dac-overlay.dtb
  1343. +dtb-$(RPI_DT_OVERLAYS) += iqaudio-dacplus-overlay.dtb
  1344. +dtb-$(RPI_DT_OVERLAYS) += lirc-rpi-overlay.dtb
  1345. +dtb-$(RPI_DT_OVERLAYS) += pcf2127-rtc-overlay.dtb
  1346. +dtb-$(RPI_DT_OVERLAYS) += pcf8523-rtc-overlay.dtb
  1347. +dtb-$(RPI_DT_OVERLAYS) += piscreen-overlay.dtb
  1348. +dtb-$(RPI_DT_OVERLAYS) += pps-gpio-overlay.dtb
  1349. +dtb-$(RPI_DT_OVERLAYS) += rpi-display-overlay.dtb
  1350. +dtb-$(RPI_DT_OVERLAYS) += w1-gpio-overlay.dtb
  1351. +dtb-$(RPI_DT_OVERLAYS) += w1-gpio-pullup-overlay.dtb
  1352. +dtb-$(RPI_DT_OVERLAYS) += spi-bcm2835-overlay.dtb
  1353. +dtb-$(RPI_DT_OVERLAYS) += mcp2515-can0-overlay.dtb
  1354. dtb-$(CONFIG_ARCH_BCM2835) += bcm2835-rpi-b.dtb
  1355. +
  1356. dtb-$(CONFIG_ARCH_BCM_5301X) += bcm4708-netgear-r6250.dtb
  1357. dtb-$(CONFIG_ARCH_BCM_63XX) += bcm963138dvt.dtb
  1358. dtb-$(CONFIG_ARCH_BCM_MOBILE) += bcm28155-ap.dtb \
  1359. @@ -519,6 +553,12 @@
  1360. targets += dtbs dtbs_install
  1361. targets += $(dtb-y)
  1362. +
  1363. +endif
  1364. +
  1365. +# Enable fixups to support overlays on BCM2708 platforms
  1366. +ifeq ($(RPI_DT_OVERLAYS),y)
  1367. + DTC_FLAGS ?= -@
  1368. endif
  1369. # *.dtb used to be generated in the directory above. Clean out the
  1370. diff -Nur linux-3.18.8/arch/arm/boot/dts/mcp2515-can0-overlay.dts linux-rpi/arch/arm/boot/dts/mcp2515-can0-overlay.dts
  1371. --- linux-3.18.8/arch/arm/boot/dts/mcp2515-can0-overlay.dts 1970-01-01 01:00:00.000000000 +0100
  1372. +++ linux-rpi/arch/arm/boot/dts/mcp2515-can0-overlay.dts 2015-03-05 14:40:11.065715840 +0100
  1373. @@ -0,0 +1,69 @@
  1374. +/*
  1375. + * Device tree overlay for mcp251x/can0 on spi0.0
  1376. + */
  1377. +
  1378. +/dts-v1/;
  1379. +/plugin/;
  1380. +
  1381. +/ {
  1382. + compatible = "brcm,bcm2835", "brcm,bcm2836", "brcm,bcm2708", "brcm,bcm2709";
  1383. + /* disable spi-dev for spi0.0 */
  1384. + fragment@0 {
  1385. + target = <&spi0>;
  1386. + __overlay__ {
  1387. + status = "okay";
  1388. + spidev@0{
  1389. + status = "disabled";
  1390. + };
  1391. + };
  1392. + };
  1393. +
  1394. + /* the interrupt pin of the can-controller */
  1395. + fragment@1 {
  1396. + target = <&gpio>;
  1397. + __overlay__ {
  1398. + can0_pins: can0_pins {
  1399. + brcm,pins = <25>;
  1400. + brcm,function = <0>; /* input */
  1401. + };
  1402. + };
  1403. + };
  1404. +
  1405. + /* the clock/oscillator of the can-controller */
  1406. + fragment@2 {
  1407. + target-path = "/clocks";
  1408. + __overlay__ {
  1409. + /* external oscillator of mcp2515 on SPI0.0 */
  1410. + can0_osc: can0_osc {
  1411. + compatible = "fixed-clock";
  1412. + #clock-cells = <0>;
  1413. + clock-frequency = <16000000>;
  1414. + };
  1415. + };
  1416. + };
  1417. +
  1418. + /* the spi config of the can-controller itself binding everything together */
  1419. + fragment@3 {
  1420. + target = <&spi0>;
  1421. + __overlay__ {
  1422. + /* needed to avoid dtc warning */
  1423. + #address-cells = <1>;
  1424. + #size-cells = <0>;
  1425. + can0: mcp2515@0 {
  1426. + reg = <0>;
  1427. + compatible = "microchip,mcp2515";
  1428. + pinctrl-names = "default";
  1429. + pinctrl-0 = <&can0_pins>;
  1430. + spi-max-frequency = <10000000>;
  1431. + interrupt-parent = <&gpio>;
  1432. + interrupts = <25 0x2>;
  1433. + clocks = <&can0_osc>;
  1434. + };
  1435. + };
  1436. + };
  1437. + __overrides__ {
  1438. + oscillator = <&can0_osc>,"oscillator-frequency";
  1439. + spimaxfrequency = <&can0>,"spi-max-frequency:0";
  1440. + interrupt = <&can0_pins>,"brcm,pins:0",<&can0>,"interrupts:0";
  1441. + };
  1442. +};
  1443. diff -Nur linux-3.18.8/arch/arm/boot/dts/pcf2127-rtc-overlay.dts linux-rpi/arch/arm/boot/dts/pcf2127-rtc-overlay.dts
  1444. --- linux-3.18.8/arch/arm/boot/dts/pcf2127-rtc-overlay.dts 1970-01-01 01:00:00.000000000 +0100
  1445. +++ linux-rpi/arch/arm/boot/dts/pcf2127-rtc-overlay.dts 2015-03-05 14:40:11.069715840 +0100
  1446. @@ -0,0 +1,22 @@
  1447. +// Definitions for PCF2127 Real Time Clock
  1448. +/dts-v1/;
  1449. +/plugin/;
  1450. +
  1451. +/ {
  1452. + compatible = "brcm,bcm2708";
  1453. +
  1454. + fragment@0 {
  1455. + target = <&i2c1>;
  1456. + __overlay__ {
  1457. + #address-cells = <1>;
  1458. + #size-cells = <0>;
  1459. + status = "okay";
  1460. +
  1461. + pcf2127@51 {
  1462. + compatible = "nxp,pcf2127";
  1463. + reg = <0x51>;
  1464. + status = "okay";
  1465. + };
  1466. + };
  1467. + };
  1468. +};
  1469. diff -Nur linux-3.18.8/arch/arm/boot/dts/pcf8523-rtc-overlay.dts linux-rpi/arch/arm/boot/dts/pcf8523-rtc-overlay.dts
  1470. --- linux-3.18.8/arch/arm/boot/dts/pcf8523-rtc-overlay.dts 1970-01-01 01:00:00.000000000 +0100
  1471. +++ linux-rpi/arch/arm/boot/dts/pcf8523-rtc-overlay.dts 2015-03-05 14:40:11.069715840 +0100
  1472. @@ -0,0 +1,22 @@
  1473. +// Definitions for PCF8523 Real Time Clock
  1474. +/dts-v1/;
  1475. +/plugin/;
  1476. +
  1477. +/ {
  1478. + compatible = "brcm,bcm2708";
  1479. +
  1480. + fragment@0 {
  1481. + target = <&i2c1>;
  1482. + __overlay__ {
  1483. + #address-cells = <1>;
  1484. + #size-cells = <0>;
  1485. + status = "okay";
  1486. +
  1487. + pcf8523@68 {
  1488. + compatible = "nxp,pcf8523";
  1489. + reg = <0x68>;
  1490. + status = "okay";
  1491. + };
  1492. + };
  1493. + };
  1494. +};
  1495. diff -Nur linux-3.18.8/arch/arm/boot/dts/piscreen-overlay.dts linux-rpi/arch/arm/boot/dts/piscreen-overlay.dts
  1496. --- linux-3.18.8/arch/arm/boot/dts/piscreen-overlay.dts 1970-01-01 01:00:00.000000000 +0100
  1497. +++ linux-rpi/arch/arm/boot/dts/piscreen-overlay.dts 2015-03-05 14:40:11.069715840 +0100
  1498. @@ -0,0 +1,94 @@
  1499. +/*
  1500. + * Device Tree overlay for PiScreen 3.5" display shield by Ozzmaker
  1501. + *
  1502. + */
  1503. +
  1504. +/dts-v1/;
  1505. +/plugin/;
  1506. +
  1507. +/ {
  1508. + compatible = "brcm,bcm2835", "brcm,bcm2708", "brcm,bcm2709";
  1509. +
  1510. + fragment@0 {
  1511. + target = <&spi0>;
  1512. + __overlay__ {
  1513. + status = "okay";
  1514. +
  1515. + spidev@0{
  1516. + status = "disabled";
  1517. + };
  1518. +
  1519. + spidev@1{
  1520. + status = "disabled";
  1521. + };
  1522. + };
  1523. + };
  1524. +
  1525. + fragment@1 {
  1526. + target = <&gpio>;
  1527. + __overlay__ {
  1528. + piscreen_pins: piscreen_pins {
  1529. + brcm,pins = <17 25 24 22>;
  1530. + brcm,function = <0 1 1 1>; /* in out out out */
  1531. + };
  1532. + };
  1533. + };
  1534. +
  1535. + fragment@2 {
  1536. + target = <&spi0>;
  1537. + __overlay__ {
  1538. + /* needed to avoid dtc warning */
  1539. + #address-cells = <1>;
  1540. + #size-cells = <0>;
  1541. +
  1542. + piscreen: piscreen@0{
  1543. + compatible = "ilitek,ili9486";
  1544. + reg = <0>;
  1545. + pinctrl-names = "default";
  1546. + pinctrl-0 = <&piscreen_pins>;
  1547. +
  1548. + spi-max-frequency = <32000000>;
  1549. + rotate = <270>;
  1550. + bgr;
  1551. + fps = <30>;
  1552. + buswidth = <8>;
  1553. + regwidth = <16>;
  1554. + reset-gpios = <&gpio 25 0>;
  1555. + dc-gpios = <&gpio 24 0>;
  1556. + led-gpios = <&gpio 22 1>;
  1557. + debug = <0>;
  1558. +
  1559. + init = <0x10000b0 0x00
  1560. + 0x1000011
  1561. + 0x20000ff
  1562. + 0x100003a 0x55
  1563. + 0x1000036 0x28
  1564. + 0x10000c2 0x44
  1565. + 0x10000c5 0x00 0x00 0x00 0x00
  1566. + 0x10000e0 0x0f 0x1f 0x1c 0x0c 0x0f 0x08 0x48 0x98 0x37 0x0a 0x13 0x04 0x11 0x0d 0x00
  1567. + 0x10000e1 0x0f 0x32 0x2e 0x0b 0x0d 0x05 0x47 0x75 0x37 0x06 0x10 0x03 0x24 0x20 0x00
  1568. + 0x10000e2 0x0f 0x32 0x2e 0x0b 0x0d 0x05 0x47 0x75 0x37 0x06 0x10 0x03 0x24 0x20 0x00
  1569. + 0x1000011
  1570. + 0x1000029>;
  1571. + };
  1572. +
  1573. + piscreen-ts@1 {
  1574. + compatible = "ti,ads7846";
  1575. + reg = <1>;
  1576. +
  1577. + spi-max-frequency = <2000000>;
  1578. + interrupts = <17 2>; /* high-to-low edge triggered */
  1579. + interrupt-parent = <&gpio>;
  1580. + pendown-gpio = <&gpio 17 0>;
  1581. + ti,x-plate-ohms = /bits/ 16 <100>;
  1582. + ti,pressure-max = /bits/ 16 <255>;
  1583. + };
  1584. + };
  1585. + };
  1586. + __overrides__ {
  1587. + speed = <&piscreen>,"spi-max-frequency:0";
  1588. + rotate = <&piscreen>,"rotate:0";
  1589. + fps = <&piscreen>,"fps:0";
  1590. + debug = <&piscreen>,"debug:0";
  1591. + };
  1592. +};
  1593. diff -Nur linux-3.18.8/arch/arm/boot/dts/pps-gpio-overlay.dts linux-rpi/arch/arm/boot/dts/pps-gpio-overlay.dts
  1594. --- linux-3.18.8/arch/arm/boot/dts/pps-gpio-overlay.dts 1970-01-01 01:00:00.000000000 +0100
  1595. +++ linux-rpi/arch/arm/boot/dts/pps-gpio-overlay.dts 2015-03-05 14:40:11.069715840 +0100
  1596. @@ -0,0 +1,34 @@
  1597. +/dts-v1/;
  1598. +/plugin/;
  1599. +
  1600. +/ {
  1601. + compatible = "brcm,bcm2708";
  1602. + fragment@0 {
  1603. + target-path = "/";
  1604. + __overlay__ {
  1605. + pps: pps {
  1606. + compatible = "pps-gpio";
  1607. + pinctrl-names = "default";
  1608. + pinctrl-0 = <&pps_pins>;
  1609. + gpios = <&gpio 18 0>;
  1610. + status = "okay";
  1611. + };
  1612. + };
  1613. + };
  1614. +
  1615. + fragment@1 {
  1616. + target = <&gpio>;
  1617. + __overlay__ {
  1618. + pps_pins: pps_pins {
  1619. + brcm,pins = <18>;
  1620. + brcm,function = <0>; // in
  1621. + brcm,pull = <0>; // off
  1622. + };
  1623. + };
  1624. + };
  1625. +
  1626. + __overrides__ {
  1627. + gpiopin = <&pps>,"gpios:4",
  1628. + <&pps_pins>,"brcm,pins:0";
  1629. + };
  1630. +};
  1631. diff -Nur linux-3.18.8/arch/arm/boot/dts/rpi-display-overlay.dts linux-rpi/arch/arm/boot/dts/rpi-display-overlay.dts
  1632. --- linux-3.18.8/arch/arm/boot/dts/rpi-display-overlay.dts 1970-01-01 01:00:00.000000000 +0100
  1633. +++ linux-rpi/arch/arm/boot/dts/rpi-display-overlay.dts 2015-03-05 14:40:11.069715840 +0100
  1634. @@ -0,0 +1,81 @@
  1635. +/*
  1636. + * Device Tree overlay for rpi-display by Watterott
  1637. + *
  1638. + */
  1639. +
  1640. +/dts-v1/;
  1641. +/plugin/;
  1642. +
  1643. +/ {
  1644. + compatible = "brcm,bcm2835", "brcm,bcm2708", "brcm,bcm2709";
  1645. +
  1646. + fragment@0 {
  1647. + target = <&spi0>;
  1648. + __overlay__ {
  1649. + status = "okay";
  1650. +
  1651. + spidev@0{
  1652. + status = "disabled";
  1653. + };
  1654. +
  1655. + spidev@1{
  1656. + status = "disabled";
  1657. + };
  1658. + };
  1659. + };
  1660. +
  1661. + fragment@1 {
  1662. + target = <&gpio>;
  1663. + __overlay__ {
  1664. + rpi_display_pins: rpi_display_pins {
  1665. + brcm,pins = <18 23 24 25>;
  1666. + brcm,function = <1 1 1 0>; /* out out out in */
  1667. + };
  1668. + };
  1669. + };
  1670. +
  1671. + fragment@2 {
  1672. + target = <&spi0>;
  1673. + __overlay__ {
  1674. + /* needed to avoid dtc warning */
  1675. + #address-cells = <1>;
  1676. + #size-cells = <0>;
  1677. +
  1678. + rpidisplay: rpi-display@0{
  1679. + compatible = "ilitek,ili9341";
  1680. + reg = <0>;
  1681. + pinctrl-names = "default";
  1682. + pinctrl-0 = <&rpi_display_pins>;
  1683. +
  1684. + spi-max-frequency = <32000000>;
  1685. + rotate = <270>;
  1686. + bgr;
  1687. + fps = <30>;
  1688. + buswidth = <8>;
  1689. + reset-gpios = <&gpio 23 0>;
  1690. + dc-gpios = <&gpio 24 0>;
  1691. + led-gpios = <&gpio 18 1>;
  1692. + debug = <0>;
  1693. + };
  1694. +
  1695. + rpidisplay_ts: rpi-display-ts@1 {
  1696. + compatible = "ti,ads7846";
  1697. + reg = <1>;
  1698. +
  1699. + spi-max-frequency = <2000000>;
  1700. + interrupts = <25 2>; /* high-to-low edge triggered */
  1701. + interrupt-parent = <&gpio>;
  1702. + pendown-gpio = <&gpio 25 0>;
  1703. + ti,x-plate-ohms = /bits/ 16 <60>;
  1704. + ti,pressure-max = /bits/ 16 <255>;
  1705. + };
  1706. + };
  1707. + };
  1708. + __overrides__ {
  1709. + speed = <&rpidisplay>,"spi-max-frequency:0";
  1710. + rotate = <&rpidisplay>,"rotate:0";
  1711. + fps = <&rpidisplay>,"fps:0";
  1712. + debug = <&rpidisplay>,"debug:0";
  1713. + xohms = <&rpidisplay_ts>,"ti,x-plate-ohms;0";
  1714. + };
  1715. +};
  1716. diff -Nur linux-3.18.8/arch/arm/boot/dts/spi-bcm2835-overlay.dts linux-rpi/arch/arm/boot/dts/spi-bcm2835-overlay.dts
  1717. --- linux-3.18.8/arch/arm/boot/dts/spi-bcm2835-overlay.dts 1970-01-01 01:00:00.000000000 +0100
  1718. +++ linux-rpi/arch/arm/boot/dts/spi-bcm2835-overlay.dts 2015-03-05 14:40:11.073715840 +0100
  1719. @@ -0,0 +1,18 @@
  1720. +/*
  1721. + * Device tree overlay for spi-bcm2835
  1722. + */
  1723. +
  1724. +/dts-v1/;
  1725. +/plugin/;
  1726. +
  1727. +/ {
  1728. + compatible = "brcm,bcm2835", "brcm,bcm2836", "brcm,bcm2708", "brcm,bcm2709";
  1729. + /* setting up compatiblity to allow loading the spi-bcm2835 driver */
  1730. + fragment@0 {
  1731. + target = <&spi0>;
  1732. + __overlay__ {
  1733. + status = "okay";
  1734. + compatible = "brcm,bcm2835-spi";
  1735. + };
  1736. + };
  1737. +};
  1738. diff -Nur linux-3.18.8/arch/arm/boot/dts/w1-gpio-overlay.dts linux-rpi/arch/arm/boot/dts/w1-gpio-overlay.dts
  1739. --- linux-3.18.8/arch/arm/boot/dts/w1-gpio-overlay.dts 1970-01-01 01:00:00.000000000 +0100
  1740. +++ linux-rpi/arch/arm/boot/dts/w1-gpio-overlay.dts 2015-03-05 14:40:11.081715840 +0100
  1741. @@ -0,0 +1,39 @@
  1742. +// Definitions for w1-gpio module (without external pullup)
  1743. +/dts-v1/;
  1744. +/plugin/;
  1745. +
  1746. +/ {
  1747. + compatible = "brcm,bcm2708";
  1748. +
  1749. + fragment@0 {
  1750. + target-path = "/";
  1751. + __overlay__ {
  1752. +
  1753. + w1: onewire@0 {
  1754. + compatible = "w1-gpio";
  1755. + pinctrl-names = "default";
  1756. + pinctrl-0 = <&w1_pins>;
  1757. + gpios = <&gpio 4 0>;
  1758. + rpi,parasitic-power = <0>;
  1759. + status = "okay";
  1760. + };
  1761. + };
  1762. + };
  1763. +
  1764. + fragment@1 {
  1765. + target = <&gpio>;
  1766. + __overlay__ {
  1767. + w1_pins: w1_pins {
  1768. + brcm,pins = <4>;
  1769. + brcm,function = <0>; // in (initially)
  1770. + brcm,pull = <0>; // off
  1771. + };
  1772. + };
  1773. + };
  1774. +
  1775. + __overrides__ {
  1776. + gpiopin = <&w1>,"gpios:4",
  1777. + <&w1_pins>,"brcm,pins:0";
  1778. + pullup = <&w1>,"rpi,parasitic-power:0";
  1779. + };
  1780. +};
  1781. diff -Nur linux-3.18.8/arch/arm/boot/dts/w1-gpio-pullup-overlay.dts linux-rpi/arch/arm/boot/dts/w1-gpio-pullup-overlay.dts
  1782. --- linux-3.18.8/arch/arm/boot/dts/w1-gpio-pullup-overlay.dts 1970-01-01 01:00:00.000000000 +0100
  1783. +++ linux-rpi/arch/arm/boot/dts/w1-gpio-pullup-overlay.dts 2015-03-05 14:40:11.081715840 +0100
  1784. @@ -0,0 +1,41 @@
  1785. +// Definitions for w1-gpio module (with external pullup)
  1786. +/dts-v1/;
  1787. +/plugin/;
  1788. +
  1789. +/ {
  1790. + compatible = "brcm,bcm2708";
  1791. +
  1792. + fragment@0 {
  1793. + target-path = "/";
  1794. + __overlay__ {
  1795. +
  1796. + w1: onewire@0 {
  1797. + compatible = "w1-gpio";
  1798. + pinctrl-names = "default";
  1799. + pinctrl-0 = <&w1_pins>;
  1800. + gpios = <&gpio 4 0>, <&gpio 5 1>;
  1801. + rpi,parasitic-power = <0>;
  1802. + status = "okay";
  1803. + };
  1804. + };
  1805. + };
  1806. +
  1807. + fragment@1 {
  1808. + target = <&gpio>;
  1809. + __overlay__ {
  1810. + w1_pins: w1_pins {
  1811. + brcm,pins = <4 5>;
  1812. + brcm,function = <0 1>; // in out
  1813. + brcm,pull = <0 0>; // off off
  1814. + };
  1815. + };
  1816. + };
  1817. +
  1818. + __overrides__ {
  1819. + gpiopin = <&w1>,"gpios:4",
  1820. + <&w1_pins>,"brcm,pins:0";
  1821. + extpullup = <&w1>,"gpios:16",
  1822. + <&w1_pins>,"brcm,pins:4";
  1823. + pullup = <&w1>,"rpi,parasitic-power:0";
  1824. + };
  1825. +};
  1826. diff -Nur linux-3.18.8/arch/arm/configs/bcm2709_defconfig linux-rpi/arch/arm/configs/bcm2709_defconfig
  1827. --- linux-3.18.8/arch/arm/configs/bcm2709_defconfig 1970-01-01 01:00:00.000000000 +0100
  1828. +++ linux-rpi/arch/arm/configs/bcm2709_defconfig 2015-03-05 14:40:11.085715840 +0100
  1829. @@ -0,0 +1,1193 @@
  1830. +# CONFIG_ARM_PATCH_PHYS_VIRT is not set
  1831. +CONFIG_PHYS_OFFSET=0
  1832. +CONFIG_LOCALVERSION="-v7"
  1833. +# CONFIG_LOCALVERSION_AUTO is not set
  1834. +CONFIG_SYSVIPC=y
  1835. +CONFIG_POSIX_MQUEUE=y
  1836. +CONFIG_FHANDLE=y
  1837. +CONFIG_AUDIT=y
  1838. +CONFIG_NO_HZ=y
  1839. +CONFIG_HIGH_RES_TIMERS=y
  1840. +CONFIG_BSD_PROCESS_ACCT=y
  1841. +CONFIG_BSD_PROCESS_ACCT_V3=y
  1842. +CONFIG_TASKSTATS=y
  1843. +CONFIG_TASK_DELAY_ACCT=y
  1844. +CONFIG_TASK_XACCT=y
  1845. +CONFIG_TASK_IO_ACCOUNTING=y
  1846. +CONFIG_IKCONFIG=y
  1847. +CONFIG_IKCONFIG_PROC=y
  1848. +CONFIG_CGROUP_FREEZER=y
  1849. +CONFIG_CGROUP_DEVICE=y
  1850. +CONFIG_CGROUP_CPUACCT=y
  1851. +CONFIG_RESOURCE_COUNTERS=y
  1852. +CONFIG_MEMCG=y
  1853. +CONFIG_BLK_CGROUP=y
  1854. +CONFIG_NAMESPACES=y
  1855. +CONFIG_SCHED_AUTOGROUP=y
  1856. +CONFIG_BLK_DEV_INITRD=y
  1857. +CONFIG_EMBEDDED=y
  1858. +# CONFIG_COMPAT_BRK is not set
  1859. +CONFIG_PROFILING=y
  1860. +CONFIG_OPROFILE=m
  1861. +CONFIG_KPROBES=y
  1862. +CONFIG_JUMP_LABEL=y
  1863. +CONFIG_MODULES=y
  1864. +CONFIG_MODULE_UNLOAD=y
  1865. +CONFIG_MODVERSIONS=y
  1866. +CONFIG_MODULE_SRCVERSION_ALL=y
  1867. +CONFIG_BLK_DEV_THROTTLING=y
  1868. +CONFIG_PARTITION_ADVANCED=y
  1869. +CONFIG_MAC_PARTITION=y
  1870. +CONFIG_CFQ_GROUP_IOSCHED=y
  1871. +CONFIG_ARCH_BCM2709=y
  1872. +CONFIG_BCM2709_DT=y
  1873. +# CONFIG_CACHE_L2X0 is not set
  1874. +CONFIG_SMP=y
  1875. +CONFIG_HAVE_ARM_ARCH_TIMER=y
  1876. +CONFIG_VMSPLIT_2G=y
  1877. +CONFIG_PREEMPT=y
  1878. +CONFIG_AEABI=y
  1879. +CONFIG_CLEANCACHE=y
  1880. +CONFIG_FRONTSWAP=y
  1881. +CONFIG_CMA=y
  1882. +CONFIG_UACCESS_WITH_MEMCPY=y
  1883. +CONFIG_SECCOMP=y
  1884. +CONFIG_ZBOOT_ROM_TEXT=0x0
  1885. +CONFIG_ZBOOT_ROM_BSS=0x0
  1886. +CONFIG_CMDLINE="console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait"
  1887. +CONFIG_CPU_FREQ=y
  1888. +CONFIG_CPU_FREQ_STAT=m
  1889. +CONFIG_CPU_FREQ_STAT_DETAILS=y
  1890. +CONFIG_CPU_FREQ_DEFAULT_GOV_POWERSAVE=y
  1891. +CONFIG_CPU_FREQ_GOV_PERFORMANCE=y
  1892. +CONFIG_CPU_FREQ_GOV_USERSPACE=y
  1893. +CONFIG_CPU_FREQ_GOV_ONDEMAND=y
  1894. +CONFIG_CPU_FREQ_GOV_CONSERVATIVE=y
  1895. +CONFIG_VFP=y
  1896. +CONFIG_NEON=y
  1897. +CONFIG_KERNEL_MODE_NEON=y
  1898. +CONFIG_BINFMT_MISC=m
  1899. +# CONFIG_SUSPEND is not set
  1900. +CONFIG_NET=y
  1901. +CONFIG_PACKET=y
  1902. +CONFIG_UNIX=y
  1903. +CONFIG_XFRM_USER=y
  1904. +CONFIG_NET_KEY=m
  1905. +CONFIG_INET=y
  1906. +CONFIG_IP_MULTICAST=y
  1907. +CONFIG_IP_ADVANCED_ROUTER=y
  1908. +CONFIG_IP_MULTIPLE_TABLES=y
  1909. +CONFIG_IP_ROUTE_MULTIPATH=y
  1910. +CONFIG_IP_ROUTE_VERBOSE=y
  1911. +CONFIG_IP_PNP=y
  1912. +CONFIG_IP_PNP_DHCP=y
  1913. +CONFIG_IP_PNP_RARP=y
  1914. +CONFIG_NET_IPIP=m
  1915. +CONFIG_NET_IPGRE_DEMUX=m
  1916. +CONFIG_NET_IPGRE=m
  1917. +CONFIG_IP_MROUTE=y
  1918. +CONFIG_IP_MROUTE_MULTIPLE_TABLES=y
  1919. +CONFIG_IP_PIMSM_V1=y
  1920. +CONFIG_IP_PIMSM_V2=y
  1921. +CONFIG_SYN_COOKIES=y
  1922. +CONFIG_INET_AH=m
  1923. +CONFIG_INET_ESP=m
  1924. +CONFIG_INET_IPCOMP=m
  1925. +CONFIG_INET_XFRM_MODE_TRANSPORT=m
  1926. +CONFIG_INET_XFRM_MODE_TUNNEL=m
  1927. +CONFIG_INET_XFRM_MODE_BEET=m
  1928. +CONFIG_INET_LRO=m
  1929. +CONFIG_INET_DIAG=m
  1930. +CONFIG_INET6_AH=m
  1931. +CONFIG_INET6_ESP=m
  1932. +CONFIG_INET6_IPCOMP=m
  1933. +CONFIG_IPV6_TUNNEL=m
  1934. +CONFIG_IPV6_MULTIPLE_TABLES=y
  1935. +CONFIG_IPV6_MROUTE=y
  1936. +CONFIG_IPV6_MROUTE_MULTIPLE_TABLES=y
  1937. +CONFIG_IPV6_PIMSM_V2=y
  1938. +CONFIG_NETFILTER=y
  1939. +CONFIG_NF_CONNTRACK=m
  1940. +CONFIG_NF_CONNTRACK_ZONES=y
  1941. +CONFIG_NF_CONNTRACK_EVENTS=y
  1942. +CONFIG_NF_CONNTRACK_TIMESTAMP=y
  1943. +CONFIG_NF_CT_PROTO_DCCP=m
  1944. +CONFIG_NF_CT_PROTO_UDPLITE=m
  1945. +CONFIG_NF_CONNTRACK_AMANDA=m
  1946. +CONFIG_NF_CONNTRACK_FTP=m
  1947. +CONFIG_NF_CONNTRACK_H323=m
  1948. +CONFIG_NF_CONNTRACK_IRC=m
  1949. +CONFIG_NF_CONNTRACK_NETBIOS_NS=m
  1950. +CONFIG_NF_CONNTRACK_SNMP=m
  1951. +CONFIG_NF_CONNTRACK_PPTP=m
  1952. +CONFIG_NF_CONNTRACK_SANE=m
  1953. +CONFIG_NF_CONNTRACK_SIP=m
  1954. +CONFIG_NF_CONNTRACK_TFTP=m
  1955. +CONFIG_NF_CT_NETLINK=m
  1956. +CONFIG_NETFILTER_XT_SET=m
  1957. +CONFIG_NETFILTER_XT_TARGET_AUDIT=m
  1958. +CONFIG_NETFILTER_XT_TARGET_CHECKSUM=m
  1959. +CONFIG_NETFILTER_XT_TARGET_CLASSIFY=m
  1960. +CONFIG_NETFILTER_XT_TARGET_CONNMARK=m
  1961. +CONFIG_NETFILTER_XT_TARGET_DSCP=m
  1962. +CONFIG_NETFILTER_XT_TARGET_HMARK=m
  1963. +CONFIG_NETFILTER_XT_TARGET_IDLETIMER=m
  1964. +CONFIG_NETFILTER_XT_TARGET_LED=m
  1965. +CONFIG_NETFILTER_XT_TARGET_LOG=m
  1966. +CONFIG_NETFILTER_XT_TARGET_MARK=m
  1967. +CONFIG_NETFILTER_XT_TARGET_NFLOG=m
  1968. +CONFIG_NETFILTER_XT_TARGET_NFQUEUE=m
  1969. +CONFIG_NETFILTER_XT_TARGET_NOTRACK=m
  1970. +CONFIG_NETFILTER_XT_TARGET_TEE=m
  1971. +CONFIG_NETFILTER_XT_TARGET_TPROXY=m
  1972. +CONFIG_NETFILTER_XT_TARGET_TRACE=m
  1973. +CONFIG_NETFILTER_XT_TARGET_TCPMSS=m
  1974. +CONFIG_NETFILTER_XT_TARGET_TCPOPTSTRIP=m
  1975. +CONFIG_NETFILTER_XT_MATCH_ADDRTYPE=m
  1976. +CONFIG_NETFILTER_XT_MATCH_BPF=m
  1977. +CONFIG_NETFILTER_XT_MATCH_CLUSTER=m
  1978. +CONFIG_NETFILTER_XT_MATCH_COMMENT=m
  1979. +CONFIG_NETFILTER_XT_MATCH_CONNBYTES=m
  1980. +CONFIG_NETFILTER_XT_MATCH_CONNLABEL=m
  1981. +CONFIG_NETFILTER_XT_MATCH_CONNLIMIT=m
  1982. +CONFIG_NETFILTER_XT_MATCH_CONNMARK=m
  1983. +CONFIG_NETFILTER_XT_MATCH_CONNTRACK=m
  1984. +CONFIG_NETFILTER_XT_MATCH_CPU=m
  1985. +CONFIG_NETFILTER_XT_MATCH_DCCP=m
  1986. +CONFIG_NETFILTER_XT_MATCH_DEVGROUP=m
  1987. +CONFIG_NETFILTER_XT_MATCH_DSCP=m
  1988. +CONFIG_NETFILTER_XT_MATCH_ESP=m
  1989. +CONFIG_NETFILTER_XT_MATCH_HASHLIMIT=m
  1990. +CONFIG_NETFILTER_XT_MATCH_HELPER=m
  1991. +CONFIG_NETFILTER_XT_MATCH_IPRANGE=m
  1992. +CONFIG_NETFILTER_XT_MATCH_IPVS=m
  1993. +CONFIG_NETFILTER_XT_MATCH_LENGTH=m
  1994. +CONFIG_NETFILTER_XT_MATCH_LIMIT=m
  1995. +CONFIG_NETFILTER_XT_MATCH_MAC=m
  1996. +CONFIG_NETFILTER_XT_MATCH_MARK=m
  1997. +CONFIG_NETFILTER_XT_MATCH_MULTIPORT=m
  1998. +CONFIG_NETFILTER_XT_MATCH_NFACCT=m
  1999. +CONFIG_NETFILTER_XT_MATCH_OSF=m
  2000. +CONFIG_NETFILTER_XT_MATCH_OWNER=m
  2001. +CONFIG_NETFILTER_XT_MATCH_POLICY=m
  2002. +CONFIG_NETFILTER_XT_MATCH_PHYSDEV=m
  2003. +CONFIG_NETFILTER_XT_MATCH_PKTTYPE=m
  2004. +CONFIG_NETFILTER_XT_MATCH_QUOTA=m
  2005. +CONFIG_NETFILTER_XT_MATCH_RATEEST=m
  2006. +CONFIG_NETFILTER_XT_MATCH_REALM=m
  2007. +CONFIG_NETFILTER_XT_MATCH_RECENT=m
  2008. +CONFIG_NETFILTER_XT_MATCH_SOCKET=m
  2009. +CONFIG_NETFILTER_XT_MATCH_STATE=m
  2010. +CONFIG_NETFILTER_XT_MATCH_STATISTIC=m
  2011. +CONFIG_NETFILTER_XT_MATCH_STRING=m
  2012. +CONFIG_NETFILTER_XT_MATCH_TCPMSS=m
  2013. +CONFIG_NETFILTER_XT_MATCH_TIME=m
  2014. +CONFIG_NETFILTER_XT_MATCH_U32=m
  2015. +CONFIG_IP_SET=m
  2016. +CONFIG_IP_SET_BITMAP_IP=m
  2017. +CONFIG_IP_SET_BITMAP_IPMAC=m
  2018. +CONFIG_IP_SET_BITMAP_PORT=m
  2019. +CONFIG_IP_SET_HASH_IP=m
  2020. +CONFIG_IP_SET_HASH_IPPORT=m
  2021. +CONFIG_IP_SET_HASH_IPPORTIP=m
  2022. +CONFIG_IP_SET_HASH_IPPORTNET=m
  2023. +CONFIG_IP_SET_HASH_NET=m
  2024. +CONFIG_IP_SET_HASH_NETPORT=m
  2025. +CONFIG_IP_SET_HASH_NETIFACE=m
  2026. +CONFIG_IP_SET_LIST_SET=m
  2027. +CONFIG_IP_VS=m
  2028. +CONFIG_IP_VS_PROTO_TCP=y
  2029. +CONFIG_IP_VS_PROTO_UDP=y
  2030. +CONFIG_IP_VS_PROTO_ESP=y
  2031. +CONFIG_IP_VS_PROTO_AH=y
  2032. +CONFIG_IP_VS_PROTO_SCTP=y
  2033. +CONFIG_IP_VS_RR=m
  2034. +CONFIG_IP_VS_WRR=m
  2035. +CONFIG_IP_VS_LC=m
  2036. +CONFIG_IP_VS_WLC=m
  2037. +CONFIG_IP_VS_LBLC=m
  2038. +CONFIG_IP_VS_LBLCR=m
  2039. +CONFIG_IP_VS_DH=m
  2040. +CONFIG_IP_VS_SH=m
  2041. +CONFIG_IP_VS_SED=m
  2042. +CONFIG_IP_VS_NQ=m
  2043. +CONFIG_IP_VS_FTP=m
  2044. +CONFIG_IP_VS_PE_SIP=m
  2045. +CONFIG_NF_CONNTRACK_IPV4=m
  2046. +CONFIG_IP_NF_IPTABLES=m
  2047. +CONFIG_IP_NF_MATCH_AH=m
  2048. +CONFIG_IP_NF_MATCH_ECN=m
  2049. +CONFIG_IP_NF_MATCH_TTL=m
  2050. +CONFIG_IP_NF_FILTER=m
  2051. +CONFIG_IP_NF_TARGET_REJECT=m
  2052. +CONFIG_IP_NF_NAT=m
  2053. +CONFIG_IP_NF_TARGET_MASQUERADE=m
  2054. +CONFIG_IP_NF_TARGET_NETMAP=m
  2055. +CONFIG_IP_NF_TARGET_REDIRECT=m
  2056. +CONFIG_IP_NF_MANGLE=m
  2057. +CONFIG_IP_NF_TARGET_CLUSTERIP=m
  2058. +CONFIG_IP_NF_TARGET_ECN=m
  2059. +CONFIG_IP_NF_TARGET_TTL=m
  2060. +CONFIG_IP_NF_RAW=m
  2061. +CONFIG_IP_NF_ARPTABLES=m
  2062. +CONFIG_IP_NF_ARPFILTER=m
  2063. +CONFIG_IP_NF_ARP_MANGLE=m
  2064. +CONFIG_NF_CONNTRACK_IPV6=m
  2065. +CONFIG_IP6_NF_IPTABLES=m
  2066. +CONFIG_IP6_NF_MATCH_AH=m
  2067. +CONFIG_IP6_NF_MATCH_EUI64=m
  2068. +CONFIG_IP6_NF_MATCH_FRAG=m
  2069. +CONFIG_IP6_NF_MATCH_OPTS=m
  2070. +CONFIG_IP6_NF_MATCH_HL=m
  2071. +CONFIG_IP6_NF_MATCH_IPV6HEADER=m
  2072. +CONFIG_IP6_NF_MATCH_MH=m
  2073. +CONFIG_IP6_NF_MATCH_RT=m
  2074. +CONFIG_IP6_NF_TARGET_HL=m
  2075. +CONFIG_IP6_NF_FILTER=m
  2076. +CONFIG_IP6_NF_TARGET_REJECT=m
  2077. +CONFIG_IP6_NF_MANGLE=m
  2078. +CONFIG_IP6_NF_RAW=m
  2079. +CONFIG_IP6_NF_NAT=m
  2080. +CONFIG_IP6_NF_TARGET_MASQUERADE=m
  2081. +CONFIG_IP6_NF_TARGET_NPT=m
  2082. +CONFIG_BRIDGE_NF_EBTABLES=m
  2083. +CONFIG_BRIDGE_EBT_BROUTE=m
  2084. +CONFIG_BRIDGE_EBT_T_FILTER=m
  2085. +CONFIG_BRIDGE_EBT_T_NAT=m
  2086. +CONFIG_BRIDGE_EBT_802_3=m
  2087. +CONFIG_BRIDGE_EBT_AMONG=m
  2088. +CONFIG_BRIDGE_EBT_ARP=m
  2089. +CONFIG_BRIDGE_EBT_IP=m
  2090. +CONFIG_BRIDGE_EBT_IP6=m
  2091. +CONFIG_BRIDGE_EBT_LIMIT=m
  2092. +CONFIG_BRIDGE_EBT_MARK=m
  2093. +CONFIG_BRIDGE_EBT_PKTTYPE=m
  2094. +CONFIG_BRIDGE_EBT_STP=m
  2095. +CONFIG_BRIDGE_EBT_VLAN=m
  2096. +CONFIG_BRIDGE_EBT_ARPREPLY=m
  2097. +CONFIG_BRIDGE_EBT_DNAT=m
  2098. +CONFIG_BRIDGE_EBT_MARK_T=m
  2099. +CONFIG_BRIDGE_EBT_REDIRECT=m
  2100. +CONFIG_BRIDGE_EBT_SNAT=m
  2101. +CONFIG_BRIDGE_EBT_LOG=m
  2102. +CONFIG_BRIDGE_EBT_NFLOG=m
  2103. +CONFIG_SCTP_COOKIE_HMAC_SHA1=y
  2104. +CONFIG_ATM=m
  2105. +CONFIG_L2TP=m
  2106. +CONFIG_L2TP_V3=y
  2107. +CONFIG_L2TP_IP=m
  2108. +CONFIG_L2TP_ETH=m
  2109. +CONFIG_BRIDGE=m
  2110. +CONFIG_VLAN_8021Q=m
  2111. +CONFIG_VLAN_8021Q_GVRP=y
  2112. +CONFIG_ATALK=m
  2113. +CONFIG_6LOWPAN=m
  2114. +CONFIG_NET_SCHED=y
  2115. +CONFIG_NET_SCH_CBQ=m
  2116. +CONFIG_NET_SCH_HTB=m
  2117. +CONFIG_NET_SCH_HFSC=m
  2118. +CONFIG_NET_SCH_PRIO=m
  2119. +CONFIG_NET_SCH_MULTIQ=m
  2120. +CONFIG_NET_SCH_RED=m
  2121. +CONFIG_NET_SCH_SFB=m
  2122. +CONFIG_NET_SCH_SFQ=m
  2123. +CONFIG_NET_SCH_TEQL=m
  2124. +CONFIG_NET_SCH_TBF=m
  2125. +CONFIG_NET_SCH_GRED=m
  2126. +CONFIG_NET_SCH_DSMARK=m
  2127. +CONFIG_NET_SCH_NETEM=m
  2128. +CONFIG_NET_SCH_DRR=m
  2129. +CONFIG_NET_SCH_MQPRIO=m
  2130. +CONFIG_NET_SCH_CHOKE=m
  2131. +CONFIG_NET_SCH_QFQ=m
  2132. +CONFIG_NET_SCH_CODEL=m
  2133. +CONFIG_NET_SCH_FQ_CODEL=m
  2134. +CONFIG_NET_SCH_INGRESS=m
  2135. +CONFIG_NET_SCH_PLUG=m
  2136. +CONFIG_NET_CLS_BASIC=m
  2137. +CONFIG_NET_CLS_TCINDEX=m
  2138. +CONFIG_NET_CLS_ROUTE4=m
  2139. +CONFIG_NET_CLS_FW=m
  2140. +CONFIG_NET_CLS_U32=m
  2141. +CONFIG_CLS_U32_MARK=y
  2142. +CONFIG_NET_CLS_RSVP=m
  2143. +CONFIG_NET_CLS_RSVP6=m
  2144. +CONFIG_NET_CLS_FLOW=m
  2145. +CONFIG_NET_CLS_CGROUP=m
  2146. +CONFIG_NET_EMATCH=y
  2147. +CONFIG_NET_EMATCH_CMP=m
  2148. +CONFIG_NET_EMATCH_NBYTE=m
  2149. +CONFIG_NET_EMATCH_U32=m
  2150. +CONFIG_NET_EMATCH_META=m
  2151. +CONFIG_NET_EMATCH_TEXT=m
  2152. +CONFIG_NET_EMATCH_IPSET=m
  2153. +CONFIG_NET_CLS_ACT=y
  2154. +CONFIG_NET_ACT_POLICE=m
  2155. +CONFIG_NET_ACT_GACT=m
  2156. +CONFIG_GACT_PROB=y
  2157. +CONFIG_NET_ACT_MIRRED=m
  2158. +CONFIG_NET_ACT_IPT=m
  2159. +CONFIG_NET_ACT_NAT=m
  2160. +CONFIG_NET_ACT_PEDIT=m
  2161. +CONFIG_NET_ACT_SIMP=m
  2162. +CONFIG_NET_ACT_SKBEDIT=m
  2163. +CONFIG_NET_ACT_CSUM=m
  2164. +CONFIG_BATMAN_ADV=m
  2165. +CONFIG_OPENVSWITCH=m
  2166. +CONFIG_NET_PKTGEN=m
  2167. +CONFIG_HAMRADIO=y
  2168. +CONFIG_AX25=m
  2169. +CONFIG_NETROM=m
  2170. +CONFIG_ROSE=m
  2171. +CONFIG_MKISS=m
  2172. +CONFIG_6PACK=m
  2173. +CONFIG_BPQETHER=m
  2174. +CONFIG_BAYCOM_SER_FDX=m
  2175. +CONFIG_BAYCOM_SER_HDX=m
  2176. +CONFIG_YAM=m
  2177. +CONFIG_CAN=m
  2178. +CONFIG_CAN_VCAN=m
  2179. +CONFIG_CAN_MCP251X=m
  2180. +CONFIG_IRDA=m
  2181. +CONFIG_IRLAN=m
  2182. +CONFIG_IRNET=m
  2183. +CONFIG_IRCOMM=m
  2184. +CONFIG_IRDA_ULTRA=y
  2185. +CONFIG_IRDA_CACHE_LAST_LSAP=y
  2186. +CONFIG_IRDA_FAST_RR=y
  2187. +CONFIG_IRTTY_SIR=m
  2188. +CONFIG_KINGSUN_DONGLE=m
  2189. +CONFIG_KSDAZZLE_DONGLE=m
  2190. +CONFIG_KS959_DONGLE=m
  2191. +CONFIG_USB_IRDA=m
  2192. +CONFIG_SIGMATEL_FIR=m
  2193. +CONFIG_MCS_FIR=m
  2194. +CONFIG_BT=m
  2195. +CONFIG_BT_6LOWPAN=m
  2196. +CONFIG_BT_RFCOMM=m
  2197. +CONFIG_BT_RFCOMM_TTY=y
  2198. +CONFIG_BT_BNEP=m
  2199. +CONFIG_BT_BNEP_MC_FILTER=y
  2200. +CONFIG_BT_BNEP_PROTO_FILTER=y
  2201. +CONFIG_BT_HIDP=m
  2202. +CONFIG_BT_HCIBTUSB=m
  2203. +CONFIG_BT_HCIBCM203X=m
  2204. +CONFIG_BT_HCIBPA10X=m
  2205. +CONFIG_BT_HCIBFUSB=m
  2206. +CONFIG_BT_HCIVHCI=m
  2207. +CONFIG_BT_MRVL=m
  2208. +CONFIG_BT_MRVL_SDIO=m
  2209. +CONFIG_BT_ATH3K=m
  2210. +CONFIG_BT_WILINK=m
  2211. +CONFIG_CFG80211_WEXT=y
  2212. +CONFIG_MAC80211=m
  2213. +CONFIG_MAC80211_MESH=y
  2214. +CONFIG_WIMAX=m
  2215. +CONFIG_RFKILL=m
  2216. +CONFIG_RFKILL_INPUT=y
  2217. +CONFIG_NET_9P=m
  2218. +CONFIG_NFC=m
  2219. +CONFIG_NFC_PN533=m
  2220. +CONFIG_DEVTMPFS=y
  2221. +CONFIG_DEVTMPFS_MOUNT=y
  2222. +CONFIG_DMA_CMA=y
  2223. +CONFIG_CMA_SIZE_MBYTES=5
  2224. +CONFIG_BLK_DEV_LOOP=y
  2225. +CONFIG_BLK_DEV_CRYPTOLOOP=m
  2226. +CONFIG_BLK_DEV_DRBD=m
  2227. +CONFIG_BLK_DEV_NBD=m
  2228. +CONFIG_BLK_DEV_RAM=y
  2229. +CONFIG_CDROM_PKTCDVD=m
  2230. +CONFIG_ATA_OVER_ETH=m
  2231. +CONFIG_EEPROM_AT24=m
  2232. +CONFIG_SCSI=y
  2233. +# CONFIG_SCSI_PROC_FS is not set
  2234. +CONFIG_BLK_DEV_SD=y
  2235. +CONFIG_CHR_DEV_ST=m
  2236. +CONFIG_CHR_DEV_OSST=m
  2237. +CONFIG_BLK_DEV_SR=m
  2238. +CONFIG_CHR_DEV_SG=m
  2239. +CONFIG_SCSI_ISCSI_ATTRS=y
  2240. +CONFIG_ISCSI_TCP=m
  2241. +CONFIG_ISCSI_BOOT_SYSFS=m
  2242. +CONFIG_MD=y
  2243. +CONFIG_MD_LINEAR=m
  2244. +CONFIG_MD_RAID0=m
  2245. +CONFIG_BLK_DEV_DM=m
  2246. +CONFIG_DM_CRYPT=m
  2247. +CONFIG_DM_SNAPSHOT=m
  2248. +CONFIG_DM_MIRROR=m
  2249. +CONFIG_DM_LOG_USERSPACE=m
  2250. +CONFIG_DM_RAID=m
  2251. +CONFIG_DM_ZERO=m
  2252. +CONFIG_DM_DELAY=m
  2253. +CONFIG_NETDEVICES=y
  2254. +CONFIG_BONDING=m
  2255. +CONFIG_DUMMY=m
  2256. +CONFIG_IFB=m
  2257. +CONFIG_MACVLAN=m
  2258. +CONFIG_NETCONSOLE=m
  2259. +CONFIG_TUN=m
  2260. +CONFIG_VETH=m
  2261. +CONFIG_ENC28J60=m
  2262. +CONFIG_MDIO_BITBANG=m
  2263. +CONFIG_PPP=m
  2264. +CONFIG_PPP_BSDCOMP=m
  2265. +CONFIG_PPP_DEFLATE=m
  2266. +CONFIG_PPP_FILTER=y
  2267. +CONFIG_PPP_MPPE=m
  2268. +CONFIG_PPP_MULTILINK=y
  2269. +CONFIG_PPPOATM=m
  2270. +CONFIG_PPPOE=m
  2271. +CONFIG_PPPOL2TP=m
  2272. +CONFIG_PPP_ASYNC=m
  2273. +CONFIG_PPP_SYNC_TTY=m
  2274. +CONFIG_SLIP=m
  2275. +CONFIG_SLIP_COMPRESSED=y
  2276. +CONFIG_SLIP_SMART=y
  2277. +CONFIG_USB_CATC=m
  2278. +CONFIG_USB_KAWETH=m
  2279. +CONFIG_USB_PEGASUS=m
  2280. +CONFIG_USB_RTL8150=m
  2281. +CONFIG_USB_RTL8152=m
  2282. +CONFIG_USB_USBNET=y
  2283. +CONFIG_USB_NET_AX8817X=m
  2284. +CONFIG_USB_NET_AX88179_178A=m
  2285. +CONFIG_USB_NET_CDCETHER=m
  2286. +CONFIG_USB_NET_CDC_EEM=m
  2287. +CONFIG_USB_NET_CDC_NCM=m
  2288. +CONFIG_USB_NET_HUAWEI_CDC_NCM=m
  2289. +CONFIG_USB_NET_CDC_MBIM=m
  2290. +CONFIG_USB_NET_DM9601=m
  2291. +CONFIG_USB_NET_SR9700=m
  2292. +CONFIG_USB_NET_SR9800=m
  2293. +CONFIG_USB_NET_SMSC75XX=m
  2294. +CONFIG_USB_NET_SMSC95XX=y
  2295. +CONFIG_USB_NET_GL620A=m
  2296. +CONFIG_USB_NET_NET1080=m
  2297. +CONFIG_USB_NET_PLUSB=m
  2298. +CONFIG_USB_NET_MCS7830=m
  2299. +CONFIG_USB_NET_CDC_SUBSET=m
  2300. +CONFIG_USB_ALI_M5632=y
  2301. +CONFIG_USB_AN2720=y
  2302. +CONFIG_USB_EPSON2888=y
  2303. +CONFIG_USB_KC2190=y
  2304. +CONFIG_USB_NET_ZAURUS=m
  2305. +CONFIG_USB_NET_CX82310_ETH=m
  2306. +CONFIG_USB_NET_KALMIA=m
  2307. +CONFIG_USB_NET_QMI_WWAN=m
  2308. +CONFIG_USB_HSO=m
  2309. +CONFIG_USB_NET_INT51X1=m
  2310. +CONFIG_USB_IPHETH=m
  2311. +CONFIG_USB_SIERRA_NET=m
  2312. +CONFIG_USB_VL600=m
  2313. +CONFIG_LIBERTAS_THINFIRM=m
  2314. +CONFIG_LIBERTAS_THINFIRM_USB=m
  2315. +CONFIG_AT76C50X_USB=m
  2316. +CONFIG_USB_ZD1201=m
  2317. +CONFIG_USB_NET_RNDIS_WLAN=m
  2318. +CONFIG_RTL8187=m
  2319. +CONFIG_MAC80211_HWSIM=m
  2320. +CONFIG_ATH_CARDS=m
  2321. +CONFIG_ATH9K=m
  2322. +CONFIG_ATH9K_HTC=m
  2323. +CONFIG_CARL9170=m
  2324. +CONFIG_ATH6KL=m
  2325. +CONFIG_ATH6KL_USB=m
  2326. +CONFIG_AR5523=m
  2327. +CONFIG_B43=m
  2328. +# CONFIG_B43_PHY_N is not set
  2329. +CONFIG_B43LEGACY=m
  2330. +CONFIG_BRCMFMAC=m
  2331. +CONFIG_BRCMFMAC_USB=y
  2332. +CONFIG_HOSTAP=m
  2333. +CONFIG_LIBERTAS=m
  2334. +CONFIG_LIBERTAS_USB=m
  2335. +CONFIG_LIBERTAS_SDIO=m
  2336. +CONFIG_P54_COMMON=m
  2337. +CONFIG_P54_USB=m
  2338. +CONFIG_RT2X00=m
  2339. +CONFIG_RT2500USB=m
  2340. +CONFIG_RT73USB=m
  2341. +CONFIG_RT2800USB=m
  2342. +CONFIG_RT2800USB_RT3573=y
  2343. +CONFIG_RT2800USB_RT53XX=y
  2344. +CONFIG_RT2800USB_RT55XX=y
  2345. +CONFIG_RT2800USB_UNKNOWN=y
  2346. +CONFIG_RTL8192CU=m
  2347. +CONFIG_ZD1211RW=m
  2348. +CONFIG_MWIFIEX=m
  2349. +CONFIG_MWIFIEX_SDIO=m
  2350. +CONFIG_WIMAX_I2400M_USB=m
  2351. +CONFIG_INPUT_POLLDEV=m
  2352. +# CONFIG_INPUT_MOUSEDEV_PSAUX is not set
  2353. +CONFIG_INPUT_JOYDEV=m
  2354. +CONFIG_INPUT_EVDEV=m
  2355. +# CONFIG_INPUT_KEYBOARD is not set
  2356. +# CONFIG_INPUT_MOUSE is not set
  2357. +CONFIG_INPUT_JOYSTICK=y
  2358. +CONFIG_JOYSTICK_IFORCE=m
  2359. +CONFIG_JOYSTICK_IFORCE_USB=y
  2360. +CONFIG_JOYSTICK_XPAD=m
  2361. +CONFIG_JOYSTICK_XPAD_FF=y
  2362. +CONFIG_INPUT_TOUCHSCREEN=y
  2363. +CONFIG_TOUCHSCREEN_ADS7846=m
  2364. +CONFIG_TOUCHSCREEN_EGALAX=m
  2365. +CONFIG_TOUCHSCREEN_USB_COMPOSITE=m
  2366. +CONFIG_INPUT_MISC=y
  2367. +CONFIG_INPUT_AD714X=m
  2368. +CONFIG_INPUT_ATI_REMOTE2=m
  2369. +CONFIG_INPUT_KEYSPAN_REMOTE=m
  2370. +CONFIG_INPUT_POWERMATE=m
  2371. +CONFIG_INPUT_YEALINK=m
  2372. +CONFIG_INPUT_CM109=m
  2373. +CONFIG_INPUT_UINPUT=m
  2374. +CONFIG_INPUT_GPIO_ROTARY_ENCODER=m
  2375. +CONFIG_INPUT_ADXL34X=m
  2376. +CONFIG_INPUT_CMA3000=m
  2377. +CONFIG_SERIO=m
  2378. +CONFIG_SERIO_RAW=m
  2379. +CONFIG_GAMEPORT=m
  2380. +CONFIG_GAMEPORT_NS558=m
  2381. +CONFIG_GAMEPORT_L4=m
  2382. +CONFIG_DEVPTS_MULTIPLE_INSTANCES=y
  2383. +# CONFIG_LEGACY_PTYS is not set
  2384. +# CONFIG_DEVKMEM is not set
  2385. +CONFIG_SERIAL_AMBA_PL011=y
  2386. +CONFIG_SERIAL_AMBA_PL011_CONSOLE=y
  2387. +CONFIG_TTY_PRINTK=y
  2388. +CONFIG_HW_RANDOM=y
  2389. +CONFIG_HW_RANDOM_BCM2708=m
  2390. +CONFIG_RAW_DRIVER=y
  2391. +CONFIG_BRCM_CHAR_DRIVERS=y
  2392. +CONFIG_BCM_VC_CMA=y
  2393. +CONFIG_BCM_VC_SM=y
  2394. +CONFIG_I2C=y
  2395. +CONFIG_I2C_CHARDEV=m
  2396. +CONFIG_I2C_MUX=m
  2397. +CONFIG_I2C_BCM2708=m
  2398. +CONFIG_SPI=y
  2399. +CONFIG_SPI_BCM2835=m
  2400. +CONFIG_SPI_BCM2708=m
  2401. +CONFIG_SPI_SPIDEV=y
  2402. +CONFIG_PPS=m
  2403. +CONFIG_PPS_CLIENT_LDISC=m
  2404. +CONFIG_PPS_CLIENT_GPIO=m
  2405. +CONFIG_GPIO_SYSFS=y
  2406. +CONFIG_GPIO_ARIZONA=m
  2407. +CONFIG_W1=m
  2408. +CONFIG_W1_MASTER_DS2490=m
  2409. +CONFIG_W1_MASTER_DS2482=m
  2410. +CONFIG_W1_MASTER_DS1WM=m
  2411. +CONFIG_W1_MASTER_GPIO=m
  2412. +CONFIG_W1_SLAVE_THERM=m
  2413. +CONFIG_W1_SLAVE_SMEM=m
  2414. +CONFIG_W1_SLAVE_DS2408=m
  2415. +CONFIG_W1_SLAVE_DS2413=m
  2416. +CONFIG_W1_SLAVE_DS2406=m
  2417. +CONFIG_W1_SLAVE_DS2423=m
  2418. +CONFIG_W1_SLAVE_DS2431=m
  2419. +CONFIG_W1_SLAVE_DS2433=m
  2420. +CONFIG_W1_SLAVE_DS2760=m
  2421. +CONFIG_W1_SLAVE_DS2780=m
  2422. +CONFIG_W1_SLAVE_DS2781=m
  2423. +CONFIG_W1_SLAVE_DS28E04=m
  2424. +CONFIG_W1_SLAVE_BQ27000=m
  2425. +CONFIG_BATTERY_DS2760=m
  2426. +# CONFIG_HWMON is not set
  2427. +CONFIG_THERMAL=y
  2428. +CONFIG_THERMAL_BCM2835=y
  2429. +CONFIG_WATCHDOG=y
  2430. +CONFIG_BCM2708_WDT=m
  2431. +CONFIG_UCB1400_CORE=m
  2432. +CONFIG_MFD_ARIZONA_I2C=m
  2433. +CONFIG_MFD_ARIZONA_SPI=m
  2434. +CONFIG_MFD_WM5102=y
  2435. +CONFIG_MEDIA_SUPPORT=m
  2436. +CONFIG_MEDIA_CAMERA_SUPPORT=y
  2437. +CONFIG_MEDIA_ANALOG_TV_SUPPORT=y
  2438. +CONFIG_MEDIA_DIGITAL_TV_SUPPORT=y
  2439. +CONFIG_MEDIA_RADIO_SUPPORT=y
  2440. +CONFIG_MEDIA_RC_SUPPORT=y
  2441. +CONFIG_MEDIA_CONTROLLER=y
  2442. +CONFIG_LIRC=m
  2443. +CONFIG_RC_DEVICES=y
  2444. +CONFIG_RC_ATI_REMOTE=m
  2445. +CONFIG_IR_IMON=m
  2446. +CONFIG_IR_MCEUSB=m
  2447. +CONFIG_IR_REDRAT3=m
  2448. +CONFIG_IR_STREAMZAP=m
  2449. +CONFIG_IR_IGUANA=m
  2450. +CONFIG_IR_TTUSBIR=m
  2451. +CONFIG_RC_LOOPBACK=m
  2452. +CONFIG_IR_GPIO_CIR=m
  2453. +CONFIG_MEDIA_USB_SUPPORT=y
  2454. +CONFIG_USB_VIDEO_CLASS=m
  2455. +CONFIG_USB_M5602=m
  2456. +CONFIG_USB_STV06XX=m
  2457. +CONFIG_USB_GL860=m
  2458. +CONFIG_USB_GSPCA_BENQ=m
  2459. +CONFIG_USB_GSPCA_CONEX=m
  2460. +CONFIG_USB_GSPCA_CPIA1=m
  2461. +CONFIG_USB_GSPCA_DTCS033=m
  2462. +CONFIG_USB_GSPCA_ETOMS=m
  2463. +CONFIG_USB_GSPCA_FINEPIX=m
  2464. +CONFIG_USB_GSPCA_JEILINJ=m
  2465. +CONFIG_USB_GSPCA_JL2005BCD=m
  2466. +CONFIG_USB_GSPCA_KINECT=m
  2467. +CONFIG_USB_GSPCA_KONICA=m
  2468. +CONFIG_USB_GSPCA_MARS=m
  2469. +CONFIG_USB_GSPCA_MR97310A=m
  2470. +CONFIG_USB_GSPCA_NW80X=m
  2471. +CONFIG_USB_GSPCA_OV519=m
  2472. +CONFIG_USB_GSPCA_OV534=m
  2473. +CONFIG_USB_GSPCA_OV534_9=m
  2474. +CONFIG_USB_GSPCA_PAC207=m
  2475. +CONFIG_USB_GSPCA_PAC7302=m
  2476. +CONFIG_USB_GSPCA_PAC7311=m
  2477. +CONFIG_USB_GSPCA_SE401=m
  2478. +CONFIG_USB_GSPCA_SN9C2028=m
  2479. +CONFIG_USB_GSPCA_SN9C20X=m
  2480. +CONFIG_USB_GSPCA_SONIXB=m
  2481. +CONFIG_USB_GSPCA_SONIXJ=m
  2482. +CONFIG_USB_GSPCA_SPCA500=m
  2483. +CONFIG_USB_GSPCA_SPCA501=m
  2484. +CONFIG_USB_GSPCA_SPCA505=m
  2485. +CONFIG_USB_GSPCA_SPCA506=m
  2486. +CONFIG_USB_GSPCA_SPCA508=m
  2487. +CONFIG_USB_GSPCA_SPCA561=m
  2488. +CONFIG_USB_GSPCA_SPCA1528=m
  2489. +CONFIG_USB_GSPCA_SQ905=m
  2490. +CONFIG_USB_GSPCA_SQ905C=m
  2491. +CONFIG_USB_GSPCA_SQ930X=m
  2492. +CONFIG_USB_GSPCA_STK014=m
  2493. +CONFIG_USB_GSPCA_STK1135=m
  2494. +CONFIG_USB_GSPCA_STV0680=m
  2495. +CONFIG_USB_GSPCA_SUNPLUS=m
  2496. +CONFIG_USB_GSPCA_T613=m
  2497. +CONFIG_USB_GSPCA_TOPRO=m
  2498. +CONFIG_USB_GSPCA_TV8532=m
  2499. +CONFIG_USB_GSPCA_VC032X=m
  2500. +CONFIG_USB_GSPCA_VICAM=m
  2501. +CONFIG_USB_GSPCA_XIRLINK_CIT=m
  2502. +CONFIG_USB_GSPCA_ZC3XX=m
  2503. +CONFIG_USB_PWC=m
  2504. +CONFIG_VIDEO_CPIA2=m
  2505. +CONFIG_USB_ZR364XX=m
  2506. +CONFIG_USB_STKWEBCAM=m
  2507. +CONFIG_USB_S2255=m
  2508. +CONFIG_VIDEO_USBTV=m
  2509. +CONFIG_VIDEO_PVRUSB2=m
  2510. +CONFIG_VIDEO_HDPVR=m
  2511. +CONFIG_VIDEO_TLG2300=m
  2512. +CONFIG_VIDEO_USBVISION=m
  2513. +CONFIG_VIDEO_STK1160_COMMON=m
  2514. +CONFIG_VIDEO_STK1160_AC97=y
  2515. +CONFIG_VIDEO_GO7007=m
  2516. +CONFIG_VIDEO_GO7007_USB=m
  2517. +CONFIG_VIDEO_GO7007_USB_S2250_BOARD=m
  2518. +CONFIG_VIDEO_AU0828=m
  2519. +CONFIG_VIDEO_AU0828_RC=y
  2520. +CONFIG_VIDEO_CX231XX=m
  2521. +CONFIG_VIDEO_CX231XX_ALSA=m
  2522. +CONFIG_VIDEO_CX231XX_DVB=m
  2523. +CONFIG_VIDEO_TM6000=m
  2524. +CONFIG_VIDEO_TM6000_ALSA=m
  2525. +CONFIG_VIDEO_TM6000_DVB=m
  2526. +CONFIG_DVB_USB=m
  2527. +CONFIG_DVB_USB_A800=m
  2528. +CONFIG_DVB_USB_DIBUSB_MB=m
  2529. +CONFIG_DVB_USB_DIBUSB_MB_FAULTY=y
  2530. +CONFIG_DVB_USB_DIBUSB_MC=m
  2531. +CONFIG_DVB_USB_DIB0700=m
  2532. +CONFIG_DVB_USB_UMT_010=m
  2533. +CONFIG_DVB_USB_CXUSB=m
  2534. +CONFIG_DVB_USB_M920X=m
  2535. +CONFIG_DVB_USB_DIGITV=m
  2536. +CONFIG_DVB_USB_VP7045=m
  2537. +CONFIG_DVB_USB_VP702X=m
  2538. +CONFIG_DVB_USB_GP8PSK=m
  2539. +CONFIG_DVB_USB_NOVA_T_USB2=m
  2540. +CONFIG_DVB_USB_TTUSB2=m
  2541. +CONFIG_DVB_USB_DTT200U=m
  2542. +CONFIG_DVB_USB_OPERA1=m
  2543. +CONFIG_DVB_USB_AF9005=m
  2544. +CONFIG_DVB_USB_AF9005_REMOTE=m
  2545. +CONFIG_DVB_USB_PCTV452E=m
  2546. +CONFIG_DVB_USB_DW2102=m
  2547. +CONFIG_DVB_USB_CINERGY_T2=m
  2548. +CONFIG_DVB_USB_DTV5100=m
  2549. +CONFIG_DVB_USB_FRIIO=m
  2550. +CONFIG_DVB_USB_AZ6027=m
  2551. +CONFIG_DVB_USB_TECHNISAT_USB2=m
  2552. +CONFIG_DVB_USB_V2=m
  2553. +CONFIG_DVB_USB_AF9015=m
  2554. +CONFIG_DVB_USB_AF9035=m
  2555. +CONFIG_DVB_USB_ANYSEE=m
  2556. +CONFIG_DVB_USB_AU6610=m
  2557. +CONFIG_DVB_USB_AZ6007=m
  2558. +CONFIG_DVB_USB_CE6230=m
  2559. +CONFIG_DVB_USB_EC168=m
  2560. +CONFIG_DVB_USB_GL861=m
  2561. +CONFIG_DVB_USB_LME2510=m
  2562. +CONFIG_DVB_USB_MXL111SF=m
  2563. +CONFIG_DVB_USB_RTL28XXU=m
  2564. +CONFIG_DVB_USB_DVBSKY=m
  2565. +CONFIG_SMS_USB_DRV=m
  2566. +CONFIG_DVB_B2C2_FLEXCOP_USB=m
  2567. +CONFIG_DVB_AS102=m
  2568. +CONFIG_VIDEO_EM28XX=m
  2569. +CONFIG_VIDEO_EM28XX_V4L2=m
  2570. +CONFIG_VIDEO_EM28XX_ALSA=m
  2571. +CONFIG_VIDEO_EM28XX_DVB=m
  2572. +CONFIG_V4L_PLATFORM_DRIVERS=y
  2573. +CONFIG_VIDEO_BCM2835=y
  2574. +CONFIG_VIDEO_BCM2835_MMAL=m
  2575. +CONFIG_RADIO_SI470X=y
  2576. +CONFIG_USB_SI470X=m
  2577. +CONFIG_I2C_SI470X=m
  2578. +CONFIG_RADIO_SI4713=m
  2579. +CONFIG_I2C_SI4713=m
  2580. +CONFIG_USB_MR800=m
  2581. +CONFIG_USB_DSBR=m
  2582. +CONFIG_RADIO_SHARK=m
  2583. +CONFIG_RADIO_SHARK2=m
  2584. +CONFIG_USB_KEENE=m
  2585. +CONFIG_USB_MA901=m
  2586. +CONFIG_RADIO_TEA5764=m
  2587. +CONFIG_RADIO_SAA7706H=m
  2588. +CONFIG_RADIO_TEF6862=m
  2589. +CONFIG_RADIO_WL1273=m
  2590. +CONFIG_RADIO_WL128X=m
  2591. +# CONFIG_MEDIA_SUBDRV_AUTOSELECT is not set
  2592. +CONFIG_VIDEO_UDA1342=m
  2593. +CONFIG_VIDEO_SONY_BTF_MPX=m
  2594. +CONFIG_VIDEO_TVP5150=m
  2595. +CONFIG_VIDEO_TW2804=m
  2596. +CONFIG_VIDEO_TW9903=m
  2597. +CONFIG_VIDEO_TW9906=m
  2598. +CONFIG_VIDEO_OV7640=m
  2599. +CONFIG_VIDEO_MT9V011=m
  2600. +CONFIG_FB=y
  2601. +CONFIG_FB_BCM2708=y
  2602. +# CONFIG_BACKLIGHT_GENERIC is not set
  2603. +CONFIG_FRAMEBUFFER_CONSOLE=y
  2604. +CONFIG_LOGO=y
  2605. +# CONFIG_LOGO_LINUX_MONO is not set
  2606. +# CONFIG_LOGO_LINUX_VGA16 is not set
  2607. +CONFIG_SOUND=y
  2608. +CONFIG_SND=m
  2609. +CONFIG_SND_SEQUENCER=m
  2610. +CONFIG_SND_SEQ_DUMMY=m
  2611. +CONFIG_SND_MIXER_OSS=m
  2612. +CONFIG_SND_PCM_OSS=m
  2613. +CONFIG_SND_SEQUENCER_OSS=y
  2614. +CONFIG_SND_HRTIMER=m
  2615. +CONFIG_SND_DUMMY=m
  2616. +CONFIG_SND_ALOOP=m
  2617. +CONFIG_SND_VIRMIDI=m
  2618. +CONFIG_SND_MTPAV=m
  2619. +CONFIG_SND_SERIAL_U16550=m
  2620. +CONFIG_SND_MPU401=m
  2621. +CONFIG_SND_BCM2835=m
  2622. +CONFIG_SND_USB_AUDIO=m
  2623. +CONFIG_SND_USB_UA101=m
  2624. +CONFIG_SND_USB_CAIAQ=m
  2625. +CONFIG_SND_USB_CAIAQ_INPUT=y
  2626. +CONFIG_SND_USB_6FIRE=m
  2627. +CONFIG_SND_SOC=m
  2628. +CONFIG_SND_BCM2708_SOC_I2S=m
  2629. +CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC=m
  2630. +CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS=m
  2631. +CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI=m
  2632. +CONFIG_SND_BCM2708_SOC_HIFIBERRY_AMP=m
  2633. +CONFIG_SND_BCM2708_SOC_RPI_DAC=m
  2634. +CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC=m
  2635. +CONFIG_SND_SIMPLE_CARD=m
  2636. +CONFIG_SOUND_PRIME=m
  2637. +CONFIG_HIDRAW=y
  2638. +CONFIG_HID_A4TECH=m
  2639. +CONFIG_HID_ACRUX=m
  2640. +CONFIG_HID_APPLE=m
  2641. +CONFIG_HID_BELKIN=m
  2642. +CONFIG_HID_CHERRY=m
  2643. +CONFIG_HID_CHICONY=m
  2644. +CONFIG_HID_CYPRESS=m
  2645. +CONFIG_HID_DRAGONRISE=m
  2646. +CONFIG_HID_EMS_FF=m
  2647. +CONFIG_HID_ELECOM=m
  2648. +CONFIG_HID_ELO=m
  2649. +CONFIG_HID_EZKEY=m
  2650. +CONFIG_HID_HOLTEK=m
  2651. +CONFIG_HID_KEYTOUCH=m
  2652. +CONFIG_HID_KYE=m
  2653. +CONFIG_HID_UCLOGIC=m
  2654. +CONFIG_HID_WALTOP=m
  2655. +CONFIG_HID_GYRATION=m
  2656. +CONFIG_HID_TWINHAN=m
  2657. +CONFIG_HID_KENSINGTON=m
  2658. +CONFIG_HID_LCPOWER=m
  2659. +CONFIG_HID_LOGITECH=m
  2660. +CONFIG_HID_MAGICMOUSE=m
  2661. +CONFIG_HID_MICROSOFT=m
  2662. +CONFIG_HID_MONTEREY=m
  2663. +CONFIG_HID_MULTITOUCH=m
  2664. +CONFIG_HID_NTRIG=m
  2665. +CONFIG_HID_ORTEK=m
  2666. +CONFIG_HID_PANTHERLORD=m
  2667. +CONFIG_HID_PETALYNX=m
  2668. +CONFIG_HID_PICOLCD=m
  2669. +CONFIG_HID_ROCCAT=m
  2670. +CONFIG_HID_SAMSUNG=m
  2671. +CONFIG_HID_SONY=m
  2672. +CONFIG_HID_SPEEDLINK=m
  2673. +CONFIG_HID_SUNPLUS=m
  2674. +CONFIG_HID_GREENASIA=m
  2675. +CONFIG_HID_SMARTJOYPLUS=m
  2676. +CONFIG_HID_TOPSEED=m
  2677. +CONFIG_HID_THINGM=m
  2678. +CONFIG_HID_THRUSTMASTER=m
  2679. +CONFIG_HID_WACOM=m
  2680. +CONFIG_HID_WIIMOTE=m
  2681. +CONFIG_HID_XINMO=m
  2682. +CONFIG_HID_ZEROPLUS=m
  2683. +CONFIG_HID_ZYDACRON=m
  2684. +CONFIG_HID_PID=y
  2685. +CONFIG_USB_HIDDEV=y
  2686. +CONFIG_USB=y
  2687. +CONFIG_USB_ANNOUNCE_NEW_DEVICES=y
  2688. +CONFIG_USB_MON=m
  2689. +CONFIG_USB_DWCOTG=y
  2690. +CONFIG_USB_PRINTER=m
  2691. +CONFIG_USB_STORAGE=y
  2692. +CONFIG_USB_STORAGE_REALTEK=m
  2693. +CONFIG_USB_STORAGE_DATAFAB=m
  2694. +CONFIG_USB_STORAGE_FREECOM=m
  2695. +CONFIG_USB_STORAGE_ISD200=m
  2696. +CONFIG_USB_STORAGE_USBAT=m
  2697. +CONFIG_USB_STORAGE_SDDR09=m
  2698. +CONFIG_USB_STORAGE_SDDR55=m
  2699. +CONFIG_USB_STORAGE_JUMPSHOT=m
  2700. +CONFIG_USB_STORAGE_ALAUDA=m
  2701. +CONFIG_USB_STORAGE_ONETOUCH=m
  2702. +CONFIG_USB_STORAGE_KARMA=m
  2703. +CONFIG_USB_STORAGE_CYPRESS_ATACB=m
  2704. +CONFIG_USB_STORAGE_ENE_UB6250=m
  2705. +CONFIG_USB_UAS=m
  2706. +CONFIG_USB_MDC800=m
  2707. +CONFIG_USB_MICROTEK=m
  2708. +CONFIG_USBIP_CORE=m
  2709. +CONFIG_USBIP_VHCI_HCD=m
  2710. +CONFIG_USBIP_HOST=m
  2711. +CONFIG_USB_SERIAL=m
  2712. +CONFIG_USB_SERIAL_GENERIC=y
  2713. +CONFIG_USB_SERIAL_AIRCABLE=m
  2714. +CONFIG_USB_SERIAL_ARK3116=m
  2715. +CONFIG_USB_SERIAL_BELKIN=m
  2716. +CONFIG_USB_SERIAL_CH341=m
  2717. +CONFIG_USB_SERIAL_WHITEHEAT=m
  2718. +CONFIG_USB_SERIAL_DIGI_ACCELEPORT=m
  2719. +CONFIG_USB_SERIAL_CP210X=m
  2720. +CONFIG_USB_SERIAL_CYPRESS_M8=m
  2721. +CONFIG_USB_SERIAL_EMPEG=m
  2722. +CONFIG_USB_SERIAL_FTDI_SIO=m
  2723. +CONFIG_USB_SERIAL_VISOR=m
  2724. +CONFIG_USB_SERIAL_IPAQ=m
  2725. +CONFIG_USB_SERIAL_IR=m
  2726. +CONFIG_USB_SERIAL_EDGEPORT=m
  2727. +CONFIG_USB_SERIAL_EDGEPORT_TI=m
  2728. +CONFIG_USB_SERIAL_F81232=m
  2729. +CONFIG_USB_SERIAL_GARMIN=m
  2730. +CONFIG_USB_SERIAL_IPW=m
  2731. +CONFIG_USB_SERIAL_IUU=m
  2732. +CONFIG_USB_SERIAL_KEYSPAN_PDA=m
  2733. +CONFIG_USB_SERIAL_KEYSPAN=m
  2734. +CONFIG_USB_SERIAL_KLSI=m
  2735. +CONFIG_USB_SERIAL_KOBIL_SCT=m
  2736. +CONFIG_USB_SERIAL_MCT_U232=m
  2737. +CONFIG_USB_SERIAL_METRO=m
  2738. +CONFIG_USB_SERIAL_MOS7720=m
  2739. +CONFIG_USB_SERIAL_MOS7840=m
  2740. +CONFIG_USB_SERIAL_NAVMAN=m
  2741. +CONFIG_USB_SERIAL_PL2303=m
  2742. +CONFIG_USB_SERIAL_OTI6858=m
  2743. +CONFIG_USB_SERIAL_QCAUX=m
  2744. +CONFIG_USB_SERIAL_QUALCOMM=m
  2745. +CONFIG_USB_SERIAL_SPCP8X5=m
  2746. +CONFIG_USB_SERIAL_SAFE=m
  2747. +CONFIG_USB_SERIAL_SIERRAWIRELESS=m
  2748. +CONFIG_USB_SERIAL_SYMBOL=m
  2749. +CONFIG_USB_SERIAL_TI=m
  2750. +CONFIG_USB_SERIAL_CYBERJACK=m
  2751. +CONFIG_USB_SERIAL_XIRCOM=m
  2752. +CONFIG_USB_SERIAL_OPTION=m
  2753. +CONFIG_USB_SERIAL_OMNINET=m
  2754. +CONFIG_USB_SERIAL_OPTICON=m
  2755. +CONFIG_USB_SERIAL_XSENS_MT=m
  2756. +CONFIG_USB_SERIAL_WISHBONE=m
  2757. +CONFIG_USB_SERIAL_SSU100=m
  2758. +CONFIG_USB_SERIAL_QT2=m
  2759. +CONFIG_USB_SERIAL_DEBUG=m
  2760. +CONFIG_USB_EMI62=m
  2761. +CONFIG_USB_EMI26=m
  2762. +CONFIG_USB_ADUTUX=m
  2763. +CONFIG_USB_SEVSEG=m
  2764. +CONFIG_USB_RIO500=m
  2765. +CONFIG_USB_LEGOTOWER=m
  2766. +CONFIG_USB_LCD=m
  2767. +CONFIG_USB_LED=m
  2768. +CONFIG_USB_CYPRESS_CY7C63=m
  2769. +CONFIG_USB_CYTHERM=m
  2770. +CONFIG_USB_IDMOUSE=m
  2771. +CONFIG_USB_FTDI_ELAN=m
  2772. +CONFIG_USB_APPLEDISPLAY=m
  2773. +CONFIG_USB_LD=m
  2774. +CONFIG_USB_TRANCEVIBRATOR=m
  2775. +CONFIG_USB_IOWARRIOR=m
  2776. +CONFIG_USB_TEST=m
  2777. +CONFIG_USB_ISIGHTFW=m
  2778. +CONFIG_USB_YUREX=m
  2779. +CONFIG_USB_ATM=m
  2780. +CONFIG_USB_SPEEDTOUCH=m
  2781. +CONFIG_USB_CXACRU=m
  2782. +CONFIG_USB_UEAGLEATM=m
  2783. +CONFIG_USB_XUSBATM=m
  2784. +CONFIG_MMC=y
  2785. +CONFIG_MMC_BLOCK_MINORS=32
  2786. +CONFIG_MMC_SDHCI=y
  2787. +CONFIG_MMC_SDHCI_PLTFM=y
  2788. +CONFIG_MMC_BCM2835=y
  2789. +CONFIG_MMC_BCM2835_DMA=y
  2790. +CONFIG_MMC_SPI=m
  2791. +CONFIG_LEDS_CLASS=y
  2792. +CONFIG_LEDS_GPIO=y
  2793. +CONFIG_LEDS_TRIGGER_TIMER=y
  2794. +CONFIG_LEDS_TRIGGER_ONESHOT=y
  2795. +CONFIG_LEDS_TRIGGER_HEARTBEAT=y
  2796. +CONFIG_LEDS_TRIGGER_BACKLIGHT=y
  2797. +CONFIG_LEDS_TRIGGER_CPU=y
  2798. +CONFIG_LEDS_TRIGGER_GPIO=y
  2799. +CONFIG_LEDS_TRIGGER_DEFAULT_ON=y
  2800. +CONFIG_LEDS_TRIGGER_TRANSIENT=m
  2801. +CONFIG_LEDS_TRIGGER_CAMERA=m
  2802. +CONFIG_LEDS_TRIGGER_INPUT=y
  2803. +CONFIG_RTC_CLASS=y
  2804. +# CONFIG_RTC_HCTOSYS is not set
  2805. +CONFIG_RTC_DRV_DS1307=m
  2806. +CONFIG_RTC_DRV_DS1374=m
  2807. +CONFIG_RTC_DRV_DS1672=m
  2808. +CONFIG_RTC_DRV_DS3232=m
  2809. +CONFIG_RTC_DRV_MAX6900=m
  2810. +CONFIG_RTC_DRV_RS5C372=m
  2811. +CONFIG_RTC_DRV_ISL1208=m
  2812. +CONFIG_RTC_DRV_ISL12022=m
  2813. +CONFIG_RTC_DRV_ISL12057=m
  2814. +CONFIG_RTC_DRV_X1205=m
  2815. +CONFIG_RTC_DRV_PCF2127=m
  2816. +CONFIG_RTC_DRV_PCF8523=m
  2817. +CONFIG_RTC_DRV_PCF8563=m
  2818. +CONFIG_RTC_DRV_PCF8583=m
  2819. +CONFIG_RTC_DRV_M41T80=m
  2820. +CONFIG_RTC_DRV_BQ32K=m
  2821. +CONFIG_RTC_DRV_S35390A=m
  2822. +CONFIG_RTC_DRV_FM3130=m
  2823. +CONFIG_RTC_DRV_RX8581=m
  2824. +CONFIG_RTC_DRV_RX8025=m
  2825. +CONFIG_RTC_DRV_EM3027=m
  2826. +CONFIG_RTC_DRV_RV3029C2=m
  2827. +CONFIG_RTC_DRV_M41T93=m
  2828. +CONFIG_RTC_DRV_M41T94=m
  2829. +CONFIG_RTC_DRV_DS1305=m
  2830. +CONFIG_RTC_DRV_DS1390=m
  2831. +CONFIG_RTC_DRV_MAX6902=m
  2832. +CONFIG_RTC_DRV_R9701=m
  2833. +CONFIG_RTC_DRV_RS5C348=m
  2834. +CONFIG_RTC_DRV_DS3234=m
  2835. +CONFIG_RTC_DRV_PCF2123=m
  2836. +CONFIG_RTC_DRV_RX4581=m
  2837. +CONFIG_DMADEVICES=y
  2838. +CONFIG_DMA_BCM2708=y
  2839. +CONFIG_UIO=m
  2840. +CONFIG_UIO_PDRV_GENIRQ=m
  2841. +CONFIG_STAGING=y
  2842. +CONFIG_PRISM2_USB=m
  2843. +CONFIG_R8712U=m
  2844. +CONFIG_R8188EU=m
  2845. +CONFIG_R8723AU=m
  2846. +CONFIG_VT6656=m
  2847. +CONFIG_SPEAKUP=m
  2848. +CONFIG_SPEAKUP_SYNTH_SOFT=m
  2849. +CONFIG_STAGING_MEDIA=y
  2850. +CONFIG_LIRC_STAGING=y
  2851. +CONFIG_LIRC_IGORPLUGUSB=m
  2852. +CONFIG_LIRC_IMON=m
  2853. +CONFIG_LIRC_RPI=m
  2854. +CONFIG_LIRC_SASEM=m
  2855. +CONFIG_LIRC_SERIAL=m
  2856. +CONFIG_FB_TFT=m
  2857. +CONFIG_FB_TFT_AGM1264K_FL=m
  2858. +CONFIG_FB_TFT_BD663474=m
  2859. +CONFIG_FB_TFT_HX8340BN=m
  2860. +CONFIG_FB_TFT_HX8347D=m
  2861. +CONFIG_FB_TFT_HX8353D=m
  2862. +CONFIG_FB_TFT_ILI9320=m
  2863. +CONFIG_FB_TFT_ILI9325=m
  2864. +CONFIG_FB_TFT_ILI9340=m
  2865. +CONFIG_FB_TFT_ILI9341=m
  2866. +CONFIG_FB_TFT_ILI9481=m
  2867. +CONFIG_FB_TFT_ILI9486=m
  2868. +CONFIG_FB_TFT_PCD8544=m
  2869. +CONFIG_FB_TFT_RA8875=m
  2870. +CONFIG_FB_TFT_S6D02A1=m
  2871. +CONFIG_FB_TFT_S6D1121=m
  2872. +CONFIG_FB_TFT_SSD1289=m
  2873. +CONFIG_FB_TFT_SSD1306=m
  2874. +CONFIG_FB_TFT_SSD1331=m
  2875. +CONFIG_FB_TFT_SSD1351=m
  2876. +CONFIG_FB_TFT_ST7735R=m
  2877. +CONFIG_FB_TFT_TINYLCD=m
  2878. +CONFIG_FB_TFT_TLS8204=m
  2879. +CONFIG_FB_TFT_UC1701=m
  2880. +CONFIG_FB_TFT_UPD161704=m
  2881. +CONFIG_FB_TFT_WATTEROTT=m
  2882. +CONFIG_FB_FLEX=m
  2883. +CONFIG_FB_TFT_FBTFT_DEVICE=m
  2884. +# CONFIG_IOMMU_SUPPORT is not set
  2885. +CONFIG_EXTCON=m
  2886. +CONFIG_EXTCON_ARIZONA=m
  2887. +CONFIG_EXT4_FS=y
  2888. +CONFIG_EXT4_FS_POSIX_ACL=y
  2889. +CONFIG_EXT4_FS_SECURITY=y
  2890. +CONFIG_REISERFS_FS=m
  2891. +CONFIG_REISERFS_FS_XATTR=y
  2892. +CONFIG_REISERFS_FS_POSIX_ACL=y
  2893. +CONFIG_REISERFS_FS_SECURITY=y
  2894. +CONFIG_JFS_FS=m
  2895. +CONFIG_JFS_POSIX_ACL=y
  2896. +CONFIG_JFS_SECURITY=y
  2897. +CONFIG_JFS_STATISTICS=y
  2898. +CONFIG_XFS_FS=m
  2899. +CONFIG_XFS_QUOTA=y
  2900. +CONFIG_XFS_POSIX_ACL=y
  2901. +CONFIG_XFS_RT=y
  2902. +CONFIG_GFS2_FS=m
  2903. +CONFIG_OCFS2_FS=m
  2904. +CONFIG_BTRFS_FS=m
  2905. +CONFIG_BTRFS_FS_POSIX_ACL=y
  2906. +CONFIG_NILFS2_FS=m
  2907. +CONFIG_FANOTIFY=y
  2908. +CONFIG_QFMT_V1=m
  2909. +CONFIG_QFMT_V2=m
  2910. +CONFIG_AUTOFS4_FS=y
  2911. +CONFIG_FUSE_FS=m
  2912. +CONFIG_CUSE=m
  2913. +CONFIG_FSCACHE=y
  2914. +CONFIG_FSCACHE_STATS=y
  2915. +CONFIG_FSCACHE_HISTOGRAM=y
  2916. +CONFIG_CACHEFILES=y
  2917. +CONFIG_ISO9660_FS=m
  2918. +CONFIG_JOLIET=y
  2919. +CONFIG_ZISOFS=y
  2920. +CONFIG_UDF_FS=m
  2921. +CONFIG_MSDOS_FS=y
  2922. +CONFIG_VFAT_FS=y
  2923. +CONFIG_FAT_DEFAULT_IOCHARSET="ascii"
  2924. +CONFIG_NTFS_FS=m
  2925. +CONFIG_NTFS_RW=y
  2926. +CONFIG_TMPFS=y
  2927. +CONFIG_TMPFS_POSIX_ACL=y
  2928. +CONFIG_CONFIGFS_FS=y
  2929. +CONFIG_ECRYPT_FS=m
  2930. +CONFIG_HFS_FS=m
  2931. +CONFIG_HFSPLUS_FS=m
  2932. +CONFIG_SQUASHFS=m
  2933. +CONFIG_SQUASHFS_XATTR=y
  2934. +CONFIG_SQUASHFS_LZO=y
  2935. +CONFIG_SQUASHFS_XZ=y
  2936. +CONFIG_F2FS_FS=y
  2937. +CONFIG_NFS_FS=y
  2938. +CONFIG_NFS_V3_ACL=y
  2939. +CONFIG_NFS_V4=y
  2940. +CONFIG_NFS_SWAP=y
  2941. +CONFIG_ROOT_NFS=y
  2942. +CONFIG_NFS_FSCACHE=y
  2943. +CONFIG_NFSD=m
  2944. +CONFIG_NFSD_V3_ACL=y
  2945. +CONFIG_NFSD_V4=y
  2946. +CONFIG_CIFS=m
  2947. +CONFIG_CIFS_WEAK_PW_HASH=y
  2948. +CONFIG_CIFS_XATTR=y
  2949. +CONFIG_CIFS_POSIX=y
  2950. +CONFIG_9P_FS=m
  2951. +CONFIG_9P_FS_POSIX_ACL=y
  2952. +CONFIG_NLS_DEFAULT="utf8"
  2953. +CONFIG_NLS_CODEPAGE_437=y
  2954. +CONFIG_NLS_CODEPAGE_737=m
  2955. +CONFIG_NLS_CODEPAGE_775=m
  2956. +CONFIG_NLS_CODEPAGE_850=m
  2957. +CONFIG_NLS_CODEPAGE_852=m
  2958. +CONFIG_NLS_CODEPAGE_855=m
  2959. +CONFIG_NLS_CODEPAGE_857=m
  2960. +CONFIG_NLS_CODEPAGE_860=m
  2961. +CONFIG_NLS_CODEPAGE_861=m
  2962. +CONFIG_NLS_CODEPAGE_862=m
  2963. +CONFIG_NLS_CODEPAGE_863=m
  2964. +CONFIG_NLS_CODEPAGE_864=m
  2965. +CONFIG_NLS_CODEPAGE_865=m
  2966. +CONFIG_NLS_CODEPAGE_866=m
  2967. +CONFIG_NLS_CODEPAGE_869=m
  2968. +CONFIG_NLS_CODEPAGE_936=m
  2969. +CONFIG_NLS_CODEPAGE_950=m
  2970. +CONFIG_NLS_CODEPAGE_932=m
  2971. +CONFIG_NLS_CODEPAGE_949=m
  2972. +CONFIG_NLS_CODEPAGE_874=m
  2973. +CONFIG_NLS_ISO8859_8=m
  2974. +CONFIG_NLS_CODEPAGE_1250=m
  2975. +CONFIG_NLS_CODEPAGE_1251=m
  2976. +CONFIG_NLS_ASCII=y
  2977. +CONFIG_NLS_ISO8859_1=m
  2978. +CONFIG_NLS_ISO8859_2=m
  2979. +CONFIG_NLS_ISO8859_3=m
  2980. +CONFIG_NLS_ISO8859_4=m
  2981. +CONFIG_NLS_ISO8859_5=m
  2982. +CONFIG_NLS_ISO8859_6=m
  2983. +CONFIG_NLS_ISO8859_7=m
  2984. +CONFIG_NLS_ISO8859_9=m
  2985. +CONFIG_NLS_ISO8859_13=m
  2986. +CONFIG_NLS_ISO8859_14=m
  2987. +CONFIG_NLS_ISO8859_15=m
  2988. +CONFIG_NLS_KOI8_R=m
  2989. +CONFIG_NLS_KOI8_U=m
  2990. +CONFIG_DLM=m
  2991. +CONFIG_PRINTK_TIME=y
  2992. +CONFIG_BOOT_PRINTK_DELAY=y
  2993. +CONFIG_DEBUG_MEMORY_INIT=y
  2994. +CONFIG_DETECT_HUNG_TASK=y
  2995. +CONFIG_TIMER_STATS=y
  2996. +# CONFIG_DEBUG_PREEMPT is not set
  2997. +CONFIG_IRQSOFF_TRACER=y
  2998. +CONFIG_SCHED_TRACER=y
  2999. +CONFIG_STACK_TRACER=y
  3000. +CONFIG_BLK_DEV_IO_TRACE=y
  3001. +# CONFIG_KPROBE_EVENT is not set
  3002. +CONFIG_FUNCTION_PROFILER=y
  3003. +CONFIG_KGDB=y
  3004. +CONFIG_KGDB_KDB=y
  3005. +CONFIG_KDB_KEYBOARD=y
  3006. +CONFIG_CRYPTO_USER=m
  3007. +CONFIG_CRYPTO_NULL=m
  3008. +CONFIG_CRYPTO_CBC=y
  3009. +CONFIG_CRYPTO_CTS=m
  3010. +CONFIG_CRYPTO_XTS=m
  3011. +CONFIG_CRYPTO_XCBC=m
  3012. +CONFIG_CRYPTO_SHA1_ARM_NEON=m
  3013. +CONFIG_CRYPTO_SHA512_ARM_NEON=m
  3014. +CONFIG_CRYPTO_TGR192=m
  3015. +CONFIG_CRYPTO_WP512=m
  3016. +CONFIG_CRYPTO_AES_ARM_BS=m
  3017. +CONFIG_CRYPTO_CAST5=m
  3018. +CONFIG_CRYPTO_DES=y
  3019. +# CONFIG_CRYPTO_ANSI_CPRNG is not set
  3020. +# CONFIG_CRYPTO_HW is not set
  3021. +CONFIG_CRC_ITU_T=y
  3022. +CONFIG_LIBCRC32C=y
  3023. diff -Nur linux-3.18.8/arch/arm/configs/bcmrpi_defconfig linux-rpi/arch/arm/configs/bcmrpi_defconfig
  3024. --- linux-3.18.8/arch/arm/configs/bcmrpi_defconfig 1970-01-01 01:00:00.000000000 +0100
  3025. +++ linux-rpi/arch/arm/configs/bcmrpi_defconfig 2015-03-05 14:40:11.085715840 +0100
  3026. @@ -0,0 +1,1189 @@
  3027. +# CONFIG_ARM_PATCH_PHYS_VIRT is not set
  3028. +CONFIG_PHYS_OFFSET=0
  3029. +# CONFIG_LOCALVERSION_AUTO is not set
  3030. +CONFIG_SYSVIPC=y
  3031. +CONFIG_POSIX_MQUEUE=y
  3032. +CONFIG_FHANDLE=y
  3033. +CONFIG_AUDIT=y
  3034. +CONFIG_NO_HZ=y
  3035. +CONFIG_HIGH_RES_TIMERS=y
  3036. +CONFIG_BSD_PROCESS_ACCT=y
  3037. +CONFIG_BSD_PROCESS_ACCT_V3=y
  3038. +CONFIG_TASKSTATS=y
  3039. +CONFIG_TASK_DELAY_ACCT=y
  3040. +CONFIG_TASK_XACCT=y
  3041. +CONFIG_TASK_IO_ACCOUNTING=y
  3042. +CONFIG_IKCONFIG=y
  3043. +CONFIG_IKCONFIG_PROC=y
  3044. +CONFIG_CGROUP_FREEZER=y
  3045. +CONFIG_CGROUP_DEVICE=y
  3046. +CONFIG_CGROUP_CPUACCT=y
  3047. +CONFIG_RESOURCE_COUNTERS=y
  3048. +CONFIG_MEMCG=y
  3049. +CONFIG_BLK_CGROUP=y
  3050. +CONFIG_NAMESPACES=y
  3051. +CONFIG_SCHED_AUTOGROUP=y
  3052. +CONFIG_BLK_DEV_INITRD=y
  3053. +CONFIG_EMBEDDED=y
  3054. +# CONFIG_COMPAT_BRK is not set
  3055. +CONFIG_PROFILING=y
  3056. +CONFIG_OPROFILE=m
  3057. +CONFIG_KPROBES=y
  3058. +CONFIG_JUMP_LABEL=y
  3059. +CONFIG_MODULES=y
  3060. +CONFIG_MODULE_UNLOAD=y
  3061. +CONFIG_MODVERSIONS=y
  3062. +CONFIG_MODULE_SRCVERSION_ALL=y
  3063. +CONFIG_BLK_DEV_THROTTLING=y
  3064. +CONFIG_PARTITION_ADVANCED=y
  3065. +CONFIG_MAC_PARTITION=y
  3066. +CONFIG_CFQ_GROUP_IOSCHED=y
  3067. +CONFIG_ARCH_BCM2708=y
  3068. +CONFIG_BCM2708_DT=y
  3069. +CONFIG_PREEMPT=y
  3070. +CONFIG_AEABI=y
  3071. +CONFIG_CLEANCACHE=y
  3072. +CONFIG_FRONTSWAP=y
  3073. +CONFIG_CMA=y
  3074. +CONFIG_UACCESS_WITH_MEMCPY=y
  3075. +CONFIG_SECCOMP=y
  3076. +CONFIG_ZBOOT_ROM_TEXT=0x0
  3077. +CONFIG_ZBOOT_ROM_BSS=0x0
  3078. +CONFIG_CMDLINE="console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait"
  3079. +CONFIG_KEXEC=y
  3080. +CONFIG_CPU_FREQ=y
  3081. +CONFIG_CPU_FREQ_STAT=m
  3082. +CONFIG_CPU_FREQ_STAT_DETAILS=y
  3083. +CONFIG_CPU_FREQ_DEFAULT_GOV_POWERSAVE=y
  3084. +CONFIG_CPU_FREQ_GOV_PERFORMANCE=y
  3085. +CONFIG_CPU_FREQ_GOV_USERSPACE=y
  3086. +CONFIG_CPU_FREQ_GOV_ONDEMAND=y
  3087. +CONFIG_CPU_FREQ_GOV_CONSERVATIVE=y
  3088. +CONFIG_VFP=y
  3089. +CONFIG_BINFMT_MISC=m
  3090. +# CONFIG_SUSPEND is not set
  3091. +CONFIG_NET=y
  3092. +CONFIG_PACKET=y
  3093. +CONFIG_UNIX=y
  3094. +CONFIG_XFRM_USER=y
  3095. +CONFIG_NET_KEY=m
  3096. +CONFIG_INET=y
  3097. +CONFIG_IP_MULTICAST=y
  3098. +CONFIG_IP_ADVANCED_ROUTER=y
  3099. +CONFIG_IP_MULTIPLE_TABLES=y
  3100. +CONFIG_IP_ROUTE_MULTIPATH=y
  3101. +CONFIG_IP_ROUTE_VERBOSE=y
  3102. +CONFIG_IP_PNP=y
  3103. +CONFIG_IP_PNP_DHCP=y
  3104. +CONFIG_IP_PNP_RARP=y
  3105. +CONFIG_NET_IPIP=m
  3106. +CONFIG_NET_IPGRE_DEMUX=m
  3107. +CONFIG_NET_IPGRE=m
  3108. +CONFIG_IP_MROUTE=y
  3109. +CONFIG_IP_MROUTE_MULTIPLE_TABLES=y
  3110. +CONFIG_IP_PIMSM_V1=y
  3111. +CONFIG_IP_PIMSM_V2=y
  3112. +CONFIG_SYN_COOKIES=y
  3113. +CONFIG_INET_AH=m
  3114. +CONFIG_INET_ESP=m
  3115. +CONFIG_INET_IPCOMP=m
  3116. +CONFIG_INET_XFRM_MODE_TRANSPORT=m
  3117. +CONFIG_INET_XFRM_MODE_TUNNEL=m
  3118. +CONFIG_INET_XFRM_MODE_BEET=m
  3119. +CONFIG_INET_LRO=m
  3120. +CONFIG_INET_DIAG=m
  3121. +CONFIG_INET6_AH=m
  3122. +CONFIG_INET6_ESP=m
  3123. +CONFIG_INET6_IPCOMP=m
  3124. +CONFIG_IPV6_TUNNEL=m
  3125. +CONFIG_IPV6_MULTIPLE_TABLES=y
  3126. +CONFIG_IPV6_MROUTE=y
  3127. +CONFIG_IPV6_MROUTE_MULTIPLE_TABLES=y
  3128. +CONFIG_IPV6_PIMSM_V2=y
  3129. +CONFIG_NETFILTER=y
  3130. +CONFIG_NF_CONNTRACK=m
  3131. +CONFIG_NF_CONNTRACK_ZONES=y
  3132. +CONFIG_NF_CONNTRACK_EVENTS=y
  3133. +CONFIG_NF_CONNTRACK_TIMESTAMP=y
  3134. +CONFIG_NF_CT_PROTO_DCCP=m
  3135. +CONFIG_NF_CT_PROTO_UDPLITE=m
  3136. +CONFIG_NF_CONNTRACK_AMANDA=m
  3137. +CONFIG_NF_CONNTRACK_FTP=m
  3138. +CONFIG_NF_CONNTRACK_H323=m
  3139. +CONFIG_NF_CONNTRACK_IRC=m
  3140. +CONFIG_NF_CONNTRACK_NETBIOS_NS=m
  3141. +CONFIG_NF_CONNTRACK_SNMP=m
  3142. +CONFIG_NF_CONNTRACK_PPTP=m
  3143. +CONFIG_NF_CONNTRACK_SANE=m
  3144. +CONFIG_NF_CONNTRACK_SIP=m
  3145. +CONFIG_NF_CONNTRACK_TFTP=m
  3146. +CONFIG_NF_CT_NETLINK=m
  3147. +CONFIG_NETFILTER_XT_SET=m
  3148. +CONFIG_NETFILTER_XT_TARGET_AUDIT=m
  3149. +CONFIG_NETFILTER_XT_TARGET_CHECKSUM=m
  3150. +CONFIG_NETFILTER_XT_TARGET_CLASSIFY=m
  3151. +CONFIG_NETFILTER_XT_TARGET_CONNMARK=m
  3152. +CONFIG_NETFILTER_XT_TARGET_DSCP=m
  3153. +CONFIG_NETFILTER_XT_TARGET_HMARK=m
  3154. +CONFIG_NETFILTER_XT_TARGET_IDLETIMER=m
  3155. +CONFIG_NETFILTER_XT_TARGET_LED=m
  3156. +CONFIG_NETFILTER_XT_TARGET_LOG=m
  3157. +CONFIG_NETFILTER_XT_TARGET_MARK=m
  3158. +CONFIG_NETFILTER_XT_TARGET_NFLOG=m
  3159. +CONFIG_NETFILTER_XT_TARGET_NFQUEUE=m
  3160. +CONFIG_NETFILTER_XT_TARGET_NOTRACK=m
  3161. +CONFIG_NETFILTER_XT_TARGET_TEE=m
  3162. +CONFIG_NETFILTER_XT_TARGET_TPROXY=m
  3163. +CONFIG_NETFILTER_XT_TARGET_TRACE=m
  3164. +CONFIG_NETFILTER_XT_TARGET_TCPMSS=m
  3165. +CONFIG_NETFILTER_XT_TARGET_TCPOPTSTRIP=m
  3166. +CONFIG_NETFILTER_XT_MATCH_ADDRTYPE=m
  3167. +CONFIG_NETFILTER_XT_MATCH_BPF=m
  3168. +CONFIG_NETFILTER_XT_MATCH_CLUSTER=m
  3169. +CONFIG_NETFILTER_XT_MATCH_COMMENT=m
  3170. +CONFIG_NETFILTER_XT_MATCH_CONNBYTES=m
  3171. +CONFIG_NETFILTER_XT_MATCH_CONNLABEL=m
  3172. +CONFIG_NETFILTER_XT_MATCH_CONNLIMIT=m
  3173. +CONFIG_NETFILTER_XT_MATCH_CONNMARK=m
  3174. +CONFIG_NETFILTER_XT_MATCH_CONNTRACK=m
  3175. +CONFIG_NETFILTER_XT_MATCH_CPU=m
  3176. +CONFIG_NETFILTER_XT_MATCH_DCCP=m
  3177. +CONFIG_NETFILTER_XT_MATCH_DEVGROUP=m
  3178. +CONFIG_NETFILTER_XT_MATCH_DSCP=m
  3179. +CONFIG_NETFILTER_XT_MATCH_ESP=m
  3180. +CONFIG_NETFILTER_XT_MATCH_HASHLIMIT=m
  3181. +CONFIG_NETFILTER_XT_MATCH_HELPER=m
  3182. +CONFIG_NETFILTER_XT_MATCH_IPRANGE=m
  3183. +CONFIG_NETFILTER_XT_MATCH_IPVS=m
  3184. +CONFIG_NETFILTER_XT_MATCH_LENGTH=m
  3185. +CONFIG_NETFILTER_XT_MATCH_LIMIT=m
  3186. +CONFIG_NETFILTER_XT_MATCH_MAC=m
  3187. +CONFIG_NETFILTER_XT_MATCH_MARK=m
  3188. +CONFIG_NETFILTER_XT_MATCH_MULTIPORT=m
  3189. +CONFIG_NETFILTER_XT_MATCH_NFACCT=m
  3190. +CONFIG_NETFILTER_XT_MATCH_OSF=m
  3191. +CONFIG_NETFILTER_XT_MATCH_OWNER=m
  3192. +CONFIG_NETFILTER_XT_MATCH_POLICY=m
  3193. +CONFIG_NETFILTER_XT_MATCH_PHYSDEV=m
  3194. +CONFIG_NETFILTER_XT_MATCH_PKTTYPE=m
  3195. +CONFIG_NETFILTER_XT_MATCH_QUOTA=m
  3196. +CONFIG_NETFILTER_XT_MATCH_RATEEST=m
  3197. +CONFIG_NETFILTER_XT_MATCH_REALM=m
  3198. +CONFIG_NETFILTER_XT_MATCH_RECENT=m
  3199. +CONFIG_NETFILTER_XT_MATCH_SOCKET=m
  3200. +CONFIG_NETFILTER_XT_MATCH_STATE=m
  3201. +CONFIG_NETFILTER_XT_MATCH_STATISTIC=m
  3202. +CONFIG_NETFILTER_XT_MATCH_STRING=m
  3203. +CONFIG_NETFILTER_XT_MATCH_TCPMSS=m
  3204. +CONFIG_NETFILTER_XT_MATCH_TIME=m
  3205. +CONFIG_NETFILTER_XT_MATCH_U32=m
  3206. +CONFIG_IP_SET=m
  3207. +CONFIG_IP_SET_BITMAP_IP=m
  3208. +CONFIG_IP_SET_BITMAP_IPMAC=m
  3209. +CONFIG_IP_SET_BITMAP_PORT=m
  3210. +CONFIG_IP_SET_HASH_IP=m
  3211. +CONFIG_IP_SET_HASH_IPPORT=m
  3212. +CONFIG_IP_SET_HASH_IPPORTIP=m
  3213. +CONFIG_IP_SET_HASH_IPPORTNET=m
  3214. +CONFIG_IP_SET_HASH_NET=m
  3215. +CONFIG_IP_SET_HASH_NETPORT=m
  3216. +CONFIG_IP_SET_HASH_NETIFACE=m
  3217. +CONFIG_IP_SET_LIST_SET=m
  3218. +CONFIG_IP_VS=m
  3219. +CONFIG_IP_VS_PROTO_TCP=y
  3220. +CONFIG_IP_VS_PROTO_UDP=y
  3221. +CONFIG_IP_VS_PROTO_ESP=y
  3222. +CONFIG_IP_VS_PROTO_AH=y
  3223. +CONFIG_IP_VS_PROTO_SCTP=y
  3224. +CONFIG_IP_VS_RR=m
  3225. +CONFIG_IP_VS_WRR=m
  3226. +CONFIG_IP_VS_LC=m
  3227. +CONFIG_IP_VS_WLC=m
  3228. +CONFIG_IP_VS_LBLC=m
  3229. +CONFIG_IP_VS_LBLCR=m
  3230. +CONFIG_IP_VS_DH=m
  3231. +CONFIG_IP_VS_SH=m
  3232. +CONFIG_IP_VS_SED=m
  3233. +CONFIG_IP_VS_NQ=m
  3234. +CONFIG_IP_VS_FTP=m
  3235. +CONFIG_IP_VS_PE_SIP=m
  3236. +CONFIG_NF_CONNTRACK_IPV4=m
  3237. +CONFIG_IP_NF_IPTABLES=m
  3238. +CONFIG_IP_NF_MATCH_AH=m
  3239. +CONFIG_IP_NF_MATCH_ECN=m
  3240. +CONFIG_IP_NF_MATCH_TTL=m
  3241. +CONFIG_IP_NF_FILTER=m
  3242. +CONFIG_IP_NF_TARGET_REJECT=m
  3243. +CONFIG_IP_NF_NAT=m
  3244. +CONFIG_IP_NF_TARGET_MASQUERADE=m
  3245. +CONFIG_IP_NF_TARGET_NETMAP=m
  3246. +CONFIG_IP_NF_TARGET_REDIRECT=m
  3247. +CONFIG_IP_NF_MANGLE=m
  3248. +CONFIG_IP_NF_TARGET_CLUSTERIP=m
  3249. +CONFIG_IP_NF_TARGET_ECN=m
  3250. +CONFIG_IP_NF_TARGET_TTL=m
  3251. +CONFIG_IP_NF_RAW=m
  3252. +CONFIG_IP_NF_ARPTABLES=m
  3253. +CONFIG_IP_NF_ARPFILTER=m
  3254. +CONFIG_IP_NF_ARP_MANGLE=m
  3255. +CONFIG_NF_CONNTRACK_IPV6=m
  3256. +CONFIG_IP6_NF_IPTABLES=m
  3257. +CONFIG_IP6_NF_MATCH_AH=m
  3258. +CONFIG_IP6_NF_MATCH_EUI64=m
  3259. +CONFIG_IP6_NF_MATCH_FRAG=m
  3260. +CONFIG_IP6_NF_MATCH_OPTS=m
  3261. +CONFIG_IP6_NF_MATCH_HL=m
  3262. +CONFIG_IP6_NF_MATCH_IPV6HEADER=m
  3263. +CONFIG_IP6_NF_MATCH_MH=m
  3264. +CONFIG_IP6_NF_MATCH_RT=m
  3265. +CONFIG_IP6_NF_TARGET_HL=m
  3266. +CONFIG_IP6_NF_FILTER=m
  3267. +CONFIG_IP6_NF_TARGET_REJECT=m
  3268. +CONFIG_IP6_NF_MANGLE=m
  3269. +CONFIG_IP6_NF_RAW=m
  3270. +CONFIG_IP6_NF_NAT=m
  3271. +CONFIG_IP6_NF_TARGET_MASQUERADE=m
  3272. +CONFIG_IP6_NF_TARGET_NPT=m
  3273. +CONFIG_BRIDGE_NF_EBTABLES=m
  3274. +CONFIG_BRIDGE_EBT_BROUTE=m
  3275. +CONFIG_BRIDGE_EBT_T_FILTER=m
  3276. +CONFIG_BRIDGE_EBT_T_NAT=m
  3277. +CONFIG_BRIDGE_EBT_802_3=m
  3278. +CONFIG_BRIDGE_EBT_AMONG=m
  3279. +CONFIG_BRIDGE_EBT_ARP=m
  3280. +CONFIG_BRIDGE_EBT_IP=m
  3281. +CONFIG_BRIDGE_EBT_IP6=m
  3282. +CONFIG_BRIDGE_EBT_LIMIT=m
  3283. +CONFIG_BRIDGE_EBT_MARK=m
  3284. +CONFIG_BRIDGE_EBT_PKTTYPE=m
  3285. +CONFIG_BRIDGE_EBT_STP=m
  3286. +CONFIG_BRIDGE_EBT_VLAN=m
  3287. +CONFIG_BRIDGE_EBT_ARPREPLY=m
  3288. +CONFIG_BRIDGE_EBT_DNAT=m
  3289. +CONFIG_BRIDGE_EBT_MARK_T=m
  3290. +CONFIG_BRIDGE_EBT_REDIRECT=m
  3291. +CONFIG_BRIDGE_EBT_SNAT=m
  3292. +CONFIG_BRIDGE_EBT_LOG=m
  3293. +CONFIG_BRIDGE_EBT_NFLOG=m
  3294. +CONFIG_SCTP_COOKIE_HMAC_SHA1=y
  3295. +CONFIG_ATM=m
  3296. +CONFIG_L2TP=m
  3297. +CONFIG_L2TP_V3=y
  3298. +CONFIG_L2TP_IP=m
  3299. +CONFIG_L2TP_ETH=m
  3300. +CONFIG_BRIDGE=m
  3301. +CONFIG_VLAN_8021Q=m
  3302. +CONFIG_VLAN_8021Q_GVRP=y
  3303. +CONFIG_ATALK=m
  3304. +CONFIG_6LOWPAN=m
  3305. +CONFIG_NET_SCHED=y
  3306. +CONFIG_NET_SCH_CBQ=m
  3307. +CONFIG_NET_SCH_HTB=m
  3308. +CONFIG_NET_SCH_HFSC=m
  3309. +CONFIG_NET_SCH_PRIO=m
  3310. +CONFIG_NET_SCH_MULTIQ=m
  3311. +CONFIG_NET_SCH_RED=m
  3312. +CONFIG_NET_SCH_SFB=m
  3313. +CONFIG_NET_SCH_SFQ=m
  3314. +CONFIG_NET_SCH_TEQL=m
  3315. +CONFIG_NET_SCH_TBF=m
  3316. +CONFIG_NET_SCH_GRED=m
  3317. +CONFIG_NET_SCH_DSMARK=m
  3318. +CONFIG_NET_SCH_NETEM=m
  3319. +CONFIG_NET_SCH_DRR=m
  3320. +CONFIG_NET_SCH_MQPRIO=m
  3321. +CONFIG_NET_SCH_CHOKE=m
  3322. +CONFIG_NET_SCH_QFQ=m
  3323. +CONFIG_NET_SCH_CODEL=m
  3324. +CONFIG_NET_SCH_FQ_CODEL=m
  3325. +CONFIG_NET_SCH_INGRESS=m
  3326. +CONFIG_NET_SCH_PLUG=m
  3327. +CONFIG_NET_CLS_BASIC=m
  3328. +CONFIG_NET_CLS_TCINDEX=m
  3329. +CONFIG_NET_CLS_ROUTE4=m
  3330. +CONFIG_NET_CLS_FW=m
  3331. +CONFIG_NET_CLS_U32=m
  3332. +CONFIG_CLS_U32_MARK=y
  3333. +CONFIG_NET_CLS_RSVP=m
  3334. +CONFIG_NET_CLS_RSVP6=m
  3335. +CONFIG_NET_CLS_FLOW=m
  3336. +CONFIG_NET_CLS_CGROUP=m
  3337. +CONFIG_NET_EMATCH=y
  3338. +CONFIG_NET_EMATCH_CMP=m
  3339. +CONFIG_NET_EMATCH_NBYTE=m
  3340. +CONFIG_NET_EMATCH_U32=m
  3341. +CONFIG_NET_EMATCH_META=m
  3342. +CONFIG_NET_EMATCH_TEXT=m
  3343. +CONFIG_NET_EMATCH_IPSET=m
  3344. +CONFIG_NET_CLS_ACT=y
  3345. +CONFIG_NET_ACT_POLICE=m
  3346. +CONFIG_NET_ACT_GACT=m
  3347. +CONFIG_GACT_PROB=y
  3348. +CONFIG_NET_ACT_MIRRED=m
  3349. +CONFIG_NET_ACT_IPT=m
  3350. +CONFIG_NET_ACT_NAT=m
  3351. +CONFIG_NET_ACT_PEDIT=m
  3352. +CONFIG_NET_ACT_SIMP=m
  3353. +CONFIG_NET_ACT_SKBEDIT=m
  3354. +CONFIG_NET_ACT_CSUM=m
  3355. +CONFIG_BATMAN_ADV=m
  3356. +CONFIG_OPENVSWITCH=m
  3357. +CONFIG_NET_PKTGEN=m
  3358. +CONFIG_HAMRADIO=y
  3359. +CONFIG_AX25=m
  3360. +CONFIG_NETROM=m
  3361. +CONFIG_ROSE=m
  3362. +CONFIG_MKISS=m
  3363. +CONFIG_6PACK=m
  3364. +CONFIG_BPQETHER=m
  3365. +CONFIG_BAYCOM_SER_FDX=m
  3366. +CONFIG_BAYCOM_SER_HDX=m
  3367. +CONFIG_YAM=m
  3368. +CONFIG_CAN=m
  3369. +CONFIG_CAN_VCAN=m
  3370. +CONFIG_CAN_MCP251X=m
  3371. +CONFIG_IRDA=m
  3372. +CONFIG_IRLAN=m
  3373. +CONFIG_IRNET=m
  3374. +CONFIG_IRCOMM=m
  3375. +CONFIG_IRDA_ULTRA=y
  3376. +CONFIG_IRDA_CACHE_LAST_LSAP=y
  3377. +CONFIG_IRDA_FAST_RR=y
  3378. +CONFIG_IRTTY_SIR=m
  3379. +CONFIG_KINGSUN_DONGLE=m
  3380. +CONFIG_KSDAZZLE_DONGLE=m
  3381. +CONFIG_KS959_DONGLE=m
  3382. +CONFIG_USB_IRDA=m
  3383. +CONFIG_SIGMATEL_FIR=m
  3384. +CONFIG_MCS_FIR=m
  3385. +CONFIG_BT=m
  3386. +CONFIG_BT_6LOWPAN=m
  3387. +CONFIG_BT_RFCOMM=m
  3388. +CONFIG_BT_RFCOMM_TTY=y
  3389. +CONFIG_BT_BNEP=m
  3390. +CONFIG_BT_BNEP_MC_FILTER=y
  3391. +CONFIG_BT_BNEP_PROTO_FILTER=y
  3392. +CONFIG_BT_HIDP=m
  3393. +CONFIG_BT_HCIBTUSB=m
  3394. +CONFIG_BT_HCIBCM203X=m
  3395. +CONFIG_BT_HCIBPA10X=m
  3396. +CONFIG_BT_HCIBFUSB=m
  3397. +CONFIG_BT_HCIVHCI=m
  3398. +CONFIG_BT_MRVL=m
  3399. +CONFIG_BT_MRVL_SDIO=m
  3400. +CONFIG_BT_ATH3K=m
  3401. +CONFIG_BT_WILINK=m
  3402. +CONFIG_CFG80211_WEXT=y
  3403. +CONFIG_MAC80211=m
  3404. +CONFIG_MAC80211_MESH=y
  3405. +CONFIG_WIMAX=m
  3406. +CONFIG_RFKILL=m
  3407. +CONFIG_RFKILL_INPUT=y
  3408. +CONFIG_NET_9P=m
  3409. +CONFIG_NFC=m
  3410. +CONFIG_NFC_PN533=m
  3411. +CONFIG_DEVTMPFS=y
  3412. +CONFIG_DEVTMPFS_MOUNT=y
  3413. +CONFIG_DMA_CMA=y
  3414. +CONFIG_CMA_SIZE_MBYTES=5
  3415. +CONFIG_BLK_DEV_LOOP=y
  3416. +CONFIG_BLK_DEV_CRYPTOLOOP=m
  3417. +CONFIG_BLK_DEV_DRBD=m
  3418. +CONFIG_BLK_DEV_NBD=m
  3419. +CONFIG_BLK_DEV_RAM=y
  3420. +CONFIG_CDROM_PKTCDVD=m
  3421. +CONFIG_ATA_OVER_ETH=m
  3422. +CONFIG_EEPROM_AT24=m
  3423. +CONFIG_SCSI=y
  3424. +# CONFIG_SCSI_PROC_FS is not set
  3425. +CONFIG_BLK_DEV_SD=y
  3426. +CONFIG_CHR_DEV_ST=m
  3427. +CONFIG_CHR_DEV_OSST=m
  3428. +CONFIG_BLK_DEV_SR=m
  3429. +CONFIG_CHR_DEV_SG=m
  3430. +CONFIG_SCSI_ISCSI_ATTRS=y
  3431. +CONFIG_ISCSI_TCP=m
  3432. +CONFIG_ISCSI_BOOT_SYSFS=m
  3433. +CONFIG_MD=y
  3434. +CONFIG_MD_LINEAR=m
  3435. +CONFIG_MD_RAID0=m
  3436. +CONFIG_BLK_DEV_DM=m
  3437. +CONFIG_DM_CRYPT=m
  3438. +CONFIG_DM_SNAPSHOT=m
  3439. +CONFIG_DM_MIRROR=m
  3440. +CONFIG_DM_LOG_USERSPACE=m
  3441. +CONFIG_DM_RAID=m
  3442. +CONFIG_DM_ZERO=m
  3443. +CONFIG_DM_DELAY=m
  3444. +CONFIG_NETDEVICES=y
  3445. +CONFIG_BONDING=m
  3446. +CONFIG_DUMMY=m
  3447. +CONFIG_IFB=m
  3448. +CONFIG_MACVLAN=m
  3449. +CONFIG_NETCONSOLE=m
  3450. +CONFIG_TUN=m
  3451. +CONFIG_VETH=m
  3452. +CONFIG_ENC28J60=m
  3453. +CONFIG_MDIO_BITBANG=m
  3454. +CONFIG_PPP=m
  3455. +CONFIG_PPP_BSDCOMP=m
  3456. +CONFIG_PPP_DEFLATE=m
  3457. +CONFIG_PPP_FILTER=y
  3458. +CONFIG_PPP_MPPE=m
  3459. +CONFIG_PPP_MULTILINK=y
  3460. +CONFIG_PPPOATM=m
  3461. +CONFIG_PPPOE=m
  3462. +CONFIG_PPPOL2TP=m
  3463. +CONFIG_PPP_ASYNC=m
  3464. +CONFIG_PPP_SYNC_TTY=m
  3465. +CONFIG_SLIP=m
  3466. +CONFIG_SLIP_COMPRESSED=y
  3467. +CONFIG_SLIP_SMART=y
  3468. +CONFIG_USB_CATC=m
  3469. +CONFIG_USB_KAWETH=m
  3470. +CONFIG_USB_PEGASUS=m
  3471. +CONFIG_USB_RTL8150=m
  3472. +CONFIG_USB_RTL8152=m
  3473. +CONFIG_USB_USBNET=y
  3474. +CONFIG_USB_NET_AX8817X=m
  3475. +CONFIG_USB_NET_AX88179_178A=m
  3476. +CONFIG_USB_NET_CDCETHER=m
  3477. +CONFIG_USB_NET_CDC_EEM=m
  3478. +CONFIG_USB_NET_CDC_NCM=m
  3479. +CONFIG_USB_NET_HUAWEI_CDC_NCM=m
  3480. +CONFIG_USB_NET_CDC_MBIM=m
  3481. +CONFIG_USB_NET_DM9601=m
  3482. +CONFIG_USB_NET_SR9700=m
  3483. +CONFIG_USB_NET_SR9800=m
  3484. +CONFIG_USB_NET_SMSC75XX=m
  3485. +CONFIG_USB_NET_SMSC95XX=y
  3486. +CONFIG_USB_NET_GL620A=m
  3487. +CONFIG_USB_NET_NET1080=m
  3488. +CONFIG_USB_NET_PLUSB=m
  3489. +CONFIG_USB_NET_MCS7830=m
  3490. +CONFIG_USB_NET_CDC_SUBSET=m
  3491. +CONFIG_USB_ALI_M5632=y
  3492. +CONFIG_USB_AN2720=y
  3493. +CONFIG_USB_EPSON2888=y
  3494. +CONFIG_USB_KC2190=y
  3495. +CONFIG_USB_NET_ZAURUS=m
  3496. +CONFIG_USB_NET_CX82310_ETH=m
  3497. +CONFIG_USB_NET_KALMIA=m
  3498. +CONFIG_USB_NET_QMI_WWAN=m
  3499. +CONFIG_USB_HSO=m
  3500. +CONFIG_USB_NET_INT51X1=m
  3501. +CONFIG_USB_IPHETH=m
  3502. +CONFIG_USB_SIERRA_NET=m
  3503. +CONFIG_USB_VL600=m
  3504. +CONFIG_LIBERTAS_THINFIRM=m
  3505. +CONFIG_LIBERTAS_THINFIRM_USB=m
  3506. +CONFIG_AT76C50X_USB=m
  3507. +CONFIG_USB_ZD1201=m
  3508. +CONFIG_USB_NET_RNDIS_WLAN=m
  3509. +CONFIG_RTL8187=m
  3510. +CONFIG_MAC80211_HWSIM=m
  3511. +CONFIG_ATH_CARDS=m
  3512. +CONFIG_ATH9K=m
  3513. +CONFIG_ATH9K_HTC=m
  3514. +CONFIG_CARL9170=m
  3515. +CONFIG_ATH6KL=m
  3516. +CONFIG_ATH6KL_USB=m
  3517. +CONFIG_AR5523=m
  3518. +CONFIG_B43=m
  3519. +# CONFIG_B43_PHY_N is not set
  3520. +CONFIG_B43LEGACY=m
  3521. +CONFIG_BRCMFMAC=m
  3522. +CONFIG_BRCMFMAC_USB=y
  3523. +CONFIG_HOSTAP=m
  3524. +CONFIG_LIBERTAS=m
  3525. +CONFIG_LIBERTAS_USB=m
  3526. +CONFIG_LIBERTAS_SDIO=m
  3527. +CONFIG_P54_COMMON=m
  3528. +CONFIG_P54_USB=m
  3529. +CONFIG_RT2X00=m
  3530. +CONFIG_RT2500USB=m
  3531. +CONFIG_RT73USB=m
  3532. +CONFIG_RT2800USB=m
  3533. +CONFIG_RT2800USB_RT3573=y
  3534. +CONFIG_RT2800USB_RT53XX=y
  3535. +CONFIG_RT2800USB_RT55XX=y
  3536. +CONFIG_RT2800USB_UNKNOWN=y
  3537. +CONFIG_RTL8192CU=m
  3538. +CONFIG_ZD1211RW=m
  3539. +CONFIG_MWIFIEX=m
  3540. +CONFIG_MWIFIEX_SDIO=m
  3541. +CONFIG_WIMAX_I2400M_USB=m
  3542. +CONFIG_INPUT_POLLDEV=m
  3543. +# CONFIG_INPUT_MOUSEDEV_PSAUX is not set
  3544. +CONFIG_INPUT_JOYDEV=m
  3545. +CONFIG_INPUT_EVDEV=m
  3546. +# CONFIG_INPUT_KEYBOARD is not set
  3547. +# CONFIG_INPUT_MOUSE is not set
  3548. +CONFIG_INPUT_JOYSTICK=y
  3549. +CONFIG_JOYSTICK_IFORCE=m
  3550. +CONFIG_JOYSTICK_IFORCE_USB=y
  3551. +CONFIG_JOYSTICK_XPAD=m
  3552. +CONFIG_JOYSTICK_XPAD_FF=y
  3553. +CONFIG_INPUT_TOUCHSCREEN=y
  3554. +CONFIG_TOUCHSCREEN_ADS7846=m
  3555. +CONFIG_TOUCHSCREEN_EGALAX=m
  3556. +CONFIG_TOUCHSCREEN_USB_COMPOSITE=m
  3557. +CONFIG_INPUT_MISC=y
  3558. +CONFIG_INPUT_AD714X=m
  3559. +CONFIG_INPUT_ATI_REMOTE2=m
  3560. +CONFIG_INPUT_KEYSPAN_REMOTE=m
  3561. +CONFIG_INPUT_POWERMATE=m
  3562. +CONFIG_INPUT_YEALINK=m
  3563. +CONFIG_INPUT_CM109=m
  3564. +CONFIG_INPUT_UINPUT=m
  3565. +CONFIG_INPUT_GPIO_ROTARY_ENCODER=m
  3566. +CONFIG_INPUT_ADXL34X=m
  3567. +CONFIG_INPUT_CMA3000=m
  3568. +CONFIG_SERIO=m
  3569. +CONFIG_SERIO_RAW=m
  3570. +CONFIG_GAMEPORT=m
  3571. +CONFIG_GAMEPORT_NS558=m
  3572. +CONFIG_GAMEPORT_L4=m
  3573. +CONFIG_DEVPTS_MULTIPLE_INSTANCES=y
  3574. +# CONFIG_LEGACY_PTYS is not set
  3575. +# CONFIG_DEVKMEM is not set
  3576. +CONFIG_SERIAL_AMBA_PL011=y
  3577. +CONFIG_SERIAL_AMBA_PL011_CONSOLE=y
  3578. +CONFIG_TTY_PRINTK=y
  3579. +CONFIG_HW_RANDOM=y
  3580. +CONFIG_HW_RANDOM_BCM2708=m
  3581. +CONFIG_RAW_DRIVER=y
  3582. +CONFIG_BRCM_CHAR_DRIVERS=y
  3583. +CONFIG_BCM_VC_CMA=y
  3584. +CONFIG_BCM_VC_SM=y
  3585. +CONFIG_I2C=y
  3586. +CONFIG_I2C_CHARDEV=m
  3587. +CONFIG_I2C_MUX=m
  3588. +CONFIG_I2C_BCM2708=m
  3589. +CONFIG_SPI=y
  3590. +CONFIG_SPI_BCM2835=m
  3591. +CONFIG_SPI_BCM2708=m
  3592. +CONFIG_SPI_SPIDEV=y
  3593. +CONFIG_PPS=m
  3594. +CONFIG_PPS_CLIENT_LDISC=m
  3595. +CONFIG_PPS_CLIENT_GPIO=m
  3596. +CONFIG_GPIO_SYSFS=y
  3597. +CONFIG_GPIO_ARIZONA=m
  3598. +CONFIG_W1=m
  3599. +CONFIG_W1_MASTER_DS2490=m
  3600. +CONFIG_W1_MASTER_DS2482=m
  3601. +CONFIG_W1_MASTER_DS1WM=m
  3602. +CONFIG_W1_MASTER_GPIO=m
  3603. +CONFIG_W1_SLAVE_THERM=m
  3604. +CONFIG_W1_SLAVE_SMEM=m
  3605. +CONFIG_W1_SLAVE_DS2408=m
  3606. +CONFIG_W1_SLAVE_DS2413=m
  3607. +CONFIG_W1_SLAVE_DS2406=m
  3608. +CONFIG_W1_SLAVE_DS2423=m
  3609. +CONFIG_W1_SLAVE_DS2431=m
  3610. +CONFIG_W1_SLAVE_DS2433=m
  3611. +CONFIG_W1_SLAVE_DS2760=m
  3612. +CONFIG_W1_SLAVE_DS2780=m
  3613. +CONFIG_W1_SLAVE_DS2781=m
  3614. +CONFIG_W1_SLAVE_DS28E04=m
  3615. +CONFIG_W1_SLAVE_BQ27000=m
  3616. +CONFIG_BATTERY_DS2760=m
  3617. +# CONFIG_HWMON is not set
  3618. +CONFIG_THERMAL=y
  3619. +CONFIG_THERMAL_BCM2835=y
  3620. +CONFIG_WATCHDOG=y
  3621. +CONFIG_BCM2708_WDT=m
  3622. +CONFIG_UCB1400_CORE=m
  3623. +CONFIG_MFD_ARIZONA_I2C=m
  3624. +CONFIG_MFD_ARIZONA_SPI=m
  3625. +CONFIG_MFD_WM5102=y
  3626. +CONFIG_MEDIA_SUPPORT=m
  3627. +CONFIG_MEDIA_CAMERA_SUPPORT=y
  3628. +CONFIG_MEDIA_ANALOG_TV_SUPPORT=y
  3629. +CONFIG_MEDIA_DIGITAL_TV_SUPPORT=y
  3630. +CONFIG_MEDIA_RADIO_SUPPORT=y
  3631. +CONFIG_MEDIA_RC_SUPPORT=y
  3632. +CONFIG_MEDIA_CONTROLLER=y
  3633. +CONFIG_LIRC=m
  3634. +CONFIG_RC_DEVICES=y
  3635. +CONFIG_RC_ATI_REMOTE=m
  3636. +CONFIG_IR_IMON=m
  3637. +CONFIG_IR_MCEUSB=m
  3638. +CONFIG_IR_REDRAT3=m
  3639. +CONFIG_IR_STREAMZAP=m
  3640. +CONFIG_IR_IGUANA=m
  3641. +CONFIG_IR_TTUSBIR=m
  3642. +CONFIG_RC_LOOPBACK=m
  3643. +CONFIG_IR_GPIO_CIR=m
  3644. +CONFIG_MEDIA_USB_SUPPORT=y
  3645. +CONFIG_USB_VIDEO_CLASS=m
  3646. +CONFIG_USB_M5602=m
  3647. +CONFIG_USB_STV06XX=m
  3648. +CONFIG_USB_GL860=m
  3649. +CONFIG_USB_GSPCA_BENQ=m
  3650. +CONFIG_USB_GSPCA_CONEX=m
  3651. +CONFIG_USB_GSPCA_CPIA1=m
  3652. +CONFIG_USB_GSPCA_DTCS033=m
  3653. +CONFIG_USB_GSPCA_ETOMS=m
  3654. +CONFIG_USB_GSPCA_FINEPIX=m
  3655. +CONFIG_USB_GSPCA_JEILINJ=m
  3656. +CONFIG_USB_GSPCA_JL2005BCD=m
  3657. +CONFIG_USB_GSPCA_KINECT=m
  3658. +CONFIG_USB_GSPCA_KONICA=m
  3659. +CONFIG_USB_GSPCA_MARS=m
  3660. +CONFIG_USB_GSPCA_MR97310A=m
  3661. +CONFIG_USB_GSPCA_NW80X=m
  3662. +CONFIG_USB_GSPCA_OV519=m
  3663. +CONFIG_USB_GSPCA_OV534=m
  3664. +CONFIG_USB_GSPCA_OV534_9=m
  3665. +CONFIG_USB_GSPCA_PAC207=m
  3666. +CONFIG_USB_GSPCA_PAC7302=m
  3667. +CONFIG_USB_GSPCA_PAC7311=m
  3668. +CONFIG_USB_GSPCA_SE401=m
  3669. +CONFIG_USB_GSPCA_SN9C2028=m
  3670. +CONFIG_USB_GSPCA_SN9C20X=m
  3671. +CONFIG_USB_GSPCA_SONIXB=m
  3672. +CONFIG_USB_GSPCA_SONIXJ=m
  3673. +CONFIG_USB_GSPCA_SPCA500=m
  3674. +CONFIG_USB_GSPCA_SPCA501=m
  3675. +CONFIG_USB_GSPCA_SPCA505=m
  3676. +CONFIG_USB_GSPCA_SPCA506=m
  3677. +CONFIG_USB_GSPCA_SPCA508=m
  3678. +CONFIG_USB_GSPCA_SPCA561=m
  3679. +CONFIG_USB_GSPCA_SPCA1528=m
  3680. +CONFIG_USB_GSPCA_SQ905=m
  3681. +CONFIG_USB_GSPCA_SQ905C=m
  3682. +CONFIG_USB_GSPCA_SQ930X=m
  3683. +CONFIG_USB_GSPCA_STK014=m
  3684. +CONFIG_USB_GSPCA_STK1135=m
  3685. +CONFIG_USB_GSPCA_STV0680=m
  3686. +CONFIG_USB_GSPCA_SUNPLUS=m
  3687. +CONFIG_USB_GSPCA_T613=m
  3688. +CONFIG_USB_GSPCA_TOPRO=m
  3689. +CONFIG_USB_GSPCA_TV8532=m
  3690. +CONFIG_USB_GSPCA_VC032X=m
  3691. +CONFIG_USB_GSPCA_VICAM=m
  3692. +CONFIG_USB_GSPCA_XIRLINK_CIT=m
  3693. +CONFIG_USB_GSPCA_ZC3XX=m
  3694. +CONFIG_USB_PWC=m
  3695. +CONFIG_VIDEO_CPIA2=m
  3696. +CONFIG_USB_ZR364XX=m
  3697. +CONFIG_USB_STKWEBCAM=m
  3698. +CONFIG_USB_S2255=m
  3699. +CONFIG_VIDEO_USBTV=m
  3700. +CONFIG_VIDEO_PVRUSB2=m
  3701. +CONFIG_VIDEO_HDPVR=m
  3702. +CONFIG_VIDEO_TLG2300=m
  3703. +CONFIG_VIDEO_USBVISION=m
  3704. +CONFIG_VIDEO_STK1160_COMMON=m
  3705. +CONFIG_VIDEO_STK1160_AC97=y
  3706. +CONFIG_VIDEO_GO7007=m
  3707. +CONFIG_VIDEO_GO7007_USB=m
  3708. +CONFIG_VIDEO_GO7007_USB_S2250_BOARD=m
  3709. +CONFIG_VIDEO_AU0828=m
  3710. +CONFIG_VIDEO_AU0828_RC=y
  3711. +CONFIG_VIDEO_CX231XX=m
  3712. +CONFIG_VIDEO_CX231XX_ALSA=m
  3713. +CONFIG_VIDEO_CX231XX_DVB=m
  3714. +CONFIG_VIDEO_TM6000=m
  3715. +CONFIG_VIDEO_TM6000_ALSA=m
  3716. +CONFIG_VIDEO_TM6000_DVB=m
  3717. +CONFIG_DVB_USB=m
  3718. +CONFIG_DVB_USB_A800=m
  3719. +CONFIG_DVB_USB_DIBUSB_MB=m
  3720. +CONFIG_DVB_USB_DIBUSB_MB_FAULTY=y
  3721. +CONFIG_DVB_USB_DIBUSB_MC=m
  3722. +CONFIG_DVB_USB_DIB0700=m
  3723. +CONFIG_DVB_USB_UMT_010=m
  3724. +CONFIG_DVB_USB_CXUSB=m
  3725. +CONFIG_DVB_USB_M920X=m
  3726. +CONFIG_DVB_USB_DIGITV=m
  3727. +CONFIG_DVB_USB_VP7045=m
  3728. +CONFIG_DVB_USB_VP702X=m
  3729. +CONFIG_DVB_USB_GP8PSK=m
  3730. +CONFIG_DVB_USB_NOVA_T_USB2=m
  3731. +CONFIG_DVB_USB_TTUSB2=m
  3732. +CONFIG_DVB_USB_DTT200U=m
  3733. +CONFIG_DVB_USB_OPERA1=m
  3734. +CONFIG_DVB_USB_AF9005=m
  3735. +CONFIG_DVB_USB_AF9005_REMOTE=m
  3736. +CONFIG_DVB_USB_PCTV452E=m
  3737. +CONFIG_DVB_USB_DW2102=m
  3738. +CONFIG_DVB_USB_CINERGY_T2=m
  3739. +CONFIG_DVB_USB_DTV5100=m
  3740. +CONFIG_DVB_USB_FRIIO=m
  3741. +CONFIG_DVB_USB_AZ6027=m
  3742. +CONFIG_DVB_USB_TECHNISAT_USB2=m
  3743. +CONFIG_DVB_USB_V2=m
  3744. +CONFIG_DVB_USB_AF9015=m
  3745. +CONFIG_DVB_USB_AF9035=m
  3746. +CONFIG_DVB_USB_ANYSEE=m
  3747. +CONFIG_DVB_USB_AU6610=m
  3748. +CONFIG_DVB_USB_AZ6007=m
  3749. +CONFIG_DVB_USB_CE6230=m
  3750. +CONFIG_DVB_USB_EC168=m
  3751. +CONFIG_DVB_USB_GL861=m
  3752. +CONFIG_DVB_USB_LME2510=m
  3753. +CONFIG_DVB_USB_MXL111SF=m
  3754. +CONFIG_DVB_USB_RTL28XXU=m
  3755. +CONFIG_DVB_USB_DVBSKY=m
  3756. +CONFIG_SMS_USB_DRV=m
  3757. +CONFIG_DVB_B2C2_FLEXCOP_USB=m
  3758. +CONFIG_DVB_AS102=m
  3759. +CONFIG_VIDEO_EM28XX=m
  3760. +CONFIG_VIDEO_EM28XX_V4L2=m
  3761. +CONFIG_VIDEO_EM28XX_ALSA=m
  3762. +CONFIG_VIDEO_EM28XX_DVB=m
  3763. +CONFIG_V4L_PLATFORM_DRIVERS=y
  3764. +CONFIG_VIDEO_BCM2835=y
  3765. +CONFIG_VIDEO_BCM2835_MMAL=m
  3766. +CONFIG_RADIO_SI470X=y
  3767. +CONFIG_USB_SI470X=m
  3768. +CONFIG_I2C_SI470X=m
  3769. +CONFIG_RADIO_SI4713=m
  3770. +CONFIG_I2C_SI4713=m
  3771. +CONFIG_USB_MR800=m
  3772. +CONFIG_USB_DSBR=m
  3773. +CONFIG_RADIO_SHARK=m
  3774. +CONFIG_RADIO_SHARK2=m
  3775. +CONFIG_USB_KEENE=m
  3776. +CONFIG_USB_MA901=m
  3777. +CONFIG_RADIO_TEA5764=m
  3778. +CONFIG_RADIO_SAA7706H=m
  3779. +CONFIG_RADIO_TEF6862=m
  3780. +CONFIG_RADIO_WL1273=m
  3781. +CONFIG_RADIO_WL128X=m
  3782. +# CONFIG_MEDIA_SUBDRV_AUTOSELECT is not set
  3783. +CONFIG_VIDEO_UDA1342=m
  3784. +CONFIG_VIDEO_SONY_BTF_MPX=m
  3785. +CONFIG_VIDEO_TVP5150=m
  3786. +CONFIG_VIDEO_TW2804=m
  3787. +CONFIG_VIDEO_TW9903=m
  3788. +CONFIG_VIDEO_TW9906=m
  3789. +CONFIG_VIDEO_OV7640=m
  3790. +CONFIG_VIDEO_MT9V011=m
  3791. +CONFIG_FB=y
  3792. +CONFIG_FB_BCM2708=y
  3793. +# CONFIG_BACKLIGHT_GENERIC is not set
  3794. +CONFIG_FRAMEBUFFER_CONSOLE=y
  3795. +CONFIG_LOGO=y
  3796. +# CONFIG_LOGO_LINUX_MONO is not set
  3797. +# CONFIG_LOGO_LINUX_VGA16 is not set
  3798. +CONFIG_SOUND=y
  3799. +CONFIG_SND=m
  3800. +CONFIG_SND_SEQUENCER=m
  3801. +CONFIG_SND_SEQ_DUMMY=m
  3802. +CONFIG_SND_MIXER_OSS=m
  3803. +CONFIG_SND_PCM_OSS=m
  3804. +CONFIG_SND_SEQUENCER_OSS=y
  3805. +CONFIG_SND_HRTIMER=m
  3806. +CONFIG_SND_DUMMY=m
  3807. +CONFIG_SND_ALOOP=m
  3808. +CONFIG_SND_VIRMIDI=m
  3809. +CONFIG_SND_MTPAV=m
  3810. +CONFIG_SND_SERIAL_U16550=m
  3811. +CONFIG_SND_MPU401=m
  3812. +CONFIG_SND_BCM2835=m
  3813. +CONFIG_SND_USB_AUDIO=m
  3814. +CONFIG_SND_USB_UA101=m
  3815. +CONFIG_SND_USB_CAIAQ=m
  3816. +CONFIG_SND_USB_CAIAQ_INPUT=y
  3817. +CONFIG_SND_USB_6FIRE=m
  3818. +CONFIG_SND_SOC=m
  3819. +CONFIG_SND_BCM2708_SOC_I2S=m
  3820. +CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC=m
  3821. +CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS=m
  3822. +CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI=m
  3823. +CONFIG_SND_BCM2708_SOC_HIFIBERRY_AMP=m
  3824. +CONFIG_SND_BCM2708_SOC_RPI_DAC=m
  3825. +CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC=m
  3826. +CONFIG_SND_SIMPLE_CARD=m
  3827. +CONFIG_SOUND_PRIME=m
  3828. +CONFIG_HIDRAW=y
  3829. +CONFIG_HID_A4TECH=m
  3830. +CONFIG_HID_ACRUX=m
  3831. +CONFIG_HID_APPLE=m
  3832. +CONFIG_HID_BELKIN=m
  3833. +CONFIG_HID_CHERRY=m
  3834. +CONFIG_HID_CHICONY=m
  3835. +CONFIG_HID_CYPRESS=m
  3836. +CONFIG_HID_DRAGONRISE=m
  3837. +CONFIG_HID_EMS_FF=m
  3838. +CONFIG_HID_ELECOM=m
  3839. +CONFIG_HID_ELO=m
  3840. +CONFIG_HID_EZKEY=m
  3841. +CONFIG_HID_HOLTEK=m
  3842. +CONFIG_HID_KEYTOUCH=m
  3843. +CONFIG_HID_KYE=m
  3844. +CONFIG_HID_UCLOGIC=m
  3845. +CONFIG_HID_WALTOP=m
  3846. +CONFIG_HID_GYRATION=m
  3847. +CONFIG_HID_TWINHAN=m
  3848. +CONFIG_HID_KENSINGTON=m
  3849. +CONFIG_HID_LCPOWER=m
  3850. +CONFIG_HID_LOGITECH=m
  3851. +CONFIG_HID_MAGICMOUSE=m
  3852. +CONFIG_HID_MICROSOFT=m
  3853. +CONFIG_HID_MONTEREY=m
  3854. +CONFIG_HID_MULTITOUCH=m
  3855. +CONFIG_HID_NTRIG=m
  3856. +CONFIG_HID_ORTEK=m
  3857. +CONFIG_HID_PANTHERLORD=m
  3858. +CONFIG_HID_PETALYNX=m
  3859. +CONFIG_HID_PICOLCD=m
  3860. +CONFIG_HID_ROCCAT=m
  3861. +CONFIG_HID_SAMSUNG=m
  3862. +CONFIG_HID_SONY=m
  3863. +CONFIG_HID_SPEEDLINK=m
  3864. +CONFIG_HID_SUNPLUS=m
  3865. +CONFIG_HID_GREENASIA=m
  3866. +CONFIG_HID_SMARTJOYPLUS=m
  3867. +CONFIG_HID_TOPSEED=m
  3868. +CONFIG_HID_THINGM=m
  3869. +CONFIG_HID_THRUSTMASTER=m
  3870. +CONFIG_HID_WACOM=m
  3871. +CONFIG_HID_WIIMOTE=m
  3872. +CONFIG_HID_XINMO=m
  3873. +CONFIG_HID_ZEROPLUS=m
  3874. +CONFIG_HID_ZYDACRON=m
  3875. +CONFIG_HID_PID=y
  3876. +CONFIG_USB_HIDDEV=y
  3877. +CONFIG_USB=y
  3878. +CONFIG_USB_ANNOUNCE_NEW_DEVICES=y
  3879. +CONFIG_USB_MON=m
  3880. +CONFIG_USB_DWCOTG=y
  3881. +CONFIG_USB_PRINTER=m
  3882. +CONFIG_USB_STORAGE=y
  3883. +CONFIG_USB_STORAGE_REALTEK=m
  3884. +CONFIG_USB_STORAGE_DATAFAB=m
  3885. +CONFIG_USB_STORAGE_FREECOM=m
  3886. +CONFIG_USB_STORAGE_ISD200=m
  3887. +CONFIG_USB_STORAGE_USBAT=m
  3888. +CONFIG_USB_STORAGE_SDDR09=m
  3889. +CONFIG_USB_STORAGE_SDDR55=m
  3890. +CONFIG_USB_STORAGE_JUMPSHOT=m
  3891. +CONFIG_USB_STORAGE_ALAUDA=m
  3892. +CONFIG_USB_STORAGE_ONETOUCH=m
  3893. +CONFIG_USB_STORAGE_KARMA=m
  3894. +CONFIG_USB_STORAGE_CYPRESS_ATACB=m
  3895. +CONFIG_USB_STORAGE_ENE_UB6250=m
  3896. +CONFIG_USB_UAS=m
  3897. +CONFIG_USB_MDC800=m
  3898. +CONFIG_USB_MICROTEK=m
  3899. +CONFIG_USBIP_CORE=m
  3900. +CONFIG_USBIP_VHCI_HCD=m
  3901. +CONFIG_USBIP_HOST=m
  3902. +CONFIG_USB_SERIAL=m
  3903. +CONFIG_USB_SERIAL_GENERIC=y
  3904. +CONFIG_USB_SERIAL_AIRCABLE=m
  3905. +CONFIG_USB_SERIAL_ARK3116=m
  3906. +CONFIG_USB_SERIAL_BELKIN=m
  3907. +CONFIG_USB_SERIAL_CH341=m
  3908. +CONFIG_USB_SERIAL_WHITEHEAT=m
  3909. +CONFIG_USB_SERIAL_DIGI_ACCELEPORT=m
  3910. +CONFIG_USB_SERIAL_CP210X=m
  3911. +CONFIG_USB_SERIAL_CYPRESS_M8=m
  3912. +CONFIG_USB_SERIAL_EMPEG=m
  3913. +CONFIG_USB_SERIAL_FTDI_SIO=m
  3914. +CONFIG_USB_SERIAL_VISOR=m
  3915. +CONFIG_USB_SERIAL_IPAQ=m
  3916. +CONFIG_USB_SERIAL_IR=m
  3917. +CONFIG_USB_SERIAL_EDGEPORT=m
  3918. +CONFIG_USB_SERIAL_EDGEPORT_TI=m
  3919. +CONFIG_USB_SERIAL_F81232=m
  3920. +CONFIG_USB_SERIAL_GARMIN=m
  3921. +CONFIG_USB_SERIAL_IPW=m
  3922. +CONFIG_USB_SERIAL_IUU=m
  3923. +CONFIG_USB_SERIAL_KEYSPAN_PDA=m
  3924. +CONFIG_USB_SERIAL_KEYSPAN=m
  3925. +CONFIG_USB_SERIAL_KLSI=m
  3926. +CONFIG_USB_SERIAL_KOBIL_SCT=m
  3927. +CONFIG_USB_SERIAL_MCT_U232=m
  3928. +CONFIG_USB_SERIAL_METRO=m
  3929. +CONFIG_USB_SERIAL_MOS7720=m
  3930. +CONFIG_USB_SERIAL_MOS7840=m
  3931. +CONFIG_USB_SERIAL_NAVMAN=m
  3932. +CONFIG_USB_SERIAL_PL2303=m
  3933. +CONFIG_USB_SERIAL_OTI6858=m
  3934. +CONFIG_USB_SERIAL_QCAUX=m
  3935. +CONFIG_USB_SERIAL_QUALCOMM=m
  3936. +CONFIG_USB_SERIAL_SPCP8X5=m
  3937. +CONFIG_USB_SERIAL_SAFE=m
  3938. +CONFIG_USB_SERIAL_SIERRAWIRELESS=m
  3939. +CONFIG_USB_SERIAL_SYMBOL=m
  3940. +CONFIG_USB_SERIAL_TI=m
  3941. +CONFIG_USB_SERIAL_CYBERJACK=m
  3942. +CONFIG_USB_SERIAL_XIRCOM=m
  3943. +CONFIG_USB_SERIAL_OPTION=m
  3944. +CONFIG_USB_SERIAL_OMNINET=m
  3945. +CONFIG_USB_SERIAL_OPTICON=m
  3946. +CONFIG_USB_SERIAL_XSENS_MT=m
  3947. +CONFIG_USB_SERIAL_WISHBONE=m
  3948. +CONFIG_USB_SERIAL_SSU100=m
  3949. +CONFIG_USB_SERIAL_QT2=m
  3950. +CONFIG_USB_SERIAL_DEBUG=m
  3951. +CONFIG_USB_EMI62=m
  3952. +CONFIG_USB_EMI26=m
  3953. +CONFIG_USB_ADUTUX=m
  3954. +CONFIG_USB_SEVSEG=m
  3955. +CONFIG_USB_RIO500=m
  3956. +CONFIG_USB_LEGOTOWER=m
  3957. +CONFIG_USB_LCD=m
  3958. +CONFIG_USB_LED=m
  3959. +CONFIG_USB_CYPRESS_CY7C63=m
  3960. +CONFIG_USB_CYTHERM=m
  3961. +CONFIG_USB_IDMOUSE=m
  3962. +CONFIG_USB_FTDI_ELAN=m
  3963. +CONFIG_USB_APPLEDISPLAY=m
  3964. +CONFIG_USB_LD=m
  3965. +CONFIG_USB_TRANCEVIBRATOR=m
  3966. +CONFIG_USB_IOWARRIOR=m
  3967. +CONFIG_USB_TEST=m
  3968. +CONFIG_USB_ISIGHTFW=m
  3969. +CONFIG_USB_YUREX=m
  3970. +CONFIG_USB_ATM=m
  3971. +CONFIG_USB_SPEEDTOUCH=m
  3972. +CONFIG_USB_CXACRU=m
  3973. +CONFIG_USB_UEAGLEATM=m
  3974. +CONFIG_USB_XUSBATM=m
  3975. +CONFIG_MMC=y
  3976. +CONFIG_MMC_BLOCK_MINORS=32
  3977. +CONFIG_MMC_SDHCI=y
  3978. +CONFIG_MMC_SDHCI_PLTFM=y
  3979. +CONFIG_MMC_BCM2835=y
  3980. +CONFIG_MMC_BCM2835_DMA=y
  3981. +CONFIG_MMC_SPI=m
  3982. +CONFIG_LEDS_CLASS=y
  3983. +CONFIG_LEDS_GPIO=y
  3984. +CONFIG_LEDS_TRIGGER_TIMER=y
  3985. +CONFIG_LEDS_TRIGGER_ONESHOT=y
  3986. +CONFIG_LEDS_TRIGGER_HEARTBEAT=y
  3987. +CONFIG_LEDS_TRIGGER_BACKLIGHT=y
  3988. +CONFIG_LEDS_TRIGGER_CPU=y
  3989. +CONFIG_LEDS_TRIGGER_GPIO=y
  3990. +CONFIG_LEDS_TRIGGER_DEFAULT_ON=y
  3991. +CONFIG_LEDS_TRIGGER_TRANSIENT=m
  3992. +CONFIG_LEDS_TRIGGER_CAMERA=m
  3993. +CONFIG_LEDS_TRIGGER_INPUT=y
  3994. +CONFIG_RTC_CLASS=y
  3995. +# CONFIG_RTC_HCTOSYS is not set
  3996. +CONFIG_RTC_DRV_DS1307=m
  3997. +CONFIG_RTC_DRV_DS1374=m
  3998. +CONFIG_RTC_DRV_DS1672=m
  3999. +CONFIG_RTC_DRV_DS3232=m
  4000. +CONFIG_RTC_DRV_MAX6900=m
  4001. +CONFIG_RTC_DRV_RS5C372=m
  4002. +CONFIG_RTC_DRV_ISL1208=m
  4003. +CONFIG_RTC_DRV_ISL12022=m
  4004. +CONFIG_RTC_DRV_ISL12057=m
  4005. +CONFIG_RTC_DRV_X1205=m
  4006. +CONFIG_RTC_DRV_PCF2127=m
  4007. +CONFIG_RTC_DRV_PCF8523=m
  4008. +CONFIG_RTC_DRV_PCF8563=m
  4009. +CONFIG_RTC_DRV_PCF8583=m
  4010. +CONFIG_RTC_DRV_M41T80=m
  4011. +CONFIG_RTC_DRV_BQ32K=m
  4012. +CONFIG_RTC_DRV_S35390A=m
  4013. +CONFIG_RTC_DRV_FM3130=m
  4014. +CONFIG_RTC_DRV_RX8581=m
  4015. +CONFIG_RTC_DRV_RX8025=m
  4016. +CONFIG_RTC_DRV_EM3027=m
  4017. +CONFIG_RTC_DRV_RV3029C2=m
  4018. +CONFIG_RTC_DRV_M41T93=m
  4019. +CONFIG_RTC_DRV_M41T94=m
  4020. +CONFIG_RTC_DRV_DS1305=m
  4021. +CONFIG_RTC_DRV_DS1390=m
  4022. +CONFIG_RTC_DRV_MAX6902=m
  4023. +CONFIG_RTC_DRV_R9701=m
  4024. +CONFIG_RTC_DRV_RS5C348=m
  4025. +CONFIG_RTC_DRV_DS3234=m
  4026. +CONFIG_RTC_DRV_PCF2123=m
  4027. +CONFIG_RTC_DRV_RX4581=m
  4028. +CONFIG_DMADEVICES=y
  4029. +CONFIG_DMA_BCM2708=y
  4030. +CONFIG_UIO=m
  4031. +CONFIG_UIO_PDRV_GENIRQ=m
  4032. +CONFIG_STAGING=y
  4033. +CONFIG_PRISM2_USB=m
  4034. +CONFIG_R8712U=m
  4035. +CONFIG_R8188EU=m
  4036. +CONFIG_R8723AU=m
  4037. +CONFIG_VT6656=m
  4038. +CONFIG_SPEAKUP=m
  4039. +CONFIG_SPEAKUP_SYNTH_SOFT=m
  4040. +CONFIG_STAGING_MEDIA=y
  4041. +CONFIG_LIRC_STAGING=y
  4042. +CONFIG_LIRC_IGORPLUGUSB=m
  4043. +CONFIG_LIRC_IMON=m
  4044. +CONFIG_LIRC_RPI=m
  4045. +CONFIG_LIRC_SASEM=m
  4046. +CONFIG_LIRC_SERIAL=m
  4047. +CONFIG_FB_TFT=m
  4048. +CONFIG_FB_TFT_AGM1264K_FL=m
  4049. +CONFIG_FB_TFT_BD663474=m
  4050. +CONFIG_FB_TFT_HX8340BN=m
  4051. +CONFIG_FB_TFT_HX8347D=m
  4052. +CONFIG_FB_TFT_HX8353D=m
  4053. +CONFIG_FB_TFT_ILI9320=m
  4054. +CONFIG_FB_TFT_ILI9325=m
  4055. +CONFIG_FB_TFT_ILI9340=m
  4056. +CONFIG_FB_TFT_ILI9341=m
  4057. +CONFIG_FB_TFT_ILI9481=m
  4058. +CONFIG_FB_TFT_ILI9486=m
  4059. +CONFIG_FB_TFT_PCD8544=m
  4060. +CONFIG_FB_TFT_RA8875=m
  4061. +CONFIG_FB_TFT_S6D02A1=m
  4062. +CONFIG_FB_TFT_S6D1121=m
  4063. +CONFIG_FB_TFT_SSD1289=m
  4064. +CONFIG_FB_TFT_SSD1306=m
  4065. +CONFIG_FB_TFT_SSD1331=m
  4066. +CONFIG_FB_TFT_SSD1351=m
  4067. +CONFIG_FB_TFT_ST7735R=m
  4068. +CONFIG_FB_TFT_TINYLCD=m
  4069. +CONFIG_FB_TFT_TLS8204=m
  4070. +CONFIG_FB_TFT_UC1701=m
  4071. +CONFIG_FB_TFT_UPD161704=m
  4072. +CONFIG_FB_TFT_WATTEROTT=m
  4073. +CONFIG_FB_FLEX=m
  4074. +CONFIG_FB_TFT_FBTFT_DEVICE=m
  4075. +# CONFIG_IOMMU_SUPPORT is not set
  4076. +CONFIG_EXTCON=m
  4077. +CONFIG_EXTCON_ARIZONA=m
  4078. +CONFIG_EXT4_FS=y
  4079. +CONFIG_EXT4_FS_POSIX_ACL=y
  4080. +CONFIG_EXT4_FS_SECURITY=y
  4081. +CONFIG_REISERFS_FS=m
  4082. +CONFIG_REISERFS_FS_XATTR=y
  4083. +CONFIG_REISERFS_FS_POSIX_ACL=y
  4084. +CONFIG_REISERFS_FS_SECURITY=y
  4085. +CONFIG_JFS_FS=m
  4086. +CONFIG_JFS_POSIX_ACL=y
  4087. +CONFIG_JFS_SECURITY=y
  4088. +CONFIG_JFS_STATISTICS=y
  4089. +CONFIG_XFS_FS=m
  4090. +CONFIG_XFS_QUOTA=y
  4091. +CONFIG_XFS_POSIX_ACL=y
  4092. +CONFIG_XFS_RT=y
  4093. +CONFIG_GFS2_FS=m
  4094. +CONFIG_OCFS2_FS=m
  4095. +CONFIG_BTRFS_FS=m
  4096. +CONFIG_BTRFS_FS_POSIX_ACL=y
  4097. +CONFIG_NILFS2_FS=m
  4098. +CONFIG_FANOTIFY=y
  4099. +CONFIG_QFMT_V1=m
  4100. +CONFIG_QFMT_V2=m
  4101. +CONFIG_AUTOFS4_FS=y
  4102. +CONFIG_FUSE_FS=m
  4103. +CONFIG_CUSE=m
  4104. +CONFIG_FSCACHE=y
  4105. +CONFIG_FSCACHE_STATS=y
  4106. +CONFIG_FSCACHE_HISTOGRAM=y
  4107. +CONFIG_CACHEFILES=y
  4108. +CONFIG_ISO9660_FS=m
  4109. +CONFIG_JOLIET=y
  4110. +CONFIG_ZISOFS=y
  4111. +CONFIG_UDF_FS=m
  4112. +CONFIG_MSDOS_FS=y
  4113. +CONFIG_VFAT_FS=y
  4114. +CONFIG_FAT_DEFAULT_IOCHARSET="ascii"
  4115. +CONFIG_NTFS_FS=m
  4116. +CONFIG_NTFS_RW=y
  4117. +CONFIG_TMPFS=y
  4118. +CONFIG_TMPFS_POSIX_ACL=y
  4119. +CONFIG_CONFIGFS_FS=y
  4120. +CONFIG_ECRYPT_FS=m
  4121. +CONFIG_HFS_FS=m
  4122. +CONFIG_HFSPLUS_FS=m
  4123. +CONFIG_SQUASHFS=m
  4124. +CONFIG_SQUASHFS_XATTR=y
  4125. +CONFIG_SQUASHFS_LZO=y
  4126. +CONFIG_SQUASHFS_XZ=y
  4127. +CONFIG_F2FS_FS=y
  4128. +CONFIG_NFS_FS=y
  4129. +CONFIG_NFS_V3_ACL=y
  4130. +CONFIG_NFS_V4=y
  4131. +CONFIG_NFS_SWAP=y
  4132. +CONFIG_ROOT_NFS=y
  4133. +CONFIG_NFS_FSCACHE=y
  4134. +CONFIG_NFSD=m
  4135. +CONFIG_NFSD_V3_ACL=y
  4136. +CONFIG_NFSD_V4=y
  4137. +CONFIG_CIFS=m
  4138. +CONFIG_CIFS_WEAK_PW_HASH=y
  4139. +CONFIG_CIFS_XATTR=y
  4140. +CONFIG_CIFS_POSIX=y
  4141. +CONFIG_9P_FS=m
  4142. +CONFIG_9P_FS_POSIX_ACL=y
  4143. +CONFIG_NLS_DEFAULT="utf8"
  4144. +CONFIG_NLS_CODEPAGE_437=y
  4145. +CONFIG_NLS_CODEPAGE_737=m
  4146. +CONFIG_NLS_CODEPAGE_775=m
  4147. +CONFIG_NLS_CODEPAGE_850=m
  4148. +CONFIG_NLS_CODEPAGE_852=m
  4149. +CONFIG_NLS_CODEPAGE_855=m
  4150. +CONFIG_NLS_CODEPAGE_857=m
  4151. +CONFIG_NLS_CODEPAGE_860=m
  4152. +CONFIG_NLS_CODEPAGE_861=m
  4153. +CONFIG_NLS_CODEPAGE_862=m
  4154. +CONFIG_NLS_CODEPAGE_863=m
  4155. +CONFIG_NLS_CODEPAGE_864=m
  4156. +CONFIG_NLS_CODEPAGE_865=m
  4157. +CONFIG_NLS_CODEPAGE_866=m
  4158. +CONFIG_NLS_CODEPAGE_869=m
  4159. +CONFIG_NLS_CODEPAGE_936=m
  4160. +CONFIG_NLS_CODEPAGE_950=m
  4161. +CONFIG_NLS_CODEPAGE_932=m
  4162. +CONFIG_NLS_CODEPAGE_949=m
  4163. +CONFIG_NLS_CODEPAGE_874=m
  4164. +CONFIG_NLS_ISO8859_8=m
  4165. +CONFIG_NLS_CODEPAGE_1250=m
  4166. +CONFIG_NLS_CODEPAGE_1251=m
  4167. +CONFIG_NLS_ASCII=y
  4168. +CONFIG_NLS_ISO8859_1=m
  4169. +CONFIG_NLS_ISO8859_2=m
  4170. +CONFIG_NLS_ISO8859_3=m
  4171. +CONFIG_NLS_ISO8859_4=m
  4172. +CONFIG_NLS_ISO8859_5=m
  4173. +CONFIG_NLS_ISO8859_6=m
  4174. +CONFIG_NLS_ISO8859_7=m
  4175. +CONFIG_NLS_ISO8859_9=m
  4176. +CONFIG_NLS_ISO8859_13=m
  4177. +CONFIG_NLS_ISO8859_14=m
  4178. +CONFIG_NLS_ISO8859_15=m
  4179. +CONFIG_NLS_KOI8_R=m
  4180. +CONFIG_NLS_KOI8_U=m
  4181. +CONFIG_DLM=m
  4182. +CONFIG_PRINTK_TIME=y
  4183. +CONFIG_BOOT_PRINTK_DELAY=y
  4184. +CONFIG_DEBUG_MEMORY_INIT=y
  4185. +CONFIG_DETECT_HUNG_TASK=y
  4186. +CONFIG_TIMER_STATS=y
  4187. +# CONFIG_DEBUG_PREEMPT is not set
  4188. +CONFIG_LATENCYTOP=y
  4189. +CONFIG_IRQSOFF_TRACER=y
  4190. +CONFIG_SCHED_TRACER=y
  4191. +CONFIG_STACK_TRACER=y
  4192. +CONFIG_BLK_DEV_IO_TRACE=y
  4193. +# CONFIG_KPROBE_EVENT is not set
  4194. +CONFIG_FUNCTION_PROFILER=y
  4195. +CONFIG_KGDB=y
  4196. +CONFIG_KGDB_KDB=y
  4197. +CONFIG_KDB_KEYBOARD=y
  4198. +CONFIG_CRYPTO_USER=m
  4199. +CONFIG_CRYPTO_NULL=m
  4200. +CONFIG_CRYPTO_CRYPTD=m
  4201. +CONFIG_CRYPTO_CBC=y
  4202. +CONFIG_CRYPTO_CTS=m
  4203. +CONFIG_CRYPTO_XTS=m
  4204. +CONFIG_CRYPTO_XCBC=m
  4205. +CONFIG_CRYPTO_SHA1_ARM=m
  4206. +CONFIG_CRYPTO_SHA512=m
  4207. +CONFIG_CRYPTO_TGR192=m
  4208. +CONFIG_CRYPTO_WP512=m
  4209. +CONFIG_CRYPTO_AES_ARM=m
  4210. +CONFIG_CRYPTO_CAST5=m
  4211. +CONFIG_CRYPTO_DES=y
  4212. +# CONFIG_CRYPTO_ANSI_CPRNG is not set
  4213. +# CONFIG_CRYPTO_HW is not set
  4214. +CONFIG_CRC_ITU_T=y
  4215. +CONFIG_LIBCRC32C=y
  4216. diff -Nur linux-3.18.8/arch/arm/include/asm/dma-mapping.h linux-rpi/arch/arm/include/asm/dma-mapping.h
  4217. --- linux-3.18.8/arch/arm/include/asm/dma-mapping.h 2015-02-27 02:49:36.000000000 +0100
  4218. +++ linux-rpi/arch/arm/include/asm/dma-mapping.h 2015-03-05 14:40:11.093715840 +0100
  4219. @@ -58,37 +58,21 @@
  4220. #ifndef __arch_pfn_to_dma
  4221. static inline dma_addr_t pfn_to_dma(struct device *dev, unsigned long pfn)
  4222. {
  4223. - if (dev)
  4224. - pfn -= dev->dma_pfn_offset;
  4225. return (dma_addr_t)__pfn_to_bus(pfn);
  4226. }
  4227. static inline unsigned long dma_to_pfn(struct device *dev, dma_addr_t addr)
  4228. {
  4229. - unsigned long pfn = __bus_to_pfn(addr);
  4230. -
  4231. - if (dev)
  4232. - pfn += dev->dma_pfn_offset;
  4233. -
  4234. - return pfn;
  4235. + return __bus_to_pfn(addr);
  4236. }
  4237. static inline void *dma_to_virt(struct device *dev, dma_addr_t addr)
  4238. {
  4239. - if (dev) {
  4240. - unsigned long pfn = dma_to_pfn(dev, addr);
  4241. -
  4242. - return phys_to_virt(__pfn_to_phys(pfn));
  4243. - }
  4244. -
  4245. return (void *)__bus_to_virt((unsigned long)addr);
  4246. }
  4247. static inline dma_addr_t virt_to_dma(struct device *dev, void *addr)
  4248. {
  4249. - if (dev)
  4250. - return pfn_to_dma(dev, virt_to_pfn(addr));
  4251. -
  4252. return (dma_addr_t)__virt_to_bus((unsigned long)(addr));
  4253. }
  4254. diff -Nur linux-3.18.8/arch/arm/include/asm/entry-macro-multi.S linux-rpi/arch/arm/include/asm/entry-macro-multi.S
  4255. --- linux-3.18.8/arch/arm/include/asm/entry-macro-multi.S 2015-02-27 02:49:36.000000000 +0100
  4256. +++ linux-rpi/arch/arm/include/asm/entry-macro-multi.S 2015-03-05 14:40:11.093715840 +0100
  4257. @@ -1,5 +1,6 @@
  4258. #include <asm/assembler.h>
  4259. +#ifndef CONFIG_ARCH_BCM2709
  4260. /*
  4261. * Interrupt handling. Preserves r7, r8, r9
  4262. */
  4263. @@ -28,6 +29,7 @@
  4264. #endif
  4265. 9997:
  4266. .endm
  4267. +#endif
  4268. .macro arch_irq_handler, symbol_name
  4269. .align 5
  4270. diff -Nur linux-3.18.8/arch/arm/include/asm/irqflags.h linux-rpi/arch/arm/include/asm/irqflags.h
  4271. --- linux-3.18.8/arch/arm/include/asm/irqflags.h 2015-02-27 02:49:36.000000000 +0100
  4272. +++ linux-rpi/arch/arm/include/asm/irqflags.h 2015-03-05 14:40:11.097715840 +0100
  4273. @@ -145,12 +145,22 @@
  4274. }
  4275. /*
  4276. - * restore saved IRQ & FIQ state
  4277. + * restore saved IRQ state
  4278. */
  4279. static inline void arch_local_irq_restore(unsigned long flags)
  4280. {
  4281. - asm volatile(
  4282. - " msr " IRQMASK_REG_NAME_W ", %0 @ local_irq_restore"
  4283. + unsigned long temp = 0;
  4284. + flags &= ~(1 << 6);
  4285. + asm volatile (
  4286. + " mrs %0, cpsr"
  4287. + : "=r" (temp)
  4288. + :
  4289. + : "memory", "cc");
  4290. + /* Preserve FIQ bit */
  4291. + temp &= (1 << 6);
  4292. + flags = flags | temp;
  4293. + asm volatile (
  4294. + " msr cpsr_c, %0 @ local_irq_restore"
  4295. :
  4296. : "r" (flags)
  4297. : "memory", "cc");
  4298. diff -Nur linux-3.18.8/arch/arm/include/asm/string.h linux-rpi/arch/arm/include/asm/string.h
  4299. --- linux-3.18.8/arch/arm/include/asm/string.h 2015-02-27 02:49:36.000000000 +0100
  4300. +++ linux-rpi/arch/arm/include/asm/string.h 2015-03-05 14:40:11.097715840 +0100
  4301. @@ -24,6 +24,11 @@
  4302. #define __HAVE_ARCH_MEMSET
  4303. extern void * memset(void *, int, __kernel_size_t);
  4304. +#ifdef CONFIG_MACH_BCM2708
  4305. +#define __HAVE_ARCH_MEMCMP
  4306. +extern int memcmp(const void *, const void *, size_t);
  4307. +#endif
  4308. +
  4309. extern void __memzero(void *ptr, __kernel_size_t n);
  4310. #define memset(p,v,n) \
  4311. diff -Nur linux-3.18.8/arch/arm/include/asm/uaccess.h linux-rpi/arch/arm/include/asm/uaccess.h
  4312. --- linux-3.18.8/arch/arm/include/asm/uaccess.h 2015-02-27 02:49:36.000000000 +0100
  4313. +++ linux-rpi/arch/arm/include/asm/uaccess.h 2015-03-05 14:40:11.097715840 +0100
  4314. @@ -475,6 +475,7 @@
  4315. #ifdef CONFIG_MMU
  4316. extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
  4317. +extern unsigned long __must_check __copy_from_user_std(void *to, const void __user *from, unsigned long n);
  4318. extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
  4319. extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
  4320. extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
  4321. diff -Nur linux-3.18.8/arch/arm/Kconfig linux-rpi/arch/arm/Kconfig
  4322. --- linux-3.18.8/arch/arm/Kconfig 2015-02-27 02:49:36.000000000 +0100
  4323. +++ linux-rpi/arch/arm/Kconfig 2015-03-05 14:40:11.017715840 +0100
  4324. @@ -381,6 +381,23 @@
  4325. This enables support for systems based on Atmel
  4326. AT91RM9200 and AT91SAM9* processors.
  4327. +config ARCH_BCM2708
  4328. + bool "Broadcom BCM2708 family"
  4329. + select CPU_V6
  4330. + select ARM_AMBA
  4331. + select HAVE_SCHED_CLOCK
  4332. + select NEED_MACH_GPIO_H
  4333. + select NEED_MACH_MEMORY_H
  4334. + select COMMON_CLK
  4335. + select ARCH_HAS_CPUFREQ
  4336. + select GENERIC_CLOCKEVENTS
  4337. + select ARM_ERRATA_411920
  4338. + select MACH_BCM2708
  4339. + select VC4
  4340. + select FIQ
  4341. + help
  4342. + This enables support for Broadcom BCM2708 boards.
  4343. +
  4344. config ARCH_CLPS711X
  4345. bool "Cirrus Logic CLPS711x/EP721x/EP731x-based"
  4346. select ARCH_REQUIRE_GPIOLIB
  4347. @@ -786,6 +803,26 @@
  4348. help
  4349. Support for older TI OMAP1 (omap7xx, omap15xx or omap16xx)
  4350. +config ARCH_BCM2709
  4351. + bool "Broadcom BCM2709 family"
  4352. + select ARCH_HAS_BARRIERS if SMP
  4353. + select CPU_V7
  4354. + select HAVE_SMP
  4355. + select ARM_AMBA
  4356. + select MIGHT_HAVE_CACHE_L2X0
  4357. + select HAVE_SCHED_CLOCK
  4358. + select NEED_MACH_MEMORY_H
  4359. + select NEED_MACH_IO_H
  4360. + select COMMON_CLK
  4361. + select ARCH_HAS_CPUFREQ
  4362. + select GENERIC_CLOCKEVENTS
  4363. + select MACH_BCM2709
  4364. + select VC4
  4365. + select FIQ
  4366. +# select ZONE_DMA
  4367. + help
  4368. + This enables support for Broadcom BCM2709 boards.
  4369. +
  4370. endchoice
  4371. menu "Multiple platform selection"
  4372. @@ -972,6 +1009,8 @@
  4373. source "arch/arm/mach-vt8500/Kconfig"
  4374. source "arch/arm/mach-w90x900/Kconfig"
  4375. +source "arch/arm/mach-bcm2708/Kconfig"
  4376. +source "arch/arm/mach-bcm2709/Kconfig"
  4377. source "arch/arm/mach-zynq/Kconfig"
  4378. diff -Nur linux-3.18.8/arch/arm/Kconfig.debug linux-rpi/arch/arm/Kconfig.debug
  4379. --- linux-3.18.8/arch/arm/Kconfig.debug 2015-02-27 02:49:36.000000000 +0100
  4380. +++ linux-rpi/arch/arm/Kconfig.debug 2015-03-05 14:40:11.017715840 +0100
  4381. @@ -985,6 +985,14 @@
  4382. options; the platform specific options are deprecated
  4383. and will be soon removed.
  4384. + config DEBUG_BCM2708_UART0
  4385. + bool "Broadcom BCM2708 UART0 (PL011)"
  4386. + depends on MACH_BCM2708
  4387. + help
  4388. + Say Y here if you want the debug print routines to direct
  4389. + their output to UART 0. The port must have been initialised
  4390. + by the boot-loader before use.
  4391. +
  4392. endchoice
  4393. config DEBUG_EXYNOS_UART
  4394. diff -Nur linux-3.18.8/arch/arm/kernel/fiqasm.S linux-rpi/arch/arm/kernel/fiqasm.S
  4395. --- linux-3.18.8/arch/arm/kernel/fiqasm.S 2015-02-27 02:49:36.000000000 +0100
  4396. +++ linux-rpi/arch/arm/kernel/fiqasm.S 2015-03-05 14:40:11.137715839 +0100
  4397. @@ -47,3 +47,7 @@
  4398. mov r0, r0 @ avoid hazard prior to ARMv4
  4399. ret lr
  4400. ENDPROC(__get_fiq_regs)
  4401. +
  4402. +ENTRY(__FIQ_Branch)
  4403. + mov pc, r8
  4404. +ENDPROC(__FIQ_Branch)
  4405. diff -Nur linux-3.18.8/arch/arm/kernel/head.S linux-rpi/arch/arm/kernel/head.S
  4406. --- linux-3.18.8/arch/arm/kernel/head.S 2015-02-27 02:49:36.000000000 +0100
  4407. +++ linux-rpi/arch/arm/kernel/head.S 2015-03-05 14:40:11.137715839 +0100
  4408. @@ -673,6 +673,14 @@
  4409. ldrcc r7, [r4], #4 @ use branch for delay slot
  4410. bcc 1b
  4411. ret lr
  4412. + nop
  4413. + nop
  4414. + nop
  4415. + nop
  4416. + nop
  4417. + nop
  4418. + nop
  4419. + nop
  4420. #endif
  4421. ENDPROC(__fixup_a_pv_table)
  4422. diff -Nur linux-3.18.8/arch/arm/kernel/process.c linux-rpi/arch/arm/kernel/process.c
  4423. --- linux-3.18.8/arch/arm/kernel/process.c 2015-02-27 02:49:36.000000000 +0100
  4424. +++ linux-rpi/arch/arm/kernel/process.c 2015-03-05 14:40:11.141715839 +0100
  4425. @@ -166,6 +166,16 @@
  4426. }
  4427. #endif
  4428. +char bcm2708_reboot_mode = 'h';
  4429. +
  4430. +int __init reboot_setup(char *str)
  4431. +{
  4432. + bcm2708_reboot_mode = str[0];
  4433. + return 1;
  4434. +}
  4435. +
  4436. +__setup("reboot=", reboot_setup);
  4437. +
  4438. /*
  4439. * Called by kexec, immediately prior to machine_kexec().
  4440. *
  4441. diff -Nur linux-3.18.8/arch/arm/lib/arm-mem.h linux-rpi/arch/arm/lib/arm-mem.h
  4442. --- linux-3.18.8/arch/arm/lib/arm-mem.h 1970-01-01 01:00:00.000000000 +0100
  4443. +++ linux-rpi/arch/arm/lib/arm-mem.h 2015-03-05 14:40:11.145715839 +0100
  4444. @@ -0,0 +1,159 @@
  4445. +/*
  4446. +Copyright (c) 2013, Raspberry Pi Foundation
  4447. +Copyright (c) 2013, RISC OS Open Ltd
  4448. +All rights reserved.
  4449. +
  4450. +Redistribution and use in source and binary forms, with or without
  4451. +modification, are permitted provided that the following conditions are met:
  4452. + * Redistributions of source code must retain the above copyright
  4453. + notice, this list of conditions and the following disclaimer.
  4454. + * Redistributions in binary form must reproduce the above copyright
  4455. + notice, this list of conditions and the following disclaimer in the
  4456. + documentation and/or other materials provided with the distribution.
  4457. + * Neither the name of the copyright holder nor the
  4458. + names of its contributors may be used to endorse or promote products
  4459. + derived from this software without specific prior written permission.
  4460. +
  4461. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  4462. +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  4463. +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  4464. +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
  4465. +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  4466. +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  4467. +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  4468. +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  4469. +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  4470. +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  4471. +*/
  4472. +
  4473. +.macro myfunc fname
  4474. + .func fname
  4475. + .global fname
  4476. +fname:
  4477. +.endm
  4478. +
  4479. +.macro preload_leading_step1 backwards, ptr, base
  4480. +/* If the destination is already 16-byte aligned, then we need to preload
  4481. + * between 0 and prefetch_distance (inclusive) cache lines ahead so there
  4482. + * are no gaps when the inner loop starts.
  4483. + */
  4484. + .if backwards
  4485. + sub ptr, base, #1
  4486. + bic ptr, ptr, #31
  4487. + .else
  4488. + bic ptr, base, #31
  4489. + .endif
  4490. + .set OFFSET, 0
  4491. + .rept prefetch_distance+1
  4492. + pld [ptr, #OFFSET]
  4493. + .if backwards
  4494. + .set OFFSET, OFFSET-32
  4495. + .else
  4496. + .set OFFSET, OFFSET+32
  4497. + .endif
  4498. + .endr
  4499. +.endm
  4500. +
  4501. +.macro preload_leading_step2 backwards, ptr, base, leading_bytes, tmp
  4502. +/* However, if the destination is not 16-byte aligned, we may need to
  4503. + * preload one more cache line than that. The question we need to ask is:
  4504. + * are the leading bytes more than the amount by which the source
  4505. + * pointer will be rounded down for preloading, and if so, by how many
  4506. + * cache lines?
  4507. + */
  4508. + .if backwards
  4509. +/* Here we compare against how many bytes we are into the
  4510. + * cache line, counting down from the highest such address.
  4511. + * Effectively, we want to calculate
  4512. + * leading_bytes = dst&15
  4513. + * cacheline_offset = 31-((src-leading_bytes-1)&31)
  4514. + * extra_needed = leading_bytes - cacheline_offset
  4515. + * and test if extra_needed is <= 0, or rearranging:
  4516. + * leading_bytes + (src-leading_bytes-1)&31 <= 31
  4517. + */
  4518. + mov tmp, base, lsl #32-5
  4519. + sbc tmp, tmp, leading_bytes, lsl #32-5
  4520. + adds tmp, tmp, leading_bytes, lsl #32-5
  4521. + bcc 61f
  4522. + pld [ptr, #-32*(prefetch_distance+1)]
  4523. + .else
  4524. +/* Effectively, we want to calculate
  4525. + * leading_bytes = (-dst)&15
  4526. + * cacheline_offset = (src+leading_bytes)&31
  4527. + * extra_needed = leading_bytes - cacheline_offset
  4528. + * and test if extra_needed is <= 0.
  4529. + */
  4530. + mov tmp, base, lsl #32-5
  4531. + add tmp, tmp, leading_bytes, lsl #32-5
  4532. + rsbs tmp, tmp, leading_bytes, lsl #32-5
  4533. + bls 61f
  4534. + pld [ptr, #32*(prefetch_distance+1)]
  4535. + .endif
  4536. +61:
  4537. +.endm
  4538. +
  4539. +.macro preload_trailing backwards, base, remain, tmp
  4540. + /* We need either 0, 1 or 2 extra preloads */
  4541. + .if backwards
  4542. + rsb tmp, base, #0
  4543. + mov tmp, tmp, lsl #32-5
  4544. + .else
  4545. + mov tmp, base, lsl #32-5
  4546. + .endif
  4547. + adds tmp, tmp, remain, lsl #32-5
  4548. + adceqs tmp, tmp, #0
  4549. + /* The instruction above has two effects: ensures Z is only
  4550. + * set if C was clear (so Z indicates that both shifted quantities
  4551. + * were 0), and clears C if Z was set (so C indicates that the sum
  4552. + * of the shifted quantities was greater and not equal to 32) */
  4553. + beq 82f
  4554. + .if backwards
  4555. + sub tmp, base, #1
  4556. + bic tmp, tmp, #31
  4557. + .else
  4558. + bic tmp, base, #31
  4559. + .endif
  4560. + bcc 81f
  4561. + .if backwards
  4562. + pld [tmp, #-32*(prefetch_distance+1)]
  4563. +81:
  4564. + pld [tmp, #-32*prefetch_distance]
  4565. + .else
  4566. + pld [tmp, #32*(prefetch_distance+2)]
  4567. +81:
  4568. + pld [tmp, #32*(prefetch_distance+1)]
  4569. + .endif
  4570. +82:
  4571. +.endm
  4572. +
  4573. +.macro preload_all backwards, narrow_case, shift, base, remain, tmp0, tmp1
  4574. + .if backwards
  4575. + sub tmp0, base, #1
  4576. + bic tmp0, tmp0, #31
  4577. + pld [tmp0]
  4578. + sub tmp1, base, remain, lsl #shift
  4579. + .else
  4580. + bic tmp0, base, #31
  4581. + pld [tmp0]
  4582. + add tmp1, base, remain, lsl #shift
  4583. + sub tmp1, tmp1, #1
  4584. + .endif
  4585. + bic tmp1, tmp1, #31
  4586. + cmp tmp1, tmp0
  4587. + beq 92f
  4588. + .if narrow_case
  4589. + /* In this case, all the data fits in either 1 or 2 cache lines */
  4590. + pld [tmp1]
  4591. + .else
  4592. +91:
  4593. + .if backwards
  4594. + sub tmp0, tmp0, #32
  4595. + .else
  4596. + add tmp0, tmp0, #32
  4597. + .endif
  4598. + cmp tmp0, tmp1
  4599. + pld [tmp0]
  4600. + bne 91b
  4601. + .endif
  4602. +92:
  4603. +.endm
  4604. diff -Nur linux-3.18.8/arch/arm/lib/copy_from_user.S linux-rpi/arch/arm/lib/copy_from_user.S
  4605. --- linux-3.18.8/arch/arm/lib/copy_from_user.S 2015-02-27 02:49:36.000000000 +0100
  4606. +++ linux-rpi/arch/arm/lib/copy_from_user.S 2015-03-05 14:40:11.145715839 +0100
  4607. @@ -84,11 +84,13 @@
  4608. .text
  4609. -ENTRY(__copy_from_user)
  4610. +ENTRY(__copy_from_user_std)
  4611. +WEAK(__copy_from_user)
  4612. #include "copy_template.S"
  4613. ENDPROC(__copy_from_user)
  4614. +ENDPROC(__copy_from_user_std)
  4615. .pushsection .fixup,"ax"
  4616. .align 0
  4617. diff -Nur linux-3.18.8/arch/arm/lib/exports_rpi.c linux-rpi/arch/arm/lib/exports_rpi.c
  4618. --- linux-3.18.8/arch/arm/lib/exports_rpi.c 1970-01-01 01:00:00.000000000 +0100
  4619. +++ linux-rpi/arch/arm/lib/exports_rpi.c 2015-03-05 14:40:11.145715839 +0100
  4620. @@ -0,0 +1,37 @@
  4621. +/**
  4622. + * Copyright (c) 2014, Raspberry Pi (Trading) Ltd.
  4623. + *
  4624. + * Redistribution and use in source and binary forms, with or without
  4625. + * modification, are permitted provided that the following conditions
  4626. + * are met:
  4627. + * 1. Redistributions of source code must retain the above copyright
  4628. + * notice, this list of conditions, and the following disclaimer,
  4629. + * without modification.
  4630. + * 2. Redistributions in binary form must reproduce the above copyright
  4631. + * notice, this list of conditions and the following disclaimer in the
  4632. + * documentation and/or other materials provided with the distribution.
  4633. + * 3. The names of the above-listed copyright holders may not be used
  4634. + * to endorse or promote products derived from this software without
  4635. + * specific prior written permission.
  4636. + *
  4637. + * ALTERNATIVELY, this software may be distributed under the terms of the
  4638. + * GNU General Public License ("GPL") version 2, as published by the Free
  4639. + * Software Foundation.
  4640. + *
  4641. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  4642. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  4643. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  4644. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  4645. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  4646. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  4647. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  4648. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  4649. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  4650. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  4651. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  4652. + */
  4653. +
  4654. +#include <linux/kernel.h>
  4655. +#include <linux/module.h>
  4656. +
  4657. +EXPORT_SYMBOL(memcmp);
  4658. diff -Nur linux-3.18.8/arch/arm/lib/Makefile linux-rpi/arch/arm/lib/Makefile
  4659. --- linux-3.18.8/arch/arm/lib/Makefile 2015-02-27 02:49:36.000000000 +0100
  4660. +++ linux-rpi/arch/arm/lib/Makefile 2015-03-05 14:40:11.145715839 +0100
  4661. @@ -6,15 +6,24 @@
  4662. lib-y := backtrace.o changebit.o csumipv6.o csumpartial.o \
  4663. csumpartialcopy.o csumpartialcopyuser.o clearbit.o \
  4664. - delay.o delay-loop.o findbit.o memchr.o memcpy.o \
  4665. - memmove.o memset.o memzero.o setbit.o \
  4666. - strchr.o strrchr.o \
  4667. + delay.o delay-loop.o findbit.o memchr.o memzero.o \
  4668. + setbit.o strchr.o strrchr.o \
  4669. testchangebit.o testclearbit.o testsetbit.o \
  4670. ashldi3.o ashrdi3.o lshrdi3.o muldi3.o \
  4671. ucmpdi2.o lib1funcs.o div64.o \
  4672. io-readsb.o io-writesb.o io-readsl.o io-writesl.o \
  4673. call_with_stack.o bswapsdi2.o
  4674. +# Choose optimised implementations for Raspberry Pi
  4675. +ifeq ($(CONFIG_MACH_BCM2708),y)
  4676. + CFLAGS_uaccess_with_memcpy.o += -DCOPY_FROM_USER_THRESHOLD=1600
  4677. + CFLAGS_uaccess_with_memcpy.o += -DCOPY_TO_USER_THRESHOLD=672
  4678. + obj-$(CONFIG_MODULES) += exports_rpi.o
  4679. + lib-y += memcpy_rpi.o memmove_rpi.o memset_rpi.o memcmp_rpi.o
  4680. +else
  4681. + lib-y += memcpy.o memmove.o memset.o
  4682. +endif
  4683. +
  4684. mmu-y := clear_user.o copy_page.o getuser.o putuser.o
  4685. # the code in uaccess.S is not preemption safe and
  4686. diff -Nur linux-3.18.8/arch/arm/lib/memcmp_rpi.S linux-rpi/arch/arm/lib/memcmp_rpi.S
  4687. --- linux-3.18.8/arch/arm/lib/memcmp_rpi.S 1970-01-01 01:00:00.000000000 +0100
  4688. +++ linux-rpi/arch/arm/lib/memcmp_rpi.S 2015-03-05 14:40:11.145715839 +0100
  4689. @@ -0,0 +1,285 @@
  4690. +/*
  4691. +Copyright (c) 2013, Raspberry Pi Foundation
  4692. +Copyright (c) 2013, RISC OS Open Ltd
  4693. +All rights reserved.
  4694. +
  4695. +Redistribution and use in source and binary forms, with or without
  4696. +modification, are permitted provided that the following conditions are met:
  4697. + * Redistributions of source code must retain the above copyright
  4698. + notice, this list of conditions and the following disclaimer.
  4699. + * Redistributions in binary form must reproduce the above copyright
  4700. + notice, this list of conditions and the following disclaimer in the
  4701. + documentation and/or other materials provided with the distribution.
  4702. + * Neither the name of the copyright holder nor the
  4703. + names of its contributors may be used to endorse or promote products
  4704. + derived from this software without specific prior written permission.
  4705. +
  4706. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  4707. +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  4708. +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  4709. +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
  4710. +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  4711. +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  4712. +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  4713. +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  4714. +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  4715. +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  4716. +*/
  4717. +
  4718. +#include <linux/linkage.h>
  4719. +#include "arm-mem.h"
  4720. +
  4721. +/* Prevent the stack from becoming executable */
  4722. +#if defined(__linux__) && defined(__ELF__)
  4723. +.section .note.GNU-stack,"",%progbits
  4724. +#endif
  4725. +
  4726. + .text
  4727. + .arch armv6
  4728. + .object_arch armv4
  4729. + .arm
  4730. + .altmacro
  4731. + .p2align 2
  4732. +
  4733. +.macro memcmp_process_head unaligned
  4734. + .if unaligned
  4735. + ldr DAT0, [S_1], #4
  4736. + ldr DAT1, [S_1], #4
  4737. + ldr DAT2, [S_1], #4
  4738. + ldr DAT3, [S_1], #4
  4739. + .else
  4740. + ldmia S_1!, {DAT0, DAT1, DAT2, DAT3}
  4741. + .endif
  4742. + ldmia S_2!, {DAT4, DAT5, DAT6, DAT7}
  4743. +.endm
  4744. +
  4745. +.macro memcmp_process_tail
  4746. + cmp DAT0, DAT4
  4747. + cmpeq DAT1, DAT5
  4748. + cmpeq DAT2, DAT6
  4749. + cmpeq DAT3, DAT7
  4750. + bne 200f
  4751. +.endm
  4752. +
  4753. +.macro memcmp_leading_31bytes
  4754. + movs DAT0, OFF, lsl #31
  4755. + ldrmib DAT0, [S_1], #1
  4756. + ldrcsh DAT1, [S_1], #2
  4757. + ldrmib DAT4, [S_2], #1
  4758. + ldrcsh DAT5, [S_2], #2
  4759. + movpl DAT0, #0
  4760. + movcc DAT1, #0
  4761. + movpl DAT4, #0
  4762. + movcc DAT5, #0
  4763. + submi N, N, #1
  4764. + subcs N, N, #2
  4765. + cmp DAT0, DAT4
  4766. + cmpeq DAT1, DAT5
  4767. + bne 200f
  4768. + movs DAT0, OFF, lsl #29
  4769. + ldrmi DAT0, [S_1], #4
  4770. + ldrcs DAT1, [S_1], #4
  4771. + ldrcs DAT2, [S_1], #4
  4772. + ldrmi DAT4, [S_2], #4
  4773. + ldmcsia S_2!, {DAT5, DAT6}
  4774. + movpl DAT0, #0
  4775. + movcc DAT1, #0
  4776. + movcc DAT2, #0
  4777. + movpl DAT4, #0
  4778. + movcc DAT5, #0
  4779. + movcc DAT6, #0
  4780. + submi N, N, #4
  4781. + subcs N, N, #8
  4782. + cmp DAT0, DAT4
  4783. + cmpeq DAT1, DAT5
  4784. + cmpeq DAT2, DAT6
  4785. + bne 200f
  4786. + tst OFF, #16
  4787. + beq 105f
  4788. + memcmp_process_head 1
  4789. + sub N, N, #16
  4790. + memcmp_process_tail
  4791. +105:
  4792. +.endm
  4793. +
  4794. +.macro memcmp_trailing_15bytes unaligned
  4795. + movs N, N, lsl #29
  4796. + .if unaligned
  4797. + ldrcs DAT0, [S_1], #4
  4798. + ldrcs DAT1, [S_1], #4
  4799. + .else
  4800. + ldmcsia S_1!, {DAT0, DAT1}
  4801. + .endif
  4802. + ldrmi DAT2, [S_1], #4
  4803. + ldmcsia S_2!, {DAT4, DAT5}
  4804. + ldrmi DAT6, [S_2], #4
  4805. + movcc DAT0, #0
  4806. + movcc DAT1, #0
  4807. + movpl DAT2, #0
  4808. + movcc DAT4, #0
  4809. + movcc DAT5, #0
  4810. + movpl DAT6, #0
  4811. + cmp DAT0, DAT4
  4812. + cmpeq DAT1, DAT5
  4813. + cmpeq DAT2, DAT6
  4814. + bne 200f
  4815. + movs N, N, lsl #2
  4816. + ldrcsh DAT0, [S_1], #2
  4817. + ldrmib DAT1, [S_1]
  4818. + ldrcsh DAT4, [S_2], #2
  4819. + ldrmib DAT5, [S_2]
  4820. + movcc DAT0, #0
  4821. + movpl DAT1, #0
  4822. + movcc DAT4, #0
  4823. + movpl DAT5, #0
  4824. + cmp DAT0, DAT4
  4825. + cmpeq DAT1, DAT5
  4826. + bne 200f
  4827. +.endm
  4828. +
  4829. +.macro memcmp_long_inner_loop unaligned
  4830. +110:
  4831. + memcmp_process_head unaligned
  4832. + pld [S_2, #prefetch_distance*32 + 16]
  4833. + memcmp_process_tail
  4834. + memcmp_process_head unaligned
  4835. + pld [S_1, OFF]
  4836. + memcmp_process_tail
  4837. + subs N, N, #32
  4838. + bhs 110b
  4839. + /* Just before the final (prefetch_distance+1) 32-byte blocks,
  4840. + * deal with final preloads */
  4841. + preload_trailing 0, S_1, N, DAT0
  4842. + preload_trailing 0, S_2, N, DAT0
  4843. + add N, N, #(prefetch_distance+2)*32 - 16
  4844. +120:
  4845. + memcmp_process_head unaligned
  4846. + memcmp_process_tail
  4847. + subs N, N, #16
  4848. + bhs 120b
  4849. + /* Trailing words and bytes */
  4850. + tst N, #15
  4851. + beq 199f
  4852. + memcmp_trailing_15bytes unaligned
  4853. +199: /* Reached end without detecting a difference */
  4854. + mov a1, #0
  4855. + setend le
  4856. + pop {DAT1-DAT6, pc}
  4857. +.endm
  4858. +
  4859. +.macro memcmp_short_inner_loop unaligned
  4860. + subs N, N, #16 /* simplifies inner loop termination */
  4861. + blo 122f
  4862. +120:
  4863. + memcmp_process_head unaligned
  4864. + memcmp_process_tail
  4865. + subs N, N, #16
  4866. + bhs 120b
  4867. +122: /* Trailing words and bytes */
  4868. + tst N, #15
  4869. + beq 199f
  4870. + memcmp_trailing_15bytes unaligned
  4871. +199: /* Reached end without detecting a difference */
  4872. + mov a1, #0
  4873. + setend le
  4874. + pop {DAT1-DAT6, pc}
  4875. +.endm
  4876. +
  4877. +/*
  4878. + * int memcmp(const void *s1, const void *s2, size_t n);
  4879. + * On entry:
  4880. + * a1 = pointer to buffer 1
  4881. + * a2 = pointer to buffer 2
  4882. + * a3 = number of bytes to compare (as unsigned chars)
  4883. + * On exit:
  4884. + * a1 = >0/=0/<0 if s1 >/=/< s2
  4885. + */
  4886. +
  4887. +.set prefetch_distance, 2
  4888. +
  4889. +ENTRY(memcmp)
  4890. + S_1 .req a1
  4891. + S_2 .req a2
  4892. + N .req a3
  4893. + DAT0 .req a4
  4894. + DAT1 .req v1
  4895. + DAT2 .req v2
  4896. + DAT3 .req v3
  4897. + DAT4 .req v4
  4898. + DAT5 .req v5
  4899. + DAT6 .req v6
  4900. + DAT7 .req ip
  4901. + OFF .req lr
  4902. +
  4903. + push {DAT1-DAT6, lr}
  4904. + setend be /* lowest-addressed bytes are most significant */
  4905. +
  4906. + /* To preload ahead as we go, we need at least (prefetch_distance+2) 32-byte blocks */
  4907. + cmp N, #(prefetch_distance+3)*32 - 1
  4908. + blo 170f
  4909. +
  4910. + /* Long case */
  4911. + /* Adjust N so that the decrement instruction can also test for
  4912. + * inner loop termination. We want it to stop when there are
  4913. + * (prefetch_distance+1) complete blocks to go. */
  4914. + sub N, N, #(prefetch_distance+2)*32
  4915. + preload_leading_step1 0, DAT0, S_1
  4916. + preload_leading_step1 0, DAT1, S_2
  4917. + tst S_2, #31
  4918. + beq 154f
  4919. + rsb OFF, S_2, #0 /* no need to AND with 15 here */
  4920. + preload_leading_step2 0, DAT0, S_1, OFF, DAT2
  4921. + preload_leading_step2 0, DAT1, S_2, OFF, DAT2
  4922. + memcmp_leading_31bytes
  4923. +154: /* Second source now cacheline (32-byte) aligned; we have at
  4924. + * least one prefetch to go. */
  4925. + /* Prefetch offset is best selected such that it lies in the
  4926. + * first 8 of each 32 bytes - but it's just as easy to aim for
  4927. + * the first one */
  4928. + and OFF, S_1, #31
  4929. + rsb OFF, OFF, #32*prefetch_distance
  4930. + tst S_1, #3
  4931. + bne 140f
  4932. + memcmp_long_inner_loop 0
  4933. +140: memcmp_long_inner_loop 1
  4934. +
  4935. +170: /* Short case */
  4936. + teq N, #0
  4937. + beq 199f
  4938. + preload_all 0, 0, 0, S_1, N, DAT0, DAT1
  4939. + preload_all 0, 0, 0, S_2, N, DAT0, DAT1
  4940. + tst S_2, #3
  4941. + beq 174f
  4942. +172: subs N, N, #1
  4943. + blo 199f
  4944. + ldrb DAT0, [S_1], #1
  4945. + ldrb DAT4, [S_2], #1
  4946. + cmp DAT0, DAT4
  4947. + bne 200f
  4948. + tst S_2, #3
  4949. + bne 172b
  4950. +174: /* Second source now 4-byte aligned; we have 0 or more bytes to go */
  4951. + tst S_1, #3
  4952. + bne 140f
  4953. + memcmp_short_inner_loop 0
  4954. +140: memcmp_short_inner_loop 1
  4955. +
  4956. +200: /* Difference found: determine sign. */
  4957. + movhi a1, #1
  4958. + movlo a1, #-1
  4959. + setend le
  4960. + pop {DAT1-DAT6, pc}
  4961. +
  4962. + .unreq S_1
  4963. + .unreq S_2
  4964. + .unreq N
  4965. + .unreq DAT0
  4966. + .unreq DAT1
  4967. + .unreq DAT2
  4968. + .unreq DAT3
  4969. + .unreq DAT4
  4970. + .unreq DAT5
  4971. + .unreq DAT6
  4972. + .unreq DAT7
  4973. + .unreq OFF
  4974. +ENDPROC(memcmp)
  4975. diff -Nur linux-3.18.8/arch/arm/lib/memcpymove.h linux-rpi/arch/arm/lib/memcpymove.h
  4976. --- linux-3.18.8/arch/arm/lib/memcpymove.h 1970-01-01 01:00:00.000000000 +0100
  4977. +++ linux-rpi/arch/arm/lib/memcpymove.h 2015-03-05 14:40:11.145715839 +0100
  4978. @@ -0,0 +1,506 @@
  4979. +/*
  4980. +Copyright (c) 2013, Raspberry Pi Foundation
  4981. +Copyright (c) 2013, RISC OS Open Ltd
  4982. +All rights reserved.
  4983. +
  4984. +Redistribution and use in source and binary forms, with or without
  4985. +modification, are permitted provided that the following conditions are met:
  4986. + * Redistributions of source code must retain the above copyright
  4987. + notice, this list of conditions and the following disclaimer.
  4988. + * Redistributions in binary form must reproduce the above copyright
  4989. + notice, this list of conditions and the following disclaimer in the
  4990. + documentation and/or other materials provided with the distribution.
  4991. + * Neither the name of the copyright holder nor the
  4992. + names of its contributors may be used to endorse or promote products
  4993. + derived from this software without specific prior written permission.
  4994. +
  4995. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  4996. +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  4997. +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  4998. +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
  4999. +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  5000. +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  5001. +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  5002. +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  5003. +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  5004. +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  5005. +*/
  5006. +
  5007. +.macro unaligned_words backwards, align, use_pld, words, r0, r1, r2, r3, r4, r5, r6, r7, r8
  5008. + .if words == 1
  5009. + .if backwards
  5010. + mov r1, r0, lsl #32-align*8
  5011. + ldr r0, [S, #-4]!
  5012. + orr r1, r1, r0, lsr #align*8
  5013. + str r1, [D, #-4]!
  5014. + .else
  5015. + mov r0, r1, lsr #align*8
  5016. + ldr r1, [S, #4]!
  5017. + orr r0, r0, r1, lsl #32-align*8
  5018. + str r0, [D], #4
  5019. + .endif
  5020. + .elseif words == 2
  5021. + .if backwards
  5022. + ldr r1, [S, #-4]!
  5023. + mov r2, r0, lsl #32-align*8
  5024. + ldr r0, [S, #-4]!
  5025. + orr r2, r2, r1, lsr #align*8
  5026. + mov r1, r1, lsl #32-align*8
  5027. + orr r1, r1, r0, lsr #align*8
  5028. + stmdb D!, {r1, r2}
  5029. + .else
  5030. + ldr r1, [S, #4]!
  5031. + mov r0, r2, lsr #align*8
  5032. + ldr r2, [S, #4]!
  5033. + orr r0, r0, r1, lsl #32-align*8
  5034. + mov r1, r1, lsr #align*8
  5035. + orr r1, r1, r2, lsl #32-align*8
  5036. + stmia D!, {r0, r1}
  5037. + .endif
  5038. + .elseif words == 4
  5039. + .if backwards
  5040. + ldmdb S!, {r2, r3}
  5041. + mov r4, r0, lsl #32-align*8
  5042. + ldmdb S!, {r0, r1}
  5043. + orr r4, r4, r3, lsr #align*8
  5044. + mov r3, r3, lsl #32-align*8
  5045. + orr r3, r3, r2, lsr #align*8
  5046. + mov r2, r2, lsl #32-align*8
  5047. + orr r2, r2, r1, lsr #align*8
  5048. + mov r1, r1, lsl #32-align*8
  5049. + orr r1, r1, r0, lsr #align*8
  5050. + stmdb D!, {r1, r2, r3, r4}
  5051. + .else
  5052. + ldmib S!, {r1, r2}
  5053. + mov r0, r4, lsr #align*8
  5054. + ldmib S!, {r3, r4}
  5055. + orr r0, r0, r1, lsl #32-align*8
  5056. + mov r1, r1, lsr #align*8
  5057. + orr r1, r1, r2, lsl #32-align*8
  5058. + mov r2, r2, lsr #align*8
  5059. + orr r2, r2, r3, lsl #32-align*8
  5060. + mov r3, r3, lsr #align*8
  5061. + orr r3, r3, r4, lsl #32-align*8
  5062. + stmia D!, {r0, r1, r2, r3}
  5063. + .endif
  5064. + .elseif words == 8
  5065. + .if backwards
  5066. + ldmdb S!, {r4, r5, r6, r7}
  5067. + mov r8, r0, lsl #32-align*8
  5068. + ldmdb S!, {r0, r1, r2, r3}
  5069. + .if use_pld
  5070. + pld [S, OFF]
  5071. + .endif
  5072. + orr r8, r8, r7, lsr #align*8
  5073. + mov r7, r7, lsl #32-align*8
  5074. + orr r7, r7, r6, lsr #align*8
  5075. + mov r6, r6, lsl #32-align*8
  5076. + orr r6, r6, r5, lsr #align*8
  5077. + mov r5, r5, lsl #32-align*8
  5078. + orr r5, r5, r4, lsr #align*8
  5079. + mov r4, r4, lsl #32-align*8
  5080. + orr r4, r4, r3, lsr #align*8
  5081. + mov r3, r3, lsl #32-align*8
  5082. + orr r3, r3, r2, lsr #align*8
  5083. + mov r2, r2, lsl #32-align*8
  5084. + orr r2, r2, r1, lsr #align*8
  5085. + mov r1, r1, lsl #32-align*8
  5086. + orr r1, r1, r0, lsr #align*8
  5087. + stmdb D!, {r5, r6, r7, r8}
  5088. + stmdb D!, {r1, r2, r3, r4}
  5089. + .else
  5090. + ldmib S!, {r1, r2, r3, r4}
  5091. + mov r0, r8, lsr #align*8
  5092. + ldmib S!, {r5, r6, r7, r8}
  5093. + .if use_pld
  5094. + pld [S, OFF]
  5095. + .endif
  5096. + orr r0, r0, r1, lsl #32-align*8
  5097. + mov r1, r1, lsr #align*8
  5098. + orr r1, r1, r2, lsl #32-align*8
  5099. + mov r2, r2, lsr #align*8
  5100. + orr r2, r2, r3, lsl #32-align*8
  5101. + mov r3, r3, lsr #align*8
  5102. + orr r3, r3, r4, lsl #32-align*8
  5103. + mov r4, r4, lsr #align*8
  5104. + orr r4, r4, r5, lsl #32-align*8
  5105. + mov r5, r5, lsr #align*8
  5106. + orr r5, r5, r6, lsl #32-align*8
  5107. + mov r6, r6, lsr #align*8
  5108. + orr r6, r6, r7, lsl #32-align*8
  5109. + mov r7, r7, lsr #align*8
  5110. + orr r7, r7, r8, lsl #32-align*8
  5111. + stmia D!, {r0, r1, r2, r3}
  5112. + stmia D!, {r4, r5, r6, r7}
  5113. + .endif
  5114. + .endif
  5115. +.endm
  5116. +
  5117. +.macro memcpy_leading_15bytes backwards, align
  5118. + movs DAT1, DAT2, lsl #31
  5119. + sub N, N, DAT2
  5120. + .if backwards
  5121. + ldrmib DAT0, [S, #-1]!
  5122. + ldrcsh DAT1, [S, #-2]!
  5123. + strmib DAT0, [D, #-1]!
  5124. + strcsh DAT1, [D, #-2]!
  5125. + .else
  5126. + ldrmib DAT0, [S], #1
  5127. + ldrcsh DAT1, [S], #2
  5128. + strmib DAT0, [D], #1
  5129. + strcsh DAT1, [D], #2
  5130. + .endif
  5131. + movs DAT1, DAT2, lsl #29
  5132. + .if backwards
  5133. + ldrmi DAT0, [S, #-4]!
  5134. + .if align == 0
  5135. + ldmcsdb S!, {DAT1, DAT2}
  5136. + .else
  5137. + ldrcs DAT2, [S, #-4]!
  5138. + ldrcs DAT1, [S, #-4]!
  5139. + .endif
  5140. + strmi DAT0, [D, #-4]!
  5141. + stmcsdb D!, {DAT1, DAT2}
  5142. + .else
  5143. + ldrmi DAT0, [S], #4
  5144. + .if align == 0
  5145. + ldmcsia S!, {DAT1, DAT2}
  5146. + .else
  5147. + ldrcs DAT1, [S], #4
  5148. + ldrcs DAT2, [S], #4
  5149. + .endif
  5150. + strmi DAT0, [D], #4
  5151. + stmcsia D!, {DAT1, DAT2}
  5152. + .endif
  5153. +.endm
  5154. +
  5155. +.macro memcpy_trailing_15bytes backwards, align
  5156. + movs N, N, lsl #29
  5157. + .if backwards
  5158. + .if align == 0
  5159. + ldmcsdb S!, {DAT0, DAT1}
  5160. + .else
  5161. + ldrcs DAT1, [S, #-4]!
  5162. + ldrcs DAT0, [S, #-4]!
  5163. + .endif
  5164. + ldrmi DAT2, [S, #-4]!
  5165. + stmcsdb D!, {DAT0, DAT1}
  5166. + strmi DAT2, [D, #-4]!
  5167. + .else
  5168. + .if align == 0
  5169. + ldmcsia S!, {DAT0, DAT1}
  5170. + .else
  5171. + ldrcs DAT0, [S], #4
  5172. + ldrcs DAT1, [S], #4
  5173. + .endif
  5174. + ldrmi DAT2, [S], #4
  5175. + stmcsia D!, {DAT0, DAT1}
  5176. + strmi DAT2, [D], #4
  5177. + .endif
  5178. + movs N, N, lsl #2
  5179. + .if backwards
  5180. + ldrcsh DAT0, [S, #-2]!
  5181. + ldrmib DAT1, [S, #-1]
  5182. + strcsh DAT0, [D, #-2]!
  5183. + strmib DAT1, [D, #-1]
  5184. + .else
  5185. + ldrcsh DAT0, [S], #2
  5186. + ldrmib DAT1, [S]
  5187. + strcsh DAT0, [D], #2
  5188. + strmib DAT1, [D]
  5189. + .endif
  5190. +.endm
  5191. +
  5192. +.macro memcpy_long_inner_loop backwards, align
  5193. + .if align != 0
  5194. + .if backwards
  5195. + ldr DAT0, [S, #-align]!
  5196. + .else
  5197. + ldr LAST, [S, #-align]!
  5198. + .endif
  5199. + .endif
  5200. +110:
  5201. + .if align == 0
  5202. + .if backwards
  5203. + ldmdb S!, {DAT0, DAT1, DAT2, DAT3, DAT4, DAT5, DAT6, LAST}
  5204. + pld [S, OFF]
  5205. + stmdb D!, {DAT4, DAT5, DAT6, LAST}
  5206. + stmdb D!, {DAT0, DAT1, DAT2, DAT3}
  5207. + .else
  5208. + ldmia S!, {DAT0, DAT1, DAT2, DAT3, DAT4, DAT5, DAT6, LAST}
  5209. + pld [S, OFF]
  5210. + stmia D!, {DAT0, DAT1, DAT2, DAT3}
  5211. + stmia D!, {DAT4, DAT5, DAT6, LAST}
  5212. + .endif
  5213. + .else
  5214. + unaligned_words backwards, align, 1, 8, DAT0, DAT1, DAT2, DAT3, DAT4, DAT5, DAT6, DAT7, LAST
  5215. + .endif
  5216. + subs N, N, #32
  5217. + bhs 110b
  5218. + /* Just before the final (prefetch_distance+1) 32-byte blocks, deal with final preloads */
  5219. + preload_trailing backwards, S, N, OFF
  5220. + add N, N, #(prefetch_distance+2)*32 - 32
  5221. +120:
  5222. + .if align == 0
  5223. + .if backwards
  5224. + ldmdb S!, {DAT0, DAT1, DAT2, DAT3, DAT4, DAT5, DAT6, LAST}
  5225. + stmdb D!, {DAT4, DAT5, DAT6, LAST}
  5226. + stmdb D!, {DAT0, DAT1, DAT2, DAT3}
  5227. + .else
  5228. + ldmia S!, {DAT0, DAT1, DAT2, DAT3, DAT4, DAT5, DAT6, LAST}
  5229. + stmia D!, {DAT0, DAT1, DAT2, DAT3}
  5230. + stmia D!, {DAT4, DAT5, DAT6, LAST}
  5231. + .endif
  5232. + .else
  5233. + unaligned_words backwards, align, 0, 8, DAT0, DAT1, DAT2, DAT3, DAT4, DAT5, DAT6, DAT7, LAST
  5234. + .endif
  5235. + subs N, N, #32
  5236. + bhs 120b
  5237. + tst N, #16
  5238. + .if align == 0
  5239. + .if backwards
  5240. + ldmnedb S!, {DAT0, DAT1, DAT2, LAST}
  5241. + stmnedb D!, {DAT0, DAT1, DAT2, LAST}
  5242. + .else
  5243. + ldmneia S!, {DAT0, DAT1, DAT2, LAST}
  5244. + stmneia D!, {DAT0, DAT1, DAT2, LAST}
  5245. + .endif
  5246. + .else
  5247. + beq 130f
  5248. + unaligned_words backwards, align, 0, 4, DAT0, DAT1, DAT2, DAT3, LAST
  5249. +130:
  5250. + .endif
  5251. + /* Trailing words and bytes */
  5252. + tst N, #15
  5253. + beq 199f
  5254. + .if align != 0
  5255. + add S, S, #align
  5256. + .endif
  5257. + memcpy_trailing_15bytes backwards, align
  5258. +199:
  5259. + pop {DAT3, DAT4, DAT5, DAT6, DAT7}
  5260. + pop {D, DAT1, DAT2, pc}
  5261. +.endm
  5262. +
  5263. +.macro memcpy_medium_inner_loop backwards, align
  5264. +120:
  5265. + .if backwards
  5266. + .if align == 0
  5267. + ldmdb S!, {DAT0, DAT1, DAT2, LAST}
  5268. + .else
  5269. + ldr LAST, [S, #-4]!
  5270. + ldr DAT2, [S, #-4]!
  5271. + ldr DAT1, [S, #-4]!
  5272. + ldr DAT0, [S, #-4]!
  5273. + .endif
  5274. + stmdb D!, {DAT0, DAT1, DAT2, LAST}
  5275. + .else
  5276. + .if align == 0
  5277. + ldmia S!, {DAT0, DAT1, DAT2, LAST}
  5278. + .else
  5279. + ldr DAT0, [S], #4
  5280. + ldr DAT1, [S], #4
  5281. + ldr DAT2, [S], #4
  5282. + ldr LAST, [S], #4
  5283. + .endif
  5284. + stmia D!, {DAT0, DAT1, DAT2, LAST}
  5285. + .endif
  5286. + subs N, N, #16
  5287. + bhs 120b
  5288. + /* Trailing words and bytes */
  5289. + tst N, #15
  5290. + beq 199f
  5291. + memcpy_trailing_15bytes backwards, align
  5292. +199:
  5293. + pop {D, DAT1, DAT2, pc}
  5294. +.endm
  5295. +
  5296. +.macro memcpy_short_inner_loop backwards, align
  5297. + tst N, #16
  5298. + .if backwards
  5299. + .if align == 0
  5300. + ldmnedb S!, {DAT0, DAT1, DAT2, LAST}
  5301. + .else
  5302. + ldrne LAST, [S, #-4]!
  5303. + ldrne DAT2, [S, #-4]!
  5304. + ldrne DAT1, [S, #-4]!
  5305. + ldrne DAT0, [S, #-4]!
  5306. + .endif
  5307. + stmnedb D!, {DAT0, DAT1, DAT2, LAST}
  5308. + .else
  5309. + .if align == 0
  5310. + ldmneia S!, {DAT0, DAT1, DAT2, LAST}
  5311. + .else
  5312. + ldrne DAT0, [S], #4
  5313. + ldrne DAT1, [S], #4
  5314. + ldrne DAT2, [S], #4
  5315. + ldrne LAST, [S], #4
  5316. + .endif
  5317. + stmneia D!, {DAT0, DAT1, DAT2, LAST}
  5318. + .endif
  5319. + memcpy_trailing_15bytes backwards, align
  5320. +199:
  5321. + pop {D, DAT1, DAT2, pc}
  5322. +.endm
  5323. +
  5324. +.macro memcpy backwards
  5325. + D .req a1
  5326. + S .req a2
  5327. + N .req a3
  5328. + DAT0 .req a4
  5329. + DAT1 .req v1
  5330. + DAT2 .req v2
  5331. + DAT3 .req v3
  5332. + DAT4 .req v4
  5333. + DAT5 .req v5
  5334. + DAT6 .req v6
  5335. + DAT7 .req sl
  5336. + LAST .req ip
  5337. + OFF .req lr
  5338. +
  5339. + .cfi_startproc
  5340. +
  5341. + push {D, DAT1, DAT2, lr}
  5342. +
  5343. + .cfi_def_cfa_offset 16
  5344. + .cfi_rel_offset D, 0
  5345. + .cfi_undefined S
  5346. + .cfi_undefined N
  5347. + .cfi_undefined DAT0
  5348. + .cfi_rel_offset DAT1, 4
  5349. + .cfi_rel_offset DAT2, 8
  5350. + .cfi_undefined LAST
  5351. + .cfi_rel_offset lr, 12
  5352. +
  5353. + .if backwards
  5354. + add D, D, N
  5355. + add S, S, N
  5356. + .endif
  5357. +
  5358. + /* See if we're guaranteed to have at least one 16-byte aligned 16-byte write */
  5359. + cmp N, #31
  5360. + blo 170f
  5361. + /* To preload ahead as we go, we need at least (prefetch_distance+2) 32-byte blocks */
  5362. + cmp N, #(prefetch_distance+3)*32 - 1
  5363. + blo 160f
  5364. +
  5365. + /* Long case */
  5366. + push {DAT3, DAT4, DAT5, DAT6, DAT7}
  5367. +
  5368. + .cfi_def_cfa_offset 36
  5369. + .cfi_rel_offset D, 20
  5370. + .cfi_rel_offset DAT1, 24
  5371. + .cfi_rel_offset DAT2, 28
  5372. + .cfi_rel_offset DAT3, 0
  5373. + .cfi_rel_offset DAT4, 4
  5374. + .cfi_rel_offset DAT5, 8
  5375. + .cfi_rel_offset DAT6, 12
  5376. + .cfi_rel_offset DAT7, 16
  5377. + .cfi_rel_offset lr, 32
  5378. +
  5379. + /* Adjust N so that the decrement instruction can also test for
  5380. + * inner loop termination. We want it to stop when there are
  5381. + * (prefetch_distance+1) complete blocks to go. */
  5382. + sub N, N, #(prefetch_distance+2)*32
  5383. + preload_leading_step1 backwards, DAT0, S
  5384. + .if backwards
  5385. + /* Bug in GAS: it accepts, but mis-assembles the instruction
  5386. + * ands DAT2, D, #60, 2
  5387. + * which sets DAT2 to the number of leading bytes until destination is aligned and also clears C (sets borrow)
  5388. + */
  5389. + .word 0xE210513C
  5390. + beq 154f
  5391. + .else
  5392. + ands DAT2, D, #15
  5393. + beq 154f
  5394. + rsb DAT2, DAT2, #16 /* number of leading bytes until destination aligned */
  5395. + .endif
  5396. + preload_leading_step2 backwards, DAT0, S, DAT2, OFF
  5397. + memcpy_leading_15bytes backwards, 1
  5398. +154: /* Destination now 16-byte aligned; we have at least one prefetch as well as at least one 16-byte output block */
  5399. + /* 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 */
  5400. + .if backwards
  5401. + rsb OFF, S, #3
  5402. + and OFF, OFF, #28
  5403. + sub OFF, OFF, #32*(prefetch_distance+1)
  5404. + .else
  5405. + and OFF, S, #28
  5406. + rsb OFF, OFF, #32*prefetch_distance
  5407. + .endif
  5408. + movs DAT0, S, lsl #31
  5409. + bhi 157f
  5410. + bcs 156f
  5411. + bmi 155f
  5412. + memcpy_long_inner_loop backwards, 0
  5413. +155: memcpy_long_inner_loop backwards, 1
  5414. +156: memcpy_long_inner_loop backwards, 2
  5415. +157: memcpy_long_inner_loop backwards, 3
  5416. +
  5417. + .cfi_def_cfa_offset 16
  5418. + .cfi_rel_offset D, 0
  5419. + .cfi_rel_offset DAT1, 4
  5420. + .cfi_rel_offset DAT2, 8
  5421. + .cfi_same_value DAT3
  5422. + .cfi_same_value DAT4
  5423. + .cfi_same_value DAT5
  5424. + .cfi_same_value DAT6
  5425. + .cfi_same_value DAT7
  5426. + .cfi_rel_offset lr, 12
  5427. +
  5428. +160: /* Medium case */
  5429. + preload_all backwards, 0, 0, S, N, DAT2, OFF
  5430. + sub N, N, #16 /* simplifies inner loop termination */
  5431. + .if backwards
  5432. + ands DAT2, D, #15
  5433. + beq 164f
  5434. + .else
  5435. + ands DAT2, D, #15
  5436. + beq 164f
  5437. + rsb DAT2, DAT2, #16
  5438. + .endif
  5439. + memcpy_leading_15bytes backwards, align
  5440. +164: /* Destination now 16-byte aligned; we have at least one 16-byte output block */
  5441. + tst S, #3
  5442. + bne 140f
  5443. + memcpy_medium_inner_loop backwards, 0
  5444. +140: memcpy_medium_inner_loop backwards, 1
  5445. +
  5446. +170: /* Short case, less than 31 bytes, so no guarantee of at least one 16-byte block */
  5447. + teq N, #0
  5448. + beq 199f
  5449. + preload_all backwards, 1, 0, S, N, DAT2, LAST
  5450. + tst D, #3
  5451. + beq 174f
  5452. +172: subs N, N, #1
  5453. + blo 199f
  5454. + .if backwards
  5455. + ldrb DAT0, [S, #-1]!
  5456. + strb DAT0, [D, #-1]!
  5457. + .else
  5458. + ldrb DAT0, [S], #1
  5459. + strb DAT0, [D], #1
  5460. + .endif
  5461. + tst D, #3
  5462. + bne 172b
  5463. +174: /* Destination now 4-byte aligned; we have 0 or more output bytes to go */
  5464. + tst S, #3
  5465. + bne 140f
  5466. + memcpy_short_inner_loop backwards, 0
  5467. +140: memcpy_short_inner_loop backwards, 1
  5468. +
  5469. + .cfi_endproc
  5470. +
  5471. + .unreq D
  5472. + .unreq S
  5473. + .unreq N
  5474. + .unreq DAT0
  5475. + .unreq DAT1
  5476. + .unreq DAT2
  5477. + .unreq DAT3
  5478. + .unreq DAT4
  5479. + .unreq DAT5
  5480. + .unreq DAT6
  5481. + .unreq DAT7
  5482. + .unreq LAST
  5483. + .unreq OFF
  5484. +.endm
  5485. diff -Nur linux-3.18.8/arch/arm/lib/memcpy_rpi.S linux-rpi/arch/arm/lib/memcpy_rpi.S
  5486. --- linux-3.18.8/arch/arm/lib/memcpy_rpi.S 1970-01-01 01:00:00.000000000 +0100
  5487. +++ linux-rpi/arch/arm/lib/memcpy_rpi.S 2015-03-05 14:40:11.145715839 +0100
  5488. @@ -0,0 +1,59 @@
  5489. +/*
  5490. +Copyright (c) 2013, Raspberry Pi Foundation
  5491. +Copyright (c) 2013, RISC OS Open Ltd
  5492. +All rights reserved.
  5493. +
  5494. +Redistribution and use in source and binary forms, with or without
  5495. +modification, are permitted provided that the following conditions are met:
  5496. + * Redistributions of source code must retain the above copyright
  5497. + notice, this list of conditions and the following disclaimer.
  5498. + * Redistributions in binary form must reproduce the above copyright
  5499. + notice, this list of conditions and the following disclaimer in the
  5500. + documentation and/or other materials provided with the distribution.
  5501. + * Neither the name of the copyright holder nor the
  5502. + names of its contributors may be used to endorse or promote products
  5503. + derived from this software without specific prior written permission.
  5504. +
  5505. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  5506. +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  5507. +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  5508. +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
  5509. +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  5510. +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  5511. +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  5512. +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  5513. +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  5514. +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  5515. +*/
  5516. +
  5517. +#include <linux/linkage.h>
  5518. +#include "arm-mem.h"
  5519. +#include "memcpymove.h"
  5520. +
  5521. +/* Prevent the stack from becoming executable */
  5522. +#if defined(__linux__) && defined(__ELF__)
  5523. +.section .note.GNU-stack,"",%progbits
  5524. +#endif
  5525. +
  5526. + .text
  5527. + .arch armv6
  5528. + .object_arch armv4
  5529. + .arm
  5530. + .altmacro
  5531. + .p2align 2
  5532. +
  5533. +/*
  5534. + * void *memcpy(void * restrict s1, const void * restrict s2, size_t n);
  5535. + * On entry:
  5536. + * a1 = pointer to destination
  5537. + * a2 = pointer to source
  5538. + * a3 = number of bytes to copy
  5539. + * On exit:
  5540. + * a1 preserved
  5541. + */
  5542. +
  5543. +.set prefetch_distance, 3
  5544. +
  5545. +ENTRY(memcpy)
  5546. + memcpy 0
  5547. +ENDPROC(memcpy)
  5548. diff -Nur linux-3.18.8/arch/arm/lib/memmove_rpi.S linux-rpi/arch/arm/lib/memmove_rpi.S
  5549. --- linux-3.18.8/arch/arm/lib/memmove_rpi.S 1970-01-01 01:00:00.000000000 +0100
  5550. +++ linux-rpi/arch/arm/lib/memmove_rpi.S 2015-03-05 14:40:11.145715839 +0100
  5551. @@ -0,0 +1,61 @@
  5552. +/*
  5553. +Copyright (c) 2013, Raspberry Pi Foundation
  5554. +Copyright (c) 2013, RISC OS Open Ltd
  5555. +All rights reserved.
  5556. +
  5557. +Redistribution and use in source and binary forms, with or without
  5558. +modification, are permitted provided that the following conditions are met:
  5559. + * Redistributions of source code must retain the above copyright
  5560. + notice, this list of conditions and the following disclaimer.
  5561. + * Redistributions in binary form must reproduce the above copyright
  5562. + notice, this list of conditions and the following disclaimer in the
  5563. + documentation and/or other materials provided with the distribution.
  5564. + * Neither the name of the copyright holder nor the
  5565. + names of its contributors may be used to endorse or promote products
  5566. + derived from this software without specific prior written permission.
  5567. +
  5568. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  5569. +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  5570. +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  5571. +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
  5572. +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  5573. +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  5574. +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  5575. +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  5576. +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  5577. +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  5578. +*/
  5579. +
  5580. +#include <linux/linkage.h>
  5581. +#include "arm-mem.h"
  5582. +#include "memcpymove.h"
  5583. +
  5584. +/* Prevent the stack from becoming executable */
  5585. +#if defined(__linux__) && defined(__ELF__)
  5586. +.section .note.GNU-stack,"",%progbits
  5587. +#endif
  5588. +
  5589. + .text
  5590. + .arch armv6
  5591. + .object_arch armv4
  5592. + .arm
  5593. + .altmacro
  5594. + .p2align 2
  5595. +
  5596. +/*
  5597. + * void *memmove(void *s1, const void *s2, size_t n);
  5598. + * On entry:
  5599. + * a1 = pointer to destination
  5600. + * a2 = pointer to source
  5601. + * a3 = number of bytes to copy
  5602. + * On exit:
  5603. + * a1 preserved
  5604. + */
  5605. +
  5606. +.set prefetch_distance, 3
  5607. +
  5608. +ENTRY(memmove)
  5609. + cmp a2, a1
  5610. + bpl memcpy /* pl works even over -1 - 0 and 0x7fffffff - 0x80000000 boundaries */
  5611. + memcpy 1
  5612. +ENDPROC(memmove)
  5613. diff -Nur linux-3.18.8/arch/arm/lib/memset_rpi.S linux-rpi/arch/arm/lib/memset_rpi.S
  5614. --- linux-3.18.8/arch/arm/lib/memset_rpi.S 1970-01-01 01:00:00.000000000 +0100
  5615. +++ linux-rpi/arch/arm/lib/memset_rpi.S 2015-03-05 14:40:11.145715839 +0100
  5616. @@ -0,0 +1,121 @@
  5617. +/*
  5618. +Copyright (c) 2013, Raspberry Pi Foundation
  5619. +Copyright (c) 2013, RISC OS Open Ltd
  5620. +All rights reserved.
  5621. +
  5622. +Redistribution and use in source and binary forms, with or without
  5623. +modification, are permitted provided that the following conditions are met:
  5624. + * Redistributions of source code must retain the above copyright
  5625. + notice, this list of conditions and the following disclaimer.
  5626. + * Redistributions in binary form must reproduce the above copyright
  5627. + notice, this list of conditions and the following disclaimer in the
  5628. + documentation and/or other materials provided with the distribution.
  5629. + * Neither the name of the copyright holder nor the
  5630. + names of its contributors may be used to endorse or promote products
  5631. + derived from this software without specific prior written permission.
  5632. +
  5633. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  5634. +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  5635. +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  5636. +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
  5637. +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  5638. +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  5639. +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  5640. +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  5641. +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  5642. +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  5643. +*/
  5644. +
  5645. +#include <linux/linkage.h>
  5646. +#include "arm-mem.h"
  5647. +
  5648. +/* Prevent the stack from becoming executable */
  5649. +#if defined(__linux__) && defined(__ELF__)
  5650. +.section .note.GNU-stack,"",%progbits
  5651. +#endif
  5652. +
  5653. + .text
  5654. + .arch armv6
  5655. + .object_arch armv4
  5656. + .arm
  5657. + .altmacro
  5658. + .p2align 2
  5659. +
  5660. +/*
  5661. + * void *memset(void *s, int c, size_t n);
  5662. + * On entry:
  5663. + * a1 = pointer to buffer to fill
  5664. + * a2 = byte pattern to fill with (caller-narrowed)
  5665. + * a3 = number of bytes to fill
  5666. + * On exit:
  5667. + * a1 preserved
  5668. + */
  5669. +ENTRY(memset)
  5670. + S .req a1
  5671. + DAT0 .req a2
  5672. + N .req a3
  5673. + DAT1 .req a4
  5674. + DAT2 .req ip
  5675. + DAT3 .req lr
  5676. +
  5677. + orr DAT0, DAT0, lsl #8
  5678. + push {S, lr}
  5679. + orr DAT0, DAT0, lsl #16
  5680. + mov DAT1, DAT0
  5681. +
  5682. + /* See if we're guaranteed to have at least one 16-byte aligned 16-byte write */
  5683. + cmp N, #31
  5684. + blo 170f
  5685. +
  5686. +161: sub N, N, #16 /* simplifies inner loop termination */
  5687. + /* Leading words and bytes */
  5688. + tst S, #15
  5689. + beq 164f
  5690. + rsb DAT3, S, #0 /* bits 0-3 = number of leading bytes until aligned */
  5691. + movs DAT2, DAT3, lsl #31
  5692. + submi N, N, #1
  5693. + strmib DAT0, [S], #1
  5694. + subcs N, N, #2
  5695. + strcsh DAT0, [S], #2
  5696. + movs DAT2, DAT3, lsl #29
  5697. + submi N, N, #4
  5698. + strmi DAT0, [S], #4
  5699. + subcs N, N, #8
  5700. + stmcsia S!, {DAT0, DAT1}
  5701. +164: /* Delayed set up of DAT2 and DAT3 so we could use them as scratch registers above */
  5702. + mov DAT2, DAT0
  5703. + mov DAT3, DAT0
  5704. + /* Now the inner loop of 16-byte stores */
  5705. +165: stmia S!, {DAT0, DAT1, DAT2, DAT3}
  5706. + subs N, N, #16
  5707. + bhs 165b
  5708. +166: /* Trailing words and bytes */
  5709. + movs N, N, lsl #29
  5710. + stmcsia S!, {DAT0, DAT1}
  5711. + strmi DAT0, [S], #4
  5712. + movs N, N, lsl #2
  5713. + strcsh DAT0, [S], #2
  5714. + strmib DAT0, [S]
  5715. +199: pop {S, pc}
  5716. +
  5717. +170: /* Short case */
  5718. + mov DAT2, DAT0
  5719. + mov DAT3, DAT0
  5720. + tst S, #3
  5721. + beq 174f
  5722. +172: subs N, N, #1
  5723. + blo 199b
  5724. + strb DAT0, [S], #1
  5725. + tst S, #3
  5726. + bne 172b
  5727. +174: tst N, #16
  5728. + stmneia S!, {DAT0, DAT1, DAT2, DAT3}
  5729. + b 166b
  5730. +
  5731. + .unreq S
  5732. + .unreq DAT0
  5733. + .unreq N
  5734. + .unreq DAT1
  5735. + .unreq DAT2
  5736. + .unreq DAT3
  5737. +ENDPROC(memset)
  5738. diff -Nur linux-3.18.8/arch/arm/lib/uaccess_with_memcpy.c linux-rpi/arch/arm/lib/uaccess_with_memcpy.c
  5739. --- linux-3.18.8/arch/arm/lib/uaccess_with_memcpy.c 2015-02-27 02:49:36.000000000 +0100
  5740. +++ linux-rpi/arch/arm/lib/uaccess_with_memcpy.c 2015-03-05 14:40:11.145715839 +0100
  5741. @@ -22,6 +22,14 @@
  5742. #include <asm/current.h>
  5743. #include <asm/page.h>
  5744. +#ifndef COPY_FROM_USER_THRESHOLD
  5745. +#define COPY_FROM_USER_THRESHOLD 64
  5746. +#endif
  5747. +
  5748. +#ifndef COPY_TO_USER_THRESHOLD
  5749. +#define COPY_TO_USER_THRESHOLD 64
  5750. +#endif
  5751. +
  5752. static int
  5753. pin_page_for_write(const void __user *_addr, pte_t **ptep, spinlock_t **ptlp)
  5754. {
  5755. @@ -85,7 +93,44 @@
  5756. return 1;
  5757. }
  5758. -static unsigned long noinline
  5759. +static int
  5760. +pin_page_for_read(const void __user *_addr, pte_t **ptep, spinlock_t **ptlp)
  5761. +{
  5762. + unsigned long addr = (unsigned long)_addr;
  5763. + pgd_t *pgd;
  5764. + pmd_t *pmd;
  5765. + pte_t *pte;
  5766. + pud_t *pud;
  5767. + spinlock_t *ptl;
  5768. +
  5769. + pgd = pgd_offset(current->mm, addr);
  5770. + if (unlikely(pgd_none(*pgd) || pgd_bad(*pgd)))
  5771. + {
  5772. + return 0;
  5773. + }
  5774. + pud = pud_offset(pgd, addr);
  5775. + if (unlikely(pud_none(*pud) || pud_bad(*pud)))
  5776. + {
  5777. + return 0;
  5778. + }
  5779. +
  5780. + pmd = pmd_offset(pud, addr);
  5781. + if (unlikely(pmd_none(*pmd) || pmd_bad(*pmd)))
  5782. + return 0;
  5783. +
  5784. + pte = pte_offset_map_lock(current->mm, pmd, addr, &ptl);
  5785. + if (unlikely(!pte_present(*pte) || !pte_young(*pte))) {
  5786. + pte_unmap_unlock(pte, ptl);
  5787. + return 0;
  5788. + }
  5789. +
  5790. + *ptep = pte;
  5791. + *ptlp = ptl;
  5792. +
  5793. + return 1;
  5794. +}
  5795. +
  5796. +unsigned long noinline
  5797. __copy_to_user_memcpy(void __user *to, const void *from, unsigned long n)
  5798. {
  5799. int atomic;
  5800. @@ -135,6 +180,54 @@
  5801. return n;
  5802. }
  5803. +unsigned long noinline
  5804. +__copy_from_user_memcpy(void *to, const void __user *from, unsigned long n)
  5805. +{
  5806. + int atomic;
  5807. +
  5808. + if (unlikely(segment_eq(get_fs(), KERNEL_DS))) {
  5809. + memcpy(to, (const void *)from, n);
  5810. + return 0;
  5811. + }
  5812. +
  5813. + /* the mmap semaphore is taken only if not in an atomic context */
  5814. + atomic = in_atomic();
  5815. +
  5816. + if (!atomic)
  5817. + down_read(&current->mm->mmap_sem);
  5818. + while (n) {
  5819. + pte_t *pte;
  5820. + spinlock_t *ptl;
  5821. + int tocopy;
  5822. +
  5823. + while (!pin_page_for_read(from, &pte, &ptl)) {
  5824. + char temp;
  5825. + if (!atomic)
  5826. + up_read(&current->mm->mmap_sem);
  5827. + if (__get_user(temp, (char __user *)from))
  5828. + goto out;
  5829. + if (!atomic)
  5830. + down_read(&current->mm->mmap_sem);
  5831. + }
  5832. +
  5833. + tocopy = (~(unsigned long)from & ~PAGE_MASK) + 1;
  5834. + if (tocopy > n)
  5835. + tocopy = n;
  5836. +
  5837. + memcpy(to, (const void *)from, tocopy);
  5838. + to += tocopy;
  5839. + from += tocopy;
  5840. + n -= tocopy;
  5841. +
  5842. + pte_unmap_unlock(pte, ptl);
  5843. + }
  5844. + if (!atomic)
  5845. + up_read(&current->mm->mmap_sem);
  5846. +
  5847. +out:
  5848. + return n;
  5849. +}
  5850. +
  5851. unsigned long
  5852. __copy_to_user(void __user *to, const void *from, unsigned long n)
  5853. {
  5854. @@ -145,10 +238,25 @@
  5855. * With frame pointer disabled, tail call optimization kicks in
  5856. * as well making this test almost invisible.
  5857. */
  5858. - if (n < 64)
  5859. + if (n < COPY_TO_USER_THRESHOLD)
  5860. return __copy_to_user_std(to, from, n);
  5861. return __copy_to_user_memcpy(to, from, n);
  5862. }
  5863. +
  5864. +unsigned long
  5865. +__copy_from_user(void *to, const void __user *from, unsigned long n)
  5866. +{
  5867. + /*
  5868. + * This test is stubbed out of the main function above to keep
  5869. + * the overhead for small copies low by avoiding a large
  5870. + * register dump on the stack just to reload them right away.
  5871. + * With frame pointer disabled, tail call optimization kicks in
  5872. + * as well making this test almost invisible.
  5873. + */
  5874. + if (n < COPY_FROM_USER_THRESHOLD)
  5875. + return __copy_from_user_std(to, from, n);
  5876. + return __copy_from_user_memcpy(to, from, n);
  5877. +}
  5878. static unsigned long noinline
  5879. __clear_user_memset(void __user *addr, unsigned long n)
  5880. diff -Nur linux-3.18.8/arch/arm/mach-bcm2708/armctrl.c linux-rpi/arch/arm/mach-bcm2708/armctrl.c
  5881. --- linux-3.18.8/arch/arm/mach-bcm2708/armctrl.c 1970-01-01 01:00:00.000000000 +0100
  5882. +++ linux-rpi/arch/arm/mach-bcm2708/armctrl.c 2015-03-05 14:40:11.153715839 +0100
  5883. @@ -0,0 +1,315 @@
  5884. +/*
  5885. + * linux/arch/arm/mach-bcm2708/armctrl.c
  5886. + *
  5887. + * Copyright (C) 2010 Broadcom
  5888. + *
  5889. + * This program is free software; you can redistribute it and/or modify
  5890. + * it under the terms of the GNU General Public License as published by
  5891. + * the Free Software Foundation; either version 2 of the License, or
  5892. + * (at your option) any later version.
  5893. + *
  5894. + * This program is distributed in the hope that it will be useful,
  5895. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  5896. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5897. + * GNU General Public License for more details.
  5898. + *
  5899. + * You should have received a copy of the GNU General Public License
  5900. + * along with this program; if not, write to the Free Software
  5901. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  5902. + */
  5903. +#include <linux/init.h>
  5904. +#include <linux/list.h>
  5905. +#include <linux/io.h>
  5906. +#include <linux/version.h>
  5907. +#include <linux/syscore_ops.h>
  5908. +#include <linux/interrupt.h>
  5909. +#include <linux/irqdomain.h>
  5910. +#include <linux/of.h>
  5911. +
  5912. +#include <asm/mach/irq.h>
  5913. +#include <mach/hardware.h>
  5914. +#include "armctrl.h"
  5915. +
  5916. +/* For support of kernels >= 3.0 assume only one VIC for now*/
  5917. +static unsigned int remap_irqs[(INTERRUPT_ARASANSDIO + 1) - INTERRUPT_JPEG] = {
  5918. + INTERRUPT_VC_JPEG,
  5919. + INTERRUPT_VC_USB,
  5920. + INTERRUPT_VC_3D,
  5921. + INTERRUPT_VC_DMA2,
  5922. + INTERRUPT_VC_DMA3,
  5923. + INTERRUPT_VC_I2C,
  5924. + INTERRUPT_VC_SPI,
  5925. + INTERRUPT_VC_I2SPCM,
  5926. + INTERRUPT_VC_SDIO,
  5927. + INTERRUPT_VC_UART,
  5928. + INTERRUPT_VC_ARASANSDIO
  5929. +};
  5930. +
  5931. +static void armctrl_mask_irq(struct irq_data *d)
  5932. +{
  5933. + static const unsigned int disables[4] = {
  5934. + ARM_IRQ_DIBL1,
  5935. + ARM_IRQ_DIBL2,
  5936. + ARM_IRQ_DIBL3,
  5937. + 0
  5938. + };
  5939. +
  5940. + if (d->irq >= FIQ_START) {
  5941. + writel(0, __io_address(ARM_IRQ_FAST));
  5942. + } else {
  5943. + unsigned int data = (unsigned int)irq_get_chip_data(d->irq);
  5944. + writel(1 << (data & 0x1f), __io_address(disables[(data >> 5) & 0x3]));
  5945. + }
  5946. +}
  5947. +
  5948. +static void armctrl_unmask_irq(struct irq_data *d)
  5949. +{
  5950. + static const unsigned int enables[4] = {
  5951. + ARM_IRQ_ENBL1,
  5952. + ARM_IRQ_ENBL2,
  5953. + ARM_IRQ_ENBL3,
  5954. + 0
  5955. + };
  5956. +
  5957. + if (d->irq >= FIQ_START) {
  5958. + unsigned int data =
  5959. + (unsigned int)irq_get_chip_data(d->irq) - FIQ_START;
  5960. + writel(0x80 | data, __io_address(ARM_IRQ_FAST));
  5961. + } else {
  5962. + unsigned int data = (unsigned int)irq_get_chip_data(d->irq);
  5963. + writel(1 << (data & 0x1f), __io_address(enables[(data >> 5) & 0x3]));
  5964. + }
  5965. +}
  5966. +
  5967. +#ifdef CONFIG_OF
  5968. +
  5969. +#define NR_IRQS_BANK0 21
  5970. +#define NR_BANKS 3
  5971. +#define IRQS_PER_BANK 32
  5972. +
  5973. +/* from drivers/irqchip/irq-bcm2835.c */
  5974. +static int armctrl_xlate(struct irq_domain *d, struct device_node *ctrlr,
  5975. + const u32 *intspec, unsigned int intsize,
  5976. + unsigned long *out_hwirq, unsigned int *out_type)
  5977. +{
  5978. + if (WARN_ON(intsize != 2))
  5979. + return -EINVAL;
  5980. +
  5981. + if (WARN_ON(intspec[0] >= NR_BANKS))
  5982. + return -EINVAL;
  5983. +
  5984. + if (WARN_ON(intspec[1] >= IRQS_PER_BANK))
  5985. + return -EINVAL;
  5986. +
  5987. + if (WARN_ON(intspec[0] == 0 && intspec[1] >= NR_IRQS_BANK0))
  5988. + return -EINVAL;
  5989. +
  5990. + if (intspec[0] == 0)
  5991. + *out_hwirq = ARM_IRQ0_BASE + intspec[1];
  5992. + else if (intspec[0] == 1)
  5993. + *out_hwirq = ARM_IRQ1_BASE + intspec[1];
  5994. + else
  5995. + *out_hwirq = ARM_IRQ2_BASE + intspec[1];
  5996. +
  5997. + /* reverse remap_irqs[] */
  5998. + switch (*out_hwirq) {
  5999. + case INTERRUPT_VC_JPEG:
  6000. + *out_hwirq = INTERRUPT_JPEG;
  6001. + break;
  6002. + case INTERRUPT_VC_USB:
  6003. + *out_hwirq = INTERRUPT_USB;
  6004. + break;
  6005. + case INTERRUPT_VC_3D:
  6006. + *out_hwirq = INTERRUPT_3D;
  6007. + break;
  6008. + case INTERRUPT_VC_DMA2:
  6009. + *out_hwirq = INTERRUPT_DMA2;
  6010. + break;
  6011. + case INTERRUPT_VC_DMA3:
  6012. + *out_hwirq = INTERRUPT_DMA3;
  6013. + break;
  6014. + case INTERRUPT_VC_I2C:
  6015. + *out_hwirq = INTERRUPT_I2C;
  6016. + break;
  6017. + case INTERRUPT_VC_SPI:
  6018. + *out_hwirq = INTERRUPT_SPI;
  6019. + break;
  6020. + case INTERRUPT_VC_I2SPCM:
  6021. + *out_hwirq = INTERRUPT_I2SPCM;
  6022. + break;
  6023. + case INTERRUPT_VC_SDIO:
  6024. + *out_hwirq = INTERRUPT_SDIO;
  6025. + break;
  6026. + case INTERRUPT_VC_UART:
  6027. + *out_hwirq = INTERRUPT_UART;
  6028. + break;
  6029. + case INTERRUPT_VC_ARASANSDIO:
  6030. + *out_hwirq = INTERRUPT_ARASANSDIO;
  6031. + break;
  6032. + }
  6033. +
  6034. + *out_type = IRQ_TYPE_NONE;
  6035. + return 0;
  6036. +}
  6037. +
  6038. +static struct irq_domain_ops armctrl_ops = {
  6039. + .xlate = armctrl_xlate
  6040. +};
  6041. +
  6042. +void __init armctrl_dt_init(void)
  6043. +{
  6044. + struct device_node *np;
  6045. + struct irq_domain *domain;
  6046. +
  6047. + np = of_find_compatible_node(NULL, NULL, "brcm,bcm2708-armctrl-ic");
  6048. + if (!np)
  6049. + return;
  6050. +
  6051. + domain = irq_domain_add_legacy(np, BCM2708_ALLOC_IRQS,
  6052. + IRQ_ARMCTRL_START, 0,
  6053. + &armctrl_ops, NULL);
  6054. + WARN_ON(!domain);
  6055. +}
  6056. +#else
  6057. +void __init armctrl_dt_init(void) { }
  6058. +#endif /* CONFIG_OF */
  6059. +
  6060. +#if defined(CONFIG_PM)
  6061. +
  6062. +/* for kernels 3.xx use the new syscore_ops apis but for older kernels use the sys dev class */
  6063. +
  6064. +/* Static defines
  6065. + * struct armctrl_device - VIC PM device (< 3.xx)
  6066. + * @sysdev: The system device which is registered. (< 3.xx)
  6067. + * @irq: The IRQ number for the base of the VIC.
  6068. + * @base: The register base for the VIC.
  6069. + * @resume_sources: A bitmask of interrupts for resume.
  6070. + * @resume_irqs: The IRQs enabled for resume.
  6071. + * @int_select: Save for VIC_INT_SELECT.
  6072. + * @int_enable: Save for VIC_INT_ENABLE.
  6073. + * @soft_int: Save for VIC_INT_SOFT.
  6074. + * @protect: Save for VIC_PROTECT.
  6075. + */
  6076. +struct armctrl_info {
  6077. + void __iomem *base;
  6078. + int irq;
  6079. + u32 resume_sources;
  6080. + u32 resume_irqs;
  6081. + u32 int_select;
  6082. + u32 int_enable;
  6083. + u32 soft_int;
  6084. + u32 protect;
  6085. +} armctrl;
  6086. +
  6087. +static int armctrl_suspend(void)
  6088. +{
  6089. + return 0;
  6090. +}
  6091. +
  6092. +static void armctrl_resume(void)
  6093. +{
  6094. + return;
  6095. +}
  6096. +
  6097. +/**
  6098. + * armctrl_pm_register - Register a VIC for later power management control
  6099. + * @base: The base address of the VIC.
  6100. + * @irq: The base IRQ for the VIC.
  6101. + * @resume_sources: bitmask of interrupts allowed for resume sources.
  6102. + *
  6103. + * For older kernels (< 3.xx) do -
  6104. + * Register the VIC with the system device tree so that it can be notified
  6105. + * of suspend and resume requests and ensure that the correct actions are
  6106. + * taken to re-instate the settings on resume.
  6107. + */
  6108. +static void __init armctrl_pm_register(void __iomem * base, unsigned int irq,
  6109. + u32 resume_sources)
  6110. +{
  6111. + armctrl.base = base;
  6112. + armctrl.resume_sources = resume_sources;
  6113. + armctrl.irq = irq;
  6114. +}
  6115. +
  6116. +static int armctrl_set_wake(struct irq_data *d, unsigned int on)
  6117. +{
  6118. + unsigned int off = d->irq & 31;
  6119. + u32 bit = 1 << off;
  6120. +
  6121. + if (!(bit & armctrl.resume_sources))
  6122. + return -EINVAL;
  6123. +
  6124. + if (on)
  6125. + armctrl.resume_irqs |= bit;
  6126. + else
  6127. + armctrl.resume_irqs &= ~bit;
  6128. +
  6129. + return 0;
  6130. +}
  6131. +
  6132. +#else
  6133. +static inline void armctrl_pm_register(void __iomem * base, unsigned int irq,
  6134. + u32 arg1)
  6135. +{
  6136. +}
  6137. +
  6138. +#define armctrl_suspend NULL
  6139. +#define armctrl_resume NULL
  6140. +#define armctrl_set_wake NULL
  6141. +#endif /* CONFIG_PM */
  6142. +
  6143. +static struct syscore_ops armctrl_syscore_ops = {
  6144. + .suspend = armctrl_suspend,
  6145. + .resume = armctrl_resume,
  6146. +};
  6147. +
  6148. +/**
  6149. + * armctrl_syscore_init - initicall to register VIC pm functions
  6150. + *
  6151. + * This is called via late_initcall() to register
  6152. + * the resources for the VICs due to the early
  6153. + * nature of the VIC's registration.
  6154. +*/
  6155. +static int __init armctrl_syscore_init(void)
  6156. +{
  6157. + register_syscore_ops(&armctrl_syscore_ops);
  6158. + return 0;
  6159. +}
  6160. +
  6161. +late_initcall(armctrl_syscore_init);
  6162. +
  6163. +static struct irq_chip armctrl_chip = {
  6164. + .name = "ARMCTRL",
  6165. + .irq_ack = NULL,
  6166. + .irq_mask = armctrl_mask_irq,
  6167. + .irq_unmask = armctrl_unmask_irq,
  6168. + .irq_set_wake = armctrl_set_wake,
  6169. +};
  6170. +
  6171. +/**
  6172. + * armctrl_init - initialise a vectored interrupt controller
  6173. + * @base: iomem base address
  6174. + * @irq_start: starting interrupt number, must be muliple of 32
  6175. + * @armctrl_sources: bitmask of interrupt sources to allow
  6176. + * @resume_sources: bitmask of interrupt sources to allow for resume
  6177. + */
  6178. +int __init armctrl_init(void __iomem * base, unsigned int irq_start,
  6179. + u32 armctrl_sources, u32 resume_sources)
  6180. +{
  6181. + unsigned int irq;
  6182. +
  6183. + for (irq = 0; irq < BCM2708_ALLOC_IRQS; irq++) {
  6184. + unsigned int data = irq;
  6185. + if (irq >= INTERRUPT_JPEG && irq <= INTERRUPT_ARASANSDIO)
  6186. + data = remap_irqs[irq - INTERRUPT_JPEG];
  6187. +
  6188. + irq_set_chip(irq, &armctrl_chip);
  6189. + irq_set_chip_data(irq, (void *)data);
  6190. + irq_set_handler(irq, handle_level_irq);
  6191. + set_irq_flags(irq, IRQF_VALID | IRQF_PROBE | IRQF_DISABLED);
  6192. + }
  6193. +
  6194. + armctrl_pm_register(base, irq_start, resume_sources);
  6195. + init_FIQ(FIQ_START);
  6196. + armctrl_dt_init();
  6197. + return 0;
  6198. +}
  6199. diff -Nur linux-3.18.8/arch/arm/mach-bcm2708/armctrl.h linux-rpi/arch/arm/mach-bcm2708/armctrl.h
  6200. --- linux-3.18.8/arch/arm/mach-bcm2708/armctrl.h 1970-01-01 01:00:00.000000000 +0100
  6201. +++ linux-rpi/arch/arm/mach-bcm2708/armctrl.h 2015-03-05 14:40:11.153715839 +0100
  6202. @@ -0,0 +1,27 @@
  6203. +/*
  6204. + * linux/arch/arm/mach-bcm2708/armctrl.h
  6205. + *
  6206. + * Copyright (C) 2010 Broadcom
  6207. + *
  6208. + * This program is free software; you can redistribute it and/or modify
  6209. + * it under the terms of the GNU General Public License as published by
  6210. + * the Free Software Foundation; either version 2 of the License, or
  6211. + * (at your option) any later version.
  6212. + *
  6213. + * This program is distributed in the hope that it will be useful,
  6214. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  6215. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  6216. + * GNU General Public License for more details.
  6217. + *
  6218. + * You should have received a copy of the GNU General Public License
  6219. + * along with this program; if not, write to the Free Software
  6220. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  6221. + */
  6222. +
  6223. +#ifndef __BCM2708_ARMCTRL_H
  6224. +#define __BCM2708_ARMCTRL_H
  6225. +
  6226. +extern int __init armctrl_init(void __iomem * base, unsigned int irq_start,
  6227. + u32 armctrl_sources, u32 resume_sources);
  6228. +
  6229. +#endif
  6230. diff -Nur linux-3.18.8/arch/arm/mach-bcm2708/bcm2708.c linux-rpi/arch/arm/mach-bcm2708/bcm2708.c
  6231. --- linux-3.18.8/arch/arm/mach-bcm2708/bcm2708.c 1970-01-01 01:00:00.000000000 +0100
  6232. +++ linux-rpi/arch/arm/mach-bcm2708/bcm2708.c 2015-03-05 14:40:11.153715839 +0100
  6233. @@ -0,0 +1,1132 @@
  6234. +/*
  6235. + * linux/arch/arm/mach-bcm2708/bcm2708.c
  6236. + *
  6237. + * Copyright (C) 2010 Broadcom
  6238. + *
  6239. + * This program is free software; you can redistribute it and/or modify
  6240. + * it under the terms of the GNU General Public License as published by
  6241. + * the Free Software Foundation; either version 2 of the License, or
  6242. + * (at your option) any later version.
  6243. + *
  6244. + * This program is distributed in the hope that it will be useful,
  6245. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  6246. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  6247. + * GNU General Public License for more details.
  6248. + *
  6249. + * You should have received a copy of the GNU General Public License
  6250. + * along with this program; if not, write to the Free Software
  6251. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  6252. + */
  6253. +
  6254. +#include <linux/init.h>
  6255. +#include <linux/device.h>
  6256. +#include <linux/dma-mapping.h>
  6257. +#include <linux/serial_8250.h>
  6258. +#include <linux/platform_device.h>
  6259. +#include <linux/syscore_ops.h>
  6260. +#include <linux/interrupt.h>
  6261. +#include <linux/amba/bus.h>
  6262. +#include <linux/amba/clcd.h>
  6263. +#include <linux/clk-provider.h>
  6264. +#include <linux/clkdev.h>
  6265. +#include <linux/clockchips.h>
  6266. +#include <linux/cnt32_to_63.h>
  6267. +#include <linux/io.h>
  6268. +#include <linux/module.h>
  6269. +#include <linux/of_platform.h>
  6270. +#include <linux/spi/spi.h>
  6271. +#include <linux/gpio/machine.h>
  6272. +#include <linux/w1-gpio.h>
  6273. +#include <linux/pps-gpio.h>
  6274. +
  6275. +#include <linux/version.h>
  6276. +#include <linux/clkdev.h>
  6277. +#include <asm/system_info.h>
  6278. +#include <mach/hardware.h>
  6279. +#include <asm/irq.h>
  6280. +#include <linux/leds.h>
  6281. +#include <asm/mach-types.h>
  6282. +#include <linux/sched_clock.h>
  6283. +
  6284. +#include <asm/mach/arch.h>
  6285. +#include <asm/mach/flash.h>
  6286. +#include <asm/mach/irq.h>
  6287. +#include <asm/mach/time.h>
  6288. +#include <asm/mach/map.h>
  6289. +
  6290. +#include <mach/timex.h>
  6291. +#include <mach/dma.h>
  6292. +#include <mach/vcio.h>
  6293. +#include <mach/system.h>
  6294. +
  6295. +#include <linux/delay.h>
  6296. +
  6297. +#include "bcm2708.h"
  6298. +#include "armctrl.h"
  6299. +
  6300. +#ifdef CONFIG_BCM_VC_CMA
  6301. +#include <linux/broadcom/vc_cma.h>
  6302. +#endif
  6303. +
  6304. +
  6305. +/* Effectively we have an IOMMU (ARM<->VideoCore map) that is set up to
  6306. + * give us IO access only to 64Mbytes of physical memory (26 bits). We could
  6307. + * represent this window by setting our dmamasks to 26 bits but, in fact
  6308. + * we're not going to use addresses outside this range (they're not in real
  6309. + * memory) so we don't bother.
  6310. + *
  6311. + * In the future we might include code to use this IOMMU to remap other
  6312. + * physical addresses onto VideoCore memory then the use of 32-bits would be
  6313. + * more legitimate.
  6314. + */
  6315. +#define DMA_MASK_BITS_COMMON 32
  6316. +
  6317. +// use GPIO 4 for the one-wire GPIO pin, if enabled
  6318. +#define W1_GPIO 4
  6319. +// ensure one-wire GPIO pullup is disabled by default
  6320. +#define W1_PULLUP -1
  6321. +
  6322. +/* command line parameters */
  6323. +static unsigned boardrev, serial;
  6324. +static unsigned uart_clock = UART0_CLOCK;
  6325. +static unsigned disk_led_gpio = 16;
  6326. +static unsigned disk_led_active_low = 1;
  6327. +static unsigned reboot_part = 0;
  6328. +static unsigned w1_gpio_pin = W1_GPIO;
  6329. +static unsigned w1_gpio_pullup = W1_PULLUP;
  6330. +static int pps_gpio_pin = -1;
  6331. +static bool vc_i2c_override = false;
  6332. +
  6333. +static unsigned use_dt = 0;
  6334. +
  6335. +static void __init bcm2708_init_led(void);
  6336. +
  6337. +void __init bcm2708_init_irq(void)
  6338. +{
  6339. + armctrl_init(__io_address(ARMCTRL_IC_BASE), 0, 0, 0);
  6340. +}
  6341. +
  6342. +static struct map_desc bcm2708_io_desc[] __initdata = {
  6343. + {
  6344. + .virtual = IO_ADDRESS(ARMCTRL_BASE),
  6345. + .pfn = __phys_to_pfn(ARMCTRL_BASE),
  6346. + .length = SZ_4K,
  6347. + .type = MT_DEVICE},
  6348. + {
  6349. + .virtual = IO_ADDRESS(UART0_BASE),
  6350. + .pfn = __phys_to_pfn(UART0_BASE),
  6351. + .length = SZ_4K,
  6352. + .type = MT_DEVICE},
  6353. + {
  6354. + .virtual = IO_ADDRESS(UART1_BASE),
  6355. + .pfn = __phys_to_pfn(UART1_BASE),
  6356. + .length = SZ_4K,
  6357. + .type = MT_DEVICE},
  6358. + {
  6359. + .virtual = IO_ADDRESS(DMA_BASE),
  6360. + .pfn = __phys_to_pfn(DMA_BASE),
  6361. + .length = SZ_4K,
  6362. + .type = MT_DEVICE},
  6363. + {
  6364. + .virtual = IO_ADDRESS(MCORE_BASE),
  6365. + .pfn = __phys_to_pfn(MCORE_BASE),
  6366. + .length = SZ_4K,
  6367. + .type = MT_DEVICE},
  6368. + {
  6369. + .virtual = IO_ADDRESS(ST_BASE),
  6370. + .pfn = __phys_to_pfn(ST_BASE),
  6371. + .length = SZ_4K,
  6372. + .type = MT_DEVICE},
  6373. + {
  6374. + .virtual = IO_ADDRESS(USB_BASE),
  6375. + .pfn = __phys_to_pfn(USB_BASE),
  6376. + .length = SZ_128K,
  6377. + .type = MT_DEVICE},
  6378. + {
  6379. + .virtual = IO_ADDRESS(PM_BASE),
  6380. + .pfn = __phys_to_pfn(PM_BASE),
  6381. + .length = SZ_4K,
  6382. + .type = MT_DEVICE},
  6383. + {
  6384. + .virtual = IO_ADDRESS(GPIO_BASE),
  6385. + .pfn = __phys_to_pfn(GPIO_BASE),
  6386. + .length = SZ_4K,
  6387. + .type = MT_DEVICE}
  6388. +};
  6389. +
  6390. +void __init bcm2708_map_io(void)
  6391. +{
  6392. + iotable_init(bcm2708_io_desc, ARRAY_SIZE(bcm2708_io_desc));
  6393. +}
  6394. +
  6395. +/* The STC is a free running counter that increments at the rate of 1MHz */
  6396. +#define STC_FREQ_HZ 1000000
  6397. +
  6398. +static inline uint32_t timer_read(void)
  6399. +{
  6400. + /* STC: a free running counter that increments at the rate of 1MHz */
  6401. + return readl(__io_address(ST_BASE + 0x04));
  6402. +}
  6403. +
  6404. +static unsigned long bcm2708_read_current_timer(void)
  6405. +{
  6406. + return timer_read();
  6407. +}
  6408. +
  6409. +static u64 notrace bcm2708_read_sched_clock(void)
  6410. +{
  6411. + return timer_read();
  6412. +}
  6413. +
  6414. +static cycle_t clksrc_read(struct clocksource *cs)
  6415. +{
  6416. + return timer_read();
  6417. +}
  6418. +
  6419. +static struct clocksource clocksource_stc = {
  6420. + .name = "stc",
  6421. + .rating = 300,
  6422. + .read = clksrc_read,
  6423. + .mask = CLOCKSOURCE_MASK(32),
  6424. + .flags = CLOCK_SOURCE_IS_CONTINUOUS,
  6425. +};
  6426. +
  6427. +unsigned long frc_clock_ticks32(void)
  6428. +{
  6429. + return timer_read();
  6430. +}
  6431. +
  6432. +static void __init bcm2708_clocksource_init(void)
  6433. +{
  6434. + if (clocksource_register_hz(&clocksource_stc, STC_FREQ_HZ)) {
  6435. + printk(KERN_ERR "timer: failed to initialize clock "
  6436. + "source %s\n", clocksource_stc.name);
  6437. + }
  6438. +}
  6439. +
  6440. +struct clk __init *bcm2708_clk_register(const char *name, unsigned long fixed_rate)
  6441. +{
  6442. + struct clk *clk;
  6443. +
  6444. + clk = clk_register_fixed_rate(NULL, name, NULL, CLK_IS_ROOT,
  6445. + fixed_rate);
  6446. + if (IS_ERR(clk))
  6447. + pr_err("%s not registered\n", name);
  6448. +
  6449. + return clk;
  6450. +}
  6451. +
  6452. +void __init bcm2708_register_clkdev(struct clk *clk, const char *name)
  6453. +{
  6454. + int ret;
  6455. +
  6456. + ret = clk_register_clkdev(clk, NULL, name);
  6457. + if (ret)
  6458. + pr_err("%s alias not registered\n", name);
  6459. +}
  6460. +
  6461. +void __init bcm2708_init_clocks(void)
  6462. +{
  6463. + struct clk *clk;
  6464. +
  6465. + clk = bcm2708_clk_register("uart0_clk", uart_clock);
  6466. + bcm2708_register_clkdev(clk, "dev:f1");
  6467. +
  6468. + clk = bcm2708_clk_register("sdhost_clk", 250000000);
  6469. + bcm2708_register_clkdev(clk, "bcm2708_spi.0");
  6470. + bcm2708_register_clkdev(clk, "bcm2708_i2c.0");
  6471. + bcm2708_register_clkdev(clk, "bcm2708_i2c.1");
  6472. +}
  6473. +
  6474. +#define UART0_IRQ { IRQ_UART, 0 /*NO_IRQ*/ }
  6475. +#define UART0_DMA { 15, 14 }
  6476. +
  6477. +AMBA_DEVICE(uart0, "dev:f1", UART0, NULL);
  6478. +
  6479. +static struct amba_device *amba_devs[] __initdata = {
  6480. + &uart0_device,
  6481. +};
  6482. +
  6483. +static struct resource bcm2708_dmaman_resources[] = {
  6484. + {
  6485. + .start = DMA_BASE,
  6486. + .end = DMA_BASE + SZ_4K - 1,
  6487. + .flags = IORESOURCE_MEM,
  6488. + }
  6489. +};
  6490. +
  6491. +static struct platform_device bcm2708_dmaman_device = {
  6492. + .name = BCM_DMAMAN_DRIVER_NAME,
  6493. + .id = 0, /* first bcm2708_dma */
  6494. + .resource = bcm2708_dmaman_resources,
  6495. + .num_resources = ARRAY_SIZE(bcm2708_dmaman_resources),
  6496. +};
  6497. +
  6498. +#if defined(CONFIG_W1_MASTER_GPIO) || defined(CONFIG_W1_MASTER_GPIO_MODULE)
  6499. +static struct w1_gpio_platform_data w1_gpio_pdata = {
  6500. + .pin = W1_GPIO,
  6501. + .ext_pullup_enable_pin = W1_PULLUP,
  6502. + .is_open_drain = 0,
  6503. +};
  6504. +
  6505. +static struct platform_device w1_device = {
  6506. + .name = "w1-gpio",
  6507. + .id = -1,
  6508. + .dev.platform_data = &w1_gpio_pdata,
  6509. +};
  6510. +#endif
  6511. +
  6512. +static struct pps_gpio_platform_data pps_gpio_info = {
  6513. + .assert_falling_edge = false,
  6514. + .capture_clear = false,
  6515. + .gpio_pin = -1,
  6516. + .gpio_label = "PPS",
  6517. +};
  6518. +
  6519. +static struct platform_device pps_gpio_device = {
  6520. + .name = "pps-gpio",
  6521. + .id = PLATFORM_DEVID_NONE,
  6522. + .dev.platform_data = &pps_gpio_info,
  6523. +};
  6524. +
  6525. +static u64 fb_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  6526. +
  6527. +static struct platform_device bcm2708_fb_device = {
  6528. + .name = "bcm2708_fb",
  6529. + .id = -1, /* only one bcm2708_fb */
  6530. + .resource = NULL,
  6531. + .num_resources = 0,
  6532. + .dev = {
  6533. + .dma_mask = &fb_dmamask,
  6534. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON),
  6535. + },
  6536. +};
  6537. +
  6538. +static struct plat_serial8250_port bcm2708_uart1_platform_data[] = {
  6539. + {
  6540. + .mapbase = UART1_BASE + 0x40,
  6541. + .irq = IRQ_AUX,
  6542. + .uartclk = 125000000,
  6543. + .regshift = 2,
  6544. + .iotype = UPIO_MEM,
  6545. + .flags = UPF_FIXED_TYPE | UPF_IOREMAP | UPF_SKIP_TEST,
  6546. + .type = PORT_8250,
  6547. + },
  6548. + {},
  6549. +};
  6550. +
  6551. +static struct platform_device bcm2708_uart1_device = {
  6552. + .name = "serial8250",
  6553. + .id = PLAT8250_DEV_PLATFORM,
  6554. + .dev = {
  6555. + .platform_data = bcm2708_uart1_platform_data,
  6556. + },
  6557. +};
  6558. +
  6559. +static struct resource bcm2708_usb_resources[] = {
  6560. + [0] = {
  6561. + .start = USB_BASE,
  6562. + .end = USB_BASE + SZ_128K - 1,
  6563. + .flags = IORESOURCE_MEM,
  6564. + },
  6565. + [1] = {
  6566. + .start = MPHI_BASE,
  6567. + .end = MPHI_BASE + SZ_4K - 1,
  6568. + .flags = IORESOURCE_MEM,
  6569. + },
  6570. + [2] = {
  6571. + .start = IRQ_HOSTPORT,
  6572. + .end = IRQ_HOSTPORT,
  6573. + .flags = IORESOURCE_IRQ,
  6574. + },
  6575. + [3] = {
  6576. + .start = IRQ_USB,
  6577. + .end = IRQ_USB,
  6578. + .flags = IORESOURCE_IRQ,
  6579. + },
  6580. +};
  6581. +
  6582. +
  6583. +static u64 usb_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  6584. +
  6585. +static struct platform_device bcm2708_usb_device = {
  6586. + .name = "bcm2708_usb",
  6587. + .id = -1, /* only one bcm2708_usb */
  6588. + .resource = bcm2708_usb_resources,
  6589. + .num_resources = ARRAY_SIZE(bcm2708_usb_resources),
  6590. + .dev = {
  6591. + .dma_mask = &usb_dmamask,
  6592. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON),
  6593. + },
  6594. +};
  6595. +
  6596. +static struct resource bcm2708_vcio_resources[] = {
  6597. + [0] = { /* mailbox/semaphore/doorbell access */
  6598. + .start = MCORE_BASE,
  6599. + .end = MCORE_BASE + SZ_4K - 1,
  6600. + .flags = IORESOURCE_MEM,
  6601. + },
  6602. +};
  6603. +
  6604. +static u64 vcio_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  6605. +
  6606. +static struct platform_device bcm2708_vcio_device = {
  6607. + .name = BCM_VCIO_DRIVER_NAME,
  6608. + .id = -1, /* only one VideoCore I/O area */
  6609. + .resource = bcm2708_vcio_resources,
  6610. + .num_resources = ARRAY_SIZE(bcm2708_vcio_resources),
  6611. + .dev = {
  6612. + .dma_mask = &vcio_dmamask,
  6613. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON),
  6614. + },
  6615. +};
  6616. +
  6617. +#ifdef CONFIG_BCM2708_GPIO
  6618. +#define BCM_GPIO_DRIVER_NAME "bcm2708_gpio"
  6619. +
  6620. +static struct resource bcm2708_gpio_resources[] = {
  6621. + [0] = { /* general purpose I/O */
  6622. + .start = GPIO_BASE,
  6623. + .end = GPIO_BASE + SZ_4K - 1,
  6624. + .flags = IORESOURCE_MEM,
  6625. + },
  6626. +};
  6627. +
  6628. +static u64 gpio_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  6629. +
  6630. +static struct platform_device bcm2708_gpio_device = {
  6631. + .name = BCM_GPIO_DRIVER_NAME,
  6632. + .id = -1, /* only one VideoCore I/O area */
  6633. + .resource = bcm2708_gpio_resources,
  6634. + .num_resources = ARRAY_SIZE(bcm2708_gpio_resources),
  6635. + .dev = {
  6636. + .dma_mask = &gpio_dmamask,
  6637. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON),
  6638. + },
  6639. +};
  6640. +#endif
  6641. +
  6642. +static struct resource bcm2708_systemtimer_resources[] = {
  6643. + [0] = { /* system timer access */
  6644. + .start = ST_BASE,
  6645. + .end = ST_BASE + SZ_4K - 1,
  6646. + .flags = IORESOURCE_MEM,
  6647. + },
  6648. + {
  6649. + .start = IRQ_TIMER3,
  6650. + .end = IRQ_TIMER3,
  6651. + .flags = IORESOURCE_IRQ,
  6652. + }
  6653. +
  6654. +};
  6655. +
  6656. +static u64 systemtimer_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  6657. +
  6658. +static struct platform_device bcm2708_systemtimer_device = {
  6659. + .name = "bcm2708_systemtimer",
  6660. + .id = -1, /* only one VideoCore I/O area */
  6661. + .resource = bcm2708_systemtimer_resources,
  6662. + .num_resources = ARRAY_SIZE(bcm2708_systemtimer_resources),
  6663. + .dev = {
  6664. + .dma_mask = &systemtimer_dmamask,
  6665. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON),
  6666. + },
  6667. +};
  6668. +
  6669. +#ifdef CONFIG_MMC_BCM2835 /* Arasan emmc SD (new) */
  6670. +static struct resource bcm2835_emmc_resources[] = {
  6671. + [0] = {
  6672. + .start = EMMC_BASE,
  6673. + .end = EMMC_BASE + SZ_256 - 1, /* we only need this area */
  6674. + /* the memory map actually makes SZ_4K available */
  6675. + .flags = IORESOURCE_MEM,
  6676. + },
  6677. + [1] = {
  6678. + .start = IRQ_ARASANSDIO,
  6679. + .end = IRQ_ARASANSDIO,
  6680. + .flags = IORESOURCE_IRQ,
  6681. + },
  6682. +};
  6683. +
  6684. +static u64 bcm2835_emmc_dmamask = 0xffffffffUL;
  6685. +
  6686. +struct platform_device bcm2835_emmc_device = {
  6687. + .name = "mmc-bcm2835",
  6688. + .id = 0,
  6689. + .num_resources = ARRAY_SIZE(bcm2835_emmc_resources),
  6690. + .resource = bcm2835_emmc_resources,
  6691. + .dev = {
  6692. + .dma_mask = &bcm2835_emmc_dmamask,
  6693. + .coherent_dma_mask = 0xffffffffUL},
  6694. +};
  6695. +#endif /* CONFIG_MMC_BCM2835 */
  6696. +
  6697. +static struct resource bcm2708_powerman_resources[] = {
  6698. + [0] = {
  6699. + .start = PM_BASE,
  6700. + .end = PM_BASE + SZ_256 - 1,
  6701. + .flags = IORESOURCE_MEM,
  6702. + },
  6703. +};
  6704. +
  6705. +static u64 powerman_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  6706. +
  6707. +struct platform_device bcm2708_powerman_device = {
  6708. + .name = "bcm2708_powerman",
  6709. + .id = 0,
  6710. + .num_resources = ARRAY_SIZE(bcm2708_powerman_resources),
  6711. + .resource = bcm2708_powerman_resources,
  6712. + .dev = {
  6713. + .dma_mask = &powerman_dmamask,
  6714. + .coherent_dma_mask = 0xffffffffUL},
  6715. +};
  6716. +
  6717. +
  6718. +static struct platform_device bcm2708_alsa_devices[] = {
  6719. + [0] = {
  6720. + .name = "bcm2835_AUD0",
  6721. + .id = 0, /* first audio device */
  6722. + .resource = 0,
  6723. + .num_resources = 0,
  6724. + },
  6725. + [1] = {
  6726. + .name = "bcm2835_AUD1",
  6727. + .id = 1, /* second audio device */
  6728. + .resource = 0,
  6729. + .num_resources = 0,
  6730. + },
  6731. + [2] = {
  6732. + .name = "bcm2835_AUD2",
  6733. + .id = 2, /* third audio device */
  6734. + .resource = 0,
  6735. + .num_resources = 0,
  6736. + },
  6737. + [3] = {
  6738. + .name = "bcm2835_AUD3",
  6739. + .id = 3, /* forth audio device */
  6740. + .resource = 0,
  6741. + .num_resources = 0,
  6742. + },
  6743. + [4] = {
  6744. + .name = "bcm2835_AUD4",
  6745. + .id = 4, /* fifth audio device */
  6746. + .resource = 0,
  6747. + .num_resources = 0,
  6748. + },
  6749. + [5] = {
  6750. + .name = "bcm2835_AUD5",
  6751. + .id = 5, /* sixth audio device */
  6752. + .resource = 0,
  6753. + .num_resources = 0,
  6754. + },
  6755. + [6] = {
  6756. + .name = "bcm2835_AUD6",
  6757. + .id = 6, /* seventh audio device */
  6758. + .resource = 0,
  6759. + .num_resources = 0,
  6760. + },
  6761. + [7] = {
  6762. + .name = "bcm2835_AUD7",
  6763. + .id = 7, /* eighth audio device */
  6764. + .resource = 0,
  6765. + .num_resources = 0,
  6766. + },
  6767. +};
  6768. +
  6769. +static struct resource bcm2708_spi_resources[] = {
  6770. + {
  6771. + .start = SPI0_BASE,
  6772. + .end = SPI0_BASE + SZ_256 - 1,
  6773. + .flags = IORESOURCE_MEM,
  6774. + }, {
  6775. + .start = IRQ_SPI,
  6776. + .end = IRQ_SPI,
  6777. + .flags = IORESOURCE_IRQ,
  6778. + }
  6779. +};
  6780. +
  6781. +
  6782. +static u64 bcm2708_spi_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  6783. +static struct platform_device bcm2708_spi_device = {
  6784. + .name = "bcm2708_spi",
  6785. + .id = 0,
  6786. + .num_resources = ARRAY_SIZE(bcm2708_spi_resources),
  6787. + .resource = bcm2708_spi_resources,
  6788. + .dev = {
  6789. + .dma_mask = &bcm2708_spi_dmamask,
  6790. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON)},
  6791. +};
  6792. +
  6793. +#ifdef CONFIG_BCM2708_SPIDEV
  6794. +static struct spi_board_info bcm2708_spi_devices[] = {
  6795. +#ifdef CONFIG_SPI_SPIDEV
  6796. + {
  6797. + .modalias = "spidev",
  6798. + .max_speed_hz = 500000,
  6799. + .bus_num = 0,
  6800. + .chip_select = 0,
  6801. + .mode = SPI_MODE_0,
  6802. + }, {
  6803. + .modalias = "spidev",
  6804. + .max_speed_hz = 500000,
  6805. + .bus_num = 0,
  6806. + .chip_select = 1,
  6807. + .mode = SPI_MODE_0,
  6808. + }
  6809. +#endif
  6810. +};
  6811. +#endif
  6812. +
  6813. +static struct resource bcm2708_bsc0_resources[] = {
  6814. + {
  6815. + .start = BSC0_BASE,
  6816. + .end = BSC0_BASE + SZ_256 - 1,
  6817. + .flags = IORESOURCE_MEM,
  6818. + }, {
  6819. + .start = INTERRUPT_I2C,
  6820. + .end = INTERRUPT_I2C,
  6821. + .flags = IORESOURCE_IRQ,
  6822. + }
  6823. +};
  6824. +
  6825. +static struct platform_device bcm2708_bsc0_device = {
  6826. + .name = "bcm2708_i2c",
  6827. + .id = 0,
  6828. + .num_resources = ARRAY_SIZE(bcm2708_bsc0_resources),
  6829. + .resource = bcm2708_bsc0_resources,
  6830. +};
  6831. +
  6832. +
  6833. +static struct resource bcm2708_bsc1_resources[] = {
  6834. + {
  6835. + .start = BSC1_BASE,
  6836. + .end = BSC1_BASE + SZ_256 - 1,
  6837. + .flags = IORESOURCE_MEM,
  6838. + }, {
  6839. + .start = INTERRUPT_I2C,
  6840. + .end = INTERRUPT_I2C,
  6841. + .flags = IORESOURCE_IRQ,
  6842. + }
  6843. +};
  6844. +
  6845. +static struct platform_device bcm2708_bsc1_device = {
  6846. + .name = "bcm2708_i2c",
  6847. + .id = 1,
  6848. + .num_resources = ARRAY_SIZE(bcm2708_bsc1_resources),
  6849. + .resource = bcm2708_bsc1_resources,
  6850. +};
  6851. +
  6852. +static struct platform_device bcm2835_hwmon_device = {
  6853. + .name = "bcm2835_hwmon",
  6854. +};
  6855. +
  6856. +static struct platform_device bcm2835_thermal_device = {
  6857. + .name = "bcm2835_thermal",
  6858. +};
  6859. +
  6860. +#if defined(CONFIG_SND_BCM2708_SOC_I2S) || defined(CONFIG_SND_BCM2708_SOC_I2S_MODULE)
  6861. +static struct resource bcm2708_i2s_resources[] = {
  6862. + {
  6863. + .start = I2S_BASE,
  6864. + .end = I2S_BASE + 0x20,
  6865. + .flags = IORESOURCE_MEM,
  6866. + },
  6867. + {
  6868. + .start = PCM_CLOCK_BASE,
  6869. + .end = PCM_CLOCK_BASE + 0x02,
  6870. + .flags = IORESOURCE_MEM,
  6871. + }
  6872. +};
  6873. +
  6874. +static struct platform_device bcm2708_i2s_device = {
  6875. + .name = "bcm2708-i2s",
  6876. + .id = 0,
  6877. + .num_resources = ARRAY_SIZE(bcm2708_i2s_resources),
  6878. + .resource = bcm2708_i2s_resources,
  6879. +};
  6880. +#endif
  6881. +
  6882. +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC_MODULE)
  6883. +static struct platform_device snd_hifiberry_dac_device = {
  6884. + .name = "snd-hifiberry-dac",
  6885. + .id = 0,
  6886. + .num_resources = 0,
  6887. +};
  6888. +
  6889. +static struct platform_device snd_pcm5102a_codec_device = {
  6890. + .name = "pcm5102a-codec",
  6891. + .id = -1,
  6892. + .num_resources = 0,
  6893. +};
  6894. +#endif
  6895. +
  6896. +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS_MODULE)
  6897. +static struct platform_device snd_rpi_hifiberry_dacplus_device = {
  6898. + .name = "snd-rpi-hifiberry-dacplus",
  6899. + .id = 0,
  6900. + .num_resources = 0,
  6901. +};
  6902. +
  6903. +static struct i2c_board_info __initdata snd_pcm512x_hbdacplus_i2c_devices[] = {
  6904. + {
  6905. + I2C_BOARD_INFO("pcm5122", 0x4d)
  6906. + },
  6907. +};
  6908. +#endif
  6909. +
  6910. +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI_MODULE)
  6911. +static struct platform_device snd_hifiberry_digi_device = {
  6912. + .name = "snd-hifiberry-digi",
  6913. + .id = 0,
  6914. + .num_resources = 0,
  6915. +};
  6916. +
  6917. +static struct i2c_board_info __initdata snd_wm8804_i2c_devices[] = {
  6918. + {
  6919. + I2C_BOARD_INFO("wm8804", 0x3b)
  6920. + },
  6921. +};
  6922. +
  6923. +#endif
  6924. +
  6925. +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_AMP) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_AMP_MODULE)
  6926. +static struct platform_device snd_hifiberry_amp_device = {
  6927. + .name = "snd-hifiberry-amp",
  6928. + .id = 0,
  6929. + .num_resources = 0,
  6930. +};
  6931. +
  6932. +static struct i2c_board_info __initdata snd_tas5713_i2c_devices[] = {
  6933. + {
  6934. + I2C_BOARD_INFO("tas5713", 0x1b)
  6935. + },
  6936. +};
  6937. +#endif
  6938. +
  6939. +#if defined(CONFIG_SND_BCM2708_SOC_RPI_DAC) || defined(CONFIG_SND_BCM2708_SOC_RPI_DAC_MODULE)
  6940. +static struct platform_device snd_rpi_dac_device = {
  6941. + .name = "snd-rpi-dac",
  6942. + .id = 0,
  6943. + .num_resources = 0,
  6944. +};
  6945. +
  6946. +static struct platform_device snd_pcm1794a_codec_device = {
  6947. + .name = "pcm1794a-codec",
  6948. + .id = -1,
  6949. + .num_resources = 0,
  6950. +};
  6951. +#endif
  6952. +
  6953. +
  6954. +#if defined(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) || defined(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC_MODULE)
  6955. +static struct platform_device snd_rpi_iqaudio_dac_device = {
  6956. + .name = "snd-rpi-iqaudio-dac",
  6957. + .id = 0,
  6958. + .num_resources = 0,
  6959. +};
  6960. +
  6961. +// Use the actual device name rather than generic driver name
  6962. +static struct i2c_board_info __initdata snd_pcm512x_i2c_devices[] = {
  6963. + {
  6964. + I2C_BOARD_INFO("pcm5122", 0x4c)
  6965. + },
  6966. +};
  6967. +#endif
  6968. +
  6969. +int __init bcm_register_device(struct platform_device *pdev)
  6970. +{
  6971. + int ret;
  6972. +
  6973. + ret = platform_device_register(pdev);
  6974. + if (ret)
  6975. + pr_debug("Unable to register platform device '%s': %d\n",
  6976. + pdev->name, ret);
  6977. +
  6978. + return ret;
  6979. +}
  6980. +
  6981. +/*
  6982. + * Use these macros for platform and i2c devices that are present in the
  6983. + * Device Tree. This way the devices are only added on non-DT systems.
  6984. + */
  6985. +#define bcm_register_device_dt(pdev) \
  6986. + if (!use_dt) bcm_register_device(pdev)
  6987. +
  6988. +#define i2c_register_board_info_dt(busnum, info, n) \
  6989. + if (!use_dt) i2c_register_board_info(busnum, info, n)
  6990. +
  6991. +int calc_rsts(int partition)
  6992. +{
  6993. + return PM_PASSWORD |
  6994. + ((partition & (1 << 0)) << 0) |
  6995. + ((partition & (1 << 1)) << 1) |
  6996. + ((partition & (1 << 2)) << 2) |
  6997. + ((partition & (1 << 3)) << 3) |
  6998. + ((partition & (1 << 4)) << 4) |
  6999. + ((partition & (1 << 5)) << 5);
  7000. +}
  7001. +
  7002. +static void bcm2708_restart(enum reboot_mode mode, const char *cmd)
  7003. +{
  7004. + extern char bcm2708_reboot_mode;
  7005. + uint32_t pm_rstc, pm_wdog;
  7006. + uint32_t timeout = 10;
  7007. + uint32_t pm_rsts = 0;
  7008. +
  7009. + if(bcm2708_reboot_mode == 'q')
  7010. + {
  7011. + // NOOBS < 1.3 booting with reboot=q
  7012. + pm_rsts = readl(__io_address(PM_RSTS));
  7013. + pm_rsts = PM_PASSWORD | pm_rsts | PM_RSTS_HADWRQ_SET;
  7014. + }
  7015. + else if(bcm2708_reboot_mode == 'p')
  7016. + {
  7017. + // NOOBS < 1.3 halting
  7018. + pm_rsts = readl(__io_address(PM_RSTS));
  7019. + pm_rsts = PM_PASSWORD | pm_rsts | PM_RSTS_HADWRH_SET;
  7020. + }
  7021. + else
  7022. + {
  7023. + pm_rsts = calc_rsts(reboot_part);
  7024. + }
  7025. +
  7026. + writel(pm_rsts, __io_address(PM_RSTS));
  7027. +
  7028. + /* Setup watchdog for reset */
  7029. + pm_rstc = readl(__io_address(PM_RSTC));
  7030. +
  7031. + pm_wdog = PM_PASSWORD | (timeout & PM_WDOG_TIME_SET); // watchdog timer = timer clock / 16; need password (31:16) + value (11:0)
  7032. + pm_rstc = PM_PASSWORD | (pm_rstc & PM_RSTC_WRCFG_CLR) | PM_RSTC_WRCFG_FULL_RESET;
  7033. +
  7034. + writel(pm_wdog, __io_address(PM_WDOG));
  7035. + writel(pm_rstc, __io_address(PM_RSTC));
  7036. +}
  7037. +
  7038. +/* 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 */
  7039. +static void bcm2708_power_off(void)
  7040. +{
  7041. + extern char bcm2708_reboot_mode;
  7042. + if(bcm2708_reboot_mode == 'q')
  7043. + {
  7044. + // NOOBS < v1.3
  7045. + bcm2708_restart('p', "");
  7046. + }
  7047. + else
  7048. + {
  7049. + /* partition 63 is special code for HALT the bootloader knows not to boot*/
  7050. + reboot_part = 63;
  7051. + /* continue with normal reset mechanism */
  7052. + bcm2708_restart(0, "");
  7053. + }
  7054. +}
  7055. +
  7056. +#ifdef CONFIG_OF
  7057. +static void __init bcm2708_dt_init(void)
  7058. +{
  7059. + int ret;
  7060. +
  7061. + of_clk_init(NULL);
  7062. + ret = of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL);
  7063. + if (ret) {
  7064. + pr_err("of_platform_populate failed: %d\n", ret);
  7065. + /* Proceed as if CONFIG_OF was not defined */
  7066. + } else {
  7067. + use_dt = 1;
  7068. + }
  7069. +}
  7070. +#else
  7071. +static void __init bcm2708_dt_init(void) { }
  7072. +#endif /* CONFIG_OF */
  7073. +
  7074. +void __init bcm2708_init(void)
  7075. +{
  7076. + int i;
  7077. +
  7078. +#if defined(CONFIG_BCM_VC_CMA)
  7079. + vc_cma_early_init();
  7080. +#endif
  7081. + printk("bcm2708.uart_clock = %d\n", uart_clock);
  7082. + pm_power_off = bcm2708_power_off;
  7083. +
  7084. + bcm2708_init_clocks();
  7085. + bcm2708_dt_init();
  7086. +
  7087. + bcm_register_device(&bcm2708_dmaman_device);
  7088. + bcm_register_device(&bcm2708_vcio_device);
  7089. +#ifdef CONFIG_BCM2708_GPIO
  7090. + bcm_register_device_dt(&bcm2708_gpio_device);
  7091. +#endif
  7092. +
  7093. +#if defined(CONFIG_PPS_CLIENT_GPIO) || defined(CONFIG_PPS_CLIENT_GPIO_MODULE)
  7094. + if (!use_dt && (pps_gpio_pin >= 0)) {
  7095. + pr_info("bcm2708: GPIO %d setup as pps-gpio device\n", pps_gpio_pin);
  7096. + pps_gpio_info.gpio_pin = pps_gpio_pin;
  7097. + pps_gpio_device.id = pps_gpio_pin;
  7098. + bcm_register_device(&pps_gpio_device);
  7099. + }
  7100. +#endif
  7101. +
  7102. +#if defined(CONFIG_W1_MASTER_GPIO) || defined(CONFIG_W1_MASTER_GPIO_MODULE)
  7103. + w1_gpio_pdata.pin = w1_gpio_pin;
  7104. + w1_gpio_pdata.ext_pullup_enable_pin = w1_gpio_pullup;
  7105. + bcm_register_device_dt(&w1_device);
  7106. +#endif
  7107. + bcm_register_device(&bcm2708_systemtimer_device);
  7108. + bcm_register_device(&bcm2708_fb_device);
  7109. + bcm_register_device(&bcm2708_usb_device);
  7110. + bcm_register_device(&bcm2708_uart1_device);
  7111. + bcm_register_device(&bcm2708_powerman_device);
  7112. +
  7113. +#ifdef CONFIG_MMC_BCM2835
  7114. + bcm_register_device(&bcm2835_emmc_device);
  7115. +#endif
  7116. + bcm2708_init_led();
  7117. + for (i = 0; i < ARRAY_SIZE(bcm2708_alsa_devices); i++)
  7118. + bcm_register_device(&bcm2708_alsa_devices[i]);
  7119. +
  7120. + bcm_register_device(&bcm2835_hwmon_device);
  7121. + bcm_register_device(&bcm2835_thermal_device);
  7122. +
  7123. + bcm_register_device_dt(&bcm2708_spi_device);
  7124. +
  7125. + if (vc_i2c_override) {
  7126. + bcm_register_device_dt(&bcm2708_bsc0_device);
  7127. + bcm_register_device_dt(&bcm2708_bsc1_device);
  7128. + } else if ((boardrev & 0xffffff) == 0x2 || (boardrev & 0xffffff) == 0x3) {
  7129. + bcm_register_device_dt(&bcm2708_bsc0_device);
  7130. + } else {
  7131. + bcm_register_device_dt(&bcm2708_bsc1_device);
  7132. + }
  7133. +
  7134. +#if defined(CONFIG_SND_BCM2708_SOC_I2S) || defined(CONFIG_SND_BCM2708_SOC_I2S_MODULE)
  7135. + bcm_register_device_dt(&bcm2708_i2s_device);
  7136. +#endif
  7137. +
  7138. +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC_MODULE)
  7139. + bcm_register_device_dt(&snd_hifiberry_dac_device);
  7140. + bcm_register_device_dt(&snd_pcm5102a_codec_device);
  7141. +#endif
  7142. +
  7143. +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS_MODULE)
  7144. + bcm_register_device_dt(&snd_rpi_hifiberry_dacplus_device);
  7145. + i2c_register_board_info_dt(1, snd_pcm512x_hbdacplus_i2c_devices, ARRAY_SIZE(snd_pcm512x_hbdacplus_i2c_devices));
  7146. +#endif
  7147. +
  7148. +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI_MODULE)
  7149. + bcm_register_device_dt(&snd_hifiberry_digi_device);
  7150. + i2c_register_board_info_dt(1, snd_wm8804_i2c_devices, ARRAY_SIZE(snd_wm8804_i2c_devices));
  7151. +#endif
  7152. +
  7153. +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_AMP) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_AMP_MODULE)
  7154. + bcm_register_device_dt(&snd_hifiberry_amp_device);
  7155. + i2c_register_board_info_dt(1, snd_tas5713_i2c_devices, ARRAY_SIZE(snd_tas5713_i2c_devices));
  7156. +#endif
  7157. +
  7158. +#if defined(CONFIG_SND_BCM2708_SOC_RPI_DAC) || defined(CONFIG_SND_BCM2708_SOC_RPI_DAC_MODULE)
  7159. + bcm_register_device_dt(&snd_rpi_dac_device);
  7160. + bcm_register_device_dt(&snd_pcm1794a_codec_device);
  7161. +#endif
  7162. +
  7163. +#if defined(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) || defined(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC_MODULE)
  7164. + bcm_register_device_dt(&snd_rpi_iqaudio_dac_device);
  7165. + i2c_register_board_info_dt(1, snd_pcm512x_i2c_devices, ARRAY_SIZE(snd_pcm512x_i2c_devices));
  7166. +#endif
  7167. +
  7168. +
  7169. + for (i = 0; i < ARRAY_SIZE(amba_devs); i++) {
  7170. + struct amba_device *d = amba_devs[i];
  7171. + amba_device_register(d, &iomem_resource);
  7172. + }
  7173. + system_rev = boardrev;
  7174. + system_serial_low = serial;
  7175. +
  7176. +#ifdef CONFIG_BCM2708_SPIDEV
  7177. + if (!use_dt)
  7178. + spi_register_board_info(bcm2708_spi_devices,
  7179. + ARRAY_SIZE(bcm2708_spi_devices));
  7180. +#endif
  7181. +}
  7182. +
  7183. +static void timer_set_mode(enum clock_event_mode mode,
  7184. + struct clock_event_device *clk)
  7185. +{
  7186. + switch (mode) {
  7187. + case CLOCK_EVT_MODE_ONESHOT: /* Leave the timer disabled, .set_next_event will enable it */
  7188. + case CLOCK_EVT_MODE_SHUTDOWN:
  7189. + break;
  7190. + case CLOCK_EVT_MODE_PERIODIC:
  7191. +
  7192. + case CLOCK_EVT_MODE_UNUSED:
  7193. + case CLOCK_EVT_MODE_RESUME:
  7194. +
  7195. + default:
  7196. + printk(KERN_ERR "timer_set_mode: unhandled mode:%d\n",
  7197. + (int)mode);
  7198. + break;
  7199. + }
  7200. +
  7201. +}
  7202. +
  7203. +static int timer_set_next_event(unsigned long cycles,
  7204. + struct clock_event_device *unused)
  7205. +{
  7206. + unsigned long stc;
  7207. + do {
  7208. + stc = readl(__io_address(ST_BASE + 0x04));
  7209. + /* We could take a FIQ here, which may push ST above STC3 */
  7210. + writel(stc + cycles, __io_address(ST_BASE + 0x18));
  7211. + } while ((signed long) cycles >= 0 &&
  7212. + (signed long) (readl(__io_address(ST_BASE + 0x04)) - stc)
  7213. + >= (signed long) cycles);
  7214. + return 0;
  7215. +}
  7216. +
  7217. +static struct clock_event_device timer0_clockevent = {
  7218. + .name = "timer0",
  7219. + .shift = 32,
  7220. + .features = CLOCK_EVT_FEAT_ONESHOT,
  7221. + .set_mode = timer_set_mode,
  7222. + .set_next_event = timer_set_next_event,
  7223. +};
  7224. +
  7225. +/*
  7226. + * IRQ handler for the timer
  7227. + */
  7228. +static irqreturn_t bcm2708_timer_interrupt(int irq, void *dev_id)
  7229. +{
  7230. + struct clock_event_device *evt = &timer0_clockevent;
  7231. +
  7232. + writel(1 << 3, __io_address(ST_BASE + 0x00)); /* stcs clear timer int */
  7233. +
  7234. + evt->event_handler(evt);
  7235. +
  7236. + return IRQ_HANDLED;
  7237. +}
  7238. +
  7239. +static struct irqaction bcm2708_timer_irq = {
  7240. + .name = "BCM2708 Timer Tick",
  7241. + .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
  7242. + .handler = bcm2708_timer_interrupt,
  7243. +};
  7244. +
  7245. +/*
  7246. + * Set up timer interrupt, and return the current time in seconds.
  7247. + */
  7248. +
  7249. +static struct delay_timer bcm2708_delay_timer = {
  7250. + .read_current_timer = bcm2708_read_current_timer,
  7251. + .freq = STC_FREQ_HZ,
  7252. +};
  7253. +
  7254. +static void __init bcm2708_timer_init(void)
  7255. +{
  7256. + /* init high res timer */
  7257. + bcm2708_clocksource_init();
  7258. +
  7259. + /*
  7260. + * Initialise to a known state (all timers off)
  7261. + */
  7262. + writel(0, __io_address(ARM_T_CONTROL));
  7263. + /*
  7264. + * Make irqs happen for the system timer
  7265. + */
  7266. + setup_irq(IRQ_TIMER3, &bcm2708_timer_irq);
  7267. +
  7268. + sched_clock_register(bcm2708_read_sched_clock, 32, STC_FREQ_HZ);
  7269. +
  7270. + timer0_clockevent.mult =
  7271. + div_sc(STC_FREQ_HZ, NSEC_PER_SEC, timer0_clockevent.shift);
  7272. + timer0_clockevent.max_delta_ns =
  7273. + clockevent_delta2ns(0xffffffff, &timer0_clockevent);
  7274. + timer0_clockevent.min_delta_ns =
  7275. + clockevent_delta2ns(0xf, &timer0_clockevent);
  7276. +
  7277. + timer0_clockevent.cpumask = cpumask_of(0);
  7278. + clockevents_register_device(&timer0_clockevent);
  7279. +
  7280. + register_current_timer_delay(&bcm2708_delay_timer);
  7281. +}
  7282. +
  7283. +#if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE)
  7284. +#include <linux/leds.h>
  7285. +
  7286. +static struct gpio_led bcm2708_leds[] = {
  7287. + [0] = {
  7288. + .gpio = 16,
  7289. + .name = "led0",
  7290. + .default_trigger = "mmc0",
  7291. + .active_low = 1,
  7292. + },
  7293. +};
  7294. +
  7295. +static struct gpio_led_platform_data bcm2708_led_pdata = {
  7296. + .num_leds = ARRAY_SIZE(bcm2708_leds),
  7297. + .leds = bcm2708_leds,
  7298. +};
  7299. +
  7300. +static struct platform_device bcm2708_led_device = {
  7301. + .name = "leds-gpio",
  7302. + .id = -1,
  7303. + .dev = {
  7304. + .platform_data = &bcm2708_led_pdata,
  7305. + },
  7306. +};
  7307. +
  7308. +static void __init bcm2708_init_led(void)
  7309. +{
  7310. + bcm2708_leds[0].gpio = disk_led_gpio;
  7311. + bcm2708_leds[0].active_low = disk_led_active_low;
  7312. + bcm_register_device_dt(&bcm2708_led_device);
  7313. +}
  7314. +#else
  7315. +static inline void bcm2708_init_led(void)
  7316. +{
  7317. +}
  7318. +#endif
  7319. +
  7320. +void __init bcm2708_init_early(void)
  7321. +{
  7322. + /*
  7323. + * Some devices allocate their coherent buffers from atomic
  7324. + * context. Increase size of atomic coherent pool to make sure such
  7325. + * the allocations won't fail.
  7326. + */
  7327. + init_dma_coherent_pool_size(SZ_4M);
  7328. +}
  7329. +
  7330. +static void __init board_reserve(void)
  7331. +{
  7332. +#if defined(CONFIG_BCM_VC_CMA)
  7333. + vc_cma_reserve();
  7334. +#endif
  7335. +}
  7336. +
  7337. +static const char * const bcm2708_compat[] = {
  7338. + "brcm,bcm2708",
  7339. + NULL
  7340. +};
  7341. +
  7342. +MACHINE_START(BCM2708, "BCM2708")
  7343. + /* Maintainer: Broadcom Europe Ltd. */
  7344. + .map_io = bcm2708_map_io,
  7345. + .init_irq = bcm2708_init_irq,
  7346. + .init_time = bcm2708_timer_init,
  7347. + .init_machine = bcm2708_init,
  7348. + .init_early = bcm2708_init_early,
  7349. + .reserve = board_reserve,
  7350. + .restart = bcm2708_restart,
  7351. + .dt_compat = bcm2708_compat,
  7352. +MACHINE_END
  7353. +
  7354. +module_param(boardrev, uint, 0644);
  7355. +module_param(serial, uint, 0644);
  7356. +module_param(uart_clock, uint, 0644);
  7357. +module_param(disk_led_gpio, uint, 0644);
  7358. +module_param(disk_led_active_low, uint, 0644);
  7359. +module_param(reboot_part, uint, 0644);
  7360. +module_param(w1_gpio_pin, uint, 0644);
  7361. +module_param(w1_gpio_pullup, uint, 0644);
  7362. +module_param(pps_gpio_pin, int, 0644);
  7363. +MODULE_PARM_DESC(pps_gpio_pin, "Set GPIO pin to reserve for PPS");
  7364. +module_param(vc_i2c_override, bool, 0644);
  7365. +MODULE_PARM_DESC(vc_i2c_override, "Allow the use of VC's I2C peripheral.");
  7366. diff -Nur linux-3.18.8/arch/arm/mach-bcm2708/bcm2708_gpio.c linux-rpi/arch/arm/mach-bcm2708/bcm2708_gpio.c
  7367. --- linux-3.18.8/arch/arm/mach-bcm2708/bcm2708_gpio.c 1970-01-01 01:00:00.000000000 +0100
  7368. +++ linux-rpi/arch/arm/mach-bcm2708/bcm2708_gpio.c 2015-03-05 14:40:11.153715839 +0100
  7369. @@ -0,0 +1,426 @@
  7370. +/*
  7371. + * linux/arch/arm/mach-bcm2708/bcm2708_gpio.c
  7372. + *
  7373. + * Copyright (C) 2010 Broadcom
  7374. + *
  7375. + * This program is free software; you can redistribute it and/or modify
  7376. + * it under the terms of the GNU General Public License version 2 as
  7377. + * published by the Free Software Foundation.
  7378. + *
  7379. + */
  7380. +
  7381. +#include <linux/spinlock.h>
  7382. +#include <linux/module.h>
  7383. +#include <linux/delay.h>
  7384. +#include <linux/list.h>
  7385. +#include <linux/io.h>
  7386. +#include <linux/irq.h>
  7387. +#include <linux/interrupt.h>
  7388. +#include <linux/slab.h>
  7389. +#include <mach/gpio.h>
  7390. +#include <linux/gpio.h>
  7391. +#include <linux/platform_device.h>
  7392. +#include <mach/platform.h>
  7393. +#include <linux/pinctrl/consumer.h>
  7394. +
  7395. +#include <linux/platform_data/bcm2708.h>
  7396. +
  7397. +#define BCM_GPIO_DRIVER_NAME "bcm2708_gpio"
  7398. +#define DRIVER_NAME BCM_GPIO_DRIVER_NAME
  7399. +#define BCM_GPIO_USE_IRQ 1
  7400. +
  7401. +#define GPIOFSEL(x) (0x00+(x)*4)
  7402. +#define GPIOSET(x) (0x1c+(x)*4)
  7403. +#define GPIOCLR(x) (0x28+(x)*4)
  7404. +#define GPIOLEV(x) (0x34+(x)*4)
  7405. +#define GPIOEDS(x) (0x40+(x)*4)
  7406. +#define GPIOREN(x) (0x4c+(x)*4)
  7407. +#define GPIOFEN(x) (0x58+(x)*4)
  7408. +#define GPIOHEN(x) (0x64+(x)*4)
  7409. +#define GPIOLEN(x) (0x70+(x)*4)
  7410. +#define GPIOAREN(x) (0x7c+(x)*4)
  7411. +#define GPIOAFEN(x) (0x88+(x)*4)
  7412. +#define GPIOUD(x) (0x94+(x)*4)
  7413. +#define GPIOUDCLK(x) (0x98+(x)*4)
  7414. +
  7415. +#define GPIO_BANKS 2
  7416. +
  7417. +enum { GPIO_FSEL_INPUT, GPIO_FSEL_OUTPUT,
  7418. + GPIO_FSEL_ALT5, GPIO_FSEL_ALT_4,
  7419. + GPIO_FSEL_ALT0, GPIO_FSEL_ALT1,
  7420. + GPIO_FSEL_ALT2, GPIO_FSEL_ALT3,
  7421. +};
  7422. +
  7423. + /* Each of the two spinlocks protects a different set of hardware
  7424. + * regiters and data structurs. This decouples the code of the IRQ from
  7425. + * the GPIO code. This also makes the case of a GPIO routine call from
  7426. + * the IRQ code simpler.
  7427. + */
  7428. +static DEFINE_SPINLOCK(lock); /* GPIO registers */
  7429. +
  7430. +struct bcm2708_gpio {
  7431. + struct list_head list;
  7432. + void __iomem *base;
  7433. + struct gpio_chip gc;
  7434. + unsigned long rising[(BCM2708_NR_GPIOS + 31) / 32];
  7435. + unsigned long falling[(BCM2708_NR_GPIOS + 31) / 32];
  7436. + unsigned long high[(BCM2708_NR_GPIOS + 31) / 32];
  7437. + unsigned long low[(BCM2708_NR_GPIOS + 31) / 32];
  7438. +};
  7439. +
  7440. +static int bcm2708_set_function(struct gpio_chip *gc, unsigned offset,
  7441. + int function)
  7442. +{
  7443. + struct bcm2708_gpio *gpio = container_of(gc, struct bcm2708_gpio, gc);
  7444. + unsigned long flags;
  7445. + unsigned gpiodir;
  7446. + unsigned gpio_bank = offset / 10;
  7447. + unsigned gpio_field_offset = (offset - 10 * gpio_bank) * 3;
  7448. +
  7449. +//printk(KERN_ERR DRIVER_NAME ": bcm2708_gpio_set_function %p (%d,%d)\n", gc, offset, function);
  7450. + if (offset >= BCM2708_NR_GPIOS)
  7451. + return -EINVAL;
  7452. +
  7453. + spin_lock_irqsave(&lock, flags);
  7454. +
  7455. + gpiodir = readl(gpio->base + GPIOFSEL(gpio_bank));
  7456. + gpiodir &= ~(7 << gpio_field_offset);
  7457. + gpiodir |= function << gpio_field_offset;
  7458. + writel(gpiodir, gpio->base + GPIOFSEL(gpio_bank));
  7459. + spin_unlock_irqrestore(&lock, flags);
  7460. + gpiodir = readl(gpio->base + GPIOFSEL(gpio_bank));
  7461. +
  7462. + return 0;
  7463. +}
  7464. +
  7465. +static int bcm2708_gpio_dir_in(struct gpio_chip *gc, unsigned offset)
  7466. +{
  7467. + return bcm2708_set_function(gc, offset, GPIO_FSEL_INPUT);
  7468. +}
  7469. +
  7470. +static void bcm2708_gpio_set(struct gpio_chip *gc, unsigned offset, int value);
  7471. +static int bcm2708_gpio_dir_out(struct gpio_chip *gc, unsigned offset,
  7472. + int value)
  7473. +{
  7474. + int ret;
  7475. + ret = bcm2708_set_function(gc, offset, GPIO_FSEL_OUTPUT);
  7476. + if (ret >= 0)
  7477. + bcm2708_gpio_set(gc, offset, value);
  7478. + return ret;
  7479. +}
  7480. +
  7481. +static int bcm2708_gpio_get(struct gpio_chip *gc, unsigned offset)
  7482. +{
  7483. + struct bcm2708_gpio *gpio = container_of(gc, struct bcm2708_gpio, gc);
  7484. + unsigned gpio_bank = offset / 32;
  7485. + unsigned gpio_field_offset = (offset - 32 * gpio_bank);
  7486. + unsigned lev;
  7487. +
  7488. + if (offset >= BCM2708_NR_GPIOS)
  7489. + return 0;
  7490. + lev = readl(gpio->base + GPIOLEV(gpio_bank));
  7491. +//printk(KERN_ERR DRIVER_NAME ": bcm2708_gpio_get %p (%d)=%d\n", gc, offset, 0x1 & (lev>>gpio_field_offset));
  7492. + return 0x1 & (lev >> gpio_field_offset);
  7493. +}
  7494. +
  7495. +static void bcm2708_gpio_set(struct gpio_chip *gc, unsigned offset, int value)
  7496. +{
  7497. + struct bcm2708_gpio *gpio = container_of(gc, struct bcm2708_gpio, gc);
  7498. + unsigned gpio_bank = offset / 32;
  7499. + unsigned gpio_field_offset = (offset - 32 * gpio_bank);
  7500. +//printk(KERN_ERR DRIVER_NAME ": bcm2708_gpio_set %p (%d=%d)\n", gc, offset, value);
  7501. + if (offset >= BCM2708_NR_GPIOS)
  7502. + return;
  7503. + if (value)
  7504. + writel(1 << gpio_field_offset, gpio->base + GPIOSET(gpio_bank));
  7505. + else
  7506. + writel(1 << gpio_field_offset, gpio->base + GPIOCLR(gpio_bank));
  7507. +}
  7508. +
  7509. +/**********************
  7510. + * extension to configure pullups
  7511. + */
  7512. +int bcm2708_gpio_setpull(struct gpio_chip *gc, unsigned offset,
  7513. + bcm2708_gpio_pull_t value)
  7514. +{
  7515. + struct bcm2708_gpio *gpio = container_of(gc, struct bcm2708_gpio, gc);
  7516. + unsigned gpio_bank = offset / 32;
  7517. + unsigned gpio_field_offset = (offset - 32 * gpio_bank);
  7518. +
  7519. + if (offset >= BCM2708_NR_GPIOS)
  7520. + return -EINVAL;
  7521. +
  7522. + switch (value) {
  7523. + case BCM2708_PULL_UP:
  7524. + writel(2, gpio->base + GPIOUD(0));
  7525. + break;
  7526. + case BCM2708_PULL_DOWN:
  7527. + writel(1, gpio->base + GPIOUD(0));
  7528. + break;
  7529. + case BCM2708_PULL_OFF:
  7530. + writel(0, gpio->base + GPIOUD(0));
  7531. + break;
  7532. + }
  7533. +
  7534. + udelay(5);
  7535. + writel(1 << gpio_field_offset, gpio->base + GPIOUDCLK(gpio_bank));
  7536. + udelay(5);
  7537. + writel(0, gpio->base + GPIOUD(0));
  7538. + writel(0 << gpio_field_offset, gpio->base + GPIOUDCLK(gpio_bank));
  7539. +
  7540. + return 0;
  7541. +}
  7542. +EXPORT_SYMBOL(bcm2708_gpio_setpull);
  7543. +
  7544. +/*************************************************************************************************************************
  7545. + * bcm2708 GPIO IRQ
  7546. + */
  7547. +
  7548. +#if BCM_GPIO_USE_IRQ
  7549. +
  7550. +static int bcm2708_gpio_to_irq(struct gpio_chip *chip, unsigned gpio)
  7551. +{
  7552. + return gpio_to_irq(gpio);
  7553. +}
  7554. +
  7555. +static int bcm2708_gpio_irq_set_type(struct irq_data *d, unsigned type)
  7556. +{
  7557. + unsigned irq = d->irq;
  7558. + struct bcm2708_gpio *gpio = irq_get_chip_data(irq);
  7559. + unsigned gn = irq_to_gpio(irq);
  7560. + unsigned gb = gn / 32;
  7561. + unsigned go = gn % 32;
  7562. +
  7563. + gpio->rising[gb] &= ~(1 << go);
  7564. + gpio->falling[gb] &= ~(1 << go);
  7565. + gpio->high[gb] &= ~(1 << go);
  7566. + gpio->low[gb] &= ~(1 << go);
  7567. +
  7568. + if (type & ~(IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING | IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH))
  7569. + return -EINVAL;
  7570. +
  7571. + if (type & IRQ_TYPE_EDGE_RISING)
  7572. + gpio->rising[gb] |= (1 << go);
  7573. + if (type & IRQ_TYPE_EDGE_FALLING)
  7574. + gpio->falling[gb] |= (1 << go);
  7575. + if (type & IRQ_TYPE_LEVEL_HIGH)
  7576. + gpio->high[gb] |= (1 << go);
  7577. + if (type & IRQ_TYPE_LEVEL_LOW)
  7578. + gpio->low[gb] |= (1 << go);
  7579. + return 0;
  7580. +}
  7581. +
  7582. +static void bcm2708_gpio_irq_mask(struct irq_data *d)
  7583. +{
  7584. + unsigned irq = d->irq;
  7585. + struct bcm2708_gpio *gpio = irq_get_chip_data(irq);
  7586. + unsigned gn = irq_to_gpio(irq);
  7587. + unsigned gb = gn / 32;
  7588. + unsigned long rising = readl(gpio->base + GPIOREN(gb));
  7589. + unsigned long falling = readl(gpio->base + GPIOFEN(gb));
  7590. + unsigned long high = readl(gpio->base + GPIOHEN(gb));
  7591. + unsigned long low = readl(gpio->base + GPIOLEN(gb));
  7592. +
  7593. + gn = gn % 32;
  7594. +
  7595. + writel(rising & ~(1 << gn), gpio->base + GPIOREN(gb));
  7596. + writel(falling & ~(1 << gn), gpio->base + GPIOFEN(gb));
  7597. + writel(high & ~(1 << gn), gpio->base + GPIOHEN(gb));
  7598. + writel(low & ~(1 << gn), gpio->base + GPIOLEN(gb));
  7599. +}
  7600. +
  7601. +static void bcm2708_gpio_irq_unmask(struct irq_data *d)
  7602. +{
  7603. + unsigned irq = d->irq;
  7604. + struct bcm2708_gpio *gpio = irq_get_chip_data(irq);
  7605. + unsigned gn = irq_to_gpio(irq);
  7606. + unsigned gb = gn / 32;
  7607. + unsigned go = gn % 32;
  7608. + unsigned long rising = readl(gpio->base + GPIOREN(gb));
  7609. + unsigned long falling = readl(gpio->base + GPIOFEN(gb));
  7610. + unsigned long high = readl(gpio->base + GPIOHEN(gb));
  7611. + unsigned long low = readl(gpio->base + GPIOLEN(gb));
  7612. +
  7613. + if (gpio->rising[gb] & (1 << go)) {
  7614. + writel(rising | (1 << go), gpio->base + GPIOREN(gb));
  7615. + } else {
  7616. + writel(rising & ~(1 << go), gpio->base + GPIOREN(gb));
  7617. + }
  7618. +
  7619. + if (gpio->falling[gb] & (1 << go)) {
  7620. + writel(falling | (1 << go), gpio->base + GPIOFEN(gb));
  7621. + } else {
  7622. + writel(falling & ~(1 << go), gpio->base + GPIOFEN(gb));
  7623. + }
  7624. +
  7625. + if (gpio->high[gb] & (1 << go)) {
  7626. + writel(high | (1 << go), gpio->base + GPIOHEN(gb));
  7627. + } else {
  7628. + writel(high & ~(1 << go), gpio->base + GPIOHEN(gb));
  7629. + }
  7630. +
  7631. + if (gpio->low[gb] & (1 << go)) {
  7632. + writel(low | (1 << go), gpio->base + GPIOLEN(gb));
  7633. + } else {
  7634. + writel(low & ~(1 << go), gpio->base + GPIOLEN(gb));
  7635. + }
  7636. +}
  7637. +
  7638. +static struct irq_chip bcm2708_irqchip = {
  7639. + .name = "GPIO",
  7640. + .irq_enable = bcm2708_gpio_irq_unmask,
  7641. + .irq_disable = bcm2708_gpio_irq_mask,
  7642. + .irq_unmask = bcm2708_gpio_irq_unmask,
  7643. + .irq_mask = bcm2708_gpio_irq_mask,
  7644. + .irq_set_type = bcm2708_gpio_irq_set_type,
  7645. +};
  7646. +
  7647. +static irqreturn_t bcm2708_gpio_interrupt(int irq, void *dev_id)
  7648. +{
  7649. + unsigned long edsr;
  7650. + unsigned bank;
  7651. + int i;
  7652. + unsigned gpio;
  7653. + unsigned level_bits;
  7654. + struct bcm2708_gpio *gpio_data = dev_id;
  7655. +
  7656. + for (bank = 0; bank < GPIO_BANKS; bank++) {
  7657. + edsr = readl(__io_address(GPIO_BASE) + GPIOEDS(bank));
  7658. + level_bits = gpio_data->high[bank] | gpio_data->low[bank];
  7659. +
  7660. + for_each_set_bit(i, &edsr, 32) {
  7661. + gpio = i + bank * 32;
  7662. + /* ack edge triggered IRQs immediately */
  7663. + if (!(level_bits & (1<<i)))
  7664. + writel(1<<i,
  7665. + __io_address(GPIO_BASE) + GPIOEDS(bank));
  7666. + generic_handle_irq(gpio_to_irq(gpio));
  7667. + /* ack level triggered IRQ after handling them */
  7668. + if (level_bits & (1<<i))
  7669. + writel(1<<i,
  7670. + __io_address(GPIO_BASE) + GPIOEDS(bank));
  7671. + }
  7672. + }
  7673. + return IRQ_HANDLED;
  7674. +}
  7675. +
  7676. +static struct irqaction bcm2708_gpio_irq = {
  7677. + .name = "BCM2708 GPIO catchall handler",
  7678. + .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
  7679. + .handler = bcm2708_gpio_interrupt,
  7680. +};
  7681. +
  7682. +static void bcm2708_gpio_irq_init(struct bcm2708_gpio *ucb)
  7683. +{
  7684. + unsigned irq;
  7685. +
  7686. + ucb->gc.to_irq = bcm2708_gpio_to_irq;
  7687. +
  7688. + for (irq = GPIO_IRQ_START; irq < (GPIO_IRQ_START + GPIO_IRQS); irq++) {
  7689. + irq_set_chip_data(irq, ucb);
  7690. + irq_set_chip_and_handler(irq, &bcm2708_irqchip,
  7691. + handle_simple_irq);
  7692. + set_irq_flags(irq, IRQF_VALID);
  7693. + }
  7694. +
  7695. + bcm2708_gpio_irq.dev_id = ucb;
  7696. + setup_irq(IRQ_GPIO3, &bcm2708_gpio_irq);
  7697. +}
  7698. +
  7699. +#else
  7700. +
  7701. +static void bcm2708_gpio_irq_init(struct bcm2708_gpio *ucb)
  7702. +{
  7703. +}
  7704. +
  7705. +#endif /* #if BCM_GPIO_USE_IRQ ***************************************************************************************************************** */
  7706. +
  7707. +static int bcm2708_gpio_probe(struct platform_device *dev)
  7708. +{
  7709. + struct bcm2708_gpio *ucb;
  7710. + struct resource *res;
  7711. + int bank;
  7712. + int err = 0;
  7713. +
  7714. + printk(KERN_INFO DRIVER_NAME ": bcm2708_gpio_probe %p\n", dev);
  7715. +
  7716. + ucb = kzalloc(sizeof(*ucb), GFP_KERNEL);
  7717. + if (NULL == ucb) {
  7718. + printk(KERN_ERR DRIVER_NAME ": failed to allocate "
  7719. + "mailbox memory\n");
  7720. + err = -ENOMEM;
  7721. + goto err;
  7722. + }
  7723. +
  7724. + res = platform_get_resource(dev, IORESOURCE_MEM, 0);
  7725. +
  7726. + platform_set_drvdata(dev, ucb);
  7727. + ucb->base = __io_address(GPIO_BASE);
  7728. +
  7729. + ucb->gc.label = "bcm2708_gpio";
  7730. + ucb->gc.base = 0;
  7731. + ucb->gc.ngpio = BCM2708_NR_GPIOS;
  7732. + ucb->gc.owner = THIS_MODULE;
  7733. +
  7734. + ucb->gc.direction_input = bcm2708_gpio_dir_in;
  7735. + ucb->gc.direction_output = bcm2708_gpio_dir_out;
  7736. + ucb->gc.get = bcm2708_gpio_get;
  7737. + ucb->gc.set = bcm2708_gpio_set;
  7738. + ucb->gc.can_sleep = 0;
  7739. +
  7740. + for (bank = 0; bank < GPIO_BANKS; bank++) {
  7741. + writel(0, ucb->base + GPIOREN(bank));
  7742. + writel(0, ucb->base + GPIOFEN(bank));
  7743. + writel(0, ucb->base + GPIOHEN(bank));
  7744. + writel(0, ucb->base + GPIOLEN(bank));
  7745. + writel(0, ucb->base + GPIOAREN(bank));
  7746. + writel(0, ucb->base + GPIOAFEN(bank));
  7747. + writel(~0, ucb->base + GPIOEDS(bank));
  7748. + }
  7749. +
  7750. + bcm2708_gpio_irq_init(ucb);
  7751. +
  7752. + err = gpiochip_add(&ucb->gc);
  7753. +
  7754. +err:
  7755. + return err;
  7756. +
  7757. +}
  7758. +
  7759. +static int bcm2708_gpio_remove(struct platform_device *dev)
  7760. +{
  7761. + int err = 0;
  7762. + struct bcm2708_gpio *ucb = platform_get_drvdata(dev);
  7763. +
  7764. + printk(KERN_ERR DRIVER_NAME ": bcm2708_gpio_remove %p\n", dev);
  7765. +
  7766. + gpiochip_remove(&ucb->gc);
  7767. +
  7768. + platform_set_drvdata(dev, NULL);
  7769. + kfree(ucb);
  7770. +
  7771. + return err;
  7772. +}
  7773. +
  7774. +static struct platform_driver bcm2708_gpio_driver = {
  7775. + .probe = bcm2708_gpio_probe,
  7776. + .remove = bcm2708_gpio_remove,
  7777. + .driver = {
  7778. + .name = "bcm2708_gpio"},
  7779. +};
  7780. +
  7781. +static int __init bcm2708_gpio_init(void)
  7782. +{
  7783. + return platform_driver_register(&bcm2708_gpio_driver);
  7784. +}
  7785. +
  7786. +static void __exit bcm2708_gpio_exit(void)
  7787. +{
  7788. + platform_driver_unregister(&bcm2708_gpio_driver);
  7789. +}
  7790. +
  7791. +module_init(bcm2708_gpio_init);
  7792. +module_exit(bcm2708_gpio_exit);
  7793. +
  7794. +MODULE_DESCRIPTION("Broadcom BCM2708 GPIO driver");
  7795. +MODULE_LICENSE("GPL");
  7796. diff -Nur linux-3.18.8/arch/arm/mach-bcm2708/bcm2708.h linux-rpi/arch/arm/mach-bcm2708/bcm2708.h
  7797. --- linux-3.18.8/arch/arm/mach-bcm2708/bcm2708.h 1970-01-01 01:00:00.000000000 +0100
  7798. +++ linux-rpi/arch/arm/mach-bcm2708/bcm2708.h 2015-03-05 14:40:11.153715839 +0100
  7799. @@ -0,0 +1,49 @@
  7800. +/*
  7801. + * linux/arch/arm/mach-bcm2708/bcm2708.h
  7802. + *
  7803. + * BCM2708 machine support header
  7804. + *
  7805. + * Copyright (C) 2010 Broadcom
  7806. + *
  7807. + * This program is free software; you can redistribute it and/or modify
  7808. + * it under the terms of the GNU General Public License as published by
  7809. + * the Free Software Foundation; either version 2 of the License, or
  7810. + * (at your option) any later version.
  7811. + *
  7812. + * This program is distributed in the hope that it will be useful,
  7813. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  7814. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  7815. + * GNU General Public License for more details.
  7816. + *
  7817. + * You should have received a copy of the GNU General Public License
  7818. + * along with this program; if not, write to the Free Software
  7819. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  7820. + */
  7821. +
  7822. +#ifndef __BCM2708_BCM2708_H
  7823. +#define __BCM2708_BCM2708_H
  7824. +
  7825. +#include <linux/amba/bus.h>
  7826. +
  7827. +extern void __init bcm2708_init(void);
  7828. +extern void __init bcm2708_init_irq(void);
  7829. +extern void __init bcm2708_map_io(void);
  7830. +extern struct sys_timer bcm2708_timer;
  7831. +extern unsigned int mmc_status(struct device *dev);
  7832. +
  7833. +#define AMBA_DEVICE(name, busid, base, plat) \
  7834. +static struct amba_device name##_device = { \
  7835. + .dev = { \
  7836. + .coherent_dma_mask = ~0, \
  7837. + .init_name = busid, \
  7838. + .platform_data = plat, \
  7839. + }, \
  7840. + .res = { \
  7841. + .start = base##_BASE, \
  7842. + .end = (base##_BASE) + SZ_4K - 1,\
  7843. + .flags = IORESOURCE_MEM, \
  7844. + }, \
  7845. + .irq = base##_IRQ, \
  7846. +}
  7847. +
  7848. +#endif
  7849. diff -Nur linux-3.18.8/arch/arm/mach-bcm2708/dma.c linux-rpi/arch/arm/mach-bcm2708/dma.c
  7850. --- linux-3.18.8/arch/arm/mach-bcm2708/dma.c 1970-01-01 01:00:00.000000000 +0100
  7851. +++ linux-rpi/arch/arm/mach-bcm2708/dma.c 2015-03-05 14:40:11.153715839 +0100
  7852. @@ -0,0 +1,409 @@
  7853. +/*
  7854. + * linux/arch/arm/mach-bcm2708/dma.c
  7855. + *
  7856. + * Copyright (C) 2010 Broadcom
  7857. + *
  7858. + * This program is free software; you can redistribute it and/or modify
  7859. + * it under the terms of the GNU General Public License version 2 as
  7860. + * published by the Free Software Foundation.
  7861. + */
  7862. +
  7863. +#include <linux/slab.h>
  7864. +#include <linux/device.h>
  7865. +#include <linux/platform_device.h>
  7866. +#include <linux/module.h>
  7867. +#include <linux/scatterlist.h>
  7868. +
  7869. +#include <mach/dma.h>
  7870. +#include <mach/irqs.h>
  7871. +
  7872. +/*****************************************************************************\
  7873. + * *
  7874. + * Configuration *
  7875. + * *
  7876. +\*****************************************************************************/
  7877. +
  7878. +#define CACHE_LINE_MASK 31
  7879. +#define DRIVER_NAME BCM_DMAMAN_DRIVER_NAME
  7880. +#define DEFAULT_DMACHAN_BITMAP 0x10 /* channel 4 only */
  7881. +
  7882. +/* valid only for channels 0 - 14, 15 has its own base address */
  7883. +#define BCM2708_DMA_CHAN(n) ((n)<<8) /* base address */
  7884. +#define BCM2708_DMA_CHANIO(dma_base, n) \
  7885. + ((void __iomem *)((char *)(dma_base)+BCM2708_DMA_CHAN(n)))
  7886. +
  7887. +
  7888. +/*****************************************************************************\
  7889. + * *
  7890. + * DMA Auxilliary Functions *
  7891. + * *
  7892. +\*****************************************************************************/
  7893. +
  7894. +/* A DMA buffer on an arbitrary boundary may separate a cache line into a
  7895. + section inside the DMA buffer and another section outside it.
  7896. + Even if we flush DMA buffers from the cache there is always the chance that
  7897. + during a DMA someone will access the part of a cache line that is outside
  7898. + the DMA buffer - which will then bring in unwelcome data.
  7899. + Without being able to dictate our own buffer pools we must insist that
  7900. + DMA buffers consist of a whole number of cache lines.
  7901. +*/
  7902. +
  7903. +extern int
  7904. +bcm_sg_suitable_for_dma(struct scatterlist *sg_ptr, int sg_len)
  7905. +{
  7906. + int i;
  7907. +
  7908. + for (i = 0; i < sg_len; i++) {
  7909. + if (sg_ptr[i].offset & CACHE_LINE_MASK ||
  7910. + sg_ptr[i].length & CACHE_LINE_MASK)
  7911. + return 0;
  7912. + }
  7913. +
  7914. + return 1;
  7915. +}
  7916. +EXPORT_SYMBOL_GPL(bcm_sg_suitable_for_dma);
  7917. +
  7918. +extern void
  7919. +bcm_dma_start(void __iomem *dma_chan_base, dma_addr_t control_block)
  7920. +{
  7921. + dsb(); /* ARM data synchronization (push) operation */
  7922. +
  7923. + writel(control_block, dma_chan_base + BCM2708_DMA_ADDR);
  7924. + writel(BCM2708_DMA_ACTIVE, dma_chan_base + BCM2708_DMA_CS);
  7925. +}
  7926. +
  7927. +extern void bcm_dma_wait_idle(void __iomem *dma_chan_base)
  7928. +{
  7929. + dsb();
  7930. +
  7931. + /* ugly busy wait only option for now */
  7932. + while (readl(dma_chan_base + BCM2708_DMA_CS) & BCM2708_DMA_ACTIVE)
  7933. + cpu_relax();
  7934. +}
  7935. +
  7936. +EXPORT_SYMBOL_GPL(bcm_dma_start);
  7937. +
  7938. +extern bool bcm_dma_is_busy(void __iomem *dma_chan_base)
  7939. +{
  7940. + dsb();
  7941. +
  7942. + return readl(dma_chan_base + BCM2708_DMA_CS) & BCM2708_DMA_ACTIVE;
  7943. +}
  7944. +EXPORT_SYMBOL_GPL(bcm_dma_is_busy);
  7945. +
  7946. +/* Complete an ongoing DMA (assuming its results are to be ignored)
  7947. + Does nothing if there is no DMA in progress.
  7948. + This routine waits for the current AXI transfer to complete before
  7949. + terminating the current DMA. If the current transfer is hung on a DREQ used
  7950. + by an uncooperative peripheral the AXI transfer may never complete. In this
  7951. + case the routine times out and return a non-zero error code.
  7952. + Use of this routine doesn't guarantee that the ongoing or aborted DMA
  7953. + does not produce an interrupt.
  7954. +*/
  7955. +extern int
  7956. +bcm_dma_abort(void __iomem *dma_chan_base)
  7957. +{
  7958. + unsigned long int cs;
  7959. + int rc = 0;
  7960. +
  7961. + cs = readl(dma_chan_base + BCM2708_DMA_CS);
  7962. +
  7963. + if (BCM2708_DMA_ACTIVE & cs) {
  7964. + long int timeout = 10000;
  7965. +
  7966. + /* write 0 to the active bit - pause the DMA */
  7967. + writel(0, dma_chan_base + BCM2708_DMA_CS);
  7968. +
  7969. + /* wait for any current AXI transfer to complete */
  7970. + while (0 != (cs & BCM2708_DMA_ISPAUSED) && --timeout >= 0)
  7971. + cs = readl(dma_chan_base + BCM2708_DMA_CS);
  7972. +
  7973. + if (0 != (cs & BCM2708_DMA_ISPAUSED)) {
  7974. + /* we'll un-pause when we set of our next DMA */
  7975. + rc = -ETIMEDOUT;
  7976. +
  7977. + } else if (BCM2708_DMA_ACTIVE & cs) {
  7978. + /* terminate the control block chain */
  7979. + writel(0, dma_chan_base + BCM2708_DMA_NEXTCB);
  7980. +
  7981. + /* abort the whole DMA */
  7982. + writel(BCM2708_DMA_ABORT | BCM2708_DMA_ACTIVE,
  7983. + dma_chan_base + BCM2708_DMA_CS);
  7984. + }
  7985. + }
  7986. +
  7987. + return rc;
  7988. +}
  7989. +EXPORT_SYMBOL_GPL(bcm_dma_abort);
  7990. +
  7991. +
  7992. +/***************************************************************************** \
  7993. + * *
  7994. + * DMA Manager Device Methods *
  7995. + * *
  7996. +\*****************************************************************************/
  7997. +
  7998. +struct vc_dmaman {
  7999. + void __iomem *dma_base;
  8000. + u32 chan_available; /* bitmap of available channels */
  8001. + u32 has_feature[BCM_DMA_FEATURE_COUNT]; /* bitmap of feature presence */
  8002. +};
  8003. +
  8004. +static void vc_dmaman_init(struct vc_dmaman *dmaman, void __iomem *dma_base,
  8005. + u32 chans_available)
  8006. +{
  8007. + dmaman->dma_base = dma_base;
  8008. + dmaman->chan_available = chans_available;
  8009. + dmaman->has_feature[BCM_DMA_FEATURE_FAST_ORD] = 0x0c; /* chans 2 & 3 */
  8010. + dmaman->has_feature[BCM_DMA_FEATURE_BULK_ORD] = 0x01; /* chan 0 */
  8011. + dmaman->has_feature[BCM_DMA_FEATURE_NORMAL_ORD] = 0xfe; /* chans 1 to 7 */
  8012. + dmaman->has_feature[BCM_DMA_FEATURE_LITE_ORD] = 0x7f00; /* chans 8 to 14 */
  8013. +}
  8014. +
  8015. +static int vc_dmaman_chan_alloc(struct vc_dmaman *dmaman,
  8016. + unsigned preferred_feature_set)
  8017. +{
  8018. + u32 chans;
  8019. + int feature;
  8020. +
  8021. + chans = dmaman->chan_available;
  8022. + for (feature = 0; feature < BCM_DMA_FEATURE_COUNT; feature++)
  8023. + /* select the subset of available channels with the desired
  8024. + feature so long as some of the candidate channels have that
  8025. + feature */
  8026. + if ((preferred_feature_set & (1 << feature)) &&
  8027. + (chans & dmaman->has_feature[feature]))
  8028. + chans &= dmaman->has_feature[feature];
  8029. +
  8030. + if (chans) {
  8031. + int chan = 0;
  8032. + /* return the ordinal of the first channel in the bitmap */
  8033. + while (chans != 0 && (chans & 1) == 0) {
  8034. + chans >>= 1;
  8035. + chan++;
  8036. + }
  8037. + /* claim the channel */
  8038. + dmaman->chan_available &= ~(1 << chan);
  8039. + return chan;
  8040. + } else
  8041. + return -ENOMEM;
  8042. +}
  8043. +
  8044. +static int vc_dmaman_chan_free(struct vc_dmaman *dmaman, int chan)
  8045. +{
  8046. + if (chan < 0)
  8047. + return -EINVAL;
  8048. + else if ((1 << chan) & dmaman->chan_available)
  8049. + return -EIDRM;
  8050. + else {
  8051. + dmaman->chan_available |= (1 << chan);
  8052. + return 0;
  8053. + }
  8054. +}
  8055. +
  8056. +/*****************************************************************************\
  8057. + * *
  8058. + * DMA IRQs *
  8059. + * *
  8060. +\*****************************************************************************/
  8061. +
  8062. +static unsigned char bcm_dma_irqs[] = {
  8063. + IRQ_DMA0,
  8064. + IRQ_DMA1,
  8065. + IRQ_DMA2,
  8066. + IRQ_DMA3,
  8067. + IRQ_DMA4,
  8068. + IRQ_DMA5,
  8069. + IRQ_DMA6,
  8070. + IRQ_DMA7,
  8071. + IRQ_DMA8,
  8072. + IRQ_DMA9,
  8073. + IRQ_DMA10,
  8074. + IRQ_DMA11,
  8075. + IRQ_DMA12
  8076. +};
  8077. +
  8078. +
  8079. +/***************************************************************************** \
  8080. + * *
  8081. + * DMA Manager Monitor *
  8082. + * *
  8083. +\*****************************************************************************/
  8084. +
  8085. +static struct device *dmaman_dev; /* we assume there's only one! */
  8086. +
  8087. +extern int bcm_dma_chan_alloc(unsigned preferred_feature_set,
  8088. + void __iomem **out_dma_base, int *out_dma_irq)
  8089. +{
  8090. + if (!dmaman_dev)
  8091. + return -ENODEV;
  8092. + else {
  8093. + struct vc_dmaman *dmaman = dev_get_drvdata(dmaman_dev);
  8094. + int rc;
  8095. +
  8096. + device_lock(dmaman_dev);
  8097. + rc = vc_dmaman_chan_alloc(dmaman, preferred_feature_set);
  8098. + if (rc >= 0) {
  8099. + *out_dma_base = BCM2708_DMA_CHANIO(dmaman->dma_base,
  8100. + rc);
  8101. + *out_dma_irq = bcm_dma_irqs[rc];
  8102. + }
  8103. + device_unlock(dmaman_dev);
  8104. +
  8105. + return rc;
  8106. + }
  8107. +}
  8108. +EXPORT_SYMBOL_GPL(bcm_dma_chan_alloc);
  8109. +
  8110. +extern int bcm_dma_chan_free(int channel)
  8111. +{
  8112. + if (dmaman_dev) {
  8113. + struct vc_dmaman *dmaman = dev_get_drvdata(dmaman_dev);
  8114. + int rc;
  8115. +
  8116. + device_lock(dmaman_dev);
  8117. + rc = vc_dmaman_chan_free(dmaman, channel);
  8118. + device_unlock(dmaman_dev);
  8119. +
  8120. + return rc;
  8121. + } else
  8122. + return -ENODEV;
  8123. +}
  8124. +EXPORT_SYMBOL_GPL(bcm_dma_chan_free);
  8125. +
  8126. +static int dev_dmaman_register(const char *dev_name, struct device *dev)
  8127. +{
  8128. + int rc = dmaman_dev ? -EINVAL : 0;
  8129. + dmaman_dev = dev;
  8130. + return rc;
  8131. +}
  8132. +
  8133. +static void dev_dmaman_deregister(const char *dev_name, struct device *dev)
  8134. +{
  8135. + dmaman_dev = NULL;
  8136. +}
  8137. +
  8138. +/*****************************************************************************\
  8139. + * *
  8140. + * DMA Device *
  8141. + * *
  8142. +\*****************************************************************************/
  8143. +
  8144. +static int dmachans = -1; /* module parameter */
  8145. +
  8146. +static int bcm_dmaman_probe(struct platform_device *pdev)
  8147. +{
  8148. + int ret = 0;
  8149. + struct vc_dmaman *dmaman;
  8150. + struct resource *dma_res = NULL;
  8151. + void __iomem *dma_base = NULL;
  8152. + int have_dma_region = 0;
  8153. +
  8154. + dmaman = kzalloc(sizeof(*dmaman), GFP_KERNEL);
  8155. + if (NULL == dmaman) {
  8156. + printk(KERN_ERR DRIVER_NAME ": failed to allocate "
  8157. + "DMA management memory\n");
  8158. + ret = -ENOMEM;
  8159. + } else {
  8160. +
  8161. + dma_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  8162. + if (dma_res == NULL) {
  8163. + printk(KERN_ERR DRIVER_NAME ": failed to obtain memory "
  8164. + "resource\n");
  8165. + ret = -ENODEV;
  8166. + } else if (!request_mem_region(dma_res->start,
  8167. + resource_size(dma_res),
  8168. + DRIVER_NAME)) {
  8169. + dev_err(&pdev->dev, "cannot obtain DMA region\n");
  8170. + ret = -EBUSY;
  8171. + } else {
  8172. + have_dma_region = 1;
  8173. + dma_base = ioremap(dma_res->start,
  8174. + resource_size(dma_res));
  8175. + if (!dma_base) {
  8176. + dev_err(&pdev->dev, "cannot map DMA region\n");
  8177. + ret = -ENOMEM;
  8178. + } else {
  8179. + /* use module parameter if one was provided */
  8180. + if (dmachans > 0)
  8181. + vc_dmaman_init(dmaman, dma_base,
  8182. + dmachans);
  8183. + else
  8184. + vc_dmaman_init(dmaman, dma_base,
  8185. + DEFAULT_DMACHAN_BITMAP);
  8186. +
  8187. + platform_set_drvdata(pdev, dmaman);
  8188. + dev_dmaman_register(DRIVER_NAME, &pdev->dev);
  8189. +
  8190. + printk(KERN_INFO DRIVER_NAME ": DMA manager "
  8191. + "at %p\n", dma_base);
  8192. + }
  8193. + }
  8194. + }
  8195. + if (ret != 0) {
  8196. + if (dma_base)
  8197. + iounmap(dma_base);
  8198. + if (dma_res && have_dma_region)
  8199. + release_mem_region(dma_res->start,
  8200. + resource_size(dma_res));
  8201. + if (dmaman)
  8202. + kfree(dmaman);
  8203. + }
  8204. + return ret;
  8205. +}
  8206. +
  8207. +static int bcm_dmaman_remove(struct platform_device *pdev)
  8208. +{
  8209. + struct vc_dmaman *dmaman = platform_get_drvdata(pdev);
  8210. +
  8211. + platform_set_drvdata(pdev, NULL);
  8212. + dev_dmaman_deregister(DRIVER_NAME, &pdev->dev);
  8213. + kfree(dmaman);
  8214. +
  8215. + return 0;
  8216. +}
  8217. +
  8218. +static struct platform_driver bcm_dmaman_driver = {
  8219. + .probe = bcm_dmaman_probe,
  8220. + .remove = bcm_dmaman_remove,
  8221. +
  8222. + .driver = {
  8223. + .name = DRIVER_NAME,
  8224. + .owner = THIS_MODULE,
  8225. + },
  8226. +};
  8227. +
  8228. +/*****************************************************************************\
  8229. + * *
  8230. + * Driver init/exit *
  8231. + * *
  8232. +\*****************************************************************************/
  8233. +
  8234. +static int __init bcm_dmaman_drv_init(void)
  8235. +{
  8236. + int ret;
  8237. +
  8238. + ret = platform_driver_register(&bcm_dmaman_driver);
  8239. + if (ret != 0) {
  8240. + printk(KERN_ERR DRIVER_NAME ": failed to register "
  8241. + "on platform\n");
  8242. + }
  8243. +
  8244. + return ret;
  8245. +}
  8246. +
  8247. +static void __exit bcm_dmaman_drv_exit(void)
  8248. +{
  8249. + platform_driver_unregister(&bcm_dmaman_driver);
  8250. +}
  8251. +
  8252. +module_init(bcm_dmaman_drv_init);
  8253. +module_exit(bcm_dmaman_drv_exit);
  8254. +
  8255. +module_param(dmachans, int, 0644);
  8256. +
  8257. +MODULE_AUTHOR("Gray Girling <grayg@broadcom.com>");
  8258. +MODULE_DESCRIPTION("DMA channel manager driver");
  8259. +MODULE_LICENSE("GPL");
  8260. +
  8261. +MODULE_PARM_DESC(dmachans, "Bitmap of DMA channels available to the ARM");
  8262. diff -Nur linux-3.18.8/arch/arm/mach-bcm2708/include/mach/arm_control.h linux-rpi/arch/arm/mach-bcm2708/include/mach/arm_control.h
  8263. --- linux-3.18.8/arch/arm/mach-bcm2708/include/mach/arm_control.h 1970-01-01 01:00:00.000000000 +0100
  8264. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/arm_control.h 2015-03-05 14:40:11.153715839 +0100
  8265. @@ -0,0 +1,419 @@
  8266. +/*
  8267. + * linux/arch/arm/mach-bcm2708/arm_control.h
  8268. + *
  8269. + * Copyright (C) 2010 Broadcom
  8270. + *
  8271. + * This program is free software; you can redistribute it and/or modify
  8272. + * it under the terms of the GNU General Public License as published by
  8273. + * the Free Software Foundation; either version 2 of the License, or
  8274. + * (at your option) any later version.
  8275. + *
  8276. + * This program is distributed in the hope that it will be useful,
  8277. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8278. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8279. + * GNU General Public License for more details.
  8280. + *
  8281. + * You should have received a copy of the GNU General Public License
  8282. + * along with this program; if not, write to the Free Software
  8283. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  8284. + */
  8285. +
  8286. +#ifndef __BCM2708_ARM_CONTROL_H
  8287. +#define __BCM2708_ARM_CONTROL_H
  8288. +
  8289. +/*
  8290. + * Definitions and addresses for the ARM CONTROL logic
  8291. + * This file is manually generated.
  8292. + */
  8293. +
  8294. +#define ARM_BASE 0x7E00B000
  8295. +
  8296. +/* Basic configuration */
  8297. +#define ARM_CONTROL0 HW_REGISTER_RW(ARM_BASE+0x000)
  8298. +#define ARM_C0_SIZ128M 0x00000000
  8299. +#define ARM_C0_SIZ256M 0x00000001
  8300. +#define ARM_C0_SIZ512M 0x00000002
  8301. +#define ARM_C0_SIZ1G 0x00000003
  8302. +#define ARM_C0_BRESP0 0x00000000
  8303. +#define ARM_C0_BRESP1 0x00000004
  8304. +#define ARM_C0_BRESP2 0x00000008
  8305. +#define ARM_C0_BOOTHI 0x00000010
  8306. +#define ARM_C0_UNUSED05 0x00000020 /* free */
  8307. +#define ARM_C0_FULLPERI 0x00000040
  8308. +#define ARM_C0_UNUSED78 0x00000180 /* free */
  8309. +#define ARM_C0_JTAGMASK 0x00000E00
  8310. +#define ARM_C0_JTAGOFF 0x00000000
  8311. +#define ARM_C0_JTAGBASH 0x00000800 /* Debug on GPIO off */
  8312. +#define ARM_C0_JTAGGPIO 0x00000C00 /* Debug on GPIO on */
  8313. +#define ARM_C0_APROTMSK 0x0000F000
  8314. +#define ARM_C0_DBG0SYNC 0x00010000 /* VPU0 halt sync */
  8315. +#define ARM_C0_DBG1SYNC 0x00020000 /* VPU1 halt sync */
  8316. +#define ARM_C0_SWDBGREQ 0x00040000 /* HW debug request */
  8317. +#define ARM_C0_PASSHALT 0x00080000 /* ARM halt passed to debugger */
  8318. +#define ARM_C0_PRIO_PER 0x00F00000 /* per priority mask */
  8319. +#define ARM_C0_PRIO_L2 0x0F000000
  8320. +#define ARM_C0_PRIO_UC 0xF0000000
  8321. +
  8322. +#define ARM_C0_APROTPASS 0x0000A000 /* Translate 1:1 */
  8323. +#define ARM_C0_APROTUSER 0x00000000 /* Only user mode */
  8324. +#define ARM_C0_APROTSYST 0x0000F000 /* Only system mode */
  8325. +
  8326. +
  8327. +#define ARM_CONTROL1 HW_REGISTER_RW(ARM_BASE+0x440)
  8328. +#define ARM_C1_TIMER 0x00000001 /* re-route timer IRQ to VC */
  8329. +#define ARM_C1_MAIL 0x00000002 /* re-route Mail IRQ to VC */
  8330. +#define ARM_C1_BELL0 0x00000004 /* re-route Doorbell 0 to VC */
  8331. +#define ARM_C1_BELL1 0x00000008 /* re-route Doorbell 1 to VC */
  8332. +#define ARM_C1_PERSON 0x00000100 /* peripherals on */
  8333. +#define ARM_C1_REQSTOP 0x00000200 /* ASYNC bridge request stop */
  8334. +
  8335. +#define ARM_STATUS HW_REGISTER_RW(ARM_BASE+0x444)
  8336. +#define ARM_S_ACKSTOP 0x80000000 /* Bridge stopped */
  8337. +#define ARM_S_READPEND 0x000003FF /* pending reads counter */
  8338. +#define ARM_S_WRITPEND 0x000FFC00 /* pending writes counter */
  8339. +
  8340. +#define ARM_ERRHALT HW_REGISTER_RW(ARM_BASE+0x448)
  8341. +#define ARM_EH_PERIBURST 0x00000001 /* Burst write seen on peri bus */
  8342. +#define ARM_EH_ILLADDRS1 0x00000002 /* Address bits 25-27 error */
  8343. +#define ARM_EH_ILLADDRS2 0x00000004 /* Address bits 31-28 error */
  8344. +#define ARM_EH_VPU0HALT 0x00000008 /* VPU0 halted & in debug mode */
  8345. +#define ARM_EH_VPU1HALT 0x00000010 /* VPU1 halted & in debug mode */
  8346. +#define ARM_EH_ARMHALT 0x00000020 /* ARM in halted debug mode */
  8347. +
  8348. +#define ARM_ID_SECURE HW_REGISTER_RW(ARM_BASE+0x00C)
  8349. +#define ARM_ID HW_REGISTER_RW(ARM_BASE+0x44C)
  8350. +#define ARM_IDVAL 0x364D5241
  8351. +
  8352. +/* Translation memory */
  8353. +#define ARM_TRANSLATE HW_REGISTER_RW(ARM_BASE+0x100)
  8354. +/* 32 locations: 0x100.. 0x17F */
  8355. +/* 32 spare means we CAN go to 64 pages.... */
  8356. +
  8357. +
  8358. +/* Interrupts */
  8359. +#define ARM_IRQ_PEND0 HW_REGISTER_RW(ARM_BASE+0x200) /* Top IRQ bits */
  8360. +#define ARM_I0_TIMER 0x00000001 /* timer IRQ */
  8361. +#define ARM_I0_MAIL 0x00000002 /* Mail IRQ */
  8362. +#define ARM_I0_BELL0 0x00000004 /* Doorbell 0 */
  8363. +#define ARM_I0_BELL1 0x00000008 /* Doorbell 1 */
  8364. +#define ARM_I0_BANK1 0x00000100 /* Bank1 IRQ */
  8365. +#define ARM_I0_BANK2 0x00000200 /* Bank2 IRQ */
  8366. +
  8367. +#define ARM_IRQ_PEND1 HW_REGISTER_RW(ARM_BASE+0x204) /* All bank1 IRQ bits */
  8368. +/* todo: all I1_interrupt sources */
  8369. +#define ARM_IRQ_PEND2 HW_REGISTER_RW(ARM_BASE+0x208) /* All bank2 IRQ bits */
  8370. +/* todo: all I2_interrupt sources */
  8371. +
  8372. +#define ARM_IRQ_FAST HW_REGISTER_RW(ARM_BASE+0x20C) /* FIQ control */
  8373. +#define ARM_IF_INDEX 0x0000007F /* FIQ select */
  8374. +#define ARM_IF_ENABLE 0x00000080 /* FIQ enable */
  8375. +#define ARM_IF_VCMASK 0x0000003F /* FIQ = (index from VC source) */
  8376. +#define ARM_IF_TIMER 0x00000040 /* FIQ = ARM timer */
  8377. +#define ARM_IF_MAIL 0x00000041 /* FIQ = ARM Mail */
  8378. +#define ARM_IF_BELL0 0x00000042 /* FIQ = ARM Doorbell 0 */
  8379. +#define ARM_IF_BELL1 0x00000043 /* FIQ = ARM Doorbell 1 */
  8380. +#define ARM_IF_VP0HALT 0x00000044 /* FIQ = VPU0 Halt seen */
  8381. +#define ARM_IF_VP1HALT 0x00000045 /* FIQ = VPU1 Halt seen */
  8382. +#define ARM_IF_ILLEGAL 0x00000046 /* FIQ = Illegal access seen */
  8383. +
  8384. +#define ARM_IRQ_ENBL1 HW_REGISTER_RW(ARM_BASE+0x210) /* Bank1 enable bits */
  8385. +#define ARM_IRQ_ENBL2 HW_REGISTER_RW(ARM_BASE+0x214) /* Bank2 enable bits */
  8386. +#define ARM_IRQ_ENBL3 HW_REGISTER_RW(ARM_BASE+0x218) /* ARM irqs enable bits */
  8387. +#define ARM_IRQ_DIBL1 HW_REGISTER_RW(ARM_BASE+0x21C) /* Bank1 disable bits */
  8388. +#define ARM_IRQ_DIBL2 HW_REGISTER_RW(ARM_BASE+0x220) /* Bank2 disable bits */
  8389. +#define ARM_IRQ_DIBL3 HW_REGISTER_RW(ARM_BASE+0x224) /* ARM irqs disable bits */
  8390. +#define ARM_IE_TIMER 0x00000001 /* Timer IRQ */
  8391. +#define ARM_IE_MAIL 0x00000002 /* Mail IRQ */
  8392. +#define ARM_IE_BELL0 0x00000004 /* Doorbell 0 */
  8393. +#define ARM_IE_BELL1 0x00000008 /* Doorbell 1 */
  8394. +#define ARM_IE_VP0HALT 0x00000010 /* VPU0 Halt */
  8395. +#define ARM_IE_VP1HALT 0x00000020 /* VPU1 Halt */
  8396. +#define ARM_IE_ILLEGAL 0x00000040 /* Illegal access seen */
  8397. +
  8398. +/* Timer */
  8399. +/* For reg. fields see sp804 spec. */
  8400. +#define ARM_T_LOAD HW_REGISTER_RW(ARM_BASE+0x400)
  8401. +#define ARM_T_VALUE HW_REGISTER_RW(ARM_BASE+0x404)
  8402. +#define ARM_T_CONTROL HW_REGISTER_RW(ARM_BASE+0x408)
  8403. +#define ARM_T_IRQCNTL HW_REGISTER_RW(ARM_BASE+0x40C)
  8404. +#define ARM_T_RAWIRQ HW_REGISTER_RW(ARM_BASE+0x410)
  8405. +#define ARM_T_MSKIRQ HW_REGISTER_RW(ARM_BASE+0x414)
  8406. +#define ARM_T_RELOAD HW_REGISTER_RW(ARM_BASE+0x418)
  8407. +#define ARM_T_PREDIV HW_REGISTER_RW(ARM_BASE+0x41c)
  8408. +#define ARM_T_FREECNT HW_REGISTER_RW(ARM_BASE+0x420)
  8409. +
  8410. +#define TIMER_CTRL_ONESHOT (1 << 0)
  8411. +#define TIMER_CTRL_32BIT (1 << 1)
  8412. +#define TIMER_CTRL_DIV1 (0 << 2)
  8413. +#define TIMER_CTRL_DIV16 (1 << 2)
  8414. +#define TIMER_CTRL_DIV256 (2 << 2)
  8415. +#define TIMER_CTRL_IE (1 << 5)
  8416. +#define TIMER_CTRL_PERIODIC (1 << 6)
  8417. +#define TIMER_CTRL_ENABLE (1 << 7)
  8418. +#define TIMER_CTRL_DBGHALT (1 << 8)
  8419. +#define TIMER_CTRL_ENAFREE (1 << 9)
  8420. +#define TIMER_CTRL_FREEDIV_SHIFT 16)
  8421. +#define TIMER_CTRL_FREEDIV_MASK 0xff
  8422. +
  8423. +/* Semaphores, Doorbells, Mailboxes */
  8424. +#define ARM_SBM_OWN0 (ARM_BASE+0x800)
  8425. +#define ARM_SBM_OWN1 (ARM_BASE+0x900)
  8426. +#define ARM_SBM_OWN2 (ARM_BASE+0xA00)
  8427. +#define ARM_SBM_OWN3 (ARM_BASE+0xB00)
  8428. +
  8429. +/* MAILBOXES
  8430. + * Register flags are common across all
  8431. + * owner registers. See end of this section
  8432. + *
  8433. + * Semaphores, Doorbells, Mailboxes Owner 0
  8434. + *
  8435. + */
  8436. +
  8437. +#define ARM_0_SEMS HW_REGISTER_RW(ARM_SBM_OWN0+0x00)
  8438. +#define ARM_0_SEM0 HW_REGISTER_RW(ARM_SBM_OWN0+0x00)
  8439. +#define ARM_0_SEM1 HW_REGISTER_RW(ARM_SBM_OWN0+0x04)
  8440. +#define ARM_0_SEM2 HW_REGISTER_RW(ARM_SBM_OWN0+0x08)
  8441. +#define ARM_0_SEM3 HW_REGISTER_RW(ARM_SBM_OWN0+0x0C)
  8442. +#define ARM_0_SEM4 HW_REGISTER_RW(ARM_SBM_OWN0+0x10)
  8443. +#define ARM_0_SEM5 HW_REGISTER_RW(ARM_SBM_OWN0+0x14)
  8444. +#define ARM_0_SEM6 HW_REGISTER_RW(ARM_SBM_OWN0+0x18)
  8445. +#define ARM_0_SEM7 HW_REGISTER_RW(ARM_SBM_OWN0+0x1C)
  8446. +#define ARM_0_BELL0 HW_REGISTER_RW(ARM_SBM_OWN0+0x40)
  8447. +#define ARM_0_BELL1 HW_REGISTER_RW(ARM_SBM_OWN0+0x44)
  8448. +#define ARM_0_BELL2 HW_REGISTER_RW(ARM_SBM_OWN0+0x48)
  8449. +#define ARM_0_BELL3 HW_REGISTER_RW(ARM_SBM_OWN0+0x4C)
  8450. +/* MAILBOX 0 access in Owner 0 area */
  8451. +/* Some addresses should ONLY be used by owner 0 */
  8452. +#define ARM_0_MAIL0_WRT HW_REGISTER_RW(ARM_SBM_OWN0+0x80) /* .. 0x8C (4 locations) */
  8453. +#define ARM_0_MAIL0_RD HW_REGISTER_RW(ARM_SBM_OWN0+0x80) /* .. 0x8C (4 locations) Normal read */
  8454. +#define ARM_0_MAIL0_POL HW_REGISTER_RW(ARM_SBM_OWN0+0x90) /* none-pop read */
  8455. +#define ARM_0_MAIL0_SND HW_REGISTER_RW(ARM_SBM_OWN0+0x94) /* Sender read (only LS 2 bits) */
  8456. +#define ARM_0_MAIL0_STA HW_REGISTER_RW(ARM_SBM_OWN0+0x98) /* Status read */
  8457. +#define ARM_0_MAIL0_CNF HW_REGISTER_RW(ARM_SBM_OWN0+0x9C) /* Config read/write */
  8458. +/* MAILBOX 1 access in Owner 0 area */
  8459. +/* Owner 0 should only WRITE to this mailbox */
  8460. +#define ARM_0_MAIL1_WRT HW_REGISTER_RW(ARM_SBM_OWN0+0xA0) /* .. 0xAC (4 locations) */
  8461. +/*#define ARM_0_MAIL1_RD HW_REGISTER_RW(ARM_SBM_OWN0+0xA0) */ /* DO NOT USE THIS !!!!! */
  8462. +/*#define ARM_0_MAIL1_POL HW_REGISTER_RW(ARM_SBM_OWN0+0xB0) */ /* DO NOT USE THIS !!!!! */
  8463. +/*#define ARM_0_MAIL1_SND HW_REGISTER_RW(ARM_SBM_OWN0+0xB4) */ /* DO NOT USE THIS !!!!! */
  8464. +#define ARM_0_MAIL1_STA HW_REGISTER_RW(ARM_SBM_OWN0+0xB8) /* Status read */
  8465. +/*#define ARM_0_MAIL1_CNF HW_REGISTER_RW(ARM_SBM_OWN0+0xBC) */ /* DO NOT USE THIS !!!!! */
  8466. +/* General SEM, BELL, MAIL config/status */
  8467. +#define ARM_0_SEMCLRDBG HW_REGISTER_RW(ARM_SBM_OWN0+0xE0) /* semaphore clear/debug register */
  8468. +#define ARM_0_BELLCLRDBG HW_REGISTER_RW(ARM_SBM_OWN0+0xE4) /* Doorbells clear/debug register */
  8469. +#define ARM_0_ALL_IRQS HW_REGISTER_RW(ARM_SBM_OWN0+0xF8) /* ALL interrupts */
  8470. +#define ARM_0_MY_IRQS HW_REGISTER_RW(ARM_SBM_OWN0+0xFC) /* IRQS pending for owner 0 */
  8471. +
  8472. +/* Semaphores, Doorbells, Mailboxes Owner 1 */
  8473. +#define ARM_1_SEMS HW_REGISTER_RW(ARM_SBM_OWN1+0x00)
  8474. +#define ARM_1_SEM0 HW_REGISTER_RW(ARM_SBM_OWN1+0x00)
  8475. +#define ARM_1_SEM1 HW_REGISTER_RW(ARM_SBM_OWN1+0x04)
  8476. +#define ARM_1_SEM2 HW_REGISTER_RW(ARM_SBM_OWN1+0x08)
  8477. +#define ARM_1_SEM3 HW_REGISTER_RW(ARM_SBM_OWN1+0x0C)
  8478. +#define ARM_1_SEM4 HW_REGISTER_RW(ARM_SBM_OWN1+0x10)
  8479. +#define ARM_1_SEM5 HW_REGISTER_RW(ARM_SBM_OWN1+0x14)
  8480. +#define ARM_1_SEM6 HW_REGISTER_RW(ARM_SBM_OWN1+0x18)
  8481. +#define ARM_1_SEM7 HW_REGISTER_RW(ARM_SBM_OWN1+0x1C)
  8482. +#define ARM_1_BELL0 HW_REGISTER_RW(ARM_SBM_OWN1+0x40)
  8483. +#define ARM_1_BELL1 HW_REGISTER_RW(ARM_SBM_OWN1+0x44)
  8484. +#define ARM_1_BELL2 HW_REGISTER_RW(ARM_SBM_OWN1+0x48)
  8485. +#define ARM_1_BELL3 HW_REGISTER_RW(ARM_SBM_OWN1+0x4C)
  8486. +/* MAILBOX 0 access in Owner 0 area */
  8487. +/* Owner 1 should only WRITE to this mailbox */
  8488. +#define ARM_1_MAIL0_WRT HW_REGISTER_RW(ARM_SBM_OWN1+0x80) /* .. 0x8C (4 locations) */
  8489. +/*#define ARM_1_MAIL0_RD HW_REGISTER_RW(ARM_SBM_OWN1+0x80) */ /* DO NOT USE THIS !!!!! */
  8490. +/*#define ARM_1_MAIL0_POL HW_REGISTER_RW(ARM_SBM_OWN1+0x90) */ /* DO NOT USE THIS !!!!! */
  8491. +/*#define ARM_1_MAIL0_SND HW_REGISTER_RW(ARM_SBM_OWN1+0x94) */ /* DO NOT USE THIS !!!!! */
  8492. +#define ARM_1_MAIL0_STA HW_REGISTER_RW(ARM_SBM_OWN1+0x98) /* Status read */
  8493. +/*#define ARM_1_MAIL0_CNF HW_REGISTER_RW(ARM_SBM_OWN1+0x9C) */ /* DO NOT USE THIS !!!!! */
  8494. +/* MAILBOX 1 access in Owner 0 area */
  8495. +#define ARM_1_MAIL1_WRT HW_REGISTER_RW(ARM_SBM_OWN1+0xA0) /* .. 0xAC (4 locations) */
  8496. +#define ARM_1_MAIL1_RD HW_REGISTER_RW(ARM_SBM_OWN1+0xA0) /* .. 0xAC (4 locations) Normal read */
  8497. +#define ARM_1_MAIL1_POL HW_REGISTER_RW(ARM_SBM_OWN1+0xB0) /* none-pop read */
  8498. +#define ARM_1_MAIL1_SND HW_REGISTER_RW(ARM_SBM_OWN1+0xB4) /* Sender read (only LS 2 bits) */
  8499. +#define ARM_1_MAIL1_STA HW_REGISTER_RW(ARM_SBM_OWN1+0xB8) /* Status read */
  8500. +#define ARM_1_MAIL1_CNF HW_REGISTER_RW(ARM_SBM_OWN1+0xBC)
  8501. +/* General SEM, BELL, MAIL config/status */
  8502. +#define ARM_1_SEMCLRDBG HW_REGISTER_RW(ARM_SBM_OWN1+0xE0) /* semaphore clear/debug register */
  8503. +#define ARM_1_BELLCLRDBG HW_REGISTER_RW(ARM_SBM_OWN1+0xE4) /* Doorbells clear/debug register */
  8504. +#define ARM_1_MY_IRQS HW_REGISTER_RW(ARM_SBM_OWN1+0xFC) /* IRQS pending for owner 1 */
  8505. +#define ARM_1_ALL_IRQS HW_REGISTER_RW(ARM_SBM_OWN1+0xF8) /* ALL interrupts */
  8506. +
  8507. +/* Semaphores, Doorbells, Mailboxes Owner 2 */
  8508. +#define ARM_2_SEMS HW_REGISTER_RW(ARM_SBM_OWN2+0x00)
  8509. +#define ARM_2_SEM0 HW_REGISTER_RW(ARM_SBM_OWN2+0x00)
  8510. +#define ARM_2_SEM1 HW_REGISTER_RW(ARM_SBM_OWN2+0x04)
  8511. +#define ARM_2_SEM2 HW_REGISTER_RW(ARM_SBM_OWN2+0x08)
  8512. +#define ARM_2_SEM3 HW_REGISTER_RW(ARM_SBM_OWN2+0x0C)
  8513. +#define ARM_2_SEM4 HW_REGISTER_RW(ARM_SBM_OWN2+0x10)
  8514. +#define ARM_2_SEM5 HW_REGISTER_RW(ARM_SBM_OWN2+0x14)
  8515. +#define ARM_2_SEM6 HW_REGISTER_RW(ARM_SBM_OWN2+0x18)
  8516. +#define ARM_2_SEM7 HW_REGISTER_RW(ARM_SBM_OWN2+0x1C)
  8517. +#define ARM_2_BELL0 HW_REGISTER_RW(ARM_SBM_OWN2+0x40)
  8518. +#define ARM_2_BELL1 HW_REGISTER_RW(ARM_SBM_OWN2+0x44)
  8519. +#define ARM_2_BELL2 HW_REGISTER_RW(ARM_SBM_OWN2+0x48)
  8520. +#define ARM_2_BELL3 HW_REGISTER_RW(ARM_SBM_OWN2+0x4C)
  8521. +/* MAILBOX 0 access in Owner 2 area */
  8522. +/* Owner 2 should only WRITE to this mailbox */
  8523. +#define ARM_2_MAIL0_WRT HW_REGISTER_RW(ARM_SBM_OWN2+0x80) /* .. 0x8C (4 locations) */
  8524. +/*#define ARM_2_MAIL0_RD HW_REGISTER_RW(ARM_SBM_OWN2+0x80) */ /* DO NOT USE THIS !!!!! */
  8525. +/*#define ARM_2_MAIL0_POL HW_REGISTER_RW(ARM_SBM_OWN2+0x90) */ /* DO NOT USE THIS !!!!! */
  8526. +/*#define ARM_2_MAIL0_SND HW_REGISTER_RW(ARM_SBM_OWN2+0x94) */ /* DO NOT USE THIS !!!!! */
  8527. +#define ARM_2_MAIL0_STA HW_REGISTER_RW(ARM_SBM_OWN2+0x98) /* Status read */
  8528. +/*#define ARM_2_MAIL0_CNF HW_REGISTER_RW(ARM_SBM_OWN2+0x9C) */ /* DO NOT USE THIS !!!!! */
  8529. +/* MAILBOX 1 access in Owner 2 area */
  8530. +/* Owner 2 should only WRITE to this mailbox */
  8531. +#define ARM_2_MAIL1_WRT HW_REGISTER_RW(ARM_SBM_OWN2+0xA0) /* .. 0xAC (4 locations) */
  8532. +/*#define ARM_2_MAIL1_RD HW_REGISTER_RW(ARM_SBM_OWN2+0xA0) */ /* DO NOT USE THIS !!!!! */
  8533. +/*#define ARM_2_MAIL1_POL HW_REGISTER_RW(ARM_SBM_OWN2+0xB0) */ /* DO NOT USE THIS !!!!! */
  8534. +/*#define ARM_2_MAIL1_SND HW_REGISTER_RW(ARM_SBM_OWN2+0xB4) */ /* DO NOT USE THIS !!!!! */
  8535. +#define ARM_2_MAIL1_STA HW_REGISTER_RW(ARM_SBM_OWN2+0xB8) /* Status read */
  8536. +/*#define ARM_2_MAIL1_CNF HW_REGISTER_RW(ARM_SBM_OWN2+0xBC) */ /* DO NOT USE THIS !!!!! */
  8537. +/* General SEM, BELL, MAIL config/status */
  8538. +#define ARM_2_SEMCLRDBG HW_REGISTER_RW(ARM_SBM_OWN2+0xE0) /* semaphore clear/debug register */
  8539. +#define ARM_2_BELLCLRDBG HW_REGISTER_RW(ARM_SBM_OWN2+0xE4) /* Doorbells clear/debug register */
  8540. +#define ARM_2_MY_IRQS HW_REGISTER_RW(ARM_SBM_OWN2+0xFC) /* IRQS pending for owner 2 */
  8541. +#define ARM_2_ALL_IRQS HW_REGISTER_RW(ARM_SBM_OWN2+0xF8) /* ALL interrupts */
  8542. +
  8543. +/* Semaphores, Doorbells, Mailboxes Owner 3 */
  8544. +#define ARM_3_SEMS HW_REGISTER_RW(ARM_SBM_OWN3+0x00)
  8545. +#define ARM_3_SEM0 HW_REGISTER_RW(ARM_SBM_OWN3+0x00)
  8546. +#define ARM_3_SEM1 HW_REGISTER_RW(ARM_SBM_OWN3+0x04)
  8547. +#define ARM_3_SEM2 HW_REGISTER_RW(ARM_SBM_OWN3+0x08)
  8548. +#define ARM_3_SEM3 HW_REGISTER_RW(ARM_SBM_OWN3+0x0C)
  8549. +#define ARM_3_SEM4 HW_REGISTER_RW(ARM_SBM_OWN3+0x10)
  8550. +#define ARM_3_SEM5 HW_REGISTER_RW(ARM_SBM_OWN3+0x14)
  8551. +#define ARM_3_SEM6 HW_REGISTER_RW(ARM_SBM_OWN3+0x18)
  8552. +#define ARM_3_SEM7 HW_REGISTER_RW(ARM_SBM_OWN3+0x1C)
  8553. +#define ARM_3_BELL0 HW_REGISTER_RW(ARM_SBM_OWN3+0x40)
  8554. +#define ARM_3_BELL1 HW_REGISTER_RW(ARM_SBM_OWN3+0x44)
  8555. +#define ARM_3_BELL2 HW_REGISTER_RW(ARM_SBM_OWN3+0x48)
  8556. +#define ARM_3_BELL3 HW_REGISTER_RW(ARM_SBM_OWN3+0x4C)
  8557. +/* MAILBOX 0 access in Owner 3 area */
  8558. +/* Owner 3 should only WRITE to this mailbox */
  8559. +#define ARM_3_MAIL0_WRT HW_REGISTER_RW(ARM_SBM_OWN3+0x80) /* .. 0x8C (4 locations) */
  8560. +/*#define ARM_3_MAIL0_RD HW_REGISTER_RW(ARM_SBM_OWN3+0x80) */ /* DO NOT USE THIS !!!!! */
  8561. +/*#define ARM_3_MAIL0_POL HW_REGISTER_RW(ARM_SBM_OWN3+0x90) */ /* DO NOT USE THIS !!!!! */
  8562. +/*#define ARM_3_MAIL0_SND HW_REGISTER_RW(ARM_SBM_OWN3+0x94) */ /* DO NOT USE THIS !!!!! */
  8563. +#define ARM_3_MAIL0_STA HW_REGISTER_RW(ARM_SBM_OWN3+0x98) /* Status read */
  8564. +/*#define ARM_3_MAIL0_CNF HW_REGISTER_RW(ARM_SBM_OWN3+0x9C) */ /* DO NOT USE THIS !!!!! */
  8565. +/* MAILBOX 1 access in Owner 3 area */
  8566. +/* Owner 3 should only WRITE to this mailbox */
  8567. +#define ARM_3_MAIL1_WRT HW_REGISTER_RW(ARM_SBM_OWN3+0xA0) /* .. 0xAC (4 locations) */
  8568. +/*#define ARM_3_MAIL1_RD HW_REGISTER_RW(ARM_SBM_OWN3+0xA0) */ /* DO NOT USE THIS !!!!! */
  8569. +/*#define ARM_3_MAIL1_POL HW_REGISTER_RW(ARM_SBM_OWN3+0xB0) */ /* DO NOT USE THIS !!!!! */
  8570. +/*#define ARM_3_MAIL1_SND HW_REGISTER_RW(ARM_SBM_OWN3+0xB4) */ /* DO NOT USE THIS !!!!! */
  8571. +#define ARM_3_MAIL1_STA HW_REGISTER_RW(ARM_SBM_OWN3+0xB8) /* Status read */
  8572. +/*#define ARM_3_MAIL1_CNF HW_REGISTER_RW(ARM_SBM_OWN3+0xBC) */ /* DO NOT USE THIS !!!!! */
  8573. +/* General SEM, BELL, MAIL config/status */
  8574. +#define ARM_3_SEMCLRDBG HW_REGISTER_RW(ARM_SBM_OWN3+0xE0) /* semaphore clear/debug register */
  8575. +#define ARM_3_BELLCLRDBG HW_REGISTER_RW(ARM_SBM_OWN3+0xE4) /* Doorbells clear/debug register */
  8576. +#define ARM_3_MY_IRQS HW_REGISTER_RW(ARM_SBM_OWN3+0xFC) /* IRQS pending for owner 3 */
  8577. +#define ARM_3_ALL_IRQS HW_REGISTER_RW(ARM_SBM_OWN3+0xF8) /* ALL interrupts */
  8578. +
  8579. +
  8580. +
  8581. +/* Mailbox flags. Valid for all owners */
  8582. +
  8583. +/* Mailbox status register (...0x98) */
  8584. +#define ARM_MS_FULL 0x80000000
  8585. +#define ARM_MS_EMPTY 0x40000000
  8586. +#define ARM_MS_LEVEL 0x400000FF /* Max. value depdnds on mailbox depth parameter */
  8587. +
  8588. +/* MAILBOX config/status register (...0x9C) */
  8589. +/* ANY write to this register clears the error bits! */
  8590. +#define ARM_MC_IHAVEDATAIRQEN 0x00000001 /* mailbox irq enable: has data */
  8591. +#define ARM_MC_IHAVESPACEIRQEN 0x00000002 /* mailbox irq enable: has space */
  8592. +#define ARM_MC_OPPISEMPTYIRQEN 0x00000004 /* mailbox irq enable: Opp. is empty */
  8593. +#define ARM_MC_MAIL_CLEAR 0x00000008 /* mailbox clear write 1, then 0 */
  8594. +#define ARM_MC_IHAVEDATAIRQPEND 0x00000010 /* mailbox irq pending: has space */
  8595. +#define ARM_MC_IHAVESPACEIRQPEND 0x00000020 /* mailbox irq pending: Opp. is empty */
  8596. +#define ARM_MC_OPPISEMPTYIRQPEND 0x00000040 /* mailbox irq pending */
  8597. +/* Bit 7 is unused */
  8598. +#define ARM_MC_ERRNOOWN 0x00000100 /* error : none owner read from mailbox */
  8599. +#define ARM_MC_ERROVERFLW 0x00000200 /* error : write to fill mailbox */
  8600. +#define ARM_MC_ERRUNDRFLW 0x00000400 /* error : read from empty mailbox */
  8601. +
  8602. +/* Semaphore clear/debug register (...0xE0) */
  8603. +#define ARM_SD_OWN0 0x00000003 /* Owner of sem 0 */
  8604. +#define ARM_SD_OWN1 0x0000000C /* Owner of sem 1 */
  8605. +#define ARM_SD_OWN2 0x00000030 /* Owner of sem 2 */
  8606. +#define ARM_SD_OWN3 0x000000C0 /* Owner of sem 3 */
  8607. +#define ARM_SD_OWN4 0x00000300 /* Owner of sem 4 */
  8608. +#define ARM_SD_OWN5 0x00000C00 /* Owner of sem 5 */
  8609. +#define ARM_SD_OWN6 0x00003000 /* Owner of sem 6 */
  8610. +#define ARM_SD_OWN7 0x0000C000 /* Owner of sem 7 */
  8611. +#define ARM_SD_SEM0 0x00010000 /* Status of sem 0 */
  8612. +#define ARM_SD_SEM1 0x00020000 /* Status of sem 1 */
  8613. +#define ARM_SD_SEM2 0x00040000 /* Status of sem 2 */
  8614. +#define ARM_SD_SEM3 0x00080000 /* Status of sem 3 */
  8615. +#define ARM_SD_SEM4 0x00100000 /* Status of sem 4 */
  8616. +#define ARM_SD_SEM5 0x00200000 /* Status of sem 5 */
  8617. +#define ARM_SD_SEM6 0x00400000 /* Status of sem 6 */
  8618. +#define ARM_SD_SEM7 0x00800000 /* Status of sem 7 */
  8619. +
  8620. +/* Doorbells clear/debug register (...0xE4) */
  8621. +#define ARM_BD_OWN0 0x00000003 /* Owner of doorbell 0 */
  8622. +#define ARM_BD_OWN1 0x0000000C /* Owner of doorbell 1 */
  8623. +#define ARM_BD_OWN2 0x00000030 /* Owner of doorbell 2 */
  8624. +#define ARM_BD_OWN3 0x000000C0 /* Owner of doorbell 3 */
  8625. +#define ARM_BD_BELL0 0x00000100 /* Status of doorbell 0 */
  8626. +#define ARM_BD_BELL1 0x00000200 /* Status of doorbell 1 */
  8627. +#define ARM_BD_BELL2 0x00000400 /* Status of doorbell 2 */
  8628. +#define ARM_BD_BELL3 0x00000800 /* Status of doorbell 3 */
  8629. +
  8630. +/* MY IRQS register (...0xF8) */
  8631. +#define ARM_MYIRQ_BELL 0x00000001 /* This owner has a doorbell IRQ */
  8632. +#define ARM_MYIRQ_MAIL 0x00000002 /* This owner has a mailbox IRQ */
  8633. +
  8634. +/* ALL IRQS register (...0xF8) */
  8635. +#define ARM_AIS_BELL0 0x00000001 /* Doorbell 0 IRQ pending */
  8636. +#define ARM_AIS_BELL1 0x00000002 /* Doorbell 1 IRQ pending */
  8637. +#define ARM_AIS_BELL2 0x00000004 /* Doorbell 2 IRQ pending */
  8638. +#define ARM_AIS_BELL3 0x00000008 /* Doorbell 3 IRQ pending */
  8639. +#define ARM_AIS0_HAVEDATA 0x00000010 /* MAIL 0 has data IRQ pending */
  8640. +#define ARM_AIS0_HAVESPAC 0x00000020 /* MAIL 0 has space IRQ pending */
  8641. +#define ARM_AIS0_OPPEMPTY 0x00000040 /* MAIL 0 opposite is empty IRQ */
  8642. +#define ARM_AIS1_HAVEDATA 0x00000080 /* MAIL 1 has data IRQ pending */
  8643. +#define ARM_AIS1_HAVESPAC 0x00000100 /* MAIL 1 has space IRQ pending */
  8644. +#define ARM_AIS1_OPPEMPTY 0x00000200 /* MAIL 1 opposite is empty IRQ */
  8645. +/* Note that bell-0, bell-1 and MAIL0 IRQ go only to the ARM */
  8646. +/* Whilst that bell-2, bell-3 and MAIL1 IRQ go only to the VC */
  8647. +/* */
  8648. +/* ARM JTAG BASH */
  8649. +/* */
  8650. +#define AJB_BASE 0x7e2000c0
  8651. +
  8652. +#define AJBCONF HW_REGISTER_RW(AJB_BASE+0x00)
  8653. +#define AJB_BITS0 0x000000
  8654. +#define AJB_BITS4 0x000004
  8655. +#define AJB_BITS8 0x000008
  8656. +#define AJB_BITS12 0x00000C
  8657. +#define AJB_BITS16 0x000010
  8658. +#define AJB_BITS20 0x000014
  8659. +#define AJB_BITS24 0x000018
  8660. +#define AJB_BITS28 0x00001C
  8661. +#define AJB_BITS32 0x000020
  8662. +#define AJB_BITS34 0x000022
  8663. +#define AJB_OUT_MS 0x000040
  8664. +#define AJB_OUT_LS 0x000000
  8665. +#define AJB_INV_CLK 0x000080
  8666. +#define AJB_D0_RISE 0x000100
  8667. +#define AJB_D0_FALL 0x000000
  8668. +#define AJB_D1_RISE 0x000200
  8669. +#define AJB_D1_FALL 0x000000
  8670. +#define AJB_IN_RISE 0x000400
  8671. +#define AJB_IN_FALL 0x000000
  8672. +#define AJB_ENABLE 0x000800
  8673. +#define AJB_HOLD0 0x000000
  8674. +#define AJB_HOLD1 0x001000
  8675. +#define AJB_HOLD2 0x002000
  8676. +#define AJB_HOLD3 0x003000
  8677. +#define AJB_RESETN 0x004000
  8678. +#define AJB_CLKSHFT 16
  8679. +#define AJB_BUSY 0x80000000
  8680. +#define AJBTMS HW_REGISTER_RW(AJB_BASE+0x04)
  8681. +#define AJBTDI HW_REGISTER_RW(AJB_BASE+0x08)
  8682. +#define AJBTDO HW_REGISTER_RW(AJB_BASE+0x0c)
  8683. +
  8684. +#endif
  8685. diff -Nur linux-3.18.8/arch/arm/mach-bcm2708/include/mach/arm_power.h linux-rpi/arch/arm/mach-bcm2708/include/mach/arm_power.h
  8686. --- linux-3.18.8/arch/arm/mach-bcm2708/include/mach/arm_power.h 1970-01-01 01:00:00.000000000 +0100
  8687. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/arm_power.h 2015-03-05 14:40:11.153715839 +0100
  8688. @@ -0,0 +1,62 @@
  8689. +/*
  8690. + * linux/arch/arm/mach-bcm2708/include/mach/arm_power.h
  8691. + *
  8692. + * Copyright (C) 2010 Broadcom
  8693. + *
  8694. + * This program is free software; you can redistribute it and/or modify
  8695. + * it under the terms of the GNU General Public License as published by
  8696. + * the Free Software Foundation; either version 2 of the License, or
  8697. + * (at your option) any later version.
  8698. + *
  8699. + * This program is distributed in the hope that it will be useful,
  8700. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8701. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8702. + * GNU General Public License for more details.
  8703. + *
  8704. + * You should have received a copy of the GNU General Public License
  8705. + * along with this program; if not, write to the Free Software
  8706. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  8707. + */
  8708. +
  8709. +#ifndef _ARM_POWER_H
  8710. +#define _ARM_POWER_H
  8711. +
  8712. +/* Use meaningful names on each side */
  8713. +#ifdef __VIDEOCORE__
  8714. +#define PREFIX(x) ARM_##x
  8715. +#else
  8716. +#define PREFIX(x) BCM_##x
  8717. +#endif
  8718. +
  8719. +enum {
  8720. + PREFIX(POWER_SDCARD_BIT),
  8721. + PREFIX(POWER_UART_BIT),
  8722. + PREFIX(POWER_MINIUART_BIT),
  8723. + PREFIX(POWER_USB_BIT),
  8724. + PREFIX(POWER_I2C0_BIT),
  8725. + PREFIX(POWER_I2C1_BIT),
  8726. + PREFIX(POWER_I2C2_BIT),
  8727. + PREFIX(POWER_SPI_BIT),
  8728. + PREFIX(POWER_CCP2TX_BIT),
  8729. + PREFIX(POWER_DSI_BIT),
  8730. +
  8731. + PREFIX(POWER_MAX)
  8732. +};
  8733. +
  8734. +enum {
  8735. + PREFIX(POWER_SDCARD) = (1 << PREFIX(POWER_SDCARD_BIT)),
  8736. + PREFIX(POWER_UART) = (1 << PREFIX(POWER_UART_BIT)),
  8737. + PREFIX(POWER_MINIUART) = (1 << PREFIX(POWER_MINIUART_BIT)),
  8738. + PREFIX(POWER_USB) = (1 << PREFIX(POWER_USB_BIT)),
  8739. + PREFIX(POWER_I2C0) = (1 << PREFIX(POWER_I2C0_BIT)),
  8740. + PREFIX(POWER_I2C1_MASK) = (1 << PREFIX(POWER_I2C1_BIT)),
  8741. + PREFIX(POWER_I2C2_MASK) = (1 << PREFIX(POWER_I2C2_BIT)),
  8742. + PREFIX(POWER_SPI_MASK) = (1 << PREFIX(POWER_SPI_BIT)),
  8743. + PREFIX(POWER_CCP2TX_MASK) = (1 << PREFIX(POWER_CCP2TX_BIT)),
  8744. + PREFIX(POWER_DSI) = (1 << PREFIX(POWER_DSI_BIT)),
  8745. +
  8746. + PREFIX(POWER_MASK) = (1 << PREFIX(POWER_MAX)) - 1,
  8747. + PREFIX(POWER_NONE) = 0
  8748. +};
  8749. +
  8750. +#endif
  8751. diff -Nur linux-3.18.8/arch/arm/mach-bcm2708/include/mach/clkdev.h linux-rpi/arch/arm/mach-bcm2708/include/mach/clkdev.h
  8752. --- linux-3.18.8/arch/arm/mach-bcm2708/include/mach/clkdev.h 1970-01-01 01:00:00.000000000 +0100
  8753. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/clkdev.h 2015-03-05 14:40:11.153715839 +0100
  8754. @@ -0,0 +1,7 @@
  8755. +#ifndef __ASM_MACH_CLKDEV_H
  8756. +#define __ASM_MACH_CLKDEV_H
  8757. +
  8758. +#define __clk_get(clk) ({ 1; })
  8759. +#define __clk_put(clk) do { } while (0)
  8760. +
  8761. +#endif
  8762. diff -Nur linux-3.18.8/arch/arm/mach-bcm2708/include/mach/debug-macro.S linux-rpi/arch/arm/mach-bcm2708/include/mach/debug-macro.S
  8763. --- linux-3.18.8/arch/arm/mach-bcm2708/include/mach/debug-macro.S 1970-01-01 01:00:00.000000000 +0100
  8764. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/debug-macro.S 2015-03-05 14:40:11.153715839 +0100
  8765. @@ -0,0 +1,22 @@
  8766. +/* arch/arm/mach-bcm2708/include/mach/debug-macro.S
  8767. + *
  8768. + * Debugging macro include header
  8769. + *
  8770. + * Copyright (C) 2010 Broadcom
  8771. + * Copyright (C) 1994-1999 Russell King
  8772. + * Moved from linux/arch/arm/kernel/debug.S by Ben Dooks
  8773. + *
  8774. + * This program is free software; you can redistribute it and/or modify
  8775. + * it under the terms of the GNU General Public License version 2 as
  8776. + * published by the Free Software Foundation.
  8777. + *
  8778. +*/
  8779. +
  8780. +#include <mach/platform.h>
  8781. +
  8782. + .macro addruart, rp, rv, tmp
  8783. + ldr \rp, =UART0_BASE
  8784. + ldr \rv, =IO_ADDRESS(UART0_BASE)
  8785. + .endm
  8786. +
  8787. +#include <debug/pl01x.S>
  8788. diff -Nur linux-3.18.8/arch/arm/mach-bcm2708/include/mach/dma.h linux-rpi/arch/arm/mach-bcm2708/include/mach/dma.h
  8789. --- linux-3.18.8/arch/arm/mach-bcm2708/include/mach/dma.h 1970-01-01 01:00:00.000000000 +0100
  8790. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/dma.h 2015-03-05 14:40:11.153715839 +0100
  8791. @@ -0,0 +1,94 @@
  8792. +/*
  8793. + * linux/arch/arm/mach-bcm2708/include/mach/dma.h
  8794. + *
  8795. + * Copyright (C) 2010 Broadcom
  8796. + *
  8797. + * This program is free software; you can redistribute it and/or modify
  8798. + * it under the terms of the GNU General Public License version 2 as
  8799. + * published by the Free Software Foundation.
  8800. + */
  8801. +
  8802. +
  8803. +#ifndef _MACH_BCM2708_DMA_H
  8804. +#define _MACH_BCM2708_DMA_H
  8805. +
  8806. +#define BCM_DMAMAN_DRIVER_NAME "bcm2708_dma"
  8807. +
  8808. +/* DMA CS Control and Status bits */
  8809. +#define BCM2708_DMA_ACTIVE (1 << 0)
  8810. +#define BCM2708_DMA_INT (1 << 2)
  8811. +#define BCM2708_DMA_ISPAUSED (1 << 4) /* Pause requested or not active */
  8812. +#define BCM2708_DMA_ISHELD (1 << 5) /* Is held by DREQ flow control */
  8813. +#define BCM2708_DMA_ERR (1 << 8)
  8814. +#define BCM2708_DMA_ABORT (1 << 30) /* stop current CB, go to next, WO */
  8815. +#define BCM2708_DMA_RESET (1 << 31) /* WO, self clearing */
  8816. +
  8817. +/* DMA control block "info" field bits */
  8818. +#define BCM2708_DMA_INT_EN (1 << 0)
  8819. +#define BCM2708_DMA_TDMODE (1 << 1)
  8820. +#define BCM2708_DMA_WAIT_RESP (1 << 3)
  8821. +#define BCM2708_DMA_D_INC (1 << 4)
  8822. +#define BCM2708_DMA_D_WIDTH (1 << 5)
  8823. +#define BCM2708_DMA_D_DREQ (1 << 6)
  8824. +#define BCM2708_DMA_S_INC (1 << 8)
  8825. +#define BCM2708_DMA_S_WIDTH (1 << 9)
  8826. +#define BCM2708_DMA_S_DREQ (1 << 10)
  8827. +
  8828. +#define BCM2708_DMA_BURST(x) (((x)&0xf) << 12)
  8829. +#define BCM2708_DMA_PER_MAP(x) ((x) << 16)
  8830. +#define BCM2708_DMA_WAITS(x) (((x)&0x1f) << 21)
  8831. +
  8832. +#define BCM2708_DMA_DREQ_EMMC 11
  8833. +#define BCM2708_DMA_DREQ_SDHOST 13
  8834. +
  8835. +#define BCM2708_DMA_CS 0x00 /* Control and Status */
  8836. +#define BCM2708_DMA_ADDR 0x04
  8837. +/* the current control block appears in the following registers - read only */
  8838. +#define BCM2708_DMA_INFO 0x08
  8839. +#define BCM2708_DMA_SOURCE_AD 0x0c
  8840. +#define BCM2708_DMA_DEST_AD 0x10
  8841. +#define BCM2708_DMA_NEXTCB 0x1C
  8842. +#define BCM2708_DMA_DEBUG 0x20
  8843. +
  8844. +#define BCM2708_DMA4_CS (BCM2708_DMA_CHAN(4)+BCM2708_DMA_CS)
  8845. +#define BCM2708_DMA4_ADDR (BCM2708_DMA_CHAN(4)+BCM2708_DMA_ADDR)
  8846. +
  8847. +#define BCM2708_DMA_TDMODE_LEN(w, h) ((h) << 16 | (w))
  8848. +
  8849. +struct bcm2708_dma_cb {
  8850. + unsigned long info;
  8851. + unsigned long src;
  8852. + unsigned long dst;
  8853. + unsigned long length;
  8854. + unsigned long stride;
  8855. + unsigned long next;
  8856. + unsigned long pad[2];
  8857. +};
  8858. +struct scatterlist;
  8859. +
  8860. +extern int bcm_sg_suitable_for_dma(struct scatterlist *sg_ptr, int sg_len);
  8861. +extern void bcm_dma_start(void __iomem *dma_chan_base,
  8862. + dma_addr_t control_block);
  8863. +extern void bcm_dma_wait_idle(void __iomem *dma_chan_base);
  8864. +extern bool bcm_dma_is_busy(void __iomem *dma_chan_base);
  8865. +extern int /*rc*/ bcm_dma_abort(void __iomem *dma_chan_base);
  8866. +
  8867. +/* When listing features we can ask for when allocating DMA channels give
  8868. + those with higher priority smaller ordinal numbers */
  8869. +#define BCM_DMA_FEATURE_FAST_ORD 0
  8870. +#define BCM_DMA_FEATURE_BULK_ORD 1
  8871. +#define BCM_DMA_FEATURE_NORMAL_ORD 2
  8872. +#define BCM_DMA_FEATURE_LITE_ORD 3
  8873. +#define BCM_DMA_FEATURE_FAST (1<<BCM_DMA_FEATURE_FAST_ORD)
  8874. +#define BCM_DMA_FEATURE_BULK (1<<BCM_DMA_FEATURE_BULK_ORD)
  8875. +#define BCM_DMA_FEATURE_NORMAL (1<<BCM_DMA_FEATURE_NORMAL_ORD)
  8876. +#define BCM_DMA_FEATURE_LITE (1<<BCM_DMA_FEATURE_LITE_ORD)
  8877. +#define BCM_DMA_FEATURE_COUNT 4
  8878. +
  8879. +/* return channel no or -ve error */
  8880. +extern int bcm_dma_chan_alloc(unsigned preferred_feature_set,
  8881. + void __iomem **out_dma_base, int *out_dma_irq);
  8882. +extern int bcm_dma_chan_free(int channel);
  8883. +
  8884. +
  8885. +#endif /* _MACH_BCM2708_DMA_H */
  8886. diff -Nur linux-3.18.8/arch/arm/mach-bcm2708/include/mach/entry-macro.S linux-rpi/arch/arm/mach-bcm2708/include/mach/entry-macro.S
  8887. --- linux-3.18.8/arch/arm/mach-bcm2708/include/mach/entry-macro.S 1970-01-01 01:00:00.000000000 +0100
  8888. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/entry-macro.S 2015-03-05 14:40:11.153715839 +0100
  8889. @@ -0,0 +1,69 @@
  8890. +/*
  8891. + * arch/arm/mach-bcm2708/include/mach/entry-macro.S
  8892. + *
  8893. + * Low-level IRQ helper macros for BCM2708 platforms
  8894. + *
  8895. + * Copyright (C) 2010 Broadcom
  8896. + *
  8897. + * This program is free software; you can redistribute it and/or modify
  8898. + * it under the terms of the GNU General Public License as published by
  8899. + * the Free Software Foundation; either version 2 of the License, or
  8900. + * (at your option) any later version.
  8901. + *
  8902. + * This program is distributed in the hope that it will be useful,
  8903. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8904. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8905. + * GNU General Public License for more details.
  8906. + *
  8907. + * You should have received a copy of the GNU General Public License
  8908. + * along with this program; if not, write to the Free Software
  8909. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  8910. + */
  8911. +#include <mach/hardware.h>
  8912. +
  8913. + .macro disable_fiq
  8914. + .endm
  8915. +
  8916. + .macro get_irqnr_preamble, base, tmp
  8917. + ldr \base, =IO_ADDRESS(ARMCTRL_IC_BASE)
  8918. + .endm
  8919. +
  8920. + .macro arch_ret_to_user, tmp1, tmp2
  8921. + .endm
  8922. +
  8923. + .macro get_irqnr_and_base, irqnr, irqstat, base, tmp
  8924. + /* get masked status */
  8925. + ldr \irqstat, [\base, #(ARM_IRQ_PEND0 - ARMCTRL_IC_BASE)]
  8926. + mov \irqnr, #(ARM_IRQ0_BASE + 31)
  8927. + and \tmp, \irqstat, #0x300 @ save bits 8 and 9
  8928. + /* clear bits 8 and 9, and test */
  8929. + bics \irqstat, \irqstat, #0x300
  8930. + bne 1010f
  8931. +
  8932. + tst \tmp, #0x100
  8933. + ldrne \irqstat, [\base, #(ARM_IRQ_PEND1 - ARMCTRL_IC_BASE)]
  8934. + movne \irqnr, #(ARM_IRQ1_BASE + 31)
  8935. + @ Mask out the interrupts also present in PEND0 - see SW-5809
  8936. + bicne \irqstat, #((1<<7) | (1<<9) | (1<<10))
  8937. + bicne \irqstat, #((1<<18) | (1<<19))
  8938. + bne 1010f
  8939. +
  8940. + tst \tmp, #0x200
  8941. + ldrne \irqstat, [\base, #(ARM_IRQ_PEND2 - ARMCTRL_IC_BASE)]
  8942. + movne \irqnr, #(ARM_IRQ2_BASE + 31)
  8943. + @ Mask out the interrupts also present in PEND0 - see SW-5809
  8944. + bicne \irqstat, #((1<<21) | (1<<22) | (1<<23) | (1<<24) | (1<<25))
  8945. + bicne \irqstat, #((1<<30))
  8946. + beq 1020f
  8947. +
  8948. +1010:
  8949. + @ For non-zero x, LSB(x) = 31 - CLZ(x^(x-1))
  8950. + @ N.B. CLZ is an ARM5 instruction.
  8951. + sub \tmp, \irqstat, #1
  8952. + eor \irqstat, \irqstat, \tmp
  8953. + clz \tmp, \irqstat
  8954. + sub \irqnr, \tmp
  8955. +
  8956. +1020: @ EQ will be set if no irqs pending
  8957. +
  8958. + .endm
  8959. diff -Nur linux-3.18.8/arch/arm/mach-bcm2708/include/mach/frc.h linux-rpi/arch/arm/mach-bcm2708/include/mach/frc.h
  8960. --- linux-3.18.8/arch/arm/mach-bcm2708/include/mach/frc.h 1970-01-01 01:00:00.000000000 +0100
  8961. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/frc.h 2015-03-05 14:40:11.153715839 +0100
  8962. @@ -0,0 +1,38 @@
  8963. +/*
  8964. + * arch/arm/mach-bcm2708/include/mach/timex.h
  8965. + *
  8966. + * BCM2708 free running counter (timer)
  8967. + *
  8968. + * Copyright (C) 2010 Broadcom
  8969. + *
  8970. + * This program is free software; you can redistribute it and/or modify
  8971. + * it under the terms of the GNU General Public License as published by
  8972. + * the Free Software Foundation; either version 2 of the License, or
  8973. + * (at your option) any later version.
  8974. + *
  8975. + * This program is distributed in the hope that it will be useful,
  8976. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8977. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8978. + * GNU General Public License for more details.
  8979. + *
  8980. + * You should have received a copy of the GNU General Public License
  8981. + * along with this program; if not, write to the Free Software
  8982. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  8983. + */
  8984. +
  8985. +#ifndef _MACH_FRC_H
  8986. +#define _MACH_FRC_H
  8987. +
  8988. +#define FRC_TICK_RATE (1000000)
  8989. +
  8990. +/*! Free running counter incrementing at the CLOCK_TICK_RATE
  8991. + (slightly faster than frc_clock_ticks63()
  8992. + */
  8993. +extern unsigned long frc_clock_ticks32(void);
  8994. +
  8995. +/*! Free running counter incrementing at the CLOCK_TICK_RATE
  8996. + * Note - top bit should be ignored (see cnt32_to_63)
  8997. + */
  8998. +extern unsigned long long frc_clock_ticks63(void);
  8999. +
  9000. +#endif
  9001. diff -Nur linux-3.18.8/arch/arm/mach-bcm2708/include/mach/gpio.h linux-rpi/arch/arm/mach-bcm2708/include/mach/gpio.h
  9002. --- linux-3.18.8/arch/arm/mach-bcm2708/include/mach/gpio.h 1970-01-01 01:00:00.000000000 +0100
  9003. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/gpio.h 2015-03-05 14:40:11.153715839 +0100
  9004. @@ -0,0 +1,17 @@
  9005. +/*
  9006. + * arch/arm/mach-bcm2708/include/mach/gpio.h
  9007. + *
  9008. + * This file is licensed under the terms of the GNU General Public
  9009. + * License version 2. This program is licensed "as is" without any
  9010. + * warranty of any kind, whether express or implied.
  9011. + */
  9012. +
  9013. +#ifndef __ASM_ARCH_GPIO_H
  9014. +#define __ASM_ARCH_GPIO_H
  9015. +
  9016. +#define BCM2708_NR_GPIOS 54 // number of gpio lines
  9017. +
  9018. +#define gpio_to_irq(x) ((x) + GPIO_IRQ_START)
  9019. +#define irq_to_gpio(x) ((x) - GPIO_IRQ_START)
  9020. +
  9021. +#endif
  9022. diff -Nur linux-3.18.8/arch/arm/mach-bcm2708/include/mach/hardware.h linux-rpi/arch/arm/mach-bcm2708/include/mach/hardware.h
  9023. --- linux-3.18.8/arch/arm/mach-bcm2708/include/mach/hardware.h 1970-01-01 01:00:00.000000000 +0100
  9024. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/hardware.h 2015-03-05 14:40:11.153715839 +0100
  9025. @@ -0,0 +1,28 @@
  9026. +/*
  9027. + * arch/arm/mach-bcm2708/include/mach/hardware.h
  9028. + *
  9029. + * This file contains the hardware definitions of the BCM2708 devices.
  9030. + *
  9031. + * Copyright (C) 2010 Broadcom
  9032. + *
  9033. + * This program is free software; you can redistribute it and/or modify
  9034. + * it under the terms of the GNU General Public License as published by
  9035. + * the Free Software Foundation; either version 2 of the License, or
  9036. + * (at your option) any later version.
  9037. + *
  9038. + * This program is distributed in the hope that it will be useful,
  9039. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9040. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9041. + * GNU General Public License for more details.
  9042. + *
  9043. + * You should have received a copy of the GNU General Public License
  9044. + * along with this program; if not, write to the Free Software
  9045. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  9046. + */
  9047. +#ifndef __ASM_ARCH_HARDWARE_H
  9048. +#define __ASM_ARCH_HARDWARE_H
  9049. +
  9050. +#include <asm/sizes.h>
  9051. +#include <mach/platform.h>
  9052. +
  9053. +#endif
  9054. diff -Nur linux-3.18.8/arch/arm/mach-bcm2708/include/mach/io.h linux-rpi/arch/arm/mach-bcm2708/include/mach/io.h
  9055. --- linux-3.18.8/arch/arm/mach-bcm2708/include/mach/io.h 1970-01-01 01:00:00.000000000 +0100
  9056. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/io.h 2015-03-05 14:40:11.153715839 +0100
  9057. @@ -0,0 +1,27 @@
  9058. +/*
  9059. + * arch/arm/mach-bcm2708/include/mach/io.h
  9060. + *
  9061. + * Copyright (C) 2003 ARM Limited
  9062. + *
  9063. + * This program is free software; you can redistribute it and/or modify
  9064. + * it under the terms of the GNU General Public License as published by
  9065. + * the Free Software Foundation; either version 2 of the License, or
  9066. + * (at your option) any later version.
  9067. + *
  9068. + * This program is distributed in the hope that it will be useful,
  9069. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9070. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9071. + * GNU General Public License for more details.
  9072. + *
  9073. + * You should have received a copy of the GNU General Public License
  9074. + * along with this program; if not, write to the Free Software
  9075. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  9076. + */
  9077. +#ifndef __ASM_ARM_ARCH_IO_H
  9078. +#define __ASM_ARM_ARCH_IO_H
  9079. +
  9080. +#define IO_SPACE_LIMIT 0xffffffff
  9081. +
  9082. +#define __io(a) __typesafe_io(a)
  9083. +
  9084. +#endif
  9085. diff -Nur linux-3.18.8/arch/arm/mach-bcm2708/include/mach/irqs.h linux-rpi/arch/arm/mach-bcm2708/include/mach/irqs.h
  9086. --- linux-3.18.8/arch/arm/mach-bcm2708/include/mach/irqs.h 1970-01-01 01:00:00.000000000 +0100
  9087. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/irqs.h 2015-03-05 14:40:11.153715839 +0100
  9088. @@ -0,0 +1,199 @@
  9089. +/*
  9090. + * arch/arm/mach-bcm2708/include/mach/irqs.h
  9091. + *
  9092. + * Copyright (C) 2010 Broadcom
  9093. + * Copyright (C) 2003 ARM Limited
  9094. + * Copyright (C) 2000 Deep Blue Solutions Ltd.
  9095. + *
  9096. + * This program is free software; you can redistribute it and/or modify
  9097. + * it under the terms of the GNU General Public License as published by
  9098. + * the Free Software Foundation; either version 2 of the License, or
  9099. + * (at your option) any later version.
  9100. + *
  9101. + * This program is distributed in the hope that it will be useful,
  9102. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9103. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9104. + * GNU General Public License for more details.
  9105. + *
  9106. + * You should have received a copy of the GNU General Public License
  9107. + * along with this program; if not, write to the Free Software
  9108. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  9109. + */
  9110. +
  9111. +#ifndef _BCM2708_IRQS_H_
  9112. +#define _BCM2708_IRQS_H_
  9113. +
  9114. +#include <mach/platform.h>
  9115. +
  9116. +/*
  9117. + * IRQ interrupts definitions are the same as the INT definitions
  9118. + * held within platform.h
  9119. + */
  9120. +#define IRQ_ARMCTRL_START 0
  9121. +#define IRQ_TIMER0 (IRQ_ARMCTRL_START + INTERRUPT_TIMER0)
  9122. +#define IRQ_TIMER1 (IRQ_ARMCTRL_START + INTERRUPT_TIMER1)
  9123. +#define IRQ_TIMER2 (IRQ_ARMCTRL_START + INTERRUPT_TIMER2)
  9124. +#define IRQ_TIMER3 (IRQ_ARMCTRL_START + INTERRUPT_TIMER3)
  9125. +#define IRQ_CODEC0 (IRQ_ARMCTRL_START + INTERRUPT_CODEC0)
  9126. +#define IRQ_CODEC1 (IRQ_ARMCTRL_START + INTERRUPT_CODEC1)
  9127. +#define IRQ_CODEC2 (IRQ_ARMCTRL_START + INTERRUPT_CODEC2)
  9128. +#define IRQ_JPEG (IRQ_ARMCTRL_START + INTERRUPT_JPEG)
  9129. +#define IRQ_ISP (IRQ_ARMCTRL_START + INTERRUPT_ISP)
  9130. +#define IRQ_USB (IRQ_ARMCTRL_START + INTERRUPT_USB)
  9131. +#define IRQ_3D (IRQ_ARMCTRL_START + INTERRUPT_3D)
  9132. +#define IRQ_TRANSPOSER (IRQ_ARMCTRL_START + INTERRUPT_TRANSPOSER)
  9133. +#define IRQ_MULTICORESYNC0 (IRQ_ARMCTRL_START + INTERRUPT_MULTICORESYNC0)
  9134. +#define IRQ_MULTICORESYNC1 (IRQ_ARMCTRL_START + INTERRUPT_MULTICORESYNC1)
  9135. +#define IRQ_MULTICORESYNC2 (IRQ_ARMCTRL_START + INTERRUPT_MULTICORESYNC2)
  9136. +#define IRQ_MULTICORESYNC3 (IRQ_ARMCTRL_START + INTERRUPT_MULTICORESYNC3)
  9137. +#define IRQ_DMA0 (IRQ_ARMCTRL_START + INTERRUPT_DMA0)
  9138. +#define IRQ_DMA1 (IRQ_ARMCTRL_START + INTERRUPT_DMA1)
  9139. +#define IRQ_DMA2 (IRQ_ARMCTRL_START + INTERRUPT_DMA2)
  9140. +#define IRQ_DMA3 (IRQ_ARMCTRL_START + INTERRUPT_DMA3)
  9141. +#define IRQ_DMA4 (IRQ_ARMCTRL_START + INTERRUPT_DMA4)
  9142. +#define IRQ_DMA5 (IRQ_ARMCTRL_START + INTERRUPT_DMA5)
  9143. +#define IRQ_DMA6 (IRQ_ARMCTRL_START + INTERRUPT_DMA6)
  9144. +#define IRQ_DMA7 (IRQ_ARMCTRL_START + INTERRUPT_DMA7)
  9145. +#define IRQ_DMA8 (IRQ_ARMCTRL_START + INTERRUPT_DMA8)
  9146. +#define IRQ_DMA9 (IRQ_ARMCTRL_START + INTERRUPT_DMA9)
  9147. +#define IRQ_DMA10 (IRQ_ARMCTRL_START + INTERRUPT_DMA10)
  9148. +#define IRQ_DMA11 (IRQ_ARMCTRL_START + INTERRUPT_DMA11)
  9149. +#define IRQ_DMA12 (IRQ_ARMCTRL_START + INTERRUPT_DMA12)
  9150. +#define IRQ_AUX (IRQ_ARMCTRL_START + INTERRUPT_AUX)
  9151. +#define IRQ_ARM (IRQ_ARMCTRL_START + INTERRUPT_ARM)
  9152. +#define IRQ_VPUDMA (IRQ_ARMCTRL_START + INTERRUPT_VPUDMA)
  9153. +#define IRQ_HOSTPORT (IRQ_ARMCTRL_START + INTERRUPT_HOSTPORT)
  9154. +#define IRQ_VIDEOSCALER (IRQ_ARMCTRL_START + INTERRUPT_VIDEOSCALER)
  9155. +#define IRQ_CCP2TX (IRQ_ARMCTRL_START + INTERRUPT_CCP2TX)
  9156. +#define IRQ_SDC (IRQ_ARMCTRL_START + INTERRUPT_SDC)
  9157. +#define IRQ_DSI0 (IRQ_ARMCTRL_START + INTERRUPT_DSI0)
  9158. +#define IRQ_AVE (IRQ_ARMCTRL_START + INTERRUPT_AVE)
  9159. +#define IRQ_CAM0 (IRQ_ARMCTRL_START + INTERRUPT_CAM0)
  9160. +#define IRQ_CAM1 (IRQ_ARMCTRL_START + INTERRUPT_CAM1)
  9161. +#define IRQ_HDMI0 (IRQ_ARMCTRL_START + INTERRUPT_HDMI0)
  9162. +#define IRQ_HDMI1 (IRQ_ARMCTRL_START + INTERRUPT_HDMI1)
  9163. +#define IRQ_PIXELVALVE1 (IRQ_ARMCTRL_START + INTERRUPT_PIXELVALVE1)
  9164. +#define IRQ_I2CSPISLV (IRQ_ARMCTRL_START + INTERRUPT_I2CSPISLV)
  9165. +#define IRQ_DSI1 (IRQ_ARMCTRL_START + INTERRUPT_DSI1)
  9166. +#define IRQ_PWA0 (IRQ_ARMCTRL_START + INTERRUPT_PWA0)
  9167. +#define IRQ_PWA1 (IRQ_ARMCTRL_START + INTERRUPT_PWA1)
  9168. +#define IRQ_CPR (IRQ_ARMCTRL_START + INTERRUPT_CPR)
  9169. +#define IRQ_SMI (IRQ_ARMCTRL_START + INTERRUPT_SMI)
  9170. +#define IRQ_GPIO0 (IRQ_ARMCTRL_START + INTERRUPT_GPIO0)
  9171. +#define IRQ_GPIO1 (IRQ_ARMCTRL_START + INTERRUPT_GPIO1)
  9172. +#define IRQ_GPIO2 (IRQ_ARMCTRL_START + INTERRUPT_GPIO2)
  9173. +#define IRQ_GPIO3 (IRQ_ARMCTRL_START + INTERRUPT_GPIO3)
  9174. +#define IRQ_I2C (IRQ_ARMCTRL_START + INTERRUPT_I2C)
  9175. +#define IRQ_SPI (IRQ_ARMCTRL_START + INTERRUPT_SPI)
  9176. +#define IRQ_I2SPCM (IRQ_ARMCTRL_START + INTERRUPT_I2SPCM)
  9177. +#define IRQ_SDIO (IRQ_ARMCTRL_START + INTERRUPT_SDIO)
  9178. +#define IRQ_UART (IRQ_ARMCTRL_START + INTERRUPT_UART)
  9179. +#define IRQ_SLIMBUS (IRQ_ARMCTRL_START + INTERRUPT_SLIMBUS)
  9180. +#define IRQ_VEC (IRQ_ARMCTRL_START + INTERRUPT_VEC)
  9181. +#define IRQ_CPG (IRQ_ARMCTRL_START + INTERRUPT_CPG)
  9182. +#define IRQ_RNG (IRQ_ARMCTRL_START + INTERRUPT_RNG)
  9183. +#define IRQ_ARASANSDIO (IRQ_ARMCTRL_START + INTERRUPT_ARASANSDIO)
  9184. +#define IRQ_AVSPMON (IRQ_ARMCTRL_START + INTERRUPT_AVSPMON)
  9185. +
  9186. +#define IRQ_ARM_TIMER (IRQ_ARMCTRL_START + INTERRUPT_ARM_TIMER)
  9187. +#define IRQ_ARM_MAILBOX (IRQ_ARMCTRL_START + INTERRUPT_ARM_MAILBOX)
  9188. +#define IRQ_ARM_DOORBELL_0 (IRQ_ARMCTRL_START + INTERRUPT_ARM_DOORBELL_0)
  9189. +#define IRQ_ARM_DOORBELL_1 (IRQ_ARMCTRL_START + INTERRUPT_ARM_DOORBELL_1)
  9190. +#define IRQ_VPU0_HALTED (IRQ_ARMCTRL_START + INTERRUPT_VPU0_HALTED)
  9191. +#define IRQ_VPU1_HALTED (IRQ_ARMCTRL_START + INTERRUPT_VPU1_HALTED)
  9192. +#define IRQ_ILLEGAL_TYPE0 (IRQ_ARMCTRL_START + INTERRUPT_ILLEGAL_TYPE0)
  9193. +#define IRQ_ILLEGAL_TYPE1 (IRQ_ARMCTRL_START + INTERRUPT_ILLEGAL_TYPE1)
  9194. +#define IRQ_PENDING1 (IRQ_ARMCTRL_START + INTERRUPT_PENDING1)
  9195. +#define IRQ_PENDING2 (IRQ_ARMCTRL_START + INTERRUPT_PENDING2)
  9196. +
  9197. +#define FIQ_START HARD_IRQS
  9198. +
  9199. +/*
  9200. + * FIQ interrupts definitions are the same as the INT definitions.
  9201. + */
  9202. +#define FIQ_TIMER0 (FIQ_START+INTERRUPT_TIMER0)
  9203. +#define FIQ_TIMER1 (FIQ_START+INTERRUPT_TIMER1)
  9204. +#define FIQ_TIMER2 (FIQ_START+INTERRUPT_TIMER2)
  9205. +#define FIQ_TIMER3 (FIQ_START+INTERRUPT_TIMER3)
  9206. +#define FIQ_CODEC0 (FIQ_START+INTERRUPT_CODEC0)
  9207. +#define FIQ_CODEC1 (FIQ_START+INTERRUPT_CODEC1)
  9208. +#define FIQ_CODEC2 (FIQ_START+INTERRUPT_CODEC2)
  9209. +#define FIQ_JPEG (FIQ_START+INTERRUPT_JPEG)
  9210. +#define FIQ_ISP (FIQ_START+INTERRUPT_ISP)
  9211. +#define FIQ_USB (FIQ_START+INTERRUPT_USB)
  9212. +#define FIQ_3D (FIQ_START+INTERRUPT_3D)
  9213. +#define FIQ_TRANSPOSER (FIQ_START+INTERRUPT_TRANSPOSER)
  9214. +#define FIQ_MULTICORESYNC0 (FIQ_START+INTERRUPT_MULTICORESYNC0)
  9215. +#define FIQ_MULTICORESYNC1 (FIQ_START+INTERRUPT_MULTICORESYNC1)
  9216. +#define FIQ_MULTICORESYNC2 (FIQ_START+INTERRUPT_MULTICORESYNC2)
  9217. +#define FIQ_MULTICORESYNC3 (FIQ_START+INTERRUPT_MULTICORESYNC3)
  9218. +#define FIQ_DMA0 (FIQ_START+INTERRUPT_DMA0)
  9219. +#define FIQ_DMA1 (FIQ_START+INTERRUPT_DMA1)
  9220. +#define FIQ_DMA2 (FIQ_START+INTERRUPT_DMA2)
  9221. +#define FIQ_DMA3 (FIQ_START+INTERRUPT_DMA3)
  9222. +#define FIQ_DMA4 (FIQ_START+INTERRUPT_DMA4)
  9223. +#define FIQ_DMA5 (FIQ_START+INTERRUPT_DMA5)
  9224. +#define FIQ_DMA6 (FIQ_START+INTERRUPT_DMA6)
  9225. +#define FIQ_DMA7 (FIQ_START+INTERRUPT_DMA7)
  9226. +#define FIQ_DMA8 (FIQ_START+INTERRUPT_DMA8)
  9227. +#define FIQ_DMA9 (FIQ_START+INTERRUPT_DMA9)
  9228. +#define FIQ_DMA10 (FIQ_START+INTERRUPT_DMA10)
  9229. +#define FIQ_DMA11 (FIQ_START+INTERRUPT_DMA11)
  9230. +#define FIQ_DMA12 (FIQ_START+INTERRUPT_DMA12)
  9231. +#define FIQ_AUX (FIQ_START+INTERRUPT_AUX)
  9232. +#define FIQ_ARM (FIQ_START+INTERRUPT_ARM)
  9233. +#define FIQ_VPUDMA (FIQ_START+INTERRUPT_VPUDMA)
  9234. +#define FIQ_HOSTPORT (FIQ_START+INTERRUPT_HOSTPORT)
  9235. +#define FIQ_VIDEOSCALER (FIQ_START+INTERRUPT_VIDEOSCALER)
  9236. +#define FIQ_CCP2TX (FIQ_START+INTERRUPT_CCP2TX)
  9237. +#define FIQ_SDC (FIQ_START+INTERRUPT_SDC)
  9238. +#define FIQ_DSI0 (FIQ_START+INTERRUPT_DSI0)
  9239. +#define FIQ_AVE (FIQ_START+INTERRUPT_AVE)
  9240. +#define FIQ_CAM0 (FIQ_START+INTERRUPT_CAM0)
  9241. +#define FIQ_CAM1 (FIQ_START+INTERRUPT_CAM1)
  9242. +#define FIQ_HDMI0 (FIQ_START+INTERRUPT_HDMI0)
  9243. +#define FIQ_HDMI1 (FIQ_START+INTERRUPT_HDMI1)
  9244. +#define FIQ_PIXELVALVE1 (FIQ_START+INTERRUPT_PIXELVALVE1)
  9245. +#define FIQ_I2CSPISLV (FIQ_START+INTERRUPT_I2CSPISLV)
  9246. +#define FIQ_DSI1 (FIQ_START+INTERRUPT_DSI1)
  9247. +#define FIQ_PWA0 (FIQ_START+INTERRUPT_PWA0)
  9248. +#define FIQ_PWA1 (FIQ_START+INTERRUPT_PWA1)
  9249. +#define FIQ_CPR (FIQ_START+INTERRUPT_CPR)
  9250. +#define FIQ_SMI (FIQ_START+INTERRUPT_SMI)
  9251. +#define FIQ_GPIO0 (FIQ_START+INTERRUPT_GPIO0)
  9252. +#define FIQ_GPIO1 (FIQ_START+INTERRUPT_GPIO1)
  9253. +#define FIQ_GPIO2 (FIQ_START+INTERRUPT_GPIO2)
  9254. +#define FIQ_GPIO3 (FIQ_START+INTERRUPT_GPIO3)
  9255. +#define FIQ_I2C (FIQ_START+INTERRUPT_I2C)
  9256. +#define FIQ_SPI (FIQ_START+INTERRUPT_SPI)
  9257. +#define FIQ_I2SPCM (FIQ_START+INTERRUPT_I2SPCM)
  9258. +#define FIQ_SDIO (FIQ_START+INTERRUPT_SDIO)
  9259. +#define FIQ_UART (FIQ_START+INTERRUPT_UART)
  9260. +#define FIQ_SLIMBUS (FIQ_START+INTERRUPT_SLIMBUS)
  9261. +#define FIQ_VEC (FIQ_START+INTERRUPT_VEC)
  9262. +#define FIQ_CPG (FIQ_START+INTERRUPT_CPG)
  9263. +#define FIQ_RNG (FIQ_START+INTERRUPT_RNG)
  9264. +#define FIQ_ARASANSDIO (FIQ_START+INTERRUPT_ARASANSDIO)
  9265. +#define FIQ_AVSPMON (FIQ_START+INTERRUPT_AVSPMON)
  9266. +
  9267. +#define FIQ_ARM_TIMER (FIQ_START+INTERRUPT_ARM_TIMER)
  9268. +#define FIQ_ARM_MAILBOX (FIQ_START+INTERRUPT_ARM_MAILBOX)
  9269. +#define FIQ_ARM_DOORBELL_0 (FIQ_START+INTERRUPT_ARM_DOORBELL_0)
  9270. +#define FIQ_ARM_DOORBELL_1 (FIQ_START+INTERRUPT_ARM_DOORBELL_1)
  9271. +#define FIQ_VPU0_HALTED (FIQ_START+INTERRUPT_VPU0_HALTED)
  9272. +#define FIQ_VPU1_HALTED (FIQ_START+INTERRUPT_VPU1_HALTED)
  9273. +#define FIQ_ILLEGAL_TYPE0 (FIQ_START+INTERRUPT_ILLEGAL_TYPE0)
  9274. +#define FIQ_ILLEGAL_TYPE1 (FIQ_START+INTERRUPT_ILLEGAL_TYPE1)
  9275. +#define FIQ_PENDING1 (FIQ_START+INTERRUPT_PENDING1)
  9276. +#define FIQ_PENDING2 (FIQ_START+INTERRUPT_PENDING2)
  9277. +
  9278. +#define HARD_IRQS (64 + 21)
  9279. +#define FIQ_IRQS (64 + 21)
  9280. +#define GPIO_IRQ_START (HARD_IRQS + FIQ_IRQS)
  9281. +#define GPIO_IRQS (32*5)
  9282. +#define SPARE_ALLOC_IRQS 64
  9283. +#define BCM2708_ALLOC_IRQS (HARD_IRQS+FIQ_IRQS+GPIO_IRQS+SPARE_ALLOC_IRQS)
  9284. +#define FREE_IRQS 128
  9285. +#define NR_IRQS (BCM2708_ALLOC_IRQS+FREE_IRQS)
  9286. +
  9287. +#endif /* _BCM2708_IRQS_H_ */
  9288. diff -Nur linux-3.18.8/arch/arm/mach-bcm2708/include/mach/memory.h linux-rpi/arch/arm/mach-bcm2708/include/mach/memory.h
  9289. --- linux-3.18.8/arch/arm/mach-bcm2708/include/mach/memory.h 1970-01-01 01:00:00.000000000 +0100
  9290. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/memory.h 2015-03-05 14:40:11.153715839 +0100
  9291. @@ -0,0 +1,57 @@
  9292. +/*
  9293. + * arch/arm/mach-bcm2708/include/mach/memory.h
  9294. + *
  9295. + * Copyright (C) 2010 Broadcom
  9296. + *
  9297. + * This program is free software; you can redistribute it and/or modify
  9298. + * it under the terms of the GNU General Public License as published by
  9299. + * the Free Software Foundation; either version 2 of the License, or
  9300. + * (at your option) any later version.
  9301. + *
  9302. + * This program is distributed in the hope that it will be useful,
  9303. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9304. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9305. + * GNU General Public License for more details.
  9306. + *
  9307. + * You should have received a copy of the GNU General Public License
  9308. + * along with this program; if not, write to the Free Software
  9309. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  9310. + */
  9311. +#ifndef __ASM_ARCH_MEMORY_H
  9312. +#define __ASM_ARCH_MEMORY_H
  9313. +
  9314. +/* Memory overview:
  9315. +
  9316. + [ARMcore] <--virtual addr-->
  9317. + [ARMmmu] <--physical addr-->
  9318. + [GERTmap] <--bus add-->
  9319. + [VCperiph]
  9320. +
  9321. +*/
  9322. +
  9323. +/*
  9324. + * Physical DRAM offset.
  9325. + */
  9326. +#define BCM_PLAT_PHYS_OFFSET UL(0x00000000)
  9327. +#define VC_ARMMEM_OFFSET UL(0x00000000) /* offset in VC of ARM memory */
  9328. +
  9329. +#ifdef CONFIG_BCM2708_NOL2CACHE
  9330. + #define _REAL_BUS_OFFSET UL(0xC0000000) /* don't use L1 or L2 caches */
  9331. +#else
  9332. + #define _REAL_BUS_OFFSET UL(0x40000000) /* use L2 cache */
  9333. +#endif
  9334. +
  9335. +/* We're using the memory at 64M in the VideoCore for Linux - this adjustment
  9336. + * will provide the offset into this area as well as setting the bits that
  9337. + * stop the L1 and L2 cache from being used
  9338. + *
  9339. + * WARNING: this only works because the ARM is given memory at a fixed location
  9340. + * (ARMMEM_OFFSET)
  9341. + */
  9342. +#define BUS_OFFSET (VC_ARMMEM_OFFSET + _REAL_BUS_OFFSET)
  9343. +#define __virt_to_bus(x) ((x) + (BUS_OFFSET - PAGE_OFFSET))
  9344. +#define __bus_to_virt(x) ((x) - (BUS_OFFSET - PAGE_OFFSET))
  9345. +#define __pfn_to_bus(x) (__pfn_to_phys(x) + (BUS_OFFSET - BCM_PLAT_PHYS_OFFSET))
  9346. +#define __bus_to_pfn(x) __phys_to_pfn((x) - (BUS_OFFSET - BCM_PLAT_PHYS_OFFSET))
  9347. +
  9348. +#endif
  9349. diff -Nur linux-3.18.8/arch/arm/mach-bcm2708/include/mach/platform.h linux-rpi/arch/arm/mach-bcm2708/include/mach/platform.h
  9350. --- linux-3.18.8/arch/arm/mach-bcm2708/include/mach/platform.h 1970-01-01 01:00:00.000000000 +0100
  9351. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/platform.h 2015-03-05 14:40:11.153715839 +0100
  9352. @@ -0,0 +1,228 @@
  9353. +/*
  9354. + * arch/arm/mach-bcm2708/include/mach/platform.h
  9355. + *
  9356. + * Copyright (C) 2010 Broadcom
  9357. + *
  9358. + * This program is free software; you can redistribute it and/or modify
  9359. + * it under the terms of the GNU General Public License as published by
  9360. + * the Free Software Foundation; either version 2 of the License, or
  9361. + * (at your option) any later version.
  9362. + *
  9363. + * This program is distributed in the hope that it will be useful,
  9364. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9365. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9366. + * GNU General Public License for more details.
  9367. + *
  9368. + * You should have received a copy of the GNU General Public License
  9369. + * along with this program; if not, write to the Free Software
  9370. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  9371. + */
  9372. +
  9373. +#ifndef _BCM2708_PLATFORM_H
  9374. +#define _BCM2708_PLATFORM_H
  9375. +
  9376. +
  9377. +/* macros to get at IO space when running virtually */
  9378. +#define IO_ADDRESS(x) (((x) & 0x0fffffff) + (((x) >> 4) & 0x0f000000) + 0xf0000000)
  9379. +
  9380. +#define __io_address(n) IOMEM(IO_ADDRESS(n))
  9381. +
  9382. +
  9383. +/*
  9384. + * SDRAM
  9385. + */
  9386. +#define BCM2708_SDRAM_BASE 0x00000000
  9387. +
  9388. +/*
  9389. + * Logic expansion modules
  9390. + *
  9391. + */
  9392. +
  9393. +
  9394. +/* ------------------------------------------------------------------------
  9395. + * BCM2708 ARMCTRL Registers
  9396. + * ------------------------------------------------------------------------
  9397. + */
  9398. +
  9399. +#define HW_REGISTER_RW(addr) (addr)
  9400. +#define HW_REGISTER_RO(addr) (addr)
  9401. +
  9402. +#include "arm_control.h"
  9403. +#undef ARM_BASE
  9404. +
  9405. +/*
  9406. + * Definitions and addresses for the ARM CONTROL logic
  9407. + * This file is manually generated.
  9408. + */
  9409. +
  9410. +#define BCM2708_PERI_BASE 0x20000000
  9411. +#define IC0_BASE (BCM2708_PERI_BASE + 0x2000)
  9412. +#define ST_BASE (BCM2708_PERI_BASE + 0x3000) /* System Timer */
  9413. +#define MPHI_BASE (BCM2708_PERI_BASE + 0x6000) /* Message -based Parallel Host Interface */
  9414. +#define DMA_BASE (BCM2708_PERI_BASE + 0x7000) /* DMA controller */
  9415. +#define ARM_BASE (BCM2708_PERI_BASE + 0xB000) /* BCM2708 ARM control block */
  9416. +#define PM_BASE (BCM2708_PERI_BASE + 0x100000) /* Power Management, Reset controller and Watchdog registers */
  9417. +#define PCM_CLOCK_BASE (BCM2708_PERI_BASE + 0x101098) /* PCM Clock */
  9418. +#define RNG_BASE (BCM2708_PERI_BASE + 0x104000) /* Hardware RNG */
  9419. +#define GPIO_BASE (BCM2708_PERI_BASE + 0x200000) /* GPIO */
  9420. +#define UART0_BASE (BCM2708_PERI_BASE + 0x201000) /* Uart 0 */
  9421. +#define MMCI0_BASE (BCM2708_PERI_BASE + 0x202000) /* MMC interface */
  9422. +#define I2S_BASE (BCM2708_PERI_BASE + 0x203000) /* I2S */
  9423. +#define SPI0_BASE (BCM2708_PERI_BASE + 0x204000) /* SPI0 */
  9424. +#define BSC0_BASE (BCM2708_PERI_BASE + 0x205000) /* BSC0 I2C/TWI */
  9425. +#define UART1_BASE (BCM2708_PERI_BASE + 0x215000) /* Uart 1 */
  9426. +#define EMMC_BASE (BCM2708_PERI_BASE + 0x300000) /* eMMC interface */
  9427. +#define SMI_BASE (BCM2708_PERI_BASE + 0x600000) /* SMI */
  9428. +#define BSC1_BASE (BCM2708_PERI_BASE + 0x804000) /* BSC1 I2C/TWI */
  9429. +#define USB_BASE (BCM2708_PERI_BASE + 0x980000) /* DTC_OTG USB controller */
  9430. +#define MCORE_BASE (BCM2708_PERI_BASE + 0x0000) /* Fake frame buffer device (actually the multicore sync block*/
  9431. +
  9432. +#define ARMCTRL_BASE (ARM_BASE + 0x000)
  9433. +#define ARMCTRL_IC_BASE (ARM_BASE + 0x200) /* ARM interrupt controller */
  9434. +#define ARMCTRL_TIMER0_1_BASE (ARM_BASE + 0x400) /* Timer 0 and 1 */
  9435. +#define ARMCTRL_0_SBM_BASE (ARM_BASE + 0x800) /* User 0 (ARM)'s Semaphores Doorbells and Mailboxes */
  9436. +
  9437. +
  9438. +/*
  9439. + * Interrupt assignments
  9440. + */
  9441. +
  9442. +#define ARM_IRQ1_BASE 0
  9443. +#define INTERRUPT_TIMER0 (ARM_IRQ1_BASE + 0)
  9444. +#define INTERRUPT_TIMER1 (ARM_IRQ1_BASE + 1)
  9445. +#define INTERRUPT_TIMER2 (ARM_IRQ1_BASE + 2)
  9446. +#define INTERRUPT_TIMER3 (ARM_IRQ1_BASE + 3)
  9447. +#define INTERRUPT_CODEC0 (ARM_IRQ1_BASE + 4)
  9448. +#define INTERRUPT_CODEC1 (ARM_IRQ1_BASE + 5)
  9449. +#define INTERRUPT_CODEC2 (ARM_IRQ1_BASE + 6)
  9450. +#define INTERRUPT_VC_JPEG (ARM_IRQ1_BASE + 7)
  9451. +#define INTERRUPT_ISP (ARM_IRQ1_BASE + 8)
  9452. +#define INTERRUPT_VC_USB (ARM_IRQ1_BASE + 9)
  9453. +#define INTERRUPT_VC_3D (ARM_IRQ1_BASE + 10)
  9454. +#define INTERRUPT_TRANSPOSER (ARM_IRQ1_BASE + 11)
  9455. +#define INTERRUPT_MULTICORESYNC0 (ARM_IRQ1_BASE + 12)
  9456. +#define INTERRUPT_MULTICORESYNC1 (ARM_IRQ1_BASE + 13)
  9457. +#define INTERRUPT_MULTICORESYNC2 (ARM_IRQ1_BASE + 14)
  9458. +#define INTERRUPT_MULTICORESYNC3 (ARM_IRQ1_BASE + 15)
  9459. +#define INTERRUPT_DMA0 (ARM_IRQ1_BASE + 16)
  9460. +#define INTERRUPT_DMA1 (ARM_IRQ1_BASE + 17)
  9461. +#define INTERRUPT_VC_DMA2 (ARM_IRQ1_BASE + 18)
  9462. +#define INTERRUPT_VC_DMA3 (ARM_IRQ1_BASE + 19)
  9463. +#define INTERRUPT_DMA4 (ARM_IRQ1_BASE + 20)
  9464. +#define INTERRUPT_DMA5 (ARM_IRQ1_BASE + 21)
  9465. +#define INTERRUPT_DMA6 (ARM_IRQ1_BASE + 22)
  9466. +#define INTERRUPT_DMA7 (ARM_IRQ1_BASE + 23)
  9467. +#define INTERRUPT_DMA8 (ARM_IRQ1_BASE + 24)
  9468. +#define INTERRUPT_DMA9 (ARM_IRQ1_BASE + 25)
  9469. +#define INTERRUPT_DMA10 (ARM_IRQ1_BASE + 26)
  9470. +#define INTERRUPT_DMA11 (ARM_IRQ1_BASE + 27)
  9471. +#define INTERRUPT_DMA12 (ARM_IRQ1_BASE + 28)
  9472. +#define INTERRUPT_AUX (ARM_IRQ1_BASE + 29)
  9473. +#define INTERRUPT_ARM (ARM_IRQ1_BASE + 30)
  9474. +#define INTERRUPT_VPUDMA (ARM_IRQ1_BASE + 31)
  9475. +
  9476. +#define ARM_IRQ2_BASE 32
  9477. +#define INTERRUPT_HOSTPORT (ARM_IRQ2_BASE + 0)
  9478. +#define INTERRUPT_VIDEOSCALER (ARM_IRQ2_BASE + 1)
  9479. +#define INTERRUPT_CCP2TX (ARM_IRQ2_BASE + 2)
  9480. +#define INTERRUPT_SDC (ARM_IRQ2_BASE + 3)
  9481. +#define INTERRUPT_DSI0 (ARM_IRQ2_BASE + 4)
  9482. +#define INTERRUPT_AVE (ARM_IRQ2_BASE + 5)
  9483. +#define INTERRUPT_CAM0 (ARM_IRQ2_BASE + 6)
  9484. +#define INTERRUPT_CAM1 (ARM_IRQ2_BASE + 7)
  9485. +#define INTERRUPT_HDMI0 (ARM_IRQ2_BASE + 8)
  9486. +#define INTERRUPT_HDMI1 (ARM_IRQ2_BASE + 9)
  9487. +#define INTERRUPT_PIXELVALVE1 (ARM_IRQ2_BASE + 10)
  9488. +#define INTERRUPT_I2CSPISLV (ARM_IRQ2_BASE + 11)
  9489. +#define INTERRUPT_DSI1 (ARM_IRQ2_BASE + 12)
  9490. +#define INTERRUPT_PWA0 (ARM_IRQ2_BASE + 13)
  9491. +#define INTERRUPT_PWA1 (ARM_IRQ2_BASE + 14)
  9492. +#define INTERRUPT_CPR (ARM_IRQ2_BASE + 15)
  9493. +#define INTERRUPT_SMI (ARM_IRQ2_BASE + 16)
  9494. +#define INTERRUPT_GPIO0 (ARM_IRQ2_BASE + 17)
  9495. +#define INTERRUPT_GPIO1 (ARM_IRQ2_BASE + 18)
  9496. +#define INTERRUPT_GPIO2 (ARM_IRQ2_BASE + 19)
  9497. +#define INTERRUPT_GPIO3 (ARM_IRQ2_BASE + 20)
  9498. +#define INTERRUPT_VC_I2C (ARM_IRQ2_BASE + 21)
  9499. +#define INTERRUPT_VC_SPI (ARM_IRQ2_BASE + 22)
  9500. +#define INTERRUPT_VC_I2SPCM (ARM_IRQ2_BASE + 23)
  9501. +#define INTERRUPT_VC_SDIO (ARM_IRQ2_BASE + 24)
  9502. +#define INTERRUPT_VC_UART (ARM_IRQ2_BASE + 25)
  9503. +#define INTERRUPT_SLIMBUS (ARM_IRQ2_BASE + 26)
  9504. +#define INTERRUPT_VEC (ARM_IRQ2_BASE + 27)
  9505. +#define INTERRUPT_CPG (ARM_IRQ2_BASE + 28)
  9506. +#define INTERRUPT_RNG (ARM_IRQ2_BASE + 29)
  9507. +#define INTERRUPT_VC_ARASANSDIO (ARM_IRQ2_BASE + 30)
  9508. +#define INTERRUPT_AVSPMON (ARM_IRQ2_BASE + 31)
  9509. +
  9510. +#define ARM_IRQ0_BASE 64
  9511. +#define INTERRUPT_ARM_TIMER (ARM_IRQ0_BASE + 0)
  9512. +#define INTERRUPT_ARM_MAILBOX (ARM_IRQ0_BASE + 1)
  9513. +#define INTERRUPT_ARM_DOORBELL_0 (ARM_IRQ0_BASE + 2)
  9514. +#define INTERRUPT_ARM_DOORBELL_1 (ARM_IRQ0_BASE + 3)
  9515. +#define INTERRUPT_VPU0_HALTED (ARM_IRQ0_BASE + 4)
  9516. +#define INTERRUPT_VPU1_HALTED (ARM_IRQ0_BASE + 5)
  9517. +#define INTERRUPT_ILLEGAL_TYPE0 (ARM_IRQ0_BASE + 6)
  9518. +#define INTERRUPT_ILLEGAL_TYPE1 (ARM_IRQ0_BASE + 7)
  9519. +#define INTERRUPT_PENDING1 (ARM_IRQ0_BASE + 8)
  9520. +#define INTERRUPT_PENDING2 (ARM_IRQ0_BASE + 9)
  9521. +#define INTERRUPT_JPEG (ARM_IRQ0_BASE + 10)
  9522. +#define INTERRUPT_USB (ARM_IRQ0_BASE + 11)
  9523. +#define INTERRUPT_3D (ARM_IRQ0_BASE + 12)
  9524. +#define INTERRUPT_DMA2 (ARM_IRQ0_BASE + 13)
  9525. +#define INTERRUPT_DMA3 (ARM_IRQ0_BASE + 14)
  9526. +#define INTERRUPT_I2C (ARM_IRQ0_BASE + 15)
  9527. +#define INTERRUPT_SPI (ARM_IRQ0_BASE + 16)
  9528. +#define INTERRUPT_I2SPCM (ARM_IRQ0_BASE + 17)
  9529. +#define INTERRUPT_SDIO (ARM_IRQ0_BASE + 18)
  9530. +#define INTERRUPT_UART (ARM_IRQ0_BASE + 19)
  9531. +#define INTERRUPT_ARASANSDIO (ARM_IRQ0_BASE + 20)
  9532. +
  9533. +#define MAXIRQNUM (32 + 32 + 20)
  9534. +#define MAXFIQNUM (32 + 32 + 20)
  9535. +
  9536. +#define MAX_TIMER 2
  9537. +#define MAX_PERIOD 699050
  9538. +#define TICKS_PER_uSEC 1
  9539. +
  9540. +/*
  9541. + * These are useconds NOT ticks.
  9542. + *
  9543. + */
  9544. +#define mSEC_1 1000
  9545. +#define mSEC_5 (mSEC_1 * 5)
  9546. +#define mSEC_10 (mSEC_1 * 10)
  9547. +#define mSEC_25 (mSEC_1 * 25)
  9548. +#define SEC_1 (mSEC_1 * 1000)
  9549. +
  9550. +/*
  9551. + * Watchdog
  9552. + */
  9553. +#define PM_RSTC (PM_BASE+0x1c)
  9554. +#define PM_RSTS (PM_BASE+0x20)
  9555. +#define PM_WDOG (PM_BASE+0x24)
  9556. +
  9557. +#define PM_WDOG_RESET 0000000000
  9558. +#define PM_PASSWORD 0x5a000000
  9559. +#define PM_WDOG_TIME_SET 0x000fffff
  9560. +#define PM_RSTC_WRCFG_CLR 0xffffffcf
  9561. +#define PM_RSTC_WRCFG_SET 0x00000030
  9562. +#define PM_RSTC_WRCFG_FULL_RESET 0x00000020
  9563. +#define PM_RSTC_RESET 0x00000102
  9564. +
  9565. +#define PM_RSTS_HADPOR_SET 0x00001000
  9566. +#define PM_RSTS_HADSRH_SET 0x00000400
  9567. +#define PM_RSTS_HADSRF_SET 0x00000200
  9568. +#define PM_RSTS_HADSRQ_SET 0x00000100
  9569. +#define PM_RSTS_HADWRH_SET 0x00000040
  9570. +#define PM_RSTS_HADWRF_SET 0x00000020
  9571. +#define PM_RSTS_HADWRQ_SET 0x00000010
  9572. +#define PM_RSTS_HADDRH_SET 0x00000004
  9573. +#define PM_RSTS_HADDRF_SET 0x00000002
  9574. +#define PM_RSTS_HADDRQ_SET 0x00000001
  9575. +
  9576. +#define UART0_CLOCK 3000000
  9577. +
  9578. +#endif
  9579. +
  9580. +/* END */
  9581. diff -Nur linux-3.18.8/arch/arm/mach-bcm2708/include/mach/power.h linux-rpi/arch/arm/mach-bcm2708/include/mach/power.h
  9582. --- linux-3.18.8/arch/arm/mach-bcm2708/include/mach/power.h 1970-01-01 01:00:00.000000000 +0100
  9583. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/power.h 2015-03-05 14:40:11.153715839 +0100
  9584. @@ -0,0 +1,26 @@
  9585. +/*
  9586. + * linux/arch/arm/mach-bcm2708/power.h
  9587. + *
  9588. + * Copyright (C) 2010 Broadcom
  9589. + *
  9590. + * This program is free software; you can redistribute it and/or modify
  9591. + * it under the terms of the GNU General Public License version 2 as
  9592. + * published by the Free Software Foundation.
  9593. + *
  9594. + * This device provides a shared mechanism for controlling the power to
  9595. + * VideoCore subsystems.
  9596. + */
  9597. +
  9598. +#ifndef _MACH_BCM2708_POWER_H
  9599. +#define _MACH_BCM2708_POWER_H
  9600. +
  9601. +#include <linux/types.h>
  9602. +#include <mach/arm_power.h>
  9603. +
  9604. +typedef unsigned int BCM_POWER_HANDLE_T;
  9605. +
  9606. +extern int bcm_power_open(BCM_POWER_HANDLE_T *handle);
  9607. +extern int bcm_power_request(BCM_POWER_HANDLE_T handle, uint32_t request);
  9608. +extern int bcm_power_close(BCM_POWER_HANDLE_T handle);
  9609. +
  9610. +#endif
  9611. diff -Nur linux-3.18.8/arch/arm/mach-bcm2708/include/mach/system.h linux-rpi/arch/arm/mach-bcm2708/include/mach/system.h
  9612. --- linux-3.18.8/arch/arm/mach-bcm2708/include/mach/system.h 1970-01-01 01:00:00.000000000 +0100
  9613. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/system.h 2015-03-05 14:40:11.153715839 +0100
  9614. @@ -0,0 +1,38 @@
  9615. +/*
  9616. + * arch/arm/mach-bcm2708/include/mach/system.h
  9617. + *
  9618. + * Copyright (C) 2010 Broadcom
  9619. + * Copyright (C) 2003 ARM Limited
  9620. + * Copyright (C) 2000 Deep Blue Solutions Ltd
  9621. + *
  9622. + * This program is free software; you can redistribute it and/or modify
  9623. + * it under the terms of the GNU General Public License as published by
  9624. + * the Free Software Foundation; either version 2 of the License, or
  9625. + * (at your option) any later version.
  9626. + *
  9627. + * This program is distributed in the hope that it will be useful,
  9628. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9629. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9630. + * GNU General Public License for more details.
  9631. + *
  9632. + * You should have received a copy of the GNU General Public License
  9633. + * along with this program; if not, write to the Free Software
  9634. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  9635. + */
  9636. +#ifndef __ASM_ARCH_SYSTEM_H
  9637. +#define __ASM_ARCH_SYSTEM_H
  9638. +
  9639. +#include <linux/io.h>
  9640. +#include <mach/hardware.h>
  9641. +#include <mach/platform.h>
  9642. +
  9643. +static inline void arch_idle(void)
  9644. +{
  9645. + /*
  9646. + * This should do all the clock switching
  9647. + * and wait for interrupt tricks
  9648. + */
  9649. + cpu_do_idle();
  9650. +}
  9651. +
  9652. +#endif
  9653. diff -Nur linux-3.18.8/arch/arm/mach-bcm2708/include/mach/timex.h linux-rpi/arch/arm/mach-bcm2708/include/mach/timex.h
  9654. --- linux-3.18.8/arch/arm/mach-bcm2708/include/mach/timex.h 1970-01-01 01:00:00.000000000 +0100
  9655. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/timex.h 2015-03-05 14:40:11.153715839 +0100
  9656. @@ -0,0 +1,23 @@
  9657. +/*
  9658. + * arch/arm/mach-bcm2708/include/mach/timex.h
  9659. + *
  9660. + * BCM2708 sysem clock frequency
  9661. + *
  9662. + * Copyright (C) 2010 Broadcom
  9663. + *
  9664. + * This program is free software; you can redistribute it and/or modify
  9665. + * it under the terms of the GNU General Public License as published by
  9666. + * the Free Software Foundation; either version 2 of the License, or
  9667. + * (at your option) any later version.
  9668. + *
  9669. + * This program is distributed in the hope that it will be useful,
  9670. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9671. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9672. + * GNU General Public License for more details.
  9673. + *
  9674. + * You should have received a copy of the GNU General Public License
  9675. + * along with this program; if not, write to the Free Software
  9676. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  9677. + */
  9678. +
  9679. +#define CLOCK_TICK_RATE (1000000)
  9680. diff -Nur linux-3.18.8/arch/arm/mach-bcm2708/include/mach/uncompress.h linux-rpi/arch/arm/mach-bcm2708/include/mach/uncompress.h
  9681. --- linux-3.18.8/arch/arm/mach-bcm2708/include/mach/uncompress.h 1970-01-01 01:00:00.000000000 +0100
  9682. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/uncompress.h 2015-03-05 14:40:11.153715839 +0100
  9683. @@ -0,0 +1,84 @@
  9684. +/*
  9685. + * arch/arm/mach-bcn2708/include/mach/uncompress.h
  9686. + *
  9687. + * Copyright (C) 2010 Broadcom
  9688. + * Copyright (C) 2003 ARM Limited
  9689. + *
  9690. + * This program is free software; you can redistribute it and/or modify
  9691. + * it under the terms of the GNU General Public License as published by
  9692. + * the Free Software Foundation; either version 2 of the License, or
  9693. + * (at your option) any later version.
  9694. + *
  9695. + * This program is distributed in the hope that it will be useful,
  9696. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9697. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9698. + * GNU General Public License for more details.
  9699. + *
  9700. + * You should have received a copy of the GNU General Public License
  9701. + * along with this program; if not, write to the Free Software
  9702. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  9703. + */
  9704. +
  9705. +#include <linux/io.h>
  9706. +#include <linux/amba/serial.h>
  9707. +#include <mach/hardware.h>
  9708. +
  9709. +#define UART_BAUD 115200
  9710. +
  9711. +#define BCM2708_UART_DR __io(UART0_BASE + UART01x_DR)
  9712. +#define BCM2708_UART_FR __io(UART0_BASE + UART01x_FR)
  9713. +#define BCM2708_UART_IBRD __io(UART0_BASE + UART011_IBRD)
  9714. +#define BCM2708_UART_FBRD __io(UART0_BASE + UART011_FBRD)
  9715. +#define BCM2708_UART_LCRH __io(UART0_BASE + UART011_LCRH)
  9716. +#define BCM2708_UART_CR __io(UART0_BASE + UART011_CR)
  9717. +
  9718. +/*
  9719. + * This does not append a newline
  9720. + */
  9721. +static inline void putc(int c)
  9722. +{
  9723. + while (__raw_readl(BCM2708_UART_FR) & UART01x_FR_TXFF)
  9724. + barrier();
  9725. +
  9726. + __raw_writel(c, BCM2708_UART_DR);
  9727. +}
  9728. +
  9729. +static inline void flush(void)
  9730. +{
  9731. + int fr;
  9732. +
  9733. + do {
  9734. + fr = __raw_readl(BCM2708_UART_FR);
  9735. + barrier();
  9736. + } while ((fr & (UART011_FR_TXFE | UART01x_FR_BUSY)) != UART011_FR_TXFE);
  9737. +}
  9738. +
  9739. +static inline void arch_decomp_setup(void)
  9740. +{
  9741. + int temp, div, rem, frac;
  9742. +
  9743. + temp = 16 * UART_BAUD;
  9744. + div = UART0_CLOCK / temp;
  9745. + rem = UART0_CLOCK % temp;
  9746. + temp = (8 * rem) / UART_BAUD;
  9747. + frac = (temp >> 1) + (temp & 1);
  9748. +
  9749. + /* Make sure the UART is disabled before we start */
  9750. + __raw_writel(0, BCM2708_UART_CR);
  9751. +
  9752. + /* Set the baud rate */
  9753. + __raw_writel(div, BCM2708_UART_IBRD);
  9754. + __raw_writel(frac, BCM2708_UART_FBRD);
  9755. +
  9756. + /* Set the UART to 8n1, FIFO enabled */
  9757. + __raw_writel(UART01x_LCRH_WLEN_8 | UART01x_LCRH_FEN, BCM2708_UART_LCRH);
  9758. +
  9759. + /* Enable the UART */
  9760. + __raw_writel(UART01x_CR_UARTEN | UART011_CR_TXE | UART011_CR_RXE,
  9761. + BCM2708_UART_CR);
  9762. +}
  9763. +
  9764. +/*
  9765. + * nothing to do
  9766. + */
  9767. +#define arch_decomp_wdog()
  9768. diff -Nur linux-3.18.8/arch/arm/mach-bcm2708/include/mach/vcio.h linux-rpi/arch/arm/mach-bcm2708/include/mach/vcio.h
  9769. --- linux-3.18.8/arch/arm/mach-bcm2708/include/mach/vcio.h 1970-01-01 01:00:00.000000000 +0100
  9770. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/vcio.h 2015-03-05 14:40:11.153715839 +0100
  9771. @@ -0,0 +1,165 @@
  9772. +/*
  9773. + * arch/arm/mach-bcm2708/include/mach/vcio.h
  9774. + *
  9775. + * Copyright (C) 2010 Broadcom
  9776. + *
  9777. + * This program is free software; you can redistribute it and/or modify
  9778. + * it under the terms of the GNU General Public License as published by
  9779. + * the Free Software Foundation; either version 2 of the License, or
  9780. + * (at your option) any later version.
  9781. + *
  9782. + * This program is distributed in the hope that it will be useful,
  9783. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9784. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9785. + * GNU General Public License for more details.
  9786. + *
  9787. + * You should have received a copy of the GNU General Public License
  9788. + * along with this program; if not, write to the Free Software
  9789. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  9790. + */
  9791. +#ifndef _MACH_BCM2708_VCIO_H
  9792. +#define _MACH_BCM2708_VCIO_H
  9793. +
  9794. +/* Routines to handle I/O via the VideoCore "ARM control" registers
  9795. + * (semaphores, doorbells, mailboxes)
  9796. + */
  9797. +
  9798. +#define BCM_VCIO_DRIVER_NAME "bcm2708_vcio"
  9799. +
  9800. +/* Constants shared with the ARM identifying separate mailbox channels */
  9801. +#define MBOX_CHAN_POWER 0 /* for use by the power management interface */
  9802. +#define MBOX_CHAN_FB 1 /* for use by the frame buffer */
  9803. +#define MBOX_CHAN_VCHIQ 3 /* for use by the VCHIQ interface */
  9804. +#define MBOX_CHAN_PROPERTY 8 /* for use by the property channel */
  9805. +#define MBOX_CHAN_COUNT 9
  9806. +
  9807. +enum {
  9808. + VCMSG_PROCESS_REQUEST = 0x00000000
  9809. +};
  9810. +enum {
  9811. + VCMSG_REQUEST_SUCCESSFUL = 0x80000000,
  9812. + VCMSG_REQUEST_FAILED = 0x80000001
  9813. +};
  9814. +/* Mailbox property tags */
  9815. +enum {
  9816. + VCMSG_PROPERTY_END = 0x00000000,
  9817. + VCMSG_GET_FIRMWARE_REVISION = 0x00000001,
  9818. + VCMSG_GET_BOARD_MODEL = 0x00010001,
  9819. + VCMSG_GET_BOARD_REVISION = 0x00010002,
  9820. + VCMSG_GET_BOARD_MAC_ADDRESS = 0x00010003,
  9821. + VCMSG_GET_BOARD_SERIAL = 0x00010004,
  9822. + VCMSG_GET_ARM_MEMORY = 0x00010005,
  9823. + VCMSG_GET_VC_MEMORY = 0x00010006,
  9824. + VCMSG_GET_CLOCKS = 0x00010007,
  9825. + VCMSG_GET_COMMAND_LINE = 0x00050001,
  9826. + VCMSG_GET_DMA_CHANNELS = 0x00060001,
  9827. + VCMSG_GET_POWER_STATE = 0x00020001,
  9828. + VCMSG_GET_TIMING = 0x00020002,
  9829. + VCMSG_SET_POWER_STATE = 0x00028001,
  9830. + VCMSG_GET_CLOCK_STATE = 0x00030001,
  9831. + VCMSG_SET_CLOCK_STATE = 0x00038001,
  9832. + VCMSG_GET_CLOCK_RATE = 0x00030002,
  9833. + VCMSG_SET_CLOCK_RATE = 0x00038002,
  9834. + VCMSG_GET_VOLTAGE = 0x00030003,
  9835. + VCMSG_SET_VOLTAGE = 0x00038003,
  9836. + VCMSG_GET_MAX_CLOCK = 0x00030004,
  9837. + VCMSG_GET_MAX_VOLTAGE = 0x00030005,
  9838. + VCMSG_GET_TEMPERATURE = 0x00030006,
  9839. + VCMSG_GET_MIN_CLOCK = 0x00030007,
  9840. + VCMSG_GET_MIN_VOLTAGE = 0x00030008,
  9841. + VCMSG_GET_TURBO = 0x00030009,
  9842. + VCMSG_GET_MAX_TEMPERATURE = 0x0003000a,
  9843. + VCMSG_GET_STC = 0x0003000b,
  9844. + VCMSG_SET_TURBO = 0x00038009,
  9845. + VCMSG_SET_ALLOCATE_MEM = 0x0003000c,
  9846. + VCMSG_SET_LOCK_MEM = 0x0003000d,
  9847. + VCMSG_SET_UNLOCK_MEM = 0x0003000e,
  9848. + VCMSG_SET_RELEASE_MEM = 0x0003000f,
  9849. + VCMSG_SET_EXECUTE_CODE = 0x00030010,
  9850. + VCMSG_SET_EXECUTE_QPU = 0x00030011,
  9851. + VCMSG_SET_ENABLE_QPU = 0x00030012,
  9852. + VCMSG_GET_RESOURCE_HANDLE = 0x00030014,
  9853. + VCMSG_GET_EDID_BLOCK = 0x00030020,
  9854. + VCMSG_GET_CUSTOMER_OTP = 0x00030021,
  9855. + VCMSG_SET_CUSTOMER_OTP = 0x00038021,
  9856. + VCMSG_SET_ALLOCATE_BUFFER = 0x00040001,
  9857. + VCMSG_SET_RELEASE_BUFFER = 0x00048001,
  9858. + VCMSG_SET_BLANK_SCREEN = 0x00040002,
  9859. + VCMSG_TST_BLANK_SCREEN = 0x00044002,
  9860. + VCMSG_GET_PHYSICAL_WIDTH_HEIGHT = 0x00040003,
  9861. + VCMSG_TST_PHYSICAL_WIDTH_HEIGHT = 0x00044003,
  9862. + VCMSG_SET_PHYSICAL_WIDTH_HEIGHT = 0x00048003,
  9863. + VCMSG_GET_VIRTUAL_WIDTH_HEIGHT = 0x00040004,
  9864. + VCMSG_TST_VIRTUAL_WIDTH_HEIGHT = 0x00044004,
  9865. + VCMSG_SET_VIRTUAL_WIDTH_HEIGHT = 0x00048004,
  9866. + VCMSG_GET_DEPTH = 0x00040005,
  9867. + VCMSG_TST_DEPTH = 0x00044005,
  9868. + VCMSG_SET_DEPTH = 0x00048005,
  9869. + VCMSG_GET_PIXEL_ORDER = 0x00040006,
  9870. + VCMSG_TST_PIXEL_ORDER = 0x00044006,
  9871. + VCMSG_SET_PIXEL_ORDER = 0x00048006,
  9872. + VCMSG_GET_ALPHA_MODE = 0x00040007,
  9873. + VCMSG_TST_ALPHA_MODE = 0x00044007,
  9874. + VCMSG_SET_ALPHA_MODE = 0x00048007,
  9875. + VCMSG_GET_PITCH = 0x00040008,
  9876. + VCMSG_TST_PITCH = 0x00044008,
  9877. + VCMSG_SET_PITCH = 0x00048008,
  9878. + VCMSG_GET_VIRTUAL_OFFSET = 0x00040009,
  9879. + VCMSG_TST_VIRTUAL_OFFSET = 0x00044009,
  9880. + VCMSG_SET_VIRTUAL_OFFSET = 0x00048009,
  9881. + VCMSG_GET_OVERSCAN = 0x0004000a,
  9882. + VCMSG_TST_OVERSCAN = 0x0004400a,
  9883. + VCMSG_SET_OVERSCAN = 0x0004800a,
  9884. + VCMSG_GET_PALETTE = 0x0004000b,
  9885. + VCMSG_TST_PALETTE = 0x0004400b,
  9886. + VCMSG_SET_PALETTE = 0x0004800b,
  9887. + VCMSG_GET_LAYER = 0x0004000c,
  9888. + VCMSG_TST_LAYER = 0x0004400c,
  9889. + VCMSG_SET_LAYER = 0x0004800c,
  9890. + VCMSG_GET_TRANSFORM = 0x0004000d,
  9891. + VCMSG_TST_TRANSFORM = 0x0004400d,
  9892. + VCMSG_SET_TRANSFORM = 0x0004800d,
  9893. + VCMSG_TST_VSYNC = 0x0004400e,
  9894. + VCMSG_SET_VSYNC = 0x0004800e,
  9895. + VCMSG_SET_CURSOR_INFO = 0x00008010,
  9896. + VCMSG_SET_CURSOR_STATE = 0x00008011,
  9897. +};
  9898. +
  9899. +extern int /*rc*/ bcm_mailbox_read(unsigned chan, uint32_t *data28);
  9900. +extern int /*rc*/ bcm_mailbox_write(unsigned chan, uint32_t data28);
  9901. +extern int /*rc*/ bcm_mailbox_property(void *data, int size);
  9902. +
  9903. +#include <linux/ioctl.h>
  9904. +
  9905. +/*
  9906. + * The major device number. We can't rely on dynamic
  9907. + * registration any more, because ioctls need to know
  9908. + * it.
  9909. + */
  9910. +#define MAJOR_NUM 100
  9911. +
  9912. +/*
  9913. + * Set the message of the device driver
  9914. + */
  9915. +#define IOCTL_MBOX_PROPERTY _IOWR(MAJOR_NUM, 0, char *)
  9916. +/*
  9917. + * _IOWR means that we're creating an ioctl command
  9918. + * number for passing information from a user process
  9919. + * to the kernel module and from the kernel module to user process
  9920. + *
  9921. + * The first arguments, MAJOR_NUM, is the major device
  9922. + * number we're using.
  9923. + *
  9924. + * The second argument is the number of the command
  9925. + * (there could be several with different meanings).
  9926. + *
  9927. + * The third argument is the type we want to get from
  9928. + * the process to the kernel.
  9929. + */
  9930. +
  9931. +/*
  9932. + * The name of the device file
  9933. + */
  9934. +#define DEVICE_FILE_NAME "vcio"
  9935. +
  9936. +#endif
  9937. diff -Nur linux-3.18.8/arch/arm/mach-bcm2708/include/mach/vc_mem.h linux-rpi/arch/arm/mach-bcm2708/include/mach/vc_mem.h
  9938. --- linux-3.18.8/arch/arm/mach-bcm2708/include/mach/vc_mem.h 1970-01-01 01:00:00.000000000 +0100
  9939. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/vc_mem.h 2015-03-05 14:40:11.153715839 +0100
  9940. @@ -0,0 +1,35 @@
  9941. +/*****************************************************************************
  9942. +* Copyright 2010 - 2011 Broadcom Corporation. All rights reserved.
  9943. +*
  9944. +* Unless you and Broadcom execute a separate written software license
  9945. +* agreement governing use of this software, this software is licensed to you
  9946. +* under the terms of the GNU General Public License version 2, available at
  9947. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  9948. +*
  9949. +* Notwithstanding the above, under no circumstances may you combine this
  9950. +* software in any way with any other Broadcom software provided under a
  9951. +* license other than the GPL, without Broadcom's express prior written
  9952. +* consent.
  9953. +*****************************************************************************/
  9954. +
  9955. +#if !defined( VC_MEM_H )
  9956. +#define VC_MEM_H
  9957. +
  9958. +#include <linux/ioctl.h>
  9959. +
  9960. +#define VC_MEM_IOC_MAGIC 'v'
  9961. +
  9962. +#define VC_MEM_IOC_MEM_PHYS_ADDR _IOR( VC_MEM_IOC_MAGIC, 0, unsigned long )
  9963. +#define VC_MEM_IOC_MEM_SIZE _IOR( VC_MEM_IOC_MAGIC, 1, unsigned int )
  9964. +#define VC_MEM_IOC_MEM_BASE _IOR( VC_MEM_IOC_MAGIC, 2, unsigned int )
  9965. +#define VC_MEM_IOC_MEM_LOAD _IOR( VC_MEM_IOC_MAGIC, 3, unsigned int )
  9966. +
  9967. +#if defined( __KERNEL__ )
  9968. +#define VC_MEM_TO_ARM_ADDR_MASK 0x3FFFFFFF
  9969. +
  9970. +extern unsigned long mm_vc_mem_phys_addr;
  9971. +extern unsigned int mm_vc_mem_size;
  9972. +extern int vc_mem_get_current_size( void );
  9973. +#endif
  9974. +
  9975. +#endif /* VC_MEM_H */
  9976. diff -Nur linux-3.18.8/arch/arm/mach-bcm2708/include/mach/vc_sm_defs.h linux-rpi/arch/arm/mach-bcm2708/include/mach/vc_sm_defs.h
  9977. --- linux-3.18.8/arch/arm/mach-bcm2708/include/mach/vc_sm_defs.h 1970-01-01 01:00:00.000000000 +0100
  9978. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/vc_sm_defs.h 2015-03-05 14:40:11.153715839 +0100
  9979. @@ -0,0 +1,181 @@
  9980. +/*****************************************************************************
  9981. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  9982. +*
  9983. +* Unless you and Broadcom execute a separate written software license
  9984. +* agreement governing use of this software, this software is licensed to you
  9985. +* under the terms of the GNU General Public License version 2, available at
  9986. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  9987. +*
  9988. +* Notwithstanding the above, under no circumstances may you combine this
  9989. +* software in any way with any other Broadcom software provided under a
  9990. +* license other than the GPL, without Broadcom's express prior written
  9991. +* consent.
  9992. +*****************************************************************************/
  9993. +
  9994. +#ifndef __VC_SM_DEFS_H__INCLUDED__
  9995. +#define __VC_SM_DEFS_H__INCLUDED__
  9996. +
  9997. +/* FourCC code used for VCHI connection */
  9998. +#define VC_SM_SERVER_NAME MAKE_FOURCC("SMEM")
  9999. +
  10000. +/* Maximum message length */
  10001. +#define VC_SM_MAX_MSG_LEN (sizeof(VC_SM_MSG_UNION_T) + \
  10002. + sizeof(VC_SM_MSG_HDR_T))
  10003. +#define VC_SM_MAX_RSP_LEN (sizeof(VC_SM_MSG_UNION_T))
  10004. +
  10005. +/* Resource name maximum size */
  10006. +#define VC_SM_RESOURCE_NAME 32
  10007. +
  10008. +/* All message types supported for HOST->VC direction */
  10009. +typedef enum {
  10010. + /* Allocate shared memory block */
  10011. + VC_SM_MSG_TYPE_ALLOC,
  10012. + /* Lock allocated shared memory block */
  10013. + VC_SM_MSG_TYPE_LOCK,
  10014. + /* Unlock allocated shared memory block */
  10015. + VC_SM_MSG_TYPE_UNLOCK,
  10016. + /* Unlock allocated shared memory block, do not answer command */
  10017. + VC_SM_MSG_TYPE_UNLOCK_NOANS,
  10018. + /* Free shared memory block */
  10019. + VC_SM_MSG_TYPE_FREE,
  10020. + /* Resize a shared memory block */
  10021. + VC_SM_MSG_TYPE_RESIZE,
  10022. + /* Walk the allocated shared memory block(s) */
  10023. + VC_SM_MSG_TYPE_WALK_ALLOC,
  10024. +
  10025. + /* A previously applied action will need to be reverted */
  10026. + VC_SM_MSG_TYPE_ACTION_CLEAN,
  10027. + VC_SM_MSG_TYPE_MAX
  10028. +} VC_SM_MSG_TYPE;
  10029. +
  10030. +/* Type of memory to be allocated */
  10031. +typedef enum {
  10032. + VC_SM_ALLOC_CACHED,
  10033. + VC_SM_ALLOC_NON_CACHED,
  10034. +
  10035. +} VC_SM_ALLOC_TYPE_T;
  10036. +
  10037. +/* Message header for all messages in HOST->VC direction */
  10038. +typedef struct {
  10039. + int32_t type;
  10040. + uint32_t trans_id;
  10041. + uint8_t body[0];
  10042. +
  10043. +} VC_SM_MSG_HDR_T;
  10044. +
  10045. +/* Request to allocate memory (HOST->VC) */
  10046. +typedef struct {
  10047. + /* type of memory to allocate */
  10048. + VC_SM_ALLOC_TYPE_T type;
  10049. + /* byte amount of data to allocate per unit */
  10050. + uint32_t base_unit;
  10051. + /* number of unit to allocate */
  10052. + uint32_t num_unit;
  10053. + /* alignement to be applied on allocation */
  10054. + uint32_t alignement;
  10055. + /* identity of who allocated this block */
  10056. + uint32_t allocator;
  10057. + /* resource name (for easier tracking on vc side) */
  10058. + char name[VC_SM_RESOURCE_NAME];
  10059. +
  10060. +} VC_SM_ALLOC_T;
  10061. +
  10062. +/* Result of a requested memory allocation (VC->HOST) */
  10063. +typedef struct {
  10064. + /* Transaction identifier */
  10065. + uint32_t trans_id;
  10066. +
  10067. + /* Resource handle */
  10068. + uint32_t res_handle;
  10069. + /* Pointer to resource buffer */
  10070. + void *res_mem;
  10071. + /* Resource base size (bytes) */
  10072. + uint32_t res_base_size;
  10073. + /* Resource number */
  10074. + uint32_t res_num;
  10075. +
  10076. +} VC_SM_ALLOC_RESULT_T;
  10077. +
  10078. +/* Request to free a previously allocated memory (HOST->VC) */
  10079. +typedef struct {
  10080. + /* Resource handle (returned from alloc) */
  10081. + uint32_t res_handle;
  10082. + /* Resource buffer (returned from alloc) */
  10083. + void *res_mem;
  10084. +
  10085. +} VC_SM_FREE_T;
  10086. +
  10087. +/* Request to lock a previously allocated memory (HOST->VC) */
  10088. +typedef struct {
  10089. + /* Resource handle (returned from alloc) */
  10090. + uint32_t res_handle;
  10091. + /* Resource buffer (returned from alloc) */
  10092. + void *res_mem;
  10093. +
  10094. +} VC_SM_LOCK_UNLOCK_T;
  10095. +
  10096. +/* Request to resize a previously allocated memory (HOST->VC) */
  10097. +typedef struct {
  10098. + /* Resource handle (returned from alloc) */
  10099. + uint32_t res_handle;
  10100. + /* Resource buffer (returned from alloc) */
  10101. + void *res_mem;
  10102. + /* Resource *new* size requested (bytes) */
  10103. + uint32_t res_new_size;
  10104. +
  10105. +} VC_SM_RESIZE_T;
  10106. +
  10107. +/* Result of a requested memory lock (VC->HOST) */
  10108. +typedef struct {
  10109. + /* Transaction identifier */
  10110. + uint32_t trans_id;
  10111. +
  10112. + /* Resource handle */
  10113. + uint32_t res_handle;
  10114. + /* Pointer to resource buffer */
  10115. + void *res_mem;
  10116. + /* Pointer to former resource buffer if the memory
  10117. + * was reallocated */
  10118. + void *res_old_mem;
  10119. +
  10120. +} VC_SM_LOCK_RESULT_T;
  10121. +
  10122. +/* Generic result for a request (VC->HOST) */
  10123. +typedef struct {
  10124. + /* Transaction identifier */
  10125. + uint32_t trans_id;
  10126. +
  10127. + int32_t success;
  10128. +
  10129. +} VC_SM_RESULT_T;
  10130. +
  10131. +/* Request to revert a previously applied action (HOST->VC) */
  10132. +typedef struct {
  10133. + /* Action of interest */
  10134. + VC_SM_MSG_TYPE res_action;
  10135. + /* Transaction identifier for the action of interest */
  10136. + uint32_t action_trans_id;
  10137. +
  10138. +} VC_SM_ACTION_CLEAN_T;
  10139. +
  10140. +/* Request to remove all data associated with a given allocator (HOST->VC) */
  10141. +typedef struct {
  10142. + /* Allocator identifier */
  10143. + uint32_t allocator;
  10144. +
  10145. +} VC_SM_FREE_ALL_T;
  10146. +
  10147. +/* Union of ALL messages */
  10148. +typedef union {
  10149. + VC_SM_ALLOC_T alloc;
  10150. + VC_SM_ALLOC_RESULT_T alloc_result;
  10151. + VC_SM_FREE_T free;
  10152. + VC_SM_ACTION_CLEAN_T action_clean;
  10153. + VC_SM_RESIZE_T resize;
  10154. + VC_SM_LOCK_RESULT_T lock_result;
  10155. + VC_SM_RESULT_T result;
  10156. + VC_SM_FREE_ALL_T free_all;
  10157. +
  10158. +} VC_SM_MSG_UNION_T;
  10159. +
  10160. +#endif /* __VC_SM_DEFS_H__INCLUDED__ */
  10161. diff -Nur linux-3.18.8/arch/arm/mach-bcm2708/include/mach/vc_sm_knl.h linux-rpi/arch/arm/mach-bcm2708/include/mach/vc_sm_knl.h
  10162. --- linux-3.18.8/arch/arm/mach-bcm2708/include/mach/vc_sm_knl.h 1970-01-01 01:00:00.000000000 +0100
  10163. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/vc_sm_knl.h 2015-03-05 14:40:11.153715839 +0100
  10164. @@ -0,0 +1,55 @@
  10165. +/*****************************************************************************
  10166. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  10167. +*
  10168. +* Unless you and Broadcom execute a separate written software license
  10169. +* agreement governing use of this software, this software is licensed to you
  10170. +* under the terms of the GNU General Public License version 2, available at
  10171. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  10172. +*
  10173. +* Notwithstanding the above, under no circumstances may you combine this
  10174. +* software in any way with any other Broadcom software provided under a
  10175. +* license other than the GPL, without Broadcom's express prior written
  10176. +* consent.
  10177. +*****************************************************************************/
  10178. +
  10179. +#ifndef __VC_SM_KNL_H__INCLUDED__
  10180. +#define __VC_SM_KNL_H__INCLUDED__
  10181. +
  10182. +#if !defined(__KERNEL__)
  10183. +#error "This interface is for kernel use only..."
  10184. +#endif
  10185. +
  10186. +/* Type of memory to be locked (ie mapped) */
  10187. +typedef enum {
  10188. + VC_SM_LOCK_CACHED,
  10189. + VC_SM_LOCK_NON_CACHED,
  10190. +
  10191. +} VC_SM_LOCK_CACHE_MODE_T;
  10192. +
  10193. +/* Allocate a shared memory handle and block.
  10194. +*/
  10195. +int vc_sm_alloc(VC_SM_ALLOC_T *alloc, int *handle);
  10196. +
  10197. +/* Free a previously allocated shared memory handle and block.
  10198. +*/
  10199. +int vc_sm_free(int handle);
  10200. +
  10201. +/* Lock a memory handle for use by kernel.
  10202. +*/
  10203. +int vc_sm_lock(int handle, VC_SM_LOCK_CACHE_MODE_T mode,
  10204. + long unsigned int *data);
  10205. +
  10206. +/* Unlock a memory handle in use by kernel.
  10207. +*/
  10208. +int vc_sm_unlock(int handle, int flush, int no_vc_unlock);
  10209. +
  10210. +/* Get an internal resource handle mapped from the external one.
  10211. +*/
  10212. +int vc_sm_int_handle(int handle);
  10213. +
  10214. +/* Map a shared memory region for use by kernel.
  10215. +*/
  10216. +int vc_sm_map(int handle, unsigned int sm_addr, VC_SM_LOCK_CACHE_MODE_T mode,
  10217. + long unsigned int *data);
  10218. +
  10219. +#endif /* __VC_SM_KNL_H__INCLUDED__ */
  10220. diff -Nur linux-3.18.8/arch/arm/mach-bcm2708/include/mach/vc_vchi_sm.h linux-rpi/arch/arm/mach-bcm2708/include/mach/vc_vchi_sm.h
  10221. --- linux-3.18.8/arch/arm/mach-bcm2708/include/mach/vc_vchi_sm.h 1970-01-01 01:00:00.000000000 +0100
  10222. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/vc_vchi_sm.h 2015-03-05 14:40:11.153715839 +0100
  10223. @@ -0,0 +1,82 @@
  10224. +/*****************************************************************************
  10225. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  10226. +*
  10227. +* Unless you and Broadcom execute a separate written software license
  10228. +* agreement governing use of this software, this software is licensed to you
  10229. +* under the terms of the GNU General Public License version 2, available at
  10230. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  10231. +*
  10232. +* Notwithstanding the above, under no circumstances may you combine this
  10233. +* software in any way with any other Broadcom software provided under a
  10234. +* license other than the GPL, without Broadcom's express prior written
  10235. +* consent.
  10236. +*****************************************************************************/
  10237. +
  10238. +#ifndef __VC_VCHI_SM_H__INCLUDED__
  10239. +#define __VC_VCHI_SM_H__INCLUDED__
  10240. +
  10241. +#include "interface/vchi/vchi.h"
  10242. +
  10243. +#include "vc_sm_defs.h"
  10244. +
  10245. +/* Forward declare.
  10246. +*/
  10247. +typedef struct sm_instance *VC_VCHI_SM_HANDLE_T;
  10248. +
  10249. +/* Initialize the shared memory service, opens up vchi connection to talk to it.
  10250. +*/
  10251. +VC_VCHI_SM_HANDLE_T vc_vchi_sm_init(VCHI_INSTANCE_T vchi_instance,
  10252. + VCHI_CONNECTION_T **vchi_connections,
  10253. + uint32_t num_connections);
  10254. +
  10255. +/* Terminates the shared memory service.
  10256. +*/
  10257. +int vc_vchi_sm_stop(VC_VCHI_SM_HANDLE_T *handle);
  10258. +
  10259. +/* Ask the shared memory service to allocate some memory on videocre and
  10260. +** return the result of this allocation (which upon success will be a pointer
  10261. +** to some memory in videocore space).
  10262. +*/
  10263. +int vc_vchi_sm_alloc(VC_VCHI_SM_HANDLE_T handle,
  10264. + VC_SM_ALLOC_T *alloc,
  10265. + VC_SM_ALLOC_RESULT_T *alloc_result, uint32_t *trans_id);
  10266. +
  10267. +/* Ask the shared memory service to free up some memory that was previously
  10268. +** allocated by the vc_vchi_sm_alloc function call.
  10269. +*/
  10270. +int vc_vchi_sm_free(VC_VCHI_SM_HANDLE_T handle,
  10271. + VC_SM_FREE_T *free, uint32_t *trans_id);
  10272. +
  10273. +/* Ask the shared memory service to lock up some memory that was previously
  10274. +** allocated by the vc_vchi_sm_alloc function call.
  10275. +*/
  10276. +int vc_vchi_sm_lock(VC_VCHI_SM_HANDLE_T handle,
  10277. + VC_SM_LOCK_UNLOCK_T *lock_unlock,
  10278. + VC_SM_LOCK_RESULT_T *lock_result, uint32_t *trans_id);
  10279. +
  10280. +/* Ask the shared memory service to unlock some memory that was previously
  10281. +** allocated by the vc_vchi_sm_alloc function call.
  10282. +*/
  10283. +int vc_vchi_sm_unlock(VC_VCHI_SM_HANDLE_T handle,
  10284. + VC_SM_LOCK_UNLOCK_T *lock_unlock,
  10285. + uint32_t *trans_id, uint8_t wait_reply);
  10286. +
  10287. +/* Ask the shared memory service to resize some memory that was previously
  10288. +** allocated by the vc_vchi_sm_alloc function call.
  10289. +*/
  10290. +int vc_vchi_sm_resize(VC_VCHI_SM_HANDLE_T handle,
  10291. + VC_SM_RESIZE_T *resize, uint32_t *trans_id);
  10292. +
  10293. +/* Walk the allocated resources on the videocore side, the allocation will
  10294. +** show up in the log. This is purely for debug/information and takes no
  10295. +** specific actions.
  10296. +*/
  10297. +int vc_vchi_sm_walk_alloc(VC_VCHI_SM_HANDLE_T handle);
  10298. +
  10299. +/* Clean up following a previously interrupted action which left the system
  10300. +** in a bad state of some sort.
  10301. +*/
  10302. +int vc_vchi_sm_clean_up(VC_VCHI_SM_HANDLE_T handle,
  10303. + VC_SM_ACTION_CLEAN_T *action_clean);
  10304. +
  10305. +#endif /* __VC_VCHI_SM_H__INCLUDED__ */
  10306. diff -Nur linux-3.18.8/arch/arm/mach-bcm2708/include/mach/vmalloc.h linux-rpi/arch/arm/mach-bcm2708/include/mach/vmalloc.h
  10307. --- linux-3.18.8/arch/arm/mach-bcm2708/include/mach/vmalloc.h 1970-01-01 01:00:00.000000000 +0100
  10308. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/vmalloc.h 2015-03-05 14:40:11.153715839 +0100
  10309. @@ -0,0 +1,20 @@
  10310. +/*
  10311. + * arch/arm/mach-bcm2708/include/mach/vmalloc.h
  10312. + *
  10313. + * Copyright (C) 2010 Broadcom
  10314. + *
  10315. + * This program is free software; you can redistribute it and/or modify
  10316. + * it under the terms of the GNU General Public License as published by
  10317. + * the Free Software Foundation; either version 2 of the License, or
  10318. + * (at your option) any later version.
  10319. + *
  10320. + * This program is distributed in the hope that it will be useful,
  10321. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10322. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10323. + * GNU General Public License for more details.
  10324. + *
  10325. + * You should have received a copy of the GNU General Public License
  10326. + * along with this program; if not, write to the Free Software
  10327. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  10328. + */
  10329. +#define VMALLOC_END (0xe8000000)
  10330. diff -Nur linux-3.18.8/arch/arm/mach-bcm2708/include/mach/vmcs_sm_ioctl.h linux-rpi/arch/arm/mach-bcm2708/include/mach/vmcs_sm_ioctl.h
  10331. --- linux-3.18.8/arch/arm/mach-bcm2708/include/mach/vmcs_sm_ioctl.h 1970-01-01 01:00:00.000000000 +0100
  10332. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/vmcs_sm_ioctl.h 2015-03-05 14:40:11.153715839 +0100
  10333. @@ -0,0 +1,233 @@
  10334. +/*****************************************************************************
  10335. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  10336. +*
  10337. +* Unless you and Broadcom execute a separate written software license
  10338. +* agreement governing use of this software, this software is licensed to you
  10339. +* under the terms of the GNU General Public License version 2, available at
  10340. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  10341. +*
  10342. +* Notwithstanding the above, under no circumstances may you combine this
  10343. +* software in any way with any other Broadcom software provided under a
  10344. +* license other than the GPL, without Broadcom's express prior written
  10345. +* consent.
  10346. +*
  10347. +*****************************************************************************/
  10348. +
  10349. +#if !defined(__VMCS_SM_IOCTL_H__INCLUDED__)
  10350. +#define __VMCS_SM_IOCTL_H__INCLUDED__
  10351. +
  10352. +/* ---- Include Files ---------------------------------------------------- */
  10353. +
  10354. +#if defined(__KERNEL__)
  10355. +#include <linux/types.h> /* Needed for standard types */
  10356. +#else
  10357. +#include <stdint.h>
  10358. +#endif
  10359. +
  10360. +#include <linux/ioctl.h>
  10361. +
  10362. +/* ---- Constants and Types ---------------------------------------------- */
  10363. +
  10364. +#define VMCS_SM_RESOURCE_NAME 32
  10365. +#define VMCS_SM_RESOURCE_NAME_DEFAULT "sm-host-resource"
  10366. +
  10367. +/* Type define used to create unique IOCTL number */
  10368. +#define VMCS_SM_MAGIC_TYPE 'I'
  10369. +
  10370. +/* IOCTL commands */
  10371. +enum vmcs_sm_cmd_e {
  10372. + VMCS_SM_CMD_ALLOC = 0x5A, /* Start at 0x5A arbitrarily */
  10373. + VMCS_SM_CMD_ALLOC_SHARE,
  10374. + VMCS_SM_CMD_LOCK,
  10375. + VMCS_SM_CMD_LOCK_CACHE,
  10376. + VMCS_SM_CMD_UNLOCK,
  10377. + VMCS_SM_CMD_RESIZE,
  10378. + VMCS_SM_CMD_UNMAP,
  10379. + VMCS_SM_CMD_FREE,
  10380. + VMCS_SM_CMD_FLUSH,
  10381. + VMCS_SM_CMD_INVALID,
  10382. +
  10383. + VMCS_SM_CMD_SIZE_USR_HANDLE,
  10384. + VMCS_SM_CMD_CHK_USR_HANDLE,
  10385. +
  10386. + VMCS_SM_CMD_MAPPED_USR_HANDLE,
  10387. + VMCS_SM_CMD_MAPPED_USR_ADDRESS,
  10388. + VMCS_SM_CMD_MAPPED_VC_HDL_FROM_ADDR,
  10389. + VMCS_SM_CMD_MAPPED_VC_HDL_FROM_HDL,
  10390. + VMCS_SM_CMD_MAPPED_VC_ADDR_FROM_HDL,
  10391. +
  10392. + VMCS_SM_CMD_VC_WALK_ALLOC,
  10393. + VMCS_SM_CMD_HOST_WALK_MAP,
  10394. + VMCS_SM_CMD_HOST_WALK_PID_ALLOC,
  10395. + VMCS_SM_CMD_HOST_WALK_PID_MAP,
  10396. +
  10397. + VMCS_SM_CMD_LAST /* Do no delete */
  10398. +};
  10399. +
  10400. +/* Cache type supported, conveniently matches the user space definition in
  10401. +** user-vcsm.h.
  10402. +*/
  10403. +enum vmcs_sm_cache_e {
  10404. + VMCS_SM_CACHE_NONE,
  10405. + VMCS_SM_CACHE_HOST,
  10406. + VMCS_SM_CACHE_VC,
  10407. + VMCS_SM_CACHE_BOTH,
  10408. +};
  10409. +
  10410. +/* IOCTL Data structures */
  10411. +struct vmcs_sm_ioctl_alloc {
  10412. + /* user -> kernel */
  10413. + unsigned int size;
  10414. + unsigned int num;
  10415. + enum vmcs_sm_cache_e cached;
  10416. + char name[VMCS_SM_RESOURCE_NAME];
  10417. +
  10418. + /* kernel -> user */
  10419. + unsigned int handle;
  10420. + /* unsigned int base_addr; */
  10421. +};
  10422. +
  10423. +struct vmcs_sm_ioctl_alloc_share {
  10424. + /* user -> kernel */
  10425. + unsigned int handle;
  10426. + unsigned int size;
  10427. +};
  10428. +
  10429. +struct vmcs_sm_ioctl_free {
  10430. + /* user -> kernel */
  10431. + unsigned int handle;
  10432. + /* unsigned int base_addr; */
  10433. +};
  10434. +
  10435. +struct vmcs_sm_ioctl_lock_unlock {
  10436. + /* user -> kernel */
  10437. + unsigned int handle;
  10438. +
  10439. + /* kernel -> user */
  10440. + unsigned int addr;
  10441. +};
  10442. +
  10443. +struct vmcs_sm_ioctl_lock_cache {
  10444. + /* user -> kernel */
  10445. + unsigned int handle;
  10446. + enum vmcs_sm_cache_e cached;
  10447. +};
  10448. +
  10449. +struct vmcs_sm_ioctl_resize {
  10450. + /* user -> kernel */
  10451. + unsigned int handle;
  10452. + unsigned int new_size;
  10453. +
  10454. + /* kernel -> user */
  10455. + unsigned int old_size;
  10456. +};
  10457. +
  10458. +struct vmcs_sm_ioctl_map {
  10459. + /* user -> kernel */
  10460. + /* and kernel -> user */
  10461. + unsigned int pid;
  10462. + unsigned int handle;
  10463. + unsigned int addr;
  10464. +
  10465. + /* kernel -> user */
  10466. + unsigned int size;
  10467. +};
  10468. +
  10469. +struct vmcs_sm_ioctl_walk {
  10470. + /* user -> kernel */
  10471. + unsigned int pid;
  10472. +};
  10473. +
  10474. +struct vmcs_sm_ioctl_chk {
  10475. + /* user -> kernel */
  10476. + unsigned int handle;
  10477. +
  10478. + /* kernel -> user */
  10479. + unsigned int addr;
  10480. + unsigned int size;
  10481. + enum vmcs_sm_cache_e cache;
  10482. +};
  10483. +
  10484. +struct vmcs_sm_ioctl_size {
  10485. + /* user -> kernel */
  10486. + unsigned int handle;
  10487. +
  10488. + /* kernel -> user */
  10489. + unsigned int size;
  10490. +};
  10491. +
  10492. +struct vmcs_sm_ioctl_cache {
  10493. + /* user -> kernel */
  10494. + unsigned int handle;
  10495. + unsigned int addr;
  10496. + unsigned int size;
  10497. +};
  10498. +
  10499. +/* IOCTL numbers */
  10500. +#define VMCS_SM_IOCTL_MEM_ALLOC\
  10501. + _IOR(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_ALLOC,\
  10502. + struct vmcs_sm_ioctl_alloc)
  10503. +#define VMCS_SM_IOCTL_MEM_ALLOC_SHARE\
  10504. + _IOR(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_ALLOC_SHARE,\
  10505. + struct vmcs_sm_ioctl_alloc_share)
  10506. +#define VMCS_SM_IOCTL_MEM_LOCK\
  10507. + _IOR(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_LOCK,\
  10508. + struct vmcs_sm_ioctl_lock_unlock)
  10509. +#define VMCS_SM_IOCTL_MEM_LOCK_CACHE\
  10510. + _IOR(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_LOCK_CACHE,\
  10511. + struct vmcs_sm_ioctl_lock_cache)
  10512. +#define VMCS_SM_IOCTL_MEM_UNLOCK\
  10513. + _IOR(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_UNLOCK,\
  10514. + struct vmcs_sm_ioctl_lock_unlock)
  10515. +#define VMCS_SM_IOCTL_MEM_RESIZE\
  10516. + _IOR(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_RESIZE,\
  10517. + struct vmcs_sm_ioctl_resize)
  10518. +#define VMCS_SM_IOCTL_MEM_FREE\
  10519. + _IOR(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_FREE,\
  10520. + struct vmcs_sm_ioctl_free)
  10521. +#define VMCS_SM_IOCTL_MEM_FLUSH\
  10522. + _IOR(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_FLUSH,\
  10523. + struct vmcs_sm_ioctl_cache)
  10524. +#define VMCS_SM_IOCTL_MEM_INVALID\
  10525. + _IOR(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_INVALID,\
  10526. + struct vmcs_sm_ioctl_cache)
  10527. +
  10528. +#define VMCS_SM_IOCTL_SIZE_USR_HDL\
  10529. + _IOR(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_SIZE_USR_HANDLE,\
  10530. + struct vmcs_sm_ioctl_size)
  10531. +#define VMCS_SM_IOCTL_CHK_USR_HDL\
  10532. + _IOR(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_CHK_USR_HANDLE,\
  10533. + struct vmcs_sm_ioctl_chk)
  10534. +
  10535. +#define VMCS_SM_IOCTL_MAP_USR_HDL\
  10536. + _IOR(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_MAPPED_USR_HANDLE,\
  10537. + struct vmcs_sm_ioctl_map)
  10538. +#define VMCS_SM_IOCTL_MAP_USR_ADDRESS\
  10539. + _IOR(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_MAPPED_USR_ADDRESS,\
  10540. + struct vmcs_sm_ioctl_map)
  10541. +#define VMCS_SM_IOCTL_MAP_VC_HDL_FR_ADDR\
  10542. + _IOR(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_MAPPED_VC_HDL_FROM_ADDR,\
  10543. + struct vmcs_sm_ioctl_map)
  10544. +#define VMCS_SM_IOCTL_MAP_VC_HDL_FR_HDL\
  10545. + _IOR(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_MAPPED_VC_HDL_FROM_HDL,\
  10546. + struct vmcs_sm_ioctl_map)
  10547. +#define VMCS_SM_IOCTL_MAP_VC_ADDR_FR_HDL\
  10548. + _IOR(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_MAPPED_VC_ADDR_FROM_HDL,\
  10549. + struct vmcs_sm_ioctl_map)
  10550. +
  10551. +#define VMCS_SM_IOCTL_VC_WALK_ALLOC\
  10552. + _IO(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_VC_WALK_ALLOC)
  10553. +#define VMCS_SM_IOCTL_HOST_WALK_MAP\
  10554. + _IO(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_HOST_WALK_MAP)
  10555. +#define VMCS_SM_IOCTL_HOST_WALK_PID_ALLOC\
  10556. + _IOR(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_HOST_WALK_PID_ALLOC,\
  10557. + struct vmcs_sm_ioctl_walk)
  10558. +#define VMCS_SM_IOCTL_HOST_WALK_PID_MAP\
  10559. + _IOR(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_HOST_WALK_PID_MAP,\
  10560. + struct vmcs_sm_ioctl_walk)
  10561. +
  10562. +/* ---- Variable Externs ------------------------------------------------- */
  10563. +
  10564. +/* ---- Function Prototypes ---------------------------------------------- */
  10565. +
  10566. +#endif /* __VMCS_SM_IOCTL_H__INCLUDED__ */
  10567. diff -Nur linux-3.18.8/arch/arm/mach-bcm2708/Kconfig linux-rpi/arch/arm/mach-bcm2708/Kconfig
  10568. --- linux-3.18.8/arch/arm/mach-bcm2708/Kconfig 1970-01-01 01:00:00.000000000 +0100
  10569. +++ linux-rpi/arch/arm/mach-bcm2708/Kconfig 2015-03-05 14:40:11.153715839 +0100
  10570. @@ -0,0 +1,52 @@
  10571. +menu "Broadcom BCM2708 Implementations"
  10572. + depends on ARCH_BCM2708
  10573. +
  10574. +config MACH_BCM2708
  10575. + bool "Broadcom BCM2708 Development Platform"
  10576. + select NEED_MACH_MEMORY_H
  10577. + select NEED_MACH_IO_H
  10578. + select CPU_V6
  10579. + help
  10580. + Include support for the Broadcom(R) BCM2708 platform.
  10581. +
  10582. +config BCM2708_DT
  10583. + bool "BCM2708 Device Tree support"
  10584. + depends on MACH_BCM2708
  10585. + default n
  10586. + select USE_OF
  10587. + select ARCH_REQUIRE_GPIOLIB
  10588. + select PINCTRL
  10589. + select PINCTRL_BCM2835
  10590. + help
  10591. + Enable Device Tree support for BCM2708
  10592. +
  10593. +config BCM2708_GPIO
  10594. + bool "BCM2708 gpio support"
  10595. + depends on MACH_BCM2708
  10596. + select ARCH_REQUIRE_GPIOLIB
  10597. + default y
  10598. + help
  10599. + Include support for the Broadcom(R) BCM2708 gpio.
  10600. +
  10601. +config BCM2708_VCMEM
  10602. + bool "Videocore Memory"
  10603. + depends on MACH_BCM2708
  10604. + default y
  10605. + help
  10606. + Helper for videocore memory access and total size allocation.
  10607. +
  10608. +config BCM2708_NOL2CACHE
  10609. + bool "Videocore L2 cache disable"
  10610. + depends on MACH_BCM2708
  10611. + default n
  10612. + help
  10613. + Do not allow ARM to use GPU's L2 cache. Requires disable_l2cache in config.txt.
  10614. +
  10615. +config BCM2708_SPIDEV
  10616. + bool "Bind spidev to SPI0 master"
  10617. + depends on MACH_BCM2708
  10618. + depends on SPI
  10619. + default y
  10620. + help
  10621. + Binds spidev driver to the SPI0 master
  10622. +endmenu
  10623. diff -Nur linux-3.18.8/arch/arm/mach-bcm2708/Makefile linux-rpi/arch/arm/mach-bcm2708/Makefile
  10624. --- linux-3.18.8/arch/arm/mach-bcm2708/Makefile 1970-01-01 01:00:00.000000000 +0100
  10625. +++ linux-rpi/arch/arm/mach-bcm2708/Makefile 2015-03-05 14:40:11.153715839 +0100
  10626. @@ -0,0 +1,7 @@
  10627. +#
  10628. +# Makefile for the linux kernel.
  10629. +#
  10630. +
  10631. +obj-$(CONFIG_MACH_BCM2708) += bcm2708.o armctrl.o vcio.o power.o dma.o
  10632. +obj-$(CONFIG_BCM2708_GPIO) += bcm2708_gpio.o
  10633. +obj-$(CONFIG_BCM2708_VCMEM) += vc_mem.o
  10634. diff -Nur linux-3.18.8/arch/arm/mach-bcm2708/Makefile.boot linux-rpi/arch/arm/mach-bcm2708/Makefile.boot
  10635. --- linux-3.18.8/arch/arm/mach-bcm2708/Makefile.boot 1970-01-01 01:00:00.000000000 +0100
  10636. +++ linux-rpi/arch/arm/mach-bcm2708/Makefile.boot 2015-03-05 14:40:11.153715839 +0100
  10637. @@ -0,0 +1,3 @@
  10638. + zreladdr-y := 0x00008000
  10639. +params_phys-y := 0x00000100
  10640. +initrd_phys-y := 0x00800000
  10641. diff -Nur linux-3.18.8/arch/arm/mach-bcm2708/power.c linux-rpi/arch/arm/mach-bcm2708/power.c
  10642. --- linux-3.18.8/arch/arm/mach-bcm2708/power.c 1970-01-01 01:00:00.000000000 +0100
  10643. +++ linux-rpi/arch/arm/mach-bcm2708/power.c 2015-03-05 14:40:11.153715839 +0100
  10644. @@ -0,0 +1,197 @@
  10645. +/*
  10646. + * linux/arch/arm/mach-bcm2708/power.c
  10647. + *
  10648. + * Copyright (C) 2010 Broadcom
  10649. + *
  10650. + * This program is free software; you can redistribute it and/or modify
  10651. + * it under the terms of the GNU General Public License version 2 as
  10652. + * published by the Free Software Foundation.
  10653. + *
  10654. + * This device provides a shared mechanism for controlling the power to
  10655. + * VideoCore subsystems.
  10656. + */
  10657. +
  10658. +#include <linux/module.h>
  10659. +#include <linux/semaphore.h>
  10660. +#include <linux/bug.h>
  10661. +#include <mach/power.h>
  10662. +#include <mach/vcio.h>
  10663. +#include <mach/arm_power.h>
  10664. +
  10665. +#define DRIVER_NAME "bcm2708_power"
  10666. +
  10667. +#define BCM_POWER_MAXCLIENTS 4
  10668. +#define BCM_POWER_NOCLIENT (1<<31)
  10669. +
  10670. +/* Some drivers expect there devices to be permanently powered */
  10671. +
  10672. +#ifdef CONFIG_USB
  10673. +#define BCM_POWER_ALWAYS_ON (BCM_POWER_USB)
  10674. +#endif
  10675. +
  10676. +#if 1
  10677. +#define DPRINTK printk
  10678. +#else
  10679. +#define DPRINTK if (0) printk
  10680. +#endif
  10681. +
  10682. +struct state_struct {
  10683. + uint32_t global_request;
  10684. + uint32_t client_request[BCM_POWER_MAXCLIENTS];
  10685. + struct semaphore client_mutex;
  10686. + struct semaphore mutex;
  10687. +} g_state;
  10688. +
  10689. +int bcm_power_open(BCM_POWER_HANDLE_T *handle)
  10690. +{
  10691. + BCM_POWER_HANDLE_T i;
  10692. + int ret = -EBUSY;
  10693. +
  10694. + down(&g_state.client_mutex);
  10695. +
  10696. + for (i = 0; i < BCM_POWER_MAXCLIENTS; i++) {
  10697. + if (g_state.client_request[i] == BCM_POWER_NOCLIENT) {
  10698. + g_state.client_request[i] = BCM_POWER_NONE;
  10699. + *handle = i;
  10700. + ret = 0;
  10701. + break;
  10702. + }
  10703. + }
  10704. +
  10705. + up(&g_state.client_mutex);
  10706. +
  10707. + DPRINTK("bcm_power_open() -> %d\n", *handle);
  10708. +
  10709. + return ret;
  10710. +}
  10711. +EXPORT_SYMBOL_GPL(bcm_power_open);
  10712. +
  10713. +int bcm_power_request(BCM_POWER_HANDLE_T handle, uint32_t request)
  10714. +{
  10715. + int rc = 0;
  10716. +
  10717. + DPRINTK("bcm_power_request(%d, %x)\n", handle, request);
  10718. +
  10719. + if ((handle < BCM_POWER_MAXCLIENTS) &&
  10720. + (g_state.client_request[handle] != BCM_POWER_NOCLIENT)) {
  10721. + if (down_interruptible(&g_state.mutex) != 0) {
  10722. + DPRINTK("bcm_power_request -> interrupted\n");
  10723. + return -EINTR;
  10724. + }
  10725. +
  10726. + if (request != g_state.client_request[handle]) {
  10727. + uint32_t others_request = 0;
  10728. + uint32_t global_request;
  10729. + BCM_POWER_HANDLE_T i;
  10730. +
  10731. + for (i = 0; i < BCM_POWER_MAXCLIENTS; i++) {
  10732. + if (i != handle)
  10733. + others_request |=
  10734. + g_state.client_request[i];
  10735. + }
  10736. + others_request &= ~BCM_POWER_NOCLIENT;
  10737. +
  10738. + global_request = request | others_request;
  10739. + if (global_request != g_state.global_request) {
  10740. + uint32_t actual;
  10741. +
  10742. + /* Send a request to VideoCore */
  10743. + bcm_mailbox_write(MBOX_CHAN_POWER,
  10744. + global_request << 4);
  10745. +
  10746. + /* Wait for a response during power-up */
  10747. + if (global_request & ~g_state.global_request) {
  10748. + rc = bcm_mailbox_read(MBOX_CHAN_POWER,
  10749. + &actual);
  10750. + DPRINTK
  10751. + ("bcm_mailbox_read -> %08x, %d\n",
  10752. + actual, rc);
  10753. + actual >>= 4;
  10754. + } else {
  10755. + rc = 0;
  10756. + actual = global_request;
  10757. + }
  10758. +
  10759. + if (rc == 0) {
  10760. + if (actual != global_request) {
  10761. + printk(KERN_ERR
  10762. + "%s: prev global %x, new global %x, actual %x, request %x, others_request %x\n",
  10763. + __func__,
  10764. + g_state.global_request,
  10765. + global_request, actual, request, others_request);
  10766. + /* A failure */
  10767. + BUG_ON((others_request & actual)
  10768. + != others_request);
  10769. + request &= actual;
  10770. + rc = -EIO;
  10771. + }
  10772. +
  10773. + g_state.global_request = actual;
  10774. + g_state.client_request[handle] =
  10775. + request;
  10776. + }
  10777. + }
  10778. + }
  10779. + up(&g_state.mutex);
  10780. + } else {
  10781. + rc = -EINVAL;
  10782. + }
  10783. + DPRINTK("bcm_power_request -> %d\n", rc);
  10784. + return rc;
  10785. +}
  10786. +EXPORT_SYMBOL_GPL(bcm_power_request);
  10787. +
  10788. +int bcm_power_close(BCM_POWER_HANDLE_T handle)
  10789. +{
  10790. + int rc;
  10791. +
  10792. + DPRINTK("bcm_power_close(%d)\n", handle);
  10793. +
  10794. + rc = bcm_power_request(handle, BCM_POWER_NONE);
  10795. + if (rc == 0)
  10796. + g_state.client_request[handle] = BCM_POWER_NOCLIENT;
  10797. +
  10798. + return rc;
  10799. +}
  10800. +EXPORT_SYMBOL_GPL(bcm_power_close);
  10801. +
  10802. +static int __init bcm_power_init(void)
  10803. +{
  10804. +#if defined(BCM_POWER_ALWAYS_ON)
  10805. + BCM_POWER_HANDLE_T always_on_handle;
  10806. +#endif
  10807. + int rc = 0;
  10808. + int i;
  10809. +
  10810. + printk(KERN_INFO "bcm_power: Broadcom power driver\n");
  10811. + bcm_mailbox_write(MBOX_CHAN_POWER, 0);
  10812. +
  10813. + for (i = 0; i < BCM_POWER_MAXCLIENTS; i++)
  10814. + g_state.client_request[i] = BCM_POWER_NOCLIENT;
  10815. +
  10816. + sema_init(&g_state.client_mutex, 1);
  10817. + sema_init(&g_state.mutex, 1);
  10818. +
  10819. + g_state.global_request = 0;
  10820. +
  10821. +#if defined(BCM_POWER_ALWAYS_ON)
  10822. + if (BCM_POWER_ALWAYS_ON) {
  10823. + bcm_power_open(&always_on_handle);
  10824. + bcm_power_request(always_on_handle, BCM_POWER_ALWAYS_ON);
  10825. + }
  10826. +#endif
  10827. +
  10828. + return rc;
  10829. +}
  10830. +
  10831. +static void __exit bcm_power_exit(void)
  10832. +{
  10833. + bcm_mailbox_write(MBOX_CHAN_POWER, 0);
  10834. +}
  10835. +
  10836. +arch_initcall(bcm_power_init); /* Initialize early */
  10837. +module_exit(bcm_power_exit);
  10838. +
  10839. +MODULE_AUTHOR("Phil Elwell");
  10840. +MODULE_DESCRIPTION("Interface to BCM2708 power management");
  10841. +MODULE_LICENSE("GPL");
  10842. diff -Nur linux-3.18.8/arch/arm/mach-bcm2708/vcio.c linux-rpi/arch/arm/mach-bcm2708/vcio.c
  10843. --- linux-3.18.8/arch/arm/mach-bcm2708/vcio.c 1970-01-01 01:00:00.000000000 +0100
  10844. +++ linux-rpi/arch/arm/mach-bcm2708/vcio.c 2015-03-05 14:40:11.153715839 +0100
  10845. @@ -0,0 +1,484 @@
  10846. +/*
  10847. + * linux/arch/arm/mach-bcm2708/vcio.c
  10848. + *
  10849. + * Copyright (C) 2010 Broadcom
  10850. + *
  10851. + * This program is free software; you can redistribute it and/or modify
  10852. + * it under the terms of the GNU General Public License version 2 as
  10853. + * published by the Free Software Foundation.
  10854. + *
  10855. + * This device provides a shared mechanism for writing to the mailboxes,
  10856. + * semaphores, doorbells etc. that are shared between the ARM and the
  10857. + * VideoCore processor
  10858. + */
  10859. +
  10860. +#if defined(CONFIG_SERIAL_BCM_MBOX_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
  10861. +#define SUPPORT_SYSRQ
  10862. +#endif
  10863. +
  10864. +#include <linux/module.h>
  10865. +#include <linux/console.h>
  10866. +#include <linux/serial_core.h>
  10867. +#include <linux/serial.h>
  10868. +#include <linux/errno.h>
  10869. +#include <linux/device.h>
  10870. +#include <linux/init.h>
  10871. +#include <linux/mm.h>
  10872. +#include <linux/dma-mapping.h>
  10873. +#include <linux/platform_device.h>
  10874. +#include <linux/sysrq.h>
  10875. +#include <linux/delay.h>
  10876. +#include <linux/slab.h>
  10877. +#include <linux/interrupt.h>
  10878. +#include <linux/irq.h>
  10879. +
  10880. +#include <linux/io.h>
  10881. +
  10882. +#include <mach/vcio.h>
  10883. +#include <mach/platform.h>
  10884. +
  10885. +#include <asm/uaccess.h>
  10886. +
  10887. +
  10888. +#define DRIVER_NAME BCM_VCIO_DRIVER_NAME
  10889. +
  10890. +/* ----------------------------------------------------------------------
  10891. + * Mailbox
  10892. + * -------------------------------------------------------------------- */
  10893. +
  10894. +/* offsets from a mail box base address */
  10895. +#define MAIL_WRT 0x00 /* write - and next 4 words */
  10896. +#define MAIL_RD 0x00 /* read - and next 4 words */
  10897. +#define MAIL_POL 0x10 /* read without popping the fifo */
  10898. +#define MAIL_SND 0x14 /* sender ID (bottom two bits) */
  10899. +#define MAIL_STA 0x18 /* status */
  10900. +#define MAIL_CNF 0x1C /* configuration */
  10901. +
  10902. +#define MBOX_MSG(chan, data28) (((data28) & ~0xf) | ((chan) & 0xf))
  10903. +#define MBOX_MSG_LSB(chan, data28) (((data28) << 4) | ((chan) & 0xf))
  10904. +#define MBOX_CHAN(msg) ((msg) & 0xf)
  10905. +#define MBOX_DATA28(msg) ((msg) & ~0xf)
  10906. +#define MBOX_DATA28_LSB(msg) (((uint32_t)msg) >> 4)
  10907. +
  10908. +#define MBOX_MAGIC 0xd0d0c0de
  10909. +static struct class *vcio_class = NULL;
  10910. +struct vc_mailbox {
  10911. + struct device *dev; /* parent device */
  10912. + void __iomem *status;
  10913. + void __iomem *config;
  10914. + void __iomem *read;
  10915. + void __iomem *write;
  10916. + uint32_t msg[MBOX_CHAN_COUNT];
  10917. + struct semaphore sema[MBOX_CHAN_COUNT];
  10918. + uint32_t magic;
  10919. +};
  10920. +
  10921. +static void mbox_init(struct vc_mailbox *mbox_out, struct device *dev,
  10922. + uint32_t addr_mbox)
  10923. +{
  10924. + int i;
  10925. +
  10926. + mbox_out->dev = dev;
  10927. + mbox_out->status = __io_address(addr_mbox + MAIL_STA);
  10928. + mbox_out->config = __io_address(addr_mbox + MAIL_CNF);
  10929. + mbox_out->read = __io_address(addr_mbox + MAIL_RD);
  10930. + /* Write to the other mailbox */
  10931. + mbox_out->write =
  10932. + __io_address((addr_mbox ^ ARM_0_MAIL0_WRT ^ ARM_0_MAIL1_WRT) +
  10933. + MAIL_WRT);
  10934. +
  10935. + for (i = 0; i < MBOX_CHAN_COUNT; i++) {
  10936. + mbox_out->msg[i] = 0;
  10937. + sema_init(&mbox_out->sema[i], 0);
  10938. + }
  10939. +
  10940. + /* Enable the interrupt on data reception */
  10941. + writel(ARM_MC_IHAVEDATAIRQEN, mbox_out->config);
  10942. +
  10943. + mbox_out->magic = MBOX_MAGIC;
  10944. +}
  10945. +
  10946. +static int mbox_write(struct vc_mailbox *mbox, unsigned chan, uint32_t data28)
  10947. +{
  10948. + int rc;
  10949. +
  10950. + if (mbox->magic != MBOX_MAGIC)
  10951. + rc = -EINVAL;
  10952. + else {
  10953. + /* wait for the mailbox FIFO to have some space in it */
  10954. + while (0 != (readl(mbox->status) & ARM_MS_FULL))
  10955. + cpu_relax();
  10956. +
  10957. + writel(MBOX_MSG(chan, data28), mbox->write);
  10958. + rc = 0;
  10959. + }
  10960. + return rc;
  10961. +}
  10962. +
  10963. +static int mbox_read(struct vc_mailbox *mbox, unsigned chan, uint32_t *data28)
  10964. +{
  10965. + int rc;
  10966. +
  10967. + if (mbox->magic != MBOX_MAGIC)
  10968. + rc = -EINVAL;
  10969. + else {
  10970. + down(&mbox->sema[chan]);
  10971. + *data28 = MBOX_DATA28(mbox->msg[chan]);
  10972. + mbox->msg[chan] = 0;
  10973. + rc = 0;
  10974. + }
  10975. + return rc;
  10976. +}
  10977. +
  10978. +static irqreturn_t mbox_irq(int irq, void *dev_id)
  10979. +{
  10980. + /* wait for the mailbox FIFO to have some data in it */
  10981. + struct vc_mailbox *mbox = (struct vc_mailbox *) dev_id;
  10982. + int status = readl(mbox->status);
  10983. + int ret = IRQ_NONE;
  10984. +
  10985. + while (!(status & ARM_MS_EMPTY)) {
  10986. + uint32_t msg = readl(mbox->read);
  10987. + int chan = MBOX_CHAN(msg);
  10988. + if (chan < MBOX_CHAN_COUNT) {
  10989. + if (mbox->msg[chan]) {
  10990. + /* Overflow */
  10991. + printk(KERN_ERR DRIVER_NAME
  10992. + ": mbox chan %d overflow - drop %08x\n",
  10993. + chan, msg);
  10994. + } else {
  10995. + mbox->msg[chan] = (msg | 0xf);
  10996. + up(&mbox->sema[chan]);
  10997. + }
  10998. + } else {
  10999. + printk(KERN_ERR DRIVER_NAME
  11000. + ": invalid channel selector (msg %08x)\n", msg);
  11001. + }
  11002. + ret = IRQ_HANDLED;
  11003. + status = readl(mbox->status);
  11004. + }
  11005. + return ret;
  11006. +}
  11007. +
  11008. +static struct irqaction mbox_irqaction = {
  11009. + .name = "ARM Mailbox IRQ",
  11010. + .flags = IRQF_DISABLED | IRQF_IRQPOLL,
  11011. + .handler = mbox_irq,
  11012. +};
  11013. +
  11014. +/* ----------------------------------------------------------------------
  11015. + * Mailbox Methods
  11016. + * -------------------------------------------------------------------- */
  11017. +
  11018. +static struct device *mbox_dev; /* we assume there's only one! */
  11019. +
  11020. +static int dev_mbox_write(struct device *dev, unsigned chan, uint32_t data28)
  11021. +{
  11022. + int rc;
  11023. +
  11024. + struct vc_mailbox *mailbox = dev_get_drvdata(dev);
  11025. + device_lock(dev);
  11026. + rc = mbox_write(mailbox, chan, data28);
  11027. + device_unlock(dev);
  11028. +
  11029. + return rc;
  11030. +}
  11031. +
  11032. +static int dev_mbox_read(struct device *dev, unsigned chan, uint32_t *data28)
  11033. +{
  11034. + int rc;
  11035. +
  11036. + struct vc_mailbox *mailbox = dev_get_drvdata(dev);
  11037. + device_lock(dev);
  11038. + rc = mbox_read(mailbox, chan, data28);
  11039. + device_unlock(dev);
  11040. +
  11041. + return rc;
  11042. +}
  11043. +
  11044. +extern int bcm_mailbox_write(unsigned chan, uint32_t data28)
  11045. +{
  11046. + if (mbox_dev)
  11047. + return dev_mbox_write(mbox_dev, chan, data28);
  11048. + else
  11049. + return -ENODEV;
  11050. +}
  11051. +EXPORT_SYMBOL_GPL(bcm_mailbox_write);
  11052. +
  11053. +extern int bcm_mailbox_read(unsigned chan, uint32_t *data28)
  11054. +{
  11055. + if (mbox_dev)
  11056. + return dev_mbox_read(mbox_dev, chan, data28);
  11057. + else
  11058. + return -ENODEV;
  11059. +}
  11060. +EXPORT_SYMBOL_GPL(bcm_mailbox_read);
  11061. +
  11062. +static void dev_mbox_register(const char *dev_name, struct device *dev)
  11063. +{
  11064. + mbox_dev = dev;
  11065. +}
  11066. +
  11067. +static int mbox_copy_from_user(void *dst, const void *src, int size)
  11068. +{
  11069. + if ( (uint32_t)src < TASK_SIZE)
  11070. + {
  11071. + return copy_from_user(dst, src, size);
  11072. + }
  11073. + else
  11074. + {
  11075. + memcpy( dst, src, size );
  11076. + return 0;
  11077. + }
  11078. +}
  11079. +
  11080. +static int mbox_copy_to_user(void *dst, const void *src, int size)
  11081. +{
  11082. + if ( (uint32_t)dst < TASK_SIZE)
  11083. + {
  11084. + return copy_to_user(dst, src, size);
  11085. + }
  11086. + else
  11087. + {
  11088. + memcpy( dst, src, size );
  11089. + return 0;
  11090. + }
  11091. +}
  11092. +
  11093. +static DEFINE_MUTEX(mailbox_lock);
  11094. +extern int bcm_mailbox_property(void *data, int size)
  11095. +{
  11096. + uint32_t success;
  11097. + dma_addr_t mem_bus; /* the memory address accessed from videocore */
  11098. + void *mem_kern; /* the memory address accessed from driver */
  11099. + int s = 0;
  11100. +
  11101. + mutex_lock(&mailbox_lock);
  11102. + /* allocate some memory for the messages communicating with GPU */
  11103. + mem_kern = dma_alloc_coherent(NULL, PAGE_ALIGN(size), &mem_bus, GFP_ATOMIC);
  11104. + if (mem_kern) {
  11105. + /* create the message */
  11106. + mbox_copy_from_user(mem_kern, data, size);
  11107. +
  11108. + /* send the message */
  11109. + wmb();
  11110. + s = bcm_mailbox_write(MBOX_CHAN_PROPERTY, (uint32_t)mem_bus);
  11111. + if (s == 0) {
  11112. + s = bcm_mailbox_read(MBOX_CHAN_PROPERTY, &success);
  11113. + }
  11114. + if (s == 0) {
  11115. + /* copy the response */
  11116. + rmb();
  11117. + mbox_copy_to_user(data, mem_kern, size);
  11118. + }
  11119. + dma_free_coherent(NULL, PAGE_ALIGN(size), mem_kern, mem_bus);
  11120. + } else {
  11121. + s = -ENOMEM;
  11122. + }
  11123. + if (s != 0)
  11124. + printk(KERN_ERR DRIVER_NAME ": %s failed (%d)\n", __func__, s);
  11125. +
  11126. + mutex_unlock(&mailbox_lock);
  11127. + return s;
  11128. +}
  11129. +EXPORT_SYMBOL_GPL(bcm_mailbox_property);
  11130. +
  11131. +/* ----------------------------------------------------------------------
  11132. + * Platform Device for Mailbox
  11133. + * -------------------------------------------------------------------- */
  11134. +
  11135. +/*
  11136. + * Is the device open right now? Used to prevent
  11137. + * concurent access into the same device
  11138. + */
  11139. +static int Device_Open = 0;
  11140. +
  11141. +/*
  11142. + * This is called whenever a process attempts to open the device file
  11143. + */
  11144. +static int device_open(struct inode *inode, struct file *file)
  11145. +{
  11146. + /*
  11147. + * We don't want to talk to two processes at the same time
  11148. + */
  11149. + if (Device_Open)
  11150. + return -EBUSY;
  11151. +
  11152. + Device_Open++;
  11153. + /*
  11154. + * Initialize the message
  11155. + */
  11156. + try_module_get(THIS_MODULE);
  11157. + return 0;
  11158. +}
  11159. +
  11160. +static int device_release(struct inode *inode, struct file *file)
  11161. +{
  11162. + /*
  11163. + * We're now ready for our next caller
  11164. + */
  11165. + Device_Open--;
  11166. +
  11167. + module_put(THIS_MODULE);
  11168. + return 0;
  11169. +}
  11170. +
  11171. +/*
  11172. + * This function is called whenever a process tries to do an ioctl on our
  11173. + * device file. We get two extra parameters (additional to the inode and file
  11174. + * structures, which all device functions get): the number of the ioctl called
  11175. + * and the parameter given to the ioctl function.
  11176. + *
  11177. + * If the ioctl is write or read/write (meaning output is returned to the
  11178. + * calling process), the ioctl call returns the output of this function.
  11179. + *
  11180. + */
  11181. +static long device_ioctl(struct file *file, /* see include/linux/fs.h */
  11182. + unsigned int ioctl_num, /* number and param for ioctl */
  11183. + unsigned long ioctl_param)
  11184. +{
  11185. + unsigned size;
  11186. + /*
  11187. + * Switch according to the ioctl called
  11188. + */
  11189. + switch (ioctl_num) {
  11190. + case IOCTL_MBOX_PROPERTY:
  11191. + /*
  11192. + * Receive a pointer to a message (in user space) and set that
  11193. + * to be the device's message. Get the parameter given to
  11194. + * ioctl by the process.
  11195. + */
  11196. + mbox_copy_from_user(&size, (void *)ioctl_param, sizeof size);
  11197. + return bcm_mailbox_property((void *)ioctl_param, size);
  11198. + break;
  11199. + default:
  11200. + printk(KERN_ERR DRIVER_NAME "unknown ioctl: %d\n", ioctl_num);
  11201. + return -EINVAL;
  11202. + }
  11203. +
  11204. + return 0;
  11205. +}
  11206. +
  11207. +/* Module Declarations */
  11208. +
  11209. +/*
  11210. + * This structure will hold the functions to be called
  11211. + * when a process does something to the device we
  11212. + * created. Since a pointer to this structure is kept in
  11213. + * the devices table, it can't be local to
  11214. + * init_module. NULL is for unimplemented functios.
  11215. + */
  11216. +struct file_operations fops = {
  11217. + .unlocked_ioctl = device_ioctl,
  11218. + .open = device_open,
  11219. + .release = device_release, /* a.k.a. close */
  11220. +};
  11221. +
  11222. +static int bcm_vcio_probe(struct platform_device *pdev)
  11223. +{
  11224. + int ret = 0;
  11225. + struct vc_mailbox *mailbox;
  11226. +
  11227. + mailbox = kzalloc(sizeof(*mailbox), GFP_KERNEL);
  11228. + if (NULL == mailbox) {
  11229. + printk(KERN_ERR DRIVER_NAME ": failed to allocate "
  11230. + "mailbox memory\n");
  11231. + ret = -ENOMEM;
  11232. + } else {
  11233. + struct resource *res;
  11234. +
  11235. + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  11236. + if (res == NULL) {
  11237. + printk(KERN_ERR DRIVER_NAME ": failed to obtain memory "
  11238. + "resource\n");
  11239. + ret = -ENODEV;
  11240. + kfree(mailbox);
  11241. + } else {
  11242. + /* should be based on the registers from res really */
  11243. + mbox_init(mailbox, &pdev->dev, ARM_0_MAIL0_RD);
  11244. +
  11245. + platform_set_drvdata(pdev, mailbox);
  11246. + dev_mbox_register(DRIVER_NAME, &pdev->dev);
  11247. +
  11248. + mbox_irqaction.dev_id = mailbox;
  11249. + setup_irq(IRQ_ARM_MAILBOX, &mbox_irqaction);
  11250. + printk(KERN_INFO DRIVER_NAME ": mailbox at %p\n",
  11251. + __io_address(ARM_0_MAIL0_RD));
  11252. + }
  11253. + }
  11254. +
  11255. + if (ret == 0) {
  11256. + /*
  11257. + * Register the character device
  11258. + */
  11259. + ret = register_chrdev(MAJOR_NUM, DEVICE_FILE_NAME, &fops);
  11260. +
  11261. + /*
  11262. + * Negative values signify an error
  11263. + */
  11264. + if (ret < 0) {
  11265. + printk(KERN_ERR DRIVER_NAME
  11266. + "Failed registering the character device %d\n", ret);
  11267. + return ret;
  11268. + }
  11269. + vcio_class = class_create(THIS_MODULE, BCM_VCIO_DRIVER_NAME);
  11270. + if (IS_ERR(vcio_class)) {
  11271. + ret = PTR_ERR(vcio_class);
  11272. + return ret ;
  11273. + }
  11274. + device_create(vcio_class, NULL, MKDEV(MAJOR_NUM, 0), NULL,
  11275. + "vcio");
  11276. + }
  11277. + return ret;
  11278. +}
  11279. +
  11280. +static int bcm_vcio_remove(struct platform_device *pdev)
  11281. +{
  11282. + struct vc_mailbox *mailbox = platform_get_drvdata(pdev);
  11283. +
  11284. + platform_set_drvdata(pdev, NULL);
  11285. + kfree(mailbox);
  11286. +
  11287. + return 0;
  11288. +}
  11289. +
  11290. +static struct platform_driver bcm_mbox_driver = {
  11291. + .probe = bcm_vcio_probe,
  11292. + .remove = bcm_vcio_remove,
  11293. +
  11294. + .driver = {
  11295. + .name = DRIVER_NAME,
  11296. + .owner = THIS_MODULE,
  11297. + },
  11298. +};
  11299. +
  11300. +static int __init bcm_mbox_init(void)
  11301. +{
  11302. + int ret;
  11303. +
  11304. + printk(KERN_INFO "mailbox: Broadcom VideoCore Mailbox driver\n");
  11305. +
  11306. + ret = platform_driver_register(&bcm_mbox_driver);
  11307. + if (ret != 0) {
  11308. + printk(KERN_ERR DRIVER_NAME ": failed to register "
  11309. + "on platform\n");
  11310. + }
  11311. +
  11312. + return ret;
  11313. +}
  11314. +
  11315. +static void __exit bcm_mbox_exit(void)
  11316. +{
  11317. + device_destroy(vcio_class,MKDEV(MAJOR_NUM, 0));
  11318. + class_destroy(vcio_class);
  11319. + unregister_chrdev(MAJOR_NUM, DEVICE_FILE_NAME);
  11320. + platform_driver_unregister(&bcm_mbox_driver);
  11321. +}
  11322. +
  11323. +arch_initcall(bcm_mbox_init); /* Initialize early */
  11324. +module_exit(bcm_mbox_exit);
  11325. +
  11326. +MODULE_AUTHOR("Gray Girling");
  11327. +MODULE_DESCRIPTION("ARM I/O to VideoCore processor");
  11328. +MODULE_LICENSE("GPL");
  11329. +MODULE_ALIAS("platform:bcm-mbox");
  11330. diff -Nur linux-3.18.8/arch/arm/mach-bcm2708/vc_mem.c linux-rpi/arch/arm/mach-bcm2708/vc_mem.c
  11331. --- linux-3.18.8/arch/arm/mach-bcm2708/vc_mem.c 1970-01-01 01:00:00.000000000 +0100
  11332. +++ linux-rpi/arch/arm/mach-bcm2708/vc_mem.c 2015-03-05 14:40:11.153715839 +0100
  11333. @@ -0,0 +1,432 @@
  11334. +/*****************************************************************************
  11335. +* Copyright 2010 - 2011 Broadcom Corporation. All rights reserved.
  11336. +*
  11337. +* Unless you and Broadcom execute a separate written software license
  11338. +* agreement governing use of this software, this software is licensed to you
  11339. +* under the terms of the GNU General Public License version 2, available at
  11340. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  11341. +*
  11342. +* Notwithstanding the above, under no circumstances may you combine this
  11343. +* software in any way with any other Broadcom software provided under a
  11344. +* license other than the GPL, without Broadcom's express prior written
  11345. +* consent.
  11346. +*****************************************************************************/
  11347. +
  11348. +#include <linux/kernel.h>
  11349. +#include <linux/module.h>
  11350. +#include <linux/fs.h>
  11351. +#include <linux/device.h>
  11352. +#include <linux/cdev.h>
  11353. +#include <linux/mm.h>
  11354. +#include <linux/slab.h>
  11355. +#include <linux/debugfs.h>
  11356. +#include <asm/uaccess.h>
  11357. +#include <linux/dma-mapping.h>
  11358. +
  11359. +#ifdef CONFIG_ARCH_KONA
  11360. +#include <chal/chal_ipc.h>
  11361. +#elif CONFIG_ARCH_BCM2708
  11362. +#else
  11363. +#include <csp/chal_ipc.h>
  11364. +#endif
  11365. +
  11366. +#include "mach/vc_mem.h"
  11367. +#include <mach/vcio.h>
  11368. +
  11369. +#define DRIVER_NAME "vc-mem"
  11370. +
  11371. +// Device (/dev) related variables
  11372. +static dev_t vc_mem_devnum = 0;
  11373. +static struct class *vc_mem_class = NULL;
  11374. +static struct cdev vc_mem_cdev;
  11375. +static int vc_mem_inited = 0;
  11376. +
  11377. +#ifdef CONFIG_DEBUG_FS
  11378. +static struct dentry *vc_mem_debugfs_entry;
  11379. +#endif
  11380. +
  11381. +/*
  11382. + * Videocore memory addresses and size
  11383. + *
  11384. + * Drivers that wish to know the videocore memory addresses and sizes should
  11385. + * use these variables instead of the MM_IO_BASE and MM_ADDR_IO defines in
  11386. + * headers. This allows the other drivers to not be tied down to a a certain
  11387. + * address/size at compile time.
  11388. + *
  11389. + * In the future, the goal is to have the videocore memory virtual address and
  11390. + * size be calculated at boot time rather than at compile time. The decision of
  11391. + * where the videocore memory resides and its size would be in the hands of the
  11392. + * bootloader (and/or kernel). When that happens, the values of these variables
  11393. + * would be calculated and assigned in the init function.
  11394. + */
  11395. +// in the 2835 VC in mapped above ARM, but ARM has full access to VC space
  11396. +unsigned long mm_vc_mem_phys_addr = 0x00000000;
  11397. +unsigned int mm_vc_mem_size = 0;
  11398. +unsigned int mm_vc_mem_base = 0;
  11399. +
  11400. +EXPORT_SYMBOL(mm_vc_mem_phys_addr);
  11401. +EXPORT_SYMBOL(mm_vc_mem_size);
  11402. +EXPORT_SYMBOL(mm_vc_mem_base);
  11403. +
  11404. +static uint phys_addr = 0;
  11405. +static uint mem_size = 0;
  11406. +static uint mem_base = 0;
  11407. +
  11408. +
  11409. +/****************************************************************************
  11410. +*
  11411. +* vc_mem_open
  11412. +*
  11413. +***************************************************************************/
  11414. +
  11415. +static int
  11416. +vc_mem_open(struct inode *inode, struct file *file)
  11417. +{
  11418. + (void) inode;
  11419. + (void) file;
  11420. +
  11421. + pr_debug("%s: called file = 0x%p\n", __func__, file);
  11422. +
  11423. + return 0;
  11424. +}
  11425. +
  11426. +/****************************************************************************
  11427. +*
  11428. +* vc_mem_release
  11429. +*
  11430. +***************************************************************************/
  11431. +
  11432. +static int
  11433. +vc_mem_release(struct inode *inode, struct file *file)
  11434. +{
  11435. + (void) inode;
  11436. + (void) file;
  11437. +
  11438. + pr_debug("%s: called file = 0x%p\n", __func__, file);
  11439. +
  11440. + return 0;
  11441. +}
  11442. +
  11443. +/****************************************************************************
  11444. +*
  11445. +* vc_mem_get_size
  11446. +*
  11447. +***************************************************************************/
  11448. +
  11449. +static void
  11450. +vc_mem_get_size(void)
  11451. +{
  11452. +}
  11453. +
  11454. +/****************************************************************************
  11455. +*
  11456. +* vc_mem_get_base
  11457. +*
  11458. +***************************************************************************/
  11459. +
  11460. +static void
  11461. +vc_mem_get_base(void)
  11462. +{
  11463. +}
  11464. +
  11465. +/****************************************************************************
  11466. +*
  11467. +* vc_mem_get_current_size
  11468. +*
  11469. +***************************************************************************/
  11470. +
  11471. +int
  11472. +vc_mem_get_current_size(void)
  11473. +{
  11474. + return mm_vc_mem_size;
  11475. +}
  11476. +
  11477. +EXPORT_SYMBOL_GPL(vc_mem_get_current_size);
  11478. +
  11479. +/****************************************************************************
  11480. +*
  11481. +* vc_mem_ioctl
  11482. +*
  11483. +***************************************************************************/
  11484. +
  11485. +static long
  11486. +vc_mem_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  11487. +{
  11488. + int rc = 0;
  11489. +
  11490. + (void) cmd;
  11491. + (void) arg;
  11492. +
  11493. + pr_debug("%s: called file = 0x%p\n", __func__, file);
  11494. +
  11495. + switch (cmd) {
  11496. + case VC_MEM_IOC_MEM_PHYS_ADDR:
  11497. + {
  11498. + pr_debug("%s: VC_MEM_IOC_MEM_PHYS_ADDR=0x%p\n",
  11499. + __func__, (void *) mm_vc_mem_phys_addr);
  11500. +
  11501. + if (copy_to_user((void *) arg, &mm_vc_mem_phys_addr,
  11502. + sizeof (mm_vc_mem_phys_addr)) != 0) {
  11503. + rc = -EFAULT;
  11504. + }
  11505. + break;
  11506. + }
  11507. + case VC_MEM_IOC_MEM_SIZE:
  11508. + {
  11509. + // Get the videocore memory size first
  11510. + vc_mem_get_size();
  11511. +
  11512. + pr_debug("%s: VC_MEM_IOC_MEM_SIZE=%u\n", __func__,
  11513. + mm_vc_mem_size);
  11514. +
  11515. + if (copy_to_user((void *) arg, &mm_vc_mem_size,
  11516. + sizeof (mm_vc_mem_size)) != 0) {
  11517. + rc = -EFAULT;
  11518. + }
  11519. + break;
  11520. + }
  11521. + case VC_MEM_IOC_MEM_BASE:
  11522. + {
  11523. + // Get the videocore memory base
  11524. + vc_mem_get_base();
  11525. +
  11526. + pr_debug("%s: VC_MEM_IOC_MEM_BASE=%u\n", __func__,
  11527. + mm_vc_mem_base);
  11528. +
  11529. + if (copy_to_user((void *) arg, &mm_vc_mem_base,
  11530. + sizeof (mm_vc_mem_base)) != 0) {
  11531. + rc = -EFAULT;
  11532. + }
  11533. + break;
  11534. + }
  11535. + case VC_MEM_IOC_MEM_LOAD:
  11536. + {
  11537. + // Get the videocore memory base
  11538. + vc_mem_get_base();
  11539. +
  11540. + pr_debug("%s: VC_MEM_IOC_MEM_LOAD=%u\n", __func__,
  11541. + mm_vc_mem_base);
  11542. +
  11543. + if (copy_to_user((void *) arg, &mm_vc_mem_base,
  11544. + sizeof (mm_vc_mem_base)) != 0) {
  11545. + rc = -EFAULT;
  11546. + }
  11547. + break;
  11548. + }
  11549. + default:
  11550. + {
  11551. + return -ENOTTY;
  11552. + }
  11553. + }
  11554. + pr_debug("%s: file = 0x%p returning %d\n", __func__, file, rc);
  11555. +
  11556. + return rc;
  11557. +}
  11558. +
  11559. +/****************************************************************************
  11560. +*
  11561. +* vc_mem_mmap
  11562. +*
  11563. +***************************************************************************/
  11564. +
  11565. +static int
  11566. +vc_mem_mmap(struct file *filp, struct vm_area_struct *vma)
  11567. +{
  11568. + int rc = 0;
  11569. + unsigned long length = vma->vm_end - vma->vm_start;
  11570. + unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
  11571. +
  11572. + pr_debug("%s: vm_start = 0x%08lx vm_end = 0x%08lx vm_pgoff = 0x%08lx\n",
  11573. + __func__, (long) vma->vm_start, (long) vma->vm_end,
  11574. + (long) vma->vm_pgoff);
  11575. +
  11576. + if (offset + length > mm_vc_mem_size) {
  11577. + pr_err("%s: length %ld is too big\n", __func__, length);
  11578. + return -EINVAL;
  11579. + }
  11580. + // Do not cache the memory map
  11581. + vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
  11582. +
  11583. + rc = remap_pfn_range(vma, vma->vm_start,
  11584. + (mm_vc_mem_phys_addr >> PAGE_SHIFT) +
  11585. + vma->vm_pgoff, length, vma->vm_page_prot);
  11586. + if (rc != 0) {
  11587. + pr_err("%s: remap_pfn_range failed (rc=%d)\n", __func__, rc);
  11588. + }
  11589. +
  11590. + return rc;
  11591. +}
  11592. +
  11593. +/****************************************************************************
  11594. +*
  11595. +* File Operations for the driver.
  11596. +*
  11597. +***************************************************************************/
  11598. +
  11599. +static const struct file_operations vc_mem_fops = {
  11600. + .owner = THIS_MODULE,
  11601. + .open = vc_mem_open,
  11602. + .release = vc_mem_release,
  11603. + .unlocked_ioctl = vc_mem_ioctl,
  11604. + .mmap = vc_mem_mmap,
  11605. +};
  11606. +
  11607. +#ifdef CONFIG_DEBUG_FS
  11608. +static void vc_mem_debugfs_deinit(void)
  11609. +{
  11610. + debugfs_remove_recursive(vc_mem_debugfs_entry);
  11611. + vc_mem_debugfs_entry = NULL;
  11612. +}
  11613. +
  11614. +
  11615. +static int vc_mem_debugfs_init(
  11616. + struct device *dev)
  11617. +{
  11618. + vc_mem_debugfs_entry = debugfs_create_dir(DRIVER_NAME, NULL);
  11619. + if (!vc_mem_debugfs_entry) {
  11620. + dev_warn(dev, "could not create debugfs entry\n");
  11621. + return -EFAULT;
  11622. + }
  11623. +
  11624. + if (!debugfs_create_x32("vc_mem_phys_addr",
  11625. + 0444,
  11626. + vc_mem_debugfs_entry,
  11627. + (u32 *)&mm_vc_mem_phys_addr)) {
  11628. + dev_warn(dev, "%s:could not create vc_mem_phys entry\n",
  11629. + __func__);
  11630. + goto fail;
  11631. + }
  11632. +
  11633. + if (!debugfs_create_x32("vc_mem_size",
  11634. + 0444,
  11635. + vc_mem_debugfs_entry,
  11636. + (u32 *)&mm_vc_mem_size)) {
  11637. + dev_warn(dev, "%s:could not create vc_mem_size entry\n",
  11638. + __func__);
  11639. + goto fail;
  11640. + }
  11641. +
  11642. + if (!debugfs_create_x32("vc_mem_base",
  11643. + 0444,
  11644. + vc_mem_debugfs_entry,
  11645. + (u32 *)&mm_vc_mem_base)) {
  11646. + dev_warn(dev, "%s:could not create vc_mem_base entry\n",
  11647. + __func__);
  11648. + goto fail;
  11649. + }
  11650. +
  11651. + return 0;
  11652. +
  11653. +fail:
  11654. + vc_mem_debugfs_deinit();
  11655. + return -EFAULT;
  11656. +}
  11657. +
  11658. +#endif /* CONFIG_DEBUG_FS */
  11659. +
  11660. +
  11661. +/****************************************************************************
  11662. +*
  11663. +* vc_mem_init
  11664. +*
  11665. +***************************************************************************/
  11666. +
  11667. +static int __init
  11668. +vc_mem_init(void)
  11669. +{
  11670. + int rc = -EFAULT;
  11671. + struct device *dev;
  11672. +
  11673. + pr_debug("%s: called\n", __func__);
  11674. +
  11675. + mm_vc_mem_phys_addr = phys_addr;
  11676. + mm_vc_mem_size = mem_size;
  11677. + mm_vc_mem_base = mem_base;
  11678. +
  11679. + vc_mem_get_size();
  11680. +
  11681. + pr_info("vc-mem: phys_addr:0x%08lx mem_base=0x%08x mem_size:0x%08x(%u MiB)\n",
  11682. + mm_vc_mem_phys_addr, mm_vc_mem_base, mm_vc_mem_size, mm_vc_mem_size / (1024 * 1024));
  11683. +
  11684. + if ((rc = alloc_chrdev_region(&vc_mem_devnum, 0, 1, DRIVER_NAME)) < 0) {
  11685. + pr_err("%s: alloc_chrdev_region failed (rc=%d)\n",
  11686. + __func__, rc);
  11687. + goto out_err;
  11688. + }
  11689. +
  11690. + cdev_init(&vc_mem_cdev, &vc_mem_fops);
  11691. + if ((rc = cdev_add(&vc_mem_cdev, vc_mem_devnum, 1)) != 0) {
  11692. + pr_err("%s: cdev_add failed (rc=%d)\n", __func__, rc);
  11693. + goto out_unregister;
  11694. + }
  11695. +
  11696. + vc_mem_class = class_create(THIS_MODULE, DRIVER_NAME);
  11697. + if (IS_ERR(vc_mem_class)) {
  11698. + rc = PTR_ERR(vc_mem_class);
  11699. + pr_err("%s: class_create failed (rc=%d)\n", __func__, rc);
  11700. + goto out_cdev_del;
  11701. + }
  11702. +
  11703. + dev = device_create(vc_mem_class, NULL, vc_mem_devnum, NULL,
  11704. + DRIVER_NAME);
  11705. + if (IS_ERR(dev)) {
  11706. + rc = PTR_ERR(dev);
  11707. + pr_err("%s: device_create failed (rc=%d)\n", __func__, rc);
  11708. + goto out_class_destroy;
  11709. + }
  11710. +
  11711. +#ifdef CONFIG_DEBUG_FS
  11712. + /* don't fail if the debug entries cannot be created */
  11713. + vc_mem_debugfs_init(dev);
  11714. +#endif
  11715. +
  11716. + vc_mem_inited = 1;
  11717. + return 0;
  11718. +
  11719. + device_destroy(vc_mem_class, vc_mem_devnum);
  11720. +
  11721. + out_class_destroy:
  11722. + class_destroy(vc_mem_class);
  11723. + vc_mem_class = NULL;
  11724. +
  11725. + out_cdev_del:
  11726. + cdev_del(&vc_mem_cdev);
  11727. +
  11728. + out_unregister:
  11729. + unregister_chrdev_region(vc_mem_devnum, 1);
  11730. +
  11731. + out_err:
  11732. + return -1;
  11733. +}
  11734. +
  11735. +/****************************************************************************
  11736. +*
  11737. +* vc_mem_exit
  11738. +*
  11739. +***************************************************************************/
  11740. +
  11741. +static void __exit
  11742. +vc_mem_exit(void)
  11743. +{
  11744. + pr_debug("%s: called\n", __func__);
  11745. +
  11746. + if (vc_mem_inited) {
  11747. +#if CONFIG_DEBUG_FS
  11748. + vc_mem_debugfs_deinit();
  11749. +#endif
  11750. + device_destroy(vc_mem_class, vc_mem_devnum);
  11751. + class_destroy(vc_mem_class);
  11752. + cdev_del(&vc_mem_cdev);
  11753. + unregister_chrdev_region(vc_mem_devnum, 1);
  11754. + }
  11755. +}
  11756. +
  11757. +module_init(vc_mem_init);
  11758. +module_exit(vc_mem_exit);
  11759. +MODULE_LICENSE("GPL");
  11760. +MODULE_AUTHOR("Broadcom Corporation");
  11761. +
  11762. +module_param(phys_addr, uint, 0644);
  11763. +module_param(mem_size, uint, 0644);
  11764. +module_param(mem_base, uint, 0644);
  11765. +
  11766. diff -Nur linux-3.18.8/arch/arm/mach-bcm2709/armctrl.c linux-rpi/arch/arm/mach-bcm2709/armctrl.c
  11767. --- linux-3.18.8/arch/arm/mach-bcm2709/armctrl.c 1970-01-01 01:00:00.000000000 +0100
  11768. +++ linux-rpi/arch/arm/mach-bcm2709/armctrl.c 2015-03-05 14:40:11.153715839 +0100
  11769. @@ -0,0 +1,369 @@
  11770. +/*
  11771. + * linux/arch/arm/mach-bcm2708/armctrl.c
  11772. + *
  11773. + * Copyright (C) 2010 Broadcom
  11774. + *
  11775. + * This program is free software; you can redistribute it and/or modify
  11776. + * it under the terms of the GNU General Public License as published by
  11777. + * the Free Software Foundation; either version 2 of the License, or
  11778. + * (at your option) any later version.
  11779. + *
  11780. + * This program is distributed in the hope that it will be useful,
  11781. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11782. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11783. + * GNU General Public License for more details.
  11784. + *
  11785. + * You should have received a copy of the GNU General Public License
  11786. + * along with this program; if not, write to the Free Software
  11787. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  11788. + */
  11789. +#include <linux/init.h>
  11790. +#include <linux/list.h>
  11791. +#include <linux/io.h>
  11792. +#include <linux/version.h>
  11793. +#include <linux/syscore_ops.h>
  11794. +#include <linux/interrupt.h>
  11795. +#include <linux/irqdomain.h>
  11796. +#include <linux/of.h>
  11797. +
  11798. +#include <asm/mach/irq.h>
  11799. +#include <mach/hardware.h>
  11800. +#include "armctrl.h"
  11801. +
  11802. +/* For support of kernels >= 3.0 assume only one VIC for now*/
  11803. +static unsigned int remap_irqs[(INTERRUPT_ARASANSDIO + 1) - INTERRUPT_JPEG] = {
  11804. + INTERRUPT_VC_JPEG,
  11805. + INTERRUPT_VC_USB,
  11806. + INTERRUPT_VC_3D,
  11807. + INTERRUPT_VC_DMA2,
  11808. + INTERRUPT_VC_DMA3,
  11809. + INTERRUPT_VC_I2C,
  11810. + INTERRUPT_VC_SPI,
  11811. + INTERRUPT_VC_I2SPCM,
  11812. + INTERRUPT_VC_SDIO,
  11813. + INTERRUPT_VC_UART,
  11814. + INTERRUPT_VC_ARASANSDIO
  11815. +};
  11816. +
  11817. +static void armctrl_mask_irq(struct irq_data *d)
  11818. +{
  11819. + static const unsigned int disables[4] = {
  11820. + ARM_IRQ_DIBL1,
  11821. + ARM_IRQ_DIBL2,
  11822. + ARM_IRQ_DIBL3,
  11823. + 0
  11824. + };
  11825. + int i;
  11826. + if (d->irq >= FIQ_START) {
  11827. + writel(0, __io_address(ARM_IRQ_FAST));
  11828. + } else if (d->irq >= IRQ_ARM_LOCAL_CNTPSIRQ && d->irq < IRQ_ARM_LOCAL_CNTPSIRQ + 4) {
  11829. +#if 1
  11830. + unsigned int data = (unsigned int)irq_get_chip_data(d->irq) - IRQ_ARM_LOCAL_CNTPSIRQ;
  11831. + for (i=0; i<4; i++) // i = raw_smp_processor_id(); //
  11832. + {
  11833. + unsigned int val = readl(__io_address(ARM_LOCAL_TIMER_INT_CONTROL0 + 4*i));
  11834. + writel(val &~ (1 << data), __io_address(ARM_LOCAL_TIMER_INT_CONTROL0 + 4*i));
  11835. + }
  11836. +#endif
  11837. + } else if (d->irq >= IRQ_ARM_LOCAL_MAILBOX0 && d->irq < IRQ_ARM_LOCAL_MAILBOX0 + 4) {
  11838. +#if 0
  11839. + unsigned int data = (unsigned int)irq_get_chip_data(d->irq) - IRQ_ARM_LOCAL_MAILBOX0;
  11840. + for (i=0; i<4; i++) {
  11841. + unsigned int val = readl(__io_address(ARM_LOCAL_MAILBOX_INT_CONTROL0 + 4*i));
  11842. + writel(val &~ (1 << data), __io_address(ARM_LOCAL_MAILBOX_INT_CONTROL0 + 4*i));
  11843. + }
  11844. +#endif
  11845. + } else if (d->irq >= ARM_IRQ1_BASE && d->irq < ARM_IRQ_LOCAL_BASE) {
  11846. + unsigned int data = (unsigned int)irq_get_chip_data(d->irq);
  11847. + writel(1 << (data & 0x1f), __io_address(disables[(data >> 5) & 0x3]));
  11848. + } else if (d->irq == INTERRUPT_ARM_LOCAL_PMU_FAST) {
  11849. + writel(0xf, __io_address(ARM_LOCAL_PM_ROUTING_CLR));
  11850. + } else { printk("%s: %d\n", __func__, d->irq); BUG(); }
  11851. +}
  11852. +
  11853. +static void armctrl_unmask_irq(struct irq_data *d)
  11854. +{
  11855. + static const unsigned int enables[4] = {
  11856. + ARM_IRQ_ENBL1,
  11857. + ARM_IRQ_ENBL2,
  11858. + ARM_IRQ_ENBL3,
  11859. + 0
  11860. + };
  11861. + int i;
  11862. + if (d->irq >= FIQ_START) {
  11863. + unsigned int data;
  11864. + if (num_online_cpus() > 1) {
  11865. + data = readl(__io_address(ARM_LOCAL_GPU_INT_ROUTING));
  11866. + data &= ~0xc;
  11867. + data |= (1 << 2);
  11868. + writel(data, __io_address(ARM_LOCAL_GPU_INT_ROUTING));
  11869. + }
  11870. + /* Unmask in ARMCTRL block after routing it properly */
  11871. + data = (unsigned int)irq_get_chip_data(d->irq) - FIQ_START;
  11872. + writel(0x80 | data, __io_address(ARM_IRQ_FAST));
  11873. + } else if (d->irq >= IRQ_ARM_LOCAL_CNTPSIRQ && d->irq < IRQ_ARM_LOCAL_CNTPSIRQ + 4) {
  11874. +#if 1
  11875. + unsigned int data = (unsigned int)irq_get_chip_data(d->irq) - IRQ_ARM_LOCAL_CNTPSIRQ;
  11876. + for (i=0; i<4; i++) // i = raw_smp_processor_id();
  11877. + {
  11878. + unsigned int val = readl(__io_address(ARM_LOCAL_TIMER_INT_CONTROL0 + 4*i));
  11879. + writel(val | (1 << data), __io_address(ARM_LOCAL_TIMER_INT_CONTROL0 + 4*i));
  11880. + }
  11881. +#endif
  11882. + } else if (d->irq >= IRQ_ARM_LOCAL_MAILBOX0 && d->irq < IRQ_ARM_LOCAL_MAILBOX0 + 4) {
  11883. +#if 0
  11884. + unsigned int data = (unsigned int)irq_get_chip_data(d->irq) - IRQ_ARM_LOCAL_MAILBOX0;
  11885. + for (i=0; i<4; i++) {
  11886. + unsigned int val = readl(__io_address(ARM_LOCAL_MAILBOX_INT_CONTROL0 + 4*i));
  11887. + writel(val | (1 << data), __io_address(ARM_LOCAL_MAILBOX_INT_CONTROL0 + 4*i));
  11888. + }
  11889. +#endif
  11890. + } else if (d->irq >= ARM_IRQ1_BASE && d->irq < ARM_IRQ_LOCAL_BASE) {
  11891. + unsigned int data = (unsigned int)irq_get_chip_data(d->irq);
  11892. + writel(1 << (data & 0x1f), __io_address(enables[(data >> 5) & 0x3]));
  11893. + } else if (d->irq == INTERRUPT_ARM_LOCAL_PMU_FAST) {
  11894. + writel(0xf, __io_address(ARM_LOCAL_PM_ROUTING_SET));
  11895. + } else { printk("%s: %d\n", __func__, d->irq); BUG(); }
  11896. +}
  11897. +
  11898. +#ifdef CONFIG_OF
  11899. +
  11900. +#define NR_IRQS_BANK0 21
  11901. +#define NR_BANKS 4
  11902. +#define IRQS_PER_BANK 32
  11903. +
  11904. +/* from drivers/irqchip/irq-bcm2835.c */
  11905. +static int armctrl_xlate(struct irq_domain *d, struct device_node *ctrlr,
  11906. + const u32 *intspec, unsigned int intsize,
  11907. + unsigned long *out_hwirq, unsigned int *out_type)
  11908. +{
  11909. + if (WARN_ON(intsize != 2))
  11910. + return -EINVAL;
  11911. +
  11912. + if (WARN_ON(intspec[0] >= NR_BANKS))
  11913. + return -EINVAL;
  11914. +
  11915. + if (WARN_ON(intspec[1] >= IRQS_PER_BANK))
  11916. + return -EINVAL;
  11917. +
  11918. + if (WARN_ON(intspec[0] == 0 && intspec[1] >= NR_IRQS_BANK0))
  11919. + return -EINVAL;
  11920. +
  11921. + if (WARN_ON(intspec[0] == 3 && intspec[1] > 3 && intspec[1] != 5 && intspec[1] != 9))
  11922. + return -EINVAL;
  11923. +
  11924. + if (intspec[0] == 0)
  11925. + *out_hwirq = ARM_IRQ0_BASE + intspec[1];
  11926. + else if (intspec[0] == 1)
  11927. + *out_hwirq = ARM_IRQ1_BASE + intspec[1];
  11928. + else if (intspec[0] == 2)
  11929. + *out_hwirq = ARM_IRQ2_BASE + intspec[1];
  11930. + else
  11931. + *out_hwirq = ARM_IRQ_LOCAL_BASE + intspec[1];
  11932. +
  11933. + /* reverse remap_irqs[] */
  11934. + switch (*out_hwirq) {
  11935. + case INTERRUPT_VC_JPEG:
  11936. + *out_hwirq = INTERRUPT_JPEG;
  11937. + break;
  11938. + case INTERRUPT_VC_USB:
  11939. + *out_hwirq = INTERRUPT_USB;
  11940. + break;
  11941. + case INTERRUPT_VC_3D:
  11942. + *out_hwirq = INTERRUPT_3D;
  11943. + break;
  11944. + case INTERRUPT_VC_DMA2:
  11945. + *out_hwirq = INTERRUPT_DMA2;
  11946. + break;
  11947. + case INTERRUPT_VC_DMA3:
  11948. + *out_hwirq = INTERRUPT_DMA3;
  11949. + break;
  11950. + case INTERRUPT_VC_I2C:
  11951. + *out_hwirq = INTERRUPT_I2C;
  11952. + break;
  11953. + case INTERRUPT_VC_SPI:
  11954. + *out_hwirq = INTERRUPT_SPI;
  11955. + break;
  11956. + case INTERRUPT_VC_I2SPCM:
  11957. + *out_hwirq = INTERRUPT_I2SPCM;
  11958. + break;
  11959. + case INTERRUPT_VC_SDIO:
  11960. + *out_hwirq = INTERRUPT_SDIO;
  11961. + break;
  11962. + case INTERRUPT_VC_UART:
  11963. + *out_hwirq = INTERRUPT_UART;
  11964. + break;
  11965. + case INTERRUPT_VC_ARASANSDIO:
  11966. + *out_hwirq = INTERRUPT_ARASANSDIO;
  11967. + break;
  11968. + }
  11969. +
  11970. + *out_type = IRQ_TYPE_NONE;
  11971. + return 0;
  11972. +}
  11973. +
  11974. +static struct irq_domain_ops armctrl_ops = {
  11975. + .xlate = armctrl_xlate
  11976. +};
  11977. +
  11978. +void __init armctrl_dt_init(void)
  11979. +{
  11980. + struct device_node *np;
  11981. + struct irq_domain *domain;
  11982. +
  11983. + np = of_find_compatible_node(NULL, NULL, "brcm,bcm2708-armctrl-ic");
  11984. + if (!np)
  11985. + return;
  11986. +
  11987. + domain = irq_domain_add_legacy(np, BCM2708_ALLOC_IRQS,
  11988. + IRQ_ARMCTRL_START, 0,
  11989. + &armctrl_ops, NULL);
  11990. + WARN_ON(!domain);
  11991. +}
  11992. +#else
  11993. +void __init armctrl_dt_init(void) { }
  11994. +#endif /* CONFIG_OF */
  11995. +
  11996. +#if defined(CONFIG_PM)
  11997. +
  11998. +/* for kernels 3.xx use the new syscore_ops apis but for older kernels use the sys dev class */
  11999. +
  12000. +/* Static defines
  12001. + * struct armctrl_device - VIC PM device (< 3.xx)
  12002. + * @sysdev: The system device which is registered. (< 3.xx)
  12003. + * @irq: The IRQ number for the base of the VIC.
  12004. + * @base: The register base for the VIC.
  12005. + * @resume_sources: A bitmask of interrupts for resume.
  12006. + * @resume_irqs: The IRQs enabled for resume.
  12007. + * @int_select: Save for VIC_INT_SELECT.
  12008. + * @int_enable: Save for VIC_INT_ENABLE.
  12009. + * @soft_int: Save for VIC_INT_SOFT.
  12010. + * @protect: Save for VIC_PROTECT.
  12011. + */
  12012. +struct armctrl_info {
  12013. + void __iomem *base;
  12014. + int irq;
  12015. + u32 resume_sources;
  12016. + u32 resume_irqs;
  12017. + u32 int_select;
  12018. + u32 int_enable;
  12019. + u32 soft_int;
  12020. + u32 protect;
  12021. +} armctrl;
  12022. +
  12023. +static int armctrl_suspend(void)
  12024. +{
  12025. + return 0;
  12026. +}
  12027. +
  12028. +static void armctrl_resume(void)
  12029. +{
  12030. + return;
  12031. +}
  12032. +
  12033. +/**
  12034. + * armctrl_pm_register - Register a VIC for later power management control
  12035. + * @base: The base address of the VIC.
  12036. + * @irq: The base IRQ for the VIC.
  12037. + * @resume_sources: bitmask of interrupts allowed for resume sources.
  12038. + *
  12039. + * For older kernels (< 3.xx) do -
  12040. + * Register the VIC with the system device tree so that it can be notified
  12041. + * of suspend and resume requests and ensure that the correct actions are
  12042. + * taken to re-instate the settings on resume.
  12043. + */
  12044. +static void __init armctrl_pm_register(void __iomem * base, unsigned int irq,
  12045. + u32 resume_sources)
  12046. +{
  12047. + armctrl.base = base;
  12048. + armctrl.resume_sources = resume_sources;
  12049. + armctrl.irq = irq;
  12050. +}
  12051. +
  12052. +static int armctrl_set_wake(struct irq_data *d, unsigned int on)
  12053. +{
  12054. + unsigned int off = d->irq & 31;
  12055. + u32 bit = 1 << off;
  12056. +
  12057. + if (!(bit & armctrl.resume_sources))
  12058. + return -EINVAL;
  12059. +
  12060. + if (on)
  12061. + armctrl.resume_irqs |= bit;
  12062. + else
  12063. + armctrl.resume_irqs &= ~bit;
  12064. +
  12065. + return 0;
  12066. +}
  12067. +
  12068. +#else
  12069. +static inline void armctrl_pm_register(void __iomem * base, unsigned int irq,
  12070. + u32 arg1)
  12071. +{
  12072. +}
  12073. +
  12074. +#define armctrl_suspend NULL
  12075. +#define armctrl_resume NULL
  12076. +#define armctrl_set_wake NULL
  12077. +#endif /* CONFIG_PM */
  12078. +
  12079. +static struct syscore_ops armctrl_syscore_ops = {
  12080. + .suspend = armctrl_suspend,
  12081. + .resume = armctrl_resume,
  12082. +};
  12083. +
  12084. +/**
  12085. + * armctrl_syscore_init - initicall to register VIC pm functions
  12086. + *
  12087. + * This is called via late_initcall() to register
  12088. + * the resources for the VICs due to the early
  12089. + * nature of the VIC's registration.
  12090. +*/
  12091. +static int __init armctrl_syscore_init(void)
  12092. +{
  12093. + register_syscore_ops(&armctrl_syscore_ops);
  12094. + return 0;
  12095. +}
  12096. +
  12097. +late_initcall(armctrl_syscore_init);
  12098. +
  12099. +static struct irq_chip armctrl_chip = {
  12100. + .name = "ARMCTRL",
  12101. + .irq_ack = NULL,
  12102. + .irq_mask = armctrl_mask_irq,
  12103. + .irq_unmask = armctrl_unmask_irq,
  12104. + .irq_set_wake = armctrl_set_wake,
  12105. +};
  12106. +
  12107. +/**
  12108. + * armctrl_init - initialise a vectored interrupt controller
  12109. + * @base: iomem base address
  12110. + * @irq_start: starting interrupt number, must be muliple of 32
  12111. + * @armctrl_sources: bitmask of interrupt sources to allow
  12112. + * @resume_sources: bitmask of interrupt sources to allow for resume
  12113. + */
  12114. +int __init armctrl_init(void __iomem * base, unsigned int irq_start,
  12115. + u32 armctrl_sources, u32 resume_sources)
  12116. +{
  12117. + unsigned int irq;
  12118. +
  12119. + for (irq = 0; irq < BCM2708_ALLOC_IRQS; irq++) {
  12120. + unsigned int data = irq;
  12121. + if (irq >= INTERRUPT_JPEG && irq <= INTERRUPT_ARASANSDIO)
  12122. + data = remap_irqs[irq - INTERRUPT_JPEG];
  12123. + if (irq >= IRQ_ARM_LOCAL_CNTPSIRQ && irq <= IRQ_ARM_LOCAL_TIMER) {
  12124. + irq_set_percpu_devid(irq);
  12125. + irq_set_chip_and_handler(irq, &armctrl_chip, handle_percpu_devid_irq);
  12126. + set_irq_flags(irq, IRQF_VALID | IRQF_NOAUTOEN);
  12127. + } else {
  12128. + irq_set_chip_and_handler(irq, &armctrl_chip, handle_level_irq);
  12129. + set_irq_flags(irq, IRQF_VALID | IRQF_PROBE | IRQF_DISABLED);
  12130. + }
  12131. + irq_set_chip_data(irq, (void *)data);
  12132. + }
  12133. +
  12134. + armctrl_pm_register(base, irq_start, resume_sources);
  12135. + init_FIQ(FIQ_START);
  12136. + armctrl_dt_init();
  12137. + return 0;
  12138. +}
  12139. diff -Nur linux-3.18.8/arch/arm/mach-bcm2709/armctrl.h linux-rpi/arch/arm/mach-bcm2709/armctrl.h
  12140. --- linux-3.18.8/arch/arm/mach-bcm2709/armctrl.h 1970-01-01 01:00:00.000000000 +0100
  12141. +++ linux-rpi/arch/arm/mach-bcm2709/armctrl.h 2015-03-05 14:40:11.153715839 +0100
  12142. @@ -0,0 +1,27 @@
  12143. +/*
  12144. + * linux/arch/arm/mach-bcm2708/armctrl.h
  12145. + *
  12146. + * Copyright (C) 2010 Broadcom
  12147. + *
  12148. + * This program is free software; you can redistribute it and/or modify
  12149. + * it under the terms of the GNU General Public License as published by
  12150. + * the Free Software Foundation; either version 2 of the License, or
  12151. + * (at your option) any later version.
  12152. + *
  12153. + * This program is distributed in the hope that it will be useful,
  12154. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12155. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12156. + * GNU General Public License for more details.
  12157. + *
  12158. + * You should have received a copy of the GNU General Public License
  12159. + * along with this program; if not, write to the Free Software
  12160. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  12161. + */
  12162. +
  12163. +#ifndef __BCM2708_ARMCTRL_H
  12164. +#define __BCM2708_ARMCTRL_H
  12165. +
  12166. +extern int __init armctrl_init(void __iomem * base, unsigned int irq_start,
  12167. + u32 armctrl_sources, u32 resume_sources);
  12168. +
  12169. +#endif
  12170. diff -Nur linux-3.18.8/arch/arm/mach-bcm2709/bcm2708_gpio.c linux-rpi/arch/arm/mach-bcm2709/bcm2708_gpio.c
  12171. --- linux-3.18.8/arch/arm/mach-bcm2709/bcm2708_gpio.c 1970-01-01 01:00:00.000000000 +0100
  12172. +++ linux-rpi/arch/arm/mach-bcm2709/bcm2708_gpio.c 2015-03-05 14:40:11.153715839 +0100
  12173. @@ -0,0 +1,426 @@
  12174. +/*
  12175. + * linux/arch/arm/mach-bcm2708/bcm2708_gpio.c
  12176. + *
  12177. + * Copyright (C) 2010 Broadcom
  12178. + *
  12179. + * This program is free software; you can redistribute it and/or modify
  12180. + * it under the terms of the GNU General Public License version 2 as
  12181. + * published by the Free Software Foundation.
  12182. + *
  12183. + */
  12184. +
  12185. +#include <linux/spinlock.h>
  12186. +#include <linux/module.h>
  12187. +#include <linux/delay.h>
  12188. +#include <linux/list.h>
  12189. +#include <linux/io.h>
  12190. +#include <linux/irq.h>
  12191. +#include <linux/interrupt.h>
  12192. +#include <linux/slab.h>
  12193. +#include <mach/gpio.h>
  12194. +#include <linux/gpio.h>
  12195. +#include <linux/platform_device.h>
  12196. +#include <mach/platform.h>
  12197. +#include <linux/pinctrl/consumer.h>
  12198. +
  12199. +#include <linux/platform_data/bcm2708.h>
  12200. +
  12201. +#define BCM_GPIO_DRIVER_NAME "bcm2708_gpio"
  12202. +#define DRIVER_NAME BCM_GPIO_DRIVER_NAME
  12203. +#define BCM_GPIO_USE_IRQ 1
  12204. +
  12205. +#define GPIOFSEL(x) (0x00+(x)*4)
  12206. +#define GPIOSET(x) (0x1c+(x)*4)
  12207. +#define GPIOCLR(x) (0x28+(x)*4)
  12208. +#define GPIOLEV(x) (0x34+(x)*4)
  12209. +#define GPIOEDS(x) (0x40+(x)*4)
  12210. +#define GPIOREN(x) (0x4c+(x)*4)
  12211. +#define GPIOFEN(x) (0x58+(x)*4)
  12212. +#define GPIOHEN(x) (0x64+(x)*4)
  12213. +#define GPIOLEN(x) (0x70+(x)*4)
  12214. +#define GPIOAREN(x) (0x7c+(x)*4)
  12215. +#define GPIOAFEN(x) (0x88+(x)*4)
  12216. +#define GPIOUD(x) (0x94+(x)*4)
  12217. +#define GPIOUDCLK(x) (0x98+(x)*4)
  12218. +
  12219. +#define GPIO_BANKS 2
  12220. +
  12221. +enum { GPIO_FSEL_INPUT, GPIO_FSEL_OUTPUT,
  12222. + GPIO_FSEL_ALT5, GPIO_FSEL_ALT_4,
  12223. + GPIO_FSEL_ALT0, GPIO_FSEL_ALT1,
  12224. + GPIO_FSEL_ALT2, GPIO_FSEL_ALT3,
  12225. +};
  12226. +
  12227. + /* Each of the two spinlocks protects a different set of hardware
  12228. + * regiters and data structurs. This decouples the code of the IRQ from
  12229. + * the GPIO code. This also makes the case of a GPIO routine call from
  12230. + * the IRQ code simpler.
  12231. + */
  12232. +static DEFINE_SPINLOCK(lock); /* GPIO registers */
  12233. +
  12234. +struct bcm2708_gpio {
  12235. + struct list_head list;
  12236. + void __iomem *base;
  12237. + struct gpio_chip gc;
  12238. + unsigned long rising[(BCM2708_NR_GPIOS + 31) / 32];
  12239. + unsigned long falling[(BCM2708_NR_GPIOS + 31) / 32];
  12240. + unsigned long high[(BCM2708_NR_GPIOS + 31) / 32];
  12241. + unsigned long low[(BCM2708_NR_GPIOS + 31) / 32];
  12242. +};
  12243. +
  12244. +static int bcm2708_set_function(struct gpio_chip *gc, unsigned offset,
  12245. + int function)
  12246. +{
  12247. + struct bcm2708_gpio *gpio = container_of(gc, struct bcm2708_gpio, gc);
  12248. + unsigned long flags;
  12249. + unsigned gpiodir;
  12250. + unsigned gpio_bank = offset / 10;
  12251. + unsigned gpio_field_offset = (offset - 10 * gpio_bank) * 3;
  12252. +
  12253. +//printk(KERN_ERR DRIVER_NAME ": bcm2708_gpio_set_function %p (%d,%d)\n", gc, offset, function);
  12254. + if (offset >= BCM2708_NR_GPIOS)
  12255. + return -EINVAL;
  12256. +
  12257. + spin_lock_irqsave(&lock, flags);
  12258. +
  12259. + gpiodir = readl(gpio->base + GPIOFSEL(gpio_bank));
  12260. + gpiodir &= ~(7 << gpio_field_offset);
  12261. + gpiodir |= function << gpio_field_offset;
  12262. + writel(gpiodir, gpio->base + GPIOFSEL(gpio_bank));
  12263. + spin_unlock_irqrestore(&lock, flags);
  12264. + gpiodir = readl(gpio->base + GPIOFSEL(gpio_bank));
  12265. +
  12266. + return 0;
  12267. +}
  12268. +
  12269. +static int bcm2708_gpio_dir_in(struct gpio_chip *gc, unsigned offset)
  12270. +{
  12271. + return bcm2708_set_function(gc, offset, GPIO_FSEL_INPUT);
  12272. +}
  12273. +
  12274. +static void bcm2708_gpio_set(struct gpio_chip *gc, unsigned offset, int value);
  12275. +static int bcm2708_gpio_dir_out(struct gpio_chip *gc, unsigned offset,
  12276. + int value)
  12277. +{
  12278. + int ret;
  12279. + ret = bcm2708_set_function(gc, offset, GPIO_FSEL_OUTPUT);
  12280. + if (ret >= 0)
  12281. + bcm2708_gpio_set(gc, offset, value);
  12282. + return ret;
  12283. +}
  12284. +
  12285. +static int bcm2708_gpio_get(struct gpio_chip *gc, unsigned offset)
  12286. +{
  12287. + struct bcm2708_gpio *gpio = container_of(gc, struct bcm2708_gpio, gc);
  12288. + unsigned gpio_bank = offset / 32;
  12289. + unsigned gpio_field_offset = (offset - 32 * gpio_bank);
  12290. + unsigned lev;
  12291. +
  12292. + if (offset >= BCM2708_NR_GPIOS)
  12293. + return 0;
  12294. + lev = readl(gpio->base + GPIOLEV(gpio_bank));
  12295. +//printk(KERN_ERR DRIVER_NAME ": bcm2708_gpio_get %p (%d)=%d\n", gc, offset, 0x1 & (lev>>gpio_field_offset));
  12296. + return 0x1 & (lev >> gpio_field_offset);
  12297. +}
  12298. +
  12299. +static void bcm2708_gpio_set(struct gpio_chip *gc, unsigned offset, int value)
  12300. +{
  12301. + struct bcm2708_gpio *gpio = container_of(gc, struct bcm2708_gpio, gc);
  12302. + unsigned gpio_bank = offset / 32;
  12303. + unsigned gpio_field_offset = (offset - 32 * gpio_bank);
  12304. +//printk(KERN_ERR DRIVER_NAME ": bcm2708_gpio_set %p (%d=%d)\n", gc, offset, value);
  12305. + if (offset >= BCM2708_NR_GPIOS)
  12306. + return;
  12307. + if (value)
  12308. + writel(1 << gpio_field_offset, gpio->base + GPIOSET(gpio_bank));
  12309. + else
  12310. + writel(1 << gpio_field_offset, gpio->base + GPIOCLR(gpio_bank));
  12311. +}
  12312. +
  12313. +/**********************
  12314. + * extension to configure pullups
  12315. + */
  12316. +int bcm2708_gpio_setpull(struct gpio_chip *gc, unsigned offset,
  12317. + bcm2708_gpio_pull_t value)
  12318. +{
  12319. + struct bcm2708_gpio *gpio = container_of(gc, struct bcm2708_gpio, gc);
  12320. + unsigned gpio_bank = offset / 32;
  12321. + unsigned gpio_field_offset = (offset - 32 * gpio_bank);
  12322. +
  12323. + if (offset >= BCM2708_NR_GPIOS)
  12324. + return -EINVAL;
  12325. +
  12326. + switch (value) {
  12327. + case BCM2708_PULL_UP:
  12328. + writel(2, gpio->base + GPIOUD(0));
  12329. + break;
  12330. + case BCM2708_PULL_DOWN:
  12331. + writel(1, gpio->base + GPIOUD(0));
  12332. + break;
  12333. + case BCM2708_PULL_OFF:
  12334. + writel(0, gpio->base + GPIOUD(0));
  12335. + break;
  12336. + }
  12337. +
  12338. + udelay(5);
  12339. + writel(1 << gpio_field_offset, gpio->base + GPIOUDCLK(gpio_bank));
  12340. + udelay(5);
  12341. + writel(0, gpio->base + GPIOUD(0));
  12342. + writel(0 << gpio_field_offset, gpio->base + GPIOUDCLK(gpio_bank));
  12343. +
  12344. + return 0;
  12345. +}
  12346. +EXPORT_SYMBOL(bcm2708_gpio_setpull);
  12347. +
  12348. +/*************************************************************************************************************************
  12349. + * bcm2708 GPIO IRQ
  12350. + */
  12351. +
  12352. +#if BCM_GPIO_USE_IRQ
  12353. +
  12354. +static int bcm2708_gpio_to_irq(struct gpio_chip *chip, unsigned gpio)
  12355. +{
  12356. + return gpio_to_irq(gpio);
  12357. +}
  12358. +
  12359. +static int bcm2708_gpio_irq_set_type(struct irq_data *d, unsigned type)
  12360. +{
  12361. + unsigned irq = d->irq;
  12362. + struct bcm2708_gpio *gpio = irq_get_chip_data(irq);
  12363. + unsigned gn = irq_to_gpio(irq);
  12364. + unsigned gb = gn / 32;
  12365. + unsigned go = gn % 32;
  12366. +
  12367. + gpio->rising[gb] &= ~(1 << go);
  12368. + gpio->falling[gb] &= ~(1 << go);
  12369. + gpio->high[gb] &= ~(1 << go);
  12370. + gpio->low[gb] &= ~(1 << go);
  12371. +
  12372. + if (type & ~(IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING | IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH))
  12373. + return -EINVAL;
  12374. +
  12375. + if (type & IRQ_TYPE_EDGE_RISING)
  12376. + gpio->rising[gb] |= (1 << go);
  12377. + if (type & IRQ_TYPE_EDGE_FALLING)
  12378. + gpio->falling[gb] |= (1 << go);
  12379. + if (type & IRQ_TYPE_LEVEL_HIGH)
  12380. + gpio->high[gb] |= (1 << go);
  12381. + if (type & IRQ_TYPE_LEVEL_LOW)
  12382. + gpio->low[gb] |= (1 << go);
  12383. + return 0;
  12384. +}
  12385. +
  12386. +static void bcm2708_gpio_irq_mask(struct irq_data *d)
  12387. +{
  12388. + unsigned irq = d->irq;
  12389. + struct bcm2708_gpio *gpio = irq_get_chip_data(irq);
  12390. + unsigned gn = irq_to_gpio(irq);
  12391. + unsigned gb = gn / 32;
  12392. + unsigned long rising = readl(gpio->base + GPIOREN(gb));
  12393. + unsigned long falling = readl(gpio->base + GPIOFEN(gb));
  12394. + unsigned long high = readl(gpio->base + GPIOHEN(gb));
  12395. + unsigned long low = readl(gpio->base + GPIOLEN(gb));
  12396. +
  12397. + gn = gn % 32;
  12398. +
  12399. + writel(rising & ~(1 << gn), gpio->base + GPIOREN(gb));
  12400. + writel(falling & ~(1 << gn), gpio->base + GPIOFEN(gb));
  12401. + writel(high & ~(1 << gn), gpio->base + GPIOHEN(gb));
  12402. + writel(low & ~(1 << gn), gpio->base + GPIOLEN(gb));
  12403. +}
  12404. +
  12405. +static void bcm2708_gpio_irq_unmask(struct irq_data *d)
  12406. +{
  12407. + unsigned irq = d->irq;
  12408. + struct bcm2708_gpio *gpio = irq_get_chip_data(irq);
  12409. + unsigned gn = irq_to_gpio(irq);
  12410. + unsigned gb = gn / 32;
  12411. + unsigned go = gn % 32;
  12412. + unsigned long rising = readl(gpio->base + GPIOREN(gb));
  12413. + unsigned long falling = readl(gpio->base + GPIOFEN(gb));
  12414. + unsigned long high = readl(gpio->base + GPIOHEN(gb));
  12415. + unsigned long low = readl(gpio->base + GPIOLEN(gb));
  12416. +
  12417. + if (gpio->rising[gb] & (1 << go)) {
  12418. + writel(rising | (1 << go), gpio->base + GPIOREN(gb));
  12419. + } else {
  12420. + writel(rising & ~(1 << go), gpio->base + GPIOREN(gb));
  12421. + }
  12422. +
  12423. + if (gpio->falling[gb] & (1 << go)) {
  12424. + writel(falling | (1 << go), gpio->base + GPIOFEN(gb));
  12425. + } else {
  12426. + writel(falling & ~(1 << go), gpio->base + GPIOFEN(gb));
  12427. + }
  12428. +
  12429. + if (gpio->high[gb] & (1 << go)) {
  12430. + writel(high | (1 << go), gpio->base + GPIOHEN(gb));
  12431. + } else {
  12432. + writel(high & ~(1 << go), gpio->base + GPIOHEN(gb));
  12433. + }
  12434. +
  12435. + if (gpio->low[gb] & (1 << go)) {
  12436. + writel(low | (1 << go), gpio->base + GPIOLEN(gb));
  12437. + } else {
  12438. + writel(low & ~(1 << go), gpio->base + GPIOLEN(gb));
  12439. + }
  12440. +}
  12441. +
  12442. +static struct irq_chip bcm2708_irqchip = {
  12443. + .name = "GPIO",
  12444. + .irq_enable = bcm2708_gpio_irq_unmask,
  12445. + .irq_disable = bcm2708_gpio_irq_mask,
  12446. + .irq_unmask = bcm2708_gpio_irq_unmask,
  12447. + .irq_mask = bcm2708_gpio_irq_mask,
  12448. + .irq_set_type = bcm2708_gpio_irq_set_type,
  12449. +};
  12450. +
  12451. +static irqreturn_t bcm2708_gpio_interrupt(int irq, void *dev_id)
  12452. +{
  12453. + unsigned long edsr;
  12454. + unsigned bank;
  12455. + int i;
  12456. + unsigned gpio;
  12457. + unsigned level_bits;
  12458. + struct bcm2708_gpio *gpio_data = dev_id;
  12459. +
  12460. + for (bank = 0; bank < GPIO_BANKS; bank++) {
  12461. + edsr = readl(__io_address(GPIO_BASE) + GPIOEDS(bank));
  12462. + level_bits = gpio_data->high[bank] | gpio_data->low[bank];
  12463. +
  12464. + for_each_set_bit(i, &edsr, 32) {
  12465. + gpio = i + bank * 32;
  12466. + /* ack edge triggered IRQs immediately */
  12467. + if (!(level_bits & (1<<i)))
  12468. + writel(1<<i,
  12469. + __io_address(GPIO_BASE) + GPIOEDS(bank));
  12470. + generic_handle_irq(gpio_to_irq(gpio));
  12471. + /* ack level triggered IRQ after handling them */
  12472. + if (level_bits & (1<<i))
  12473. + writel(1<<i,
  12474. + __io_address(GPIO_BASE) + GPIOEDS(bank));
  12475. + }
  12476. + }
  12477. + return IRQ_HANDLED;
  12478. +}
  12479. +
  12480. +static struct irqaction bcm2708_gpio_irq = {
  12481. + .name = "BCM2708 GPIO catchall handler",
  12482. + .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
  12483. + .handler = bcm2708_gpio_interrupt,
  12484. +};
  12485. +
  12486. +static void bcm2708_gpio_irq_init(struct bcm2708_gpio *ucb)
  12487. +{
  12488. + unsigned irq;
  12489. +
  12490. + ucb->gc.to_irq = bcm2708_gpio_to_irq;
  12491. +
  12492. + for (irq = GPIO_IRQ_START; irq < (GPIO_IRQ_START + GPIO_IRQS); irq++) {
  12493. + irq_set_chip_data(irq, ucb);
  12494. + irq_set_chip_and_handler(irq, &bcm2708_irqchip,
  12495. + handle_simple_irq);
  12496. + set_irq_flags(irq, IRQF_VALID);
  12497. + }
  12498. +
  12499. + bcm2708_gpio_irq.dev_id = ucb;
  12500. + setup_irq(IRQ_GPIO3, &bcm2708_gpio_irq);
  12501. +}
  12502. +
  12503. +#else
  12504. +
  12505. +static void bcm2708_gpio_irq_init(struct bcm2708_gpio *ucb)
  12506. +{
  12507. +}
  12508. +
  12509. +#endif /* #if BCM_GPIO_USE_IRQ ***************************************************************************************************************** */
  12510. +
  12511. +static int bcm2708_gpio_probe(struct platform_device *dev)
  12512. +{
  12513. + struct bcm2708_gpio *ucb;
  12514. + struct resource *res;
  12515. + int bank;
  12516. + int err = 0;
  12517. +
  12518. + printk(KERN_INFO DRIVER_NAME ": bcm2708_gpio_probe %p\n", dev);
  12519. +
  12520. + ucb = kzalloc(sizeof(*ucb), GFP_KERNEL);
  12521. + if (NULL == ucb) {
  12522. + printk(KERN_ERR DRIVER_NAME ": failed to allocate "
  12523. + "mailbox memory\n");
  12524. + err = -ENOMEM;
  12525. + goto err;
  12526. + }
  12527. +
  12528. + res = platform_get_resource(dev, IORESOURCE_MEM, 0);
  12529. +
  12530. + platform_set_drvdata(dev, ucb);
  12531. + ucb->base = __io_address(GPIO_BASE);
  12532. +
  12533. + ucb->gc.label = "bcm2708_gpio";
  12534. + ucb->gc.base = 0;
  12535. + ucb->gc.ngpio = BCM2708_NR_GPIOS;
  12536. + ucb->gc.owner = THIS_MODULE;
  12537. +
  12538. + ucb->gc.direction_input = bcm2708_gpio_dir_in;
  12539. + ucb->gc.direction_output = bcm2708_gpio_dir_out;
  12540. + ucb->gc.get = bcm2708_gpio_get;
  12541. + ucb->gc.set = bcm2708_gpio_set;
  12542. + ucb->gc.can_sleep = 0;
  12543. +
  12544. + for (bank = 0; bank < GPIO_BANKS; bank++) {
  12545. + writel(0, ucb->base + GPIOREN(bank));
  12546. + writel(0, ucb->base + GPIOFEN(bank));
  12547. + writel(0, ucb->base + GPIOHEN(bank));
  12548. + writel(0, ucb->base + GPIOLEN(bank));
  12549. + writel(0, ucb->base + GPIOAREN(bank));
  12550. + writel(0, ucb->base + GPIOAFEN(bank));
  12551. + writel(~0, ucb->base + GPIOEDS(bank));
  12552. + }
  12553. +
  12554. + bcm2708_gpio_irq_init(ucb);
  12555. +
  12556. + err = gpiochip_add(&ucb->gc);
  12557. +
  12558. +err:
  12559. + return err;
  12560. +
  12561. +}
  12562. +
  12563. +static int bcm2708_gpio_remove(struct platform_device *dev)
  12564. +{
  12565. + int err = 0;
  12566. + struct bcm2708_gpio *ucb = platform_get_drvdata(dev);
  12567. +
  12568. + printk(KERN_ERR DRIVER_NAME ": bcm2708_gpio_remove %p\n", dev);
  12569. +
  12570. + gpiochip_remove(&ucb->gc);
  12571. +
  12572. + platform_set_drvdata(dev, NULL);
  12573. + kfree(ucb);
  12574. +
  12575. + return err;
  12576. +}
  12577. +
  12578. +static struct platform_driver bcm2708_gpio_driver = {
  12579. + .probe = bcm2708_gpio_probe,
  12580. + .remove = bcm2708_gpio_remove,
  12581. + .driver = {
  12582. + .name = "bcm2708_gpio"},
  12583. +};
  12584. +
  12585. +static int __init bcm2708_gpio_init(void)
  12586. +{
  12587. + return platform_driver_register(&bcm2708_gpio_driver);
  12588. +}
  12589. +
  12590. +static void __exit bcm2708_gpio_exit(void)
  12591. +{
  12592. + platform_driver_unregister(&bcm2708_gpio_driver);
  12593. +}
  12594. +
  12595. +module_init(bcm2708_gpio_init);
  12596. +module_exit(bcm2708_gpio_exit);
  12597. +
  12598. +MODULE_DESCRIPTION("Broadcom BCM2708 GPIO driver");
  12599. +MODULE_LICENSE("GPL");
  12600. diff -Nur linux-3.18.8/arch/arm/mach-bcm2709/bcm2709.c linux-rpi/arch/arm/mach-bcm2709/bcm2709.c
  12601. --- linux-3.18.8/arch/arm/mach-bcm2709/bcm2709.c 1970-01-01 01:00:00.000000000 +0100
  12602. +++ linux-rpi/arch/arm/mach-bcm2709/bcm2709.c 2015-03-05 14:40:11.153715839 +0100
  12603. @@ -0,0 +1,1297 @@
  12604. +/*
  12605. + * linux/arch/arm/mach-bcm2709/bcm2709.c
  12606. + *
  12607. + * Copyright (C) 2010 Broadcom
  12608. + *
  12609. + * This program is free software; you can redistribute it and/or modify
  12610. + * it under the terms of the GNU General Public License as published by
  12611. + * the Free Software Foundation; either version 2 of the License, or
  12612. + * (at your option) any later version.
  12613. + *
  12614. + * This program is distributed in the hope that it will be useful,
  12615. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12616. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12617. + * GNU General Public License for more details.
  12618. + *
  12619. + * You should have received a copy of the GNU General Public License
  12620. + * along with this program; if not, write to the Free Software
  12621. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  12622. + */
  12623. +
  12624. +#include <linux/init.h>
  12625. +#include <linux/device.h>
  12626. +#include <linux/dma-mapping.h>
  12627. +#include <linux/serial_8250.h>
  12628. +#include <linux/platform_device.h>
  12629. +#include <linux/syscore_ops.h>
  12630. +#include <linux/interrupt.h>
  12631. +#include <linux/amba/bus.h>
  12632. +#include <linux/amba/clcd.h>
  12633. +#include <linux/clk-provider.h>
  12634. +#include <linux/clkdev.h>
  12635. +#include <linux/clockchips.h>
  12636. +#include <linux/cnt32_to_63.h>
  12637. +#include <linux/io.h>
  12638. +#include <linux/module.h>
  12639. +#include <linux/of_platform.h>
  12640. +#include <linux/spi/spi.h>
  12641. +#include <linux/gpio/machine.h>
  12642. +#include <linux/w1-gpio.h>
  12643. +#include <linux/pps-gpio.h>
  12644. +
  12645. +#include <linux/version.h>
  12646. +#include <linux/clkdev.h>
  12647. +#include <asm/system_info.h>
  12648. +#include <mach/hardware.h>
  12649. +#include <asm/irq.h>
  12650. +#include <linux/leds.h>
  12651. +#include <asm/mach-types.h>
  12652. +#include <asm/cputype.h>
  12653. +#include <linux/sched_clock.h>
  12654. +
  12655. +#include <asm/mach/arch.h>
  12656. +#include <asm/mach/flash.h>
  12657. +#include <asm/mach/irq.h>
  12658. +#include <asm/mach/time.h>
  12659. +#include <asm/mach/map.h>
  12660. +
  12661. +#include <mach/timex.h>
  12662. +#include <mach/dma.h>
  12663. +#include <mach/vcio.h>
  12664. +#include <mach/system.h>
  12665. +
  12666. +#include <linux/delay.h>
  12667. +
  12668. +#include "bcm2709.h"
  12669. +#include "armctrl.h"
  12670. +
  12671. +#ifdef CONFIG_BCM_VC_CMA
  12672. +#include <linux/broadcom/vc_cma.h>
  12673. +#endif
  12674. +
  12675. +//#define SYSTEM_TIMER
  12676. +
  12677. +/* Effectively we have an IOMMU (ARM<->VideoCore map) that is set up to
  12678. + * give us IO access only to 64Mbytes of physical memory (26 bits). We could
  12679. + * represent this window by setting our dmamasks to 26 bits but, in fact
  12680. + * we're not going to use addresses outside this range (they're not in real
  12681. + * memory) so we don't bother.
  12682. + *
  12683. + * In the future we might include code to use this IOMMU to remap other
  12684. + * physical addresses onto VideoCore memory then the use of 32-bits would be
  12685. + * more legitimate.
  12686. + */
  12687. +#define DMA_MASK_BITS_COMMON 32
  12688. +
  12689. +// use GPIO 4 for the one-wire GPIO pin, if enabled
  12690. +#define W1_GPIO 4
  12691. +// ensure one-wire GPIO pullup is disabled by default
  12692. +#define W1_PULLUP -1
  12693. +
  12694. +/* command line parameters */
  12695. +static unsigned boardrev, serial;
  12696. +static unsigned uart_clock = UART0_CLOCK;
  12697. +static unsigned disk_led_gpio = 16;
  12698. +static unsigned disk_led_active_low = 1;
  12699. +static unsigned reboot_part = 0;
  12700. +static unsigned w1_gpio_pin = W1_GPIO;
  12701. +static unsigned w1_gpio_pullup = W1_PULLUP;
  12702. +static int pps_gpio_pin = -1;
  12703. +static bool vc_i2c_override = false;
  12704. +
  12705. +static unsigned use_dt = 0;
  12706. +
  12707. +static void __init bcm2709_init_led(void);
  12708. +
  12709. +void __init bcm2709_init_irq(void)
  12710. +{
  12711. + armctrl_init(__io_address(ARMCTRL_IC_BASE), 0, 0, 0);
  12712. +}
  12713. +
  12714. +static struct map_desc bcm2709_io_desc[] __initdata = {
  12715. + {
  12716. + .virtual = IO_ADDRESS(ARMCTRL_BASE),
  12717. + .pfn = __phys_to_pfn(ARMCTRL_BASE),
  12718. + .length = SZ_4K,
  12719. + .type = MT_DEVICE},
  12720. + {
  12721. + .virtual = IO_ADDRESS(UART0_BASE),
  12722. + .pfn = __phys_to_pfn(UART0_BASE),
  12723. + .length = SZ_4K,
  12724. + .type = MT_DEVICE},
  12725. + {
  12726. + .virtual = IO_ADDRESS(UART1_BASE),
  12727. + .pfn = __phys_to_pfn(UART1_BASE),
  12728. + .length = SZ_4K,
  12729. + .type = MT_DEVICE},
  12730. + {
  12731. + .virtual = IO_ADDRESS(DMA_BASE),
  12732. + .pfn = __phys_to_pfn(DMA_BASE),
  12733. + .length = SZ_4K,
  12734. + .type = MT_DEVICE},
  12735. + {
  12736. + .virtual = IO_ADDRESS(MCORE_BASE),
  12737. + .pfn = __phys_to_pfn(MCORE_BASE),
  12738. + .length = SZ_4K,
  12739. + .type = MT_DEVICE},
  12740. + {
  12741. + .virtual = IO_ADDRESS(ST_BASE),
  12742. + .pfn = __phys_to_pfn(ST_BASE),
  12743. + .length = SZ_4K,
  12744. + .type = MT_DEVICE},
  12745. + {
  12746. + .virtual = IO_ADDRESS(USB_BASE),
  12747. + .pfn = __phys_to_pfn(USB_BASE),
  12748. + .length = SZ_128K,
  12749. + .type = MT_DEVICE},
  12750. + {
  12751. + .virtual = IO_ADDRESS(PM_BASE),
  12752. + .pfn = __phys_to_pfn(PM_BASE),
  12753. + .length = SZ_4K,
  12754. + .type = MT_DEVICE},
  12755. + {
  12756. + .virtual = IO_ADDRESS(GPIO_BASE),
  12757. + .pfn = __phys_to_pfn(GPIO_BASE),
  12758. + .length = SZ_4K,
  12759. + .type = MT_DEVICE},
  12760. + {
  12761. + .virtual = IO_ADDRESS(ARM_LOCAL_BASE),
  12762. + .pfn = __phys_to_pfn(ARM_LOCAL_BASE),
  12763. + .length = SZ_4K,
  12764. + .type = MT_DEVICE},
  12765. +};
  12766. +
  12767. +void __init bcm2709_map_io(void)
  12768. +{
  12769. + iotable_init(bcm2709_io_desc, ARRAY_SIZE(bcm2709_io_desc));
  12770. +}
  12771. +
  12772. +#ifdef SYSTEM_TIMER
  12773. +
  12774. +/* The STC is a free running counter that increments at the rate of 1MHz */
  12775. +#define STC_FREQ_HZ 1000000
  12776. +
  12777. +static inline uint32_t timer_read(void)
  12778. +{
  12779. + /* STC: a free running counter that increments at the rate of 1MHz */
  12780. + return readl(__io_address(ST_BASE + 0x04));
  12781. +}
  12782. +
  12783. +static unsigned long bcm2709_read_current_timer(void)
  12784. +{
  12785. + return timer_read();
  12786. +}
  12787. +
  12788. +static u64 notrace bcm2709_read_sched_clock(void)
  12789. +{
  12790. + return timer_read();
  12791. +}
  12792. +
  12793. +static cycle_t clksrc_read(struct clocksource *cs)
  12794. +{
  12795. + return timer_read();
  12796. +}
  12797. +
  12798. +static struct clocksource clocksource_stc = {
  12799. + .name = "stc",
  12800. + .rating = 300,
  12801. + .read = clksrc_read,
  12802. + .mask = CLOCKSOURCE_MASK(32),
  12803. + .flags = CLOCK_SOURCE_IS_CONTINUOUS,
  12804. +};
  12805. +
  12806. +unsigned long frc_clock_ticks32(void)
  12807. +{
  12808. + return timer_read();
  12809. +}
  12810. +
  12811. +static void __init bcm2709_clocksource_init(void)
  12812. +{
  12813. + if (clocksource_register_hz(&clocksource_stc, STC_FREQ_HZ)) {
  12814. + printk(KERN_ERR "timer: failed to initialize clock "
  12815. + "source %s\n", clocksource_stc.name);
  12816. + }
  12817. +}
  12818. +#endif
  12819. +
  12820. +struct clk __init *bcm2709_clk_register(const char *name, unsigned long fixed_rate)
  12821. +{
  12822. + struct clk *clk;
  12823. +
  12824. + clk = clk_register_fixed_rate(NULL, name, NULL, CLK_IS_ROOT,
  12825. + fixed_rate);
  12826. + if (IS_ERR(clk))
  12827. + pr_err("%s not registered\n", name);
  12828. +
  12829. + return clk;
  12830. +}
  12831. +
  12832. +void __init bcm2709_register_clkdev(struct clk *clk, const char *name)
  12833. +{
  12834. + int ret;
  12835. +
  12836. + ret = clk_register_clkdev(clk, NULL, name);
  12837. + if (ret)
  12838. + pr_err("%s alias not registered\n", name);
  12839. +}
  12840. +
  12841. +void __init bcm2709_init_clocks(void)
  12842. +{
  12843. + struct clk *clk;
  12844. +
  12845. + clk = bcm2709_clk_register("uart0_clk", uart_clock);
  12846. + bcm2709_register_clkdev(clk, "dev:f1");
  12847. +
  12848. + clk = bcm2709_clk_register("sdhost_clk", 250000000);
  12849. + bcm2709_register_clkdev(clk, "bcm2708_spi.0");
  12850. + bcm2709_register_clkdev(clk, "bcm2708_i2c.0");
  12851. + bcm2709_register_clkdev(clk, "bcm2708_i2c.1");
  12852. +}
  12853. +
  12854. +#define UART0_IRQ { IRQ_UART, 0 /*NO_IRQ*/ }
  12855. +#define UART0_DMA { 15, 14 }
  12856. +
  12857. +AMBA_DEVICE(uart0, "dev:f1", UART0, NULL);
  12858. +
  12859. +static struct amba_device *amba_devs[] __initdata = {
  12860. + &uart0_device,
  12861. +};
  12862. +
  12863. +static struct resource bcm2708_dmaman_resources[] = {
  12864. + {
  12865. + .start = DMA_BASE,
  12866. + .end = DMA_BASE + SZ_4K - 1,
  12867. + .flags = IORESOURCE_MEM,
  12868. + }
  12869. +};
  12870. +
  12871. +static struct platform_device bcm2708_dmaman_device = {
  12872. + .name = BCM_DMAMAN_DRIVER_NAME,
  12873. + .id = 0, /* first bcm2708_dma */
  12874. + .resource = bcm2708_dmaman_resources,
  12875. + .num_resources = ARRAY_SIZE(bcm2708_dmaman_resources),
  12876. +};
  12877. +
  12878. +#if defined(CONFIG_W1_MASTER_GPIO) || defined(CONFIG_W1_MASTER_GPIO_MODULE)
  12879. +static struct w1_gpio_platform_data w1_gpio_pdata = {
  12880. + .pin = W1_GPIO,
  12881. + .ext_pullup_enable_pin = W1_PULLUP,
  12882. + .is_open_drain = 0,
  12883. +};
  12884. +
  12885. +static struct platform_device w1_device = {
  12886. + .name = "w1-gpio",
  12887. + .id = -1,
  12888. + .dev.platform_data = &w1_gpio_pdata,
  12889. +};
  12890. +#endif
  12891. +
  12892. +static struct pps_gpio_platform_data pps_gpio_info = {
  12893. + .assert_falling_edge = false,
  12894. + .capture_clear = false,
  12895. + .gpio_pin = -1,
  12896. + .gpio_label = "PPS",
  12897. +};
  12898. +
  12899. +static struct platform_device pps_gpio_device = {
  12900. + .name = "pps-gpio",
  12901. + .id = PLATFORM_DEVID_NONE,
  12902. + .dev.platform_data = &pps_gpio_info,
  12903. +};
  12904. +
  12905. +static u64 fb_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  12906. +
  12907. +static struct platform_device bcm2708_fb_device = {
  12908. + .name = "bcm2708_fb",
  12909. + .id = -1, /* only one bcm2708_fb */
  12910. + .resource = NULL,
  12911. + .num_resources = 0,
  12912. + .dev = {
  12913. + .dma_mask = &fb_dmamask,
  12914. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON),
  12915. + },
  12916. +};
  12917. +
  12918. +static struct plat_serial8250_port bcm2708_uart1_platform_data[] = {
  12919. + {
  12920. + .mapbase = UART1_BASE + 0x40,
  12921. + .irq = IRQ_AUX,
  12922. + .uartclk = 125000000,
  12923. + .regshift = 2,
  12924. + .iotype = UPIO_MEM,
  12925. + .flags = UPF_FIXED_TYPE | UPF_IOREMAP | UPF_SKIP_TEST,
  12926. + .type = PORT_8250,
  12927. + },
  12928. + {},
  12929. +};
  12930. +
  12931. +static struct platform_device bcm2708_uart1_device = {
  12932. + .name = "serial8250",
  12933. + .id = PLAT8250_DEV_PLATFORM,
  12934. + .dev = {
  12935. + .platform_data = bcm2708_uart1_platform_data,
  12936. + },
  12937. +};
  12938. +
  12939. +static struct resource bcm2708_usb_resources[] = {
  12940. + [0] = {
  12941. + .start = USB_BASE,
  12942. + .end = USB_BASE + SZ_128K - 1,
  12943. + .flags = IORESOURCE_MEM,
  12944. + },
  12945. + [1] = {
  12946. + .start = MPHI_BASE,
  12947. + .end = MPHI_BASE + SZ_4K - 1,
  12948. + .flags = IORESOURCE_MEM,
  12949. + },
  12950. + [2] = {
  12951. + .start = IRQ_HOSTPORT,
  12952. + .end = IRQ_HOSTPORT,
  12953. + .flags = IORESOURCE_IRQ,
  12954. + },
  12955. + [3] = {
  12956. + .start = IRQ_USB,
  12957. + .end = IRQ_USB,
  12958. + .flags = IORESOURCE_IRQ,
  12959. + },
  12960. + [4] = {
  12961. + .start = ARM_LOCAL_BASE,
  12962. + .end = ARM_LOCAL_BASE + SZ_4K - 1,
  12963. + .flags = IORESOURCE_MEM,
  12964. + },
  12965. + [5] = {
  12966. + .start = IRQ_ARM_LOCAL_MAILBOX1,
  12967. + .end = IRQ_ARM_LOCAL_MAILBOX1,
  12968. + .flags = IORESOURCE_IRQ
  12969. + },
  12970. +};
  12971. +
  12972. +
  12973. +static u64 usb_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  12974. +
  12975. +static struct platform_device bcm2708_usb_device = {
  12976. + .name = "bcm2708_usb",
  12977. + .id = -1, /* only one bcm2708_usb */
  12978. + .resource = bcm2708_usb_resources,
  12979. + .num_resources = ARRAY_SIZE(bcm2708_usb_resources),
  12980. + .dev = {
  12981. + .dma_mask = &usb_dmamask,
  12982. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON),
  12983. + },
  12984. +};
  12985. +
  12986. +static struct resource bcm2708_vcio_resources[] = {
  12987. + [0] = { /* mailbox/semaphore/doorbell access */
  12988. + .start = MCORE_BASE,
  12989. + .end = MCORE_BASE + SZ_4K - 1,
  12990. + .flags = IORESOURCE_MEM,
  12991. + },
  12992. +};
  12993. +
  12994. +static u64 vcio_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  12995. +
  12996. +static struct platform_device bcm2708_vcio_device = {
  12997. + .name = BCM_VCIO_DRIVER_NAME,
  12998. + .id = -1, /* only one VideoCore I/O area */
  12999. + .resource = bcm2708_vcio_resources,
  13000. + .num_resources = ARRAY_SIZE(bcm2708_vcio_resources),
  13001. + .dev = {
  13002. + .dma_mask = &vcio_dmamask,
  13003. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON),
  13004. + },
  13005. +};
  13006. +
  13007. +#ifdef CONFIG_BCM2708_GPIO
  13008. +#define BCM_GPIO_DRIVER_NAME "bcm2708_gpio"
  13009. +
  13010. +static struct resource bcm2708_gpio_resources[] = {
  13011. + [0] = { /* general purpose I/O */
  13012. + .start = GPIO_BASE,
  13013. + .end = GPIO_BASE + SZ_4K - 1,
  13014. + .flags = IORESOURCE_MEM,
  13015. + },
  13016. +};
  13017. +
  13018. +static u64 gpio_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  13019. +
  13020. +static struct platform_device bcm2708_gpio_device = {
  13021. + .name = BCM_GPIO_DRIVER_NAME,
  13022. + .id = -1, /* only one VideoCore I/O area */
  13023. + .resource = bcm2708_gpio_resources,
  13024. + .num_resources = ARRAY_SIZE(bcm2708_gpio_resources),
  13025. + .dev = {
  13026. + .dma_mask = &gpio_dmamask,
  13027. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON),
  13028. + },
  13029. +};
  13030. +#endif
  13031. +
  13032. +#ifdef SYSTEM_TIMER
  13033. +static struct resource bcm2708_systemtimer_resources[] = {
  13034. + [0] = { /* system timer access */
  13035. + .start = ST_BASE,
  13036. + .end = ST_BASE + SZ_4K - 1,
  13037. + .flags = IORESOURCE_MEM,
  13038. + },
  13039. + {
  13040. + .start = IRQ_TIMER3,
  13041. + .end = IRQ_TIMER3,
  13042. + .flags = IORESOURCE_IRQ,
  13043. + }
  13044. +
  13045. +};
  13046. +
  13047. +static u64 systemtimer_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  13048. +
  13049. +static struct platform_device bcm2708_systemtimer_device = {
  13050. + .name = "bcm2708_systemtimer",
  13051. + .id = -1, /* only one VideoCore I/O area */
  13052. + .resource = bcm2708_systemtimer_resources,
  13053. + .num_resources = ARRAY_SIZE(bcm2708_systemtimer_resources),
  13054. + .dev = {
  13055. + .dma_mask = &systemtimer_dmamask,
  13056. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON),
  13057. + },
  13058. +};
  13059. +#endif
  13060. +
  13061. +#ifdef CONFIG_MMC_BCM2835 /* Arasan emmc SD (new) */
  13062. +static struct resource bcm2835_emmc_resources[] = {
  13063. + [0] = {
  13064. + .start = EMMC_BASE,
  13065. + .end = EMMC_BASE + SZ_256 - 1, /* we only need this area */
  13066. + /* the memory map actually makes SZ_4K available */
  13067. + .flags = IORESOURCE_MEM,
  13068. + },
  13069. + [1] = {
  13070. + .start = IRQ_ARASANSDIO,
  13071. + .end = IRQ_ARASANSDIO,
  13072. + .flags = IORESOURCE_IRQ,
  13073. + },
  13074. +};
  13075. +
  13076. +static u64 bcm2835_emmc_dmamask = 0xffffffffUL;
  13077. +
  13078. +struct platform_device bcm2835_emmc_device = {
  13079. + .name = "mmc-bcm2835",
  13080. + .id = 0,
  13081. + .num_resources = ARRAY_SIZE(bcm2835_emmc_resources),
  13082. + .resource = bcm2835_emmc_resources,
  13083. + .dev = {
  13084. + .dma_mask = &bcm2835_emmc_dmamask,
  13085. + .coherent_dma_mask = 0xffffffffUL},
  13086. +};
  13087. +#endif /* CONFIG_MMC_BCM2835 */
  13088. +
  13089. +static struct resource bcm2708_powerman_resources[] = {
  13090. + [0] = {
  13091. + .start = PM_BASE,
  13092. + .end = PM_BASE + SZ_256 - 1,
  13093. + .flags = IORESOURCE_MEM,
  13094. + },
  13095. +};
  13096. +
  13097. +static u64 powerman_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  13098. +
  13099. +struct platform_device bcm2708_powerman_device = {
  13100. + .name = "bcm2708_powerman",
  13101. + .id = 0,
  13102. + .num_resources = ARRAY_SIZE(bcm2708_powerman_resources),
  13103. + .resource = bcm2708_powerman_resources,
  13104. + .dev = {
  13105. + .dma_mask = &powerman_dmamask,
  13106. + .coherent_dma_mask = 0xffffffffUL},
  13107. +};
  13108. +
  13109. +
  13110. +static struct platform_device bcm2708_alsa_devices[] = {
  13111. + [0] = {
  13112. + .name = "bcm2835_AUD0",
  13113. + .id = 0, /* first audio device */
  13114. + .resource = 0,
  13115. + .num_resources = 0,
  13116. + },
  13117. + [1] = {
  13118. + .name = "bcm2835_AUD1",
  13119. + .id = 1, /* second audio device */
  13120. + .resource = 0,
  13121. + .num_resources = 0,
  13122. + },
  13123. + [2] = {
  13124. + .name = "bcm2835_AUD2",
  13125. + .id = 2, /* third audio device */
  13126. + .resource = 0,
  13127. + .num_resources = 0,
  13128. + },
  13129. + [3] = {
  13130. + .name = "bcm2835_AUD3",
  13131. + .id = 3, /* forth audio device */
  13132. + .resource = 0,
  13133. + .num_resources = 0,
  13134. + },
  13135. + [4] = {
  13136. + .name = "bcm2835_AUD4",
  13137. + .id = 4, /* fifth audio device */
  13138. + .resource = 0,
  13139. + .num_resources = 0,
  13140. + },
  13141. + [5] = {
  13142. + .name = "bcm2835_AUD5",
  13143. + .id = 5, /* sixth audio device */
  13144. + .resource = 0,
  13145. + .num_resources = 0,
  13146. + },
  13147. + [6] = {
  13148. + .name = "bcm2835_AUD6",
  13149. + .id = 6, /* seventh audio device */
  13150. + .resource = 0,
  13151. + .num_resources = 0,
  13152. + },
  13153. + [7] = {
  13154. + .name = "bcm2835_AUD7",
  13155. + .id = 7, /* eighth audio device */
  13156. + .resource = 0,
  13157. + .num_resources = 0,
  13158. + },
  13159. +};
  13160. +
  13161. +static struct resource bcm2708_spi_resources[] = {
  13162. + {
  13163. + .start = SPI0_BASE,
  13164. + .end = SPI0_BASE + SZ_256 - 1,
  13165. + .flags = IORESOURCE_MEM,
  13166. + }, {
  13167. + .start = IRQ_SPI,
  13168. + .end = IRQ_SPI,
  13169. + .flags = IORESOURCE_IRQ,
  13170. + }
  13171. +};
  13172. +
  13173. +
  13174. +static u64 bcm2708_spi_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  13175. +static struct platform_device bcm2708_spi_device = {
  13176. + .name = "bcm2708_spi",
  13177. + .id = 0,
  13178. + .num_resources = ARRAY_SIZE(bcm2708_spi_resources),
  13179. + .resource = bcm2708_spi_resources,
  13180. + .dev = {
  13181. + .dma_mask = &bcm2708_spi_dmamask,
  13182. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON)},
  13183. +};
  13184. +
  13185. +#ifdef CONFIG_BCM2708_SPIDEV
  13186. +static struct spi_board_info bcm2708_spi_devices[] = {
  13187. +#ifdef CONFIG_SPI_SPIDEV
  13188. + {
  13189. + .modalias = "spidev",
  13190. + .max_speed_hz = 500000,
  13191. + .bus_num = 0,
  13192. + .chip_select = 0,
  13193. + .mode = SPI_MODE_0,
  13194. + }, {
  13195. + .modalias = "spidev",
  13196. + .max_speed_hz = 500000,
  13197. + .bus_num = 0,
  13198. + .chip_select = 1,
  13199. + .mode = SPI_MODE_0,
  13200. + }
  13201. +#endif
  13202. +};
  13203. +#endif
  13204. +
  13205. +static struct resource bcm2708_bsc0_resources[] = {
  13206. + {
  13207. + .start = BSC0_BASE,
  13208. + .end = BSC0_BASE + SZ_256 - 1,
  13209. + .flags = IORESOURCE_MEM,
  13210. + }, {
  13211. + .start = INTERRUPT_I2C,
  13212. + .end = INTERRUPT_I2C,
  13213. + .flags = IORESOURCE_IRQ,
  13214. + }
  13215. +};
  13216. +
  13217. +static struct platform_device bcm2708_bsc0_device = {
  13218. + .name = "bcm2708_i2c",
  13219. + .id = 0,
  13220. + .num_resources = ARRAY_SIZE(bcm2708_bsc0_resources),
  13221. + .resource = bcm2708_bsc0_resources,
  13222. +};
  13223. +
  13224. +
  13225. +static struct resource bcm2708_bsc1_resources[] = {
  13226. + {
  13227. + .start = BSC1_BASE,
  13228. + .end = BSC1_BASE + SZ_256 - 1,
  13229. + .flags = IORESOURCE_MEM,
  13230. + }, {
  13231. + .start = INTERRUPT_I2C,
  13232. + .end = INTERRUPT_I2C,
  13233. + .flags = IORESOURCE_IRQ,
  13234. + }
  13235. +};
  13236. +
  13237. +static struct platform_device bcm2708_bsc1_device = {
  13238. + .name = "bcm2708_i2c",
  13239. + .id = 1,
  13240. + .num_resources = ARRAY_SIZE(bcm2708_bsc1_resources),
  13241. + .resource = bcm2708_bsc1_resources,
  13242. +};
  13243. +
  13244. +static struct platform_device bcm2835_hwmon_device = {
  13245. + .name = "bcm2835_hwmon",
  13246. +};
  13247. +
  13248. +static struct platform_device bcm2835_thermal_device = {
  13249. + .name = "bcm2835_thermal",
  13250. +};
  13251. +
  13252. +#if defined(CONFIG_SND_BCM2708_SOC_I2S) || defined(CONFIG_SND_BCM2708_SOC_I2S_MODULE)
  13253. +static struct resource bcm2708_i2s_resources[] = {
  13254. + {
  13255. + .start = I2S_BASE,
  13256. + .end = I2S_BASE + 0x20,
  13257. + .flags = IORESOURCE_MEM,
  13258. + },
  13259. + {
  13260. + .start = PCM_CLOCK_BASE,
  13261. + .end = PCM_CLOCK_BASE + 0x02,
  13262. + .flags = IORESOURCE_MEM,
  13263. + }
  13264. +};
  13265. +
  13266. +static struct platform_device bcm2708_i2s_device = {
  13267. + .name = "bcm2708-i2s",
  13268. + .id = 0,
  13269. + .num_resources = ARRAY_SIZE(bcm2708_i2s_resources),
  13270. + .resource = bcm2708_i2s_resources,
  13271. +};
  13272. +#endif
  13273. +
  13274. +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC_MODULE)
  13275. +static struct platform_device snd_hifiberry_dac_device = {
  13276. + .name = "snd-hifiberry-dac",
  13277. + .id = 0,
  13278. + .num_resources = 0,
  13279. +};
  13280. +
  13281. +static struct platform_device snd_pcm5102a_codec_device = {
  13282. + .name = "pcm5102a-codec",
  13283. + .id = -1,
  13284. + .num_resources = 0,
  13285. +};
  13286. +#endif
  13287. +
  13288. +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS_MODULE)
  13289. +static struct platform_device snd_rpi_hifiberry_dacplus_device = {
  13290. + .name = "snd-rpi-hifiberry-dacplus",
  13291. + .id = 0,
  13292. + .num_resources = 0,
  13293. +};
  13294. +
  13295. +static struct i2c_board_info __initdata snd_pcm512x_hbdacplus_i2c_devices[] = {
  13296. + {
  13297. + I2C_BOARD_INFO("pcm5122", 0x4d)
  13298. + },
  13299. +};
  13300. +#endif
  13301. +
  13302. +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI_MODULE)
  13303. +static struct platform_device snd_hifiberry_digi_device = {
  13304. + .name = "snd-hifiberry-digi",
  13305. + .id = 0,
  13306. + .num_resources = 0,
  13307. +};
  13308. +
  13309. +static struct i2c_board_info __initdata snd_wm8804_i2c_devices[] = {
  13310. + {
  13311. + I2C_BOARD_INFO("wm8804", 0x3b)
  13312. + },
  13313. +};
  13314. +
  13315. +#endif
  13316. +
  13317. +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_AMP) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_AMP_MODULE)
  13318. +static struct platform_device snd_hifiberry_amp_device = {
  13319. + .name = "snd-hifiberry-amp",
  13320. + .id = 0,
  13321. + .num_resources = 0,
  13322. +};
  13323. +
  13324. +static struct i2c_board_info __initdata snd_tas5713_i2c_devices[] = {
  13325. + {
  13326. + I2C_BOARD_INFO("tas5713", 0x1b)
  13327. + },
  13328. +};
  13329. +#endif
  13330. +
  13331. +#if defined(CONFIG_SND_BCM2708_SOC_RPI_DAC) || defined(CONFIG_SND_BCM2708_SOC_RPI_DAC_MODULE)
  13332. +static struct platform_device snd_rpi_dac_device = {
  13333. + .name = "snd-rpi-dac",
  13334. + .id = 0,
  13335. + .num_resources = 0,
  13336. +};
  13337. +
  13338. +static struct platform_device snd_pcm1794a_codec_device = {
  13339. + .name = "pcm1794a-codec",
  13340. + .id = -1,
  13341. + .num_resources = 0,
  13342. +};
  13343. +#endif
  13344. +
  13345. +
  13346. +#if defined(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) || defined(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC_MODULE)
  13347. +static struct platform_device snd_rpi_iqaudio_dac_device = {
  13348. + .name = "snd-rpi-iqaudio-dac",
  13349. + .id = 0,
  13350. + .num_resources = 0,
  13351. +};
  13352. +
  13353. +// Use the actual device name rather than generic driver name
  13354. +static struct i2c_board_info __initdata snd_pcm512x_i2c_devices[] = {
  13355. + {
  13356. + I2C_BOARD_INFO("pcm5122", 0x4c)
  13357. + },
  13358. +};
  13359. +#endif
  13360. +
  13361. +int __init bcm_register_device(struct platform_device *pdev)
  13362. +{
  13363. + int ret;
  13364. +
  13365. + ret = platform_device_register(pdev);
  13366. + if (ret)
  13367. + pr_debug("Unable to register platform device '%s': %d\n",
  13368. + pdev->name, ret);
  13369. +
  13370. + return ret;
  13371. +}
  13372. +
  13373. +/*
  13374. + * Use these macros for platform and i2c devices that are present in the
  13375. + * Device Tree. This way the devices are only added on non-DT systems.
  13376. + */
  13377. +#define bcm_register_device_dt(pdev) \
  13378. + if (!use_dt) bcm_register_device(pdev)
  13379. +
  13380. +#define i2c_register_board_info_dt(busnum, info, n) \
  13381. + if (!use_dt) i2c_register_board_info(busnum, info, n)
  13382. +
  13383. +int calc_rsts(int partition)
  13384. +{
  13385. + return PM_PASSWORD |
  13386. + ((partition & (1 << 0)) << 0) |
  13387. + ((partition & (1 << 1)) << 1) |
  13388. + ((partition & (1 << 2)) << 2) |
  13389. + ((partition & (1 << 3)) << 3) |
  13390. + ((partition & (1 << 4)) << 4) |
  13391. + ((partition & (1 << 5)) << 5);
  13392. +}
  13393. +
  13394. +static void bcm2709_restart(enum reboot_mode mode, const char *cmd)
  13395. +{
  13396. + extern char bcm2708_reboot_mode;
  13397. + uint32_t pm_rstc, pm_wdog;
  13398. + uint32_t timeout = 10;
  13399. + uint32_t pm_rsts = 0;
  13400. +
  13401. + if(bcm2708_reboot_mode == 'q')
  13402. + {
  13403. + // NOOBS < 1.3 booting with reboot=q
  13404. + pm_rsts = readl(__io_address(PM_RSTS));
  13405. + pm_rsts = PM_PASSWORD | pm_rsts | PM_RSTS_HADWRQ_SET;
  13406. + }
  13407. + else if(bcm2708_reboot_mode == 'p')
  13408. + {
  13409. + // NOOBS < 1.3 halting
  13410. + pm_rsts = readl(__io_address(PM_RSTS));
  13411. + pm_rsts = PM_PASSWORD | pm_rsts | PM_RSTS_HADWRH_SET;
  13412. + }
  13413. + else
  13414. + {
  13415. + pm_rsts = calc_rsts(reboot_part);
  13416. + }
  13417. +
  13418. + writel(pm_rsts, __io_address(PM_RSTS));
  13419. +
  13420. + /* Setup watchdog for reset */
  13421. + pm_rstc = readl(__io_address(PM_RSTC));
  13422. +
  13423. + pm_wdog = PM_PASSWORD | (timeout & PM_WDOG_TIME_SET); // watchdog timer = timer clock / 16; need password (31:16) + value (11:0)
  13424. + pm_rstc = PM_PASSWORD | (pm_rstc & PM_RSTC_WRCFG_CLR) | PM_RSTC_WRCFG_FULL_RESET;
  13425. +
  13426. + writel(pm_wdog, __io_address(PM_WDOG));
  13427. + writel(pm_rstc, __io_address(PM_RSTC));
  13428. +}
  13429. +
  13430. +/* 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 */
  13431. +static void bcm2709_power_off(void)
  13432. +{
  13433. + extern char bcm2708_reboot_mode;
  13434. + if(bcm2708_reboot_mode == 'q')
  13435. + {
  13436. + // NOOBS < v1.3
  13437. + bcm2709_restart('p', "");
  13438. + }
  13439. + else
  13440. + {
  13441. + /* partition 63 is special code for HALT the bootloader knows not to boot*/
  13442. + reboot_part = 63;
  13443. + /* continue with normal reset mechanism */
  13444. + bcm2709_restart(0, "");
  13445. + }
  13446. +}
  13447. +
  13448. +#ifdef CONFIG_OF
  13449. +static void __init bcm2709_dt_init(void)
  13450. +{
  13451. + int ret;
  13452. +
  13453. + ret = of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL);
  13454. + if (ret) {
  13455. + pr_err("of_platform_populate failed: %d\n", ret);
  13456. + use_dt = 0;
  13457. + }
  13458. +}
  13459. +#else
  13460. +static void __init bcm2709_dt_init(void) { }
  13461. +#endif /* CONFIG_OF */
  13462. +
  13463. +void __init bcm2709_init(void)
  13464. +{
  13465. + int i;
  13466. +
  13467. +#if defined(CONFIG_BCM_VC_CMA)
  13468. + vc_cma_early_init();
  13469. +#endif
  13470. + printk("bcm2709.uart_clock = %d\n", uart_clock);
  13471. + pm_power_off = bcm2709_power_off;
  13472. +
  13473. + bcm2709_init_clocks();
  13474. + if (use_dt)
  13475. + bcm2709_dt_init();
  13476. +
  13477. + bcm_register_device(&bcm2708_dmaman_device);
  13478. + bcm_register_device(&bcm2708_vcio_device);
  13479. +#ifdef CONFIG_BCM2708_GPIO
  13480. + bcm_register_device_dt(&bcm2708_gpio_device);
  13481. +#endif
  13482. +
  13483. +#if defined(CONFIG_PPS_CLIENT_GPIO) || defined(CONFIG_PPS_CLIENT_GPIO_MODULE)
  13484. + if (!use_dt && (pps_gpio_pin >= 0)) {
  13485. + pr_info("bcm2709: GPIO %d setup as pps-gpio device\n", pps_gpio_pin);
  13486. + pps_gpio_info.gpio_pin = pps_gpio_pin;
  13487. + pps_gpio_device.id = pps_gpio_pin;
  13488. + bcm_register_device(&pps_gpio_device);
  13489. + }
  13490. +#endif
  13491. +
  13492. +#if defined(CONFIG_W1_MASTER_GPIO) || defined(CONFIG_W1_MASTER_GPIO_MODULE)
  13493. + w1_gpio_pdata.pin = w1_gpio_pin;
  13494. + w1_gpio_pdata.ext_pullup_enable_pin = w1_gpio_pullup;
  13495. + bcm_register_device_dt(&w1_device);
  13496. +#endif
  13497. +#ifdef SYSTEM_TIMER
  13498. + bcm_register_device(&bcm2708_systemtimer_device);
  13499. +#endif
  13500. + bcm_register_device(&bcm2708_fb_device);
  13501. + bcm_register_device(&bcm2708_usb_device);
  13502. + bcm_register_device(&bcm2708_uart1_device);
  13503. + bcm_register_device(&bcm2708_powerman_device);
  13504. +
  13505. +#ifdef CONFIG_MMC_BCM2835
  13506. + bcm_register_device(&bcm2835_emmc_device);
  13507. +#endif
  13508. + bcm2709_init_led();
  13509. + for (i = 0; i < ARRAY_SIZE(bcm2708_alsa_devices); i++)
  13510. + bcm_register_device(&bcm2708_alsa_devices[i]);
  13511. +
  13512. + bcm_register_device(&bcm2835_hwmon_device);
  13513. + bcm_register_device(&bcm2835_thermal_device);
  13514. +
  13515. + bcm_register_device_dt(&bcm2708_spi_device);
  13516. +
  13517. + if (vc_i2c_override) {
  13518. + bcm_register_device_dt(&bcm2708_bsc0_device);
  13519. + bcm_register_device_dt(&bcm2708_bsc1_device);
  13520. + } else if ((boardrev & 0xffffff) == 0x2 || (boardrev & 0xffffff) == 0x3) {
  13521. + bcm_register_device_dt(&bcm2708_bsc0_device);
  13522. + } else {
  13523. + bcm_register_device_dt(&bcm2708_bsc1_device);
  13524. + }
  13525. +
  13526. +#if defined(CONFIG_SND_BCM2708_SOC_I2S) || defined(CONFIG_SND_BCM2708_SOC_I2S_MODULE)
  13527. + bcm_register_device_dt(&bcm2708_i2s_device);
  13528. +#endif
  13529. +
  13530. +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC_MODULE)
  13531. + bcm_register_device_dt(&snd_hifiberry_dac_device);
  13532. + bcm_register_device_dt(&snd_pcm5102a_codec_device);
  13533. +#endif
  13534. +
  13535. +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS_MODULE)
  13536. + bcm_register_device_dt(&snd_rpi_hifiberry_dacplus_device);
  13537. + i2c_register_board_info_dt(1, snd_pcm512x_hbdacplus_i2c_devices, ARRAY_SIZE(snd_pcm512x_hbdacplus_i2c_devices));
  13538. +#endif
  13539. +
  13540. +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI_MODULE)
  13541. + bcm_register_device_dt(&snd_hifiberry_digi_device);
  13542. + i2c_register_board_info_dt(1, snd_wm8804_i2c_devices, ARRAY_SIZE(snd_wm8804_i2c_devices));
  13543. +#endif
  13544. +
  13545. +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_AMP) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_AMP_MODULE)
  13546. + bcm_register_device_dt(&snd_hifiberry_amp_device);
  13547. + i2c_register_board_info_dt(1, snd_tas5713_i2c_devices, ARRAY_SIZE(snd_tas5713_i2c_devices));
  13548. +#endif
  13549. +
  13550. +#if defined(CONFIG_SND_BCM2708_SOC_RPI_DAC) || defined(CONFIG_SND_BCM2708_SOC_RPI_DAC_MODULE)
  13551. + bcm_register_device_dt(&snd_rpi_dac_device);
  13552. + bcm_register_device_dt(&snd_pcm1794a_codec_device);
  13553. +#endif
  13554. +
  13555. +#if defined(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) || defined(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC_MODULE)
  13556. + bcm_register_device_dt(&snd_rpi_iqaudio_dac_device);
  13557. + i2c_register_board_info_dt(1, snd_pcm512x_i2c_devices, ARRAY_SIZE(snd_pcm512x_i2c_devices));
  13558. +#endif
  13559. +
  13560. +
  13561. + for (i = 0; i < ARRAY_SIZE(amba_devs); i++) {
  13562. + struct amba_device *d = amba_devs[i];
  13563. + amba_device_register(d, &iomem_resource);
  13564. + }
  13565. + system_rev = boardrev;
  13566. + system_serial_low = serial;
  13567. +
  13568. +#ifdef CONFIG_BCM2708_SPIDEV
  13569. + if (!use_dt)
  13570. + spi_register_board_info(bcm2708_spi_devices,
  13571. + ARRAY_SIZE(bcm2708_spi_devices));
  13572. +#endif
  13573. +}
  13574. +
  13575. +#ifdef SYSTEM_TIMER
  13576. +static void timer_set_mode(enum clock_event_mode mode,
  13577. + struct clock_event_device *clk)
  13578. +{
  13579. + switch (mode) {
  13580. + case CLOCK_EVT_MODE_ONESHOT: /* Leave the timer disabled, .set_next_event will enable it */
  13581. + case CLOCK_EVT_MODE_SHUTDOWN:
  13582. + break;
  13583. + case CLOCK_EVT_MODE_PERIODIC:
  13584. +
  13585. + case CLOCK_EVT_MODE_UNUSED:
  13586. + case CLOCK_EVT_MODE_RESUME:
  13587. +
  13588. + default:
  13589. + printk(KERN_ERR "timer_set_mode: unhandled mode:%d\n",
  13590. + (int)mode);
  13591. + break;
  13592. + }
  13593. +
  13594. +}
  13595. +
  13596. +static int timer_set_next_event(unsigned long cycles,
  13597. + struct clock_event_device *unused)
  13598. +{
  13599. + unsigned long stc;
  13600. + do {
  13601. + stc = readl(__io_address(ST_BASE + 0x04));
  13602. + /* We could take a FIQ here, which may push ST above STC3 */
  13603. + writel(stc + cycles, __io_address(ST_BASE + 0x18));
  13604. + } while ((signed long) cycles >= 0 &&
  13605. + (signed long) (readl(__io_address(ST_BASE + 0x04)) - stc)
  13606. + >= (signed long) cycles);
  13607. + return 0;
  13608. +}
  13609. +
  13610. +static struct clock_event_device timer0_clockevent = {
  13611. + .name = "timer0",
  13612. + .shift = 32,
  13613. + .features = CLOCK_EVT_FEAT_ONESHOT,
  13614. + .set_mode = timer_set_mode,
  13615. + .set_next_event = timer_set_next_event,
  13616. +};
  13617. +
  13618. +/*
  13619. + * IRQ handler for the timer
  13620. + */
  13621. +static irqreturn_t bcm2709_timer_interrupt(int irq, void *dev_id)
  13622. +{
  13623. + struct clock_event_device *evt = &timer0_clockevent;
  13624. +
  13625. + writel(1 << 3, __io_address(ST_BASE + 0x00)); /* stcs clear timer int */
  13626. +
  13627. + evt->event_handler(evt);
  13628. +
  13629. + return IRQ_HANDLED;
  13630. +}
  13631. +
  13632. +static struct irqaction bcm2709_timer_irq = {
  13633. + .name = "BCM2709 Timer Tick",
  13634. + .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
  13635. + .handler = bcm2709_timer_interrupt,
  13636. +};
  13637. +
  13638. +/*
  13639. + * Set up timer interrupt, and return the current time in seconds.
  13640. + */
  13641. +
  13642. +static struct delay_timer bcm2709_delay_timer = {
  13643. + .read_current_timer = bcm2709_read_current_timer,
  13644. + .freq = STC_FREQ_HZ,
  13645. +};
  13646. +
  13647. +static void __init bcm2709_timer_init(void)
  13648. +{
  13649. + /* init high res timer */
  13650. + bcm2709_clocksource_init();
  13651. +
  13652. + /*
  13653. + * Make irqs happen for the system timer
  13654. + */
  13655. + setup_irq(IRQ_TIMER3, &bcm2708_timer_irq);
  13656. +
  13657. + sched_clock_register(bcm2709_read_sched_clock, 32, STC_FREQ_HZ);
  13658. +
  13659. + timer0_clockevent.mult =
  13660. + div_sc(STC_FREQ_HZ, NSEC_PER_SEC, timer0_clockevent.shift);
  13661. + timer0_clockevent.max_delta_ns =
  13662. + clockevent_delta2ns(0xffffffff, &timer0_clockevent);
  13663. + timer0_clockevent.min_delta_ns =
  13664. + clockevent_delta2ns(0xf, &timer0_clockevent);
  13665. +
  13666. + timer0_clockevent.cpumask = cpumask_of(0);
  13667. + clockevents_register_device(&timer0_clockevent);
  13668. +
  13669. + register_current_timer_delay(&bcm2708_delay_timer);
  13670. +}
  13671. +
  13672. +#else
  13673. +
  13674. +static void __init bcm2709_timer_init(void)
  13675. +{
  13676. + extern void dc4_arch_timer_init(void);
  13677. + // timer control
  13678. + writel(0, __io_address(ARM_LOCAL_CONTROL));
  13679. + // timer pre_scaler
  13680. + writel(0x80000000, __io_address(ARM_LOCAL_PRESCALER)); // 19.2MHz
  13681. + //writel(0x06AAAAAB, __io_address(ARM_LOCAL_PRESCALER)); // 1MHz
  13682. +
  13683. + if (use_dt)
  13684. + {
  13685. + of_clk_init(NULL);
  13686. + clocksource_of_init();
  13687. + }
  13688. + else
  13689. + dc4_arch_timer_init();
  13690. +}
  13691. +
  13692. +#endif
  13693. +
  13694. +#if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE)
  13695. +#include <linux/leds.h>
  13696. +
  13697. +static struct gpio_led bcm2709_leds[] = {
  13698. + [0] = {
  13699. + .gpio = 16,
  13700. + .name = "led0",
  13701. + .default_trigger = "mmc0",
  13702. + .active_low = 1,
  13703. + },
  13704. +};
  13705. +
  13706. +static struct gpio_led_platform_data bcm2709_led_pdata = {
  13707. + .num_leds = ARRAY_SIZE(bcm2709_leds),
  13708. + .leds = bcm2709_leds,
  13709. +};
  13710. +
  13711. +static struct platform_device bcm2709_led_device = {
  13712. + .name = "leds-gpio",
  13713. + .id = -1,
  13714. + .dev = {
  13715. + .platform_data = &bcm2709_led_pdata,
  13716. + },
  13717. +};
  13718. +
  13719. +static void __init bcm2709_init_led(void)
  13720. +{
  13721. + bcm2709_leds[0].gpio = disk_led_gpio;
  13722. + bcm2709_leds[0].active_low = disk_led_active_low;
  13723. + bcm_register_device_dt(&bcm2709_led_device);
  13724. +}
  13725. +#else
  13726. +static inline void bcm2709_init_led(void)
  13727. +{
  13728. +}
  13729. +#endif
  13730. +
  13731. +void __init bcm2709_init_early(void)
  13732. +{
  13733. + /*
  13734. + * Some devices allocate their coherent buffers from atomic
  13735. + * context. Increase size of atomic coherent pool to make sure such
  13736. + * the allocations won't fail.
  13737. + */
  13738. + init_dma_coherent_pool_size(SZ_4M);
  13739. +
  13740. +#ifdef CONFIG_OF
  13741. + if (of_allnodes)
  13742. + use_dt = 1;
  13743. +#endif
  13744. +}
  13745. +
  13746. +static void __init board_reserve(void)
  13747. +{
  13748. +#if defined(CONFIG_BCM_VC_CMA)
  13749. + vc_cma_reserve();
  13750. +#endif
  13751. +}
  13752. +
  13753. +
  13754. +#include <linux/smp.h>
  13755. +
  13756. +#include <mach/hardware.h>
  13757. +#include <asm/cacheflush.h>
  13758. +#include <asm/smp_plat.h>
  13759. +int dc4=0;
  13760. +//void dc4_log(unsigned x) { if (dc4) writel((x), __io_address(ST_BASE+10 + raw_smp_processor_id()*4)); }
  13761. +void dc4_log_dead(unsigned x) { if (dc4) writel((readl(__io_address(ST_BASE+0x10 + raw_smp_processor_id()*4)) & 0xffff) | ((x)<<16), __io_address(ST_BASE+0x10 + raw_smp_processor_id()*4)); }
  13762. +
  13763. +static void bcm2835_send_doorbell(const struct cpumask *mask, unsigned int irq)
  13764. +{
  13765. + int cpu;
  13766. + /*
  13767. + * Ensure that stores to Normal memory are visible to the
  13768. + * other CPUs before issuing the IPI.
  13769. + */
  13770. + dsb();
  13771. +
  13772. + /* Convert our logical CPU mask into a physical one. */
  13773. + for_each_cpu(cpu, mask)
  13774. + {
  13775. + /* submit softirq */
  13776. + writel(1<<irq, __io_address(ARM_LOCAL_MAILBOX0_SET0 + 0x10 * MPIDR_AFFINITY_LEVEL(cpu_logical_map(cpu), 0)));
  13777. + }
  13778. +}
  13779. +
  13780. +void __init bcm2709_smp_init_cpus(void)
  13781. +{
  13782. + void secondary_startup(void);
  13783. + unsigned int i, ncores;
  13784. +
  13785. + ncores = 4; // xxx scu_get_core_count(NULL);
  13786. + printk("[%s] enter (%x->%x)\n", __FUNCTION__, (unsigned)virt_to_phys((void *)secondary_startup), (unsigned)__io_address(ST_BASE + 0x10));
  13787. + printk("[%s] ncores=%d\n", __FUNCTION__, ncores);
  13788. +
  13789. + for (i = 0; i < ncores; i++) {
  13790. + set_cpu_possible(i, true);
  13791. + /* enable IRQ (not FIQ) */
  13792. + writel(0x1, __io_address(ARM_LOCAL_MAILBOX_INT_CONTROL0 + 0x4 * i));
  13793. + //writel(0xf, __io_address(ARM_LOCAL_TIMER_INT_CONTROL0 + 0x4 * i));
  13794. + }
  13795. + set_smp_cross_call(bcm2835_send_doorbell);
  13796. +}
  13797. +
  13798. +/*
  13799. + * for arch/arm/kernel/smp.c:smp_prepare_cpus(unsigned int max_cpus)
  13800. + */
  13801. +void __init bcm2709_smp_prepare_cpus(unsigned int max_cpus)
  13802. +{
  13803. + //void __iomem *scu_base;
  13804. +
  13805. + printk("[%s] enter\n", __FUNCTION__);
  13806. + //scu_base = scu_base_addr();
  13807. + //scu_enable(scu_base);
  13808. +}
  13809. +
  13810. +/*
  13811. + * for linux/arch/arm/kernel/smp.c:secondary_start_kernel(void)
  13812. + */
  13813. +void __cpuinit bcm2709_secondary_init(unsigned int cpu)
  13814. +{
  13815. + printk("[%s] enter cpu:%d\n", __FUNCTION__, cpu);
  13816. + //gic_secondary_init(0);
  13817. +}
  13818. +
  13819. +/*
  13820. + * for linux/arch/arm/kernel/smp.c:__cpu_up(..)
  13821. + */
  13822. +int __cpuinit bcm2709_boot_secondary(unsigned int cpu, struct task_struct *idle)
  13823. +{
  13824. + void secondary_startup(void);
  13825. + void *mbox_set = __io_address(ARM_LOCAL_MAILBOX3_SET0 + 0x10 * MPIDR_AFFINITY_LEVEL(cpu_logical_map(cpu), 0));
  13826. + void *mbox_clr = __io_address(ARM_LOCAL_MAILBOX3_CLR0 + 0x10 * MPIDR_AFFINITY_LEVEL(cpu_logical_map(cpu), 0));
  13827. + unsigned secondary_boot = (unsigned)virt_to_phys((void *)secondary_startup);
  13828. + int timeout=20;
  13829. + unsigned t = -1;
  13830. + //printk("[%s] enter cpu:%d (%x->%p) %x\n", __FUNCTION__, cpu, secondary_boot, wake, readl(wake));
  13831. +
  13832. + dsb();
  13833. + BUG_ON(readl(mbox_clr) != 0);
  13834. + writel(secondary_boot, mbox_set);
  13835. +
  13836. + while (--timeout > 0) {
  13837. + t = readl(mbox_clr);
  13838. + if (t == 0) break;
  13839. + cpu_relax();
  13840. + }
  13841. + if (timeout==0)
  13842. + printk("[%s] cpu:%d failed to start (%x)\n", __FUNCTION__, cpu, t);
  13843. + else
  13844. + printk("[%s] cpu:%d started (%x) %d\n", __FUNCTION__, cpu, t, timeout);
  13845. +
  13846. + return 0;
  13847. +}
  13848. +
  13849. +
  13850. +struct smp_operations bcm2709_smp_ops __initdata = {
  13851. + .smp_init_cpus = bcm2709_smp_init_cpus,
  13852. + .smp_prepare_cpus = bcm2709_smp_prepare_cpus,
  13853. + .smp_secondary_init = bcm2709_secondary_init,
  13854. + .smp_boot_secondary = bcm2709_boot_secondary,
  13855. +};
  13856. +
  13857. +static const char * const bcm2709_compat[] = {
  13858. + "brcm,bcm2709",
  13859. + "brcm,bcm2708", /* Could use bcm2708 in a pinch */
  13860. + NULL
  13861. +};
  13862. +
  13863. +MACHINE_START(BCM2709, "BCM2709")
  13864. + /* Maintainer: Broadcom Europe Ltd. */
  13865. + .smp = smp_ops(bcm2709_smp_ops),
  13866. + .map_io = bcm2709_map_io,
  13867. + .init_irq = bcm2709_init_irq,
  13868. + .init_time = bcm2709_timer_init,
  13869. + .init_machine = bcm2709_init,
  13870. + .init_early = bcm2709_init_early,
  13871. + .reserve = board_reserve,
  13872. + .restart = bcm2709_restart,
  13873. + .dt_compat = bcm2709_compat,
  13874. +MACHINE_END
  13875. +
  13876. +MACHINE_START(BCM2708, "BCM2709")
  13877. + /* Maintainer: Broadcom Europe Ltd. */
  13878. + .smp = smp_ops(bcm2709_smp_ops),
  13879. + .map_io = bcm2709_map_io,
  13880. + .init_irq = bcm2709_init_irq,
  13881. + .init_time = bcm2709_timer_init,
  13882. + .init_machine = bcm2709_init,
  13883. + .init_early = bcm2709_init_early,
  13884. + .reserve = board_reserve,
  13885. + .restart = bcm2709_restart,
  13886. + .dt_compat = bcm2709_compat,
  13887. +MACHINE_END
  13888. +
  13889. +module_param(boardrev, uint, 0644);
  13890. +module_param(serial, uint, 0644);
  13891. +module_param(uart_clock, uint, 0644);
  13892. +module_param(disk_led_gpio, uint, 0644);
  13893. +module_param(disk_led_active_low, uint, 0644);
  13894. +module_param(reboot_part, uint, 0644);
  13895. +module_param(w1_gpio_pin, uint, 0644);
  13896. +module_param(w1_gpio_pullup, uint, 0644);
  13897. +module_param(pps_gpio_pin, int, 0644);
  13898. +MODULE_PARM_DESC(pps_gpio_pin, "Set GPIO pin to reserve for PPS");
  13899. +module_param(vc_i2c_override, bool, 0644);
  13900. +MODULE_PARM_DESC(vc_i2c_override, "Allow the use of VC's I2C peripheral.");
  13901. diff -Nur linux-3.18.8/arch/arm/mach-bcm2709/bcm2709.h linux-rpi/arch/arm/mach-bcm2709/bcm2709.h
  13902. --- linux-3.18.8/arch/arm/mach-bcm2709/bcm2709.h 1970-01-01 01:00:00.000000000 +0100
  13903. +++ linux-rpi/arch/arm/mach-bcm2709/bcm2709.h 2015-03-05 14:40:11.153715839 +0100
  13904. @@ -0,0 +1,49 @@
  13905. +/*
  13906. + * linux/arch/arm/mach-bcm2708/bcm2708.h
  13907. + *
  13908. + * BCM2708 machine support header
  13909. + *
  13910. + * Copyright (C) 2010 Broadcom
  13911. + *
  13912. + * This program is free software; you can redistribute it and/or modify
  13913. + * it under the terms of the GNU General Public License as published by
  13914. + * the Free Software Foundation; either version 2 of the License, or
  13915. + * (at your option) any later version.
  13916. + *
  13917. + * This program is distributed in the hope that it will be useful,
  13918. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13919. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13920. + * GNU General Public License for more details.
  13921. + *
  13922. + * You should have received a copy of the GNU General Public License
  13923. + * along with this program; if not, write to the Free Software
  13924. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  13925. + */
  13926. +
  13927. +#ifndef __BCM2708_BCM2708_H
  13928. +#define __BCM2708_BCM2708_H
  13929. +
  13930. +#include <linux/amba/bus.h>
  13931. +
  13932. +extern void __init bcm2708_init(void);
  13933. +extern void __init bcm2708_init_irq(void);
  13934. +extern void __init bcm2708_map_io(void);
  13935. +extern struct sys_timer bcm2708_timer;
  13936. +extern unsigned int mmc_status(struct device *dev);
  13937. +
  13938. +#define AMBA_DEVICE(name, busid, base, plat) \
  13939. +static struct amba_device name##_device = { \
  13940. + .dev = { \
  13941. + .coherent_dma_mask = ~0, \
  13942. + .init_name = busid, \
  13943. + .platform_data = plat, \
  13944. + }, \
  13945. + .res = { \
  13946. + .start = base##_BASE, \
  13947. + .end = (base##_BASE) + SZ_4K - 1,\
  13948. + .flags = IORESOURCE_MEM, \
  13949. + }, \
  13950. + .irq = base##_IRQ, \
  13951. +}
  13952. +
  13953. +#endif
  13954. diff -Nur linux-3.18.8/arch/arm/mach-bcm2709/clock.c linux-rpi/arch/arm/mach-bcm2709/clock.c
  13955. --- linux-3.18.8/arch/arm/mach-bcm2709/clock.c 1970-01-01 01:00:00.000000000 +0100
  13956. +++ linux-rpi/arch/arm/mach-bcm2709/clock.c 2015-03-05 14:40:11.153715839 +0100
  13957. @@ -0,0 +1,61 @@
  13958. +/*
  13959. + * linux/arch/arm/mach-bcm2708/clock.c
  13960. + *
  13961. + * Copyright (C) 2010 Broadcom
  13962. + *
  13963. + * This program is free software; you can redistribute it and/or modify
  13964. + * it under the terms of the GNU General Public License as published by
  13965. + * the Free Software Foundation; either version 2 of the License, or
  13966. + * (at your option) any later version.
  13967. + *
  13968. + * This program is distributed in the hope that it will be useful,
  13969. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13970. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13971. + * GNU General Public License for more details.
  13972. + *
  13973. + * You should have received a copy of the GNU General Public License
  13974. + * along with this program; if not, write to the Free Software
  13975. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  13976. + */
  13977. +#include <linux/module.h>
  13978. +#include <linux/kernel.h>
  13979. +#include <linux/device.h>
  13980. +#include <linux/list.h>
  13981. +#include <linux/errno.h>
  13982. +#include <linux/err.h>
  13983. +#include <linux/string.h>
  13984. +#include <linux/clk.h>
  13985. +#include <linux/mutex.h>
  13986. +
  13987. +#include <asm/clkdev.h>
  13988. +
  13989. +#include "clock.h"
  13990. +
  13991. +int clk_enable(struct clk *clk)
  13992. +{
  13993. + return 0;
  13994. +}
  13995. +EXPORT_SYMBOL(clk_enable);
  13996. +
  13997. +void clk_disable(struct clk *clk)
  13998. +{
  13999. +}
  14000. +EXPORT_SYMBOL(clk_disable);
  14001. +
  14002. +unsigned long clk_get_rate(struct clk *clk)
  14003. +{
  14004. + return clk->rate;
  14005. +}
  14006. +EXPORT_SYMBOL(clk_get_rate);
  14007. +
  14008. +long clk_round_rate(struct clk *clk, unsigned long rate)
  14009. +{
  14010. + return clk->rate;
  14011. +}
  14012. +EXPORT_SYMBOL(clk_round_rate);
  14013. +
  14014. +int clk_set_rate(struct clk *clk, unsigned long rate)
  14015. +{
  14016. + return -EIO;
  14017. +}
  14018. +EXPORT_SYMBOL(clk_set_rate);
  14019. diff -Nur linux-3.18.8/arch/arm/mach-bcm2709/clock.h linux-rpi/arch/arm/mach-bcm2709/clock.h
  14020. --- linux-3.18.8/arch/arm/mach-bcm2709/clock.h 1970-01-01 01:00:00.000000000 +0100
  14021. +++ linux-rpi/arch/arm/mach-bcm2709/clock.h 2015-03-05 14:40:11.153715839 +0100
  14022. @@ -0,0 +1,24 @@
  14023. +/*
  14024. + * linux/arch/arm/mach-bcm2708/clock.h
  14025. + *
  14026. + * Copyright (C) 2010 Broadcom
  14027. + *
  14028. + * This program is free software; you can redistribute it and/or modify
  14029. + * it under the terms of the GNU General Public License as published by
  14030. + * the Free Software Foundation; either version 2 of the License, or
  14031. + * (at your option) any later version.
  14032. + *
  14033. + * This program is distributed in the hope that it will be useful,
  14034. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14035. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14036. + * GNU General Public License for more details.
  14037. + *
  14038. + * You should have received a copy of the GNU General Public License
  14039. + * along with this program; if not, write to the Free Software
  14040. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  14041. + */
  14042. +struct module;
  14043. +
  14044. +struct clk {
  14045. + unsigned long rate;
  14046. +};
  14047. diff -Nur linux-3.18.8/arch/arm/mach-bcm2709/delay.S linux-rpi/arch/arm/mach-bcm2709/delay.S
  14048. --- linux-3.18.8/arch/arm/mach-bcm2709/delay.S 1970-01-01 01:00:00.000000000 +0100
  14049. +++ linux-rpi/arch/arm/mach-bcm2709/delay.S 2015-03-05 14:40:11.153715839 +0100
  14050. @@ -0,0 +1,21 @@
  14051. +/*
  14052. + * linux/arch/arm/lib/delay.S
  14053. + *
  14054. + * Copyright (C) 1995, 1996 Russell King
  14055. + *
  14056. + * This program is free software; you can redistribute it and/or modify
  14057. + * it under the terms of the GNU General Public License version 2 as
  14058. + * published by the Free Software Foundation.
  14059. + */
  14060. +#include <linux/linkage.h>
  14061. +#include <asm/assembler.h>
  14062. +#include <asm/param.h>
  14063. +
  14064. + .text
  14065. +.align 3 @ 8 byte alignment seems to be needed to avoid fetching stalls
  14066. +@ Delay routine
  14067. +ENTRY(bcm2708_delay)
  14068. + subs r0, r0, #1
  14069. + bhi bcm2708_delay
  14070. + mov pc, lr
  14071. +ENDPROC(bcm2708_delay)
  14072. diff -Nur linux-3.18.8/arch/arm/mach-bcm2709/dma.c linux-rpi/arch/arm/mach-bcm2709/dma.c
  14073. --- linux-3.18.8/arch/arm/mach-bcm2709/dma.c 1970-01-01 01:00:00.000000000 +0100
  14074. +++ linux-rpi/arch/arm/mach-bcm2709/dma.c 2015-03-05 14:40:11.153715839 +0100
  14075. @@ -0,0 +1,409 @@
  14076. +/*
  14077. + * linux/arch/arm/mach-bcm2708/dma.c
  14078. + *
  14079. + * Copyright (C) 2010 Broadcom
  14080. + *
  14081. + * This program is free software; you can redistribute it and/or modify
  14082. + * it under the terms of the GNU General Public License version 2 as
  14083. + * published by the Free Software Foundation.
  14084. + */
  14085. +
  14086. +#include <linux/slab.h>
  14087. +#include <linux/device.h>
  14088. +#include <linux/platform_device.h>
  14089. +#include <linux/module.h>
  14090. +#include <linux/scatterlist.h>
  14091. +
  14092. +#include <mach/dma.h>
  14093. +#include <mach/irqs.h>
  14094. +
  14095. +/*****************************************************************************\
  14096. + * *
  14097. + * Configuration *
  14098. + * *
  14099. +\*****************************************************************************/
  14100. +
  14101. +#define CACHE_LINE_MASK 31
  14102. +#define DRIVER_NAME BCM_DMAMAN_DRIVER_NAME
  14103. +#define DEFAULT_DMACHAN_BITMAP 0x10 /* channel 4 only */
  14104. +
  14105. +/* valid only for channels 0 - 14, 15 has its own base address */
  14106. +#define BCM2708_DMA_CHAN(n) ((n)<<8) /* base address */
  14107. +#define BCM2708_DMA_CHANIO(dma_base, n) \
  14108. + ((void __iomem *)((char *)(dma_base)+BCM2708_DMA_CHAN(n)))
  14109. +
  14110. +
  14111. +/*****************************************************************************\
  14112. + * *
  14113. + * DMA Auxilliary Functions *
  14114. + * *
  14115. +\*****************************************************************************/
  14116. +
  14117. +/* A DMA buffer on an arbitrary boundary may separate a cache line into a
  14118. + section inside the DMA buffer and another section outside it.
  14119. + Even if we flush DMA buffers from the cache there is always the chance that
  14120. + during a DMA someone will access the part of a cache line that is outside
  14121. + the DMA buffer - which will then bring in unwelcome data.
  14122. + Without being able to dictate our own buffer pools we must insist that
  14123. + DMA buffers consist of a whole number of cache lines.
  14124. +*/
  14125. +
  14126. +extern int
  14127. +bcm_sg_suitable_for_dma(struct scatterlist *sg_ptr, int sg_len)
  14128. +{
  14129. + int i;
  14130. +
  14131. + for (i = 0; i < sg_len; i++) {
  14132. + if (sg_ptr[i].offset & CACHE_LINE_MASK ||
  14133. + sg_ptr[i].length & CACHE_LINE_MASK)
  14134. + return 0;
  14135. + }
  14136. +
  14137. + return 1;
  14138. +}
  14139. +EXPORT_SYMBOL_GPL(bcm_sg_suitable_for_dma);
  14140. +
  14141. +extern void
  14142. +bcm_dma_start(void __iomem *dma_chan_base, dma_addr_t control_block)
  14143. +{
  14144. + dsb(); /* ARM data synchronization (push) operation */
  14145. +
  14146. + writel(control_block, dma_chan_base + BCM2708_DMA_ADDR);
  14147. + writel(BCM2708_DMA_ACTIVE, dma_chan_base + BCM2708_DMA_CS);
  14148. +}
  14149. +
  14150. +extern void bcm_dma_wait_idle(void __iomem *dma_chan_base)
  14151. +{
  14152. + dsb();
  14153. +
  14154. + /* ugly busy wait only option for now */
  14155. + while (readl(dma_chan_base + BCM2708_DMA_CS) & BCM2708_DMA_ACTIVE)
  14156. + cpu_relax();
  14157. +}
  14158. +
  14159. +EXPORT_SYMBOL_GPL(bcm_dma_start);
  14160. +
  14161. +extern bool bcm_dma_is_busy(void __iomem *dma_chan_base)
  14162. +{
  14163. + dsb();
  14164. +
  14165. + return readl(dma_chan_base + BCM2708_DMA_CS) & BCM2708_DMA_ACTIVE;
  14166. +}
  14167. +EXPORT_SYMBOL_GPL(bcm_dma_is_busy);
  14168. +
  14169. +/* Complete an ongoing DMA (assuming its results are to be ignored)
  14170. + Does nothing if there is no DMA in progress.
  14171. + This routine waits for the current AXI transfer to complete before
  14172. + terminating the current DMA. If the current transfer is hung on a DREQ used
  14173. + by an uncooperative peripheral the AXI transfer may never complete. In this
  14174. + case the routine times out and return a non-zero error code.
  14175. + Use of this routine doesn't guarantee that the ongoing or aborted DMA
  14176. + does not produce an interrupt.
  14177. +*/
  14178. +extern int
  14179. +bcm_dma_abort(void __iomem *dma_chan_base)
  14180. +{
  14181. + unsigned long int cs;
  14182. + int rc = 0;
  14183. +
  14184. + cs = readl(dma_chan_base + BCM2708_DMA_CS);
  14185. +
  14186. + if (BCM2708_DMA_ACTIVE & cs) {
  14187. + long int timeout = 10000;
  14188. +
  14189. + /* write 0 to the active bit - pause the DMA */
  14190. + writel(0, dma_chan_base + BCM2708_DMA_CS);
  14191. +
  14192. + /* wait for any current AXI transfer to complete */
  14193. + while (0 != (cs & BCM2708_DMA_ISPAUSED) && --timeout >= 0)
  14194. + cs = readl(dma_chan_base + BCM2708_DMA_CS);
  14195. +
  14196. + if (0 != (cs & BCM2708_DMA_ISPAUSED)) {
  14197. + /* we'll un-pause when we set of our next DMA */
  14198. + rc = -ETIMEDOUT;
  14199. +
  14200. + } else if (BCM2708_DMA_ACTIVE & cs) {
  14201. + /* terminate the control block chain */
  14202. + writel(0, dma_chan_base + BCM2708_DMA_NEXTCB);
  14203. +
  14204. + /* abort the whole DMA */
  14205. + writel(BCM2708_DMA_ABORT | BCM2708_DMA_ACTIVE,
  14206. + dma_chan_base + BCM2708_DMA_CS);
  14207. + }
  14208. + }
  14209. +
  14210. + return rc;
  14211. +}
  14212. +EXPORT_SYMBOL_GPL(bcm_dma_abort);
  14213. +
  14214. +
  14215. +/***************************************************************************** \
  14216. + * *
  14217. + * DMA Manager Device Methods *
  14218. + * *
  14219. +\*****************************************************************************/
  14220. +
  14221. +struct vc_dmaman {
  14222. + void __iomem *dma_base;
  14223. + u32 chan_available; /* bitmap of available channels */
  14224. + u32 has_feature[BCM_DMA_FEATURE_COUNT]; /* bitmap of feature presence */
  14225. +};
  14226. +
  14227. +static void vc_dmaman_init(struct vc_dmaman *dmaman, void __iomem *dma_base,
  14228. + u32 chans_available)
  14229. +{
  14230. + dmaman->dma_base = dma_base;
  14231. + dmaman->chan_available = chans_available;
  14232. + dmaman->has_feature[BCM_DMA_FEATURE_FAST_ORD] = 0x0c; /* chans 2 & 3 */
  14233. + dmaman->has_feature[BCM_DMA_FEATURE_BULK_ORD] = 0x01; /* chan 0 */
  14234. + dmaman->has_feature[BCM_DMA_FEATURE_NORMAL_ORD] = 0xfe; /* chans 1 to 7 */
  14235. + dmaman->has_feature[BCM_DMA_FEATURE_LITE_ORD] = 0x7f00; /* chans 8 to 14 */
  14236. +}
  14237. +
  14238. +static int vc_dmaman_chan_alloc(struct vc_dmaman *dmaman,
  14239. + unsigned preferred_feature_set)
  14240. +{
  14241. + u32 chans;
  14242. + int feature;
  14243. +
  14244. + chans = dmaman->chan_available;
  14245. + for (feature = 0; feature < BCM_DMA_FEATURE_COUNT; feature++)
  14246. + /* select the subset of available channels with the desired
  14247. + feature so long as some of the candidate channels have that
  14248. + feature */
  14249. + if ((preferred_feature_set & (1 << feature)) &&
  14250. + (chans & dmaman->has_feature[feature]))
  14251. + chans &= dmaman->has_feature[feature];
  14252. +
  14253. + if (chans) {
  14254. + int chan = 0;
  14255. + /* return the ordinal of the first channel in the bitmap */
  14256. + while (chans != 0 && (chans & 1) == 0) {
  14257. + chans >>= 1;
  14258. + chan++;
  14259. + }
  14260. + /* claim the channel */
  14261. + dmaman->chan_available &= ~(1 << chan);
  14262. + return chan;
  14263. + } else
  14264. + return -ENOMEM;
  14265. +}
  14266. +
  14267. +static int vc_dmaman_chan_free(struct vc_dmaman *dmaman, int chan)
  14268. +{
  14269. + if (chan < 0)
  14270. + return -EINVAL;
  14271. + else if ((1 << chan) & dmaman->chan_available)
  14272. + return -EIDRM;
  14273. + else {
  14274. + dmaman->chan_available |= (1 << chan);
  14275. + return 0;
  14276. + }
  14277. +}
  14278. +
  14279. +/*****************************************************************************\
  14280. + * *
  14281. + * DMA IRQs *
  14282. + * *
  14283. +\*****************************************************************************/
  14284. +
  14285. +static unsigned char bcm_dma_irqs[] = {
  14286. + IRQ_DMA0,
  14287. + IRQ_DMA1,
  14288. + IRQ_DMA2,
  14289. + IRQ_DMA3,
  14290. + IRQ_DMA4,
  14291. + IRQ_DMA5,
  14292. + IRQ_DMA6,
  14293. + IRQ_DMA7,
  14294. + IRQ_DMA8,
  14295. + IRQ_DMA9,
  14296. + IRQ_DMA10,
  14297. + IRQ_DMA11,
  14298. + IRQ_DMA12
  14299. +};
  14300. +
  14301. +
  14302. +/***************************************************************************** \
  14303. + * *
  14304. + * DMA Manager Monitor *
  14305. + * *
  14306. +\*****************************************************************************/
  14307. +
  14308. +static struct device *dmaman_dev; /* we assume there's only one! */
  14309. +
  14310. +extern int bcm_dma_chan_alloc(unsigned preferred_feature_set,
  14311. + void __iomem **out_dma_base, int *out_dma_irq)
  14312. +{
  14313. + if (!dmaman_dev)
  14314. + return -ENODEV;
  14315. + else {
  14316. + struct vc_dmaman *dmaman = dev_get_drvdata(dmaman_dev);
  14317. + int rc;
  14318. +
  14319. + device_lock(dmaman_dev);
  14320. + rc = vc_dmaman_chan_alloc(dmaman, preferred_feature_set);
  14321. + if (rc >= 0) {
  14322. + *out_dma_base = BCM2708_DMA_CHANIO(dmaman->dma_base,
  14323. + rc);
  14324. + *out_dma_irq = bcm_dma_irqs[rc];
  14325. + }
  14326. + device_unlock(dmaman_dev);
  14327. +
  14328. + return rc;
  14329. + }
  14330. +}
  14331. +EXPORT_SYMBOL_GPL(bcm_dma_chan_alloc);
  14332. +
  14333. +extern int bcm_dma_chan_free(int channel)
  14334. +{
  14335. + if (dmaman_dev) {
  14336. + struct vc_dmaman *dmaman = dev_get_drvdata(dmaman_dev);
  14337. + int rc;
  14338. +
  14339. + device_lock(dmaman_dev);
  14340. + rc = vc_dmaman_chan_free(dmaman, channel);
  14341. + device_unlock(dmaman_dev);
  14342. +
  14343. + return rc;
  14344. + } else
  14345. + return -ENODEV;
  14346. +}
  14347. +EXPORT_SYMBOL_GPL(bcm_dma_chan_free);
  14348. +
  14349. +static int dev_dmaman_register(const char *dev_name, struct device *dev)
  14350. +{
  14351. + int rc = dmaman_dev ? -EINVAL : 0;
  14352. + dmaman_dev = dev;
  14353. + return rc;
  14354. +}
  14355. +
  14356. +static void dev_dmaman_deregister(const char *dev_name, struct device *dev)
  14357. +{
  14358. + dmaman_dev = NULL;
  14359. +}
  14360. +
  14361. +/*****************************************************************************\
  14362. + * *
  14363. + * DMA Device *
  14364. + * *
  14365. +\*****************************************************************************/
  14366. +
  14367. +static int dmachans = -1; /* module parameter */
  14368. +
  14369. +static int bcm_dmaman_probe(struct platform_device *pdev)
  14370. +{
  14371. + int ret = 0;
  14372. + struct vc_dmaman *dmaman;
  14373. + struct resource *dma_res = NULL;
  14374. + void __iomem *dma_base = NULL;
  14375. + int have_dma_region = 0;
  14376. +
  14377. + dmaman = kzalloc(sizeof(*dmaman), GFP_KERNEL);
  14378. + if (NULL == dmaman) {
  14379. + printk(KERN_ERR DRIVER_NAME ": failed to allocate "
  14380. + "DMA management memory\n");
  14381. + ret = -ENOMEM;
  14382. + } else {
  14383. +
  14384. + dma_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  14385. + if (dma_res == NULL) {
  14386. + printk(KERN_ERR DRIVER_NAME ": failed to obtain memory "
  14387. + "resource\n");
  14388. + ret = -ENODEV;
  14389. + } else if (!request_mem_region(dma_res->start,
  14390. + resource_size(dma_res),
  14391. + DRIVER_NAME)) {
  14392. + dev_err(&pdev->dev, "cannot obtain DMA region\n");
  14393. + ret = -EBUSY;
  14394. + } else {
  14395. + have_dma_region = 1;
  14396. + dma_base = ioremap(dma_res->start,
  14397. + resource_size(dma_res));
  14398. + if (!dma_base) {
  14399. + dev_err(&pdev->dev, "cannot map DMA region\n");
  14400. + ret = -ENOMEM;
  14401. + } else {
  14402. + /* use module parameter if one was provided */
  14403. + if (dmachans > 0)
  14404. + vc_dmaman_init(dmaman, dma_base,
  14405. + dmachans);
  14406. + else
  14407. + vc_dmaman_init(dmaman, dma_base,
  14408. + DEFAULT_DMACHAN_BITMAP);
  14409. +
  14410. + platform_set_drvdata(pdev, dmaman);
  14411. + dev_dmaman_register(DRIVER_NAME, &pdev->dev);
  14412. +
  14413. + printk(KERN_INFO DRIVER_NAME ": DMA manager "
  14414. + "at %p\n", dma_base);
  14415. + }
  14416. + }
  14417. + }
  14418. + if (ret != 0) {
  14419. + if (dma_base)
  14420. + iounmap(dma_base);
  14421. + if (dma_res && have_dma_region)
  14422. + release_mem_region(dma_res->start,
  14423. + resource_size(dma_res));
  14424. + if (dmaman)
  14425. + kfree(dmaman);
  14426. + }
  14427. + return ret;
  14428. +}
  14429. +
  14430. +static int bcm_dmaman_remove(struct platform_device *pdev)
  14431. +{
  14432. + struct vc_dmaman *dmaman = platform_get_drvdata(pdev);
  14433. +
  14434. + platform_set_drvdata(pdev, NULL);
  14435. + dev_dmaman_deregister(DRIVER_NAME, &pdev->dev);
  14436. + kfree(dmaman);
  14437. +
  14438. + return 0;
  14439. +}
  14440. +
  14441. +static struct platform_driver bcm_dmaman_driver = {
  14442. + .probe = bcm_dmaman_probe,
  14443. + .remove = bcm_dmaman_remove,
  14444. +
  14445. + .driver = {
  14446. + .name = DRIVER_NAME,
  14447. + .owner = THIS_MODULE,
  14448. + },
  14449. +};
  14450. +
  14451. +/*****************************************************************************\
  14452. + * *
  14453. + * Driver init/exit *
  14454. + * *
  14455. +\*****************************************************************************/
  14456. +
  14457. +static int __init bcm_dmaman_drv_init(void)
  14458. +{
  14459. + int ret;
  14460. +
  14461. + ret = platform_driver_register(&bcm_dmaman_driver);
  14462. + if (ret != 0) {
  14463. + printk(KERN_ERR DRIVER_NAME ": failed to register "
  14464. + "on platform\n");
  14465. + }
  14466. +
  14467. + return ret;
  14468. +}
  14469. +
  14470. +static void __exit bcm_dmaman_drv_exit(void)
  14471. +{
  14472. + platform_driver_unregister(&bcm_dmaman_driver);
  14473. +}
  14474. +
  14475. +module_init(bcm_dmaman_drv_init);
  14476. +module_exit(bcm_dmaman_drv_exit);
  14477. +
  14478. +module_param(dmachans, int, 0644);
  14479. +
  14480. +MODULE_AUTHOR("Gray Girling <grayg@broadcom.com>");
  14481. +MODULE_DESCRIPTION("DMA channel manager driver");
  14482. +MODULE_LICENSE("GPL");
  14483. +
  14484. +MODULE_PARM_DESC(dmachans, "Bitmap of DMA channels available to the ARM");
  14485. diff -Nur linux-3.18.8/arch/arm/mach-bcm2709/dmaer.c linux-rpi/arch/arm/mach-bcm2709/dmaer.c
  14486. --- linux-3.18.8/arch/arm/mach-bcm2709/dmaer.c 1970-01-01 01:00:00.000000000 +0100
  14487. +++ linux-rpi/arch/arm/mach-bcm2709/dmaer.c 2015-03-05 14:40:11.153715839 +0100
  14488. @@ -0,0 +1,886 @@
  14489. +#include <linux/init.h>
  14490. +#include <linux/sched.h>
  14491. +#include <linux/module.h>
  14492. +#include <linux/types.h>
  14493. +#include <linux/kdev_t.h>
  14494. +#include <linux/fs.h>
  14495. +#include <linux/cdev.h>
  14496. +#include <linux/mm.h>
  14497. +#include <linux/slab.h>
  14498. +#include <linux/pagemap.h>
  14499. +#include <linux/device.h>
  14500. +#include <linux/jiffies.h>
  14501. +#include <linux/timex.h>
  14502. +#include <linux/dma-mapping.h>
  14503. +
  14504. +#include <asm/uaccess.h>
  14505. +#include <asm/atomic.h>
  14506. +#include <asm/cacheflush.h>
  14507. +#include <asm/io.h>
  14508. +
  14509. +#include <mach/dma.h>
  14510. +#include <mach/vc_support.h>
  14511. +
  14512. +#ifdef ECLIPSE_IGNORE
  14513. +
  14514. +#define __user
  14515. +#define __init
  14516. +#define __exit
  14517. +#define __iomem
  14518. +#define KERN_DEBUG
  14519. +#define KERN_ERR
  14520. +#define KERN_WARNING
  14521. +#define KERN_INFO
  14522. +#define _IOWR(a, b, c) b
  14523. +#define _IOW(a, b, c) b
  14524. +#define _IO(a, b) b
  14525. +
  14526. +#endif
  14527. +
  14528. +//#define inline
  14529. +
  14530. +#define PRINTK(args...) printk(args)
  14531. +//#define PRINTK_VERBOSE(args...) printk(args)
  14532. +//#define PRINTK(args...)
  14533. +#define PRINTK_VERBOSE(args...)
  14534. +
  14535. +/***** TYPES ****/
  14536. +#define PAGES_PER_LIST 500
  14537. +struct PageList
  14538. +{
  14539. + struct page *m_pPages[PAGES_PER_LIST];
  14540. + unsigned int m_used;
  14541. + struct PageList *m_pNext;
  14542. +};
  14543. +
  14544. +struct VmaPageList
  14545. +{
  14546. + //each vma has a linked list of pages associated with it
  14547. + struct PageList *m_pPageHead;
  14548. + struct PageList *m_pPageTail;
  14549. + unsigned int m_refCount;
  14550. +};
  14551. +
  14552. +struct DmaControlBlock
  14553. +{
  14554. + unsigned int m_transferInfo;
  14555. + void __user *m_pSourceAddr;
  14556. + void __user *m_pDestAddr;
  14557. + unsigned int m_xferLen;
  14558. + unsigned int m_tdStride;
  14559. + struct DmaControlBlock *m_pNext;
  14560. + unsigned int m_blank1, m_blank2;
  14561. +};
  14562. +
  14563. +/***** DEFINES ******/
  14564. +//magic number defining the module
  14565. +#define DMA_MAGIC 0xdd
  14566. +
  14567. +//do user virtual to physical translation of the CB chain
  14568. +#define DMA_PREPARE _IOWR(DMA_MAGIC, 0, struct DmaControlBlock *)
  14569. +
  14570. +//kick the pre-prepared CB chain
  14571. +#define DMA_KICK _IOW(DMA_MAGIC, 1, struct DmaControlBlock *)
  14572. +
  14573. +//prepare it, kick it, wait for it
  14574. +#define DMA_PREPARE_KICK_WAIT _IOWR(DMA_MAGIC, 2, struct DmaControlBlock *)
  14575. +
  14576. +//prepare it, kick it, don't wait for it
  14577. +#define DMA_PREPARE_KICK _IOWR(DMA_MAGIC, 3, struct DmaControlBlock *)
  14578. +
  14579. +//not currently implemented
  14580. +#define DMA_WAIT_ONE _IO(DMA_MAGIC, 4, struct DmaControlBlock *)
  14581. +
  14582. +//wait on all kicked CB chains
  14583. +#define DMA_WAIT_ALL _IO(DMA_MAGIC, 5)
  14584. +
  14585. +//in order to discover the largest AXI burst that should be programmed into the transfer params
  14586. +#define DMA_MAX_BURST _IO(DMA_MAGIC, 6)
  14587. +
  14588. +//set the address range through which the user address is assumed to already by a physical address
  14589. +#define DMA_SET_MIN_PHYS _IOW(DMA_MAGIC, 7, unsigned long)
  14590. +#define DMA_SET_MAX_PHYS _IOW(DMA_MAGIC, 8, unsigned long)
  14591. +#define DMA_SET_PHYS_OFFSET _IOW(DMA_MAGIC, 9, unsigned long)
  14592. +
  14593. +//used to define the size for the CMA-based allocation *in pages*, can only be done once once the file is opened
  14594. +#define DMA_CMA_SET_SIZE _IOW(DMA_MAGIC, 10, unsigned long)
  14595. +
  14596. +//used to get the version of the module, to test for a capability
  14597. +#define DMA_GET_VERSION _IO(DMA_MAGIC, 99)
  14598. +
  14599. +#define VERSION_NUMBER 1
  14600. +
  14601. +#define VIRT_TO_BUS_CACHE_SIZE 8
  14602. +
  14603. +/***** FILE OPS *****/
  14604. +static int Open(struct inode *pInode, struct file *pFile);
  14605. +static int Release(struct inode *pInode, struct file *pFile);
  14606. +static long Ioctl(struct file *pFile, unsigned int cmd, unsigned long arg);
  14607. +static ssize_t Read(struct file *pFile, char __user *pUser, size_t count, loff_t *offp);
  14608. +static int Mmap(struct file *pFile, struct vm_area_struct *pVma);
  14609. +
  14610. +/***** VMA OPS ****/
  14611. +static void VmaOpen4k(struct vm_area_struct *pVma);
  14612. +static void VmaClose4k(struct vm_area_struct *pVma);
  14613. +static int VmaFault4k(struct vm_area_struct *pVma, struct vm_fault *pVmf);
  14614. +
  14615. +/**** DMA PROTOTYPES */
  14616. +static struct DmaControlBlock __user *DmaPrepare(struct DmaControlBlock __user *pUserCB, int *pError);
  14617. +static int DmaKick(struct DmaControlBlock __user *pUserCB);
  14618. +static void DmaWaitAll(void);
  14619. +
  14620. +/**** GENERIC ****/
  14621. +static int __init dmaer_init(void);
  14622. +static void __exit dmaer_exit(void);
  14623. +
  14624. +/*** OPS ***/
  14625. +static struct vm_operations_struct g_vmOps4k = {
  14626. + .open = VmaOpen4k,
  14627. + .close = VmaClose4k,
  14628. + .fault = VmaFault4k,
  14629. +};
  14630. +
  14631. +static struct file_operations g_fOps = {
  14632. + .owner = THIS_MODULE,
  14633. + .llseek = 0,
  14634. + .read = Read,
  14635. + .write = 0,
  14636. + .unlocked_ioctl = Ioctl,
  14637. + .open = Open,
  14638. + .release = Release,
  14639. + .mmap = Mmap,
  14640. +};
  14641. +
  14642. +/***** GLOBALS ******/
  14643. +static dev_t g_majorMinor;
  14644. +
  14645. +//tracking usage of the two files
  14646. +static atomic_t g_oneLock4k = ATOMIC_INIT(1);
  14647. +
  14648. +//device operations
  14649. +static struct cdev g_cDev;
  14650. +static int g_trackedPages = 0;
  14651. +
  14652. +//dma control
  14653. +static unsigned int *g_pDmaChanBase;
  14654. +static int g_dmaIrq;
  14655. +static int g_dmaChan;
  14656. +
  14657. +//cma allocation
  14658. +static int g_cmaHandle;
  14659. +
  14660. +//user virtual to bus address translation acceleration
  14661. +static unsigned long g_virtAddr[VIRT_TO_BUS_CACHE_SIZE];
  14662. +static unsigned long g_busAddr[VIRT_TO_BUS_CACHE_SIZE];
  14663. +static unsigned long g_cbVirtAddr;
  14664. +static unsigned long g_cbBusAddr;
  14665. +static int g_cacheInsertAt;
  14666. +static int g_cacheHit, g_cacheMiss;
  14667. +
  14668. +//off by default
  14669. +static void __user *g_pMinPhys;
  14670. +static void __user *g_pMaxPhys;
  14671. +static unsigned long g_physOffset;
  14672. +
  14673. +/****** CACHE OPERATIONS ********/
  14674. +static inline void FlushAddrCache(void)
  14675. +{
  14676. + int count = 0;
  14677. + for (count = 0; count < VIRT_TO_BUS_CACHE_SIZE; count++)
  14678. + g_virtAddr[count] = 0xffffffff; //never going to match as we always chop the bottom bits anyway
  14679. +
  14680. + g_cbVirtAddr = 0xffffffff;
  14681. +
  14682. + g_cacheInsertAt = 0;
  14683. +}
  14684. +
  14685. +//translate from a user virtual address to a bus address by mapping the page
  14686. +//NB this won't lock a page in memory, so to avoid potential paging issues using kernel logical addresses
  14687. +static inline void __iomem *UserVirtualToBus(void __user *pUser)
  14688. +{
  14689. + int mapped;
  14690. + struct page *pPage;
  14691. + void *phys;
  14692. +
  14693. + //map it (requiring that the pointer points to something that does not hang off the page boundary)
  14694. + mapped = get_user_pages(current, current->mm,
  14695. + (unsigned long)pUser, 1,
  14696. + 1, 0,
  14697. + &pPage,
  14698. + 0);
  14699. +
  14700. + if (mapped <= 0) //error
  14701. + return 0;
  14702. +
  14703. + PRINTK_VERBOSE(KERN_DEBUG "user virtual %p arm phys %p bus %p\n",
  14704. + pUser, page_address(pPage), (void __iomem *)__virt_to_bus(page_address(pPage)));
  14705. +
  14706. + //get the arm physical address
  14707. + phys = page_address(pPage) + offset_in_page(pUser);
  14708. + page_cache_release(pPage);
  14709. +
  14710. + //and now the bus address
  14711. + return (void __iomem *)__virt_to_bus(phys);
  14712. +}
  14713. +
  14714. +static inline void __iomem *UserVirtualToBusViaCbCache(void __user *pUser)
  14715. +{
  14716. + unsigned long virtual_page = (unsigned long)pUser & ~4095;
  14717. + unsigned long page_offset = (unsigned long)pUser & 4095;
  14718. + unsigned long bus_addr;
  14719. +
  14720. + if (g_cbVirtAddr == virtual_page)
  14721. + {
  14722. + bus_addr = g_cbBusAddr + page_offset;
  14723. + g_cacheHit++;
  14724. + return (void __iomem *)bus_addr;
  14725. + }
  14726. + else
  14727. + {
  14728. + bus_addr = (unsigned long)UserVirtualToBus(pUser);
  14729. +
  14730. + if (!bus_addr)
  14731. + return 0;
  14732. +
  14733. + g_cbVirtAddr = virtual_page;
  14734. + g_cbBusAddr = bus_addr & ~4095;
  14735. + g_cacheMiss++;
  14736. +
  14737. + return (void __iomem *)bus_addr;
  14738. + }
  14739. +}
  14740. +
  14741. +//do the same as above, by query our virt->bus cache
  14742. +static inline void __iomem *UserVirtualToBusViaCache(void __user *pUser)
  14743. +{
  14744. + int count;
  14745. + //get the page and its offset
  14746. + unsigned long virtual_page = (unsigned long)pUser & ~4095;
  14747. + unsigned long page_offset = (unsigned long)pUser & 4095;
  14748. + unsigned long bus_addr;
  14749. +
  14750. + if (pUser >= g_pMinPhys && pUser < g_pMaxPhys)
  14751. + {
  14752. + PRINTK_VERBOSE(KERN_DEBUG "user->phys passthrough on %p\n", pUser);
  14753. + return (void __iomem *)((unsigned long)pUser + g_physOffset);
  14754. + }
  14755. +
  14756. + //check the cache for our entry
  14757. + for (count = 0; count < VIRT_TO_BUS_CACHE_SIZE; count++)
  14758. + if (g_virtAddr[count] == virtual_page)
  14759. + {
  14760. + bus_addr = g_busAddr[count] + page_offset;
  14761. + g_cacheHit++;
  14762. + return (void __iomem *)bus_addr;
  14763. + }
  14764. +
  14765. + //not found, look up manually and then insert its page address
  14766. + bus_addr = (unsigned long)UserVirtualToBus(pUser);
  14767. +
  14768. + if (!bus_addr)
  14769. + return 0;
  14770. +
  14771. + g_virtAddr[g_cacheInsertAt] = virtual_page;
  14772. + g_busAddr[g_cacheInsertAt] = bus_addr & ~4095;
  14773. +
  14774. + //round robin
  14775. + g_cacheInsertAt++;
  14776. + if (g_cacheInsertAt == VIRT_TO_BUS_CACHE_SIZE)
  14777. + g_cacheInsertAt = 0;
  14778. +
  14779. + g_cacheMiss++;
  14780. +
  14781. + return (void __iomem *)bus_addr;
  14782. +}
  14783. +
  14784. +/***** FILE OPERATIONS ****/
  14785. +static int Open(struct inode *pInode, struct file *pFile)
  14786. +{
  14787. + PRINTK(KERN_DEBUG "file opening: %d/%d\n", imajor(pInode), iminor(pInode));
  14788. +
  14789. + //check which device we are
  14790. + if (iminor(pInode) == 0) //4k
  14791. + {
  14792. + //only one at a time
  14793. + if (!atomic_dec_and_test(&g_oneLock4k))
  14794. + {
  14795. + atomic_inc(&g_oneLock4k);
  14796. + return -EBUSY;
  14797. + }
  14798. + }
  14799. + else
  14800. + return -EINVAL;
  14801. +
  14802. + //todo there will be trouble if two different processes open the files
  14803. +
  14804. + //reset after any file is opened
  14805. + g_pMinPhys = (void __user *)-1;
  14806. + g_pMaxPhys = (void __user *)0;
  14807. + g_physOffset = 0;
  14808. + g_cmaHandle = 0;
  14809. +
  14810. + return 0;
  14811. +}
  14812. +
  14813. +static int Release(struct inode *pInode, struct file *pFile)
  14814. +{
  14815. + PRINTK(KERN_DEBUG "file closing, %d pages tracked\n", g_trackedPages);
  14816. + if (g_trackedPages)
  14817. + PRINTK(KERN_ERR "we\'re leaking memory!\n");
  14818. +
  14819. + //wait for any dmas to finish
  14820. + DmaWaitAll();
  14821. +
  14822. + //free this memory on the application closing the file or it crashing (implicitly closing the file)
  14823. + if (g_cmaHandle)
  14824. + {
  14825. + PRINTK(KERN_DEBUG "unlocking vc memory\n");
  14826. + if (UnlockVcMemory(g_cmaHandle))
  14827. + PRINTK(KERN_ERR "uh-oh, unable to unlock vc memory!\n");
  14828. + PRINTK(KERN_DEBUG "releasing vc memory\n");
  14829. + if (ReleaseVcMemory(g_cmaHandle))
  14830. + PRINTK(KERN_ERR "uh-oh, unable to release vc memory!\n");
  14831. + }
  14832. +
  14833. + if (iminor(pInode) == 0)
  14834. + atomic_inc(&g_oneLock4k);
  14835. + else
  14836. + return -EINVAL;
  14837. +
  14838. + return 0;
  14839. +}
  14840. +
  14841. +static struct DmaControlBlock __user *DmaPrepare(struct DmaControlBlock __user *pUserCB, int *pError)
  14842. +{
  14843. + struct DmaControlBlock kernCB;
  14844. + struct DmaControlBlock __user *pUNext;
  14845. + void __iomem *pSourceBus, __iomem *pDestBus;
  14846. +
  14847. + //get the control block into kernel memory so we can work on it
  14848. + if (copy_from_user(&kernCB, pUserCB, sizeof(struct DmaControlBlock)) != 0)
  14849. + {
  14850. + PRINTK(KERN_ERR "copy_from_user failed for user cb %p\n", pUserCB);
  14851. + *pError = 1;
  14852. + return 0;
  14853. + }
  14854. +
  14855. + if (kernCB.m_pSourceAddr == 0 || kernCB.m_pDestAddr == 0)
  14856. + {
  14857. + PRINTK(KERN_ERR "faulty source (%p) dest (%p) addresses for user cb %p\n",
  14858. + kernCB.m_pSourceAddr, kernCB.m_pDestAddr, pUserCB);
  14859. + *pError = 1;
  14860. + return 0;
  14861. + }
  14862. +
  14863. + pSourceBus = UserVirtualToBusViaCache(kernCB.m_pSourceAddr);
  14864. + pDestBus = UserVirtualToBusViaCache(kernCB.m_pDestAddr);
  14865. +
  14866. + if (!pSourceBus || !pDestBus)
  14867. + {
  14868. + PRINTK(KERN_ERR "virtual to bus translation failure for source/dest %p/%p->%p/%p\n",
  14869. + kernCB.m_pSourceAddr, kernCB.m_pDestAddr,
  14870. + pSourceBus, pDestBus);
  14871. + *pError = 1;
  14872. + return 0;
  14873. + }
  14874. +
  14875. + //update the user structure with the new bus addresses
  14876. + kernCB.m_pSourceAddr = pSourceBus;
  14877. + kernCB.m_pDestAddr = pDestBus;
  14878. +
  14879. + PRINTK_VERBOSE(KERN_DEBUG "final source %p dest %p\n", kernCB.m_pSourceAddr, kernCB.m_pDestAddr);
  14880. +
  14881. + //sort out the bus address for the next block
  14882. + pUNext = kernCB.m_pNext;
  14883. +
  14884. + if (kernCB.m_pNext)
  14885. + {
  14886. + void __iomem *pNextBus;
  14887. + pNextBus = UserVirtualToBusViaCbCache(kernCB.m_pNext);
  14888. +
  14889. + if (!pNextBus)
  14890. + {
  14891. + PRINTK(KERN_ERR "virtual to bus translation failure for m_pNext\n");
  14892. + *pError = 1;
  14893. + return 0;
  14894. + }
  14895. +
  14896. + //update the pointer with the bus address
  14897. + kernCB.m_pNext = pNextBus;
  14898. + }
  14899. +
  14900. + //write it back to user space
  14901. + if (copy_to_user(pUserCB, &kernCB, sizeof(struct DmaControlBlock)) != 0)
  14902. + {
  14903. + PRINTK(KERN_ERR "copy_to_user failed for cb %p\n", pUserCB);
  14904. + *pError = 1;
  14905. + return 0;
  14906. + }
  14907. +
  14908. + __cpuc_flush_dcache_area(pUserCB, 32);
  14909. +
  14910. + *pError = 0;
  14911. + return pUNext;
  14912. +}
  14913. +
  14914. +static int DmaKick(struct DmaControlBlock __user *pUserCB)
  14915. +{
  14916. + void __iomem *pBusCB;
  14917. +
  14918. + pBusCB = UserVirtualToBusViaCbCache(pUserCB);
  14919. + if (!pBusCB)
  14920. + {
  14921. + PRINTK(KERN_ERR "virtual to bus translation failure for cb\n");
  14922. + return 1;
  14923. + }
  14924. +
  14925. + //flush_cache_all();
  14926. +
  14927. + bcm_dma_start(g_pDmaChanBase, (dma_addr_t)pBusCB);
  14928. +
  14929. + return 0;
  14930. +}
  14931. +
  14932. +static void DmaWaitAll(void)
  14933. +{
  14934. + int counter = 0;
  14935. + volatile int inner_count;
  14936. + volatile unsigned int cs;
  14937. + unsigned long time_before, time_after;
  14938. +
  14939. + time_before = jiffies;
  14940. + //bcm_dma_wait_idle(g_pDmaChanBase);
  14941. + dsb();
  14942. +
  14943. + cs = readl(g_pDmaChanBase);
  14944. +
  14945. + while ((cs & 1) == 1)
  14946. + {
  14947. + cs = readl(g_pDmaChanBase);
  14948. + counter++;
  14949. +
  14950. + for (inner_count = 0; inner_count < 32; inner_count++);
  14951. +
  14952. + asm volatile ("MCR p15,0,r0,c7,c0,4 \n");
  14953. + //cpu_do_idle();
  14954. + if (counter >= 1000000)
  14955. + {
  14956. + PRINTK(KERN_WARNING "DMA failed to finish in a timely fashion\n");
  14957. + break;
  14958. + }
  14959. + }
  14960. + time_after = jiffies;
  14961. + PRINTK_VERBOSE(KERN_DEBUG "done, counter %d, cs %08x", counter, cs);
  14962. + PRINTK_VERBOSE(KERN_DEBUG "took %ld jiffies, %d HZ\n", time_after - time_before, HZ);
  14963. +}
  14964. +
  14965. +static long Ioctl(struct file *pFile, unsigned int cmd, unsigned long arg)
  14966. +{
  14967. + int error = 0;
  14968. + PRINTK_VERBOSE(KERN_DEBUG "ioctl cmd %x arg %lx\n", cmd, arg);
  14969. +
  14970. + switch (cmd)
  14971. + {
  14972. + case DMA_PREPARE:
  14973. + case DMA_PREPARE_KICK:
  14974. + case DMA_PREPARE_KICK_WAIT:
  14975. + {
  14976. + struct DmaControlBlock __user *pUCB = (struct DmaControlBlock *)arg;
  14977. + int steps = 0;
  14978. + unsigned long start_time = jiffies;
  14979. + (void)start_time;
  14980. +
  14981. + //flush our address cache
  14982. + FlushAddrCache();
  14983. +
  14984. + PRINTK_VERBOSE(KERN_DEBUG "dma prepare\n");
  14985. +
  14986. + //do virtual to bus translation for each entry
  14987. + do
  14988. + {
  14989. + pUCB = DmaPrepare(pUCB, &error);
  14990. + } while (error == 0 && ++steps && pUCB);
  14991. + PRINTK_VERBOSE(KERN_DEBUG "prepare done in %d steps, %ld\n", steps, jiffies - start_time);
  14992. +
  14993. + //carry straight on if we want to kick too
  14994. + if (cmd == DMA_PREPARE || error)
  14995. + {
  14996. + PRINTK_VERBOSE(KERN_DEBUG "falling out\n");
  14997. + return error ? -EINVAL : 0;
  14998. + }
  14999. + }
  15000. + case DMA_KICK:
  15001. + PRINTK_VERBOSE(KERN_DEBUG "dma begin\n");
  15002. +
  15003. + if (cmd == DMA_KICK)
  15004. + FlushAddrCache();
  15005. +
  15006. + DmaKick((struct DmaControlBlock __user *)arg);
  15007. +
  15008. + if (cmd != DMA_PREPARE_KICK_WAIT)
  15009. + break;
  15010. +/* case DMA_WAIT_ONE:
  15011. + //PRINTK(KERN_DEBUG "dma wait one\n");
  15012. + break;*/
  15013. + case DMA_WAIT_ALL:
  15014. + //PRINTK(KERN_DEBUG "dma wait all\n");
  15015. + DmaWaitAll();
  15016. + break;
  15017. + case DMA_MAX_BURST:
  15018. + if (g_dmaChan == 0)
  15019. + return 10;
  15020. + else
  15021. + return 5;
  15022. + case DMA_SET_MIN_PHYS:
  15023. + g_pMinPhys = (void __user *)arg;
  15024. + PRINTK(KERN_DEBUG "min/max user/phys bypass set to %p %p\n", g_pMinPhys, g_pMaxPhys);
  15025. + break;
  15026. + case DMA_SET_MAX_PHYS:
  15027. + g_pMaxPhys = (void __user *)arg;
  15028. + PRINTK(KERN_DEBUG "min/max user/phys bypass set to %p %p\n", g_pMinPhys, g_pMaxPhys);
  15029. + break;
  15030. + case DMA_SET_PHYS_OFFSET:
  15031. + g_physOffset = arg;
  15032. + PRINTK(KERN_DEBUG "user/phys bypass offset set to %ld\n", g_physOffset);
  15033. + break;
  15034. + case DMA_CMA_SET_SIZE:
  15035. + {
  15036. + unsigned int pBusAddr;
  15037. +
  15038. + if (g_cmaHandle)
  15039. + {
  15040. + PRINTK(KERN_ERR "memory has already been allocated (handle %d)\n", g_cmaHandle);
  15041. + return -EINVAL;
  15042. + }
  15043. +
  15044. + PRINTK(KERN_INFO "allocating %ld bytes of VC memory\n", arg * 4096);
  15045. +
  15046. + //get the memory
  15047. + if (AllocateVcMemory(&g_cmaHandle, arg * 4096, 4096, MEM_FLAG_L1_NONALLOCATING | MEM_FLAG_NO_INIT | MEM_FLAG_HINT_PERMALOCK))
  15048. + {
  15049. + PRINTK(KERN_ERR "failed to allocate %ld bytes of VC memory\n", arg * 4096);
  15050. + g_cmaHandle = 0;
  15051. + return -EINVAL;
  15052. + }
  15053. +
  15054. + //get an address for it
  15055. + PRINTK(KERN_INFO "trying to map VC memory\n");
  15056. +
  15057. + if (LockVcMemory(&pBusAddr, g_cmaHandle))
  15058. + {
  15059. + PRINTK(KERN_ERR "failed to map CMA handle %d, releasing memory\n", g_cmaHandle);
  15060. + ReleaseVcMemory(g_cmaHandle);
  15061. + g_cmaHandle = 0;
  15062. + }
  15063. +
  15064. + PRINTK(KERN_INFO "bus address for CMA memory is %x\n", pBusAddr);
  15065. + return pBusAddr;
  15066. + }
  15067. + case DMA_GET_VERSION:
  15068. + PRINTK(KERN_DEBUG "returning version number, %d\n", VERSION_NUMBER);
  15069. + return VERSION_NUMBER;
  15070. + default:
  15071. + PRINTK(KERN_DEBUG "unknown ioctl: %d\n", cmd);
  15072. + return -EINVAL;
  15073. + }
  15074. +
  15075. + return 0;
  15076. +}
  15077. +
  15078. +static ssize_t Read(struct file *pFile, char __user *pUser, size_t count, loff_t *offp)
  15079. +{
  15080. + return -EIO;
  15081. +}
  15082. +
  15083. +static int Mmap(struct file *pFile, struct vm_area_struct *pVma)
  15084. +{
  15085. + struct PageList *pPages;
  15086. + struct VmaPageList *pVmaList;
  15087. +
  15088. + PRINTK_VERBOSE(KERN_DEBUG "MMAP vma %p, length %ld (%s %d)\n",
  15089. + pVma, pVma->vm_end - pVma->vm_start,
  15090. + current->comm, current->pid);
  15091. + PRINTK_VERBOSE(KERN_DEBUG "MMAP %p %d (tracked %d)\n", pVma, current->pid, g_trackedPages);
  15092. +
  15093. + //make a new page list
  15094. + pPages = (struct PageList *)kmalloc(sizeof(struct PageList), GFP_KERNEL);
  15095. + if (!pPages)
  15096. + {
  15097. + PRINTK(KERN_ERR "couldn\'t allocate a new page list (%s %d)\n",
  15098. + current->comm, current->pid);
  15099. + return -ENOMEM;
  15100. + }
  15101. +
  15102. + //clear the page list
  15103. + pPages->m_used = 0;
  15104. + pPages->m_pNext = 0;
  15105. +
  15106. + //insert our vma and new page list somewhere
  15107. + if (!pVma->vm_private_data)
  15108. + {
  15109. + struct VmaPageList *pList;
  15110. +
  15111. + PRINTK_VERBOSE(KERN_DEBUG "new vma list, making new one (%s %d)\n",
  15112. + current->comm, current->pid);
  15113. +
  15114. + //make a new vma list
  15115. + pList = (struct VmaPageList *)kmalloc(sizeof(struct VmaPageList), GFP_KERNEL);
  15116. + if (!pList)
  15117. + {
  15118. + PRINTK(KERN_ERR "couldn\'t allocate vma page list (%s %d)\n",
  15119. + current->comm, current->pid);
  15120. + kfree(pPages);
  15121. + return -ENOMEM;
  15122. + }
  15123. +
  15124. + //clear this list
  15125. + pVma->vm_private_data = (void *)pList;
  15126. + pList->m_refCount = 0;
  15127. + }
  15128. +
  15129. + pVmaList = (struct VmaPageList *)pVma->vm_private_data;
  15130. +
  15131. + //add it to the vma list
  15132. + pVmaList->m_pPageHead = pPages;
  15133. + pVmaList->m_pPageTail = pPages;
  15134. +
  15135. + pVma->vm_ops = &g_vmOps4k;
  15136. + pVma->vm_flags |= VM_IO;
  15137. +
  15138. + VmaOpen4k(pVma);
  15139. +
  15140. + return 0;
  15141. +}
  15142. +
  15143. +/****** VMA OPERATIONS ******/
  15144. +
  15145. +static void VmaOpen4k(struct vm_area_struct *pVma)
  15146. +{
  15147. + struct VmaPageList *pVmaList;
  15148. +
  15149. + PRINTK_VERBOSE(KERN_DEBUG "vma open %p private %p (%s %d), %d live pages\n", pVma, pVma->vm_private_data, current->comm, current->pid, g_trackedPages);
  15150. + PRINTK_VERBOSE(KERN_DEBUG "OPEN %p %d %ld pages (tracked pages %d)\n",
  15151. + pVma, current->pid, (pVma->vm_end - pVma->vm_start) >> 12,
  15152. + g_trackedPages);
  15153. +
  15154. + pVmaList = (struct VmaPageList *)pVma->vm_private_data;
  15155. +
  15156. + if (pVmaList)
  15157. + {
  15158. + pVmaList->m_refCount++;
  15159. + PRINTK_VERBOSE(KERN_DEBUG "ref count is now %d\n", pVmaList->m_refCount);
  15160. + }
  15161. + else
  15162. + {
  15163. + PRINTK_VERBOSE(KERN_DEBUG "err, open but no vma page list\n");
  15164. + }
  15165. +}
  15166. +
  15167. +static void VmaClose4k(struct vm_area_struct *pVma)
  15168. +{
  15169. + struct VmaPageList *pVmaList;
  15170. + int freed = 0;
  15171. +
  15172. + PRINTK_VERBOSE(KERN_DEBUG "vma close %p private %p (%s %d)\n", pVma, pVma->vm_private_data, current->comm, current->pid);
  15173. +
  15174. + //wait for any dmas to finish
  15175. + DmaWaitAll();
  15176. +
  15177. + //find our vma in the list
  15178. + pVmaList = (struct VmaPageList *)pVma->vm_private_data;
  15179. +
  15180. + //may be a fork
  15181. + if (pVmaList)
  15182. + {
  15183. + struct PageList *pPages;
  15184. +
  15185. + pVmaList->m_refCount--;
  15186. +
  15187. + if (pVmaList->m_refCount == 0)
  15188. + {
  15189. + PRINTK_VERBOSE(KERN_DEBUG "found vma, freeing pages (%s %d)\n",
  15190. + current->comm, current->pid);
  15191. +
  15192. + pPages = pVmaList->m_pPageHead;
  15193. +
  15194. + if (!pPages)
  15195. + {
  15196. + PRINTK(KERN_ERR "no page list (%s %d)!\n",
  15197. + current->comm, current->pid);
  15198. + return;
  15199. + }
  15200. +
  15201. + while (pPages)
  15202. + {
  15203. + struct PageList *next;
  15204. + int count;
  15205. +
  15206. + PRINTK_VERBOSE(KERN_DEBUG "page list (%s %d)\n",
  15207. + current->comm, current->pid);
  15208. +
  15209. + next = pPages->m_pNext;
  15210. + for (count = 0; count < pPages->m_used; count++)
  15211. + {
  15212. + PRINTK_VERBOSE(KERN_DEBUG "freeing page %p (%s %d)\n",
  15213. + pPages->m_pPages[count],
  15214. + current->comm, current->pid);
  15215. + __free_pages(pPages->m_pPages[count], 0);
  15216. + g_trackedPages--;
  15217. + freed++;
  15218. + }
  15219. +
  15220. + PRINTK_VERBOSE(KERN_DEBUG "freeing page list (%s %d)\n",
  15221. + current->comm, current->pid);
  15222. + kfree(pPages);
  15223. + pPages = next;
  15224. + }
  15225. +
  15226. + //remove our vma from the list
  15227. + kfree(pVmaList);
  15228. + pVma->vm_private_data = 0;
  15229. + }
  15230. + else
  15231. + {
  15232. + PRINTK_VERBOSE(KERN_DEBUG "ref count is %d, not closing\n", pVmaList->m_refCount);
  15233. + }
  15234. + }
  15235. + else
  15236. + {
  15237. + PRINTK_VERBOSE(KERN_ERR "uh-oh, vma %p not found (%s %d)!\n", pVma, current->comm, current->pid);
  15238. + PRINTK_VERBOSE(KERN_ERR "CLOSE ERR\n");
  15239. + }
  15240. +
  15241. + PRINTK_VERBOSE(KERN_DEBUG "CLOSE %p %d %d pages (tracked pages %d)",
  15242. + pVma, current->pid, freed, g_trackedPages);
  15243. +
  15244. + PRINTK_VERBOSE(KERN_DEBUG "%d pages open\n", g_trackedPages);
  15245. +}
  15246. +
  15247. +static int VmaFault4k(struct vm_area_struct *pVma, struct vm_fault *pVmf)
  15248. +{
  15249. + PRINTK_VERBOSE(KERN_DEBUG "vma fault for vma %p private %p at offset %ld (%s %d)\n", pVma, pVma->vm_private_data, pVmf->pgoff,
  15250. + current->comm, current->pid);
  15251. + PRINTK_VERBOSE(KERN_DEBUG "FAULT\n");
  15252. + pVmf->page = alloc_page(GFP_KERNEL);
  15253. +
  15254. + if (pVmf->page)
  15255. + {
  15256. + PRINTK_VERBOSE(KERN_DEBUG "alloc page virtual %p\n", page_address(pVmf->page));
  15257. + }
  15258. +
  15259. + if (!pVmf->page)
  15260. + {
  15261. + PRINTK(KERN_ERR "vma fault oom (%s %d)\n", current->comm, current->pid);
  15262. + return VM_FAULT_OOM;
  15263. + }
  15264. + else
  15265. + {
  15266. + struct VmaPageList *pVmaList;
  15267. +
  15268. + get_page(pVmf->page);
  15269. + g_trackedPages++;
  15270. +
  15271. + //find our vma in the list
  15272. + pVmaList = (struct VmaPageList *)pVma->vm_private_data;
  15273. +
  15274. + if (pVmaList)
  15275. + {
  15276. + PRINTK_VERBOSE(KERN_DEBUG "vma found (%s %d)\n", current->comm, current->pid);
  15277. +
  15278. + if (pVmaList->m_pPageTail->m_used == PAGES_PER_LIST)
  15279. + {
  15280. + PRINTK_VERBOSE(KERN_DEBUG "making new page list (%s %d)\n", current->comm, current->pid);
  15281. + //making a new page list
  15282. + pVmaList->m_pPageTail->m_pNext = (struct PageList *)kmalloc(sizeof(struct PageList), GFP_KERNEL);
  15283. + if (!pVmaList->m_pPageTail->m_pNext)
  15284. + return -ENOMEM;
  15285. +
  15286. + //update the tail pointer
  15287. + pVmaList->m_pPageTail = pVmaList->m_pPageTail->m_pNext;
  15288. + pVmaList->m_pPageTail->m_used = 0;
  15289. + pVmaList->m_pPageTail->m_pNext = 0;
  15290. + }
  15291. +
  15292. + PRINTK_VERBOSE(KERN_DEBUG "adding page to list (%s %d)\n", current->comm, current->pid);
  15293. +
  15294. + pVmaList->m_pPageTail->m_pPages[pVmaList->m_pPageTail->m_used] = pVmf->page;
  15295. + pVmaList->m_pPageTail->m_used++;
  15296. + }
  15297. + else
  15298. + PRINTK(KERN_ERR "returned page for vma we don\'t know %p (%s %d)\n", pVma, current->comm, current->pid);
  15299. +
  15300. + return 0;
  15301. + }
  15302. +}
  15303. +
  15304. +/****** GENERIC FUNCTIONS ******/
  15305. +static int __init dmaer_init(void)
  15306. +{
  15307. + int result = alloc_chrdev_region(&g_majorMinor, 0, 1, "dmaer");
  15308. + if (result < 0)
  15309. + {
  15310. + PRINTK(KERN_ERR "unable to get major device number\n");
  15311. + return result;
  15312. + }
  15313. + else
  15314. + PRINTK(KERN_DEBUG "major device number %d\n", MAJOR(g_majorMinor));
  15315. +
  15316. + PRINTK(KERN_DEBUG "vma list size %d, page list size %d, page size %ld\n",
  15317. + sizeof(struct VmaPageList), sizeof(struct PageList), PAGE_SIZE);
  15318. +
  15319. + //get a dma channel to work with
  15320. + result = bcm_dma_chan_alloc(BCM_DMA_FEATURE_FAST, (void **)&g_pDmaChanBase, &g_dmaIrq);
  15321. +
  15322. + //uncomment to force to channel 0
  15323. + //result = 0;
  15324. + //g_pDmaChanBase = 0xce808000;
  15325. +
  15326. + if (result < 0)
  15327. + {
  15328. + PRINTK(KERN_ERR "failed to allocate dma channel\n");
  15329. + cdev_del(&g_cDev);
  15330. + unregister_chrdev_region(g_majorMinor, 1);
  15331. + }
  15332. +
  15333. + //reset the channel
  15334. + PRINTK(KERN_DEBUG "allocated dma channel %d (%p), initial state %08x\n", result, g_pDmaChanBase, *g_pDmaChanBase);
  15335. + *g_pDmaChanBase = 1 << 31;
  15336. + PRINTK(KERN_DEBUG "post-reset %08x\n", *g_pDmaChanBase);
  15337. +
  15338. + g_dmaChan = result;
  15339. +
  15340. + //clear the cache stats
  15341. + g_cacheHit = 0;
  15342. + g_cacheMiss = 0;
  15343. +
  15344. + //register our device - after this we are go go go
  15345. + cdev_init(&g_cDev, &g_fOps);
  15346. + g_cDev.owner = THIS_MODULE;
  15347. + g_cDev.ops = &g_fOps;
  15348. +
  15349. + result = cdev_add(&g_cDev, g_majorMinor, 1);
  15350. + if (result < 0)
  15351. + {
  15352. + PRINTK(KERN_ERR "failed to add character device\n");
  15353. + unregister_chrdev_region(g_majorMinor, 1);
  15354. + bcm_dma_chan_free(g_dmaChan);
  15355. + return result;
  15356. + }
  15357. +
  15358. + return 0;
  15359. +}
  15360. +
  15361. +static void __exit dmaer_exit(void)
  15362. +{
  15363. + PRINTK(KERN_INFO "closing dmaer device, cache stats: %d hits %d misses\n", g_cacheHit, g_cacheMiss);
  15364. + //unregister the device
  15365. + cdev_del(&g_cDev);
  15366. + unregister_chrdev_region(g_majorMinor, 1);
  15367. + //free the dma channel
  15368. + bcm_dma_chan_free(g_dmaChan);
  15369. +}
  15370. +
  15371. +MODULE_LICENSE("Dual BSD/GPL");
  15372. +MODULE_AUTHOR("Simon Hall");
  15373. +module_init(dmaer_init);
  15374. +module_exit(dmaer_exit);
  15375. diff -Nur linux-3.18.8/arch/arm/mach-bcm2709/include/mach/arm_control.h linux-rpi/arch/arm/mach-bcm2709/include/mach/arm_control.h
  15376. --- linux-3.18.8/arch/arm/mach-bcm2709/include/mach/arm_control.h 1970-01-01 01:00:00.000000000 +0100
  15377. +++ linux-rpi/arch/arm/mach-bcm2709/include/mach/arm_control.h 2015-03-05 14:40:11.153715839 +0100
  15378. @@ -0,0 +1,493 @@
  15379. +/*
  15380. + * linux/arch/arm/mach-bcm2708/arm_control.h
  15381. + *
  15382. + * Copyright (C) 2010 Broadcom
  15383. + *
  15384. + * This program is free software; you can redistribute it and/or modify
  15385. + * it under the terms of the GNU General Public License as published by
  15386. + * the Free Software Foundation; either version 2 of the License, or
  15387. + * (at your option) any later version.
  15388. + *
  15389. + * This program is distributed in the hope that it will be useful,
  15390. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15391. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15392. + * GNU General Public License for more details.
  15393. + *
  15394. + * You should have received a copy of the GNU General Public License
  15395. + * along with this program; if not, write to the Free Software
  15396. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  15397. + */
  15398. +
  15399. +#ifndef __BCM2708_ARM_CONTROL_H
  15400. +#define __BCM2708_ARM_CONTROL_H
  15401. +
  15402. +/*
  15403. + * Definitions and addresses for the ARM CONTROL logic
  15404. + * This file is manually generated.
  15405. + */
  15406. +
  15407. +#define ARM_BASE 0x7E00B000
  15408. +
  15409. +/* Basic configuration */
  15410. +#define ARM_CONTROL0 HW_REGISTER_RW(ARM_BASE+0x000)
  15411. +#define ARM_C0_SIZ128M 0x00000000
  15412. +#define ARM_C0_SIZ256M 0x00000001
  15413. +#define ARM_C0_SIZ512M 0x00000002
  15414. +#define ARM_C0_SIZ1G 0x00000003
  15415. +#define ARM_C0_BRESP0 0x00000000
  15416. +#define ARM_C0_BRESP1 0x00000004
  15417. +#define ARM_C0_BRESP2 0x00000008
  15418. +#define ARM_C0_BOOTHI 0x00000010
  15419. +#define ARM_C0_UNUSED05 0x00000020 /* free */
  15420. +#define ARM_C0_FULLPERI 0x00000040
  15421. +#define ARM_C0_UNUSED78 0x00000180 /* free */
  15422. +#define ARM_C0_JTAGMASK 0x00000E00
  15423. +#define ARM_C0_JTAGOFF 0x00000000
  15424. +#define ARM_C0_JTAGBASH 0x00000800 /* Debug on GPIO off */
  15425. +#define ARM_C0_JTAGGPIO 0x00000C00 /* Debug on GPIO on */
  15426. +#define ARM_C0_APROTMSK 0x0000F000
  15427. +#define ARM_C0_DBG0SYNC 0x00010000 /* VPU0 halt sync */
  15428. +#define ARM_C0_DBG1SYNC 0x00020000 /* VPU1 halt sync */
  15429. +#define ARM_C0_SWDBGREQ 0x00040000 /* HW debug request */
  15430. +#define ARM_C0_PASSHALT 0x00080000 /* ARM halt passed to debugger */
  15431. +#define ARM_C0_PRIO_PER 0x00F00000 /* per priority mask */
  15432. +#define ARM_C0_PRIO_L2 0x0F000000
  15433. +#define ARM_C0_PRIO_UC 0xF0000000
  15434. +
  15435. +#define ARM_C0_APROTPASS 0x0000A000 /* Translate 1:1 */
  15436. +#define ARM_C0_APROTUSER 0x00000000 /* Only user mode */
  15437. +#define ARM_C0_APROTSYST 0x0000F000 /* Only system mode */
  15438. +
  15439. +
  15440. +#define ARM_CONTROL1 HW_REGISTER_RW(ARM_BASE+0x440)
  15441. +#define ARM_C1_TIMER 0x00000001 /* re-route timer IRQ to VC */
  15442. +#define ARM_C1_MAIL 0x00000002 /* re-route Mail IRQ to VC */
  15443. +#define ARM_C1_BELL0 0x00000004 /* re-route Doorbell 0 to VC */
  15444. +#define ARM_C1_BELL1 0x00000008 /* re-route Doorbell 1 to VC */
  15445. +#define ARM_C1_PERSON 0x00000100 /* peripherals on */
  15446. +#define ARM_C1_REQSTOP 0x00000200 /* ASYNC bridge request stop */
  15447. +
  15448. +#define ARM_STATUS HW_REGISTER_RW(ARM_BASE+0x444)
  15449. +#define ARM_S_ACKSTOP 0x80000000 /* Bridge stopped */
  15450. +#define ARM_S_READPEND 0x000003FF /* pending reads counter */
  15451. +#define ARM_S_WRITPEND 0x000FFC00 /* pending writes counter */
  15452. +
  15453. +#define ARM_ERRHALT HW_REGISTER_RW(ARM_BASE+0x448)
  15454. +#define ARM_EH_PERIBURST 0x00000001 /* Burst write seen on peri bus */
  15455. +#define ARM_EH_ILLADDRS1 0x00000002 /* Address bits 25-27 error */
  15456. +#define ARM_EH_ILLADDRS2 0x00000004 /* Address bits 31-28 error */
  15457. +#define ARM_EH_VPU0HALT 0x00000008 /* VPU0 halted & in debug mode */
  15458. +#define ARM_EH_VPU1HALT 0x00000010 /* VPU1 halted & in debug mode */
  15459. +#define ARM_EH_ARMHALT 0x00000020 /* ARM in halted debug mode */
  15460. +
  15461. +#define ARM_ID_SECURE HW_REGISTER_RW(ARM_BASE+0x00C)
  15462. +#define ARM_ID HW_REGISTER_RW(ARM_BASE+0x44C)
  15463. +#define ARM_IDVAL 0x364D5241
  15464. +
  15465. +/* Translation memory */
  15466. +#define ARM_TRANSLATE HW_REGISTER_RW(ARM_BASE+0x100)
  15467. +/* 32 locations: 0x100.. 0x17F */
  15468. +/* 32 spare means we CAN go to 64 pages.... */
  15469. +
  15470. +
  15471. +/* Interrupts */
  15472. +#define ARM_IRQ_PEND0 HW_REGISTER_RW(ARM_BASE+0x200) /* Top IRQ bits */
  15473. +#define ARM_I0_TIMER 0x00000001 /* timer IRQ */
  15474. +#define ARM_I0_MAIL 0x00000002 /* Mail IRQ */
  15475. +#define ARM_I0_BELL0 0x00000004 /* Doorbell 0 */
  15476. +#define ARM_I0_BELL1 0x00000008 /* Doorbell 1 */
  15477. +#define ARM_I0_BANK1 0x00000100 /* Bank1 IRQ */
  15478. +#define ARM_I0_BANK2 0x00000200 /* Bank2 IRQ */
  15479. +
  15480. +#define ARM_IRQ_PEND1 HW_REGISTER_RW(ARM_BASE+0x204) /* All bank1 IRQ bits */
  15481. +/* todo: all I1_interrupt sources */
  15482. +#define ARM_IRQ_PEND2 HW_REGISTER_RW(ARM_BASE+0x208) /* All bank2 IRQ bits */
  15483. +/* todo: all I2_interrupt sources */
  15484. +
  15485. +#define ARM_IRQ_FAST HW_REGISTER_RW(ARM_BASE+0x20C) /* FIQ control */
  15486. +#define ARM_IF_INDEX 0x0000007F /* FIQ select */
  15487. +#define ARM_IF_ENABLE 0x00000080 /* FIQ enable */
  15488. +#define ARM_IF_VCMASK 0x0000003F /* FIQ = (index from VC source) */
  15489. +#define ARM_IF_TIMER 0x00000040 /* FIQ = ARM timer */
  15490. +#define ARM_IF_MAIL 0x00000041 /* FIQ = ARM Mail */
  15491. +#define ARM_IF_BELL0 0x00000042 /* FIQ = ARM Doorbell 0 */
  15492. +#define ARM_IF_BELL1 0x00000043 /* FIQ = ARM Doorbell 1 */
  15493. +#define ARM_IF_VP0HALT 0x00000044 /* FIQ = VPU0 Halt seen */
  15494. +#define ARM_IF_VP1HALT 0x00000045 /* FIQ = VPU1 Halt seen */
  15495. +#define ARM_IF_ILLEGAL 0x00000046 /* FIQ = Illegal access seen */
  15496. +
  15497. +#define ARM_IRQ_ENBL1 HW_REGISTER_RW(ARM_BASE+0x210) /* Bank1 enable bits */
  15498. +#define ARM_IRQ_ENBL2 HW_REGISTER_RW(ARM_BASE+0x214) /* Bank2 enable bits */
  15499. +#define ARM_IRQ_ENBL3 HW_REGISTER_RW(ARM_BASE+0x218) /* ARM irqs enable bits */
  15500. +#define ARM_IRQ_DIBL1 HW_REGISTER_RW(ARM_BASE+0x21C) /* Bank1 disable bits */
  15501. +#define ARM_IRQ_DIBL2 HW_REGISTER_RW(ARM_BASE+0x220) /* Bank2 disable bits */
  15502. +#define ARM_IRQ_DIBL3 HW_REGISTER_RW(ARM_BASE+0x224) /* ARM irqs disable bits */
  15503. +#define ARM_IE_TIMER 0x00000001 /* Timer IRQ */
  15504. +#define ARM_IE_MAIL 0x00000002 /* Mail IRQ */
  15505. +#define ARM_IE_BELL0 0x00000004 /* Doorbell 0 */
  15506. +#define ARM_IE_BELL1 0x00000008 /* Doorbell 1 */
  15507. +#define ARM_IE_VP0HALT 0x00000010 /* VPU0 Halt */
  15508. +#define ARM_IE_VP1HALT 0x00000020 /* VPU1 Halt */
  15509. +#define ARM_IE_ILLEGAL 0x00000040 /* Illegal access seen */
  15510. +
  15511. +/* Timer */
  15512. +/* For reg. fields see sp804 spec. */
  15513. +#define ARM_T_LOAD HW_REGISTER_RW(ARM_BASE+0x400)
  15514. +#define ARM_T_VALUE HW_REGISTER_RW(ARM_BASE+0x404)
  15515. +#define ARM_T_CONTROL HW_REGISTER_RW(ARM_BASE+0x408)
  15516. +#define ARM_T_IRQCNTL HW_REGISTER_RW(ARM_BASE+0x40C)
  15517. +#define ARM_T_RAWIRQ HW_REGISTER_RW(ARM_BASE+0x410)
  15518. +#define ARM_T_MSKIRQ HW_REGISTER_RW(ARM_BASE+0x414)
  15519. +#define ARM_T_RELOAD HW_REGISTER_RW(ARM_BASE+0x418)
  15520. +#define ARM_T_PREDIV HW_REGISTER_RW(ARM_BASE+0x41c)
  15521. +#define ARM_T_FREECNT HW_REGISTER_RW(ARM_BASE+0x420)
  15522. +
  15523. +#define TIMER_CTRL_ONESHOT (1 << 0)
  15524. +#define TIMER_CTRL_32BIT (1 << 1)
  15525. +#define TIMER_CTRL_DIV1 (0 << 2)
  15526. +#define TIMER_CTRL_DIV16 (1 << 2)
  15527. +#define TIMER_CTRL_DIV256 (2 << 2)
  15528. +#define TIMER_CTRL_IE (1 << 5)
  15529. +#define TIMER_CTRL_PERIODIC (1 << 6)
  15530. +#define TIMER_CTRL_ENABLE (1 << 7)
  15531. +#define TIMER_CTRL_DBGHALT (1 << 8)
  15532. +#define TIMER_CTRL_ENAFREE (1 << 9)
  15533. +#define TIMER_CTRL_FREEDIV_SHIFT 16)
  15534. +#define TIMER_CTRL_FREEDIV_MASK 0xff
  15535. +
  15536. +/* Semaphores, Doorbells, Mailboxes */
  15537. +#define ARM_SBM_OWN0 (ARM_BASE+0x800)
  15538. +#define ARM_SBM_OWN1 (ARM_BASE+0x900)
  15539. +#define ARM_SBM_OWN2 (ARM_BASE+0xA00)
  15540. +#define ARM_SBM_OWN3 (ARM_BASE+0xB00)
  15541. +
  15542. +/* MAILBOXES
  15543. + * Register flags are common across all
  15544. + * owner registers. See end of this section
  15545. + *
  15546. + * Semaphores, Doorbells, Mailboxes Owner 0
  15547. + *
  15548. + */
  15549. +
  15550. +#define ARM_0_SEMS HW_REGISTER_RW(ARM_SBM_OWN0+0x00)
  15551. +#define ARM_0_SEM0 HW_REGISTER_RW(ARM_SBM_OWN0+0x00)
  15552. +#define ARM_0_SEM1 HW_REGISTER_RW(ARM_SBM_OWN0+0x04)
  15553. +#define ARM_0_SEM2 HW_REGISTER_RW(ARM_SBM_OWN0+0x08)
  15554. +#define ARM_0_SEM3 HW_REGISTER_RW(ARM_SBM_OWN0+0x0C)
  15555. +#define ARM_0_SEM4 HW_REGISTER_RW(ARM_SBM_OWN0+0x10)
  15556. +#define ARM_0_SEM5 HW_REGISTER_RW(ARM_SBM_OWN0+0x14)
  15557. +#define ARM_0_SEM6 HW_REGISTER_RW(ARM_SBM_OWN0+0x18)
  15558. +#define ARM_0_SEM7 HW_REGISTER_RW(ARM_SBM_OWN0+0x1C)
  15559. +#define ARM_0_BELL0 HW_REGISTER_RW(ARM_SBM_OWN0+0x40)
  15560. +#define ARM_0_BELL1 HW_REGISTER_RW(ARM_SBM_OWN0+0x44)
  15561. +#define ARM_0_BELL2 HW_REGISTER_RW(ARM_SBM_OWN0+0x48)
  15562. +#define ARM_0_BELL3 HW_REGISTER_RW(ARM_SBM_OWN0+0x4C)
  15563. +/* MAILBOX 0 access in Owner 0 area */
  15564. +/* Some addresses should ONLY be used by owner 0 */
  15565. +#define ARM_0_MAIL0_WRT HW_REGISTER_RW(ARM_SBM_OWN0+0x80) /* .. 0x8C (4 locations) */
  15566. +#define ARM_0_MAIL0_RD HW_REGISTER_RW(ARM_SBM_OWN0+0x80) /* .. 0x8C (4 locations) Normal read */
  15567. +#define ARM_0_MAIL0_POL HW_REGISTER_RW(ARM_SBM_OWN0+0x90) /* none-pop read */
  15568. +#define ARM_0_MAIL0_SND HW_REGISTER_RW(ARM_SBM_OWN0+0x94) /* Sender read (only LS 2 bits) */
  15569. +#define ARM_0_MAIL0_STA HW_REGISTER_RW(ARM_SBM_OWN0+0x98) /* Status read */
  15570. +#define ARM_0_MAIL0_CNF HW_REGISTER_RW(ARM_SBM_OWN0+0x9C) /* Config read/write */
  15571. +/* MAILBOX 1 access in Owner 0 area */
  15572. +/* Owner 0 should only WRITE to this mailbox */
  15573. +#define ARM_0_MAIL1_WRT HW_REGISTER_RW(ARM_SBM_OWN0+0xA0) /* .. 0xAC (4 locations) */
  15574. +/*#define ARM_0_MAIL1_RD HW_REGISTER_RW(ARM_SBM_OWN0+0xA0) */ /* DO NOT USE THIS !!!!! */
  15575. +/*#define ARM_0_MAIL1_POL HW_REGISTER_RW(ARM_SBM_OWN0+0xB0) */ /* DO NOT USE THIS !!!!! */
  15576. +/*#define ARM_0_MAIL1_SND HW_REGISTER_RW(ARM_SBM_OWN0+0xB4) */ /* DO NOT USE THIS !!!!! */
  15577. +#define ARM_0_MAIL1_STA HW_REGISTER_RW(ARM_SBM_OWN0+0xB8) /* Status read */
  15578. +/*#define ARM_0_MAIL1_CNF HW_REGISTER_RW(ARM_SBM_OWN0+0xBC) */ /* DO NOT USE THIS !!!!! */
  15579. +/* General SEM, BELL, MAIL config/status */
  15580. +#define ARM_0_SEMCLRDBG HW_REGISTER_RW(ARM_SBM_OWN0+0xE0) /* semaphore clear/debug register */
  15581. +#define ARM_0_BELLCLRDBG HW_REGISTER_RW(ARM_SBM_OWN0+0xE4) /* Doorbells clear/debug register */
  15582. +#define ARM_0_ALL_IRQS HW_REGISTER_RW(ARM_SBM_OWN0+0xF8) /* ALL interrupts */
  15583. +#define ARM_0_MY_IRQS HW_REGISTER_RW(ARM_SBM_OWN0+0xFC) /* IRQS pending for owner 0 */
  15584. +
  15585. +/* Semaphores, Doorbells, Mailboxes Owner 1 */
  15586. +#define ARM_1_SEMS HW_REGISTER_RW(ARM_SBM_OWN1+0x00)
  15587. +#define ARM_1_SEM0 HW_REGISTER_RW(ARM_SBM_OWN1+0x00)
  15588. +#define ARM_1_SEM1 HW_REGISTER_RW(ARM_SBM_OWN1+0x04)
  15589. +#define ARM_1_SEM2 HW_REGISTER_RW(ARM_SBM_OWN1+0x08)
  15590. +#define ARM_1_SEM3 HW_REGISTER_RW(ARM_SBM_OWN1+0x0C)
  15591. +#define ARM_1_SEM4 HW_REGISTER_RW(ARM_SBM_OWN1+0x10)
  15592. +#define ARM_1_SEM5 HW_REGISTER_RW(ARM_SBM_OWN1+0x14)
  15593. +#define ARM_1_SEM6 HW_REGISTER_RW(ARM_SBM_OWN1+0x18)
  15594. +#define ARM_1_SEM7 HW_REGISTER_RW(ARM_SBM_OWN1+0x1C)
  15595. +#define ARM_1_BELL0 HW_REGISTER_RW(ARM_SBM_OWN1+0x40)
  15596. +#define ARM_1_BELL1 HW_REGISTER_RW(ARM_SBM_OWN1+0x44)
  15597. +#define ARM_1_BELL2 HW_REGISTER_RW(ARM_SBM_OWN1+0x48)
  15598. +#define ARM_1_BELL3 HW_REGISTER_RW(ARM_SBM_OWN1+0x4C)
  15599. +/* MAILBOX 0 access in Owner 0 area */
  15600. +/* Owner 1 should only WRITE to this mailbox */
  15601. +#define ARM_1_MAIL0_WRT HW_REGISTER_RW(ARM_SBM_OWN1+0x80) /* .. 0x8C (4 locations) */
  15602. +/*#define ARM_1_MAIL0_RD HW_REGISTER_RW(ARM_SBM_OWN1+0x80) */ /* DO NOT USE THIS !!!!! */
  15603. +/*#define ARM_1_MAIL0_POL HW_REGISTER_RW(ARM_SBM_OWN1+0x90) */ /* DO NOT USE THIS !!!!! */
  15604. +/*#define ARM_1_MAIL0_SND HW_REGISTER_RW(ARM_SBM_OWN1+0x94) */ /* DO NOT USE THIS !!!!! */
  15605. +#define ARM_1_MAIL0_STA HW_REGISTER_RW(ARM_SBM_OWN1+0x98) /* Status read */
  15606. +/*#define ARM_1_MAIL0_CNF HW_REGISTER_RW(ARM_SBM_OWN1+0x9C) */ /* DO NOT USE THIS !!!!! */
  15607. +/* MAILBOX 1 access in Owner 0 area */
  15608. +#define ARM_1_MAIL1_WRT HW_REGISTER_RW(ARM_SBM_OWN1+0xA0) /* .. 0xAC (4 locations) */
  15609. +#define ARM_1_MAIL1_RD HW_REGISTER_RW(ARM_SBM_OWN1+0xA0) /* .. 0xAC (4 locations) Normal read */
  15610. +#define ARM_1_MAIL1_POL HW_REGISTER_RW(ARM_SBM_OWN1+0xB0) /* none-pop read */
  15611. +#define ARM_1_MAIL1_SND HW_REGISTER_RW(ARM_SBM_OWN1+0xB4) /* Sender read (only LS 2 bits) */
  15612. +#define ARM_1_MAIL1_STA HW_REGISTER_RW(ARM_SBM_OWN1+0xB8) /* Status read */
  15613. +#define ARM_1_MAIL1_CNF HW_REGISTER_RW(ARM_SBM_OWN1+0xBC)
  15614. +/* General SEM, BELL, MAIL config/status */
  15615. +#define ARM_1_SEMCLRDBG HW_REGISTER_RW(ARM_SBM_OWN1+0xE0) /* semaphore clear/debug register */
  15616. +#define ARM_1_BELLCLRDBG HW_REGISTER_RW(ARM_SBM_OWN1+0xE4) /* Doorbells clear/debug register */
  15617. +#define ARM_1_MY_IRQS HW_REGISTER_RW(ARM_SBM_OWN1+0xFC) /* IRQS pending for owner 1 */
  15618. +#define ARM_1_ALL_IRQS HW_REGISTER_RW(ARM_SBM_OWN1+0xF8) /* ALL interrupts */
  15619. +
  15620. +/* Semaphores, Doorbells, Mailboxes Owner 2 */
  15621. +#define ARM_2_SEMS HW_REGISTER_RW(ARM_SBM_OWN2+0x00)
  15622. +#define ARM_2_SEM0 HW_REGISTER_RW(ARM_SBM_OWN2+0x00)
  15623. +#define ARM_2_SEM1 HW_REGISTER_RW(ARM_SBM_OWN2+0x04)
  15624. +#define ARM_2_SEM2 HW_REGISTER_RW(ARM_SBM_OWN2+0x08)
  15625. +#define ARM_2_SEM3 HW_REGISTER_RW(ARM_SBM_OWN2+0x0C)
  15626. +#define ARM_2_SEM4 HW_REGISTER_RW(ARM_SBM_OWN2+0x10)
  15627. +#define ARM_2_SEM5 HW_REGISTER_RW(ARM_SBM_OWN2+0x14)
  15628. +#define ARM_2_SEM6 HW_REGISTER_RW(ARM_SBM_OWN2+0x18)
  15629. +#define ARM_2_SEM7 HW_REGISTER_RW(ARM_SBM_OWN2+0x1C)
  15630. +#define ARM_2_BELL0 HW_REGISTER_RW(ARM_SBM_OWN2+0x40)
  15631. +#define ARM_2_BELL1 HW_REGISTER_RW(ARM_SBM_OWN2+0x44)
  15632. +#define ARM_2_BELL2 HW_REGISTER_RW(ARM_SBM_OWN2+0x48)
  15633. +#define ARM_2_BELL3 HW_REGISTER_RW(ARM_SBM_OWN2+0x4C)
  15634. +/* MAILBOX 0 access in Owner 2 area */
  15635. +/* Owner 2 should only WRITE to this mailbox */
  15636. +#define ARM_2_MAIL0_WRT HW_REGISTER_RW(ARM_SBM_OWN2+0x80) /* .. 0x8C (4 locations) */
  15637. +/*#define ARM_2_MAIL0_RD HW_REGISTER_RW(ARM_SBM_OWN2+0x80) */ /* DO NOT USE THIS !!!!! */
  15638. +/*#define ARM_2_MAIL0_POL HW_REGISTER_RW(ARM_SBM_OWN2+0x90) */ /* DO NOT USE THIS !!!!! */
  15639. +/*#define ARM_2_MAIL0_SND HW_REGISTER_RW(ARM_SBM_OWN2+0x94) */ /* DO NOT USE THIS !!!!! */
  15640. +#define ARM_2_MAIL0_STA HW_REGISTER_RW(ARM_SBM_OWN2+0x98) /* Status read */
  15641. +/*#define ARM_2_MAIL0_CNF HW_REGISTER_RW(ARM_SBM_OWN2+0x9C) */ /* DO NOT USE THIS !!!!! */
  15642. +/* MAILBOX 1 access in Owner 2 area */
  15643. +/* Owner 2 should only WRITE to this mailbox */
  15644. +#define ARM_2_MAIL1_WRT HW_REGISTER_RW(ARM_SBM_OWN2+0xA0) /* .. 0xAC (4 locations) */
  15645. +/*#define ARM_2_MAIL1_RD HW_REGISTER_RW(ARM_SBM_OWN2+0xA0) */ /* DO NOT USE THIS !!!!! */
  15646. +/*#define ARM_2_MAIL1_POL HW_REGISTER_RW(ARM_SBM_OWN2+0xB0) */ /* DO NOT USE THIS !!!!! */
  15647. +/*#define ARM_2_MAIL1_SND HW_REGISTER_RW(ARM_SBM_OWN2+0xB4) */ /* DO NOT USE THIS !!!!! */
  15648. +#define ARM_2_MAIL1_STA HW_REGISTER_RW(ARM_SBM_OWN2+0xB8) /* Status read */
  15649. +/*#define ARM_2_MAIL1_CNF HW_REGISTER_RW(ARM_SBM_OWN2+0xBC) */ /* DO NOT USE THIS !!!!! */
  15650. +/* General SEM, BELL, MAIL config/status */
  15651. +#define ARM_2_SEMCLRDBG HW_REGISTER_RW(ARM_SBM_OWN2+0xE0) /* semaphore clear/debug register */
  15652. +#define ARM_2_BELLCLRDBG HW_REGISTER_RW(ARM_SBM_OWN2+0xE4) /* Doorbells clear/debug register */
  15653. +#define ARM_2_MY_IRQS HW_REGISTER_RW(ARM_SBM_OWN2+0xFC) /* IRQS pending for owner 2 */
  15654. +#define ARM_2_ALL_IRQS HW_REGISTER_RW(ARM_SBM_OWN2+0xF8) /* ALL interrupts */
  15655. +
  15656. +/* Semaphores, Doorbells, Mailboxes Owner 3 */
  15657. +#define ARM_3_SEMS HW_REGISTER_RW(ARM_SBM_OWN3+0x00)
  15658. +#define ARM_3_SEM0 HW_REGISTER_RW(ARM_SBM_OWN3+0x00)
  15659. +#define ARM_3_SEM1 HW_REGISTER_RW(ARM_SBM_OWN3+0x04)
  15660. +#define ARM_3_SEM2 HW_REGISTER_RW(ARM_SBM_OWN3+0x08)
  15661. +#define ARM_3_SEM3 HW_REGISTER_RW(ARM_SBM_OWN3+0x0C)
  15662. +#define ARM_3_SEM4 HW_REGISTER_RW(ARM_SBM_OWN3+0x10)
  15663. +#define ARM_3_SEM5 HW_REGISTER_RW(ARM_SBM_OWN3+0x14)
  15664. +#define ARM_3_SEM6 HW_REGISTER_RW(ARM_SBM_OWN3+0x18)
  15665. +#define ARM_3_SEM7 HW_REGISTER_RW(ARM_SBM_OWN3+0x1C)
  15666. +#define ARM_3_BELL0 HW_REGISTER_RW(ARM_SBM_OWN3+0x40)
  15667. +#define ARM_3_BELL1 HW_REGISTER_RW(ARM_SBM_OWN3+0x44)
  15668. +#define ARM_3_BELL2 HW_REGISTER_RW(ARM_SBM_OWN3+0x48)
  15669. +#define ARM_3_BELL3 HW_REGISTER_RW(ARM_SBM_OWN3+0x4C)
  15670. +/* MAILBOX 0 access in Owner 3 area */
  15671. +/* Owner 3 should only WRITE to this mailbox */
  15672. +#define ARM_3_MAIL0_WRT HW_REGISTER_RW(ARM_SBM_OWN3+0x80) /* .. 0x8C (4 locations) */
  15673. +/*#define ARM_3_MAIL0_RD HW_REGISTER_RW(ARM_SBM_OWN3+0x80) */ /* DO NOT USE THIS !!!!! */
  15674. +/*#define ARM_3_MAIL0_POL HW_REGISTER_RW(ARM_SBM_OWN3+0x90) */ /* DO NOT USE THIS !!!!! */
  15675. +/*#define ARM_3_MAIL0_SND HW_REGISTER_RW(ARM_SBM_OWN3+0x94) */ /* DO NOT USE THIS !!!!! */
  15676. +#define ARM_3_MAIL0_STA HW_REGISTER_RW(ARM_SBM_OWN3+0x98) /* Status read */
  15677. +/*#define ARM_3_MAIL0_CNF HW_REGISTER_RW(ARM_SBM_OWN3+0x9C) */ /* DO NOT USE THIS !!!!! */
  15678. +/* MAILBOX 1 access in Owner 3 area */
  15679. +/* Owner 3 should only WRITE to this mailbox */
  15680. +#define ARM_3_MAIL1_WRT HW_REGISTER_RW(ARM_SBM_OWN3+0xA0) /* .. 0xAC (4 locations) */
  15681. +/*#define ARM_3_MAIL1_RD HW_REGISTER_RW(ARM_SBM_OWN3+0xA0) */ /* DO NOT USE THIS !!!!! */
  15682. +/*#define ARM_3_MAIL1_POL HW_REGISTER_RW(ARM_SBM_OWN3+0xB0) */ /* DO NOT USE THIS !!!!! */
  15683. +/*#define ARM_3_MAIL1_SND HW_REGISTER_RW(ARM_SBM_OWN3+0xB4) */ /* DO NOT USE THIS !!!!! */
  15684. +#define ARM_3_MAIL1_STA HW_REGISTER_RW(ARM_SBM_OWN3+0xB8) /* Status read */
  15685. +/*#define ARM_3_MAIL1_CNF HW_REGISTER_RW(ARM_SBM_OWN3+0xBC) */ /* DO NOT USE THIS !!!!! */
  15686. +/* General SEM, BELL, MAIL config/status */
  15687. +#define ARM_3_SEMCLRDBG HW_REGISTER_RW(ARM_SBM_OWN3+0xE0) /* semaphore clear/debug register */
  15688. +#define ARM_3_BELLCLRDBG HW_REGISTER_RW(ARM_SBM_OWN3+0xE4) /* Doorbells clear/debug register */
  15689. +#define ARM_3_MY_IRQS HW_REGISTER_RW(ARM_SBM_OWN3+0xFC) /* IRQS pending for owner 3 */
  15690. +#define ARM_3_ALL_IRQS HW_REGISTER_RW(ARM_SBM_OWN3+0xF8) /* ALL interrupts */
  15691. +
  15692. +
  15693. +
  15694. +/* Mailbox flags. Valid for all owners */
  15695. +
  15696. +/* Mailbox status register (...0x98) */
  15697. +#define ARM_MS_FULL 0x80000000
  15698. +#define ARM_MS_EMPTY 0x40000000
  15699. +#define ARM_MS_LEVEL 0x400000FF /* Max. value depdnds on mailbox depth parameter */
  15700. +
  15701. +/* MAILBOX config/status register (...0x9C) */
  15702. +/* ANY write to this register clears the error bits! */
  15703. +#define ARM_MC_IHAVEDATAIRQEN 0x00000001 /* mailbox irq enable: has data */
  15704. +#define ARM_MC_IHAVESPACEIRQEN 0x00000002 /* mailbox irq enable: has space */
  15705. +#define ARM_MC_OPPISEMPTYIRQEN 0x00000004 /* mailbox irq enable: Opp. is empty */
  15706. +#define ARM_MC_MAIL_CLEAR 0x00000008 /* mailbox clear write 1, then 0 */
  15707. +#define ARM_MC_IHAVEDATAIRQPEND 0x00000010 /* mailbox irq pending: has space */
  15708. +#define ARM_MC_IHAVESPACEIRQPEND 0x00000020 /* mailbox irq pending: Opp. is empty */
  15709. +#define ARM_MC_OPPISEMPTYIRQPEND 0x00000040 /* mailbox irq pending */
  15710. +/* Bit 7 is unused */
  15711. +#define ARM_MC_ERRNOOWN 0x00000100 /* error : none owner read from mailbox */
  15712. +#define ARM_MC_ERROVERFLW 0x00000200 /* error : write to fill mailbox */
  15713. +#define ARM_MC_ERRUNDRFLW 0x00000400 /* error : read from empty mailbox */
  15714. +
  15715. +/* Semaphore clear/debug register (...0xE0) */
  15716. +#define ARM_SD_OWN0 0x00000003 /* Owner of sem 0 */
  15717. +#define ARM_SD_OWN1 0x0000000C /* Owner of sem 1 */
  15718. +#define ARM_SD_OWN2 0x00000030 /* Owner of sem 2 */
  15719. +#define ARM_SD_OWN3 0x000000C0 /* Owner of sem 3 */
  15720. +#define ARM_SD_OWN4 0x00000300 /* Owner of sem 4 */
  15721. +#define ARM_SD_OWN5 0x00000C00 /* Owner of sem 5 */
  15722. +#define ARM_SD_OWN6 0x00003000 /* Owner of sem 6 */
  15723. +#define ARM_SD_OWN7 0x0000C000 /* Owner of sem 7 */
  15724. +#define ARM_SD_SEM0 0x00010000 /* Status of sem 0 */
  15725. +#define ARM_SD_SEM1 0x00020000 /* Status of sem 1 */
  15726. +#define ARM_SD_SEM2 0x00040000 /* Status of sem 2 */
  15727. +#define ARM_SD_SEM3 0x00080000 /* Status of sem 3 */
  15728. +#define ARM_SD_SEM4 0x00100000 /* Status of sem 4 */
  15729. +#define ARM_SD_SEM5 0x00200000 /* Status of sem 5 */
  15730. +#define ARM_SD_SEM6 0x00400000 /* Status of sem 6 */
  15731. +#define ARM_SD_SEM7 0x00800000 /* Status of sem 7 */
  15732. +
  15733. +/* Doorbells clear/debug register (...0xE4) */
  15734. +#define ARM_BD_OWN0 0x00000003 /* Owner of doorbell 0 */
  15735. +#define ARM_BD_OWN1 0x0000000C /* Owner of doorbell 1 */
  15736. +#define ARM_BD_OWN2 0x00000030 /* Owner of doorbell 2 */
  15737. +#define ARM_BD_OWN3 0x000000C0 /* Owner of doorbell 3 */
  15738. +#define ARM_BD_BELL0 0x00000100 /* Status of doorbell 0 */
  15739. +#define ARM_BD_BELL1 0x00000200 /* Status of doorbell 1 */
  15740. +#define ARM_BD_BELL2 0x00000400 /* Status of doorbell 2 */
  15741. +#define ARM_BD_BELL3 0x00000800 /* Status of doorbell 3 */
  15742. +
  15743. +/* MY IRQS register (...0xF8) */
  15744. +#define ARM_MYIRQ_BELL 0x00000001 /* This owner has a doorbell IRQ */
  15745. +#define ARM_MYIRQ_MAIL 0x00000002 /* This owner has a mailbox IRQ */
  15746. +
  15747. +/* ALL IRQS register (...0xF8) */
  15748. +#define ARM_AIS_BELL0 0x00000001 /* Doorbell 0 IRQ pending */
  15749. +#define ARM_AIS_BELL1 0x00000002 /* Doorbell 1 IRQ pending */
  15750. +#define ARM_AIS_BELL2 0x00000004 /* Doorbell 2 IRQ pending */
  15751. +#define ARM_AIS_BELL3 0x00000008 /* Doorbell 3 IRQ pending */
  15752. +#define ARM_AIS0_HAVEDATA 0x00000010 /* MAIL 0 has data IRQ pending */
  15753. +#define ARM_AIS0_HAVESPAC 0x00000020 /* MAIL 0 has space IRQ pending */
  15754. +#define ARM_AIS0_OPPEMPTY 0x00000040 /* MAIL 0 opposite is empty IRQ */
  15755. +#define ARM_AIS1_HAVEDATA 0x00000080 /* MAIL 1 has data IRQ pending */
  15756. +#define ARM_AIS1_HAVESPAC 0x00000100 /* MAIL 1 has space IRQ pending */
  15757. +#define ARM_AIS1_OPPEMPTY 0x00000200 /* MAIL 1 opposite is empty IRQ */
  15758. +/* Note that bell-0, bell-1 and MAIL0 IRQ go only to the ARM */
  15759. +/* Whilst that bell-2, bell-3 and MAIL1 IRQ go only to the VC */
  15760. +/* */
  15761. +/* ARM JTAG BASH */
  15762. +/* */
  15763. +#define AJB_BASE 0x7e2000c0
  15764. +
  15765. +#define AJBCONF HW_REGISTER_RW(AJB_BASE+0x00)
  15766. +#define AJB_BITS0 0x000000
  15767. +#define AJB_BITS4 0x000004
  15768. +#define AJB_BITS8 0x000008
  15769. +#define AJB_BITS12 0x00000C
  15770. +#define AJB_BITS16 0x000010
  15771. +#define AJB_BITS20 0x000014
  15772. +#define AJB_BITS24 0x000018
  15773. +#define AJB_BITS28 0x00001C
  15774. +#define AJB_BITS32 0x000020
  15775. +#define AJB_BITS34 0x000022
  15776. +#define AJB_OUT_MS 0x000040
  15777. +#define AJB_OUT_LS 0x000000
  15778. +#define AJB_INV_CLK 0x000080
  15779. +#define AJB_D0_RISE 0x000100
  15780. +#define AJB_D0_FALL 0x000000
  15781. +#define AJB_D1_RISE 0x000200
  15782. +#define AJB_D1_FALL 0x000000
  15783. +#define AJB_IN_RISE 0x000400
  15784. +#define AJB_IN_FALL 0x000000
  15785. +#define AJB_ENABLE 0x000800
  15786. +#define AJB_HOLD0 0x000000
  15787. +#define AJB_HOLD1 0x001000
  15788. +#define AJB_HOLD2 0x002000
  15789. +#define AJB_HOLD3 0x003000
  15790. +#define AJB_RESETN 0x004000
  15791. +#define AJB_CLKSHFT 16
  15792. +#define AJB_BUSY 0x80000000
  15793. +#define AJBTMS HW_REGISTER_RW(AJB_BASE+0x04)
  15794. +#define AJBTDI HW_REGISTER_RW(AJB_BASE+0x08)
  15795. +#define AJBTDO HW_REGISTER_RW(AJB_BASE+0x0c)
  15796. +
  15797. +#define ARM_LOCAL_BASE 0x40000000
  15798. +#define ARM_LOCAL_CONTROL HW_REGISTER_RW(ARM_LOCAL_BASE+0x000)
  15799. +#define ARM_LOCAL_PRESCALER HW_REGISTER_RW(ARM_LOCAL_BASE+0x008)
  15800. +#define ARM_LOCAL_GPU_INT_ROUTING HW_REGISTER_RW(ARM_LOCAL_BASE+0x00C)
  15801. +#define ARM_LOCAL_PM_ROUTING_SET HW_REGISTER_RW(ARM_LOCAL_BASE+0x010)
  15802. +#define ARM_LOCAL_PM_ROUTING_CLR HW_REGISTER_RW(ARM_LOCAL_BASE+0x014)
  15803. +#define ARM_LOCAL_TIMER_LS HW_REGISTER_RW(ARM_LOCAL_BASE+0x01C)
  15804. +#define ARM_LOCAL_TIMER_MS HW_REGISTER_RW(ARM_LOCAL_BASE+0x020)
  15805. +#define ARM_LOCAL_INT_ROUTING HW_REGISTER_RW(ARM_LOCAL_BASE+0x024)
  15806. +#define ARM_LOCAL_AXI_COUNT HW_REGISTER_RW(ARM_LOCAL_BASE+0x02C)
  15807. +#define ARM_LOCAL_AXI_IRQ HW_REGISTER_RW(ARM_LOCAL_BASE+0x030)
  15808. +#define ARM_LOCAL_TIMER_CONTROL HW_REGISTER_RW(ARM_LOCAL_BASE+0x034)
  15809. +#define ARM_LOCAL_TIMER_WRITE HW_REGISTER_RW(ARM_LOCAL_BASE+0x038)
  15810. +
  15811. +#define ARM_LOCAL_TIMER_INT_CONTROL0 HW_REGISTER_RW(ARM_LOCAL_BASE+0x040)
  15812. +#define ARM_LOCAL_TIMER_INT_CONTROL1 HW_REGISTER_RW(ARM_LOCAL_BASE+0x044)
  15813. +#define ARM_LOCAL_TIMER_INT_CONTROL2 HW_REGISTER_RW(ARM_LOCAL_BASE+0x048)
  15814. +#define ARM_LOCAL_TIMER_INT_CONTROL3 HW_REGISTER_RW(ARM_LOCAL_BASE+0x04C)
  15815. +
  15816. +#define ARM_LOCAL_MAILBOX_INT_CONTROL0 HW_REGISTER_RW(ARM_LOCAL_BASE+0x050)
  15817. +#define ARM_LOCAL_MAILBOX_INT_CONTROL1 HW_REGISTER_RW(ARM_LOCAL_BASE+0x054)
  15818. +#define ARM_LOCAL_MAILBOX_INT_CONTROL2 HW_REGISTER_RW(ARM_LOCAL_BASE+0x058)
  15819. +#define ARM_LOCAL_MAILBOX_INT_CONTROL3 HW_REGISTER_RW(ARM_LOCAL_BASE+0x05C)
  15820. +
  15821. +#define ARM_LOCAL_IRQ_PENDING0 HW_REGISTER_RW(ARM_LOCAL_BASE+0x060)
  15822. +#define ARM_LOCAL_IRQ_PENDING1 HW_REGISTER_RW(ARM_LOCAL_BASE+0x064)
  15823. +#define ARM_LOCAL_IRQ_PENDING2 HW_REGISTER_RW(ARM_LOCAL_BASE+0x068)
  15824. +#define ARM_LOCAL_IRQ_PENDING3 HW_REGISTER_RW(ARM_LOCAL_BASE+0x06C)
  15825. +
  15826. +#define ARM_LOCAL_FIQ_PENDING0 HW_REGISTER_RW(ARM_LOCAL_BASE+0x070)
  15827. +#define ARM_LOCAL_FIQ_PENDING1 HW_REGISTER_RW(ARM_LOCAL_BASE+0x074)
  15828. +#define ARM_LOCAL_FIQ_PENDING2 HW_REGISTER_RW(ARM_LOCAL_BASE+0x078)
  15829. +#define ARM_LOCAL_FIQ_PENDING3 HW_REGISTER_RW(ARM_LOCAL_BASE+0x07C)
  15830. +
  15831. +#define ARM_LOCAL_MAILBOX0_SET0 HW_REGISTER_RW(ARM_LOCAL_BASE+0x080)
  15832. +#define ARM_LOCAL_MAILBOX1_SET0 HW_REGISTER_RW(ARM_LOCAL_BASE+0x084)
  15833. +#define ARM_LOCAL_MAILBOX2_SET0 HW_REGISTER_RW(ARM_LOCAL_BASE+0x088)
  15834. +#define ARM_LOCAL_MAILBOX3_SET0 HW_REGISTER_RW(ARM_LOCAL_BASE+0x08C)
  15835. +
  15836. +#define ARM_LOCAL_MAILBOX0_SET1 HW_REGISTER_RW(ARM_LOCAL_BASE+0x090)
  15837. +#define ARM_LOCAL_MAILBOX1_SET1 HW_REGISTER_RW(ARM_LOCAL_BASE+0x094)
  15838. +#define ARM_LOCAL_MAILBOX2_SET1 HW_REGISTER_RW(ARM_LOCAL_BASE+0x098)
  15839. +#define ARM_LOCAL_MAILBOX3_SET1 HW_REGISTER_RW(ARM_LOCAL_BASE+0x09C)
  15840. +
  15841. +#define ARM_LOCAL_MAILBOX0_SET2 HW_REGISTER_RW(ARM_LOCAL_BASE+0x0A0)
  15842. +#define ARM_LOCAL_MAILBOX1_SET2 HW_REGISTER_RW(ARM_LOCAL_BASE+0x0A4)
  15843. +#define ARM_LOCAL_MAILBOX2_SET2 HW_REGISTER_RW(ARM_LOCAL_BASE+0x0A8)
  15844. +#define ARM_LOCAL_MAILBOX3_SET2 HW_REGISTER_RW(ARM_LOCAL_BASE+0x0AC)
  15845. +
  15846. +#define ARM_LOCAL_MAILBOX0_SET3 HW_REGISTER_RW(ARM_LOCAL_BASE+0x0B0)
  15847. +#define ARM_LOCAL_MAILBOX1_SET3 HW_REGISTER_RW(ARM_LOCAL_BASE+0x0B4)
  15848. +#define ARM_LOCAL_MAILBOX2_SET3 HW_REGISTER_RW(ARM_LOCAL_BASE+0x0B8)
  15849. +#define ARM_LOCAL_MAILBOX3_SET3 HW_REGISTER_RW(ARM_LOCAL_BASE+0x0BC)
  15850. +
  15851. +#define ARM_LOCAL_MAILBOX0_CLR0 HW_REGISTER_RW(ARM_LOCAL_BASE+0x0C0)
  15852. +#define ARM_LOCAL_MAILBOX1_CLR0 HW_REGISTER_RW(ARM_LOCAL_BASE+0x0C4)
  15853. +#define ARM_LOCAL_MAILBOX2_CLR0 HW_REGISTER_RW(ARM_LOCAL_BASE+0x0C8)
  15854. +#define ARM_LOCAL_MAILBOX3_CLR0 HW_REGISTER_RW(ARM_LOCAL_BASE+0x0CC)
  15855. +
  15856. +#define ARM_LOCAL_MAILBOX0_CLR1 HW_REGISTER_RW(ARM_LOCAL_BASE+0x0D0)
  15857. +#define ARM_LOCAL_MAILBOX1_CLR1 HW_REGISTER_RW(ARM_LOCAL_BASE+0x0D4)
  15858. +#define ARM_LOCAL_MAILBOX2_CLR1 HW_REGISTER_RW(ARM_LOCAL_BASE+0x0D8)
  15859. +#define ARM_LOCAL_MAILBOX3_CLR1 HW_REGISTER_RW(ARM_LOCAL_BASE+0x0DC)
  15860. +
  15861. +#define ARM_LOCAL_MAILBOX0_CLR2 HW_REGISTER_RW(ARM_LOCAL_BASE+0x0E0)
  15862. +#define ARM_LOCAL_MAILBOX1_CLR2 HW_REGISTER_RW(ARM_LOCAL_BASE+0x0E4)
  15863. +#define ARM_LOCAL_MAILBOX2_CLR2 HW_REGISTER_RW(ARM_LOCAL_BASE+0x0E8)
  15864. +#define ARM_LOCAL_MAILBOX3_CLR2 HW_REGISTER_RW(ARM_LOCAL_BASE+0x0EC)
  15865. +
  15866. +#define ARM_LOCAL_MAILBOX0_CLR3 HW_REGISTER_RW(ARM_LOCAL_BASE+0x0F0)
  15867. +#define ARM_LOCAL_MAILBOX1_CLR3 HW_REGISTER_RW(ARM_LOCAL_BASE+0x0F4)
  15868. +#define ARM_LOCAL_MAILBOX2_CLR3 HW_REGISTER_RW(ARM_LOCAL_BASE+0x0F8)
  15869. +#define ARM_LOCAL_MAILBOX3_CLR3 HW_REGISTER_RW(ARM_LOCAL_BASE+0x0FC)
  15870. +
  15871. +#endif
  15872. diff -Nur linux-3.18.8/arch/arm/mach-bcm2709/include/mach/arm_power.h linux-rpi/arch/arm/mach-bcm2709/include/mach/arm_power.h
  15873. --- linux-3.18.8/arch/arm/mach-bcm2709/include/mach/arm_power.h 1970-01-01 01:00:00.000000000 +0100
  15874. +++ linux-rpi/arch/arm/mach-bcm2709/include/mach/arm_power.h 2015-03-05 14:40:11.153715839 +0100
  15875. @@ -0,0 +1,62 @@
  15876. +/*
  15877. + * linux/arch/arm/mach-bcm2708/include/mach/arm_power.h
  15878. + *
  15879. + * Copyright (C) 2010 Broadcom
  15880. + *
  15881. + * This program is free software; you can redistribute it and/or modify
  15882. + * it under the terms of the GNU General Public License as published by
  15883. + * the Free Software Foundation; either version 2 of the License, or
  15884. + * (at your option) any later version.
  15885. + *
  15886. + * This program is distributed in the hope that it will be useful,
  15887. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15888. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15889. + * GNU General Public License for more details.
  15890. + *
  15891. + * You should have received a copy of the GNU General Public License
  15892. + * along with this program; if not, write to the Free Software
  15893. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  15894. + */
  15895. +
  15896. +#ifndef _ARM_POWER_H
  15897. +#define _ARM_POWER_H
  15898. +
  15899. +/* Use meaningful names on each side */
  15900. +#ifdef __VIDEOCORE__
  15901. +#define PREFIX(x) ARM_##x
  15902. +#else
  15903. +#define PREFIX(x) BCM_##x
  15904. +#endif
  15905. +
  15906. +enum {
  15907. + PREFIX(POWER_SDCARD_BIT),
  15908. + PREFIX(POWER_UART_BIT),
  15909. + PREFIX(POWER_MINIUART_BIT),
  15910. + PREFIX(POWER_USB_BIT),
  15911. + PREFIX(POWER_I2C0_BIT),
  15912. + PREFIX(POWER_I2C1_BIT),
  15913. + PREFIX(POWER_I2C2_BIT),
  15914. + PREFIX(POWER_SPI_BIT),
  15915. + PREFIX(POWER_CCP2TX_BIT),
  15916. + PREFIX(POWER_DSI_BIT),
  15917. +
  15918. + PREFIX(POWER_MAX)
  15919. +};
  15920. +
  15921. +enum {
  15922. + PREFIX(POWER_SDCARD) = (1 << PREFIX(POWER_SDCARD_BIT)),
  15923. + PREFIX(POWER_UART) = (1 << PREFIX(POWER_UART_BIT)),
  15924. + PREFIX(POWER_MINIUART) = (1 << PREFIX(POWER_MINIUART_BIT)),
  15925. + PREFIX(POWER_USB) = (1 << PREFIX(POWER_USB_BIT)),
  15926. + PREFIX(POWER_I2C0) = (1 << PREFIX(POWER_I2C0_BIT)),
  15927. + PREFIX(POWER_I2C1_MASK) = (1 << PREFIX(POWER_I2C1_BIT)),
  15928. + PREFIX(POWER_I2C2_MASK) = (1 << PREFIX(POWER_I2C2_BIT)),
  15929. + PREFIX(POWER_SPI_MASK) = (1 << PREFIX(POWER_SPI_BIT)),
  15930. + PREFIX(POWER_CCP2TX_MASK) = (1 << PREFIX(POWER_CCP2TX_BIT)),
  15931. + PREFIX(POWER_DSI) = (1 << PREFIX(POWER_DSI_BIT)),
  15932. +
  15933. + PREFIX(POWER_MASK) = (1 << PREFIX(POWER_MAX)) - 1,
  15934. + PREFIX(POWER_NONE) = 0
  15935. +};
  15936. +
  15937. +#endif
  15938. diff -Nur linux-3.18.8/arch/arm/mach-bcm2709/include/mach/barriers.h linux-rpi/arch/arm/mach-bcm2709/include/mach/barriers.h
  15939. --- linux-3.18.8/arch/arm/mach-bcm2709/include/mach/barriers.h 1970-01-01 01:00:00.000000000 +0100
  15940. +++ linux-rpi/arch/arm/mach-bcm2709/include/mach/barriers.h 2015-03-05 14:40:11.153715839 +0100
  15941. @@ -0,0 +1,3 @@
  15942. +#define mb() dsb()
  15943. +#define rmb() dsb()
  15944. +#define wmb() mb()
  15945. diff -Nur linux-3.18.8/arch/arm/mach-bcm2709/include/mach/clkdev.h linux-rpi/arch/arm/mach-bcm2709/include/mach/clkdev.h
  15946. --- linux-3.18.8/arch/arm/mach-bcm2709/include/mach/clkdev.h 1970-01-01 01:00:00.000000000 +0100
  15947. +++ linux-rpi/arch/arm/mach-bcm2709/include/mach/clkdev.h 2015-03-05 14:40:11.153715839 +0100
  15948. @@ -0,0 +1,7 @@
  15949. +#ifndef __ASM_MACH_CLKDEV_H
  15950. +#define __ASM_MACH_CLKDEV_H
  15951. +
  15952. +#define __clk_get(clk) ({ 1; })
  15953. +#define __clk_put(clk) do { } while (0)
  15954. +
  15955. +#endif
  15956. diff -Nur linux-3.18.8/arch/arm/mach-bcm2709/include/mach/debug-macro.S linux-rpi/arch/arm/mach-bcm2709/include/mach/debug-macro.S
  15957. --- linux-3.18.8/arch/arm/mach-bcm2709/include/mach/debug-macro.S 1970-01-01 01:00:00.000000000 +0100
  15958. +++ linux-rpi/arch/arm/mach-bcm2709/include/mach/debug-macro.S 2015-03-05 14:40:11.153715839 +0100
  15959. @@ -0,0 +1,22 @@
  15960. +/* arch/arm/mach-bcm2708/include/mach/debug-macro.S
  15961. + *
  15962. + * Debugging macro include header
  15963. + *
  15964. + * Copyright (C) 2010 Broadcom
  15965. + * Copyright (C) 1994-1999 Russell King
  15966. + * Moved from linux/arch/arm/kernel/debug.S by Ben Dooks
  15967. + *
  15968. + * This program is free software; you can redistribute it and/or modify
  15969. + * it under the terms of the GNU General Public License version 2 as
  15970. + * published by the Free Software Foundation.
  15971. + *
  15972. +*/
  15973. +
  15974. +#include <mach/platform.h>
  15975. +
  15976. + .macro addruart, rp, rv, tmp
  15977. + ldr \rp, =UART0_BASE
  15978. + ldr \rv, =IO_ADDRESS(UART0_BASE)
  15979. + .endm
  15980. +
  15981. +#include <debug/pl01x.S>
  15982. diff -Nur linux-3.18.8/arch/arm/mach-bcm2709/include/mach/dma.h linux-rpi/arch/arm/mach-bcm2709/include/mach/dma.h
  15983. --- linux-3.18.8/arch/arm/mach-bcm2709/include/mach/dma.h 1970-01-01 01:00:00.000000000 +0100
  15984. +++ linux-rpi/arch/arm/mach-bcm2709/include/mach/dma.h 2015-03-05 14:40:11.153715839 +0100
  15985. @@ -0,0 +1,94 @@
  15986. +/*
  15987. + * linux/arch/arm/mach-bcm2708/include/mach/dma.h
  15988. + *
  15989. + * Copyright (C) 2010 Broadcom
  15990. + *
  15991. + * This program is free software; you can redistribute it and/or modify
  15992. + * it under the terms of the GNU General Public License version 2 as
  15993. + * published by the Free Software Foundation.
  15994. + */
  15995. +
  15996. +
  15997. +#ifndef _MACH_BCM2708_DMA_H
  15998. +#define _MACH_BCM2708_DMA_H
  15999. +
  16000. +#define BCM_DMAMAN_DRIVER_NAME "bcm2708_dma"
  16001. +
  16002. +/* DMA CS Control and Status bits */
  16003. +#define BCM2708_DMA_ACTIVE (1 << 0)
  16004. +#define BCM2708_DMA_INT (1 << 2)
  16005. +#define BCM2708_DMA_ISPAUSED (1 << 4) /* Pause requested or not active */
  16006. +#define BCM2708_DMA_ISHELD (1 << 5) /* Is held by DREQ flow control */
  16007. +#define BCM2708_DMA_ERR (1 << 8)
  16008. +#define BCM2708_DMA_ABORT (1 << 30) /* stop current CB, go to next, WO */
  16009. +#define BCM2708_DMA_RESET (1 << 31) /* WO, self clearing */
  16010. +
  16011. +/* DMA control block "info" field bits */
  16012. +#define BCM2708_DMA_INT_EN (1 << 0)
  16013. +#define BCM2708_DMA_TDMODE (1 << 1)
  16014. +#define BCM2708_DMA_WAIT_RESP (1 << 3)
  16015. +#define BCM2708_DMA_D_INC (1 << 4)
  16016. +#define BCM2708_DMA_D_WIDTH (1 << 5)
  16017. +#define BCM2708_DMA_D_DREQ (1 << 6)
  16018. +#define BCM2708_DMA_S_INC (1 << 8)
  16019. +#define BCM2708_DMA_S_WIDTH (1 << 9)
  16020. +#define BCM2708_DMA_S_DREQ (1 << 10)
  16021. +
  16022. +#define BCM2708_DMA_BURST(x) (((x)&0xf) << 12)
  16023. +#define BCM2708_DMA_PER_MAP(x) ((x) << 16)
  16024. +#define BCM2708_DMA_WAITS(x) (((x)&0x1f) << 21)
  16025. +
  16026. +#define BCM2708_DMA_DREQ_EMMC 11
  16027. +#define BCM2708_DMA_DREQ_SDHOST 13
  16028. +
  16029. +#define BCM2708_DMA_CS 0x00 /* Control and Status */
  16030. +#define BCM2708_DMA_ADDR 0x04
  16031. +/* the current control block appears in the following registers - read only */
  16032. +#define BCM2708_DMA_INFO 0x08
  16033. +#define BCM2708_DMA_SOURCE_AD 0x0c
  16034. +#define BCM2708_DMA_DEST_AD 0x10
  16035. +#define BCM2708_DMA_NEXTCB 0x1C
  16036. +#define BCM2708_DMA_DEBUG 0x20
  16037. +
  16038. +#define BCM2708_DMA4_CS (BCM2708_DMA_CHAN(4)+BCM2708_DMA_CS)
  16039. +#define BCM2708_DMA4_ADDR (BCM2708_DMA_CHAN(4)+BCM2708_DMA_ADDR)
  16040. +
  16041. +#define BCM2708_DMA_TDMODE_LEN(w, h) ((h) << 16 | (w))
  16042. +
  16043. +struct bcm2708_dma_cb {
  16044. + unsigned long info;
  16045. + unsigned long src;
  16046. + unsigned long dst;
  16047. + unsigned long length;
  16048. + unsigned long stride;
  16049. + unsigned long next;
  16050. + unsigned long pad[2];
  16051. +};
  16052. +struct scatterlist;
  16053. +
  16054. +extern int bcm_sg_suitable_for_dma(struct scatterlist *sg_ptr, int sg_len);
  16055. +extern void bcm_dma_start(void __iomem *dma_chan_base,
  16056. + dma_addr_t control_block);
  16057. +extern void bcm_dma_wait_idle(void __iomem *dma_chan_base);
  16058. +extern bool bcm_dma_is_busy(void __iomem *dma_chan_base);
  16059. +extern int /*rc*/ bcm_dma_abort(void __iomem *dma_chan_base);
  16060. +
  16061. +/* When listing features we can ask for when allocating DMA channels give
  16062. + those with higher priority smaller ordinal numbers */
  16063. +#define BCM_DMA_FEATURE_FAST_ORD 0
  16064. +#define BCM_DMA_FEATURE_BULK_ORD 1
  16065. +#define BCM_DMA_FEATURE_NORMAL_ORD 2
  16066. +#define BCM_DMA_FEATURE_LITE_ORD 3
  16067. +#define BCM_DMA_FEATURE_FAST (1<<BCM_DMA_FEATURE_FAST_ORD)
  16068. +#define BCM_DMA_FEATURE_BULK (1<<BCM_DMA_FEATURE_BULK_ORD)
  16069. +#define BCM_DMA_FEATURE_NORMAL (1<<BCM_DMA_FEATURE_NORMAL_ORD)
  16070. +#define BCM_DMA_FEATURE_LITE (1<<BCM_DMA_FEATURE_LITE_ORD)
  16071. +#define BCM_DMA_FEATURE_COUNT 4
  16072. +
  16073. +/* return channel no or -ve error */
  16074. +extern int bcm_dma_chan_alloc(unsigned preferred_feature_set,
  16075. + void __iomem **out_dma_base, int *out_dma_irq);
  16076. +extern int bcm_dma_chan_free(int channel);
  16077. +
  16078. +
  16079. +#endif /* _MACH_BCM2708_DMA_H */
  16080. diff -Nur linux-3.18.8/arch/arm/mach-bcm2709/include/mach/entry-macro.S linux-rpi/arch/arm/mach-bcm2709/include/mach/entry-macro.S
  16081. --- linux-3.18.8/arch/arm/mach-bcm2709/include/mach/entry-macro.S 1970-01-01 01:00:00.000000000 +0100
  16082. +++ linux-rpi/arch/arm/mach-bcm2709/include/mach/entry-macro.S 2015-03-05 14:40:11.153715839 +0100
  16083. @@ -0,0 +1,120 @@
  16084. +/*
  16085. + * arch/arm/mach-bcm2708/include/mach/entry-macro.S
  16086. + *
  16087. + * Low-level IRQ helper macros for BCM2708 platforms
  16088. + *
  16089. + * Copyright (C) 2010 Broadcom
  16090. + *
  16091. + * This program is free software; you can redistribute it and/or modify
  16092. + * it under the terms of the GNU General Public License as published by
  16093. + * the Free Software Foundation; either version 2 of the License, or
  16094. + * (at your option) any later version.
  16095. + *
  16096. + * This program is distributed in the hope that it will be useful,
  16097. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16098. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16099. + * GNU General Public License for more details.
  16100. + *
  16101. + * You should have received a copy of the GNU General Public License
  16102. + * along with this program; if not, write to the Free Software
  16103. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16104. + */
  16105. +#include <mach/hardware.h>
  16106. +#include <mach/irqs.h>
  16107. +
  16108. + .macro arch_ret_to_user, tmp1, tmp2
  16109. + .endm
  16110. +
  16111. + .macro get_irqnr_and_base, irqnr, irqstat, base, tmp
  16112. +
  16113. + /* get core number */
  16114. + mrc p15, 0, \base, c0, c0, 5
  16115. + ubfx \base, \base, #0, #2
  16116. +
  16117. + /* get core's local interrupt controller */
  16118. + ldr \irqstat, = __io_address(ARM_LOCAL_IRQ_PENDING0) @ local interrupt source
  16119. + add \irqstat, \irqstat, \base, lsl #2
  16120. + ldr \tmp, [\irqstat]
  16121. +
  16122. + /* test for mailbox0 (IPI) interrupt */
  16123. + tst \tmp, #0x10
  16124. + beq 1030f
  16125. +
  16126. + /* get core's mailbox interrupt control */
  16127. + ldr \irqstat, = __io_address(ARM_LOCAL_MAILBOX0_CLR0) @ mbox_clr
  16128. + add \irqstat, \irqstat, \base, lsl #4
  16129. + ldr \tmp, [\irqstat]
  16130. + clz \tmp, \tmp
  16131. + rsb \irqnr, \tmp, #31
  16132. + mov \tmp, #1
  16133. + lsl \tmp, \irqnr
  16134. + str \tmp, [\irqstat] @ clear interrupt source
  16135. + dsb
  16136. + mov r1, sp
  16137. + adr lr, BSYM(1b)
  16138. + b do_IPI
  16139. +
  16140. +1030:
  16141. + /* check gpu interrupt */
  16142. + tst \tmp, #0x100
  16143. + beq 1040f
  16144. +
  16145. + ldr \base, =IO_ADDRESS(ARMCTRL_IC_BASE)
  16146. + /* get masked status */
  16147. + ldr \irqstat, [\base, #(ARM_IRQ_PEND0 - ARMCTRL_IC_BASE)]
  16148. + mov \irqnr, #(ARM_IRQ0_BASE + 31)
  16149. + and \tmp, \irqstat, #0x300 @ save bits 8 and 9
  16150. + /* clear bits 8 and 9, and test */
  16151. + bics \irqstat, \irqstat, #0x300
  16152. + bne 1010f
  16153. +
  16154. + tst \tmp, #0x100
  16155. + ldrne \irqstat, [\base, #(ARM_IRQ_PEND1 - ARMCTRL_IC_BASE)]
  16156. + movne \irqnr, #(ARM_IRQ1_BASE + 31)
  16157. + @ Mask out the interrupts also present in PEND0 - see SW-5809
  16158. + bicne \irqstat, #((1<<7) | (1<<9) | (1<<10))
  16159. + bicne \irqstat, #((1<<18) | (1<<19))
  16160. + bne 1010f
  16161. +
  16162. + tst \tmp, #0x200
  16163. + ldrne \irqstat, [\base, #(ARM_IRQ_PEND2 - ARMCTRL_IC_BASE)]
  16164. + movne \irqnr, #(ARM_IRQ2_BASE + 31)
  16165. + @ Mask out the interrupts also present in PEND0 - see SW-5809
  16166. + bicne \irqstat, #((1<<21) | (1<<22) | (1<<23) | (1<<24) | (1<<25))
  16167. + bicne \irqstat, #((1<<30))
  16168. + beq 1020f
  16169. +1010:
  16170. + @ For non-zero x, LSB(x) = 31 - CLZ(x^(x-1))
  16171. + sub \tmp, \irqstat, #1
  16172. + eor \irqstat, \irqstat, \tmp
  16173. + clz \tmp, \irqstat
  16174. + sub \irqnr, \tmp
  16175. + b 1050f
  16176. +1040:
  16177. + cmp \tmp, #0
  16178. + beq 1020f
  16179. +
  16180. + /* handle local (e.g. timer) interrupts */
  16181. + @ For non-zero x, LSB(x) = 31 - CLZ(x^(x-1))
  16182. + mov \irqnr, #(ARM_IRQ_LOCAL_BASE + 31)
  16183. + sub \irqstat, \tmp, #1
  16184. + eor \irqstat, \irqstat, \tmp
  16185. + clz \tmp, \irqstat
  16186. + sub \irqnr, \tmp
  16187. +1050:
  16188. + mov r1, sp
  16189. + @
  16190. + @ routine called with r0 = irq number, r1 = struct pt_regs *
  16191. + @
  16192. + adr lr, BSYM(1b)
  16193. + b asm_do_IRQ
  16194. +
  16195. +1020: @ EQ will be set if no irqs pending
  16196. + .endm
  16197. +
  16198. +/*
  16199. + * Interrupt handling. Preserves r7, r8, r9
  16200. + */
  16201. + .macro arch_irq_handler_default
  16202. +1: get_irqnr_and_base r0, r2, r6, lr
  16203. + .endm
  16204. diff -Nur linux-3.18.8/arch/arm/mach-bcm2709/include/mach/frc.h linux-rpi/arch/arm/mach-bcm2709/include/mach/frc.h
  16205. --- linux-3.18.8/arch/arm/mach-bcm2709/include/mach/frc.h 1970-01-01 01:00:00.000000000 +0100
  16206. +++ linux-rpi/arch/arm/mach-bcm2709/include/mach/frc.h 2015-03-05 14:40:11.153715839 +0100
  16207. @@ -0,0 +1,38 @@
  16208. +/*
  16209. + * arch/arm/mach-bcm2708/include/mach/timex.h
  16210. + *
  16211. + * BCM2708 free running counter (timer)
  16212. + *
  16213. + * Copyright (C) 2010 Broadcom
  16214. + *
  16215. + * This program is free software; you can redistribute it and/or modify
  16216. + * it under the terms of the GNU General Public License as published by
  16217. + * the Free Software Foundation; either version 2 of the License, or
  16218. + * (at your option) any later version.
  16219. + *
  16220. + * This program is distributed in the hope that it will be useful,
  16221. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16222. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16223. + * GNU General Public License for more details.
  16224. + *
  16225. + * You should have received a copy of the GNU General Public License
  16226. + * along with this program; if not, write to the Free Software
  16227. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16228. + */
  16229. +
  16230. +#ifndef _MACH_FRC_H
  16231. +#define _MACH_FRC_H
  16232. +
  16233. +#define FRC_TICK_RATE (1000000)
  16234. +
  16235. +/*! Free running counter incrementing at the CLOCK_TICK_RATE
  16236. + (slightly faster than frc_clock_ticks63()
  16237. + */
  16238. +extern unsigned long frc_clock_ticks32(void);
  16239. +
  16240. +/*! Free running counter incrementing at the CLOCK_TICK_RATE
  16241. + * Note - top bit should be ignored (see cnt32_to_63)
  16242. + */
  16243. +extern unsigned long long frc_clock_ticks63(void);
  16244. +
  16245. +#endif
  16246. diff -Nur linux-3.18.8/arch/arm/mach-bcm2709/include/mach/gpio.h linux-rpi/arch/arm/mach-bcm2709/include/mach/gpio.h
  16247. --- linux-3.18.8/arch/arm/mach-bcm2709/include/mach/gpio.h 1970-01-01 01:00:00.000000000 +0100
  16248. +++ linux-rpi/arch/arm/mach-bcm2709/include/mach/gpio.h 2015-03-05 14:40:11.153715839 +0100
  16249. @@ -0,0 +1,17 @@
  16250. +/*
  16251. + * arch/arm/mach-bcm2708/include/mach/gpio.h
  16252. + *
  16253. + * This file is licensed under the terms of the GNU General Public
  16254. + * License version 2. This program is licensed "as is" without any
  16255. + * warranty of any kind, whether express or implied.
  16256. + */
  16257. +
  16258. +#ifndef __ASM_ARCH_GPIO_H
  16259. +#define __ASM_ARCH_GPIO_H
  16260. +
  16261. +#define BCM2708_NR_GPIOS 54 // number of gpio lines
  16262. +
  16263. +#define gpio_to_irq(x) ((x) + GPIO_IRQ_START)
  16264. +#define irq_to_gpio(x) ((x) - GPIO_IRQ_START)
  16265. +
  16266. +#endif
  16267. diff -Nur linux-3.18.8/arch/arm/mach-bcm2709/include/mach/hardware.h linux-rpi/arch/arm/mach-bcm2709/include/mach/hardware.h
  16268. --- linux-3.18.8/arch/arm/mach-bcm2709/include/mach/hardware.h 1970-01-01 01:00:00.000000000 +0100
  16269. +++ linux-rpi/arch/arm/mach-bcm2709/include/mach/hardware.h 2015-03-05 14:40:11.153715839 +0100
  16270. @@ -0,0 +1,28 @@
  16271. +/*
  16272. + * arch/arm/mach-bcm2708/include/mach/hardware.h
  16273. + *
  16274. + * This file contains the hardware definitions of the BCM2708 devices.
  16275. + *
  16276. + * Copyright (C) 2010 Broadcom
  16277. + *
  16278. + * This program is free software; you can redistribute it and/or modify
  16279. + * it under the terms of the GNU General Public License as published by
  16280. + * the Free Software Foundation; either version 2 of the License, or
  16281. + * (at your option) any later version.
  16282. + *
  16283. + * This program is distributed in the hope that it will be useful,
  16284. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16285. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16286. + * GNU General Public License for more details.
  16287. + *
  16288. + * You should have received a copy of the GNU General Public License
  16289. + * along with this program; if not, write to the Free Software
  16290. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16291. + */
  16292. +#ifndef __ASM_ARCH_HARDWARE_H
  16293. +#define __ASM_ARCH_HARDWARE_H
  16294. +
  16295. +#include <asm/sizes.h>
  16296. +#include <mach/platform.h>
  16297. +
  16298. +#endif
  16299. diff -Nur linux-3.18.8/arch/arm/mach-bcm2709/include/mach/io.h linux-rpi/arch/arm/mach-bcm2709/include/mach/io.h
  16300. --- linux-3.18.8/arch/arm/mach-bcm2709/include/mach/io.h 1970-01-01 01:00:00.000000000 +0100
  16301. +++ linux-rpi/arch/arm/mach-bcm2709/include/mach/io.h 2015-03-05 14:40:11.153715839 +0100
  16302. @@ -0,0 +1,27 @@
  16303. +/*
  16304. + * arch/arm/mach-bcm2708/include/mach/io.h
  16305. + *
  16306. + * Copyright (C) 2003 ARM Limited
  16307. + *
  16308. + * This program is free software; you can redistribute it and/or modify
  16309. + * it under the terms of the GNU General Public License as published by
  16310. + * the Free Software Foundation; either version 2 of the License, or
  16311. + * (at your option) any later version.
  16312. + *
  16313. + * This program is distributed in the hope that it will be useful,
  16314. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16315. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16316. + * GNU General Public License for more details.
  16317. + *
  16318. + * You should have received a copy of the GNU General Public License
  16319. + * along with this program; if not, write to the Free Software
  16320. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16321. + */
  16322. +#ifndef __ASM_ARM_ARCH_IO_H
  16323. +#define __ASM_ARM_ARCH_IO_H
  16324. +
  16325. +#define IO_SPACE_LIMIT 0xffffffff
  16326. +
  16327. +#define __io(a) __typesafe_io(a)
  16328. +
  16329. +#endif
  16330. diff -Nur linux-3.18.8/arch/arm/mach-bcm2709/include/mach/irqs.h linux-rpi/arch/arm/mach-bcm2709/include/mach/irqs.h
  16331. --- linux-3.18.8/arch/arm/mach-bcm2709/include/mach/irqs.h 1970-01-01 01:00:00.000000000 +0100
  16332. +++ linux-rpi/arch/arm/mach-bcm2709/include/mach/irqs.h 2015-03-05 14:40:11.157715839 +0100
  16333. @@ -0,0 +1,225 @@
  16334. +/*
  16335. + * arch/arm/mach-bcm2708/include/mach/irqs.h
  16336. + *
  16337. + * Copyright (C) 2010 Broadcom
  16338. + * Copyright (C) 2003 ARM Limited
  16339. + * Copyright (C) 2000 Deep Blue Solutions Ltd.
  16340. + *
  16341. + * This program is free software; you can redistribute it and/or modify
  16342. + * it under the terms of the GNU General Public License as published by
  16343. + * the Free Software Foundation; either version 2 of the License, or
  16344. + * (at your option) any later version.
  16345. + *
  16346. + * This program is distributed in the hope that it will be useful,
  16347. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16348. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16349. + * GNU General Public License for more details.
  16350. + *
  16351. + * You should have received a copy of the GNU General Public License
  16352. + * along with this program; if not, write to the Free Software
  16353. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16354. + */
  16355. +
  16356. +#ifndef _BCM2708_IRQS_H_
  16357. +#define _BCM2708_IRQS_H_
  16358. +
  16359. +#include <mach/platform.h>
  16360. +
  16361. +/*
  16362. + * IRQ interrupts definitions are the same as the INT definitions
  16363. + * held within platform.h
  16364. + */
  16365. +#define IRQ_ARMCTRL_START 0
  16366. +#define IRQ_TIMER0 (IRQ_ARMCTRL_START + INTERRUPT_TIMER0)
  16367. +#define IRQ_TIMER1 (IRQ_ARMCTRL_START + INTERRUPT_TIMER1)
  16368. +#define IRQ_TIMER2 (IRQ_ARMCTRL_START + INTERRUPT_TIMER2)
  16369. +#define IRQ_TIMER3 (IRQ_ARMCTRL_START + INTERRUPT_TIMER3)
  16370. +#define IRQ_CODEC0 (IRQ_ARMCTRL_START + INTERRUPT_CODEC0)
  16371. +#define IRQ_CODEC1 (IRQ_ARMCTRL_START + INTERRUPT_CODEC1)
  16372. +#define IRQ_CODEC2 (IRQ_ARMCTRL_START + INTERRUPT_CODEC2)
  16373. +#define IRQ_JPEG (IRQ_ARMCTRL_START + INTERRUPT_JPEG)
  16374. +#define IRQ_ISP (IRQ_ARMCTRL_START + INTERRUPT_ISP)
  16375. +#define IRQ_USB (IRQ_ARMCTRL_START + INTERRUPT_USB)
  16376. +#define IRQ_3D (IRQ_ARMCTRL_START + INTERRUPT_3D)
  16377. +#define IRQ_TRANSPOSER (IRQ_ARMCTRL_START + INTERRUPT_TRANSPOSER)
  16378. +#define IRQ_MULTICORESYNC0 (IRQ_ARMCTRL_START + INTERRUPT_MULTICORESYNC0)
  16379. +#define IRQ_MULTICORESYNC1 (IRQ_ARMCTRL_START + INTERRUPT_MULTICORESYNC1)
  16380. +#define IRQ_MULTICORESYNC2 (IRQ_ARMCTRL_START + INTERRUPT_MULTICORESYNC2)
  16381. +#define IRQ_MULTICORESYNC3 (IRQ_ARMCTRL_START + INTERRUPT_MULTICORESYNC3)
  16382. +#define IRQ_DMA0 (IRQ_ARMCTRL_START + INTERRUPT_DMA0)
  16383. +#define IRQ_DMA1 (IRQ_ARMCTRL_START + INTERRUPT_DMA1)
  16384. +#define IRQ_DMA2 (IRQ_ARMCTRL_START + INTERRUPT_DMA2)
  16385. +#define IRQ_DMA3 (IRQ_ARMCTRL_START + INTERRUPT_DMA3)
  16386. +#define IRQ_DMA4 (IRQ_ARMCTRL_START + INTERRUPT_DMA4)
  16387. +#define IRQ_DMA5 (IRQ_ARMCTRL_START + INTERRUPT_DMA5)
  16388. +#define IRQ_DMA6 (IRQ_ARMCTRL_START + INTERRUPT_DMA6)
  16389. +#define IRQ_DMA7 (IRQ_ARMCTRL_START + INTERRUPT_DMA7)
  16390. +#define IRQ_DMA8 (IRQ_ARMCTRL_START + INTERRUPT_DMA8)
  16391. +#define IRQ_DMA9 (IRQ_ARMCTRL_START + INTERRUPT_DMA9)
  16392. +#define IRQ_DMA10 (IRQ_ARMCTRL_START + INTERRUPT_DMA10)
  16393. +#define IRQ_DMA11 (IRQ_ARMCTRL_START + INTERRUPT_DMA11)
  16394. +#define IRQ_DMA12 (IRQ_ARMCTRL_START + INTERRUPT_DMA12)
  16395. +#define IRQ_AUX (IRQ_ARMCTRL_START + INTERRUPT_AUX)
  16396. +#define IRQ_ARM (IRQ_ARMCTRL_START + INTERRUPT_ARM)
  16397. +#define IRQ_VPUDMA (IRQ_ARMCTRL_START + INTERRUPT_VPUDMA)
  16398. +#define IRQ_HOSTPORT (IRQ_ARMCTRL_START + INTERRUPT_HOSTPORT)
  16399. +#define IRQ_VIDEOSCALER (IRQ_ARMCTRL_START + INTERRUPT_VIDEOSCALER)
  16400. +#define IRQ_CCP2TX (IRQ_ARMCTRL_START + INTERRUPT_CCP2TX)
  16401. +#define IRQ_SDC (IRQ_ARMCTRL_START + INTERRUPT_SDC)
  16402. +#define IRQ_DSI0 (IRQ_ARMCTRL_START + INTERRUPT_DSI0)
  16403. +#define IRQ_AVE (IRQ_ARMCTRL_START + INTERRUPT_AVE)
  16404. +#define IRQ_CAM0 (IRQ_ARMCTRL_START + INTERRUPT_CAM0)
  16405. +#define IRQ_CAM1 (IRQ_ARMCTRL_START + INTERRUPT_CAM1)
  16406. +#define IRQ_HDMI0 (IRQ_ARMCTRL_START + INTERRUPT_HDMI0)
  16407. +#define IRQ_HDMI1 (IRQ_ARMCTRL_START + INTERRUPT_HDMI1)
  16408. +#define IRQ_PIXELVALVE1 (IRQ_ARMCTRL_START + INTERRUPT_PIXELVALVE1)
  16409. +#define IRQ_I2CSPISLV (IRQ_ARMCTRL_START + INTERRUPT_I2CSPISLV)
  16410. +#define IRQ_DSI1 (IRQ_ARMCTRL_START + INTERRUPT_DSI1)
  16411. +#define IRQ_PWA0 (IRQ_ARMCTRL_START + INTERRUPT_PWA0)
  16412. +#define IRQ_PWA1 (IRQ_ARMCTRL_START + INTERRUPT_PWA1)
  16413. +#define IRQ_CPR (IRQ_ARMCTRL_START + INTERRUPT_CPR)
  16414. +#define IRQ_SMI (IRQ_ARMCTRL_START + INTERRUPT_SMI)
  16415. +#define IRQ_GPIO0 (IRQ_ARMCTRL_START + INTERRUPT_GPIO0)
  16416. +#define IRQ_GPIO1 (IRQ_ARMCTRL_START + INTERRUPT_GPIO1)
  16417. +#define IRQ_GPIO2 (IRQ_ARMCTRL_START + INTERRUPT_GPIO2)
  16418. +#define IRQ_GPIO3 (IRQ_ARMCTRL_START + INTERRUPT_GPIO3)
  16419. +#define IRQ_I2C (IRQ_ARMCTRL_START + INTERRUPT_I2C)
  16420. +#define IRQ_SPI (IRQ_ARMCTRL_START + INTERRUPT_SPI)
  16421. +#define IRQ_I2SPCM (IRQ_ARMCTRL_START + INTERRUPT_I2SPCM)
  16422. +#define IRQ_SDIO (IRQ_ARMCTRL_START + INTERRUPT_SDIO)
  16423. +#define IRQ_UART (IRQ_ARMCTRL_START + INTERRUPT_UART)
  16424. +#define IRQ_SLIMBUS (IRQ_ARMCTRL_START + INTERRUPT_SLIMBUS)
  16425. +#define IRQ_VEC (IRQ_ARMCTRL_START + INTERRUPT_VEC)
  16426. +#define IRQ_CPG (IRQ_ARMCTRL_START + INTERRUPT_CPG)
  16427. +#define IRQ_RNG (IRQ_ARMCTRL_START + INTERRUPT_RNG)
  16428. +#define IRQ_ARASANSDIO (IRQ_ARMCTRL_START + INTERRUPT_ARASANSDIO)
  16429. +#define IRQ_AVSPMON (IRQ_ARMCTRL_START + INTERRUPT_AVSPMON)
  16430. +
  16431. +#define IRQ_ARM_TIMER (IRQ_ARMCTRL_START + INTERRUPT_ARM_TIMER)
  16432. +#define IRQ_ARM_MAILBOX (IRQ_ARMCTRL_START + INTERRUPT_ARM_MAILBOX)
  16433. +#define IRQ_ARM_DOORBELL_0 (IRQ_ARMCTRL_START + INTERRUPT_ARM_DOORBELL_0)
  16434. +#define IRQ_ARM_DOORBELL_1 (IRQ_ARMCTRL_START + INTERRUPT_ARM_DOORBELL_1)
  16435. +#define IRQ_VPU0_HALTED (IRQ_ARMCTRL_START + INTERRUPT_VPU0_HALTED)
  16436. +#define IRQ_VPU1_HALTED (IRQ_ARMCTRL_START + INTERRUPT_VPU1_HALTED)
  16437. +#define IRQ_ILLEGAL_TYPE0 (IRQ_ARMCTRL_START + INTERRUPT_ILLEGAL_TYPE0)
  16438. +#define IRQ_ILLEGAL_TYPE1 (IRQ_ARMCTRL_START + INTERRUPT_ILLEGAL_TYPE1)
  16439. +#define IRQ_PENDING1 (IRQ_ARMCTRL_START + INTERRUPT_PENDING1)
  16440. +#define IRQ_PENDING2 (IRQ_ARMCTRL_START + INTERRUPT_PENDING2)
  16441. +
  16442. +#define IRQ_ARM_LOCAL_CNTPSIRQ (IRQ_ARMCTRL_START + INTERRUPT_ARM_LOCAL_CNTPSIRQ)
  16443. +#define IRQ_ARM_LOCAL_CNTPNSIRQ (IRQ_ARMCTRL_START + INTERRUPT_ARM_LOCAL_CNTPNSIRQ)
  16444. +#define IRQ_ARM_LOCAL_CNTHPIRQ (IRQ_ARMCTRL_START + INTERRUPT_ARM_LOCAL_CNTHPIRQ)
  16445. +#define IRQ_ARM_LOCAL_CNTVIRQ (IRQ_ARMCTRL_START + INTERRUPT_ARM_LOCAL_CNTVIRQ)
  16446. +#define IRQ_ARM_LOCAL_MAILBOX0 (IRQ_ARMCTRL_START + INTERRUPT_ARM_LOCAL_MAILBOX0)
  16447. +#define IRQ_ARM_LOCAL_MAILBOX1 (IRQ_ARMCTRL_START + INTERRUPT_ARM_LOCAL_MAILBOX1)
  16448. +#define IRQ_ARM_LOCAL_MAILBOX2 (IRQ_ARMCTRL_START + INTERRUPT_ARM_LOCAL_MAILBOX2)
  16449. +#define IRQ_ARM_LOCAL_MAILBOX3 (IRQ_ARMCTRL_START + INTERRUPT_ARM_LOCAL_MAILBOX3)
  16450. +#define IRQ_ARM_LOCAL_GPU_FAST (IRQ_ARMCTRL_START + INTERRUPT_ARM_LOCAL_GPU_FAST)
  16451. +#define IRQ_ARM_LOCAL_PMU_FAST (IRQ_ARMCTRL_START + INTERRUPT_ARM_LOCAL_PMU_FAST)
  16452. +#define IRQ_ARM_LOCAL_ZERO (IRQ_ARMCTRL_START + INTERRUPT_ARM_LOCAL_ZERO)
  16453. +#define IRQ_ARM_LOCAL_TIMER (IRQ_ARMCTRL_START + INTERRUPT_ARM_LOCAL_TIMER)
  16454. +
  16455. +#define FIQ_START HARD_IRQS
  16456. +
  16457. +/*
  16458. + * FIQ interrupts definitions are the same as the INT definitions.
  16459. + */
  16460. +#define FIQ_TIMER0 (FIQ_START+INTERRUPT_TIMER0)
  16461. +#define FIQ_TIMER1 (FIQ_START+INTERRUPT_TIMER1)
  16462. +#define FIQ_TIMER2 (FIQ_START+INTERRUPT_TIMER2)
  16463. +#define FIQ_TIMER3 (FIQ_START+INTERRUPT_TIMER3)
  16464. +#define FIQ_CODEC0 (FIQ_START+INTERRUPT_CODEC0)
  16465. +#define FIQ_CODEC1 (FIQ_START+INTERRUPT_CODEC1)
  16466. +#define FIQ_CODEC2 (FIQ_START+INTERRUPT_CODEC2)
  16467. +#define FIQ_JPEG (FIQ_START+INTERRUPT_JPEG)
  16468. +#define FIQ_ISP (FIQ_START+INTERRUPT_ISP)
  16469. +#define FIQ_USB (FIQ_START+INTERRUPT_USB)
  16470. +#define FIQ_3D (FIQ_START+INTERRUPT_3D)
  16471. +#define FIQ_TRANSPOSER (FIQ_START+INTERRUPT_TRANSPOSER)
  16472. +#define FIQ_MULTICORESYNC0 (FIQ_START+INTERRUPT_MULTICORESYNC0)
  16473. +#define FIQ_MULTICORESYNC1 (FIQ_START+INTERRUPT_MULTICORESYNC1)
  16474. +#define FIQ_MULTICORESYNC2 (FIQ_START+INTERRUPT_MULTICORESYNC2)
  16475. +#define FIQ_MULTICORESYNC3 (FIQ_START+INTERRUPT_MULTICORESYNC3)
  16476. +#define FIQ_DMA0 (FIQ_START+INTERRUPT_DMA0)
  16477. +#define FIQ_DMA1 (FIQ_START+INTERRUPT_DMA1)
  16478. +#define FIQ_DMA2 (FIQ_START+INTERRUPT_DMA2)
  16479. +#define FIQ_DMA3 (FIQ_START+INTERRUPT_DMA3)
  16480. +#define FIQ_DMA4 (FIQ_START+INTERRUPT_DMA4)
  16481. +#define FIQ_DMA5 (FIQ_START+INTERRUPT_DMA5)
  16482. +#define FIQ_DMA6 (FIQ_START+INTERRUPT_DMA6)
  16483. +#define FIQ_DMA7 (FIQ_START+INTERRUPT_DMA7)
  16484. +#define FIQ_DMA8 (FIQ_START+INTERRUPT_DMA8)
  16485. +#define FIQ_DMA9 (FIQ_START+INTERRUPT_DMA9)
  16486. +#define FIQ_DMA10 (FIQ_START+INTERRUPT_DMA10)
  16487. +#define FIQ_DMA11 (FIQ_START+INTERRUPT_DMA11)
  16488. +#define FIQ_DMA12 (FIQ_START+INTERRUPT_DMA12)
  16489. +#define FIQ_AUX (FIQ_START+INTERRUPT_AUX)
  16490. +#define FIQ_ARM (FIQ_START+INTERRUPT_ARM)
  16491. +#define FIQ_VPUDMA (FIQ_START+INTERRUPT_VPUDMA)
  16492. +#define FIQ_HOSTPORT (FIQ_START+INTERRUPT_HOSTPORT)
  16493. +#define FIQ_VIDEOSCALER (FIQ_START+INTERRUPT_VIDEOSCALER)
  16494. +#define FIQ_CCP2TX (FIQ_START+INTERRUPT_CCP2TX)
  16495. +#define FIQ_SDC (FIQ_START+INTERRUPT_SDC)
  16496. +#define FIQ_DSI0 (FIQ_START+INTERRUPT_DSI0)
  16497. +#define FIQ_AVE (FIQ_START+INTERRUPT_AVE)
  16498. +#define FIQ_CAM0 (FIQ_START+INTERRUPT_CAM0)
  16499. +#define FIQ_CAM1 (FIQ_START+INTERRUPT_CAM1)
  16500. +#define FIQ_HDMI0 (FIQ_START+INTERRUPT_HDMI0)
  16501. +#define FIQ_HDMI1 (FIQ_START+INTERRUPT_HDMI1)
  16502. +#define FIQ_PIXELVALVE1 (FIQ_START+INTERRUPT_PIXELVALVE1)
  16503. +#define FIQ_I2CSPISLV (FIQ_START+INTERRUPT_I2CSPISLV)
  16504. +#define FIQ_DSI1 (FIQ_START+INTERRUPT_DSI1)
  16505. +#define FIQ_PWA0 (FIQ_START+INTERRUPT_PWA0)
  16506. +#define FIQ_PWA1 (FIQ_START+INTERRUPT_PWA1)
  16507. +#define FIQ_CPR (FIQ_START+INTERRUPT_CPR)
  16508. +#define FIQ_SMI (FIQ_START+INTERRUPT_SMI)
  16509. +#define FIQ_GPIO0 (FIQ_START+INTERRUPT_GPIO0)
  16510. +#define FIQ_GPIO1 (FIQ_START+INTERRUPT_GPIO1)
  16511. +#define FIQ_GPIO2 (FIQ_START+INTERRUPT_GPIO2)
  16512. +#define FIQ_GPIO3 (FIQ_START+INTERRUPT_GPIO3)
  16513. +#define FIQ_I2C (FIQ_START+INTERRUPT_I2C)
  16514. +#define FIQ_SPI (FIQ_START+INTERRUPT_SPI)
  16515. +#define FIQ_I2SPCM (FIQ_START+INTERRUPT_I2SPCM)
  16516. +#define FIQ_SDIO (FIQ_START+INTERRUPT_SDIO)
  16517. +#define FIQ_UART (FIQ_START+INTERRUPT_UART)
  16518. +#define FIQ_SLIMBUS (FIQ_START+INTERRUPT_SLIMBUS)
  16519. +#define FIQ_VEC (FIQ_START+INTERRUPT_VEC)
  16520. +#define FIQ_CPG (FIQ_START+INTERRUPT_CPG)
  16521. +#define FIQ_RNG (FIQ_START+INTERRUPT_RNG)
  16522. +#define FIQ_ARASANSDIO (FIQ_START+INTERRUPT_ARASANSDIO)
  16523. +#define FIQ_AVSPMON (FIQ_START+INTERRUPT_AVSPMON)
  16524. +
  16525. +#define FIQ_ARM_TIMER (FIQ_START+INTERRUPT_ARM_TIMER)
  16526. +#define FIQ_ARM_MAILBOX (FIQ_START+INTERRUPT_ARM_MAILBOX)
  16527. +#define FIQ_ARM_DOORBELL_0 (FIQ_START+INTERRUPT_ARM_DOORBELL_0)
  16528. +#define FIQ_ARM_DOORBELL_1 (FIQ_START+INTERRUPT_ARM_DOORBELL_1)
  16529. +#define FIQ_VPU0_HALTED (FIQ_START+INTERRUPT_VPU0_HALTED)
  16530. +#define FIQ_VPU1_HALTED (FIQ_START+INTERRUPT_VPU1_HALTED)
  16531. +#define FIQ_ILLEGAL_TYPE0 (FIQ_START+INTERRUPT_ILLEGAL_TYPE0)
  16532. +#define FIQ_ILLEGAL_TYPE1 (FIQ_START+INTERRUPT_ILLEGAL_TYPE1)
  16533. +#define FIQ_PENDING1 (FIQ_START+INTERRUPT_PENDING1)
  16534. +#define FIQ_PENDING2 (FIQ_START+INTERRUPT_PENDING2)
  16535. +
  16536. +#define FIQ_ARM_LOCAL_CNTPSIRQ (FIQ_ARMCTRL_START + INTERRUPT_ARM_LOCAL_CNTPSIRQ)
  16537. +#define FIQ_ARM_LOCAL_CNTPNSIRQ (FIQ_ARMCTRL_START + INTERRUPT_ARM_LOCAL_CNTPNSIRQ)
  16538. +#define FIQ_ARM_LOCAL_CNTHPIRQ (FIQ_ARMCTRL_START + INTERRUPT_ARM_LOCAL_CNTHPIRQ)
  16539. +#define FIQ_ARM_LOCAL_CNTVIRQ (FIQ_ARMCTRL_START + INTERRUPT_ARM_LOCAL_CNTVIRQ)
  16540. +#define FIQ_ARM_LOCAL_MAILBOX0 (FIQ_ARMCTRL_START + INTERRUPT_ARM_LOCAL_MAILBOX0)
  16541. +#define FIQ_ARM_LOCAL_MAILBOX1 (FIQ_ARMCTRL_START + INTERRUPT_ARM_LOCAL_MAILBOX1)
  16542. +#define FIQ_ARM_LOCAL_MAILBOX2 (FIQ_ARMCTRL_START + INTERRUPT_ARM_LOCAL_MAILBOX2)
  16543. +#define FIQ_ARM_LOCAL_MAILBOX3 (FIQ_ARMCTRL_START + INTERRUPT_ARM_LOCAL_MAILBOX3)
  16544. +#define FIQ_ARM_LOCAL_GPU_FAST (FIQ_ARMCTRL_START + INTERRUPT_ARM_LOCAL_GPU_FAST)
  16545. +#define FIQ_ARM_LOCAL_PMU_FAST (FIQ_ARMCTRL_START + INTERRUPT_ARM_LOCAL_PMU_FAST)
  16546. +#define FIQ_ARM_LOCAL_ZERO (FIQ_ARMCTRL_START + INTERRUPT_ARM_LOCAL_ZERO)
  16547. +#define FIQ_ARM_LOCAL_TIMER (FIQ_ARMCTRL_START + INTERRUPT_ARM_LOCAL_TIMER)
  16548. +
  16549. +#define HARD_IRQS (128)
  16550. +#define FIQ_IRQS (128)
  16551. +#define GPIO_IRQ_START (HARD_IRQS + FIQ_IRQS)
  16552. +#define GPIO_IRQS (32*5)
  16553. +#define SPARE_ALLOC_IRQS 32
  16554. +#define BCM2708_ALLOC_IRQS (HARD_IRQS+FIQ_IRQS+GPIO_IRQS+SPARE_ALLOC_IRQS)
  16555. +#define FREE_IRQS 32
  16556. +#define NR_IRQS (BCM2708_ALLOC_IRQS+FREE_IRQS)
  16557. +
  16558. +#endif /* _BCM2708_IRQS_H_ */
  16559. diff -Nur linux-3.18.8/arch/arm/mach-bcm2709/include/mach/memory.h linux-rpi/arch/arm/mach-bcm2709/include/mach/memory.h
  16560. --- linux-3.18.8/arch/arm/mach-bcm2709/include/mach/memory.h 1970-01-01 01:00:00.000000000 +0100
  16561. +++ linux-rpi/arch/arm/mach-bcm2709/include/mach/memory.h 2015-03-05 14:40:11.157715839 +0100
  16562. @@ -0,0 +1,57 @@
  16563. +/*
  16564. + * arch/arm/mach-bcm2708/include/mach/memory.h
  16565. + *
  16566. + * Copyright (C) 2010 Broadcom
  16567. + *
  16568. + * This program is free software; you can redistribute it and/or modify
  16569. + * it under the terms of the GNU General Public License as published by
  16570. + * the Free Software Foundation; either version 2 of the License, or
  16571. + * (at your option) any later version.
  16572. + *
  16573. + * This program is distributed in the hope that it will be useful,
  16574. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16575. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16576. + * GNU General Public License for more details.
  16577. + *
  16578. + * You should have received a copy of the GNU General Public License
  16579. + * along with this program; if not, write to the Free Software
  16580. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16581. + */
  16582. +#ifndef __ASM_ARCH_MEMORY_H
  16583. +#define __ASM_ARCH_MEMORY_H
  16584. +
  16585. +/* Memory overview:
  16586. +
  16587. + [ARMcore] <--virtual addr-->
  16588. + [ARMmmu] <--physical addr-->
  16589. + [GERTmap] <--bus add-->
  16590. + [VCperiph]
  16591. +
  16592. +*/
  16593. +
  16594. +/*
  16595. + * Physical DRAM offset.
  16596. + */
  16597. +#define BCM_PLAT_PHYS_OFFSET UL(0x00000000)
  16598. +#define VC_ARMMEM_OFFSET UL(0x00000000) /* offset in VC of ARM memory */
  16599. +
  16600. +#ifdef CONFIG_BCM2708_NOL2CACHE
  16601. + #define _REAL_BUS_OFFSET UL(0xC0000000) /* don't use L1 or L2 caches */
  16602. +#else
  16603. + #define _REAL_BUS_OFFSET UL(0x40000000) /* use L2 cache */
  16604. +#endif
  16605. +
  16606. +/* We're using the memory at 64M in the VideoCore for Linux - this adjustment
  16607. + * will provide the offset into this area as well as setting the bits that
  16608. + * stop the L1 and L2 cache from being used
  16609. + *
  16610. + * WARNING: this only works because the ARM is given memory at a fixed location
  16611. + * (ARMMEM_OFFSET)
  16612. + */
  16613. +#define BUS_OFFSET (VC_ARMMEM_OFFSET + _REAL_BUS_OFFSET)
  16614. +#define __virt_to_bus(x) ((x) + (BUS_OFFSET - PAGE_OFFSET))
  16615. +#define __bus_to_virt(x) ((x) - (BUS_OFFSET - PAGE_OFFSET))
  16616. +#define __pfn_to_bus(x) (__pfn_to_phys(x) + (BUS_OFFSET - BCM_PLAT_PHYS_OFFSET))
  16617. +#define __bus_to_pfn(x) __phys_to_pfn((x) - (BUS_OFFSET - BCM_PLAT_PHYS_OFFSET))
  16618. +
  16619. +#endif
  16620. diff -Nur linux-3.18.8/arch/arm/mach-bcm2709/include/mach/platform.h linux-rpi/arch/arm/mach-bcm2709/include/mach/platform.h
  16621. --- linux-3.18.8/arch/arm/mach-bcm2709/include/mach/platform.h 1970-01-01 01:00:00.000000000 +0100
  16622. +++ linux-rpi/arch/arm/mach-bcm2709/include/mach/platform.h 2015-03-05 14:40:11.157715839 +0100
  16623. @@ -0,0 +1,225 @@
  16624. +/*
  16625. + * arch/arm/mach-bcm2708/include/mach/platform.h
  16626. + *
  16627. + * Copyright (C) 2010 Broadcom
  16628. + *
  16629. + * This program is free software; you can redistribute it and/or modify
  16630. + * it under the terms of the GNU General Public License as published by
  16631. + * the Free Software Foundation; either version 2 of the License, or
  16632. + * (at your option) any later version.
  16633. + *
  16634. + * This program is distributed in the hope that it will be useful,
  16635. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16636. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16637. + * GNU General Public License for more details.
  16638. + *
  16639. + * You should have received a copy of the GNU General Public License
  16640. + * along with this program; if not, write to the Free Software
  16641. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16642. + */
  16643. +
  16644. +#ifndef _BCM2708_PLATFORM_H
  16645. +#define _BCM2708_PLATFORM_H
  16646. +
  16647. +
  16648. +/* macros to get at IO space when running virtually */
  16649. +#define IO_ADDRESS(x) (((x) & 0x00ffffff) + (((x) >> 4) & 0x0f000000) + 0xf0000000)
  16650. +
  16651. +#define __io_address(n) IOMEM(IO_ADDRESS(n))
  16652. +
  16653. +
  16654. +/*
  16655. + * SDRAM
  16656. + */
  16657. +#define BCM2708_SDRAM_BASE 0x00000000
  16658. +
  16659. +/*
  16660. + * Logic expansion modules
  16661. + *
  16662. + */
  16663. +
  16664. +
  16665. +/* ------------------------------------------------------------------------
  16666. + * BCM2708 ARMCTRL Registers
  16667. + * ------------------------------------------------------------------------
  16668. + */
  16669. +
  16670. +#define HW_REGISTER_RW(addr) (addr)
  16671. +#define HW_REGISTER_RO(addr) (addr)
  16672. +
  16673. +#include "arm_control.h"
  16674. +#undef ARM_BASE
  16675. +
  16676. +/*
  16677. + * Definitions and addresses for the ARM CONTROL logic
  16678. + * This file is manually generated.
  16679. + */
  16680. +
  16681. +#define BCM2708_PERI_BASE 0x3F000000
  16682. +#define IC0_BASE (BCM2708_PERI_BASE + 0x2000)
  16683. +#define ST_BASE (BCM2708_PERI_BASE + 0x3000) /* System Timer */
  16684. +#define MPHI_BASE (BCM2708_PERI_BASE + 0x6000) /* Message -based Parallel Host Interface */
  16685. +#define DMA_BASE (BCM2708_PERI_BASE + 0x7000) /* DMA controller */
  16686. +#define ARM_BASE (BCM2708_PERI_BASE + 0xB000) /* BCM2708 ARM control block */
  16687. +#define PM_BASE (BCM2708_PERI_BASE + 0x100000) /* Power Management, Reset controller and Watchdog registers */
  16688. +#define PCM_CLOCK_BASE (BCM2708_PERI_BASE + 0x101098) /* PCM Clock */
  16689. +#define RNG_BASE (BCM2708_PERI_BASE + 0x104000) /* Hardware RNG */
  16690. +#define GPIO_BASE (BCM2708_PERI_BASE + 0x200000) /* GPIO */
  16691. +#define UART0_BASE (BCM2708_PERI_BASE + 0x201000) /* Uart 0 */
  16692. +#define MMCI0_BASE (BCM2708_PERI_BASE + 0x202000) /* MMC interface */
  16693. +#define I2S_BASE (BCM2708_PERI_BASE + 0x203000) /* I2S */
  16694. +#define SPI0_BASE (BCM2708_PERI_BASE + 0x204000) /* SPI0 */
  16695. +#define BSC0_BASE (BCM2708_PERI_BASE + 0x205000) /* BSC0 I2C/TWI */
  16696. +#define UART1_BASE (BCM2708_PERI_BASE + 0x215000) /* Uart 1 */
  16697. +#define EMMC_BASE (BCM2708_PERI_BASE + 0x300000) /* eMMC interface */
  16698. +#define SMI_BASE (BCM2708_PERI_BASE + 0x600000) /* SMI */
  16699. +#define BSC1_BASE (BCM2708_PERI_BASE + 0x804000) /* BSC1 I2C/TWI */
  16700. +#define USB_BASE (BCM2708_PERI_BASE + 0x980000) /* DTC_OTG USB controller */
  16701. +#define MCORE_BASE (BCM2708_PERI_BASE + 0x0000) /* Fake frame buffer device (actually the multicore sync block*/
  16702. +
  16703. +#define ARMCTRL_BASE (ARM_BASE + 0x000)
  16704. +#define ARMCTRL_IC_BASE (ARM_BASE + 0x200) /* ARM interrupt controller */
  16705. +#define ARMCTRL_TIMER0_1_BASE (ARM_BASE + 0x400) /* Timer 0 and 1 */
  16706. +#define ARMCTRL_0_SBM_BASE (ARM_BASE + 0x800) /* User 0 (ARM)'s Semaphores Doorbells and Mailboxes */
  16707. +
  16708. +
  16709. +/*
  16710. + * Interrupt assignments
  16711. + */
  16712. +
  16713. +#define ARM_IRQ1_BASE 0
  16714. +#define INTERRUPT_TIMER0 (ARM_IRQ1_BASE + 0)
  16715. +#define INTERRUPT_TIMER1 (ARM_IRQ1_BASE + 1)
  16716. +#define INTERRUPT_TIMER2 (ARM_IRQ1_BASE + 2)
  16717. +#define INTERRUPT_TIMER3 (ARM_IRQ1_BASE + 3)
  16718. +#define INTERRUPT_CODEC0 (ARM_IRQ1_BASE + 4)
  16719. +#define INTERRUPT_CODEC1 (ARM_IRQ1_BASE + 5)
  16720. +#define INTERRUPT_CODEC2 (ARM_IRQ1_BASE + 6)
  16721. +#define INTERRUPT_VC_JPEG (ARM_IRQ1_BASE + 7)
  16722. +#define INTERRUPT_ISP (ARM_IRQ1_BASE + 8)
  16723. +#define INTERRUPT_VC_USB (ARM_IRQ1_BASE + 9)
  16724. +#define INTERRUPT_VC_3D (ARM_IRQ1_BASE + 10)
  16725. +#define INTERRUPT_TRANSPOSER (ARM_IRQ1_BASE + 11)
  16726. +#define INTERRUPT_MULTICORESYNC0 (ARM_IRQ1_BASE + 12)
  16727. +#define INTERRUPT_MULTICORESYNC1 (ARM_IRQ1_BASE + 13)
  16728. +#define INTERRUPT_MULTICORESYNC2 (ARM_IRQ1_BASE + 14)
  16729. +#define INTERRUPT_MULTICORESYNC3 (ARM_IRQ1_BASE + 15)
  16730. +#define INTERRUPT_DMA0 (ARM_IRQ1_BASE + 16)
  16731. +#define INTERRUPT_DMA1 (ARM_IRQ1_BASE + 17)
  16732. +#define INTERRUPT_VC_DMA2 (ARM_IRQ1_BASE + 18)
  16733. +#define INTERRUPT_VC_DMA3 (ARM_IRQ1_BASE + 19)
  16734. +#define INTERRUPT_DMA4 (ARM_IRQ1_BASE + 20)
  16735. +#define INTERRUPT_DMA5 (ARM_IRQ1_BASE + 21)
  16736. +#define INTERRUPT_DMA6 (ARM_IRQ1_BASE + 22)
  16737. +#define INTERRUPT_DMA7 (ARM_IRQ1_BASE + 23)
  16738. +#define INTERRUPT_DMA8 (ARM_IRQ1_BASE + 24)
  16739. +#define INTERRUPT_DMA9 (ARM_IRQ1_BASE + 25)
  16740. +#define INTERRUPT_DMA10 (ARM_IRQ1_BASE + 26)
  16741. +#define INTERRUPT_DMA11 (ARM_IRQ1_BASE + 27)
  16742. +#define INTERRUPT_DMA12 (ARM_IRQ1_BASE + 28)
  16743. +#define INTERRUPT_AUX (ARM_IRQ1_BASE + 29)
  16744. +#define INTERRUPT_ARM (ARM_IRQ1_BASE + 30)
  16745. +#define INTERRUPT_VPUDMA (ARM_IRQ1_BASE + 31)
  16746. +
  16747. +#define ARM_IRQ2_BASE 32
  16748. +#define INTERRUPT_HOSTPORT (ARM_IRQ2_BASE + 0)
  16749. +#define INTERRUPT_VIDEOSCALER (ARM_IRQ2_BASE + 1)
  16750. +#define INTERRUPT_CCP2TX (ARM_IRQ2_BASE + 2)
  16751. +#define INTERRUPT_SDC (ARM_IRQ2_BASE + 3)
  16752. +#define INTERRUPT_DSI0 (ARM_IRQ2_BASE + 4)
  16753. +#define INTERRUPT_AVE (ARM_IRQ2_BASE + 5)
  16754. +#define INTERRUPT_CAM0 (ARM_IRQ2_BASE + 6)
  16755. +#define INTERRUPT_CAM1 (ARM_IRQ2_BASE + 7)
  16756. +#define INTERRUPT_HDMI0 (ARM_IRQ2_BASE + 8)
  16757. +#define INTERRUPT_HDMI1 (ARM_IRQ2_BASE + 9)
  16758. +#define INTERRUPT_PIXELVALVE1 (ARM_IRQ2_BASE + 10)
  16759. +#define INTERRUPT_I2CSPISLV (ARM_IRQ2_BASE + 11)
  16760. +#define INTERRUPT_DSI1 (ARM_IRQ2_BASE + 12)
  16761. +#define INTERRUPT_PWA0 (ARM_IRQ2_BASE + 13)
  16762. +#define INTERRUPT_PWA1 (ARM_IRQ2_BASE + 14)
  16763. +#define INTERRUPT_CPR (ARM_IRQ2_BASE + 15)
  16764. +#define INTERRUPT_SMI (ARM_IRQ2_BASE + 16)
  16765. +#define INTERRUPT_GPIO0 (ARM_IRQ2_BASE + 17)
  16766. +#define INTERRUPT_GPIO1 (ARM_IRQ2_BASE + 18)
  16767. +#define INTERRUPT_GPIO2 (ARM_IRQ2_BASE + 19)
  16768. +#define INTERRUPT_GPIO3 (ARM_IRQ2_BASE + 20)
  16769. +#define INTERRUPT_VC_I2C (ARM_IRQ2_BASE + 21)
  16770. +#define INTERRUPT_VC_SPI (ARM_IRQ2_BASE + 22)
  16771. +#define INTERRUPT_VC_I2SPCM (ARM_IRQ2_BASE + 23)
  16772. +#define INTERRUPT_VC_SDIO (ARM_IRQ2_BASE + 24)
  16773. +#define INTERRUPT_VC_UART (ARM_IRQ2_BASE + 25)
  16774. +#define INTERRUPT_SLIMBUS (ARM_IRQ2_BASE + 26)
  16775. +#define INTERRUPT_VEC (ARM_IRQ2_BASE + 27)
  16776. +#define INTERRUPT_CPG (ARM_IRQ2_BASE + 28)
  16777. +#define INTERRUPT_RNG (ARM_IRQ2_BASE + 29)
  16778. +#define INTERRUPT_VC_ARASANSDIO (ARM_IRQ2_BASE + 30)
  16779. +#define INTERRUPT_AVSPMON (ARM_IRQ2_BASE + 31)
  16780. +
  16781. +#define ARM_IRQ0_BASE 64
  16782. +#define INTERRUPT_ARM_TIMER (ARM_IRQ0_BASE + 0)
  16783. +#define INTERRUPT_ARM_MAILBOX (ARM_IRQ0_BASE + 1)
  16784. +#define INTERRUPT_ARM_DOORBELL_0 (ARM_IRQ0_BASE + 2)
  16785. +#define INTERRUPT_ARM_DOORBELL_1 (ARM_IRQ0_BASE + 3)
  16786. +#define INTERRUPT_VPU0_HALTED (ARM_IRQ0_BASE + 4)
  16787. +#define INTERRUPT_VPU1_HALTED (ARM_IRQ0_BASE + 5)
  16788. +#define INTERRUPT_ILLEGAL_TYPE0 (ARM_IRQ0_BASE + 6)
  16789. +#define INTERRUPT_ILLEGAL_TYPE1 (ARM_IRQ0_BASE + 7)
  16790. +#define INTERRUPT_PENDING1 (ARM_IRQ0_BASE + 8)
  16791. +#define INTERRUPT_PENDING2 (ARM_IRQ0_BASE + 9)
  16792. +#define INTERRUPT_JPEG (ARM_IRQ0_BASE + 10)
  16793. +#define INTERRUPT_USB (ARM_IRQ0_BASE + 11)
  16794. +#define INTERRUPT_3D (ARM_IRQ0_BASE + 12)
  16795. +#define INTERRUPT_DMA2 (ARM_IRQ0_BASE + 13)
  16796. +#define INTERRUPT_DMA3 (ARM_IRQ0_BASE + 14)
  16797. +#define INTERRUPT_I2C (ARM_IRQ0_BASE + 15)
  16798. +#define INTERRUPT_SPI (ARM_IRQ0_BASE + 16)
  16799. +#define INTERRUPT_I2SPCM (ARM_IRQ0_BASE + 17)
  16800. +#define INTERRUPT_SDIO (ARM_IRQ0_BASE + 18)
  16801. +#define INTERRUPT_UART (ARM_IRQ0_BASE + 19)
  16802. +#define INTERRUPT_ARASANSDIO (ARM_IRQ0_BASE + 20)
  16803. +
  16804. +#define ARM_IRQ_LOCAL_BASE 96
  16805. +#define INTERRUPT_ARM_LOCAL_CNTPSIRQ (ARM_IRQ_LOCAL_BASE + 0)
  16806. +#define INTERRUPT_ARM_LOCAL_CNTPNSIRQ (ARM_IRQ_LOCAL_BASE + 1)
  16807. +#define INTERRUPT_ARM_LOCAL_CNTHPIRQ (ARM_IRQ_LOCAL_BASE + 2)
  16808. +#define INTERRUPT_ARM_LOCAL_CNTVIRQ (ARM_IRQ_LOCAL_BASE + 3)
  16809. +#define INTERRUPT_ARM_LOCAL_MAILBOX0 (ARM_IRQ_LOCAL_BASE + 4)
  16810. +#define INTERRUPT_ARM_LOCAL_MAILBOX1 (ARM_IRQ_LOCAL_BASE + 5)
  16811. +#define INTERRUPT_ARM_LOCAL_MAILBOX2 (ARM_IRQ_LOCAL_BASE + 6)
  16812. +#define INTERRUPT_ARM_LOCAL_MAILBOX3 (ARM_IRQ_LOCAL_BASE + 7)
  16813. +#define INTERRUPT_ARM_LOCAL_GPU_FAST (ARM_IRQ_LOCAL_BASE + 8)
  16814. +#define INTERRUPT_ARM_LOCAL_PMU_FAST (ARM_IRQ_LOCAL_BASE + 9)
  16815. +#define INTERRUPT_ARM_LOCAL_ZERO (ARM_IRQ_LOCAL_BASE + 10)
  16816. +#define INTERRUPT_ARM_LOCAL_TIMER (ARM_IRQ_LOCAL_BASE + 11)
  16817. +
  16818. +/*
  16819. + * Watchdog
  16820. + */
  16821. +#define PM_RSTC (PM_BASE+0x1c)
  16822. +#define PM_RSTS (PM_BASE+0x20)
  16823. +#define PM_WDOG (PM_BASE+0x24)
  16824. +
  16825. +#define PM_WDOG_RESET 0000000000
  16826. +#define PM_PASSWORD 0x5a000000
  16827. +#define PM_WDOG_TIME_SET 0x000fffff
  16828. +#define PM_RSTC_WRCFG_CLR 0xffffffcf
  16829. +#define PM_RSTC_WRCFG_SET 0x00000030
  16830. +#define PM_RSTC_WRCFG_FULL_RESET 0x00000020
  16831. +#define PM_RSTC_RESET 0x00000102
  16832. +
  16833. +#define PM_RSTS_HADPOR_SET 0x00001000
  16834. +#define PM_RSTS_HADSRH_SET 0x00000400
  16835. +#define PM_RSTS_HADSRF_SET 0x00000200
  16836. +#define PM_RSTS_HADSRQ_SET 0x00000100
  16837. +#define PM_RSTS_HADWRH_SET 0x00000040
  16838. +#define PM_RSTS_HADWRF_SET 0x00000020
  16839. +#define PM_RSTS_HADWRQ_SET 0x00000010
  16840. +#define PM_RSTS_HADDRH_SET 0x00000004
  16841. +#define PM_RSTS_HADDRF_SET 0x00000002
  16842. +#define PM_RSTS_HADDRQ_SET 0x00000001
  16843. +
  16844. +#define UART0_CLOCK 3000000
  16845. +
  16846. +#endif
  16847. +
  16848. +/* END */
  16849. diff -Nur linux-3.18.8/arch/arm/mach-bcm2709/include/mach/power.h linux-rpi/arch/arm/mach-bcm2709/include/mach/power.h
  16850. --- linux-3.18.8/arch/arm/mach-bcm2709/include/mach/power.h 1970-01-01 01:00:00.000000000 +0100
  16851. +++ linux-rpi/arch/arm/mach-bcm2709/include/mach/power.h 2015-03-05 14:40:11.157715839 +0100
  16852. @@ -0,0 +1,26 @@
  16853. +/*
  16854. + * linux/arch/arm/mach-bcm2708/power.h
  16855. + *
  16856. + * Copyright (C) 2010 Broadcom
  16857. + *
  16858. + * This program is free software; you can redistribute it and/or modify
  16859. + * it under the terms of the GNU General Public License version 2 as
  16860. + * published by the Free Software Foundation.
  16861. + *
  16862. + * This device provides a shared mechanism for controlling the power to
  16863. + * VideoCore subsystems.
  16864. + */
  16865. +
  16866. +#ifndef _MACH_BCM2708_POWER_H
  16867. +#define _MACH_BCM2708_POWER_H
  16868. +
  16869. +#include <linux/types.h>
  16870. +#include <mach/arm_power.h>
  16871. +
  16872. +typedef unsigned int BCM_POWER_HANDLE_T;
  16873. +
  16874. +extern int bcm_power_open(BCM_POWER_HANDLE_T *handle);
  16875. +extern int bcm_power_request(BCM_POWER_HANDLE_T handle, uint32_t request);
  16876. +extern int bcm_power_close(BCM_POWER_HANDLE_T handle);
  16877. +
  16878. +#endif
  16879. diff -Nur linux-3.18.8/arch/arm/mach-bcm2709/include/mach/system.h linux-rpi/arch/arm/mach-bcm2709/include/mach/system.h
  16880. --- linux-3.18.8/arch/arm/mach-bcm2709/include/mach/system.h 1970-01-01 01:00:00.000000000 +0100
  16881. +++ linux-rpi/arch/arm/mach-bcm2709/include/mach/system.h 2015-03-05 14:40:11.157715839 +0100
  16882. @@ -0,0 +1,38 @@
  16883. +/*
  16884. + * arch/arm/mach-bcm2708/include/mach/system.h
  16885. + *
  16886. + * Copyright (C) 2010 Broadcom
  16887. + * Copyright (C) 2003 ARM Limited
  16888. + * Copyright (C) 2000 Deep Blue Solutions Ltd
  16889. + *
  16890. + * This program is free software; you can redistribute it and/or modify
  16891. + * it under the terms of the GNU General Public License as published by
  16892. + * the Free Software Foundation; either version 2 of the License, or
  16893. + * (at your option) any later version.
  16894. + *
  16895. + * This program is distributed in the hope that it will be useful,
  16896. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16897. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16898. + * GNU General Public License for more details.
  16899. + *
  16900. + * You should have received a copy of the GNU General Public License
  16901. + * along with this program; if not, write to the Free Software
  16902. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16903. + */
  16904. +#ifndef __ASM_ARCH_SYSTEM_H
  16905. +#define __ASM_ARCH_SYSTEM_H
  16906. +
  16907. +#include <linux/io.h>
  16908. +#include <mach/hardware.h>
  16909. +#include <mach/platform.h>
  16910. +
  16911. +static inline void arch_idle(void)
  16912. +{
  16913. + /*
  16914. + * This should do all the clock switching
  16915. + * and wait for interrupt tricks
  16916. + */
  16917. + cpu_do_idle();
  16918. +}
  16919. +
  16920. +#endif
  16921. diff -Nur linux-3.18.8/arch/arm/mach-bcm2709/include/mach/timex.h linux-rpi/arch/arm/mach-bcm2709/include/mach/timex.h
  16922. --- linux-3.18.8/arch/arm/mach-bcm2709/include/mach/timex.h 1970-01-01 01:00:00.000000000 +0100
  16923. +++ linux-rpi/arch/arm/mach-bcm2709/include/mach/timex.h 2015-03-05 14:40:11.157715839 +0100
  16924. @@ -0,0 +1,23 @@
  16925. +/*
  16926. + * arch/arm/mach-bcm2708/include/mach/timex.h
  16927. + *
  16928. + * BCM2708 sysem clock frequency
  16929. + *
  16930. + * Copyright (C) 2010 Broadcom
  16931. + *
  16932. + * This program is free software; you can redistribute it and/or modify
  16933. + * it under the terms of the GNU General Public License as published by
  16934. + * the Free Software Foundation; either version 2 of the License, or
  16935. + * (at your option) any later version.
  16936. + *
  16937. + * This program is distributed in the hope that it will be useful,
  16938. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16939. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16940. + * GNU General Public License for more details.
  16941. + *
  16942. + * You should have received a copy of the GNU General Public License
  16943. + * along with this program; if not, write to the Free Software
  16944. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16945. + */
  16946. +
  16947. +#define CLOCK_TICK_RATE (1000000)
  16948. diff -Nur linux-3.18.8/arch/arm/mach-bcm2709/include/mach/uncompress.h linux-rpi/arch/arm/mach-bcm2709/include/mach/uncompress.h
  16949. --- linux-3.18.8/arch/arm/mach-bcm2709/include/mach/uncompress.h 1970-01-01 01:00:00.000000000 +0100
  16950. +++ linux-rpi/arch/arm/mach-bcm2709/include/mach/uncompress.h 2015-03-05 14:40:11.157715839 +0100
  16951. @@ -0,0 +1,84 @@
  16952. +/*
  16953. + * arch/arm/mach-bcn2708/include/mach/uncompress.h
  16954. + *
  16955. + * Copyright (C) 2010 Broadcom
  16956. + * Copyright (C) 2003 ARM Limited
  16957. + *
  16958. + * This program is free software; you can redistribute it and/or modify
  16959. + * it under the terms of the GNU General Public License as published by
  16960. + * the Free Software Foundation; either version 2 of the License, or
  16961. + * (at your option) any later version.
  16962. + *
  16963. + * This program is distributed in the hope that it will be useful,
  16964. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16965. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16966. + * GNU General Public License for more details.
  16967. + *
  16968. + * You should have received a copy of the GNU General Public License
  16969. + * along with this program; if not, write to the Free Software
  16970. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16971. + */
  16972. +
  16973. +#include <linux/io.h>
  16974. +#include <linux/amba/serial.h>
  16975. +#include <mach/hardware.h>
  16976. +
  16977. +#define UART_BAUD 115200
  16978. +
  16979. +#define BCM2708_UART_DR __io(UART0_BASE + UART01x_DR)
  16980. +#define BCM2708_UART_FR __io(UART0_BASE + UART01x_FR)
  16981. +#define BCM2708_UART_IBRD __io(UART0_BASE + UART011_IBRD)
  16982. +#define BCM2708_UART_FBRD __io(UART0_BASE + UART011_FBRD)
  16983. +#define BCM2708_UART_LCRH __io(UART0_BASE + UART011_LCRH)
  16984. +#define BCM2708_UART_CR __io(UART0_BASE + UART011_CR)
  16985. +
  16986. +/*
  16987. + * This does not append a newline
  16988. + */
  16989. +static inline void putc(int c)
  16990. +{
  16991. + while (__raw_readl(BCM2708_UART_FR) & UART01x_FR_TXFF)
  16992. + barrier();
  16993. +
  16994. + __raw_writel(c, BCM2708_UART_DR);
  16995. +}
  16996. +
  16997. +static inline void flush(void)
  16998. +{
  16999. + int fr;
  17000. +
  17001. + do {
  17002. + fr = __raw_readl(BCM2708_UART_FR);
  17003. + barrier();
  17004. + } while ((fr & (UART011_FR_TXFE | UART01x_FR_BUSY)) != UART011_FR_TXFE);
  17005. +}
  17006. +
  17007. +static inline void arch_decomp_setup(void)
  17008. +{
  17009. + int temp, div, rem, frac;
  17010. +
  17011. + temp = 16 * UART_BAUD;
  17012. + div = UART0_CLOCK / temp;
  17013. + rem = UART0_CLOCK % temp;
  17014. + temp = (8 * rem) / UART_BAUD;
  17015. + frac = (temp >> 1) + (temp & 1);
  17016. +
  17017. + /* Make sure the UART is disabled before we start */
  17018. + __raw_writel(0, BCM2708_UART_CR);
  17019. +
  17020. + /* Set the baud rate */
  17021. + __raw_writel(div, BCM2708_UART_IBRD);
  17022. + __raw_writel(frac, BCM2708_UART_FBRD);
  17023. +
  17024. + /* Set the UART to 8n1, FIFO enabled */
  17025. + __raw_writel(UART01x_LCRH_WLEN_8 | UART01x_LCRH_FEN, BCM2708_UART_LCRH);
  17026. +
  17027. + /* Enable the UART */
  17028. + __raw_writel(UART01x_CR_UARTEN | UART011_CR_TXE | UART011_CR_RXE,
  17029. + BCM2708_UART_CR);
  17030. +}
  17031. +
  17032. +/*
  17033. + * nothing to do
  17034. + */
  17035. +#define arch_decomp_wdog()
  17036. diff -Nur linux-3.18.8/arch/arm/mach-bcm2709/include/mach/vcio.h linux-rpi/arch/arm/mach-bcm2709/include/mach/vcio.h
  17037. --- linux-3.18.8/arch/arm/mach-bcm2709/include/mach/vcio.h 1970-01-01 01:00:00.000000000 +0100
  17038. +++ linux-rpi/arch/arm/mach-bcm2709/include/mach/vcio.h 2015-03-05 14:40:11.157715839 +0100
  17039. @@ -0,0 +1,165 @@
  17040. +/*
  17041. + * arch/arm/mach-bcm2708/include/mach/vcio.h
  17042. + *
  17043. + * Copyright (C) 2010 Broadcom
  17044. + *
  17045. + * This program is free software; you can redistribute it and/or modify
  17046. + * it under the terms of the GNU General Public License as published by
  17047. + * the Free Software Foundation; either version 2 of the License, or
  17048. + * (at your option) any later version.
  17049. + *
  17050. + * This program is distributed in the hope that it will be useful,
  17051. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17052. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17053. + * GNU General Public License for more details.
  17054. + *
  17055. + * You should have received a copy of the GNU General Public License
  17056. + * along with this program; if not, write to the Free Software
  17057. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17058. + */
  17059. +#ifndef _MACH_BCM2708_VCIO_H
  17060. +#define _MACH_BCM2708_VCIO_H
  17061. +
  17062. +/* Routines to handle I/O via the VideoCore "ARM control" registers
  17063. + * (semaphores, doorbells, mailboxes)
  17064. + */
  17065. +
  17066. +#define BCM_VCIO_DRIVER_NAME "bcm2708_vcio"
  17067. +
  17068. +/* Constants shared with the ARM identifying separate mailbox channels */
  17069. +#define MBOX_CHAN_POWER 0 /* for use by the power management interface */
  17070. +#define MBOX_CHAN_FB 1 /* for use by the frame buffer */
  17071. +#define MBOX_CHAN_VCHIQ 3 /* for use by the VCHIQ interface */
  17072. +#define MBOX_CHAN_PROPERTY 8 /* for use by the property channel */
  17073. +#define MBOX_CHAN_COUNT 9
  17074. +
  17075. +enum {
  17076. + VCMSG_PROCESS_REQUEST = 0x00000000
  17077. +};
  17078. +enum {
  17079. + VCMSG_REQUEST_SUCCESSFUL = 0x80000000,
  17080. + VCMSG_REQUEST_FAILED = 0x80000001
  17081. +};
  17082. +/* Mailbox property tags */
  17083. +enum {
  17084. + VCMSG_PROPERTY_END = 0x00000000,
  17085. + VCMSG_GET_FIRMWARE_REVISION = 0x00000001,
  17086. + VCMSG_GET_BOARD_MODEL = 0x00010001,
  17087. + VCMSG_GET_BOARD_REVISION = 0x00010002,
  17088. + VCMSG_GET_BOARD_MAC_ADDRESS = 0x00010003,
  17089. + VCMSG_GET_BOARD_SERIAL = 0x00010004,
  17090. + VCMSG_GET_ARM_MEMORY = 0x00010005,
  17091. + VCMSG_GET_VC_MEMORY = 0x00010006,
  17092. + VCMSG_GET_CLOCKS = 0x00010007,
  17093. + VCMSG_GET_COMMAND_LINE = 0x00050001,
  17094. + VCMSG_GET_DMA_CHANNELS = 0x00060001,
  17095. + VCMSG_GET_POWER_STATE = 0x00020001,
  17096. + VCMSG_GET_TIMING = 0x00020002,
  17097. + VCMSG_SET_POWER_STATE = 0x00028001,
  17098. + VCMSG_GET_CLOCK_STATE = 0x00030001,
  17099. + VCMSG_SET_CLOCK_STATE = 0x00038001,
  17100. + VCMSG_GET_CLOCK_RATE = 0x00030002,
  17101. + VCMSG_SET_CLOCK_RATE = 0x00038002,
  17102. + VCMSG_GET_VOLTAGE = 0x00030003,
  17103. + VCMSG_SET_VOLTAGE = 0x00038003,
  17104. + VCMSG_GET_MAX_CLOCK = 0x00030004,
  17105. + VCMSG_GET_MAX_VOLTAGE = 0x00030005,
  17106. + VCMSG_GET_TEMPERATURE = 0x00030006,
  17107. + VCMSG_GET_MIN_CLOCK = 0x00030007,
  17108. + VCMSG_GET_MIN_VOLTAGE = 0x00030008,
  17109. + VCMSG_GET_TURBO = 0x00030009,
  17110. + VCMSG_GET_MAX_TEMPERATURE = 0x0003000a,
  17111. + VCMSG_GET_STC = 0x0003000b,
  17112. + VCMSG_SET_TURBO = 0x00038009,
  17113. + VCMSG_SET_ALLOCATE_MEM = 0x0003000c,
  17114. + VCMSG_SET_LOCK_MEM = 0x0003000d,
  17115. + VCMSG_SET_UNLOCK_MEM = 0x0003000e,
  17116. + VCMSG_SET_RELEASE_MEM = 0x0003000f,
  17117. + VCMSG_SET_EXECUTE_CODE = 0x00030010,
  17118. + VCMSG_SET_EXECUTE_QPU = 0x00030011,
  17119. + VCMSG_SET_ENABLE_QPU = 0x00030012,
  17120. + VCMSG_GET_RESOURCE_HANDLE = 0x00030014,
  17121. + VCMSG_GET_EDID_BLOCK = 0x00030020,
  17122. + VCMSG_GET_CUSTOMER_OTP = 0x00030021,
  17123. + VCMSG_SET_CUSTOMER_OTP = 0x00038021,
  17124. + VCMSG_SET_ALLOCATE_BUFFER = 0x00040001,
  17125. + VCMSG_SET_RELEASE_BUFFER = 0x00048001,
  17126. + VCMSG_SET_BLANK_SCREEN = 0x00040002,
  17127. + VCMSG_TST_BLANK_SCREEN = 0x00044002,
  17128. + VCMSG_GET_PHYSICAL_WIDTH_HEIGHT = 0x00040003,
  17129. + VCMSG_TST_PHYSICAL_WIDTH_HEIGHT = 0x00044003,
  17130. + VCMSG_SET_PHYSICAL_WIDTH_HEIGHT = 0x00048003,
  17131. + VCMSG_GET_VIRTUAL_WIDTH_HEIGHT = 0x00040004,
  17132. + VCMSG_TST_VIRTUAL_WIDTH_HEIGHT = 0x00044004,
  17133. + VCMSG_SET_VIRTUAL_WIDTH_HEIGHT = 0x00048004,
  17134. + VCMSG_GET_DEPTH = 0x00040005,
  17135. + VCMSG_TST_DEPTH = 0x00044005,
  17136. + VCMSG_SET_DEPTH = 0x00048005,
  17137. + VCMSG_GET_PIXEL_ORDER = 0x00040006,
  17138. + VCMSG_TST_PIXEL_ORDER = 0x00044006,
  17139. + VCMSG_SET_PIXEL_ORDER = 0x00048006,
  17140. + VCMSG_GET_ALPHA_MODE = 0x00040007,
  17141. + VCMSG_TST_ALPHA_MODE = 0x00044007,
  17142. + VCMSG_SET_ALPHA_MODE = 0x00048007,
  17143. + VCMSG_GET_PITCH = 0x00040008,
  17144. + VCMSG_TST_PITCH = 0x00044008,
  17145. + VCMSG_SET_PITCH = 0x00048008,
  17146. + VCMSG_GET_VIRTUAL_OFFSET = 0x00040009,
  17147. + VCMSG_TST_VIRTUAL_OFFSET = 0x00044009,
  17148. + VCMSG_SET_VIRTUAL_OFFSET = 0x00048009,
  17149. + VCMSG_GET_OVERSCAN = 0x0004000a,
  17150. + VCMSG_TST_OVERSCAN = 0x0004400a,
  17151. + VCMSG_SET_OVERSCAN = 0x0004800a,
  17152. + VCMSG_GET_PALETTE = 0x0004000b,
  17153. + VCMSG_TST_PALETTE = 0x0004400b,
  17154. + VCMSG_SET_PALETTE = 0x0004800b,
  17155. + VCMSG_GET_LAYER = 0x0004000c,
  17156. + VCMSG_TST_LAYER = 0x0004400c,
  17157. + VCMSG_SET_LAYER = 0x0004800c,
  17158. + VCMSG_GET_TRANSFORM = 0x0004000d,
  17159. + VCMSG_TST_TRANSFORM = 0x0004400d,
  17160. + VCMSG_SET_TRANSFORM = 0x0004800d,
  17161. + VCMSG_TST_VSYNC = 0x0004400e,
  17162. + VCMSG_SET_VSYNC = 0x0004800e,
  17163. + VCMSG_SET_CURSOR_INFO = 0x00008010,
  17164. + VCMSG_SET_CURSOR_STATE = 0x00008011,
  17165. +};
  17166. +
  17167. +extern int /*rc*/ bcm_mailbox_read(unsigned chan, uint32_t *data28);
  17168. +extern int /*rc*/ bcm_mailbox_write(unsigned chan, uint32_t data28);
  17169. +extern int /*rc*/ bcm_mailbox_property(void *data, int size);
  17170. +
  17171. +#include <linux/ioctl.h>
  17172. +
  17173. +/*
  17174. + * The major device number. We can't rely on dynamic
  17175. + * registration any more, because ioctls need to know
  17176. + * it.
  17177. + */
  17178. +#define MAJOR_NUM 100
  17179. +
  17180. +/*
  17181. + * Set the message of the device driver
  17182. + */
  17183. +#define IOCTL_MBOX_PROPERTY _IOWR(MAJOR_NUM, 0, char *)
  17184. +/*
  17185. + * _IOWR means that we're creating an ioctl command
  17186. + * number for passing information from a user process
  17187. + * to the kernel module and from the kernel module to user process
  17188. + *
  17189. + * The first arguments, MAJOR_NUM, is the major device
  17190. + * number we're using.
  17191. + *
  17192. + * The second argument is the number of the command
  17193. + * (there could be several with different meanings).
  17194. + *
  17195. + * The third argument is the type we want to get from
  17196. + * the process to the kernel.
  17197. + */
  17198. +
  17199. +/*
  17200. + * The name of the device file
  17201. + */
  17202. +#define DEVICE_FILE_NAME "vcio"
  17203. +
  17204. +#endif
  17205. diff -Nur linux-3.18.8/arch/arm/mach-bcm2709/include/mach/vc_mem.h linux-rpi/arch/arm/mach-bcm2709/include/mach/vc_mem.h
  17206. --- linux-3.18.8/arch/arm/mach-bcm2709/include/mach/vc_mem.h 1970-01-01 01:00:00.000000000 +0100
  17207. +++ linux-rpi/arch/arm/mach-bcm2709/include/mach/vc_mem.h 2015-03-05 14:40:11.157715839 +0100
  17208. @@ -0,0 +1,35 @@
  17209. +/*****************************************************************************
  17210. +* Copyright 2010 - 2011 Broadcom Corporation. All rights reserved.
  17211. +*
  17212. +* Unless you and Broadcom execute a separate written software license
  17213. +* agreement governing use of this software, this software is licensed to you
  17214. +* under the terms of the GNU General Public License version 2, available at
  17215. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  17216. +*
  17217. +* Notwithstanding the above, under no circumstances may you combine this
  17218. +* software in any way with any other Broadcom software provided under a
  17219. +* license other than the GPL, without Broadcom's express prior written
  17220. +* consent.
  17221. +*****************************************************************************/
  17222. +
  17223. +#if !defined( VC_MEM_H )
  17224. +#define VC_MEM_H
  17225. +
  17226. +#include <linux/ioctl.h>
  17227. +
  17228. +#define VC_MEM_IOC_MAGIC 'v'
  17229. +
  17230. +#define VC_MEM_IOC_MEM_PHYS_ADDR _IOR( VC_MEM_IOC_MAGIC, 0, unsigned long )
  17231. +#define VC_MEM_IOC_MEM_SIZE _IOR( VC_MEM_IOC_MAGIC, 1, unsigned int )
  17232. +#define VC_MEM_IOC_MEM_BASE _IOR( VC_MEM_IOC_MAGIC, 2, unsigned int )
  17233. +#define VC_MEM_IOC_MEM_LOAD _IOR( VC_MEM_IOC_MAGIC, 3, unsigned int )
  17234. +
  17235. +#if defined( __KERNEL__ )
  17236. +#define VC_MEM_TO_ARM_ADDR_MASK 0x3FFFFFFF
  17237. +
  17238. +extern unsigned long mm_vc_mem_phys_addr;
  17239. +extern unsigned int mm_vc_mem_size;
  17240. +extern int vc_mem_get_current_size( void );
  17241. +#endif
  17242. +
  17243. +#endif /* VC_MEM_H */
  17244. diff -Nur linux-3.18.8/arch/arm/mach-bcm2709/include/mach/vc_support.h linux-rpi/arch/arm/mach-bcm2709/include/mach/vc_support.h
  17245. --- linux-3.18.8/arch/arm/mach-bcm2709/include/mach/vc_support.h 1970-01-01 01:00:00.000000000 +0100
  17246. +++ linux-rpi/arch/arm/mach-bcm2709/include/mach/vc_support.h 2015-03-05 14:40:11.157715839 +0100
  17247. @@ -0,0 +1,69 @@
  17248. +#ifndef _VC_SUPPORT_H_
  17249. +#define _VC_SUPPORT_H_
  17250. +
  17251. +/*
  17252. + * vc_support.h
  17253. + *
  17254. + * Created on: 25 Nov 2012
  17255. + * Author: Simon
  17256. + */
  17257. +
  17258. +enum {
  17259. +/*
  17260. + If a MEM_HANDLE_T is discardable, the memory manager may resize it to size
  17261. + 0 at any time when it is not locked or retained.
  17262. + */
  17263. + MEM_FLAG_DISCARDABLE = 1 << 0,
  17264. +
  17265. + /*
  17266. + If a MEM_HANDLE_T is allocating (or normal), its block of memory will be
  17267. + accessed in an allocating fashion through the cache.
  17268. + */
  17269. + MEM_FLAG_NORMAL = 0 << 2,
  17270. + MEM_FLAG_ALLOCATING = MEM_FLAG_NORMAL,
  17271. +
  17272. + /*
  17273. + If a MEM_HANDLE_T is direct, its block of memory will be accessed
  17274. + directly, bypassing the cache.
  17275. + */
  17276. + MEM_FLAG_DIRECT = 1 << 2,
  17277. +
  17278. + /*
  17279. + If a MEM_HANDLE_T is coherent, its block of memory will be accessed in a
  17280. + non-allocating fashion through the cache.
  17281. + */
  17282. + MEM_FLAG_COHERENT = 2 << 2,
  17283. +
  17284. + /*
  17285. + If a MEM_HANDLE_T is L1-nonallocating, its block of memory will be accessed by
  17286. + the VPU in a fashion which is allocating in L2, but only coherent in L1.
  17287. + */
  17288. + MEM_FLAG_L1_NONALLOCATING = (MEM_FLAG_DIRECT | MEM_FLAG_COHERENT),
  17289. +
  17290. + /*
  17291. + If a MEM_HANDLE_T is zero'd, its contents are set to 0 rather than
  17292. + MEM_HANDLE_INVALID on allocation and resize up.
  17293. + */
  17294. + MEM_FLAG_ZERO = 1 << 4,
  17295. +
  17296. + /*
  17297. + If a MEM_HANDLE_T is uninitialised, it will not be reset to a defined value
  17298. + (either zero, or all 1's) on allocation.
  17299. + */
  17300. + MEM_FLAG_NO_INIT = 1 << 5,
  17301. +
  17302. + /*
  17303. + Hints.
  17304. + */
  17305. + MEM_FLAG_HINT_PERMALOCK = 1 << 6, /* Likely to be locked for long periods of time. */
  17306. +};
  17307. +
  17308. +unsigned int AllocateVcMemory(unsigned int *pHandle, unsigned int size, unsigned int alignment, unsigned int flags);
  17309. +unsigned int ReleaseVcMemory(unsigned int handle);
  17310. +unsigned int LockVcMemory(unsigned int *pBusAddress, unsigned int handle);
  17311. +unsigned int UnlockVcMemory(unsigned int handle);
  17312. +
  17313. +unsigned int ExecuteVcCode(unsigned int code,
  17314. + unsigned int r0, unsigned int r1, unsigned int r2, unsigned int r3, unsigned int r4, unsigned int r5);
  17315. +
  17316. +#endif
  17317. diff -Nur linux-3.18.8/arch/arm/mach-bcm2709/include/mach/vmalloc.h linux-rpi/arch/arm/mach-bcm2709/include/mach/vmalloc.h
  17318. --- linux-3.18.8/arch/arm/mach-bcm2709/include/mach/vmalloc.h 1970-01-01 01:00:00.000000000 +0100
  17319. +++ linux-rpi/arch/arm/mach-bcm2709/include/mach/vmalloc.h 2015-03-05 14:40:11.157715839 +0100
  17320. @@ -0,0 +1,20 @@
  17321. +/*
  17322. + * arch/arm/mach-bcm2708/include/mach/vmalloc.h
  17323. + *
  17324. + * Copyright (C) 2010 Broadcom
  17325. + *
  17326. + * This program is free software; you can redistribute it and/or modify
  17327. + * it under the terms of the GNU General Public License as published by
  17328. + * the Free Software Foundation; either version 2 of the License, or
  17329. + * (at your option) any later version.
  17330. + *
  17331. + * This program is distributed in the hope that it will be useful,
  17332. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17333. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17334. + * GNU General Public License for more details.
  17335. + *
  17336. + * You should have received a copy of the GNU General Public License
  17337. + * along with this program; if not, write to the Free Software
  17338. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17339. + */
  17340. +#define VMALLOC_END (0xff000000)
  17341. diff -Nur linux-3.18.8/arch/arm/mach-bcm2709/Kconfig linux-rpi/arch/arm/mach-bcm2709/Kconfig
  17342. --- linux-3.18.8/arch/arm/mach-bcm2709/Kconfig 1970-01-01 01:00:00.000000000 +0100
  17343. +++ linux-rpi/arch/arm/mach-bcm2709/Kconfig 2015-03-05 14:40:11.153715839 +0100
  17344. @@ -0,0 +1,49 @@
  17345. +menu "Broadcom BCM2709 Implementations"
  17346. + depends on ARCH_BCM2709
  17347. +
  17348. +config MACH_BCM2709
  17349. + bool "Broadcom BCM2709 Development Platform"
  17350. + help
  17351. + Include support for the Broadcom(R) BCM2709 platform.
  17352. +
  17353. +config BCM2709_DT
  17354. + bool "BCM2709 Device Tree support"
  17355. + depends on MACH_BCM2709
  17356. + default n
  17357. + select USE_OF
  17358. + select ARCH_REQUIRE_GPIOLIB
  17359. + select PINCTRL
  17360. + select PINCTRL_BCM2835
  17361. + help
  17362. + Enable Device Tree support for BCM2709
  17363. +
  17364. +config BCM2708_GPIO
  17365. + bool "BCM2709 gpio support"
  17366. + depends on MACH_BCM2709
  17367. + select ARCH_REQUIRE_GPIOLIB
  17368. + default y
  17369. + help
  17370. + Include support for the Broadcom(R) BCM2709 gpio.
  17371. +
  17372. +config BCM2708_VCMEM
  17373. + bool "Videocore Memory"
  17374. + depends on MACH_BCM2709
  17375. + default y
  17376. + help
  17377. + Helper for videocore memory access and total size allocation.
  17378. +
  17379. +config BCM2708_NOL2CACHE
  17380. + bool "Videocore L2 cache disable"
  17381. + depends on MACH_BCM2709
  17382. + default y
  17383. + help
  17384. + Do not allow ARM to use GPU's L2 cache. Requires disable_l2cache in config.txt.
  17385. +
  17386. +config BCM2708_SPIDEV
  17387. + bool "Bind spidev to SPI0 master"
  17388. + depends on MACH_BCM2709
  17389. + depends on SPI
  17390. + default y
  17391. + help
  17392. + Binds spidev driver to the SPI0 master
  17393. +endmenu
  17394. diff -Nur linux-3.18.8/arch/arm/mach-bcm2709/Makefile linux-rpi/arch/arm/mach-bcm2709/Makefile
  17395. --- linux-3.18.8/arch/arm/mach-bcm2709/Makefile 1970-01-01 01:00:00.000000000 +0100
  17396. +++ linux-rpi/arch/arm/mach-bcm2709/Makefile 2015-03-05 14:40:11.153715839 +0100
  17397. @@ -0,0 +1,7 @@
  17398. +#
  17399. +# Makefile for the linux kernel.
  17400. +#
  17401. +
  17402. +obj-$(CONFIG_MACH_BCM2709) += bcm2709.o armctrl.o vcio.o power.o dma.o
  17403. +obj-$(CONFIG_BCM2708_GPIO) += bcm2708_gpio.o
  17404. +obj-$(CONFIG_BCM2708_VCMEM) += vc_mem.o
  17405. diff -Nur linux-3.18.8/arch/arm/mach-bcm2709/Makefile.boot linux-rpi/arch/arm/mach-bcm2709/Makefile.boot
  17406. --- linux-3.18.8/arch/arm/mach-bcm2709/Makefile.boot 1970-01-01 01:00:00.000000000 +0100
  17407. +++ linux-rpi/arch/arm/mach-bcm2709/Makefile.boot 2015-03-05 14:40:11.153715839 +0100
  17408. @@ -0,0 +1,3 @@
  17409. + zreladdr-y := 0x00008000
  17410. +params_phys-y := 0x00000100
  17411. +initrd_phys-y := 0x00800000
  17412. diff -Nur linux-3.18.8/arch/arm/mach-bcm2709/power.c linux-rpi/arch/arm/mach-bcm2709/power.c
  17413. --- linux-3.18.8/arch/arm/mach-bcm2709/power.c 1970-01-01 01:00:00.000000000 +0100
  17414. +++ linux-rpi/arch/arm/mach-bcm2709/power.c 2015-03-05 14:40:11.157715839 +0100
  17415. @@ -0,0 +1,195 @@
  17416. +/*
  17417. + * linux/arch/arm/mach-bcm2708/power.c
  17418. + *
  17419. + * Copyright (C) 2010 Broadcom
  17420. + *
  17421. + * This program is free software; you can redistribute it and/or modify
  17422. + * it under the terms of the GNU General Public License version 2 as
  17423. + * published by the Free Software Foundation.
  17424. + *
  17425. + * This device provides a shared mechanism for controlling the power to
  17426. + * VideoCore subsystems.
  17427. + */
  17428. +
  17429. +#include <linux/module.h>
  17430. +#include <linux/semaphore.h>
  17431. +#include <linux/bug.h>
  17432. +#include <mach/power.h>
  17433. +#include <mach/vcio.h>
  17434. +#include <mach/arm_power.h>
  17435. +
  17436. +#define DRIVER_NAME "bcm2708_power"
  17437. +
  17438. +#define BCM_POWER_MAXCLIENTS 4
  17439. +#define BCM_POWER_NOCLIENT (1<<31)
  17440. +
  17441. +/* Some drivers expect there devices to be permanently powered */
  17442. +#ifdef CONFIG_USB
  17443. +#define BCM_POWER_ALWAYS_ON (BCM_POWER_USB)
  17444. +#endif
  17445. +
  17446. +#if 1
  17447. +#define DPRINTK printk
  17448. +#else
  17449. +#define DPRINTK if (0) printk
  17450. +#endif
  17451. +
  17452. +struct state_struct {
  17453. + uint32_t global_request;
  17454. + uint32_t client_request[BCM_POWER_MAXCLIENTS];
  17455. + struct semaphore client_mutex;
  17456. + struct semaphore mutex;
  17457. +} g_state;
  17458. +
  17459. +int bcm_power_open(BCM_POWER_HANDLE_T *handle)
  17460. +{
  17461. + BCM_POWER_HANDLE_T i;
  17462. + int ret = -EBUSY;
  17463. +
  17464. + down(&g_state.client_mutex);
  17465. +
  17466. + for (i = 0; i < BCM_POWER_MAXCLIENTS; i++) {
  17467. + if (g_state.client_request[i] == BCM_POWER_NOCLIENT) {
  17468. + g_state.client_request[i] = BCM_POWER_NONE;
  17469. + *handle = i;
  17470. + ret = 0;
  17471. + break;
  17472. + }
  17473. + }
  17474. +
  17475. + up(&g_state.client_mutex);
  17476. +
  17477. + DPRINTK("bcm_power_open() -> %d\n", *handle);
  17478. +
  17479. + return ret;
  17480. +}
  17481. +EXPORT_SYMBOL_GPL(bcm_power_open);
  17482. +
  17483. +int bcm_power_request(BCM_POWER_HANDLE_T handle, uint32_t request)
  17484. +{
  17485. + int rc = 0;
  17486. +
  17487. + DPRINTK("bcm_power_request(%d, %x)\n", handle, request);
  17488. +
  17489. + if ((handle < BCM_POWER_MAXCLIENTS) &&
  17490. + (g_state.client_request[handle] != BCM_POWER_NOCLIENT)) {
  17491. + if (down_interruptible(&g_state.mutex) != 0) {
  17492. + DPRINTK("bcm_power_request -> interrupted\n");
  17493. + return -EINTR;
  17494. + }
  17495. +
  17496. + if (request != g_state.client_request[handle]) {
  17497. + uint32_t others_request = 0;
  17498. + uint32_t global_request;
  17499. + BCM_POWER_HANDLE_T i;
  17500. +
  17501. + for (i = 0; i < BCM_POWER_MAXCLIENTS; i++) {
  17502. + if (i != handle)
  17503. + others_request |=
  17504. + g_state.client_request[i];
  17505. + }
  17506. + others_request &= ~BCM_POWER_NOCLIENT;
  17507. +
  17508. + global_request = request | others_request;
  17509. + if (global_request != g_state.global_request) {
  17510. + uint32_t actual;
  17511. +
  17512. + /* Send a request to VideoCore */
  17513. + bcm_mailbox_write(MBOX_CHAN_POWER,
  17514. + global_request << 4);
  17515. +
  17516. + /* Wait for a response during power-up */
  17517. + if (global_request & ~g_state.global_request) {
  17518. + rc = bcm_mailbox_read(MBOX_CHAN_POWER,
  17519. + &actual);
  17520. + DPRINTK
  17521. + ("bcm_mailbox_read -> %08x, %d\n",
  17522. + actual, rc);
  17523. + actual >>= 4;
  17524. + } else {
  17525. + rc = 0;
  17526. + actual = global_request;
  17527. + }
  17528. +
  17529. + if (rc == 0) {
  17530. + if (actual != global_request) {
  17531. + printk(KERN_ERR
  17532. + "%s: prev global %x, new global %x, actual %x, request %x, others_request %x\n",
  17533. + __func__,
  17534. + g_state.global_request,
  17535. + global_request, actual, request, others_request);
  17536. + /* A failure */
  17537. + BUG_ON((others_request & actual)
  17538. + != others_request);
  17539. + request &= actual;
  17540. + rc = -EIO;
  17541. + }
  17542. +
  17543. + g_state.global_request = actual;
  17544. + g_state.client_request[handle] =
  17545. + request;
  17546. + }
  17547. + }
  17548. + }
  17549. + up(&g_state.mutex);
  17550. + } else {
  17551. + rc = -EINVAL;
  17552. + }
  17553. + DPRINTK("bcm_power_request -> %d\n", rc);
  17554. + return rc;
  17555. +}
  17556. +EXPORT_SYMBOL_GPL(bcm_power_request);
  17557. +
  17558. +int bcm_power_close(BCM_POWER_HANDLE_T handle)
  17559. +{
  17560. + int rc;
  17561. +
  17562. + DPRINTK("bcm_power_close(%d)\n", handle);
  17563. +
  17564. + rc = bcm_power_request(handle, BCM_POWER_NONE);
  17565. + if (rc == 0)
  17566. + g_state.client_request[handle] = BCM_POWER_NOCLIENT;
  17567. +
  17568. + return rc;
  17569. +}
  17570. +EXPORT_SYMBOL_GPL(bcm_power_close);
  17571. +
  17572. +static int __init bcm_power_init(void)
  17573. +{
  17574. +#if defined(BCM_POWER_ALWAYS_ON)
  17575. + BCM_POWER_HANDLE_T always_on_handle;
  17576. +#endif
  17577. + int rc = 0;
  17578. + int i;
  17579. +
  17580. + printk(KERN_INFO "bcm_power: Broadcom power driver\n");
  17581. + bcm_mailbox_write(MBOX_CHAN_POWER, 0);
  17582. +
  17583. + for (i = 0; i < BCM_POWER_MAXCLIENTS; i++)
  17584. + g_state.client_request[i] = BCM_POWER_NOCLIENT;
  17585. +
  17586. + sema_init(&g_state.client_mutex, 1);
  17587. + sema_init(&g_state.mutex, 1);
  17588. +
  17589. + g_state.global_request = 0;
  17590. +#if defined(BCM_POWER_ALWAYS_ON)
  17591. + if (BCM_POWER_ALWAYS_ON) {
  17592. + bcm_power_open(&always_on_handle);
  17593. + bcm_power_request(always_on_handle, BCM_POWER_ALWAYS_ON);
  17594. + }
  17595. +#endif
  17596. +
  17597. + return rc;
  17598. +}
  17599. +
  17600. +static void __exit bcm_power_exit(void)
  17601. +{
  17602. + bcm_mailbox_write(MBOX_CHAN_POWER, 0);
  17603. +}
  17604. +
  17605. +arch_initcall(bcm_power_init); /* Initialize early */
  17606. +module_exit(bcm_power_exit);
  17607. +
  17608. +MODULE_AUTHOR("Phil Elwell");
  17609. +MODULE_DESCRIPTION("Interface to BCM2708 power management");
  17610. +MODULE_LICENSE("GPL");
  17611. diff -Nur linux-3.18.8/arch/arm/mach-bcm2709/vcio.c linux-rpi/arch/arm/mach-bcm2709/vcio.c
  17612. --- linux-3.18.8/arch/arm/mach-bcm2709/vcio.c 1970-01-01 01:00:00.000000000 +0100
  17613. +++ linux-rpi/arch/arm/mach-bcm2709/vcio.c 2015-03-05 14:40:11.157715839 +0100
  17614. @@ -0,0 +1,484 @@
  17615. +/*
  17616. + * linux/arch/arm/mach-bcm2708/vcio.c
  17617. + *
  17618. + * Copyright (C) 2010 Broadcom
  17619. + *
  17620. + * This program is free software; you can redistribute it and/or modify
  17621. + * it under the terms of the GNU General Public License version 2 as
  17622. + * published by the Free Software Foundation.
  17623. + *
  17624. + * This device provides a shared mechanism for writing to the mailboxes,
  17625. + * semaphores, doorbells etc. that are shared between the ARM and the
  17626. + * VideoCore processor
  17627. + */
  17628. +
  17629. +#if defined(CONFIG_SERIAL_BCM_MBOX_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
  17630. +#define SUPPORT_SYSRQ
  17631. +#endif
  17632. +
  17633. +#include <linux/module.h>
  17634. +#include <linux/console.h>
  17635. +#include <linux/serial_core.h>
  17636. +#include <linux/serial.h>
  17637. +#include <linux/errno.h>
  17638. +#include <linux/device.h>
  17639. +#include <linux/init.h>
  17640. +#include <linux/mm.h>
  17641. +#include <linux/dma-mapping.h>
  17642. +#include <linux/platform_device.h>
  17643. +#include <linux/sysrq.h>
  17644. +#include <linux/delay.h>
  17645. +#include <linux/slab.h>
  17646. +#include <linux/interrupt.h>
  17647. +#include <linux/irq.h>
  17648. +
  17649. +#include <linux/io.h>
  17650. +
  17651. +#include <mach/vcio.h>
  17652. +#include <mach/platform.h>
  17653. +
  17654. +#include <asm/uaccess.h>
  17655. +
  17656. +
  17657. +#define DRIVER_NAME BCM_VCIO_DRIVER_NAME
  17658. +
  17659. +/* ----------------------------------------------------------------------
  17660. + * Mailbox
  17661. + * -------------------------------------------------------------------- */
  17662. +
  17663. +/* offsets from a mail box base address */
  17664. +#define MAIL_WRT 0x00 /* write - and next 4 words */
  17665. +#define MAIL_RD 0x00 /* read - and next 4 words */
  17666. +#define MAIL_POL 0x10 /* read without popping the fifo */
  17667. +#define MAIL_SND 0x14 /* sender ID (bottom two bits) */
  17668. +#define MAIL_STA 0x18 /* status */
  17669. +#define MAIL_CNF 0x1C /* configuration */
  17670. +
  17671. +#define MBOX_MSG(chan, data28) (((data28) & ~0xf) | ((chan) & 0xf))
  17672. +#define MBOX_MSG_LSB(chan, data28) (((data28) << 4) | ((chan) & 0xf))
  17673. +#define MBOX_CHAN(msg) ((msg) & 0xf)
  17674. +#define MBOX_DATA28(msg) ((msg) & ~0xf)
  17675. +#define MBOX_DATA28_LSB(msg) (((uint32_t)msg) >> 4)
  17676. +
  17677. +#define MBOX_MAGIC 0xd0d0c0de
  17678. +static struct class *vcio_class = NULL;
  17679. +struct vc_mailbox {
  17680. + struct device *dev; /* parent device */
  17681. + void __iomem *status;
  17682. + void __iomem *config;
  17683. + void __iomem *read;
  17684. + void __iomem *write;
  17685. + uint32_t msg[MBOX_CHAN_COUNT];
  17686. + struct semaphore sema[MBOX_CHAN_COUNT];
  17687. + uint32_t magic;
  17688. +};
  17689. +
  17690. +static void mbox_init(struct vc_mailbox *mbox_out, struct device *dev,
  17691. + uint32_t addr_mbox)
  17692. +{
  17693. + int i;
  17694. +
  17695. + mbox_out->dev = dev;
  17696. + mbox_out->status = __io_address(addr_mbox + MAIL_STA);
  17697. + mbox_out->config = __io_address(addr_mbox + MAIL_CNF);
  17698. + mbox_out->read = __io_address(addr_mbox + MAIL_RD);
  17699. + /* Write to the other mailbox */
  17700. + mbox_out->write =
  17701. + __io_address((addr_mbox ^ ARM_0_MAIL0_WRT ^ ARM_0_MAIL1_WRT) +
  17702. + MAIL_WRT);
  17703. +
  17704. + for (i = 0; i < MBOX_CHAN_COUNT; i++) {
  17705. + mbox_out->msg[i] = 0;
  17706. + sema_init(&mbox_out->sema[i], 0);
  17707. + }
  17708. +
  17709. + /* Enable the interrupt on data reception */
  17710. + writel(ARM_MC_IHAVEDATAIRQEN, mbox_out->config);
  17711. +
  17712. + mbox_out->magic = MBOX_MAGIC;
  17713. +}
  17714. +
  17715. +static int mbox_write(struct vc_mailbox *mbox, unsigned chan, uint32_t data28)
  17716. +{
  17717. + int rc;
  17718. +
  17719. + if (mbox->magic != MBOX_MAGIC)
  17720. + rc = -EINVAL;
  17721. + else {
  17722. + /* wait for the mailbox FIFO to have some space in it */
  17723. + while (0 != (readl(mbox->status) & ARM_MS_FULL))
  17724. + cpu_relax();
  17725. +
  17726. + writel(MBOX_MSG(chan, data28), mbox->write);
  17727. + rc = 0;
  17728. + }
  17729. + return rc;
  17730. +}
  17731. +
  17732. +static int mbox_read(struct vc_mailbox *mbox, unsigned chan, uint32_t *data28)
  17733. +{
  17734. + int rc;
  17735. +
  17736. + if (mbox->magic != MBOX_MAGIC)
  17737. + rc = -EINVAL;
  17738. + else {
  17739. + down(&mbox->sema[chan]);
  17740. + *data28 = MBOX_DATA28(mbox->msg[chan]);
  17741. + mbox->msg[chan] = 0;
  17742. + rc = 0;
  17743. + }
  17744. + return rc;
  17745. +}
  17746. +
  17747. +static irqreturn_t mbox_irq(int irq, void *dev_id)
  17748. +{
  17749. + /* wait for the mailbox FIFO to have some data in it */
  17750. + struct vc_mailbox *mbox = (struct vc_mailbox *) dev_id;
  17751. + int status = readl(mbox->status);
  17752. + int ret = IRQ_NONE;
  17753. +
  17754. + while (!(status & ARM_MS_EMPTY)) {
  17755. + uint32_t msg = readl(mbox->read);
  17756. + int chan = MBOX_CHAN(msg);
  17757. + if (chan < MBOX_CHAN_COUNT) {
  17758. + if (mbox->msg[chan]) {
  17759. + /* Overflow */
  17760. + printk(KERN_ERR DRIVER_NAME
  17761. + ": mbox chan %d overflow - drop %08x\n",
  17762. + chan, msg);
  17763. + } else {
  17764. + mbox->msg[chan] = (msg | 0xf);
  17765. + up(&mbox->sema[chan]);
  17766. + }
  17767. + } else {
  17768. + printk(KERN_ERR DRIVER_NAME
  17769. + ": invalid channel selector (msg %08x)\n", msg);
  17770. + }
  17771. + ret = IRQ_HANDLED;
  17772. + status = readl(mbox->status);
  17773. + }
  17774. + return ret;
  17775. +}
  17776. +
  17777. +static struct irqaction mbox_irqaction = {
  17778. + .name = "ARM Mailbox IRQ",
  17779. + .flags = IRQF_DISABLED | IRQF_IRQPOLL,
  17780. + .handler = mbox_irq,
  17781. +};
  17782. +
  17783. +/* ----------------------------------------------------------------------
  17784. + * Mailbox Methods
  17785. + * -------------------------------------------------------------------- */
  17786. +
  17787. +static struct device *mbox_dev; /* we assume there's only one! */
  17788. +
  17789. +static int dev_mbox_write(struct device *dev, unsigned chan, uint32_t data28)
  17790. +{
  17791. + int rc;
  17792. +
  17793. + struct vc_mailbox *mailbox = dev_get_drvdata(dev);
  17794. + device_lock(dev);
  17795. + rc = mbox_write(mailbox, chan, data28);
  17796. + device_unlock(dev);
  17797. +
  17798. + return rc;
  17799. +}
  17800. +
  17801. +static int dev_mbox_read(struct device *dev, unsigned chan, uint32_t *data28)
  17802. +{
  17803. + int rc;
  17804. +
  17805. + struct vc_mailbox *mailbox = dev_get_drvdata(dev);
  17806. + device_lock(dev);
  17807. + rc = mbox_read(mailbox, chan, data28);
  17808. + device_unlock(dev);
  17809. +
  17810. + return rc;
  17811. +}
  17812. +
  17813. +extern int bcm_mailbox_write(unsigned chan, uint32_t data28)
  17814. +{
  17815. + if (mbox_dev)
  17816. + return dev_mbox_write(mbox_dev, chan, data28);
  17817. + else
  17818. + return -ENODEV;
  17819. +}
  17820. +EXPORT_SYMBOL_GPL(bcm_mailbox_write);
  17821. +
  17822. +extern int bcm_mailbox_read(unsigned chan, uint32_t *data28)
  17823. +{
  17824. + if (mbox_dev)
  17825. + return dev_mbox_read(mbox_dev, chan, data28);
  17826. + else
  17827. + return -ENODEV;
  17828. +}
  17829. +EXPORT_SYMBOL_GPL(bcm_mailbox_read);
  17830. +
  17831. +static void dev_mbox_register(const char *dev_name, struct device *dev)
  17832. +{
  17833. + mbox_dev = dev;
  17834. +}
  17835. +
  17836. +static int mbox_copy_from_user(void *dst, const void *src, int size)
  17837. +{
  17838. + if ( (uint32_t)src < TASK_SIZE)
  17839. + {
  17840. + return copy_from_user(dst, src, size);
  17841. + }
  17842. + else
  17843. + {
  17844. + memcpy( dst, src, size );
  17845. + return 0;
  17846. + }
  17847. +}
  17848. +
  17849. +static int mbox_copy_to_user(void *dst, const void *src, int size)
  17850. +{
  17851. + if ( (uint32_t)dst < TASK_SIZE)
  17852. + {
  17853. + return copy_to_user(dst, src, size);
  17854. + }
  17855. + else
  17856. + {
  17857. + memcpy( dst, src, size );
  17858. + return 0;
  17859. + }
  17860. +}
  17861. +
  17862. +static DEFINE_MUTEX(mailbox_lock);
  17863. +extern int bcm_mailbox_property(void *data, int size)
  17864. +{
  17865. + uint32_t success;
  17866. + dma_addr_t mem_bus; /* the memory address accessed from videocore */
  17867. + void *mem_kern; /* the memory address accessed from driver */
  17868. + int s = 0;
  17869. +
  17870. + mutex_lock(&mailbox_lock);
  17871. + /* allocate some memory for the messages communicating with GPU */
  17872. + mem_kern = dma_alloc_coherent(NULL, PAGE_ALIGN(size), &mem_bus, GFP_ATOMIC);
  17873. + if (mem_kern) {
  17874. + /* create the message */
  17875. + mbox_copy_from_user(mem_kern, data, size);
  17876. +
  17877. + /* send the message */
  17878. + wmb();
  17879. + s = bcm_mailbox_write(MBOX_CHAN_PROPERTY, (uint32_t)mem_bus);
  17880. + if (s == 0) {
  17881. + s = bcm_mailbox_read(MBOX_CHAN_PROPERTY, &success);
  17882. + }
  17883. + if (s == 0) {
  17884. + /* copy the response */
  17885. + rmb();
  17886. + mbox_copy_to_user(data, mem_kern, size);
  17887. + }
  17888. + dma_free_coherent(NULL, PAGE_ALIGN(size), mem_kern, mem_bus);
  17889. + } else {
  17890. + s = -ENOMEM;
  17891. + }
  17892. + if (s != 0)
  17893. + printk(KERN_ERR DRIVER_NAME ": %s failed (%d)\n", __func__, s);
  17894. +
  17895. + mutex_unlock(&mailbox_lock);
  17896. + return s;
  17897. +}
  17898. +EXPORT_SYMBOL_GPL(bcm_mailbox_property);
  17899. +
  17900. +/* ----------------------------------------------------------------------
  17901. + * Platform Device for Mailbox
  17902. + * -------------------------------------------------------------------- */
  17903. +
  17904. +/*
  17905. + * Is the device open right now? Used to prevent
  17906. + * concurent access into the same device
  17907. + */
  17908. +static int Device_Open = 0;
  17909. +
  17910. +/*
  17911. + * This is called whenever a process attempts to open the device file
  17912. + */
  17913. +static int device_open(struct inode *inode, struct file *file)
  17914. +{
  17915. + /*
  17916. + * We don't want to talk to two processes at the same time
  17917. + */
  17918. + if (Device_Open)
  17919. + return -EBUSY;
  17920. +
  17921. + Device_Open++;
  17922. + /*
  17923. + * Initialize the message
  17924. + */
  17925. + try_module_get(THIS_MODULE);
  17926. + return 0;
  17927. +}
  17928. +
  17929. +static int device_release(struct inode *inode, struct file *file)
  17930. +{
  17931. + /*
  17932. + * We're now ready for our next caller
  17933. + */
  17934. + Device_Open--;
  17935. +
  17936. + module_put(THIS_MODULE);
  17937. + return 0;
  17938. +}
  17939. +
  17940. +/*
  17941. + * This function is called whenever a process tries to do an ioctl on our
  17942. + * device file. We get two extra parameters (additional to the inode and file
  17943. + * structures, which all device functions get): the number of the ioctl called
  17944. + * and the parameter given to the ioctl function.
  17945. + *
  17946. + * If the ioctl is write or read/write (meaning output is returned to the
  17947. + * calling process), the ioctl call returns the output of this function.
  17948. + *
  17949. + */
  17950. +static long device_ioctl(struct file *file, /* see include/linux/fs.h */
  17951. + unsigned int ioctl_num, /* number and param for ioctl */
  17952. + unsigned long ioctl_param)
  17953. +{
  17954. + unsigned size;
  17955. + /*
  17956. + * Switch according to the ioctl called
  17957. + */
  17958. + switch (ioctl_num) {
  17959. + case IOCTL_MBOX_PROPERTY:
  17960. + /*
  17961. + * Receive a pointer to a message (in user space) and set that
  17962. + * to be the device's message. Get the parameter given to
  17963. + * ioctl by the process.
  17964. + */
  17965. + mbox_copy_from_user(&size, (void *)ioctl_param, sizeof size);
  17966. + return bcm_mailbox_property((void *)ioctl_param, size);
  17967. + break;
  17968. + default:
  17969. + printk(KERN_ERR DRIVER_NAME "unknown ioctl: %d\n", ioctl_num);
  17970. + return -EINVAL;
  17971. + }
  17972. +
  17973. + return 0;
  17974. +}
  17975. +
  17976. +/* Module Declarations */
  17977. +
  17978. +/*
  17979. + * This structure will hold the functions to be called
  17980. + * when a process does something to the device we
  17981. + * created. Since a pointer to this structure is kept in
  17982. + * the devices table, it can't be local to
  17983. + * init_module. NULL is for unimplemented functios.
  17984. + */
  17985. +struct file_operations fops = {
  17986. + .unlocked_ioctl = device_ioctl,
  17987. + .open = device_open,
  17988. + .release = device_release, /* a.k.a. close */
  17989. +};
  17990. +
  17991. +static int bcm_vcio_probe(struct platform_device *pdev)
  17992. +{
  17993. + int ret = 0;
  17994. + struct vc_mailbox *mailbox;
  17995. +
  17996. + mailbox = kzalloc(sizeof(*mailbox), GFP_KERNEL);
  17997. + if (NULL == mailbox) {
  17998. + printk(KERN_ERR DRIVER_NAME ": failed to allocate "
  17999. + "mailbox memory\n");
  18000. + ret = -ENOMEM;
  18001. + } else {
  18002. + struct resource *res;
  18003. +
  18004. + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  18005. + if (res == NULL) {
  18006. + printk(KERN_ERR DRIVER_NAME ": failed to obtain memory "
  18007. + "resource\n");
  18008. + ret = -ENODEV;
  18009. + kfree(mailbox);
  18010. + } else {
  18011. + /* should be based on the registers from res really */
  18012. + mbox_init(mailbox, &pdev->dev, ARM_0_MAIL0_RD);
  18013. +
  18014. + platform_set_drvdata(pdev, mailbox);
  18015. + dev_mbox_register(DRIVER_NAME, &pdev->dev);
  18016. +
  18017. + mbox_irqaction.dev_id = mailbox;
  18018. + setup_irq(IRQ_ARM_MAILBOX, &mbox_irqaction);
  18019. + printk(KERN_INFO DRIVER_NAME ": mailbox at %p\n",
  18020. + __io_address(ARM_0_MAIL0_RD));
  18021. + }
  18022. + }
  18023. +
  18024. + if (ret == 0) {
  18025. + /*
  18026. + * Register the character device
  18027. + */
  18028. + ret = register_chrdev(MAJOR_NUM, DEVICE_FILE_NAME, &fops);
  18029. +
  18030. + /*
  18031. + * Negative values signify an error
  18032. + */
  18033. + if (ret < 0) {
  18034. + printk(KERN_ERR DRIVER_NAME
  18035. + "Failed registering the character device %d\n", ret);
  18036. + return ret;
  18037. + }
  18038. + vcio_class = class_create(THIS_MODULE, BCM_VCIO_DRIVER_NAME);
  18039. + if (IS_ERR(vcio_class)) {
  18040. + ret = PTR_ERR(vcio_class);
  18041. + return ret ;
  18042. + }
  18043. + device_create(vcio_class, NULL, MKDEV(MAJOR_NUM, 0), NULL,
  18044. + "vcio");
  18045. + }
  18046. + return ret;
  18047. +}
  18048. +
  18049. +static int bcm_vcio_remove(struct platform_device *pdev)
  18050. +{
  18051. + struct vc_mailbox *mailbox = platform_get_drvdata(pdev);
  18052. +
  18053. + platform_set_drvdata(pdev, NULL);
  18054. + kfree(mailbox);
  18055. +
  18056. + return 0;
  18057. +}
  18058. +
  18059. +static struct platform_driver bcm_mbox_driver = {
  18060. + .probe = bcm_vcio_probe,
  18061. + .remove = bcm_vcio_remove,
  18062. +
  18063. + .driver = {
  18064. + .name = DRIVER_NAME,
  18065. + .owner = THIS_MODULE,
  18066. + },
  18067. +};
  18068. +
  18069. +static int __init bcm_mbox_init(void)
  18070. +{
  18071. + int ret;
  18072. +
  18073. + printk(KERN_INFO "mailbox: Broadcom VideoCore Mailbox driver\n");
  18074. +
  18075. + ret = platform_driver_register(&bcm_mbox_driver);
  18076. + if (ret != 0) {
  18077. + printk(KERN_ERR DRIVER_NAME ": failed to register "
  18078. + "on platform\n");
  18079. + }
  18080. +
  18081. + return ret;
  18082. +}
  18083. +
  18084. +static void __exit bcm_mbox_exit(void)
  18085. +{
  18086. + device_destroy(vcio_class,MKDEV(MAJOR_NUM, 0));
  18087. + class_destroy(vcio_class);
  18088. + unregister_chrdev(MAJOR_NUM, DEVICE_FILE_NAME);
  18089. + platform_driver_unregister(&bcm_mbox_driver);
  18090. +}
  18091. +
  18092. +arch_initcall(bcm_mbox_init); /* Initialize early */
  18093. +module_exit(bcm_mbox_exit);
  18094. +
  18095. +MODULE_AUTHOR("Gray Girling");
  18096. +MODULE_DESCRIPTION("ARM I/O to VideoCore processor");
  18097. +MODULE_LICENSE("GPL");
  18098. +MODULE_ALIAS("platform:bcm-mbox");
  18099. diff -Nur linux-3.18.8/arch/arm/mach-bcm2709/vc_mem.c linux-rpi/arch/arm/mach-bcm2709/vc_mem.c
  18100. --- linux-3.18.8/arch/arm/mach-bcm2709/vc_mem.c 1970-01-01 01:00:00.000000000 +0100
  18101. +++ linux-rpi/arch/arm/mach-bcm2709/vc_mem.c 2015-03-05 14:40:11.157715839 +0100
  18102. @@ -0,0 +1,431 @@
  18103. +/*****************************************************************************
  18104. +* Copyright 2010 - 2011 Broadcom Corporation. All rights reserved.
  18105. +*
  18106. +* Unless you and Broadcom execute a separate written software license
  18107. +* agreement governing use of this software, this software is licensed to you
  18108. +* under the terms of the GNU General Public License version 2, available at
  18109. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  18110. +*
  18111. +* Notwithstanding the above, under no circumstances may you combine this
  18112. +* software in any way with any other Broadcom software provided under a
  18113. +* license other than the GPL, without Broadcom's express prior written
  18114. +* consent.
  18115. +*****************************************************************************/
  18116. +
  18117. +#include <linux/kernel.h>
  18118. +#include <linux/module.h>
  18119. +#include <linux/fs.h>
  18120. +#include <linux/device.h>
  18121. +#include <linux/cdev.h>
  18122. +#include <linux/mm.h>
  18123. +#include <linux/slab.h>
  18124. +#include <linux/debugfs.h>
  18125. +#include <asm/uaccess.h>
  18126. +#include <linux/dma-mapping.h>
  18127. +
  18128. +#ifdef CONFIG_ARCH_KONA
  18129. +#include <chal/chal_ipc.h>
  18130. +#elif defined(CONFIG_ARCH_BCM2708) || defined(CONFIG_ARCH_BCM2709)
  18131. +#else
  18132. +#include <csp/chal_ipc.h>
  18133. +#endif
  18134. +
  18135. +#include "mach/vc_mem.h"
  18136. +#include <mach/vcio.h>
  18137. +
  18138. +#define DRIVER_NAME "vc-mem"
  18139. +
  18140. +// Device (/dev) related variables
  18141. +static dev_t vc_mem_devnum = 0;
  18142. +static struct class *vc_mem_class = NULL;
  18143. +static struct cdev vc_mem_cdev;
  18144. +static int vc_mem_inited = 0;
  18145. +
  18146. +#ifdef CONFIG_DEBUG_FS
  18147. +static struct dentry *vc_mem_debugfs_entry;
  18148. +#endif
  18149. +
  18150. +/*
  18151. + * Videocore memory addresses and size
  18152. + *
  18153. + * Drivers that wish to know the videocore memory addresses and sizes should
  18154. + * use these variables instead of the MM_IO_BASE and MM_ADDR_IO defines in
  18155. + * headers. This allows the other drivers to not be tied down to a a certain
  18156. + * address/size at compile time.
  18157. + *
  18158. + * In the future, the goal is to have the videocore memory virtual address and
  18159. + * size be calculated at boot time rather than at compile time. The decision of
  18160. + * where the videocore memory resides and its size would be in the hands of the
  18161. + * bootloader (and/or kernel). When that happens, the values of these variables
  18162. + * would be calculated and assigned in the init function.
  18163. + */
  18164. +// in the 2835 VC in mapped above ARM, but ARM has full access to VC space
  18165. +unsigned long mm_vc_mem_phys_addr = 0x00000000;
  18166. +unsigned int mm_vc_mem_size = 0;
  18167. +unsigned int mm_vc_mem_base = 0;
  18168. +
  18169. +EXPORT_SYMBOL(mm_vc_mem_phys_addr);
  18170. +EXPORT_SYMBOL(mm_vc_mem_size);
  18171. +EXPORT_SYMBOL(mm_vc_mem_base);
  18172. +
  18173. +static uint phys_addr = 0;
  18174. +static uint mem_size = 0;
  18175. +static uint mem_base = 0;
  18176. +
  18177. +
  18178. +/****************************************************************************
  18179. +*
  18180. +* vc_mem_open
  18181. +*
  18182. +***************************************************************************/
  18183. +
  18184. +static int
  18185. +vc_mem_open(struct inode *inode, struct file *file)
  18186. +{
  18187. + (void) inode;
  18188. + (void) file;
  18189. +
  18190. + pr_debug("%s: called file = 0x%p\n", __func__, file);
  18191. +
  18192. + return 0;
  18193. +}
  18194. +
  18195. +/****************************************************************************
  18196. +*
  18197. +* vc_mem_release
  18198. +*
  18199. +***************************************************************************/
  18200. +
  18201. +static int
  18202. +vc_mem_release(struct inode *inode, struct file *file)
  18203. +{
  18204. + (void) inode;
  18205. + (void) file;
  18206. +
  18207. + pr_debug("%s: called file = 0x%p\n", __func__, file);
  18208. +
  18209. + return 0;
  18210. +}
  18211. +
  18212. +/****************************************************************************
  18213. +*
  18214. +* vc_mem_get_size
  18215. +*
  18216. +***************************************************************************/
  18217. +
  18218. +static void
  18219. +vc_mem_get_size(void)
  18220. +{
  18221. +}
  18222. +
  18223. +/****************************************************************************
  18224. +*
  18225. +* vc_mem_get_base
  18226. +*
  18227. +***************************************************************************/
  18228. +
  18229. +static void
  18230. +vc_mem_get_base(void)
  18231. +{
  18232. +}
  18233. +
  18234. +/****************************************************************************
  18235. +*
  18236. +* vc_mem_get_current_size
  18237. +*
  18238. +***************************************************************************/
  18239. +
  18240. +int
  18241. +vc_mem_get_current_size(void)
  18242. +{
  18243. + return mm_vc_mem_size;
  18244. +}
  18245. +
  18246. +EXPORT_SYMBOL_GPL(vc_mem_get_current_size);
  18247. +
  18248. +/****************************************************************************
  18249. +*
  18250. +* vc_mem_ioctl
  18251. +*
  18252. +***************************************************************************/
  18253. +
  18254. +static long
  18255. +vc_mem_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  18256. +{
  18257. + int rc = 0;
  18258. +
  18259. + (void) cmd;
  18260. + (void) arg;
  18261. +
  18262. + pr_debug("%s: called file = 0x%p\n", __func__, file);
  18263. +
  18264. + switch (cmd) {
  18265. + case VC_MEM_IOC_MEM_PHYS_ADDR:
  18266. + {
  18267. + pr_debug("%s: VC_MEM_IOC_MEM_PHYS_ADDR=0x%p\n",
  18268. + __func__, (void *) mm_vc_mem_phys_addr);
  18269. +
  18270. + if (copy_to_user((void *) arg, &mm_vc_mem_phys_addr,
  18271. + sizeof (mm_vc_mem_phys_addr)) != 0) {
  18272. + rc = -EFAULT;
  18273. + }
  18274. + break;
  18275. + }
  18276. + case VC_MEM_IOC_MEM_SIZE:
  18277. + {
  18278. + // Get the videocore memory size first
  18279. + vc_mem_get_size();
  18280. +
  18281. + pr_debug("%s: VC_MEM_IOC_MEM_SIZE=%u\n", __func__,
  18282. + mm_vc_mem_size);
  18283. +
  18284. + if (copy_to_user((void *) arg, &mm_vc_mem_size,
  18285. + sizeof (mm_vc_mem_size)) != 0) {
  18286. + rc = -EFAULT;
  18287. + }
  18288. + break;
  18289. + }
  18290. + case VC_MEM_IOC_MEM_BASE:
  18291. + {
  18292. + // Get the videocore memory base
  18293. + vc_mem_get_base();
  18294. +
  18295. + pr_debug("%s: VC_MEM_IOC_MEM_BASE=%u\n", __func__,
  18296. + mm_vc_mem_base);
  18297. +
  18298. + if (copy_to_user((void *) arg, &mm_vc_mem_base,
  18299. + sizeof (mm_vc_mem_base)) != 0) {
  18300. + rc = -EFAULT;
  18301. + }
  18302. + break;
  18303. + }
  18304. + case VC_MEM_IOC_MEM_LOAD:
  18305. + {
  18306. + // Get the videocore memory base
  18307. + vc_mem_get_base();
  18308. +
  18309. + pr_debug("%s: VC_MEM_IOC_MEM_LOAD=%u\n", __func__,
  18310. + mm_vc_mem_base);
  18311. +
  18312. + if (copy_to_user((void *) arg, &mm_vc_mem_base,
  18313. + sizeof (mm_vc_mem_base)) != 0) {
  18314. + rc = -EFAULT;
  18315. + }
  18316. + break;
  18317. + }
  18318. + default:
  18319. + {
  18320. + return -ENOTTY;
  18321. + }
  18322. + }
  18323. + pr_debug("%s: file = 0x%p returning %d\n", __func__, file, rc);
  18324. +
  18325. + return rc;
  18326. +}
  18327. +
  18328. +/****************************************************************************
  18329. +*
  18330. +* vc_mem_mmap
  18331. +*
  18332. +***************************************************************************/
  18333. +
  18334. +static int
  18335. +vc_mem_mmap(struct file *filp, struct vm_area_struct *vma)
  18336. +{
  18337. + int rc = 0;
  18338. + unsigned long length = vma->vm_end - vma->vm_start;
  18339. + unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
  18340. +
  18341. + pr_debug("%s: vm_start = 0x%08lx vm_end = 0x%08lx vm_pgoff = 0x%08lx\n",
  18342. + __func__, (long) vma->vm_start, (long) vma->vm_end,
  18343. + (long) vma->vm_pgoff);
  18344. +
  18345. + if (offset + length > mm_vc_mem_size) {
  18346. + pr_err("%s: length %ld is too big\n", __func__, length);
  18347. + return -EINVAL;
  18348. + }
  18349. + // Do not cache the memory map
  18350. + vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
  18351. +
  18352. + rc = remap_pfn_range(vma, vma->vm_start,
  18353. + (mm_vc_mem_phys_addr >> PAGE_SHIFT) +
  18354. + vma->vm_pgoff, length, vma->vm_page_prot);
  18355. + if (rc != 0) {
  18356. + pr_err("%s: remap_pfn_range failed (rc=%d)\n", __func__, rc);
  18357. + }
  18358. +
  18359. + return rc;
  18360. +}
  18361. +
  18362. +/****************************************************************************
  18363. +*
  18364. +* File Operations for the driver.
  18365. +*
  18366. +***************************************************************************/
  18367. +
  18368. +static const struct file_operations vc_mem_fops = {
  18369. + .owner = THIS_MODULE,
  18370. + .open = vc_mem_open,
  18371. + .release = vc_mem_release,
  18372. + .unlocked_ioctl = vc_mem_ioctl,
  18373. + .mmap = vc_mem_mmap,
  18374. +};
  18375. +
  18376. +#ifdef CONFIG_DEBUG_FS
  18377. +static void vc_mem_debugfs_deinit(void)
  18378. +{
  18379. + debugfs_remove_recursive(vc_mem_debugfs_entry);
  18380. + vc_mem_debugfs_entry = NULL;
  18381. +}
  18382. +
  18383. +
  18384. +static int vc_mem_debugfs_init(
  18385. + struct device *dev)
  18386. +{
  18387. + vc_mem_debugfs_entry = debugfs_create_dir(DRIVER_NAME, NULL);
  18388. + if (!vc_mem_debugfs_entry) {
  18389. + dev_warn(dev, "could not create debugfs entry\n");
  18390. + return -EFAULT;
  18391. + }
  18392. +
  18393. + if (!debugfs_create_x32("vc_mem_phys_addr",
  18394. + 0444,
  18395. + vc_mem_debugfs_entry,
  18396. + (u32 *)&mm_vc_mem_phys_addr)) {
  18397. + dev_warn(dev, "%s:could not create vc_mem_phys entry\n",
  18398. + __func__);
  18399. + goto fail;
  18400. + }
  18401. +
  18402. + if (!debugfs_create_x32("vc_mem_size",
  18403. + 0444,
  18404. + vc_mem_debugfs_entry,
  18405. + (u32 *)&mm_vc_mem_size)) {
  18406. + dev_warn(dev, "%s:could not create vc_mem_size entry\n",
  18407. + __func__);
  18408. + goto fail;
  18409. + }
  18410. +
  18411. + if (!debugfs_create_x32("vc_mem_base",
  18412. + 0444,
  18413. + vc_mem_debugfs_entry,
  18414. + (u32 *)&mm_vc_mem_base)) {
  18415. + dev_warn(dev, "%s:could not create vc_mem_base entry\n",
  18416. + __func__);
  18417. + goto fail;
  18418. + }
  18419. +
  18420. + return 0;
  18421. +
  18422. +fail:
  18423. + vc_mem_debugfs_deinit();
  18424. + return -EFAULT;
  18425. +}
  18426. +
  18427. +#endif /* CONFIG_DEBUG_FS */
  18428. +
  18429. +
  18430. +/****************************************************************************
  18431. +*
  18432. +* vc_mem_init
  18433. +*
  18434. +***************************************************************************/
  18435. +
  18436. +static int __init
  18437. +vc_mem_init(void)
  18438. +{
  18439. + int rc = -EFAULT;
  18440. + struct device *dev;
  18441. +
  18442. + pr_debug("%s: called\n", __func__);
  18443. +
  18444. + mm_vc_mem_phys_addr = phys_addr;
  18445. + mm_vc_mem_size = mem_size;
  18446. + mm_vc_mem_base = mem_base;
  18447. +
  18448. + vc_mem_get_size();
  18449. +
  18450. + pr_info("vc-mem: phys_addr:0x%08lx mem_base=0x%08x mem_size:0x%08x(%u MiB)\n",
  18451. + mm_vc_mem_phys_addr, mm_vc_mem_base, mm_vc_mem_size, mm_vc_mem_size / (1024 * 1024));
  18452. +
  18453. + if ((rc = alloc_chrdev_region(&vc_mem_devnum, 0, 1, DRIVER_NAME)) < 0) {
  18454. + pr_err("%s: alloc_chrdev_region failed (rc=%d)\n",
  18455. + __func__, rc);
  18456. + goto out_err;
  18457. + }
  18458. +
  18459. + cdev_init(&vc_mem_cdev, &vc_mem_fops);
  18460. + if ((rc = cdev_add(&vc_mem_cdev, vc_mem_devnum, 1)) != 0) {
  18461. + pr_err("%s: cdev_add failed (rc=%d)\n", __func__, rc);
  18462. + goto out_unregister;
  18463. + }
  18464. +
  18465. + vc_mem_class = class_create(THIS_MODULE, DRIVER_NAME);
  18466. + if (IS_ERR(vc_mem_class)) {
  18467. + rc = PTR_ERR(vc_mem_class);
  18468. + pr_err("%s: class_create failed (rc=%d)\n", __func__, rc);
  18469. + goto out_cdev_del;
  18470. + }
  18471. +
  18472. + dev = device_create(vc_mem_class, NULL, vc_mem_devnum, NULL,
  18473. + DRIVER_NAME);
  18474. + if (IS_ERR(dev)) {
  18475. + rc = PTR_ERR(dev);
  18476. + pr_err("%s: device_create failed (rc=%d)\n", __func__, rc);
  18477. + goto out_class_destroy;
  18478. + }
  18479. +
  18480. +#ifdef CONFIG_DEBUG_FS
  18481. + /* don't fail if the debug entries cannot be created */
  18482. + vc_mem_debugfs_init(dev);
  18483. +#endif
  18484. +
  18485. + vc_mem_inited = 1;
  18486. + return 0;
  18487. +
  18488. + device_destroy(vc_mem_class, vc_mem_devnum);
  18489. +
  18490. + out_class_destroy:
  18491. + class_destroy(vc_mem_class);
  18492. + vc_mem_class = NULL;
  18493. +
  18494. + out_cdev_del:
  18495. + cdev_del(&vc_mem_cdev);
  18496. +
  18497. + out_unregister:
  18498. + unregister_chrdev_region(vc_mem_devnum, 1);
  18499. +
  18500. + out_err:
  18501. + return -1;
  18502. +}
  18503. +
  18504. +/****************************************************************************
  18505. +*
  18506. +* vc_mem_exit
  18507. +*
  18508. +***************************************************************************/
  18509. +
  18510. +static void __exit
  18511. +vc_mem_exit(void)
  18512. +{
  18513. + pr_debug("%s: called\n", __func__);
  18514. +
  18515. + if (vc_mem_inited) {
  18516. +#if CONFIG_DEBUG_FS
  18517. + vc_mem_debugfs_deinit();
  18518. +#endif
  18519. + device_destroy(vc_mem_class, vc_mem_devnum);
  18520. + class_destroy(vc_mem_class);
  18521. + cdev_del(&vc_mem_cdev);
  18522. + unregister_chrdev_region(vc_mem_devnum, 1);
  18523. + }
  18524. +}
  18525. +
  18526. +module_init(vc_mem_init);
  18527. +module_exit(vc_mem_exit);
  18528. +MODULE_LICENSE("GPL");
  18529. +MODULE_AUTHOR("Broadcom Corporation");
  18530. +
  18531. +module_param(phys_addr, uint, 0644);
  18532. +module_param(mem_size, uint, 0644);
  18533. +module_param(mem_base, uint, 0644);
  18534. diff -Nur linux-3.18.8/arch/arm/mach-bcm2709/vc_support.c linux-rpi/arch/arm/mach-bcm2709/vc_support.c
  18535. --- linux-3.18.8/arch/arm/mach-bcm2709/vc_support.c 1970-01-01 01:00:00.000000000 +0100
  18536. +++ linux-rpi/arch/arm/mach-bcm2709/vc_support.c 2015-03-05 14:40:11.157715839 +0100
  18537. @@ -0,0 +1,318 @@
  18538. +/*
  18539. + * vc_support.c
  18540. + *
  18541. + * Created on: 25 Nov 2012
  18542. + * Author: Simon
  18543. + */
  18544. +
  18545. +#include <linux/module.h>
  18546. +#include <mach/vcio.h>
  18547. +
  18548. +#ifdef ECLIPSE_IGNORE
  18549. +
  18550. +#define __user
  18551. +#define __init
  18552. +#define __exit
  18553. +#define __iomem
  18554. +#define KERN_DEBUG
  18555. +#define KERN_ERR
  18556. +#define KERN_WARNING
  18557. +#define KERN_INFO
  18558. +#define _IOWR(a, b, c) b
  18559. +#define _IOW(a, b, c) b
  18560. +#define _IO(a, b) b
  18561. +
  18562. +#endif
  18563. +
  18564. +/****** VC MAILBOX FUNCTIONALITY ******/
  18565. +unsigned int AllocateVcMemory(unsigned int *pHandle, unsigned int size, unsigned int alignment, unsigned int flags)
  18566. +{
  18567. + struct vc_msg
  18568. + {
  18569. + unsigned int m_msgSize;
  18570. + unsigned int m_response;
  18571. +
  18572. + struct vc_tag
  18573. + {
  18574. + unsigned int m_tagId;
  18575. + unsigned int m_sendBufferSize;
  18576. + union {
  18577. + unsigned int m_sendDataSize;
  18578. + unsigned int m_recvDataSize;
  18579. + };
  18580. +
  18581. + struct args
  18582. + {
  18583. + union {
  18584. + unsigned int m_size;
  18585. + unsigned int m_handle;
  18586. + };
  18587. + unsigned int m_alignment;
  18588. + unsigned int m_flags;
  18589. + } m_args;
  18590. + } m_tag;
  18591. +
  18592. + unsigned int m_endTag;
  18593. + } msg;
  18594. + int s;
  18595. +
  18596. + msg.m_msgSize = sizeof(msg);
  18597. + msg.m_response = 0;
  18598. + msg.m_endTag = 0;
  18599. +
  18600. + //fill in the tag for the allocation command
  18601. + msg.m_tag.m_tagId = 0x3000c;
  18602. + msg.m_tag.m_sendBufferSize = 12;
  18603. + msg.m_tag.m_sendDataSize = 12;
  18604. +
  18605. + //fill in our args
  18606. + msg.m_tag.m_args.m_size = size;
  18607. + msg.m_tag.m_args.m_alignment = alignment;
  18608. + msg.m_tag.m_args.m_flags = flags;
  18609. +
  18610. + //run the command
  18611. + s = bcm_mailbox_property(&msg, sizeof(msg));
  18612. +
  18613. + if (s == 0 && msg.m_response == 0x80000000 && msg.m_tag.m_recvDataSize == 0x80000004)
  18614. + {
  18615. + *pHandle = msg.m_tag.m_args.m_handle;
  18616. + return 0;
  18617. + }
  18618. + else
  18619. + {
  18620. + printk(KERN_ERR "failed to allocate vc memory: s=%d response=%08x recv data size=%08x\n",
  18621. + s, msg.m_response, msg.m_tag.m_recvDataSize);
  18622. + return 1;
  18623. + }
  18624. +}
  18625. +
  18626. +unsigned int ReleaseVcMemory(unsigned int handle)
  18627. +{
  18628. + struct vc_msg
  18629. + {
  18630. + unsigned int m_msgSize;
  18631. + unsigned int m_response;
  18632. +
  18633. + struct vc_tag
  18634. + {
  18635. + unsigned int m_tagId;
  18636. + unsigned int m_sendBufferSize;
  18637. + union {
  18638. + unsigned int m_sendDataSize;
  18639. + unsigned int m_recvDataSize;
  18640. + };
  18641. +
  18642. + struct args
  18643. + {
  18644. + union {
  18645. + unsigned int m_handle;
  18646. + unsigned int m_error;
  18647. + };
  18648. + } m_args;
  18649. + } m_tag;
  18650. +
  18651. + unsigned int m_endTag;
  18652. + } msg;
  18653. + int s;
  18654. +
  18655. + msg.m_msgSize = sizeof(msg);
  18656. + msg.m_response = 0;
  18657. + msg.m_endTag = 0;
  18658. +
  18659. + //fill in the tag for the release command
  18660. + msg.m_tag.m_tagId = 0x3000f;
  18661. + msg.m_tag.m_sendBufferSize = 4;
  18662. + msg.m_tag.m_sendDataSize = 4;
  18663. +
  18664. + //pass across the handle
  18665. + msg.m_tag.m_args.m_handle = handle;
  18666. +
  18667. + s = bcm_mailbox_property(&msg, sizeof(msg));
  18668. +
  18669. + if (s == 0 && msg.m_response == 0x80000000 && msg.m_tag.m_recvDataSize == 0x80000004 && msg.m_tag.m_args.m_error == 0)
  18670. + return 0;
  18671. + else
  18672. + {
  18673. + printk(KERN_ERR "failed to release vc memory: s=%d response=%08x recv data size=%08x error=%08x\n",
  18674. + s, msg.m_response, msg.m_tag.m_recvDataSize, msg.m_tag.m_args.m_error);
  18675. + return 1;
  18676. + }
  18677. +}
  18678. +
  18679. +unsigned int LockVcMemory(unsigned int *pBusAddress, unsigned int handle)
  18680. +{
  18681. + struct vc_msg
  18682. + {
  18683. + unsigned int m_msgSize;
  18684. + unsigned int m_response;
  18685. +
  18686. + struct vc_tag
  18687. + {
  18688. + unsigned int m_tagId;
  18689. + unsigned int m_sendBufferSize;
  18690. + union {
  18691. + unsigned int m_sendDataSize;
  18692. + unsigned int m_recvDataSize;
  18693. + };
  18694. +
  18695. + struct args
  18696. + {
  18697. + union {
  18698. + unsigned int m_handle;
  18699. + unsigned int m_busAddress;
  18700. + };
  18701. + } m_args;
  18702. + } m_tag;
  18703. +
  18704. + unsigned int m_endTag;
  18705. + } msg;
  18706. + int s;
  18707. +
  18708. + msg.m_msgSize = sizeof(msg);
  18709. + msg.m_response = 0;
  18710. + msg.m_endTag = 0;
  18711. +
  18712. + //fill in the tag for the lock command
  18713. + msg.m_tag.m_tagId = 0x3000d;
  18714. + msg.m_tag.m_sendBufferSize = 4;
  18715. + msg.m_tag.m_sendDataSize = 4;
  18716. +
  18717. + //pass across the handle
  18718. + msg.m_tag.m_args.m_handle = handle;
  18719. +
  18720. + s = bcm_mailbox_property(&msg, sizeof(msg));
  18721. +
  18722. + if (s == 0 && msg.m_response == 0x80000000 && msg.m_tag.m_recvDataSize == 0x80000004)
  18723. + {
  18724. + //pick out the bus address
  18725. + *pBusAddress = msg.m_tag.m_args.m_busAddress;
  18726. + return 0;
  18727. + }
  18728. + else
  18729. + {
  18730. + printk(KERN_ERR "failed to lock vc memory: s=%d response=%08x recv data size=%08x\n",
  18731. + s, msg.m_response, msg.m_tag.m_recvDataSize);
  18732. + return 1;
  18733. + }
  18734. +}
  18735. +
  18736. +unsigned int UnlockVcMemory(unsigned int handle)
  18737. +{
  18738. + struct vc_msg
  18739. + {
  18740. + unsigned int m_msgSize;
  18741. + unsigned int m_response;
  18742. +
  18743. + struct vc_tag
  18744. + {
  18745. + unsigned int m_tagId;
  18746. + unsigned int m_sendBufferSize;
  18747. + union {
  18748. + unsigned int m_sendDataSize;
  18749. + unsigned int m_recvDataSize;
  18750. + };
  18751. +
  18752. + struct args
  18753. + {
  18754. + union {
  18755. + unsigned int m_handle;
  18756. + unsigned int m_error;
  18757. + };
  18758. + } m_args;
  18759. + } m_tag;
  18760. +
  18761. + unsigned int m_endTag;
  18762. + } msg;
  18763. + int s;
  18764. +
  18765. + msg.m_msgSize = sizeof(msg);
  18766. + msg.m_response = 0;
  18767. + msg.m_endTag = 0;
  18768. +
  18769. + //fill in the tag for the unlock command
  18770. + msg.m_tag.m_tagId = 0x3000e;
  18771. + msg.m_tag.m_sendBufferSize = 4;
  18772. + msg.m_tag.m_sendDataSize = 4;
  18773. +
  18774. + //pass across the handle
  18775. + msg.m_tag.m_args.m_handle = handle;
  18776. +
  18777. + s = bcm_mailbox_property(&msg, sizeof(msg));
  18778. +
  18779. + //check the error code too
  18780. + if (s == 0 && msg.m_response == 0x80000000 && msg.m_tag.m_recvDataSize == 0x80000004 && msg.m_tag.m_args.m_error == 0)
  18781. + return 0;
  18782. + else
  18783. + {
  18784. + printk(KERN_ERR "failed to unlock vc memory: s=%d response=%08x recv data size=%08x error%08x\n",
  18785. + s, msg.m_response, msg.m_tag.m_recvDataSize, msg.m_tag.m_args.m_error);
  18786. + return 1;
  18787. + }
  18788. +}
  18789. +
  18790. +unsigned int ExecuteVcCode(unsigned int code,
  18791. + unsigned int r0, unsigned int r1, unsigned int r2, unsigned int r3, unsigned int r4, unsigned int r5)
  18792. +{
  18793. + struct vc_msg
  18794. + {
  18795. + unsigned int m_msgSize;
  18796. + unsigned int m_response;
  18797. +
  18798. + struct vc_tag
  18799. + {
  18800. + unsigned int m_tagId;
  18801. + unsigned int m_sendBufferSize;
  18802. + union {
  18803. + unsigned int m_sendDataSize;
  18804. + unsigned int m_recvDataSize;
  18805. + };
  18806. +
  18807. + struct args
  18808. + {
  18809. + union {
  18810. + unsigned int m_pCode;
  18811. + unsigned int m_return;
  18812. + };
  18813. + unsigned int m_r0;
  18814. + unsigned int m_r1;
  18815. + unsigned int m_r2;
  18816. + unsigned int m_r3;
  18817. + unsigned int m_r4;
  18818. + unsigned int m_r5;
  18819. + } m_args;
  18820. + } m_tag;
  18821. +
  18822. + unsigned int m_endTag;
  18823. + } msg;
  18824. + int s;
  18825. +
  18826. + msg.m_msgSize = sizeof(msg);
  18827. + msg.m_response = 0;
  18828. + msg.m_endTag = 0;
  18829. +
  18830. + //fill in the tag for the unlock command
  18831. + msg.m_tag.m_tagId = 0x30010;
  18832. + msg.m_tag.m_sendBufferSize = 28;
  18833. + msg.m_tag.m_sendDataSize = 28;
  18834. +
  18835. + //pass across the handle
  18836. + msg.m_tag.m_args.m_pCode = code;
  18837. + msg.m_tag.m_args.m_r0 = r0;
  18838. + msg.m_tag.m_args.m_r1 = r1;
  18839. + msg.m_tag.m_args.m_r2 = r2;
  18840. + msg.m_tag.m_args.m_r3 = r3;
  18841. + msg.m_tag.m_args.m_r4 = r4;
  18842. + msg.m_tag.m_args.m_r5 = r5;
  18843. +
  18844. + s = bcm_mailbox_property(&msg, sizeof(msg));
  18845. +
  18846. + //check the error code too
  18847. + if (s == 0 && msg.m_response == 0x80000000 && msg.m_tag.m_recvDataSize == 0x80000004)
  18848. + return msg.m_tag.m_args.m_return;
  18849. + else
  18850. + {
  18851. + printk(KERN_ERR "failed to execute: s=%d response=%08x recv data size=%08x\n",
  18852. + s, msg.m_response, msg.m_tag.m_recvDataSize);
  18853. + return 1;
  18854. + }
  18855. +}
  18856. diff -Nur linux-3.18.8/arch/arm/Makefile linux-rpi/arch/arm/Makefile
  18857. --- linux-3.18.8/arch/arm/Makefile 2015-02-27 02:49:36.000000000 +0100
  18858. +++ linux-rpi/arch/arm/Makefile 2015-03-05 14:40:11.017715840 +0100
  18859. @@ -146,6 +146,8 @@
  18860. machine-$(CONFIG_ARCH_AT91) += at91
  18861. machine-$(CONFIG_ARCH_AXXIA) += axxia
  18862. machine-$(CONFIG_ARCH_BCM) += bcm
  18863. +machine-$(CONFIG_ARCH_BCM2708) += bcm2708
  18864. +machine-$(CONFIG_ARCH_BCM2709) += bcm2709
  18865. machine-$(CONFIG_ARCH_BERLIN) += berlin
  18866. machine-$(CONFIG_ARCH_CLPS711X) += clps711x
  18867. machine-$(CONFIG_ARCH_CNS3XXX) += cns3xxx
  18868. diff -Nur linux-3.18.8/arch/arm/mm/Kconfig linux-rpi/arch/arm/mm/Kconfig
  18869. --- linux-3.18.8/arch/arm/mm/Kconfig 2015-02-27 02:49:36.000000000 +0100
  18870. +++ linux-rpi/arch/arm/mm/Kconfig 2015-03-05 14:40:11.261715839 +0100
  18871. @@ -358,7 +358,7 @@
  18872. # ARMv6
  18873. config CPU_V6
  18874. - bool "Support ARM V6 processor" if ARCH_INTEGRATOR || MACH_REALVIEW_EB || MACH_REALVIEW_PBX
  18875. + bool "Support ARM V6 processor" if ARCH_INTEGRATOR || MACH_REALVIEW_EB || MACH_REALVIEW_PBX || MACH_BCM2708
  18876. select CPU_32v6
  18877. select CPU_ABRT_EV6
  18878. select CPU_CACHE_V6
  18879. diff -Nur linux-3.18.8/arch/arm/mm/proc-v6.S linux-rpi/arch/arm/mm/proc-v6.S
  18880. --- linux-3.18.8/arch/arm/mm/proc-v6.S 2015-02-27 02:49:36.000000000 +0100
  18881. +++ linux-rpi/arch/arm/mm/proc-v6.S 2015-03-05 14:40:11.277715838 +0100
  18882. @@ -73,10 +73,19 @@
  18883. *
  18884. * IRQs are already disabled.
  18885. */
  18886. +
  18887. +/* See jira SW-5991 for details of this workaround */
  18888. ENTRY(cpu_v6_do_idle)
  18889. - mov r1, #0
  18890. - mcr p15, 0, r1, c7, c10, 4 @ DWB - WFI may enter a low-power mode
  18891. - mcr p15, 0, r1, c7, c0, 4 @ wait for interrupt
  18892. + .align 5
  18893. + mov r1, #2
  18894. +1: subs r1, #1
  18895. + nop
  18896. + mcreq p15, 0, r1, c7, c10, 4 @ DWB - WFI may enter a low-power mode
  18897. + mcreq p15, 0, r1, c7, c0, 4 @ wait for interrupt
  18898. + nop
  18899. + nop
  18900. + nop
  18901. + bne 1b
  18902. ret lr
  18903. ENTRY(cpu_v6_dcache_clean_area)
  18904. diff -Nur linux-3.18.8/arch/arm/mm/proc-v7.S linux-rpi/arch/arm/mm/proc-v7.S
  18905. --- linux-3.18.8/arch/arm/mm/proc-v7.S 2015-02-27 02:49:36.000000000 +0100
  18906. +++ linux-rpi/arch/arm/mm/proc-v7.S 2015-03-05 14:40:11.277715838 +0100
  18907. @@ -441,6 +441,7 @@
  18908. orr r0, r0, r6 @ set them
  18909. THUMB( orr r0, r0, #1 << 30 ) @ Thumb exceptions
  18910. ret lr @ return to head.S:__ret
  18911. + .space 256
  18912. ENDPROC(__v7_setup)
  18913. .align 2
  18914. diff -Nur linux-3.18.8/arch/arm/tools/mach-types linux-rpi/arch/arm/tools/mach-types
  18915. --- linux-3.18.8/arch/arm/tools/mach-types 2015-02-27 02:49:36.000000000 +0100
  18916. +++ linux-rpi/arch/arm/tools/mach-types 2015-03-05 14:40:11.297715838 +0100
  18917. @@ -522,6 +522,8 @@
  18918. prima2_evb MACH_PRIMA2_EVB PRIMA2_EVB 3103
  18919. paz00 MACH_PAZ00 PAZ00 3128
  18920. acmenetusfoxg20 MACH_ACMENETUSFOXG20 ACMENETUSFOXG20 3129
  18921. +bcm2708 MACH_BCM2708 BCM2708 3138
  18922. +bcm2709 MACH_BCM2709 BCM2709 3139
  18923. ag5evm MACH_AG5EVM AG5EVM 3189
  18924. ics_if_voip MACH_ICS_IF_VOIP ICS_IF_VOIP 3206
  18925. wlf_cragg_6410 MACH_WLF_CRAGG_6410 WLF_CRAGG_6410 3207
  18926. diff -Nur linux-3.18.8/Documentation/video4linux/bcm2835-v4l2.txt linux-rpi/Documentation/video4linux/bcm2835-v4l2.txt
  18927. --- linux-3.18.8/Documentation/video4linux/bcm2835-v4l2.txt 1970-01-01 01:00:00.000000000 +0100
  18928. +++ linux-rpi/Documentation/video4linux/bcm2835-v4l2.txt 2015-03-05 14:40:10.925715841 +0100
  18929. @@ -0,0 +1,60 @@
  18930. +
  18931. +BCM2835 (aka Raspberry Pi) V4L2 driver
  18932. +======================================
  18933. +
  18934. +1. Copyright
  18935. +============
  18936. +
  18937. +Copyright © 2013 Raspberry Pi (Trading) Ltd.
  18938. +
  18939. +2. License
  18940. +==========
  18941. +
  18942. +This program is free software; you can redistribute it and/or modify
  18943. +it under the terms of the GNU General Public License as published by
  18944. +the Free Software Foundation; either version 2 of the License, or
  18945. +(at your option) any later version.
  18946. +
  18947. +This program is distributed in the hope that it will be useful,
  18948. +but WITHOUT ANY WARRANTY; without even the implied warranty of
  18949. +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18950. +GNU General Public License for more details.
  18951. +
  18952. +You should have received a copy of the GNU General Public License
  18953. +along with this program; if not, write to the Free Software
  18954. +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18955. +
  18956. +3. Quick Start
  18957. +==============
  18958. +
  18959. +You need a version 1.0 or later of v4l2-ctl, available from:
  18960. + git://git.linuxtv.org/v4l-utils.git
  18961. +
  18962. +$ sudo modprobe bcm2835-v4l2
  18963. +
  18964. +Turn on the overlay:
  18965. +
  18966. +$ v4l2-ctl --overlay=1
  18967. +
  18968. +Turn off the overlay:
  18969. +
  18970. +$ v4l2-ctl --overlay=0
  18971. +
  18972. +Set the capture format for video:
  18973. +
  18974. +$ v4l2-ctl --set-fmt-video=width=1920,height=1088,pixelformat=4
  18975. +
  18976. +(Note: 1088 not 1080).
  18977. +
  18978. +Capture:
  18979. +
  18980. +$ v4l2-ctl --stream-mmap=3 --stream-count=100 --stream-to=somefile.h264
  18981. +
  18982. +Stills capture:
  18983. +
  18984. +$ v4l2-ctl --set-fmt-video=width=2592,height=1944,pixelformat=3
  18985. +$ v4l2-ctl --stream-mmap=3 --stream-count=1 --stream-to=somefile.jpg
  18986. +
  18987. +List of available formats:
  18988. +
  18989. +$ v4l2-ctl --list-formats
  18990. diff -Nur linux-3.18.8/drivers/char/broadcom/Kconfig linux-rpi/drivers/char/broadcom/Kconfig
  18991. --- linux-3.18.8/drivers/char/broadcom/Kconfig 1970-01-01 01:00:00.000000000 +0100
  18992. +++ linux-rpi/drivers/char/broadcom/Kconfig 2015-03-05 14:40:12.661715830 +0100
  18993. @@ -0,0 +1,22 @@
  18994. +#
  18995. +# Broadcom char driver config
  18996. +#
  18997. +
  18998. +menuconfig BRCM_CHAR_DRIVERS
  18999. + bool "Broadcom Char Drivers"
  19000. + help
  19001. + Broadcom's char drivers
  19002. +
  19003. +config BCM_VC_CMA
  19004. + bool "Videocore CMA"
  19005. + depends on CMA && BRCM_CHAR_DRIVERS && BCM2708_VCHIQ
  19006. + default n
  19007. + help
  19008. + Helper for videocore CMA access.
  19009. +
  19010. +config BCM_VC_SM
  19011. + tristate "VMCS Shared Memory"
  19012. + default n
  19013. + help
  19014. + Support for the VC shared memory on the Broadcom reference
  19015. + design. Uses the VCHIQ stack.
  19016. diff -Nur linux-3.18.8/drivers/char/broadcom/Makefile linux-rpi/drivers/char/broadcom/Makefile
  19017. --- linux-3.18.8/drivers/char/broadcom/Makefile 1970-01-01 01:00:00.000000000 +0100
  19018. +++ linux-rpi/drivers/char/broadcom/Makefile 2015-03-05 14:40:12.661715830 +0100
  19019. @@ -0,0 +1,2 @@
  19020. +obj-$(CONFIG_BCM_VC_CMA) += vc_cma/
  19021. +obj-$(CONFIG_BCM_VC_SM) += vc_sm/
  19022. diff -Nur linux-3.18.8/drivers/char/broadcom/vc_cma/Makefile linux-rpi/drivers/char/broadcom/vc_cma/Makefile
  19023. --- linux-3.18.8/drivers/char/broadcom/vc_cma/Makefile 1970-01-01 01:00:00.000000000 +0100
  19024. +++ linux-rpi/drivers/char/broadcom/vc_cma/Makefile 2015-03-05 14:40:12.661715830 +0100
  19025. @@ -0,0 +1,14 @@
  19026. +ccflags-y += -Wall -Wstrict-prototypes -Wno-trigraphs
  19027. +ccflags-y += -Werror
  19028. +ccflags-y += -Iinclude/linux/broadcom
  19029. +ccflags-y += -Idrivers/misc/vc04_services
  19030. +ccflags-y += -Idrivers/misc/vc04_services/interface/vchi
  19031. +ccflags-y += -Idrivers/misc/vc04_services/interface/vchiq_arm
  19032. +
  19033. +ccflags-y += -D__KERNEL__
  19034. +ccflags-y += -D__linux__
  19035. +ccflags-y += -Werror
  19036. +
  19037. +obj-$(CONFIG_BCM_VC_CMA) += vc-cma.o
  19038. +
  19039. +vc-cma-objs := vc_cma.o
  19040. diff -Nur linux-3.18.8/drivers/char/broadcom/vc_cma/vc_cma.c linux-rpi/drivers/char/broadcom/vc_cma/vc_cma.c
  19041. --- linux-3.18.8/drivers/char/broadcom/vc_cma/vc_cma.c 1970-01-01 01:00:00.000000000 +0100
  19042. +++ linux-rpi/drivers/char/broadcom/vc_cma/vc_cma.c 2015-03-05 14:40:12.661715830 +0100
  19043. @@ -0,0 +1,1193 @@
  19044. +/**
  19045. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  19046. + *
  19047. + * Redistribution and use in source and binary forms, with or without
  19048. + * modification, are permitted provided that the following conditions
  19049. + * are met:
  19050. + * 1. Redistributions of source code must retain the above copyright
  19051. + * notice, this list of conditions, and the following disclaimer,
  19052. + * without modification.
  19053. + * 2. Redistributions in binary form must reproduce the above copyright
  19054. + * notice, this list of conditions and the following disclaimer in the
  19055. + * documentation and/or other materials provided with the distribution.
  19056. + * 3. The names of the above-listed copyright holders may not be used
  19057. + * to endorse or promote products derived from this software without
  19058. + * specific prior written permission.
  19059. + *
  19060. + * ALTERNATIVELY, this software may be distributed under the terms of the
  19061. + * GNU General Public License ("GPL") version 2, as published by the Free
  19062. + * Software Foundation.
  19063. + *
  19064. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  19065. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  19066. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  19067. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  19068. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  19069. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  19070. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  19071. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  19072. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  19073. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  19074. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  19075. + */
  19076. +
  19077. +#include <linux/kernel.h>
  19078. +#include <linux/module.h>
  19079. +#include <linux/kthread.h>
  19080. +#include <linux/fs.h>
  19081. +#include <linux/device.h>
  19082. +#include <linux/cdev.h>
  19083. +#include <linux/mm.h>
  19084. +#include <linux/proc_fs.h>
  19085. +#include <linux/seq_file.h>
  19086. +#include <linux/dma-mapping.h>
  19087. +#include <linux/dma-contiguous.h>
  19088. +#include <linux/platform_device.h>
  19089. +#include <linux/uaccess.h>
  19090. +#include <asm/cacheflush.h>
  19091. +
  19092. +#include "vc_cma.h"
  19093. +
  19094. +#include "vchiq_util.h"
  19095. +#include "vchiq_connected.h"
  19096. +//#include "debug_sym.h"
  19097. +//#include "vc_mem.h"
  19098. +
  19099. +#define DRIVER_NAME "vc-cma"
  19100. +
  19101. +#define LOG_DBG(fmt, ...) \
  19102. + if (vc_cma_debug) \
  19103. + printk(KERN_INFO fmt "\n", ##__VA_ARGS__)
  19104. +#define LOG_INFO(fmt, ...) \
  19105. + printk(KERN_INFO fmt "\n", ##__VA_ARGS__)
  19106. +#define LOG_ERR(fmt, ...) \
  19107. + printk(KERN_ERR fmt "\n", ##__VA_ARGS__)
  19108. +
  19109. +#define VC_CMA_FOURCC VCHIQ_MAKE_FOURCC('C', 'M', 'A', ' ')
  19110. +#define VC_CMA_VERSION 2
  19111. +
  19112. +#define VC_CMA_CHUNK_ORDER 6 /* 256K */
  19113. +#define VC_CMA_CHUNK_SIZE (4096 << VC_CMA_CHUNK_ORDER)
  19114. +#define VC_CMA_MAX_PARAMS_PER_MSG \
  19115. + ((VCHIQ_MAX_MSG_SIZE - sizeof(unsigned short))/sizeof(unsigned short))
  19116. +#define VC_CMA_RESERVE_COUNT_MAX 16
  19117. +
  19118. +#define PAGES_PER_CHUNK (VC_CMA_CHUNK_SIZE / PAGE_SIZE)
  19119. +
  19120. +#define VCADDR_TO_PHYSADDR(vcaddr) (mm_vc_mem_phys_addr + vcaddr)
  19121. +
  19122. +#define loud_error(...) \
  19123. + LOG_ERR("===== " __VA_ARGS__)
  19124. +
  19125. +enum {
  19126. + VC_CMA_MSG_QUIT,
  19127. + VC_CMA_MSG_OPEN,
  19128. + VC_CMA_MSG_TICK,
  19129. + VC_CMA_MSG_ALLOC, /* chunk count */
  19130. + VC_CMA_MSG_FREE, /* chunk, chunk, ... */
  19131. + VC_CMA_MSG_ALLOCATED, /* chunk, chunk, ... */
  19132. + VC_CMA_MSG_REQUEST_ALLOC, /* chunk count */
  19133. + VC_CMA_MSG_REQUEST_FREE, /* chunk count */
  19134. + VC_CMA_MSG_RESERVE, /* bytes lo, bytes hi */
  19135. + VC_CMA_MSG_UPDATE_RESERVE,
  19136. + VC_CMA_MSG_MAX
  19137. +};
  19138. +
  19139. +struct cma_msg {
  19140. + unsigned short type;
  19141. + unsigned short params[VC_CMA_MAX_PARAMS_PER_MSG];
  19142. +};
  19143. +
  19144. +struct vc_cma_reserve_user {
  19145. + unsigned int pid;
  19146. + unsigned int reserve;
  19147. +};
  19148. +
  19149. +/* Device (/dev) related variables */
  19150. +static dev_t vc_cma_devnum;
  19151. +static struct class *vc_cma_class;
  19152. +static struct cdev vc_cma_cdev;
  19153. +static int vc_cma_inited;
  19154. +static int vc_cma_debug;
  19155. +
  19156. +/* Proc entry */
  19157. +static struct proc_dir_entry *vc_cma_proc_entry;
  19158. +
  19159. +phys_addr_t vc_cma_base;
  19160. +struct page *vc_cma_base_page;
  19161. +unsigned int vc_cma_size;
  19162. +EXPORT_SYMBOL(vc_cma_size);
  19163. +unsigned int vc_cma_initial;
  19164. +unsigned int vc_cma_chunks;
  19165. +unsigned int vc_cma_chunks_used;
  19166. +unsigned int vc_cma_chunks_reserved;
  19167. +
  19168. +
  19169. +void *vc_cma_dma_alloc;
  19170. +unsigned int vc_cma_dma_size;
  19171. +
  19172. +static int in_loud_error;
  19173. +
  19174. +unsigned int vc_cma_reserve_total;
  19175. +unsigned int vc_cma_reserve_count;
  19176. +struct vc_cma_reserve_user vc_cma_reserve_users[VC_CMA_RESERVE_COUNT_MAX];
  19177. +static DEFINE_SEMAPHORE(vc_cma_reserve_mutex);
  19178. +static DEFINE_SEMAPHORE(vc_cma_worker_queue_push_mutex);
  19179. +
  19180. +static u64 vc_cma_dma_mask = DMA_BIT_MASK(32);
  19181. +static struct platform_device vc_cma_device = {
  19182. + .name = "vc-cma",
  19183. + .id = 0,
  19184. + .dev = {
  19185. + .dma_mask = &vc_cma_dma_mask,
  19186. + .coherent_dma_mask = DMA_BIT_MASK(32),
  19187. + },
  19188. +};
  19189. +
  19190. +static VCHIQ_INSTANCE_T cma_instance;
  19191. +static VCHIQ_SERVICE_HANDLE_T cma_service;
  19192. +static VCHIU_QUEUE_T cma_msg_queue;
  19193. +static struct task_struct *cma_worker;
  19194. +
  19195. +static int vc_cma_set_reserve(unsigned int reserve, unsigned int pid);
  19196. +static int vc_cma_alloc_chunks(int num_chunks, struct cma_msg *reply);
  19197. +static VCHIQ_STATUS_T cma_service_callback(VCHIQ_REASON_T reason,
  19198. + VCHIQ_HEADER_T * header,
  19199. + VCHIQ_SERVICE_HANDLE_T service,
  19200. + void *bulk_userdata);
  19201. +static void send_vc_msg(unsigned short type,
  19202. + unsigned short param1, unsigned short param2);
  19203. +static bool send_worker_msg(VCHIQ_HEADER_T * msg);
  19204. +
  19205. +static int early_vc_cma_mem(char *p)
  19206. +{
  19207. + unsigned int new_size;
  19208. + printk(KERN_NOTICE "early_vc_cma_mem(%s)", p);
  19209. + vc_cma_size = memparse(p, &p);
  19210. + vc_cma_initial = vc_cma_size;
  19211. + if (*p == '/')
  19212. + vc_cma_size = memparse(p + 1, &p);
  19213. + if (*p == '@')
  19214. + vc_cma_base = memparse(p + 1, &p);
  19215. +
  19216. + new_size = (vc_cma_size - ((-vc_cma_base) & (VC_CMA_CHUNK_SIZE - 1)))
  19217. + & ~(VC_CMA_CHUNK_SIZE - 1);
  19218. + if (new_size > vc_cma_size)
  19219. + vc_cma_size = 0;
  19220. + vc_cma_initial = (vc_cma_initial + VC_CMA_CHUNK_SIZE - 1)
  19221. + & ~(VC_CMA_CHUNK_SIZE - 1);
  19222. + if (vc_cma_initial > vc_cma_size)
  19223. + vc_cma_initial = vc_cma_size;
  19224. + vc_cma_base = (vc_cma_base + VC_CMA_CHUNK_SIZE - 1)
  19225. + & ~(VC_CMA_CHUNK_SIZE - 1);
  19226. +
  19227. + printk(KERN_NOTICE " -> initial %x, size %x, base %x", vc_cma_initial,
  19228. + vc_cma_size, (unsigned int)vc_cma_base);
  19229. +
  19230. + return 0;
  19231. +}
  19232. +
  19233. +early_param("vc-cma-mem", early_vc_cma_mem);
  19234. +
  19235. +void vc_cma_early_init(void)
  19236. +{
  19237. + LOG_DBG("vc_cma_early_init - vc_cma_chunks = %d", vc_cma_chunks);
  19238. + if (vc_cma_size) {
  19239. + int rc = platform_device_register(&vc_cma_device);
  19240. + LOG_DBG("platform_device_register -> %d", rc);
  19241. + }
  19242. +}
  19243. +
  19244. +void vc_cma_reserve(void)
  19245. +{
  19246. + /* if vc_cma_size is set, then declare vc CMA area of the same
  19247. + * size from the end of memory
  19248. + */
  19249. + if (vc_cma_size) {
  19250. + if (dma_declare_contiguous(&vc_cma_device.dev, vc_cma_size,
  19251. + vc_cma_base, 0) == 0) {
  19252. + if (!dev_get_cma_area(NULL)) {
  19253. + /* There is no default CMA area - make this
  19254. + the default */
  19255. + struct cma *vc_cma_area = dev_get_cma_area(
  19256. + &vc_cma_device.dev);
  19257. + dma_contiguous_set_default(vc_cma_area);
  19258. + LOG_INFO("vc_cma_reserve - using vc_cma as "
  19259. + "the default contiguous DMA area");
  19260. + }
  19261. + } else {
  19262. + LOG_ERR("vc_cma: dma_declare_contiguous(%x,%x) failed",
  19263. + vc_cma_size, (unsigned int)vc_cma_base);
  19264. + vc_cma_size = 0;
  19265. + }
  19266. + }
  19267. + vc_cma_chunks = vc_cma_size / VC_CMA_CHUNK_SIZE;
  19268. +}
  19269. +
  19270. +/****************************************************************************
  19271. +*
  19272. +* vc_cma_open
  19273. +*
  19274. +***************************************************************************/
  19275. +
  19276. +static int vc_cma_open(struct inode *inode, struct file *file)
  19277. +{
  19278. + (void)inode;
  19279. + (void)file;
  19280. +
  19281. + return 0;
  19282. +}
  19283. +
  19284. +/****************************************************************************
  19285. +*
  19286. +* vc_cma_release
  19287. +*
  19288. +***************************************************************************/
  19289. +
  19290. +static int vc_cma_release(struct inode *inode, struct file *file)
  19291. +{
  19292. + (void)inode;
  19293. + (void)file;
  19294. +
  19295. + vc_cma_set_reserve(0, current->tgid);
  19296. +
  19297. + return 0;
  19298. +}
  19299. +
  19300. +/****************************************************************************
  19301. +*
  19302. +* vc_cma_ioctl
  19303. +*
  19304. +***************************************************************************/
  19305. +
  19306. +static long vc_cma_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  19307. +{
  19308. + int rc = 0;
  19309. +
  19310. + (void)cmd;
  19311. + (void)arg;
  19312. +
  19313. + switch (cmd) {
  19314. + case VC_CMA_IOC_RESERVE:
  19315. + rc = vc_cma_set_reserve((unsigned int)arg, current->tgid);
  19316. + if (rc >= 0)
  19317. + rc = 0;
  19318. + break;
  19319. + default:
  19320. + LOG_ERR("vc-cma: Unknown ioctl %x", cmd);
  19321. + return -ENOTTY;
  19322. + }
  19323. +
  19324. + return rc;
  19325. +}
  19326. +
  19327. +/****************************************************************************
  19328. +*
  19329. +* File Operations for the driver.
  19330. +*
  19331. +***************************************************************************/
  19332. +
  19333. +static const struct file_operations vc_cma_fops = {
  19334. + .owner = THIS_MODULE,
  19335. + .open = vc_cma_open,
  19336. + .release = vc_cma_release,
  19337. + .unlocked_ioctl = vc_cma_ioctl,
  19338. +};
  19339. +
  19340. +/****************************************************************************
  19341. +*
  19342. +* vc_cma_proc_open
  19343. +*
  19344. +***************************************************************************/
  19345. +
  19346. +static int vc_cma_show_info(struct seq_file *m, void *v)
  19347. +{
  19348. + int i;
  19349. +
  19350. + seq_printf(m, "Videocore CMA:\n");
  19351. + seq_printf(m, " Base : %08x\n", (unsigned int)vc_cma_base);
  19352. + seq_printf(m, " Length : %08x\n", vc_cma_size);
  19353. + seq_printf(m, " Initial : %08x\n", vc_cma_initial);
  19354. + seq_printf(m, " Chunk size : %08x\n", VC_CMA_CHUNK_SIZE);
  19355. + seq_printf(m, " Chunks : %4d (%d bytes)\n",
  19356. + (int)vc_cma_chunks,
  19357. + (int)(vc_cma_chunks * VC_CMA_CHUNK_SIZE));
  19358. + seq_printf(m, " Used : %4d (%d bytes)\n",
  19359. + (int)vc_cma_chunks_used,
  19360. + (int)(vc_cma_chunks_used * VC_CMA_CHUNK_SIZE));
  19361. + seq_printf(m, " Reserved : %4d (%d bytes)\n",
  19362. + (unsigned int)vc_cma_chunks_reserved,
  19363. + (int)(vc_cma_chunks_reserved * VC_CMA_CHUNK_SIZE));
  19364. +
  19365. + for (i = 0; i < vc_cma_reserve_count; i++) {
  19366. + struct vc_cma_reserve_user *user = &vc_cma_reserve_users[i];
  19367. + seq_printf(m, " PID %5d: %d bytes\n", user->pid,
  19368. + user->reserve);
  19369. + }
  19370. + seq_printf(m, " dma_alloc : %p (%d pages)\n",
  19371. + vc_cma_dma_alloc ? page_address(vc_cma_dma_alloc) : 0,
  19372. + vc_cma_dma_size);
  19373. +
  19374. + seq_printf(m, "\n");
  19375. +
  19376. + return 0;
  19377. +}
  19378. +
  19379. +static int vc_cma_proc_open(struct inode *inode, struct file *file)
  19380. +{
  19381. + return single_open(file, vc_cma_show_info, NULL);
  19382. +}
  19383. +
  19384. +/****************************************************************************
  19385. +*
  19386. +* vc_cma_proc_write
  19387. +*
  19388. +***************************************************************************/
  19389. +
  19390. +static int vc_cma_proc_write(struct file *file,
  19391. + const char __user *buffer,
  19392. + size_t size, loff_t *ppos)
  19393. +{
  19394. + int rc = -EFAULT;
  19395. + char input_str[20];
  19396. +
  19397. + memset(input_str, 0, sizeof(input_str));
  19398. +
  19399. + if (size > sizeof(input_str)) {
  19400. + LOG_ERR("%s: input string length too long", __func__);
  19401. + goto out;
  19402. + }
  19403. +
  19404. + if (copy_from_user(input_str, buffer, size - 1)) {
  19405. + LOG_ERR("%s: failed to get input string", __func__);
  19406. + goto out;
  19407. + }
  19408. +#define ALLOC_STR "alloc"
  19409. +#define FREE_STR "free"
  19410. +#define DEBUG_STR "debug"
  19411. +#define RESERVE_STR "reserve"
  19412. +#define DMA_ALLOC_STR "dma_alloc"
  19413. +#define DMA_FREE_STR "dma_free"
  19414. + if (strncmp(input_str, ALLOC_STR, strlen(ALLOC_STR)) == 0) {
  19415. + int alloc_size;
  19416. + char *p = input_str + strlen(ALLOC_STR);
  19417. +
  19418. + while (*p == ' ')
  19419. + p++;
  19420. + alloc_size = memparse(p, NULL);
  19421. + LOG_INFO("/proc/vc-cma: alloc %d", alloc_size);
  19422. + if (alloc_size)
  19423. + send_vc_msg(VC_CMA_MSG_REQUEST_FREE,
  19424. + alloc_size / VC_CMA_CHUNK_SIZE, 0);
  19425. + else
  19426. + LOG_ERR("invalid size '%s'", p);
  19427. + rc = size;
  19428. + } else if (strncmp(input_str, FREE_STR, strlen(FREE_STR)) == 0) {
  19429. + int alloc_size;
  19430. + char *p = input_str + strlen(FREE_STR);
  19431. +
  19432. + while (*p == ' ')
  19433. + p++;
  19434. + alloc_size = memparse(p, NULL);
  19435. + LOG_INFO("/proc/vc-cma: free %d", alloc_size);
  19436. + if (alloc_size)
  19437. + send_vc_msg(VC_CMA_MSG_REQUEST_ALLOC,
  19438. + alloc_size / VC_CMA_CHUNK_SIZE, 0);
  19439. + else
  19440. + LOG_ERR("invalid size '%s'", p);
  19441. + rc = size;
  19442. + } else if (strncmp(input_str, DEBUG_STR, strlen(DEBUG_STR)) == 0) {
  19443. + char *p = input_str + strlen(DEBUG_STR);
  19444. + while (*p == ' ')
  19445. + p++;
  19446. + if ((strcmp(p, "on") == 0) || (strcmp(p, "1") == 0))
  19447. + vc_cma_debug = 1;
  19448. + else if ((strcmp(p, "off") == 0) || (strcmp(p, "0") == 0))
  19449. + vc_cma_debug = 0;
  19450. + LOG_INFO("/proc/vc-cma: debug %s", vc_cma_debug ? "on" : "off");
  19451. + rc = size;
  19452. + } else if (strncmp(input_str, RESERVE_STR, strlen(RESERVE_STR)) == 0) {
  19453. + int alloc_size;
  19454. + int reserved;
  19455. + char *p = input_str + strlen(RESERVE_STR);
  19456. + while (*p == ' ')
  19457. + p++;
  19458. + alloc_size = memparse(p, NULL);
  19459. +
  19460. + reserved = vc_cma_set_reserve(alloc_size, current->tgid);
  19461. + rc = (reserved >= 0) ? size : reserved;
  19462. + } else if (strncmp(input_str, DMA_ALLOC_STR, strlen(DMA_ALLOC_STR)) == 0) {
  19463. + int alloc_size;
  19464. + char *p = input_str + strlen(DMA_ALLOC_STR);
  19465. + while (*p == ' ')
  19466. + p++;
  19467. + alloc_size = memparse(p, NULL);
  19468. +
  19469. + if (vc_cma_dma_alloc) {
  19470. + dma_release_from_contiguous(NULL, vc_cma_dma_alloc,
  19471. + vc_cma_dma_size);
  19472. + vc_cma_dma_alloc = NULL;
  19473. + vc_cma_dma_size = 0;
  19474. + }
  19475. + vc_cma_dma_alloc = dma_alloc_from_contiguous(NULL, alloc_size, 0);
  19476. + vc_cma_dma_size = (vc_cma_dma_alloc ? alloc_size : 0);
  19477. + if (vc_cma_dma_alloc)
  19478. + LOG_INFO("dma_alloc(%d pages) -> %p", alloc_size, page_address(vc_cma_dma_alloc));
  19479. + else
  19480. + LOG_ERR("dma_alloc(%d pages) failed", alloc_size);
  19481. + rc = size;
  19482. + } else if (strncmp(input_str, DMA_FREE_STR, strlen(DMA_FREE_STR)) == 0) {
  19483. + if (vc_cma_dma_alloc) {
  19484. + dma_release_from_contiguous(NULL, vc_cma_dma_alloc,
  19485. + vc_cma_dma_size);
  19486. + vc_cma_dma_alloc = NULL;
  19487. + vc_cma_dma_size = 0;
  19488. + }
  19489. + rc = size;
  19490. + }
  19491. +
  19492. +out:
  19493. + return rc;
  19494. +}
  19495. +
  19496. +/****************************************************************************
  19497. +*
  19498. +* File Operations for /proc interface.
  19499. +*
  19500. +***************************************************************************/
  19501. +
  19502. +static const struct file_operations vc_cma_proc_fops = {
  19503. + .open = vc_cma_proc_open,
  19504. + .read = seq_read,
  19505. + .write = vc_cma_proc_write,
  19506. + .llseek = seq_lseek,
  19507. + .release = single_release
  19508. +};
  19509. +
  19510. +static int vc_cma_set_reserve(unsigned int reserve, unsigned int pid)
  19511. +{
  19512. + struct vc_cma_reserve_user *user = NULL;
  19513. + int delta = 0;
  19514. + int i;
  19515. +
  19516. + if (down_interruptible(&vc_cma_reserve_mutex))
  19517. + return -ERESTARTSYS;
  19518. +
  19519. + for (i = 0; i < vc_cma_reserve_count; i++) {
  19520. + if (pid == vc_cma_reserve_users[i].pid) {
  19521. + user = &vc_cma_reserve_users[i];
  19522. + delta = reserve - user->reserve;
  19523. + if (reserve)
  19524. + user->reserve = reserve;
  19525. + else {
  19526. + /* Remove this entry by copying downwards */
  19527. + while ((i + 1) < vc_cma_reserve_count) {
  19528. + user[0].pid = user[1].pid;
  19529. + user[0].reserve = user[1].reserve;
  19530. + user++;
  19531. + i++;
  19532. + }
  19533. + vc_cma_reserve_count--;
  19534. + user = NULL;
  19535. + }
  19536. + break;
  19537. + }
  19538. + }
  19539. +
  19540. + if (reserve && !user) {
  19541. + if (vc_cma_reserve_count == VC_CMA_RESERVE_COUNT_MAX) {
  19542. + LOG_ERR("vc-cma: Too many reservations - "
  19543. + "increase CMA_RESERVE_COUNT_MAX");
  19544. + up(&vc_cma_reserve_mutex);
  19545. + return -EBUSY;
  19546. + }
  19547. + user = &vc_cma_reserve_users[vc_cma_reserve_count];
  19548. + user->pid = pid;
  19549. + user->reserve = reserve;
  19550. + delta = reserve;
  19551. + vc_cma_reserve_count++;
  19552. + }
  19553. +
  19554. + vc_cma_reserve_total += delta;
  19555. +
  19556. + send_vc_msg(VC_CMA_MSG_RESERVE,
  19557. + vc_cma_reserve_total & 0xffff, vc_cma_reserve_total >> 16);
  19558. +
  19559. + send_worker_msg((VCHIQ_HEADER_T *) VC_CMA_MSG_UPDATE_RESERVE);
  19560. +
  19561. + LOG_DBG("/proc/vc-cma: reserve %d (PID %d) - total %u",
  19562. + reserve, pid, vc_cma_reserve_total);
  19563. +
  19564. + up(&vc_cma_reserve_mutex);
  19565. +
  19566. + return vc_cma_reserve_total;
  19567. +}
  19568. +
  19569. +static VCHIQ_STATUS_T cma_service_callback(VCHIQ_REASON_T reason,
  19570. + VCHIQ_HEADER_T * header,
  19571. + VCHIQ_SERVICE_HANDLE_T service,
  19572. + void *bulk_userdata)
  19573. +{
  19574. + switch (reason) {
  19575. + case VCHIQ_MESSAGE_AVAILABLE:
  19576. + if (!send_worker_msg(header))
  19577. + return VCHIQ_RETRY;
  19578. + break;
  19579. + case VCHIQ_SERVICE_CLOSED:
  19580. + LOG_DBG("CMA service closed");
  19581. + break;
  19582. + default:
  19583. + LOG_ERR("Unexpected CMA callback reason %d", reason);
  19584. + break;
  19585. + }
  19586. + return VCHIQ_SUCCESS;
  19587. +}
  19588. +
  19589. +static void send_vc_msg(unsigned short type,
  19590. + unsigned short param1, unsigned short param2)
  19591. +{
  19592. + unsigned short msg[] = { type, param1, param2 };
  19593. + VCHIQ_ELEMENT_T elem = { &msg, sizeof(msg) };
  19594. + VCHIQ_STATUS_T ret;
  19595. + vchiq_use_service(cma_service);
  19596. + ret = vchiq_queue_message(cma_service, &elem, 1);
  19597. + vchiq_release_service(cma_service);
  19598. + if (ret != VCHIQ_SUCCESS)
  19599. + LOG_ERR("vchiq_queue_message returned %x", ret);
  19600. +}
  19601. +
  19602. +static bool send_worker_msg(VCHIQ_HEADER_T * msg)
  19603. +{
  19604. + if (down_interruptible(&vc_cma_worker_queue_push_mutex))
  19605. + return false;
  19606. + vchiu_queue_push(&cma_msg_queue, msg);
  19607. + up(&vc_cma_worker_queue_push_mutex);
  19608. + return true;
  19609. +}
  19610. +
  19611. +static int vc_cma_alloc_chunks(int num_chunks, struct cma_msg *reply)
  19612. +{
  19613. + int i;
  19614. + for (i = 0; i < num_chunks; i++) {
  19615. + struct page *chunk;
  19616. + unsigned int chunk_num;
  19617. + uint8_t *chunk_addr;
  19618. + size_t chunk_size = PAGES_PER_CHUNK << PAGE_SHIFT;
  19619. +
  19620. + chunk = dma_alloc_from_contiguous(&vc_cma_device.dev,
  19621. + PAGES_PER_CHUNK,
  19622. + VC_CMA_CHUNK_ORDER);
  19623. + if (!chunk)
  19624. + break;
  19625. +
  19626. + chunk_addr = page_address(chunk);
  19627. + dmac_flush_range(chunk_addr, chunk_addr + chunk_size);
  19628. + outer_inv_range(__pa(chunk_addr), __pa(chunk_addr) +
  19629. + chunk_size);
  19630. +
  19631. + chunk_num =
  19632. + (page_to_phys(chunk) - vc_cma_base) / VC_CMA_CHUNK_SIZE;
  19633. + BUG_ON(((page_to_phys(chunk) - vc_cma_base) %
  19634. + VC_CMA_CHUNK_SIZE) != 0);
  19635. + if (chunk_num >= vc_cma_chunks) {
  19636. + phys_addr_t _pa = vc_cma_base + vc_cma_size - 1;
  19637. + LOG_ERR("%s: ===============================",
  19638. + __func__);
  19639. + LOG_ERR("%s: chunk phys %x, vc_cma %pa-%pa - "
  19640. + "bad SPARSEMEM configuration?",
  19641. + __func__, (unsigned int)page_to_phys(chunk),
  19642. + &vc_cma_base, &_pa);
  19643. + LOG_ERR("%s: dev->cma_area = %p", __func__,
  19644. + (void*)0/*vc_cma_device.dev.cma_area*/);
  19645. + LOG_ERR("%s: ===============================",
  19646. + __func__);
  19647. + break;
  19648. + }
  19649. + reply->params[i] = chunk_num;
  19650. + vc_cma_chunks_used++;
  19651. + }
  19652. +
  19653. + if (i < num_chunks) {
  19654. + LOG_ERR("%s: dma_alloc_from_contiguous failed "
  19655. + "for %x bytes (alloc %d of %d, %d free)",
  19656. + __func__, VC_CMA_CHUNK_SIZE, i,
  19657. + num_chunks, vc_cma_chunks - vc_cma_chunks_used);
  19658. + num_chunks = i;
  19659. + }
  19660. +
  19661. + LOG_DBG("CMA allocated %d chunks -> %d used",
  19662. + num_chunks, vc_cma_chunks_used);
  19663. + reply->type = VC_CMA_MSG_ALLOCATED;
  19664. +
  19665. + {
  19666. + VCHIQ_ELEMENT_T elem = {
  19667. + reply,
  19668. + offsetof(struct cma_msg, params[0]) +
  19669. + num_chunks * sizeof(reply->params[0])
  19670. + };
  19671. + VCHIQ_STATUS_T ret;
  19672. + vchiq_use_service(cma_service);
  19673. + ret = vchiq_queue_message(cma_service, &elem, 1);
  19674. + vchiq_release_service(cma_service);
  19675. + if (ret != VCHIQ_SUCCESS)
  19676. + LOG_ERR("vchiq_queue_message return " "%x", ret);
  19677. + }
  19678. +
  19679. + return num_chunks;
  19680. +}
  19681. +
  19682. +static int cma_worker_proc(void *param)
  19683. +{
  19684. + static struct cma_msg reply;
  19685. + (void)param;
  19686. +
  19687. + while (1) {
  19688. + VCHIQ_HEADER_T *msg;
  19689. + static struct cma_msg msg_copy;
  19690. + struct cma_msg *cma_msg = &msg_copy;
  19691. + int type, msg_size;
  19692. +
  19693. + msg = vchiu_queue_pop(&cma_msg_queue);
  19694. + if ((unsigned int)msg >= VC_CMA_MSG_MAX) {
  19695. + msg_size = msg->size;
  19696. + memcpy(&msg_copy, msg->data, msg_size);
  19697. + type = cma_msg->type;
  19698. + vchiq_release_message(cma_service, msg);
  19699. + } else {
  19700. + msg_size = 0;
  19701. + type = (int)msg;
  19702. + if (type == VC_CMA_MSG_QUIT)
  19703. + break;
  19704. + else if (type == VC_CMA_MSG_UPDATE_RESERVE) {
  19705. + msg = NULL;
  19706. + cma_msg = NULL;
  19707. + } else {
  19708. + BUG();
  19709. + continue;
  19710. + }
  19711. + }
  19712. +
  19713. + switch (type) {
  19714. + case VC_CMA_MSG_ALLOC:{
  19715. + int num_chunks, free_chunks;
  19716. + num_chunks = cma_msg->params[0];
  19717. + free_chunks =
  19718. + vc_cma_chunks - vc_cma_chunks_used;
  19719. + LOG_DBG("CMA_MSG_ALLOC(%d chunks)", num_chunks);
  19720. + if (num_chunks > VC_CMA_MAX_PARAMS_PER_MSG) {
  19721. + LOG_ERR
  19722. + ("CMA_MSG_ALLOC - chunk count (%d) "
  19723. + "exceeds VC_CMA_MAX_PARAMS_PER_MSG (%d)",
  19724. + num_chunks,
  19725. + VC_CMA_MAX_PARAMS_PER_MSG);
  19726. + num_chunks = VC_CMA_MAX_PARAMS_PER_MSG;
  19727. + }
  19728. +
  19729. + if (num_chunks > free_chunks) {
  19730. + LOG_ERR
  19731. + ("CMA_MSG_ALLOC - chunk count (%d) "
  19732. + "exceeds free chunks (%d)",
  19733. + num_chunks, free_chunks);
  19734. + num_chunks = free_chunks;
  19735. + }
  19736. +
  19737. + vc_cma_alloc_chunks(num_chunks, &reply);
  19738. + }
  19739. + break;
  19740. +
  19741. + case VC_CMA_MSG_FREE:{
  19742. + int chunk_count =
  19743. + (msg_size -
  19744. + offsetof(struct cma_msg,
  19745. + params)) /
  19746. + sizeof(cma_msg->params[0]);
  19747. + int i;
  19748. + BUG_ON(chunk_count <= 0);
  19749. +
  19750. + LOG_DBG("CMA_MSG_FREE(%d chunks - %x, ...)",
  19751. + chunk_count, cma_msg->params[0]);
  19752. + for (i = 0; i < chunk_count; i++) {
  19753. + int chunk_num = cma_msg->params[i];
  19754. + struct page *page = vc_cma_base_page +
  19755. + chunk_num * PAGES_PER_CHUNK;
  19756. + if (chunk_num >= vc_cma_chunks) {
  19757. + LOG_ERR
  19758. + ("CMA_MSG_FREE - chunk %d of %d"
  19759. + " (value %x) exceeds maximum "
  19760. + "(%x)", i, chunk_count,
  19761. + chunk_num,
  19762. + vc_cma_chunks - 1);
  19763. + break;
  19764. + }
  19765. +
  19766. + if (!dma_release_from_contiguous
  19767. + (&vc_cma_device.dev, page,
  19768. + PAGES_PER_CHUNK)) {
  19769. + phys_addr_t _pa = page_to_phys(page);
  19770. + LOG_ERR
  19771. + ("CMA_MSG_FREE - failed to "
  19772. + "release chunk %d (phys %pa, "
  19773. + "page %x)", chunk_num,
  19774. + &_pa,
  19775. + (unsigned int)page);
  19776. + }
  19777. + vc_cma_chunks_used--;
  19778. + }
  19779. + LOG_DBG("CMA released %d chunks -> %d used",
  19780. + i, vc_cma_chunks_used);
  19781. + }
  19782. + break;
  19783. +
  19784. + case VC_CMA_MSG_UPDATE_RESERVE:{
  19785. + int chunks_needed =
  19786. + ((vc_cma_reserve_total + VC_CMA_CHUNK_SIZE -
  19787. + 1)
  19788. + / VC_CMA_CHUNK_SIZE) -
  19789. + vc_cma_chunks_reserved;
  19790. +
  19791. + LOG_DBG
  19792. + ("CMA_MSG_UPDATE_RESERVE(%d chunks needed)",
  19793. + chunks_needed);
  19794. +
  19795. + /* Cap the reservations to what is available */
  19796. + if (chunks_needed > 0) {
  19797. + if (chunks_needed >
  19798. + (vc_cma_chunks -
  19799. + vc_cma_chunks_used))
  19800. + chunks_needed =
  19801. + (vc_cma_chunks -
  19802. + vc_cma_chunks_used);
  19803. +
  19804. + chunks_needed =
  19805. + vc_cma_alloc_chunks(chunks_needed,
  19806. + &reply);
  19807. + }
  19808. +
  19809. + LOG_DBG
  19810. + ("CMA_MSG_UPDATE_RESERVE(%d chunks allocated)",
  19811. + chunks_needed);
  19812. + vc_cma_chunks_reserved += chunks_needed;
  19813. + }
  19814. + break;
  19815. +
  19816. + default:
  19817. + LOG_ERR("unexpected msg type %d", type);
  19818. + break;
  19819. + }
  19820. + }
  19821. +
  19822. + LOG_DBG("quitting...");
  19823. + return 0;
  19824. +}
  19825. +
  19826. +/****************************************************************************
  19827. +*
  19828. +* vc_cma_connected_init
  19829. +*
  19830. +* This function is called once the videocore has been connected.
  19831. +*
  19832. +***************************************************************************/
  19833. +
  19834. +static void vc_cma_connected_init(void)
  19835. +{
  19836. + VCHIQ_SERVICE_PARAMS_T service_params;
  19837. +
  19838. + LOG_DBG("vc_cma_connected_init");
  19839. +
  19840. + if (!vchiu_queue_init(&cma_msg_queue, 16)) {
  19841. + LOG_ERR("could not create CMA msg queue");
  19842. + goto fail_queue;
  19843. + }
  19844. +
  19845. + if (vchiq_initialise(&cma_instance) != VCHIQ_SUCCESS)
  19846. + goto fail_vchiq_init;
  19847. +
  19848. + vchiq_connect(cma_instance);
  19849. +
  19850. + service_params.fourcc = VC_CMA_FOURCC;
  19851. + service_params.callback = cma_service_callback;
  19852. + service_params.userdata = NULL;
  19853. + service_params.version = VC_CMA_VERSION;
  19854. + service_params.version_min = VC_CMA_VERSION;
  19855. +
  19856. + if (vchiq_open_service(cma_instance, &service_params,
  19857. + &cma_service) != VCHIQ_SUCCESS) {
  19858. + LOG_ERR("failed to open service - already in use?");
  19859. + goto fail_vchiq_open;
  19860. + }
  19861. +
  19862. + vchiq_release_service(cma_service);
  19863. +
  19864. + cma_worker = kthread_create(cma_worker_proc, NULL, "cma_worker");
  19865. + if (!cma_worker) {
  19866. + LOG_ERR("could not create CMA worker thread");
  19867. + goto fail_worker;
  19868. + }
  19869. + set_user_nice(cma_worker, -20);
  19870. + wake_up_process(cma_worker);
  19871. +
  19872. + return;
  19873. +
  19874. +fail_worker:
  19875. + vchiq_close_service(cma_service);
  19876. +fail_vchiq_open:
  19877. + vchiq_shutdown(cma_instance);
  19878. +fail_vchiq_init:
  19879. + vchiu_queue_delete(&cma_msg_queue);
  19880. +fail_queue:
  19881. + return;
  19882. +}
  19883. +
  19884. +void
  19885. +loud_error_header(void)
  19886. +{
  19887. + if (in_loud_error)
  19888. + return;
  19889. +
  19890. + LOG_ERR("============================================================"
  19891. + "================");
  19892. + LOG_ERR("============================================================"
  19893. + "================");
  19894. + LOG_ERR("=====");
  19895. +
  19896. + in_loud_error = 1;
  19897. +}
  19898. +
  19899. +void
  19900. +loud_error_footer(void)
  19901. +{
  19902. + if (!in_loud_error)
  19903. + return;
  19904. +
  19905. + LOG_ERR("=====");
  19906. + LOG_ERR("============================================================"
  19907. + "================");
  19908. + LOG_ERR("============================================================"
  19909. + "================");
  19910. +
  19911. + in_loud_error = 0;
  19912. +}
  19913. +
  19914. +#if 1
  19915. +static int check_cma_config(void) { return 1; }
  19916. +#else
  19917. +static int
  19918. +read_vc_debug_var(VC_MEM_ACCESS_HANDLE_T handle,
  19919. + const char *symbol,
  19920. + void *buf, size_t bufsize)
  19921. +{
  19922. + VC_MEM_ADDR_T vcMemAddr;
  19923. + size_t vcMemSize;
  19924. + uint8_t *mapAddr;
  19925. + off_t vcMapAddr;
  19926. +
  19927. + if (!LookupVideoCoreSymbol(handle, symbol,
  19928. + &vcMemAddr,
  19929. + &vcMemSize)) {
  19930. + loud_error_header();
  19931. + loud_error(
  19932. + "failed to find VC symbol \"%s\".",
  19933. + symbol);
  19934. + loud_error_footer();
  19935. + return 0;
  19936. + }
  19937. +
  19938. + if (vcMemSize != bufsize) {
  19939. + loud_error_header();
  19940. + loud_error(
  19941. + "VC symbol \"%s\" is the wrong size.",
  19942. + symbol);
  19943. + loud_error_footer();
  19944. + return 0;
  19945. + }
  19946. +
  19947. + vcMapAddr = (off_t)vcMemAddr & VC_MEM_TO_ARM_ADDR_MASK;
  19948. + vcMapAddr += mm_vc_mem_phys_addr;
  19949. + mapAddr = ioremap_nocache(vcMapAddr, vcMemSize);
  19950. + if (mapAddr == 0) {
  19951. + loud_error_header();
  19952. + loud_error(
  19953. + "failed to ioremap \"%s\" @ 0x%x "
  19954. + "(phys: 0x%x, size: %u).",
  19955. + symbol,
  19956. + (unsigned int)vcMapAddr,
  19957. + (unsigned int)vcMemAddr,
  19958. + (unsigned int)vcMemSize);
  19959. + loud_error_footer();
  19960. + return 0;
  19961. + }
  19962. +
  19963. + memcpy(buf, mapAddr, bufsize);
  19964. + iounmap(mapAddr);
  19965. +
  19966. + return 1;
  19967. +}
  19968. +
  19969. +
  19970. +static int
  19971. +check_cma_config(void)
  19972. +{
  19973. + VC_MEM_ACCESS_HANDLE_T mem_hndl;
  19974. + VC_MEM_ADDR_T mempool_start;
  19975. + VC_MEM_ADDR_T mempool_end;
  19976. + VC_MEM_ADDR_T mempool_offline_start;
  19977. + VC_MEM_ADDR_T mempool_offline_end;
  19978. + VC_MEM_ADDR_T cam_alloc_base;
  19979. + VC_MEM_ADDR_T cam_alloc_size;
  19980. + VC_MEM_ADDR_T cam_alloc_end;
  19981. + int success = 0;
  19982. +
  19983. + if (OpenVideoCoreMemory(&mem_hndl) != 0)
  19984. + goto out;
  19985. +
  19986. + /* Read the relevant VideoCore variables */
  19987. + if (!read_vc_debug_var(mem_hndl, "__MEMPOOL_START",
  19988. + &mempool_start,
  19989. + sizeof(mempool_start)))
  19990. + goto close;
  19991. +
  19992. + if (!read_vc_debug_var(mem_hndl, "__MEMPOOL_END",
  19993. + &mempool_end,
  19994. + sizeof(mempool_end)))
  19995. + goto close;
  19996. +
  19997. + if (!read_vc_debug_var(mem_hndl, "__MEMPOOL_OFFLINE_START",
  19998. + &mempool_offline_start,
  19999. + sizeof(mempool_offline_start)))
  20000. + goto close;
  20001. +
  20002. + if (!read_vc_debug_var(mem_hndl, "__MEMPOOL_OFFLINE_END",
  20003. + &mempool_offline_end,
  20004. + sizeof(mempool_offline_end)))
  20005. + goto close;
  20006. +
  20007. + if (!read_vc_debug_var(mem_hndl, "cam_alloc_base",
  20008. + &cam_alloc_base,
  20009. + sizeof(cam_alloc_base)))
  20010. + goto close;
  20011. +
  20012. + if (!read_vc_debug_var(mem_hndl, "cam_alloc_size",
  20013. + &cam_alloc_size,
  20014. + sizeof(cam_alloc_size)))
  20015. + goto close;
  20016. +
  20017. + cam_alloc_end = cam_alloc_base + cam_alloc_size;
  20018. +
  20019. + success = 1;
  20020. +
  20021. + /* Now the sanity checks */
  20022. + if (!mempool_offline_start)
  20023. + mempool_offline_start = mempool_start;
  20024. + if (!mempool_offline_end)
  20025. + mempool_offline_end = mempool_end;
  20026. +
  20027. + if (VCADDR_TO_PHYSADDR(mempool_offline_start) != vc_cma_base) {
  20028. + loud_error_header();
  20029. + loud_error(
  20030. + "__MEMPOOL_OFFLINE_START(%x -> %lx) doesn't match "
  20031. + "vc_cma_base(%x)",
  20032. + mempool_offline_start,
  20033. + VCADDR_TO_PHYSADDR(mempool_offline_start),
  20034. + vc_cma_base);
  20035. + success = 0;
  20036. + }
  20037. +
  20038. + if (VCADDR_TO_PHYSADDR(mempool_offline_end) !=
  20039. + (vc_cma_base + vc_cma_size)) {
  20040. + loud_error_header();
  20041. + loud_error(
  20042. + "__MEMPOOL_OFFLINE_END(%x -> %lx) doesn't match "
  20043. + "vc_cma_base(%x) + vc_cma_size(%x) = %x",
  20044. + mempool_offline_start,
  20045. + VCADDR_TO_PHYSADDR(mempool_offline_end),
  20046. + vc_cma_base, vc_cma_size, vc_cma_base + vc_cma_size);
  20047. + success = 0;
  20048. + }
  20049. +
  20050. + if (mempool_end < mempool_start) {
  20051. + loud_error_header();
  20052. + loud_error(
  20053. + "__MEMPOOL_END(%x) must not be before "
  20054. + "__MEMPOOL_START(%x)",
  20055. + mempool_end,
  20056. + mempool_start);
  20057. + success = 0;
  20058. + }
  20059. +
  20060. + if (mempool_offline_end < mempool_offline_start) {
  20061. + loud_error_header();
  20062. + loud_error(
  20063. + "__MEMPOOL_OFFLINE_END(%x) must not be before "
  20064. + "__MEMPOOL_OFFLINE_START(%x)",
  20065. + mempool_offline_end,
  20066. + mempool_offline_start);
  20067. + success = 0;
  20068. + }
  20069. +
  20070. + if (mempool_offline_start < mempool_start) {
  20071. + loud_error_header();
  20072. + loud_error(
  20073. + "__MEMPOOL_OFFLINE_START(%x) must not be before "
  20074. + "__MEMPOOL_START(%x)",
  20075. + mempool_offline_start,
  20076. + mempool_start);
  20077. + success = 0;
  20078. + }
  20079. +
  20080. + if (mempool_offline_end > mempool_end) {
  20081. + loud_error_header();
  20082. + loud_error(
  20083. + "__MEMPOOL_OFFLINE_END(%x) must not be after "
  20084. + "__MEMPOOL_END(%x)",
  20085. + mempool_offline_end,
  20086. + mempool_end);
  20087. + success = 0;
  20088. + }
  20089. +
  20090. + if ((cam_alloc_base < mempool_end) &&
  20091. + (cam_alloc_end > mempool_start)) {
  20092. + loud_error_header();
  20093. + loud_error(
  20094. + "cam_alloc pool(%x-%x) overlaps "
  20095. + "mempool(%x-%x)",
  20096. + cam_alloc_base, cam_alloc_end,
  20097. + mempool_start, mempool_end);
  20098. + success = 0;
  20099. + }
  20100. +
  20101. + loud_error_footer();
  20102. +
  20103. +close:
  20104. + CloseVideoCoreMemory(mem_hndl);
  20105. +
  20106. +out:
  20107. + return success;
  20108. +}
  20109. +#endif
  20110. +
  20111. +static int vc_cma_init(void)
  20112. +{
  20113. + int rc = -EFAULT;
  20114. + struct device *dev;
  20115. +
  20116. + if (!check_cma_config())
  20117. + goto out_release;
  20118. +
  20119. + LOG_INFO("vc-cma: Videocore CMA driver");
  20120. + LOG_INFO("vc-cma: vc_cma_base = %pa", &vc_cma_base);
  20121. + LOG_INFO("vc-cma: vc_cma_size = 0x%08x (%u MiB)",
  20122. + vc_cma_size, vc_cma_size / (1024 * 1024));
  20123. + LOG_INFO("vc-cma: vc_cma_initial = 0x%08x (%u MiB)",
  20124. + vc_cma_initial, vc_cma_initial / (1024 * 1024));
  20125. +
  20126. + vc_cma_base_page = phys_to_page(vc_cma_base);
  20127. +
  20128. + if (vc_cma_chunks) {
  20129. + int chunks_needed = vc_cma_initial / VC_CMA_CHUNK_SIZE;
  20130. +
  20131. + for (vc_cma_chunks_used = 0;
  20132. + vc_cma_chunks_used < chunks_needed; vc_cma_chunks_used++) {
  20133. + struct page *chunk;
  20134. + chunk = dma_alloc_from_contiguous(&vc_cma_device.dev,
  20135. + PAGES_PER_CHUNK,
  20136. + VC_CMA_CHUNK_ORDER);
  20137. + if (!chunk)
  20138. + break;
  20139. + BUG_ON(((page_to_phys(chunk) - vc_cma_base) %
  20140. + VC_CMA_CHUNK_SIZE) != 0);
  20141. + }
  20142. + if (vc_cma_chunks_used != chunks_needed) {
  20143. + LOG_ERR("%s: dma_alloc_from_contiguous failed (%d "
  20144. + "bytes, allocation %d of %d)",
  20145. + __func__, VC_CMA_CHUNK_SIZE,
  20146. + vc_cma_chunks_used, chunks_needed);
  20147. + goto out_release;
  20148. + }
  20149. +
  20150. + vchiq_add_connected_callback(vc_cma_connected_init);
  20151. + }
  20152. +
  20153. + rc = alloc_chrdev_region(&vc_cma_devnum, 0, 1, DRIVER_NAME);
  20154. + if (rc < 0) {
  20155. + LOG_ERR("%s: alloc_chrdev_region failed (rc=%d)", __func__, rc);
  20156. + goto out_release;
  20157. + }
  20158. +
  20159. + cdev_init(&vc_cma_cdev, &vc_cma_fops);
  20160. + rc = cdev_add(&vc_cma_cdev, vc_cma_devnum, 1);
  20161. + if (rc != 0) {
  20162. + LOG_ERR("%s: cdev_add failed (rc=%d)", __func__, rc);
  20163. + goto out_unregister;
  20164. + }
  20165. +
  20166. + vc_cma_class = class_create(THIS_MODULE, DRIVER_NAME);
  20167. + if (IS_ERR(vc_cma_class)) {
  20168. + rc = PTR_ERR(vc_cma_class);
  20169. + LOG_ERR("%s: class_create failed (rc=%d)", __func__, rc);
  20170. + goto out_cdev_del;
  20171. + }
  20172. +
  20173. + dev = device_create(vc_cma_class, NULL, vc_cma_devnum, NULL,
  20174. + DRIVER_NAME);
  20175. + if (IS_ERR(dev)) {
  20176. + rc = PTR_ERR(dev);
  20177. + LOG_ERR("%s: device_create failed (rc=%d)", __func__, rc);
  20178. + goto out_class_destroy;
  20179. + }
  20180. +
  20181. + vc_cma_proc_entry = proc_create(DRIVER_NAME, 0444, NULL, &vc_cma_proc_fops);
  20182. + if (vc_cma_proc_entry == NULL) {
  20183. + rc = -EFAULT;
  20184. + LOG_ERR("%s: proc_create failed", __func__);
  20185. + goto out_device_destroy;
  20186. + }
  20187. +
  20188. + vc_cma_inited = 1;
  20189. + return 0;
  20190. +
  20191. +out_device_destroy:
  20192. + device_destroy(vc_cma_class, vc_cma_devnum);
  20193. +
  20194. +out_class_destroy:
  20195. + class_destroy(vc_cma_class);
  20196. + vc_cma_class = NULL;
  20197. +
  20198. +out_cdev_del:
  20199. + cdev_del(&vc_cma_cdev);
  20200. +
  20201. +out_unregister:
  20202. + unregister_chrdev_region(vc_cma_devnum, 1);
  20203. +
  20204. +out_release:
  20205. + /* It is tempting to try to clean up by calling
  20206. + dma_release_from_contiguous for all allocated chunks, but it isn't
  20207. + a very safe thing to do. If vc_cma_initial is non-zero it is because
  20208. + VideoCore is already using that memory, so giving it back to Linux
  20209. + is likely to be fatal.
  20210. + */
  20211. + return -1;
  20212. +}
  20213. +
  20214. +/****************************************************************************
  20215. +*
  20216. +* vc_cma_exit
  20217. +*
  20218. +***************************************************************************/
  20219. +
  20220. +static void __exit vc_cma_exit(void)
  20221. +{
  20222. + LOG_DBG("%s: called", __func__);
  20223. +
  20224. + if (vc_cma_inited) {
  20225. + remove_proc_entry(DRIVER_NAME, NULL);
  20226. + device_destroy(vc_cma_class, vc_cma_devnum);
  20227. + class_destroy(vc_cma_class);
  20228. + cdev_del(&vc_cma_cdev);
  20229. + unregister_chrdev_region(vc_cma_devnum, 1);
  20230. + }
  20231. +}
  20232. +
  20233. +module_init(vc_cma_init);
  20234. +module_exit(vc_cma_exit);
  20235. +MODULE_LICENSE("GPL");
  20236. +MODULE_AUTHOR("Broadcom Corporation");
  20237. diff -Nur linux-3.18.8/drivers/char/broadcom/vc_sm/Makefile linux-rpi/drivers/char/broadcom/vc_sm/Makefile
  20238. --- linux-3.18.8/drivers/char/broadcom/vc_sm/Makefile 1970-01-01 01:00:00.000000000 +0100
  20239. +++ linux-rpi/drivers/char/broadcom/vc_sm/Makefile 2015-03-05 14:40:12.661715830 +0100
  20240. @@ -0,0 +1,21 @@
  20241. +EXTRA_CFLAGS += -Wall -Wstrict-prototypes -Wno-trigraphs -O2
  20242. +
  20243. +EXTRA_CFLAGS += -I"./arch/arm/mach-bcm2708/include/mach"
  20244. +EXTRA_CFLAGS += -I"drivers/misc/vc04_services"
  20245. +EXTRA_CFLAGS += -I"drivers/misc/vc04_services/interface/vchi"
  20246. +EXTRA_CFLAGS += -I"drivers/misc/vc04_services/interface/vchiq_arm"
  20247. +EXTRA_CFLAGS += -I"$(srctree)/fs/"
  20248. +
  20249. +EXTRA_CFLAGS += -DOS_ASSERT_FAILURE
  20250. +EXTRA_CFLAGS += -D__STDC_VERSION=199901L
  20251. +EXTRA_CFLAGS += -D__STDC_VERSION__=199901L
  20252. +EXTRA_CFLAGS += -D__VCCOREVER__=0
  20253. +EXTRA_CFLAGS += -D__KERNEL__
  20254. +EXTRA_CFLAGS += -D__linux__
  20255. +EXTRA_CFLAGS += -Werror
  20256. +
  20257. +obj-$(CONFIG_BCM_VC_SM) := vc-sm.o
  20258. +
  20259. +vc-sm-objs := \
  20260. + vmcs_sm.o \
  20261. + vc_vchi_sm.o
  20262. diff -Nur linux-3.18.8/drivers/char/broadcom/vc_sm/vc_vchi_sm.c linux-rpi/drivers/char/broadcom/vc_sm/vc_vchi_sm.c
  20263. --- linux-3.18.8/drivers/char/broadcom/vc_sm/vc_vchi_sm.c 1970-01-01 01:00:00.000000000 +0100
  20264. +++ linux-rpi/drivers/char/broadcom/vc_sm/vc_vchi_sm.c 2015-03-05 14:40:12.661715830 +0100
  20265. @@ -0,0 +1,492 @@
  20266. +/*****************************************************************************
  20267. +* Copyright 2011-2012 Broadcom Corporation. All rights reserved.
  20268. +*
  20269. +* Unless you and Broadcom execute a separate written software license
  20270. +* agreement governing use of this software, this software is licensed to you
  20271. +* under the terms of the GNU General Public License version 2, available at
  20272. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  20273. +*
  20274. +* Notwithstanding the above, under no circumstances may you combine this
  20275. +* software in any way with any other Broadcom software provided under a
  20276. +* license other than the GPL, without Broadcom's express prior written
  20277. +* consent.
  20278. +*****************************************************************************/
  20279. +
  20280. +/* ---- Include Files ----------------------------------------------------- */
  20281. +#include <linux/types.h>
  20282. +#include <linux/kernel.h>
  20283. +#include <linux/list.h>
  20284. +#include <linux/semaphore.h>
  20285. +#include <linux/mutex.h>
  20286. +#include <linux/slab.h>
  20287. +#include <linux/kthread.h>
  20288. +
  20289. +#include "vc_vchi_sm.h"
  20290. +
  20291. +#define VC_SM_VER 1
  20292. +#define VC_SM_MIN_VER 0
  20293. +
  20294. +/* ---- Private Constants and Types -------------------------------------- */
  20295. +
  20296. +/* Command blocks come from a pool */
  20297. +#define SM_MAX_NUM_CMD_RSP_BLKS 32
  20298. +
  20299. +struct sm_cmd_rsp_blk {
  20300. + struct list_head head; /* To create lists */
  20301. + struct semaphore sema; /* To be signaled when the response is there */
  20302. +
  20303. + uint16_t id;
  20304. + uint16_t length;
  20305. +
  20306. + uint8_t msg[VC_SM_MAX_MSG_LEN];
  20307. +
  20308. + uint32_t wait:1;
  20309. + uint32_t sent:1;
  20310. + uint32_t alloc:1;
  20311. +
  20312. +};
  20313. +
  20314. +struct sm_instance {
  20315. + uint32_t num_connections;
  20316. + VCHI_SERVICE_HANDLE_T vchi_handle[VCHI_MAX_NUM_CONNECTIONS];
  20317. + struct task_struct *io_thread;
  20318. + struct semaphore io_sema;
  20319. +
  20320. + uint32_t trans_id;
  20321. +
  20322. + struct mutex lock;
  20323. + struct list_head cmd_list;
  20324. + struct list_head rsp_list;
  20325. + struct list_head dead_list;
  20326. +
  20327. + struct sm_cmd_rsp_blk free_blk[SM_MAX_NUM_CMD_RSP_BLKS];
  20328. + struct list_head free_list;
  20329. + struct mutex free_lock;
  20330. + struct semaphore free_sema;
  20331. +
  20332. +};
  20333. +
  20334. +/* ---- Private Variables ------------------------------------------------ */
  20335. +
  20336. +/* ---- Private Function Prototypes -------------------------------------- */
  20337. +
  20338. +/* ---- Private Functions ------------------------------------------------ */
  20339. +static struct
  20340. +sm_cmd_rsp_blk *vc_vchi_cmd_create(struct sm_instance *instance,
  20341. + VC_SM_MSG_TYPE id, void *msg,
  20342. + uint32_t size, int wait)
  20343. +{
  20344. + struct sm_cmd_rsp_blk *blk;
  20345. + VC_SM_MSG_HDR_T *hdr;
  20346. +
  20347. + if (down_interruptible(&instance->free_sema)) {
  20348. + blk = kmalloc(sizeof(*blk), GFP_KERNEL);
  20349. + if (!blk)
  20350. + return NULL;
  20351. +
  20352. + blk->alloc = 1;
  20353. + sema_init(&blk->sema, 0);
  20354. + } else {
  20355. + mutex_lock(&instance->free_lock);
  20356. + blk =
  20357. + list_first_entry(&instance->free_list,
  20358. + struct sm_cmd_rsp_blk, head);
  20359. + list_del(&blk->head);
  20360. + mutex_unlock(&instance->free_lock);
  20361. + }
  20362. +
  20363. + blk->sent = 0;
  20364. + blk->wait = wait;
  20365. + blk->length = sizeof(*hdr) + size;
  20366. +
  20367. + hdr = (VC_SM_MSG_HDR_T *) blk->msg;
  20368. + hdr->type = id;
  20369. + mutex_lock(&instance->lock);
  20370. + hdr->trans_id = blk->id = ++instance->trans_id;
  20371. + mutex_unlock(&instance->lock);
  20372. +
  20373. + if (size)
  20374. + memcpy(hdr->body, msg, size);
  20375. +
  20376. + return blk;
  20377. +}
  20378. +
  20379. +static void
  20380. +vc_vchi_cmd_delete(struct sm_instance *instance, struct sm_cmd_rsp_blk *blk)
  20381. +{
  20382. + if (blk->alloc) {
  20383. + kfree(blk);
  20384. + return;
  20385. + }
  20386. +
  20387. + mutex_lock(&instance->free_lock);
  20388. + list_add(&blk->head, &instance->free_list);
  20389. + mutex_unlock(&instance->free_lock);
  20390. + up(&instance->free_sema);
  20391. +}
  20392. +
  20393. +static int vc_vchi_sm_videocore_io(void *arg)
  20394. +{
  20395. + struct sm_instance *instance = arg;
  20396. + struct sm_cmd_rsp_blk *cmd = NULL, *cmd_tmp;
  20397. + VC_SM_RESULT_T *reply;
  20398. + uint32_t reply_len;
  20399. + int32_t status;
  20400. + int svc_use = 1;
  20401. +
  20402. + while (1) {
  20403. + if (svc_use)
  20404. + vchi_service_release(instance->vchi_handle[0]);
  20405. + svc_use = 0;
  20406. + if (!down_interruptible(&instance->io_sema)) {
  20407. + vchi_service_use(instance->vchi_handle[0]);
  20408. + svc_use = 1;
  20409. +
  20410. + do {
  20411. + unsigned int flags;
  20412. + /*
  20413. + * Get new command and move it to response list
  20414. + */
  20415. + mutex_lock(&instance->lock);
  20416. + if (list_empty(&instance->cmd_list)) {
  20417. + /* no more commands to process */
  20418. + mutex_unlock(&instance->lock);
  20419. + break;
  20420. + }
  20421. + cmd =
  20422. + list_first_entry(&instance->cmd_list,
  20423. + struct sm_cmd_rsp_blk,
  20424. + head);
  20425. + list_move(&cmd->head, &instance->rsp_list);
  20426. + cmd->sent = 1;
  20427. + mutex_unlock(&instance->lock);
  20428. +
  20429. + /* Send the command */
  20430. + flags = VCHI_FLAGS_BLOCK_UNTIL_QUEUED;
  20431. + status = vchi_msg_queue(
  20432. + instance->vchi_handle[0],
  20433. + cmd->msg, cmd->length,
  20434. + flags, NULL);
  20435. + if (status) {
  20436. + pr_err("%s: failed to queue message (%d)",
  20437. + __func__, status);
  20438. + }
  20439. +
  20440. + /* If no reply is needed then we're done */
  20441. + if (!cmd->wait) {
  20442. + mutex_lock(&instance->lock);
  20443. + list_del(&cmd->head);
  20444. + mutex_unlock(&instance->lock);
  20445. + vc_vchi_cmd_delete(instance, cmd);
  20446. + continue;
  20447. + }
  20448. +
  20449. + if (status) {
  20450. + up(&cmd->sema);
  20451. + continue;
  20452. + }
  20453. +
  20454. + } while (1);
  20455. +
  20456. + while (!vchi_msg_peek
  20457. + (instance->vchi_handle[0], (void **)&reply,
  20458. + &reply_len, VCHI_FLAGS_NONE)) {
  20459. + mutex_lock(&instance->lock);
  20460. + list_for_each_entry(cmd, &instance->rsp_list,
  20461. + head) {
  20462. + if (cmd->id == reply->trans_id)
  20463. + break;
  20464. + }
  20465. + mutex_unlock(&instance->lock);
  20466. +
  20467. + if (&cmd->head == &instance->rsp_list) {
  20468. + pr_debug("%s: received response %u, throw away...",
  20469. + __func__, reply->trans_id);
  20470. + } else if (reply_len > sizeof(cmd->msg)) {
  20471. + pr_err("%s: reply too big (%u) %u, throw away...",
  20472. + __func__, reply_len,
  20473. + reply->trans_id);
  20474. + } else {
  20475. + memcpy(cmd->msg, reply, reply_len);
  20476. + up(&cmd->sema);
  20477. + }
  20478. +
  20479. + vchi_msg_remove(instance->vchi_handle[0]);
  20480. + }
  20481. +
  20482. + /* Go through the dead list and free them */
  20483. + mutex_lock(&instance->lock);
  20484. + list_for_each_entry_safe(cmd, cmd_tmp,
  20485. + &instance->dead_list, head) {
  20486. + list_del(&cmd->head);
  20487. + vc_vchi_cmd_delete(instance, cmd);
  20488. + }
  20489. + mutex_unlock(&instance->lock);
  20490. + }
  20491. + }
  20492. +
  20493. + return 0;
  20494. +}
  20495. +
  20496. +static void vc_sm_vchi_callback(void *param,
  20497. + const VCHI_CALLBACK_REASON_T reason,
  20498. + void *msg_handle)
  20499. +{
  20500. + struct sm_instance *instance = param;
  20501. +
  20502. + (void)msg_handle;
  20503. +
  20504. + switch (reason) {
  20505. + case VCHI_CALLBACK_MSG_AVAILABLE:
  20506. + up(&instance->io_sema);
  20507. + break;
  20508. +
  20509. + case VCHI_CALLBACK_SERVICE_CLOSED:
  20510. + pr_info("%s: service CLOSED!!", __func__);
  20511. + default:
  20512. + break;
  20513. + }
  20514. +}
  20515. +
  20516. +VC_VCHI_SM_HANDLE_T vc_vchi_sm_init(VCHI_INSTANCE_T vchi_instance,
  20517. + VCHI_CONNECTION_T **vchi_connections,
  20518. + uint32_t num_connections)
  20519. +{
  20520. + uint32_t i;
  20521. + struct sm_instance *instance;
  20522. + int status;
  20523. +
  20524. + pr_debug("%s: start", __func__);
  20525. +
  20526. + if (num_connections > VCHI_MAX_NUM_CONNECTIONS) {
  20527. + pr_err("%s: unsupported number of connections %u (max=%u)",
  20528. + __func__, num_connections, VCHI_MAX_NUM_CONNECTIONS);
  20529. +
  20530. + goto err_null;
  20531. + }
  20532. + /* Allocate memory for this instance */
  20533. + instance = kzalloc(sizeof(*instance), GFP_KERNEL);
  20534. +
  20535. + /* Misc initialisations */
  20536. + mutex_init(&instance->lock);
  20537. + sema_init(&instance->io_sema, 0);
  20538. + INIT_LIST_HEAD(&instance->cmd_list);
  20539. + INIT_LIST_HEAD(&instance->rsp_list);
  20540. + INIT_LIST_HEAD(&instance->dead_list);
  20541. + INIT_LIST_HEAD(&instance->free_list);
  20542. + sema_init(&instance->free_sema, SM_MAX_NUM_CMD_RSP_BLKS);
  20543. + mutex_init(&instance->free_lock);
  20544. + for (i = 0; i < SM_MAX_NUM_CMD_RSP_BLKS; i++) {
  20545. + sema_init(&instance->free_blk[i].sema, 0);
  20546. + list_add(&instance->free_blk[i].head, &instance->free_list);
  20547. + }
  20548. +
  20549. + /* Open the VCHI service connections */
  20550. + instance->num_connections = num_connections;
  20551. + for (i = 0; i < num_connections; i++) {
  20552. + SERVICE_CREATION_T params = {
  20553. + VCHI_VERSION_EX(VC_SM_VER, VC_SM_MIN_VER),
  20554. + VC_SM_SERVER_NAME,
  20555. + vchi_connections[i],
  20556. + 0,
  20557. + 0,
  20558. + vc_sm_vchi_callback,
  20559. + instance,
  20560. + 0,
  20561. + 0,
  20562. + 0,
  20563. + };
  20564. +
  20565. + status = vchi_service_open(vchi_instance,
  20566. + &params, &instance->vchi_handle[i]);
  20567. + if (status) {
  20568. + pr_err("%s: failed to open VCHI service (%d)",
  20569. + __func__, status);
  20570. +
  20571. + goto err_close_services;
  20572. + }
  20573. + }
  20574. +
  20575. + /* Create the thread which takes care of all io to/from videoocore. */
  20576. + instance->io_thread = kthread_create(&vc_vchi_sm_videocore_io,
  20577. + (void *)instance, "SMIO");
  20578. + if (instance->io_thread == NULL) {
  20579. + pr_err("%s: failed to create SMIO thread", __func__);
  20580. +
  20581. + goto err_close_services;
  20582. + }
  20583. + set_user_nice(instance->io_thread, -10);
  20584. + wake_up_process(instance->io_thread);
  20585. +
  20586. + pr_debug("%s: success - instance 0x%x", __func__, (unsigned)instance);
  20587. + return instance;
  20588. +
  20589. +err_close_services:
  20590. + for (i = 0; i < instance->num_connections; i++) {
  20591. + if (instance->vchi_handle[i] != NULL)
  20592. + vchi_service_close(instance->vchi_handle[i]);
  20593. + }
  20594. + kfree(instance);
  20595. +err_null:
  20596. + pr_debug("%s: FAILED", __func__);
  20597. + return NULL;
  20598. +}
  20599. +
  20600. +int vc_vchi_sm_stop(VC_VCHI_SM_HANDLE_T *handle)
  20601. +{
  20602. + struct sm_instance *instance;
  20603. + uint32_t i;
  20604. +
  20605. + if (handle == NULL) {
  20606. + pr_err("%s: invalid pointer to handle %p", __func__, handle);
  20607. + goto lock;
  20608. + }
  20609. +
  20610. + if (*handle == NULL) {
  20611. + pr_err("%s: invalid handle %p", __func__, *handle);
  20612. + goto lock;
  20613. + }
  20614. +
  20615. + instance = *handle;
  20616. +
  20617. + /* Close all VCHI service connections */
  20618. + for (i = 0; i < instance->num_connections; i++) {
  20619. + int32_t success;
  20620. + vchi_service_use(instance->vchi_handle[i]);
  20621. +
  20622. + success = vchi_service_close(instance->vchi_handle[i]);
  20623. + }
  20624. +
  20625. + kfree(instance);
  20626. +
  20627. + *handle = NULL;
  20628. + return 0;
  20629. +
  20630. +lock:
  20631. + return -EINVAL;
  20632. +}
  20633. +
  20634. +int vc_vchi_sm_send_msg(VC_VCHI_SM_HANDLE_T handle,
  20635. + VC_SM_MSG_TYPE msg_id,
  20636. + void *msg, uint32_t msg_size,
  20637. + void *result, uint32_t result_size,
  20638. + uint32_t *cur_trans_id, uint8_t wait_reply)
  20639. +{
  20640. + int status = 0;
  20641. + struct sm_instance *instance = handle;
  20642. + struct sm_cmd_rsp_blk *cmd_blk;
  20643. +
  20644. + if (handle == NULL) {
  20645. + pr_err("%s: invalid handle", __func__);
  20646. + return -EINVAL;
  20647. + }
  20648. + if (msg == NULL) {
  20649. + pr_err("%s: invalid msg pointer", __func__);
  20650. + return -EINVAL;
  20651. + }
  20652. +
  20653. + cmd_blk =
  20654. + vc_vchi_cmd_create(instance, msg_id, msg, msg_size, wait_reply);
  20655. + if (cmd_blk == NULL) {
  20656. + pr_err("[%s]: failed to allocate global tracking resource",
  20657. + __func__);
  20658. + return -ENOMEM;
  20659. + }
  20660. +
  20661. + if (cur_trans_id != NULL)
  20662. + *cur_trans_id = cmd_blk->id;
  20663. +
  20664. + mutex_lock(&instance->lock);
  20665. + list_add_tail(&cmd_blk->head, &instance->cmd_list);
  20666. + mutex_unlock(&instance->lock);
  20667. + up(&instance->io_sema);
  20668. +
  20669. + if (!wait_reply)
  20670. + /* We're done */
  20671. + return 0;
  20672. +
  20673. + /* Wait for the response */
  20674. + if (down_interruptible(&cmd_blk->sema)) {
  20675. + mutex_lock(&instance->lock);
  20676. + if (!cmd_blk->sent) {
  20677. + list_del(&cmd_blk->head);
  20678. + mutex_unlock(&instance->lock);
  20679. + vc_vchi_cmd_delete(instance, cmd_blk);
  20680. + return -ENXIO;
  20681. + }
  20682. + mutex_unlock(&instance->lock);
  20683. +
  20684. + mutex_lock(&instance->lock);
  20685. + list_move(&cmd_blk->head, &instance->dead_list);
  20686. + mutex_unlock(&instance->lock);
  20687. + up(&instance->io_sema);
  20688. + return -EINTR; /* We're done */
  20689. + }
  20690. +
  20691. + if (result && result_size) {
  20692. + memcpy(result, cmd_blk->msg, result_size);
  20693. + } else {
  20694. + VC_SM_RESULT_T *res = (VC_SM_RESULT_T *) cmd_blk->msg;
  20695. + status = (res->success == 0) ? 0 : -ENXIO;
  20696. + }
  20697. +
  20698. + mutex_lock(&instance->lock);
  20699. + list_del(&cmd_blk->head);
  20700. + mutex_unlock(&instance->lock);
  20701. + vc_vchi_cmd_delete(instance, cmd_blk);
  20702. + return status;
  20703. +}
  20704. +
  20705. +int vc_vchi_sm_alloc(VC_VCHI_SM_HANDLE_T handle, VC_SM_ALLOC_T *msg,
  20706. + VC_SM_ALLOC_RESULT_T *result, uint32_t *cur_trans_id)
  20707. +{
  20708. + return vc_vchi_sm_send_msg(handle, VC_SM_MSG_TYPE_ALLOC,
  20709. + msg, sizeof(*msg), result, sizeof(*result),
  20710. + cur_trans_id, 1);
  20711. +}
  20712. +
  20713. +int vc_vchi_sm_free(VC_VCHI_SM_HANDLE_T handle,
  20714. + VC_SM_FREE_T *msg, uint32_t *cur_trans_id)
  20715. +{
  20716. + return vc_vchi_sm_send_msg(handle, VC_SM_MSG_TYPE_FREE,
  20717. + msg, sizeof(*msg), 0, 0, cur_trans_id, 0);
  20718. +}
  20719. +
  20720. +int vc_vchi_sm_lock(VC_VCHI_SM_HANDLE_T handle,
  20721. + VC_SM_LOCK_UNLOCK_T *msg,
  20722. + VC_SM_LOCK_RESULT_T *result, uint32_t *cur_trans_id)
  20723. +{
  20724. + return vc_vchi_sm_send_msg(handle, VC_SM_MSG_TYPE_LOCK,
  20725. + msg, sizeof(*msg), result, sizeof(*result),
  20726. + cur_trans_id, 1);
  20727. +}
  20728. +
  20729. +int vc_vchi_sm_unlock(VC_VCHI_SM_HANDLE_T handle,
  20730. + VC_SM_LOCK_UNLOCK_T *msg,
  20731. + uint32_t *cur_trans_id, uint8_t wait_reply)
  20732. +{
  20733. + return vc_vchi_sm_send_msg(handle, wait_reply ?
  20734. + VC_SM_MSG_TYPE_UNLOCK :
  20735. + VC_SM_MSG_TYPE_UNLOCK_NOANS, msg,
  20736. + sizeof(*msg), 0, 0, cur_trans_id,
  20737. + wait_reply);
  20738. +}
  20739. +
  20740. +int vc_vchi_sm_resize(VC_VCHI_SM_HANDLE_T handle, VC_SM_RESIZE_T *msg,
  20741. + uint32_t *cur_trans_id)
  20742. +{
  20743. + return vc_vchi_sm_send_msg(handle, VC_SM_MSG_TYPE_RESIZE,
  20744. + msg, sizeof(*msg), 0, 0, cur_trans_id, 1);
  20745. +}
  20746. +
  20747. +int vc_vchi_sm_walk_alloc(VC_VCHI_SM_HANDLE_T handle)
  20748. +{
  20749. + return vc_vchi_sm_send_msg(handle, VC_SM_MSG_TYPE_WALK_ALLOC,
  20750. + 0, 0, 0, 0, 0, 0);
  20751. +}
  20752. +
  20753. +int vc_vchi_sm_clean_up(VC_VCHI_SM_HANDLE_T handle, VC_SM_ACTION_CLEAN_T *msg)
  20754. +{
  20755. + return vc_vchi_sm_send_msg(handle, VC_SM_MSG_TYPE_ACTION_CLEAN,
  20756. + msg, sizeof(*msg), 0, 0, 0, 0);
  20757. +}
  20758. diff -Nur linux-3.18.8/drivers/char/broadcom/vc_sm/vmcs_sm.c linux-rpi/drivers/char/broadcom/vc_sm/vmcs_sm.c
  20759. --- linux-3.18.8/drivers/char/broadcom/vc_sm/vmcs_sm.c 1970-01-01 01:00:00.000000000 +0100
  20760. +++ linux-rpi/drivers/char/broadcom/vc_sm/vmcs_sm.c 2015-03-05 14:40:12.661715830 +0100
  20761. @@ -0,0 +1,3163 @@
  20762. +/*****************************************************************************
  20763. +* Copyright 2011-2012 Broadcom Corporation. All rights reserved.
  20764. +*
  20765. +* Unless you and Broadcom execute a separate written software license
  20766. +* agreement governing use of this software, this software is licensed to you
  20767. +* under the terms of the GNU General Public License version 2, available at
  20768. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  20769. +*
  20770. +* Notwithstanding the above, under no circumstances may you combine this
  20771. +* software in any way with any other Broadcom software provided under a
  20772. +* license other than the GPL, without Broadcom's express prior written
  20773. +* consent.
  20774. +*****************************************************************************/
  20775. +
  20776. +/* ---- Include Files ----------------------------------------------------- */
  20777. +
  20778. +#include <linux/cdev.h>
  20779. +#include <linux/device.h>
  20780. +#include <linux/debugfs.h>
  20781. +#include <linux/dma-mapping.h>
  20782. +#include <linux/errno.h>
  20783. +#include <linux/fs.h>
  20784. +#include <linux/hugetlb.h>
  20785. +#include <linux/ioctl.h>
  20786. +#include <linux/kernel.h>
  20787. +#include <linux/list.h>
  20788. +#include <linux/module.h>
  20789. +#include <linux/mm.h>
  20790. +#include <linux/pfn.h>
  20791. +#include <linux/proc_fs.h>
  20792. +#include <linux/pagemap.h>
  20793. +#include <linux/semaphore.h>
  20794. +#include <linux/slab.h>
  20795. +#include <linux/seq_file.h>
  20796. +#include <linux/types.h>
  20797. +#include <asm/cacheflush.h>
  20798. +
  20799. +#include <vc_mem.h>
  20800. +
  20801. +#include "vchiq_connected.h"
  20802. +#include "vc_vchi_sm.h"
  20803. +
  20804. +#include <vmcs_sm_ioctl.h>
  20805. +#include "vc_sm_knl.h"
  20806. +
  20807. +/* ---- Private Constants and Types --------------------------------------- */
  20808. +
  20809. +#define DEVICE_NAME "vcsm"
  20810. +#define DEVICE_MINOR 0
  20811. +
  20812. +#define VC_SM_DIR_ROOT_NAME "vc-smem"
  20813. +#define VC_SM_DIR_ALLOC_NAME "alloc"
  20814. +#define VC_SM_STATE "state"
  20815. +#define VC_SM_STATS "statistics"
  20816. +#define VC_SM_RESOURCES "resources"
  20817. +#define VC_SM_DEBUG "debug"
  20818. +#define VC_SM_WRITE_BUF_SIZE 128
  20819. +
  20820. +/* Statistics tracked per resource and globally.
  20821. +*/
  20822. +enum SM_STATS_T {
  20823. + /* Attempt. */
  20824. + ALLOC,
  20825. + FREE,
  20826. + LOCK,
  20827. + UNLOCK,
  20828. + MAP,
  20829. + FLUSH,
  20830. + INVALID,
  20831. +
  20832. + END_ATTEMPT,
  20833. +
  20834. + /* Failure. */
  20835. + ALLOC_FAIL,
  20836. + FREE_FAIL,
  20837. + LOCK_FAIL,
  20838. + UNLOCK_FAIL,
  20839. + MAP_FAIL,
  20840. + FLUSH_FAIL,
  20841. + INVALID_FAIL,
  20842. +
  20843. + END_ALL,
  20844. +
  20845. +};
  20846. +
  20847. +static const char *const sm_stats_human_read[] = {
  20848. + "Alloc",
  20849. + "Free",
  20850. + "Lock",
  20851. + "Unlock",
  20852. + "Map",
  20853. + "Cache Flush",
  20854. + "Cache Invalidate",
  20855. +};
  20856. +
  20857. +typedef int (*VC_SM_SHOW) (struct seq_file *s, void *v);
  20858. +struct SM_PDE_T {
  20859. + VC_SM_SHOW show; /* Debug fs function hookup. */
  20860. + struct dentry *dir_entry; /* Debug fs directory entry. */
  20861. + void *priv_data; /* Private data */
  20862. +
  20863. +};
  20864. +
  20865. +/* Single resource allocation tracked for all devices.
  20866. +*/
  20867. +struct sm_mmap {
  20868. + struct list_head map_list; /* Linked list of maps. */
  20869. +
  20870. + struct SM_RESOURCE_T *resource; /* Pointer to the resource. */
  20871. +
  20872. + pid_t res_pid; /* PID owning that resource. */
  20873. + unsigned int res_vc_hdl; /* Resource handle (videocore). */
  20874. + unsigned int res_usr_hdl; /* Resource handle (user). */
  20875. +
  20876. + long unsigned int res_addr; /* Mapped virtual address. */
  20877. + struct vm_area_struct *vma; /* VM area for this mapping. */
  20878. + unsigned int ref_count; /* Reference count to this vma. */
  20879. +
  20880. + /* Used to link maps associated with a resource. */
  20881. + struct list_head resource_map_list;
  20882. +};
  20883. +
  20884. +/* Single resource allocation tracked for each opened device.
  20885. +*/
  20886. +struct SM_RESOURCE_T {
  20887. + struct list_head resource_list; /* List of resources. */
  20888. + struct list_head global_resource_list; /* Global list of resources. */
  20889. +
  20890. + pid_t pid; /* PID owning that resource. */
  20891. + uint32_t res_guid; /* Unique identifier. */
  20892. + uint32_t lock_count; /* Lock count for this resource. */
  20893. + uint32_t ref_count; /* Ref count for this resource. */
  20894. +
  20895. + uint32_t res_handle; /* Resource allocation handle. */
  20896. + void *res_base_mem; /* Resource base memory address. */
  20897. + uint32_t res_size; /* Resource size allocated. */
  20898. + enum vmcs_sm_cache_e res_cached; /* Resource cache type. */
  20899. + struct SM_RESOURCE_T *res_shared; /* Shared resource */
  20900. +
  20901. + enum SM_STATS_T res_stats[END_ALL]; /* Resource statistics. */
  20902. +
  20903. + uint8_t map_count; /* Counter of mappings for this resource. */
  20904. + struct list_head map_list; /* Maps associated with a resource. */
  20905. +
  20906. + struct SM_PRIV_DATA_T *private;
  20907. +};
  20908. +
  20909. +/* Private file data associated with each opened device.
  20910. +*/
  20911. +struct SM_PRIV_DATA_T {
  20912. + struct list_head resource_list; /* List of resources. */
  20913. +
  20914. + pid_t pid; /* PID of creator. */
  20915. +
  20916. + struct dentry *dir_pid; /* Debug fs entries root. */
  20917. + struct SM_PDE_T dir_stats; /* Debug fs entries statistics sub-tree. */
  20918. + struct SM_PDE_T dir_res; /* Debug fs resource sub-tree. */
  20919. +
  20920. + int restart_sys; /* Tracks restart on interrupt. */
  20921. + VC_SM_MSG_TYPE int_action; /* Interrupted action. */
  20922. + uint32_t int_trans_id; /* Interrupted transaction. */
  20923. +
  20924. +};
  20925. +
  20926. +/* Global state information.
  20927. +*/
  20928. +struct SM_STATE_T {
  20929. + VC_VCHI_SM_HANDLE_T sm_handle; /* Handle for videocore service. */
  20930. + struct dentry *dir_root; /* Debug fs entries root. */
  20931. + struct dentry *dir_alloc; /* Debug fs entries allocations. */
  20932. + struct SM_PDE_T dir_stats; /* Debug fs entries statistics sub-tree. */
  20933. + struct SM_PDE_T dir_state; /* Debug fs entries state sub-tree. */
  20934. + struct dentry *debug; /* Debug fs entries debug. */
  20935. +
  20936. + struct mutex map_lock; /* Global map lock. */
  20937. + struct list_head map_list; /* List of maps. */
  20938. + struct list_head resource_list; /* List of resources. */
  20939. +
  20940. + enum SM_STATS_T deceased[END_ALL]; /* Natural termination stats. */
  20941. + enum SM_STATS_T terminated[END_ALL]; /* Forced termination stats. */
  20942. + uint32_t res_deceased_cnt; /* Natural termination counter. */
  20943. + uint32_t res_terminated_cnt; /* Forced termination counter. */
  20944. +
  20945. + struct cdev sm_cdev; /* Device. */
  20946. + dev_t sm_devid; /* Device identifier. */
  20947. + struct class *sm_class; /* Class. */
  20948. + struct device *sm_dev; /* Device. */
  20949. +
  20950. + struct SM_PRIV_DATA_T *data_knl; /* Kernel internal data tracking. */
  20951. +
  20952. + struct mutex lock; /* Global lock. */
  20953. + uint32_t guid; /* GUID (next) tracker. */
  20954. +
  20955. +};
  20956. +
  20957. +/* ---- Private Variables ----------------------------------------------- */
  20958. +
  20959. +static struct SM_STATE_T *sm_state;
  20960. +static int sm_inited;
  20961. +
  20962. +static const char *const sm_cache_map_vector[] = {
  20963. + "(null)",
  20964. + "host",
  20965. + "videocore",
  20966. + "host+videocore",
  20967. +};
  20968. +
  20969. +/* ---- Private Function Prototypes -------------------------------------- */
  20970. +
  20971. +/* ---- Private Functions ------------------------------------------------ */
  20972. +
  20973. +static inline unsigned vcaddr_to_pfn(unsigned long vc_addr)
  20974. +{
  20975. + unsigned long pfn = vc_addr & 0x3FFFFFFF;
  20976. + pfn += mm_vc_mem_phys_addr;
  20977. + pfn >>= PAGE_SHIFT;
  20978. + return pfn;
  20979. +}
  20980. +
  20981. +/* Carries over to the state statistics the statistics once owned by a deceased
  20982. +** resource.
  20983. +*/
  20984. +static void vc_sm_resource_deceased(struct SM_RESOURCE_T *p_res, int terminated)
  20985. +{
  20986. + if (sm_state != NULL) {
  20987. + if (p_res != NULL) {
  20988. + int ix;
  20989. +
  20990. + if (terminated)
  20991. + sm_state->res_terminated_cnt++;
  20992. + else
  20993. + sm_state->res_deceased_cnt++;
  20994. +
  20995. + for (ix = 0; ix < END_ALL; ix++) {
  20996. + if (terminated)
  20997. + sm_state->terminated[ix] +=
  20998. + p_res->res_stats[ix];
  20999. + else
  21000. + sm_state->deceased[ix] +=
  21001. + p_res->res_stats[ix];
  21002. + }
  21003. + }
  21004. + }
  21005. +}
  21006. +
  21007. +/* Fetch a videocore handle corresponding to a mapping of the pid+address
  21008. +** returns 0 (ie NULL) if no such handle exists in the global map.
  21009. +*/
  21010. +static unsigned int vmcs_sm_vc_handle_from_pid_and_address(unsigned int pid,
  21011. + unsigned int addr)
  21012. +{
  21013. + struct sm_mmap *map = NULL;
  21014. + unsigned int handle = 0;
  21015. +
  21016. + if (!sm_state || addr == 0)
  21017. + goto out;
  21018. +
  21019. + mutex_lock(&(sm_state->map_lock));
  21020. +
  21021. + /* Lookup the resource.
  21022. + */
  21023. + if (!list_empty(&sm_state->map_list)) {
  21024. + list_for_each_entry(map, &sm_state->map_list, map_list) {
  21025. + if (map->res_pid != pid || map->res_addr != addr)
  21026. + continue;
  21027. +
  21028. + pr_debug("[%s]: global map %p (pid %u, addr %lx) -> vc-hdl %x (usr-hdl %x)\n",
  21029. + __func__, map, map->res_pid, map->res_addr,
  21030. + map->res_vc_hdl, map->res_usr_hdl);
  21031. +
  21032. + handle = map->res_vc_hdl;
  21033. + break;
  21034. + }
  21035. + }
  21036. +
  21037. + mutex_unlock(&(sm_state->map_lock));
  21038. +
  21039. +out:
  21040. + /* Use a debug log here as it may be a valid situation that we query
  21041. + ** for something that is not mapped, we do not want a kernel log each
  21042. + ** time around.
  21043. + **
  21044. + ** There are other error log that would pop up accordingly if someone
  21045. + ** subsequently tries to use something invalid after being told not to
  21046. + ** use it...
  21047. + */
  21048. + if (handle == 0) {
  21049. + pr_debug("[%s]: not a valid map (pid %u, addr %x)\n",
  21050. + __func__, pid, addr);
  21051. + }
  21052. +
  21053. + return handle;
  21054. +}
  21055. +
  21056. +/* Fetch a user handle corresponding to a mapping of the pid+address
  21057. +** returns 0 (ie NULL) if no such handle exists in the global map.
  21058. +*/
  21059. +static unsigned int vmcs_sm_usr_handle_from_pid_and_address(unsigned int pid,
  21060. + unsigned int addr)
  21061. +{
  21062. + struct sm_mmap *map = NULL;
  21063. + unsigned int handle = 0;
  21064. +
  21065. + if (!sm_state || addr == 0)
  21066. + goto out;
  21067. +
  21068. + mutex_lock(&(sm_state->map_lock));
  21069. +
  21070. + /* Lookup the resource.
  21071. + */
  21072. + if (!list_empty(&sm_state->map_list)) {
  21073. + list_for_each_entry(map, &sm_state->map_list, map_list) {
  21074. + if (map->res_pid != pid || map->res_addr != addr)
  21075. + continue;
  21076. +
  21077. + pr_debug("[%s]: global map %p (pid %u, addr %lx) -> usr-hdl %x (vc-hdl %x)\n",
  21078. + __func__, map, map->res_pid, map->res_addr,
  21079. + map->res_usr_hdl, map->res_vc_hdl);
  21080. +
  21081. + handle = map->res_usr_hdl;
  21082. + break;
  21083. + }
  21084. + }
  21085. +
  21086. + mutex_unlock(&(sm_state->map_lock));
  21087. +
  21088. +out:
  21089. + /* Use a debug log here as it may be a valid situation that we query
  21090. + * for something that is not mapped yet.
  21091. + *
  21092. + * There are other error log that would pop up accordingly if someone
  21093. + * subsequently tries to use something invalid after being told not to
  21094. + * use it...
  21095. + */
  21096. + if (handle == 0)
  21097. + pr_debug("[%s]: not a valid map (pid %u, addr %x)\n",
  21098. + __func__, pid, addr);
  21099. +
  21100. + return handle;
  21101. +}
  21102. +
  21103. +#if defined(DO_NOT_USE)
  21104. +/* Fetch an address corresponding to a mapping of the pid+handle
  21105. +** returns 0 (ie NULL) if no such address exists in the global map.
  21106. +*/
  21107. +static unsigned int vmcs_sm_usr_address_from_pid_and_vc_handle(unsigned int pid,
  21108. + unsigned int hdl)
  21109. +{
  21110. + struct sm_mmap *map = NULL;
  21111. + unsigned int addr = 0;
  21112. +
  21113. + if (sm_state == NULL || hdl == 0)
  21114. + goto out;
  21115. +
  21116. + mutex_lock(&(sm_state->map_lock));
  21117. +
  21118. + /* Lookup the resource.
  21119. + */
  21120. + if (!list_empty(&sm_state->map_list)) {
  21121. + list_for_each_entry(map, &sm_state->map_list, map_list) {
  21122. + if (map->res_pid != pid || map->res_vc_hdl != hdl)
  21123. + continue;
  21124. +
  21125. + pr_debug("[%s]: global map %p (pid %u, vc-hdl %x, usr-hdl %x) -> addr %lx\n",
  21126. + __func__, map, map->res_pid, map->res_vc_hdl,
  21127. + map->res_usr_hdl, map->res_addr);
  21128. +
  21129. + addr = map->res_addr;
  21130. + break;
  21131. + }
  21132. + }
  21133. +
  21134. + mutex_unlock(&(sm_state->map_lock));
  21135. +
  21136. +out:
  21137. + /* Use a debug log here as it may be a valid situation that we query
  21138. + ** for something that is not mapped, we do not want a kernel log each
  21139. + ** time around.
  21140. + **
  21141. + ** There are other error log that would pop up accordingly if someone
  21142. + ** subsequently tries to use something invalid after being told not to
  21143. + ** use it...
  21144. + */
  21145. + if (addr == 0)
  21146. + pr_debug("[%s]: not a valid map (pid %u, hdl %x)\n",
  21147. + __func__, pid, hdl);
  21148. +
  21149. + return addr;
  21150. +}
  21151. +#endif
  21152. +
  21153. +/* Fetch an address corresponding to a mapping of the pid+handle
  21154. +** returns 0 (ie NULL) if no such address exists in the global map.
  21155. +*/
  21156. +static unsigned int vmcs_sm_usr_address_from_pid_and_usr_handle(unsigned int
  21157. + pid,
  21158. + unsigned int
  21159. + hdl)
  21160. +{
  21161. + struct sm_mmap *map = NULL;
  21162. + unsigned int addr = 0;
  21163. +
  21164. + if (sm_state == NULL || hdl == 0)
  21165. + goto out;
  21166. +
  21167. + mutex_lock(&(sm_state->map_lock));
  21168. +
  21169. + /* Lookup the resource.
  21170. + */
  21171. + if (!list_empty(&sm_state->map_list)) {
  21172. + list_for_each_entry(map, &sm_state->map_list, map_list) {
  21173. + if (map->res_pid != pid || map->res_usr_hdl != hdl)
  21174. + continue;
  21175. +
  21176. + pr_debug("[%s]: global map %p (pid %u, vc-hdl %x, usr-hdl %x) -> addr %lx\n",
  21177. + __func__, map, map->res_pid, map->res_vc_hdl,
  21178. + map->res_usr_hdl, map->res_addr);
  21179. +
  21180. + addr = map->res_addr;
  21181. + break;
  21182. + }
  21183. + }
  21184. +
  21185. + mutex_unlock(&(sm_state->map_lock));
  21186. +
  21187. +out:
  21188. + /* Use a debug log here as it may be a valid situation that we query
  21189. + * for something that is not mapped, we do not want a kernel log each
  21190. + * time around.
  21191. + *
  21192. + * There are other error log that would pop up accordingly if someone
  21193. + * subsequently tries to use something invalid after being told not to
  21194. + * use it...
  21195. + */
  21196. + if (addr == 0)
  21197. + pr_debug("[%s]: not a valid map (pid %u, hdl %x)\n", __func__,
  21198. + pid, hdl);
  21199. +
  21200. + return addr;
  21201. +}
  21202. +
  21203. +/* Adds a resource mapping to the global data list.
  21204. +*/
  21205. +static void vmcs_sm_add_map(struct SM_STATE_T *state,
  21206. + struct SM_RESOURCE_T *resource, struct sm_mmap *map)
  21207. +{
  21208. + mutex_lock(&(state->map_lock));
  21209. +
  21210. + /* Add to the global list of mappings
  21211. + */
  21212. + list_add(&map->map_list, &state->map_list);
  21213. +
  21214. + /* Add to the list of mappings for this resource
  21215. + */
  21216. + list_add(&map->resource_map_list, &resource->map_list);
  21217. + resource->map_count++;
  21218. +
  21219. + mutex_unlock(&(state->map_lock));
  21220. +
  21221. + pr_debug("[%s]: added map %p (pid %u, vc-hdl %x, usr-hdl %x, addr %lx)\n",
  21222. + __func__, map, map->res_pid, map->res_vc_hdl,
  21223. + map->res_usr_hdl, map->res_addr);
  21224. +}
  21225. +
  21226. +/* Removes a resource mapping from the global data list.
  21227. +*/
  21228. +static void vmcs_sm_remove_map(struct SM_STATE_T *state,
  21229. + struct SM_RESOURCE_T *resource,
  21230. + struct sm_mmap *map)
  21231. +{
  21232. + mutex_lock(&(state->map_lock));
  21233. +
  21234. + /* Remove from the global list of mappings
  21235. + */
  21236. + list_del(&map->map_list);
  21237. +
  21238. + /* Remove from the list of mapping for this resource
  21239. + */
  21240. + list_del(&map->resource_map_list);
  21241. + if (resource->map_count > 0)
  21242. + resource->map_count--;
  21243. +
  21244. + mutex_unlock(&(state->map_lock));
  21245. +
  21246. + pr_debug("[%s]: removed map %p (pid %d, vc-hdl %x, usr-hdl %x, addr %lx)\n",
  21247. + __func__, map, map->res_pid, map->res_vc_hdl, map->res_usr_hdl,
  21248. + map->res_addr);
  21249. +
  21250. + kfree(map);
  21251. +}
  21252. +
  21253. +/* Read callback for the global state proc entry.
  21254. +*/
  21255. +static int vc_sm_global_state_show(struct seq_file *s, void *v)
  21256. +{
  21257. + struct sm_mmap *map = NULL;
  21258. + int map_count = 0;
  21259. +
  21260. + if (sm_state == NULL)
  21261. + return 0;
  21262. +
  21263. + seq_printf(s, "\nVC-ServiceHandle 0x%x\n",
  21264. + (unsigned int)sm_state->sm_handle);
  21265. +
  21266. + /* Log all applicable mapping(s).
  21267. + */
  21268. +
  21269. + mutex_lock(&(sm_state->map_lock));
  21270. +
  21271. + if (!list_empty(&sm_state->map_list)) {
  21272. + list_for_each_entry(map, &sm_state->map_list, map_list) {
  21273. + map_count++;
  21274. +
  21275. + seq_printf(s, "\nMapping 0x%x\n",
  21276. + (unsigned int)map);
  21277. + seq_printf(s, " TGID %u\n",
  21278. + map->res_pid);
  21279. + seq_printf(s, " VC-HDL 0x%x\n",
  21280. + map->res_vc_hdl);
  21281. + seq_printf(s, " USR-HDL 0x%x\n",
  21282. + map->res_usr_hdl);
  21283. + seq_printf(s, " USR-ADDR 0x%lx\n",
  21284. + map->res_addr);
  21285. + }
  21286. + }
  21287. +
  21288. + mutex_unlock(&(sm_state->map_lock));
  21289. + seq_printf(s, "\n\nTotal map count: %d\n\n", map_count);
  21290. +
  21291. + return 0;
  21292. +}
  21293. +
  21294. +static int vc_sm_global_statistics_show(struct seq_file *s, void *v)
  21295. +{
  21296. + int ix;
  21297. +
  21298. + /* Global state tracked statistics.
  21299. + */
  21300. + if (sm_state != NULL) {
  21301. + seq_puts(s, "\nDeceased Resources Statistics\n");
  21302. +
  21303. + seq_printf(s, "\nNatural Cause (%u occurences)\n",
  21304. + sm_state->res_deceased_cnt);
  21305. + for (ix = 0; ix < END_ATTEMPT; ix++) {
  21306. + if (sm_state->deceased[ix] > 0) {
  21307. + seq_printf(s, " %u\t%s\n",
  21308. + sm_state->deceased[ix],
  21309. + sm_stats_human_read[ix]);
  21310. + }
  21311. + }
  21312. + seq_puts(s, "\n");
  21313. + for (ix = 0; ix < END_ATTEMPT; ix++) {
  21314. + if (sm_state->deceased[ix + END_ATTEMPT] > 0) {
  21315. + seq_printf(s, " %u\tFAILED %s\n",
  21316. + sm_state->deceased[ix + END_ATTEMPT],
  21317. + sm_stats_human_read[ix]);
  21318. + }
  21319. + }
  21320. +
  21321. + seq_printf(s, "\nForcefull (%u occurences)\n",
  21322. + sm_state->res_terminated_cnt);
  21323. + for (ix = 0; ix < END_ATTEMPT; ix++) {
  21324. + if (sm_state->terminated[ix] > 0) {
  21325. + seq_printf(s, " %u\t%s\n",
  21326. + sm_state->terminated[ix],
  21327. + sm_stats_human_read[ix]);
  21328. + }
  21329. + }
  21330. + seq_puts(s, "\n");
  21331. + for (ix = 0; ix < END_ATTEMPT; ix++) {
  21332. + if (sm_state->terminated[ix + END_ATTEMPT] > 0) {
  21333. + seq_printf(s, " %u\tFAILED %s\n",
  21334. + sm_state->terminated[ix +
  21335. + END_ATTEMPT],
  21336. + sm_stats_human_read[ix]);
  21337. + }
  21338. + }
  21339. + }
  21340. +
  21341. + return 0;
  21342. +}
  21343. +
  21344. +#if 0
  21345. +/* Read callback for the statistics proc entry.
  21346. +*/
  21347. +static int vc_sm_statistics_show(struct seq_file *s, void *v)
  21348. +{
  21349. + int ix;
  21350. + struct SM_PRIV_DATA_T *file_data;
  21351. + struct SM_RESOURCE_T *resource;
  21352. + int res_count = 0;
  21353. + struct SM_PDE_T *p_pde;
  21354. +
  21355. + p_pde = (struct SM_PDE_T *)(s->private);
  21356. + file_data = (struct SM_PRIV_DATA_T *)(p_pde->priv_data);
  21357. +
  21358. + if (file_data == NULL)
  21359. + return 0;
  21360. +
  21361. + /* Per process statistics.
  21362. + */
  21363. +
  21364. + seq_printf(s, "\nStatistics for TGID %d\n", file_data->pid);
  21365. +
  21366. + mutex_lock(&(sm_state->map_lock));
  21367. +
  21368. + if (!list_empty(&file_data->resource_list)) {
  21369. + list_for_each_entry(resource, &file_data->resource_list,
  21370. + resource_list) {
  21371. + res_count++;
  21372. +
  21373. + seq_printf(s, "\nGUID: 0x%x\n\n",
  21374. + resource->res_guid);
  21375. + for (ix = 0; ix < END_ATTEMPT; ix++) {
  21376. + if (resource->res_stats[ix] > 0) {
  21377. + seq_printf(s,
  21378. + " %u\t%s\n",
  21379. + resource->res_stats[ix],
  21380. + sm_stats_human_read[ix]);
  21381. + }
  21382. + }
  21383. + seq_puts(s, "\n");
  21384. + for (ix = 0; ix < END_ATTEMPT; ix++) {
  21385. + if (resource->res_stats[ix + END_ATTEMPT] > 0) {
  21386. + seq_printf(s,
  21387. + " %u\tFAILED %s\n",
  21388. + resource->res_stats[
  21389. + ix + END_ATTEMPT],
  21390. + sm_stats_human_read[ix]);
  21391. + }
  21392. + }
  21393. + }
  21394. + }
  21395. +
  21396. + mutex_unlock(&(sm_state->map_lock));
  21397. +
  21398. + seq_printf(s, "\nResources Count %d\n", res_count);
  21399. +
  21400. + return 0;
  21401. +}
  21402. +#endif
  21403. +
  21404. +#if 0
  21405. +/* Read callback for the allocation proc entry. */
  21406. +static int vc_sm_alloc_show(struct seq_file *s, void *v)
  21407. +{
  21408. + struct SM_PRIV_DATA_T *file_data;
  21409. + struct SM_RESOURCE_T *resource;
  21410. + int alloc_count = 0;
  21411. + struct SM_PDE_T *p_pde;
  21412. +
  21413. + p_pde = (struct SM_PDE_T *)(s->private);
  21414. + file_data = (struct SM_PRIV_DATA_T *)(p_pde->priv_data);
  21415. +
  21416. + if (!file_data)
  21417. + return 0;
  21418. +
  21419. + /* Per process statistics. */
  21420. + seq_printf(s, "\nAllocation for TGID %d\n", file_data->pid);
  21421. +
  21422. + mutex_lock(&(sm_state->map_lock));
  21423. +
  21424. + if (!list_empty(&file_data->resource_list)) {
  21425. + list_for_each_entry(resource, &file_data->resource_list,
  21426. + resource_list) {
  21427. + alloc_count++;
  21428. +
  21429. + seq_printf(s, "\nGUID: 0x%x\n",
  21430. + resource->res_guid);
  21431. + seq_printf(s, "Lock Count: %u\n",
  21432. + resource->lock_count);
  21433. + seq_printf(s, "Mapped: %s\n",
  21434. + (resource->map_count ? "yes" : "no"));
  21435. + seq_printf(s, "VC-handle: 0x%x\n",
  21436. + resource->res_handle);
  21437. + seq_printf(s, "VC-address: 0x%p\n",
  21438. + resource->res_base_mem);
  21439. + seq_printf(s, "VC-size (bytes): %u\n",
  21440. + resource->res_size);
  21441. + seq_printf(s, "Cache: %s\n",
  21442. + sm_cache_map_vector[resource->res_cached]);
  21443. + }
  21444. + }
  21445. +
  21446. + mutex_unlock(&(sm_state->map_lock));
  21447. +
  21448. + seq_printf(s, "\n\nTotal allocation count: %d\n\n", alloc_count);
  21449. +
  21450. + return 0;
  21451. +}
  21452. +#endif
  21453. +
  21454. +static int vc_sm_seq_file_show(struct seq_file *s, void *v)
  21455. +{
  21456. + struct SM_PDE_T *sm_pde;
  21457. +
  21458. + sm_pde = (struct SM_PDE_T *)(s->private);
  21459. +
  21460. + if (sm_pde && sm_pde->show)
  21461. + sm_pde->show(s, v);
  21462. +
  21463. + return 0;
  21464. +}
  21465. +
  21466. +static int vc_sm_single_open(struct inode *inode, struct file *file)
  21467. +{
  21468. + return single_open(file, vc_sm_seq_file_show, inode->i_private);
  21469. +}
  21470. +
  21471. +static const struct file_operations vc_sm_debug_fs_fops = {
  21472. + .open = vc_sm_single_open,
  21473. + .read = seq_read,
  21474. + .llseek = seq_lseek,
  21475. + .release = single_release,
  21476. +};
  21477. +
  21478. +/* Adds a resource to the private data list which tracks all the allocated
  21479. +** data.
  21480. +*/
  21481. +static void vmcs_sm_add_resource(struct SM_PRIV_DATA_T *privdata,
  21482. + struct SM_RESOURCE_T *resource)
  21483. +{
  21484. + mutex_lock(&(sm_state->map_lock));
  21485. + list_add(&resource->resource_list, &privdata->resource_list);
  21486. + list_add(&resource->global_resource_list, &sm_state->resource_list);
  21487. + mutex_unlock(&(sm_state->map_lock));
  21488. +
  21489. + pr_debug("[%s]: added resource %p (base addr %p, hdl %x, size %u, cache %u)\n",
  21490. + __func__, resource, resource->res_base_mem,
  21491. + resource->res_handle, resource->res_size, resource->res_cached);
  21492. +}
  21493. +
  21494. +/* Locates a resource and acquire a reference on it.
  21495. +** The resource won't be deleted while there is a reference on it.
  21496. +*/
  21497. +static struct SM_RESOURCE_T *vmcs_sm_acquire_resource(struct SM_PRIV_DATA_T
  21498. + *private,
  21499. + unsigned int res_guid)
  21500. +{
  21501. + struct SM_RESOURCE_T *resource, *ret = NULL;
  21502. +
  21503. + mutex_lock(&(sm_state->map_lock));
  21504. +
  21505. + list_for_each_entry(resource, &private->resource_list, resource_list) {
  21506. + if (resource->res_guid != res_guid)
  21507. + continue;
  21508. +
  21509. + pr_debug("[%s]: located resource %p (guid: %x, base addr %p, hdl %x, size %u, cache %u)\n",
  21510. + __func__, resource, resource->res_guid,
  21511. + resource->res_base_mem, resource->res_handle,
  21512. + resource->res_size, resource->res_cached);
  21513. + resource->ref_count++;
  21514. + ret = resource;
  21515. + break;
  21516. + }
  21517. +
  21518. + mutex_unlock(&(sm_state->map_lock));
  21519. +
  21520. + return ret;
  21521. +}
  21522. +
  21523. +/* Locates a resource and acquire a reference on it.
  21524. +** The resource won't be deleted while there is a reference on it.
  21525. +*/
  21526. +static struct SM_RESOURCE_T *vmcs_sm_acquire_first_resource(
  21527. + struct SM_PRIV_DATA_T *private)
  21528. +{
  21529. + struct SM_RESOURCE_T *resource, *ret = NULL;
  21530. +
  21531. + mutex_lock(&(sm_state->map_lock));
  21532. +
  21533. + list_for_each_entry(resource, &private->resource_list, resource_list) {
  21534. + pr_debug("[%s]: located resource %p (guid: %x, base addr %p, hdl %x, size %u, cache %u)\n",
  21535. + __func__, resource, resource->res_guid,
  21536. + resource->res_base_mem, resource->res_handle,
  21537. + resource->res_size, resource->res_cached);
  21538. + resource->ref_count++;
  21539. + ret = resource;
  21540. + break;
  21541. + }
  21542. +
  21543. + mutex_unlock(&(sm_state->map_lock));
  21544. +
  21545. + return ret;
  21546. +}
  21547. +
  21548. +/* Locates a resource and acquire a reference on it.
  21549. +** The resource won't be deleted while there is a reference on it.
  21550. +*/
  21551. +static struct SM_RESOURCE_T *vmcs_sm_acquire_global_resource(unsigned int
  21552. + res_guid)
  21553. +{
  21554. + struct SM_RESOURCE_T *resource, *ret = NULL;
  21555. +
  21556. + mutex_lock(&(sm_state->map_lock));
  21557. +
  21558. + list_for_each_entry(resource, &sm_state->resource_list,
  21559. + global_resource_list) {
  21560. + if (resource->res_guid != res_guid)
  21561. + continue;
  21562. +
  21563. + pr_debug("[%s]: located resource %p (guid: %x, base addr %p, hdl %x, size %u, cache %u)\n",
  21564. + __func__, resource, resource->res_guid,
  21565. + resource->res_base_mem, resource->res_handle,
  21566. + resource->res_size, resource->res_cached);
  21567. + resource->ref_count++;
  21568. + ret = resource;
  21569. + break;
  21570. + }
  21571. +
  21572. + mutex_unlock(&(sm_state->map_lock));
  21573. +
  21574. + return ret;
  21575. +}
  21576. +
  21577. +/* Release a previously acquired resource.
  21578. +** The resource will be deleted when its refcount reaches 0.
  21579. +*/
  21580. +static void vmcs_sm_release_resource(struct SM_RESOURCE_T *resource, int force)
  21581. +{
  21582. + struct SM_PRIV_DATA_T *private = resource->private;
  21583. + struct sm_mmap *map, *map_tmp;
  21584. + struct SM_RESOURCE_T *res_tmp;
  21585. + int ret;
  21586. +
  21587. + mutex_lock(&(sm_state->map_lock));
  21588. +
  21589. + if (--resource->ref_count) {
  21590. + if (force)
  21591. + pr_err("[%s]: resource %p in use\n", __func__, resource);
  21592. +
  21593. + mutex_unlock(&(sm_state->map_lock));
  21594. + return;
  21595. + }
  21596. +
  21597. + /* Time to free the resource. Start by removing it from the list */
  21598. + list_del(&resource->resource_list);
  21599. + list_del(&resource->global_resource_list);
  21600. +
  21601. + /* Walk the global resource list, find out if the resource is used
  21602. + * somewhere else. In which case we don't want to delete it.
  21603. + */
  21604. + list_for_each_entry(res_tmp, &sm_state->resource_list,
  21605. + global_resource_list) {
  21606. + if (res_tmp->res_handle == resource->res_handle) {
  21607. + resource->res_handle = 0;
  21608. + break;
  21609. + }
  21610. + }
  21611. +
  21612. + mutex_unlock(&(sm_state->map_lock));
  21613. +
  21614. + pr_debug("[%s]: freeing data - guid %x, hdl %x, base address %p\n",
  21615. + __func__, resource->res_guid, resource->res_handle,
  21616. + resource->res_base_mem);
  21617. + resource->res_stats[FREE]++;
  21618. +
  21619. + /* Make sure the resource we're removing is unmapped first */
  21620. + if (resource->map_count && !list_empty(&resource->map_list)) {
  21621. + down_write(&current->mm->mmap_sem);
  21622. + list_for_each_entry_safe(map, map_tmp, &resource->map_list,
  21623. + resource_map_list) {
  21624. + ret =
  21625. + do_munmap(current->mm, map->res_addr,
  21626. + resource->res_size);
  21627. + if (ret) {
  21628. + pr_err("[%s]: could not unmap resource %p\n",
  21629. + __func__, resource);
  21630. + }
  21631. + }
  21632. + up_write(&current->mm->mmap_sem);
  21633. + }
  21634. +
  21635. + /* Free up the videocore allocated resource.
  21636. + */
  21637. + if (resource->res_handle) {
  21638. + VC_SM_FREE_T free = {
  21639. + resource->res_handle, resource->res_base_mem
  21640. + };
  21641. + int status = vc_vchi_sm_free(sm_state->sm_handle, &free,
  21642. + &private->int_trans_id);
  21643. + if (status != 0 && status != -EINTR) {
  21644. + pr_err("[%s]: failed to free memory on videocore (status: %u, trans_id: %u)\n",
  21645. + __func__, status, private->int_trans_id);
  21646. + resource->res_stats[FREE_FAIL]++;
  21647. + ret = -EPERM;
  21648. + }
  21649. + }
  21650. +
  21651. + /* Free up the shared resource.
  21652. + */
  21653. + if (resource->res_shared)
  21654. + vmcs_sm_release_resource(resource->res_shared, 0);
  21655. +
  21656. + /* Free up the local resource tracking this allocation.
  21657. + */
  21658. + vc_sm_resource_deceased(resource, force);
  21659. + kfree(resource);
  21660. +}
  21661. +
  21662. +/* Dump the map table for the driver. If process is -1, dumps the whole table,
  21663. +** if process is a valid pid (non -1) dump only the entries associated with the
  21664. +** pid of interest.
  21665. +*/
  21666. +static void vmcs_sm_host_walk_map_per_pid(int pid)
  21667. +{
  21668. + struct sm_mmap *map = NULL;
  21669. +
  21670. + /* Make sure the device was started properly.
  21671. + */
  21672. + if (sm_state == NULL) {
  21673. + pr_err("[%s]: invalid device\n", __func__);
  21674. + return;
  21675. + }
  21676. +
  21677. + mutex_lock(&(sm_state->map_lock));
  21678. +
  21679. + /* Log all applicable mapping(s).
  21680. + */
  21681. + if (!list_empty(&sm_state->map_list)) {
  21682. + list_for_each_entry(map, &sm_state->map_list, map_list) {
  21683. + if (pid == -1 || map->res_pid == pid) {
  21684. + pr_info("[%s]: tgid: %u - vc-hdl: %x, usr-hdl: %x, usr-addr: %lx\n",
  21685. + __func__, map->res_pid, map->res_vc_hdl,
  21686. + map->res_usr_hdl, map->res_addr);
  21687. + }
  21688. + }
  21689. + }
  21690. +
  21691. + mutex_unlock(&(sm_state->map_lock));
  21692. +
  21693. + return;
  21694. +}
  21695. +
  21696. +/* Dump the allocation table from host side point of view. This only dumps the
  21697. +** data allocated for this process/device referenced by the file_data.
  21698. +*/
  21699. +static void vmcs_sm_host_walk_alloc(struct SM_PRIV_DATA_T *file_data)
  21700. +{
  21701. + struct SM_RESOURCE_T *resource = NULL;
  21702. +
  21703. + /* Make sure the device was started properly.
  21704. + */
  21705. + if ((sm_state == NULL) || (file_data == NULL)) {
  21706. + pr_err("[%s]: invalid device\n", __func__);
  21707. + return;
  21708. + }
  21709. +
  21710. + mutex_lock(&(sm_state->map_lock));
  21711. +
  21712. + if (!list_empty(&file_data->resource_list)) {
  21713. + list_for_each_entry(resource, &file_data->resource_list,
  21714. + resource_list) {
  21715. + pr_info("[%s]: guid: %x - hdl: %x, vc-mem: %p, size: %u, cache: %u\n",
  21716. + __func__, resource->res_guid, resource->res_handle,
  21717. + resource->res_base_mem, resource->res_size,
  21718. + resource->res_cached);
  21719. + }
  21720. + }
  21721. +
  21722. + mutex_unlock(&(sm_state->map_lock));
  21723. +
  21724. + return;
  21725. +}
  21726. +
  21727. +/* Create support for private data tracking.
  21728. +*/
  21729. +static struct SM_PRIV_DATA_T *vc_sm_create_priv_data(pid_t id)
  21730. +{
  21731. + char alloc_name[32];
  21732. + struct SM_PRIV_DATA_T *file_data = NULL;
  21733. +
  21734. + /* Allocate private structure. */
  21735. + file_data = kzalloc(sizeof(*file_data), GFP_KERNEL);
  21736. +
  21737. + if (!file_data) {
  21738. + pr_err("[%s]: cannot allocate file data\n", __func__);
  21739. + goto out;
  21740. + }
  21741. +
  21742. + snprintf(alloc_name, sizeof(alloc_name), "%d", id);
  21743. +
  21744. + INIT_LIST_HEAD(&file_data->resource_list);
  21745. + file_data->pid = id;
  21746. + file_data->dir_pid = debugfs_create_dir(alloc_name,
  21747. + sm_state->dir_alloc);
  21748. +#if 0
  21749. + /* TODO: fix this to support querying statistics per pid */
  21750. +
  21751. + if (IS_ERR_OR_NULL(file_data->dir_pid)) {
  21752. + file_data->dir_pid = NULL;
  21753. + } else {
  21754. + struct dentry *dir_entry;
  21755. +
  21756. + dir_entry = debugfs_create_file(VC_SM_RESOURCES, S_IRUGO,
  21757. + file_data->dir_pid, file_data,
  21758. + vc_sm_debug_fs_fops);
  21759. +
  21760. + file_data->dir_res.dir_entry = dir_entry;
  21761. + file_data->dir_res.priv_data = file_data;
  21762. + file_data->dir_res.show = &vc_sm_alloc_show;
  21763. +
  21764. + dir_entry = debugfs_create_file(VC_SM_STATS, S_IRUGO,
  21765. + file_data->dir_pid, file_data,
  21766. + vc_sm_debug_fs_fops);
  21767. +
  21768. + file_data->dir_res.dir_entry = dir_entry;
  21769. + file_data->dir_res.priv_data = file_data;
  21770. + file_data->dir_res.show = &vc_sm_statistics_show;
  21771. + }
  21772. + pr_debug("[%s]: private data allocated %p\n", __func__, file_data);
  21773. +
  21774. +#endif
  21775. +out:
  21776. + return file_data;
  21777. +}
  21778. +
  21779. +/* Open the device. Creates a private state to help track all allocation
  21780. +** associated with this device.
  21781. +*/
  21782. +static int vc_sm_open(struct inode *inode, struct file *file)
  21783. +{
  21784. + int ret = 0;
  21785. +
  21786. + /* Make sure the device was started properly.
  21787. + */
  21788. + if (!sm_state) {
  21789. + pr_err("[%s]: invalid device\n", __func__);
  21790. + ret = -EPERM;
  21791. + goto out;
  21792. + }
  21793. +
  21794. + file->private_data = vc_sm_create_priv_data(current->tgid);
  21795. + if (file->private_data == NULL) {
  21796. + pr_err("[%s]: failed to create data tracker\n", __func__);
  21797. +
  21798. + ret = -ENOMEM;
  21799. + goto out;
  21800. + }
  21801. +
  21802. +out:
  21803. + return ret;
  21804. +}
  21805. +
  21806. +/* Close the device. Free up all resources still associated with this device
  21807. +** at the time.
  21808. +*/
  21809. +static int vc_sm_release(struct inode *inode, struct file *file)
  21810. +{
  21811. + struct SM_PRIV_DATA_T *file_data =
  21812. + (struct SM_PRIV_DATA_T *)file->private_data;
  21813. + struct SM_RESOURCE_T *resource;
  21814. + int ret = 0;
  21815. +
  21816. + /* Make sure the device was started properly.
  21817. + */
  21818. + if (sm_state == NULL || file_data == NULL) {
  21819. + pr_err("[%s]: invalid device\n", __func__);
  21820. + ret = -EPERM;
  21821. + goto out;
  21822. + }
  21823. +
  21824. + pr_debug("[%s]: using private data %p\n", __func__, file_data);
  21825. +
  21826. + if (file_data->restart_sys == -EINTR) {
  21827. + VC_SM_ACTION_CLEAN_T action_clean;
  21828. +
  21829. + pr_debug("[%s]: releasing following EINTR on %u (trans_id: %u) (likely due to signal)...\n",
  21830. + __func__, file_data->int_action,
  21831. + file_data->int_trans_id);
  21832. +
  21833. + action_clean.res_action = file_data->int_action;
  21834. + action_clean.action_trans_id = file_data->int_trans_id;
  21835. +
  21836. + vc_vchi_sm_clean_up(sm_state->sm_handle, &action_clean);
  21837. + }
  21838. +
  21839. + while ((resource = vmcs_sm_acquire_first_resource(file_data)) != NULL) {
  21840. + vmcs_sm_release_resource(resource, 0);
  21841. + vmcs_sm_release_resource(resource, 1);
  21842. + }
  21843. +
  21844. + /* Remove the corresponding proc entry. */
  21845. + debugfs_remove_recursive(file_data->dir_pid);
  21846. +
  21847. + /* Terminate the private data.
  21848. + */
  21849. + kfree(file_data);
  21850. +
  21851. +out:
  21852. + return ret;
  21853. +}
  21854. +
  21855. +static void vcsm_vma_open(struct vm_area_struct *vma)
  21856. +{
  21857. + struct sm_mmap *map = (struct sm_mmap *)vma->vm_private_data;
  21858. +
  21859. + pr_debug("[%s]: virt %lx-%lx, pid %i, pfn %i\n",
  21860. + __func__, vma->vm_start, vma->vm_end, (int)current->tgid,
  21861. + (int)vma->vm_pgoff);
  21862. +
  21863. + map->ref_count++;
  21864. +}
  21865. +
  21866. +static void vcsm_vma_close(struct vm_area_struct *vma)
  21867. +{
  21868. + struct sm_mmap *map = (struct sm_mmap *)vma->vm_private_data;
  21869. +
  21870. + pr_debug("[%s]: virt %lx-%lx, pid %i, pfn %i\n",
  21871. + __func__, vma->vm_start, vma->vm_end, (int)current->tgid,
  21872. + (int)vma->vm_pgoff);
  21873. +
  21874. + map->ref_count--;
  21875. +
  21876. + /* Remove from the map table.
  21877. + */
  21878. + if (map->ref_count == 0)
  21879. + vmcs_sm_remove_map(sm_state, map->resource, map);
  21880. +}
  21881. +
  21882. +static int vcsm_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
  21883. +{
  21884. + struct sm_mmap *map = (struct sm_mmap *)vma->vm_private_data;
  21885. + struct SM_RESOURCE_T *resource = map->resource;
  21886. + pgoff_t page_offset;
  21887. + unsigned long pfn;
  21888. + int ret = 0;
  21889. +
  21890. + /* Lock the resource if necessary.
  21891. + */
  21892. + if (!resource->lock_count) {
  21893. + VC_SM_LOCK_UNLOCK_T lock_unlock;
  21894. + VC_SM_LOCK_RESULT_T lock_result;
  21895. + int status;
  21896. +
  21897. + lock_unlock.res_handle = resource->res_handle;
  21898. + lock_unlock.res_mem = resource->res_base_mem;
  21899. +
  21900. + pr_debug("[%s]: attempt to lock data - hdl %x, base address %p\n",
  21901. + __func__, lock_unlock.res_handle, lock_unlock.res_mem);
  21902. +
  21903. + /* Lock the videocore allocated resource.
  21904. + */
  21905. + status = vc_vchi_sm_lock(sm_state->sm_handle,
  21906. + &lock_unlock, &lock_result, 0);
  21907. + if ((status != 0) ||
  21908. + ((status == 0) && (lock_result.res_mem == NULL))) {
  21909. + pr_err("[%s]: failed to lock memory on videocore (status: %u)\n",
  21910. + __func__, status);
  21911. + resource->res_stats[LOCK_FAIL]++;
  21912. + return VM_FAULT_SIGBUS;
  21913. + }
  21914. +
  21915. + pfn = vcaddr_to_pfn((unsigned long)resource->res_base_mem);
  21916. + outer_inv_range(__pfn_to_phys(pfn),
  21917. + __pfn_to_phys(pfn) + resource->res_size);
  21918. +
  21919. + resource->res_stats[LOCK]++;
  21920. + resource->lock_count++;
  21921. +
  21922. + /* Keep track of the new base memory.
  21923. + */
  21924. + if ((lock_result.res_mem != NULL) &&
  21925. + (lock_result.res_old_mem != NULL) &&
  21926. + (lock_result.res_mem != lock_result.res_old_mem)) {
  21927. + resource->res_base_mem = lock_result.res_mem;
  21928. + }
  21929. + }
  21930. +
  21931. + /* We don't use vmf->pgoff since that has the fake offset */
  21932. + page_offset = ((unsigned long)vmf->virtual_address - vma->vm_start);
  21933. + pfn = (uint32_t)resource->res_base_mem & 0x3FFFFFFF;
  21934. + pfn += mm_vc_mem_phys_addr;
  21935. + pfn += page_offset;
  21936. + pfn >>= PAGE_SHIFT;
  21937. +
  21938. + /* Finally, remap it */
  21939. + ret = vm_insert_pfn(vma, (unsigned long)vmf->virtual_address, pfn);
  21940. +
  21941. + switch (ret) {
  21942. + case 0:
  21943. + case -ERESTARTSYS:
  21944. + return VM_FAULT_NOPAGE;
  21945. + case -ENOMEM:
  21946. + case -EAGAIN:
  21947. + return VM_FAULT_OOM;
  21948. + default:
  21949. + return VM_FAULT_SIGBUS;
  21950. + }
  21951. +}
  21952. +
  21953. +static struct vm_operations_struct vcsm_vm_ops = {
  21954. + .open = vcsm_vma_open,
  21955. + .close = vcsm_vma_close,
  21956. + .fault = vcsm_vma_fault,
  21957. +};
  21958. +
  21959. +/* Walks a VMA and clean each valid page from the cache */
  21960. +static void vcsm_vma_cache_clean_page_range(unsigned long addr,
  21961. + unsigned long end)
  21962. +{
  21963. + pgd_t *pgd;
  21964. + pud_t *pud;
  21965. + pmd_t *pmd;
  21966. + pte_t *pte;
  21967. + unsigned long pgd_next, pud_next, pmd_next;
  21968. +
  21969. + if (addr >= end)
  21970. + return;
  21971. +
  21972. + /* Walk PGD */
  21973. + pgd = pgd_offset(current->mm, addr);
  21974. + do {
  21975. + pgd_next = pgd_addr_end(addr, end);
  21976. +
  21977. + if (pgd_none(*pgd) || pgd_bad(*pgd))
  21978. + continue;
  21979. +
  21980. + /* Walk PUD */
  21981. + pud = pud_offset(pgd, addr);
  21982. + do {
  21983. + pud_next = pud_addr_end(addr, pgd_next);
  21984. + if (pud_none(*pud) || pud_bad(*pud))
  21985. + continue;
  21986. +
  21987. + /* Walk PMD */
  21988. + pmd = pmd_offset(pud, addr);
  21989. + do {
  21990. + pmd_next = pmd_addr_end(addr, pud_next);
  21991. + if (pmd_none(*pmd) || pmd_bad(*pmd))
  21992. + continue;
  21993. +
  21994. + /* Walk PTE */
  21995. + pte = pte_offset_map(pmd, addr);
  21996. + do {
  21997. + if (pte_none(*pte)
  21998. + || !pte_present(*pte))
  21999. + continue;
  22000. +
  22001. + /* Clean + invalidate */
  22002. + dmac_flush_range((const void *) addr,
  22003. + (const void *)
  22004. + (addr + PAGE_SIZE));
  22005. +
  22006. + } while (pte++, addr +=
  22007. + PAGE_SIZE, addr != pmd_next);
  22008. + pte_unmap(pte);
  22009. +
  22010. + } while (pmd++, addr = pmd_next, addr != pud_next);
  22011. +
  22012. + } while (pud++, addr = pud_next, addr != pgd_next);
  22013. + } while (pgd++, addr = pgd_next, addr != end);
  22014. +}
  22015. +
  22016. +/* Map an allocated data into something that the user space.
  22017. +*/
  22018. +static int vc_sm_mmap(struct file *file, struct vm_area_struct *vma)
  22019. +{
  22020. + int ret = 0;
  22021. + struct SM_PRIV_DATA_T *file_data =
  22022. + (struct SM_PRIV_DATA_T *)file->private_data;
  22023. + struct SM_RESOURCE_T *resource = NULL;
  22024. + struct sm_mmap *map = NULL;
  22025. +
  22026. + /* Make sure the device was started properly.
  22027. + */
  22028. + if ((sm_state == NULL) || (file_data == NULL)) {
  22029. + pr_err("[%s]: invalid device\n", __func__);
  22030. + return -EPERM;
  22031. + }
  22032. +
  22033. + pr_debug("[%s]: private data %p, guid %x\n", __func__, file_data,
  22034. + ((unsigned int)vma->vm_pgoff << PAGE_SHIFT));
  22035. +
  22036. + /* We lookup to make sure that the data we are being asked to mmap is
  22037. + ** something that we allocated.
  22038. + **
  22039. + ** We use the offset information as the key to tell us which resource
  22040. + ** we are mapping.
  22041. + */
  22042. + resource = vmcs_sm_acquire_resource(file_data,
  22043. + ((unsigned int)vma->vm_pgoff <<
  22044. + PAGE_SHIFT));
  22045. + if (resource == NULL) {
  22046. + pr_err("[%s]: failed to locate resource for guid %x\n", __func__,
  22047. + ((unsigned int)vma->vm_pgoff << PAGE_SHIFT));
  22048. + return -ENOMEM;
  22049. + }
  22050. +
  22051. + pr_debug("[%s]: guid %x, tgid %u, %u, %u\n",
  22052. + __func__, resource->res_guid, current->tgid, resource->pid,
  22053. + file_data->pid);
  22054. +
  22055. + /* Check permissions.
  22056. + */
  22057. + if (resource->pid && (resource->pid != current->tgid)) {
  22058. + pr_err("[%s]: current tgid %u != %u owner\n",
  22059. + __func__, current->tgid, resource->pid);
  22060. + ret = -EPERM;
  22061. + goto error;
  22062. + }
  22063. +
  22064. + /* Verify that what we are asked to mmap is proper.
  22065. + */
  22066. + if (resource->res_size != (unsigned int)(vma->vm_end - vma->vm_start)) {
  22067. + pr_err("[%s]: size inconsistency (resource: %u - mmap: %u)\n",
  22068. + __func__,
  22069. + resource->res_size,
  22070. + (unsigned int)(vma->vm_end - vma->vm_start));
  22071. +
  22072. + ret = -EINVAL;
  22073. + goto error;
  22074. + }
  22075. +
  22076. + /* Keep track of the tuple in the global resource list such that one
  22077. + * can do a mapping lookup for address/memory handle.
  22078. + */
  22079. + map = kzalloc(sizeof(*map), GFP_KERNEL);
  22080. + if (map == NULL) {
  22081. + pr_err("[%s]: failed to allocate global tracking resource\n",
  22082. + __func__);
  22083. + ret = -ENOMEM;
  22084. + goto error;
  22085. + }
  22086. +
  22087. + map->res_pid = current->tgid;
  22088. + map->res_vc_hdl = resource->res_handle;
  22089. + map->res_usr_hdl = resource->res_guid;
  22090. + map->res_addr = (long unsigned int)vma->vm_start;
  22091. + map->resource = resource;
  22092. + map->vma = vma;
  22093. + vmcs_sm_add_map(sm_state, resource, map);
  22094. +
  22095. + /* We are not actually mapping the pages, we just provide a fault
  22096. + ** handler to allow pages to be mapped when accessed
  22097. + */
  22098. + vma->vm_flags |=
  22099. + VM_IO | VM_PFNMAP | VM_DONTCOPY | VM_DONTEXPAND;
  22100. + vma->vm_ops = &vcsm_vm_ops;
  22101. + vma->vm_private_data = map;
  22102. +
  22103. + /* vm_pgoff is the first PFN of the mapped memory */
  22104. + vma->vm_pgoff = (unsigned long)resource->res_base_mem & 0x3FFFFFFF;
  22105. + vma->vm_pgoff += mm_vc_mem_phys_addr;
  22106. + vma->vm_pgoff >>= PAGE_SHIFT;
  22107. +
  22108. + if ((resource->res_cached == VMCS_SM_CACHE_NONE) ||
  22109. + (resource->res_cached == VMCS_SM_CACHE_VC)) {
  22110. + /* Allocated non host cached memory, honour it.
  22111. + */
  22112. + vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
  22113. + }
  22114. +
  22115. + pr_debug("[%s]: resource %p (guid %x) - cnt %u, base address %p, handle %x, size %u (%u), cache %u\n",
  22116. + __func__,
  22117. + resource, resource->res_guid, resource->lock_count,
  22118. + resource->res_base_mem, resource->res_handle,
  22119. + resource->res_size, (unsigned int)(vma->vm_end - vma->vm_start),
  22120. + resource->res_cached);
  22121. +
  22122. + pr_debug("[%s]: resource %p (base address %p, handle %x) - map-count %d, usr-addr %x\n",
  22123. + __func__, resource, resource->res_base_mem,
  22124. + resource->res_handle, resource->map_count,
  22125. + (unsigned int)vma->vm_start);
  22126. +
  22127. + vcsm_vma_open(vma);
  22128. + resource->res_stats[MAP]++;
  22129. + vmcs_sm_release_resource(resource, 0);
  22130. + return 0;
  22131. +
  22132. +error:
  22133. + vmcs_sm_release_resource(resource, 0);
  22134. + resource->res_stats[MAP_FAIL]++;
  22135. + return ret;
  22136. +}
  22137. +
  22138. +/* Allocate a shared memory handle and block.
  22139. +*/
  22140. +int vc_sm_ioctl_alloc(struct SM_PRIV_DATA_T *private,
  22141. + struct vmcs_sm_ioctl_alloc *ioparam)
  22142. +{
  22143. + int ret = 0;
  22144. + int status;
  22145. + struct SM_RESOURCE_T *resource;
  22146. + VC_SM_ALLOC_T alloc = { 0 };
  22147. + VC_SM_ALLOC_RESULT_T result = { 0 };
  22148. +
  22149. + /* Setup our allocation parameters */
  22150. + alloc.type = ((ioparam->cached == VMCS_SM_CACHE_VC)
  22151. + || (ioparam->cached ==
  22152. + VMCS_SM_CACHE_BOTH)) ? VC_SM_ALLOC_CACHED :
  22153. + VC_SM_ALLOC_NON_CACHED;
  22154. + alloc.base_unit = ioparam->size;
  22155. + alloc.num_unit = ioparam->num;
  22156. + alloc.allocator = current->tgid;
  22157. + /* Align to kernel page size */
  22158. + alloc.alignement = 4096;
  22159. + /* Align the size to the kernel page size */
  22160. + alloc.base_unit =
  22161. + (alloc.base_unit + alloc.alignement - 1) & ~(alloc.alignement - 1);
  22162. + if (*ioparam->name) {
  22163. + memcpy(alloc.name, ioparam->name, sizeof(alloc.name) - 1);
  22164. + } else {
  22165. + memcpy(alloc.name, VMCS_SM_RESOURCE_NAME_DEFAULT,
  22166. + sizeof(VMCS_SM_RESOURCE_NAME_DEFAULT));
  22167. + }
  22168. +
  22169. + pr_debug("[%s]: attempt to allocate \"%s\" data - type %u, base %u (%u), num %u, alignement %u\n",
  22170. + __func__, alloc.name, alloc.type, ioparam->size,
  22171. + alloc.base_unit, alloc.num_unit, alloc.alignement);
  22172. +
  22173. + /* Allocate local resource to track this allocation.
  22174. + */
  22175. + resource = kzalloc(sizeof(*resource), GFP_KERNEL);
  22176. + if (!resource) {
  22177. + ret = -ENOMEM;
  22178. + goto error;
  22179. + }
  22180. + INIT_LIST_HEAD(&resource->map_list);
  22181. + resource->ref_count++;
  22182. + resource->pid = current->tgid;
  22183. +
  22184. + /* Allocate the videocore resource.
  22185. + */
  22186. + status = vc_vchi_sm_alloc(sm_state->sm_handle, &alloc, &result,
  22187. + &private->int_trans_id);
  22188. + if (status == -EINTR) {
  22189. + pr_debug("[%s]: requesting allocate memory action restart (trans_id: %u)\n",
  22190. + __func__, private->int_trans_id);
  22191. + ret = -ERESTARTSYS;
  22192. + private->restart_sys = -EINTR;
  22193. + private->int_action = VC_SM_MSG_TYPE_ALLOC;
  22194. + goto error;
  22195. + } else if (status != 0 || (status == 0 && result.res_mem == NULL)) {
  22196. + pr_err("[%s]: failed to allocate memory on videocore (status: %u, trans_id: %u)\n",
  22197. + __func__, status, private->int_trans_id);
  22198. + ret = -ENOMEM;
  22199. + resource->res_stats[ALLOC_FAIL]++;
  22200. + goto error;
  22201. + }
  22202. +
  22203. + /* Keep track of the resource we created.
  22204. + */
  22205. + resource->private = private;
  22206. + resource->res_handle = result.res_handle;
  22207. + resource->res_base_mem = result.res_mem;
  22208. + resource->res_size = alloc.base_unit * alloc.num_unit;
  22209. + resource->res_cached = ioparam->cached;
  22210. +
  22211. + /* Kernel/user GUID. This global identifier is used for mmap'ing the
  22212. + * allocated region from user space, it is passed as the mmap'ing
  22213. + * offset, we use it to 'hide' the videocore handle/address.
  22214. + */
  22215. + mutex_lock(&sm_state->lock);
  22216. + resource->res_guid = ++sm_state->guid;
  22217. + mutex_unlock(&sm_state->lock);
  22218. + resource->res_guid <<= PAGE_SHIFT;
  22219. +
  22220. + vmcs_sm_add_resource(private, resource);
  22221. +
  22222. + pr_debug("[%s]: allocated data - guid %x, hdl %x, base address %p, size %d, cache %d\n",
  22223. + __func__, resource->res_guid, resource->res_handle,
  22224. + resource->res_base_mem, resource->res_size,
  22225. + resource->res_cached);
  22226. +
  22227. + /* We're done */
  22228. + resource->res_stats[ALLOC]++;
  22229. + ioparam->handle = resource->res_guid;
  22230. + return 0;
  22231. +
  22232. +error:
  22233. + pr_err("[%s]: failed to allocate \"%s\" data (%i) - type %u, base %u (%u), num %u, alignment %u\n",
  22234. + __func__, alloc.name, ret, alloc.type, ioparam->size,
  22235. + alloc.base_unit, alloc.num_unit, alloc.alignement);
  22236. + if (resource != NULL) {
  22237. + vc_sm_resource_deceased(resource, 1);
  22238. + kfree(resource);
  22239. + }
  22240. + return ret;
  22241. +}
  22242. +
  22243. +/* Share an allocate memory handle and block.
  22244. +*/
  22245. +int vc_sm_ioctl_alloc_share(struct SM_PRIV_DATA_T *private,
  22246. + struct vmcs_sm_ioctl_alloc_share *ioparam)
  22247. +{
  22248. + struct SM_RESOURCE_T *resource, *shared_resource;
  22249. + int ret = 0;
  22250. +
  22251. + pr_debug("[%s]: attempt to share resource %u\n", __func__,
  22252. + ioparam->handle);
  22253. +
  22254. + shared_resource = vmcs_sm_acquire_global_resource(ioparam->handle);
  22255. + if (shared_resource == NULL) {
  22256. + ret = -ENOMEM;
  22257. + goto error;
  22258. + }
  22259. +
  22260. + /* Allocate local resource to track this allocation.
  22261. + */
  22262. + resource = kzalloc(sizeof(*resource), GFP_KERNEL);
  22263. + if (resource == NULL) {
  22264. + pr_err("[%s]: failed to allocate local tracking resource\n",
  22265. + __func__);
  22266. + ret = -ENOMEM;
  22267. + goto error;
  22268. + }
  22269. + INIT_LIST_HEAD(&resource->map_list);
  22270. + resource->ref_count++;
  22271. + resource->pid = current->tgid;
  22272. +
  22273. + /* Keep track of the resource we created.
  22274. + */
  22275. + resource->private = private;
  22276. + resource->res_handle = shared_resource->res_handle;
  22277. + resource->res_base_mem = shared_resource->res_base_mem;
  22278. + resource->res_size = shared_resource->res_size;
  22279. + resource->res_cached = shared_resource->res_cached;
  22280. + resource->res_shared = shared_resource;
  22281. +
  22282. + mutex_lock(&sm_state->lock);
  22283. + resource->res_guid = ++sm_state->guid;
  22284. + mutex_unlock(&sm_state->lock);
  22285. + resource->res_guid <<= PAGE_SHIFT;
  22286. +
  22287. + vmcs_sm_add_resource(private, resource);
  22288. +
  22289. + pr_debug("[%s]: allocated data - guid %x, hdl %x, base address %p, size %d, cache %d\n",
  22290. + __func__, resource->res_guid, resource->res_handle,
  22291. + resource->res_base_mem, resource->res_size,
  22292. + resource->res_cached);
  22293. +
  22294. + /* We're done */
  22295. + resource->res_stats[ALLOC]++;
  22296. + ioparam->handle = resource->res_guid;
  22297. + ioparam->size = resource->res_size;
  22298. + return 0;
  22299. +
  22300. +error:
  22301. + pr_err("[%s]: failed to share %u\n", __func__, ioparam->handle);
  22302. + if (shared_resource != NULL)
  22303. + vmcs_sm_release_resource(shared_resource, 0);
  22304. +
  22305. + return ret;
  22306. +}
  22307. +
  22308. +/* Free a previously allocated shared memory handle and block.
  22309. +*/
  22310. +static int vc_sm_ioctl_free(struct SM_PRIV_DATA_T *private,
  22311. + struct vmcs_sm_ioctl_free *ioparam)
  22312. +{
  22313. + struct SM_RESOURCE_T *resource =
  22314. + vmcs_sm_acquire_resource(private, ioparam->handle);
  22315. +
  22316. + if (resource == NULL) {
  22317. + pr_err("[%s]: resource for guid %u does not exist\n", __func__,
  22318. + ioparam->handle);
  22319. + return -EINVAL;
  22320. + }
  22321. +
  22322. + /* Check permissions.
  22323. + */
  22324. + if (resource->pid && (resource->pid != current->tgid)) {
  22325. + pr_err("[%s]: current tgid %u != %u owner\n",
  22326. + __func__, current->tgid, resource->pid);
  22327. + vmcs_sm_release_resource(resource, 0);
  22328. + return -EPERM;
  22329. + }
  22330. +
  22331. + vmcs_sm_release_resource(resource, 0);
  22332. + vmcs_sm_release_resource(resource, 0);
  22333. + return 0;
  22334. +}
  22335. +
  22336. +/* Resize a previously allocated shared memory handle and block.
  22337. +*/
  22338. +static int vc_sm_ioctl_resize(struct SM_PRIV_DATA_T *private,
  22339. + struct vmcs_sm_ioctl_resize *ioparam)
  22340. +{
  22341. + int ret = 0;
  22342. + int status;
  22343. + VC_SM_RESIZE_T resize;
  22344. + struct SM_RESOURCE_T *resource;
  22345. +
  22346. + /* Locate resource from GUID.
  22347. + */
  22348. + resource = vmcs_sm_acquire_resource(private, ioparam->handle);
  22349. + if (!resource) {
  22350. + pr_err("[%s]: failed resource - guid %x\n",
  22351. + __func__, ioparam->handle);
  22352. + ret = -EFAULT;
  22353. + goto error;
  22354. + }
  22355. +
  22356. + /* If the resource is locked, its reference count will be not NULL,
  22357. + ** in which case we will not be allowed to resize it anyways, so
  22358. + ** reject the attempt here.
  22359. + */
  22360. + if (resource->lock_count != 0) {
  22361. + pr_err("[%s]: cannot resize - guid %x, ref-cnt %d\n",
  22362. + __func__, ioparam->handle, resource->lock_count);
  22363. + ret = -EFAULT;
  22364. + goto error;
  22365. + }
  22366. +
  22367. + /* Check permissions.
  22368. + */
  22369. + if (resource->pid && (resource->pid != current->tgid)) {
  22370. + pr_err("[%s]: current tgid %u != %u owner\n", __func__,
  22371. + current->tgid, resource->pid);
  22372. + ret = -EPERM;
  22373. + goto error;
  22374. + }
  22375. +
  22376. + if (resource->map_count != 0) {
  22377. + pr_err("[%s]: cannot resize - guid %x, ref-cnt %d\n",
  22378. + __func__, ioparam->handle, resource->map_count);
  22379. + ret = -EFAULT;
  22380. + goto error;
  22381. + }
  22382. +
  22383. + resize.res_handle = resource->res_handle;
  22384. + resize.res_mem = resource->res_base_mem;
  22385. + resize.res_new_size = ioparam->new_size;
  22386. +
  22387. + pr_debug("[%s]: attempt to resize data - guid %x, hdl %x, base address %p\n",
  22388. + __func__, ioparam->handle, resize.res_handle, resize.res_mem);
  22389. +
  22390. + /* Resize the videocore allocated resource.
  22391. + */
  22392. + status = vc_vchi_sm_resize(sm_state->sm_handle, &resize,
  22393. + &private->int_trans_id);
  22394. + if (status == -EINTR) {
  22395. + pr_debug("[%s]: requesting resize memory action restart (trans_id: %u)\n",
  22396. + __func__, private->int_trans_id);
  22397. + ret = -ERESTARTSYS;
  22398. + private->restart_sys = -EINTR;
  22399. + private->int_action = VC_SM_MSG_TYPE_RESIZE;
  22400. + goto error;
  22401. + } else if (status != 0) {
  22402. + pr_err("[%s]: failed to resize memory on videocore (status: %u, trans_id: %u)\n",
  22403. + __func__, status, private->int_trans_id);
  22404. + ret = -EPERM;
  22405. + goto error;
  22406. + }
  22407. +
  22408. + pr_debug("[%s]: success to resize data - hdl %x, size %d -> %d\n",
  22409. + __func__, resize.res_handle, resource->res_size,
  22410. + resize.res_new_size);
  22411. +
  22412. + /* Successfully resized, save the information and inform the user.
  22413. + */
  22414. + ioparam->old_size = resource->res_size;
  22415. + resource->res_size = resize.res_new_size;
  22416. +
  22417. +error:
  22418. + if (resource)
  22419. + vmcs_sm_release_resource(resource, 0);
  22420. +
  22421. + return ret;
  22422. +}
  22423. +
  22424. +/* Lock a previously allocated shared memory handle and block.
  22425. +*/
  22426. +static int vc_sm_ioctl_lock(struct SM_PRIV_DATA_T *private,
  22427. + struct vmcs_sm_ioctl_lock_unlock *ioparam,
  22428. + int change_cache, enum vmcs_sm_cache_e cache_type,
  22429. + unsigned int vc_addr)
  22430. +{
  22431. + int status;
  22432. + VC_SM_LOCK_UNLOCK_T lock;
  22433. + VC_SM_LOCK_RESULT_T result;
  22434. + struct SM_RESOURCE_T *resource;
  22435. + int ret = 0;
  22436. + struct sm_mmap *map, *map_tmp;
  22437. + long unsigned int phys_addr;
  22438. +
  22439. + map = NULL;
  22440. +
  22441. + /* Locate resource from GUID.
  22442. + */
  22443. + resource = vmcs_sm_acquire_resource(private, ioparam->handle);
  22444. + if (resource == NULL) {
  22445. + ret = -EINVAL;
  22446. + goto error;
  22447. + }
  22448. +
  22449. + /* Check permissions.
  22450. + */
  22451. + if (resource->pid && (resource->pid != current->tgid)) {
  22452. + pr_err("[%s]: current tgid %u != %u owner\n", __func__,
  22453. + current->tgid, resource->pid);
  22454. + ret = -EPERM;
  22455. + goto error;
  22456. + }
  22457. +
  22458. + lock.res_handle = resource->res_handle;
  22459. + lock.res_mem = resource->res_base_mem;
  22460. +
  22461. + /* Take the lock and get the address to be mapped.
  22462. + */
  22463. + if (vc_addr == 0) {
  22464. + pr_debug("[%s]: attempt to lock data - guid %x, hdl %x, base address %p\n",
  22465. + __func__, ioparam->handle, lock.res_handle,
  22466. + lock.res_mem);
  22467. +
  22468. + /* Lock the videocore allocated resource.
  22469. + */
  22470. + status = vc_vchi_sm_lock(sm_state->sm_handle, &lock, &result,
  22471. + &private->int_trans_id);
  22472. + if (status == -EINTR) {
  22473. + pr_debug("[%s]: requesting lock memory action restart (trans_id: %u)\n",
  22474. + __func__, private->int_trans_id);
  22475. + ret = -ERESTARTSYS;
  22476. + private->restart_sys = -EINTR;
  22477. + private->int_action = VC_SM_MSG_TYPE_LOCK;
  22478. + goto error;
  22479. + } else if (status != 0 ||
  22480. + (status == 0 && result.res_mem == NULL)) {
  22481. + pr_err("[%s]: failed to lock memory on videocore (status: %u, trans_id: %u)\n",
  22482. + __func__, status, private->int_trans_id);
  22483. + ret = -EPERM;
  22484. + resource->res_stats[LOCK_FAIL]++;
  22485. + goto error;
  22486. + }
  22487. +
  22488. + pr_debug("[%s]: succeed to lock data - hdl %x, base address %p (%p), ref-cnt %d\n",
  22489. + __func__, lock.res_handle, result.res_mem,
  22490. + lock.res_mem, resource->lock_count);
  22491. + }
  22492. + /* Lock assumed taken already, address to be mapped is known.
  22493. + */
  22494. + else
  22495. + resource->res_base_mem = (void *)vc_addr;
  22496. +
  22497. + resource->res_stats[LOCK]++;
  22498. + resource->lock_count++;
  22499. +
  22500. + /* Keep track of the new base memory allocation if it has changed.
  22501. + */
  22502. + if ((vc_addr == 0) &&
  22503. + (result.res_mem != NULL) &&
  22504. + (result.res_old_mem != NULL) &&
  22505. + (result.res_mem != result.res_old_mem)) {
  22506. + resource->res_base_mem = result.res_mem;
  22507. +
  22508. + /* Kernel allocated resources.
  22509. + */
  22510. + if (resource->pid == 0) {
  22511. + if (!list_empty(&resource->map_list)) {
  22512. + list_for_each_entry_safe(map, map_tmp,
  22513. + &resource->map_list,
  22514. + resource_map_list) {
  22515. + if (map->res_addr) {
  22516. + iounmap((void *)map->res_addr);
  22517. + map->res_addr = 0;
  22518. +
  22519. + vmcs_sm_remove_map(sm_state,
  22520. + map->resource,
  22521. + map);
  22522. + break;
  22523. + }
  22524. + }
  22525. + }
  22526. + }
  22527. + }
  22528. +
  22529. + if (change_cache)
  22530. + resource->res_cached = cache_type;
  22531. +
  22532. + if (resource->map_count) {
  22533. + ioparam->addr =
  22534. + vmcs_sm_usr_address_from_pid_and_usr_handle(
  22535. + current->tgid, ioparam->handle);
  22536. +
  22537. + pr_debug("[%s] map_count %d private->pid %d current->tgid %d hnd %x addr %u\n",
  22538. + __func__, resource->map_count, private->pid,
  22539. + current->tgid, ioparam->handle, ioparam->addr);
  22540. + } else {
  22541. + /* Kernel allocated resources.
  22542. + */
  22543. + if (resource->pid == 0) {
  22544. + pr_debug("[%s]: attempt mapping kernel resource - guid %x, hdl %x\n",
  22545. + __func__, ioparam->handle, lock.res_handle);
  22546. +
  22547. + ioparam->addr = 0;
  22548. +
  22549. + map = kzalloc(sizeof(*map), GFP_KERNEL);
  22550. + if (map == NULL) {
  22551. + pr_err("[%s]: failed allocating tracker\n",
  22552. + __func__);
  22553. + ret = -ENOMEM;
  22554. + goto error;
  22555. + } else {
  22556. + phys_addr = (uint32_t)resource->res_base_mem &
  22557. + 0x3FFFFFFF;
  22558. + phys_addr += mm_vc_mem_phys_addr;
  22559. + if (resource->res_cached
  22560. + == VMCS_SM_CACHE_HOST) {
  22561. + ioparam->addr = (long unsigned int)
  22562. + /* TODO - make cached work */
  22563. + ioremap_nocache(phys_addr,
  22564. + resource->res_size);
  22565. +
  22566. + pr_debug("[%s]: mapping kernel - guid %x, hdl %x - cached mapping %u\n",
  22567. + __func__, ioparam->handle,
  22568. + lock.res_handle, ioparam->addr);
  22569. + } else {
  22570. + ioparam->addr = (long unsigned int)
  22571. + ioremap_nocache(phys_addr,
  22572. + resource->res_size);
  22573. +
  22574. + pr_debug("[%s]: mapping kernel- guid %x, hdl %x - non cached mapping %u\n",
  22575. + __func__, ioparam->handle,
  22576. + lock.res_handle, ioparam->addr);
  22577. + }
  22578. +
  22579. + map->res_pid = 0;
  22580. + map->res_vc_hdl = resource->res_handle;
  22581. + map->res_usr_hdl = resource->res_guid;
  22582. + map->res_addr = ioparam->addr;
  22583. + map->resource = resource;
  22584. + map->vma = NULL;
  22585. +
  22586. + vmcs_sm_add_map(sm_state, resource, map);
  22587. + }
  22588. + } else
  22589. + ioparam->addr = 0;
  22590. + }
  22591. +
  22592. +error:
  22593. + if (resource)
  22594. + vmcs_sm_release_resource(resource, 0);
  22595. +
  22596. + return ret;
  22597. +}
  22598. +
  22599. +/* Unlock a previously allocated shared memory handle and block.
  22600. +*/
  22601. +static int vc_sm_ioctl_unlock(struct SM_PRIV_DATA_T *private,
  22602. + struct vmcs_sm_ioctl_lock_unlock *ioparam,
  22603. + int flush, int wait_reply, int no_vc_unlock)
  22604. +{
  22605. + int status;
  22606. + VC_SM_LOCK_UNLOCK_T unlock;
  22607. + struct sm_mmap *map, *map_tmp;
  22608. + struct SM_RESOURCE_T *resource;
  22609. + int ret = 0;
  22610. +
  22611. + map = NULL;
  22612. +
  22613. + /* Locate resource from GUID.
  22614. + */
  22615. + resource = vmcs_sm_acquire_resource(private, ioparam->handle);
  22616. + if (resource == NULL) {
  22617. + ret = -EINVAL;
  22618. + goto error;
  22619. + }
  22620. +
  22621. + /* Check permissions.
  22622. + */
  22623. + if (resource->pid && (resource->pid != current->tgid)) {
  22624. + pr_err("[%s]: current tgid %u != %u owner\n",
  22625. + __func__, current->tgid, resource->pid);
  22626. + ret = -EPERM;
  22627. + goto error;
  22628. + }
  22629. +
  22630. + unlock.res_handle = resource->res_handle;
  22631. + unlock.res_mem = resource->res_base_mem;
  22632. +
  22633. + pr_debug("[%s]: attempt to unlock data - guid %x, hdl %x, base address %p\n",
  22634. + __func__, ioparam->handle, unlock.res_handle, unlock.res_mem);
  22635. +
  22636. + /* User space allocated resources.
  22637. + */
  22638. + if (resource->pid) {
  22639. + /* Flush if requested */
  22640. + if (resource->res_cached && flush) {
  22641. + dma_addr_t phys_addr = 0;
  22642. + resource->res_stats[FLUSH]++;
  22643. +
  22644. + phys_addr =
  22645. + (dma_addr_t)((uint32_t)resource->res_base_mem &
  22646. + 0x3FFFFFFF);
  22647. + phys_addr += (dma_addr_t)mm_vc_mem_phys_addr;
  22648. +
  22649. + /* L1 cache flush */
  22650. + down_read(&current->mm->mmap_sem);
  22651. + list_for_each_entry(map, &resource->map_list,
  22652. + resource_map_list) {
  22653. + if (map->vma) {
  22654. + unsigned long start;
  22655. + unsigned long end;
  22656. + start = map->vma->vm_start;
  22657. + end = map->vma->vm_end;
  22658. +
  22659. + vcsm_vma_cache_clean_page_range(
  22660. + start, end);
  22661. + }
  22662. + }
  22663. + up_read(&current->mm->mmap_sem);
  22664. +
  22665. + /* L2 cache flush */
  22666. + outer_clean_range(phys_addr,
  22667. + phys_addr +
  22668. + (size_t) resource->res_size);
  22669. + }
  22670. +
  22671. + /* We need to zap all the vmas associated with this resource */
  22672. + if (resource->lock_count == 1) {
  22673. + down_read(&current->mm->mmap_sem);
  22674. + list_for_each_entry(map, &resource->map_list,
  22675. + resource_map_list) {
  22676. + if (map->vma) {
  22677. + zap_vma_ptes(map->vma,
  22678. + map->vma->vm_start,
  22679. + map->vma->vm_end -
  22680. + map->vma->vm_start);
  22681. + }
  22682. + }
  22683. + up_read(&current->mm->mmap_sem);
  22684. + }
  22685. + }
  22686. + /* Kernel allocated resources. */
  22687. + else {
  22688. + /* Global + Taken in this context */
  22689. + if (resource->ref_count == 2) {
  22690. + if (!list_empty(&resource->map_list)) {
  22691. + list_for_each_entry_safe(map, map_tmp,
  22692. + &resource->map_list,
  22693. + resource_map_list) {
  22694. + if (map->res_addr) {
  22695. + if (flush &&
  22696. + (resource->res_cached ==
  22697. + VMCS_SM_CACHE_HOST)) {
  22698. + long unsigned int
  22699. + phys_addr;
  22700. + phys_addr = (uint32_t)
  22701. + resource->res_base_mem & 0x3FFFFFFF;
  22702. + phys_addr +=
  22703. + mm_vc_mem_phys_addr;
  22704. +
  22705. + /* L1 cache flush */
  22706. + dmac_flush_range((const
  22707. + void
  22708. + *)
  22709. + map->res_addr, (const void *)
  22710. + (map->res_addr + resource->res_size));
  22711. +
  22712. + /* L2 cache flush */
  22713. + outer_clean_range
  22714. + (phys_addr,
  22715. + phys_addr +
  22716. + (size_t)
  22717. + resource->res_size);
  22718. + }
  22719. +
  22720. + iounmap((void *)map->res_addr);
  22721. + map->res_addr = 0;
  22722. +
  22723. + vmcs_sm_remove_map(sm_state,
  22724. + map->resource,
  22725. + map);
  22726. + break;
  22727. + }
  22728. + }
  22729. + }
  22730. + }
  22731. + }
  22732. +
  22733. + if (resource->lock_count) {
  22734. + /* Bypass the videocore unlock.
  22735. + */
  22736. + if (no_vc_unlock)
  22737. + status = 0;
  22738. + /* Unlock the videocore allocated resource.
  22739. + */
  22740. + else {
  22741. + status =
  22742. + vc_vchi_sm_unlock(sm_state->sm_handle, &unlock,
  22743. + &private->int_trans_id,
  22744. + wait_reply);
  22745. + if (status == -EINTR) {
  22746. + pr_debug("[%s]: requesting unlock memory action restart (trans_id: %u)\n",
  22747. + __func__, private->int_trans_id);
  22748. +
  22749. + ret = -ERESTARTSYS;
  22750. + resource->res_stats[UNLOCK]--;
  22751. + private->restart_sys = -EINTR;
  22752. + private->int_action = VC_SM_MSG_TYPE_UNLOCK;
  22753. + goto error;
  22754. + } else if (status != 0) {
  22755. + pr_err("[%s]: failed to unlock vc mem (status: %u, trans_id: %u)\n",
  22756. + __func__, status, private->int_trans_id);
  22757. +
  22758. + ret = -EPERM;
  22759. + resource->res_stats[UNLOCK_FAIL]++;
  22760. + goto error;
  22761. + }
  22762. + }
  22763. +
  22764. + resource->res_stats[UNLOCK]++;
  22765. + resource->lock_count--;
  22766. + }
  22767. +
  22768. + pr_debug("[%s]: success to unlock data - hdl %x, base address %p, ref-cnt %d\n",
  22769. + __func__, unlock.res_handle, unlock.res_mem,
  22770. + resource->lock_count);
  22771. +
  22772. +error:
  22773. + if (resource)
  22774. + vmcs_sm_release_resource(resource, 0);
  22775. +
  22776. + return ret;
  22777. +}
  22778. +
  22779. +/* Handle control from host. */
  22780. +static long vc_sm_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  22781. +{
  22782. + int ret = 0;
  22783. + unsigned int cmdnr = _IOC_NR(cmd);
  22784. + struct SM_PRIV_DATA_T *file_data =
  22785. + (struct SM_PRIV_DATA_T *)file->private_data;
  22786. + struct SM_RESOURCE_T *resource = NULL;
  22787. +
  22788. + /* Validate we can work with this device. */
  22789. + if ((sm_state == NULL) || (file_data == NULL)) {
  22790. + pr_err("[%s]: invalid device\n", __func__);
  22791. + ret = -EPERM;
  22792. + goto out;
  22793. + }
  22794. +
  22795. + pr_debug("[%s]: cmd %x tgid %u, owner %u\n", __func__, cmdnr,
  22796. + current->tgid, file_data->pid);
  22797. +
  22798. + /* Action is a re-post of a previously interrupted action? */
  22799. + if (file_data->restart_sys == -EINTR) {
  22800. + VC_SM_ACTION_CLEAN_T action_clean;
  22801. +
  22802. + pr_debug("[%s]: clean up of action %u (trans_id: %u) following EINTR\n",
  22803. + __func__, file_data->int_action,
  22804. + file_data->int_trans_id);
  22805. +
  22806. + action_clean.res_action = file_data->int_action;
  22807. + action_clean.action_trans_id = file_data->int_trans_id;
  22808. +
  22809. + vc_vchi_sm_clean_up(sm_state->sm_handle, &action_clean);
  22810. +
  22811. + file_data->restart_sys = 0;
  22812. + }
  22813. +
  22814. + /* Now process the command.
  22815. + */
  22816. + switch (cmdnr) {
  22817. + /* New memory allocation.
  22818. + */
  22819. + case VMCS_SM_CMD_ALLOC:
  22820. + {
  22821. + struct vmcs_sm_ioctl_alloc ioparam;
  22822. +
  22823. + /* Get the parameter data.
  22824. + */
  22825. + if (copy_from_user
  22826. + (&ioparam, (void *)arg, sizeof(ioparam)) != 0) {
  22827. + pr_err("[%s]: failed to copy-from-user for cmd %x\n",
  22828. + __func__, cmdnr);
  22829. + ret = -EFAULT;
  22830. + goto out;
  22831. + }
  22832. +
  22833. + ret = vc_sm_ioctl_alloc(file_data, &ioparam);
  22834. + if (!ret &&
  22835. + (copy_to_user((void *)arg,
  22836. + &ioparam, sizeof(ioparam)) != 0)) {
  22837. + struct vmcs_sm_ioctl_free freeparam = {
  22838. + ioparam.handle
  22839. + };
  22840. + pr_err("[%s]: failed to copy-to-user for cmd %x\n",
  22841. + __func__, cmdnr);
  22842. + vc_sm_ioctl_free(file_data, &freeparam);
  22843. + ret = -EFAULT;
  22844. + }
  22845. +
  22846. + /* Done.
  22847. + */
  22848. + goto out;
  22849. + }
  22850. + break;
  22851. +
  22852. + /* Share existing memory allocation.
  22853. + */
  22854. + case VMCS_SM_CMD_ALLOC_SHARE:
  22855. + {
  22856. + struct vmcs_sm_ioctl_alloc_share ioparam;
  22857. +
  22858. + /* Get the parameter data.
  22859. + */
  22860. + if (copy_from_user
  22861. + (&ioparam, (void *)arg, sizeof(ioparam)) != 0) {
  22862. + pr_err("[%s]: failed to copy-from-user for cmd %x\n",
  22863. + __func__, cmdnr);
  22864. + ret = -EFAULT;
  22865. + goto out;
  22866. + }
  22867. +
  22868. + ret = vc_sm_ioctl_alloc_share(file_data, &ioparam);
  22869. +
  22870. + /* Copy result back to user.
  22871. + */
  22872. + if (!ret
  22873. + && copy_to_user((void *)arg, &ioparam,
  22874. + sizeof(ioparam)) != 0) {
  22875. + struct vmcs_sm_ioctl_free freeparam = {
  22876. + ioparam.handle
  22877. + };
  22878. + pr_err("[%s]: failed to copy-to-user for cmd %x\n",
  22879. + __func__, cmdnr);
  22880. + vc_sm_ioctl_free(file_data, &freeparam);
  22881. + ret = -EFAULT;
  22882. + }
  22883. +
  22884. + /* Done.
  22885. + */
  22886. + goto out;
  22887. + }
  22888. + break;
  22889. +
  22890. + /* Lock (attempt to) *and* register a cache behavior change.
  22891. + */
  22892. + case VMCS_SM_CMD_LOCK_CACHE:
  22893. + {
  22894. + struct vmcs_sm_ioctl_lock_cache ioparam;
  22895. + struct vmcs_sm_ioctl_lock_unlock lock;
  22896. +
  22897. + /* Get parameter data.
  22898. + */
  22899. + if (copy_from_user
  22900. + (&ioparam, (void *)arg, sizeof(ioparam)) != 0) {
  22901. + pr_err("[%s]: failed to copy-from-user for cmd %x\n",
  22902. + __func__, cmdnr);
  22903. + ret = -EFAULT;
  22904. + goto out;
  22905. + }
  22906. +
  22907. + lock.handle = ioparam.handle;
  22908. + ret =
  22909. + vc_sm_ioctl_lock(file_data, &lock, 1,
  22910. + ioparam.cached, 0);
  22911. +
  22912. + /* Done.
  22913. + */
  22914. + goto out;
  22915. + }
  22916. + break;
  22917. +
  22918. + /* Lock (attempt to) existing memory allocation.
  22919. + */
  22920. + case VMCS_SM_CMD_LOCK:
  22921. + {
  22922. + struct vmcs_sm_ioctl_lock_unlock ioparam;
  22923. +
  22924. + /* Get parameter data.
  22925. + */
  22926. + if (copy_from_user
  22927. + (&ioparam, (void *)arg, sizeof(ioparam)) != 0) {
  22928. + pr_err("[%s]: failed to copy-from-user for cmd %x\n",
  22929. + __func__, cmdnr);
  22930. + ret = -EFAULT;
  22931. + goto out;
  22932. + }
  22933. +
  22934. + ret = vc_sm_ioctl_lock(file_data, &ioparam, 0, 0, 0);
  22935. +
  22936. + /* Copy result back to user.
  22937. + */
  22938. + if (copy_to_user((void *)arg, &ioparam, sizeof(ioparam))
  22939. + != 0) {
  22940. + pr_err("[%s]: failed to copy-to-user for cmd %x\n",
  22941. + __func__, cmdnr);
  22942. + ret = -EFAULT;
  22943. + }
  22944. +
  22945. + /* Done.
  22946. + */
  22947. + goto out;
  22948. + }
  22949. + break;
  22950. +
  22951. + /* Unlock (attempt to) existing memory allocation.
  22952. + */
  22953. + case VMCS_SM_CMD_UNLOCK:
  22954. + {
  22955. + struct vmcs_sm_ioctl_lock_unlock ioparam;
  22956. +
  22957. + /* Get parameter data.
  22958. + */
  22959. + if (copy_from_user
  22960. + (&ioparam, (void *)arg, sizeof(ioparam)) != 0) {
  22961. + pr_err("[%s]: failed to copy-from-user for cmd %x\n",
  22962. + __func__, cmdnr);
  22963. + ret = -EFAULT;
  22964. + goto out;
  22965. + }
  22966. +
  22967. + ret = vc_sm_ioctl_unlock(file_data, &ioparam, 0, 1, 0);
  22968. +
  22969. + /* Done.
  22970. + */
  22971. + goto out;
  22972. + }
  22973. + break;
  22974. +
  22975. + /* Resize (attempt to) existing memory allocation.
  22976. + */
  22977. + case VMCS_SM_CMD_RESIZE:
  22978. + {
  22979. + struct vmcs_sm_ioctl_resize ioparam;
  22980. +
  22981. + /* Get parameter data.
  22982. + */
  22983. + if (copy_from_user
  22984. + (&ioparam, (void *)arg, sizeof(ioparam)) != 0) {
  22985. + pr_err("[%s]: failed to copy-from-user for cmd %x\n",
  22986. + __func__, cmdnr);
  22987. + ret = -EFAULT;
  22988. + goto out;
  22989. + }
  22990. +
  22991. + ret = vc_sm_ioctl_resize(file_data, &ioparam);
  22992. +
  22993. + /* Copy result back to user.
  22994. + */
  22995. + if (copy_to_user((void *)arg, &ioparam, sizeof(ioparam))
  22996. + != 0) {
  22997. + pr_err("[%s]: failed to copy-to-user for cmd %x\n",
  22998. + __func__, cmdnr);
  22999. + ret = -EFAULT;
  23000. + }
  23001. +
  23002. + /* Done.
  23003. + */
  23004. + goto out;
  23005. + }
  23006. + break;
  23007. +
  23008. + /* Terminate existing memory allocation.
  23009. + */
  23010. + case VMCS_SM_CMD_FREE:
  23011. + {
  23012. + struct vmcs_sm_ioctl_free ioparam;
  23013. +
  23014. + /* Get parameter data.
  23015. + */
  23016. + if (copy_from_user
  23017. + (&ioparam, (void *)arg, sizeof(ioparam)) != 0) {
  23018. + pr_err("[%s]: failed to copy-from-user for cmd %x\n",
  23019. + __func__, cmdnr);
  23020. + ret = -EFAULT;
  23021. + goto out;
  23022. + }
  23023. +
  23024. + ret = vc_sm_ioctl_free(file_data, &ioparam);
  23025. +
  23026. + /* Done.
  23027. + */
  23028. + goto out;
  23029. + }
  23030. + break;
  23031. +
  23032. + /* Walk allocation on videocore, information shows up in the
  23033. + ** videocore log.
  23034. + */
  23035. + case VMCS_SM_CMD_VC_WALK_ALLOC:
  23036. + {
  23037. + pr_debug("[%s]: invoking walk alloc\n", __func__);
  23038. +
  23039. + if (vc_vchi_sm_walk_alloc(sm_state->sm_handle) != 0)
  23040. + pr_err("[%s]: failed to walk-alloc on videocore\n",
  23041. + __func__);
  23042. +
  23043. + /* Done.
  23044. + */
  23045. + goto out;
  23046. + }
  23047. + break;
  23048. +/* Walk mapping table on host, information shows up in the
  23049. + ** kernel log.
  23050. + */
  23051. + case VMCS_SM_CMD_HOST_WALK_MAP:
  23052. + {
  23053. + /* Use pid of -1 to tell to walk the whole map. */
  23054. + vmcs_sm_host_walk_map_per_pid(-1);
  23055. +
  23056. + /* Done. */
  23057. + goto out;
  23058. + }
  23059. + break;
  23060. +
  23061. + /* Walk mapping table per process on host. */
  23062. + case VMCS_SM_CMD_HOST_WALK_PID_ALLOC:
  23063. + {
  23064. + struct vmcs_sm_ioctl_walk ioparam;
  23065. +
  23066. + /* Get parameter data. */
  23067. + if (copy_from_user(&ioparam,
  23068. + (void *)arg, sizeof(ioparam)) != 0) {
  23069. + pr_err("[%s]: failed to copy-from-user for cmd %x\n",
  23070. + __func__, cmdnr);
  23071. + ret = -EFAULT;
  23072. + goto out;
  23073. + }
  23074. +
  23075. + vmcs_sm_host_walk_alloc(file_data);
  23076. +
  23077. + /* Done. */
  23078. + goto out;
  23079. + }
  23080. + break;
  23081. +
  23082. + /* Walk allocation per process on host. */
  23083. + case VMCS_SM_CMD_HOST_WALK_PID_MAP:
  23084. + {
  23085. + struct vmcs_sm_ioctl_walk ioparam;
  23086. +
  23087. + /* Get parameter data. */
  23088. + if (copy_from_user(&ioparam,
  23089. + (void *)arg, sizeof(ioparam)) != 0) {
  23090. + pr_err("[%s]: failed to copy-from-user for cmd %x\n",
  23091. + __func__, cmdnr);
  23092. + ret = -EFAULT;
  23093. + goto out;
  23094. + }
  23095. +
  23096. + vmcs_sm_host_walk_map_per_pid(ioparam.pid);
  23097. +
  23098. + /* Done. */
  23099. + goto out;
  23100. + }
  23101. + break;
  23102. +
  23103. + /* Gets the size of the memory associated with a user handle. */
  23104. + case VMCS_SM_CMD_SIZE_USR_HANDLE:
  23105. + {
  23106. + struct vmcs_sm_ioctl_size ioparam;
  23107. +
  23108. + /* Get parameter data. */
  23109. + if (copy_from_user(&ioparam,
  23110. + (void *)arg, sizeof(ioparam)) != 0) {
  23111. + pr_err("[%s]: failed to copy-from-user for cmd %x\n",
  23112. + __func__, cmdnr);
  23113. + ret = -EFAULT;
  23114. + goto out;
  23115. + }
  23116. +
  23117. + /* Locate resource from GUID. */
  23118. + resource =
  23119. + vmcs_sm_acquire_resource(file_data, ioparam.handle);
  23120. + if (resource != NULL) {
  23121. + ioparam.size = resource->res_size;
  23122. + vmcs_sm_release_resource(resource, 0);
  23123. + } else {
  23124. + ioparam.size = 0;
  23125. + }
  23126. +
  23127. + if (copy_to_user((void *)arg,
  23128. + &ioparam, sizeof(ioparam)) != 0) {
  23129. + pr_err("[%s]: failed to copy-to-user for cmd %x\n",
  23130. + __func__, cmdnr);
  23131. + ret = -EFAULT;
  23132. + }
  23133. +
  23134. + /* Done. */
  23135. + goto out;
  23136. + }
  23137. + break;
  23138. +
  23139. + /* Verify we are dealing with a valid resource. */
  23140. + case VMCS_SM_CMD_CHK_USR_HANDLE:
  23141. + {
  23142. + struct vmcs_sm_ioctl_chk ioparam;
  23143. +
  23144. + /* Get parameter data.
  23145. + */
  23146. + if (copy_from_user(&ioparam,
  23147. + (void *)arg, sizeof(ioparam)) != 0) {
  23148. + pr_err("[%s]: failed to copy-from-user for cmd %x\n",
  23149. + __func__, cmdnr);
  23150. +
  23151. + ret = -EFAULT;
  23152. + goto out;
  23153. + }
  23154. +
  23155. + /* Locate resource from GUID. */
  23156. + resource =
  23157. + vmcs_sm_acquire_resource(file_data, ioparam.handle);
  23158. + if (resource == NULL)
  23159. + ret = -EINVAL;
  23160. + /* If the resource is cacheable, return additional
  23161. + * information that may be needed to flush the cache.
  23162. + */
  23163. + else if ((resource->res_cached == VMCS_SM_CACHE_HOST) ||
  23164. + (resource->res_cached == VMCS_SM_CACHE_BOTH)) {
  23165. + ioparam.addr =
  23166. + vmcs_sm_usr_address_from_pid_and_usr_handle
  23167. + (current->tgid, ioparam.handle);
  23168. + ioparam.size = resource->res_size;
  23169. + ioparam.cache = resource->res_cached;
  23170. + } else {
  23171. + ioparam.addr = 0;
  23172. + ioparam.size = 0;
  23173. + ioparam.cache = resource->res_cached;
  23174. + }
  23175. +
  23176. + if (resource)
  23177. + vmcs_sm_release_resource(resource, 0);
  23178. +
  23179. + if (copy_to_user((void *)arg,
  23180. + &ioparam, sizeof(ioparam)) != 0) {
  23181. + pr_err("[%s]: failed to copy-to-user for cmd %x\n",
  23182. + __func__, cmdnr);
  23183. + ret = -EFAULT;
  23184. + }
  23185. +
  23186. + /* Done.
  23187. + */
  23188. + goto out;
  23189. + }
  23190. + break;
  23191. +
  23192. + /*
  23193. + * Maps a user handle given the process and the virtual address.
  23194. + */
  23195. + case VMCS_SM_CMD_MAPPED_USR_HANDLE:
  23196. + {
  23197. + struct vmcs_sm_ioctl_map ioparam;
  23198. +
  23199. + /* Get parameter data. */
  23200. + if (copy_from_user(&ioparam,
  23201. + (void *)arg, sizeof(ioparam)) != 0) {
  23202. + pr_err("[%s]: failed to copy-from-user for cmd %x\n",
  23203. + __func__, cmdnr);
  23204. +
  23205. + ret = -EFAULT;
  23206. + goto out;
  23207. + }
  23208. +
  23209. + ioparam.handle =
  23210. + vmcs_sm_usr_handle_from_pid_and_address(
  23211. + ioparam.pid, ioparam.addr);
  23212. +
  23213. + resource =
  23214. + vmcs_sm_acquire_resource(file_data, ioparam.handle);
  23215. + if ((resource != NULL)
  23216. + && ((resource->res_cached == VMCS_SM_CACHE_HOST)
  23217. + || (resource->res_cached ==
  23218. + VMCS_SM_CACHE_BOTH))) {
  23219. + ioparam.size = resource->res_size;
  23220. + } else {
  23221. + ioparam.size = 0;
  23222. + }
  23223. +
  23224. + if (resource)
  23225. + vmcs_sm_release_resource(resource, 0);
  23226. +
  23227. + if (copy_to_user((void *)arg,
  23228. + &ioparam, sizeof(ioparam)) != 0) {
  23229. + pr_err("[%s]: failed to copy-to-user for cmd %x\n",
  23230. + __func__, cmdnr);
  23231. + ret = -EFAULT;
  23232. + }
  23233. +
  23234. + /* Done. */
  23235. + goto out;
  23236. + }
  23237. + break;
  23238. +
  23239. + /*
  23240. + * Maps a videocore handle given process and virtual address.
  23241. + */
  23242. + case VMCS_SM_CMD_MAPPED_VC_HDL_FROM_ADDR:
  23243. + {
  23244. + struct vmcs_sm_ioctl_map ioparam;
  23245. +
  23246. + /* Get parameter data. */
  23247. + if (copy_from_user(&ioparam,
  23248. + (void *)arg, sizeof(ioparam)) != 0) {
  23249. + pr_err("[%s]: failed to copy-from-user for cmd %x\n",
  23250. + __func__, cmdnr);
  23251. + ret = -EFAULT;
  23252. + goto out;
  23253. + }
  23254. +
  23255. + ioparam.handle = vmcs_sm_vc_handle_from_pid_and_address(
  23256. + ioparam.pid, ioparam.addr);
  23257. +
  23258. + if (copy_to_user((void *)arg,
  23259. + &ioparam, sizeof(ioparam)) != 0) {
  23260. + pr_err("[%s]: failed to copy-to-user for cmd %x\n",
  23261. + __func__, cmdnr);
  23262. +
  23263. + ret = -EFAULT;
  23264. + }
  23265. +
  23266. + /* Done.
  23267. + */
  23268. + goto out;
  23269. + }
  23270. + break;
  23271. +
  23272. + /* Maps a videocore handle given process and user handle. */
  23273. + case VMCS_SM_CMD_MAPPED_VC_HDL_FROM_HDL:
  23274. + {
  23275. + struct vmcs_sm_ioctl_map ioparam;
  23276. +
  23277. + /* Get parameter data. */
  23278. + if (copy_from_user(&ioparam,
  23279. + (void *)arg, sizeof(ioparam)) != 0) {
  23280. + pr_err("[%s]: failed to copy-from-user for cmd %x\n",
  23281. + __func__, cmdnr);
  23282. + ret = -EFAULT;
  23283. + goto out;
  23284. + }
  23285. +
  23286. + /* Locate resource from GUID. */
  23287. + resource =
  23288. + vmcs_sm_acquire_resource(file_data, ioparam.handle);
  23289. + if (resource != NULL) {
  23290. + ioparam.handle = resource->res_handle;
  23291. + vmcs_sm_release_resource(resource, 0);
  23292. + } else {
  23293. + ioparam.handle = 0;
  23294. + }
  23295. +
  23296. + if (copy_to_user((void *)arg,
  23297. + &ioparam, sizeof(ioparam)) != 0) {
  23298. + pr_err("[%s]: failed to copy-to-user for cmd %x\n",
  23299. + __func__, cmdnr);
  23300. +
  23301. + ret = -EFAULT;
  23302. + }
  23303. +
  23304. + /* Done. */
  23305. + goto out;
  23306. + }
  23307. + break;
  23308. +
  23309. + /*
  23310. + * Maps a videocore address given process and videocore handle.
  23311. + */
  23312. + case VMCS_SM_CMD_MAPPED_VC_ADDR_FROM_HDL:
  23313. + {
  23314. + struct vmcs_sm_ioctl_map ioparam;
  23315. +
  23316. + /* Get parameter data. */
  23317. + if (copy_from_user(&ioparam,
  23318. + (void *)arg, sizeof(ioparam)) != 0) {
  23319. + pr_err("[%s]: failed to copy-from-user for cmd %x\n",
  23320. + __func__, cmdnr);
  23321. +
  23322. + ret = -EFAULT;
  23323. + goto out;
  23324. + }
  23325. +
  23326. + /* Locate resource from GUID. */
  23327. + resource =
  23328. + vmcs_sm_acquire_resource(file_data, ioparam.handle);
  23329. + if (resource != NULL) {
  23330. + ioparam.addr =
  23331. + (unsigned int)resource->res_base_mem;
  23332. + vmcs_sm_release_resource(resource, 0);
  23333. + } else {
  23334. + ioparam.addr = 0;
  23335. + }
  23336. +
  23337. + if (copy_to_user((void *)arg,
  23338. + &ioparam, sizeof(ioparam)) != 0) {
  23339. + pr_err("[%s]: failed to copy-to-user for cmd %x\n",
  23340. + __func__, cmdnr);
  23341. + ret = -EFAULT;
  23342. + }
  23343. +
  23344. + /* Done. */
  23345. + goto out;
  23346. + }
  23347. + break;
  23348. +
  23349. + /* Maps a user address given process and vc handle.
  23350. + */
  23351. + case VMCS_SM_CMD_MAPPED_USR_ADDRESS:
  23352. + {
  23353. + struct vmcs_sm_ioctl_map ioparam;
  23354. +
  23355. + /* Get parameter data. */
  23356. + if (copy_from_user(&ioparam,
  23357. + (void *)arg, sizeof(ioparam)) != 0) {
  23358. + pr_err("[%s]: failed to copy-from-user for cmd %x\n",
  23359. + __func__, cmdnr);
  23360. + ret = -EFAULT;
  23361. + goto out;
  23362. + }
  23363. +
  23364. + /*
  23365. + * Return the address information from the mapping,
  23366. + * 0 (ie NULL) if it cannot locate the actual mapping.
  23367. + */
  23368. + ioparam.addr =
  23369. + vmcs_sm_usr_address_from_pid_and_usr_handle
  23370. + (ioparam.pid, ioparam.handle);
  23371. +
  23372. + if (copy_to_user((void *)arg,
  23373. + &ioparam, sizeof(ioparam)) != 0) {
  23374. + pr_err("[%s]: failed to copy-to-user for cmd %x\n",
  23375. + __func__, cmdnr);
  23376. + ret = -EFAULT;
  23377. + }
  23378. +
  23379. + /* Done. */
  23380. + goto out;
  23381. + }
  23382. + break;
  23383. +
  23384. + /* Flush the cache for a given mapping. */
  23385. + case VMCS_SM_CMD_FLUSH:
  23386. + {
  23387. + struct vmcs_sm_ioctl_cache ioparam;
  23388. +
  23389. + /* Get parameter data. */
  23390. + if (copy_from_user(&ioparam,
  23391. + (void *)arg, sizeof(ioparam)) != 0) {
  23392. + pr_err("[%s]: failed to copy-from-user for cmd %x\n",
  23393. + __func__, cmdnr);
  23394. + ret = -EFAULT;
  23395. + goto out;
  23396. + }
  23397. +
  23398. + /* Locate resource from GUID. */
  23399. + resource =
  23400. + vmcs_sm_acquire_resource(file_data, ioparam.handle);
  23401. +
  23402. + if ((resource != NULL) && resource->res_cached) {
  23403. + dma_addr_t phys_addr = 0;
  23404. +
  23405. + resource->res_stats[FLUSH]++;
  23406. +
  23407. + phys_addr =
  23408. + (dma_addr_t)((uint32_t)
  23409. + resource->res_base_mem &
  23410. + 0x3FFFFFFF);
  23411. + phys_addr += (dma_addr_t)mm_vc_mem_phys_addr;
  23412. +
  23413. + /* L1 cache flush */
  23414. + down_read(&current->mm->mmap_sem);
  23415. + vcsm_vma_cache_clean_page_range((unsigned long)
  23416. + ioparam.addr,
  23417. + (unsigned long)
  23418. + ioparam.addr +
  23419. + ioparam.size);
  23420. + up_read(&current->mm->mmap_sem);
  23421. +
  23422. + /* L2 cache flush */
  23423. + outer_clean_range(phys_addr,
  23424. + phys_addr +
  23425. + (size_t) ioparam.size);
  23426. + } else if (resource == NULL) {
  23427. + ret = -EINVAL;
  23428. + goto out;
  23429. + }
  23430. +
  23431. + if (resource)
  23432. + vmcs_sm_release_resource(resource, 0);
  23433. +
  23434. + /* Done. */
  23435. + goto out;
  23436. + }
  23437. + break;
  23438. +
  23439. + /* Invalidate the cache for a given mapping. */
  23440. + case VMCS_SM_CMD_INVALID:
  23441. + {
  23442. + struct vmcs_sm_ioctl_cache ioparam;
  23443. +
  23444. + /* Get parameter data. */
  23445. + if (copy_from_user(&ioparam,
  23446. + (void *)arg, sizeof(ioparam)) != 0) {
  23447. + pr_err("[%s]: failed to copy-from-user for cmd %x\n",
  23448. + __func__, cmdnr);
  23449. + ret = -EFAULT;
  23450. + goto out;
  23451. + }
  23452. +
  23453. + /* Locate resource from GUID.
  23454. + */
  23455. + resource =
  23456. + vmcs_sm_acquire_resource(file_data, ioparam.handle);
  23457. +
  23458. + if ((resource != NULL) && resource->res_cached) {
  23459. + dma_addr_t phys_addr = 0;
  23460. +
  23461. + resource->res_stats[INVALID]++;
  23462. +
  23463. + phys_addr =
  23464. + (dma_addr_t)((uint32_t)
  23465. + resource->res_base_mem &
  23466. + 0x3FFFFFFF);
  23467. + phys_addr += (dma_addr_t)mm_vc_mem_phys_addr;
  23468. +
  23469. + /* L2 cache invalidate */
  23470. + outer_inv_range(phys_addr,
  23471. + phys_addr +
  23472. + (size_t) ioparam.size);
  23473. +
  23474. + /* L1 cache invalidate */
  23475. + down_read(&current->mm->mmap_sem);
  23476. + vcsm_vma_cache_clean_page_range((unsigned long)
  23477. + ioparam.addr,
  23478. + (unsigned long)
  23479. + ioparam.addr +
  23480. + ioparam.size);
  23481. + up_read(&current->mm->mmap_sem);
  23482. + } else if (resource == NULL) {
  23483. + ret = -EINVAL;
  23484. + goto out;
  23485. + }
  23486. +
  23487. + if (resource)
  23488. + vmcs_sm_release_resource(resource, 0);
  23489. +
  23490. + /* Done.
  23491. + */
  23492. + goto out;
  23493. + }
  23494. + break;
  23495. +
  23496. + default:
  23497. + {
  23498. + ret = -EINVAL;
  23499. + goto out;
  23500. + }
  23501. + break;
  23502. + }
  23503. +
  23504. +out:
  23505. + return ret;
  23506. +}
  23507. +
  23508. +/* Device operations that we managed in this driver.
  23509. +*/
  23510. +static const struct file_operations vmcs_sm_ops = {
  23511. + .owner = THIS_MODULE,
  23512. + .unlocked_ioctl = vc_sm_ioctl,
  23513. + .open = vc_sm_open,
  23514. + .release = vc_sm_release,
  23515. + .mmap = vc_sm_mmap,
  23516. +};
  23517. +
  23518. +/* Creation of device.
  23519. +*/
  23520. +static int vc_sm_create_sharedmemory(void)
  23521. +{
  23522. + int ret;
  23523. +
  23524. + if (sm_state == NULL) {
  23525. + ret = -ENOMEM;
  23526. + goto out;
  23527. + }
  23528. +
  23529. + /* Create a device class for creating dev nodes.
  23530. + */
  23531. + sm_state->sm_class = class_create(THIS_MODULE, "vc-sm");
  23532. + if (IS_ERR(sm_state->sm_class)) {
  23533. + pr_err("[%s]: unable to create device class\n", __func__);
  23534. + ret = PTR_ERR(sm_state->sm_class);
  23535. + goto out;
  23536. + }
  23537. +
  23538. + /* Create a character driver.
  23539. + */
  23540. + ret = alloc_chrdev_region(&sm_state->sm_devid,
  23541. + DEVICE_MINOR, 1, DEVICE_NAME);
  23542. + if (ret != 0) {
  23543. + pr_err("[%s]: unable to allocate device number\n", __func__);
  23544. + goto out_dev_class_destroy;
  23545. + }
  23546. +
  23547. + cdev_init(&sm_state->sm_cdev, &vmcs_sm_ops);
  23548. + ret = cdev_add(&sm_state->sm_cdev, sm_state->sm_devid, 1);
  23549. + if (ret != 0) {
  23550. + pr_err("[%s]: unable to register device\n", __func__);
  23551. + goto out_chrdev_unreg;
  23552. + }
  23553. +
  23554. + /* Create a device node.
  23555. + */
  23556. + sm_state->sm_dev = device_create(sm_state->sm_class,
  23557. + NULL,
  23558. + MKDEV(MAJOR(sm_state->sm_devid),
  23559. + DEVICE_MINOR), NULL,
  23560. + DEVICE_NAME);
  23561. + if (IS_ERR(sm_state->sm_dev)) {
  23562. + pr_err("[%s]: unable to create device node\n", __func__);
  23563. + ret = PTR_ERR(sm_state->sm_dev);
  23564. + goto out_chrdev_del;
  23565. + }
  23566. +
  23567. + goto out;
  23568. +
  23569. +out_chrdev_del:
  23570. + cdev_del(&sm_state->sm_cdev);
  23571. +out_chrdev_unreg:
  23572. + unregister_chrdev_region(sm_state->sm_devid, 1);
  23573. +out_dev_class_destroy:
  23574. + class_destroy(sm_state->sm_class);
  23575. + sm_state->sm_class = NULL;
  23576. +out:
  23577. + return ret;
  23578. +}
  23579. +
  23580. +/* Termination of the device.
  23581. +*/
  23582. +static int vc_sm_remove_sharedmemory(void)
  23583. +{
  23584. + int ret;
  23585. +
  23586. + if (sm_state == NULL) {
  23587. + /* Nothing to do.
  23588. + */
  23589. + ret = 0;
  23590. + goto out;
  23591. + }
  23592. +
  23593. + /* Remove the sharedmemory character driver.
  23594. + */
  23595. + cdev_del(&sm_state->sm_cdev);
  23596. +
  23597. + /* Unregister region.
  23598. + */
  23599. + unregister_chrdev_region(sm_state->sm_devid, 1);
  23600. +
  23601. + ret = 0;
  23602. + goto out;
  23603. +
  23604. +out:
  23605. + return ret;
  23606. +}
  23607. +
  23608. +/* Videocore connected. */
  23609. +static void vc_sm_connected_init(void)
  23610. +{
  23611. + int ret;
  23612. + VCHI_INSTANCE_T vchi_instance;
  23613. + VCHI_CONNECTION_T *vchi_connection = NULL;
  23614. +
  23615. + pr_info("[%s]: start\n", __func__);
  23616. +
  23617. + /* Allocate memory for the state structure.
  23618. + */
  23619. + sm_state = kzalloc(sizeof(struct SM_STATE_T), GFP_KERNEL);
  23620. + if (sm_state == NULL) {
  23621. + pr_err("[%s]: failed to allocate memory\n", __func__);
  23622. + ret = -ENOMEM;
  23623. + goto out;
  23624. + }
  23625. +
  23626. + mutex_init(&sm_state->lock);
  23627. + mutex_init(&sm_state->map_lock);
  23628. +
  23629. + /* Initialize and create a VCHI connection for the shared memory service
  23630. + ** running on videocore.
  23631. + */
  23632. + ret = vchi_initialise(&vchi_instance);
  23633. + if (ret != 0) {
  23634. + pr_err("[%s]: failed to initialise VCHI instance (ret=%d)\n",
  23635. + __func__, ret);
  23636. +
  23637. + ret = -EIO;
  23638. + goto err_free_mem;
  23639. + }
  23640. +
  23641. + ret = vchi_connect(NULL, 0, vchi_instance);
  23642. + if (ret != 0) {
  23643. + pr_err("[%s]: failed to connect VCHI instance (ret=%d)\n",
  23644. + __func__, ret);
  23645. +
  23646. + ret = -EIO;
  23647. + goto err_free_mem;
  23648. + }
  23649. +
  23650. + /* Initialize an instance of the shared memory service. */
  23651. + sm_state->sm_handle =
  23652. + vc_vchi_sm_init(vchi_instance, &vchi_connection, 1);
  23653. + if (sm_state->sm_handle == NULL) {
  23654. + pr_err("[%s]: failed to initialize shared memory service\n",
  23655. + __func__);
  23656. +
  23657. + ret = -EPERM;
  23658. + goto err_free_mem;
  23659. + }
  23660. +
  23661. + /* Create a debug fs directory entry (root). */
  23662. + sm_state->dir_root = debugfs_create_dir(VC_SM_DIR_ROOT_NAME, NULL);
  23663. + if (!sm_state->dir_root) {
  23664. + pr_err("[%s]: failed to create \'%s\' directory entry\n",
  23665. + __func__, VC_SM_DIR_ROOT_NAME);
  23666. +
  23667. + ret = -EPERM;
  23668. + goto err_stop_sm_service;
  23669. + }
  23670. +
  23671. + sm_state->dir_state.show = &vc_sm_global_state_show;
  23672. + sm_state->dir_state.dir_entry = debugfs_create_file(VC_SM_STATE,
  23673. + S_IRUGO, sm_state->dir_root, &sm_state->dir_state,
  23674. + &vc_sm_debug_fs_fops);
  23675. +
  23676. + sm_state->dir_stats.show = &vc_sm_global_statistics_show;
  23677. + sm_state->dir_stats.dir_entry = debugfs_create_file(VC_SM_STATS,
  23678. + S_IRUGO, sm_state->dir_root, &sm_state->dir_stats,
  23679. + &vc_sm_debug_fs_fops);
  23680. +
  23681. + /* Create the proc entry children. */
  23682. + sm_state->dir_alloc = debugfs_create_dir(VC_SM_DIR_ALLOC_NAME,
  23683. + sm_state->dir_root);
  23684. +
  23685. + /* Create a shared memory device. */
  23686. + ret = vc_sm_create_sharedmemory();
  23687. + if (ret != 0) {
  23688. + pr_err("[%s]: failed to create shared memory device\n",
  23689. + __func__);
  23690. + goto err_remove_debugfs;
  23691. + }
  23692. +
  23693. + INIT_LIST_HEAD(&sm_state->map_list);
  23694. + INIT_LIST_HEAD(&sm_state->resource_list);
  23695. +
  23696. + sm_state->data_knl = vc_sm_create_priv_data(0);
  23697. + if (sm_state->data_knl == NULL) {
  23698. + pr_err("[%s]: failed to create kernel private data tracker\n",
  23699. + __func__);
  23700. + goto err_remove_shared_memory;
  23701. + }
  23702. +
  23703. + /* Done!
  23704. + */
  23705. + sm_inited = 1;
  23706. + goto out;
  23707. +
  23708. +err_remove_shared_memory:
  23709. + vc_sm_remove_sharedmemory();
  23710. +err_remove_debugfs:
  23711. + debugfs_remove_recursive(sm_state->dir_root);
  23712. +err_stop_sm_service:
  23713. + vc_vchi_sm_stop(&sm_state->sm_handle);
  23714. +err_free_mem:
  23715. + kfree(sm_state);
  23716. +out:
  23717. + pr_info("[%s]: end - returning %d\n", __func__, ret);
  23718. +}
  23719. +
  23720. +/* Driver loading. */
  23721. +static int __init vc_sm_init(void)
  23722. +{
  23723. + pr_info("vc-sm: Videocore shared memory driver\n");
  23724. + vchiq_add_connected_callback(vc_sm_connected_init);
  23725. + return 0;
  23726. +}
  23727. +
  23728. +/* Driver unloading. */
  23729. +static void __exit vc_sm_exit(void)
  23730. +{
  23731. + pr_debug("[%s]: start\n", __func__);
  23732. + if (sm_inited) {
  23733. + /* Remove shared memory device.
  23734. + */
  23735. + vc_sm_remove_sharedmemory();
  23736. +
  23737. + /* Remove all proc entries.
  23738. + */
  23739. + debugfs_remove_recursive(sm_state->dir_root);
  23740. +
  23741. + /* Stop the videocore shared memory service.
  23742. + */
  23743. + vc_vchi_sm_stop(&sm_state->sm_handle);
  23744. +
  23745. + /* Free the memory for the state structure.
  23746. + */
  23747. + mutex_destroy(&(sm_state->map_lock));
  23748. + kfree(sm_state);
  23749. + }
  23750. +
  23751. + pr_debug("[%s]: end\n", __func__);
  23752. +}
  23753. +
  23754. +#if defined(__KERNEL__)
  23755. +/* Allocate a shared memory handle and block. */
  23756. +int vc_sm_alloc(VC_SM_ALLOC_T *alloc, int *handle)
  23757. +{
  23758. + struct vmcs_sm_ioctl_alloc ioparam = { 0 };
  23759. + int ret;
  23760. + struct SM_RESOURCE_T *resource;
  23761. +
  23762. + /* Validate we can work with this device.
  23763. + */
  23764. + if (sm_state == NULL || alloc == NULL || handle == NULL) {
  23765. + pr_err("[%s]: invalid input\n", __func__);
  23766. + return -EPERM;
  23767. + }
  23768. +
  23769. + ioparam.size = alloc->base_unit;
  23770. + ioparam.num = alloc->num_unit;
  23771. + ioparam.cached =
  23772. + alloc->type == VC_SM_ALLOC_CACHED ? VMCS_SM_CACHE_VC : 0;
  23773. +
  23774. + ret = vc_sm_ioctl_alloc(sm_state->data_knl, &ioparam);
  23775. +
  23776. + if (ret == 0) {
  23777. + resource =
  23778. + vmcs_sm_acquire_resource(sm_state->data_knl,
  23779. + ioparam.handle);
  23780. + if (resource) {
  23781. + resource->pid = 0;
  23782. + vmcs_sm_release_resource(resource, 0);
  23783. +
  23784. + /* Assign valid handle at this time.
  23785. + */
  23786. + *handle = ioparam.handle;
  23787. + } else {
  23788. + ret = -ENOMEM;
  23789. + }
  23790. + }
  23791. +
  23792. + return ret;
  23793. +}
  23794. +EXPORT_SYMBOL_GPL(vc_sm_alloc);
  23795. +
  23796. +/* Get an internal resource handle mapped from the external one.
  23797. +*/
  23798. +int vc_sm_int_handle(int handle)
  23799. +{
  23800. + struct SM_RESOURCE_T *resource;
  23801. + int ret = 0;
  23802. +
  23803. + /* Validate we can work with this device.
  23804. + */
  23805. + if (sm_state == NULL || handle == 0) {
  23806. + pr_err("[%s]: invalid input\n", __func__);
  23807. + return 0;
  23808. + }
  23809. +
  23810. + /* Locate resource from GUID.
  23811. + */
  23812. + resource = vmcs_sm_acquire_resource(sm_state->data_knl, handle);
  23813. + if (resource) {
  23814. + ret = resource->res_handle;
  23815. + vmcs_sm_release_resource(resource, 0);
  23816. + }
  23817. +
  23818. + return ret;
  23819. +}
  23820. +EXPORT_SYMBOL_GPL(vc_sm_int_handle);
  23821. +
  23822. +/* Free a previously allocated shared memory handle and block.
  23823. +*/
  23824. +int vc_sm_free(int handle)
  23825. +{
  23826. + struct vmcs_sm_ioctl_free ioparam = { handle };
  23827. +
  23828. + /* Validate we can work with this device.
  23829. + */
  23830. + if (sm_state == NULL || handle == 0) {
  23831. + pr_err("[%s]: invalid input\n", __func__);
  23832. + return -EPERM;
  23833. + }
  23834. +
  23835. + return vc_sm_ioctl_free(sm_state->data_knl, &ioparam);
  23836. +}
  23837. +EXPORT_SYMBOL_GPL(vc_sm_free);
  23838. +
  23839. +/* Lock a memory handle for use by kernel.
  23840. +*/
  23841. +int vc_sm_lock(int handle, VC_SM_LOCK_CACHE_MODE_T mode,
  23842. + long unsigned int *data)
  23843. +{
  23844. + struct vmcs_sm_ioctl_lock_unlock ioparam;
  23845. + int ret;
  23846. +
  23847. + /* Validate we can work with this device.
  23848. + */
  23849. + if (sm_state == NULL || handle == 0 || data == NULL) {
  23850. + pr_err("[%s]: invalid input\n", __func__);
  23851. + return -EPERM;
  23852. + }
  23853. +
  23854. + *data = 0;
  23855. +
  23856. + ioparam.handle = handle;
  23857. + ret = vc_sm_ioctl_lock(sm_state->data_knl,
  23858. + &ioparam,
  23859. + 1,
  23860. + ((mode ==
  23861. + VC_SM_LOCK_CACHED) ? VMCS_SM_CACHE_HOST :
  23862. + VMCS_SM_CACHE_NONE), 0);
  23863. +
  23864. + *data = ioparam.addr;
  23865. + return ret;
  23866. +}
  23867. +EXPORT_SYMBOL_GPL(vc_sm_lock);
  23868. +
  23869. +/* Unlock a memory handle in use by kernel.
  23870. +*/
  23871. +int vc_sm_unlock(int handle, int flush, int no_vc_unlock)
  23872. +{
  23873. + struct vmcs_sm_ioctl_lock_unlock ioparam;
  23874. +
  23875. + /* Validate we can work with this device.
  23876. + */
  23877. + if (sm_state == NULL || handle == 0) {
  23878. + pr_err("[%s]: invalid input\n", __func__);
  23879. + return -EPERM;
  23880. + }
  23881. +
  23882. + ioparam.handle = handle;
  23883. + return vc_sm_ioctl_unlock(sm_state->data_knl,
  23884. + &ioparam, flush, 0, no_vc_unlock);
  23885. +}
  23886. +EXPORT_SYMBOL_GPL(vc_sm_unlock);
  23887. +
  23888. +/* Map a shared memory region for use by kernel.
  23889. +*/
  23890. +int vc_sm_map(int handle, unsigned int sm_addr, VC_SM_LOCK_CACHE_MODE_T mode,
  23891. + long unsigned int *data)
  23892. +{
  23893. + struct vmcs_sm_ioctl_lock_unlock ioparam;
  23894. + int ret;
  23895. +
  23896. + /* Validate we can work with this device.
  23897. + */
  23898. + if (sm_state == NULL || handle == 0 || data == NULL || sm_addr == 0) {
  23899. + pr_err("[%s]: invalid input\n", __func__);
  23900. + return -EPERM;
  23901. + }
  23902. +
  23903. + *data = 0;
  23904. +
  23905. + ioparam.handle = handle;
  23906. + ret = vc_sm_ioctl_lock(sm_state->data_knl,
  23907. + &ioparam,
  23908. + 1,
  23909. + ((mode ==
  23910. + VC_SM_LOCK_CACHED) ? VMCS_SM_CACHE_HOST :
  23911. + VMCS_SM_CACHE_NONE), sm_addr);
  23912. +
  23913. + *data = ioparam.addr;
  23914. + return ret;
  23915. +}
  23916. +EXPORT_SYMBOL_GPL(vc_sm_map);
  23917. +#endif
  23918. +
  23919. +late_initcall(vc_sm_init);
  23920. +module_exit(vc_sm_exit);
  23921. +
  23922. +MODULE_AUTHOR("Broadcom");
  23923. +MODULE_DESCRIPTION("VideoCore SharedMemory Driver");
  23924. +MODULE_LICENSE("GPL v2");
  23925. diff -Nur linux-3.18.8/drivers/char/hw_random/bcm2708-rng.c linux-rpi/drivers/char/hw_random/bcm2708-rng.c
  23926. --- linux-3.18.8/drivers/char/hw_random/bcm2708-rng.c 1970-01-01 01:00:00.000000000 +0100
  23927. +++ linux-rpi/drivers/char/hw_random/bcm2708-rng.c 2015-03-05 14:40:12.661715830 +0100
  23928. @@ -0,0 +1,118 @@
  23929. +/**
  23930. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  23931. + *
  23932. + * Redistribution and use in source and binary forms, with or without
  23933. + * modification, are permitted provided that the following conditions
  23934. + * are met:
  23935. + * 1. Redistributions of source code must retain the above copyright
  23936. + * notice, this list of conditions, and the following disclaimer,
  23937. + * without modification.
  23938. + * 2. Redistributions in binary form must reproduce the above copyright
  23939. + * notice, this list of conditions and the following disclaimer in the
  23940. + * documentation and/or other materials provided with the distribution.
  23941. + * 3. The names of the above-listed copyright holders may not be used
  23942. + * to endorse or promote products derived from this software without
  23943. + * specific prior written permission.
  23944. + *
  23945. + * ALTERNATIVELY, this software may be distributed under the terms of the
  23946. + * GNU General Public License ("GPL") version 2, as published by the Free
  23947. + * Software Foundation.
  23948. + *
  23949. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  23950. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  23951. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  23952. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  23953. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  23954. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  23955. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  23956. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  23957. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  23958. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  23959. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23960. + */
  23961. +
  23962. +#include <linux/kernel.h>
  23963. +#include <linux/module.h>
  23964. +#include <linux/init.h>
  23965. +#include <linux/hw_random.h>
  23966. +#include <linux/printk.h>
  23967. +
  23968. +#include <asm/io.h>
  23969. +#include <mach/hardware.h>
  23970. +#include <mach/platform.h>
  23971. +
  23972. +#define RNG_CTRL (0x0)
  23973. +#define RNG_STATUS (0x4)
  23974. +#define RNG_DATA (0x8)
  23975. +#define RNG_FF_THRESHOLD (0xc)
  23976. +
  23977. +/* enable rng */
  23978. +#define RNG_RBGEN 0x1
  23979. +/* double speed, less random mode */
  23980. +#define RNG_RBG2X 0x2
  23981. +
  23982. +/* the initial numbers generated are "less random" so will be discarded */
  23983. +#define RNG_WARMUP_COUNT 0x40000
  23984. +
  23985. +static int bcm2708_rng_data_read(struct hwrng *rng, u32 *buffer)
  23986. +{
  23987. + void __iomem *rng_base = (void __iomem *)rng->priv;
  23988. + unsigned words;
  23989. + /* wait for a random number to be in fifo */
  23990. + do {
  23991. + words = __raw_readl(rng_base + RNG_STATUS)>>24;
  23992. + }
  23993. + while (words == 0);
  23994. + /* read the random number */
  23995. + *buffer = __raw_readl(rng_base + RNG_DATA);
  23996. + return 4;
  23997. +}
  23998. +
  23999. +static struct hwrng bcm2708_rng_ops = {
  24000. + .name = "bcm2708",
  24001. + .data_read = bcm2708_rng_data_read,
  24002. +};
  24003. +
  24004. +static int __init bcm2708_rng_init(void)
  24005. +{
  24006. + void __iomem *rng_base;
  24007. + int err;
  24008. +
  24009. + /* map peripheral */
  24010. + rng_base = ioremap(RNG_BASE, 0x10);
  24011. + pr_info("bcm2708_rng_init=%p\n", rng_base);
  24012. + if (!rng_base) {
  24013. + pr_err("bcm2708_rng_init failed to ioremap\n");
  24014. + return -ENOMEM;
  24015. + }
  24016. + bcm2708_rng_ops.priv = (unsigned long)rng_base;
  24017. +
  24018. + /* set warm-up count & enable */
  24019. + __raw_writel(RNG_WARMUP_COUNT, rng_base + RNG_STATUS);
  24020. + __raw_writel(RNG_RBGEN, rng_base + RNG_CTRL);
  24021. +
  24022. + /* register driver */
  24023. + err = hwrng_register(&bcm2708_rng_ops);
  24024. + if (err) {
  24025. + pr_err("bcm2708_rng_init hwrng_register()=%d\n", err);
  24026. + iounmap(rng_base);
  24027. + }
  24028. + return err;
  24029. +}
  24030. +
  24031. +static void __exit bcm2708_rng_exit(void)
  24032. +{
  24033. + void __iomem *rng_base = (void __iomem *)bcm2708_rng_ops.priv;
  24034. + pr_info("bcm2708_rng_exit\n");
  24035. + /* disable rng hardware */
  24036. + __raw_writel(0, rng_base + RNG_CTRL);
  24037. + /* unregister driver */
  24038. + hwrng_unregister(&bcm2708_rng_ops);
  24039. + iounmap(rng_base);
  24040. +}
  24041. +
  24042. +module_init(bcm2708_rng_init);
  24043. +module_exit(bcm2708_rng_exit);
  24044. +
  24045. +MODULE_DESCRIPTION("BCM2708 H/W Random Number Generator (RNG) driver");
  24046. +MODULE_LICENSE("GPL and additional rights");
  24047. diff -Nur linux-3.18.8/drivers/char/hw_random/Kconfig linux-rpi/drivers/char/hw_random/Kconfig
  24048. --- linux-3.18.8/drivers/char/hw_random/Kconfig 2015-02-27 02:49:36.000000000 +0100
  24049. +++ linux-rpi/drivers/char/hw_random/Kconfig 2015-03-05 14:40:12.661715830 +0100
  24050. @@ -320,6 +320,17 @@
  24051. If unsure, say Y.
  24052. +config HW_RANDOM_BCM2708
  24053. + tristate "BCM2708 generic true random number generator support"
  24054. + depends on HW_RANDOM && (ARCH_BCM2708 || ARCH_BCM2709)
  24055. + ---help---
  24056. + This driver provides the kernel-side support for the BCM2708 hardware.
  24057. +
  24058. + To compile this driver as a module, choose M here: the
  24059. + module will be called bcm2708-rng.
  24060. +
  24061. + If unsure, say N.
  24062. +
  24063. config HW_RANDOM_MSM
  24064. tristate "Qualcomm SoCs Random Number Generator support"
  24065. depends on HW_RANDOM && ARCH_QCOM
  24066. diff -Nur linux-3.18.8/drivers/char/hw_random/Makefile linux-rpi/drivers/char/hw_random/Makefile
  24067. --- linux-3.18.8/drivers/char/hw_random/Makefile 2015-02-27 02:49:36.000000000 +0100
  24068. +++ linux-rpi/drivers/char/hw_random/Makefile 2015-03-05 14:40:12.661715830 +0100
  24069. @@ -28,5 +28,6 @@
  24070. obj-$(CONFIG_HW_RANDOM_EXYNOS) += exynos-rng.o
  24071. obj-$(CONFIG_HW_RANDOM_TPM) += tpm-rng.o
  24072. obj-$(CONFIG_HW_RANDOM_BCM2835) += bcm2835-rng.o
  24073. +obj-$(CONFIG_HW_RANDOM_BCM2708) += bcm2708-rng.o
  24074. obj-$(CONFIG_HW_RANDOM_MSM) += msm-rng.o
  24075. obj-$(CONFIG_HW_RANDOM_XGENE) += xgene-rng.o
  24076. diff -Nur linux-3.18.8/drivers/char/Kconfig linux-rpi/drivers/char/Kconfig
  24077. --- linux-3.18.8/drivers/char/Kconfig 2015-02-27 02:49:36.000000000 +0100
  24078. +++ linux-rpi/drivers/char/Kconfig 2015-03-05 14:40:12.657715830 +0100
  24079. @@ -581,6 +581,8 @@
  24080. source "drivers/s390/char/Kconfig"
  24081. +source "drivers/char/broadcom/Kconfig"
  24082. +
  24083. config MSM_SMD_PKT
  24084. bool "Enable device interface for some SMD packet ports"
  24085. default n
  24086. diff -Nur linux-3.18.8/drivers/char/Makefile linux-rpi/drivers/char/Makefile
  24087. --- linux-3.18.8/drivers/char/Makefile 2015-02-27 02:49:36.000000000 +0100
  24088. +++ linux-rpi/drivers/char/Makefile 2015-03-05 14:40:12.657715830 +0100
  24089. @@ -62,3 +62,4 @@
  24090. obj-$(CONFIG_TILE_SROM) += tile-srom.o
  24091. obj-$(CONFIG_XILLYBUS) += xillybus/
  24092. +obj-$(CONFIG_BRCM_CHAR_DRIVERS) += broadcom/
  24093. diff -Nur linux-3.18.8/drivers/clocksource/arm_arch_timer.c linux-rpi/drivers/clocksource/arm_arch_timer.c
  24094. --- linux-3.18.8/drivers/clocksource/arm_arch_timer.c 2015-02-27 02:49:36.000000000 +0100
  24095. +++ linux-rpi/drivers/clocksource/arm_arch_timer.c 2015-03-05 14:40:12.693715830 +0100
  24096. @@ -795,3 +795,39 @@
  24097. }
  24098. CLOCKSOURCE_OF_DECLARE(armv7_arch_timer_mem, "arm,armv7-timer-mem",
  24099. arch_timer_mem_init);
  24100. +
  24101. +int __init dc4_arch_timer_init(void)
  24102. +{
  24103. + if (arch_timers_present & ARCH_CP15_TIMER) {
  24104. + pr_warn("arch_timer: multiple nodes in dt, skipping\n");
  24105. + return -1;
  24106. + }
  24107. +
  24108. + arch_timers_present |= ARCH_CP15_TIMER;
  24109. +
  24110. + /* Try to determine the frequency from the device tree or CNTFRQ */
  24111. + arch_timer_rate = 19200000;
  24112. +
  24113. + arch_timer_ppi[PHYS_SECURE_PPI] = IRQ_ARM_LOCAL_CNTPSIRQ;
  24114. + arch_timer_ppi[PHYS_NONSECURE_PPI] = IRQ_ARM_LOCAL_CNTPNSIRQ;
  24115. + arch_timer_ppi[VIRT_PPI] = IRQ_ARM_LOCAL_CNTVIRQ;
  24116. + arch_timer_ppi[HYP_PPI] = IRQ_ARM_LOCAL_CNTHPIRQ;
  24117. +
  24118. + /*
  24119. + * If HYP mode is available, we know that the physical timer
  24120. + * has been configured to be accessible from PL1. Use it, so
  24121. + * that a guest can use the virtual timer instead.
  24122. + *
  24123. + * If no interrupt provided for virtual timer, we'll have to
  24124. + * stick to the physical timer. It'd better be accessible...
  24125. + */
  24126. + if (is_hyp_mode_available() || !arch_timer_ppi[VIRT_PPI]) {
  24127. + arch_timer_use_virtual = false;
  24128. + }
  24129. +
  24130. + arch_timer_c3stop = 0;
  24131. +
  24132. + arch_timer_register();
  24133. + arch_timer_common_init();
  24134. + return 0;
  24135. +}
  24136. diff -Nur linux-3.18.8/drivers/cpufreq/bcm2835-cpufreq.c linux-rpi/drivers/cpufreq/bcm2835-cpufreq.c
  24137. --- linux-3.18.8/drivers/cpufreq/bcm2835-cpufreq.c 1970-01-01 01:00:00.000000000 +0100
  24138. +++ linux-rpi/drivers/cpufreq/bcm2835-cpufreq.c 2015-03-05 14:40:12.697715830 +0100
  24139. @@ -0,0 +1,224 @@
  24140. +/*****************************************************************************
  24141. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  24142. +*
  24143. +* Unless you and Broadcom execute a separate written software license
  24144. +* agreement governing use of this software, this software is licensed to you
  24145. +* under the terms of the GNU General Public License version 2, available at
  24146. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  24147. +*
  24148. +* Notwithstanding the above, under no circumstances may you combine this
  24149. +* software in any way with any other Broadcom software provided under a
  24150. +* license other than the GPL, without Broadcom's express prior written
  24151. +* consent.
  24152. +*****************************************************************************/
  24153. +
  24154. +/*****************************************************************************
  24155. +* FILENAME: bcm2835-cpufreq.h
  24156. +* DESCRIPTION: This driver dynamically manages the CPU Frequency of the ARM
  24157. +* processor. Messages are sent to Videocore either setting or requesting the
  24158. +* frequency of the ARM in order to match an appropiate frequency to the current
  24159. +* usage of the processor. The policy which selects the frequency to use is
  24160. +* defined in the kernel .config file, but can be changed during runtime.
  24161. +*****************************************************************************/
  24162. +
  24163. +/* ---------- INCLUDES ---------- */
  24164. +#include <linux/kernel.h>
  24165. +#include <linux/init.h>
  24166. +#include <linux/module.h>
  24167. +#include <linux/cpufreq.h>
  24168. +#include <mach/vcio.h>
  24169. +
  24170. +/* ---------- DEFINES ---------- */
  24171. +/*#define CPUFREQ_DEBUG_ENABLE*/ /* enable debugging */
  24172. +#define MODULE_NAME "bcm2835-cpufreq"
  24173. +
  24174. +#define VCMSG_ID_ARM_CLOCK 0x000000003 /* Clock/Voltage ID's */
  24175. +
  24176. +/* debug printk macros */
  24177. +#ifdef CPUFREQ_DEBUG_ENABLE
  24178. +#define print_debug(fmt,...) pr_debug("%s:%s:%d: "fmt, MODULE_NAME, __func__, __LINE__, ##__VA_ARGS__)
  24179. +#else
  24180. +#define print_debug(fmt,...)
  24181. +#endif
  24182. +#define print_err(fmt,...) pr_err("%s:%s:%d: "fmt, MODULE_NAME, __func__,__LINE__, ##__VA_ARGS__)
  24183. +#define print_info(fmt,...) pr_info("%s: "fmt, MODULE_NAME, ##__VA_ARGS__)
  24184. +
  24185. +/* tag part of the message */
  24186. +struct vc_msg_tag {
  24187. + uint32_t tag_id; /* the message id */
  24188. + uint32_t buffer_size; /* size of the buffer (which in this case is always 8 bytes) */
  24189. + uint32_t data_size; /* amount of data being sent or received */
  24190. + uint32_t dev_id; /* the ID of the clock/voltage to get or set */
  24191. + uint32_t val; /* the value (e.g. rate (in Hz)) to set */
  24192. +};
  24193. +
  24194. +/* message structure to be sent to videocore */
  24195. +struct vc_msg {
  24196. + uint32_t msg_size; /* simply, sizeof(struct vc_msg) */
  24197. + uint32_t request_code; /* holds various information like the success and number of bytes returned (refer to mailboxes wiki) */
  24198. + struct vc_msg_tag tag; /* the tag structure above to make */
  24199. + uint32_t end_tag; /* an end identifier, should be set to NULL */
  24200. +};
  24201. +
  24202. +/* ---------- GLOBALS ---------- */
  24203. +static struct cpufreq_driver bcm2835_cpufreq_driver; /* the cpufreq driver global */
  24204. +
  24205. +static struct cpufreq_frequency_table bcm2835_freq_table[] = {
  24206. + {0, 0, 0},
  24207. + {0, 0, 0},
  24208. + {0, 0, CPUFREQ_TABLE_END},
  24209. +};
  24210. +
  24211. +/*
  24212. + ===============================================
  24213. + clk_rate either gets or sets the clock rates.
  24214. + ===============================================
  24215. +*/
  24216. +static uint32_t bcm2835_cpufreq_set_clock(int cur_rate, int arm_rate)
  24217. +{
  24218. + int s, actual_rate=0;
  24219. + struct vc_msg msg;
  24220. +
  24221. + /* wipe all previous message data */
  24222. + memset(&msg, 0, sizeof msg);
  24223. +
  24224. + msg.msg_size = sizeof msg;
  24225. +
  24226. + msg.tag.tag_id = VCMSG_SET_CLOCK_RATE;
  24227. + msg.tag.buffer_size = 8;
  24228. + msg.tag.data_size = 8; /* we're sending the clock ID and the new rates which is a total of 2 words */
  24229. + msg.tag.dev_id = VCMSG_ID_ARM_CLOCK;
  24230. + msg.tag.val = arm_rate * 1000;
  24231. +
  24232. + /* send the message */
  24233. + s = bcm_mailbox_property(&msg, sizeof msg);
  24234. +
  24235. + /* check if it was all ok and return the rate in KHz */
  24236. + if (s == 0 && (msg.request_code & 0x80000000))
  24237. + actual_rate = msg.tag.val/1000;
  24238. +
  24239. + print_debug("Setting new frequency = %d -> %d (actual %d)\n", cur_rate, arm_rate, actual_rate);
  24240. + return actual_rate;
  24241. +}
  24242. +
  24243. +static uint32_t bcm2835_cpufreq_get_clock(int tag)
  24244. +{
  24245. + int s;
  24246. + int arm_rate = 0;
  24247. + struct vc_msg msg;
  24248. +
  24249. + /* wipe all previous message data */
  24250. + memset(&msg, 0, sizeof msg);
  24251. +
  24252. + msg.msg_size = sizeof msg;
  24253. + msg.tag.tag_id = tag;
  24254. + msg.tag.buffer_size = 8;
  24255. + msg.tag.data_size = 4; /* we're just sending the clock ID which is one word long */
  24256. + msg.tag.dev_id = VCMSG_ID_ARM_CLOCK;
  24257. +
  24258. + /* send the message */
  24259. + s = bcm_mailbox_property(&msg, sizeof msg);
  24260. +
  24261. + /* check if it was all ok and return the rate in KHz */
  24262. + if (s == 0 && (msg.request_code & 0x80000000))
  24263. + arm_rate = msg.tag.val/1000;
  24264. +
  24265. + print_debug("%s frequency = %d\n",
  24266. + tag == VCMSG_GET_CLOCK_RATE ? "Current":
  24267. + tag == VCMSG_GET_MIN_CLOCK ? "Min":
  24268. + tag == VCMSG_GET_MAX_CLOCK ? "Max":
  24269. + "Unexpected", arm_rate);
  24270. +
  24271. + return arm_rate;
  24272. +}
  24273. +
  24274. +/*
  24275. + ====================================================
  24276. + Module Initialisation registers the cpufreq driver
  24277. + ====================================================
  24278. +*/
  24279. +static int __init bcm2835_cpufreq_module_init(void)
  24280. +{
  24281. + print_debug("IN\n");
  24282. + return cpufreq_register_driver(&bcm2835_cpufreq_driver);
  24283. +}
  24284. +
  24285. +/*
  24286. + =============
  24287. + Module exit
  24288. + =============
  24289. +*/
  24290. +static void __exit bcm2835_cpufreq_module_exit(void)
  24291. +{
  24292. + print_debug("IN\n");
  24293. + cpufreq_unregister_driver(&bcm2835_cpufreq_driver);
  24294. + return;
  24295. +}
  24296. +
  24297. +/*
  24298. + ==============================================================
  24299. + Initialisation function sets up the CPU policy for first use
  24300. + ==============================================================
  24301. +*/
  24302. +static int bcm2835_cpufreq_driver_init(struct cpufreq_policy *policy)
  24303. +{
  24304. + /* measured value of how long it takes to change frequency */
  24305. + const unsigned int transition_latency = 355000; /* ns */
  24306. +
  24307. + /* now find out what the maximum and minimum frequencies are */
  24308. + bcm2835_freq_table[0].frequency = bcm2835_cpufreq_get_clock(VCMSG_GET_MIN_CLOCK);
  24309. + bcm2835_freq_table[1].frequency = bcm2835_cpufreq_get_clock(VCMSG_GET_MAX_CLOCK);
  24310. +
  24311. + print_info("min=%d max=%d\n", bcm2835_freq_table[0].frequency, bcm2835_freq_table[1].frequency);
  24312. + return cpufreq_generic_init(policy, bcm2835_freq_table, transition_latency);
  24313. +}
  24314. +
  24315. +/*
  24316. + =====================================================================
  24317. + Target index function chooses the requested frequency from the table
  24318. + =====================================================================
  24319. +*/
  24320. +
  24321. +static int bcm2835_cpufreq_driver_target_index(struct cpufreq_policy *policy, unsigned int state)
  24322. +{
  24323. + unsigned int target_freq = bcm2835_freq_table[state].frequency;
  24324. + unsigned int cur = bcm2835_cpufreq_set_clock(policy->cur, target_freq);
  24325. +
  24326. + if (!cur)
  24327. + {
  24328. + print_err("Error occurred setting a new frequency (%d)\n", target_freq);
  24329. + return -EINVAL;
  24330. + }
  24331. + print_debug("%s: %i: freq %d->%d\n", policy->governor->name, state, policy->cur, cur);
  24332. + return 0;
  24333. +}
  24334. +
  24335. +/*
  24336. + ======================================================
  24337. + Get function returns the current frequency from table
  24338. + ======================================================
  24339. +*/
  24340. +
  24341. +static unsigned int bcm2835_cpufreq_driver_get(unsigned int cpu)
  24342. +{
  24343. + unsigned int actual_rate = bcm2835_cpufreq_get_clock(VCMSG_GET_CLOCK_RATE);
  24344. + print_debug("%d: freq=%d\n", cpu, actual_rate);
  24345. + return actual_rate <= bcm2835_freq_table[0].frequency ? bcm2835_freq_table[0].frequency : bcm2835_freq_table[1].frequency;
  24346. +}
  24347. +
  24348. +/* the CPUFreq driver */
  24349. +static struct cpufreq_driver bcm2835_cpufreq_driver = {
  24350. + .name = "BCM2835 CPUFreq",
  24351. + .init = bcm2835_cpufreq_driver_init,
  24352. + .verify = cpufreq_generic_frequency_table_verify,
  24353. + .target_index = bcm2835_cpufreq_driver_target_index,
  24354. + .get = bcm2835_cpufreq_driver_get,
  24355. + .attr = cpufreq_generic_attr,
  24356. +};
  24357. +
  24358. +MODULE_AUTHOR("Dorian Peake and Dom Cobley");
  24359. +MODULE_DESCRIPTION("CPU frequency driver for BCM2835 chip");
  24360. +MODULE_LICENSE("GPL");
  24361. +
  24362. +module_init(bcm2835_cpufreq_module_init);
  24363. +module_exit(bcm2835_cpufreq_module_exit);
  24364. diff -Nur linux-3.18.8/drivers/cpufreq/Kconfig.arm linux-rpi/drivers/cpufreq/Kconfig.arm
  24365. --- linux-3.18.8/drivers/cpufreq/Kconfig.arm 2015-02-27 02:49:36.000000000 +0100
  24366. +++ linux-rpi/drivers/cpufreq/Kconfig.arm 2015-03-05 14:40:12.697715830 +0100
  24367. @@ -241,6 +241,14 @@
  24368. help
  24369. This adds the CPUFreq driver support for SPEAr SOCs.
  24370. +config ARM_BCM2835_CPUFREQ
  24371. + bool "BCM2835 Driver"
  24372. + default y
  24373. + help
  24374. + This adds the CPUFreq driver for BCM2835
  24375. +
  24376. + If in doubt, say N.
  24377. +
  24378. config ARM_TEGRA_CPUFREQ
  24379. bool "TEGRA CPUFreq support"
  24380. depends on ARCH_TEGRA
  24381. diff -Nur linux-3.18.8/drivers/cpufreq/Makefile linux-rpi/drivers/cpufreq/Makefile
  24382. --- linux-3.18.8/drivers/cpufreq/Makefile 2015-02-27 02:49:36.000000000 +0100
  24383. +++ linux-rpi/drivers/cpufreq/Makefile 2015-03-05 14:40:12.697715830 +0100
  24384. @@ -75,6 +75,7 @@
  24385. obj-$(CONFIG_ARM_SA1100_CPUFREQ) += sa1100-cpufreq.o
  24386. obj-$(CONFIG_ARM_SA1110_CPUFREQ) += sa1110-cpufreq.o
  24387. obj-$(CONFIG_ARM_SPEAR_CPUFREQ) += spear-cpufreq.o
  24388. +obj-$(CONFIG_ARM_BCM2835_CPUFREQ) += bcm2835-cpufreq.o
  24389. obj-$(CONFIG_ARM_TEGRA_CPUFREQ) += tegra-cpufreq.o
  24390. obj-$(CONFIG_ARM_VEXPRESS_SPC_CPUFREQ) += vexpress-spc-cpufreq.o
  24391. diff -Nur linux-3.18.8/drivers/dma/bcm2708-dmaengine.c linux-rpi/drivers/dma/bcm2708-dmaengine.c
  24392. --- linux-3.18.8/drivers/dma/bcm2708-dmaengine.c 1970-01-01 01:00:00.000000000 +0100
  24393. +++ linux-rpi/drivers/dma/bcm2708-dmaengine.c 2015-03-05 14:40:12.717715830 +0100
  24394. @@ -0,0 +1,1052 @@
  24395. +/*
  24396. + * BCM2835 DMA engine support
  24397. + *
  24398. + * This driver supports cyclic and scatter/gather DMA transfers.
  24399. + *
  24400. + * Author: Florian Meier <florian.meier@koalo.de>
  24401. + * Gellert Weisz <gellert@raspberrypi.org>
  24402. + * Copyright 2013-2014
  24403. + *
  24404. + * Based on
  24405. + * OMAP DMAengine support by Russell King
  24406. + *
  24407. + * BCM2708 DMA Driver
  24408. + * Copyright (C) 2010 Broadcom
  24409. + *
  24410. + * Raspberry Pi PCM I2S ALSA Driver
  24411. + * Copyright (c) by Phil Poole 2013
  24412. + *
  24413. + * MARVELL MMP Peripheral DMA Driver
  24414. + * Copyright 2012 Marvell International Ltd.
  24415. + *
  24416. + * This program is free software; you can redistribute it and/or modify
  24417. + * it under the terms of the GNU General Public License as published by
  24418. + * the Free Software Foundation; either version 2 of the License, or
  24419. + * (at your option) any later version.
  24420. + *
  24421. + * This program is distributed in the hope that it will be useful,
  24422. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  24423. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24424. + * GNU General Public License for more details.
  24425. + */
  24426. +
  24427. +#include <linux/dmaengine.h>
  24428. +#include <linux/dma-mapping.h>
  24429. +#include <linux/err.h>
  24430. +#include <linux/init.h>
  24431. +#include <linux/interrupt.h>
  24432. +#include <linux/list.h>
  24433. +#include <linux/module.h>
  24434. +#include <linux/platform_device.h>
  24435. +#include <linux/slab.h>
  24436. +#include <linux/io.h>
  24437. +#include <linux/spinlock.h>
  24438. +
  24439. +#ifndef CONFIG_ARCH_BCM2835
  24440. +
  24441. +/* dma manager */
  24442. +#include <mach/dma.h>
  24443. +
  24444. +//#define DMA_COMPLETE DMA_SUCCESS
  24445. +
  24446. +#endif
  24447. +
  24448. +#include <linux/of.h>
  24449. +#include <linux/of_dma.h>
  24450. +
  24451. +#include "virt-dma.h"
  24452. +
  24453. +
  24454. +struct bcm2835_dmadev {
  24455. + struct dma_device ddev;
  24456. + spinlock_t lock;
  24457. + void __iomem *base;
  24458. + struct device_dma_parameters dma_parms;
  24459. +};
  24460. +
  24461. +struct bcm2835_dma_cb {
  24462. + uint32_t info;
  24463. + uint32_t src;
  24464. + uint32_t dst;
  24465. + uint32_t length;
  24466. + uint32_t stride;
  24467. + uint32_t next;
  24468. + uint32_t pad[2];
  24469. +};
  24470. +
  24471. +struct bcm2835_chan {
  24472. + struct virt_dma_chan vc;
  24473. + struct list_head node;
  24474. +
  24475. + struct dma_slave_config cfg;
  24476. + bool cyclic;
  24477. +
  24478. + int ch;
  24479. + struct bcm2835_desc *desc;
  24480. +
  24481. + void __iomem *chan_base;
  24482. + int irq_number;
  24483. +
  24484. + unsigned int dreq;
  24485. +};
  24486. +
  24487. +struct bcm2835_desc {
  24488. + struct virt_dma_desc vd;
  24489. + enum dma_transfer_direction dir;
  24490. +
  24491. + unsigned int control_block_size;
  24492. + struct bcm2835_dma_cb *control_block_base;
  24493. + dma_addr_t control_block_base_phys;
  24494. +
  24495. + unsigned int frames;
  24496. + size_t size;
  24497. +};
  24498. +
  24499. +#define BCM2835_DMA_CS 0x00
  24500. +#define BCM2835_DMA_ADDR 0x04
  24501. +#define BCM2835_DMA_SOURCE_AD 0x0c
  24502. +#define BCM2835_DMA_DEST_AD 0x10
  24503. +#define BCM2835_DMA_NEXTCB 0x1C
  24504. +
  24505. +/* DMA CS Control and Status bits */
  24506. +#define BCM2835_DMA_ACTIVE BIT(0)
  24507. +#define BCM2835_DMA_INT BIT(2)
  24508. +#define BCM2835_DMA_ISPAUSED BIT(4) /* Pause requested or not active */
  24509. +#define BCM2835_DMA_ISHELD BIT(5) /* Is held by DREQ flow control */
  24510. +#define BCM2835_DMA_ERR BIT(8)
  24511. +#define BCM2835_DMA_ABORT BIT(30) /* Stop current CB, go to next, WO */
  24512. +#define BCM2835_DMA_RESET BIT(31) /* WO, self clearing */
  24513. +
  24514. +#define BCM2835_DMA_INT_EN BIT(0)
  24515. +#define BCM2835_DMA_WAIT_RESP BIT(3)
  24516. +#define BCM2835_DMA_D_INC BIT(4)
  24517. +#define BCM2835_DMA_D_WIDTH BIT(5)
  24518. +#define BCM2835_DMA_D_DREQ BIT(6)
  24519. +#define BCM2835_DMA_S_INC BIT(8)
  24520. +#define BCM2835_DMA_S_WIDTH BIT(9)
  24521. +#define BCM2835_DMA_S_DREQ BIT(10)
  24522. +
  24523. +#define BCM2835_DMA_PER_MAP(x) ((x) << 16)
  24524. +#define BCM2835_DMA_WAITS(x) (((x)&0x1f) << 21)
  24525. +
  24526. +#define SDHCI_BCM_DMA_WAITS 0 /* delays slowing DMA transfers: 0-31 */
  24527. +
  24528. +#define BCM2835_DMA_DATA_TYPE_S8 1
  24529. +#define BCM2835_DMA_DATA_TYPE_S16 2
  24530. +#define BCM2835_DMA_DATA_TYPE_S32 4
  24531. +#define BCM2835_DMA_DATA_TYPE_S128 16
  24532. +
  24533. +#define BCM2835_DMA_BULK_MASK BIT(0)
  24534. +#define BCM2835_DMA_FIQ_MASK (BIT(2) | BIT(3))
  24535. +
  24536. +
  24537. +/* Valid only for channels 0 - 14, 15 has its own base address */
  24538. +#define BCM2835_DMA_CHAN(n) ((n) << 8) /* Base address */
  24539. +#define BCM2835_DMA_CHANIO(base, n) ((base) + BCM2835_DMA_CHAN(n))
  24540. +
  24541. +#define MAX_LITE_TRANSFER 32768
  24542. +#define MAX_NORMAL_TRANSFER 1073741824
  24543. +
  24544. +static inline struct bcm2835_dmadev *to_bcm2835_dma_dev(struct dma_device *d)
  24545. +{
  24546. + return container_of(d, struct bcm2835_dmadev, ddev);
  24547. +}
  24548. +
  24549. +static inline struct bcm2835_chan *to_bcm2835_dma_chan(struct dma_chan *c)
  24550. +{
  24551. + return container_of(c, struct bcm2835_chan, vc.chan);
  24552. +}
  24553. +
  24554. +static inline struct bcm2835_desc *to_bcm2835_dma_desc(
  24555. + struct dma_async_tx_descriptor *t)
  24556. +{
  24557. + return container_of(t, struct bcm2835_desc, vd.tx);
  24558. +}
  24559. +
  24560. +static void dma_dumpregs(struct bcm2835_chan *c)
  24561. +{
  24562. + pr_debug("-------------DMA DUMPREGS-------------\n");
  24563. + pr_debug("CS= %u\n",
  24564. + readl(c->chan_base + BCM2835_DMA_CS));
  24565. + pr_debug("ADDR= %u\n",
  24566. + readl(c->chan_base + BCM2835_DMA_ADDR));
  24567. + pr_debug("SOURCE_ADDR= %u\n",
  24568. + readl(c->chan_base + BCM2835_DMA_SOURCE_AD));
  24569. + pr_debug("DEST_AD= %u\n",
  24570. + readl(c->chan_base + BCM2835_DMA_DEST_AD));
  24571. + pr_debug("NEXTCB= %u\n",
  24572. + readl(c->chan_base + BCM2835_DMA_NEXTCB));
  24573. + pr_debug("--------------------------------------\n");
  24574. +}
  24575. +
  24576. +static void bcm2835_dma_desc_free(struct virt_dma_desc *vd)
  24577. +{
  24578. + struct bcm2835_desc *desc = container_of(vd, struct bcm2835_desc, vd);
  24579. + dma_free_coherent(desc->vd.tx.chan->device->dev,
  24580. + desc->control_block_size,
  24581. + desc->control_block_base,
  24582. + desc->control_block_base_phys);
  24583. + kfree(desc);
  24584. +}
  24585. +
  24586. +static int bcm2835_dma_abort(void __iomem *chan_base)
  24587. +{
  24588. + unsigned long cs;
  24589. + long int timeout = 10000;
  24590. +
  24591. + cs = readl(chan_base + BCM2835_DMA_CS);
  24592. + if (!(cs & BCM2835_DMA_ACTIVE))
  24593. + return 0;
  24594. +
  24595. + /* Write 0 to the active bit - Pause the DMA */
  24596. + writel(0, chan_base + BCM2835_DMA_CS);
  24597. +
  24598. + /* Wait for any current AXI transfer to complete */
  24599. + while ((cs & BCM2835_DMA_ISPAUSED) && --timeout) {
  24600. + cpu_relax();
  24601. + cs = readl(chan_base + BCM2835_DMA_CS);
  24602. + }
  24603. +
  24604. + /* We'll un-pause when we set of our next DMA */
  24605. + if (!timeout)
  24606. + return -ETIMEDOUT;
  24607. +
  24608. + if (!(cs & BCM2835_DMA_ACTIVE))
  24609. + return 0;
  24610. +
  24611. + /* Terminate the control block chain */
  24612. + writel(0, chan_base + BCM2835_DMA_NEXTCB);
  24613. +
  24614. + /* Abort the whole DMA */
  24615. + writel(BCM2835_DMA_ABORT | BCM2835_DMA_ACTIVE,
  24616. + chan_base + BCM2835_DMA_CS);
  24617. +
  24618. + return 0;
  24619. +}
  24620. +
  24621. +
  24622. +static void bcm2835_dma_start_desc(struct bcm2835_chan *c)
  24623. +{
  24624. + struct virt_dma_desc *vd = vchan_next_desc(&c->vc);
  24625. + struct bcm2835_desc *d;
  24626. +
  24627. + if (!vd) {
  24628. + c->desc = NULL;
  24629. + return;
  24630. + }
  24631. +
  24632. + list_del(&vd->node);
  24633. +
  24634. + c->desc = d = to_bcm2835_dma_desc(&vd->tx);
  24635. +
  24636. + writel(d->control_block_base_phys, c->chan_base + BCM2835_DMA_ADDR);
  24637. + writel(BCM2835_DMA_ACTIVE, c->chan_base + BCM2835_DMA_CS);
  24638. +
  24639. +}
  24640. +
  24641. +static irqreturn_t bcm2835_dma_callback(int irq, void *data)
  24642. +{
  24643. + struct bcm2835_chan *c = data;
  24644. + struct bcm2835_desc *d;
  24645. + unsigned long flags;
  24646. +
  24647. + spin_lock_irqsave(&c->vc.lock, flags);
  24648. +
  24649. + /* Acknowledge interrupt */
  24650. + writel(BCM2835_DMA_INT, c->chan_base + BCM2835_DMA_CS);
  24651. +
  24652. + d = c->desc;
  24653. +
  24654. + if (d) {
  24655. + if (c->cyclic) {
  24656. + vchan_cyclic_callback(&d->vd);
  24657. +
  24658. + /* Keep the DMA engine running */
  24659. + writel(BCM2835_DMA_ACTIVE,
  24660. + c->chan_base + BCM2835_DMA_CS);
  24661. +
  24662. + } else {
  24663. + vchan_cookie_complete(&c->desc->vd);
  24664. + bcm2835_dma_start_desc(c);
  24665. + }
  24666. + }
  24667. +
  24668. + spin_unlock_irqrestore(&c->vc.lock, flags);
  24669. +
  24670. + return IRQ_HANDLED;
  24671. +}
  24672. +
  24673. +static int bcm2835_dma_alloc_chan_resources(struct dma_chan *chan)
  24674. +{
  24675. + struct bcm2835_chan *c = to_bcm2835_dma_chan(chan);
  24676. + int ret;
  24677. +
  24678. + dev_dbg(c->vc.chan.device->dev,
  24679. + "Allocating DMA channel %d\n", c->ch);
  24680. +
  24681. + ret = request_irq(c->irq_number,
  24682. + bcm2835_dma_callback, 0, "DMA IRQ", c);
  24683. +
  24684. + return ret;
  24685. +}
  24686. +
  24687. +static void bcm2835_dma_free_chan_resources(struct dma_chan *chan)
  24688. +{
  24689. + struct bcm2835_chan *c = to_bcm2835_dma_chan(chan);
  24690. +
  24691. + vchan_free_chan_resources(&c->vc);
  24692. + free_irq(c->irq_number, c);
  24693. +
  24694. + dev_dbg(c->vc.chan.device->dev, "Freeing DMA channel %u\n", c->ch);
  24695. +}
  24696. +
  24697. +static size_t bcm2835_dma_desc_size(struct bcm2835_desc *d)
  24698. +{
  24699. + return d->size;
  24700. +}
  24701. +
  24702. +static size_t bcm2835_dma_desc_size_pos(struct bcm2835_desc *d, dma_addr_t addr)
  24703. +{
  24704. + unsigned int i;
  24705. + size_t size;
  24706. +
  24707. + for (size = i = 0; i < d->frames; i++) {
  24708. + struct bcm2835_dma_cb *control_block =
  24709. + &d->control_block_base[i];
  24710. + size_t this_size = control_block->length;
  24711. + dma_addr_t dma;
  24712. +
  24713. + if (d->dir == DMA_DEV_TO_MEM)
  24714. + dma = control_block->dst;
  24715. + else
  24716. + dma = control_block->src;
  24717. +
  24718. + if (size)
  24719. + size += this_size;
  24720. + else if (addr >= dma && addr < dma + this_size)
  24721. + size += dma + this_size - addr;
  24722. + }
  24723. +
  24724. + return size;
  24725. +}
  24726. +
  24727. +static enum dma_status bcm2835_dma_tx_status(struct dma_chan *chan,
  24728. + dma_cookie_t cookie, struct dma_tx_state *txstate)
  24729. +{
  24730. + struct bcm2835_chan *c = to_bcm2835_dma_chan(chan);
  24731. + struct bcm2835_desc *d;
  24732. + struct virt_dma_desc *vd;
  24733. + enum dma_status ret;
  24734. + unsigned long flags;
  24735. + dma_addr_t pos;
  24736. +
  24737. + ret = dma_cookie_status(chan, cookie, txstate);
  24738. + if (ret == DMA_COMPLETE || !txstate)
  24739. + return ret;
  24740. +
  24741. + spin_lock_irqsave(&c->vc.lock, flags);
  24742. + vd = vchan_find_desc(&c->vc, cookie);
  24743. + if (vd) {
  24744. + txstate->residue =
  24745. + bcm2835_dma_desc_size(to_bcm2835_dma_desc(&vd->tx));
  24746. + } else if (c->desc && c->desc->vd.tx.cookie == cookie) {
  24747. + d = c->desc;
  24748. +
  24749. + if (d->dir == DMA_MEM_TO_DEV)
  24750. + pos = readl(c->chan_base + BCM2835_DMA_SOURCE_AD);
  24751. + else if (d->dir == DMA_DEV_TO_MEM)
  24752. + pos = readl(c->chan_base + BCM2835_DMA_DEST_AD);
  24753. + else
  24754. + pos = 0;
  24755. +
  24756. + txstate->residue = bcm2835_dma_desc_size_pos(d, pos);
  24757. + } else {
  24758. + txstate->residue = 0;
  24759. + }
  24760. +
  24761. + spin_unlock_irqrestore(&c->vc.lock, flags);
  24762. +
  24763. + return ret;
  24764. +}
  24765. +
  24766. +static void bcm2835_dma_issue_pending(struct dma_chan *chan)
  24767. +{
  24768. + struct bcm2835_chan *c = to_bcm2835_dma_chan(chan);
  24769. + unsigned long flags;
  24770. +
  24771. + spin_lock_irqsave(&c->vc.lock, flags);
  24772. + if (vchan_issue_pending(&c->vc) && !c->desc)
  24773. + bcm2835_dma_start_desc(c);
  24774. +
  24775. + spin_unlock_irqrestore(&c->vc.lock, flags);
  24776. +}
  24777. +
  24778. +static struct dma_async_tx_descriptor *bcm2835_dma_prep_dma_cyclic(
  24779. + struct dma_chan *chan, dma_addr_t buf_addr, size_t buf_len,
  24780. + size_t period_len, enum dma_transfer_direction direction,
  24781. + unsigned long flags)
  24782. +{
  24783. + struct bcm2835_chan *c = to_bcm2835_dma_chan(chan);
  24784. + enum dma_slave_buswidth dev_width;
  24785. + struct bcm2835_desc *d;
  24786. + dma_addr_t dev_addr;
  24787. + unsigned int es, sync_type;
  24788. + unsigned int frame, max_size;
  24789. +
  24790. + /* Grab configuration */
  24791. + if (!is_slave_direction(direction)) {
  24792. + dev_err(chan->device->dev, "%s: bad direction?\n", __func__);
  24793. + return NULL;
  24794. + }
  24795. +
  24796. + if (direction == DMA_DEV_TO_MEM) {
  24797. + dev_addr = c->cfg.src_addr;
  24798. + dev_width = c->cfg.src_addr_width;
  24799. + sync_type = BCM2835_DMA_S_DREQ;
  24800. + } else {
  24801. + dev_addr = c->cfg.dst_addr;
  24802. + dev_width = c->cfg.dst_addr_width;
  24803. + sync_type = BCM2835_DMA_D_DREQ;
  24804. + }
  24805. +
  24806. + /* Bus width translates to the element size (ES) */
  24807. + switch (dev_width) {
  24808. + case DMA_SLAVE_BUSWIDTH_4_BYTES:
  24809. + es = BCM2835_DMA_DATA_TYPE_S32;
  24810. + break;
  24811. + default:
  24812. + return NULL;
  24813. + }
  24814. +
  24815. + /* Now allocate and setup the descriptor. */
  24816. + d = kzalloc(sizeof(*d), GFP_NOWAIT);
  24817. + if (!d)
  24818. + return NULL;
  24819. +
  24820. + d->dir = direction;
  24821. +
  24822. + if (c->ch >= 8) /* we have a LITE channel */
  24823. + max_size = MAX_LITE_TRANSFER;
  24824. + else
  24825. + max_size = MAX_NORMAL_TRANSFER;
  24826. + period_len = min(period_len, max_size);
  24827. +
  24828. + d->frames = (buf_len-1) / period_len + 1;
  24829. +
  24830. + /* Allocate memory for control blocks */
  24831. + d->control_block_size = d->frames * sizeof(struct bcm2835_dma_cb);
  24832. + d->control_block_base = dma_zalloc_coherent(chan->device->dev,
  24833. + d->control_block_size, &d->control_block_base_phys,
  24834. + GFP_NOWAIT);
  24835. +
  24836. + if (!d->control_block_base) {
  24837. + kfree(d);
  24838. + return NULL;
  24839. + }
  24840. +
  24841. + /*
  24842. + * Iterate over all frames, create a control block
  24843. + * for each frame and link them together.
  24844. + */
  24845. + for (frame = 0; frame < d->frames; frame++) {
  24846. + struct bcm2835_dma_cb *control_block =
  24847. + &d->control_block_base[frame];
  24848. +
  24849. + /* Setup adresses */
  24850. + if (d->dir == DMA_DEV_TO_MEM) {
  24851. + control_block->info = BCM2835_DMA_D_INC;
  24852. + control_block->src = dev_addr;
  24853. + control_block->dst = buf_addr + frame * period_len;
  24854. + } else {
  24855. + control_block->info = BCM2835_DMA_S_INC;
  24856. + control_block->src = buf_addr + frame * period_len;
  24857. + control_block->dst = dev_addr;
  24858. + }
  24859. +
  24860. + /* Enable interrupt */
  24861. + control_block->info |= BCM2835_DMA_INT_EN;
  24862. +
  24863. + /* Setup synchronization */
  24864. + if (sync_type != 0)
  24865. + control_block->info |= sync_type;
  24866. +
  24867. + /* Setup DREQ channel */
  24868. + if (c->cfg.slave_id != 0)
  24869. + control_block->info |=
  24870. + BCM2835_DMA_PER_MAP(c->cfg.slave_id);
  24871. +
  24872. + /* Length of a frame */
  24873. + if (frame != d->frames-1)
  24874. + control_block->length = period_len;
  24875. + else
  24876. + control_block->length = buf_len - (d->frames - 1) * period_len;
  24877. +
  24878. + d->size += control_block->length;
  24879. +
  24880. + /*
  24881. + * Next block is the next frame.
  24882. + * This function is called on cyclic DMA transfers.
  24883. + * Therefore, wrap around at number of frames.
  24884. + */
  24885. + control_block->next = d->control_block_base_phys +
  24886. + sizeof(struct bcm2835_dma_cb)
  24887. + * ((frame + 1) % d->frames);
  24888. + }
  24889. +
  24890. + c->cyclic = true;
  24891. +
  24892. + return vchan_tx_prep(&c->vc, &d->vd, flags);
  24893. +}
  24894. +
  24895. +
  24896. +static struct dma_async_tx_descriptor *bcm2835_dma_prep_slave_sg(
  24897. + struct dma_chan *chan, struct scatterlist *sgl,
  24898. + unsigned int sg_len, enum dma_transfer_direction direction,
  24899. + unsigned long flags, void *context)
  24900. +{
  24901. + struct bcm2835_chan *c = to_bcm2835_dma_chan(chan);
  24902. + enum dma_slave_buswidth dev_width;
  24903. + struct bcm2835_desc *d;
  24904. + dma_addr_t dev_addr;
  24905. + struct scatterlist *sgent;
  24906. + unsigned int es, sync_type;
  24907. + unsigned int i, j, splitct, max_size;
  24908. +
  24909. + if (!is_slave_direction(direction)) {
  24910. + dev_err(chan->device->dev, "%s: bad direction?\n", __func__);
  24911. + return NULL;
  24912. + }
  24913. +
  24914. + if (direction == DMA_DEV_TO_MEM) {
  24915. + dev_addr = c->cfg.src_addr;
  24916. + dev_width = c->cfg.src_addr_width;
  24917. + sync_type = BCM2835_DMA_S_DREQ;
  24918. + } else {
  24919. + dev_addr = c->cfg.dst_addr;
  24920. + dev_width = c->cfg.dst_addr_width;
  24921. + sync_type = BCM2835_DMA_D_DREQ;
  24922. + }
  24923. +
  24924. + /* Bus width translates to the element size (ES) */
  24925. + switch (dev_width) {
  24926. + case DMA_SLAVE_BUSWIDTH_4_BYTES:
  24927. + es = BCM2835_DMA_DATA_TYPE_S32;
  24928. + break;
  24929. + default:
  24930. + return NULL;
  24931. + }
  24932. +
  24933. + /* Now allocate and setup the descriptor. */
  24934. + d = kzalloc(sizeof(*d), GFP_NOWAIT);
  24935. + if (!d)
  24936. + return NULL;
  24937. +
  24938. + d->dir = direction;
  24939. +
  24940. + if (c->ch >= 8) /* we have a LITE channel */
  24941. + max_size = MAX_LITE_TRANSFER;
  24942. + else
  24943. + max_size = MAX_NORMAL_TRANSFER;
  24944. +
  24945. + /* We store the length of the SG list in d->frames
  24946. + taking care to account for splitting up transfers
  24947. + too large for a LITE channel */
  24948. +
  24949. + d->frames = 0;
  24950. + for_each_sg(sgl, sgent, sg_len, i) {
  24951. + uint32_t len = sg_dma_len(sgent);
  24952. + d->frames += 1 + len / max_size;
  24953. + }
  24954. +
  24955. + /* Allocate memory for control blocks */
  24956. + d->control_block_size = d->frames * sizeof(struct bcm2835_dma_cb);
  24957. + d->control_block_base = dma_zalloc_coherent(chan->device->dev,
  24958. + d->control_block_size, &d->control_block_base_phys,
  24959. + GFP_NOWAIT);
  24960. +
  24961. + if (!d->control_block_base) {
  24962. + kfree(d);
  24963. + return NULL;
  24964. + }
  24965. +
  24966. + /*
  24967. + * Iterate over all SG entries, create a control block
  24968. + * for each frame and link them together.
  24969. + */
  24970. +
  24971. + /* we count the number of times an SG entry had to be splitct
  24972. + as a result of using a LITE channel */
  24973. + splitct = 0;
  24974. +
  24975. + for_each_sg(sgl, sgent, sg_len, i) {
  24976. + dma_addr_t addr = sg_dma_address(sgent);
  24977. + uint32_t len = sg_dma_len(sgent);
  24978. +
  24979. + for (j = 0; j < len; j += max_size) {
  24980. + struct bcm2835_dma_cb *control_block =
  24981. + &d->control_block_base[i+splitct];
  24982. +
  24983. + /* Setup adresses */
  24984. + if (d->dir == DMA_DEV_TO_MEM) {
  24985. + control_block->info = BCM2835_DMA_D_INC |
  24986. + BCM2835_DMA_D_WIDTH | BCM2835_DMA_S_DREQ;
  24987. + control_block->src = dev_addr;
  24988. + control_block->dst = addr + (dma_addr_t)j;
  24989. + } else {
  24990. + control_block->info = BCM2835_DMA_S_INC |
  24991. + BCM2835_DMA_S_WIDTH | BCM2835_DMA_D_DREQ;
  24992. + control_block->src = addr + (dma_addr_t)j;
  24993. + control_block->dst = dev_addr;
  24994. + }
  24995. +
  24996. + /* Common part */
  24997. + control_block->info |= BCM2835_DMA_WAITS(SDHCI_BCM_DMA_WAITS);
  24998. + control_block->info |= BCM2835_DMA_WAIT_RESP;
  24999. +
  25000. + /* Enable */
  25001. + if (i == sg_len-1 && len-j <= max_size)
  25002. + control_block->info |= BCM2835_DMA_INT_EN;
  25003. +
  25004. + /* Setup synchronization */
  25005. + if (sync_type != 0)
  25006. + control_block->info |= sync_type;
  25007. +
  25008. + /* Setup DREQ channel */
  25009. + c->dreq = c->cfg.slave_id; /* DREQ loaded from config */
  25010. +
  25011. + if (c->dreq != 0)
  25012. + control_block->info |=
  25013. + BCM2835_DMA_PER_MAP(c->dreq);
  25014. +
  25015. + /* Length of a frame */
  25016. + control_block->length = min(len-j, max_size);
  25017. + d->size += control_block->length;
  25018. +
  25019. + /*
  25020. + * Next block is the next frame.
  25021. + */
  25022. + if (i < sg_len-1 || len-j > max_size) {
  25023. + /* next block is the next frame. */
  25024. + control_block->next = d->control_block_base_phys +
  25025. + sizeof(struct bcm2835_dma_cb) * (i + splitct + 1);
  25026. + } else {
  25027. + /* next block is empty. */
  25028. + control_block->next = 0;
  25029. + }
  25030. +
  25031. + if (len-j > max_size)
  25032. + splitct++;
  25033. + }
  25034. + }
  25035. +
  25036. + c->cyclic = false;
  25037. +
  25038. + return vchan_tx_prep(&c->vc, &d->vd, flags);
  25039. +}
  25040. +
  25041. +static int bcm2835_dma_slave_config(struct bcm2835_chan *c,
  25042. + struct dma_slave_config *cfg)
  25043. +{
  25044. + if ((cfg->direction == DMA_DEV_TO_MEM &&
  25045. + cfg->src_addr_width != DMA_SLAVE_BUSWIDTH_4_BYTES) ||
  25046. + (cfg->direction == DMA_MEM_TO_DEV &&
  25047. + cfg->dst_addr_width != DMA_SLAVE_BUSWIDTH_4_BYTES) ||
  25048. + !is_slave_direction(cfg->direction)) {
  25049. + return -EINVAL;
  25050. + }
  25051. +
  25052. + c->cfg = *cfg;
  25053. +
  25054. + return 0;
  25055. +}
  25056. +
  25057. +static int bcm2835_dma_terminate_all(struct bcm2835_chan *c)
  25058. +{
  25059. + struct bcm2835_dmadev *d = to_bcm2835_dma_dev(c->vc.chan.device);
  25060. + unsigned long flags;
  25061. + int timeout = 10000;
  25062. + LIST_HEAD(head);
  25063. +
  25064. + spin_lock_irqsave(&c->vc.lock, flags);
  25065. +
  25066. + /* Prevent this channel being scheduled */
  25067. + spin_lock(&d->lock);
  25068. + list_del_init(&c->node);
  25069. + spin_unlock(&d->lock);
  25070. +
  25071. + /*
  25072. + * Stop DMA activity: we assume the callback will not be called
  25073. + * after bcm_dma_abort() returns (even if it does, it will see
  25074. + * c->desc is NULL and exit.)
  25075. + */
  25076. + if (c->desc) {
  25077. + c->desc = NULL;
  25078. + bcm2835_dma_abort(c->chan_base);
  25079. +
  25080. + /* Wait for stopping */
  25081. + while (--timeout) {
  25082. + if (!(readl(c->chan_base + BCM2835_DMA_CS) &
  25083. + BCM2835_DMA_ACTIVE))
  25084. + break;
  25085. +
  25086. + cpu_relax();
  25087. + }
  25088. +
  25089. + if (!timeout)
  25090. + dev_err(d->ddev.dev, "DMA transfer could not be terminated\n");
  25091. + }
  25092. +
  25093. + vchan_get_all_descriptors(&c->vc, &head);
  25094. + spin_unlock_irqrestore(&c->vc.lock, flags);
  25095. + vchan_dma_desc_free_list(&c->vc, &head);
  25096. +
  25097. + return 0;
  25098. +}
  25099. +
  25100. +static int bcm2835_dma_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd,
  25101. + unsigned long arg)
  25102. +{
  25103. + struct bcm2835_chan *c = to_bcm2835_dma_chan(chan);
  25104. +
  25105. + switch (cmd) {
  25106. + case DMA_SLAVE_CONFIG:
  25107. + return bcm2835_dma_slave_config(c,
  25108. + (struct dma_slave_config *)arg);
  25109. +
  25110. + case DMA_TERMINATE_ALL:
  25111. + return bcm2835_dma_terminate_all(c);
  25112. +
  25113. + default:
  25114. + return -ENXIO;
  25115. + }
  25116. +}
  25117. +
  25118. +#ifdef CONFIG_ARCH_BCM2835
  25119. +static int bcm2835_dma_chan_init(struct bcm2835_dmadev *d, int chan_id, int irq)
  25120. +{
  25121. + struct bcm2835_chan *c;
  25122. +
  25123. + c = devm_kzalloc(d->ddev.dev, sizeof(*c), GFP_KERNEL);
  25124. + if (!c)
  25125. + return -ENOMEM;
  25126. +
  25127. + c->vc.desc_free = bcm2835_dma_desc_free;
  25128. + vchan_init(&c->vc, &d->ddev);
  25129. + INIT_LIST_HEAD(&c->node);
  25130. +
  25131. + d->ddev.chancnt++;
  25132. +
  25133. + c->chan_base = BCM2835_DMA_CHANIO(d->base, chan_id);
  25134. + c->ch = chan_id;
  25135. + c->irq_number = irq;
  25136. +
  25137. + return 0;
  25138. +}
  25139. +#endif
  25140. +
  25141. +static int bcm2708_dma_chan_init(struct bcm2835_dmadev *d,
  25142. + void __iomem *chan_base, int chan_id, int irq)
  25143. +{
  25144. + struct bcm2835_chan *c;
  25145. +
  25146. + c = devm_kzalloc(d->ddev.dev, sizeof(*c), GFP_KERNEL);
  25147. + if (!c)
  25148. + return -ENOMEM;
  25149. +
  25150. + c->vc.desc_free = bcm2835_dma_desc_free;
  25151. + vchan_init(&c->vc, &d->ddev);
  25152. + INIT_LIST_HEAD(&c->node);
  25153. +
  25154. + d->ddev.chancnt++;
  25155. +
  25156. + c->chan_base = chan_base;
  25157. + c->ch = chan_id;
  25158. + c->irq_number = irq;
  25159. +
  25160. + return 0;
  25161. +}
  25162. +
  25163. +
  25164. +static void bcm2835_dma_free(struct bcm2835_dmadev *od)
  25165. +{
  25166. + struct bcm2835_chan *c, *next;
  25167. +
  25168. + list_for_each_entry_safe(c, next, &od->ddev.channels,
  25169. + vc.chan.device_node) {
  25170. + list_del(&c->vc.chan.device_node);
  25171. + tasklet_kill(&c->vc.task);
  25172. + }
  25173. +}
  25174. +
  25175. +static const struct of_device_id bcm2835_dma_of_match[] = {
  25176. + { .compatible = "brcm,bcm2835-dma", },
  25177. + {},
  25178. +};
  25179. +MODULE_DEVICE_TABLE(of, bcm2835_dma_of_match);
  25180. +
  25181. +#ifdef CONFIG_ARCH_BCM2835
  25182. +static struct dma_chan *bcm2835_dma_xlate(struct of_phandle_args *spec,
  25183. + struct of_dma *ofdma)
  25184. +{
  25185. + struct bcm2835_dmadev *d = ofdma->of_dma_data;
  25186. + struct dma_chan *chan;
  25187. +
  25188. + chan = dma_get_any_slave_channel(&d->ddev);
  25189. + if (!chan)
  25190. + return NULL;
  25191. +
  25192. + /* Set DREQ from param */
  25193. + to_bcm2835_dma_chan(chan)->dreq = spec->args[0];
  25194. +
  25195. + return chan;
  25196. +}
  25197. +#endif
  25198. +
  25199. +static int bcm2835_dma_device_slave_caps(struct dma_chan *dchan,
  25200. + struct dma_slave_caps *caps)
  25201. +{
  25202. + caps->src_addr_widths = BIT(DMA_SLAVE_BUSWIDTH_4_BYTES);
  25203. + caps->dstn_addr_widths = BIT(DMA_SLAVE_BUSWIDTH_4_BYTES);
  25204. + caps->directions = BIT(DMA_DEV_TO_MEM) | BIT(DMA_MEM_TO_DEV);
  25205. + caps->cmd_pause = false;
  25206. + caps->cmd_terminate = true;
  25207. +
  25208. + return 0;
  25209. +}
  25210. +
  25211. +static int bcm2835_dma_probe(struct platform_device *pdev)
  25212. +{
  25213. + struct bcm2835_dmadev *od;
  25214. +#ifdef CONFIG_ARCH_BCM2835
  25215. + struct resource *res;
  25216. + void __iomem *base;
  25217. + uint32_t chans_available;
  25218. +#endif
  25219. + int rc;
  25220. + int i;
  25221. + int irq;
  25222. +
  25223. +
  25224. + if (!pdev->dev.dma_mask)
  25225. + pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask;
  25226. +
  25227. + /* If CONFIG_ARCH_BCM2835 is selected, device tree is used */
  25228. + /* hence the difference between probing */
  25229. +
  25230. +#ifndef CONFIG_ARCH_BCM2835
  25231. +
  25232. + rc = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
  25233. + if (rc)
  25234. + return rc;
  25235. + dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
  25236. +
  25237. +
  25238. + od = devm_kzalloc(&pdev->dev, sizeof(*od), GFP_KERNEL);
  25239. + if (!od)
  25240. + return -ENOMEM;
  25241. +
  25242. + pdev->dev.dma_parms = &od->dma_parms;
  25243. + dma_set_max_seg_size(&pdev->dev, 0x3FFFFFFF);
  25244. +
  25245. +
  25246. + dma_cap_set(DMA_SLAVE, od->ddev.cap_mask);
  25247. + dma_cap_set(DMA_PRIVATE, od->ddev.cap_mask);
  25248. + dma_cap_set(DMA_CYCLIC, od->ddev.cap_mask);
  25249. + od->ddev.device_alloc_chan_resources = bcm2835_dma_alloc_chan_resources;
  25250. + od->ddev.device_free_chan_resources = bcm2835_dma_free_chan_resources;
  25251. + od->ddev.device_tx_status = bcm2835_dma_tx_status;
  25252. + od->ddev.device_issue_pending = bcm2835_dma_issue_pending;
  25253. + od->ddev.device_slave_caps = bcm2835_dma_device_slave_caps;
  25254. + od->ddev.device_prep_dma_cyclic = bcm2835_dma_prep_dma_cyclic;
  25255. + od->ddev.device_prep_slave_sg = bcm2835_dma_prep_slave_sg;
  25256. + od->ddev.device_control = bcm2835_dma_control;
  25257. + od->ddev.dev = &pdev->dev;
  25258. + INIT_LIST_HEAD(&od->ddev.channels);
  25259. + spin_lock_init(&od->lock);
  25260. +
  25261. + platform_set_drvdata(pdev, od);
  25262. +
  25263. + for (i = 0; i < 5; i++) {
  25264. + void __iomem *chan_base;
  25265. + int chan_id;
  25266. +
  25267. + chan_id = bcm_dma_chan_alloc(BCM_DMA_FEATURE_LITE,
  25268. + &chan_base,
  25269. + &irq);
  25270. +
  25271. + if (chan_id < 0)
  25272. + break;
  25273. +
  25274. + rc = bcm2708_dma_chan_init(od, chan_base, chan_id, irq);
  25275. + if (rc)
  25276. + goto err_no_dma;
  25277. + }
  25278. +#else
  25279. + rc = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
  25280. + if (rc)
  25281. + return rc;
  25282. +
  25283. +
  25284. + od = devm_kzalloc(&pdev->dev, sizeof(*od), GFP_KERNEL);
  25285. + if (!od)
  25286. + return -ENOMEM;
  25287. +
  25288. + pdev->dev.dma_parms = &od->dma_parms;
  25289. + dma_set_max_seg_size(&pdev->dev, 0x3FFFFFFF);
  25290. +
  25291. +
  25292. + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  25293. + base = devm_ioremap_resource(&pdev->dev, res);
  25294. + if (IS_ERR(base))
  25295. + return PTR_ERR(base);
  25296. +
  25297. + od->base = base;
  25298. +
  25299. +
  25300. + dma_cap_set(DMA_SLAVE, od->ddev.cap_mask);
  25301. + dma_cap_set(DMA_PRIVATE, od->ddev.cap_mask);
  25302. + dma_cap_set(DMA_CYCLIC, od->ddev.cap_mask);
  25303. + od->ddev.device_alloc_chan_resources = bcm2835_dma_alloc_chan_resources;
  25304. + od->ddev.device_free_chan_resources = bcm2835_dma_free_chan_resources;
  25305. + od->ddev.device_tx_status = bcm2835_dma_tx_status;
  25306. + od->ddev.device_issue_pending = bcm2835_dma_issue_pending;
  25307. + od->ddev.device_slave_caps = bcm2835_dma_device_slave_caps;
  25308. + od->ddev.device_prep_dma_cyclic = bcm2835_dma_prep_dma_cyclic;
  25309. + od->ddev.device_prep_slave_sg = bcm2835_dma_prep_slave_sg;
  25310. + od->ddev.device_control = bcm2835_dma_control;
  25311. + od->ddev.dev = &pdev->dev;
  25312. + INIT_LIST_HEAD(&od->ddev.channels);
  25313. + spin_lock_init(&od->lock);
  25314. +
  25315. + platform_set_drvdata(pdev, od);
  25316. +
  25317. +
  25318. + /* Request DMA channel mask from device tree */
  25319. + if (of_property_read_u32(pdev->dev.of_node,
  25320. + "brcm,dma-channel-mask",
  25321. + &chans_available)) {
  25322. + dev_err(&pdev->dev, "Failed to get channel mask\n");
  25323. + rc = -EINVAL;
  25324. + goto err_no_dma;
  25325. + }
  25326. +
  25327. +
  25328. + /*
  25329. + * Do not use the FIQ and BULK channels,
  25330. + * because they are used by the GPU.
  25331. + */
  25332. + chans_available &= ~(BCM2835_DMA_FIQ_MASK | BCM2835_DMA_BULK_MASK);
  25333. +
  25334. +
  25335. + for (i = 0; i < pdev->num_resources; i++) {
  25336. + irq = platform_get_irq(pdev, i);
  25337. + if (irq < 0)
  25338. + break;
  25339. +
  25340. + if (chans_available & (1 << i)) {
  25341. + rc = bcm2835_dma_chan_init(od, i, irq);
  25342. + if (rc)
  25343. + goto err_no_dma;
  25344. + }
  25345. + }
  25346. +
  25347. + dev_dbg(&pdev->dev, "Initialized %i DMA channels\n", i);
  25348. +
  25349. + /* Device-tree DMA controller registration */
  25350. + rc = of_dma_controller_register(pdev->dev.of_node,
  25351. + bcm2835_dma_xlate, od);
  25352. + if (rc) {
  25353. + dev_err(&pdev->dev, "Failed to register DMA controller\n");
  25354. + goto err_no_dma;
  25355. + }
  25356. +#endif
  25357. +
  25358. + rc = dma_async_device_register(&od->ddev);
  25359. + if (rc) {
  25360. + dev_err(&pdev->dev,
  25361. + "Failed to register slave DMA engine device: %d\n", rc);
  25362. + goto err_no_dma;
  25363. + }
  25364. +
  25365. + dev_info(&pdev->dev, "Load BCM2835 DMA engine driver\n");
  25366. +
  25367. + return 0;
  25368. +
  25369. +err_no_dma:
  25370. + bcm2835_dma_free(od);
  25371. + return rc;
  25372. +}
  25373. +
  25374. +static int bcm2835_dma_remove(struct platform_device *pdev)
  25375. +{
  25376. + struct bcm2835_dmadev *od = platform_get_drvdata(pdev);
  25377. +
  25378. + dma_async_device_unregister(&od->ddev);
  25379. + bcm2835_dma_free(od);
  25380. +
  25381. + return 0;
  25382. +}
  25383. +
  25384. +#ifndef CONFIG_ARCH_BCM2835
  25385. +
  25386. +
  25387. +static struct platform_driver bcm2835_dma_driver = {
  25388. + .probe = bcm2835_dma_probe,
  25389. + .remove = bcm2835_dma_remove,
  25390. + .driver = {
  25391. + .name = "bcm2708-dmaengine",
  25392. + .owner = THIS_MODULE,
  25393. + },
  25394. +};
  25395. +
  25396. +static struct platform_device *pdev;
  25397. +
  25398. +static const struct platform_device_info bcm2835_dma_dev_info = {
  25399. + .name = "bcm2708-dmaengine",
  25400. + .id = -1,
  25401. +};
  25402. +
  25403. +static int bcm2835_dma_init(void)
  25404. +{
  25405. + int rc = platform_driver_register(&bcm2835_dma_driver);
  25406. +
  25407. + if (rc == 0) {
  25408. + pdev = platform_device_register_full(&bcm2835_dma_dev_info);
  25409. + if (IS_ERR(pdev)) {
  25410. + platform_driver_unregister(&bcm2835_dma_driver);
  25411. + rc = PTR_ERR(pdev);
  25412. + }
  25413. + }
  25414. +
  25415. + return rc;
  25416. +}
  25417. +module_init(bcm2835_dma_init); /* preferable to subsys_initcall */
  25418. +
  25419. +static void __exit bcm2835_dma_exit(void)
  25420. +{
  25421. + platform_device_unregister(pdev);
  25422. + platform_driver_unregister(&bcm2835_dma_driver);
  25423. +}
  25424. +module_exit(bcm2835_dma_exit);
  25425. +
  25426. +#else
  25427. +
  25428. +static struct platform_driver bcm2835_dma_driver = {
  25429. + .probe = bcm2835_dma_probe,
  25430. + .remove = bcm2835_dma_remove,
  25431. + .driver = {
  25432. + .name = "bcm2835-dma",
  25433. + .owner = THIS_MODULE,
  25434. + .of_match_table = of_match_ptr(bcm2835_dma_of_match),
  25435. + },
  25436. +};
  25437. +
  25438. +module_platform_driver(bcm2835_dma_driver);
  25439. +
  25440. +#endif
  25441. +
  25442. +MODULE_ALIAS("platform:bcm2835-dma");
  25443. +MODULE_DESCRIPTION("BCM2835 DMA engine driver");
  25444. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  25445. +MODULE_AUTHOR("Gellert Weisz <gellert@raspberrypi.org>");
  25446. +MODULE_LICENSE("GPL v2");
  25447. diff -Nur linux-3.18.8/drivers/dma/Kconfig linux-rpi/drivers/dma/Kconfig
  25448. --- linux-3.18.8/drivers/dma/Kconfig 2015-02-27 02:49:36.000000000 +0100
  25449. +++ linux-rpi/drivers/dma/Kconfig 2015-03-05 14:40:12.717715830 +0100
  25450. @@ -330,6 +330,12 @@
  25451. select DMA_ENGINE
  25452. select DMA_VIRTUAL_CHANNELS
  25453. +config DMA_BCM2708
  25454. + tristate "BCM2708 DMA engine support"
  25455. + depends on MACH_BCM2708 || MACH_BCM2709
  25456. + select DMA_ENGINE
  25457. + select DMA_VIRTUAL_CHANNELS
  25458. +
  25459. config TI_CPPI41
  25460. tristate "AM33xx CPPI41 DMA support"
  25461. depends on ARCH_OMAP
  25462. diff -Nur linux-3.18.8/drivers/dma/Makefile linux-rpi/drivers/dma/Makefile
  25463. --- linux-3.18.8/drivers/dma/Makefile 2015-02-27 02:49:36.000000000 +0100
  25464. +++ linux-rpi/drivers/dma/Makefile 2015-03-05 14:40:12.717715830 +0100
  25465. @@ -38,6 +38,7 @@
  25466. obj-$(CONFIG_MMP_TDMA) += mmp_tdma.o
  25467. obj-$(CONFIG_DMA_OMAP) += omap-dma.o
  25468. obj-$(CONFIG_DMA_BCM2835) += bcm2835-dma.o
  25469. +obj-$(CONFIG_DMA_BCM2708) += bcm2708-dmaengine.o
  25470. obj-$(CONFIG_MMP_PDMA) += mmp_pdma.o
  25471. obj-$(CONFIG_DMA_JZ4740) += dma-jz4740.o
  25472. obj-$(CONFIG_TI_CPPI41) += cppi41.o
  25473. diff -Nur linux-3.18.8/drivers/hid/usbhid/hid-core.c linux-rpi/drivers/hid/usbhid/hid-core.c
  25474. --- linux-3.18.8/drivers/hid/usbhid/hid-core.c 2015-02-27 02:49:36.000000000 +0100
  25475. +++ linux-rpi/drivers/hid/usbhid/hid-core.c 2015-03-05 14:40:13.017715828 +0100
  25476. @@ -49,7 +49,7 @@
  25477. * Module parameters.
  25478. */
  25479. -static unsigned int hid_mousepoll_interval;
  25480. +static unsigned int hid_mousepoll_interval = ~0;
  25481. module_param_named(mousepoll, hid_mousepoll_interval, uint, 0644);
  25482. MODULE_PARM_DESC(mousepoll, "Polling interval of mice");
  25483. @@ -1079,8 +1079,12 @@
  25484. }
  25485. /* Change the polling interval of mice. */
  25486. - if (hid->collection->usage == HID_GD_MOUSE && hid_mousepoll_interval > 0)
  25487. - interval = hid_mousepoll_interval;
  25488. + if (hid->collection->usage == HID_GD_MOUSE) {
  25489. + if (hid_mousepoll_interval == ~0 && interval < 16)
  25490. + interval = 16;
  25491. + else if (hid_mousepoll_interval != ~0 && hid_mousepoll_interval != 0)
  25492. + interval = hid_mousepoll_interval;
  25493. + }
  25494. ret = -ENOMEM;
  25495. if (usb_endpoint_dir_in(endpoint)) {
  25496. diff -Nur linux-3.18.8/drivers/hwmon/bcm2835-hwmon.c linux-rpi/drivers/hwmon/bcm2835-hwmon.c
  25497. --- linux-3.18.8/drivers/hwmon/bcm2835-hwmon.c 1970-01-01 01:00:00.000000000 +0100
  25498. +++ linux-rpi/drivers/hwmon/bcm2835-hwmon.c 2015-03-05 14:40:13.029715828 +0100
  25499. @@ -0,0 +1,219 @@
  25500. +/*****************************************************************************
  25501. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  25502. +*
  25503. +* Unless you and Broadcom execute a separate written software license
  25504. +* agreement governing use of this software, this software is licensed to you
  25505. +* under the terms of the GNU General Public License version 2, available at
  25506. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  25507. +*
  25508. +* Notwithstanding the above, under no circumstances may you combine this
  25509. +* software in any way with any other Broadcom software provided under a
  25510. +* license other than the GPL, without Broadcom's express prior written
  25511. +* consent.
  25512. +*****************************************************************************/
  25513. +
  25514. +#include <linux/kernel.h>
  25515. +#include <linux/module.h>
  25516. +#include <linux/init.h>
  25517. +#include <linux/hwmon.h>
  25518. +#include <linux/hwmon-sysfs.h>
  25519. +#include <linux/platform_device.h>
  25520. +#include <linux/sysfs.h>
  25521. +#include <mach/vcio.h>
  25522. +#include <linux/slab.h>
  25523. +#include <linux/err.h>
  25524. +
  25525. +#define MODULE_NAME "bcm2835_hwmon"
  25526. +
  25527. +/*#define HWMON_DEBUG_ENABLE*/
  25528. +
  25529. +#ifdef HWMON_DEBUG_ENABLE
  25530. +#define print_debug(fmt,...) printk(KERN_INFO "%s:%s:%d: "fmt"\n", MODULE_NAME, __func__, __LINE__, ##__VA_ARGS__)
  25531. +#else
  25532. +#define print_debug(fmt,...)
  25533. +#endif
  25534. +#define print_err(fmt,...) printk(KERN_ERR "%s:%s:%d: "fmt"\n", MODULE_NAME, __func__,__LINE__, ##__VA_ARGS__)
  25535. +#define print_info(fmt,...) printk(KERN_INFO "%s: "fmt"\n", MODULE_NAME, ##__VA_ARGS__)
  25536. +
  25537. +#define VC_TAG_GET_TEMP 0x00030006
  25538. +#define VC_TAG_GET_MAX_TEMP 0x0003000A
  25539. +
  25540. +/* --- STRUCTS --- */
  25541. +struct bcm2835_hwmon_data {
  25542. + struct device *hwmon_dev;
  25543. +};
  25544. +
  25545. +/* tag part of the message */
  25546. +struct vc_msg_tag {
  25547. + uint32_t tag_id; /* the tag ID for the temperature */
  25548. + uint32_t buffer_size; /* size of the buffer (should be 8) */
  25549. + uint32_t request_code; /* identifies message as a request (should be 0) */
  25550. + uint32_t id; /* extra ID field (should be 0) */
  25551. + uint32_t val; /* returned value of the temperature */
  25552. +};
  25553. +
  25554. +/* message structure to be sent to videocore */
  25555. +struct vc_msg {
  25556. + uint32_t msg_size; /* simply, sizeof(struct vc_msg) */
  25557. + uint32_t request_code; /* holds various information like the success and number of bytes returned (refer to mailboxes wiki) */
  25558. + struct vc_msg_tag tag; /* the tag structure above to make */
  25559. + uint32_t end_tag; /* an end identifier, should be set to NULL */
  25560. +};
  25561. +
  25562. +typedef enum {
  25563. + TEMP,
  25564. + MAX_TEMP,
  25565. +} temp_type;
  25566. +
  25567. +/* --- PROTOTYPES --- */
  25568. +static ssize_t bcm2835_get_temp(struct device *dev, struct device_attribute *attr, char *buf);
  25569. +static ssize_t bcm2835_get_name(struct device *dev, struct device_attribute *attr, char *buf);
  25570. +
  25571. +/* --- GLOBALS --- */
  25572. +
  25573. +static struct bcm2835_hwmon_data *bcm2835_data;
  25574. +static struct platform_driver bcm2835_hwmon_driver;
  25575. +
  25576. +static SENSOR_DEVICE_ATTR(name, S_IRUGO,bcm2835_get_name,NULL,0);
  25577. +static SENSOR_DEVICE_ATTR(temp1_input,S_IRUGO,bcm2835_get_temp,NULL,TEMP);
  25578. +static SENSOR_DEVICE_ATTR(temp1_max,S_IRUGO,bcm2835_get_temp,NULL,MAX_TEMP);
  25579. +
  25580. +static struct attribute* bcm2835_attributes[] = {
  25581. + &sensor_dev_attr_name.dev_attr.attr,
  25582. + &sensor_dev_attr_temp1_input.dev_attr.attr,
  25583. + &sensor_dev_attr_temp1_max.dev_attr.attr,
  25584. + NULL,
  25585. +};
  25586. +
  25587. +static struct attribute_group bcm2835_attr_group = {
  25588. + .attrs = bcm2835_attributes,
  25589. +};
  25590. +
  25591. +/* --- FUNCTIONS --- */
  25592. +
  25593. +static ssize_t bcm2835_get_name(struct device *dev, struct device_attribute *attr, char *buf)
  25594. +{
  25595. + return sprintf(buf,"bcm2835_hwmon\n");
  25596. +}
  25597. +
  25598. +static ssize_t bcm2835_get_temp(struct device *dev, struct device_attribute *attr, char *buf)
  25599. +{
  25600. + struct vc_msg msg;
  25601. + int result;
  25602. + uint temp = 0;
  25603. + int index = ((struct sensor_device_attribute*)to_sensor_dev_attr(attr))->index;
  25604. +
  25605. + print_debug("IN");
  25606. +
  25607. + /* wipe all previous message data */
  25608. + memset(&msg, 0, sizeof msg);
  25609. +
  25610. + /* determine the message type */
  25611. + if(index == TEMP)
  25612. + msg.tag.tag_id = VC_TAG_GET_TEMP;
  25613. + else if (index == MAX_TEMP)
  25614. + msg.tag.tag_id = VC_TAG_GET_MAX_TEMP;
  25615. + else
  25616. + {
  25617. + print_debug("Unknown temperature message!");
  25618. + return -EINVAL;
  25619. + }
  25620. +
  25621. + msg.msg_size = sizeof msg;
  25622. + msg.tag.buffer_size = 8;
  25623. +
  25624. + /* send the message */
  25625. + result = bcm_mailbox_property(&msg, sizeof msg);
  25626. +
  25627. + /* check if it was all ok and return the rate in milli degrees C */
  25628. + if (result == 0 && (msg.request_code & 0x80000000))
  25629. + temp = (uint)msg.tag.val;
  25630. + #ifdef HWMON_DEBUG_ENABLE
  25631. + else
  25632. + print_debug("Failed to get temperature!");
  25633. + #endif
  25634. + print_debug("Got temperature as %u",temp);
  25635. + print_debug("OUT");
  25636. + return sprintf(buf, "%u\n", temp);
  25637. +}
  25638. +
  25639. +
  25640. +static int bcm2835_hwmon_probe(struct platform_device *pdev)
  25641. +{
  25642. + int err;
  25643. +
  25644. + print_debug("IN");
  25645. + print_debug("HWMON Driver has been probed!");
  25646. +
  25647. + /* check that the device isn't null!*/
  25648. + if(pdev == NULL)
  25649. + {
  25650. + print_debug("Platform device is empty!");
  25651. + return -ENODEV;
  25652. + }
  25653. +
  25654. + /* allocate memory for neccessary data */
  25655. + bcm2835_data = kzalloc(sizeof(struct bcm2835_hwmon_data),GFP_KERNEL);
  25656. + if(!bcm2835_data)
  25657. + {
  25658. + print_debug("Unable to allocate memory for hwmon data!");
  25659. + err = -ENOMEM;
  25660. + goto kzalloc_error;
  25661. + }
  25662. +
  25663. + /* create the sysfs files */
  25664. + if(sysfs_create_group(&pdev->dev.kobj, &bcm2835_attr_group))
  25665. + {
  25666. + print_debug("Unable to create sysfs files!");
  25667. + err = -EFAULT;
  25668. + goto sysfs_error;
  25669. + }
  25670. +
  25671. + /* register the hwmon device */
  25672. + bcm2835_data->hwmon_dev = hwmon_device_register(&pdev->dev);
  25673. + if (IS_ERR(bcm2835_data->hwmon_dev))
  25674. + {
  25675. + err = PTR_ERR(bcm2835_data->hwmon_dev);
  25676. + goto hwmon_error;
  25677. + }
  25678. + print_debug("OUT");
  25679. + return 0;
  25680. +
  25681. + /* error goto's */
  25682. + hwmon_error:
  25683. + sysfs_remove_group(&pdev->dev.kobj, &bcm2835_attr_group);
  25684. +
  25685. + sysfs_error:
  25686. + kfree(bcm2835_data);
  25687. +
  25688. + kzalloc_error:
  25689. +
  25690. + return err;
  25691. +
  25692. +}
  25693. +
  25694. +static int bcm2835_hwmon_remove(struct platform_device *pdev)
  25695. +{
  25696. + print_debug("IN");
  25697. + hwmon_device_unregister(bcm2835_data->hwmon_dev);
  25698. +
  25699. + sysfs_remove_group(&pdev->dev.kobj, &bcm2835_attr_group);
  25700. + print_debug("OUT");
  25701. + return 0;
  25702. +}
  25703. +
  25704. +/* Hwmon Driver */
  25705. +static struct platform_driver bcm2835_hwmon_driver = {
  25706. + .probe = bcm2835_hwmon_probe,
  25707. + .remove = bcm2835_hwmon_remove,
  25708. + .driver = {
  25709. + .name = "bcm2835_hwmon",
  25710. + .owner = THIS_MODULE,
  25711. + },
  25712. +};
  25713. +
  25714. +MODULE_LICENSE("GPL");
  25715. +MODULE_AUTHOR("Dorian Peake");
  25716. +MODULE_DESCRIPTION("HW Monitor driver for bcm2835 chip");
  25717. +
  25718. +module_platform_driver(bcm2835_hwmon_driver);
  25719. diff -Nur linux-3.18.8/drivers/hwmon/Kconfig linux-rpi/drivers/hwmon/Kconfig
  25720. --- linux-3.18.8/drivers/hwmon/Kconfig 2015-02-27 02:49:36.000000000 +0100
  25721. +++ linux-rpi/drivers/hwmon/Kconfig 2015-03-05 14:40:13.025715828 +0100
  25722. @@ -1680,6 +1680,16 @@
  25723. This driver provides support for the Ultra45 workstation environmental
  25724. sensors.
  25725. +config SENSORS_BCM2835
  25726. + depends on THERMAL_BCM2835=n
  25727. + tristate "Broadcom BCM2835 HWMON Driver"
  25728. + help
  25729. + If you say yes here you get support for the hardware
  25730. + monitoring features of the BCM2835 Chip
  25731. +
  25732. + This driver can also be built as a module. If so, the module
  25733. + will be called bcm2835-hwmon.
  25734. +
  25735. if ACPI
  25736. comment "ACPI drivers"
  25737. diff -Nur linux-3.18.8/drivers/hwmon/Makefile linux-rpi/drivers/hwmon/Makefile
  25738. --- linux-3.18.8/drivers/hwmon/Makefile 2015-02-27 02:49:36.000000000 +0100
  25739. +++ linux-rpi/drivers/hwmon/Makefile 2015-03-05 14:40:13.025715828 +0100
  25740. @@ -153,6 +153,7 @@
  25741. obj-$(CONFIG_SENSORS_W83L786NG) += w83l786ng.o
  25742. obj-$(CONFIG_SENSORS_WM831X) += wm831x-hwmon.o
  25743. obj-$(CONFIG_SENSORS_WM8350) += wm8350-hwmon.o
  25744. +obj-$(CONFIG_SENSORS_BCM2835) += bcm2835-hwmon.o
  25745. obj-$(CONFIG_PMBUS) += pmbus/
  25746. diff -Nur linux-3.18.8/drivers/i2c/busses/i2c-bcm2708.c linux-rpi/drivers/i2c/busses/i2c-bcm2708.c
  25747. --- linux-3.18.8/drivers/i2c/busses/i2c-bcm2708.c 1970-01-01 01:00:00.000000000 +0100
  25748. +++ linux-rpi/drivers/i2c/busses/i2c-bcm2708.c 2015-03-05 14:40:13.045715828 +0100
  25749. @@ -0,0 +1,521 @@
  25750. +/*
  25751. + * Driver for Broadcom BCM2708 BSC Controllers
  25752. + *
  25753. + * Copyright (C) 2012 Chris Boot & Frank Buss
  25754. + *
  25755. + * This driver is inspired by:
  25756. + * i2c-ocores.c, by Peter Korsgaard <jacmet@sunsite.dk>
  25757. + *
  25758. + * This program is free software; you can redistribute it and/or modify
  25759. + * it under the terms of the GNU General Public License as published by
  25760. + * the Free Software Foundation; either version 2 of the License, or
  25761. + * (at your option) any later version.
  25762. + *
  25763. + * This program is distributed in the hope that it will be useful,
  25764. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  25765. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25766. + * GNU General Public License for more details.
  25767. + *
  25768. + * You should have received a copy of the GNU General Public License
  25769. + * along with this program; if not, write to the Free Software
  25770. + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  25771. + */
  25772. +
  25773. +#include <linux/kernel.h>
  25774. +#include <linux/module.h>
  25775. +#include <linux/spinlock.h>
  25776. +#include <linux/clk.h>
  25777. +#include <linux/err.h>
  25778. +#include <linux/of.h>
  25779. +#include <linux/platform_device.h>
  25780. +#include <linux/io.h>
  25781. +#include <linux/slab.h>
  25782. +#include <linux/i2c.h>
  25783. +#include <linux/interrupt.h>
  25784. +#include <linux/sched.h>
  25785. +#include <linux/wait.h>
  25786. +
  25787. +/* BSC register offsets */
  25788. +#define BSC_C 0x00
  25789. +#define BSC_S 0x04
  25790. +#define BSC_DLEN 0x08
  25791. +#define BSC_A 0x0c
  25792. +#define BSC_FIFO 0x10
  25793. +#define BSC_DIV 0x14
  25794. +#define BSC_DEL 0x18
  25795. +#define BSC_CLKT 0x1c
  25796. +
  25797. +/* Bitfields in BSC_C */
  25798. +#define BSC_C_I2CEN 0x00008000
  25799. +#define BSC_C_INTR 0x00000400
  25800. +#define BSC_C_INTT 0x00000200
  25801. +#define BSC_C_INTD 0x00000100
  25802. +#define BSC_C_ST 0x00000080
  25803. +#define BSC_C_CLEAR_1 0x00000020
  25804. +#define BSC_C_CLEAR_2 0x00000010
  25805. +#define BSC_C_READ 0x00000001
  25806. +
  25807. +/* Bitfields in BSC_S */
  25808. +#define BSC_S_CLKT 0x00000200
  25809. +#define BSC_S_ERR 0x00000100
  25810. +#define BSC_S_RXF 0x00000080
  25811. +#define BSC_S_TXE 0x00000040
  25812. +#define BSC_S_RXD 0x00000020
  25813. +#define BSC_S_TXD 0x00000010
  25814. +#define BSC_S_RXR 0x00000008
  25815. +#define BSC_S_TXW 0x00000004
  25816. +#define BSC_S_DONE 0x00000002
  25817. +#define BSC_S_TA 0x00000001
  25818. +
  25819. +#define I2C_TIMEOUT_MS 150
  25820. +#define I2C_WAIT_LOOP_COUNT 40
  25821. +
  25822. +#define DRV_NAME "bcm2708_i2c"
  25823. +
  25824. +static unsigned int baudrate = CONFIG_I2C_BCM2708_BAUDRATE;
  25825. +module_param(baudrate, uint, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
  25826. +MODULE_PARM_DESC(baudrate, "The I2C baudrate");
  25827. +
  25828. +static bool combined = false;
  25829. +module_param(combined, bool, 0644);
  25830. +MODULE_PARM_DESC(combined, "Use combined transactions");
  25831. +
  25832. +struct bcm2708_i2c {
  25833. + struct i2c_adapter adapter;
  25834. +
  25835. + spinlock_t lock;
  25836. + void __iomem *base;
  25837. + int irq;
  25838. + struct clk *clk;
  25839. + u32 cdiv;
  25840. +
  25841. + struct completion done;
  25842. +
  25843. + struct i2c_msg *msg;
  25844. + int pos;
  25845. + int nmsgs;
  25846. + bool error;
  25847. +};
  25848. +
  25849. +/*
  25850. + * This function sets the ALT mode on the I2C pins so that we can use them with
  25851. + * the BSC hardware.
  25852. + *
  25853. + * FIXME: This is a hack. Use pinmux / pinctrl.
  25854. + */
  25855. +static void bcm2708_i2c_init_pinmode(int id)
  25856. +{
  25857. +#define INP_GPIO(g) *(gpio+((g)/10)) &= ~(7<<(((g)%10)*3))
  25858. +#define SET_GPIO_ALT(g,a) *(gpio+(((g)/10))) |= (((a)<=3?(a)+4:(a)==4?3:2)<<(((g)%10)*3))
  25859. +
  25860. + int pin;
  25861. + u32 *gpio = ioremap(GPIO_BASE, SZ_16K);
  25862. +
  25863. + BUG_ON(id != 0 && id != 1);
  25864. + /* BSC0 is on GPIO 0 & 1, BSC1 is on GPIO 2 & 3 */
  25865. + for (pin = id*2+0; pin <= id*2+1; pin++) {
  25866. + printk("bcm2708_i2c_init_pinmode(%d,%d)\n", id, pin);
  25867. + INP_GPIO(pin); /* set mode to GPIO input first */
  25868. + SET_GPIO_ALT(pin, 0); /* set mode to ALT 0 */
  25869. + }
  25870. +
  25871. + iounmap(gpio);
  25872. +
  25873. +#undef INP_GPIO
  25874. +#undef SET_GPIO_ALT
  25875. +}
  25876. +
  25877. +static inline u32 bcm2708_rd(struct bcm2708_i2c *bi, unsigned reg)
  25878. +{
  25879. + return readl(bi->base + reg);
  25880. +}
  25881. +
  25882. +static inline void bcm2708_wr(struct bcm2708_i2c *bi, unsigned reg, u32 val)
  25883. +{
  25884. + writel(val, bi->base + reg);
  25885. +}
  25886. +
  25887. +static inline void bcm2708_bsc_reset(struct bcm2708_i2c *bi)
  25888. +{
  25889. + bcm2708_wr(bi, BSC_C, 0);
  25890. + bcm2708_wr(bi, BSC_S, BSC_S_CLKT | BSC_S_ERR | BSC_S_DONE);
  25891. +}
  25892. +
  25893. +static inline void bcm2708_bsc_fifo_drain(struct bcm2708_i2c *bi)
  25894. +{
  25895. + while ((bcm2708_rd(bi, BSC_S) & BSC_S_RXD) && (bi->pos < bi->msg->len))
  25896. + bi->msg->buf[bi->pos++] = bcm2708_rd(bi, BSC_FIFO);
  25897. +}
  25898. +
  25899. +static inline void bcm2708_bsc_fifo_fill(struct bcm2708_i2c *bi)
  25900. +{
  25901. + while ((bcm2708_rd(bi, BSC_S) & BSC_S_TXD) && (bi->pos < bi->msg->len))
  25902. + bcm2708_wr(bi, BSC_FIFO, bi->msg->buf[bi->pos++]);
  25903. +}
  25904. +
  25905. +static inline int bcm2708_bsc_setup(struct bcm2708_i2c *bi)
  25906. +{
  25907. + u32 cdiv, s;
  25908. + u32 c = BSC_C_I2CEN | BSC_C_INTD | BSC_C_ST | BSC_C_CLEAR_1;
  25909. + int wait_loops = I2C_WAIT_LOOP_COUNT;
  25910. +
  25911. + /* Can't call clk_get_rate as it locks a mutex and here we are spinlocked.
  25912. + * Use the value that we cached in the probe.
  25913. + */
  25914. + cdiv = bi->cdiv;
  25915. +
  25916. + if (bi->msg->flags & I2C_M_RD)
  25917. + c |= BSC_C_INTR | BSC_C_READ;
  25918. + else
  25919. + c |= BSC_C_INTT;
  25920. +
  25921. + bcm2708_wr(bi, BSC_DIV, cdiv);
  25922. + bcm2708_wr(bi, BSC_A, bi->msg->addr);
  25923. + bcm2708_wr(bi, BSC_DLEN, bi->msg->len);
  25924. + if (combined)
  25925. + {
  25926. + /* Do the next two messages meet combined transaction criteria?
  25927. + - Current message is a write, next message is a read
  25928. + - Both messages to same slave address
  25929. + - Write message can fit inside FIFO (16 bytes or less) */
  25930. + if ( (bi->nmsgs > 1) &&
  25931. + !(bi->msg[0].flags & I2C_M_RD) && (bi->msg[1].flags & I2C_M_RD) &&
  25932. + (bi->msg[0].addr == bi->msg[1].addr) && (bi->msg[0].len <= 16)) {
  25933. + /* Fill FIFO with entire write message (16 byte FIFO) */
  25934. + while (bi->pos < bi->msg->len) {
  25935. + bcm2708_wr(bi, BSC_FIFO, bi->msg->buf[bi->pos++]);
  25936. + }
  25937. + /* Start write transfer (no interrupts, don't clear FIFO) */
  25938. + bcm2708_wr(bi, BSC_C, BSC_C_I2CEN | BSC_C_ST);
  25939. +
  25940. + /* poll for transfer start bit (should only take 1-20 polls) */
  25941. + do {
  25942. + s = bcm2708_rd(bi, BSC_S);
  25943. + } while (!(s & (BSC_S_TA | BSC_S_ERR | BSC_S_CLKT | BSC_S_DONE)) && --wait_loops >= 0);
  25944. +
  25945. + /* did we time out or some error occured? */
  25946. + if (wait_loops < 0 || (s & (BSC_S_ERR | BSC_S_CLKT))) {
  25947. + return -1;
  25948. + }
  25949. +
  25950. + /* Send next read message before the write transfer finishes. */
  25951. + bi->nmsgs--;
  25952. + bi->msg++;
  25953. + bi->pos = 0;
  25954. + bcm2708_wr(bi, BSC_DLEN, bi->msg->len);
  25955. + c = BSC_C_I2CEN | BSC_C_INTD | BSC_C_INTR | BSC_C_ST | BSC_C_READ;
  25956. + }
  25957. + }
  25958. + bcm2708_wr(bi, BSC_C, c);
  25959. +
  25960. + return 0;
  25961. +}
  25962. +
  25963. +static irqreturn_t bcm2708_i2c_interrupt(int irq, void *dev_id)
  25964. +{
  25965. + struct bcm2708_i2c *bi = dev_id;
  25966. + bool handled = true;
  25967. + u32 s;
  25968. + int ret;
  25969. +
  25970. + spin_lock(&bi->lock);
  25971. +
  25972. + /* we may see camera interrupts on the "other" I2C channel
  25973. + Just return if we've not sent anything */
  25974. + if (!bi->nmsgs || !bi->msg) {
  25975. + goto early_exit;
  25976. + }
  25977. +
  25978. + s = bcm2708_rd(bi, BSC_S);
  25979. +
  25980. + if (s & (BSC_S_CLKT | BSC_S_ERR)) {
  25981. + bcm2708_bsc_reset(bi);
  25982. + bi->error = true;
  25983. +
  25984. + bi->msg = 0; /* to inform the that all work is done */
  25985. + bi->nmsgs = 0;
  25986. + /* wake up our bh */
  25987. + complete(&bi->done);
  25988. + } else if (s & BSC_S_DONE) {
  25989. + bi->nmsgs--;
  25990. +
  25991. + if (bi->msg->flags & I2C_M_RD) {
  25992. + bcm2708_bsc_fifo_drain(bi);
  25993. + }
  25994. +
  25995. + bcm2708_bsc_reset(bi);
  25996. +
  25997. + if (bi->nmsgs) {
  25998. + /* advance to next message */
  25999. + bi->msg++;
  26000. + bi->pos = 0;
  26001. + ret = bcm2708_bsc_setup(bi);
  26002. + if (ret < 0) {
  26003. + bcm2708_bsc_reset(bi);
  26004. + bi->error = true;
  26005. + bi->msg = 0; /* to inform the that all work is done */
  26006. + bi->nmsgs = 0;
  26007. + /* wake up our bh */
  26008. + complete(&bi->done);
  26009. + goto early_exit;
  26010. + }
  26011. + } else {
  26012. + bi->msg = 0; /* to inform the that all work is done */
  26013. + bi->nmsgs = 0;
  26014. + /* wake up our bh */
  26015. + complete(&bi->done);
  26016. + }
  26017. + } else if (s & BSC_S_TXW) {
  26018. + bcm2708_bsc_fifo_fill(bi);
  26019. + } else if (s & BSC_S_RXR) {
  26020. + bcm2708_bsc_fifo_drain(bi);
  26021. + } else {
  26022. + handled = false;
  26023. + }
  26024. +
  26025. +early_exit:
  26026. + spin_unlock(&bi->lock);
  26027. +
  26028. + return handled ? IRQ_HANDLED : IRQ_NONE;
  26029. +}
  26030. +
  26031. +static int bcm2708_i2c_master_xfer(struct i2c_adapter *adap,
  26032. + struct i2c_msg *msgs, int num)
  26033. +{
  26034. + struct bcm2708_i2c *bi = adap->algo_data;
  26035. + unsigned long flags;
  26036. + int ret;
  26037. +
  26038. + spin_lock_irqsave(&bi->lock, flags);
  26039. +
  26040. + reinit_completion(&bi->done);
  26041. + bi->msg = msgs;
  26042. + bi->pos = 0;
  26043. + bi->nmsgs = num;
  26044. + bi->error = false;
  26045. +
  26046. + ret = bcm2708_bsc_setup(bi);
  26047. +
  26048. + spin_unlock_irqrestore(&bi->lock, flags);
  26049. +
  26050. + /* check the result of the setup */
  26051. + if (ret < 0)
  26052. + {
  26053. + dev_err(&adap->dev, "transfer setup timed out\n");
  26054. + goto error_timeout;
  26055. + }
  26056. +
  26057. + ret = wait_for_completion_timeout(&bi->done, msecs_to_jiffies(I2C_TIMEOUT_MS));
  26058. + if (ret == 0) {
  26059. + dev_err(&adap->dev, "transfer timed out\n");
  26060. + goto error_timeout;
  26061. + }
  26062. +
  26063. + ret = bi->error ? -EIO : num;
  26064. + return ret;
  26065. +
  26066. +error_timeout:
  26067. + spin_lock_irqsave(&bi->lock, flags);
  26068. + bcm2708_bsc_reset(bi);
  26069. + bi->msg = 0; /* to inform the interrupt handler that there's nothing else to be done */
  26070. + bi->nmsgs = 0;
  26071. + spin_unlock_irqrestore(&bi->lock, flags);
  26072. + return -ETIMEDOUT;
  26073. +}
  26074. +
  26075. +static u32 bcm2708_i2c_functionality(struct i2c_adapter *adap)
  26076. +{
  26077. + return I2C_FUNC_I2C | /*I2C_FUNC_10BIT_ADDR |*/ I2C_FUNC_SMBUS_EMUL;
  26078. +}
  26079. +
  26080. +static struct i2c_algorithm bcm2708_i2c_algorithm = {
  26081. + .master_xfer = bcm2708_i2c_master_xfer,
  26082. + .functionality = bcm2708_i2c_functionality,
  26083. +};
  26084. +
  26085. +static int bcm2708_i2c_probe(struct platform_device *pdev)
  26086. +{
  26087. + struct resource *regs;
  26088. + int irq, err = -ENOMEM;
  26089. + struct clk *clk;
  26090. + struct bcm2708_i2c *bi;
  26091. + struct i2c_adapter *adap;
  26092. + unsigned long bus_hz;
  26093. + u32 cdiv;
  26094. +
  26095. + if (pdev->dev.of_node) {
  26096. + u32 bus_clk_rate;
  26097. + pdev->id = of_alias_get_id(pdev->dev.of_node, "i2c");
  26098. + if (pdev->id < 0) {
  26099. + dev_err(&pdev->dev, "alias is missing\n");
  26100. + return -EINVAL;
  26101. + }
  26102. + if (!of_property_read_u32(pdev->dev.of_node,
  26103. + "clock-frequency", &bus_clk_rate))
  26104. + baudrate = bus_clk_rate;
  26105. + else
  26106. + dev_warn(&pdev->dev,
  26107. + "Could not read clock-frequency property\n");
  26108. + }
  26109. +
  26110. + regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  26111. + if (!regs) {
  26112. + dev_err(&pdev->dev, "could not get IO memory\n");
  26113. + return -ENXIO;
  26114. + }
  26115. +
  26116. + irq = platform_get_irq(pdev, 0);
  26117. + if (irq < 0) {
  26118. + dev_err(&pdev->dev, "could not get IRQ\n");
  26119. + return irq;
  26120. + }
  26121. +
  26122. + clk = clk_get(&pdev->dev, NULL);
  26123. + if (IS_ERR(clk)) {
  26124. + dev_err(&pdev->dev, "could not find clk: %ld\n", PTR_ERR(clk));
  26125. + return PTR_ERR(clk);
  26126. + }
  26127. +
  26128. + err = clk_prepare_enable(clk);
  26129. + if (err) {
  26130. + dev_err(&pdev->dev, "could not enable clk: %d\n", err);
  26131. + goto out_clk_put;
  26132. + }
  26133. +
  26134. + bcm2708_i2c_init_pinmode(pdev->id);
  26135. +
  26136. + bi = kzalloc(sizeof(*bi), GFP_KERNEL);
  26137. + if (!bi)
  26138. + goto out_clk_disable;
  26139. +
  26140. + platform_set_drvdata(pdev, bi);
  26141. +
  26142. + adap = &bi->adapter;
  26143. + adap->class = I2C_CLASS_HWMON | I2C_CLASS_DDC;
  26144. + adap->algo = &bcm2708_i2c_algorithm;
  26145. + adap->algo_data = bi;
  26146. + adap->dev.parent = &pdev->dev;
  26147. + adap->nr = pdev->id;
  26148. + strlcpy(adap->name, dev_name(&pdev->dev), sizeof(adap->name));
  26149. + adap->dev.of_node = pdev->dev.of_node;
  26150. +
  26151. + switch (pdev->id) {
  26152. + case 0:
  26153. + adap->class = I2C_CLASS_HWMON;
  26154. + break;
  26155. + case 1:
  26156. + adap->class = I2C_CLASS_DDC;
  26157. + break;
  26158. + default:
  26159. + dev_err(&pdev->dev, "can only bind to BSC 0 or 1\n");
  26160. + err = -ENXIO;
  26161. + goto out_free_bi;
  26162. + }
  26163. +
  26164. + spin_lock_init(&bi->lock);
  26165. + init_completion(&bi->done);
  26166. +
  26167. + bi->base = ioremap(regs->start, resource_size(regs));
  26168. + if (!bi->base) {
  26169. + dev_err(&pdev->dev, "could not remap memory\n");
  26170. + goto out_free_bi;
  26171. + }
  26172. +
  26173. + bi->irq = irq;
  26174. + bi->clk = clk;
  26175. +
  26176. + err = request_irq(irq, bcm2708_i2c_interrupt, IRQF_SHARED,
  26177. + dev_name(&pdev->dev), bi);
  26178. + if (err) {
  26179. + dev_err(&pdev->dev, "could not request IRQ: %d\n", err);
  26180. + goto out_iounmap;
  26181. + }
  26182. +
  26183. + bcm2708_bsc_reset(bi);
  26184. +
  26185. + err = i2c_add_numbered_adapter(adap);
  26186. + if (err < 0) {
  26187. + dev_err(&pdev->dev, "could not add I2C adapter: %d\n", err);
  26188. + goto out_free_irq;
  26189. + }
  26190. +
  26191. + bus_hz = clk_get_rate(bi->clk);
  26192. + cdiv = bus_hz / baudrate;
  26193. + if (cdiv > 0xffff) {
  26194. + cdiv = 0xffff;
  26195. + baudrate = bus_hz / cdiv;
  26196. + }
  26197. + bi->cdiv = cdiv;
  26198. +
  26199. + dev_info(&pdev->dev, "BSC%d Controller at 0x%08lx (irq %d) (baudrate %d)\n",
  26200. + pdev->id, (unsigned long)regs->start, irq, baudrate);
  26201. +
  26202. + return 0;
  26203. +
  26204. +out_free_irq:
  26205. + free_irq(bi->irq, bi);
  26206. +out_iounmap:
  26207. + iounmap(bi->base);
  26208. +out_free_bi:
  26209. + kfree(bi);
  26210. +out_clk_disable:
  26211. + clk_disable_unprepare(clk);
  26212. +out_clk_put:
  26213. + clk_put(clk);
  26214. + return err;
  26215. +}
  26216. +
  26217. +static int bcm2708_i2c_remove(struct platform_device *pdev)
  26218. +{
  26219. + struct bcm2708_i2c *bi = platform_get_drvdata(pdev);
  26220. +
  26221. + platform_set_drvdata(pdev, NULL);
  26222. +
  26223. + i2c_del_adapter(&bi->adapter);
  26224. + free_irq(bi->irq, bi);
  26225. + iounmap(bi->base);
  26226. + clk_disable_unprepare(bi->clk);
  26227. + clk_put(bi->clk);
  26228. + kfree(bi);
  26229. +
  26230. + return 0;
  26231. +}
  26232. +
  26233. +static const struct of_device_id bcm2708_i2c_of_match[] = {
  26234. + { .compatible = "brcm,bcm2708-i2c" },
  26235. + {},
  26236. +};
  26237. +MODULE_DEVICE_TABLE(of, bcm2708_i2c_of_match);
  26238. +
  26239. +static struct platform_driver bcm2708_i2c_driver = {
  26240. + .driver = {
  26241. + .name = DRV_NAME,
  26242. + .owner = THIS_MODULE,
  26243. + .of_match_table = bcm2708_i2c_of_match,
  26244. + },
  26245. + .probe = bcm2708_i2c_probe,
  26246. + .remove = bcm2708_i2c_remove,
  26247. +};
  26248. +
  26249. +// module_platform_driver(bcm2708_i2c_driver);
  26250. +
  26251. +
  26252. +static int __init bcm2708_i2c_init(void)
  26253. +{
  26254. + return platform_driver_register(&bcm2708_i2c_driver);
  26255. +}
  26256. +
  26257. +static void __exit bcm2708_i2c_exit(void)
  26258. +{
  26259. + platform_driver_unregister(&bcm2708_i2c_driver);
  26260. +}
  26261. +
  26262. +module_init(bcm2708_i2c_init);
  26263. +module_exit(bcm2708_i2c_exit);
  26264. +
  26265. +
  26266. +
  26267. +MODULE_DESCRIPTION("BSC controller driver for Broadcom BCM2708");
  26268. +MODULE_AUTHOR("Chris Boot <bootc@bootc.net>");
  26269. +MODULE_LICENSE("GPL v2");
  26270. +MODULE_ALIAS("platform:" DRV_NAME);
  26271. diff -Nur linux-3.18.8/drivers/i2c/busses/Kconfig linux-rpi/drivers/i2c/busses/Kconfig
  26272. --- linux-3.18.8/drivers/i2c/busses/Kconfig 2015-02-27 02:49:36.000000000 +0100
  26273. +++ linux-rpi/drivers/i2c/busses/Kconfig 2015-03-05 14:40:13.045715828 +0100
  26274. @@ -361,7 +361,7 @@
  26275. config I2C_BCM2835
  26276. tristate "Broadcom BCM2835 I2C controller"
  26277. - depends on ARCH_BCM2835
  26278. + depends on ARCH_BCM2835 || ARCH_BCM2708 || ARCH_BCM2709
  26279. help
  26280. If you say yes to this option, support will be included for the
  26281. BCM2835 I2C controller.
  26282. @@ -371,6 +371,25 @@
  26283. This support is also available as a module. If so, the module
  26284. will be called i2c-bcm2835.
  26285. +config I2C_BCM2708
  26286. + tristate "BCM2708 BSC"
  26287. + depends on MACH_BCM2708 || MACH_BCM2709
  26288. + help
  26289. + Enabling this option will add BSC (Broadcom Serial Controller)
  26290. + support for the BCM2708. BSC is a Broadcom proprietary bus compatible
  26291. + with I2C/TWI/SMBus.
  26292. +
  26293. +config I2C_BCM2708_BAUDRATE
  26294. + prompt "BCM2708 I2C baudrate"
  26295. + depends on I2C_BCM2708
  26296. + int
  26297. + default 100000
  26298. + help
  26299. + Set the I2C baudrate. This will alter the default value. A
  26300. + different baudrate can be set by using a module parameter as well. If
  26301. + no parameter is provided when loading, this is the value that will be
  26302. + used.
  26303. +
  26304. config I2C_BCM_KONA
  26305. tristate "BCM Kona I2C adapter"
  26306. depends on ARCH_BCM_MOBILE
  26307. diff -Nur linux-3.18.8/drivers/i2c/busses/Makefile linux-rpi/drivers/i2c/busses/Makefile
  26308. --- linux-3.18.8/drivers/i2c/busses/Makefile 2015-02-27 02:49:36.000000000 +0100
  26309. +++ linux-rpi/drivers/i2c/busses/Makefile 2015-03-05 14:40:13.045715828 +0100
  26310. @@ -33,6 +33,7 @@
  26311. obj-$(CONFIG_I2C_AU1550) += i2c-au1550.o
  26312. obj-$(CONFIG_I2C_AXXIA) += i2c-axxia.o
  26313. obj-$(CONFIG_I2C_BCM2835) += i2c-bcm2835.o
  26314. +obj-$(CONFIG_I2C_BCM2708) += i2c-bcm2708.o
  26315. obj-$(CONFIG_I2C_BLACKFIN_TWI) += i2c-bfin-twi.o
  26316. obj-$(CONFIG_I2C_CADENCE) += i2c-cadence.o
  26317. obj-$(CONFIG_I2C_CBUS_GPIO) += i2c-cbus-gpio.o
  26318. diff -Nur linux-3.18.8/drivers/leds/trigger/Kconfig linux-rpi/drivers/leds/trigger/Kconfig
  26319. --- linux-3.18.8/drivers/leds/trigger/Kconfig 2015-02-27 02:49:36.000000000 +0100
  26320. +++ linux-rpi/drivers/leds/trigger/Kconfig 2015-03-05 14:40:13.401715826 +0100
  26321. @@ -108,4 +108,11 @@
  26322. This enables direct flash/torch on/off by the driver, kernel space.
  26323. If unsure, say Y.
  26324. +config LEDS_TRIGGER_INPUT
  26325. + tristate "LED Input Trigger"
  26326. + depends on LEDS_TRIGGERS
  26327. + help
  26328. + This allows the GPIOs assigned to be LEDs to be initialised to inputs.
  26329. + If unsure, say Y.
  26330. +
  26331. endif # LEDS_TRIGGERS
  26332. diff -Nur linux-3.18.8/drivers/leds/trigger/ledtrig-input.c linux-rpi/drivers/leds/trigger/ledtrig-input.c
  26333. --- linux-3.18.8/drivers/leds/trigger/ledtrig-input.c 1970-01-01 01:00:00.000000000 +0100
  26334. +++ linux-rpi/drivers/leds/trigger/ledtrig-input.c 2015-03-05 14:40:13.401715826 +0100
  26335. @@ -0,0 +1,65 @@
  26336. +/*
  26337. + * Set LED GPIO to Input "Trigger"
  26338. + *
  26339. + * Copyright 2015 Phil Elwell <phil@raspberrypi.org>
  26340. + *
  26341. + * Based on Nick Forbes's ledtrig-default-on.c.
  26342. + *
  26343. + * This program is free software; you can redistribute it and/or modify
  26344. + * it under the terms of the GNU General Public License version 2 as
  26345. + * published by the Free Software Foundation.
  26346. + *
  26347. + */
  26348. +
  26349. +#include <linux/module.h>
  26350. +#include <linux/kernel.h>
  26351. +#include <linux/init.h>
  26352. +#include <linux/leds.h>
  26353. +#include <linux/gpio.h>
  26354. +#include "../leds.h"
  26355. +
  26356. +/* This is a hack to get at the private 'gpio' member */
  26357. +
  26358. +struct gpio_led_data {
  26359. + struct led_classdev cdev;
  26360. + unsigned gpio;
  26361. +};
  26362. +
  26363. +static void input_trig_activate(struct led_classdev *led_cdev)
  26364. +{
  26365. + struct gpio_led_data *led_dat =
  26366. + container_of(led_cdev, struct gpio_led_data, cdev);
  26367. + if (gpio_is_valid(led_dat->gpio))
  26368. + gpio_direction_input(led_dat->gpio);
  26369. +}
  26370. +
  26371. +static void input_trig_deactivate(struct led_classdev *led_cdev)
  26372. +{
  26373. + struct gpio_led_data *led_dat =
  26374. + container_of(led_cdev, struct gpio_led_data, cdev);
  26375. + if (gpio_is_valid(led_dat->gpio))
  26376. + gpio_direction_output(led_dat->gpio, 0);
  26377. +}
  26378. +
  26379. +static struct led_trigger input_led_trigger = {
  26380. + .name = "input",
  26381. + .activate = input_trig_activate,
  26382. + .deactivate = input_trig_deactivate,
  26383. +};
  26384. +
  26385. +static int __init input_trig_init(void)
  26386. +{
  26387. + return led_trigger_register(&input_led_trigger);
  26388. +}
  26389. +
  26390. +static void __exit input_trig_exit(void)
  26391. +{
  26392. + led_trigger_unregister(&input_led_trigger);
  26393. +}
  26394. +
  26395. +module_init(input_trig_init);
  26396. +module_exit(input_trig_exit);
  26397. +
  26398. +MODULE_AUTHOR("Phil Elwell <phil@raspberrypi.org>");
  26399. +MODULE_DESCRIPTION("Set LED GPIO to Input \"trigger\"");
  26400. +MODULE_LICENSE("GPL");
  26401. diff -Nur linux-3.18.8/drivers/leds/trigger/Makefile linux-rpi/drivers/leds/trigger/Makefile
  26402. --- linux-3.18.8/drivers/leds/trigger/Makefile 2015-02-27 02:49:36.000000000 +0100
  26403. +++ linux-rpi/drivers/leds/trigger/Makefile 2015-03-05 14:40:13.401715826 +0100
  26404. @@ -8,3 +8,4 @@
  26405. obj-$(CONFIG_LEDS_TRIGGER_DEFAULT_ON) += ledtrig-default-on.o
  26406. obj-$(CONFIG_LEDS_TRIGGER_TRANSIENT) += ledtrig-transient.o
  26407. obj-$(CONFIG_LEDS_TRIGGER_CAMERA) += ledtrig-camera.o
  26408. +obj-$(CONFIG_LEDS_TRIGGER_INPUT) += ledtrig-input.o
  26409. diff -Nur linux-3.18.8/drivers/media/platform/bcm2835/bcm2835-camera.c linux-rpi/drivers/media/platform/bcm2835/bcm2835-camera.c
  26410. --- linux-3.18.8/drivers/media/platform/bcm2835/bcm2835-camera.c 1970-01-01 01:00:00.000000000 +0100
  26411. +++ linux-rpi/drivers/media/platform/bcm2835/bcm2835-camera.c 2015-03-05 14:40:13.981715822 +0100
  26412. @@ -0,0 +1,1828 @@
  26413. +/*
  26414. + * Broadcom BM2835 V4L2 driver
  26415. + *
  26416. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  26417. + *
  26418. + * This file is subject to the terms and conditions of the GNU General Public
  26419. + * License. See the file COPYING in the main directory of this archive
  26420. + * for more details.
  26421. + *
  26422. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  26423. + * Dave Stevenson <dsteve@broadcom.com>
  26424. + * Simon Mellor <simellor@broadcom.com>
  26425. + * Luke Diamand <luked@broadcom.com>
  26426. + */
  26427. +
  26428. +#include <linux/errno.h>
  26429. +#include <linux/kernel.h>
  26430. +#include <linux/module.h>
  26431. +#include <linux/slab.h>
  26432. +#include <media/videobuf2-vmalloc.h>
  26433. +#include <media/videobuf2-dma-contig.h>
  26434. +#include <media/v4l2-device.h>
  26435. +#include <media/v4l2-ioctl.h>
  26436. +#include <media/v4l2-ctrls.h>
  26437. +#include <media/v4l2-fh.h>
  26438. +#include <media/v4l2-event.h>
  26439. +#include <media/v4l2-common.h>
  26440. +#include <linux/delay.h>
  26441. +
  26442. +#include "mmal-common.h"
  26443. +#include "mmal-encodings.h"
  26444. +#include "mmal-vchiq.h"
  26445. +#include "mmal-msg.h"
  26446. +#include "mmal-parameters.h"
  26447. +#include "bcm2835-camera.h"
  26448. +
  26449. +#define BM2835_MMAL_VERSION "0.0.2"
  26450. +#define BM2835_MMAL_MODULE_NAME "bcm2835-v4l2"
  26451. +#define MIN_WIDTH 16
  26452. +#define MIN_HEIGHT 16
  26453. +#define MAX_WIDTH 2592
  26454. +#define MAX_HEIGHT 1944
  26455. +#define MIN_BUFFER_SIZE (80*1024)
  26456. +
  26457. +#define MAX_VIDEO_MODE_WIDTH 1280
  26458. +#define MAX_VIDEO_MODE_HEIGHT 720
  26459. +
  26460. +MODULE_DESCRIPTION("Broadcom 2835 MMAL video capture");
  26461. +MODULE_AUTHOR("Vincent Sanders");
  26462. +MODULE_LICENSE("GPL");
  26463. +MODULE_VERSION(BM2835_MMAL_VERSION);
  26464. +
  26465. +int bcm2835_v4l2_debug;
  26466. +module_param_named(debug, bcm2835_v4l2_debug, int, 0644);
  26467. +MODULE_PARM_DESC(bcm2835_v4l2_debug, "Debug level 0-2");
  26468. +
  26469. +int max_video_width = MAX_VIDEO_MODE_WIDTH;
  26470. +int max_video_height = MAX_VIDEO_MODE_HEIGHT;
  26471. +module_param(max_video_width, int, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
  26472. +MODULE_PARM_DESC(max_video_width, "Threshold for video mode");
  26473. +module_param(max_video_height, int, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
  26474. +MODULE_PARM_DESC(max_video_height, "Threshold for video mode");
  26475. +
  26476. +/* Gstreamer bug https://bugzilla.gnome.org/show_bug.cgi?id=726521
  26477. + * v4l2src does bad (and actually wrong) things when the vidioc_enum_framesizes
  26478. + * function says type V4L2_FRMSIZE_TYPE_STEPWISE, which we do by default.
  26479. + * It's happier if we just don't say anything at all, when it then
  26480. + * sets up a load of defaults that it thinks might work.
  26481. + * If gst_v4l2src_is_broken is non-zero, then we remove the function from
  26482. + * our function table list (actually switch to an alternate set, but same
  26483. + * result).
  26484. + */
  26485. +int gst_v4l2src_is_broken = 0;
  26486. +module_param(gst_v4l2src_is_broken, int, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
  26487. +MODULE_PARM_DESC(gst_v4l2src_is_broken, "If non-zero, enable workaround for Gstreamer");
  26488. +
  26489. +static struct bm2835_mmal_dev *gdev; /* global device data */
  26490. +
  26491. +#define FPS_MIN 1
  26492. +#define FPS_MAX 90
  26493. +
  26494. +/* timeperframe: min/max and default */
  26495. +static const struct v4l2_fract
  26496. + tpf_min = {.numerator = 1, .denominator = FPS_MAX},
  26497. + tpf_max = {.numerator = 1, .denominator = FPS_MIN},
  26498. + tpf_default = {.numerator = 1000, .denominator = 30000};
  26499. +
  26500. +/* video formats */
  26501. +static struct mmal_fmt formats[] = {
  26502. + {
  26503. + .name = "4:2:0, packed YUV",
  26504. + .fourcc = V4L2_PIX_FMT_YUV420,
  26505. + .flags = 0,
  26506. + .mmal = MMAL_ENCODING_I420,
  26507. + .depth = 12,
  26508. + .mmal_component = MMAL_COMPONENT_CAMERA,
  26509. + },
  26510. + {
  26511. + .name = "4:2:2, packed, YUYV",
  26512. + .fourcc = V4L2_PIX_FMT_YUYV,
  26513. + .flags = 0,
  26514. + .mmal = MMAL_ENCODING_YUYV,
  26515. + .depth = 16,
  26516. + .mmal_component = MMAL_COMPONENT_CAMERA,
  26517. + },
  26518. + {
  26519. + .name = "RGB24 (LE)",
  26520. + .fourcc = V4L2_PIX_FMT_RGB24,
  26521. + .flags = 0,
  26522. + .mmal = MMAL_ENCODING_BGR24,
  26523. + .depth = 24,
  26524. + .mmal_component = MMAL_COMPONENT_CAMERA,
  26525. + },
  26526. + {
  26527. + .name = "JPEG",
  26528. + .fourcc = V4L2_PIX_FMT_JPEG,
  26529. + .flags = V4L2_FMT_FLAG_COMPRESSED,
  26530. + .mmal = MMAL_ENCODING_JPEG,
  26531. + .depth = 8,
  26532. + .mmal_component = MMAL_COMPONENT_IMAGE_ENCODE,
  26533. + },
  26534. + {
  26535. + .name = "H264",
  26536. + .fourcc = V4L2_PIX_FMT_H264,
  26537. + .flags = V4L2_FMT_FLAG_COMPRESSED,
  26538. + .mmal = MMAL_ENCODING_H264,
  26539. + .depth = 8,
  26540. + .mmal_component = MMAL_COMPONENT_VIDEO_ENCODE,
  26541. + },
  26542. + {
  26543. + .name = "MJPEG",
  26544. + .fourcc = V4L2_PIX_FMT_MJPEG,
  26545. + .flags = V4L2_FMT_FLAG_COMPRESSED,
  26546. + .mmal = MMAL_ENCODING_MJPEG,
  26547. + .depth = 8,
  26548. + .mmal_component = MMAL_COMPONENT_VIDEO_ENCODE,
  26549. + },
  26550. + {
  26551. + .name = "4:2:2, packed, YVYU",
  26552. + .fourcc = V4L2_PIX_FMT_YVYU,
  26553. + .flags = 0,
  26554. + .mmal = MMAL_ENCODING_YVYU,
  26555. + .depth = 16,
  26556. + .mmal_component = MMAL_COMPONENT_CAMERA,
  26557. + },
  26558. + {
  26559. + .name = "4:2:2, packed, VYUY",
  26560. + .fourcc = V4L2_PIX_FMT_VYUY,
  26561. + .flags = 0,
  26562. + .mmal = MMAL_ENCODING_VYUY,
  26563. + .depth = 16,
  26564. + .mmal_component = MMAL_COMPONENT_CAMERA,
  26565. + },
  26566. + {
  26567. + .name = "4:2:2, packed, UYVY",
  26568. + .fourcc = V4L2_PIX_FMT_UYVY,
  26569. + .flags = 0,
  26570. + .mmal = MMAL_ENCODING_UYVY,
  26571. + .depth = 16,
  26572. + .mmal_component = MMAL_COMPONENT_CAMERA,
  26573. + },
  26574. + {
  26575. + .name = "4:2:0, packed, NV12",
  26576. + .fourcc = V4L2_PIX_FMT_NV12,
  26577. + .flags = 0,
  26578. + .mmal = MMAL_ENCODING_NV12,
  26579. + .depth = 12,
  26580. + .mmal_component = MMAL_COMPONENT_CAMERA,
  26581. + },
  26582. + {
  26583. + .name = "RGB24 (BE)",
  26584. + .fourcc = V4L2_PIX_FMT_BGR24,
  26585. + .flags = 0,
  26586. + .mmal = MMAL_ENCODING_RGB24,
  26587. + .depth = 24,
  26588. + .mmal_component = MMAL_COMPONENT_CAMERA,
  26589. + },
  26590. + {
  26591. + .name = "4:2:0, packed YVU",
  26592. + .fourcc = V4L2_PIX_FMT_YVU420,
  26593. + .flags = 0,
  26594. + .mmal = MMAL_ENCODING_YV12,
  26595. + .depth = 12,
  26596. + .mmal_component = MMAL_COMPONENT_CAMERA,
  26597. + },
  26598. + {
  26599. + .name = "4:2:0, packed, NV21",
  26600. + .fourcc = V4L2_PIX_FMT_NV21,
  26601. + .flags = 0,
  26602. + .mmal = MMAL_ENCODING_NV21,
  26603. + .depth = 12,
  26604. + .mmal_component = MMAL_COMPONENT_CAMERA,
  26605. + },
  26606. + {
  26607. + .name = "RGB32 (BE)",
  26608. + .fourcc = V4L2_PIX_FMT_BGR32,
  26609. + .flags = 0,
  26610. + .mmal = MMAL_ENCODING_BGRA,
  26611. + .depth = 32,
  26612. + .mmal_component = MMAL_COMPONENT_CAMERA,
  26613. + },
  26614. +};
  26615. +
  26616. +static struct mmal_fmt *get_format(struct v4l2_format *f)
  26617. +{
  26618. + struct mmal_fmt *fmt;
  26619. + unsigned int k;
  26620. +
  26621. + for (k = 0; k < ARRAY_SIZE(formats); k++) {
  26622. + fmt = &formats[k];
  26623. + if (fmt->fourcc == f->fmt.pix.pixelformat)
  26624. + break;
  26625. + }
  26626. +
  26627. + if (k == ARRAY_SIZE(formats))
  26628. + return NULL;
  26629. +
  26630. + return &formats[k];
  26631. +}
  26632. +
  26633. +/* ------------------------------------------------------------------
  26634. + Videobuf queue operations
  26635. + ------------------------------------------------------------------*/
  26636. +
  26637. +static int queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
  26638. + unsigned int *nbuffers, unsigned int *nplanes,
  26639. + unsigned int sizes[], void *alloc_ctxs[])
  26640. +{
  26641. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
  26642. + unsigned long size;
  26643. +
  26644. + /* refuse queue setup if port is not configured */
  26645. + if (dev->capture.port == NULL) {
  26646. + v4l2_err(&dev->v4l2_dev,
  26647. + "%s: capture port not configured\n", __func__);
  26648. + return -EINVAL;
  26649. + }
  26650. +
  26651. + size = dev->capture.port->current_buffer.size;
  26652. + if (size == 0) {
  26653. + v4l2_err(&dev->v4l2_dev,
  26654. + "%s: capture port buffer size is zero\n", __func__);
  26655. + return -EINVAL;
  26656. + }
  26657. +
  26658. + if (*nbuffers < (dev->capture.port->current_buffer.num + 2))
  26659. + *nbuffers = (dev->capture.port->current_buffer.num + 2);
  26660. +
  26661. + *nplanes = 1;
  26662. +
  26663. + sizes[0] = size;
  26664. +
  26665. + /*
  26666. + * videobuf2-vmalloc allocator is context-less so no need to set
  26667. + * alloc_ctxs array.
  26668. + */
  26669. +
  26670. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "%s: dev:%p\n",
  26671. + __func__, dev);
  26672. +
  26673. + return 0;
  26674. +}
  26675. +
  26676. +static int buffer_prepare(struct vb2_buffer *vb)
  26677. +{
  26678. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
  26679. + unsigned long size;
  26680. +
  26681. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "%s: dev:%p\n",
  26682. + __func__, dev);
  26683. +
  26684. + BUG_ON(dev->capture.port == NULL);
  26685. + BUG_ON(dev->capture.fmt == NULL);
  26686. +
  26687. + size = dev->capture.stride * dev->capture.height;
  26688. + if (vb2_plane_size(vb, 0) < size) {
  26689. + v4l2_err(&dev->v4l2_dev,
  26690. + "%s data will not fit into plane (%lu < %lu)\n",
  26691. + __func__, vb2_plane_size(vb, 0), size);
  26692. + return -EINVAL;
  26693. + }
  26694. +
  26695. + return 0;
  26696. +}
  26697. +
  26698. +static inline bool is_capturing(struct bm2835_mmal_dev *dev)
  26699. +{
  26700. + return dev->capture.camera_port ==
  26701. + &dev->
  26702. + component[MMAL_COMPONENT_CAMERA]->output[MMAL_CAMERA_PORT_CAPTURE];
  26703. +}
  26704. +
  26705. +static void buffer_cb(struct vchiq_mmal_instance *instance,
  26706. + struct vchiq_mmal_port *port,
  26707. + int status,
  26708. + struct mmal_buffer *buf,
  26709. + unsigned long length, u32 mmal_flags, s64 dts, s64 pts)
  26710. +{
  26711. + struct bm2835_mmal_dev *dev = port->cb_ctx;
  26712. +
  26713. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  26714. + "%s: status:%d, buf:%p, length:%lu, flags %u, pts %lld\n",
  26715. + __func__, status, buf, length, mmal_flags, pts);
  26716. +
  26717. + if (status != 0) {
  26718. + /* error in transfer */
  26719. + if (buf != NULL) {
  26720. + /* there was a buffer with the error so return it */
  26721. + vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
  26722. + }
  26723. + return;
  26724. + } else if (length == 0) {
  26725. + /* stream ended */
  26726. + if (buf != NULL) {
  26727. + /* this should only ever happen if the port is
  26728. + * disabled and there are buffers still queued
  26729. + */
  26730. + vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
  26731. + pr_debug("Empty buffer");
  26732. + } else if (dev->capture.frame_count) {
  26733. + /* grab another frame */
  26734. + if (is_capturing(dev)) {
  26735. + pr_debug("Grab another frame");
  26736. + vchiq_mmal_port_parameter_set(
  26737. + instance,
  26738. + dev->capture.
  26739. + camera_port,
  26740. + MMAL_PARAMETER_CAPTURE,
  26741. + &dev->capture.
  26742. + frame_count,
  26743. + sizeof(dev->capture.frame_count));
  26744. + }
  26745. + } else {
  26746. + /* signal frame completion */
  26747. + complete(&dev->capture.frame_cmplt);
  26748. + }
  26749. + } else {
  26750. + if (dev->capture.frame_count) {
  26751. + if (dev->capture.vc_start_timestamp != -1 &&
  26752. + pts != 0) {
  26753. + s64 runtime_us = pts -
  26754. + dev->capture.vc_start_timestamp;
  26755. + u32 div = 0;
  26756. + u32 rem = 0;
  26757. +
  26758. + div =
  26759. + div_u64_rem(runtime_us, USEC_PER_SEC, &rem);
  26760. + buf->vb.v4l2_buf.timestamp.tv_sec =
  26761. + dev->capture.kernel_start_ts.tv_sec - 1 +
  26762. + div;
  26763. + buf->vb.v4l2_buf.timestamp.tv_usec =
  26764. + dev->capture.kernel_start_ts.tv_usec + rem;
  26765. +
  26766. + if (buf->vb.v4l2_buf.timestamp.tv_usec >=
  26767. + USEC_PER_SEC) {
  26768. + buf->vb.v4l2_buf.timestamp.tv_sec++;
  26769. + buf->vb.v4l2_buf.timestamp.tv_usec -=
  26770. + USEC_PER_SEC;
  26771. + }
  26772. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  26773. + "Convert start time %d.%06d and %llu "
  26774. + "with offset %llu to %d.%06d\n",
  26775. + (int)dev->capture.kernel_start_ts.
  26776. + tv_sec,
  26777. + (int)dev->capture.kernel_start_ts.
  26778. + tv_usec,
  26779. + dev->capture.vc_start_timestamp, pts,
  26780. + (int)buf->vb.v4l2_buf.timestamp.tv_sec,
  26781. + (int)buf->vb.v4l2_buf.timestamp.
  26782. + tv_usec);
  26783. + } else {
  26784. + v4l2_get_timestamp(&buf->vb.v4l2_buf.timestamp);
  26785. + }
  26786. +
  26787. + vb2_set_plane_payload(&buf->vb, 0, length);
  26788. + vb2_buffer_done(&buf->vb, VB2_BUF_STATE_DONE);
  26789. +
  26790. + if (mmal_flags & MMAL_BUFFER_HEADER_FLAG_EOS &&
  26791. + is_capturing(dev)) {
  26792. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  26793. + "Grab another frame as buffer has EOS");
  26794. + vchiq_mmal_port_parameter_set(
  26795. + instance,
  26796. + dev->capture.
  26797. + camera_port,
  26798. + MMAL_PARAMETER_CAPTURE,
  26799. + &dev->capture.
  26800. + frame_count,
  26801. + sizeof(dev->capture.frame_count));
  26802. + }
  26803. + } else {
  26804. + /* signal frame completion */
  26805. + complete(&dev->capture.frame_cmplt);
  26806. + }
  26807. + }
  26808. +}
  26809. +
  26810. +static int enable_camera(struct bm2835_mmal_dev *dev)
  26811. +{
  26812. + int ret;
  26813. + if (!dev->camera_use_count) {
  26814. + ret = vchiq_mmal_component_enable(
  26815. + dev->instance,
  26816. + dev->component[MMAL_COMPONENT_CAMERA]);
  26817. + if (ret < 0) {
  26818. + v4l2_err(&dev->v4l2_dev,
  26819. + "Failed enabling camera, ret %d\n", ret);
  26820. + return -EINVAL;
  26821. + }
  26822. + }
  26823. + dev->camera_use_count++;
  26824. + v4l2_dbg(1, bcm2835_v4l2_debug,
  26825. + &dev->v4l2_dev, "enabled camera (refcount %d)\n",
  26826. + dev->camera_use_count);
  26827. + return 0;
  26828. +}
  26829. +
  26830. +static int disable_camera(struct bm2835_mmal_dev *dev)
  26831. +{
  26832. + int ret;
  26833. + if (!dev->camera_use_count) {
  26834. + v4l2_err(&dev->v4l2_dev,
  26835. + "Disabled the camera when already disabled\n");
  26836. + return -EINVAL;
  26837. + }
  26838. + dev->camera_use_count--;
  26839. + if (!dev->camera_use_count) {
  26840. + unsigned int i = 0xFFFFFFFF;
  26841. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  26842. + "Disabling camera\n");
  26843. + ret =
  26844. + vchiq_mmal_component_disable(
  26845. + dev->instance,
  26846. + dev->component[MMAL_COMPONENT_CAMERA]);
  26847. + if (ret < 0) {
  26848. + v4l2_err(&dev->v4l2_dev,
  26849. + "Failed disabling camera, ret %d\n", ret);
  26850. + return -EINVAL;
  26851. + }
  26852. + vchiq_mmal_port_parameter_set(
  26853. + dev->instance,
  26854. + &dev->component[MMAL_COMPONENT_CAMERA]->control,
  26855. + MMAL_PARAMETER_CAMERA_NUM, &i,
  26856. + sizeof(i));
  26857. + }
  26858. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  26859. + "Camera refcount now %d\n", dev->camera_use_count);
  26860. + return 0;
  26861. +}
  26862. +
  26863. +static void buffer_queue(struct vb2_buffer *vb)
  26864. +{
  26865. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
  26866. + struct mmal_buffer *buf = container_of(vb, struct mmal_buffer, vb);
  26867. + int ret;
  26868. +
  26869. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  26870. + "%s: dev:%p buf:%p\n", __func__, dev, buf);
  26871. +
  26872. + buf->buffer = vb2_plane_vaddr(&buf->vb, 0);
  26873. + buf->buffer_size = vb2_plane_size(&buf->vb, 0);
  26874. +
  26875. + ret = vchiq_mmal_submit_buffer(dev->instance, dev->capture.port, buf);
  26876. + if (ret < 0)
  26877. + v4l2_err(&dev->v4l2_dev, "%s: error submitting buffer\n",
  26878. + __func__);
  26879. +}
  26880. +
  26881. +static int start_streaming(struct vb2_queue *vq, unsigned int count)
  26882. +{
  26883. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
  26884. + int ret;
  26885. + int parameter_size;
  26886. +
  26887. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "%s: dev:%p\n",
  26888. + __func__, dev);
  26889. +
  26890. + /* ensure a format has actually been set */
  26891. + if (dev->capture.port == NULL)
  26892. + return -EINVAL;
  26893. +
  26894. + if (enable_camera(dev) < 0) {
  26895. + v4l2_err(&dev->v4l2_dev, "Failed to enable camera\n");
  26896. + return -EINVAL;
  26897. + }
  26898. +
  26899. + /*init_completion(&dev->capture.frame_cmplt); */
  26900. +
  26901. + /* enable frame capture */
  26902. + dev->capture.frame_count = 1;
  26903. +
  26904. + /* if the preview is not already running, wait for a few frames for AGC
  26905. + * to settle down.
  26906. + */
  26907. + if (!dev->component[MMAL_COMPONENT_PREVIEW]->enabled)
  26908. + msleep(300);
  26909. +
  26910. + /* enable the connection from camera to encoder (if applicable) */
  26911. + if (dev->capture.camera_port != dev->capture.port
  26912. + && dev->capture.camera_port) {
  26913. + ret = vchiq_mmal_port_enable(dev->instance,
  26914. + dev->capture.camera_port, NULL);
  26915. + if (ret) {
  26916. + v4l2_err(&dev->v4l2_dev,
  26917. + "Failed to enable encode tunnel - error %d\n",
  26918. + ret);
  26919. + return -1;
  26920. + }
  26921. + }
  26922. +
  26923. + /* Get VC timestamp at this point in time */
  26924. + parameter_size = sizeof(dev->capture.vc_start_timestamp);
  26925. + if (vchiq_mmal_port_parameter_get(dev->instance,
  26926. + dev->capture.camera_port,
  26927. + MMAL_PARAMETER_SYSTEM_TIME,
  26928. + &dev->capture.vc_start_timestamp,
  26929. + &parameter_size)) {
  26930. + v4l2_err(&dev->v4l2_dev,
  26931. + "Failed to get VC start time - update your VC f/w\n");
  26932. +
  26933. + /* Flag to indicate just to rely on kernel timestamps */
  26934. + dev->capture.vc_start_timestamp = -1;
  26935. + } else
  26936. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  26937. + "Start time %lld size %d\n",
  26938. + dev->capture.vc_start_timestamp, parameter_size);
  26939. +
  26940. + v4l2_get_timestamp(&dev->capture.kernel_start_ts);
  26941. +
  26942. + /* enable the camera port */
  26943. + dev->capture.port->cb_ctx = dev;
  26944. + ret =
  26945. + vchiq_mmal_port_enable(dev->instance, dev->capture.port, buffer_cb);
  26946. + if (ret) {
  26947. + v4l2_err(&dev->v4l2_dev,
  26948. + "Failed to enable capture port - error %d. "
  26949. + "Disabling camera port again\n", ret);
  26950. +
  26951. + vchiq_mmal_port_disable(dev->instance,
  26952. + dev->capture.camera_port);
  26953. + if (disable_camera(dev) < 0) {
  26954. + v4l2_err(&dev->v4l2_dev, "Failed to disable camera\n");
  26955. + return -EINVAL;
  26956. + }
  26957. + return -1;
  26958. + }
  26959. +
  26960. + /* capture the first frame */
  26961. + vchiq_mmal_port_parameter_set(dev->instance,
  26962. + dev->capture.camera_port,
  26963. + MMAL_PARAMETER_CAPTURE,
  26964. + &dev->capture.frame_count,
  26965. + sizeof(dev->capture.frame_count));
  26966. + return 0;
  26967. +}
  26968. +
  26969. +/* abort streaming and wait for last buffer */
  26970. +static void stop_streaming(struct vb2_queue *vq)
  26971. +{
  26972. + int ret;
  26973. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
  26974. +
  26975. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "%s: dev:%p\n",
  26976. + __func__, dev);
  26977. +
  26978. + init_completion(&dev->capture.frame_cmplt);
  26979. + dev->capture.frame_count = 0;
  26980. +
  26981. + /* ensure a format has actually been set */
  26982. + if (dev->capture.port == NULL) {
  26983. + v4l2_err(&dev->v4l2_dev,
  26984. + "no capture port - stream not started?\n");
  26985. + return;
  26986. + }
  26987. +
  26988. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "stopping capturing\n");
  26989. +
  26990. + /* stop capturing frames */
  26991. + vchiq_mmal_port_parameter_set(dev->instance,
  26992. + dev->capture.camera_port,
  26993. + MMAL_PARAMETER_CAPTURE,
  26994. + &dev->capture.frame_count,
  26995. + sizeof(dev->capture.frame_count));
  26996. +
  26997. + /* wait for last frame to complete */
  26998. + ret = wait_for_completion_timeout(&dev->capture.frame_cmplt, HZ);
  26999. + if (ret <= 0)
  27000. + v4l2_err(&dev->v4l2_dev,
  27001. + "error %d waiting for frame completion\n", ret);
  27002. +
  27003. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  27004. + "disabling connection\n");
  27005. +
  27006. + /* disable the connection from camera to encoder */
  27007. + ret = vchiq_mmal_port_disable(dev->instance, dev->capture.camera_port);
  27008. + if (!ret && dev->capture.camera_port != dev->capture.port) {
  27009. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  27010. + "disabling port\n");
  27011. + ret = vchiq_mmal_port_disable(dev->instance, dev->capture.port);
  27012. + } else if (dev->capture.camera_port != dev->capture.port) {
  27013. + v4l2_err(&dev->v4l2_dev, "port_disable failed, error %d\n",
  27014. + ret);
  27015. + }
  27016. +
  27017. + if (disable_camera(dev) < 0)
  27018. + v4l2_err(&dev->v4l2_dev, "Failed to disable camera\n");
  27019. +}
  27020. +
  27021. +static void bm2835_mmal_lock(struct vb2_queue *vq)
  27022. +{
  27023. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
  27024. + mutex_lock(&dev->mutex);
  27025. +}
  27026. +
  27027. +static void bm2835_mmal_unlock(struct vb2_queue *vq)
  27028. +{
  27029. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
  27030. + mutex_unlock(&dev->mutex);
  27031. +}
  27032. +
  27033. +static struct vb2_ops bm2835_mmal_video_qops = {
  27034. + .queue_setup = queue_setup,
  27035. + .buf_prepare = buffer_prepare,
  27036. + .buf_queue = buffer_queue,
  27037. + .start_streaming = start_streaming,
  27038. + .stop_streaming = stop_streaming,
  27039. + .wait_prepare = bm2835_mmal_unlock,
  27040. + .wait_finish = bm2835_mmal_lock,
  27041. +};
  27042. +
  27043. +/* ------------------------------------------------------------------
  27044. + IOCTL operations
  27045. + ------------------------------------------------------------------*/
  27046. +
  27047. +/* overlay ioctl */
  27048. +static int vidioc_enum_fmt_vid_overlay(struct file *file, void *priv,
  27049. + struct v4l2_fmtdesc *f)
  27050. +{
  27051. + struct mmal_fmt *fmt;
  27052. +
  27053. + if (f->index >= ARRAY_SIZE(formats))
  27054. + return -EINVAL;
  27055. +
  27056. + fmt = &formats[f->index];
  27057. +
  27058. + strlcpy(f->description, fmt->name, sizeof(f->description));
  27059. + f->pixelformat = fmt->fourcc;
  27060. + f->flags = fmt->flags;
  27061. +
  27062. + return 0;
  27063. +}
  27064. +
  27065. +static int vidioc_g_fmt_vid_overlay(struct file *file, void *priv,
  27066. + struct v4l2_format *f)
  27067. +{
  27068. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  27069. +
  27070. + f->fmt.win = dev->overlay;
  27071. +
  27072. + return 0;
  27073. +}
  27074. +
  27075. +static int vidioc_try_fmt_vid_overlay(struct file *file, void *priv,
  27076. + struct v4l2_format *f)
  27077. +{
  27078. + /* Only support one format so get the current one. */
  27079. + vidioc_g_fmt_vid_overlay(file, priv, f);
  27080. +
  27081. + /* todo: allow the size and/or offset to be changed. */
  27082. + return 0;
  27083. +}
  27084. +
  27085. +static int vidioc_s_fmt_vid_overlay(struct file *file, void *priv,
  27086. + struct v4l2_format *f)
  27087. +{
  27088. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  27089. +
  27090. + vidioc_try_fmt_vid_overlay(file, priv, f);
  27091. +
  27092. + dev->overlay = f->fmt.win;
  27093. +
  27094. + /* todo: program the preview port parameters */
  27095. + return 0;
  27096. +}
  27097. +
  27098. +static int vidioc_overlay(struct file *file, void *f, unsigned int on)
  27099. +{
  27100. + int ret;
  27101. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  27102. + struct vchiq_mmal_port *src;
  27103. + struct vchiq_mmal_port *dst;
  27104. + struct mmal_parameter_displayregion prev_config = {
  27105. + .set = MMAL_DISPLAY_SET_LAYER | MMAL_DISPLAY_SET_ALPHA |
  27106. + MMAL_DISPLAY_SET_DEST_RECT | MMAL_DISPLAY_SET_FULLSCREEN,
  27107. + .layer = PREVIEW_LAYER,
  27108. + .alpha = 255,
  27109. + .fullscreen = 0,
  27110. + .dest_rect = {
  27111. + .x = dev->overlay.w.left,
  27112. + .y = dev->overlay.w.top,
  27113. + .width = dev->overlay.w.width,
  27114. + .height = dev->overlay.w.height,
  27115. + },
  27116. + };
  27117. +
  27118. + if ((on && dev->component[MMAL_COMPONENT_PREVIEW]->enabled) ||
  27119. + (!on && !dev->component[MMAL_COMPONENT_PREVIEW]->enabled))
  27120. + return 0; /* already in requested state */
  27121. +
  27122. + src =
  27123. + &dev->component[MMAL_COMPONENT_CAMERA]->
  27124. + output[MMAL_CAMERA_PORT_PREVIEW];
  27125. +
  27126. + if (!on) {
  27127. + /* disconnect preview ports and disable component */
  27128. + ret = vchiq_mmal_port_disable(dev->instance, src);
  27129. + if (!ret)
  27130. + ret =
  27131. + vchiq_mmal_port_connect_tunnel(dev->instance, src,
  27132. + NULL);
  27133. + if (ret >= 0)
  27134. + ret = vchiq_mmal_component_disable(
  27135. + dev->instance,
  27136. + dev->component[MMAL_COMPONENT_PREVIEW]);
  27137. +
  27138. + disable_camera(dev);
  27139. + return ret;
  27140. + }
  27141. +
  27142. + /* set preview port format and connect it to output */
  27143. + dst = &dev->component[MMAL_COMPONENT_PREVIEW]->input[0];
  27144. +
  27145. + ret = vchiq_mmal_port_set_format(dev->instance, src);
  27146. + if (ret < 0)
  27147. + goto error;
  27148. +
  27149. + ret = vchiq_mmal_port_parameter_set(dev->instance, dst,
  27150. + MMAL_PARAMETER_DISPLAYREGION,
  27151. + &prev_config, sizeof(prev_config));
  27152. + if (ret < 0)
  27153. + goto error;
  27154. +
  27155. + if (enable_camera(dev) < 0)
  27156. + goto error;
  27157. +
  27158. + ret = vchiq_mmal_component_enable(
  27159. + dev->instance,
  27160. + dev->component[MMAL_COMPONENT_PREVIEW]);
  27161. + if (ret < 0)
  27162. + goto error;
  27163. +
  27164. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "connecting %p to %p\n",
  27165. + src, dst);
  27166. + ret = vchiq_mmal_port_connect_tunnel(dev->instance, src, dst);
  27167. + if (!ret)
  27168. + ret = vchiq_mmal_port_enable(dev->instance, src, NULL);
  27169. +error:
  27170. + return ret;
  27171. +}
  27172. +
  27173. +static int vidioc_g_fbuf(struct file *file, void *fh,
  27174. + struct v4l2_framebuffer *a)
  27175. +{
  27176. + /* The video overlay must stay within the framebuffer and can't be
  27177. + positioned independently. */
  27178. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  27179. + struct vchiq_mmal_port *preview_port =
  27180. + &dev->component[MMAL_COMPONENT_CAMERA]->
  27181. + output[MMAL_CAMERA_PORT_PREVIEW];
  27182. + a->flags = V4L2_FBUF_FLAG_OVERLAY;
  27183. + a->fmt.width = preview_port->es.video.width;
  27184. + a->fmt.height = preview_port->es.video.height;
  27185. + a->fmt.pixelformat = V4L2_PIX_FMT_YUV420;
  27186. + a->fmt.bytesperline = (preview_port->es.video.width * 3)>>1;
  27187. + a->fmt.sizeimage = (preview_port->es.video.width *
  27188. + preview_port->es.video.height * 3)>>1;
  27189. + a->fmt.colorspace = V4L2_COLORSPACE_SMPTE170M;
  27190. +
  27191. + return 0;
  27192. +}
  27193. +
  27194. +/* input ioctls */
  27195. +static int vidioc_enum_input(struct file *file, void *priv,
  27196. + struct v4l2_input *inp)
  27197. +{
  27198. + /* only a single camera input */
  27199. + if (inp->index != 0)
  27200. + return -EINVAL;
  27201. +
  27202. + inp->type = V4L2_INPUT_TYPE_CAMERA;
  27203. + sprintf(inp->name, "Camera %u", inp->index);
  27204. + return 0;
  27205. +}
  27206. +
  27207. +static int vidioc_g_input(struct file *file, void *priv, unsigned int *i)
  27208. +{
  27209. + *i = 0;
  27210. + return 0;
  27211. +}
  27212. +
  27213. +static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
  27214. +{
  27215. + if (i != 0)
  27216. + return -EINVAL;
  27217. +
  27218. + return 0;
  27219. +}
  27220. +
  27221. +/* capture ioctls */
  27222. +static int vidioc_querycap(struct file *file, void *priv,
  27223. + struct v4l2_capability *cap)
  27224. +{
  27225. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  27226. + u32 major;
  27227. + u32 minor;
  27228. +
  27229. + vchiq_mmal_version(dev->instance, &major, &minor);
  27230. +
  27231. + strcpy(cap->driver, "bm2835 mmal");
  27232. + snprintf(cap->card, sizeof(cap->card), "mmal service %d.%d",
  27233. + major, minor);
  27234. +
  27235. + snprintf(cap->bus_info, sizeof(cap->bus_info),
  27236. + "platform:%s", dev->v4l2_dev.name);
  27237. + cap->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_VIDEO_OVERLAY |
  27238. + V4L2_CAP_STREAMING | V4L2_CAP_READWRITE;
  27239. + cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
  27240. +
  27241. + return 0;
  27242. +}
  27243. +
  27244. +static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
  27245. + struct v4l2_fmtdesc *f)
  27246. +{
  27247. + struct mmal_fmt *fmt;
  27248. +
  27249. + if (f->index >= ARRAY_SIZE(formats))
  27250. + return -EINVAL;
  27251. +
  27252. + fmt = &formats[f->index];
  27253. +
  27254. + strlcpy(f->description, fmt->name, sizeof(f->description));
  27255. + f->pixelformat = fmt->fourcc;
  27256. + f->flags = fmt->flags;
  27257. +
  27258. + return 0;
  27259. +}
  27260. +
  27261. +static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
  27262. + struct v4l2_format *f)
  27263. +{
  27264. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  27265. +
  27266. + f->fmt.pix.width = dev->capture.width;
  27267. + f->fmt.pix.height = dev->capture.height;
  27268. + f->fmt.pix.field = V4L2_FIELD_NONE;
  27269. + f->fmt.pix.pixelformat = dev->capture.fmt->fourcc;
  27270. + f->fmt.pix.bytesperline = dev->capture.stride;
  27271. + f->fmt.pix.sizeimage = dev->capture.buffersize;
  27272. +
  27273. + if (dev->capture.fmt->fourcc == V4L2_PIX_FMT_RGB24)
  27274. + f->fmt.pix.colorspace = V4L2_COLORSPACE_SRGB;
  27275. + else if (dev->capture.fmt->fourcc == V4L2_PIX_FMT_JPEG)
  27276. + f->fmt.pix.colorspace = V4L2_COLORSPACE_JPEG;
  27277. + else
  27278. + f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
  27279. + f->fmt.pix.priv = 0;
  27280. +
  27281. + v4l2_dump_pix_format(1, bcm2835_v4l2_debug, &dev->v4l2_dev, &f->fmt.pix,
  27282. + __func__);
  27283. + return 0;
  27284. +}
  27285. +
  27286. +static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
  27287. + struct v4l2_format *f)
  27288. +{
  27289. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  27290. + struct mmal_fmt *mfmt;
  27291. +
  27292. + mfmt = get_format(f);
  27293. + if (!mfmt) {
  27294. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  27295. + "Fourcc format (0x%08x) unknown.\n",
  27296. + f->fmt.pix.pixelformat);
  27297. + f->fmt.pix.pixelformat = formats[0].fourcc;
  27298. + mfmt = get_format(f);
  27299. + }
  27300. +
  27301. + f->fmt.pix.field = V4L2_FIELD_NONE;
  27302. +
  27303. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  27304. + "Clipping/aligning %dx%d format %08X\n",
  27305. + f->fmt.pix.width, f->fmt.pix.height, f->fmt.pix.pixelformat);
  27306. +
  27307. + v4l_bound_align_image(&f->fmt.pix.width, MIN_WIDTH, MAX_WIDTH, 1,
  27308. + &f->fmt.pix.height, MIN_HEIGHT, MAX_HEIGHT, 1, 0);
  27309. + f->fmt.pix.bytesperline = (f->fmt.pix.width * mfmt->depth)>>3;
  27310. +
  27311. + /* Image buffer has to be padded to allow for alignment, even though
  27312. + * we then remove that padding before delivering the buffer.
  27313. + */
  27314. + f->fmt.pix.sizeimage = ((f->fmt.pix.height+15)&~15) *
  27315. + (((f->fmt.pix.width+31)&~31) * mfmt->depth) >> 3;
  27316. +
  27317. + if ((mfmt->flags & V4L2_FMT_FLAG_COMPRESSED) &&
  27318. + f->fmt.pix.sizeimage < MIN_BUFFER_SIZE)
  27319. + f->fmt.pix.sizeimage = MIN_BUFFER_SIZE;
  27320. +
  27321. + if (f->fmt.pix.pixelformat == V4L2_PIX_FMT_RGB24)
  27322. + f->fmt.pix.colorspace = V4L2_COLORSPACE_SRGB;
  27323. + else if (f->fmt.pix.pixelformat == V4L2_PIX_FMT_JPEG)
  27324. + f->fmt.pix.colorspace = V4L2_COLORSPACE_JPEG;
  27325. + else
  27326. + f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
  27327. + f->fmt.pix.priv = 0;
  27328. +
  27329. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  27330. + "Now %dx%d format %08X\n",
  27331. + f->fmt.pix.width, f->fmt.pix.height, f->fmt.pix.pixelformat);
  27332. +
  27333. + v4l2_dump_pix_format(1, bcm2835_v4l2_debug, &dev->v4l2_dev, &f->fmt.pix,
  27334. + __func__);
  27335. + return 0;
  27336. +}
  27337. +
  27338. +static int mmal_setup_components(struct bm2835_mmal_dev *dev,
  27339. + struct v4l2_format *f)
  27340. +{
  27341. + int ret;
  27342. + struct vchiq_mmal_port *port = NULL, *camera_port = NULL;
  27343. + struct vchiq_mmal_component *encode_component = NULL;
  27344. + struct mmal_fmt *mfmt = get_format(f);
  27345. +
  27346. + BUG_ON(!mfmt);
  27347. +
  27348. + if (dev->capture.encode_component) {
  27349. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  27350. + "vid_cap - disconnect previous tunnel\n");
  27351. +
  27352. + /* Disconnect any previous connection */
  27353. + vchiq_mmal_port_connect_tunnel(dev->instance,
  27354. + dev->capture.camera_port, NULL);
  27355. + dev->capture.camera_port = NULL;
  27356. + ret = vchiq_mmal_component_disable(dev->instance,
  27357. + dev->capture.
  27358. + encode_component);
  27359. + if (ret)
  27360. + v4l2_err(&dev->v4l2_dev,
  27361. + "Failed to disable encode component %d\n",
  27362. + ret);
  27363. +
  27364. + dev->capture.encode_component = NULL;
  27365. + }
  27366. + /* format dependant port setup */
  27367. + switch (mfmt->mmal_component) {
  27368. + case MMAL_COMPONENT_CAMERA:
  27369. + /* Make a further decision on port based on resolution */
  27370. + if (f->fmt.pix.width <= max_video_width
  27371. + && f->fmt.pix.height <= max_video_height)
  27372. + camera_port = port =
  27373. + &dev->component[MMAL_COMPONENT_CAMERA]->
  27374. + output[MMAL_CAMERA_PORT_VIDEO];
  27375. + else
  27376. + camera_port = port =
  27377. + &dev->component[MMAL_COMPONENT_CAMERA]->
  27378. + output[MMAL_CAMERA_PORT_CAPTURE];
  27379. + break;
  27380. + case MMAL_COMPONENT_IMAGE_ENCODE:
  27381. + encode_component = dev->component[MMAL_COMPONENT_IMAGE_ENCODE];
  27382. + port = &dev->component[MMAL_COMPONENT_IMAGE_ENCODE]->output[0];
  27383. + camera_port =
  27384. + &dev->component[MMAL_COMPONENT_CAMERA]->
  27385. + output[MMAL_CAMERA_PORT_CAPTURE];
  27386. + break;
  27387. + case MMAL_COMPONENT_VIDEO_ENCODE:
  27388. + encode_component = dev->component[MMAL_COMPONENT_VIDEO_ENCODE];
  27389. + port = &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0];
  27390. + camera_port =
  27391. + &dev->component[MMAL_COMPONENT_CAMERA]->
  27392. + output[MMAL_CAMERA_PORT_VIDEO];
  27393. + break;
  27394. + default:
  27395. + break;
  27396. + }
  27397. +
  27398. + if (!port)
  27399. + return -EINVAL;
  27400. +
  27401. + if (encode_component)
  27402. + camera_port->format.encoding = MMAL_ENCODING_OPAQUE;
  27403. + else
  27404. + camera_port->format.encoding = mfmt->mmal;
  27405. +
  27406. + camera_port->format.encoding_variant = 0;
  27407. + camera_port->es.video.width = f->fmt.pix.width;
  27408. + camera_port->es.video.height = f->fmt.pix.height;
  27409. + camera_port->es.video.crop.x = 0;
  27410. + camera_port->es.video.crop.y = 0;
  27411. + camera_port->es.video.crop.width = f->fmt.pix.width;
  27412. + camera_port->es.video.crop.height = f->fmt.pix.height;
  27413. + camera_port->es.video.frame_rate.num = 0;
  27414. + camera_port->es.video.frame_rate.den = 1;
  27415. + camera_port->es.video.color_space = MMAL_COLOR_SPACE_JPEG_JFIF;
  27416. +
  27417. + ret = vchiq_mmal_port_set_format(dev->instance, camera_port);
  27418. +
  27419. + if (!ret
  27420. + && camera_port ==
  27421. + &dev->component[MMAL_COMPONENT_CAMERA]->
  27422. + output[MMAL_CAMERA_PORT_VIDEO]) {
  27423. + bool overlay_enabled =
  27424. + !!dev->component[MMAL_COMPONENT_PREVIEW]->enabled;
  27425. + struct vchiq_mmal_port *preview_port =
  27426. + &dev->component[MMAL_COMPONENT_CAMERA]->
  27427. + output[MMAL_CAMERA_PORT_PREVIEW];
  27428. + /* Preview and encode ports need to match on resolution */
  27429. + if (overlay_enabled) {
  27430. + /* Need to disable the overlay before we can update
  27431. + * the resolution
  27432. + */
  27433. + ret =
  27434. + vchiq_mmal_port_disable(dev->instance,
  27435. + preview_port);
  27436. + if (!ret)
  27437. + ret =
  27438. + vchiq_mmal_port_connect_tunnel(
  27439. + dev->instance,
  27440. + preview_port,
  27441. + NULL);
  27442. + }
  27443. + preview_port->es.video.width = f->fmt.pix.width;
  27444. + preview_port->es.video.height = f->fmt.pix.height;
  27445. + preview_port->es.video.crop.x = 0;
  27446. + preview_port->es.video.crop.y = 0;
  27447. + preview_port->es.video.crop.width = f->fmt.pix.width;
  27448. + preview_port->es.video.crop.height = f->fmt.pix.height;
  27449. + preview_port->es.video.frame_rate.num =
  27450. + dev->capture.timeperframe.denominator;
  27451. + preview_port->es.video.frame_rate.den =
  27452. + dev->capture.timeperframe.numerator;
  27453. + ret = vchiq_mmal_port_set_format(dev->instance, preview_port);
  27454. + if (overlay_enabled) {
  27455. + ret = vchiq_mmal_port_connect_tunnel(
  27456. + dev->instance,
  27457. + preview_port,
  27458. + &dev->component[MMAL_COMPONENT_PREVIEW]->input[0]);
  27459. + if (!ret)
  27460. + ret = vchiq_mmal_port_enable(dev->instance,
  27461. + preview_port,
  27462. + NULL);
  27463. + }
  27464. + }
  27465. +
  27466. + if (ret) {
  27467. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  27468. + "%s failed to set format %dx%d %08X\n", __func__,
  27469. + f->fmt.pix.width, f->fmt.pix.height,
  27470. + f->fmt.pix.pixelformat);
  27471. + /* ensure capture is not going to be tried */
  27472. + dev->capture.port = NULL;
  27473. + } else {
  27474. + if (encode_component) {
  27475. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  27476. + "vid_cap - set up encode comp\n");
  27477. +
  27478. + /* configure buffering */
  27479. + camera_port->current_buffer.size =
  27480. + camera_port->recommended_buffer.size;
  27481. + camera_port->current_buffer.num =
  27482. + camera_port->recommended_buffer.num;
  27483. +
  27484. + ret =
  27485. + vchiq_mmal_port_connect_tunnel(
  27486. + dev->instance,
  27487. + camera_port,
  27488. + &encode_component->input[0]);
  27489. + if (ret) {
  27490. + v4l2_dbg(1, bcm2835_v4l2_debug,
  27491. + &dev->v4l2_dev,
  27492. + "%s failed to create connection\n",
  27493. + __func__);
  27494. + /* ensure capture is not going to be tried */
  27495. + dev->capture.port = NULL;
  27496. + } else {
  27497. + port->es.video.width = f->fmt.pix.width;
  27498. + port->es.video.height = f->fmt.pix.height;
  27499. + port->es.video.crop.x = 0;
  27500. + port->es.video.crop.y = 0;
  27501. + port->es.video.crop.width = f->fmt.pix.width;
  27502. + port->es.video.crop.height = f->fmt.pix.height;
  27503. + port->es.video.frame_rate.num =
  27504. + dev->capture.timeperframe.denominator;
  27505. + port->es.video.frame_rate.den =
  27506. + dev->capture.timeperframe.numerator;
  27507. +
  27508. + port->format.encoding = mfmt->mmal;
  27509. + port->format.encoding_variant = 0;
  27510. + /* Set any encoding specific parameters */
  27511. + switch (mfmt->mmal_component) {
  27512. + case MMAL_COMPONENT_VIDEO_ENCODE:
  27513. + port->format.bitrate =
  27514. + dev->capture.encode_bitrate;
  27515. + break;
  27516. + case MMAL_COMPONENT_IMAGE_ENCODE:
  27517. + /* Could set EXIF parameters here */
  27518. + break;
  27519. + default:
  27520. + break;
  27521. + }
  27522. + ret = vchiq_mmal_port_set_format(dev->instance,
  27523. + port);
  27524. + if (ret)
  27525. + v4l2_dbg(1, bcm2835_v4l2_debug,
  27526. + &dev->v4l2_dev,
  27527. + "%s failed to set format %dx%d fmt %08X\n",
  27528. + __func__,
  27529. + f->fmt.pix.width,
  27530. + f->fmt.pix.height,
  27531. + f->fmt.pix.pixelformat
  27532. + );
  27533. + }
  27534. +
  27535. + if (!ret) {
  27536. + ret = vchiq_mmal_component_enable(
  27537. + dev->instance,
  27538. + encode_component);
  27539. + if (ret) {
  27540. + v4l2_dbg(1, bcm2835_v4l2_debug,
  27541. + &dev->v4l2_dev,
  27542. + "%s Failed to enable encode components\n",
  27543. + __func__);
  27544. + }
  27545. + }
  27546. + if (!ret) {
  27547. + /* configure buffering */
  27548. + port->current_buffer.num = 1;
  27549. + port->current_buffer.size =
  27550. + f->fmt.pix.sizeimage;
  27551. + if (port->format.encoding ==
  27552. + MMAL_ENCODING_JPEG) {
  27553. + v4l2_dbg(1, bcm2835_v4l2_debug,
  27554. + &dev->v4l2_dev,
  27555. + "JPG - buf size now %d was %d\n",
  27556. + f->fmt.pix.sizeimage,
  27557. + port->current_buffer.size);
  27558. + port->current_buffer.size =
  27559. + (f->fmt.pix.sizeimage <
  27560. + (100 << 10))
  27561. + ? (100 << 10) : f->fmt.pix.
  27562. + sizeimage;
  27563. + }
  27564. + v4l2_dbg(1, bcm2835_v4l2_debug,
  27565. + &dev->v4l2_dev,
  27566. + "vid_cap - cur_buf.size set to %d\n",
  27567. + f->fmt.pix.sizeimage);
  27568. + port->current_buffer.alignment = 0;
  27569. + }
  27570. + } else {
  27571. + /* configure buffering */
  27572. + camera_port->current_buffer.num = 1;
  27573. + camera_port->current_buffer.size = f->fmt.pix.sizeimage;
  27574. + camera_port->current_buffer.alignment = 0;
  27575. + }
  27576. +
  27577. + if (!ret) {
  27578. + dev->capture.fmt = mfmt;
  27579. + dev->capture.stride = f->fmt.pix.bytesperline;
  27580. + dev->capture.width = camera_port->es.video.crop.width;
  27581. + dev->capture.height = camera_port->es.video.crop.height;
  27582. + dev->capture.buffersize = port->current_buffer.size;
  27583. +
  27584. + /* select port for capture */
  27585. + dev->capture.port = port;
  27586. + dev->capture.camera_port = camera_port;
  27587. + dev->capture.encode_component = encode_component;
  27588. + v4l2_dbg(1, bcm2835_v4l2_debug,
  27589. + &dev->v4l2_dev,
  27590. + "Set dev->capture.fmt %08X, %dx%d, stride %d, size %d",
  27591. + port->format.encoding,
  27592. + dev->capture.width, dev->capture.height,
  27593. + dev->capture.stride, dev->capture.buffersize);
  27594. + }
  27595. + }
  27596. +
  27597. + /* todo: Need to convert the vchiq/mmal error into a v4l2 error. */
  27598. + return ret;
  27599. +}
  27600. +
  27601. +static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
  27602. + struct v4l2_format *f)
  27603. +{
  27604. + int ret;
  27605. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  27606. + struct mmal_fmt *mfmt;
  27607. +
  27608. + /* try the format to set valid parameters */
  27609. + ret = vidioc_try_fmt_vid_cap(file, priv, f);
  27610. + if (ret) {
  27611. + v4l2_err(&dev->v4l2_dev,
  27612. + "vid_cap - vidioc_try_fmt_vid_cap failed\n");
  27613. + return ret;
  27614. + }
  27615. +
  27616. + /* if a capture is running refuse to set format */
  27617. + if (vb2_is_busy(&dev->capture.vb_vidq)) {
  27618. + v4l2_info(&dev->v4l2_dev, "%s device busy\n", __func__);
  27619. + return -EBUSY;
  27620. + }
  27621. +
  27622. + /* If the format is unsupported v4l2 says we should switch to
  27623. + * a supported one and not return an error. */
  27624. + mfmt = get_format(f);
  27625. + if (!mfmt) {
  27626. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  27627. + "Fourcc format (0x%08x) unknown.\n",
  27628. + f->fmt.pix.pixelformat);
  27629. + f->fmt.pix.pixelformat = formats[0].fourcc;
  27630. + mfmt = get_format(f);
  27631. + }
  27632. +
  27633. + ret = mmal_setup_components(dev, f);
  27634. + if (ret != 0) {
  27635. + v4l2_err(&dev->v4l2_dev,
  27636. + "%s: failed to setup mmal components: %d\n",
  27637. + __func__, ret);
  27638. + ret = -EINVAL;
  27639. + }
  27640. +
  27641. + return ret;
  27642. +}
  27643. +
  27644. +int vidioc_enum_framesizes(struct file *file, void *fh,
  27645. + struct v4l2_frmsizeenum *fsize)
  27646. +{
  27647. + static const struct v4l2_frmsize_stepwise sizes = {
  27648. + MIN_WIDTH, MAX_WIDTH, 2,
  27649. + MIN_HEIGHT, MAX_HEIGHT, 2
  27650. + };
  27651. + int i;
  27652. +
  27653. + if (fsize->index)
  27654. + return -EINVAL;
  27655. + for (i = 0; i < ARRAY_SIZE(formats); i++)
  27656. + if (formats[i].fourcc == fsize->pixel_format)
  27657. + break;
  27658. + if (i == ARRAY_SIZE(formats))
  27659. + return -EINVAL;
  27660. + fsize->type = V4L2_FRMSIZE_TYPE_STEPWISE;
  27661. + fsize->stepwise = sizes;
  27662. + return 0;
  27663. +}
  27664. +
  27665. +/* timeperframe is arbitrary and continous */
  27666. +static int vidioc_enum_frameintervals(struct file *file, void *priv,
  27667. + struct v4l2_frmivalenum *fival)
  27668. +{
  27669. + int i;
  27670. +
  27671. + if (fival->index)
  27672. + return -EINVAL;
  27673. +
  27674. + for (i = 0; i < ARRAY_SIZE(formats); i++)
  27675. + if (formats[i].fourcc == fival->pixel_format)
  27676. + break;
  27677. + if (i == ARRAY_SIZE(formats))
  27678. + return -EINVAL;
  27679. +
  27680. + /* regarding width & height - we support any within range */
  27681. + if (fival->width < MIN_WIDTH || fival->width > MAX_WIDTH ||
  27682. + fival->height < MIN_HEIGHT || fival->height > MAX_HEIGHT)
  27683. + return -EINVAL;
  27684. +
  27685. + fival->type = V4L2_FRMIVAL_TYPE_CONTINUOUS;
  27686. +
  27687. + /* fill in stepwise (step=1.0 is requred by V4L2 spec) */
  27688. + fival->stepwise.min = tpf_min;
  27689. + fival->stepwise.max = tpf_max;
  27690. + fival->stepwise.step = (struct v4l2_fract) {1, 1};
  27691. +
  27692. + return 0;
  27693. +}
  27694. +
  27695. +static int vidioc_g_parm(struct file *file, void *priv,
  27696. + struct v4l2_streamparm *parm)
  27697. +{
  27698. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  27699. +
  27700. + if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  27701. + return -EINVAL;
  27702. +
  27703. + parm->parm.capture.capability = V4L2_CAP_TIMEPERFRAME;
  27704. + parm->parm.capture.timeperframe = dev->capture.timeperframe;
  27705. + parm->parm.capture.readbuffers = 1;
  27706. + return 0;
  27707. +}
  27708. +
  27709. +#define FRACT_CMP(a, OP, b) \
  27710. + ((u64)(a).numerator * (b).denominator OP \
  27711. + (u64)(b).numerator * (a).denominator)
  27712. +
  27713. +static int vidioc_s_parm(struct file *file, void *priv,
  27714. + struct v4l2_streamparm *parm)
  27715. +{
  27716. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  27717. + struct v4l2_fract tpf;
  27718. + struct mmal_parameter_rational fps_param;
  27719. +
  27720. + if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  27721. + return -EINVAL;
  27722. +
  27723. + tpf = parm->parm.capture.timeperframe;
  27724. +
  27725. + /* tpf: {*, 0} resets timing; clip to [min, max]*/
  27726. + tpf = tpf.denominator ? tpf : tpf_default;
  27727. + tpf = FRACT_CMP(tpf, <, tpf_min) ? tpf_min : tpf;
  27728. + tpf = FRACT_CMP(tpf, >, tpf_max) ? tpf_max : tpf;
  27729. +
  27730. + dev->capture.timeperframe = tpf;
  27731. + parm->parm.capture.timeperframe = tpf;
  27732. + parm->parm.capture.readbuffers = 1;
  27733. +
  27734. + fps_param.num = 0; /* Select variable fps, and then use
  27735. + * FPS_RANGE to select the actual limits.
  27736. + */
  27737. + fps_param.den = 1;
  27738. + set_framerate_params(dev);
  27739. +
  27740. + return 0;
  27741. +}
  27742. +
  27743. +static const struct v4l2_ioctl_ops camera0_ioctl_ops = {
  27744. + /* overlay */
  27745. + .vidioc_enum_fmt_vid_overlay = vidioc_enum_fmt_vid_overlay,
  27746. + .vidioc_g_fmt_vid_overlay = vidioc_g_fmt_vid_overlay,
  27747. + .vidioc_try_fmt_vid_overlay = vidioc_try_fmt_vid_overlay,
  27748. + .vidioc_s_fmt_vid_overlay = vidioc_s_fmt_vid_overlay,
  27749. + .vidioc_overlay = vidioc_overlay,
  27750. + .vidioc_g_fbuf = vidioc_g_fbuf,
  27751. +
  27752. + /* inputs */
  27753. + .vidioc_enum_input = vidioc_enum_input,
  27754. + .vidioc_g_input = vidioc_g_input,
  27755. + .vidioc_s_input = vidioc_s_input,
  27756. +
  27757. + /* capture */
  27758. + .vidioc_querycap = vidioc_querycap,
  27759. + .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
  27760. + .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
  27761. + .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
  27762. + .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
  27763. +
  27764. + /* buffer management */
  27765. + .vidioc_reqbufs = vb2_ioctl_reqbufs,
  27766. + .vidioc_create_bufs = vb2_ioctl_create_bufs,
  27767. + .vidioc_prepare_buf = vb2_ioctl_prepare_buf,
  27768. + .vidioc_querybuf = vb2_ioctl_querybuf,
  27769. + .vidioc_qbuf = vb2_ioctl_qbuf,
  27770. + .vidioc_dqbuf = vb2_ioctl_dqbuf,
  27771. + .vidioc_enum_framesizes = vidioc_enum_framesizes,
  27772. + .vidioc_enum_frameintervals = vidioc_enum_frameintervals,
  27773. + .vidioc_g_parm = vidioc_g_parm,
  27774. + .vidioc_s_parm = vidioc_s_parm,
  27775. + .vidioc_streamon = vb2_ioctl_streamon,
  27776. + .vidioc_streamoff = vb2_ioctl_streamoff,
  27777. +
  27778. + .vidioc_log_status = v4l2_ctrl_log_status,
  27779. + .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
  27780. + .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
  27781. +};
  27782. +
  27783. +static const struct v4l2_ioctl_ops camera0_ioctl_ops_gstreamer = {
  27784. + /* overlay */
  27785. + .vidioc_enum_fmt_vid_overlay = vidioc_enum_fmt_vid_overlay,
  27786. + .vidioc_g_fmt_vid_overlay = vidioc_g_fmt_vid_overlay,
  27787. + .vidioc_try_fmt_vid_overlay = vidioc_try_fmt_vid_overlay,
  27788. + .vidioc_s_fmt_vid_overlay = vidioc_s_fmt_vid_overlay,
  27789. + .vidioc_overlay = vidioc_overlay,
  27790. + .vidioc_g_fbuf = vidioc_g_fbuf,
  27791. +
  27792. + /* inputs */
  27793. + .vidioc_enum_input = vidioc_enum_input,
  27794. + .vidioc_g_input = vidioc_g_input,
  27795. + .vidioc_s_input = vidioc_s_input,
  27796. +
  27797. + /* capture */
  27798. + .vidioc_querycap = vidioc_querycap,
  27799. + .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
  27800. + .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
  27801. + .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
  27802. + .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
  27803. +
  27804. + /* buffer management */
  27805. + .vidioc_reqbufs = vb2_ioctl_reqbufs,
  27806. + .vidioc_create_bufs = vb2_ioctl_create_bufs,
  27807. + .vidioc_prepare_buf = vb2_ioctl_prepare_buf,
  27808. + .vidioc_querybuf = vb2_ioctl_querybuf,
  27809. + .vidioc_qbuf = vb2_ioctl_qbuf,
  27810. + .vidioc_dqbuf = vb2_ioctl_dqbuf,
  27811. + /* Remove this function ptr to fix gstreamer bug
  27812. + .vidioc_enum_framesizes = vidioc_enum_framesizes, */
  27813. + .vidioc_enum_frameintervals = vidioc_enum_frameintervals,
  27814. + .vidioc_g_parm = vidioc_g_parm,
  27815. + .vidioc_s_parm = vidioc_s_parm,
  27816. + .vidioc_streamon = vb2_ioctl_streamon,
  27817. + .vidioc_streamoff = vb2_ioctl_streamoff,
  27818. +
  27819. + .vidioc_log_status = v4l2_ctrl_log_status,
  27820. + .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
  27821. + .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
  27822. +};
  27823. +
  27824. +/* ------------------------------------------------------------------
  27825. + Driver init/finalise
  27826. + ------------------------------------------------------------------*/
  27827. +
  27828. +static const struct v4l2_file_operations camera0_fops = {
  27829. + .owner = THIS_MODULE,
  27830. + .open = v4l2_fh_open,
  27831. + .release = vb2_fop_release,
  27832. + .read = vb2_fop_read,
  27833. + .poll = vb2_fop_poll,
  27834. + .unlocked_ioctl = video_ioctl2, /* V4L2 ioctl handler */
  27835. + .mmap = vb2_fop_mmap,
  27836. +};
  27837. +
  27838. +static struct video_device vdev_template = {
  27839. + .name = "camera0",
  27840. + .fops = &camera0_fops,
  27841. + .ioctl_ops = &camera0_ioctl_ops,
  27842. + .release = video_device_release_empty,
  27843. +};
  27844. +
  27845. +static int set_camera_parameters(struct vchiq_mmal_instance *instance,
  27846. + struct vchiq_mmal_component *camera)
  27847. +{
  27848. + int ret;
  27849. + struct mmal_parameter_camera_config cam_config = {
  27850. + .max_stills_w = MAX_WIDTH,
  27851. + .max_stills_h = MAX_HEIGHT,
  27852. + .stills_yuv422 = 1,
  27853. + .one_shot_stills = 1,
  27854. + .max_preview_video_w = (max_video_width > 1920) ?
  27855. + max_video_width : 1920,
  27856. + .max_preview_video_h = (max_video_height > 1088) ?
  27857. + max_video_height : 1088,
  27858. + .num_preview_video_frames = 3,
  27859. + .stills_capture_circular_buffer_height = 0,
  27860. + .fast_preview_resume = 0,
  27861. + .use_stc_timestamp = MMAL_PARAM_TIMESTAMP_MODE_RAW_STC
  27862. + };
  27863. +
  27864. + ret = vchiq_mmal_port_parameter_set(instance, &camera->control,
  27865. + MMAL_PARAMETER_CAMERA_CONFIG,
  27866. + &cam_config, sizeof(cam_config));
  27867. + return ret;
  27868. +}
  27869. +
  27870. +/* MMAL instance and component init */
  27871. +static int __init mmal_init(struct bm2835_mmal_dev *dev)
  27872. +{
  27873. + int ret;
  27874. + struct mmal_es_format *format;
  27875. + u32 bool_true = 1;
  27876. +
  27877. + ret = vchiq_mmal_init(&dev->instance);
  27878. + if (ret < 0)
  27879. + return ret;
  27880. +
  27881. + /* get the camera component ready */
  27882. + ret = vchiq_mmal_component_init(dev->instance, "ril.camera",
  27883. + &dev->component[MMAL_COMPONENT_CAMERA]);
  27884. + if (ret < 0)
  27885. + goto unreg_mmal;
  27886. +
  27887. + if (dev->component[MMAL_COMPONENT_CAMERA]->outputs <
  27888. + MMAL_CAMERA_PORT_COUNT) {
  27889. + ret = -EINVAL;
  27890. + goto unreg_camera;
  27891. + }
  27892. +
  27893. + ret = set_camera_parameters(dev->instance,
  27894. + dev->component[MMAL_COMPONENT_CAMERA]);
  27895. + if (ret < 0)
  27896. + goto unreg_camera;
  27897. +
  27898. + format =
  27899. + &dev->component[MMAL_COMPONENT_CAMERA]->
  27900. + output[MMAL_CAMERA_PORT_PREVIEW].format;
  27901. +
  27902. + format->encoding = MMAL_ENCODING_OPAQUE;
  27903. + format->encoding_variant = MMAL_ENCODING_I420;
  27904. +
  27905. + format->es->video.width = 1024;
  27906. + format->es->video.height = 768;
  27907. + format->es->video.crop.x = 0;
  27908. + format->es->video.crop.y = 0;
  27909. + format->es->video.crop.width = 1024;
  27910. + format->es->video.crop.height = 768;
  27911. + format->es->video.frame_rate.num = 0; /* Rely on fps_range */
  27912. + format->es->video.frame_rate.den = 1;
  27913. +
  27914. + format =
  27915. + &dev->component[MMAL_COMPONENT_CAMERA]->
  27916. + output[MMAL_CAMERA_PORT_VIDEO].format;
  27917. +
  27918. + format->encoding = MMAL_ENCODING_OPAQUE;
  27919. + format->encoding_variant = MMAL_ENCODING_I420;
  27920. +
  27921. + format->es->video.width = 1024;
  27922. + format->es->video.height = 768;
  27923. + format->es->video.crop.x = 0;
  27924. + format->es->video.crop.y = 0;
  27925. + format->es->video.crop.width = 1024;
  27926. + format->es->video.crop.height = 768;
  27927. + format->es->video.frame_rate.num = 0; /* Rely on fps_range */
  27928. + format->es->video.frame_rate.den = 1;
  27929. +
  27930. + vchiq_mmal_port_parameter_set(dev->instance,
  27931. + &dev->component[MMAL_COMPONENT_CAMERA]->
  27932. + output[MMAL_CAMERA_PORT_VIDEO],
  27933. + MMAL_PARAMETER_NO_IMAGE_PADDING,
  27934. + &bool_true, sizeof(bool_true));
  27935. +
  27936. + format =
  27937. + &dev->component[MMAL_COMPONENT_CAMERA]->
  27938. + output[MMAL_CAMERA_PORT_CAPTURE].format;
  27939. +
  27940. + format->encoding = MMAL_ENCODING_OPAQUE;
  27941. +
  27942. + format->es->video.width = 2592;
  27943. + format->es->video.height = 1944;
  27944. + format->es->video.crop.x = 0;
  27945. + format->es->video.crop.y = 0;
  27946. + format->es->video.crop.width = 2592;
  27947. + format->es->video.crop.height = 1944;
  27948. + format->es->video.frame_rate.num = 0; /* Rely on fps_range */
  27949. + format->es->video.frame_rate.den = 1;
  27950. +
  27951. + dev->capture.width = format->es->video.width;
  27952. + dev->capture.height = format->es->video.height;
  27953. + dev->capture.fmt = &formats[0];
  27954. + dev->capture.encode_component = NULL;
  27955. + dev->capture.timeperframe = tpf_default;
  27956. + dev->capture.enc_profile = V4L2_MPEG_VIDEO_H264_PROFILE_HIGH;
  27957. + dev->capture.enc_level = V4L2_MPEG_VIDEO_H264_LEVEL_4_0;
  27958. +
  27959. + vchiq_mmal_port_parameter_set(dev->instance,
  27960. + &dev->component[MMAL_COMPONENT_CAMERA]->
  27961. + output[MMAL_CAMERA_PORT_CAPTURE],
  27962. + MMAL_PARAMETER_NO_IMAGE_PADDING,
  27963. + &bool_true, sizeof(bool_true));
  27964. +
  27965. + /* get the preview component ready */
  27966. + ret = vchiq_mmal_component_init(
  27967. + dev->instance, "ril.video_render",
  27968. + &dev->component[MMAL_COMPONENT_PREVIEW]);
  27969. + if (ret < 0)
  27970. + goto unreg_camera;
  27971. +
  27972. + if (dev->component[MMAL_COMPONENT_PREVIEW]->inputs < 1) {
  27973. + ret = -EINVAL;
  27974. + pr_debug("too few input ports %d needed %d\n",
  27975. + dev->component[MMAL_COMPONENT_PREVIEW]->inputs, 1);
  27976. + goto unreg_preview;
  27977. + }
  27978. +
  27979. + /* get the image encoder component ready */
  27980. + ret = vchiq_mmal_component_init(
  27981. + dev->instance, "ril.image_encode",
  27982. + &dev->component[MMAL_COMPONENT_IMAGE_ENCODE]);
  27983. + if (ret < 0)
  27984. + goto unreg_preview;
  27985. +
  27986. + if (dev->component[MMAL_COMPONENT_IMAGE_ENCODE]->inputs < 1) {
  27987. + ret = -EINVAL;
  27988. + v4l2_err(&dev->v4l2_dev, "too few input ports %d needed %d\n",
  27989. + dev->component[MMAL_COMPONENT_IMAGE_ENCODE]->inputs,
  27990. + 1);
  27991. + goto unreg_image_encoder;
  27992. + }
  27993. +
  27994. + /* get the video encoder component ready */
  27995. + ret = vchiq_mmal_component_init(dev->instance, "ril.video_encode",
  27996. + &dev->
  27997. + component[MMAL_COMPONENT_VIDEO_ENCODE]);
  27998. + if (ret < 0)
  27999. + goto unreg_image_encoder;
  28000. +
  28001. + if (dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->inputs < 1) {
  28002. + ret = -EINVAL;
  28003. + v4l2_err(&dev->v4l2_dev, "too few input ports %d needed %d\n",
  28004. + dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->inputs,
  28005. + 1);
  28006. + goto unreg_vid_encoder;
  28007. + }
  28008. +
  28009. + {
  28010. + struct vchiq_mmal_port *encoder_port =
  28011. + &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0];
  28012. + encoder_port->format.encoding = MMAL_ENCODING_H264;
  28013. + ret = vchiq_mmal_port_set_format(dev->instance,
  28014. + encoder_port);
  28015. + }
  28016. +
  28017. + {
  28018. + unsigned int enable = 1;
  28019. + vchiq_mmal_port_parameter_set(
  28020. + dev->instance,
  28021. + &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->control,
  28022. + MMAL_PARAMETER_VIDEO_IMMUTABLE_INPUT,
  28023. + &enable, sizeof(enable));
  28024. +
  28025. + vchiq_mmal_port_parameter_set(dev->instance,
  28026. + &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->control,
  28027. + MMAL_PARAMETER_MINIMISE_FRAGMENTATION,
  28028. + &enable,
  28029. + sizeof(enable));
  28030. + }
  28031. + ret = bm2835_mmal_set_all_camera_controls(dev);
  28032. + if (ret < 0)
  28033. + goto unreg_vid_encoder;
  28034. +
  28035. + return 0;
  28036. +
  28037. +unreg_vid_encoder:
  28038. + pr_err("Cleanup: Destroy video encoder\n");
  28039. + vchiq_mmal_component_finalise(
  28040. + dev->instance,
  28041. + dev->component[MMAL_COMPONENT_VIDEO_ENCODE]);
  28042. +
  28043. +unreg_image_encoder:
  28044. + pr_err("Cleanup: Destroy image encoder\n");
  28045. + vchiq_mmal_component_finalise(
  28046. + dev->instance,
  28047. + dev->component[MMAL_COMPONENT_IMAGE_ENCODE]);
  28048. +
  28049. +unreg_preview:
  28050. + pr_err("Cleanup: Destroy video render\n");
  28051. + vchiq_mmal_component_finalise(dev->instance,
  28052. + dev->component[MMAL_COMPONENT_PREVIEW]);
  28053. +
  28054. +unreg_camera:
  28055. + pr_err("Cleanup: Destroy camera\n");
  28056. + vchiq_mmal_component_finalise(dev->instance,
  28057. + dev->component[MMAL_COMPONENT_CAMERA]);
  28058. +
  28059. +unreg_mmal:
  28060. + vchiq_mmal_finalise(dev->instance);
  28061. + return ret;
  28062. +}
  28063. +
  28064. +static int __init bm2835_mmal_init_device(struct bm2835_mmal_dev *dev,
  28065. + struct video_device *vfd)
  28066. +{
  28067. + int ret;
  28068. +
  28069. + *vfd = vdev_template;
  28070. + if (gst_v4l2src_is_broken) {
  28071. + v4l2_info(&dev->v4l2_dev,
  28072. + "Work-around for gstreamer issue is active.\n");
  28073. + vfd->ioctl_ops = &camera0_ioctl_ops_gstreamer;
  28074. + }
  28075. +
  28076. + vfd->v4l2_dev = &dev->v4l2_dev;
  28077. +
  28078. + vfd->lock = &dev->mutex;
  28079. +
  28080. + vfd->queue = &dev->capture.vb_vidq;
  28081. +
  28082. + /* video device needs to be able to access instance data */
  28083. + video_set_drvdata(vfd, dev);
  28084. +
  28085. + ret = video_register_device(vfd, VFL_TYPE_GRABBER, -1);
  28086. + if (ret < 0)
  28087. + return ret;
  28088. +
  28089. + v4l2_info(vfd->v4l2_dev,
  28090. + "V4L2 device registered as %s - stills mode > %dx%d\n",
  28091. + video_device_node_name(vfd), max_video_width, max_video_height);
  28092. +
  28093. + return 0;
  28094. +}
  28095. +
  28096. +static struct v4l2_format default_v4l2_format = {
  28097. + .fmt.pix.pixelformat = V4L2_PIX_FMT_JPEG,
  28098. + .fmt.pix.width = 1024,
  28099. + .fmt.pix.bytesperline = 1024,
  28100. + .fmt.pix.height = 768,
  28101. + .fmt.pix.sizeimage = 1024*768,
  28102. +};
  28103. +
  28104. +static int __init bm2835_mmal_init(void)
  28105. +{
  28106. + int ret;
  28107. + struct bm2835_mmal_dev *dev;
  28108. + struct vb2_queue *q;
  28109. +
  28110. + dev = kzalloc(sizeof(*gdev), GFP_KERNEL);
  28111. + if (!dev)
  28112. + return -ENOMEM;
  28113. +
  28114. + /* setup device defaults */
  28115. + dev->overlay.w.left = 150;
  28116. + dev->overlay.w.top = 50;
  28117. + dev->overlay.w.width = 1024;
  28118. + dev->overlay.w.height = 768;
  28119. + dev->overlay.clipcount = 0;
  28120. + dev->overlay.field = V4L2_FIELD_NONE;
  28121. +
  28122. + dev->capture.fmt = &formats[3]; /* JPEG */
  28123. +
  28124. + /* v4l device registration */
  28125. + snprintf(dev->v4l2_dev.name, sizeof(dev->v4l2_dev.name),
  28126. + "%s", BM2835_MMAL_MODULE_NAME);
  28127. + ret = v4l2_device_register(NULL, &dev->v4l2_dev);
  28128. + if (ret)
  28129. + goto free_dev;
  28130. +
  28131. + /* setup v4l controls */
  28132. + ret = bm2835_mmal_init_controls(dev, &dev->ctrl_handler);
  28133. + if (ret < 0)
  28134. + goto unreg_dev;
  28135. + dev->v4l2_dev.ctrl_handler = &dev->ctrl_handler;
  28136. +
  28137. + /* mmal init */
  28138. + ret = mmal_init(dev);
  28139. + if (ret < 0)
  28140. + goto unreg_dev;
  28141. +
  28142. + /* initialize queue */
  28143. + q = &dev->capture.vb_vidq;
  28144. + memset(q, 0, sizeof(*q));
  28145. + q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  28146. + q->io_modes = VB2_MMAP | VB2_USERPTR | VB2_READ;
  28147. + q->drv_priv = dev;
  28148. + q->buf_struct_size = sizeof(struct mmal_buffer);
  28149. + q->ops = &bm2835_mmal_video_qops;
  28150. + q->mem_ops = &vb2_vmalloc_memops;
  28151. + q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
  28152. + ret = vb2_queue_init(q);
  28153. + if (ret < 0)
  28154. + goto unreg_dev;
  28155. +
  28156. + /* v4l2 core mutex used to protect all fops and v4l2 ioctls. */
  28157. + mutex_init(&dev->mutex);
  28158. +
  28159. + /* initialise video devices */
  28160. + ret = bm2835_mmal_init_device(dev, &dev->vdev);
  28161. + if (ret < 0)
  28162. + goto unreg_dev;
  28163. +
  28164. + /* Really want to call vidioc_s_fmt_vid_cap with the default
  28165. + * format, but currently the APIs don't join up.
  28166. + */
  28167. + ret = mmal_setup_components(dev, &default_v4l2_format);
  28168. + if (ret < 0) {
  28169. + v4l2_err(&dev->v4l2_dev,
  28170. + "%s: could not setup components\n", __func__);
  28171. + goto unreg_dev;
  28172. + }
  28173. +
  28174. + v4l2_info(&dev->v4l2_dev,
  28175. + "Broadcom 2835 MMAL video capture ver %s loaded.\n",
  28176. + BM2835_MMAL_VERSION);
  28177. +
  28178. + gdev = dev;
  28179. + return 0;
  28180. +
  28181. +unreg_dev:
  28182. + v4l2_ctrl_handler_free(&dev->ctrl_handler);
  28183. + v4l2_device_unregister(&dev->v4l2_dev);
  28184. +
  28185. +free_dev:
  28186. + kfree(dev);
  28187. +
  28188. + v4l2_err(&dev->v4l2_dev,
  28189. + "%s: error %d while loading driver\n",
  28190. + BM2835_MMAL_MODULE_NAME, ret);
  28191. +
  28192. + return ret;
  28193. +}
  28194. +
  28195. +static void __exit bm2835_mmal_exit(void)
  28196. +{
  28197. + if (!gdev)
  28198. + return;
  28199. +
  28200. + v4l2_info(&gdev->v4l2_dev, "unregistering %s\n",
  28201. + video_device_node_name(&gdev->vdev));
  28202. +
  28203. + video_unregister_device(&gdev->vdev);
  28204. +
  28205. + if (gdev->capture.encode_component) {
  28206. + v4l2_dbg(1, bcm2835_v4l2_debug, &gdev->v4l2_dev,
  28207. + "mmal_exit - disconnect tunnel\n");
  28208. + vchiq_mmal_port_connect_tunnel(gdev->instance,
  28209. + gdev->capture.camera_port, NULL);
  28210. + vchiq_mmal_component_disable(gdev->instance,
  28211. + gdev->capture.encode_component);
  28212. + }
  28213. + vchiq_mmal_component_disable(gdev->instance,
  28214. + gdev->component[MMAL_COMPONENT_CAMERA]);
  28215. +
  28216. + vchiq_mmal_component_finalise(gdev->instance,
  28217. + gdev->
  28218. + component[MMAL_COMPONENT_VIDEO_ENCODE]);
  28219. +
  28220. + vchiq_mmal_component_finalise(gdev->instance,
  28221. + gdev->
  28222. + component[MMAL_COMPONENT_IMAGE_ENCODE]);
  28223. +
  28224. + vchiq_mmal_component_finalise(gdev->instance,
  28225. + gdev->component[MMAL_COMPONENT_PREVIEW]);
  28226. +
  28227. + vchiq_mmal_component_finalise(gdev->instance,
  28228. + gdev->component[MMAL_COMPONENT_CAMERA]);
  28229. +
  28230. + vchiq_mmal_finalise(gdev->instance);
  28231. +
  28232. + v4l2_ctrl_handler_free(&gdev->ctrl_handler);
  28233. +
  28234. + v4l2_device_unregister(&gdev->v4l2_dev);
  28235. +
  28236. + kfree(gdev);
  28237. +}
  28238. +
  28239. +module_init(bm2835_mmal_init);
  28240. +module_exit(bm2835_mmal_exit);
  28241. diff -Nur linux-3.18.8/drivers/media/platform/bcm2835/bcm2835-camera.h linux-rpi/drivers/media/platform/bcm2835/bcm2835-camera.h
  28242. --- linux-3.18.8/drivers/media/platform/bcm2835/bcm2835-camera.h 1970-01-01 01:00:00.000000000 +0100
  28243. +++ linux-rpi/drivers/media/platform/bcm2835/bcm2835-camera.h 2015-03-05 14:40:13.981715822 +0100
  28244. @@ -0,0 +1,126 @@
  28245. +/*
  28246. + * Broadcom BM2835 V4L2 driver
  28247. + *
  28248. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  28249. + *
  28250. + * This file is subject to the terms and conditions of the GNU General Public
  28251. + * License. See the file COPYING in the main directory of this archive
  28252. + * for more details.
  28253. + *
  28254. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  28255. + * Dave Stevenson <dsteve@broadcom.com>
  28256. + * Simon Mellor <simellor@broadcom.com>
  28257. + * Luke Diamand <luked@broadcom.com>
  28258. + *
  28259. + * core driver device
  28260. + */
  28261. +
  28262. +#define V4L2_CTRL_COUNT 28 /* number of v4l controls */
  28263. +
  28264. +enum {
  28265. + MMAL_COMPONENT_CAMERA = 0,
  28266. + MMAL_COMPONENT_PREVIEW,
  28267. + MMAL_COMPONENT_IMAGE_ENCODE,
  28268. + MMAL_COMPONENT_VIDEO_ENCODE,
  28269. + MMAL_COMPONENT_COUNT
  28270. +};
  28271. +
  28272. +enum {
  28273. + MMAL_CAMERA_PORT_PREVIEW = 0,
  28274. + MMAL_CAMERA_PORT_VIDEO,
  28275. + MMAL_CAMERA_PORT_CAPTURE,
  28276. + MMAL_CAMERA_PORT_COUNT
  28277. +};
  28278. +
  28279. +#define PREVIEW_LAYER 2
  28280. +
  28281. +extern int bcm2835_v4l2_debug;
  28282. +
  28283. +struct bm2835_mmal_dev {
  28284. + /* v4l2 devices */
  28285. + struct v4l2_device v4l2_dev;
  28286. + struct video_device vdev;
  28287. + struct mutex mutex;
  28288. +
  28289. + /* controls */
  28290. + struct v4l2_ctrl_handler ctrl_handler;
  28291. + struct v4l2_ctrl *ctrls[V4L2_CTRL_COUNT];
  28292. + enum v4l2_scene_mode scene_mode;
  28293. + struct mmal_colourfx colourfx;
  28294. + int hflip;
  28295. + int vflip;
  28296. + int red_gain;
  28297. + int blue_gain;
  28298. + enum mmal_parameter_exposuremode exposure_mode_user;
  28299. + enum v4l2_exposure_auto_type exposure_mode_v4l2_user;
  28300. + /* active exposure mode may differ if selected via a scene mode */
  28301. + enum mmal_parameter_exposuremode exposure_mode_active;
  28302. + enum mmal_parameter_exposuremeteringmode metering_mode;
  28303. + unsigned int manual_shutter_speed;
  28304. + bool exp_auto_priority;
  28305. +
  28306. + /* allocated mmal instance and components */
  28307. + struct vchiq_mmal_instance *instance;
  28308. + struct vchiq_mmal_component *component[MMAL_COMPONENT_COUNT];
  28309. + int camera_use_count;
  28310. +
  28311. + struct v4l2_window overlay;
  28312. +
  28313. + struct {
  28314. + unsigned int width; /* width */
  28315. + unsigned int height; /* height */
  28316. + unsigned int stride; /* stride */
  28317. + unsigned int buffersize; /* buffer size with padding */
  28318. + struct mmal_fmt *fmt;
  28319. + struct v4l2_fract timeperframe;
  28320. +
  28321. + /* H264 encode bitrate */
  28322. + int encode_bitrate;
  28323. + /* H264 bitrate mode. CBR/VBR */
  28324. + int encode_bitrate_mode;
  28325. + /* H264 profile */
  28326. + enum v4l2_mpeg_video_h264_profile enc_profile;
  28327. + /* H264 level */
  28328. + enum v4l2_mpeg_video_h264_level enc_level;
  28329. + /* JPEG Q-factor */
  28330. + int q_factor;
  28331. +
  28332. + struct vb2_queue vb_vidq;
  28333. +
  28334. + /* VC start timestamp for streaming */
  28335. + s64 vc_start_timestamp;
  28336. + /* Kernel start timestamp for streaming */
  28337. + struct timeval kernel_start_ts;
  28338. +
  28339. + struct vchiq_mmal_port *port; /* port being used for capture */
  28340. + /* camera port being used for capture */
  28341. + struct vchiq_mmal_port *camera_port;
  28342. + /* component being used for encode */
  28343. + struct vchiq_mmal_component *encode_component;
  28344. + /* number of frames remaining which driver should capture */
  28345. + unsigned int frame_count;
  28346. + /* last frame completion */
  28347. + struct completion frame_cmplt;
  28348. +
  28349. + } capture;
  28350. +
  28351. +};
  28352. +
  28353. +int bm2835_mmal_init_controls(
  28354. + struct bm2835_mmal_dev *dev,
  28355. + struct v4l2_ctrl_handler *hdl);
  28356. +
  28357. +int bm2835_mmal_set_all_camera_controls(struct bm2835_mmal_dev *dev);
  28358. +int set_framerate_params(struct bm2835_mmal_dev *dev);
  28359. +
  28360. +/* Debug helpers */
  28361. +
  28362. +#define v4l2_dump_pix_format(level, debug, dev, pix_fmt, desc) \
  28363. +{ \
  28364. + v4l2_dbg(level, debug, dev, \
  28365. +"%s: w %u h %u field %u pfmt 0x%x bpl %u sz_img %u colorspace 0x%x priv %u\n", \
  28366. + desc == NULL ? "" : desc, \
  28367. + (pix_fmt)->width, (pix_fmt)->height, (pix_fmt)->field, \
  28368. + (pix_fmt)->pixelformat, (pix_fmt)->bytesperline, \
  28369. + (pix_fmt)->sizeimage, (pix_fmt)->colorspace, (pix_fmt)->priv); \
  28370. +}
  28371. diff -Nur linux-3.18.8/drivers/media/platform/bcm2835/controls.c linux-rpi/drivers/media/platform/bcm2835/controls.c
  28372. --- linux-3.18.8/drivers/media/platform/bcm2835/controls.c 1970-01-01 01:00:00.000000000 +0100
  28373. +++ linux-rpi/drivers/media/platform/bcm2835/controls.c 2015-03-05 14:40:13.981715822 +0100
  28374. @@ -0,0 +1,1322 @@
  28375. +/*
  28376. + * Broadcom BM2835 V4L2 driver
  28377. + *
  28378. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  28379. + *
  28380. + * This file is subject to the terms and conditions of the GNU General Public
  28381. + * License. See the file COPYING in the main directory of this archive
  28382. + * for more details.
  28383. + *
  28384. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  28385. + * Dave Stevenson <dsteve@broadcom.com>
  28386. + * Simon Mellor <simellor@broadcom.com>
  28387. + * Luke Diamand <luked@broadcom.com>
  28388. + */
  28389. +
  28390. +#include <linux/errno.h>
  28391. +#include <linux/kernel.h>
  28392. +#include <linux/module.h>
  28393. +#include <linux/slab.h>
  28394. +#include <media/videobuf2-vmalloc.h>
  28395. +#include <media/v4l2-device.h>
  28396. +#include <media/v4l2-ioctl.h>
  28397. +#include <media/v4l2-ctrls.h>
  28398. +#include <media/v4l2-fh.h>
  28399. +#include <media/v4l2-event.h>
  28400. +#include <media/v4l2-common.h>
  28401. +
  28402. +#include "mmal-common.h"
  28403. +#include "mmal-vchiq.h"
  28404. +#include "mmal-parameters.h"
  28405. +#include "bcm2835-camera.h"
  28406. +
  28407. +/* The supported V4L2_CID_AUTO_EXPOSURE_BIAS values are from -4.0 to +4.0.
  28408. + * MMAL values are in 1/6th increments so the MMAL range is -24 to +24.
  28409. + * V4L2 docs say value "is expressed in terms of EV, drivers should interpret
  28410. + * the values as 0.001 EV units, where the value 1000 stands for +1 EV."
  28411. + * V4L2 is limited to a max of 32 values in a menu, so count in 1/3rds from
  28412. + * -4 to +4
  28413. + */
  28414. +static const s64 ev_bias_qmenu[] = {
  28415. + -4000, -3667, -3333,
  28416. + -3000, -2667, -2333,
  28417. + -2000, -1667, -1333,
  28418. + -1000, -667, -333,
  28419. + 0, 333, 667,
  28420. + 1000, 1333, 1667,
  28421. + 2000, 2333, 2667,
  28422. + 3000, 3333, 3667,
  28423. + 4000
  28424. +};
  28425. +
  28426. +/* Supported ISO values
  28427. + * ISOO = auto ISO
  28428. + */
  28429. +static const s64 iso_qmenu[] = {
  28430. + 0, 100, 200, 400, 800,
  28431. +};
  28432. +
  28433. +static const s64 mains_freq_qmenu[] = {
  28434. + V4L2_CID_POWER_LINE_FREQUENCY_DISABLED,
  28435. + V4L2_CID_POWER_LINE_FREQUENCY_50HZ,
  28436. + V4L2_CID_POWER_LINE_FREQUENCY_60HZ,
  28437. + V4L2_CID_POWER_LINE_FREQUENCY_AUTO
  28438. +};
  28439. +
  28440. +/* Supported video encode modes */
  28441. +static const s64 bitrate_mode_qmenu[] = {
  28442. + (s64)V4L2_MPEG_VIDEO_BITRATE_MODE_VBR,
  28443. + (s64)V4L2_MPEG_VIDEO_BITRATE_MODE_CBR,
  28444. +};
  28445. +
  28446. +enum bm2835_mmal_ctrl_type {
  28447. + MMAL_CONTROL_TYPE_STD,
  28448. + MMAL_CONTROL_TYPE_STD_MENU,
  28449. + MMAL_CONTROL_TYPE_INT_MENU,
  28450. + MMAL_CONTROL_TYPE_CLUSTER, /* special cluster entry */
  28451. +};
  28452. +
  28453. +struct bm2835_mmal_v4l2_ctrl;
  28454. +
  28455. +typedef int(bm2835_mmal_v4l2_ctrl_cb)(
  28456. + struct bm2835_mmal_dev *dev,
  28457. + struct v4l2_ctrl *ctrl,
  28458. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl);
  28459. +
  28460. +struct bm2835_mmal_v4l2_ctrl {
  28461. + u32 id; /* v4l2 control identifier */
  28462. + enum bm2835_mmal_ctrl_type type;
  28463. + /* control minimum value or
  28464. + * mask for MMAL_CONTROL_TYPE_STD_MENU */
  28465. + s32 min;
  28466. + s32 max; /* maximum value of control */
  28467. + s32 def; /* default value of control */
  28468. + s32 step; /* step size of the control */
  28469. + const s64 *imenu; /* integer menu array */
  28470. + u32 mmal_id; /* mmal parameter id */
  28471. + bm2835_mmal_v4l2_ctrl_cb *setter;
  28472. + bool ignore_errors;
  28473. +};
  28474. +
  28475. +struct v4l2_to_mmal_effects_setting {
  28476. + u32 v4l2_effect;
  28477. + u32 mmal_effect;
  28478. + s32 col_fx_enable;
  28479. + s32 col_fx_fixed_cbcr;
  28480. + u32 u;
  28481. + u32 v;
  28482. + u32 num_effect_params;
  28483. + u32 effect_params[MMAL_MAX_IMAGEFX_PARAMETERS];
  28484. +};
  28485. +
  28486. +static const struct v4l2_to_mmal_effects_setting
  28487. + v4l2_to_mmal_effects_values[] = {
  28488. + { V4L2_COLORFX_NONE, MMAL_PARAM_IMAGEFX_NONE,
  28489. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  28490. + { V4L2_COLORFX_BW, MMAL_PARAM_IMAGEFX_NONE,
  28491. + 1, 0, 128, 128, 0, {0, 0, 0, 0, 0} },
  28492. + { V4L2_COLORFX_SEPIA, MMAL_PARAM_IMAGEFX_NONE,
  28493. + 1, 0, 87, 151, 0, {0, 0, 0, 0, 0} },
  28494. + { V4L2_COLORFX_NEGATIVE, MMAL_PARAM_IMAGEFX_NEGATIVE,
  28495. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  28496. + { V4L2_COLORFX_EMBOSS, MMAL_PARAM_IMAGEFX_EMBOSS,
  28497. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  28498. + { V4L2_COLORFX_SKETCH, MMAL_PARAM_IMAGEFX_SKETCH,
  28499. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  28500. + { V4L2_COLORFX_SKY_BLUE, MMAL_PARAM_IMAGEFX_PASTEL,
  28501. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  28502. + { V4L2_COLORFX_GRASS_GREEN, MMAL_PARAM_IMAGEFX_WATERCOLOUR,
  28503. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  28504. + { V4L2_COLORFX_SKIN_WHITEN, MMAL_PARAM_IMAGEFX_WASHEDOUT,
  28505. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  28506. + { V4L2_COLORFX_VIVID, MMAL_PARAM_IMAGEFX_SATURATION,
  28507. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  28508. + { V4L2_COLORFX_AQUA, MMAL_PARAM_IMAGEFX_NONE,
  28509. + 1, 0, 171, 121, 0, {0, 0, 0, 0, 0} },
  28510. + { V4L2_COLORFX_ART_FREEZE, MMAL_PARAM_IMAGEFX_HATCH,
  28511. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  28512. + { V4L2_COLORFX_SILHOUETTE, MMAL_PARAM_IMAGEFX_FILM,
  28513. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  28514. + { V4L2_COLORFX_SOLARIZATION, MMAL_PARAM_IMAGEFX_SOLARIZE,
  28515. + 0, 0, 0, 0, 5, {1, 128, 160, 160, 48} },
  28516. + { V4L2_COLORFX_ANTIQUE, MMAL_PARAM_IMAGEFX_COLOURBALANCE,
  28517. + 0, 0, 0, 0, 3, {108, 274, 238, 0, 0} },
  28518. + { V4L2_COLORFX_SET_CBCR, MMAL_PARAM_IMAGEFX_NONE,
  28519. + 1, 1, 0, 0, 0, {0, 0, 0, 0, 0} }
  28520. +};
  28521. +
  28522. +struct v4l2_mmal_scene_config {
  28523. + enum v4l2_scene_mode v4l2_scene;
  28524. + enum mmal_parameter_exposuremode exposure_mode;
  28525. + enum mmal_parameter_exposuremeteringmode metering_mode;
  28526. +};
  28527. +
  28528. +static const struct v4l2_mmal_scene_config scene_configs[] = {
  28529. + /* V4L2_SCENE_MODE_NONE automatically added */
  28530. + {
  28531. + V4L2_SCENE_MODE_NIGHT,
  28532. + MMAL_PARAM_EXPOSUREMODE_NIGHT,
  28533. + MMAL_PARAM_EXPOSUREMETERINGMODE_AVERAGE
  28534. + },
  28535. + {
  28536. + V4L2_SCENE_MODE_SPORTS,
  28537. + MMAL_PARAM_EXPOSUREMODE_SPORTS,
  28538. + MMAL_PARAM_EXPOSUREMETERINGMODE_AVERAGE
  28539. + },
  28540. +};
  28541. +
  28542. +/* control handlers*/
  28543. +
  28544. +static int ctrl_set_rational(struct bm2835_mmal_dev *dev,
  28545. + struct v4l2_ctrl *ctrl,
  28546. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  28547. +{
  28548. + struct mmal_parameter_rational rational_value;
  28549. + struct vchiq_mmal_port *control;
  28550. +
  28551. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  28552. +
  28553. + rational_value.num = ctrl->val;
  28554. + rational_value.den = 100;
  28555. +
  28556. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  28557. + mmal_ctrl->mmal_id,
  28558. + &rational_value,
  28559. + sizeof(rational_value));
  28560. +}
  28561. +
  28562. +static int ctrl_set_value(struct bm2835_mmal_dev *dev,
  28563. + struct v4l2_ctrl *ctrl,
  28564. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  28565. +{
  28566. + u32 u32_value;
  28567. + struct vchiq_mmal_port *control;
  28568. +
  28569. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  28570. +
  28571. + u32_value = ctrl->val;
  28572. +
  28573. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  28574. + mmal_ctrl->mmal_id,
  28575. + &u32_value, sizeof(u32_value));
  28576. +}
  28577. +
  28578. +static int ctrl_set_value_menu(struct bm2835_mmal_dev *dev,
  28579. + struct v4l2_ctrl *ctrl,
  28580. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  28581. +{
  28582. + u32 u32_value;
  28583. + struct vchiq_mmal_port *control;
  28584. +
  28585. + if (ctrl->val > mmal_ctrl->max || ctrl->val < mmal_ctrl->min)
  28586. + return 1;
  28587. +
  28588. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  28589. +
  28590. + u32_value = mmal_ctrl->imenu[ctrl->val];
  28591. +
  28592. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  28593. + mmal_ctrl->mmal_id,
  28594. + &u32_value, sizeof(u32_value));
  28595. +}
  28596. +
  28597. +static int ctrl_set_value_ev(struct bm2835_mmal_dev *dev,
  28598. + struct v4l2_ctrl *ctrl,
  28599. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  28600. +{
  28601. + s32 s32_value;
  28602. + struct vchiq_mmal_port *control;
  28603. +
  28604. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  28605. +
  28606. + s32_value = (ctrl->val-12)*2; /* Convert from index to 1/6ths */
  28607. +
  28608. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  28609. + mmal_ctrl->mmal_id,
  28610. + &s32_value, sizeof(s32_value));
  28611. +}
  28612. +
  28613. +static int ctrl_set_rotate(struct bm2835_mmal_dev *dev,
  28614. + struct v4l2_ctrl *ctrl,
  28615. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  28616. +{
  28617. + int ret;
  28618. + u32 u32_value;
  28619. + struct vchiq_mmal_component *camera;
  28620. +
  28621. + camera = dev->component[MMAL_COMPONENT_CAMERA];
  28622. +
  28623. + u32_value = ((ctrl->val % 360) / 90) * 90;
  28624. +
  28625. + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[0],
  28626. + mmal_ctrl->mmal_id,
  28627. + &u32_value, sizeof(u32_value));
  28628. + if (ret < 0)
  28629. + return ret;
  28630. +
  28631. + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[1],
  28632. + mmal_ctrl->mmal_id,
  28633. + &u32_value, sizeof(u32_value));
  28634. + if (ret < 0)
  28635. + return ret;
  28636. +
  28637. + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[2],
  28638. + mmal_ctrl->mmal_id,
  28639. + &u32_value, sizeof(u32_value));
  28640. +
  28641. + return ret;
  28642. +}
  28643. +
  28644. +static int ctrl_set_flip(struct bm2835_mmal_dev *dev,
  28645. + struct v4l2_ctrl *ctrl,
  28646. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  28647. +{
  28648. + int ret;
  28649. + u32 u32_value;
  28650. + struct vchiq_mmal_component *camera;
  28651. +
  28652. + if (ctrl->id == V4L2_CID_HFLIP)
  28653. + dev->hflip = ctrl->val;
  28654. + else
  28655. + dev->vflip = ctrl->val;
  28656. +
  28657. + camera = dev->component[MMAL_COMPONENT_CAMERA];
  28658. +
  28659. + if (dev->hflip && dev->vflip)
  28660. + u32_value = MMAL_PARAM_MIRROR_BOTH;
  28661. + else if (dev->hflip)
  28662. + u32_value = MMAL_PARAM_MIRROR_HORIZONTAL;
  28663. + else if (dev->vflip)
  28664. + u32_value = MMAL_PARAM_MIRROR_VERTICAL;
  28665. + else
  28666. + u32_value = MMAL_PARAM_MIRROR_NONE;
  28667. +
  28668. + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[0],
  28669. + mmal_ctrl->mmal_id,
  28670. + &u32_value, sizeof(u32_value));
  28671. + if (ret < 0)
  28672. + return ret;
  28673. +
  28674. + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[1],
  28675. + mmal_ctrl->mmal_id,
  28676. + &u32_value, sizeof(u32_value));
  28677. + if (ret < 0)
  28678. + return ret;
  28679. +
  28680. + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[2],
  28681. + mmal_ctrl->mmal_id,
  28682. + &u32_value, sizeof(u32_value));
  28683. +
  28684. + return ret;
  28685. +
  28686. +}
  28687. +
  28688. +static int ctrl_set_exposure(struct bm2835_mmal_dev *dev,
  28689. + struct v4l2_ctrl *ctrl,
  28690. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  28691. +{
  28692. + enum mmal_parameter_exposuremode exp_mode = dev->exposure_mode_user;
  28693. + u32 shutter_speed = 0;
  28694. + struct vchiq_mmal_port *control;
  28695. + int ret = 0;
  28696. +
  28697. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  28698. +
  28699. + if (mmal_ctrl->mmal_id == MMAL_PARAMETER_SHUTTER_SPEED) {
  28700. + /* V4L2 is in 100usec increments.
  28701. + * MMAL is 1usec.
  28702. + */
  28703. + dev->manual_shutter_speed = ctrl->val * 100;
  28704. + } else if (mmal_ctrl->mmal_id == MMAL_PARAMETER_EXPOSURE_MODE) {
  28705. + switch (ctrl->val) {
  28706. + case V4L2_EXPOSURE_AUTO:
  28707. + exp_mode = MMAL_PARAM_EXPOSUREMODE_AUTO;
  28708. + break;
  28709. +
  28710. + case V4L2_EXPOSURE_MANUAL:
  28711. + exp_mode = MMAL_PARAM_EXPOSUREMODE_OFF;
  28712. + break;
  28713. + }
  28714. + dev->exposure_mode_user = exp_mode;
  28715. + dev->exposure_mode_v4l2_user = ctrl->val;
  28716. + } else if (mmal_ctrl->id == V4L2_CID_EXPOSURE_AUTO_PRIORITY) {
  28717. + dev->exp_auto_priority = ctrl->val;
  28718. + }
  28719. +
  28720. + if (dev->scene_mode == V4L2_SCENE_MODE_NONE) {
  28721. + if (exp_mode == MMAL_PARAM_EXPOSUREMODE_OFF)
  28722. + shutter_speed = dev->manual_shutter_speed;
  28723. +
  28724. + ret = vchiq_mmal_port_parameter_set(dev->instance,
  28725. + control,
  28726. + MMAL_PARAMETER_SHUTTER_SPEED,
  28727. + &shutter_speed,
  28728. + sizeof(shutter_speed));
  28729. + ret += vchiq_mmal_port_parameter_set(dev->instance,
  28730. + control,
  28731. + MMAL_PARAMETER_EXPOSURE_MODE,
  28732. + &exp_mode,
  28733. + sizeof(u32));
  28734. + dev->exposure_mode_active = exp_mode;
  28735. + }
  28736. + /* exposure_dynamic_framerate (V4L2_CID_EXPOSURE_AUTO_PRIORITY) should
  28737. + * always apply irrespective of scene mode.
  28738. + */
  28739. + ret += set_framerate_params(dev);
  28740. +
  28741. + return ret;
  28742. +}
  28743. +
  28744. +static int ctrl_set_metering_mode(struct bm2835_mmal_dev *dev,
  28745. + struct v4l2_ctrl *ctrl,
  28746. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  28747. +{
  28748. + switch (ctrl->val) {
  28749. + case V4L2_EXPOSURE_METERING_AVERAGE:
  28750. + dev->metering_mode = MMAL_PARAM_EXPOSUREMETERINGMODE_AVERAGE;
  28751. + break;
  28752. +
  28753. + case V4L2_EXPOSURE_METERING_CENTER_WEIGHTED:
  28754. + dev->metering_mode = MMAL_PARAM_EXPOSUREMETERINGMODE_BACKLIT;
  28755. + break;
  28756. +
  28757. + case V4L2_EXPOSURE_METERING_SPOT:
  28758. + dev->metering_mode = MMAL_PARAM_EXPOSUREMETERINGMODE_SPOT;
  28759. + break;
  28760. +
  28761. + /* todo matrix weighting not added to Linux API till 3.9
  28762. + case V4L2_EXPOSURE_METERING_MATRIX:
  28763. + dev->metering_mode = MMAL_PARAM_EXPOSUREMETERINGMODE_MATRIX;
  28764. + break;
  28765. + */
  28766. +
  28767. + }
  28768. +
  28769. + if (dev->scene_mode == V4L2_SCENE_MODE_NONE) {
  28770. + struct vchiq_mmal_port *control;
  28771. + u32 u32_value = dev->metering_mode;
  28772. +
  28773. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  28774. +
  28775. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  28776. + mmal_ctrl->mmal_id,
  28777. + &u32_value, sizeof(u32_value));
  28778. + } else
  28779. + return 0;
  28780. +}
  28781. +
  28782. +static int ctrl_set_flicker_avoidance(struct bm2835_mmal_dev *dev,
  28783. + struct v4l2_ctrl *ctrl,
  28784. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  28785. +{
  28786. + u32 u32_value;
  28787. + struct vchiq_mmal_port *control;
  28788. +
  28789. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  28790. +
  28791. + switch (ctrl->val) {
  28792. + case V4L2_CID_POWER_LINE_FREQUENCY_DISABLED:
  28793. + u32_value = MMAL_PARAM_FLICKERAVOID_OFF;
  28794. + break;
  28795. + case V4L2_CID_POWER_LINE_FREQUENCY_50HZ:
  28796. + u32_value = MMAL_PARAM_FLICKERAVOID_50HZ;
  28797. + break;
  28798. + case V4L2_CID_POWER_LINE_FREQUENCY_60HZ:
  28799. + u32_value = MMAL_PARAM_FLICKERAVOID_60HZ;
  28800. + break;
  28801. + case V4L2_CID_POWER_LINE_FREQUENCY_AUTO:
  28802. + u32_value = MMAL_PARAM_FLICKERAVOID_AUTO;
  28803. + break;
  28804. + }
  28805. +
  28806. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  28807. + mmal_ctrl->mmal_id,
  28808. + &u32_value, sizeof(u32_value));
  28809. +}
  28810. +
  28811. +static int ctrl_set_awb_mode(struct bm2835_mmal_dev *dev,
  28812. + struct v4l2_ctrl *ctrl,
  28813. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  28814. +{
  28815. + u32 u32_value;
  28816. + struct vchiq_mmal_port *control;
  28817. +
  28818. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  28819. +
  28820. + switch (ctrl->val) {
  28821. + case V4L2_WHITE_BALANCE_MANUAL:
  28822. + u32_value = MMAL_PARAM_AWBMODE_OFF;
  28823. + break;
  28824. +
  28825. + case V4L2_WHITE_BALANCE_AUTO:
  28826. + u32_value = MMAL_PARAM_AWBMODE_AUTO;
  28827. + break;
  28828. +
  28829. + case V4L2_WHITE_BALANCE_INCANDESCENT:
  28830. + u32_value = MMAL_PARAM_AWBMODE_INCANDESCENT;
  28831. + break;
  28832. +
  28833. + case V4L2_WHITE_BALANCE_FLUORESCENT:
  28834. + u32_value = MMAL_PARAM_AWBMODE_FLUORESCENT;
  28835. + break;
  28836. +
  28837. + case V4L2_WHITE_BALANCE_FLUORESCENT_H:
  28838. + u32_value = MMAL_PARAM_AWBMODE_TUNGSTEN;
  28839. + break;
  28840. +
  28841. + case V4L2_WHITE_BALANCE_HORIZON:
  28842. + u32_value = MMAL_PARAM_AWBMODE_HORIZON;
  28843. + break;
  28844. +
  28845. + case V4L2_WHITE_BALANCE_DAYLIGHT:
  28846. + u32_value = MMAL_PARAM_AWBMODE_SUNLIGHT;
  28847. + break;
  28848. +
  28849. + case V4L2_WHITE_BALANCE_FLASH:
  28850. + u32_value = MMAL_PARAM_AWBMODE_FLASH;
  28851. + break;
  28852. +
  28853. + case V4L2_WHITE_BALANCE_CLOUDY:
  28854. + u32_value = MMAL_PARAM_AWBMODE_CLOUDY;
  28855. + break;
  28856. +
  28857. + case V4L2_WHITE_BALANCE_SHADE:
  28858. + u32_value = MMAL_PARAM_AWBMODE_SHADE;
  28859. + break;
  28860. +
  28861. + }
  28862. +
  28863. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  28864. + mmal_ctrl->mmal_id,
  28865. + &u32_value, sizeof(u32_value));
  28866. +}
  28867. +
  28868. +static int ctrl_set_awb_gains(struct bm2835_mmal_dev *dev,
  28869. + struct v4l2_ctrl *ctrl,
  28870. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  28871. +{
  28872. + struct vchiq_mmal_port *control;
  28873. + struct mmal_parameter_awbgains gains;
  28874. +
  28875. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  28876. +
  28877. + if (ctrl->id == V4L2_CID_RED_BALANCE)
  28878. + dev->red_gain = ctrl->val;
  28879. + else if (ctrl->id == V4L2_CID_BLUE_BALANCE)
  28880. + dev->blue_gain = ctrl->val;
  28881. +
  28882. + gains.r_gain.num = dev->red_gain;
  28883. + gains.b_gain.num = dev->blue_gain;
  28884. + gains.r_gain.den = gains.b_gain.den = 1000;
  28885. +
  28886. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  28887. + mmal_ctrl->mmal_id,
  28888. + &gains, sizeof(gains));
  28889. +}
  28890. +
  28891. +static int ctrl_set_image_effect(struct bm2835_mmal_dev *dev,
  28892. + struct v4l2_ctrl *ctrl,
  28893. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  28894. +{
  28895. + int ret = -EINVAL;
  28896. + int i, j;
  28897. + struct vchiq_mmal_port *control;
  28898. + struct mmal_parameter_imagefx_parameters imagefx;
  28899. +
  28900. + for (i = 0; i < ARRAY_SIZE(v4l2_to_mmal_effects_values); i++) {
  28901. + if (ctrl->val == v4l2_to_mmal_effects_values[i].v4l2_effect) {
  28902. +
  28903. + imagefx.effect =
  28904. + v4l2_to_mmal_effects_values[i].mmal_effect;
  28905. + imagefx.num_effect_params =
  28906. + v4l2_to_mmal_effects_values[i].num_effect_params;
  28907. +
  28908. + if (imagefx.num_effect_params > MMAL_MAX_IMAGEFX_PARAMETERS)
  28909. + imagefx.num_effect_params = MMAL_MAX_IMAGEFX_PARAMETERS;
  28910. +
  28911. + for (j = 0; j < imagefx.num_effect_params; j++)
  28912. + imagefx.effect_parameter[j] =
  28913. + v4l2_to_mmal_effects_values[i].effect_params[j];
  28914. +
  28915. + dev->colourfx.enable =
  28916. + v4l2_to_mmal_effects_values[i].col_fx_enable;
  28917. + if (!v4l2_to_mmal_effects_values[i].col_fx_fixed_cbcr) {
  28918. + dev->colourfx.u =
  28919. + v4l2_to_mmal_effects_values[i].u;
  28920. + dev->colourfx.v =
  28921. + v4l2_to_mmal_effects_values[i].v;
  28922. + }
  28923. +
  28924. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  28925. +
  28926. + ret = vchiq_mmal_port_parameter_set(
  28927. + dev->instance, control,
  28928. + MMAL_PARAMETER_IMAGE_EFFECT_PARAMETERS,
  28929. + &imagefx, sizeof(imagefx));
  28930. + if (ret)
  28931. + goto exit;
  28932. +
  28933. + ret = vchiq_mmal_port_parameter_set(
  28934. + dev->instance, control,
  28935. + MMAL_PARAMETER_COLOUR_EFFECT,
  28936. + &dev->colourfx, sizeof(dev->colourfx));
  28937. + }
  28938. + }
  28939. +
  28940. +exit:
  28941. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  28942. + "mmal_ctrl:%p ctrl id:0x%x ctrl val:%d imagefx:0x%x color_effect:%s u:%d v:%d ret %d(%d)\n",
  28943. + mmal_ctrl, ctrl->id, ctrl->val, imagefx.effect,
  28944. + dev->colourfx.enable ? "true" : "false",
  28945. + dev->colourfx.u, dev->colourfx.v,
  28946. + ret, (ret == 0 ? 0 : -EINVAL));
  28947. + return (ret == 0 ? 0 : EINVAL);
  28948. +}
  28949. +
  28950. +static int ctrl_set_colfx(struct bm2835_mmal_dev *dev,
  28951. + struct v4l2_ctrl *ctrl,
  28952. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  28953. +{
  28954. + int ret = -EINVAL;
  28955. + struct vchiq_mmal_port *control;
  28956. +
  28957. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  28958. +
  28959. + dev->colourfx.enable = (ctrl->val & 0xff00) >> 8;
  28960. + dev->colourfx.enable = ctrl->val & 0xff;
  28961. +
  28962. + ret = vchiq_mmal_port_parameter_set(dev->instance, control,
  28963. + MMAL_PARAMETER_COLOUR_EFFECT,
  28964. + &dev->colourfx, sizeof(dev->colourfx));
  28965. +
  28966. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  28967. + "%s: After: mmal_ctrl:%p ctrl id:0x%x ctrl val:%d ret %d(%d)\n",
  28968. + __func__, mmal_ctrl, ctrl->id, ctrl->val, ret,
  28969. + (ret == 0 ? 0 : -EINVAL));
  28970. + return (ret == 0 ? 0 : EINVAL);
  28971. +}
  28972. +
  28973. +static int ctrl_set_bitrate(struct bm2835_mmal_dev *dev,
  28974. + struct v4l2_ctrl *ctrl,
  28975. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  28976. +{
  28977. + int ret;
  28978. + struct vchiq_mmal_port *encoder_out;
  28979. +
  28980. + dev->capture.encode_bitrate = ctrl->val;
  28981. +
  28982. + encoder_out = &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0];
  28983. +
  28984. + ret = vchiq_mmal_port_parameter_set(dev->instance, encoder_out,
  28985. + mmal_ctrl->mmal_id,
  28986. + &ctrl->val, sizeof(ctrl->val));
  28987. + ret = 0;
  28988. + return ret;
  28989. +}
  28990. +
  28991. +static int ctrl_set_bitrate_mode(struct bm2835_mmal_dev *dev,
  28992. + struct v4l2_ctrl *ctrl,
  28993. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  28994. +{
  28995. + u32 bitrate_mode;
  28996. + struct vchiq_mmal_port *encoder_out;
  28997. +
  28998. + encoder_out = &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0];
  28999. +
  29000. + dev->capture.encode_bitrate_mode = ctrl->val;
  29001. + switch (ctrl->val) {
  29002. + default:
  29003. + case V4L2_MPEG_VIDEO_BITRATE_MODE_VBR:
  29004. + bitrate_mode = MMAL_VIDEO_RATECONTROL_VARIABLE;
  29005. + break;
  29006. + case V4L2_MPEG_VIDEO_BITRATE_MODE_CBR:
  29007. + bitrate_mode = MMAL_VIDEO_RATECONTROL_CONSTANT;
  29008. + break;
  29009. + }
  29010. +
  29011. + vchiq_mmal_port_parameter_set(dev->instance, encoder_out,
  29012. + mmal_ctrl->mmal_id,
  29013. + &bitrate_mode,
  29014. + sizeof(bitrate_mode));
  29015. + return 0;
  29016. +}
  29017. +
  29018. +static int ctrl_set_image_encode_output(struct bm2835_mmal_dev *dev,
  29019. + struct v4l2_ctrl *ctrl,
  29020. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  29021. +{
  29022. + u32 u32_value;
  29023. + struct vchiq_mmal_port *jpeg_out;
  29024. +
  29025. + jpeg_out = &dev->component[MMAL_COMPONENT_IMAGE_ENCODE]->output[0];
  29026. +
  29027. + u32_value = ctrl->val;
  29028. +
  29029. + return vchiq_mmal_port_parameter_set(dev->instance, jpeg_out,
  29030. + mmal_ctrl->mmal_id,
  29031. + &u32_value, sizeof(u32_value));
  29032. +}
  29033. +
  29034. +static int ctrl_set_video_encode_param_output(struct bm2835_mmal_dev *dev,
  29035. + struct v4l2_ctrl *ctrl,
  29036. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  29037. +{
  29038. + u32 u32_value;
  29039. + struct vchiq_mmal_port *vid_enc_ctl;
  29040. +
  29041. + vid_enc_ctl = &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0];
  29042. +
  29043. + u32_value = ctrl->val;
  29044. +
  29045. + return vchiq_mmal_port_parameter_set(dev->instance, vid_enc_ctl,
  29046. + mmal_ctrl->mmal_id,
  29047. + &u32_value, sizeof(u32_value));
  29048. +}
  29049. +
  29050. +static int ctrl_set_video_encode_profile_level(struct bm2835_mmal_dev *dev,
  29051. + struct v4l2_ctrl *ctrl,
  29052. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  29053. +{
  29054. + struct mmal_parameter_video_profile param;
  29055. + int ret = 0;
  29056. +
  29057. + if (ctrl->id == V4L2_CID_MPEG_VIDEO_H264_PROFILE) {
  29058. + switch (ctrl->val) {
  29059. + case V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE:
  29060. + case V4L2_MPEG_VIDEO_H264_PROFILE_CONSTRAINED_BASELINE:
  29061. + case V4L2_MPEG_VIDEO_H264_PROFILE_MAIN:
  29062. + case V4L2_MPEG_VIDEO_H264_PROFILE_HIGH:
  29063. + dev->capture.enc_profile = ctrl->val;
  29064. + break;
  29065. + default:
  29066. + ret = -EINVAL;
  29067. + break;
  29068. + }
  29069. + } else if (ctrl->id == V4L2_CID_MPEG_VIDEO_H264_LEVEL) {
  29070. + switch (ctrl->val) {
  29071. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_0:
  29072. + case V4L2_MPEG_VIDEO_H264_LEVEL_1B:
  29073. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_1:
  29074. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_2:
  29075. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_3:
  29076. + case V4L2_MPEG_VIDEO_H264_LEVEL_2_0:
  29077. + case V4L2_MPEG_VIDEO_H264_LEVEL_2_1:
  29078. + case V4L2_MPEG_VIDEO_H264_LEVEL_2_2:
  29079. + case V4L2_MPEG_VIDEO_H264_LEVEL_3_0:
  29080. + case V4L2_MPEG_VIDEO_H264_LEVEL_3_1:
  29081. + case V4L2_MPEG_VIDEO_H264_LEVEL_3_2:
  29082. + case V4L2_MPEG_VIDEO_H264_LEVEL_4_0:
  29083. + dev->capture.enc_level = ctrl->val;
  29084. + break;
  29085. + default:
  29086. + ret = -EINVAL;
  29087. + break;
  29088. + }
  29089. + }
  29090. +
  29091. + if (!ret) {
  29092. + switch (dev->capture.enc_profile) {
  29093. + case V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE:
  29094. + param.profile = MMAL_VIDEO_PROFILE_H264_BASELINE;
  29095. + break;
  29096. + case V4L2_MPEG_VIDEO_H264_PROFILE_CONSTRAINED_BASELINE:
  29097. + param.profile =
  29098. + MMAL_VIDEO_PROFILE_H264_CONSTRAINED_BASELINE;
  29099. + break;
  29100. + case V4L2_MPEG_VIDEO_H264_PROFILE_MAIN:
  29101. + param.profile = MMAL_VIDEO_PROFILE_H264_MAIN;
  29102. + break;
  29103. + case V4L2_MPEG_VIDEO_H264_PROFILE_HIGH:
  29104. + param.profile = MMAL_VIDEO_PROFILE_H264_HIGH;
  29105. + break;
  29106. + default:
  29107. + /* Should never get here */
  29108. + break;
  29109. + }
  29110. +
  29111. + switch (dev->capture.enc_level) {
  29112. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_0:
  29113. + param.level = MMAL_VIDEO_LEVEL_H264_1;
  29114. + break;
  29115. + case V4L2_MPEG_VIDEO_H264_LEVEL_1B:
  29116. + param.level = MMAL_VIDEO_LEVEL_H264_1b;
  29117. + break;
  29118. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_1:
  29119. + param.level = MMAL_VIDEO_LEVEL_H264_11;
  29120. + break;
  29121. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_2:
  29122. + param.level = MMAL_VIDEO_LEVEL_H264_12;
  29123. + break;
  29124. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_3:
  29125. + param.level = MMAL_VIDEO_LEVEL_H264_13;
  29126. + break;
  29127. + case V4L2_MPEG_VIDEO_H264_LEVEL_2_0:
  29128. + param.level = MMAL_VIDEO_LEVEL_H264_2;
  29129. + break;
  29130. + case V4L2_MPEG_VIDEO_H264_LEVEL_2_1:
  29131. + param.level = MMAL_VIDEO_LEVEL_H264_21;
  29132. + break;
  29133. + case V4L2_MPEG_VIDEO_H264_LEVEL_2_2:
  29134. + param.level = MMAL_VIDEO_LEVEL_H264_22;
  29135. + break;
  29136. + case V4L2_MPEG_VIDEO_H264_LEVEL_3_0:
  29137. + param.level = MMAL_VIDEO_LEVEL_H264_3;
  29138. + break;
  29139. + case V4L2_MPEG_VIDEO_H264_LEVEL_3_1:
  29140. + param.level = MMAL_VIDEO_LEVEL_H264_31;
  29141. + break;
  29142. + case V4L2_MPEG_VIDEO_H264_LEVEL_3_2:
  29143. + param.level = MMAL_VIDEO_LEVEL_H264_32;
  29144. + break;
  29145. + case V4L2_MPEG_VIDEO_H264_LEVEL_4_0:
  29146. + param.level = MMAL_VIDEO_LEVEL_H264_4;
  29147. + break;
  29148. + default:
  29149. + /* Should never get here */
  29150. + break;
  29151. + }
  29152. +
  29153. + ret = vchiq_mmal_port_parameter_set(dev->instance,
  29154. + &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0],
  29155. + mmal_ctrl->mmal_id,
  29156. + &param, sizeof(param));
  29157. + }
  29158. + return ret;
  29159. +}
  29160. +
  29161. +static int ctrl_set_scene_mode(struct bm2835_mmal_dev *dev,
  29162. + struct v4l2_ctrl *ctrl,
  29163. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  29164. +{
  29165. + int ret = 0;
  29166. + int shutter_speed;
  29167. + struct vchiq_mmal_port *control;
  29168. +
  29169. + v4l2_dbg(0, bcm2835_v4l2_debug, &dev->v4l2_dev,
  29170. + "scene mode selected %d, was %d\n", ctrl->val,
  29171. + dev->scene_mode);
  29172. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  29173. +
  29174. + if (ctrl->val == dev->scene_mode)
  29175. + return 0;
  29176. +
  29177. + if (ctrl->val == V4L2_SCENE_MODE_NONE) {
  29178. + /* Restore all user selections */
  29179. + dev->scene_mode = V4L2_SCENE_MODE_NONE;
  29180. +
  29181. + if (dev->exposure_mode_user == MMAL_PARAM_EXPOSUREMODE_OFF)
  29182. + shutter_speed = dev->manual_shutter_speed;
  29183. + else
  29184. + shutter_speed = 0;
  29185. +
  29186. + v4l2_dbg(0, bcm2835_v4l2_debug, &dev->v4l2_dev,
  29187. + "%s: scene mode none: shut_speed %d, exp_mode %d, metering %d\n",
  29188. + __func__, shutter_speed, dev->exposure_mode_user,
  29189. + dev->metering_mode);
  29190. + ret = vchiq_mmal_port_parameter_set(dev->instance,
  29191. + control,
  29192. + MMAL_PARAMETER_SHUTTER_SPEED,
  29193. + &shutter_speed,
  29194. + sizeof(shutter_speed));
  29195. + ret += vchiq_mmal_port_parameter_set(dev->instance,
  29196. + control,
  29197. + MMAL_PARAMETER_EXPOSURE_MODE,
  29198. + &dev->exposure_mode_user,
  29199. + sizeof(u32));
  29200. + dev->exposure_mode_active = dev->exposure_mode_user;
  29201. + ret += vchiq_mmal_port_parameter_set(dev->instance,
  29202. + control,
  29203. + MMAL_PARAMETER_EXP_METERING_MODE,
  29204. + &dev->metering_mode,
  29205. + sizeof(u32));
  29206. + ret += set_framerate_params(dev);
  29207. + } else {
  29208. + /* Set up scene mode */
  29209. + int i;
  29210. + const struct v4l2_mmal_scene_config *scene = NULL;
  29211. + int shutter_speed;
  29212. + enum mmal_parameter_exposuremode exposure_mode;
  29213. + enum mmal_parameter_exposuremeteringmode metering_mode;
  29214. +
  29215. + for (i = 0; i < ARRAY_SIZE(scene_configs); i++) {
  29216. + if (scene_configs[i].v4l2_scene ==
  29217. + ctrl->val) {
  29218. + scene = &scene_configs[i];
  29219. + break;
  29220. + }
  29221. + }
  29222. + if (i >= ARRAY_SIZE(scene_configs))
  29223. + return -EINVAL;
  29224. +
  29225. + /* Set all the values */
  29226. + dev->scene_mode = ctrl->val;
  29227. +
  29228. + if (scene->exposure_mode == MMAL_PARAM_EXPOSUREMODE_OFF)
  29229. + shutter_speed = dev->manual_shutter_speed;
  29230. + else
  29231. + shutter_speed = 0;
  29232. + exposure_mode = scene->exposure_mode;
  29233. + metering_mode = scene->metering_mode;
  29234. +
  29235. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  29236. + "%s: scene mode none: shut_speed %d, exp_mode %d, metering %d\n",
  29237. + __func__, shutter_speed, exposure_mode, metering_mode);
  29238. +
  29239. + ret = vchiq_mmal_port_parameter_set(dev->instance, control,
  29240. + MMAL_PARAMETER_SHUTTER_SPEED,
  29241. + &shutter_speed,
  29242. + sizeof(shutter_speed));
  29243. + ret += vchiq_mmal_port_parameter_set(dev->instance,
  29244. + control,
  29245. + MMAL_PARAMETER_EXPOSURE_MODE,
  29246. + &exposure_mode,
  29247. + sizeof(u32));
  29248. + dev->exposure_mode_active = exposure_mode;
  29249. + ret += vchiq_mmal_port_parameter_set(dev->instance, control,
  29250. + MMAL_PARAMETER_EXPOSURE_MODE,
  29251. + &exposure_mode,
  29252. + sizeof(u32));
  29253. + ret += vchiq_mmal_port_parameter_set(dev->instance, control,
  29254. + MMAL_PARAMETER_EXP_METERING_MODE,
  29255. + &metering_mode,
  29256. + sizeof(u32));
  29257. + ret += set_framerate_params(dev);
  29258. + }
  29259. + if (ret) {
  29260. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  29261. + "%s: Setting scene to %d, ret=%d\n",
  29262. + __func__, ctrl->val, ret);
  29263. + ret = -EINVAL;
  29264. + }
  29265. + return 0;
  29266. +}
  29267. +
  29268. +static int bm2835_mmal_s_ctrl(struct v4l2_ctrl *ctrl)
  29269. +{
  29270. + struct bm2835_mmal_dev *dev =
  29271. + container_of(ctrl->handler, struct bm2835_mmal_dev,
  29272. + ctrl_handler);
  29273. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl = ctrl->priv;
  29274. + int ret;
  29275. +
  29276. + if ((mmal_ctrl == NULL) ||
  29277. + (mmal_ctrl->id != ctrl->id) ||
  29278. + (mmal_ctrl->setter == NULL)) {
  29279. + pr_warn("mmal_ctrl:%p ctrl id:%d\n", mmal_ctrl, ctrl->id);
  29280. + return -EINVAL;
  29281. + }
  29282. +
  29283. + ret = mmal_ctrl->setter(dev, ctrl, mmal_ctrl);
  29284. + if (ret)
  29285. + pr_warn("ctrl id:%d/MMAL param %08X- returned ret %d\n",
  29286. + ctrl->id, mmal_ctrl->mmal_id, ret);
  29287. + if (mmal_ctrl->ignore_errors)
  29288. + ret = 0;
  29289. + return ret;
  29290. +}
  29291. +
  29292. +static const struct v4l2_ctrl_ops bm2835_mmal_ctrl_ops = {
  29293. + .s_ctrl = bm2835_mmal_s_ctrl,
  29294. +};
  29295. +
  29296. +
  29297. +
  29298. +static const struct bm2835_mmal_v4l2_ctrl v4l2_ctrls[V4L2_CTRL_COUNT] = {
  29299. + {
  29300. + V4L2_CID_SATURATION, MMAL_CONTROL_TYPE_STD,
  29301. + -100, 100, 0, 1, NULL,
  29302. + MMAL_PARAMETER_SATURATION,
  29303. + &ctrl_set_rational,
  29304. + false
  29305. + },
  29306. + {
  29307. + V4L2_CID_SHARPNESS, MMAL_CONTROL_TYPE_STD,
  29308. + -100, 100, 0, 1, NULL,
  29309. + MMAL_PARAMETER_SHARPNESS,
  29310. + &ctrl_set_rational,
  29311. + false
  29312. + },
  29313. + {
  29314. + V4L2_CID_CONTRAST, MMAL_CONTROL_TYPE_STD,
  29315. + -100, 100, 0, 1, NULL,
  29316. + MMAL_PARAMETER_CONTRAST,
  29317. + &ctrl_set_rational,
  29318. + false
  29319. + },
  29320. + {
  29321. + V4L2_CID_BRIGHTNESS, MMAL_CONTROL_TYPE_STD,
  29322. + 0, 100, 50, 1, NULL,
  29323. + MMAL_PARAMETER_BRIGHTNESS,
  29324. + &ctrl_set_rational,
  29325. + false
  29326. + },
  29327. + {
  29328. + V4L2_CID_ISO_SENSITIVITY, MMAL_CONTROL_TYPE_INT_MENU,
  29329. + 0, ARRAY_SIZE(iso_qmenu) - 1, 0, 1, iso_qmenu,
  29330. + MMAL_PARAMETER_ISO,
  29331. + &ctrl_set_value_menu,
  29332. + false
  29333. + },
  29334. + {
  29335. + V4L2_CID_IMAGE_STABILIZATION, MMAL_CONTROL_TYPE_STD,
  29336. + 0, 1, 0, 1, NULL,
  29337. + MMAL_PARAMETER_VIDEO_STABILISATION,
  29338. + &ctrl_set_value,
  29339. + false
  29340. + },
  29341. +/* {
  29342. + 0, MMAL_CONTROL_TYPE_CLUSTER, 3, 1, 0, NULL, 0, NULL
  29343. + }, */
  29344. + {
  29345. + V4L2_CID_EXPOSURE_AUTO, MMAL_CONTROL_TYPE_STD_MENU,
  29346. + ~0x03, 3, V4L2_EXPOSURE_AUTO, 0, NULL,
  29347. + MMAL_PARAMETER_EXPOSURE_MODE,
  29348. + &ctrl_set_exposure,
  29349. + false
  29350. + },
  29351. +/* todo this needs mixing in with set exposure
  29352. + {
  29353. + V4L2_CID_SCENE_MODE, MMAL_CONTROL_TYPE_STD_MENU,
  29354. + },
  29355. + */
  29356. + {
  29357. + V4L2_CID_EXPOSURE_ABSOLUTE, MMAL_CONTROL_TYPE_STD,
  29358. + /* Units of 100usecs */
  29359. + 1, 1*1000*10, 100*10, 1, NULL,
  29360. + MMAL_PARAMETER_SHUTTER_SPEED,
  29361. + &ctrl_set_exposure,
  29362. + false
  29363. + },
  29364. + {
  29365. + V4L2_CID_AUTO_EXPOSURE_BIAS, MMAL_CONTROL_TYPE_INT_MENU,
  29366. + 0, ARRAY_SIZE(ev_bias_qmenu) - 1,
  29367. + (ARRAY_SIZE(ev_bias_qmenu)+1)/2 - 1, 0, ev_bias_qmenu,
  29368. + MMAL_PARAMETER_EXPOSURE_COMP,
  29369. + &ctrl_set_value_ev,
  29370. + false
  29371. + },
  29372. + {
  29373. + V4L2_CID_EXPOSURE_AUTO_PRIORITY, MMAL_CONTROL_TYPE_STD,
  29374. + 0, 1,
  29375. + 0, 1, NULL,
  29376. + 0, /* Dummy MMAL ID as it gets mapped into FPS range*/
  29377. + &ctrl_set_exposure,
  29378. + false
  29379. + },
  29380. + {
  29381. + V4L2_CID_EXPOSURE_METERING,
  29382. + MMAL_CONTROL_TYPE_STD_MENU,
  29383. + ~0x7, 2, V4L2_EXPOSURE_METERING_AVERAGE, 0, NULL,
  29384. + MMAL_PARAMETER_EXP_METERING_MODE,
  29385. + &ctrl_set_metering_mode,
  29386. + false
  29387. + },
  29388. + {
  29389. + V4L2_CID_AUTO_N_PRESET_WHITE_BALANCE,
  29390. + MMAL_CONTROL_TYPE_STD_MENU,
  29391. + ~0x3ff, 9, V4L2_WHITE_BALANCE_AUTO, 0, NULL,
  29392. + MMAL_PARAMETER_AWB_MODE,
  29393. + &ctrl_set_awb_mode,
  29394. + false
  29395. + },
  29396. + {
  29397. + V4L2_CID_RED_BALANCE, MMAL_CONTROL_TYPE_STD,
  29398. + 1, 7999, 1000, 1, NULL,
  29399. + MMAL_PARAMETER_CUSTOM_AWB_GAINS,
  29400. + &ctrl_set_awb_gains,
  29401. + false
  29402. + },
  29403. + {
  29404. + V4L2_CID_BLUE_BALANCE, MMAL_CONTROL_TYPE_STD,
  29405. + 1, 7999, 1000, 1, NULL,
  29406. + MMAL_PARAMETER_CUSTOM_AWB_GAINS,
  29407. + &ctrl_set_awb_gains,
  29408. + false
  29409. + },
  29410. + {
  29411. + V4L2_CID_COLORFX, MMAL_CONTROL_TYPE_STD_MENU,
  29412. + 0, 15, V4L2_COLORFX_NONE, 0, NULL,
  29413. + MMAL_PARAMETER_IMAGE_EFFECT,
  29414. + &ctrl_set_image_effect,
  29415. + false
  29416. + },
  29417. + {
  29418. + V4L2_CID_COLORFX_CBCR, MMAL_CONTROL_TYPE_STD,
  29419. + 0, 0xffff, 0x8080, 1, NULL,
  29420. + MMAL_PARAMETER_COLOUR_EFFECT,
  29421. + &ctrl_set_colfx,
  29422. + false
  29423. + },
  29424. + {
  29425. + V4L2_CID_ROTATE, MMAL_CONTROL_TYPE_STD,
  29426. + 0, 360, 0, 90, NULL,
  29427. + MMAL_PARAMETER_ROTATION,
  29428. + &ctrl_set_rotate,
  29429. + false
  29430. + },
  29431. + {
  29432. + V4L2_CID_HFLIP, MMAL_CONTROL_TYPE_STD,
  29433. + 0, 1, 0, 1, NULL,
  29434. + MMAL_PARAMETER_MIRROR,
  29435. + &ctrl_set_flip,
  29436. + false
  29437. + },
  29438. + {
  29439. + V4L2_CID_VFLIP, MMAL_CONTROL_TYPE_STD,
  29440. + 0, 1, 0, 1, NULL,
  29441. + MMAL_PARAMETER_MIRROR,
  29442. + &ctrl_set_flip,
  29443. + false
  29444. + },
  29445. + {
  29446. + V4L2_CID_MPEG_VIDEO_BITRATE_MODE, MMAL_CONTROL_TYPE_STD_MENU,
  29447. + 0, ARRAY_SIZE(bitrate_mode_qmenu) - 1,
  29448. + 0, 0, bitrate_mode_qmenu,
  29449. + MMAL_PARAMETER_RATECONTROL,
  29450. + &ctrl_set_bitrate_mode,
  29451. + false
  29452. + },
  29453. + {
  29454. + V4L2_CID_MPEG_VIDEO_BITRATE, MMAL_CONTROL_TYPE_STD,
  29455. + 25*1000, 25*1000*1000, 10*1000*1000, 25*1000, NULL,
  29456. + MMAL_PARAMETER_VIDEO_BIT_RATE,
  29457. + &ctrl_set_bitrate,
  29458. + false
  29459. + },
  29460. + {
  29461. + V4L2_CID_JPEG_COMPRESSION_QUALITY, MMAL_CONTROL_TYPE_STD,
  29462. + 1, 100,
  29463. + 30, 1, NULL,
  29464. + MMAL_PARAMETER_JPEG_Q_FACTOR,
  29465. + &ctrl_set_image_encode_output,
  29466. + false
  29467. + },
  29468. + {
  29469. + V4L2_CID_POWER_LINE_FREQUENCY, MMAL_CONTROL_TYPE_STD_MENU,
  29470. + 0, ARRAY_SIZE(mains_freq_qmenu) - 1,
  29471. + 1, 1, NULL,
  29472. + MMAL_PARAMETER_FLICKER_AVOID,
  29473. + &ctrl_set_flicker_avoidance,
  29474. + false
  29475. + },
  29476. + {
  29477. + V4L2_CID_MPEG_VIDEO_REPEAT_SEQ_HEADER, MMAL_CONTROL_TYPE_STD,
  29478. + 0, 1,
  29479. + 0, 1, NULL,
  29480. + MMAL_PARAMETER_VIDEO_ENCODE_INLINE_HEADER,
  29481. + &ctrl_set_video_encode_param_output,
  29482. + true /* Errors ignored as requires latest firmware to work */
  29483. + },
  29484. + {
  29485. + V4L2_CID_MPEG_VIDEO_H264_PROFILE,
  29486. + MMAL_CONTROL_TYPE_STD_MENU,
  29487. + ~((1<<V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE) |
  29488. + (1<<V4L2_MPEG_VIDEO_H264_PROFILE_CONSTRAINED_BASELINE) |
  29489. + (1<<V4L2_MPEG_VIDEO_H264_PROFILE_MAIN) |
  29490. + (1<<V4L2_MPEG_VIDEO_H264_PROFILE_HIGH)),
  29491. + V4L2_MPEG_VIDEO_H264_PROFILE_HIGH,
  29492. + V4L2_MPEG_VIDEO_H264_PROFILE_HIGH, 1, NULL,
  29493. + MMAL_PARAMETER_PROFILE,
  29494. + &ctrl_set_video_encode_profile_level,
  29495. + false
  29496. + },
  29497. + {
  29498. + V4L2_CID_MPEG_VIDEO_H264_LEVEL, MMAL_CONTROL_TYPE_STD_MENU,
  29499. + ~((1<<V4L2_MPEG_VIDEO_H264_LEVEL_1_0) |
  29500. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_1B) |
  29501. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_1_1) |
  29502. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_1_2) |
  29503. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_1_3) |
  29504. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_2_0) |
  29505. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_2_1) |
  29506. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_2_2) |
  29507. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_3_0) |
  29508. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_3_1) |
  29509. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_3_2) |
  29510. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_4_0)),
  29511. + V4L2_MPEG_VIDEO_H264_LEVEL_4_0,
  29512. + V4L2_MPEG_VIDEO_H264_LEVEL_4_0, 1, NULL,
  29513. + MMAL_PARAMETER_PROFILE,
  29514. + &ctrl_set_video_encode_profile_level,
  29515. + false
  29516. + },
  29517. + {
  29518. + V4L2_CID_SCENE_MODE, MMAL_CONTROL_TYPE_STD_MENU,
  29519. + -1, /* Min is computed at runtime */
  29520. + V4L2_SCENE_MODE_TEXT,
  29521. + V4L2_SCENE_MODE_NONE, 1, NULL,
  29522. + MMAL_PARAMETER_PROFILE,
  29523. + &ctrl_set_scene_mode,
  29524. + false
  29525. + },
  29526. + {
  29527. + V4L2_CID_MPEG_VIDEO_H264_I_PERIOD, MMAL_CONTROL_TYPE_STD,
  29528. + 0, 0x7FFFFFFF, 60, 1, NULL,
  29529. + MMAL_PARAMETER_INTRAPERIOD,
  29530. + &ctrl_set_video_encode_param_output,
  29531. + false
  29532. + },
  29533. +};
  29534. +
  29535. +int bm2835_mmal_set_all_camera_controls(struct bm2835_mmal_dev *dev)
  29536. +{
  29537. + int c;
  29538. + int ret = 0;
  29539. +
  29540. + for (c = 0; c < V4L2_CTRL_COUNT; c++) {
  29541. + if ((dev->ctrls[c]) && (v4l2_ctrls[c].setter)) {
  29542. + ret = v4l2_ctrls[c].setter(dev, dev->ctrls[c],
  29543. + &v4l2_ctrls[c]);
  29544. + if (!v4l2_ctrls[c].ignore_errors && ret) {
  29545. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  29546. + "Failed when setting default values for ctrl %d\n",
  29547. + c);
  29548. + break;
  29549. + }
  29550. + }
  29551. + }
  29552. + return ret;
  29553. +}
  29554. +
  29555. +int set_framerate_params(struct bm2835_mmal_dev *dev)
  29556. +{
  29557. + struct mmal_parameter_fps_range fps_range;
  29558. + int ret;
  29559. +
  29560. + if ((dev->exposure_mode_active != MMAL_PARAM_EXPOSUREMODE_OFF) &&
  29561. + (dev->exp_auto_priority)) {
  29562. + /* Variable FPS. Define min FPS as 1fps.
  29563. + * Max as max defined FPS.
  29564. + */
  29565. + fps_range.fps_low.num = 1;
  29566. + fps_range.fps_low.den = 1;
  29567. + fps_range.fps_high.num = dev->capture.timeperframe.denominator;
  29568. + fps_range.fps_high.den = dev->capture.timeperframe.numerator;
  29569. + } else {
  29570. + /* Fixed FPS - set min and max to be the same */
  29571. + fps_range.fps_low.num = fps_range.fps_high.num =
  29572. + dev->capture.timeperframe.denominator;
  29573. + fps_range.fps_low.den = fps_range.fps_high.den =
  29574. + dev->capture.timeperframe.numerator;
  29575. + }
  29576. +
  29577. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  29578. + "Set fps range to %d/%d to %d/%d\n",
  29579. + fps_range.fps_low.num,
  29580. + fps_range.fps_low.den,
  29581. + fps_range.fps_high.num,
  29582. + fps_range.fps_high.den
  29583. + );
  29584. +
  29585. + ret = vchiq_mmal_port_parameter_set(dev->instance,
  29586. + &dev->component[MMAL_COMPONENT_CAMERA]->
  29587. + output[MMAL_CAMERA_PORT_PREVIEW],
  29588. + MMAL_PARAMETER_FPS_RANGE,
  29589. + &fps_range, sizeof(fps_range));
  29590. + ret += vchiq_mmal_port_parameter_set(dev->instance,
  29591. + &dev->component[MMAL_COMPONENT_CAMERA]->
  29592. + output[MMAL_CAMERA_PORT_VIDEO],
  29593. + MMAL_PARAMETER_FPS_RANGE,
  29594. + &fps_range, sizeof(fps_range));
  29595. + ret += vchiq_mmal_port_parameter_set(dev->instance,
  29596. + &dev->component[MMAL_COMPONENT_CAMERA]->
  29597. + output[MMAL_CAMERA_PORT_CAPTURE],
  29598. + MMAL_PARAMETER_FPS_RANGE,
  29599. + &fps_range, sizeof(fps_range));
  29600. + if (ret)
  29601. + v4l2_dbg(0, bcm2835_v4l2_debug, &dev->v4l2_dev,
  29602. + "Failed to set fps ret %d\n",
  29603. + ret);
  29604. +
  29605. + return ret;
  29606. +
  29607. +}
  29608. +
  29609. +int bm2835_mmal_init_controls(struct bm2835_mmal_dev *dev,
  29610. + struct v4l2_ctrl_handler *hdl)
  29611. +{
  29612. + int c;
  29613. + const struct bm2835_mmal_v4l2_ctrl *ctrl;
  29614. +
  29615. + v4l2_ctrl_handler_init(hdl, V4L2_CTRL_COUNT);
  29616. +
  29617. + for (c = 0; c < V4L2_CTRL_COUNT; c++) {
  29618. + ctrl = &v4l2_ctrls[c];
  29619. +
  29620. + switch (ctrl->type) {
  29621. + case MMAL_CONTROL_TYPE_STD:
  29622. + dev->ctrls[c] = v4l2_ctrl_new_std(hdl,
  29623. + &bm2835_mmal_ctrl_ops, ctrl->id,
  29624. + ctrl->min, ctrl->max, ctrl->step, ctrl->def);
  29625. + break;
  29626. +
  29627. + case MMAL_CONTROL_TYPE_STD_MENU:
  29628. + {
  29629. + int mask = ctrl->min;
  29630. +
  29631. + if (ctrl->id == V4L2_CID_SCENE_MODE) {
  29632. + /* Special handling to work out the mask
  29633. + * value based on the scene_configs array
  29634. + * at runtime. Reduces the chance of
  29635. + * mismatches.
  29636. + */
  29637. + int i;
  29638. + mask = 1<<V4L2_SCENE_MODE_NONE;
  29639. + for (i = 0;
  29640. + i < ARRAY_SIZE(scene_configs);
  29641. + i++) {
  29642. + mask |= 1<<scene_configs[i].v4l2_scene;
  29643. + }
  29644. + mask = ~mask;
  29645. + }
  29646. +
  29647. + dev->ctrls[c] = v4l2_ctrl_new_std_menu(hdl,
  29648. + &bm2835_mmal_ctrl_ops, ctrl->id,
  29649. + ctrl->max, mask, ctrl->def);
  29650. + break;
  29651. + }
  29652. +
  29653. + case MMAL_CONTROL_TYPE_INT_MENU:
  29654. + dev->ctrls[c] = v4l2_ctrl_new_int_menu(hdl,
  29655. + &bm2835_mmal_ctrl_ops, ctrl->id,
  29656. + ctrl->max, ctrl->def, ctrl->imenu);
  29657. + break;
  29658. +
  29659. + case MMAL_CONTROL_TYPE_CLUSTER:
  29660. + /* skip this entry when constructing controls */
  29661. + continue;
  29662. + }
  29663. +
  29664. + if (hdl->error)
  29665. + break;
  29666. +
  29667. + dev->ctrls[c]->priv = (void *)ctrl;
  29668. + }
  29669. +
  29670. + if (hdl->error) {
  29671. + pr_err("error adding control %d/%d id 0x%x\n", c,
  29672. + V4L2_CTRL_COUNT, ctrl->id);
  29673. + return hdl->error;
  29674. + }
  29675. +
  29676. + for (c = 0; c < V4L2_CTRL_COUNT; c++) {
  29677. + ctrl = &v4l2_ctrls[c];
  29678. +
  29679. + switch (ctrl->type) {
  29680. + case MMAL_CONTROL_TYPE_CLUSTER:
  29681. + v4l2_ctrl_auto_cluster(ctrl->min,
  29682. + &dev->ctrls[c+1],
  29683. + ctrl->max,
  29684. + ctrl->def);
  29685. + break;
  29686. +
  29687. + case MMAL_CONTROL_TYPE_STD:
  29688. + case MMAL_CONTROL_TYPE_STD_MENU:
  29689. + case MMAL_CONTROL_TYPE_INT_MENU:
  29690. + break;
  29691. + }
  29692. +
  29693. + }
  29694. +
  29695. + return 0;
  29696. +}
  29697. diff -Nur linux-3.18.8/drivers/media/platform/bcm2835/Kconfig linux-rpi/drivers/media/platform/bcm2835/Kconfig
  29698. --- linux-3.18.8/drivers/media/platform/bcm2835/Kconfig 1970-01-01 01:00:00.000000000 +0100
  29699. +++ linux-rpi/drivers/media/platform/bcm2835/Kconfig 2015-03-05 14:40:13.981715822 +0100
  29700. @@ -0,0 +1,25 @@
  29701. +# Broadcom VideoCore IV v4l2 camera support
  29702. +
  29703. +config VIDEO_BCM2835
  29704. + bool "Broadcom BCM2835 camera interface driver"
  29705. + depends on VIDEO_V4L2 && (ARCH_BCM2708 || ARCH_BCM2709)
  29706. + ---help---
  29707. + Say Y here to enable camera host interface devices for
  29708. + Broadcom BCM2835 SoC. This operates over the VCHIQ interface
  29709. + to a service running on VideoCore.
  29710. +
  29711. +
  29712. +if VIDEO_BCM2835
  29713. +
  29714. +config VIDEO_BCM2835_MMAL
  29715. + tristate "Broadcom BM2835 MMAL camera interface driver"
  29716. + depends on BCM2708_VCHIQ
  29717. + select VIDEOBUF2_VMALLOC
  29718. + ---help---
  29719. + This is a V4L2 driver for the Broadcom BCM2835 MMAL camera host interface
  29720. +
  29721. + To compile this driver as a module, choose M here: the
  29722. + module will be called bcm2835-v4l2.o
  29723. +
  29724. +
  29725. +endif # VIDEO_BM2835
  29726. diff -Nur linux-3.18.8/drivers/media/platform/bcm2835/Makefile linux-rpi/drivers/media/platform/bcm2835/Makefile
  29727. --- linux-3.18.8/drivers/media/platform/bcm2835/Makefile 1970-01-01 01:00:00.000000000 +0100
  29728. +++ linux-rpi/drivers/media/platform/bcm2835/Makefile 2015-03-05 14:40:13.981715822 +0100
  29729. @@ -0,0 +1,5 @@
  29730. +bcm2835-v4l2-objs := bcm2835-camera.o controls.o mmal-vchiq.o
  29731. +
  29732. +obj-$(CONFIG_VIDEO_BCM2835_MMAL) += bcm2835-v4l2.o
  29733. +
  29734. +ccflags-$(CONFIG_VIDEO_BCM2835) += -Idrivers/misc/vc04_services -Idrivers/misc/vc04_services/interface/vcos/linuxkernel -D__VCCOREVER__=0x04000000
  29735. diff -Nur linux-3.18.8/drivers/media/platform/bcm2835/mmal-common.h linux-rpi/drivers/media/platform/bcm2835/mmal-common.h
  29736. --- linux-3.18.8/drivers/media/platform/bcm2835/mmal-common.h 1970-01-01 01:00:00.000000000 +0100
  29737. +++ linux-rpi/drivers/media/platform/bcm2835/mmal-common.h 2015-03-05 14:40:13.981715822 +0100
  29738. @@ -0,0 +1,53 @@
  29739. +/*
  29740. + * Broadcom BM2835 V4L2 driver
  29741. + *
  29742. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  29743. + *
  29744. + * This file is subject to the terms and conditions of the GNU General Public
  29745. + * License. See the file COPYING in the main directory of this archive
  29746. + * for more details.
  29747. + *
  29748. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  29749. + * Dave Stevenson <dsteve@broadcom.com>
  29750. + * Simon Mellor <simellor@broadcom.com>
  29751. + * Luke Diamand <luked@broadcom.com>
  29752. + *
  29753. + * MMAL structures
  29754. + *
  29755. + */
  29756. +
  29757. +#define MMAL_FOURCC(a, b, c, d) ((a) | (b << 8) | (c << 16) | (d << 24))
  29758. +#define MMAL_MAGIC MMAL_FOURCC('m', 'm', 'a', 'l')
  29759. +
  29760. +/** Special value signalling that time is not known */
  29761. +#define MMAL_TIME_UNKNOWN (1LL<<63)
  29762. +
  29763. +/* mapping between v4l and mmal video modes */
  29764. +struct mmal_fmt {
  29765. + char *name;
  29766. + u32 fourcc; /* v4l2 format id */
  29767. + int flags; /* v4l2 flags field */
  29768. + u32 mmal;
  29769. + int depth;
  29770. + u32 mmal_component; /* MMAL component index to be used to encode */
  29771. +};
  29772. +
  29773. +/* buffer for one video frame */
  29774. +struct mmal_buffer {
  29775. + /* v4l buffer data -- must be first */
  29776. + struct vb2_buffer vb;
  29777. +
  29778. + /* list of buffers available */
  29779. + struct list_head list;
  29780. +
  29781. + void *buffer; /* buffer pointer */
  29782. + unsigned long buffer_size; /* size of allocated buffer */
  29783. +};
  29784. +
  29785. +/* */
  29786. +struct mmal_colourfx {
  29787. + s32 enable;
  29788. + u32 u;
  29789. + u32 v;
  29790. +};
  29791. +
  29792. diff -Nur linux-3.18.8/drivers/media/platform/bcm2835/mmal-encodings.h linux-rpi/drivers/media/platform/bcm2835/mmal-encodings.h
  29793. --- linux-3.18.8/drivers/media/platform/bcm2835/mmal-encodings.h 1970-01-01 01:00:00.000000000 +0100
  29794. +++ linux-rpi/drivers/media/platform/bcm2835/mmal-encodings.h 2015-03-05 14:40:13.981715822 +0100
  29795. @@ -0,0 +1,127 @@
  29796. +/*
  29797. + * Broadcom BM2835 V4L2 driver
  29798. + *
  29799. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  29800. + *
  29801. + * This file is subject to the terms and conditions of the GNU General Public
  29802. + * License. See the file COPYING in the main directory of this archive
  29803. + * for more details.
  29804. + *
  29805. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  29806. + * Dave Stevenson <dsteve@broadcom.com>
  29807. + * Simon Mellor <simellor@broadcom.com>
  29808. + * Luke Diamand <luked@broadcom.com>
  29809. + */
  29810. +#ifndef MMAL_ENCODINGS_H
  29811. +#define MMAL_ENCODINGS_H
  29812. +
  29813. +#define MMAL_ENCODING_H264 MMAL_FOURCC('H', '2', '6', '4')
  29814. +#define MMAL_ENCODING_H263 MMAL_FOURCC('H', '2', '6', '3')
  29815. +#define MMAL_ENCODING_MP4V MMAL_FOURCC('M', 'P', '4', 'V')
  29816. +#define MMAL_ENCODING_MP2V MMAL_FOURCC('M', 'P', '2', 'V')
  29817. +#define MMAL_ENCODING_MP1V MMAL_FOURCC('M', 'P', '1', 'V')
  29818. +#define MMAL_ENCODING_WMV3 MMAL_FOURCC('W', 'M', 'V', '3')
  29819. +#define MMAL_ENCODING_WMV2 MMAL_FOURCC('W', 'M', 'V', '2')
  29820. +#define MMAL_ENCODING_WMV1 MMAL_FOURCC('W', 'M', 'V', '1')
  29821. +#define MMAL_ENCODING_WVC1 MMAL_FOURCC('W', 'V', 'C', '1')
  29822. +#define MMAL_ENCODING_VP8 MMAL_FOURCC('V', 'P', '8', ' ')
  29823. +#define MMAL_ENCODING_VP7 MMAL_FOURCC('V', 'P', '7', ' ')
  29824. +#define MMAL_ENCODING_VP6 MMAL_FOURCC('V', 'P', '6', ' ')
  29825. +#define MMAL_ENCODING_THEORA MMAL_FOURCC('T', 'H', 'E', 'O')
  29826. +#define MMAL_ENCODING_SPARK MMAL_FOURCC('S', 'P', 'R', 'K')
  29827. +#define MMAL_ENCODING_MJPEG MMAL_FOURCC('M', 'J', 'P', 'G')
  29828. +
  29829. +#define MMAL_ENCODING_JPEG MMAL_FOURCC('J', 'P', 'E', 'G')
  29830. +#define MMAL_ENCODING_GIF MMAL_FOURCC('G', 'I', 'F', ' ')
  29831. +#define MMAL_ENCODING_PNG MMAL_FOURCC('P', 'N', 'G', ' ')
  29832. +#define MMAL_ENCODING_PPM MMAL_FOURCC('P', 'P', 'M', ' ')
  29833. +#define MMAL_ENCODING_TGA MMAL_FOURCC('T', 'G', 'A', ' ')
  29834. +#define MMAL_ENCODING_BMP MMAL_FOURCC('B', 'M', 'P', ' ')
  29835. +
  29836. +#define MMAL_ENCODING_I420 MMAL_FOURCC('I', '4', '2', '0')
  29837. +#define MMAL_ENCODING_I420_SLICE MMAL_FOURCC('S', '4', '2', '0')
  29838. +#define MMAL_ENCODING_YV12 MMAL_FOURCC('Y', 'V', '1', '2')
  29839. +#define MMAL_ENCODING_I422 MMAL_FOURCC('I', '4', '2', '2')
  29840. +#define MMAL_ENCODING_I422_SLICE MMAL_FOURCC('S', '4', '2', '2')
  29841. +#define MMAL_ENCODING_YUYV MMAL_FOURCC('Y', 'U', 'Y', 'V')
  29842. +#define MMAL_ENCODING_YVYU MMAL_FOURCC('Y', 'V', 'Y', 'U')
  29843. +#define MMAL_ENCODING_UYVY MMAL_FOURCC('U', 'Y', 'V', 'Y')
  29844. +#define MMAL_ENCODING_VYUY MMAL_FOURCC('V', 'Y', 'U', 'Y')
  29845. +#define MMAL_ENCODING_NV12 MMAL_FOURCC('N', 'V', '1', '2')
  29846. +#define MMAL_ENCODING_NV21 MMAL_FOURCC('N', 'V', '2', '1')
  29847. +#define MMAL_ENCODING_ARGB MMAL_FOURCC('A', 'R', 'G', 'B')
  29848. +#define MMAL_ENCODING_RGBA MMAL_FOURCC('R', 'G', 'B', 'A')
  29849. +#define MMAL_ENCODING_ABGR MMAL_FOURCC('A', 'B', 'G', 'R')
  29850. +#define MMAL_ENCODING_BGRA MMAL_FOURCC('B', 'G', 'R', 'A')
  29851. +#define MMAL_ENCODING_RGB16 MMAL_FOURCC('R', 'G', 'B', '2')
  29852. +#define MMAL_ENCODING_RGB24 MMAL_FOURCC('R', 'G', 'B', '3')
  29853. +#define MMAL_ENCODING_RGB32 MMAL_FOURCC('R', 'G', 'B', '4')
  29854. +#define MMAL_ENCODING_BGR16 MMAL_FOURCC('B', 'G', 'R', '2')
  29855. +#define MMAL_ENCODING_BGR24 MMAL_FOURCC('B', 'G', 'R', '3')
  29856. +#define MMAL_ENCODING_BGR32 MMAL_FOURCC('B', 'G', 'R', '4')
  29857. +
  29858. +/** SAND Video (YUVUV128) format, native format understood by VideoCore.
  29859. + * This format is *not* opaque - if requested you will receive full frames
  29860. + * of YUV_UV video.
  29861. + */
  29862. +#define MMAL_ENCODING_YUVUV128 MMAL_FOURCC('S', 'A', 'N', 'D')
  29863. +
  29864. +/** VideoCore opaque image format, image handles are returned to
  29865. + * the host but not the actual image data.
  29866. + */
  29867. +#define MMAL_ENCODING_OPAQUE MMAL_FOURCC('O', 'P', 'Q', 'V')
  29868. +
  29869. +/** An EGL image handle
  29870. + */
  29871. +#define MMAL_ENCODING_EGL_IMAGE MMAL_FOURCC('E', 'G', 'L', 'I')
  29872. +
  29873. +/* }@ */
  29874. +
  29875. +/** \name Pre-defined audio encodings */
  29876. +/* @{ */
  29877. +#define MMAL_ENCODING_PCM_UNSIGNED_BE MMAL_FOURCC('P', 'C', 'M', 'U')
  29878. +#define MMAL_ENCODING_PCM_UNSIGNED_LE MMAL_FOURCC('p', 'c', 'm', 'u')
  29879. +#define MMAL_ENCODING_PCM_SIGNED_BE MMAL_FOURCC('P', 'C', 'M', 'S')
  29880. +#define MMAL_ENCODING_PCM_SIGNED_LE MMAL_FOURCC('p', 'c', 'm', 's')
  29881. +#define MMAL_ENCODING_PCM_FLOAT_BE MMAL_FOURCC('P', 'C', 'M', 'F')
  29882. +#define MMAL_ENCODING_PCM_FLOAT_LE MMAL_FOURCC('p', 'c', 'm', 'f')
  29883. +
  29884. +/* Pre-defined H264 encoding variants */
  29885. +
  29886. +/** ISO 14496-10 Annex B byte stream format */
  29887. +#define MMAL_ENCODING_VARIANT_H264_DEFAULT 0
  29888. +/** ISO 14496-15 AVC stream format */
  29889. +#define MMAL_ENCODING_VARIANT_H264_AVC1 MMAL_FOURCC('A', 'V', 'C', '1')
  29890. +/** Implicitly delineated NAL units without emulation prevention */
  29891. +#define MMAL_ENCODING_VARIANT_H264_RAW MMAL_FOURCC('R', 'A', 'W', ' ')
  29892. +
  29893. +
  29894. +/** \defgroup MmalColorSpace List of pre-defined video color spaces
  29895. + * This defines a list of common color spaces. This list isn't exhaustive and
  29896. + * is only provided as a convenience to avoid clients having to use FourCC
  29897. + * codes directly. However components are allowed to define and use their own
  29898. + * FourCC codes.
  29899. + */
  29900. +/* @{ */
  29901. +
  29902. +/** Unknown color space */
  29903. +#define MMAL_COLOR_SPACE_UNKNOWN 0
  29904. +/** ITU-R BT.601-5 [SDTV] */
  29905. +#define MMAL_COLOR_SPACE_ITUR_BT601 MMAL_FOURCC('Y', '6', '0', '1')
  29906. +/** ITU-R BT.709-3 [HDTV] */
  29907. +#define MMAL_COLOR_SPACE_ITUR_BT709 MMAL_FOURCC('Y', '7', '0', '9')
  29908. +/** JPEG JFIF */
  29909. +#define MMAL_COLOR_SPACE_JPEG_JFIF MMAL_FOURCC('Y', 'J', 'F', 'I')
  29910. +/** Title 47 Code of Federal Regulations (2003) 73.682 (a) (20) */
  29911. +#define MMAL_COLOR_SPACE_FCC MMAL_FOURCC('Y', 'F', 'C', 'C')
  29912. +/** Society of Motion Picture and Television Engineers 240M (1999) */
  29913. +#define MMAL_COLOR_SPACE_SMPTE240M MMAL_FOURCC('Y', '2', '4', '0')
  29914. +/** ITU-R BT.470-2 System M */
  29915. +#define MMAL_COLOR_SPACE_BT470_2_M MMAL_FOURCC('Y', '_', '_', 'M')
  29916. +/** ITU-R BT.470-2 System BG */
  29917. +#define MMAL_COLOR_SPACE_BT470_2_BG MMAL_FOURCC('Y', '_', 'B', 'G')
  29918. +/** JPEG JFIF, but with 16..255 luma */
  29919. +#define MMAL_COLOR_SPACE_JFIF_Y16_255 MMAL_FOURCC('Y', 'Y', '1', '6')
  29920. +/* @} MmalColorSpace List */
  29921. +
  29922. +#endif /* MMAL_ENCODINGS_H */
  29923. diff -Nur linux-3.18.8/drivers/media/platform/bcm2835/mmal-msg-common.h linux-rpi/drivers/media/platform/bcm2835/mmal-msg-common.h
  29924. --- linux-3.18.8/drivers/media/platform/bcm2835/mmal-msg-common.h 1970-01-01 01:00:00.000000000 +0100
  29925. +++ linux-rpi/drivers/media/platform/bcm2835/mmal-msg-common.h 2015-03-05 14:40:13.981715822 +0100
  29926. @@ -0,0 +1,50 @@
  29927. +/*
  29928. + * Broadcom BM2835 V4L2 driver
  29929. + *
  29930. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  29931. + *
  29932. + * This file is subject to the terms and conditions of the GNU General Public
  29933. + * License. See the file COPYING in the main directory of this archive
  29934. + * for more details.
  29935. + *
  29936. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  29937. + * Dave Stevenson <dsteve@broadcom.com>
  29938. + * Simon Mellor <simellor@broadcom.com>
  29939. + * Luke Diamand <luked@broadcom.com>
  29940. + */
  29941. +
  29942. +#ifndef MMAL_MSG_COMMON_H
  29943. +#define MMAL_MSG_COMMON_H
  29944. +
  29945. +enum mmal_msg_status {
  29946. + MMAL_MSG_STATUS_SUCCESS = 0, /**< Success */
  29947. + MMAL_MSG_STATUS_ENOMEM, /**< Out of memory */
  29948. + MMAL_MSG_STATUS_ENOSPC, /**< Out of resources other than memory */
  29949. + MMAL_MSG_STATUS_EINVAL, /**< Argument is invalid */
  29950. + MMAL_MSG_STATUS_ENOSYS, /**< Function not implemented */
  29951. + MMAL_MSG_STATUS_ENOENT, /**< No such file or directory */
  29952. + MMAL_MSG_STATUS_ENXIO, /**< No such device or address */
  29953. + MMAL_MSG_STATUS_EIO, /**< I/O error */
  29954. + MMAL_MSG_STATUS_ESPIPE, /**< Illegal seek */
  29955. + MMAL_MSG_STATUS_ECORRUPT, /**< Data is corrupt \attention */
  29956. + MMAL_MSG_STATUS_ENOTREADY, /**< Component is not ready */
  29957. + MMAL_MSG_STATUS_ECONFIG, /**< Component is not configured */
  29958. + MMAL_MSG_STATUS_EISCONN, /**< Port is already connected */
  29959. + MMAL_MSG_STATUS_ENOTCONN, /**< Port is disconnected */
  29960. + MMAL_MSG_STATUS_EAGAIN, /**< Resource temporarily unavailable. */
  29961. + MMAL_MSG_STATUS_EFAULT, /**< Bad address */
  29962. +};
  29963. +
  29964. +struct mmal_rect {
  29965. + s32 x; /**< x coordinate (from left) */
  29966. + s32 y; /**< y coordinate (from top) */
  29967. + s32 width; /**< width */
  29968. + s32 height; /**< height */
  29969. +};
  29970. +
  29971. +struct mmal_rational {
  29972. + s32 num; /**< Numerator */
  29973. + s32 den; /**< Denominator */
  29974. +};
  29975. +
  29976. +#endif /* MMAL_MSG_COMMON_H */
  29977. diff -Nur linux-3.18.8/drivers/media/platform/bcm2835/mmal-msg-format.h linux-rpi/drivers/media/platform/bcm2835/mmal-msg-format.h
  29978. --- linux-3.18.8/drivers/media/platform/bcm2835/mmal-msg-format.h 1970-01-01 01:00:00.000000000 +0100
  29979. +++ linux-rpi/drivers/media/platform/bcm2835/mmal-msg-format.h 2015-03-05 14:40:13.981715822 +0100
  29980. @@ -0,0 +1,81 @@
  29981. +/*
  29982. + * Broadcom BM2835 V4L2 driver
  29983. + *
  29984. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  29985. + *
  29986. + * This file is subject to the terms and conditions of the GNU General Public
  29987. + * License. See the file COPYING in the main directory of this archive
  29988. + * for more details.
  29989. + *
  29990. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  29991. + * Dave Stevenson <dsteve@broadcom.com>
  29992. + * Simon Mellor <simellor@broadcom.com>
  29993. + * Luke Diamand <luked@broadcom.com>
  29994. + */
  29995. +
  29996. +#ifndef MMAL_MSG_FORMAT_H
  29997. +#define MMAL_MSG_FORMAT_H
  29998. +
  29999. +#include "mmal-msg-common.h"
  30000. +
  30001. +/* MMAL_ES_FORMAT_T */
  30002. +
  30003. +
  30004. +struct mmal_audio_format {
  30005. + u32 channels; /**< Number of audio channels */
  30006. + u32 sample_rate; /**< Sample rate */
  30007. +
  30008. + u32 bits_per_sample; /**< Bits per sample */
  30009. + u32 block_align; /**< Size of a block of data */
  30010. +};
  30011. +
  30012. +struct mmal_video_format {
  30013. + u32 width; /**< Width of frame in pixels */
  30014. + u32 height; /**< Height of frame in rows of pixels */
  30015. + struct mmal_rect crop; /**< Visible region of the frame */
  30016. + struct mmal_rational frame_rate; /**< Frame rate */
  30017. + struct mmal_rational par; /**< Pixel aspect ratio */
  30018. +
  30019. + /* FourCC specifying the color space of the video stream. See the
  30020. + * \ref MmalColorSpace "pre-defined color spaces" for some examples.
  30021. + */
  30022. + u32 color_space;
  30023. +};
  30024. +
  30025. +struct mmal_subpicture_format {
  30026. + u32 x_offset;
  30027. + u32 y_offset;
  30028. +};
  30029. +
  30030. +union mmal_es_specific_format {
  30031. + struct mmal_audio_format audio;
  30032. + struct mmal_video_format video;
  30033. + struct mmal_subpicture_format subpicture;
  30034. +};
  30035. +
  30036. +/** Definition of an elementary stream format (MMAL_ES_FORMAT_T) */
  30037. +struct mmal_es_format {
  30038. + u32 type; /* enum mmal_es_type */
  30039. +
  30040. + u32 encoding; /* FourCC specifying encoding of the elementary stream.*/
  30041. + u32 encoding_variant; /* FourCC specifying the specific
  30042. + * encoding variant of the elementary
  30043. + * stream.
  30044. + */
  30045. +
  30046. + union mmal_es_specific_format *es; /* TODO: pointers in
  30047. + * message serialisation?!?
  30048. + */
  30049. + /* Type specific
  30050. + * information for the
  30051. + * elementary stream
  30052. + */
  30053. +
  30054. + u32 bitrate; /**< Bitrate in bits per second */
  30055. + u32 flags; /**< Flags describing properties of the elementary stream. */
  30056. +
  30057. + u32 extradata_size; /**< Size of the codec specific data */
  30058. + u8 *extradata; /**< Codec specific data */
  30059. +};
  30060. +
  30061. +#endif /* MMAL_MSG_FORMAT_H */
  30062. diff -Nur linux-3.18.8/drivers/media/platform/bcm2835/mmal-msg.h linux-rpi/drivers/media/platform/bcm2835/mmal-msg.h
  30063. --- linux-3.18.8/drivers/media/platform/bcm2835/mmal-msg.h 1970-01-01 01:00:00.000000000 +0100
  30064. +++ linux-rpi/drivers/media/platform/bcm2835/mmal-msg.h 2015-03-05 14:40:13.981715822 +0100
  30065. @@ -0,0 +1,404 @@
  30066. +/*
  30067. + * Broadcom BM2835 V4L2 driver
  30068. + *
  30069. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  30070. + *
  30071. + * This file is subject to the terms and conditions of the GNU General Public
  30072. + * License. See the file COPYING in the main directory of this archive
  30073. + * for more details.
  30074. + *
  30075. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  30076. + * Dave Stevenson <dsteve@broadcom.com>
  30077. + * Simon Mellor <simellor@broadcom.com>
  30078. + * Luke Diamand <luked@broadcom.com>
  30079. + */
  30080. +
  30081. +/* all the data structures which serialise the MMAL protocol. note
  30082. + * these are directly mapped onto the recived message data.
  30083. + *
  30084. + * BEWARE: They seem to *assume* pointers are u32 and that there is no
  30085. + * structure padding!
  30086. + *
  30087. + * NOTE: this implementation uses kernel types to ensure sizes. Rather
  30088. + * than assigning values to enums to force their size the
  30089. + * implementation uses fixed size types and not the enums (though the
  30090. + * comments have the actual enum type
  30091. + */
  30092. +
  30093. +#define VC_MMAL_VER 15
  30094. +#define VC_MMAL_MIN_VER 10
  30095. +#define VC_MMAL_SERVER_NAME MAKE_FOURCC("mmal")
  30096. +
  30097. +/* max total message size is 512 bytes */
  30098. +#define MMAL_MSG_MAX_SIZE 512
  30099. +/* with six 32bit header elements max payload is therefore 488 bytes */
  30100. +#define MMAL_MSG_MAX_PAYLOAD 488
  30101. +
  30102. +#include "mmal-msg-common.h"
  30103. +#include "mmal-msg-format.h"
  30104. +#include "mmal-msg-port.h"
  30105. +
  30106. +enum mmal_msg_type {
  30107. + MMAL_MSG_TYPE_QUIT = 1,
  30108. + MMAL_MSG_TYPE_SERVICE_CLOSED,
  30109. + MMAL_MSG_TYPE_GET_VERSION,
  30110. + MMAL_MSG_TYPE_COMPONENT_CREATE,
  30111. + MMAL_MSG_TYPE_COMPONENT_DESTROY, /* 5 */
  30112. + MMAL_MSG_TYPE_COMPONENT_ENABLE,
  30113. + MMAL_MSG_TYPE_COMPONENT_DISABLE,
  30114. + MMAL_MSG_TYPE_PORT_INFO_GET,
  30115. + MMAL_MSG_TYPE_PORT_INFO_SET,
  30116. + MMAL_MSG_TYPE_PORT_ACTION, /* 10 */
  30117. + MMAL_MSG_TYPE_BUFFER_FROM_HOST,
  30118. + MMAL_MSG_TYPE_BUFFER_TO_HOST,
  30119. + MMAL_MSG_TYPE_GET_STATS,
  30120. + MMAL_MSG_TYPE_PORT_PARAMETER_SET,
  30121. + MMAL_MSG_TYPE_PORT_PARAMETER_GET, /* 15 */
  30122. + MMAL_MSG_TYPE_EVENT_TO_HOST,
  30123. + MMAL_MSG_TYPE_GET_CORE_STATS_FOR_PORT,
  30124. + MMAL_MSG_TYPE_OPAQUE_ALLOCATOR,
  30125. + MMAL_MSG_TYPE_CONSUME_MEM,
  30126. + MMAL_MSG_TYPE_LMK, /* 20 */
  30127. + MMAL_MSG_TYPE_OPAQUE_ALLOCATOR_DESC,
  30128. + MMAL_MSG_TYPE_DRM_GET_LHS32,
  30129. + MMAL_MSG_TYPE_DRM_GET_TIME,
  30130. + MMAL_MSG_TYPE_BUFFER_FROM_HOST_ZEROLEN,
  30131. + MMAL_MSG_TYPE_PORT_FLUSH, /* 25 */
  30132. + MMAL_MSG_TYPE_HOST_LOG,
  30133. + MMAL_MSG_TYPE_MSG_LAST
  30134. +};
  30135. +
  30136. +/* port action request messages differ depending on the action type */
  30137. +enum mmal_msg_port_action_type {
  30138. + MMAL_MSG_PORT_ACTION_TYPE_UNKNOWN = 0, /* Unkown action */
  30139. + MMAL_MSG_PORT_ACTION_TYPE_ENABLE, /* Enable a port */
  30140. + MMAL_MSG_PORT_ACTION_TYPE_DISABLE, /* Disable a port */
  30141. + MMAL_MSG_PORT_ACTION_TYPE_FLUSH, /* Flush a port */
  30142. + MMAL_MSG_PORT_ACTION_TYPE_CONNECT, /* Connect ports */
  30143. + MMAL_MSG_PORT_ACTION_TYPE_DISCONNECT, /* Disconnect ports */
  30144. + MMAL_MSG_PORT_ACTION_TYPE_SET_REQUIREMENTS, /* Set buffer requirements*/
  30145. +};
  30146. +
  30147. +struct mmal_msg_header {
  30148. + u32 magic;
  30149. + u32 type; /** enum mmal_msg_type */
  30150. +
  30151. + /* Opaque handle to the control service */
  30152. + struct mmal_control_service *control_service;
  30153. +
  30154. + struct mmal_msg_context *context; /** a u32 per message context */
  30155. + u32 status; /** The status of the vchiq operation */
  30156. + u32 padding;
  30157. +};
  30158. +
  30159. +/* Send from VC to host to report version */
  30160. +struct mmal_msg_version {
  30161. + u32 flags;
  30162. + u32 major;
  30163. + u32 minor;
  30164. + u32 minimum;
  30165. +};
  30166. +
  30167. +/* request to VC to create component */
  30168. +struct mmal_msg_component_create {
  30169. + void *client_component; /* component context */
  30170. + char name[128];
  30171. + u32 pid; /* For debug */
  30172. +};
  30173. +
  30174. +/* reply from VC to component creation request */
  30175. +struct mmal_msg_component_create_reply {
  30176. + u32 status; /** enum mmal_msg_status - how does this differ to
  30177. + * the one in the header?
  30178. + */
  30179. + u32 component_handle; /* VideoCore handle for component */
  30180. + u32 input_num; /* Number of input ports */
  30181. + u32 output_num; /* Number of output ports */
  30182. + u32 clock_num; /* Number of clock ports */
  30183. +};
  30184. +
  30185. +/* request to VC to destroy a component */
  30186. +struct mmal_msg_component_destroy {
  30187. + u32 component_handle;
  30188. +};
  30189. +
  30190. +struct mmal_msg_component_destroy_reply {
  30191. + u32 status; /** The component destruction status */
  30192. +};
  30193. +
  30194. +
  30195. +/* request and reply to VC to enable a component */
  30196. +struct mmal_msg_component_enable {
  30197. + u32 component_handle;
  30198. +};
  30199. +
  30200. +struct mmal_msg_component_enable_reply {
  30201. + u32 status; /** The component enable status */
  30202. +};
  30203. +
  30204. +
  30205. +/* request and reply to VC to disable a component */
  30206. +struct mmal_msg_component_disable {
  30207. + u32 component_handle;
  30208. +};
  30209. +
  30210. +struct mmal_msg_component_disable_reply {
  30211. + u32 status; /** The component disable status */
  30212. +};
  30213. +
  30214. +/* request to VC to get port information */
  30215. +struct mmal_msg_port_info_get {
  30216. + u32 component_handle; /* component handle port is associated with */
  30217. + u32 port_type; /* enum mmal_msg_port_type */
  30218. + u32 index; /* port index to query */
  30219. +};
  30220. +
  30221. +/* reply from VC to get port info request */
  30222. +struct mmal_msg_port_info_get_reply {
  30223. + u32 status; /** enum mmal_msg_status */
  30224. + u32 component_handle; /* component handle port is associated with */
  30225. + u32 port_type; /* enum mmal_msg_port_type */
  30226. + u32 port_index; /* port indexed in query */
  30227. + s32 found; /* unused */
  30228. + u32 port_handle; /**< Handle to use for this port */
  30229. + struct mmal_port port;
  30230. + struct mmal_es_format format; /* elementry stream format */
  30231. + union mmal_es_specific_format es; /* es type specific data */
  30232. + u8 extradata[MMAL_FORMAT_EXTRADATA_MAX_SIZE]; /* es extra data */
  30233. +};
  30234. +
  30235. +/* request to VC to set port information */
  30236. +struct mmal_msg_port_info_set {
  30237. + u32 component_handle;
  30238. + u32 port_type; /* enum mmal_msg_port_type */
  30239. + u32 port_index; /* port indexed in query */
  30240. + struct mmal_port port;
  30241. + struct mmal_es_format format;
  30242. + union mmal_es_specific_format es;
  30243. + u8 extradata[MMAL_FORMAT_EXTRADATA_MAX_SIZE];
  30244. +};
  30245. +
  30246. +/* reply from VC to port info set request */
  30247. +struct mmal_msg_port_info_set_reply {
  30248. + u32 status;
  30249. + u32 component_handle; /* component handle port is associated with */
  30250. + u32 port_type; /* enum mmal_msg_port_type */
  30251. + u32 index; /* port indexed in query */
  30252. + s32 found; /* unused */
  30253. + u32 port_handle; /**< Handle to use for this port */
  30254. + struct mmal_port port;
  30255. + struct mmal_es_format format;
  30256. + union mmal_es_specific_format es;
  30257. + u8 extradata[MMAL_FORMAT_EXTRADATA_MAX_SIZE];
  30258. +};
  30259. +
  30260. +
  30261. +/* port action requests that take a mmal_port as a parameter */
  30262. +struct mmal_msg_port_action_port {
  30263. + u32 component_handle;
  30264. + u32 port_handle;
  30265. + u32 action; /* enum mmal_msg_port_action_type */
  30266. + struct mmal_port port;
  30267. +};
  30268. +
  30269. +/* port action requests that take handles as a parameter */
  30270. +struct mmal_msg_port_action_handle {
  30271. + u32 component_handle;
  30272. + u32 port_handle;
  30273. + u32 action; /* enum mmal_msg_port_action_type */
  30274. + u32 connect_component_handle;
  30275. + u32 connect_port_handle;
  30276. +};
  30277. +
  30278. +struct mmal_msg_port_action_reply {
  30279. + u32 status; /** The port action operation status */
  30280. +};
  30281. +
  30282. +
  30283. +
  30284. +
  30285. +/* MMAL buffer transfer */
  30286. +
  30287. +/** Size of space reserved in a buffer message for short messages. */
  30288. +#define MMAL_VC_SHORT_DATA 128
  30289. +
  30290. +/** Signals that the current payload is the end of the stream of data */
  30291. +#define MMAL_BUFFER_HEADER_FLAG_EOS (1<<0)
  30292. +/** Signals that the start of the current payload starts a frame */
  30293. +#define MMAL_BUFFER_HEADER_FLAG_FRAME_START (1<<1)
  30294. +/** Signals that the end of the current payload ends a frame */
  30295. +#define MMAL_BUFFER_HEADER_FLAG_FRAME_END (1<<2)
  30296. +/** Signals that the current payload contains only complete frames (>1) */
  30297. +#define MMAL_BUFFER_HEADER_FLAG_FRAME \
  30298. + (MMAL_BUFFER_HEADER_FLAG_FRAME_START|MMAL_BUFFER_HEADER_FLAG_FRAME_END)
  30299. +/** Signals that the current payload is a keyframe (i.e. self decodable) */
  30300. +#define MMAL_BUFFER_HEADER_FLAG_KEYFRAME (1<<3)
  30301. +/** Signals a discontinuity in the stream of data (e.g. after a seek).
  30302. + * Can be used for instance by a decoder to reset its state */
  30303. +#define MMAL_BUFFER_HEADER_FLAG_DISCONTINUITY (1<<4)
  30304. +/** Signals a buffer containing some kind of config data for the component
  30305. + * (e.g. codec config data) */
  30306. +#define MMAL_BUFFER_HEADER_FLAG_CONFIG (1<<5)
  30307. +/** Signals an encrypted payload */
  30308. +#define MMAL_BUFFER_HEADER_FLAG_ENCRYPTED (1<<6)
  30309. +/** Signals a buffer containing side information */
  30310. +#define MMAL_BUFFER_HEADER_FLAG_CODECSIDEINFO (1<<7)
  30311. +/** Signals a buffer which is the snapshot/postview image from a stills
  30312. + * capture
  30313. + */
  30314. +#define MMAL_BUFFER_HEADER_FLAGS_SNAPSHOT (1<<8)
  30315. +/** Signals a buffer which contains data known to be corrupted */
  30316. +#define MMAL_BUFFER_HEADER_FLAG_CORRUPTED (1<<9)
  30317. +/** Signals that a buffer failed to be transmitted */
  30318. +#define MMAL_BUFFER_HEADER_FLAG_TRANSMISSION_FAILED (1<<10)
  30319. +
  30320. +struct mmal_driver_buffer {
  30321. + u32 magic;
  30322. + u32 component_handle;
  30323. + u32 port_handle;
  30324. + void *client_context;
  30325. +};
  30326. +
  30327. +/* buffer header */
  30328. +struct mmal_buffer_header {
  30329. + struct mmal_buffer_header *next; /* next header */
  30330. + void *priv; /* framework private data */
  30331. + u32 cmd;
  30332. + void *data;
  30333. + u32 alloc_size;
  30334. + u32 length;
  30335. + u32 offset;
  30336. + u32 flags;
  30337. + s64 pts;
  30338. + s64 dts;
  30339. + void *type;
  30340. + void *user_data;
  30341. +};
  30342. +
  30343. +struct mmal_buffer_header_type_specific {
  30344. + union {
  30345. + struct {
  30346. + u32 planes;
  30347. + u32 offset[4];
  30348. + u32 pitch[4];
  30349. + u32 flags;
  30350. + } video;
  30351. + } u;
  30352. +};
  30353. +
  30354. +struct mmal_msg_buffer_from_host {
  30355. + /* The front 32 bytes of the buffer header are copied
  30356. + * back to us in the reply to allow for context. This
  30357. + * area is used to store two mmal_driver_buffer structures to
  30358. + * allow for multiple concurrent service users.
  30359. + */
  30360. + /* control data */
  30361. + struct mmal_driver_buffer drvbuf;
  30362. +
  30363. + /* referenced control data for passthrough buffer management */
  30364. + struct mmal_driver_buffer drvbuf_ref;
  30365. + struct mmal_buffer_header buffer_header; /* buffer header itself */
  30366. + struct mmal_buffer_header_type_specific buffer_header_type_specific;
  30367. + s32 is_zero_copy;
  30368. + s32 has_reference;
  30369. +
  30370. + /** allows short data to be xfered in control message */
  30371. + u32 payload_in_message;
  30372. + u8 short_data[MMAL_VC_SHORT_DATA];
  30373. +};
  30374. +
  30375. +
  30376. +/* port parameter setting */
  30377. +
  30378. +#define MMAL_WORKER_PORT_PARAMETER_SPACE 96
  30379. +
  30380. +struct mmal_msg_port_parameter_set {
  30381. + u32 component_handle; /* component */
  30382. + u32 port_handle; /* port */
  30383. + u32 id; /* Parameter ID */
  30384. + u32 size; /* Parameter size */
  30385. + uint32_t value[MMAL_WORKER_PORT_PARAMETER_SPACE];
  30386. +};
  30387. +
  30388. +struct mmal_msg_port_parameter_set_reply {
  30389. + u32 status; /** enum mmal_msg_status todo: how does this
  30390. + * differ to the one in the header?
  30391. + */
  30392. +};
  30393. +
  30394. +/* port parameter getting */
  30395. +
  30396. +struct mmal_msg_port_parameter_get {
  30397. + u32 component_handle; /* component */
  30398. + u32 port_handle; /* port */
  30399. + u32 id; /* Parameter ID */
  30400. + u32 size; /* Parameter size */
  30401. +};
  30402. +
  30403. +struct mmal_msg_port_parameter_get_reply {
  30404. + u32 status; /* Status of mmal_port_parameter_get call */
  30405. + u32 id; /* Parameter ID */
  30406. + u32 size; /* Parameter size */
  30407. + uint32_t value[MMAL_WORKER_PORT_PARAMETER_SPACE];
  30408. +};
  30409. +
  30410. +/* event messages */
  30411. +#define MMAL_WORKER_EVENT_SPACE 256
  30412. +
  30413. +struct mmal_msg_event_to_host {
  30414. + void *client_component; /* component context */
  30415. +
  30416. + u32 port_type;
  30417. + u32 port_num;
  30418. +
  30419. + u32 cmd;
  30420. + u32 length;
  30421. + u8 data[MMAL_WORKER_EVENT_SPACE];
  30422. + struct mmal_buffer_header *delayed_buffer;
  30423. +};
  30424. +
  30425. +/* all mmal messages are serialised through this structure */
  30426. +struct mmal_msg {
  30427. + /* header */
  30428. + struct mmal_msg_header h;
  30429. + /* payload */
  30430. + union {
  30431. + struct mmal_msg_version version;
  30432. +
  30433. + struct mmal_msg_component_create component_create;
  30434. + struct mmal_msg_component_create_reply component_create_reply;
  30435. +
  30436. + struct mmal_msg_component_destroy component_destroy;
  30437. + struct mmal_msg_component_destroy_reply component_destroy_reply;
  30438. +
  30439. + struct mmal_msg_component_enable component_enable;
  30440. + struct mmal_msg_component_enable_reply component_enable_reply;
  30441. +
  30442. + struct mmal_msg_component_disable component_disable;
  30443. + struct mmal_msg_component_disable_reply component_disable_reply;
  30444. +
  30445. + struct mmal_msg_port_info_get port_info_get;
  30446. + struct mmal_msg_port_info_get_reply port_info_get_reply;
  30447. +
  30448. + struct mmal_msg_port_info_set port_info_set;
  30449. + struct mmal_msg_port_info_set_reply port_info_set_reply;
  30450. +
  30451. + struct mmal_msg_port_action_port port_action_port;
  30452. + struct mmal_msg_port_action_handle port_action_handle;
  30453. + struct mmal_msg_port_action_reply port_action_reply;
  30454. +
  30455. + struct mmal_msg_buffer_from_host buffer_from_host;
  30456. +
  30457. + struct mmal_msg_port_parameter_set port_parameter_set;
  30458. + struct mmal_msg_port_parameter_set_reply
  30459. + port_parameter_set_reply;
  30460. + struct mmal_msg_port_parameter_get
  30461. + port_parameter_get;
  30462. + struct mmal_msg_port_parameter_get_reply
  30463. + port_parameter_get_reply;
  30464. +
  30465. + struct mmal_msg_event_to_host event_to_host;
  30466. +
  30467. + u8 payload[MMAL_MSG_MAX_PAYLOAD];
  30468. + } u;
  30469. +};
  30470. diff -Nur linux-3.18.8/drivers/media/platform/bcm2835/mmal-msg-port.h linux-rpi/drivers/media/platform/bcm2835/mmal-msg-port.h
  30471. --- linux-3.18.8/drivers/media/platform/bcm2835/mmal-msg-port.h 1970-01-01 01:00:00.000000000 +0100
  30472. +++ linux-rpi/drivers/media/platform/bcm2835/mmal-msg-port.h 2015-03-05 14:40:13.981715822 +0100
  30473. @@ -0,0 +1,107 @@
  30474. +/*
  30475. + * Broadcom BM2835 V4L2 driver
  30476. + *
  30477. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  30478. + *
  30479. + * This file is subject to the terms and conditions of the GNU General Public
  30480. + * License. See the file COPYING in the main directory of this archive
  30481. + * for more details.
  30482. + *
  30483. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  30484. + * Dave Stevenson <dsteve@broadcom.com>
  30485. + * Simon Mellor <simellor@broadcom.com>
  30486. + * Luke Diamand <luked@broadcom.com>
  30487. + */
  30488. +
  30489. +/* MMAL_PORT_TYPE_T */
  30490. +enum mmal_port_type {
  30491. + MMAL_PORT_TYPE_UNKNOWN = 0, /**< Unknown port type */
  30492. + MMAL_PORT_TYPE_CONTROL, /**< Control port */
  30493. + MMAL_PORT_TYPE_INPUT, /**< Input port */
  30494. + MMAL_PORT_TYPE_OUTPUT, /**< Output port */
  30495. + MMAL_PORT_TYPE_CLOCK, /**< Clock port */
  30496. +};
  30497. +
  30498. +/** The port is pass-through and doesn't need buffer headers allocated */
  30499. +#define MMAL_PORT_CAPABILITY_PASSTHROUGH 0x01
  30500. +/** The port wants to allocate the buffer payloads.
  30501. + * This signals a preference that payload allocation should be done
  30502. + * on this port for efficiency reasons. */
  30503. +#define MMAL_PORT_CAPABILITY_ALLOCATION 0x02
  30504. +/** The port supports format change events.
  30505. + * This applies to input ports and is used to let the client know
  30506. + * whether the port supports being reconfigured via a format
  30507. + * change event (i.e. without having to disable the port). */
  30508. +#define MMAL_PORT_CAPABILITY_SUPPORTS_EVENT_FORMAT_CHANGE 0x04
  30509. +
  30510. +/* mmal port structure (MMAL_PORT_T)
  30511. + *
  30512. + * most elements are informational only, the pointer values for
  30513. + * interogation messages are generally provided as additional
  30514. + * strucures within the message. When used to set values only teh
  30515. + * buffer_num, buffer_size and userdata parameters are writable.
  30516. + */
  30517. +struct mmal_port {
  30518. + void *priv; /* Private member used by the framework */
  30519. + const char *name; /* Port name. Used for debugging purposes (RO) */
  30520. +
  30521. + u32 type; /* Type of the port (RO) enum mmal_port_type */
  30522. + u16 index; /* Index of the port in its type list (RO) */
  30523. + u16 index_all; /* Index of the port in the list of all ports (RO) */
  30524. +
  30525. + u32 is_enabled; /* Indicates whether the port is enabled or not (RO) */
  30526. + struct mmal_es_format *format; /* Format of the elementary stream */
  30527. +
  30528. + u32 buffer_num_min; /* Minimum number of buffers the port
  30529. + * requires (RO). This is set by the
  30530. + * component.
  30531. + */
  30532. +
  30533. + u32 buffer_size_min; /* Minimum size of buffers the port
  30534. + * requires (RO). This is set by the
  30535. + * component.
  30536. + */
  30537. +
  30538. + u32 buffer_alignment_min; /* Minimum alignment requirement for
  30539. + * the buffers (RO). A value of
  30540. + * zero means no special alignment
  30541. + * requirements. This is set by the
  30542. + * component.
  30543. + */
  30544. +
  30545. + u32 buffer_num_recommended; /* Number of buffers the port
  30546. + * recommends for optimal
  30547. + * performance (RO). A value of
  30548. + * zero means no special
  30549. + * recommendation. This is set
  30550. + * by the component.
  30551. + */
  30552. +
  30553. + u32 buffer_size_recommended; /* Size of buffers the port
  30554. + * recommends for optimal
  30555. + * performance (RO). A value of
  30556. + * zero means no special
  30557. + * recommendation. This is set
  30558. + * by the component.
  30559. + */
  30560. +
  30561. + u32 buffer_num; /* Actual number of buffers the port will use.
  30562. + * This is set by the client.
  30563. + */
  30564. +
  30565. + u32 buffer_size; /* Actual maximum size of the buffers that
  30566. + * will be sent to the port. This is set by
  30567. + * the client.
  30568. + */
  30569. +
  30570. + void *component; /* Component this port belongs to (Read Only) */
  30571. +
  30572. + void *userdata; /* Field reserved for use by the client */
  30573. +
  30574. + u32 capabilities; /* Flags describing the capabilities of a
  30575. + * port (RO). Bitwise combination of \ref
  30576. + * portcapabilities "Port capabilities"
  30577. + * values.
  30578. + */
  30579. +
  30580. +};
  30581. diff -Nur linux-3.18.8/drivers/media/platform/bcm2835/mmal-parameters.h linux-rpi/drivers/media/platform/bcm2835/mmal-parameters.h
  30582. --- linux-3.18.8/drivers/media/platform/bcm2835/mmal-parameters.h 1970-01-01 01:00:00.000000000 +0100
  30583. +++ linux-rpi/drivers/media/platform/bcm2835/mmal-parameters.h 2015-03-05 14:40:13.981715822 +0100
  30584. @@ -0,0 +1,656 @@
  30585. +/*
  30586. + * Broadcom BM2835 V4L2 driver
  30587. + *
  30588. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  30589. + *
  30590. + * This file is subject to the terms and conditions of the GNU General Public
  30591. + * License. See the file COPYING in the main directory of this archive
  30592. + * for more details.
  30593. + *
  30594. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  30595. + * Dave Stevenson <dsteve@broadcom.com>
  30596. + * Simon Mellor <simellor@broadcom.com>
  30597. + * Luke Diamand <luked@broadcom.com>
  30598. + */
  30599. +
  30600. +/* common parameters */
  30601. +
  30602. +/** @name Parameter groups
  30603. + * Parameters are divided into groups, and then allocated sequentially within
  30604. + * a group using an enum.
  30605. + * @{
  30606. + */
  30607. +
  30608. +/** Common parameter ID group, used with many types of component. */
  30609. +#define MMAL_PARAMETER_GROUP_COMMON (0<<16)
  30610. +/** Camera-specific parameter ID group. */
  30611. +#define MMAL_PARAMETER_GROUP_CAMERA (1<<16)
  30612. +/** Video-specific parameter ID group. */
  30613. +#define MMAL_PARAMETER_GROUP_VIDEO (2<<16)
  30614. +/** Audio-specific parameter ID group. */
  30615. +#define MMAL_PARAMETER_GROUP_AUDIO (3<<16)
  30616. +/** Clock-specific parameter ID group. */
  30617. +#define MMAL_PARAMETER_GROUP_CLOCK (4<<16)
  30618. +/** Miracast-specific parameter ID group. */
  30619. +#define MMAL_PARAMETER_GROUP_MIRACAST (5<<16)
  30620. +
  30621. +/* Common parameters */
  30622. +enum mmal_parameter_common_type {
  30623. + MMAL_PARAMETER_UNUSED /**< Never a valid parameter ID */
  30624. + = MMAL_PARAMETER_GROUP_COMMON,
  30625. + MMAL_PARAMETER_SUPPORTED_ENCODINGS, /**< MMAL_PARAMETER_ENCODING_T */
  30626. + MMAL_PARAMETER_URI, /**< MMAL_PARAMETER_URI_T */
  30627. +
  30628. + /** MMAL_PARAMETER_CHANGE_EVENT_REQUEST_T */
  30629. + MMAL_PARAMETER_CHANGE_EVENT_REQUEST,
  30630. +
  30631. + /** MMAL_PARAMETER_BOOLEAN_T */
  30632. + MMAL_PARAMETER_ZERO_COPY,
  30633. +
  30634. + /**< MMAL_PARAMETER_BUFFER_REQUIREMENTS_T */
  30635. + MMAL_PARAMETER_BUFFER_REQUIREMENTS,
  30636. +
  30637. + MMAL_PARAMETER_STATISTICS, /**< MMAL_PARAMETER_STATISTICS_T */
  30638. + MMAL_PARAMETER_CORE_STATISTICS, /**< MMAL_PARAMETER_CORE_STATISTICS_T */
  30639. + MMAL_PARAMETER_MEM_USAGE, /**< MMAL_PARAMETER_MEM_USAGE_T */
  30640. + MMAL_PARAMETER_BUFFER_FLAG_FILTER, /**< MMAL_PARAMETER_UINT32_T */
  30641. + MMAL_PARAMETER_SEEK, /**< MMAL_PARAMETER_SEEK_T */
  30642. + MMAL_PARAMETER_POWERMON_ENABLE, /**< MMAL_PARAMETER_BOOLEAN_T */
  30643. + MMAL_PARAMETER_LOGGING, /**< MMAL_PARAMETER_LOGGING_T */
  30644. + MMAL_PARAMETER_SYSTEM_TIME, /**< MMAL_PARAMETER_UINT64_T */
  30645. + MMAL_PARAMETER_NO_IMAGE_PADDING /**< MMAL_PARAMETER_BOOLEAN_T */
  30646. +};
  30647. +
  30648. +/* camera parameters */
  30649. +
  30650. +enum mmal_parameter_camera_type {
  30651. + /* 0 */
  30652. + /** @ref MMAL_PARAMETER_THUMBNAIL_CONFIG_T */
  30653. + MMAL_PARAMETER_THUMBNAIL_CONFIGURATION
  30654. + = MMAL_PARAMETER_GROUP_CAMERA,
  30655. + MMAL_PARAMETER_CAPTURE_QUALITY, /**< Unused? */
  30656. + MMAL_PARAMETER_ROTATION, /**< @ref MMAL_PARAMETER_INT32_T */
  30657. + MMAL_PARAMETER_EXIF_DISABLE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  30658. + MMAL_PARAMETER_EXIF, /**< @ref MMAL_PARAMETER_EXIF_T */
  30659. + MMAL_PARAMETER_AWB_MODE, /**< @ref MMAL_PARAM_AWBMODE_T */
  30660. + MMAL_PARAMETER_IMAGE_EFFECT, /**< @ref MMAL_PARAMETER_IMAGEFX_T */
  30661. + MMAL_PARAMETER_COLOUR_EFFECT, /**< @ref MMAL_PARAMETER_COLOURFX_T */
  30662. + MMAL_PARAMETER_FLICKER_AVOID, /**< @ref MMAL_PARAMETER_FLICKERAVOID_T */
  30663. + MMAL_PARAMETER_FLASH, /**< @ref MMAL_PARAMETER_FLASH_T */
  30664. + MMAL_PARAMETER_REDEYE, /**< @ref MMAL_PARAMETER_REDEYE_T */
  30665. + MMAL_PARAMETER_FOCUS, /**< @ref MMAL_PARAMETER_FOCUS_T */
  30666. + MMAL_PARAMETER_FOCAL_LENGTHS, /**< Unused? */
  30667. + MMAL_PARAMETER_EXPOSURE_COMP, /**< @ref MMAL_PARAMETER_INT32_T */
  30668. + MMAL_PARAMETER_ZOOM, /**< @ref MMAL_PARAMETER_SCALEFACTOR_T */
  30669. + MMAL_PARAMETER_MIRROR, /**< @ref MMAL_PARAMETER_MIRROR_T */
  30670. +
  30671. + /* 0x10 */
  30672. + MMAL_PARAMETER_CAMERA_NUM, /**< @ref MMAL_PARAMETER_UINT32_T */
  30673. + MMAL_PARAMETER_CAPTURE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  30674. + MMAL_PARAMETER_EXPOSURE_MODE, /**< @ref MMAL_PARAMETER_EXPOSUREMODE_T */
  30675. + MMAL_PARAMETER_EXP_METERING_MODE, /**< @ref MMAL_PARAMETER_EXPOSUREMETERINGMODE_T */
  30676. + MMAL_PARAMETER_FOCUS_STATUS, /**< @ref MMAL_PARAMETER_FOCUS_STATUS_T */
  30677. + MMAL_PARAMETER_CAMERA_CONFIG, /**< @ref MMAL_PARAMETER_CAMERA_CONFIG_T */
  30678. + MMAL_PARAMETER_CAPTURE_STATUS, /**< @ref MMAL_PARAMETER_CAPTURE_STATUS_T */
  30679. + MMAL_PARAMETER_FACE_TRACK, /**< @ref MMAL_PARAMETER_FACE_TRACK_T */
  30680. + MMAL_PARAMETER_DRAW_BOX_FACES_AND_FOCUS, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  30681. + MMAL_PARAMETER_JPEG_Q_FACTOR, /**< @ref MMAL_PARAMETER_UINT32_T */
  30682. + MMAL_PARAMETER_FRAME_RATE, /**< @ref MMAL_PARAMETER_FRAME_RATE_T */
  30683. + MMAL_PARAMETER_USE_STC, /**< @ref MMAL_PARAMETER_CAMERA_STC_MODE_T */
  30684. + MMAL_PARAMETER_CAMERA_INFO, /**< @ref MMAL_PARAMETER_CAMERA_INFO_T */
  30685. + MMAL_PARAMETER_VIDEO_STABILISATION, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  30686. + MMAL_PARAMETER_FACE_TRACK_RESULTS, /**< @ref MMAL_PARAMETER_FACE_TRACK_RESULTS_T */
  30687. + MMAL_PARAMETER_ENABLE_RAW_CAPTURE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  30688. +
  30689. + /* 0x20 */
  30690. + MMAL_PARAMETER_DPF_FILE, /**< @ref MMAL_PARAMETER_URI_T */
  30691. + MMAL_PARAMETER_ENABLE_DPF_FILE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  30692. + MMAL_PARAMETER_DPF_FAIL_IS_FATAL, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  30693. + MMAL_PARAMETER_CAPTURE_MODE, /**< @ref MMAL_PARAMETER_CAPTUREMODE_T */
  30694. + MMAL_PARAMETER_FOCUS_REGIONS, /**< @ref MMAL_PARAMETER_FOCUS_REGIONS_T */
  30695. + MMAL_PARAMETER_INPUT_CROP, /**< @ref MMAL_PARAMETER_INPUT_CROP_T */
  30696. + MMAL_PARAMETER_SENSOR_INFORMATION, /**< @ref MMAL_PARAMETER_SENSOR_INFORMATION_T */
  30697. + MMAL_PARAMETER_FLASH_SELECT, /**< @ref MMAL_PARAMETER_FLASH_SELECT_T */
  30698. + MMAL_PARAMETER_FIELD_OF_VIEW, /**< @ref MMAL_PARAMETER_FIELD_OF_VIEW_T */
  30699. + MMAL_PARAMETER_HIGH_DYNAMIC_RANGE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  30700. + MMAL_PARAMETER_DYNAMIC_RANGE_COMPRESSION, /**< @ref MMAL_PARAMETER_DRC_T */
  30701. + MMAL_PARAMETER_ALGORITHM_CONTROL, /**< @ref MMAL_PARAMETER_ALGORITHM_CONTROL_T */
  30702. + MMAL_PARAMETER_SHARPNESS, /**< @ref MMAL_PARAMETER_RATIONAL_T */
  30703. + MMAL_PARAMETER_CONTRAST, /**< @ref MMAL_PARAMETER_RATIONAL_T */
  30704. + MMAL_PARAMETER_BRIGHTNESS, /**< @ref MMAL_PARAMETER_RATIONAL_T */
  30705. + MMAL_PARAMETER_SATURATION, /**< @ref MMAL_PARAMETER_RATIONAL_T */
  30706. +
  30707. + /* 0x30 */
  30708. + MMAL_PARAMETER_ISO, /**< @ref MMAL_PARAMETER_UINT32_T */
  30709. + MMAL_PARAMETER_ANTISHAKE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  30710. +
  30711. + /** @ref MMAL_PARAMETER_IMAGEFX_PARAMETERS_T */
  30712. + MMAL_PARAMETER_IMAGE_EFFECT_PARAMETERS,
  30713. +
  30714. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  30715. + MMAL_PARAMETER_CAMERA_BURST_CAPTURE,
  30716. +
  30717. + /** @ref MMAL_PARAMETER_UINT32_T */
  30718. + MMAL_PARAMETER_CAMERA_MIN_ISO,
  30719. +
  30720. + /** @ref MMAL_PARAMETER_CAMERA_USE_CASE_T */
  30721. + MMAL_PARAMETER_CAMERA_USE_CASE,
  30722. +
  30723. + /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  30724. + MMAL_PARAMETER_CAPTURE_STATS_PASS,
  30725. +
  30726. + /** @ref MMAL_PARAMETER_UINT32_T */
  30727. + MMAL_PARAMETER_CAMERA_CUSTOM_SENSOR_CONFIG,
  30728. +
  30729. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  30730. + MMAL_PARAMETER_ENABLE_REGISTER_FILE,
  30731. +
  30732. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  30733. + MMAL_PARAMETER_REGISTER_FAIL_IS_FATAL,
  30734. +
  30735. + /** @ref MMAL_PARAMETER_CONFIGFILE_T */
  30736. + MMAL_PARAMETER_CONFIGFILE_REGISTERS,
  30737. +
  30738. + /** @ref MMAL_PARAMETER_CONFIGFILE_CHUNK_T */
  30739. + MMAL_PARAMETER_CONFIGFILE_CHUNK_REGISTERS,
  30740. + MMAL_PARAMETER_JPEG_ATTACH_LOG, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  30741. + MMAL_PARAMETER_ZERO_SHUTTER_LAG, /**< @ref MMAL_PARAMETER_ZEROSHUTTERLAG_T */
  30742. + MMAL_PARAMETER_FPS_RANGE, /**< @ref MMAL_PARAMETER_FPS_RANGE_T */
  30743. + MMAL_PARAMETER_CAPTURE_EXPOSURE_COMP, /**< @ref MMAL_PARAMETER_INT32_T */
  30744. +
  30745. + /* 0x40 */
  30746. + MMAL_PARAMETER_SW_SHARPEN_DISABLE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  30747. + MMAL_PARAMETER_FLASH_REQUIRED, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  30748. + MMAL_PARAMETER_SW_SATURATION_DISABLE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  30749. + MMAL_PARAMETER_SHUTTER_SPEED, /**< Takes a @ref MMAL_PARAMETER_UINT32_T */
  30750. + MMAL_PARAMETER_CUSTOM_AWB_GAINS, /**< Takes a @ref MMAL_PARAMETER_AWB_GAINS_T */
  30751. +};
  30752. +
  30753. +struct mmal_parameter_rational {
  30754. + s32 num; /**< Numerator */
  30755. + s32 den; /**< Denominator */
  30756. +};
  30757. +
  30758. +enum mmal_parameter_camera_config_timestamp_mode {
  30759. + MMAL_PARAM_TIMESTAMP_MODE_ZERO = 0, /* Always timestamp frames as 0 */
  30760. + MMAL_PARAM_TIMESTAMP_MODE_RAW_STC, /* Use the raw STC value
  30761. + * for the frame timestamp
  30762. + */
  30763. + MMAL_PARAM_TIMESTAMP_MODE_RESET_STC, /* Use the STC timestamp
  30764. + * but subtract the
  30765. + * timestamp of the first
  30766. + * frame sent to give a
  30767. + * zero based timestamp.
  30768. + */
  30769. +};
  30770. +
  30771. +struct mmal_parameter_fps_range {
  30772. + /**< Low end of the permitted framerate range */
  30773. + struct mmal_parameter_rational fps_low;
  30774. + /**< High end of the permitted framerate range */
  30775. + struct mmal_parameter_rational fps_high;
  30776. +};
  30777. +
  30778. +
  30779. +/* camera configuration parameter */
  30780. +struct mmal_parameter_camera_config {
  30781. + /* Parameters for setting up the image pools */
  30782. + u32 max_stills_w; /* Max size of stills capture */
  30783. + u32 max_stills_h;
  30784. + u32 stills_yuv422; /* Allow YUV422 stills capture */
  30785. + u32 one_shot_stills; /* Continuous or one shot stills captures. */
  30786. +
  30787. + u32 max_preview_video_w; /* Max size of the preview or video
  30788. + * capture frames
  30789. + */
  30790. + u32 max_preview_video_h;
  30791. + u32 num_preview_video_frames;
  30792. +
  30793. + /** Sets the height of the circular buffer for stills capture. */
  30794. + u32 stills_capture_circular_buffer_height;
  30795. +
  30796. + /** Allows preview/encode to resume as fast as possible after the stills
  30797. + * input frame has been received, and then processes the still frame in
  30798. + * the background whilst preview/encode has resumed.
  30799. + * Actual mode is controlled by MMAL_PARAMETER_CAPTURE_MODE.
  30800. + */
  30801. + u32 fast_preview_resume;
  30802. +
  30803. + /** Selects algorithm for timestamping frames if
  30804. + * there is no clock component connected.
  30805. + * enum mmal_parameter_camera_config_timestamp_mode
  30806. + */
  30807. + s32 use_stc_timestamp;
  30808. +};
  30809. +
  30810. +
  30811. +enum mmal_parameter_exposuremode {
  30812. + MMAL_PARAM_EXPOSUREMODE_OFF,
  30813. + MMAL_PARAM_EXPOSUREMODE_AUTO,
  30814. + MMAL_PARAM_EXPOSUREMODE_NIGHT,
  30815. + MMAL_PARAM_EXPOSUREMODE_NIGHTPREVIEW,
  30816. + MMAL_PARAM_EXPOSUREMODE_BACKLIGHT,
  30817. + MMAL_PARAM_EXPOSUREMODE_SPOTLIGHT,
  30818. + MMAL_PARAM_EXPOSUREMODE_SPORTS,
  30819. + MMAL_PARAM_EXPOSUREMODE_SNOW,
  30820. + MMAL_PARAM_EXPOSUREMODE_BEACH,
  30821. + MMAL_PARAM_EXPOSUREMODE_VERYLONG,
  30822. + MMAL_PARAM_EXPOSUREMODE_FIXEDFPS,
  30823. + MMAL_PARAM_EXPOSUREMODE_ANTISHAKE,
  30824. + MMAL_PARAM_EXPOSUREMODE_FIREWORKS,
  30825. +};
  30826. +
  30827. +enum mmal_parameter_exposuremeteringmode {
  30828. + MMAL_PARAM_EXPOSUREMETERINGMODE_AVERAGE,
  30829. + MMAL_PARAM_EXPOSUREMETERINGMODE_SPOT,
  30830. + MMAL_PARAM_EXPOSUREMETERINGMODE_BACKLIT,
  30831. + MMAL_PARAM_EXPOSUREMETERINGMODE_MATRIX,
  30832. +};
  30833. +
  30834. +enum mmal_parameter_awbmode {
  30835. + MMAL_PARAM_AWBMODE_OFF,
  30836. + MMAL_PARAM_AWBMODE_AUTO,
  30837. + MMAL_PARAM_AWBMODE_SUNLIGHT,
  30838. + MMAL_PARAM_AWBMODE_CLOUDY,
  30839. + MMAL_PARAM_AWBMODE_SHADE,
  30840. + MMAL_PARAM_AWBMODE_TUNGSTEN,
  30841. + MMAL_PARAM_AWBMODE_FLUORESCENT,
  30842. + MMAL_PARAM_AWBMODE_INCANDESCENT,
  30843. + MMAL_PARAM_AWBMODE_FLASH,
  30844. + MMAL_PARAM_AWBMODE_HORIZON,
  30845. +};
  30846. +
  30847. +enum mmal_parameter_imagefx {
  30848. + MMAL_PARAM_IMAGEFX_NONE,
  30849. + MMAL_PARAM_IMAGEFX_NEGATIVE,
  30850. + MMAL_PARAM_IMAGEFX_SOLARIZE,
  30851. + MMAL_PARAM_IMAGEFX_POSTERIZE,
  30852. + MMAL_PARAM_IMAGEFX_WHITEBOARD,
  30853. + MMAL_PARAM_IMAGEFX_BLACKBOARD,
  30854. + MMAL_PARAM_IMAGEFX_SKETCH,
  30855. + MMAL_PARAM_IMAGEFX_DENOISE,
  30856. + MMAL_PARAM_IMAGEFX_EMBOSS,
  30857. + MMAL_PARAM_IMAGEFX_OILPAINT,
  30858. + MMAL_PARAM_IMAGEFX_HATCH,
  30859. + MMAL_PARAM_IMAGEFX_GPEN,
  30860. + MMAL_PARAM_IMAGEFX_PASTEL,
  30861. + MMAL_PARAM_IMAGEFX_WATERCOLOUR,
  30862. + MMAL_PARAM_IMAGEFX_FILM,
  30863. + MMAL_PARAM_IMAGEFX_BLUR,
  30864. + MMAL_PARAM_IMAGEFX_SATURATION,
  30865. + MMAL_PARAM_IMAGEFX_COLOURSWAP,
  30866. + MMAL_PARAM_IMAGEFX_WASHEDOUT,
  30867. + MMAL_PARAM_IMAGEFX_POSTERISE,
  30868. + MMAL_PARAM_IMAGEFX_COLOURPOINT,
  30869. + MMAL_PARAM_IMAGEFX_COLOURBALANCE,
  30870. + MMAL_PARAM_IMAGEFX_CARTOON,
  30871. +};
  30872. +
  30873. +enum MMAL_PARAM_FLICKERAVOID_T {
  30874. + MMAL_PARAM_FLICKERAVOID_OFF,
  30875. + MMAL_PARAM_FLICKERAVOID_AUTO,
  30876. + MMAL_PARAM_FLICKERAVOID_50HZ,
  30877. + MMAL_PARAM_FLICKERAVOID_60HZ,
  30878. + MMAL_PARAM_FLICKERAVOID_MAX = 0x7FFFFFFF
  30879. +};
  30880. +
  30881. +struct mmal_parameter_awbgains {
  30882. + struct mmal_parameter_rational r_gain; /**< Red gain */
  30883. + struct mmal_parameter_rational b_gain; /**< Blue gain */
  30884. +};
  30885. +
  30886. +/** Manner of video rate control */
  30887. +enum mmal_parameter_rate_control_mode {
  30888. + MMAL_VIDEO_RATECONTROL_DEFAULT,
  30889. + MMAL_VIDEO_RATECONTROL_VARIABLE,
  30890. + MMAL_VIDEO_RATECONTROL_CONSTANT,
  30891. + MMAL_VIDEO_RATECONTROL_VARIABLE_SKIP_FRAMES,
  30892. + MMAL_VIDEO_RATECONTROL_CONSTANT_SKIP_FRAMES
  30893. +};
  30894. +
  30895. +enum mmal_video_profile {
  30896. + MMAL_VIDEO_PROFILE_H263_BASELINE,
  30897. + MMAL_VIDEO_PROFILE_H263_H320CODING,
  30898. + MMAL_VIDEO_PROFILE_H263_BACKWARDCOMPATIBLE,
  30899. + MMAL_VIDEO_PROFILE_H263_ISWV2,
  30900. + MMAL_VIDEO_PROFILE_H263_ISWV3,
  30901. + MMAL_VIDEO_PROFILE_H263_HIGHCOMPRESSION,
  30902. + MMAL_VIDEO_PROFILE_H263_INTERNET,
  30903. + MMAL_VIDEO_PROFILE_H263_INTERLACE,
  30904. + MMAL_VIDEO_PROFILE_H263_HIGHLATENCY,
  30905. + MMAL_VIDEO_PROFILE_MP4V_SIMPLE,
  30906. + MMAL_VIDEO_PROFILE_MP4V_SIMPLESCALABLE,
  30907. + MMAL_VIDEO_PROFILE_MP4V_CORE,
  30908. + MMAL_VIDEO_PROFILE_MP4V_MAIN,
  30909. + MMAL_VIDEO_PROFILE_MP4V_NBIT,
  30910. + MMAL_VIDEO_PROFILE_MP4V_SCALABLETEXTURE,
  30911. + MMAL_VIDEO_PROFILE_MP4V_SIMPLEFACE,
  30912. + MMAL_VIDEO_PROFILE_MP4V_SIMPLEFBA,
  30913. + MMAL_VIDEO_PROFILE_MP4V_BASICANIMATED,
  30914. + MMAL_VIDEO_PROFILE_MP4V_HYBRID,
  30915. + MMAL_VIDEO_PROFILE_MP4V_ADVANCEDREALTIME,
  30916. + MMAL_VIDEO_PROFILE_MP4V_CORESCALABLE,
  30917. + MMAL_VIDEO_PROFILE_MP4V_ADVANCEDCODING,
  30918. + MMAL_VIDEO_PROFILE_MP4V_ADVANCEDCORE,
  30919. + MMAL_VIDEO_PROFILE_MP4V_ADVANCEDSCALABLE,
  30920. + MMAL_VIDEO_PROFILE_MP4V_ADVANCEDSIMPLE,
  30921. + MMAL_VIDEO_PROFILE_H264_BASELINE,
  30922. + MMAL_VIDEO_PROFILE_H264_MAIN,
  30923. + MMAL_VIDEO_PROFILE_H264_EXTENDED,
  30924. + MMAL_VIDEO_PROFILE_H264_HIGH,
  30925. + MMAL_VIDEO_PROFILE_H264_HIGH10,
  30926. + MMAL_VIDEO_PROFILE_H264_HIGH422,
  30927. + MMAL_VIDEO_PROFILE_H264_HIGH444,
  30928. + MMAL_VIDEO_PROFILE_H264_CONSTRAINED_BASELINE,
  30929. + MMAL_VIDEO_PROFILE_DUMMY = 0x7FFFFFFF
  30930. +};
  30931. +
  30932. +enum mmal_video_level {
  30933. + MMAL_VIDEO_LEVEL_H263_10,
  30934. + MMAL_VIDEO_LEVEL_H263_20,
  30935. + MMAL_VIDEO_LEVEL_H263_30,
  30936. + MMAL_VIDEO_LEVEL_H263_40,
  30937. + MMAL_VIDEO_LEVEL_H263_45,
  30938. + MMAL_VIDEO_LEVEL_H263_50,
  30939. + MMAL_VIDEO_LEVEL_H263_60,
  30940. + MMAL_VIDEO_LEVEL_H263_70,
  30941. + MMAL_VIDEO_LEVEL_MP4V_0,
  30942. + MMAL_VIDEO_LEVEL_MP4V_0b,
  30943. + MMAL_VIDEO_LEVEL_MP4V_1,
  30944. + MMAL_VIDEO_LEVEL_MP4V_2,
  30945. + MMAL_VIDEO_LEVEL_MP4V_3,
  30946. + MMAL_VIDEO_LEVEL_MP4V_4,
  30947. + MMAL_VIDEO_LEVEL_MP4V_4a,
  30948. + MMAL_VIDEO_LEVEL_MP4V_5,
  30949. + MMAL_VIDEO_LEVEL_MP4V_6,
  30950. + MMAL_VIDEO_LEVEL_H264_1,
  30951. + MMAL_VIDEO_LEVEL_H264_1b,
  30952. + MMAL_VIDEO_LEVEL_H264_11,
  30953. + MMAL_VIDEO_LEVEL_H264_12,
  30954. + MMAL_VIDEO_LEVEL_H264_13,
  30955. + MMAL_VIDEO_LEVEL_H264_2,
  30956. + MMAL_VIDEO_LEVEL_H264_21,
  30957. + MMAL_VIDEO_LEVEL_H264_22,
  30958. + MMAL_VIDEO_LEVEL_H264_3,
  30959. + MMAL_VIDEO_LEVEL_H264_31,
  30960. + MMAL_VIDEO_LEVEL_H264_32,
  30961. + MMAL_VIDEO_LEVEL_H264_4,
  30962. + MMAL_VIDEO_LEVEL_H264_41,
  30963. + MMAL_VIDEO_LEVEL_H264_42,
  30964. + MMAL_VIDEO_LEVEL_H264_5,
  30965. + MMAL_VIDEO_LEVEL_H264_51,
  30966. + MMAL_VIDEO_LEVEL_DUMMY = 0x7FFFFFFF
  30967. +};
  30968. +
  30969. +struct mmal_parameter_video_profile {
  30970. + enum mmal_video_profile profile;
  30971. + enum mmal_video_level level;
  30972. +};
  30973. +
  30974. +/* video parameters */
  30975. +
  30976. +enum mmal_parameter_video_type {
  30977. + /** @ref MMAL_DISPLAYREGION_T */
  30978. + MMAL_PARAMETER_DISPLAYREGION = MMAL_PARAMETER_GROUP_VIDEO,
  30979. +
  30980. + /** @ref MMAL_PARAMETER_VIDEO_PROFILE_T */
  30981. + MMAL_PARAMETER_SUPPORTED_PROFILES,
  30982. +
  30983. + /** @ref MMAL_PARAMETER_VIDEO_PROFILE_T */
  30984. + MMAL_PARAMETER_PROFILE,
  30985. +
  30986. + /** @ref MMAL_PARAMETER_UINT32_T */
  30987. + MMAL_PARAMETER_INTRAPERIOD,
  30988. +
  30989. + /** @ref MMAL_PARAMETER_VIDEO_RATECONTROL_T */
  30990. + MMAL_PARAMETER_RATECONTROL,
  30991. +
  30992. + /** @ref MMAL_PARAMETER_VIDEO_NALUNITFORMAT_T */
  30993. + MMAL_PARAMETER_NALUNITFORMAT,
  30994. +
  30995. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  30996. + MMAL_PARAMETER_MINIMISE_FRAGMENTATION,
  30997. +
  30998. + /** @ref MMAL_PARAMETER_UINT32_T.
  30999. + * Setting the value to zero resets to the default (one slice per frame).
  31000. + */
  31001. + MMAL_PARAMETER_MB_ROWS_PER_SLICE,
  31002. +
  31003. + /** @ref MMAL_PARAMETER_VIDEO_LEVEL_EXTENSION_T */
  31004. + MMAL_PARAMETER_VIDEO_LEVEL_EXTENSION,
  31005. +
  31006. + /** @ref MMAL_PARAMETER_VIDEO_EEDE_ENABLE_T */
  31007. + MMAL_PARAMETER_VIDEO_EEDE_ENABLE,
  31008. +
  31009. + /** @ref MMAL_PARAMETER_VIDEO_EEDE_LOSSRATE_T */
  31010. + MMAL_PARAMETER_VIDEO_EEDE_LOSSRATE,
  31011. +
  31012. + /** @ref MMAL_PARAMETER_BOOLEAN_T. Request an I-frame. */
  31013. + MMAL_PARAMETER_VIDEO_REQUEST_I_FRAME,
  31014. + /** @ref MMAL_PARAMETER_VIDEO_INTRA_REFRESH_T */
  31015. + MMAL_PARAMETER_VIDEO_INTRA_REFRESH,
  31016. +
  31017. + /** @ref MMAL_PARAMETER_BOOLEAN_T. */
  31018. + MMAL_PARAMETER_VIDEO_IMMUTABLE_INPUT,
  31019. +
  31020. + /** @ref MMAL_PARAMETER_UINT32_T. Run-time bit rate control */
  31021. + MMAL_PARAMETER_VIDEO_BIT_RATE,
  31022. +
  31023. + /** @ref MMAL_PARAMETER_FRAME_RATE_T */
  31024. + MMAL_PARAMETER_VIDEO_FRAME_RATE,
  31025. +
  31026. + /** @ref MMAL_PARAMETER_UINT32_T. */
  31027. + MMAL_PARAMETER_VIDEO_ENCODE_MIN_QUANT,
  31028. +
  31029. + /** @ref MMAL_PARAMETER_UINT32_T. */
  31030. + MMAL_PARAMETER_VIDEO_ENCODE_MAX_QUANT,
  31031. +
  31032. + /** @ref MMAL_PARAMETER_VIDEO_ENCODE_RC_MODEL_T. */
  31033. + MMAL_PARAMETER_VIDEO_ENCODE_RC_MODEL,
  31034. +
  31035. + MMAL_PARAMETER_EXTRA_BUFFERS, /**< @ref MMAL_PARAMETER_UINT32_T. */
  31036. + /** @ref MMAL_PARAMETER_UINT32_T.
  31037. + * Changing this parameter from the default can reduce frame rate
  31038. + * because image buffers need to be re-pitched.
  31039. + */
  31040. + MMAL_PARAMETER_VIDEO_ALIGN_HORIZ,
  31041. +
  31042. + /** @ref MMAL_PARAMETER_UINT32_T.
  31043. + * Changing this parameter from the default can reduce frame rate
  31044. + * because image buffers need to be re-pitched.
  31045. + */
  31046. + MMAL_PARAMETER_VIDEO_ALIGN_VERT,
  31047. +
  31048. + /** @ref MMAL_PARAMETER_BOOLEAN_T. */
  31049. + MMAL_PARAMETER_VIDEO_DROPPABLE_PFRAMES,
  31050. +
  31051. + /** @ref MMAL_PARAMETER_UINT32_T. */
  31052. + MMAL_PARAMETER_VIDEO_ENCODE_INITIAL_QUANT,
  31053. +
  31054. + /**< @ref MMAL_PARAMETER_UINT32_T. */
  31055. + MMAL_PARAMETER_VIDEO_ENCODE_QP_P,
  31056. +
  31057. + /**< @ref MMAL_PARAMETER_UINT32_T. */
  31058. + MMAL_PARAMETER_VIDEO_ENCODE_RC_SLICE_DQUANT,
  31059. +
  31060. + /** @ref MMAL_PARAMETER_UINT32_T */
  31061. + MMAL_PARAMETER_VIDEO_ENCODE_FRAME_LIMIT_BITS,
  31062. +
  31063. + /** @ref MMAL_PARAMETER_UINT32_T. */
  31064. + MMAL_PARAMETER_VIDEO_ENCODE_PEAK_RATE,
  31065. +
  31066. + /* H264 specific parameters */
  31067. +
  31068. + /** @ref MMAL_PARAMETER_BOOLEAN_T. */
  31069. + MMAL_PARAMETER_VIDEO_ENCODE_H264_DISABLE_CABAC,
  31070. +
  31071. + /** @ref MMAL_PARAMETER_BOOLEAN_T. */
  31072. + MMAL_PARAMETER_VIDEO_ENCODE_H264_LOW_LATENCY,
  31073. +
  31074. + /** @ref MMAL_PARAMETER_BOOLEAN_T. */
  31075. + MMAL_PARAMETER_VIDEO_ENCODE_H264_AU_DELIMITERS,
  31076. +
  31077. + /** @ref MMAL_PARAMETER_UINT32_T. */
  31078. + MMAL_PARAMETER_VIDEO_ENCODE_H264_DEBLOCK_IDC,
  31079. +
  31080. + /** @ref MMAL_PARAMETER_VIDEO_ENCODER_H264_MB_INTRA_MODES_T. */
  31081. + MMAL_PARAMETER_VIDEO_ENCODE_H264_MB_INTRA_MODE,
  31082. +
  31083. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  31084. + MMAL_PARAMETER_VIDEO_ENCODE_HEADER_ON_OPEN,
  31085. +
  31086. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  31087. + MMAL_PARAMETER_VIDEO_ENCODE_PRECODE_FOR_QP,
  31088. +
  31089. + /** @ref MMAL_PARAMETER_VIDEO_DRM_INIT_INFO_T. */
  31090. + MMAL_PARAMETER_VIDEO_DRM_INIT_INFO,
  31091. +
  31092. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  31093. + MMAL_PARAMETER_VIDEO_TIMESTAMP_FIFO,
  31094. +
  31095. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  31096. + MMAL_PARAMETER_VIDEO_DECODE_ERROR_CONCEALMENT,
  31097. +
  31098. + /** @ref MMAL_PARAMETER_VIDEO_DRM_PROTECT_BUFFER_T. */
  31099. + MMAL_PARAMETER_VIDEO_DRM_PROTECT_BUFFER,
  31100. +
  31101. + /** @ref MMAL_PARAMETER_BYTES_T */
  31102. + MMAL_PARAMETER_VIDEO_DECODE_CONFIG_VD3,
  31103. +
  31104. + /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  31105. + MMAL_PARAMETER_VIDEO_ENCODE_H264_VCL_HRD_PARAMETERS,
  31106. +
  31107. + /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  31108. + MMAL_PARAMETER_VIDEO_ENCODE_H264_LOW_DELAY_HRD_FLAG,
  31109. +
  31110. + /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  31111. + MMAL_PARAMETER_VIDEO_ENCODE_INLINE_HEADER
  31112. +};
  31113. +
  31114. +/** Valid mirror modes */
  31115. +enum mmal_parameter_mirror {
  31116. + MMAL_PARAM_MIRROR_NONE,
  31117. + MMAL_PARAM_MIRROR_VERTICAL,
  31118. + MMAL_PARAM_MIRROR_HORIZONTAL,
  31119. + MMAL_PARAM_MIRROR_BOTH,
  31120. +};
  31121. +
  31122. +enum mmal_parameter_displaytransform {
  31123. + MMAL_DISPLAY_ROT0 = 0,
  31124. + MMAL_DISPLAY_MIRROR_ROT0 = 1,
  31125. + MMAL_DISPLAY_MIRROR_ROT180 = 2,
  31126. + MMAL_DISPLAY_ROT180 = 3,
  31127. + MMAL_DISPLAY_MIRROR_ROT90 = 4,
  31128. + MMAL_DISPLAY_ROT270 = 5,
  31129. + MMAL_DISPLAY_ROT90 = 6,
  31130. + MMAL_DISPLAY_MIRROR_ROT270 = 7,
  31131. +};
  31132. +
  31133. +enum mmal_parameter_displaymode {
  31134. + MMAL_DISPLAY_MODE_FILL = 0,
  31135. + MMAL_DISPLAY_MODE_LETTERBOX = 1,
  31136. +};
  31137. +
  31138. +enum mmal_parameter_displayset {
  31139. + MMAL_DISPLAY_SET_NONE = 0,
  31140. + MMAL_DISPLAY_SET_NUM = 1,
  31141. + MMAL_DISPLAY_SET_FULLSCREEN = 2,
  31142. + MMAL_DISPLAY_SET_TRANSFORM = 4,
  31143. + MMAL_DISPLAY_SET_DEST_RECT = 8,
  31144. + MMAL_DISPLAY_SET_SRC_RECT = 0x10,
  31145. + MMAL_DISPLAY_SET_MODE = 0x20,
  31146. + MMAL_DISPLAY_SET_PIXEL = 0x40,
  31147. + MMAL_DISPLAY_SET_NOASPECT = 0x80,
  31148. + MMAL_DISPLAY_SET_LAYER = 0x100,
  31149. + MMAL_DISPLAY_SET_COPYPROTECT = 0x200,
  31150. + MMAL_DISPLAY_SET_ALPHA = 0x400,
  31151. +};
  31152. +
  31153. +struct mmal_parameter_displayregion {
  31154. + /** Bitfield that indicates which fields are set and should be
  31155. + * used. All other fields will maintain their current value.
  31156. + * \ref MMAL_DISPLAYSET_T defines the bits that can be
  31157. + * combined.
  31158. + */
  31159. + u32 set;
  31160. +
  31161. + /** Describes the display output device, with 0 typically
  31162. + * being a directly connected LCD display. The actual values
  31163. + * will depend on the hardware. Code using hard-wired numbers
  31164. + * (e.g. 2) is certain to fail.
  31165. + */
  31166. +
  31167. + u32 display_num;
  31168. + /** Indicates that we are using the full device screen area,
  31169. + * rather than a window of the display. If zero, then
  31170. + * dest_rect is used to specify a region of the display to
  31171. + * use.
  31172. + */
  31173. +
  31174. + s32 fullscreen;
  31175. + /** Indicates any rotation or flipping used to map frames onto
  31176. + * the natural display orientation.
  31177. + */
  31178. + u32 transform; /* enum mmal_parameter_displaytransform */
  31179. +
  31180. + /** Where to display the frame within the screen, if
  31181. + * fullscreen is zero.
  31182. + */
  31183. + struct vchiq_mmal_rect dest_rect;
  31184. +
  31185. + /** Indicates which area of the frame to display. If all
  31186. + * values are zero, the whole frame will be used.
  31187. + */
  31188. + struct vchiq_mmal_rect src_rect;
  31189. +
  31190. + /** If set to non-zero, indicates that any display scaling
  31191. + * should disregard the aspect ratio of the frame region being
  31192. + * displayed.
  31193. + */
  31194. + s32 noaspect;
  31195. +
  31196. + /** Indicates how the image should be scaled to fit the
  31197. + * display. \code MMAL_DISPLAY_MODE_FILL \endcode indicates
  31198. + * that the image should fill the screen by potentially
  31199. + * cropping the frames. Setting \code mode \endcode to \code
  31200. + * MMAL_DISPLAY_MODE_LETTERBOX \endcode indicates that all the
  31201. + * source region should be displayed and black bars added if
  31202. + * necessary.
  31203. + */
  31204. + u32 mode; /* enum mmal_parameter_displaymode */
  31205. +
  31206. + /** If non-zero, defines the width of a source pixel relative
  31207. + * to \code pixel_y \endcode. If zero, then pixels default to
  31208. + * being square.
  31209. + */
  31210. + u32 pixel_x;
  31211. +
  31212. + /** If non-zero, defines the height of a source pixel relative
  31213. + * to \code pixel_x \endcode. If zero, then pixels default to
  31214. + * being square.
  31215. + */
  31216. + u32 pixel_y;
  31217. +
  31218. + /** Sets the relative depth of the images, with greater values
  31219. + * being in front of smaller values.
  31220. + */
  31221. + u32 layer;
  31222. +
  31223. + /** Set to non-zero to ensure copy protection is used on
  31224. + * output.
  31225. + */
  31226. + s32 copyprotect_required;
  31227. +
  31228. + /** Level of opacity of the layer, where zero is fully
  31229. + * transparent and 255 is fully opaque.
  31230. + */
  31231. + u32 alpha;
  31232. +};
  31233. +
  31234. +#define MMAL_MAX_IMAGEFX_PARAMETERS 5
  31235. +
  31236. +struct mmal_parameter_imagefx_parameters {
  31237. + enum mmal_parameter_imagefx effect;
  31238. + u32 num_effect_params;
  31239. + u32 effect_parameter[MMAL_MAX_IMAGEFX_PARAMETERS];
  31240. +};
  31241. diff -Nur linux-3.18.8/drivers/media/platform/bcm2835/mmal-vchiq.c linux-rpi/drivers/media/platform/bcm2835/mmal-vchiq.c
  31242. --- linux-3.18.8/drivers/media/platform/bcm2835/mmal-vchiq.c 1970-01-01 01:00:00.000000000 +0100
  31243. +++ linux-rpi/drivers/media/platform/bcm2835/mmal-vchiq.c 2015-03-05 14:40:13.981715822 +0100
  31244. @@ -0,0 +1,1916 @@
  31245. +/*
  31246. + * Broadcom BM2835 V4L2 driver
  31247. + *
  31248. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  31249. + *
  31250. + * This file is subject to the terms and conditions of the GNU General Public
  31251. + * License. See the file COPYING in the main directory of this archive
  31252. + * for more details.
  31253. + *
  31254. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  31255. + * Dave Stevenson <dsteve@broadcom.com>
  31256. + * Simon Mellor <simellor@broadcom.com>
  31257. + * Luke Diamand <luked@broadcom.com>
  31258. + *
  31259. + * V4L2 driver MMAL vchiq interface code
  31260. + */
  31261. +
  31262. +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  31263. +
  31264. +#include <linux/errno.h>
  31265. +#include <linux/kernel.h>
  31266. +#include <linux/mutex.h>
  31267. +#include <linux/mm.h>
  31268. +#include <linux/slab.h>
  31269. +#include <linux/completion.h>
  31270. +#include <linux/vmalloc.h>
  31271. +#include <asm/cacheflush.h>
  31272. +#include <media/videobuf2-vmalloc.h>
  31273. +
  31274. +#include "mmal-common.h"
  31275. +#include "mmal-vchiq.h"
  31276. +#include "mmal-msg.h"
  31277. +
  31278. +#define USE_VCHIQ_ARM
  31279. +#include "interface/vchi/vchi.h"
  31280. +
  31281. +/* maximum number of components supported */
  31282. +#define VCHIQ_MMAL_MAX_COMPONENTS 4
  31283. +
  31284. +/*#define FULL_MSG_DUMP 1*/
  31285. +
  31286. +#ifdef DEBUG
  31287. +static const char *const msg_type_names[] = {
  31288. + "UNKNOWN",
  31289. + "QUIT",
  31290. + "SERVICE_CLOSED",
  31291. + "GET_VERSION",
  31292. + "COMPONENT_CREATE",
  31293. + "COMPONENT_DESTROY",
  31294. + "COMPONENT_ENABLE",
  31295. + "COMPONENT_DISABLE",
  31296. + "PORT_INFO_GET",
  31297. + "PORT_INFO_SET",
  31298. + "PORT_ACTION",
  31299. + "BUFFER_FROM_HOST",
  31300. + "BUFFER_TO_HOST",
  31301. + "GET_STATS",
  31302. + "PORT_PARAMETER_SET",
  31303. + "PORT_PARAMETER_GET",
  31304. + "EVENT_TO_HOST",
  31305. + "GET_CORE_STATS_FOR_PORT",
  31306. + "OPAQUE_ALLOCATOR",
  31307. + "CONSUME_MEM",
  31308. + "LMK",
  31309. + "OPAQUE_ALLOCATOR_DESC",
  31310. + "DRM_GET_LHS32",
  31311. + "DRM_GET_TIME",
  31312. + "BUFFER_FROM_HOST_ZEROLEN",
  31313. + "PORT_FLUSH",
  31314. + "HOST_LOG",
  31315. +};
  31316. +#endif
  31317. +
  31318. +static const char *const port_action_type_names[] = {
  31319. + "UNKNOWN",
  31320. + "ENABLE",
  31321. + "DISABLE",
  31322. + "FLUSH",
  31323. + "CONNECT",
  31324. + "DISCONNECT",
  31325. + "SET_REQUIREMENTS",
  31326. +};
  31327. +
  31328. +#if defined(DEBUG)
  31329. +#if defined(FULL_MSG_DUMP)
  31330. +#define DBG_DUMP_MSG(MSG, MSG_LEN, TITLE) \
  31331. + do { \
  31332. + pr_debug(TITLE" type:%s(%d) length:%d\n", \
  31333. + msg_type_names[(MSG)->h.type], \
  31334. + (MSG)->h.type, (MSG_LEN)); \
  31335. + print_hex_dump(KERN_DEBUG, "<<h: ", DUMP_PREFIX_OFFSET, \
  31336. + 16, 4, (MSG), \
  31337. + sizeof(struct mmal_msg_header), 1); \
  31338. + print_hex_dump(KERN_DEBUG, "<<p: ", DUMP_PREFIX_OFFSET, \
  31339. + 16, 4, \
  31340. + ((u8 *)(MSG)) + sizeof(struct mmal_msg_header),\
  31341. + (MSG_LEN) - sizeof(struct mmal_msg_header), 1); \
  31342. + } while (0)
  31343. +#else
  31344. +#define DBG_DUMP_MSG(MSG, MSG_LEN, TITLE) \
  31345. + { \
  31346. + pr_debug(TITLE" type:%s(%d) length:%d\n", \
  31347. + msg_type_names[(MSG)->h.type], \
  31348. + (MSG)->h.type, (MSG_LEN)); \
  31349. + }
  31350. +#endif
  31351. +#else
  31352. +#define DBG_DUMP_MSG(MSG, MSG_LEN, TITLE)
  31353. +#endif
  31354. +
  31355. +/* normal message context */
  31356. +struct mmal_msg_context {
  31357. + union {
  31358. + struct {
  31359. + /* work struct for defered callback - must come first */
  31360. + struct work_struct work;
  31361. + /* mmal instance */
  31362. + struct vchiq_mmal_instance *instance;
  31363. + /* mmal port */
  31364. + struct vchiq_mmal_port *port;
  31365. + /* actual buffer used to store bulk reply */
  31366. + struct mmal_buffer *buffer;
  31367. + /* amount of buffer used */
  31368. + unsigned long buffer_used;
  31369. + /* MMAL buffer flags */
  31370. + u32 mmal_flags;
  31371. + /* Presentation and Decode timestamps */
  31372. + s64 pts;
  31373. + s64 dts;
  31374. +
  31375. + int status; /* context status */
  31376. +
  31377. + } bulk; /* bulk data */
  31378. +
  31379. + struct {
  31380. + /* message handle to release */
  31381. + VCHI_HELD_MSG_T msg_handle;
  31382. + /* pointer to received message */
  31383. + struct mmal_msg *msg;
  31384. + /* received message length */
  31385. + u32 msg_len;
  31386. + /* completion upon reply */
  31387. + struct completion cmplt;
  31388. + } sync; /* synchronous response */
  31389. + } u;
  31390. +
  31391. +};
  31392. +
  31393. +struct vchiq_mmal_instance {
  31394. + VCHI_SERVICE_HANDLE_T handle;
  31395. +
  31396. + /* ensure serialised access to service */
  31397. + struct mutex vchiq_mutex;
  31398. +
  31399. + /* ensure serialised access to bulk operations */
  31400. + struct mutex bulk_mutex;
  31401. +
  31402. + /* vmalloc page to receive scratch bulk xfers into */
  31403. + void *bulk_scratch;
  31404. +
  31405. + /* component to use next */
  31406. + int component_idx;
  31407. + struct vchiq_mmal_component component[VCHIQ_MMAL_MAX_COMPONENTS];
  31408. +};
  31409. +
  31410. +static struct mmal_msg_context *get_msg_context(struct vchiq_mmal_instance
  31411. + *instance)
  31412. +{
  31413. + struct mmal_msg_context *msg_context;
  31414. +
  31415. + /* todo: should this be allocated from a pool to avoid kmalloc */
  31416. + msg_context = kmalloc(sizeof(*msg_context), GFP_KERNEL);
  31417. + memset(msg_context, 0, sizeof(*msg_context));
  31418. +
  31419. + return msg_context;
  31420. +}
  31421. +
  31422. +static void release_msg_context(struct mmal_msg_context *msg_context)
  31423. +{
  31424. + kfree(msg_context);
  31425. +}
  31426. +
  31427. +/* deals with receipt of event to host message */
  31428. +static void event_to_host_cb(struct vchiq_mmal_instance *instance,
  31429. + struct mmal_msg *msg, u32 msg_len)
  31430. +{
  31431. + pr_debug("unhandled event\n");
  31432. + pr_debug("component:%p port type:%d num:%d cmd:0x%x length:%d\n",
  31433. + msg->u.event_to_host.client_component,
  31434. + msg->u.event_to_host.port_type,
  31435. + msg->u.event_to_host.port_num,
  31436. + msg->u.event_to_host.cmd, msg->u.event_to_host.length);
  31437. +}
  31438. +
  31439. +/* workqueue scheduled callback
  31440. + *
  31441. + * we do this because it is important we do not call any other vchiq
  31442. + * sync calls from witin the message delivery thread
  31443. + */
  31444. +static void buffer_work_cb(struct work_struct *work)
  31445. +{
  31446. + struct mmal_msg_context *msg_context = (struct mmal_msg_context *)work;
  31447. +
  31448. + msg_context->u.bulk.port->buffer_cb(msg_context->u.bulk.instance,
  31449. + msg_context->u.bulk.port,
  31450. + msg_context->u.bulk.status,
  31451. + msg_context->u.bulk.buffer,
  31452. + msg_context->u.bulk.buffer_used,
  31453. + msg_context->u.bulk.mmal_flags,
  31454. + msg_context->u.bulk.dts,
  31455. + msg_context->u.bulk.pts);
  31456. +
  31457. + /* release message context */
  31458. + release_msg_context(msg_context);
  31459. +}
  31460. +
  31461. +/* enqueue a bulk receive for a given message context */
  31462. +static int bulk_receive(struct vchiq_mmal_instance *instance,
  31463. + struct mmal_msg *msg,
  31464. + struct mmal_msg_context *msg_context)
  31465. +{
  31466. + unsigned long rd_len;
  31467. + unsigned long flags = 0;
  31468. + int ret;
  31469. +
  31470. + /* bulk mutex stops other bulk operations while we have a
  31471. + * receive in progress - released in callback
  31472. + */
  31473. + ret = mutex_lock_interruptible(&instance->bulk_mutex);
  31474. + if (ret != 0)
  31475. + return ret;
  31476. +
  31477. + rd_len = msg->u.buffer_from_host.buffer_header.length;
  31478. +
  31479. + /* take buffer from queue */
  31480. + spin_lock_irqsave(&msg_context->u.bulk.port->slock, flags);
  31481. + if (list_empty(&msg_context->u.bulk.port->buffers)) {
  31482. + spin_unlock_irqrestore(&msg_context->u.bulk.port->slock, flags);
  31483. + pr_err("buffer list empty trying to submit bulk receive\n");
  31484. +
  31485. + /* todo: this is a serious error, we should never have
  31486. + * commited a buffer_to_host operation to the mmal
  31487. + * port without the buffer to back it up (underflow
  31488. + * handling) and there is no obvious way to deal with
  31489. + * this - how is the mmal servie going to react when
  31490. + * we fail to do the xfer and reschedule a buffer when
  31491. + * it arrives? perhaps a starved flag to indicate a
  31492. + * waiting bulk receive?
  31493. + */
  31494. +
  31495. + mutex_unlock(&instance->bulk_mutex);
  31496. +
  31497. + return -EINVAL;
  31498. + }
  31499. +
  31500. + msg_context->u.bulk.buffer =
  31501. + list_entry(msg_context->u.bulk.port->buffers.next,
  31502. + struct mmal_buffer, list);
  31503. + list_del(&msg_context->u.bulk.buffer->list);
  31504. +
  31505. + spin_unlock_irqrestore(&msg_context->u.bulk.port->slock, flags);
  31506. +
  31507. + /* ensure we do not overrun the available buffer */
  31508. + if (rd_len > msg_context->u.bulk.buffer->buffer_size) {
  31509. + rd_len = msg_context->u.bulk.buffer->buffer_size;
  31510. + pr_warn("short read as not enough receive buffer space\n");
  31511. + /* todo: is this the correct response, what happens to
  31512. + * the rest of the message data?
  31513. + */
  31514. + }
  31515. +
  31516. + /* store length */
  31517. + msg_context->u.bulk.buffer_used = rd_len;
  31518. + msg_context->u.bulk.mmal_flags =
  31519. + msg->u.buffer_from_host.buffer_header.flags;
  31520. + msg_context->u.bulk.dts = msg->u.buffer_from_host.buffer_header.dts;
  31521. + msg_context->u.bulk.pts = msg->u.buffer_from_host.buffer_header.pts;
  31522. +
  31523. + // only need to flush L1 cache here, as VCHIQ takes care of the L2
  31524. + // cache.
  31525. + __cpuc_flush_dcache_area(msg_context->u.bulk.buffer->buffer, rd_len);
  31526. +
  31527. + /* queue the bulk submission */
  31528. + vchi_service_use(instance->handle);
  31529. + ret = vchi_bulk_queue_receive(instance->handle,
  31530. + msg_context->u.bulk.buffer->buffer,
  31531. + /* Actual receive needs to be a multiple
  31532. + * of 4 bytes
  31533. + */
  31534. + (rd_len + 3) & ~3,
  31535. + VCHI_FLAGS_CALLBACK_WHEN_OP_COMPLETE |
  31536. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED,
  31537. + msg_context);
  31538. +
  31539. + vchi_service_release(instance->handle);
  31540. +
  31541. + if (ret != 0) {
  31542. + /* callback will not be clearing the mutex */
  31543. + mutex_unlock(&instance->bulk_mutex);
  31544. + }
  31545. +
  31546. + return ret;
  31547. +}
  31548. +
  31549. +/* enque a dummy bulk receive for a given message context */
  31550. +static int dummy_bulk_receive(struct vchiq_mmal_instance *instance,
  31551. + struct mmal_msg_context *msg_context)
  31552. +{
  31553. + int ret;
  31554. +
  31555. + /* bulk mutex stops other bulk operations while we have a
  31556. + * receive in progress - released in callback
  31557. + */
  31558. + ret = mutex_lock_interruptible(&instance->bulk_mutex);
  31559. + if (ret != 0)
  31560. + return ret;
  31561. +
  31562. + /* zero length indicates this was a dummy transfer */
  31563. + msg_context->u.bulk.buffer_used = 0;
  31564. +
  31565. + /* queue the bulk submission */
  31566. + vchi_service_use(instance->handle);
  31567. +
  31568. + ret = vchi_bulk_queue_receive(instance->handle,
  31569. + instance->bulk_scratch,
  31570. + 8,
  31571. + VCHI_FLAGS_CALLBACK_WHEN_OP_COMPLETE |
  31572. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED,
  31573. + msg_context);
  31574. +
  31575. + vchi_service_release(instance->handle);
  31576. +
  31577. + if (ret != 0) {
  31578. + /* callback will not be clearing the mutex */
  31579. + mutex_unlock(&instance->bulk_mutex);
  31580. + }
  31581. +
  31582. + return ret;
  31583. +}
  31584. +
  31585. +/* data in message, memcpy from packet into output buffer */
  31586. +static int inline_receive(struct vchiq_mmal_instance *instance,
  31587. + struct mmal_msg *msg,
  31588. + struct mmal_msg_context *msg_context)
  31589. +{
  31590. + unsigned long flags = 0;
  31591. +
  31592. + /* take buffer from queue */
  31593. + spin_lock_irqsave(&msg_context->u.bulk.port->slock, flags);
  31594. + if (list_empty(&msg_context->u.bulk.port->buffers)) {
  31595. + spin_unlock_irqrestore(&msg_context->u.bulk.port->slock, flags);
  31596. + pr_err("buffer list empty trying to receive inline\n");
  31597. +
  31598. + /* todo: this is a serious error, we should never have
  31599. + * commited a buffer_to_host operation to the mmal
  31600. + * port without the buffer to back it up (with
  31601. + * underflow handling) and there is no obvious way to
  31602. + * deal with this. Less bad than the bulk case as we
  31603. + * can just drop this on the floor but...unhelpful
  31604. + */
  31605. + return -EINVAL;
  31606. + }
  31607. +
  31608. + msg_context->u.bulk.buffer =
  31609. + list_entry(msg_context->u.bulk.port->buffers.next,
  31610. + struct mmal_buffer, list);
  31611. + list_del(&msg_context->u.bulk.buffer->list);
  31612. +
  31613. + spin_unlock_irqrestore(&msg_context->u.bulk.port->slock, flags);
  31614. +
  31615. + memcpy(msg_context->u.bulk.buffer->buffer,
  31616. + msg->u.buffer_from_host.short_data,
  31617. + msg->u.buffer_from_host.payload_in_message);
  31618. +
  31619. + msg_context->u.bulk.buffer_used =
  31620. + msg->u.buffer_from_host.payload_in_message;
  31621. +
  31622. + return 0;
  31623. +}
  31624. +
  31625. +/* queue the buffer availability with MMAL_MSG_TYPE_BUFFER_FROM_HOST */
  31626. +static int
  31627. +buffer_from_host(struct vchiq_mmal_instance *instance,
  31628. + struct vchiq_mmal_port *port, struct mmal_buffer *buf)
  31629. +{
  31630. + struct mmal_msg_context *msg_context;
  31631. + struct mmal_msg m;
  31632. + int ret;
  31633. +
  31634. + pr_debug("instance:%p buffer:%p\n", instance->handle, buf);
  31635. +
  31636. + /* bulk mutex stops other bulk operations while we
  31637. + * have a receive in progress
  31638. + */
  31639. + if (mutex_lock_interruptible(&instance->bulk_mutex))
  31640. + return -EINTR;
  31641. +
  31642. + /* get context */
  31643. + msg_context = get_msg_context(instance);
  31644. + if (msg_context == NULL)
  31645. + return -ENOMEM;
  31646. +
  31647. + /* store bulk message context for when data arrives */
  31648. + msg_context->u.bulk.instance = instance;
  31649. + msg_context->u.bulk.port = port;
  31650. + msg_context->u.bulk.buffer = NULL; /* not valid until bulk xfer */
  31651. + msg_context->u.bulk.buffer_used = 0;
  31652. +
  31653. + /* initialise work structure ready to schedule callback */
  31654. + INIT_WORK(&msg_context->u.bulk.work, buffer_work_cb);
  31655. +
  31656. + /* prep the buffer from host message */
  31657. + memset(&m, 0xbc, sizeof(m)); /* just to make debug clearer */
  31658. +
  31659. + m.h.type = MMAL_MSG_TYPE_BUFFER_FROM_HOST;
  31660. + m.h.magic = MMAL_MAGIC;
  31661. + m.h.context = msg_context;
  31662. + m.h.status = 0;
  31663. +
  31664. + /* drvbuf is our private data passed back */
  31665. + m.u.buffer_from_host.drvbuf.magic = MMAL_MAGIC;
  31666. + m.u.buffer_from_host.drvbuf.component_handle = port->component->handle;
  31667. + m.u.buffer_from_host.drvbuf.port_handle = port->handle;
  31668. + m.u.buffer_from_host.drvbuf.client_context = msg_context;
  31669. +
  31670. + /* buffer header */
  31671. + m.u.buffer_from_host.buffer_header.cmd = 0;
  31672. + m.u.buffer_from_host.buffer_header.data = buf->buffer;
  31673. + m.u.buffer_from_host.buffer_header.alloc_size = buf->buffer_size;
  31674. + m.u.buffer_from_host.buffer_header.length = 0; /* nothing used yet */
  31675. + m.u.buffer_from_host.buffer_header.offset = 0; /* no offset */
  31676. + m.u.buffer_from_host.buffer_header.flags = 0; /* no flags */
  31677. + m.u.buffer_from_host.buffer_header.pts = MMAL_TIME_UNKNOWN;
  31678. + m.u.buffer_from_host.buffer_header.dts = MMAL_TIME_UNKNOWN;
  31679. +
  31680. + /* clear buffer type sepecific data */
  31681. + memset(&m.u.buffer_from_host.buffer_header_type_specific, 0,
  31682. + sizeof(m.u.buffer_from_host.buffer_header_type_specific));
  31683. +
  31684. + /* no payload in message */
  31685. + m.u.buffer_from_host.payload_in_message = 0;
  31686. +
  31687. + vchi_service_use(instance->handle);
  31688. +
  31689. + ret = vchi_msg_queue(instance->handle, &m,
  31690. + sizeof(struct mmal_msg_header) +
  31691. + sizeof(m.u.buffer_from_host),
  31692. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  31693. +
  31694. + if (ret != 0) {
  31695. + release_msg_context(msg_context);
  31696. + /* todo: is this correct error value? */
  31697. + }
  31698. +
  31699. + vchi_service_release(instance->handle);
  31700. +
  31701. + mutex_unlock(&instance->bulk_mutex);
  31702. +
  31703. + return ret;
  31704. +}
  31705. +
  31706. +/* submit a buffer to the mmal sevice
  31707. + *
  31708. + * the buffer_from_host uses size data from the ports next available
  31709. + * mmal_buffer and deals with there being no buffer available by
  31710. + * incrementing the underflow for later
  31711. + */
  31712. +static int port_buffer_from_host(struct vchiq_mmal_instance *instance,
  31713. + struct vchiq_mmal_port *port)
  31714. +{
  31715. + int ret;
  31716. + struct mmal_buffer *buf;
  31717. + unsigned long flags = 0;
  31718. +
  31719. + if (!port->enabled)
  31720. + return -EINVAL;
  31721. +
  31722. + /* peek buffer from queue */
  31723. + spin_lock_irqsave(&port->slock, flags);
  31724. + if (list_empty(&port->buffers)) {
  31725. + port->buffer_underflow++;
  31726. + spin_unlock_irqrestore(&port->slock, flags);
  31727. + return -ENOSPC;
  31728. + }
  31729. +
  31730. + buf = list_entry(port->buffers.next, struct mmal_buffer, list);
  31731. +
  31732. + spin_unlock_irqrestore(&port->slock, flags);
  31733. +
  31734. + /* issue buffer to mmal service */
  31735. + ret = buffer_from_host(instance, port, buf);
  31736. + if (ret) {
  31737. + pr_err("adding buffer header failed\n");
  31738. + /* todo: how should this be dealt with */
  31739. + }
  31740. +
  31741. + return ret;
  31742. +}
  31743. +
  31744. +/* deals with receipt of buffer to host message */
  31745. +static void buffer_to_host_cb(struct vchiq_mmal_instance *instance,
  31746. + struct mmal_msg *msg, u32 msg_len)
  31747. +{
  31748. + struct mmal_msg_context *msg_context;
  31749. +
  31750. + pr_debug("buffer_to_host_cb: instance:%p msg:%p msg_len:%d\n",
  31751. + instance, msg, msg_len);
  31752. +
  31753. + if (msg->u.buffer_from_host.drvbuf.magic == MMAL_MAGIC) {
  31754. + msg_context = msg->u.buffer_from_host.drvbuf.client_context;
  31755. + } else {
  31756. + pr_err("MMAL_MSG_TYPE_BUFFER_TO_HOST with bad magic\n");
  31757. + return;
  31758. + }
  31759. +
  31760. + if (msg->h.status != MMAL_MSG_STATUS_SUCCESS) {
  31761. + /* message reception had an error */
  31762. + pr_warn("error %d in reply\n", msg->h.status);
  31763. +
  31764. + msg_context->u.bulk.status = msg->h.status;
  31765. +
  31766. + } else if (msg->u.buffer_from_host.buffer_header.length == 0) {
  31767. + /* empty buffer */
  31768. + if (msg->u.buffer_from_host.buffer_header.flags &
  31769. + MMAL_BUFFER_HEADER_FLAG_EOS) {
  31770. + msg_context->u.bulk.status =
  31771. + dummy_bulk_receive(instance, msg_context);
  31772. + if (msg_context->u.bulk.status == 0)
  31773. + return; /* successful bulk submission, bulk
  31774. + * completion will trigger callback
  31775. + */
  31776. + } else {
  31777. + /* do callback with empty buffer - not EOS though */
  31778. + msg_context->u.bulk.status = 0;
  31779. + msg_context->u.bulk.buffer_used = 0;
  31780. + }
  31781. + } else if (msg->u.buffer_from_host.payload_in_message == 0) {
  31782. + /* data is not in message, queue a bulk receive */
  31783. + msg_context->u.bulk.status =
  31784. + bulk_receive(instance, msg, msg_context);
  31785. + if (msg_context->u.bulk.status == 0)
  31786. + return; /* successful bulk submission, bulk
  31787. + * completion will trigger callback
  31788. + */
  31789. +
  31790. + /* failed to submit buffer, this will end badly */
  31791. + pr_err("error %d on bulk submission\n",
  31792. + msg_context->u.bulk.status);
  31793. +
  31794. + } else if (msg->u.buffer_from_host.payload_in_message <=
  31795. + MMAL_VC_SHORT_DATA) {
  31796. + /* data payload within message */
  31797. + msg_context->u.bulk.status = inline_receive(instance, msg,
  31798. + msg_context);
  31799. + } else {
  31800. + pr_err("message with invalid short payload\n");
  31801. +
  31802. + /* signal error */
  31803. + msg_context->u.bulk.status = -EINVAL;
  31804. + msg_context->u.bulk.buffer_used =
  31805. + msg->u.buffer_from_host.payload_in_message;
  31806. + }
  31807. +
  31808. + /* replace the buffer header */
  31809. + port_buffer_from_host(instance, msg_context->u.bulk.port);
  31810. +
  31811. + /* schedule the port callback */
  31812. + schedule_work(&msg_context->u.bulk.work);
  31813. +}
  31814. +
  31815. +static void bulk_receive_cb(struct vchiq_mmal_instance *instance,
  31816. + struct mmal_msg_context *msg_context)
  31817. +{
  31818. + /* bulk receive operation complete */
  31819. + mutex_unlock(&msg_context->u.bulk.instance->bulk_mutex);
  31820. +
  31821. + /* replace the buffer header */
  31822. + port_buffer_from_host(msg_context->u.bulk.instance,
  31823. + msg_context->u.bulk.port);
  31824. +
  31825. + msg_context->u.bulk.status = 0;
  31826. +
  31827. + /* schedule the port callback */
  31828. + schedule_work(&msg_context->u.bulk.work);
  31829. +}
  31830. +
  31831. +static void bulk_abort_cb(struct vchiq_mmal_instance *instance,
  31832. + struct mmal_msg_context *msg_context)
  31833. +{
  31834. + pr_err("%s: bulk ABORTED msg_context:%p\n", __func__, msg_context);
  31835. +
  31836. + /* bulk receive operation complete */
  31837. + mutex_unlock(&msg_context->u.bulk.instance->bulk_mutex);
  31838. +
  31839. + /* replace the buffer header */
  31840. + port_buffer_from_host(msg_context->u.bulk.instance,
  31841. + msg_context->u.bulk.port);
  31842. +
  31843. + msg_context->u.bulk.status = -EINTR;
  31844. +
  31845. + schedule_work(&msg_context->u.bulk.work);
  31846. +}
  31847. +
  31848. +/* incoming event service callback */
  31849. +static void service_callback(void *param,
  31850. + const VCHI_CALLBACK_REASON_T reason,
  31851. + void *bulk_ctx)
  31852. +{
  31853. + struct vchiq_mmal_instance *instance = param;
  31854. + int status;
  31855. + u32 msg_len;
  31856. + struct mmal_msg *msg;
  31857. + VCHI_HELD_MSG_T msg_handle;
  31858. +
  31859. + if (!instance) {
  31860. + pr_err("Message callback passed NULL instance\n");
  31861. + return;
  31862. + }
  31863. +
  31864. + switch (reason) {
  31865. + case VCHI_CALLBACK_MSG_AVAILABLE:
  31866. + status = vchi_msg_hold(instance->handle, (void **)&msg,
  31867. + &msg_len, VCHI_FLAGS_NONE, &msg_handle);
  31868. + if (status) {
  31869. + pr_err("Unable to dequeue a message (%d)\n", status);
  31870. + break;
  31871. + }
  31872. +
  31873. + DBG_DUMP_MSG(msg, msg_len, "<<< reply message");
  31874. +
  31875. + /* handling is different for buffer messages */
  31876. + switch (msg->h.type) {
  31877. +
  31878. + case MMAL_MSG_TYPE_BUFFER_FROM_HOST:
  31879. + vchi_held_msg_release(&msg_handle);
  31880. + break;
  31881. +
  31882. + case MMAL_MSG_TYPE_EVENT_TO_HOST:
  31883. + event_to_host_cb(instance, msg, msg_len);
  31884. + vchi_held_msg_release(&msg_handle);
  31885. +
  31886. + break;
  31887. +
  31888. + case MMAL_MSG_TYPE_BUFFER_TO_HOST:
  31889. + buffer_to_host_cb(instance, msg, msg_len);
  31890. + vchi_held_msg_release(&msg_handle);
  31891. + break;
  31892. +
  31893. + default:
  31894. + /* messages dependant on header context to complete */
  31895. +
  31896. + /* todo: the msg.context really ought to be sanity
  31897. + * checked before we just use it, afaict it comes back
  31898. + * and is used raw from the videocore. Perhaps it
  31899. + * should be verified the address lies in the kernel
  31900. + * address space.
  31901. + */
  31902. + if (msg->h.context == NULL) {
  31903. + pr_err("received message context was null!\n");
  31904. + vchi_held_msg_release(&msg_handle);
  31905. + break;
  31906. + }
  31907. +
  31908. + /* fill in context values */
  31909. + msg->h.context->u.sync.msg_handle = msg_handle;
  31910. + msg->h.context->u.sync.msg = msg;
  31911. + msg->h.context->u.sync.msg_len = msg_len;
  31912. +
  31913. + /* todo: should this check (completion_done()
  31914. + * == 1) for no one waiting? or do we need a
  31915. + * flag to tell us the completion has been
  31916. + * interrupted so we can free the message and
  31917. + * its context. This probably also solves the
  31918. + * message arriving after interruption todo
  31919. + * below
  31920. + */
  31921. +
  31922. + /* complete message so caller knows it happened */
  31923. + complete(&msg->h.context->u.sync.cmplt);
  31924. + break;
  31925. + }
  31926. +
  31927. + break;
  31928. +
  31929. + case VCHI_CALLBACK_BULK_RECEIVED:
  31930. + bulk_receive_cb(instance, bulk_ctx);
  31931. + break;
  31932. +
  31933. + case VCHI_CALLBACK_BULK_RECEIVE_ABORTED:
  31934. + bulk_abort_cb(instance, bulk_ctx);
  31935. + break;
  31936. +
  31937. + case VCHI_CALLBACK_SERVICE_CLOSED:
  31938. + /* TODO: consider if this requires action if received when
  31939. + * driver is not explicitly closing the service
  31940. + */
  31941. + break;
  31942. +
  31943. + default:
  31944. + pr_err("Received unhandled message reason %d\n", reason);
  31945. + break;
  31946. + }
  31947. +}
  31948. +
  31949. +static int send_synchronous_mmal_msg(struct vchiq_mmal_instance *instance,
  31950. + struct mmal_msg *msg,
  31951. + unsigned int payload_len,
  31952. + struct mmal_msg **msg_out,
  31953. + VCHI_HELD_MSG_T *msg_handle_out)
  31954. +{
  31955. + struct mmal_msg_context msg_context;
  31956. + int ret;
  31957. +
  31958. + /* payload size must not cause message to exceed max size */
  31959. + if (payload_len >
  31960. + (MMAL_MSG_MAX_SIZE - sizeof(struct mmal_msg_header))) {
  31961. + pr_err("payload length %d exceeds max:%d\n", payload_len,
  31962. + (MMAL_MSG_MAX_SIZE - sizeof(struct mmal_msg_header)));
  31963. + return -EINVAL;
  31964. + }
  31965. +
  31966. + init_completion(&msg_context.u.sync.cmplt);
  31967. +
  31968. + msg->h.magic = MMAL_MAGIC;
  31969. + msg->h.context = &msg_context;
  31970. + msg->h.status = 0;
  31971. +
  31972. + DBG_DUMP_MSG(msg, (sizeof(struct mmal_msg_header) + payload_len),
  31973. + ">>> sync message");
  31974. +
  31975. + vchi_service_use(instance->handle);
  31976. +
  31977. + ret = vchi_msg_queue(instance->handle,
  31978. + msg,
  31979. + sizeof(struct mmal_msg_header) + payload_len,
  31980. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  31981. +
  31982. + vchi_service_release(instance->handle);
  31983. +
  31984. + if (ret) {
  31985. + pr_err("error %d queuing message\n", ret);
  31986. + return ret;
  31987. + }
  31988. +
  31989. + ret = wait_for_completion_timeout(&msg_context.u.sync.cmplt, 3*HZ);
  31990. + if (ret <= 0) {
  31991. + pr_err("error %d waiting for sync completion\n", ret);
  31992. + if (ret == 0)
  31993. + ret = -ETIME;
  31994. + /* todo: what happens if the message arrives after aborting */
  31995. + return ret;
  31996. + }
  31997. +
  31998. + *msg_out = msg_context.u.sync.msg;
  31999. + *msg_handle_out = msg_context.u.sync.msg_handle;
  32000. +
  32001. + return 0;
  32002. +}
  32003. +
  32004. +static void dump_port_info(struct vchiq_mmal_port *port)
  32005. +{
  32006. + pr_debug("port handle:0x%x enabled:%d\n", port->handle, port->enabled);
  32007. +
  32008. + pr_debug("buffer minimum num:%d size:%d align:%d\n",
  32009. + port->minimum_buffer.num,
  32010. + port->minimum_buffer.size, port->minimum_buffer.alignment);
  32011. +
  32012. + pr_debug("buffer recommended num:%d size:%d align:%d\n",
  32013. + port->recommended_buffer.num,
  32014. + port->recommended_buffer.size,
  32015. + port->recommended_buffer.alignment);
  32016. +
  32017. + pr_debug("buffer current values num:%d size:%d align:%d\n",
  32018. + port->current_buffer.num,
  32019. + port->current_buffer.size, port->current_buffer.alignment);
  32020. +
  32021. + pr_debug("elementry stream: type:%d encoding:0x%x varient:0x%x\n",
  32022. + port->format.type,
  32023. + port->format.encoding, port->format.encoding_variant);
  32024. +
  32025. + pr_debug(" bitrate:%d flags:0x%x\n",
  32026. + port->format.bitrate, port->format.flags);
  32027. +
  32028. + if (port->format.type == MMAL_ES_TYPE_VIDEO) {
  32029. + pr_debug
  32030. + ("es video format: width:%d height:%d colourspace:0x%x\n",
  32031. + port->es.video.width, port->es.video.height,
  32032. + port->es.video.color_space);
  32033. +
  32034. + pr_debug(" : crop xywh %d,%d,%d,%d\n",
  32035. + port->es.video.crop.x,
  32036. + port->es.video.crop.y,
  32037. + port->es.video.crop.width, port->es.video.crop.height);
  32038. + pr_debug(" : framerate %d/%d aspect %d/%d\n",
  32039. + port->es.video.frame_rate.num,
  32040. + port->es.video.frame_rate.den,
  32041. + port->es.video.par.num, port->es.video.par.den);
  32042. + }
  32043. +}
  32044. +
  32045. +static void port_to_mmal_msg(struct vchiq_mmal_port *port, struct mmal_port *p)
  32046. +{
  32047. +
  32048. + /* todo do readonly fields need setting at all? */
  32049. + p->type = port->type;
  32050. + p->index = port->index;
  32051. + p->index_all = 0;
  32052. + p->is_enabled = port->enabled;
  32053. + p->buffer_num_min = port->minimum_buffer.num;
  32054. + p->buffer_size_min = port->minimum_buffer.size;
  32055. + p->buffer_alignment_min = port->minimum_buffer.alignment;
  32056. + p->buffer_num_recommended = port->recommended_buffer.num;
  32057. + p->buffer_size_recommended = port->recommended_buffer.size;
  32058. +
  32059. + /* only three writable fields in a port */
  32060. + p->buffer_num = port->current_buffer.num;
  32061. + p->buffer_size = port->current_buffer.size;
  32062. + p->userdata = port;
  32063. +}
  32064. +
  32065. +static int port_info_set(struct vchiq_mmal_instance *instance,
  32066. + struct vchiq_mmal_port *port)
  32067. +{
  32068. + int ret;
  32069. + struct mmal_msg m;
  32070. + struct mmal_msg *rmsg;
  32071. + VCHI_HELD_MSG_T rmsg_handle;
  32072. +
  32073. + pr_debug("setting port info port %p\n", port);
  32074. + if (!port)
  32075. + return -1;
  32076. + dump_port_info(port);
  32077. +
  32078. + m.h.type = MMAL_MSG_TYPE_PORT_INFO_SET;
  32079. +
  32080. + m.u.port_info_set.component_handle = port->component->handle;
  32081. + m.u.port_info_set.port_type = port->type;
  32082. + m.u.port_info_set.port_index = port->index;
  32083. +
  32084. + port_to_mmal_msg(port, &m.u.port_info_set.port);
  32085. +
  32086. + /* elementry stream format setup */
  32087. + m.u.port_info_set.format.type = port->format.type;
  32088. + m.u.port_info_set.format.encoding = port->format.encoding;
  32089. + m.u.port_info_set.format.encoding_variant =
  32090. + port->format.encoding_variant;
  32091. + m.u.port_info_set.format.bitrate = port->format.bitrate;
  32092. + m.u.port_info_set.format.flags = port->format.flags;
  32093. +
  32094. + memcpy(&m.u.port_info_set.es, &port->es,
  32095. + sizeof(union mmal_es_specific_format));
  32096. +
  32097. + m.u.port_info_set.format.extradata_size = port->format.extradata_size;
  32098. + memcpy(rmsg->u.port_info_set.extradata, port->format.extradata,
  32099. + port->format.extradata_size);
  32100. +
  32101. + ret = send_synchronous_mmal_msg(instance, &m,
  32102. + sizeof(m.u.port_info_set),
  32103. + &rmsg, &rmsg_handle);
  32104. + if (ret)
  32105. + return ret;
  32106. +
  32107. + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_INFO_SET) {
  32108. + /* got an unexpected message type in reply */
  32109. + ret = -EINVAL;
  32110. + goto release_msg;
  32111. + }
  32112. +
  32113. + /* return operation status */
  32114. + ret = -rmsg->u.port_info_get_reply.status;
  32115. +
  32116. + pr_debug("%s:result:%d component:0x%x port:%d\n", __func__, ret,
  32117. + port->component->handle, port->handle);
  32118. +
  32119. +release_msg:
  32120. + vchi_held_msg_release(&rmsg_handle);
  32121. +
  32122. + return ret;
  32123. +
  32124. +}
  32125. +
  32126. +/* use port info get message to retrive port information */
  32127. +static int port_info_get(struct vchiq_mmal_instance *instance,
  32128. + struct vchiq_mmal_port *port)
  32129. +{
  32130. + int ret;
  32131. + struct mmal_msg m;
  32132. + struct mmal_msg *rmsg;
  32133. + VCHI_HELD_MSG_T rmsg_handle;
  32134. +
  32135. + /* port info time */
  32136. + m.h.type = MMAL_MSG_TYPE_PORT_INFO_GET;
  32137. + m.u.port_info_get.component_handle = port->component->handle;
  32138. + m.u.port_info_get.port_type = port->type;
  32139. + m.u.port_info_get.index = port->index;
  32140. +
  32141. + ret = send_synchronous_mmal_msg(instance, &m,
  32142. + sizeof(m.u.port_info_get),
  32143. + &rmsg, &rmsg_handle);
  32144. + if (ret)
  32145. + return ret;
  32146. +
  32147. + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_INFO_GET) {
  32148. + /* got an unexpected message type in reply */
  32149. + ret = -EINVAL;
  32150. + goto release_msg;
  32151. + }
  32152. +
  32153. + /* return operation status */
  32154. + ret = -rmsg->u.port_info_get_reply.status;
  32155. + if (ret != MMAL_MSG_STATUS_SUCCESS)
  32156. + goto release_msg;
  32157. +
  32158. + if (rmsg->u.port_info_get_reply.port.is_enabled == 0)
  32159. + port->enabled = false;
  32160. + else
  32161. + port->enabled = true;
  32162. +
  32163. + /* copy the values out of the message */
  32164. + port->handle = rmsg->u.port_info_get_reply.port_handle;
  32165. +
  32166. + /* port type and index cached to use on port info set becuase
  32167. + * it does not use a port handle
  32168. + */
  32169. + port->type = rmsg->u.port_info_get_reply.port_type;
  32170. + port->index = rmsg->u.port_info_get_reply.port_index;
  32171. +
  32172. + port->minimum_buffer.num =
  32173. + rmsg->u.port_info_get_reply.port.buffer_num_min;
  32174. + port->minimum_buffer.size =
  32175. + rmsg->u.port_info_get_reply.port.buffer_size_min;
  32176. + port->minimum_buffer.alignment =
  32177. + rmsg->u.port_info_get_reply.port.buffer_alignment_min;
  32178. +
  32179. + port->recommended_buffer.alignment =
  32180. + rmsg->u.port_info_get_reply.port.buffer_alignment_min;
  32181. + port->recommended_buffer.num =
  32182. + rmsg->u.port_info_get_reply.port.buffer_num_recommended;
  32183. +
  32184. + port->current_buffer.num = rmsg->u.port_info_get_reply.port.buffer_num;
  32185. + port->current_buffer.size =
  32186. + rmsg->u.port_info_get_reply.port.buffer_size;
  32187. +
  32188. + /* stream format */
  32189. + port->format.type = rmsg->u.port_info_get_reply.format.type;
  32190. + port->format.encoding = rmsg->u.port_info_get_reply.format.encoding;
  32191. + port->format.encoding_variant =
  32192. + rmsg->u.port_info_get_reply.format.encoding_variant;
  32193. + port->format.bitrate = rmsg->u.port_info_get_reply.format.bitrate;
  32194. + port->format.flags = rmsg->u.port_info_get_reply.format.flags;
  32195. +
  32196. + /* elementry stream format */
  32197. + memcpy(&port->es,
  32198. + &rmsg->u.port_info_get_reply.es,
  32199. + sizeof(union mmal_es_specific_format));
  32200. + port->format.es = &port->es;
  32201. +
  32202. + port->format.extradata_size =
  32203. + rmsg->u.port_info_get_reply.format.extradata_size;
  32204. + memcpy(port->format.extradata,
  32205. + rmsg->u.port_info_get_reply.extradata,
  32206. + port->format.extradata_size);
  32207. +
  32208. + pr_debug("received port info\n");
  32209. + dump_port_info(port);
  32210. +
  32211. +release_msg:
  32212. +
  32213. + pr_debug("%s:result:%d component:0x%x port:%d\n",
  32214. + __func__, ret, port->component->handle, port->handle);
  32215. +
  32216. + vchi_held_msg_release(&rmsg_handle);
  32217. +
  32218. + return ret;
  32219. +}
  32220. +
  32221. +/* create comonent on vc */
  32222. +static int create_component(struct vchiq_mmal_instance *instance,
  32223. + struct vchiq_mmal_component *component,
  32224. + const char *name)
  32225. +{
  32226. + int ret;
  32227. + struct mmal_msg m;
  32228. + struct mmal_msg *rmsg;
  32229. + VCHI_HELD_MSG_T rmsg_handle;
  32230. +
  32231. + /* build component create message */
  32232. + m.h.type = MMAL_MSG_TYPE_COMPONENT_CREATE;
  32233. + m.u.component_create.client_component = component;
  32234. + strncpy(m.u.component_create.name, name,
  32235. + sizeof(m.u.component_create.name));
  32236. +
  32237. + ret = send_synchronous_mmal_msg(instance, &m,
  32238. + sizeof(m.u.component_create),
  32239. + &rmsg, &rmsg_handle);
  32240. + if (ret)
  32241. + return ret;
  32242. +
  32243. + if (rmsg->h.type != m.h.type) {
  32244. + /* got an unexpected message type in reply */
  32245. + ret = -EINVAL;
  32246. + goto release_msg;
  32247. + }
  32248. +
  32249. + ret = -rmsg->u.component_create_reply.status;
  32250. + if (ret != MMAL_MSG_STATUS_SUCCESS)
  32251. + goto release_msg;
  32252. +
  32253. + /* a valid component response received */
  32254. + component->handle = rmsg->u.component_create_reply.component_handle;
  32255. + component->inputs = rmsg->u.component_create_reply.input_num;
  32256. + component->outputs = rmsg->u.component_create_reply.output_num;
  32257. + component->clocks = rmsg->u.component_create_reply.clock_num;
  32258. +
  32259. + pr_debug("Component handle:0x%x in:%d out:%d clock:%d\n",
  32260. + component->handle,
  32261. + component->inputs, component->outputs, component->clocks);
  32262. +
  32263. +release_msg:
  32264. + vchi_held_msg_release(&rmsg_handle);
  32265. +
  32266. + return ret;
  32267. +}
  32268. +
  32269. +/* destroys a component on vc */
  32270. +static int destroy_component(struct vchiq_mmal_instance *instance,
  32271. + struct vchiq_mmal_component *component)
  32272. +{
  32273. + int ret;
  32274. + struct mmal_msg m;
  32275. + struct mmal_msg *rmsg;
  32276. + VCHI_HELD_MSG_T rmsg_handle;
  32277. +
  32278. + m.h.type = MMAL_MSG_TYPE_COMPONENT_DESTROY;
  32279. + m.u.component_destroy.component_handle = component->handle;
  32280. +
  32281. + ret = send_synchronous_mmal_msg(instance, &m,
  32282. + sizeof(m.u.component_destroy),
  32283. + &rmsg, &rmsg_handle);
  32284. + if (ret)
  32285. + return ret;
  32286. +
  32287. + if (rmsg->h.type != m.h.type) {
  32288. + /* got an unexpected message type in reply */
  32289. + ret = -EINVAL;
  32290. + goto release_msg;
  32291. + }
  32292. +
  32293. + ret = -rmsg->u.component_destroy_reply.status;
  32294. +
  32295. +release_msg:
  32296. +
  32297. + vchi_held_msg_release(&rmsg_handle);
  32298. +
  32299. + return ret;
  32300. +}
  32301. +
  32302. +/* enable a component on vc */
  32303. +static int enable_component(struct vchiq_mmal_instance *instance,
  32304. + struct vchiq_mmal_component *component)
  32305. +{
  32306. + int ret;
  32307. + struct mmal_msg m;
  32308. + struct mmal_msg *rmsg;
  32309. + VCHI_HELD_MSG_T rmsg_handle;
  32310. +
  32311. + m.h.type = MMAL_MSG_TYPE_COMPONENT_ENABLE;
  32312. + m.u.component_enable.component_handle = component->handle;
  32313. +
  32314. + ret = send_synchronous_mmal_msg(instance, &m,
  32315. + sizeof(m.u.component_enable),
  32316. + &rmsg, &rmsg_handle);
  32317. + if (ret)
  32318. + return ret;
  32319. +
  32320. + if (rmsg->h.type != m.h.type) {
  32321. + /* got an unexpected message type in reply */
  32322. + ret = -EINVAL;
  32323. + goto release_msg;
  32324. + }
  32325. +
  32326. + ret = -rmsg->u.component_enable_reply.status;
  32327. +
  32328. +release_msg:
  32329. + vchi_held_msg_release(&rmsg_handle);
  32330. +
  32331. + return ret;
  32332. +}
  32333. +
  32334. +/* disable a component on vc */
  32335. +static int disable_component(struct vchiq_mmal_instance *instance,
  32336. + struct vchiq_mmal_component *component)
  32337. +{
  32338. + int ret;
  32339. + struct mmal_msg m;
  32340. + struct mmal_msg *rmsg;
  32341. + VCHI_HELD_MSG_T rmsg_handle;
  32342. +
  32343. + m.h.type = MMAL_MSG_TYPE_COMPONENT_DISABLE;
  32344. + m.u.component_disable.component_handle = component->handle;
  32345. +
  32346. + ret = send_synchronous_mmal_msg(instance, &m,
  32347. + sizeof(m.u.component_disable),
  32348. + &rmsg, &rmsg_handle);
  32349. + if (ret)
  32350. + return ret;
  32351. +
  32352. + if (rmsg->h.type != m.h.type) {
  32353. + /* got an unexpected message type in reply */
  32354. + ret = -EINVAL;
  32355. + goto release_msg;
  32356. + }
  32357. +
  32358. + ret = -rmsg->u.component_disable_reply.status;
  32359. +
  32360. +release_msg:
  32361. +
  32362. + vchi_held_msg_release(&rmsg_handle);
  32363. +
  32364. + return ret;
  32365. +}
  32366. +
  32367. +/* get version of mmal implementation */
  32368. +static int get_version(struct vchiq_mmal_instance *instance,
  32369. + u32 *major_out, u32 *minor_out)
  32370. +{
  32371. + int ret;
  32372. + struct mmal_msg m;
  32373. + struct mmal_msg *rmsg;
  32374. + VCHI_HELD_MSG_T rmsg_handle;
  32375. +
  32376. + m.h.type = MMAL_MSG_TYPE_GET_VERSION;
  32377. +
  32378. + ret = send_synchronous_mmal_msg(instance, &m,
  32379. + sizeof(m.u.version),
  32380. + &rmsg, &rmsg_handle);
  32381. + if (ret)
  32382. + return ret;
  32383. +
  32384. + if (rmsg->h.type != m.h.type) {
  32385. + /* got an unexpected message type in reply */
  32386. + ret = -EINVAL;
  32387. + goto release_msg;
  32388. + }
  32389. +
  32390. + *major_out = rmsg->u.version.major;
  32391. + *minor_out = rmsg->u.version.minor;
  32392. +
  32393. +release_msg:
  32394. + vchi_held_msg_release(&rmsg_handle);
  32395. +
  32396. + return ret;
  32397. +}
  32398. +
  32399. +/* do a port action with a port as a parameter */
  32400. +static int port_action_port(struct vchiq_mmal_instance *instance,
  32401. + struct vchiq_mmal_port *port,
  32402. + enum mmal_msg_port_action_type action_type)
  32403. +{
  32404. + int ret;
  32405. + struct mmal_msg m;
  32406. + struct mmal_msg *rmsg;
  32407. + VCHI_HELD_MSG_T rmsg_handle;
  32408. +
  32409. + m.h.type = MMAL_MSG_TYPE_PORT_ACTION;
  32410. + m.u.port_action_port.component_handle = port->component->handle;
  32411. + m.u.port_action_port.port_handle = port->handle;
  32412. + m.u.port_action_port.action = action_type;
  32413. +
  32414. + port_to_mmal_msg(port, &m.u.port_action_port.port);
  32415. +
  32416. + ret = send_synchronous_mmal_msg(instance, &m,
  32417. + sizeof(m.u.port_action_port),
  32418. + &rmsg, &rmsg_handle);
  32419. + if (ret)
  32420. + return ret;
  32421. +
  32422. + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_ACTION) {
  32423. + /* got an unexpected message type in reply */
  32424. + ret = -EINVAL;
  32425. + goto release_msg;
  32426. + }
  32427. +
  32428. + ret = -rmsg->u.port_action_reply.status;
  32429. +
  32430. + pr_debug("%s:result:%d component:0x%x port:%d action:%s(%d)\n",
  32431. + __func__,
  32432. + ret, port->component->handle, port->handle,
  32433. + port_action_type_names[action_type], action_type);
  32434. +
  32435. +release_msg:
  32436. + vchi_held_msg_release(&rmsg_handle);
  32437. +
  32438. + return ret;
  32439. +}
  32440. +
  32441. +/* do a port action with handles as parameters */
  32442. +static int port_action_handle(struct vchiq_mmal_instance *instance,
  32443. + struct vchiq_mmal_port *port,
  32444. + enum mmal_msg_port_action_type action_type,
  32445. + u32 connect_component_handle,
  32446. + u32 connect_port_handle)
  32447. +{
  32448. + int ret;
  32449. + struct mmal_msg m;
  32450. + struct mmal_msg *rmsg;
  32451. + VCHI_HELD_MSG_T rmsg_handle;
  32452. +
  32453. + m.h.type = MMAL_MSG_TYPE_PORT_ACTION;
  32454. +
  32455. + m.u.port_action_handle.component_handle = port->component->handle;
  32456. + m.u.port_action_handle.port_handle = port->handle;
  32457. + m.u.port_action_handle.action = action_type;
  32458. +
  32459. + m.u.port_action_handle.connect_component_handle =
  32460. + connect_component_handle;
  32461. + m.u.port_action_handle.connect_port_handle = connect_port_handle;
  32462. +
  32463. + ret = send_synchronous_mmal_msg(instance, &m,
  32464. + sizeof(m.u.port_action_handle),
  32465. + &rmsg, &rmsg_handle);
  32466. + if (ret)
  32467. + return ret;
  32468. +
  32469. + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_ACTION) {
  32470. + /* got an unexpected message type in reply */
  32471. + ret = -EINVAL;
  32472. + goto release_msg;
  32473. + }
  32474. +
  32475. + ret = -rmsg->u.port_action_reply.status;
  32476. +
  32477. + pr_debug("%s:result:%d component:0x%x port:%d action:%s(%d)" \
  32478. + " connect component:0x%x connect port:%d\n",
  32479. + __func__,
  32480. + ret, port->component->handle, port->handle,
  32481. + port_action_type_names[action_type],
  32482. + action_type, connect_component_handle, connect_port_handle);
  32483. +
  32484. +release_msg:
  32485. + vchi_held_msg_release(&rmsg_handle);
  32486. +
  32487. + return ret;
  32488. +}
  32489. +
  32490. +static int port_parameter_set(struct vchiq_mmal_instance *instance,
  32491. + struct vchiq_mmal_port *port,
  32492. + u32 parameter_id, void *value, u32 value_size)
  32493. +{
  32494. + int ret;
  32495. + struct mmal_msg m;
  32496. + struct mmal_msg *rmsg;
  32497. + VCHI_HELD_MSG_T rmsg_handle;
  32498. +
  32499. + m.h.type = MMAL_MSG_TYPE_PORT_PARAMETER_SET;
  32500. +
  32501. + m.u.port_parameter_set.component_handle = port->component->handle;
  32502. + m.u.port_parameter_set.port_handle = port->handle;
  32503. + m.u.port_parameter_set.id = parameter_id;
  32504. + m.u.port_parameter_set.size = (2 * sizeof(u32)) + value_size;
  32505. + memcpy(&m.u.port_parameter_set.value, value, value_size);
  32506. +
  32507. + ret = send_synchronous_mmal_msg(instance, &m,
  32508. + (4 * sizeof(u32)) + value_size,
  32509. + &rmsg, &rmsg_handle);
  32510. + if (ret)
  32511. + return ret;
  32512. +
  32513. + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_PARAMETER_SET) {
  32514. + /* got an unexpected message type in reply */
  32515. + ret = -EINVAL;
  32516. + goto release_msg;
  32517. + }
  32518. +
  32519. + ret = -rmsg->u.port_parameter_set_reply.status;
  32520. +
  32521. + pr_debug("%s:result:%d component:0x%x port:%d parameter:%d\n",
  32522. + __func__,
  32523. + ret, port->component->handle, port->handle, parameter_id);
  32524. +
  32525. +release_msg:
  32526. + vchi_held_msg_release(&rmsg_handle);
  32527. +
  32528. + return ret;
  32529. +}
  32530. +
  32531. +static int port_parameter_get(struct vchiq_mmal_instance *instance,
  32532. + struct vchiq_mmal_port *port,
  32533. + u32 parameter_id, void *value, u32 *value_size)
  32534. +{
  32535. + int ret;
  32536. + struct mmal_msg m;
  32537. + struct mmal_msg *rmsg;
  32538. + VCHI_HELD_MSG_T rmsg_handle;
  32539. +
  32540. + m.h.type = MMAL_MSG_TYPE_PORT_PARAMETER_GET;
  32541. +
  32542. + m.u.port_parameter_get.component_handle = port->component->handle;
  32543. + m.u.port_parameter_get.port_handle = port->handle;
  32544. + m.u.port_parameter_get.id = parameter_id;
  32545. + m.u.port_parameter_get.size = (2 * sizeof(u32)) + *value_size;
  32546. +
  32547. + ret = send_synchronous_mmal_msg(instance, &m,
  32548. + sizeof(struct
  32549. + mmal_msg_port_parameter_get),
  32550. + &rmsg, &rmsg_handle);
  32551. + if (ret)
  32552. + return ret;
  32553. +
  32554. + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_PARAMETER_GET) {
  32555. + /* got an unexpected message type in reply */
  32556. + pr_err("Incorrect reply type %d\n", rmsg->h.type);
  32557. + ret = -EINVAL;
  32558. + goto release_msg;
  32559. + }
  32560. +
  32561. + ret = -rmsg->u.port_parameter_get_reply.status;
  32562. + if (ret) {
  32563. + /* Copy only as much as we have space for
  32564. + * but report true size of parameter
  32565. + */
  32566. + memcpy(value, &rmsg->u.port_parameter_get_reply.value,
  32567. + *value_size);
  32568. + *value_size = rmsg->u.port_parameter_get_reply.size;
  32569. + } else
  32570. + memcpy(value, &rmsg->u.port_parameter_get_reply.value,
  32571. + rmsg->u.port_parameter_get_reply.size);
  32572. +
  32573. + pr_debug("%s:result:%d component:0x%x port:%d parameter:%d\n", __func__,
  32574. + ret, port->component->handle, port->handle, parameter_id);
  32575. +
  32576. +release_msg:
  32577. + vchi_held_msg_release(&rmsg_handle);
  32578. +
  32579. + return ret;
  32580. +}
  32581. +
  32582. +/* disables a port and drains buffers from it */
  32583. +static int port_disable(struct vchiq_mmal_instance *instance,
  32584. + struct vchiq_mmal_port *port)
  32585. +{
  32586. + int ret;
  32587. + struct list_head *q, *buf_head;
  32588. + unsigned long flags = 0;
  32589. +
  32590. + if (!port->enabled)
  32591. + return 0;
  32592. +
  32593. + port->enabled = false;
  32594. +
  32595. + ret = port_action_port(instance, port,
  32596. + MMAL_MSG_PORT_ACTION_TYPE_DISABLE);
  32597. + if (ret == 0) {
  32598. +
  32599. + /* drain all queued buffers on port */
  32600. + spin_lock_irqsave(&port->slock, flags);
  32601. +
  32602. + list_for_each_safe(buf_head, q, &port->buffers) {
  32603. + struct mmal_buffer *mmalbuf;
  32604. + mmalbuf = list_entry(buf_head, struct mmal_buffer,
  32605. + list);
  32606. + list_del(buf_head);
  32607. + if (port->buffer_cb)
  32608. + port->buffer_cb(instance,
  32609. + port, 0, mmalbuf, 0, 0,
  32610. + MMAL_TIME_UNKNOWN,
  32611. + MMAL_TIME_UNKNOWN);
  32612. + }
  32613. +
  32614. + spin_unlock_irqrestore(&port->slock, flags);
  32615. +
  32616. + ret = port_info_get(instance, port);
  32617. + }
  32618. +
  32619. + return ret;
  32620. +}
  32621. +
  32622. +/* enable a port */
  32623. +static int port_enable(struct vchiq_mmal_instance *instance,
  32624. + struct vchiq_mmal_port *port)
  32625. +{
  32626. + unsigned int hdr_count;
  32627. + struct list_head *buf_head;
  32628. + int ret;
  32629. +
  32630. + if (port->enabled)
  32631. + return 0;
  32632. +
  32633. + /* ensure there are enough buffers queued to cover the buffer headers */
  32634. + if (port->buffer_cb != NULL) {
  32635. + hdr_count = 0;
  32636. + list_for_each(buf_head, &port->buffers) {
  32637. + hdr_count++;
  32638. + }
  32639. + if (hdr_count < port->current_buffer.num)
  32640. + return -ENOSPC;
  32641. + }
  32642. +
  32643. + ret = port_action_port(instance, port,
  32644. + MMAL_MSG_PORT_ACTION_TYPE_ENABLE);
  32645. + if (ret)
  32646. + goto done;
  32647. +
  32648. + port->enabled = true;
  32649. +
  32650. + if (port->buffer_cb) {
  32651. + /* send buffer headers to videocore */
  32652. + hdr_count = 1;
  32653. + list_for_each(buf_head, &port->buffers) {
  32654. + struct mmal_buffer *mmalbuf;
  32655. + mmalbuf = list_entry(buf_head, struct mmal_buffer,
  32656. + list);
  32657. + ret = buffer_from_host(instance, port, mmalbuf);
  32658. + if (ret)
  32659. + goto done;
  32660. +
  32661. + hdr_count++;
  32662. + if (hdr_count > port->current_buffer.num)
  32663. + break;
  32664. + }
  32665. + }
  32666. +
  32667. + ret = port_info_get(instance, port);
  32668. +
  32669. +done:
  32670. + return ret;
  32671. +}
  32672. +
  32673. +/* ------------------------------------------------------------------
  32674. + * Exported API
  32675. + *------------------------------------------------------------------*/
  32676. +
  32677. +int vchiq_mmal_port_set_format(struct vchiq_mmal_instance *instance,
  32678. + struct vchiq_mmal_port *port)
  32679. +{
  32680. + int ret;
  32681. +
  32682. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  32683. + return -EINTR;
  32684. +
  32685. + ret = port_info_set(instance, port);
  32686. + if (ret)
  32687. + goto release_unlock;
  32688. +
  32689. + /* read what has actually been set */
  32690. + ret = port_info_get(instance, port);
  32691. +
  32692. +release_unlock:
  32693. + mutex_unlock(&instance->vchiq_mutex);
  32694. +
  32695. + return ret;
  32696. +
  32697. +}
  32698. +
  32699. +int vchiq_mmal_port_parameter_set(struct vchiq_mmal_instance *instance,
  32700. + struct vchiq_mmal_port *port,
  32701. + u32 parameter, void *value, u32 value_size)
  32702. +{
  32703. + int ret;
  32704. +
  32705. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  32706. + return -EINTR;
  32707. +
  32708. + ret = port_parameter_set(instance, port, parameter, value, value_size);
  32709. +
  32710. + mutex_unlock(&instance->vchiq_mutex);
  32711. +
  32712. + return ret;
  32713. +}
  32714. +
  32715. +int vchiq_mmal_port_parameter_get(struct vchiq_mmal_instance *instance,
  32716. + struct vchiq_mmal_port *port,
  32717. + u32 parameter, void *value, u32 *value_size)
  32718. +{
  32719. + int ret;
  32720. +
  32721. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  32722. + return -EINTR;
  32723. +
  32724. + ret = port_parameter_get(instance, port, parameter, value, value_size);
  32725. +
  32726. + mutex_unlock(&instance->vchiq_mutex);
  32727. +
  32728. + return ret;
  32729. +}
  32730. +
  32731. +/* enable a port
  32732. + *
  32733. + * enables a port and queues buffers for satisfying callbacks if we
  32734. + * provide a callback handler
  32735. + */
  32736. +int vchiq_mmal_port_enable(struct vchiq_mmal_instance *instance,
  32737. + struct vchiq_mmal_port *port,
  32738. + vchiq_mmal_buffer_cb buffer_cb)
  32739. +{
  32740. + int ret;
  32741. +
  32742. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  32743. + return -EINTR;
  32744. +
  32745. + /* already enabled - noop */
  32746. + if (port->enabled) {
  32747. + ret = 0;
  32748. + goto unlock;
  32749. + }
  32750. +
  32751. + port->buffer_cb = buffer_cb;
  32752. +
  32753. + ret = port_enable(instance, port);
  32754. +
  32755. +unlock:
  32756. + mutex_unlock(&instance->vchiq_mutex);
  32757. +
  32758. + return ret;
  32759. +}
  32760. +
  32761. +int vchiq_mmal_port_disable(struct vchiq_mmal_instance *instance,
  32762. + struct vchiq_mmal_port *port)
  32763. +{
  32764. + int ret;
  32765. +
  32766. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  32767. + return -EINTR;
  32768. +
  32769. + if (!port->enabled) {
  32770. + mutex_unlock(&instance->vchiq_mutex);
  32771. + return 0;
  32772. + }
  32773. +
  32774. + ret = port_disable(instance, port);
  32775. +
  32776. + mutex_unlock(&instance->vchiq_mutex);
  32777. +
  32778. + return ret;
  32779. +}
  32780. +
  32781. +/* ports will be connected in a tunneled manner so data buffers
  32782. + * are not handled by client.
  32783. + */
  32784. +int vchiq_mmal_port_connect_tunnel(struct vchiq_mmal_instance *instance,
  32785. + struct vchiq_mmal_port *src,
  32786. + struct vchiq_mmal_port *dst)
  32787. +{
  32788. + int ret;
  32789. +
  32790. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  32791. + return -EINTR;
  32792. +
  32793. + /* disconnect ports if connected */
  32794. + if (src->connected != NULL) {
  32795. + ret = port_disable(instance, src);
  32796. + if (ret) {
  32797. + pr_err("failed disabling src port(%d)\n", ret);
  32798. + goto release_unlock;
  32799. + }
  32800. +
  32801. + /* do not need to disable the destination port as they
  32802. + * are connected and it is done automatically
  32803. + */
  32804. +
  32805. + ret = port_action_handle(instance, src,
  32806. + MMAL_MSG_PORT_ACTION_TYPE_DISCONNECT,
  32807. + src->connected->component->handle,
  32808. + src->connected->handle);
  32809. + if (ret < 0) {
  32810. + pr_err("failed disconnecting src port\n");
  32811. + goto release_unlock;
  32812. + }
  32813. + src->connected->enabled = false;
  32814. + src->connected = NULL;
  32815. + }
  32816. +
  32817. + if (dst == NULL) {
  32818. + /* do not make new connection */
  32819. + ret = 0;
  32820. + pr_debug("not making new connection\n");
  32821. + goto release_unlock;
  32822. + }
  32823. +
  32824. + /* copy src port format to dst */
  32825. + dst->format.encoding = src->format.encoding;
  32826. + dst->es.video.width = src->es.video.width;
  32827. + dst->es.video.height = src->es.video.height;
  32828. + dst->es.video.crop.x = src->es.video.crop.x;
  32829. + dst->es.video.crop.y = src->es.video.crop.y;
  32830. + dst->es.video.crop.width = src->es.video.crop.width;
  32831. + dst->es.video.crop.height = src->es.video.crop.height;
  32832. + dst->es.video.frame_rate.num = src->es.video.frame_rate.num;
  32833. + dst->es.video.frame_rate.den = src->es.video.frame_rate.den;
  32834. +
  32835. + /* set new format */
  32836. + ret = port_info_set(instance, dst);
  32837. + if (ret) {
  32838. + pr_debug("setting port info failed\n");
  32839. + goto release_unlock;
  32840. + }
  32841. +
  32842. + /* read what has actually been set */
  32843. + ret = port_info_get(instance, dst);
  32844. + if (ret) {
  32845. + pr_debug("read back port info failed\n");
  32846. + goto release_unlock;
  32847. + }
  32848. +
  32849. + /* connect two ports together */
  32850. + ret = port_action_handle(instance, src,
  32851. + MMAL_MSG_PORT_ACTION_TYPE_CONNECT,
  32852. + dst->component->handle, dst->handle);
  32853. + if (ret < 0) {
  32854. + pr_debug("connecting port %d:%d to %d:%d failed\n",
  32855. + src->component->handle, src->handle,
  32856. + dst->component->handle, dst->handle);
  32857. + goto release_unlock;
  32858. + }
  32859. + src->connected = dst;
  32860. +
  32861. +release_unlock:
  32862. +
  32863. + mutex_unlock(&instance->vchiq_mutex);
  32864. +
  32865. + return ret;
  32866. +}
  32867. +
  32868. +int vchiq_mmal_submit_buffer(struct vchiq_mmal_instance *instance,
  32869. + struct vchiq_mmal_port *port,
  32870. + struct mmal_buffer *buffer)
  32871. +{
  32872. + unsigned long flags = 0;
  32873. +
  32874. + spin_lock_irqsave(&port->slock, flags);
  32875. + list_add_tail(&buffer->list, &port->buffers);
  32876. + spin_unlock_irqrestore(&port->slock, flags);
  32877. +
  32878. + /* the port previously underflowed because it was missing a
  32879. + * mmal_buffer which has just been added, submit that buffer
  32880. + * to the mmal service.
  32881. + */
  32882. + if (port->buffer_underflow) {
  32883. + port_buffer_from_host(instance, port);
  32884. + port->buffer_underflow--;
  32885. + }
  32886. +
  32887. + return 0;
  32888. +}
  32889. +
  32890. +/* Initialise a mmal component and its ports
  32891. + *
  32892. + */
  32893. +int vchiq_mmal_component_init(struct vchiq_mmal_instance *instance,
  32894. + const char *name,
  32895. + struct vchiq_mmal_component **component_out)
  32896. +{
  32897. + int ret;
  32898. + int idx; /* port index */
  32899. + struct vchiq_mmal_component *component;
  32900. +
  32901. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  32902. + return -EINTR;
  32903. +
  32904. + if (instance->component_idx == VCHIQ_MMAL_MAX_COMPONENTS) {
  32905. + ret = -EINVAL; /* todo is this correct error? */
  32906. + goto unlock;
  32907. + }
  32908. +
  32909. + component = &instance->component[instance->component_idx];
  32910. +
  32911. + ret = create_component(instance, component, name);
  32912. + if (ret < 0)
  32913. + goto unlock;
  32914. +
  32915. + /* ports info needs gathering */
  32916. + component->control.type = MMAL_PORT_TYPE_CONTROL;
  32917. + component->control.index = 0;
  32918. + component->control.component = component;
  32919. + spin_lock_init(&component->control.slock);
  32920. + INIT_LIST_HEAD(&component->control.buffers);
  32921. + ret = port_info_get(instance, &component->control);
  32922. + if (ret < 0)
  32923. + goto release_component;
  32924. +
  32925. + for (idx = 0; idx < component->inputs; idx++) {
  32926. + component->input[idx].type = MMAL_PORT_TYPE_INPUT;
  32927. + component->input[idx].index = idx;
  32928. + component->input[idx].component = component;
  32929. + spin_lock_init(&component->input[idx].slock);
  32930. + INIT_LIST_HEAD(&component->input[idx].buffers);
  32931. + ret = port_info_get(instance, &component->input[idx]);
  32932. + if (ret < 0)
  32933. + goto release_component;
  32934. + }
  32935. +
  32936. + for (idx = 0; idx < component->outputs; idx++) {
  32937. + component->output[idx].type = MMAL_PORT_TYPE_OUTPUT;
  32938. + component->output[idx].index = idx;
  32939. + component->output[idx].component = component;
  32940. + spin_lock_init(&component->output[idx].slock);
  32941. + INIT_LIST_HEAD(&component->output[idx].buffers);
  32942. + ret = port_info_get(instance, &component->output[idx]);
  32943. + if (ret < 0)
  32944. + goto release_component;
  32945. + }
  32946. +
  32947. + for (idx = 0; idx < component->clocks; idx++) {
  32948. + component->clock[idx].type = MMAL_PORT_TYPE_CLOCK;
  32949. + component->clock[idx].index = idx;
  32950. + component->clock[idx].component = component;
  32951. + spin_lock_init(&component->clock[idx].slock);
  32952. + INIT_LIST_HEAD(&component->clock[idx].buffers);
  32953. + ret = port_info_get(instance, &component->clock[idx]);
  32954. + if (ret < 0)
  32955. + goto release_component;
  32956. + }
  32957. +
  32958. + instance->component_idx++;
  32959. +
  32960. + *component_out = component;
  32961. +
  32962. + mutex_unlock(&instance->vchiq_mutex);
  32963. +
  32964. + return 0;
  32965. +
  32966. +release_component:
  32967. + destroy_component(instance, component);
  32968. +unlock:
  32969. + mutex_unlock(&instance->vchiq_mutex);
  32970. +
  32971. + return ret;
  32972. +}
  32973. +
  32974. +/*
  32975. + * cause a mmal component to be destroyed
  32976. + */
  32977. +int vchiq_mmal_component_finalise(struct vchiq_mmal_instance *instance,
  32978. + struct vchiq_mmal_component *component)
  32979. +{
  32980. + int ret;
  32981. +
  32982. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  32983. + return -EINTR;
  32984. +
  32985. + if (component->enabled)
  32986. + ret = disable_component(instance, component);
  32987. +
  32988. + ret = destroy_component(instance, component);
  32989. +
  32990. + mutex_unlock(&instance->vchiq_mutex);
  32991. +
  32992. + return ret;
  32993. +}
  32994. +
  32995. +/*
  32996. + * cause a mmal component to be enabled
  32997. + */
  32998. +int vchiq_mmal_component_enable(struct vchiq_mmal_instance *instance,
  32999. + struct vchiq_mmal_component *component)
  33000. +{
  33001. + int ret;
  33002. +
  33003. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  33004. + return -EINTR;
  33005. +
  33006. + if (component->enabled) {
  33007. + mutex_unlock(&instance->vchiq_mutex);
  33008. + return 0;
  33009. + }
  33010. +
  33011. + ret = enable_component(instance, component);
  33012. + if (ret == 0)
  33013. + component->enabled = true;
  33014. +
  33015. + mutex_unlock(&instance->vchiq_mutex);
  33016. +
  33017. + return ret;
  33018. +}
  33019. +
  33020. +/*
  33021. + * cause a mmal component to be enabled
  33022. + */
  33023. +int vchiq_mmal_component_disable(struct vchiq_mmal_instance *instance,
  33024. + struct vchiq_mmal_component *component)
  33025. +{
  33026. + int ret;
  33027. +
  33028. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  33029. + return -EINTR;
  33030. +
  33031. + if (!component->enabled) {
  33032. + mutex_unlock(&instance->vchiq_mutex);
  33033. + return 0;
  33034. + }
  33035. +
  33036. + ret = disable_component(instance, component);
  33037. + if (ret == 0)
  33038. + component->enabled = false;
  33039. +
  33040. + mutex_unlock(&instance->vchiq_mutex);
  33041. +
  33042. + return ret;
  33043. +}
  33044. +
  33045. +int vchiq_mmal_version(struct vchiq_mmal_instance *instance,
  33046. + u32 *major_out, u32 *minor_out)
  33047. +{
  33048. + int ret;
  33049. +
  33050. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  33051. + return -EINTR;
  33052. +
  33053. + ret = get_version(instance, major_out, minor_out);
  33054. +
  33055. + mutex_unlock(&instance->vchiq_mutex);
  33056. +
  33057. + return ret;
  33058. +}
  33059. +
  33060. +int vchiq_mmal_finalise(struct vchiq_mmal_instance *instance)
  33061. +{
  33062. + int status = 0;
  33063. +
  33064. + if (instance == NULL)
  33065. + return -EINVAL;
  33066. +
  33067. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  33068. + return -EINTR;
  33069. +
  33070. + vchi_service_use(instance->handle);
  33071. +
  33072. + status = vchi_service_close(instance->handle);
  33073. + if (status != 0)
  33074. + pr_err("mmal-vchiq: VCHIQ close failed");
  33075. +
  33076. + mutex_unlock(&instance->vchiq_mutex);
  33077. +
  33078. + vfree(instance->bulk_scratch);
  33079. +
  33080. + kfree(instance);
  33081. +
  33082. + return status;
  33083. +}
  33084. +
  33085. +int vchiq_mmal_init(struct vchiq_mmal_instance **out_instance)
  33086. +{
  33087. + int status;
  33088. + struct vchiq_mmal_instance *instance;
  33089. + static VCHI_CONNECTION_T *vchi_connection;
  33090. + static VCHI_INSTANCE_T vchi_instance;
  33091. + SERVICE_CREATION_T params = {
  33092. + VCHI_VERSION_EX(VC_MMAL_VER, VC_MMAL_MIN_VER),
  33093. + VC_MMAL_SERVER_NAME,
  33094. + vchi_connection,
  33095. + 0, /* rx fifo size (unused) */
  33096. + 0, /* tx fifo size (unused) */
  33097. + service_callback,
  33098. + NULL, /* service callback parameter */
  33099. + 1, /* unaligned bulk receives */
  33100. + 1, /* unaligned bulk transmits */
  33101. + 0 /* want crc check on bulk transfers */
  33102. + };
  33103. +
  33104. + /* compile time checks to ensure structure size as they are
  33105. + * directly (de)serialised from memory.
  33106. + */
  33107. +
  33108. + /* ensure the header structure has packed to the correct size */
  33109. + BUILD_BUG_ON(sizeof(struct mmal_msg_header) != 24);
  33110. +
  33111. + /* ensure message structure does not exceed maximum length */
  33112. + BUILD_BUG_ON(sizeof(struct mmal_msg) > MMAL_MSG_MAX_SIZE);
  33113. +
  33114. + /* mmal port struct is correct size */
  33115. + BUILD_BUG_ON(sizeof(struct mmal_port) != 64);
  33116. +
  33117. + /* create a vchi instance */
  33118. + status = vchi_initialise(&vchi_instance);
  33119. + if (status) {
  33120. + pr_err("Failed to initialise VCHI instance (status=%d)\n",
  33121. + status);
  33122. + return -EIO;
  33123. + }
  33124. +
  33125. + status = vchi_connect(NULL, 0, vchi_instance);
  33126. + if (status) {
  33127. + pr_err("Failed to connect VCHI instance (status=%d)\n", status);
  33128. + return -EIO;
  33129. + }
  33130. +
  33131. + instance = kmalloc(sizeof(*instance), GFP_KERNEL);
  33132. + memset(instance, 0, sizeof(*instance));
  33133. +
  33134. + mutex_init(&instance->vchiq_mutex);
  33135. + mutex_init(&instance->bulk_mutex);
  33136. +
  33137. + instance->bulk_scratch = vmalloc(PAGE_SIZE);
  33138. +
  33139. + params.callback_param = instance;
  33140. +
  33141. + status = vchi_service_open(vchi_instance, &params, &instance->handle);
  33142. + if (status) {
  33143. + pr_err("Failed to open VCHI service connection (status=%d)\n",
  33144. + status);
  33145. + goto err_close_services;
  33146. + }
  33147. +
  33148. + vchi_service_release(instance->handle);
  33149. +
  33150. + *out_instance = instance;
  33151. +
  33152. + return 0;
  33153. +
  33154. +err_close_services:
  33155. +
  33156. + vchi_service_close(instance->handle);
  33157. + vfree(instance->bulk_scratch);
  33158. + kfree(instance);
  33159. + return -ENODEV;
  33160. +}
  33161. diff -Nur linux-3.18.8/drivers/media/platform/bcm2835/mmal-vchiq.h linux-rpi/drivers/media/platform/bcm2835/mmal-vchiq.h
  33162. --- linux-3.18.8/drivers/media/platform/bcm2835/mmal-vchiq.h 1970-01-01 01:00:00.000000000 +0100
  33163. +++ linux-rpi/drivers/media/platform/bcm2835/mmal-vchiq.h 2015-03-05 14:40:13.981715822 +0100
  33164. @@ -0,0 +1,178 @@
  33165. +/*
  33166. + * Broadcom BM2835 V4L2 driver
  33167. + *
  33168. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  33169. + *
  33170. + * This file is subject to the terms and conditions of the GNU General Public
  33171. + * License. See the file COPYING in the main directory of this archive
  33172. + * for more details.
  33173. + *
  33174. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  33175. + * Dave Stevenson <dsteve@broadcom.com>
  33176. + * Simon Mellor <simellor@broadcom.com>
  33177. + * Luke Diamand <luked@broadcom.com>
  33178. + *
  33179. + * MMAL interface to VCHIQ message passing
  33180. + */
  33181. +
  33182. +#ifndef MMAL_VCHIQ_H
  33183. +#define MMAL_VCHIQ_H
  33184. +
  33185. +#include "mmal-msg-format.h"
  33186. +
  33187. +#define MAX_PORT_COUNT 4
  33188. +
  33189. +/* Maximum size of the format extradata. */
  33190. +#define MMAL_FORMAT_EXTRADATA_MAX_SIZE 128
  33191. +
  33192. +struct vchiq_mmal_instance;
  33193. +
  33194. +enum vchiq_mmal_es_type {
  33195. + MMAL_ES_TYPE_UNKNOWN, /**< Unknown elementary stream type */
  33196. + MMAL_ES_TYPE_CONTROL, /**< Elementary stream of control commands */
  33197. + MMAL_ES_TYPE_AUDIO, /**< Audio elementary stream */
  33198. + MMAL_ES_TYPE_VIDEO, /**< Video elementary stream */
  33199. + MMAL_ES_TYPE_SUBPICTURE /**< Sub-picture elementary stream */
  33200. +};
  33201. +
  33202. +/* rectangle, used lots so it gets its own struct */
  33203. +struct vchiq_mmal_rect {
  33204. + s32 x;
  33205. + s32 y;
  33206. + s32 width;
  33207. + s32 height;
  33208. +};
  33209. +
  33210. +struct vchiq_mmal_port_buffer {
  33211. + unsigned int num; /* number of buffers */
  33212. + u32 size; /* size of buffers */
  33213. + u32 alignment; /* alignment of buffers */
  33214. +};
  33215. +
  33216. +struct vchiq_mmal_port;
  33217. +
  33218. +typedef void (*vchiq_mmal_buffer_cb)(
  33219. + struct vchiq_mmal_instance *instance,
  33220. + struct vchiq_mmal_port *port,
  33221. + int status, struct mmal_buffer *buffer,
  33222. + unsigned long length, u32 mmal_flags, s64 dts, s64 pts);
  33223. +
  33224. +struct vchiq_mmal_port {
  33225. + bool enabled;
  33226. + u32 handle;
  33227. + u32 type; /* port type, cached to use on port info set */
  33228. + u32 index; /* port index, cached to use on port info set */
  33229. +
  33230. + /* component port belongs to, allows simple deref */
  33231. + struct vchiq_mmal_component *component;
  33232. +
  33233. + struct vchiq_mmal_port *connected; /* port conencted to */
  33234. +
  33235. + /* buffer info */
  33236. + struct vchiq_mmal_port_buffer minimum_buffer;
  33237. + struct vchiq_mmal_port_buffer recommended_buffer;
  33238. + struct vchiq_mmal_port_buffer current_buffer;
  33239. +
  33240. + /* stream format */
  33241. + struct mmal_es_format format;
  33242. + /* elementry stream format */
  33243. + union mmal_es_specific_format es;
  33244. +
  33245. + /* data buffers to fill */
  33246. + struct list_head buffers;
  33247. + /* lock to serialise adding and removing buffers from list */
  33248. + spinlock_t slock;
  33249. + /* count of how many buffer header refils have failed because
  33250. + * there was no buffer to satisfy them
  33251. + */
  33252. + int buffer_underflow;
  33253. + /* callback on buffer completion */
  33254. + vchiq_mmal_buffer_cb buffer_cb;
  33255. + /* callback context */
  33256. + void *cb_ctx;
  33257. +};
  33258. +
  33259. +struct vchiq_mmal_component {
  33260. + bool enabled;
  33261. + u32 handle; /* VideoCore handle for component */
  33262. + u32 inputs; /* Number of input ports */
  33263. + u32 outputs; /* Number of output ports */
  33264. + u32 clocks; /* Number of clock ports */
  33265. + struct vchiq_mmal_port control; /* control port */
  33266. + struct vchiq_mmal_port input[MAX_PORT_COUNT]; /* input ports */
  33267. + struct vchiq_mmal_port output[MAX_PORT_COUNT]; /* output ports */
  33268. + struct vchiq_mmal_port clock[MAX_PORT_COUNT]; /* clock ports */
  33269. +};
  33270. +
  33271. +
  33272. +int vchiq_mmal_init(struct vchiq_mmal_instance **out_instance);
  33273. +int vchiq_mmal_finalise(struct vchiq_mmal_instance *instance);
  33274. +
  33275. +/* Initialise a mmal component and its ports
  33276. +*
  33277. +*/
  33278. +int vchiq_mmal_component_init(
  33279. + struct vchiq_mmal_instance *instance,
  33280. + const char *name,
  33281. + struct vchiq_mmal_component **component_out);
  33282. +
  33283. +int vchiq_mmal_component_finalise(
  33284. + struct vchiq_mmal_instance *instance,
  33285. + struct vchiq_mmal_component *component);
  33286. +
  33287. +int vchiq_mmal_component_enable(
  33288. + struct vchiq_mmal_instance *instance,
  33289. + struct vchiq_mmal_component *component);
  33290. +
  33291. +int vchiq_mmal_component_disable(
  33292. + struct vchiq_mmal_instance *instance,
  33293. + struct vchiq_mmal_component *component);
  33294. +
  33295. +
  33296. +
  33297. +/* enable a mmal port
  33298. + *
  33299. + * enables a port and if a buffer callback provided enque buffer
  33300. + * headers as apropriate for the port.
  33301. + */
  33302. +int vchiq_mmal_port_enable(
  33303. + struct vchiq_mmal_instance *instance,
  33304. + struct vchiq_mmal_port *port,
  33305. + vchiq_mmal_buffer_cb buffer_cb);
  33306. +
  33307. +/* disable a port
  33308. + *
  33309. + * disable a port will dequeue any pending buffers
  33310. + */
  33311. +int vchiq_mmal_port_disable(struct vchiq_mmal_instance *instance,
  33312. + struct vchiq_mmal_port *port);
  33313. +
  33314. +
  33315. +int vchiq_mmal_port_parameter_set(struct vchiq_mmal_instance *instance,
  33316. + struct vchiq_mmal_port *port,
  33317. + u32 parameter,
  33318. + void *value,
  33319. + u32 value_size);
  33320. +
  33321. +int vchiq_mmal_port_parameter_get(struct vchiq_mmal_instance *instance,
  33322. + struct vchiq_mmal_port *port,
  33323. + u32 parameter,
  33324. + void *value,
  33325. + u32 *value_size);
  33326. +
  33327. +int vchiq_mmal_port_set_format(struct vchiq_mmal_instance *instance,
  33328. + struct vchiq_mmal_port *port);
  33329. +
  33330. +int vchiq_mmal_port_connect_tunnel(struct vchiq_mmal_instance *instance,
  33331. + struct vchiq_mmal_port *src,
  33332. + struct vchiq_mmal_port *dst);
  33333. +
  33334. +int vchiq_mmal_version(struct vchiq_mmal_instance *instance,
  33335. + u32 *major_out,
  33336. + u32 *minor_out);
  33337. +
  33338. +int vchiq_mmal_submit_buffer(struct vchiq_mmal_instance *instance,
  33339. + struct vchiq_mmal_port *port,
  33340. + struct mmal_buffer *buf);
  33341. +
  33342. +#endif /* MMAL_VCHIQ_H */
  33343. diff -Nur linux-3.18.8/drivers/media/platform/Kconfig linux-rpi/drivers/media/platform/Kconfig
  33344. --- linux-3.18.8/drivers/media/platform/Kconfig 2015-02-27 02:49:36.000000000 +0100
  33345. +++ linux-rpi/drivers/media/platform/Kconfig 2015-03-05 14:40:13.981715822 +0100
  33346. @@ -126,6 +126,7 @@
  33347. source "drivers/media/platform/soc_camera/Kconfig"
  33348. source "drivers/media/platform/exynos4-is/Kconfig"
  33349. source "drivers/media/platform/s5p-tv/Kconfig"
  33350. +source "drivers/media/platform/bcm2835/Kconfig"
  33351. endif # V4L_PLATFORM_DRIVERS
  33352. diff -Nur linux-3.18.8/drivers/media/platform/Makefile linux-rpi/drivers/media/platform/Makefile
  33353. --- linux-3.18.8/drivers/media/platform/Makefile 2015-02-27 02:49:36.000000000 +0100
  33354. +++ linux-rpi/drivers/media/platform/Makefile 2015-03-05 14:40:13.981715822 +0100
  33355. @@ -49,4 +49,6 @@
  33356. obj-y += omap/
  33357. +obj-$(CONFIG_VIDEO_BCM2835) += bcm2835/
  33358. +
  33359. ccflags-y += -I$(srctree)/drivers/media/i2c
  33360. diff -Nur linux-3.18.8/drivers/media/usb/dvb-usb-v2/rtl28xxu.c linux-rpi/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
  33361. --- linux-3.18.8/drivers/media/usb/dvb-usb-v2/rtl28xxu.c 2015-02-27 02:49:36.000000000 +0100
  33362. +++ linux-rpi/drivers/media/usb/dvb-usb-v2/rtl28xxu.c 2015-03-05 14:40:14.161715821 +0100
  33363. @@ -1531,6 +1531,10 @@
  33364. &rtl2832u_props, "Compro VideoMate U620F", NULL) },
  33365. { DVB_USB_DEVICE(USB_VID_KWORLD_2, 0xd394,
  33366. &rtl2832u_props, "MaxMedia HU394-T", NULL) },
  33367. + { DVB_USB_DEVICE(USB_VID_GTEK, 0xb803 /*USB_PID_AUGUST_DVBT205*/,
  33368. + &rtl2832u_props, "August DVB-T 205", NULL) },
  33369. + { DVB_USB_DEVICE(USB_VID_GTEK, 0xa803 /*USB_PID_AUGUST_DVBT205*/,
  33370. + &rtl2832u_props, "August DVB-T 205", NULL) },
  33371. { DVB_USB_DEVICE(USB_VID_LEADTEK, 0x6a03,
  33372. &rtl2832u_props, "Leadtek WinFast DTV Dongle mini", NULL) },
  33373. { DVB_USB_DEVICE(USB_VID_GTEK, USB_PID_CPYTO_REDI_PC50A,
  33374. diff -Nur linux-3.18.8/drivers/misc/Kconfig linux-rpi/drivers/misc/Kconfig
  33375. --- linux-3.18.8/drivers/misc/Kconfig 2015-02-27 02:49:36.000000000 +0100
  33376. +++ linux-rpi/drivers/misc/Kconfig 2015-03-05 14:40:14.221715820 +0100
  33377. @@ -524,6 +524,7 @@
  33378. source "drivers/misc/altera-stapl/Kconfig"
  33379. source "drivers/misc/mei/Kconfig"
  33380. source "drivers/misc/vmw_vmci/Kconfig"
  33381. +source "drivers/misc/vc04_services/Kconfig"
  33382. source "drivers/misc/mic/Kconfig"
  33383. source "drivers/misc/genwqe/Kconfig"
  33384. source "drivers/misc/echo/Kconfig"
  33385. diff -Nur linux-3.18.8/drivers/misc/Makefile linux-rpi/drivers/misc/Makefile
  33386. --- linux-3.18.8/drivers/misc/Makefile 2015-02-27 02:49:36.000000000 +0100
  33387. +++ linux-rpi/drivers/misc/Makefile 2015-03-05 14:40:14.221715820 +0100
  33388. @@ -51,6 +51,7 @@
  33389. obj-$(CONFIG_VMWARE_VMCI) += vmw_vmci/
  33390. obj-$(CONFIG_LATTICE_ECP3_CONFIG) += lattice-ecp3-config.o
  33391. obj-$(CONFIG_SRAM) += sram.o
  33392. +obj-$(CONFIG_BCM2708_VCHIQ) += vc04_services/
  33393. obj-y += mic/
  33394. obj-$(CONFIG_GENWQE) += genwqe/
  33395. obj-$(CONFIG_ECHO) += echo/
  33396. diff -Nur linux-3.18.8/drivers/misc/vc04_services/interface/vchi/connections/connection.h linux-rpi/drivers/misc/vc04_services/interface/vchi/connections/connection.h
  33397. --- linux-3.18.8/drivers/misc/vc04_services/interface/vchi/connections/connection.h 1970-01-01 01:00:00.000000000 +0100
  33398. +++ linux-rpi/drivers/misc/vc04_services/interface/vchi/connections/connection.h 2015-03-05 14:40:14.401715819 +0100
  33399. @@ -0,0 +1,328 @@
  33400. +/**
  33401. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  33402. + *
  33403. + * Redistribution and use in source and binary forms, with or without
  33404. + * modification, are permitted provided that the following conditions
  33405. + * are met:
  33406. + * 1. Redistributions of source code must retain the above copyright
  33407. + * notice, this list of conditions, and the following disclaimer,
  33408. + * without modification.
  33409. + * 2. Redistributions in binary form must reproduce the above copyright
  33410. + * notice, this list of conditions and the following disclaimer in the
  33411. + * documentation and/or other materials provided with the distribution.
  33412. + * 3. The names of the above-listed copyright holders may not be used
  33413. + * to endorse or promote products derived from this software without
  33414. + * specific prior written permission.
  33415. + *
  33416. + * ALTERNATIVELY, this software may be distributed under the terms of the
  33417. + * GNU General Public License ("GPL") version 2, as published by the Free
  33418. + * Software Foundation.
  33419. + *
  33420. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  33421. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  33422. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  33423. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  33424. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  33425. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  33426. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  33427. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  33428. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  33429. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  33430. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33431. + */
  33432. +
  33433. +#ifndef CONNECTION_H_
  33434. +#define CONNECTION_H_
  33435. +
  33436. +#include <linux/kernel.h>
  33437. +#include <linux/types.h>
  33438. +#include <linux/semaphore.h>
  33439. +
  33440. +#include "interface/vchi/vchi_cfg_internal.h"
  33441. +#include "interface/vchi/vchi_common.h"
  33442. +#include "interface/vchi/message_drivers/message.h"
  33443. +
  33444. +/******************************************************************************
  33445. + Global defs
  33446. + *****************************************************************************/
  33447. +
  33448. +// Opaque handle for a connection / service pair
  33449. +typedef struct opaque_vchi_connection_connected_service_handle_t *VCHI_CONNECTION_SERVICE_HANDLE_T;
  33450. +
  33451. +// opaque handle to the connection state information
  33452. +typedef struct opaque_vchi_connection_info_t VCHI_CONNECTION_STATE_T;
  33453. +
  33454. +typedef struct vchi_connection_t VCHI_CONNECTION_T;
  33455. +
  33456. +
  33457. +/******************************************************************************
  33458. + API
  33459. + *****************************************************************************/
  33460. +
  33461. +// Routine to init a connection with a particular low level driver
  33462. +typedef VCHI_CONNECTION_STATE_T * (*VCHI_CONNECTION_INIT_T)( struct vchi_connection_t * connection,
  33463. + const VCHI_MESSAGE_DRIVER_T * driver );
  33464. +
  33465. +// Routine to control CRC enabling at a connection level
  33466. +typedef int32_t (*VCHI_CONNECTION_CRC_CONTROL_T)( VCHI_CONNECTION_STATE_T *state_handle,
  33467. + VCHI_CRC_CONTROL_T control );
  33468. +
  33469. +// Routine to create a service
  33470. +typedef int32_t (*VCHI_CONNECTION_SERVICE_CONNECT_T)( VCHI_CONNECTION_STATE_T *state_handle,
  33471. + int32_t service_id,
  33472. + uint32_t rx_fifo_size,
  33473. + uint32_t tx_fifo_size,
  33474. + int server,
  33475. + VCHI_CALLBACK_T callback,
  33476. + void *callback_param,
  33477. + int32_t want_crc,
  33478. + int32_t want_unaligned_bulk_rx,
  33479. + int32_t want_unaligned_bulk_tx,
  33480. + VCHI_CONNECTION_SERVICE_HANDLE_T *service_handle );
  33481. +
  33482. +// Routine to close a service
  33483. +typedef int32_t (*VCHI_CONNECTION_SERVICE_DISCONNECT_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle );
  33484. +
  33485. +// Routine to queue a message
  33486. +typedef int32_t (*VCHI_CONNECTION_SERVICE_QUEUE_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  33487. + const void *data,
  33488. + uint32_t data_size,
  33489. + VCHI_FLAGS_T flags,
  33490. + void *msg_handle );
  33491. +
  33492. +// scatter-gather (vector) message queueing
  33493. +typedef int32_t (*VCHI_CONNECTION_SERVICE_QUEUE_MESSAGEV_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  33494. + VCHI_MSG_VECTOR_T *vector,
  33495. + uint32_t count,
  33496. + VCHI_FLAGS_T flags,
  33497. + void *msg_handle );
  33498. +
  33499. +// Routine to dequeue a message
  33500. +typedef int32_t (*VCHI_CONNECTION_SERVICE_DEQUEUE_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  33501. + void *data,
  33502. + uint32_t max_data_size_to_read,
  33503. + uint32_t *actual_msg_size,
  33504. + VCHI_FLAGS_T flags );
  33505. +
  33506. +// Routine to peek at a message
  33507. +typedef int32_t (*VCHI_CONNECTION_SERVICE_PEEK_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  33508. + void **data,
  33509. + uint32_t *msg_size,
  33510. + VCHI_FLAGS_T flags );
  33511. +
  33512. +// Routine to hold a message
  33513. +typedef int32_t (*VCHI_CONNECTION_SERVICE_HOLD_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  33514. + void **data,
  33515. + uint32_t *msg_size,
  33516. + VCHI_FLAGS_T flags,
  33517. + void **message_handle );
  33518. +
  33519. +// Routine to initialise a received message iterator
  33520. +typedef int32_t (*VCHI_CONNECTION_SERVICE_LOOKAHEAD_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  33521. + VCHI_MSG_ITER_T *iter,
  33522. + VCHI_FLAGS_T flags );
  33523. +
  33524. +// Routine to release a held message
  33525. +typedef int32_t (*VCHI_CONNECTION_HELD_MSG_RELEASE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  33526. + void *message_handle );
  33527. +
  33528. +// Routine to get info on a held message
  33529. +typedef int32_t (*VCHI_CONNECTION_HELD_MSG_INFO_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  33530. + void *message_handle,
  33531. + void **data,
  33532. + int32_t *msg_size,
  33533. + uint32_t *tx_timestamp,
  33534. + uint32_t *rx_timestamp );
  33535. +
  33536. +// Routine to check whether the iterator has a next message
  33537. +typedef int32_t (*VCHI_CONNECTION_MSG_ITER_HAS_NEXT_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service,
  33538. + const VCHI_MSG_ITER_T *iter );
  33539. +
  33540. +// Routine to advance the iterator
  33541. +typedef int32_t (*VCHI_CONNECTION_MSG_ITER_NEXT_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service,
  33542. + VCHI_MSG_ITER_T *iter,
  33543. + void **data,
  33544. + uint32_t *msg_size );
  33545. +
  33546. +// Routine to remove the last message returned by the iterator
  33547. +typedef int32_t (*VCHI_CONNECTION_MSG_ITER_REMOVE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service,
  33548. + VCHI_MSG_ITER_T *iter );
  33549. +
  33550. +// Routine to hold the last message returned by the iterator
  33551. +typedef int32_t (*VCHI_CONNECTION_MSG_ITER_HOLD_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service,
  33552. + VCHI_MSG_ITER_T *iter,
  33553. + void **msg_handle );
  33554. +
  33555. +// Routine to transmit bulk data
  33556. +typedef int32_t (*VCHI_CONNECTION_BULK_QUEUE_TRANSMIT_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  33557. + const void *data_src,
  33558. + uint32_t data_size,
  33559. + VCHI_FLAGS_T flags,
  33560. + void *bulk_handle );
  33561. +
  33562. +// Routine to receive data
  33563. +typedef int32_t (*VCHI_CONNECTION_BULK_QUEUE_RECEIVE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  33564. + void *data_dst,
  33565. + uint32_t data_size,
  33566. + VCHI_FLAGS_T flags,
  33567. + void *bulk_handle );
  33568. +
  33569. +// Routine to report if a server is available
  33570. +typedef int32_t (*VCHI_CONNECTION_SERVER_PRESENT)( VCHI_CONNECTION_STATE_T *state, int32_t service_id, int32_t peer_flags );
  33571. +
  33572. +// Routine to report the number of RX slots available
  33573. +typedef int (*VCHI_CONNECTION_RX_SLOTS_AVAILABLE)( const VCHI_CONNECTION_STATE_T *state );
  33574. +
  33575. +// Routine to report the RX slot size
  33576. +typedef uint32_t (*VCHI_CONNECTION_RX_SLOT_SIZE)( const VCHI_CONNECTION_STATE_T *state );
  33577. +
  33578. +// Callback to indicate that the other side has added a buffer to the rx bulk DMA FIFO
  33579. +typedef void (*VCHI_CONNECTION_RX_BULK_BUFFER_ADDED)(VCHI_CONNECTION_STATE_T *state,
  33580. + int32_t service,
  33581. + uint32_t length,
  33582. + MESSAGE_TX_CHANNEL_T channel,
  33583. + uint32_t channel_params,
  33584. + uint32_t data_length,
  33585. + uint32_t data_offset);
  33586. +
  33587. +// Callback to inform a service that a Xon or Xoff message has been received
  33588. +typedef void (*VCHI_CONNECTION_FLOW_CONTROL)(VCHI_CONNECTION_STATE_T *state, int32_t service_id, int32_t xoff);
  33589. +
  33590. +// Callback to inform a service that a server available reply message has been received
  33591. +typedef void (*VCHI_CONNECTION_SERVER_AVAILABLE_REPLY)(VCHI_CONNECTION_STATE_T *state, int32_t service_id, uint32_t flags);
  33592. +
  33593. +// Callback to indicate that bulk auxiliary messages have arrived
  33594. +typedef void (*VCHI_CONNECTION_BULK_AUX_RECEIVED)(VCHI_CONNECTION_STATE_T *state);
  33595. +
  33596. +// Callback to indicate that bulk auxiliary messages have arrived
  33597. +typedef void (*VCHI_CONNECTION_BULK_AUX_TRANSMITTED)(VCHI_CONNECTION_STATE_T *state, void *handle);
  33598. +
  33599. +// Callback with all the connection info you require
  33600. +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);
  33601. +
  33602. +// Callback to inform of a disconnect
  33603. +typedef void (*VCHI_CONNECTION_DISCONNECT)(VCHI_CONNECTION_STATE_T *state, uint32_t flags);
  33604. +
  33605. +// Callback to inform of a power control request
  33606. +typedef void (*VCHI_CONNECTION_POWER_CONTROL)(VCHI_CONNECTION_STATE_T *state, MESSAGE_TX_CHANNEL_T channel, int32_t enable);
  33607. +
  33608. +// allocate memory suitably aligned for this connection
  33609. +typedef void * (*VCHI_BUFFER_ALLOCATE)(VCHI_CONNECTION_SERVICE_HANDLE_T service_handle, uint32_t * length);
  33610. +
  33611. +// free memory allocated by buffer_allocate
  33612. +typedef void (*VCHI_BUFFER_FREE)(VCHI_CONNECTION_SERVICE_HANDLE_T service_handle, void * address);
  33613. +
  33614. +
  33615. +/******************************************************************************
  33616. + System driver struct
  33617. + *****************************************************************************/
  33618. +
  33619. +struct opaque_vchi_connection_api_t
  33620. +{
  33621. + // Routine to init the connection
  33622. + VCHI_CONNECTION_INIT_T init;
  33623. +
  33624. + // Connection-level CRC control
  33625. + VCHI_CONNECTION_CRC_CONTROL_T crc_control;
  33626. +
  33627. + // Routine to connect to or create service
  33628. + VCHI_CONNECTION_SERVICE_CONNECT_T service_connect;
  33629. +
  33630. + // Routine to disconnect from a service
  33631. + VCHI_CONNECTION_SERVICE_DISCONNECT_T service_disconnect;
  33632. +
  33633. + // Routine to queue a message
  33634. + VCHI_CONNECTION_SERVICE_QUEUE_MESSAGE_T service_queue_msg;
  33635. +
  33636. + // scatter-gather (vector) message queue
  33637. + VCHI_CONNECTION_SERVICE_QUEUE_MESSAGEV_T service_queue_msgv;
  33638. +
  33639. + // Routine to dequeue a message
  33640. + VCHI_CONNECTION_SERVICE_DEQUEUE_MESSAGE_T service_dequeue_msg;
  33641. +
  33642. + // Routine to peek at a message
  33643. + VCHI_CONNECTION_SERVICE_PEEK_MESSAGE_T service_peek_msg;
  33644. +
  33645. + // Routine to hold a message
  33646. + VCHI_CONNECTION_SERVICE_HOLD_MESSAGE_T service_hold_msg;
  33647. +
  33648. + // Routine to initialise a received message iterator
  33649. + VCHI_CONNECTION_SERVICE_LOOKAHEAD_MESSAGE_T service_look_ahead_msg;
  33650. +
  33651. + // Routine to release a message
  33652. + VCHI_CONNECTION_HELD_MSG_RELEASE_T held_msg_release;
  33653. +
  33654. + // Routine to get information on a held message
  33655. + VCHI_CONNECTION_HELD_MSG_INFO_T held_msg_info;
  33656. +
  33657. + // Routine to check for next message on iterator
  33658. + VCHI_CONNECTION_MSG_ITER_HAS_NEXT_T msg_iter_has_next;
  33659. +
  33660. + // Routine to get next message on iterator
  33661. + VCHI_CONNECTION_MSG_ITER_NEXT_T msg_iter_next;
  33662. +
  33663. + // Routine to remove the last message returned by iterator
  33664. + VCHI_CONNECTION_MSG_ITER_REMOVE_T msg_iter_remove;
  33665. +
  33666. + // Routine to hold the last message returned by iterator
  33667. + VCHI_CONNECTION_MSG_ITER_HOLD_T msg_iter_hold;
  33668. +
  33669. + // Routine to transmit bulk data
  33670. + VCHI_CONNECTION_BULK_QUEUE_TRANSMIT_T bulk_queue_transmit;
  33671. +
  33672. + // Routine to receive data
  33673. + VCHI_CONNECTION_BULK_QUEUE_RECEIVE_T bulk_queue_receive;
  33674. +
  33675. + // Routine to report the available servers
  33676. + VCHI_CONNECTION_SERVER_PRESENT server_present;
  33677. +
  33678. + // Routine to report the number of RX slots available
  33679. + VCHI_CONNECTION_RX_SLOTS_AVAILABLE connection_rx_slots_available;
  33680. +
  33681. + // Routine to report the RX slot size
  33682. + VCHI_CONNECTION_RX_SLOT_SIZE connection_rx_slot_size;
  33683. +
  33684. + // Callback to indicate that the other side has added a buffer to the rx bulk DMA FIFO
  33685. + VCHI_CONNECTION_RX_BULK_BUFFER_ADDED rx_bulk_buffer_added;
  33686. +
  33687. + // Callback to inform a service that a Xon or Xoff message has been received
  33688. + VCHI_CONNECTION_FLOW_CONTROL flow_control;
  33689. +
  33690. + // Callback to inform a service that a server available reply message has been received
  33691. + VCHI_CONNECTION_SERVER_AVAILABLE_REPLY server_available_reply;
  33692. +
  33693. + // Callback to indicate that bulk auxiliary messages have arrived
  33694. + VCHI_CONNECTION_BULK_AUX_RECEIVED bulk_aux_received;
  33695. +
  33696. + // Callback to indicate that a bulk auxiliary message has been transmitted
  33697. + VCHI_CONNECTION_BULK_AUX_TRANSMITTED bulk_aux_transmitted;
  33698. +
  33699. + // Callback to provide information about the connection
  33700. + VCHI_CONNECTION_INFO connection_info;
  33701. +
  33702. + // Callback to notify that peer has requested disconnect
  33703. + VCHI_CONNECTION_DISCONNECT disconnect;
  33704. +
  33705. + // Callback to notify that peer has requested power change
  33706. + VCHI_CONNECTION_POWER_CONTROL power_control;
  33707. +
  33708. + // allocate memory suitably aligned for this connection
  33709. + VCHI_BUFFER_ALLOCATE buffer_allocate;
  33710. +
  33711. + // free memory allocated by buffer_allocate
  33712. + VCHI_BUFFER_FREE buffer_free;
  33713. +
  33714. +};
  33715. +
  33716. +struct vchi_connection_t {
  33717. + const VCHI_CONNECTION_API_T *api;
  33718. + VCHI_CONNECTION_STATE_T *state;
  33719. +#ifdef VCHI_COARSE_LOCKING
  33720. + struct semaphore sem;
  33721. +#endif
  33722. +};
  33723. +
  33724. +
  33725. +#endif /* CONNECTION_H_ */
  33726. +
  33727. +/****************************** End of file **********************************/
  33728. diff -Nur linux-3.18.8/drivers/misc/vc04_services/interface/vchi/message_drivers/message.h linux-rpi/drivers/misc/vc04_services/interface/vchi/message_drivers/message.h
  33729. --- linux-3.18.8/drivers/misc/vc04_services/interface/vchi/message_drivers/message.h 1970-01-01 01:00:00.000000000 +0100
  33730. +++ linux-rpi/drivers/misc/vc04_services/interface/vchi/message_drivers/message.h 2015-03-05 14:40:14.401715819 +0100
  33731. @@ -0,0 +1,204 @@
  33732. +/**
  33733. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  33734. + *
  33735. + * Redistribution and use in source and binary forms, with or without
  33736. + * modification, are permitted provided that the following conditions
  33737. + * are met:
  33738. + * 1. Redistributions of source code must retain the above copyright
  33739. + * notice, this list of conditions, and the following disclaimer,
  33740. + * without modification.
  33741. + * 2. Redistributions in binary form must reproduce the above copyright
  33742. + * notice, this list of conditions and the following disclaimer in the
  33743. + * documentation and/or other materials provided with the distribution.
  33744. + * 3. The names of the above-listed copyright holders may not be used
  33745. + * to endorse or promote products derived from this software without
  33746. + * specific prior written permission.
  33747. + *
  33748. + * ALTERNATIVELY, this software may be distributed under the terms of the
  33749. + * GNU General Public License ("GPL") version 2, as published by the Free
  33750. + * Software Foundation.
  33751. + *
  33752. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  33753. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  33754. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  33755. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  33756. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  33757. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  33758. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  33759. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  33760. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  33761. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  33762. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33763. + */
  33764. +
  33765. +#ifndef _VCHI_MESSAGE_H_
  33766. +#define _VCHI_MESSAGE_H_
  33767. +
  33768. +#include <linux/kernel.h>
  33769. +#include <linux/types.h>
  33770. +#include <linux/semaphore.h>
  33771. +
  33772. +#include "interface/vchi/vchi_cfg_internal.h"
  33773. +#include "interface/vchi/vchi_common.h"
  33774. +
  33775. +
  33776. +typedef enum message_event_type {
  33777. + MESSAGE_EVENT_NONE,
  33778. + MESSAGE_EVENT_NOP,
  33779. + MESSAGE_EVENT_MESSAGE,
  33780. + MESSAGE_EVENT_SLOT_COMPLETE,
  33781. + MESSAGE_EVENT_RX_BULK_PAUSED,
  33782. + MESSAGE_EVENT_RX_BULK_COMPLETE,
  33783. + MESSAGE_EVENT_TX_COMPLETE,
  33784. + MESSAGE_EVENT_MSG_DISCARDED
  33785. +} MESSAGE_EVENT_TYPE_T;
  33786. +
  33787. +typedef enum vchi_msg_flags
  33788. +{
  33789. + VCHI_MSG_FLAGS_NONE = 0x0,
  33790. + VCHI_MSG_FLAGS_TERMINATE_DMA = 0x1
  33791. +} VCHI_MSG_FLAGS_T;
  33792. +
  33793. +typedef enum message_tx_channel
  33794. +{
  33795. + MESSAGE_TX_CHANNEL_MESSAGE = 0,
  33796. + MESSAGE_TX_CHANNEL_BULK = 1 // drivers may provide multiple bulk channels, from 1 upwards
  33797. +} MESSAGE_TX_CHANNEL_T;
  33798. +
  33799. +// Macros used for cycling through bulk channels
  33800. +#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)
  33801. +#define MESSAGE_TX_CHANNEL_BULK_NEXT(c) (MESSAGE_TX_CHANNEL_BULK+((c)-MESSAGE_TX_CHANNEL_BULK+1)%VCHI_MAX_BULK_TX_CHANNELS_PER_CONNECTION)
  33802. +
  33803. +typedef enum message_rx_channel
  33804. +{
  33805. + MESSAGE_RX_CHANNEL_MESSAGE = 0,
  33806. + MESSAGE_RX_CHANNEL_BULK = 1 // drivers may provide multiple bulk channels, from 1 upwards
  33807. +} MESSAGE_RX_CHANNEL_T;
  33808. +
  33809. +// Message receive slot information
  33810. +typedef struct rx_msg_slot_info {
  33811. +
  33812. + struct rx_msg_slot_info *next;
  33813. + //struct slot_info *prev;
  33814. +#if !defined VCHI_COARSE_LOCKING
  33815. + struct semaphore sem;
  33816. +#endif
  33817. +
  33818. + uint8_t *addr; // base address of slot
  33819. + uint32_t len; // length of slot in bytes
  33820. +
  33821. + uint32_t write_ptr; // hardware causes this to advance
  33822. + uint32_t read_ptr; // this module does the reading
  33823. + int active; // is this slot in the hardware dma fifo?
  33824. + uint32_t msgs_parsed; // count how many messages are in this slot
  33825. + uint32_t msgs_released; // how many messages have been released
  33826. + void *state; // connection state information
  33827. + uint8_t ref_count[VCHI_MAX_SERVICES_PER_CONNECTION]; // reference count for slots held by services
  33828. +} RX_MSG_SLOTINFO_T;
  33829. +
  33830. +// The message driver no longer needs to know about the fields of RX_BULK_SLOTINFO_T - sort this out.
  33831. +// In particular, it mustn't use addr and len - they're the client buffer, but the message
  33832. +// driver will be tasked with sending the aligned core section.
  33833. +typedef struct rx_bulk_slotinfo_t {
  33834. + struct rx_bulk_slotinfo_t *next;
  33835. +
  33836. + struct semaphore *blocking;
  33837. +
  33838. + // needed by DMA
  33839. + void *addr;
  33840. + uint32_t len;
  33841. +
  33842. + // needed for the callback
  33843. + void *service;
  33844. + void *handle;
  33845. + VCHI_FLAGS_T flags;
  33846. +} RX_BULK_SLOTINFO_T;
  33847. +
  33848. +
  33849. +/* ----------------------------------------------------------------------
  33850. + * each connection driver will have a pool of the following struct.
  33851. + *
  33852. + * the pool will be managed by vchi_qman_*
  33853. + * this means there will be multiple queues (single linked lists)
  33854. + * a given struct message_info will be on exactly one of these queues
  33855. + * at any one time
  33856. + * -------------------------------------------------------------------- */
  33857. +typedef struct rx_message_info {
  33858. +
  33859. + struct message_info *next;
  33860. + //struct message_info *prev;
  33861. +
  33862. + uint8_t *addr;
  33863. + uint32_t len;
  33864. + RX_MSG_SLOTINFO_T *slot; // points to whichever slot contains this message
  33865. + uint32_t tx_timestamp;
  33866. + uint32_t rx_timestamp;
  33867. +
  33868. +} RX_MESSAGE_INFO_T;
  33869. +
  33870. +typedef struct {
  33871. + MESSAGE_EVENT_TYPE_T type;
  33872. +
  33873. + struct {
  33874. + // for messages
  33875. + void *addr; // address of message
  33876. + uint16_t slot_delta; // whether this message indicated slot delta
  33877. + uint32_t len; // length of message
  33878. + RX_MSG_SLOTINFO_T *slot; // slot this message is in
  33879. + int32_t service; // service id this message is destined for
  33880. + uint32_t tx_timestamp; // timestamp from the header
  33881. + uint32_t rx_timestamp; // timestamp when we parsed it
  33882. + } message;
  33883. +
  33884. + // FIXME: cleanup slot reporting...
  33885. + RX_MSG_SLOTINFO_T *rx_msg;
  33886. + RX_BULK_SLOTINFO_T *rx_bulk;
  33887. + void *tx_handle;
  33888. + MESSAGE_TX_CHANNEL_T tx_channel;
  33889. +
  33890. +} MESSAGE_EVENT_T;
  33891. +
  33892. +
  33893. +// callbacks
  33894. +typedef void VCHI_MESSAGE_DRIVER_EVENT_CALLBACK_T( void *state );
  33895. +
  33896. +typedef struct {
  33897. + VCHI_MESSAGE_DRIVER_EVENT_CALLBACK_T *event_callback;
  33898. +} VCHI_MESSAGE_DRIVER_OPEN_T;
  33899. +
  33900. +
  33901. +// handle to this instance of message driver (as returned by ->open)
  33902. +typedef struct opaque_mhandle_t *VCHI_MDRIVER_HANDLE_T;
  33903. +
  33904. +struct opaque_vchi_message_driver_t {
  33905. + VCHI_MDRIVER_HANDLE_T *(*open)( VCHI_MESSAGE_DRIVER_OPEN_T *params, void *state );
  33906. + int32_t (*suspending)( VCHI_MDRIVER_HANDLE_T *handle );
  33907. + int32_t (*resumed)( VCHI_MDRIVER_HANDLE_T *handle );
  33908. + int32_t (*power_control)( VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T, int32_t enable );
  33909. + int32_t (*add_msg_rx_slot)( VCHI_MDRIVER_HANDLE_T *handle, RX_MSG_SLOTINFO_T *slot ); // rx message
  33910. + int32_t (*add_bulk_rx)( VCHI_MDRIVER_HANDLE_T *handle, void *data, uint32_t len, RX_BULK_SLOTINFO_T *slot ); // rx data (bulk)
  33911. + 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)
  33912. + void (*next_event)( VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_EVENT_T *event ); // get the next event from message_driver
  33913. + int32_t (*enable)( VCHI_MDRIVER_HANDLE_T *handle );
  33914. + int32_t (*form_message)( VCHI_MDRIVER_HANDLE_T *handle, int32_t service_id, VCHI_MSG_VECTOR_T *vector, uint32_t count, void
  33915. + *address, uint32_t length_avail, uint32_t max_total_length, int32_t pad_to_fill, int32_t allow_partial );
  33916. +
  33917. + int32_t (*update_message)( VCHI_MDRIVER_HANDLE_T *handle, void *dest, int16_t *slot_count );
  33918. + int32_t (*buffer_aligned)( VCHI_MDRIVER_HANDLE_T *handle, int tx, int uncached, const void *address, const uint32_t length );
  33919. + void * (*allocate_buffer)( VCHI_MDRIVER_HANDLE_T *handle, uint32_t *length );
  33920. + void (*free_buffer)( VCHI_MDRIVER_HANDLE_T *handle, void *address );
  33921. + int (*rx_slot_size)( VCHI_MDRIVER_HANDLE_T *handle, int msg_size );
  33922. + int (*tx_slot_size)( VCHI_MDRIVER_HANDLE_T *handle, int msg_size );
  33923. +
  33924. + int32_t (*tx_supports_terminate)( const VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T channel );
  33925. + uint32_t (*tx_bulk_chunk_size)( const VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T channel );
  33926. + int (*tx_alignment)( const VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T channel );
  33927. + int (*rx_alignment)( const VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_RX_CHANNEL_T channel );
  33928. + 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 );
  33929. + void (*debug)( VCHI_MDRIVER_HANDLE_T *handle );
  33930. +};
  33931. +
  33932. +
  33933. +#endif // _VCHI_MESSAGE_H_
  33934. +
  33935. +/****************************** End of file ***********************************/
  33936. diff -Nur linux-3.18.8/drivers/misc/vc04_services/interface/vchi/vchi_cfg.h linux-rpi/drivers/misc/vc04_services/interface/vchi/vchi_cfg.h
  33937. --- linux-3.18.8/drivers/misc/vc04_services/interface/vchi/vchi_cfg.h 1970-01-01 01:00:00.000000000 +0100
  33938. +++ linux-rpi/drivers/misc/vc04_services/interface/vchi/vchi_cfg.h 2015-03-05 14:40:14.401715819 +0100
  33939. @@ -0,0 +1,224 @@
  33940. +/**
  33941. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  33942. + *
  33943. + * Redistribution and use in source and binary forms, with or without
  33944. + * modification, are permitted provided that the following conditions
  33945. + * are met:
  33946. + * 1. Redistributions of source code must retain the above copyright
  33947. + * notice, this list of conditions, and the following disclaimer,
  33948. + * without modification.
  33949. + * 2. Redistributions in binary form must reproduce the above copyright
  33950. + * notice, this list of conditions and the following disclaimer in the
  33951. + * documentation and/or other materials provided with the distribution.
  33952. + * 3. The names of the above-listed copyright holders may not be used
  33953. + * to endorse or promote products derived from this software without
  33954. + * specific prior written permission.
  33955. + *
  33956. + * ALTERNATIVELY, this software may be distributed under the terms of the
  33957. + * GNU General Public License ("GPL") version 2, as published by the Free
  33958. + * Software Foundation.
  33959. + *
  33960. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  33961. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  33962. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  33963. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  33964. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  33965. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  33966. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  33967. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  33968. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  33969. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  33970. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33971. + */
  33972. +
  33973. +#ifndef VCHI_CFG_H_
  33974. +#define VCHI_CFG_H_
  33975. +
  33976. +/****************************************************************************************
  33977. + * Defines in this first section are part of the VCHI API and may be examined by VCHI
  33978. + * services.
  33979. + ***************************************************************************************/
  33980. +
  33981. +/* Required alignment of base addresses for bulk transfer, if unaligned transfers are not enabled */
  33982. +/* Really determined by the message driver, and should be available from a run-time call. */
  33983. +#ifndef VCHI_BULK_ALIGN
  33984. +# if __VCCOREVER__ >= 0x04000000
  33985. +# define VCHI_BULK_ALIGN 32 // Allows for the need to do cache cleans
  33986. +# else
  33987. +# define VCHI_BULK_ALIGN 16
  33988. +# endif
  33989. +#endif
  33990. +
  33991. +/* Required length multiple for bulk transfers, if unaligned transfers are not enabled */
  33992. +/* May be less than or greater than VCHI_BULK_ALIGN */
  33993. +/* Really determined by the message driver, and should be available from a run-time call. */
  33994. +#ifndef VCHI_BULK_GRANULARITY
  33995. +# if __VCCOREVER__ >= 0x04000000
  33996. +# define VCHI_BULK_GRANULARITY 32 // Allows for the need to do cache cleans
  33997. +# else
  33998. +# define VCHI_BULK_GRANULARITY 16
  33999. +# endif
  34000. +#endif
  34001. +
  34002. +/* The largest possible message to be queued with vchi_msg_queue. */
  34003. +#ifndef VCHI_MAX_MSG_SIZE
  34004. +# if defined VCHI_LOCAL_HOST_PORT
  34005. +# define VCHI_MAX_MSG_SIZE 16384 // makes file transfers fast, but should they be using bulk?
  34006. +# else
  34007. +# define VCHI_MAX_MSG_SIZE 4096 // NOTE: THIS MUST BE LARGER THAN OR EQUAL TO THE SIZE OF THE KHRONOS MERGE BUFFER!!
  34008. +# endif
  34009. +#endif
  34010. +
  34011. +/******************************************************************************************
  34012. + * Defines below are system configuration options, and should not be used by VCHI services.
  34013. + *****************************************************************************************/
  34014. +
  34015. +/* How many connections can we support? A localhost implementation uses 2 connections,
  34016. + * 1 for host-app, 1 for VMCS, and these are hooked together by a loopback MPHI VCFW
  34017. + * driver. */
  34018. +#ifndef VCHI_MAX_NUM_CONNECTIONS
  34019. +# define VCHI_MAX_NUM_CONNECTIONS 3
  34020. +#endif
  34021. +
  34022. +/* How many services can we open per connection? Extending this doesn't cost processing time, just a small
  34023. + * amount of static memory. */
  34024. +#ifndef VCHI_MAX_SERVICES_PER_CONNECTION
  34025. +# define VCHI_MAX_SERVICES_PER_CONNECTION 36
  34026. +#endif
  34027. +
  34028. +/* Adjust if using a message driver that supports more logical TX channels */
  34029. +#ifndef VCHI_MAX_BULK_TX_CHANNELS_PER_CONNECTION
  34030. +# define VCHI_MAX_BULK_TX_CHANNELS_PER_CONNECTION 9 // 1 MPHI + 8 CCP2 logical channels
  34031. +#endif
  34032. +
  34033. +/* Adjust if using a message driver that supports more logical RX channels */
  34034. +#ifndef VCHI_MAX_BULK_RX_CHANNELS_PER_CONNECTION
  34035. +# define VCHI_MAX_BULK_RX_CHANNELS_PER_CONNECTION 1 // 1 MPHI
  34036. +#endif
  34037. +
  34038. +/* How many receive slots do we use. This times VCHI_MAX_MSG_SIZE gives the effective
  34039. + * receive queue space, less message headers. */
  34040. +#ifndef VCHI_NUM_READ_SLOTS
  34041. +# if defined(VCHI_LOCAL_HOST_PORT)
  34042. +# define VCHI_NUM_READ_SLOTS 4
  34043. +# else
  34044. +# define VCHI_NUM_READ_SLOTS 48
  34045. +# endif
  34046. +#endif
  34047. +
  34048. +/* Do we utilise overrun facility for receive message slots? Can aid peer transmit
  34049. + * performance. Only define on VideoCore end, talking to host.
  34050. + */
  34051. +//#define VCHI_MSG_RX_OVERRUN
  34052. +
  34053. +/* How many transmit slots do we use. Generally don't need many, as the hardware driver
  34054. + * underneath VCHI will usually have its own buffering. */
  34055. +#ifndef VCHI_NUM_WRITE_SLOTS
  34056. +# define VCHI_NUM_WRITE_SLOTS 4
  34057. +#endif
  34058. +
  34059. +/* If a service has held or queued received messages in VCHI_XOFF_THRESHOLD or more slots,
  34060. + * then it's taking up too much buffer space, and the peer service will be told to stop
  34061. + * transmitting with an XOFF message. For this to be effective, the VCHI_NUM_READ_SLOTS
  34062. + * needs to be considerably bigger than VCHI_NUM_WRITE_SLOTS, or the transmit latency
  34063. + * is too high. */
  34064. +#ifndef VCHI_XOFF_THRESHOLD
  34065. +# define VCHI_XOFF_THRESHOLD (VCHI_NUM_READ_SLOTS / 2)
  34066. +#endif
  34067. +
  34068. +/* After we've sent an XOFF, the peer will be told to resume transmission once the local
  34069. + * service has dequeued/released enough messages that it's now occupying
  34070. + * VCHI_XON_THRESHOLD slots or fewer. */
  34071. +#ifndef VCHI_XON_THRESHOLD
  34072. +# define VCHI_XON_THRESHOLD (VCHI_NUM_READ_SLOTS / 4)
  34073. +#endif
  34074. +
  34075. +/* A size below which a bulk transfer omits the handshake completely and always goes
  34076. + * via the message channel, if bulk auxiliary is being sent on that service. (The user
  34077. + * can guarantee this by enabling unaligned transmits).
  34078. + * Not API. */
  34079. +#ifndef VCHI_MIN_BULK_SIZE
  34080. +# define VCHI_MIN_BULK_SIZE ( VCHI_MAX_MSG_SIZE / 2 < 4096 ? VCHI_MAX_MSG_SIZE / 2 : 4096 )
  34081. +#endif
  34082. +
  34083. +/* Maximum size of bulk transmission chunks, for each interface type. A trade-off between
  34084. + * speed and latency; the smaller the chunk size the better change of messages and other
  34085. + * bulk transmissions getting in when big bulk transfers are happening. Set to 0 to not
  34086. + * break transmissions into chunks.
  34087. + */
  34088. +#ifndef VCHI_MAX_BULK_CHUNK_SIZE_MPHI
  34089. +# define VCHI_MAX_BULK_CHUNK_SIZE_MPHI (16 * 1024)
  34090. +#endif
  34091. +
  34092. +/* NB Chunked CCP2 transmissions violate the letter of the CCP2 spec by using "JPEG8" mode
  34093. + * with multiple-line frames. Only use if the receiver can cope. */
  34094. +#ifndef VCHI_MAX_BULK_CHUNK_SIZE_CCP2
  34095. +# define VCHI_MAX_BULK_CHUNK_SIZE_CCP2 0
  34096. +#endif
  34097. +
  34098. +/* How many TX messages can we have pending in our transmit slots. Once exhausted,
  34099. + * vchi_msg_queue will be blocked. */
  34100. +#ifndef VCHI_TX_MSG_QUEUE_SIZE
  34101. +# define VCHI_TX_MSG_QUEUE_SIZE 256
  34102. +#endif
  34103. +
  34104. +/* How many RX messages can we have parsed in the receive slots. Once exhausted, parsing
  34105. + * will be suspended until older messages are dequeued/released. */
  34106. +#ifndef VCHI_RX_MSG_QUEUE_SIZE
  34107. +# define VCHI_RX_MSG_QUEUE_SIZE 256
  34108. +#endif
  34109. +
  34110. +/* Really should be able to cope if we run out of received message descriptors, by
  34111. + * suspending parsing as the comment above says, but we don't. This sweeps the issue
  34112. + * under the carpet. */
  34113. +#if VCHI_RX_MSG_QUEUE_SIZE < (VCHI_MAX_MSG_SIZE/16 + 1) * VCHI_NUM_READ_SLOTS
  34114. +# undef VCHI_RX_MSG_QUEUE_SIZE
  34115. +# define VCHI_RX_MSG_QUEUE_SIZE (VCHI_MAX_MSG_SIZE/16 + 1) * VCHI_NUM_READ_SLOTS
  34116. +#endif
  34117. +
  34118. +/* How many bulk transmits can we have pending. Once exhausted, vchi_bulk_queue_transmit
  34119. + * will be blocked. */
  34120. +#ifndef VCHI_TX_BULK_QUEUE_SIZE
  34121. +# define VCHI_TX_BULK_QUEUE_SIZE 64
  34122. +#endif
  34123. +
  34124. +/* How many bulk receives can we have pending. Once exhausted, vchi_bulk_queue_receive
  34125. + * will be blocked. */
  34126. +#ifndef VCHI_RX_BULK_QUEUE_SIZE
  34127. +# define VCHI_RX_BULK_QUEUE_SIZE 64
  34128. +#endif
  34129. +
  34130. +/* A limit on how many outstanding bulk requests we expect the peer to give us. If
  34131. + * the peer asks for more than this, VCHI will fail and assert. The number is determined
  34132. + * by the peer's hardware - it's the number of outstanding requests that can be queued
  34133. + * on all bulk channels. VC3's MPHI peripheral allows 16. */
  34134. +#ifndef VCHI_MAX_PEER_BULK_REQUESTS
  34135. +# define VCHI_MAX_PEER_BULK_REQUESTS 32
  34136. +#endif
  34137. +
  34138. +/* Define VCHI_CCP2TX_MANUAL_POWER if the host tells us when to turn the CCP2
  34139. + * transmitter on and off.
  34140. + */
  34141. +/*#define VCHI_CCP2TX_MANUAL_POWER*/
  34142. +
  34143. +#ifndef VCHI_CCP2TX_MANUAL_POWER
  34144. +
  34145. +/* Timeout (in milliseconds) for putting the CCP2TX interface into IDLE state. Set
  34146. + * negative for no IDLE.
  34147. + */
  34148. +# ifndef VCHI_CCP2TX_IDLE_TIMEOUT
  34149. +# define VCHI_CCP2TX_IDLE_TIMEOUT 5
  34150. +# endif
  34151. +
  34152. +/* Timeout (in milliseconds) for putting the CCP2TX interface into OFF state. Set
  34153. + * negative for no OFF.
  34154. + */
  34155. +# ifndef VCHI_CCP2TX_OFF_TIMEOUT
  34156. +# define VCHI_CCP2TX_OFF_TIMEOUT 1000
  34157. +# endif
  34158. +
  34159. +#endif /* VCHI_CCP2TX_MANUAL_POWER */
  34160. +
  34161. +#endif /* VCHI_CFG_H_ */
  34162. +
  34163. +/****************************** End of file **********************************/
  34164. diff -Nur linux-3.18.8/drivers/misc/vc04_services/interface/vchi/vchi_cfg_internal.h linux-rpi/drivers/misc/vc04_services/interface/vchi/vchi_cfg_internal.h
  34165. --- linux-3.18.8/drivers/misc/vc04_services/interface/vchi/vchi_cfg_internal.h 1970-01-01 01:00:00.000000000 +0100
  34166. +++ linux-rpi/drivers/misc/vc04_services/interface/vchi/vchi_cfg_internal.h 2015-03-05 14:40:14.401715819 +0100
  34167. @@ -0,0 +1,71 @@
  34168. +/**
  34169. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  34170. + *
  34171. + * Redistribution and use in source and binary forms, with or without
  34172. + * modification, are permitted provided that the following conditions
  34173. + * are met:
  34174. + * 1. Redistributions of source code must retain the above copyright
  34175. + * notice, this list of conditions, and the following disclaimer,
  34176. + * without modification.
  34177. + * 2. Redistributions in binary form must reproduce the above copyright
  34178. + * notice, this list of conditions and the following disclaimer in the
  34179. + * documentation and/or other materials provided with the distribution.
  34180. + * 3. The names of the above-listed copyright holders may not be used
  34181. + * to endorse or promote products derived from this software without
  34182. + * specific prior written permission.
  34183. + *
  34184. + * ALTERNATIVELY, this software may be distributed under the terms of the
  34185. + * GNU General Public License ("GPL") version 2, as published by the Free
  34186. + * Software Foundation.
  34187. + *
  34188. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  34189. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  34190. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  34191. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  34192. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  34193. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  34194. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  34195. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  34196. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  34197. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  34198. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34199. + */
  34200. +
  34201. +#ifndef VCHI_CFG_INTERNAL_H_
  34202. +#define VCHI_CFG_INTERNAL_H_
  34203. +
  34204. +/****************************************************************************************
  34205. + * Control optimisation attempts.
  34206. + ***************************************************************************************/
  34207. +
  34208. +// Don't use lots of short-term locks - use great long ones, reducing the overall locks-per-second
  34209. +#define VCHI_COARSE_LOCKING
  34210. +
  34211. +// Avoid lock then unlock on exit from blocking queue operations (msg tx, bulk rx/tx)
  34212. +// (only relevant if VCHI_COARSE_LOCKING)
  34213. +#define VCHI_ELIDE_BLOCK_EXIT_LOCK
  34214. +
  34215. +// Avoid lock on non-blocking peek
  34216. +// (only relevant if VCHI_COARSE_LOCKING)
  34217. +#define VCHI_AVOID_PEEK_LOCK
  34218. +
  34219. +// Use one slot-handler thread per connection, rather than 1 thread dealing with all connections in rotation.
  34220. +#define VCHI_MULTIPLE_HANDLER_THREADS
  34221. +
  34222. +// Put free descriptors onto the head of the free queue, rather than the tail, so that we don't thrash
  34223. +// our way through the pool of descriptors.
  34224. +#define VCHI_PUSH_FREE_DESCRIPTORS_ONTO_HEAD
  34225. +
  34226. +// Don't issue a MSG_AVAILABLE callback for every single message. Possibly only safe if VCHI_COARSE_LOCKING.
  34227. +#define VCHI_FEWER_MSG_AVAILABLE_CALLBACKS
  34228. +
  34229. +// Don't use message descriptors for TX messages that don't need them
  34230. +#define VCHI_MINIMISE_TX_MSG_DESCRIPTORS
  34231. +
  34232. +// Nano-locks for multiqueue
  34233. +//#define VCHI_MQUEUE_NANOLOCKS
  34234. +
  34235. +// Lock-free(er) dequeuing
  34236. +//#define VCHI_RX_NANOLOCKS
  34237. +
  34238. +#endif /*VCHI_CFG_INTERNAL_H_*/
  34239. diff -Nur linux-3.18.8/drivers/misc/vc04_services/interface/vchi/vchi_common.h linux-rpi/drivers/misc/vc04_services/interface/vchi/vchi_common.h
  34240. --- linux-3.18.8/drivers/misc/vc04_services/interface/vchi/vchi_common.h 1970-01-01 01:00:00.000000000 +0100
  34241. +++ linux-rpi/drivers/misc/vc04_services/interface/vchi/vchi_common.h 2015-03-05 14:40:14.401715819 +0100
  34242. @@ -0,0 +1,175 @@
  34243. +/**
  34244. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  34245. + *
  34246. + * Redistribution and use in source and binary forms, with or without
  34247. + * modification, are permitted provided that the following conditions
  34248. + * are met:
  34249. + * 1. Redistributions of source code must retain the above copyright
  34250. + * notice, this list of conditions, and the following disclaimer,
  34251. + * without modification.
  34252. + * 2. Redistributions in binary form must reproduce the above copyright
  34253. + * notice, this list of conditions and the following disclaimer in the
  34254. + * documentation and/or other materials provided with the distribution.
  34255. + * 3. The names of the above-listed copyright holders may not be used
  34256. + * to endorse or promote products derived from this software without
  34257. + * specific prior written permission.
  34258. + *
  34259. + * ALTERNATIVELY, this software may be distributed under the terms of the
  34260. + * GNU General Public License ("GPL") version 2, as published by the Free
  34261. + * Software Foundation.
  34262. + *
  34263. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  34264. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  34265. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  34266. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  34267. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  34268. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  34269. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  34270. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  34271. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  34272. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  34273. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34274. + */
  34275. +
  34276. +#ifndef VCHI_COMMON_H_
  34277. +#define VCHI_COMMON_H_
  34278. +
  34279. +
  34280. +//flags used when sending messages (must be bitmapped)
  34281. +typedef enum
  34282. +{
  34283. + VCHI_FLAGS_NONE = 0x0,
  34284. + 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)
  34285. + VCHI_FLAGS_CALLBACK_WHEN_OP_COMPLETE = 0x2, // run a callback when message sent
  34286. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED = 0x4, // return once the transfer is in a queue ready to go
  34287. + VCHI_FLAGS_ALLOW_PARTIAL = 0x8,
  34288. + VCHI_FLAGS_BLOCK_UNTIL_DATA_READ = 0x10,
  34289. + VCHI_FLAGS_CALLBACK_WHEN_DATA_READ = 0x20,
  34290. +
  34291. + VCHI_FLAGS_ALIGN_SLOT = 0x000080, // internal use only
  34292. + VCHI_FLAGS_BULK_AUX_QUEUED = 0x010000, // internal use only
  34293. + VCHI_FLAGS_BULK_AUX_COMPLETE = 0x020000, // internal use only
  34294. + VCHI_FLAGS_BULK_DATA_QUEUED = 0x040000, // internal use only
  34295. + VCHI_FLAGS_BULK_DATA_COMPLETE = 0x080000, // internal use only
  34296. + VCHI_FLAGS_INTERNAL = 0xFF0000
  34297. +} VCHI_FLAGS_T;
  34298. +
  34299. +// constants for vchi_crc_control()
  34300. +typedef enum {
  34301. + VCHI_CRC_NOTHING = -1,
  34302. + VCHI_CRC_PER_SERVICE = 0,
  34303. + VCHI_CRC_EVERYTHING = 1,
  34304. +} VCHI_CRC_CONTROL_T;
  34305. +
  34306. +//callback reasons when an event occurs on a service
  34307. +typedef enum
  34308. +{
  34309. + VCHI_CALLBACK_REASON_MIN,
  34310. +
  34311. + //This indicates that there is data available
  34312. + //handle is the msg id that was transmitted with the data
  34313. + // When a message is received and there was no FULL message available previously, send callback
  34314. + // Tasks get kicked by the callback, reset their event and try and read from the fifo until it fails
  34315. + VCHI_CALLBACK_MSG_AVAILABLE,
  34316. + VCHI_CALLBACK_MSG_SENT,
  34317. + VCHI_CALLBACK_MSG_SPACE_AVAILABLE, // XXX not yet implemented
  34318. +
  34319. + // This indicates that a transfer from the other side has completed
  34320. + VCHI_CALLBACK_BULK_RECEIVED,
  34321. + //This indicates that data queued up to be sent has now gone
  34322. + //handle is the msg id that was used when sending the data
  34323. + VCHI_CALLBACK_BULK_SENT,
  34324. + VCHI_CALLBACK_BULK_RX_SPACE_AVAILABLE, // XXX not yet implemented
  34325. + VCHI_CALLBACK_BULK_TX_SPACE_AVAILABLE, // XXX not yet implemented
  34326. +
  34327. + VCHI_CALLBACK_SERVICE_CLOSED,
  34328. +
  34329. + // this side has sent XOFF to peer due to lack of data consumption by service
  34330. + // (suggests the service may need to take some recovery action if it has
  34331. + // been deliberately holding off consuming data)
  34332. + VCHI_CALLBACK_SENT_XOFF,
  34333. + VCHI_CALLBACK_SENT_XON,
  34334. +
  34335. + // indicates that a bulk transfer has finished reading the source buffer
  34336. + VCHI_CALLBACK_BULK_DATA_READ,
  34337. +
  34338. + // power notification events (currently host side only)
  34339. + VCHI_CALLBACK_PEER_OFF,
  34340. + VCHI_CALLBACK_PEER_SUSPENDED,
  34341. + VCHI_CALLBACK_PEER_ON,
  34342. + VCHI_CALLBACK_PEER_RESUMED,
  34343. + VCHI_CALLBACK_FORCED_POWER_OFF,
  34344. +
  34345. +#ifdef USE_VCHIQ_ARM
  34346. + // some extra notifications provided by vchiq_arm
  34347. + VCHI_CALLBACK_SERVICE_OPENED,
  34348. + VCHI_CALLBACK_BULK_RECEIVE_ABORTED,
  34349. + VCHI_CALLBACK_BULK_TRANSMIT_ABORTED,
  34350. +#endif
  34351. +
  34352. + VCHI_CALLBACK_REASON_MAX
  34353. +} VCHI_CALLBACK_REASON_T;
  34354. +
  34355. +// service control options
  34356. +typedef enum
  34357. +{
  34358. + VCHI_SERVICE_OPTION_MIN,
  34359. +
  34360. + VCHI_SERVICE_OPTION_TRACE,
  34361. + VCHI_SERVICE_OPTION_SYNCHRONOUS,
  34362. +
  34363. + VCHI_SERVICE_OPTION_MAX
  34364. +} VCHI_SERVICE_OPTION_T;
  34365. +
  34366. +
  34367. +//Callback used by all services / bulk transfers
  34368. +typedef void (*VCHI_CALLBACK_T)( void *callback_param, //my service local param
  34369. + VCHI_CALLBACK_REASON_T reason,
  34370. + void *handle ); //for transmitting msg's only
  34371. +
  34372. +
  34373. +
  34374. +/*
  34375. + * Define vector struct for scatter-gather (vector) operations
  34376. + * Vectors can be nested - if a vector element has negative length, then
  34377. + * the data pointer is treated as pointing to another vector array, with
  34378. + * '-vec_len' elements. Thus to append a header onto an existing vector,
  34379. + * you can do this:
  34380. + *
  34381. + * void foo(const VCHI_MSG_VECTOR_T *v, int n)
  34382. + * {
  34383. + * VCHI_MSG_VECTOR_T nv[2];
  34384. + * nv[0].vec_base = my_header;
  34385. + * nv[0].vec_len = sizeof my_header;
  34386. + * nv[1].vec_base = v;
  34387. + * nv[1].vec_len = -n;
  34388. + * ...
  34389. + *
  34390. + */
  34391. +typedef struct vchi_msg_vector {
  34392. + const void *vec_base;
  34393. + int32_t vec_len;
  34394. +} VCHI_MSG_VECTOR_T;
  34395. +
  34396. +// Opaque type for a connection API
  34397. +typedef struct opaque_vchi_connection_api_t VCHI_CONNECTION_API_T;
  34398. +
  34399. +// Opaque type for a message driver
  34400. +typedef struct opaque_vchi_message_driver_t VCHI_MESSAGE_DRIVER_T;
  34401. +
  34402. +
  34403. +// Iterator structure for reading ahead through received message queue. Allocated by client,
  34404. +// initialised by vchi_msg_look_ahead. Fields are for internal VCHI use only.
  34405. +// Iterates over messages in queue at the instant of the call to vchi_msg_lookahead -
  34406. +// will not proceed to messages received since. Behaviour is undefined if an iterator
  34407. +// is used again after messages for that service are removed/dequeued by any
  34408. +// means other than vchi_msg_iter_... calls on the iterator itself.
  34409. +typedef struct {
  34410. + struct opaque_vchi_service_t *service;
  34411. + void *last;
  34412. + void *next;
  34413. + void *remove;
  34414. +} VCHI_MSG_ITER_T;
  34415. +
  34416. +
  34417. +#endif // VCHI_COMMON_H_
  34418. diff -Nur linux-3.18.8/drivers/misc/vc04_services/interface/vchi/vchi.h linux-rpi/drivers/misc/vc04_services/interface/vchi/vchi.h
  34419. --- linux-3.18.8/drivers/misc/vc04_services/interface/vchi/vchi.h 1970-01-01 01:00:00.000000000 +0100
  34420. +++ linux-rpi/drivers/misc/vc04_services/interface/vchi/vchi.h 2015-03-05 14:40:14.401715819 +0100
  34421. @@ -0,0 +1,378 @@
  34422. +/**
  34423. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  34424. + *
  34425. + * Redistribution and use in source and binary forms, with or without
  34426. + * modification, are permitted provided that the following conditions
  34427. + * are met:
  34428. + * 1. Redistributions of source code must retain the above copyright
  34429. + * notice, this list of conditions, and the following disclaimer,
  34430. + * without modification.
  34431. + * 2. Redistributions in binary form must reproduce the above copyright
  34432. + * notice, this list of conditions and the following disclaimer in the
  34433. + * documentation and/or other materials provided with the distribution.
  34434. + * 3. The names of the above-listed copyright holders may not be used
  34435. + * to endorse or promote products derived from this software without
  34436. + * specific prior written permission.
  34437. + *
  34438. + * ALTERNATIVELY, this software may be distributed under the terms of the
  34439. + * GNU General Public License ("GPL") version 2, as published by the Free
  34440. + * Software Foundation.
  34441. + *
  34442. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  34443. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  34444. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  34445. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  34446. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  34447. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  34448. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  34449. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  34450. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  34451. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  34452. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34453. + */
  34454. +
  34455. +#ifndef VCHI_H_
  34456. +#define VCHI_H_
  34457. +
  34458. +#include "interface/vchi/vchi_cfg.h"
  34459. +#include "interface/vchi/vchi_common.h"
  34460. +#include "interface/vchi/connections/connection.h"
  34461. +#include "vchi_mh.h"
  34462. +
  34463. +
  34464. +/******************************************************************************
  34465. + Global defs
  34466. + *****************************************************************************/
  34467. +
  34468. +#define VCHI_BULK_ROUND_UP(x) ((((unsigned long)(x))+VCHI_BULK_ALIGN-1) & ~(VCHI_BULK_ALIGN-1))
  34469. +#define VCHI_BULK_ROUND_DOWN(x) (((unsigned long)(x)) & ~(VCHI_BULK_ALIGN-1))
  34470. +#define VCHI_BULK_ALIGN_NBYTES(x) (VCHI_BULK_ALIGNED(x) ? 0 : (VCHI_BULK_ALIGN - ((unsigned long)(x) & (VCHI_BULK_ALIGN-1))))
  34471. +
  34472. +#ifdef USE_VCHIQ_ARM
  34473. +#define VCHI_BULK_ALIGNED(x) 1
  34474. +#else
  34475. +#define VCHI_BULK_ALIGNED(x) (((unsigned long)(x) & (VCHI_BULK_ALIGN-1)) == 0)
  34476. +#endif
  34477. +
  34478. +struct vchi_version {
  34479. + uint32_t version;
  34480. + uint32_t version_min;
  34481. +};
  34482. +#define VCHI_VERSION(v_) { v_, v_ }
  34483. +#define VCHI_VERSION_EX(v_, m_) { v_, m_ }
  34484. +
  34485. +typedef enum
  34486. +{
  34487. + VCHI_VEC_POINTER,
  34488. + VCHI_VEC_HANDLE,
  34489. + VCHI_VEC_LIST
  34490. +} VCHI_MSG_VECTOR_TYPE_T;
  34491. +
  34492. +typedef struct vchi_msg_vector_ex {
  34493. +
  34494. + VCHI_MSG_VECTOR_TYPE_T type;
  34495. + union
  34496. + {
  34497. + // a memory handle
  34498. + struct
  34499. + {
  34500. + VCHI_MEM_HANDLE_T handle;
  34501. + uint32_t offset;
  34502. + int32_t vec_len;
  34503. + } handle;
  34504. +
  34505. + // an ordinary data pointer
  34506. + struct
  34507. + {
  34508. + const void *vec_base;
  34509. + int32_t vec_len;
  34510. + } ptr;
  34511. +
  34512. + // a nested vector list
  34513. + struct
  34514. + {
  34515. + struct vchi_msg_vector_ex *vec;
  34516. + uint32_t vec_len;
  34517. + } list;
  34518. + } u;
  34519. +} VCHI_MSG_VECTOR_EX_T;
  34520. +
  34521. +
  34522. +// Construct an entry in a msg vector for a pointer (p) of length (l)
  34523. +#define VCHI_VEC_POINTER(p,l) VCHI_VEC_POINTER, { { (VCHI_MEM_HANDLE_T)(p), (l) } }
  34524. +
  34525. +// Construct an entry in a msg vector for a message handle (h), starting at offset (o) of length (l)
  34526. +#define VCHI_VEC_HANDLE(h,o,l) VCHI_VEC_HANDLE, { { (h), (o), (l) } }
  34527. +
  34528. +// Macros to manipulate 'FOURCC' values
  34529. +#define MAKE_FOURCC(x) ((int32_t)( (x[0] << 24) | (x[1] << 16) | (x[2] << 8) | x[3] ))
  34530. +#define FOURCC_TO_CHAR(x) (x >> 24) & 0xFF,(x >> 16) & 0xFF,(x >> 8) & 0xFF, x & 0xFF
  34531. +
  34532. +
  34533. +// Opaque service information
  34534. +struct opaque_vchi_service_t;
  34535. +
  34536. +// Descriptor for a held message. Allocated by client, initialised by vchi_msg_hold,
  34537. +// vchi_msg_iter_hold or vchi_msg_iter_hold_next. Fields are for internal VCHI use only.
  34538. +typedef struct
  34539. +{
  34540. + struct opaque_vchi_service_t *service;
  34541. + void *message;
  34542. +} VCHI_HELD_MSG_T;
  34543. +
  34544. +
  34545. +
  34546. +// structure used to provide the information needed to open a server or a client
  34547. +typedef struct {
  34548. + struct vchi_version version;
  34549. + int32_t service_id;
  34550. + VCHI_CONNECTION_T *connection;
  34551. + uint32_t rx_fifo_size;
  34552. + uint32_t tx_fifo_size;
  34553. + VCHI_CALLBACK_T callback;
  34554. + void *callback_param;
  34555. + /* client intends to receive bulk transfers of
  34556. + odd lengths or into unaligned buffers */
  34557. + int32_t want_unaligned_bulk_rx;
  34558. + /* client intends to transmit bulk transfers of
  34559. + odd lengths or out of unaligned buffers */
  34560. + int32_t want_unaligned_bulk_tx;
  34561. + /* client wants to check CRCs on (bulk) xfers.
  34562. + Only needs to be set at 1 end - will do both directions. */
  34563. + int32_t want_crc;
  34564. +} SERVICE_CREATION_T;
  34565. +
  34566. +// Opaque handle for a VCHI instance
  34567. +typedef struct opaque_vchi_instance_handle_t *VCHI_INSTANCE_T;
  34568. +
  34569. +// Opaque handle for a server or client
  34570. +typedef struct opaque_vchi_service_handle_t *VCHI_SERVICE_HANDLE_T;
  34571. +
  34572. +// Service registration & startup
  34573. +typedef void (*VCHI_SERVICE_INIT)(VCHI_INSTANCE_T initialise_instance, VCHI_CONNECTION_T **connections, uint32_t num_connections);
  34574. +
  34575. +typedef struct service_info_tag {
  34576. + const char * const vll_filename; /* VLL to load to start this service. This is an empty string if VLL is "static" */
  34577. + VCHI_SERVICE_INIT init; /* Service initialisation function */
  34578. + void *vll_handle; /* VLL handle; NULL when unloaded or a "static VLL" in build */
  34579. +} SERVICE_INFO_T;
  34580. +
  34581. +/******************************************************************************
  34582. + Global funcs - implementation is specific to which side you are on (local / remote)
  34583. + *****************************************************************************/
  34584. +
  34585. +#ifdef __cplusplus
  34586. +extern "C" {
  34587. +#endif
  34588. +
  34589. +extern /*@observer@*/ VCHI_CONNECTION_T * vchi_create_connection( const VCHI_CONNECTION_API_T * function_table,
  34590. + const VCHI_MESSAGE_DRIVER_T * low_level);
  34591. +
  34592. +
  34593. +// Routine used to initialise the vchi on both local + remote connections
  34594. +extern int32_t vchi_initialise( VCHI_INSTANCE_T *instance_handle );
  34595. +
  34596. +extern int32_t vchi_exit( void );
  34597. +
  34598. +extern int32_t vchi_connect( VCHI_CONNECTION_T **connections,
  34599. + const uint32_t num_connections,
  34600. + VCHI_INSTANCE_T instance_handle );
  34601. +
  34602. +//When this is called, ensure that all services have no data pending.
  34603. +//Bulk transfers can remain 'queued'
  34604. +extern int32_t vchi_disconnect( VCHI_INSTANCE_T instance_handle );
  34605. +
  34606. +// Global control over bulk CRC checking
  34607. +extern int32_t vchi_crc_control( VCHI_CONNECTION_T *connection,
  34608. + VCHI_CRC_CONTROL_T control );
  34609. +
  34610. +// helper functions
  34611. +extern void * vchi_allocate_buffer(VCHI_SERVICE_HANDLE_T handle, uint32_t *length);
  34612. +extern void vchi_free_buffer(VCHI_SERVICE_HANDLE_T handle, void *address);
  34613. +extern uint32_t vchi_current_time(VCHI_INSTANCE_T instance_handle);
  34614. +
  34615. +
  34616. +/******************************************************************************
  34617. + Global service API
  34618. + *****************************************************************************/
  34619. +// Routine to create a named service
  34620. +extern int32_t vchi_service_create( VCHI_INSTANCE_T instance_handle,
  34621. + SERVICE_CREATION_T *setup,
  34622. + VCHI_SERVICE_HANDLE_T *handle );
  34623. +
  34624. +// Routine to destory a service
  34625. +extern int32_t vchi_service_destroy( const VCHI_SERVICE_HANDLE_T handle );
  34626. +
  34627. +// Routine to open a named service
  34628. +extern int32_t vchi_service_open( VCHI_INSTANCE_T instance_handle,
  34629. + SERVICE_CREATION_T *setup,
  34630. + VCHI_SERVICE_HANDLE_T *handle);
  34631. +
  34632. +extern int32_t vchi_get_peer_version( const VCHI_SERVICE_HANDLE_T handle,
  34633. + short *peer_version );
  34634. +
  34635. +// Routine to close a named service
  34636. +extern int32_t vchi_service_close( const VCHI_SERVICE_HANDLE_T handle );
  34637. +
  34638. +// Routine to increment ref count on a named service
  34639. +extern int32_t vchi_service_use( const VCHI_SERVICE_HANDLE_T handle );
  34640. +
  34641. +// Routine to decrement ref count on a named service
  34642. +extern int32_t vchi_service_release( const VCHI_SERVICE_HANDLE_T handle );
  34643. +
  34644. +// Routine to set a control option for a named service
  34645. +extern int32_t vchi_service_set_option( const VCHI_SERVICE_HANDLE_T handle,
  34646. + VCHI_SERVICE_OPTION_T option,
  34647. + int value);
  34648. +
  34649. +// Routine to send a message across a service
  34650. +extern int32_t vchi_msg_queue( VCHI_SERVICE_HANDLE_T handle,
  34651. + const void *data,
  34652. + uint32_t data_size,
  34653. + VCHI_FLAGS_T flags,
  34654. + void *msg_handle );
  34655. +
  34656. +// scatter-gather (vector) and send message
  34657. +int32_t vchi_msg_queuev_ex( VCHI_SERVICE_HANDLE_T handle,
  34658. + VCHI_MSG_VECTOR_EX_T *vector,
  34659. + uint32_t count,
  34660. + VCHI_FLAGS_T flags,
  34661. + void *msg_handle );
  34662. +
  34663. +// legacy scatter-gather (vector) and send message, only handles pointers
  34664. +int32_t vchi_msg_queuev( VCHI_SERVICE_HANDLE_T handle,
  34665. + VCHI_MSG_VECTOR_T *vector,
  34666. + uint32_t count,
  34667. + VCHI_FLAGS_T flags,
  34668. + void *msg_handle );
  34669. +
  34670. +// Routine to receive a msg from a service
  34671. +// Dequeue is equivalent to hold, copy into client buffer, release
  34672. +extern int32_t vchi_msg_dequeue( VCHI_SERVICE_HANDLE_T handle,
  34673. + void *data,
  34674. + uint32_t max_data_size_to_read,
  34675. + uint32_t *actual_msg_size,
  34676. + VCHI_FLAGS_T flags );
  34677. +
  34678. +// Routine to look at a message in place.
  34679. +// The message is not dequeued, so a subsequent call to peek or dequeue
  34680. +// will return the same message.
  34681. +extern int32_t vchi_msg_peek( VCHI_SERVICE_HANDLE_T handle,
  34682. + void **data,
  34683. + uint32_t *msg_size,
  34684. + VCHI_FLAGS_T flags );
  34685. +
  34686. +// Routine to remove a message after it has been read in place with peek
  34687. +// The first message on the queue is dequeued.
  34688. +extern int32_t vchi_msg_remove( VCHI_SERVICE_HANDLE_T handle );
  34689. +
  34690. +// Routine to look at a message in place.
  34691. +// The message is dequeued, so the caller is left holding it; the descriptor is
  34692. +// filled in and must be released when the user has finished with the message.
  34693. +extern int32_t vchi_msg_hold( VCHI_SERVICE_HANDLE_T handle,
  34694. + void **data, // } may be NULL, as info can be
  34695. + uint32_t *msg_size, // } obtained from HELD_MSG_T
  34696. + VCHI_FLAGS_T flags,
  34697. + VCHI_HELD_MSG_T *message_descriptor );
  34698. +
  34699. +// Initialise an iterator to look through messages in place
  34700. +extern int32_t vchi_msg_look_ahead( VCHI_SERVICE_HANDLE_T handle,
  34701. + VCHI_MSG_ITER_T *iter,
  34702. + VCHI_FLAGS_T flags );
  34703. +
  34704. +/******************************************************************************
  34705. + Global service support API - operations on held messages and message iterators
  34706. + *****************************************************************************/
  34707. +
  34708. +// Routine to get the address of a held message
  34709. +extern void *vchi_held_msg_ptr( const VCHI_HELD_MSG_T *message );
  34710. +
  34711. +// Routine to get the size of a held message
  34712. +extern int32_t vchi_held_msg_size( const VCHI_HELD_MSG_T *message );
  34713. +
  34714. +// Routine to get the transmit timestamp as written into the header by the peer
  34715. +extern uint32_t vchi_held_msg_tx_timestamp( const VCHI_HELD_MSG_T *message );
  34716. +
  34717. +// Routine to get the reception timestamp, written as we parsed the header
  34718. +extern uint32_t vchi_held_msg_rx_timestamp( const VCHI_HELD_MSG_T *message );
  34719. +
  34720. +// Routine to release a held message after it has been processed
  34721. +extern int32_t vchi_held_msg_release( VCHI_HELD_MSG_T *message );
  34722. +
  34723. +// Indicates whether the iterator has a next message.
  34724. +extern int32_t vchi_msg_iter_has_next( const VCHI_MSG_ITER_T *iter );
  34725. +
  34726. +// Return the pointer and length for the next message and advance the iterator.
  34727. +extern int32_t vchi_msg_iter_next( VCHI_MSG_ITER_T *iter,
  34728. + void **data,
  34729. + uint32_t *msg_size );
  34730. +
  34731. +// Remove the last message returned by vchi_msg_iter_next.
  34732. +// Can only be called once after each call to vchi_msg_iter_next.
  34733. +extern int32_t vchi_msg_iter_remove( VCHI_MSG_ITER_T *iter );
  34734. +
  34735. +// Hold the last message returned by vchi_msg_iter_next.
  34736. +// Can only be called once after each call to vchi_msg_iter_next.
  34737. +extern int32_t vchi_msg_iter_hold( VCHI_MSG_ITER_T *iter,
  34738. + VCHI_HELD_MSG_T *message );
  34739. +
  34740. +// Return information for the next message, and hold it, advancing the iterator.
  34741. +extern int32_t vchi_msg_iter_hold_next( VCHI_MSG_ITER_T *iter,
  34742. + void **data, // } may be NULL
  34743. + uint32_t *msg_size, // }
  34744. + VCHI_HELD_MSG_T *message );
  34745. +
  34746. +
  34747. +/******************************************************************************
  34748. + Global bulk API
  34749. + *****************************************************************************/
  34750. +
  34751. +// Routine to prepare interface for a transfer from the other side
  34752. +extern int32_t vchi_bulk_queue_receive( VCHI_SERVICE_HANDLE_T handle,
  34753. + void *data_dst,
  34754. + uint32_t data_size,
  34755. + VCHI_FLAGS_T flags,
  34756. + void *transfer_handle );
  34757. +
  34758. +
  34759. +// Prepare interface for a transfer from the other side into relocatable memory.
  34760. +int32_t vchi_bulk_queue_receive_reloc( const VCHI_SERVICE_HANDLE_T handle,
  34761. + VCHI_MEM_HANDLE_T h_dst,
  34762. + uint32_t offset,
  34763. + uint32_t data_size,
  34764. + const VCHI_FLAGS_T flags,
  34765. + void * const bulk_handle );
  34766. +
  34767. +// Routine to queue up data ready for transfer to the other (once they have signalled they are ready)
  34768. +extern int32_t vchi_bulk_queue_transmit( VCHI_SERVICE_HANDLE_T handle,
  34769. + const void *data_src,
  34770. + uint32_t data_size,
  34771. + VCHI_FLAGS_T flags,
  34772. + void *transfer_handle );
  34773. +
  34774. +
  34775. +/******************************************************************************
  34776. + Configuration plumbing
  34777. + *****************************************************************************/
  34778. +
  34779. +// function prototypes for the different mid layers (the state info gives the different physical connections)
  34780. +extern const VCHI_CONNECTION_API_T *single_get_func_table( void );
  34781. +//extern const VCHI_CONNECTION_API_T *local_server_get_func_table( void );
  34782. +//extern const VCHI_CONNECTION_API_T *local_client_get_func_table( void );
  34783. +
  34784. +// declare all message drivers here
  34785. +const VCHI_MESSAGE_DRIVER_T *vchi_mphi_message_driver_func_table( void );
  34786. +
  34787. +#ifdef __cplusplus
  34788. +}
  34789. +#endif
  34790. +
  34791. +extern int32_t vchi_bulk_queue_transmit_reloc( VCHI_SERVICE_HANDLE_T handle,
  34792. + VCHI_MEM_HANDLE_T h_src,
  34793. + uint32_t offset,
  34794. + uint32_t data_size,
  34795. + VCHI_FLAGS_T flags,
  34796. + void *transfer_handle );
  34797. +#endif /* VCHI_H_ */
  34798. +
  34799. +/****************************** End of file **********************************/
  34800. diff -Nur linux-3.18.8/drivers/misc/vc04_services/interface/vchi/vchi_mh.h linux-rpi/drivers/misc/vc04_services/interface/vchi/vchi_mh.h
  34801. --- linux-3.18.8/drivers/misc/vc04_services/interface/vchi/vchi_mh.h 1970-01-01 01:00:00.000000000 +0100
  34802. +++ linux-rpi/drivers/misc/vc04_services/interface/vchi/vchi_mh.h 2015-03-05 14:40:14.401715819 +0100
  34803. @@ -0,0 +1,42 @@
  34804. +/**
  34805. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  34806. + *
  34807. + * Redistribution and use in source and binary forms, with or without
  34808. + * modification, are permitted provided that the following conditions
  34809. + * are met:
  34810. + * 1. Redistributions of source code must retain the above copyright
  34811. + * notice, this list of conditions, and the following disclaimer,
  34812. + * without modification.
  34813. + * 2. Redistributions in binary form must reproduce the above copyright
  34814. + * notice, this list of conditions and the following disclaimer in the
  34815. + * documentation and/or other materials provided with the distribution.
  34816. + * 3. The names of the above-listed copyright holders may not be used
  34817. + * to endorse or promote products derived from this software without
  34818. + * specific prior written permission.
  34819. + *
  34820. + * ALTERNATIVELY, this software may be distributed under the terms of the
  34821. + * GNU General Public License ("GPL") version 2, as published by the Free
  34822. + * Software Foundation.
  34823. + *
  34824. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  34825. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  34826. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  34827. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  34828. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  34829. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  34830. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  34831. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  34832. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  34833. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  34834. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34835. + */
  34836. +
  34837. +#ifndef VCHI_MH_H_
  34838. +#define VCHI_MH_H_
  34839. +
  34840. +#include <linux/types.h>
  34841. +
  34842. +typedef int32_t VCHI_MEM_HANDLE_T;
  34843. +#define VCHI_MEM_HANDLE_INVALID 0
  34844. +
  34845. +#endif
  34846. diff -Nur linux-3.18.8/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c
  34847. --- linux-3.18.8/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c 1970-01-01 01:00:00.000000000 +0100
  34848. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c 2015-03-05 14:40:14.401715819 +0100
  34849. @@ -0,0 +1,562 @@
  34850. +/**
  34851. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  34852. + *
  34853. + * Redistribution and use in source and binary forms, with or without
  34854. + * modification, are permitted provided that the following conditions
  34855. + * are met:
  34856. + * 1. Redistributions of source code must retain the above copyright
  34857. + * notice, this list of conditions, and the following disclaimer,
  34858. + * without modification.
  34859. + * 2. Redistributions in binary form must reproduce the above copyright
  34860. + * notice, this list of conditions and the following disclaimer in the
  34861. + * documentation and/or other materials provided with the distribution.
  34862. + * 3. The names of the above-listed copyright holders may not be used
  34863. + * to endorse or promote products derived from this software without
  34864. + * specific prior written permission.
  34865. + *
  34866. + * ALTERNATIVELY, this software may be distributed under the terms of the
  34867. + * GNU General Public License ("GPL") version 2, as published by the Free
  34868. + * Software Foundation.
  34869. + *
  34870. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  34871. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  34872. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  34873. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  34874. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  34875. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  34876. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  34877. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  34878. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  34879. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  34880. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34881. + */
  34882. +
  34883. +#include <linux/kernel.h>
  34884. +#include <linux/types.h>
  34885. +#include <linux/errno.h>
  34886. +#include <linux/interrupt.h>
  34887. +#include <linux/irq.h>
  34888. +#include <linux/pagemap.h>
  34889. +#include <linux/dma-mapping.h>
  34890. +#include <linux/version.h>
  34891. +#include <linux/io.h>
  34892. +#include <linux/uaccess.h>
  34893. +#include <asm/pgtable.h>
  34894. +
  34895. +#include <mach/irqs.h>
  34896. +
  34897. +#include <mach/platform.h>
  34898. +#include <mach/vcio.h>
  34899. +
  34900. +#define TOTAL_SLOTS (VCHIQ_SLOT_ZERO_SLOTS + 2 * 32)
  34901. +
  34902. +#define VCHIQ_DOORBELL_IRQ IRQ_ARM_DOORBELL_0
  34903. +#define VCHIQ_ARM_ADDRESS(x) ((void *)__virt_to_bus((unsigned)x))
  34904. +
  34905. +#include "vchiq_arm.h"
  34906. +#include "vchiq_2835.h"
  34907. +#include "vchiq_connected.h"
  34908. +#include "vchiq_killable.h"
  34909. +
  34910. +#define MAX_FRAGMENTS (VCHIQ_NUM_CURRENT_BULKS * 2)
  34911. +
  34912. +typedef struct vchiq_2835_state_struct {
  34913. + int inited;
  34914. + VCHIQ_ARM_STATE_T arm_state;
  34915. +} VCHIQ_2835_ARM_STATE_T;
  34916. +
  34917. +static char *g_slot_mem;
  34918. +static int g_slot_mem_size;
  34919. +dma_addr_t g_slot_phys;
  34920. +static FRAGMENTS_T *g_fragments_base;
  34921. +static FRAGMENTS_T *g_free_fragments;
  34922. +struct semaphore g_free_fragments_sema;
  34923. +
  34924. +extern int vchiq_arm_log_level;
  34925. +
  34926. +static DEFINE_SEMAPHORE(g_free_fragments_mutex);
  34927. +
  34928. +static irqreturn_t
  34929. +vchiq_doorbell_irq(int irq, void *dev_id);
  34930. +
  34931. +static int
  34932. +create_pagelist(char __user *buf, size_t count, unsigned short type,
  34933. + struct task_struct *task, PAGELIST_T ** ppagelist);
  34934. +
  34935. +static void
  34936. +free_pagelist(PAGELIST_T *pagelist, int actual);
  34937. +
  34938. +int __init
  34939. +vchiq_platform_init(VCHIQ_STATE_T *state)
  34940. +{
  34941. + VCHIQ_SLOT_ZERO_T *vchiq_slot_zero;
  34942. + int frag_mem_size;
  34943. + int err;
  34944. + int i;
  34945. +
  34946. + /* Allocate space for the channels in coherent memory */
  34947. + g_slot_mem_size = PAGE_ALIGN(TOTAL_SLOTS * VCHIQ_SLOT_SIZE);
  34948. + frag_mem_size = PAGE_ALIGN(sizeof(FRAGMENTS_T) * MAX_FRAGMENTS);
  34949. +
  34950. + g_slot_mem = dma_alloc_coherent(NULL, g_slot_mem_size + frag_mem_size,
  34951. + &g_slot_phys, GFP_ATOMIC);
  34952. +
  34953. + if (!g_slot_mem) {
  34954. + vchiq_log_error(vchiq_arm_log_level,
  34955. + "Unable to allocate channel memory");
  34956. + err = -ENOMEM;
  34957. + goto failed_alloc;
  34958. + }
  34959. +
  34960. + WARN_ON(((int)g_slot_mem & (PAGE_SIZE - 1)) != 0);
  34961. +
  34962. + vchiq_slot_zero = vchiq_init_slots(g_slot_mem, g_slot_mem_size);
  34963. + if (!vchiq_slot_zero) {
  34964. + err = -EINVAL;
  34965. + goto failed_init_slots;
  34966. + }
  34967. +
  34968. + vchiq_slot_zero->platform_data[VCHIQ_PLATFORM_FRAGMENTS_OFFSET_IDX] =
  34969. + (int)g_slot_phys + g_slot_mem_size;
  34970. + vchiq_slot_zero->platform_data[VCHIQ_PLATFORM_FRAGMENTS_COUNT_IDX] =
  34971. + MAX_FRAGMENTS;
  34972. +
  34973. + g_fragments_base = (FRAGMENTS_T *)(g_slot_mem + g_slot_mem_size);
  34974. + g_slot_mem_size += frag_mem_size;
  34975. +
  34976. + g_free_fragments = g_fragments_base;
  34977. + for (i = 0; i < (MAX_FRAGMENTS - 1); i++) {
  34978. + *(FRAGMENTS_T **)&g_fragments_base[i] =
  34979. + &g_fragments_base[i + 1];
  34980. + }
  34981. + *(FRAGMENTS_T **)&g_fragments_base[i] = NULL;
  34982. + sema_init(&g_free_fragments_sema, MAX_FRAGMENTS);
  34983. +
  34984. + if (vchiq_init_state(state, vchiq_slot_zero, 0/*slave*/) !=
  34985. + VCHIQ_SUCCESS) {
  34986. + err = -EINVAL;
  34987. + goto failed_vchiq_init;
  34988. + }
  34989. +
  34990. + err = request_irq(VCHIQ_DOORBELL_IRQ, vchiq_doorbell_irq,
  34991. + IRQF_IRQPOLL, "VCHIQ doorbell",
  34992. + state);
  34993. + if (err < 0) {
  34994. + vchiq_log_error(vchiq_arm_log_level, "%s: failed to register "
  34995. + "irq=%d err=%d", __func__,
  34996. + VCHIQ_DOORBELL_IRQ, err);
  34997. + goto failed_request_irq;
  34998. + }
  34999. +
  35000. + /* Send the base address of the slots to VideoCore */
  35001. +
  35002. + dsb(); /* Ensure all writes have completed */
  35003. +
  35004. + bcm_mailbox_write(MBOX_CHAN_VCHIQ, (unsigned int)g_slot_phys);
  35005. +
  35006. + vchiq_log_info(vchiq_arm_log_level,
  35007. + "vchiq_init - done (slots %x, phys %x)",
  35008. + (unsigned int)vchiq_slot_zero, g_slot_phys);
  35009. +
  35010. + vchiq_call_connected_callbacks();
  35011. +
  35012. + return 0;
  35013. +
  35014. +failed_request_irq:
  35015. +failed_vchiq_init:
  35016. +failed_init_slots:
  35017. + dma_free_coherent(NULL, g_slot_mem_size, g_slot_mem, g_slot_phys);
  35018. +
  35019. +failed_alloc:
  35020. + return err;
  35021. +}
  35022. +
  35023. +void __exit
  35024. +vchiq_platform_exit(VCHIQ_STATE_T *state)
  35025. +{
  35026. + free_irq(VCHIQ_DOORBELL_IRQ, state);
  35027. + dma_free_coherent(NULL, g_slot_mem_size,
  35028. + g_slot_mem, g_slot_phys);
  35029. +}
  35030. +
  35031. +
  35032. +VCHIQ_STATUS_T
  35033. +vchiq_platform_init_state(VCHIQ_STATE_T *state)
  35034. +{
  35035. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  35036. + state->platform_state = kzalloc(sizeof(VCHIQ_2835_ARM_STATE_T), GFP_KERNEL);
  35037. + ((VCHIQ_2835_ARM_STATE_T*)state->platform_state)->inited = 1;
  35038. + status = vchiq_arm_init_state(state, &((VCHIQ_2835_ARM_STATE_T*)state->platform_state)->arm_state);
  35039. + if(status != VCHIQ_SUCCESS)
  35040. + {
  35041. + ((VCHIQ_2835_ARM_STATE_T*)state->platform_state)->inited = 0;
  35042. + }
  35043. + return status;
  35044. +}
  35045. +
  35046. +VCHIQ_ARM_STATE_T*
  35047. +vchiq_platform_get_arm_state(VCHIQ_STATE_T *state)
  35048. +{
  35049. + if(!((VCHIQ_2835_ARM_STATE_T*)state->platform_state)->inited)
  35050. + {
  35051. + BUG();
  35052. + }
  35053. + return &((VCHIQ_2835_ARM_STATE_T*)state->platform_state)->arm_state;
  35054. +}
  35055. +
  35056. +void
  35057. +remote_event_signal(REMOTE_EVENT_T *event)
  35058. +{
  35059. + wmb();
  35060. +
  35061. + event->fired = 1;
  35062. +
  35063. + dsb(); /* data barrier operation */
  35064. +
  35065. + if (event->armed) {
  35066. + /* trigger vc interrupt */
  35067. +
  35068. + writel(0, __io_address(ARM_0_BELL2));
  35069. + }
  35070. +}
  35071. +
  35072. +int
  35073. +vchiq_copy_from_user(void *dst, const void *src, int size)
  35074. +{
  35075. + if ((uint32_t)src < TASK_SIZE) {
  35076. + return copy_from_user(dst, src, size);
  35077. + } else {
  35078. + memcpy(dst, src, size);
  35079. + return 0;
  35080. + }
  35081. +}
  35082. +
  35083. +VCHIQ_STATUS_T
  35084. +vchiq_prepare_bulk_data(VCHIQ_BULK_T *bulk, VCHI_MEM_HANDLE_T memhandle,
  35085. + void *offset, int size, int dir)
  35086. +{
  35087. + PAGELIST_T *pagelist;
  35088. + int ret;
  35089. +
  35090. + WARN_ON(memhandle != VCHI_MEM_HANDLE_INVALID);
  35091. +
  35092. + ret = create_pagelist((char __user *)offset, size,
  35093. + (dir == VCHIQ_BULK_RECEIVE)
  35094. + ? PAGELIST_READ
  35095. + : PAGELIST_WRITE,
  35096. + current,
  35097. + &pagelist);
  35098. + if (ret != 0)
  35099. + return VCHIQ_ERROR;
  35100. +
  35101. + bulk->handle = memhandle;
  35102. + bulk->data = VCHIQ_ARM_ADDRESS(pagelist);
  35103. +
  35104. + /* Store the pagelist address in remote_data, which isn't used by the
  35105. + slave. */
  35106. + bulk->remote_data = pagelist;
  35107. +
  35108. + return VCHIQ_SUCCESS;
  35109. +}
  35110. +
  35111. +void
  35112. +vchiq_complete_bulk(VCHIQ_BULK_T *bulk)
  35113. +{
  35114. + if (bulk && bulk->remote_data && bulk->actual)
  35115. + free_pagelist((PAGELIST_T *)bulk->remote_data, bulk->actual);
  35116. +}
  35117. +
  35118. +void
  35119. +vchiq_transfer_bulk(VCHIQ_BULK_T *bulk)
  35120. +{
  35121. + /*
  35122. + * This should only be called on the master (VideoCore) side, but
  35123. + * provide an implementation to avoid the need for ifdefery.
  35124. + */
  35125. + BUG();
  35126. +}
  35127. +
  35128. +void
  35129. +vchiq_dump_platform_state(void *dump_context)
  35130. +{
  35131. + char buf[80];
  35132. + int len;
  35133. + len = snprintf(buf, sizeof(buf),
  35134. + " Platform: 2835 (VC master)");
  35135. + vchiq_dump(dump_context, buf, len + 1);
  35136. +}
  35137. +
  35138. +VCHIQ_STATUS_T
  35139. +vchiq_platform_suspend(VCHIQ_STATE_T *state)
  35140. +{
  35141. + return VCHIQ_ERROR;
  35142. +}
  35143. +
  35144. +VCHIQ_STATUS_T
  35145. +vchiq_platform_resume(VCHIQ_STATE_T *state)
  35146. +{
  35147. + return VCHIQ_SUCCESS;
  35148. +}
  35149. +
  35150. +void
  35151. +vchiq_platform_paused(VCHIQ_STATE_T *state)
  35152. +{
  35153. +}
  35154. +
  35155. +void
  35156. +vchiq_platform_resumed(VCHIQ_STATE_T *state)
  35157. +{
  35158. +}
  35159. +
  35160. +int
  35161. +vchiq_platform_videocore_wanted(VCHIQ_STATE_T* state)
  35162. +{
  35163. + return 1; // autosuspend not supported - videocore always wanted
  35164. +}
  35165. +
  35166. +int
  35167. +vchiq_platform_use_suspend_timer(void)
  35168. +{
  35169. + return 0;
  35170. +}
  35171. +void
  35172. +vchiq_dump_platform_use_state(VCHIQ_STATE_T *state)
  35173. +{
  35174. + vchiq_log_info((vchiq_arm_log_level>=VCHIQ_LOG_INFO),"Suspend timer not in use");
  35175. +}
  35176. +void
  35177. +vchiq_platform_handle_timeout(VCHIQ_STATE_T *state)
  35178. +{
  35179. + (void)state;
  35180. +}
  35181. +/*
  35182. + * Local functions
  35183. + */
  35184. +
  35185. +static irqreturn_t
  35186. +vchiq_doorbell_irq(int irq, void *dev_id)
  35187. +{
  35188. + VCHIQ_STATE_T *state = dev_id;
  35189. + irqreturn_t ret = IRQ_NONE;
  35190. + unsigned int status;
  35191. +
  35192. + /* Read (and clear) the doorbell */
  35193. + status = readl(__io_address(ARM_0_BELL0));
  35194. +
  35195. + if (status & 0x4) { /* Was the doorbell rung? */
  35196. + remote_event_pollall(state);
  35197. + ret = IRQ_HANDLED;
  35198. + }
  35199. +
  35200. + return ret;
  35201. +}
  35202. +
  35203. +/* There is a potential problem with partial cache lines (pages?)
  35204. +** at the ends of the block when reading. If the CPU accessed anything in
  35205. +** the same line (page?) then it may have pulled old data into the cache,
  35206. +** obscuring the new data underneath. We can solve this by transferring the
  35207. +** partial cache lines separately, and allowing the ARM to copy into the
  35208. +** cached area.
  35209. +
  35210. +** N.B. This implementation plays slightly fast and loose with the Linux
  35211. +** driver programming rules, e.g. its use of __virt_to_bus instead of
  35212. +** dma_map_single, but it isn't a multi-platform driver and it benefits
  35213. +** from increased speed as a result.
  35214. +*/
  35215. +
  35216. +static int
  35217. +create_pagelist(char __user *buf, size_t count, unsigned short type,
  35218. + struct task_struct *task, PAGELIST_T ** ppagelist)
  35219. +{
  35220. + PAGELIST_T *pagelist;
  35221. + struct page **pages;
  35222. + struct page *page;
  35223. + unsigned long *addrs;
  35224. + unsigned int num_pages, offset, i;
  35225. + char *addr, *base_addr, *next_addr;
  35226. + int run, addridx, actual_pages;
  35227. + unsigned long *need_release;
  35228. +
  35229. + offset = (unsigned int)buf & (PAGE_SIZE - 1);
  35230. + num_pages = (count + offset + PAGE_SIZE - 1) / PAGE_SIZE;
  35231. +
  35232. + *ppagelist = NULL;
  35233. +
  35234. + /* Allocate enough storage to hold the page pointers and the page
  35235. + ** list
  35236. + */
  35237. + pagelist = kmalloc(sizeof(PAGELIST_T) +
  35238. + (num_pages * sizeof(unsigned long)) +
  35239. + sizeof(unsigned long) +
  35240. + (num_pages * sizeof(pages[0])),
  35241. + GFP_KERNEL);
  35242. +
  35243. + vchiq_log_trace(vchiq_arm_log_level,
  35244. + "create_pagelist - %x", (unsigned int)pagelist);
  35245. + if (!pagelist)
  35246. + return -ENOMEM;
  35247. +
  35248. + addrs = pagelist->addrs;
  35249. + need_release = (unsigned long *)(addrs + num_pages);
  35250. + pages = (struct page **)(addrs + num_pages + 1);
  35251. +
  35252. + if (is_vmalloc_addr(buf)) {
  35253. + for (actual_pages = 0; actual_pages < num_pages; actual_pages++) {
  35254. + pages[actual_pages] = vmalloc_to_page(buf + (actual_pages * PAGE_SIZE));
  35255. + }
  35256. + *need_release = 0; /* do not try and release vmalloc pages */
  35257. + } else {
  35258. + down_read(&task->mm->mmap_sem);
  35259. + actual_pages = get_user_pages(task, task->mm,
  35260. + (unsigned long)buf & ~(PAGE_SIZE - 1),
  35261. + num_pages,
  35262. + (type == PAGELIST_READ) /*Write */ ,
  35263. + 0 /*Force */ ,
  35264. + pages,
  35265. + NULL /*vmas */);
  35266. + up_read(&task->mm->mmap_sem);
  35267. +
  35268. + if (actual_pages != num_pages) {
  35269. + vchiq_log_info(vchiq_arm_log_level,
  35270. + "create_pagelist - only %d/%d pages locked",
  35271. + actual_pages,
  35272. + num_pages);
  35273. +
  35274. + /* This is probably due to the process being killed */
  35275. + while (actual_pages > 0)
  35276. + {
  35277. + actual_pages--;
  35278. + page_cache_release(pages[actual_pages]);
  35279. + }
  35280. + kfree(pagelist);
  35281. + if (actual_pages == 0)
  35282. + actual_pages = -ENOMEM;
  35283. + return actual_pages;
  35284. + }
  35285. + *need_release = 1; /* release user pages */
  35286. + }
  35287. +
  35288. + pagelist->length = count;
  35289. + pagelist->type = type;
  35290. + pagelist->offset = offset;
  35291. +
  35292. + /* Group the pages into runs of contiguous pages */
  35293. +
  35294. + base_addr = VCHIQ_ARM_ADDRESS(page_address(pages[0]));
  35295. + next_addr = base_addr + PAGE_SIZE;
  35296. + addridx = 0;
  35297. + run = 0;
  35298. +
  35299. + for (i = 1; i < num_pages; i++) {
  35300. + addr = VCHIQ_ARM_ADDRESS(page_address(pages[i]));
  35301. + if ((addr == next_addr) && (run < (PAGE_SIZE - 1))) {
  35302. + next_addr += PAGE_SIZE;
  35303. + run++;
  35304. + } else {
  35305. + addrs[addridx] = (unsigned long)base_addr + run;
  35306. + addridx++;
  35307. + base_addr = addr;
  35308. + next_addr = addr + PAGE_SIZE;
  35309. + run = 0;
  35310. + }
  35311. + }
  35312. +
  35313. + addrs[addridx] = (unsigned long)base_addr + run;
  35314. + addridx++;
  35315. +
  35316. + /* Partial cache lines (fragments) require special measures */
  35317. + if ((type == PAGELIST_READ) &&
  35318. + ((pagelist->offset & (CACHE_LINE_SIZE - 1)) ||
  35319. + ((pagelist->offset + pagelist->length) &
  35320. + (CACHE_LINE_SIZE - 1)))) {
  35321. + FRAGMENTS_T *fragments;
  35322. +
  35323. + if (down_interruptible(&g_free_fragments_sema) != 0) {
  35324. + kfree(pagelist);
  35325. + return -EINTR;
  35326. + }
  35327. +
  35328. + WARN_ON(g_free_fragments == NULL);
  35329. +
  35330. + down(&g_free_fragments_mutex);
  35331. + fragments = (FRAGMENTS_T *) g_free_fragments;
  35332. + WARN_ON(fragments == NULL);
  35333. + g_free_fragments = *(FRAGMENTS_T **) g_free_fragments;
  35334. + up(&g_free_fragments_mutex);
  35335. + pagelist->type =
  35336. + PAGELIST_READ_WITH_FRAGMENTS + (fragments -
  35337. + g_fragments_base);
  35338. + }
  35339. +
  35340. + for (page = virt_to_page(pagelist);
  35341. + page <= virt_to_page(addrs + num_pages - 1); page++) {
  35342. + flush_dcache_page(page);
  35343. + }
  35344. +
  35345. + *ppagelist = pagelist;
  35346. +
  35347. + return 0;
  35348. +}
  35349. +
  35350. +static void
  35351. +free_pagelist(PAGELIST_T *pagelist, int actual)
  35352. +{
  35353. + unsigned long *need_release;
  35354. + struct page **pages;
  35355. + unsigned int num_pages, i;
  35356. +
  35357. + vchiq_log_trace(vchiq_arm_log_level,
  35358. + "free_pagelist - %x, %d", (unsigned int)pagelist, actual);
  35359. +
  35360. + num_pages =
  35361. + (pagelist->length + pagelist->offset + PAGE_SIZE - 1) /
  35362. + PAGE_SIZE;
  35363. +
  35364. + need_release = (unsigned long *)(pagelist->addrs + num_pages);
  35365. + pages = (struct page **)(pagelist->addrs + num_pages + 1);
  35366. +
  35367. + /* Deal with any partial cache lines (fragments) */
  35368. + if (pagelist->type >= PAGELIST_READ_WITH_FRAGMENTS) {
  35369. + FRAGMENTS_T *fragments = g_fragments_base +
  35370. + (pagelist->type - PAGELIST_READ_WITH_FRAGMENTS);
  35371. + int head_bytes, tail_bytes;
  35372. + head_bytes = (CACHE_LINE_SIZE - pagelist->offset) &
  35373. + (CACHE_LINE_SIZE - 1);
  35374. + tail_bytes = (pagelist->offset + actual) &
  35375. + (CACHE_LINE_SIZE - 1);
  35376. +
  35377. + if ((actual >= 0) && (head_bytes != 0)) {
  35378. + if (head_bytes > actual)
  35379. + head_bytes = actual;
  35380. +
  35381. + memcpy((char *)page_address(pages[0]) +
  35382. + pagelist->offset,
  35383. + fragments->headbuf,
  35384. + head_bytes);
  35385. + }
  35386. + if ((actual >= 0) && (head_bytes < actual) &&
  35387. + (tail_bytes != 0)) {
  35388. + memcpy((char *)page_address(pages[num_pages - 1]) +
  35389. + ((pagelist->offset + actual) &
  35390. + (PAGE_SIZE - 1) & ~(CACHE_LINE_SIZE - 1)),
  35391. + fragments->tailbuf, tail_bytes);
  35392. + }
  35393. +
  35394. + down(&g_free_fragments_mutex);
  35395. + *(FRAGMENTS_T **) fragments = g_free_fragments;
  35396. + g_free_fragments = fragments;
  35397. + up(&g_free_fragments_mutex);
  35398. + up(&g_free_fragments_sema);
  35399. + }
  35400. +
  35401. + if (*need_release) {
  35402. + for (i = 0; i < num_pages; i++) {
  35403. + if (pagelist->type != PAGELIST_WRITE)
  35404. + set_page_dirty(pages[i]);
  35405. +
  35406. + page_cache_release(pages[i]);
  35407. + }
  35408. + }
  35409. +
  35410. + kfree(pagelist);
  35411. +}
  35412. diff -Nur linux-3.18.8/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835.h
  35413. --- linux-3.18.8/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835.h 1970-01-01 01:00:00.000000000 +0100
  35414. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835.h 2015-03-05 14:40:14.401715819 +0100
  35415. @@ -0,0 +1,42 @@
  35416. +/**
  35417. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  35418. + *
  35419. + * Redistribution and use in source and binary forms, with or without
  35420. + * modification, are permitted provided that the following conditions
  35421. + * are met:
  35422. + * 1. Redistributions of source code must retain the above copyright
  35423. + * notice, this list of conditions, and the following disclaimer,
  35424. + * without modification.
  35425. + * 2. Redistributions in binary form must reproduce the above copyright
  35426. + * notice, this list of conditions and the following disclaimer in the
  35427. + * documentation and/or other materials provided with the distribution.
  35428. + * 3. The names of the above-listed copyright holders may not be used
  35429. + * to endorse or promote products derived from this software without
  35430. + * specific prior written permission.
  35431. + *
  35432. + * ALTERNATIVELY, this software may be distributed under the terms of the
  35433. + * GNU General Public License ("GPL") version 2, as published by the Free
  35434. + * Software Foundation.
  35435. + *
  35436. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  35437. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  35438. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  35439. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  35440. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  35441. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  35442. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  35443. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  35444. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  35445. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  35446. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35447. + */
  35448. +
  35449. +#ifndef VCHIQ_2835_H
  35450. +#define VCHIQ_2835_H
  35451. +
  35452. +#include "vchiq_pagelist.h"
  35453. +
  35454. +#define VCHIQ_PLATFORM_FRAGMENTS_OFFSET_IDX 0
  35455. +#define VCHIQ_PLATFORM_FRAGMENTS_COUNT_IDX 1
  35456. +
  35457. +#endif /* VCHIQ_2835_H */
  35458. diff -Nur linux-3.18.8/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.c linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.c
  35459. --- linux-3.18.8/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.c 1970-01-01 01:00:00.000000000 +0100
  35460. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.c 2015-03-05 14:40:14.401715819 +0100
  35461. @@ -0,0 +1,2884 @@
  35462. +/**
  35463. + * Copyright (c) 2014 Raspberry Pi (Trading) Ltd. All rights reserved.
  35464. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  35465. + *
  35466. + * Redistribution and use in source and binary forms, with or without
  35467. + * modification, are permitted provided that the following conditions
  35468. + * are met:
  35469. + * 1. Redistributions of source code must retain the above copyright
  35470. + * notice, this list of conditions, and the following disclaimer,
  35471. + * without modification.
  35472. + * 2. Redistributions in binary form must reproduce the above copyright
  35473. + * notice, this list of conditions and the following disclaimer in the
  35474. + * documentation and/or other materials provided with the distribution.
  35475. + * 3. The names of the above-listed copyright holders may not be used
  35476. + * to endorse or promote products derived from this software without
  35477. + * specific prior written permission.
  35478. + *
  35479. + * ALTERNATIVELY, this software may be distributed under the terms of the
  35480. + * GNU General Public License ("GPL") version 2, as published by the Free
  35481. + * Software Foundation.
  35482. + *
  35483. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  35484. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  35485. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  35486. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  35487. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  35488. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  35489. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  35490. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  35491. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  35492. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  35493. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35494. + */
  35495. +
  35496. +#include <linux/kernel.h>
  35497. +#include <linux/module.h>
  35498. +#include <linux/types.h>
  35499. +#include <linux/errno.h>
  35500. +#include <linux/cdev.h>
  35501. +#include <linux/fs.h>
  35502. +#include <linux/device.h>
  35503. +#include <linux/mm.h>
  35504. +#include <linux/highmem.h>
  35505. +#include <linux/pagemap.h>
  35506. +#include <linux/bug.h>
  35507. +#include <linux/semaphore.h>
  35508. +#include <linux/list.h>
  35509. +
  35510. +#include "vchiq_core.h"
  35511. +#include "vchiq_ioctl.h"
  35512. +#include "vchiq_arm.h"
  35513. +#include "vchiq_debugfs.h"
  35514. +#include "vchiq_killable.h"
  35515. +
  35516. +#define DEVICE_NAME "vchiq"
  35517. +
  35518. +/* Override the default prefix, which would be vchiq_arm (from the filename) */
  35519. +#undef MODULE_PARAM_PREFIX
  35520. +#define MODULE_PARAM_PREFIX DEVICE_NAME "."
  35521. +
  35522. +#define VCHIQ_MINOR 0
  35523. +
  35524. +/* Some per-instance constants */
  35525. +#define MAX_COMPLETIONS 16
  35526. +#define MAX_SERVICES 64
  35527. +#define MAX_ELEMENTS 8
  35528. +#define MSG_QUEUE_SIZE 64
  35529. +
  35530. +#define KEEPALIVE_VER 1
  35531. +#define KEEPALIVE_VER_MIN KEEPALIVE_VER
  35532. +
  35533. +/* Run time control of log level, based on KERN_XXX level. */
  35534. +int vchiq_arm_log_level = VCHIQ_LOG_DEFAULT;
  35535. +int vchiq_susp_log_level = VCHIQ_LOG_ERROR;
  35536. +
  35537. +#define SUSPEND_TIMER_TIMEOUT_MS 100
  35538. +#define SUSPEND_RETRY_TIMER_TIMEOUT_MS 1000
  35539. +
  35540. +#define VC_SUSPEND_NUM_OFFSET 3 /* number of values before idle which are -ve */
  35541. +static const char *const suspend_state_names[] = {
  35542. + "VC_SUSPEND_FORCE_CANCELED",
  35543. + "VC_SUSPEND_REJECTED",
  35544. + "VC_SUSPEND_FAILED",
  35545. + "VC_SUSPEND_IDLE",
  35546. + "VC_SUSPEND_REQUESTED",
  35547. + "VC_SUSPEND_IN_PROGRESS",
  35548. + "VC_SUSPEND_SUSPENDED"
  35549. +};
  35550. +#define VC_RESUME_NUM_OFFSET 1 /* number of values before idle which are -ve */
  35551. +static const char *const resume_state_names[] = {
  35552. + "VC_RESUME_FAILED",
  35553. + "VC_RESUME_IDLE",
  35554. + "VC_RESUME_REQUESTED",
  35555. + "VC_RESUME_IN_PROGRESS",
  35556. + "VC_RESUME_RESUMED"
  35557. +};
  35558. +/* The number of times we allow force suspend to timeout before actually
  35559. +** _forcing_ suspend. This is to cater for SW which fails to release vchiq
  35560. +** correctly - we don't want to prevent ARM suspend indefinitely in this case.
  35561. +*/
  35562. +#define FORCE_SUSPEND_FAIL_MAX 8
  35563. +
  35564. +/* The time in ms allowed for videocore to go idle when force suspend has been
  35565. + * requested */
  35566. +#define FORCE_SUSPEND_TIMEOUT_MS 200
  35567. +
  35568. +
  35569. +static void suspend_timer_callback(unsigned long context);
  35570. +
  35571. +
  35572. +typedef struct user_service_struct {
  35573. + VCHIQ_SERVICE_T *service;
  35574. + void *userdata;
  35575. + VCHIQ_INSTANCE_T instance;
  35576. + char is_vchi;
  35577. + char dequeue_pending;
  35578. + char close_pending;
  35579. + int message_available_pos;
  35580. + int msg_insert;
  35581. + int msg_remove;
  35582. + struct semaphore insert_event;
  35583. + struct semaphore remove_event;
  35584. + struct semaphore close_event;
  35585. + VCHIQ_HEADER_T * msg_queue[MSG_QUEUE_SIZE];
  35586. +} USER_SERVICE_T;
  35587. +
  35588. +struct bulk_waiter_node {
  35589. + struct bulk_waiter bulk_waiter;
  35590. + int pid;
  35591. + struct list_head list;
  35592. +};
  35593. +
  35594. +struct vchiq_instance_struct {
  35595. + VCHIQ_STATE_T *state;
  35596. + VCHIQ_COMPLETION_DATA_T completions[MAX_COMPLETIONS];
  35597. + int completion_insert;
  35598. + int completion_remove;
  35599. + struct semaphore insert_event;
  35600. + struct semaphore remove_event;
  35601. + struct mutex completion_mutex;
  35602. +
  35603. + int connected;
  35604. + int closing;
  35605. + int pid;
  35606. + int mark;
  35607. + int use_close_delivered;
  35608. + int trace;
  35609. +
  35610. + struct list_head bulk_waiter_list;
  35611. + struct mutex bulk_waiter_list_mutex;
  35612. +
  35613. + VCHIQ_DEBUGFS_NODE_T debugfs_node;
  35614. +};
  35615. +
  35616. +typedef struct dump_context_struct {
  35617. + char __user *buf;
  35618. + size_t actual;
  35619. + size_t space;
  35620. + loff_t offset;
  35621. +} DUMP_CONTEXT_T;
  35622. +
  35623. +static struct cdev vchiq_cdev;
  35624. +static dev_t vchiq_devid;
  35625. +static VCHIQ_STATE_T g_state;
  35626. +static struct class *vchiq_class;
  35627. +static struct device *vchiq_dev;
  35628. +static DEFINE_SPINLOCK(msg_queue_spinlock);
  35629. +
  35630. +static const char *const ioctl_names[] = {
  35631. + "CONNECT",
  35632. + "SHUTDOWN",
  35633. + "CREATE_SERVICE",
  35634. + "REMOVE_SERVICE",
  35635. + "QUEUE_MESSAGE",
  35636. + "QUEUE_BULK_TRANSMIT",
  35637. + "QUEUE_BULK_RECEIVE",
  35638. + "AWAIT_COMPLETION",
  35639. + "DEQUEUE_MESSAGE",
  35640. + "GET_CLIENT_ID",
  35641. + "GET_CONFIG",
  35642. + "CLOSE_SERVICE",
  35643. + "USE_SERVICE",
  35644. + "RELEASE_SERVICE",
  35645. + "SET_SERVICE_OPTION",
  35646. + "DUMP_PHYS_MEM",
  35647. + "LIB_VERSION",
  35648. + "CLOSE_DELIVERED"
  35649. +};
  35650. +
  35651. +vchiq_static_assert((sizeof(ioctl_names)/sizeof(ioctl_names[0])) ==
  35652. + (VCHIQ_IOC_MAX + 1));
  35653. +
  35654. +static void
  35655. +dump_phys_mem(void *virt_addr, uint32_t num_bytes);
  35656. +
  35657. +/****************************************************************************
  35658. +*
  35659. +* add_completion
  35660. +*
  35661. +***************************************************************************/
  35662. +
  35663. +static VCHIQ_STATUS_T
  35664. +add_completion(VCHIQ_INSTANCE_T instance, VCHIQ_REASON_T reason,
  35665. + VCHIQ_HEADER_T *header, USER_SERVICE_T *user_service,
  35666. + void *bulk_userdata)
  35667. +{
  35668. + VCHIQ_COMPLETION_DATA_T *completion;
  35669. + DEBUG_INITIALISE(g_state.local)
  35670. +
  35671. + while (instance->completion_insert ==
  35672. + (instance->completion_remove + MAX_COMPLETIONS)) {
  35673. + /* Out of space - wait for the client */
  35674. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  35675. + vchiq_log_trace(vchiq_arm_log_level,
  35676. + "add_completion - completion queue full");
  35677. + DEBUG_COUNT(COMPLETION_QUEUE_FULL_COUNT);
  35678. + if (down_interruptible(&instance->remove_event) != 0) {
  35679. + vchiq_log_info(vchiq_arm_log_level,
  35680. + "service_callback interrupted");
  35681. + return VCHIQ_RETRY;
  35682. + } else if (instance->closing) {
  35683. + vchiq_log_info(vchiq_arm_log_level,
  35684. + "service_callback closing");
  35685. + return VCHIQ_ERROR;
  35686. + }
  35687. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  35688. + }
  35689. +
  35690. + completion =
  35691. + &instance->completions[instance->completion_insert &
  35692. + (MAX_COMPLETIONS - 1)];
  35693. +
  35694. + completion->header = header;
  35695. + completion->reason = reason;
  35696. + /* N.B. service_userdata is updated while processing AWAIT_COMPLETION */
  35697. + completion->service_userdata = user_service->service;
  35698. + completion->bulk_userdata = bulk_userdata;
  35699. +
  35700. + if (reason == VCHIQ_SERVICE_CLOSED) {
  35701. + /* Take an extra reference, to be held until
  35702. + this CLOSED notification is delivered. */
  35703. + lock_service(user_service->service);
  35704. + if (instance->use_close_delivered)
  35705. + user_service->close_pending = 1;
  35706. + }
  35707. +
  35708. + /* A write barrier is needed here to ensure that the entire completion
  35709. + record is written out before the insert point. */
  35710. + wmb();
  35711. +
  35712. + if (reason == VCHIQ_MESSAGE_AVAILABLE)
  35713. + user_service->message_available_pos =
  35714. + instance->completion_insert;
  35715. + instance->completion_insert++;
  35716. +
  35717. + up(&instance->insert_event);
  35718. +
  35719. + return VCHIQ_SUCCESS;
  35720. +}
  35721. +
  35722. +/****************************************************************************
  35723. +*
  35724. +* service_callback
  35725. +*
  35726. +***************************************************************************/
  35727. +
  35728. +static VCHIQ_STATUS_T
  35729. +service_callback(VCHIQ_REASON_T reason, VCHIQ_HEADER_T *header,
  35730. + VCHIQ_SERVICE_HANDLE_T handle, void *bulk_userdata)
  35731. +{
  35732. + /* How do we ensure the callback goes to the right client?
  35733. + ** The service_user data points to a USER_SERVICE_T record containing
  35734. + ** the original callback and the user state structure, which contains a
  35735. + ** circular buffer for completion records.
  35736. + */
  35737. + USER_SERVICE_T *user_service;
  35738. + VCHIQ_SERVICE_T *service;
  35739. + VCHIQ_INSTANCE_T instance;
  35740. + DEBUG_INITIALISE(g_state.local)
  35741. +
  35742. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  35743. +
  35744. + service = handle_to_service(handle);
  35745. + BUG_ON(!service);
  35746. + user_service = (USER_SERVICE_T *)service->base.userdata;
  35747. + instance = user_service->instance;
  35748. +
  35749. + if (!instance || instance->closing)
  35750. + return VCHIQ_SUCCESS;
  35751. +
  35752. + vchiq_log_trace(vchiq_arm_log_level,
  35753. + "service_callback - service %lx(%d,%p), reason %d, header %lx, "
  35754. + "instance %lx, bulk_userdata %lx",
  35755. + (unsigned long)user_service,
  35756. + service->localport, user_service->userdata,
  35757. + reason, (unsigned long)header,
  35758. + (unsigned long)instance, (unsigned long)bulk_userdata);
  35759. +
  35760. + if (header && user_service->is_vchi) {
  35761. + spin_lock(&msg_queue_spinlock);
  35762. + while (user_service->msg_insert ==
  35763. + (user_service->msg_remove + MSG_QUEUE_SIZE)) {
  35764. + spin_unlock(&msg_queue_spinlock);
  35765. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  35766. + DEBUG_COUNT(MSG_QUEUE_FULL_COUNT);
  35767. + vchiq_log_trace(vchiq_arm_log_level,
  35768. + "service_callback - msg queue full");
  35769. + /* If there is no MESSAGE_AVAILABLE in the completion
  35770. + ** queue, add one
  35771. + */
  35772. + if ((user_service->message_available_pos -
  35773. + instance->completion_remove) < 0) {
  35774. + VCHIQ_STATUS_T status;
  35775. + vchiq_log_info(vchiq_arm_log_level,
  35776. + "Inserting extra MESSAGE_AVAILABLE");
  35777. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  35778. + status = add_completion(instance, reason,
  35779. + NULL, user_service, bulk_userdata);
  35780. + if (status != VCHIQ_SUCCESS) {
  35781. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  35782. + return status;
  35783. + }
  35784. + }
  35785. +
  35786. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  35787. + if (down_interruptible(&user_service->remove_event)
  35788. + != 0) {
  35789. + vchiq_log_info(vchiq_arm_log_level,
  35790. + "service_callback interrupted");
  35791. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  35792. + return VCHIQ_RETRY;
  35793. + } else if (instance->closing) {
  35794. + vchiq_log_info(vchiq_arm_log_level,
  35795. + "service_callback closing");
  35796. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  35797. + return VCHIQ_ERROR;
  35798. + }
  35799. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  35800. + spin_lock(&msg_queue_spinlock);
  35801. + }
  35802. +
  35803. + user_service->msg_queue[user_service->msg_insert &
  35804. + (MSG_QUEUE_SIZE - 1)] = header;
  35805. + user_service->msg_insert++;
  35806. + spin_unlock(&msg_queue_spinlock);
  35807. +
  35808. + up(&user_service->insert_event);
  35809. +
  35810. + /* If there is a thread waiting in DEQUEUE_MESSAGE, or if
  35811. + ** there is a MESSAGE_AVAILABLE in the completion queue then
  35812. + ** bypass the completion queue.
  35813. + */
  35814. + if (((user_service->message_available_pos -
  35815. + instance->completion_remove) >= 0) ||
  35816. + user_service->dequeue_pending) {
  35817. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  35818. + user_service->dequeue_pending = 0;
  35819. + return VCHIQ_SUCCESS;
  35820. + }
  35821. +
  35822. + header = NULL;
  35823. + }
  35824. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  35825. +
  35826. + return add_completion(instance, reason, header, user_service,
  35827. + bulk_userdata);
  35828. +}
  35829. +
  35830. +/****************************************************************************
  35831. +*
  35832. +* user_service_free
  35833. +*
  35834. +***************************************************************************/
  35835. +static void
  35836. +user_service_free(void *userdata)
  35837. +{
  35838. + kfree(userdata);
  35839. +}
  35840. +
  35841. +/****************************************************************************
  35842. +*
  35843. +* close_delivered
  35844. +*
  35845. +***************************************************************************/
  35846. +static void close_delivered(USER_SERVICE_T *user_service)
  35847. +{
  35848. + vchiq_log_info(vchiq_arm_log_level,
  35849. + "close_delivered(handle=%x)",
  35850. + user_service->service->handle);
  35851. +
  35852. + if (user_service->close_pending) {
  35853. + /* Allow the underlying service to be culled */
  35854. + unlock_service(user_service->service);
  35855. +
  35856. + /* Wake the user-thread blocked in close_ or remove_service */
  35857. + up(&user_service->close_event);
  35858. +
  35859. + user_service->close_pending = 0;
  35860. + }
  35861. +}
  35862. +
  35863. +/****************************************************************************
  35864. +*
  35865. +* vchiq_ioctl
  35866. +*
  35867. +***************************************************************************/
  35868. +static long
  35869. +vchiq_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  35870. +{
  35871. + VCHIQ_INSTANCE_T instance = file->private_data;
  35872. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  35873. + VCHIQ_SERVICE_T *service = NULL;
  35874. + long ret = 0;
  35875. + int i, rc;
  35876. + DEBUG_INITIALISE(g_state.local)
  35877. +
  35878. + vchiq_log_trace(vchiq_arm_log_level,
  35879. + "vchiq_ioctl - instance %x, cmd %s, arg %lx",
  35880. + (unsigned int)instance,
  35881. + ((_IOC_TYPE(cmd) == VCHIQ_IOC_MAGIC) &&
  35882. + (_IOC_NR(cmd) <= VCHIQ_IOC_MAX)) ?
  35883. + ioctl_names[_IOC_NR(cmd)] : "<invalid>", arg);
  35884. +
  35885. + switch (cmd) {
  35886. + case VCHIQ_IOC_SHUTDOWN:
  35887. + if (!instance->connected)
  35888. + break;
  35889. +
  35890. + /* Remove all services */
  35891. + i = 0;
  35892. + while ((service = next_service_by_instance(instance->state,
  35893. + instance, &i)) != NULL) {
  35894. + status = vchiq_remove_service(service->handle);
  35895. + unlock_service(service);
  35896. + if (status != VCHIQ_SUCCESS)
  35897. + break;
  35898. + }
  35899. + service = NULL;
  35900. +
  35901. + if (status == VCHIQ_SUCCESS) {
  35902. + /* Wake the completion thread and ask it to exit */
  35903. + instance->closing = 1;
  35904. + up(&instance->insert_event);
  35905. + }
  35906. +
  35907. + break;
  35908. +
  35909. + case VCHIQ_IOC_CONNECT:
  35910. + if (instance->connected) {
  35911. + ret = -EINVAL;
  35912. + break;
  35913. + }
  35914. + rc = mutex_lock_interruptible(&instance->state->mutex);
  35915. + if (rc != 0) {
  35916. + vchiq_log_error(vchiq_arm_log_level,
  35917. + "vchiq: connect: could not lock mutex for "
  35918. + "state %d: %d",
  35919. + instance->state->id, rc);
  35920. + ret = -EINTR;
  35921. + break;
  35922. + }
  35923. + status = vchiq_connect_internal(instance->state, instance);
  35924. + mutex_unlock(&instance->state->mutex);
  35925. +
  35926. + if (status == VCHIQ_SUCCESS)
  35927. + instance->connected = 1;
  35928. + else
  35929. + vchiq_log_error(vchiq_arm_log_level,
  35930. + "vchiq: could not connect: %d", status);
  35931. + break;
  35932. +
  35933. + case VCHIQ_IOC_CREATE_SERVICE: {
  35934. + VCHIQ_CREATE_SERVICE_T args;
  35935. + USER_SERVICE_T *user_service = NULL;
  35936. + void *userdata;
  35937. + int srvstate;
  35938. +
  35939. + if (copy_from_user
  35940. + (&args, (const void __user *)arg,
  35941. + sizeof(args)) != 0) {
  35942. + ret = -EFAULT;
  35943. + break;
  35944. + }
  35945. +
  35946. + user_service = kmalloc(sizeof(USER_SERVICE_T), GFP_KERNEL);
  35947. + if (!user_service) {
  35948. + ret = -ENOMEM;
  35949. + break;
  35950. + }
  35951. +
  35952. + if (args.is_open) {
  35953. + if (!instance->connected) {
  35954. + ret = -ENOTCONN;
  35955. + kfree(user_service);
  35956. + break;
  35957. + }
  35958. + srvstate = VCHIQ_SRVSTATE_OPENING;
  35959. + } else {
  35960. + srvstate =
  35961. + instance->connected ?
  35962. + VCHIQ_SRVSTATE_LISTENING :
  35963. + VCHIQ_SRVSTATE_HIDDEN;
  35964. + }
  35965. +
  35966. + userdata = args.params.userdata;
  35967. + args.params.callback = service_callback;
  35968. + args.params.userdata = user_service;
  35969. + service = vchiq_add_service_internal(
  35970. + instance->state,
  35971. + &args.params, srvstate,
  35972. + instance, user_service_free);
  35973. +
  35974. + if (service != NULL) {
  35975. + user_service->service = service;
  35976. + user_service->userdata = userdata;
  35977. + user_service->instance = instance;
  35978. + user_service->is_vchi = (args.is_vchi != 0);
  35979. + user_service->dequeue_pending = 0;
  35980. + user_service->close_pending = 0;
  35981. + user_service->message_available_pos =
  35982. + instance->completion_remove - 1;
  35983. + user_service->msg_insert = 0;
  35984. + user_service->msg_remove = 0;
  35985. + sema_init(&user_service->insert_event, 0);
  35986. + sema_init(&user_service->remove_event, 0);
  35987. + sema_init(&user_service->close_event, 0);
  35988. +
  35989. + if (args.is_open) {
  35990. + status = vchiq_open_service_internal
  35991. + (service, instance->pid);
  35992. + if (status != VCHIQ_SUCCESS) {
  35993. + vchiq_remove_service(service->handle);
  35994. + service = NULL;
  35995. + ret = (status == VCHIQ_RETRY) ?
  35996. + -EINTR : -EIO;
  35997. + break;
  35998. + }
  35999. + }
  36000. +
  36001. + if (copy_to_user((void __user *)
  36002. + &(((VCHIQ_CREATE_SERVICE_T __user *)
  36003. + arg)->handle),
  36004. + (const void *)&service->handle,
  36005. + sizeof(service->handle)) != 0) {
  36006. + ret = -EFAULT;
  36007. + vchiq_remove_service(service->handle);
  36008. + }
  36009. +
  36010. + service = NULL;
  36011. + } else {
  36012. + ret = -EEXIST;
  36013. + kfree(user_service);
  36014. + }
  36015. + } break;
  36016. +
  36017. + case VCHIQ_IOC_CLOSE_SERVICE: {
  36018. + VCHIQ_SERVICE_HANDLE_T handle = (VCHIQ_SERVICE_HANDLE_T)arg;
  36019. +
  36020. + service = find_service_for_instance(instance, handle);
  36021. + if (service != NULL) {
  36022. + USER_SERVICE_T *user_service =
  36023. + (USER_SERVICE_T *)service->base.userdata;
  36024. + /* close_pending is false on first entry, and when the
  36025. + wait in vchiq_close_service has been interrupted. */
  36026. + if (!user_service->close_pending) {
  36027. + status = vchiq_close_service(service->handle);
  36028. + if (status != VCHIQ_SUCCESS)
  36029. + break;
  36030. + }
  36031. +
  36032. + /* close_pending is true once the underlying service
  36033. + has been closed until the client library calls the
  36034. + CLOSE_DELIVERED ioctl, signalling close_event. */
  36035. + if (user_service->close_pending &&
  36036. + down_interruptible(&user_service->close_event))
  36037. + status = VCHIQ_RETRY;
  36038. + }
  36039. + else
  36040. + ret = -EINVAL;
  36041. + } break;
  36042. +
  36043. + case VCHIQ_IOC_REMOVE_SERVICE: {
  36044. + VCHIQ_SERVICE_HANDLE_T handle = (VCHIQ_SERVICE_HANDLE_T)arg;
  36045. +
  36046. + service = find_service_for_instance(instance, handle);
  36047. + if (service != NULL) {
  36048. + USER_SERVICE_T *user_service =
  36049. + (USER_SERVICE_T *)service->base.userdata;
  36050. + /* close_pending is false on first entry, and when the
  36051. + wait in vchiq_close_service has been interrupted. */
  36052. + if (!user_service->close_pending) {
  36053. + status = vchiq_remove_service(service->handle);
  36054. + if (status != VCHIQ_SUCCESS)
  36055. + break;
  36056. + }
  36057. +
  36058. + /* close_pending is true once the underlying service
  36059. + has been closed until the client library calls the
  36060. + CLOSE_DELIVERED ioctl, signalling close_event. */
  36061. + if (user_service->close_pending &&
  36062. + down_interruptible(&user_service->close_event))
  36063. + status = VCHIQ_RETRY;
  36064. + }
  36065. + else
  36066. + ret = -EINVAL;
  36067. + } break;
  36068. +
  36069. + case VCHIQ_IOC_USE_SERVICE:
  36070. + case VCHIQ_IOC_RELEASE_SERVICE: {
  36071. + VCHIQ_SERVICE_HANDLE_T handle = (VCHIQ_SERVICE_HANDLE_T)arg;
  36072. +
  36073. + service = find_service_for_instance(instance, handle);
  36074. + if (service != NULL) {
  36075. + status = (cmd == VCHIQ_IOC_USE_SERVICE) ?
  36076. + vchiq_use_service_internal(service) :
  36077. + vchiq_release_service_internal(service);
  36078. + if (status != VCHIQ_SUCCESS) {
  36079. + vchiq_log_error(vchiq_susp_log_level,
  36080. + "%s: cmd %s returned error %d for "
  36081. + "service %c%c%c%c:%03d",
  36082. + __func__,
  36083. + (cmd == VCHIQ_IOC_USE_SERVICE) ?
  36084. + "VCHIQ_IOC_USE_SERVICE" :
  36085. + "VCHIQ_IOC_RELEASE_SERVICE",
  36086. + status,
  36087. + VCHIQ_FOURCC_AS_4CHARS(
  36088. + service->base.fourcc),
  36089. + service->client_id);
  36090. + ret = -EINVAL;
  36091. + }
  36092. + } else
  36093. + ret = -EINVAL;
  36094. + } break;
  36095. +
  36096. + case VCHIQ_IOC_QUEUE_MESSAGE: {
  36097. + VCHIQ_QUEUE_MESSAGE_T args;
  36098. + if (copy_from_user
  36099. + (&args, (const void __user *)arg,
  36100. + sizeof(args)) != 0) {
  36101. + ret = -EFAULT;
  36102. + break;
  36103. + }
  36104. +
  36105. + service = find_service_for_instance(instance, args.handle);
  36106. +
  36107. + if ((service != NULL) && (args.count <= MAX_ELEMENTS)) {
  36108. + /* Copy elements into kernel space */
  36109. + VCHIQ_ELEMENT_T elements[MAX_ELEMENTS];
  36110. + if (copy_from_user(elements, args.elements,
  36111. + args.count * sizeof(VCHIQ_ELEMENT_T)) == 0)
  36112. + status = vchiq_queue_message
  36113. + (args.handle,
  36114. + elements, args.count);
  36115. + else
  36116. + ret = -EFAULT;
  36117. + } else {
  36118. + ret = -EINVAL;
  36119. + }
  36120. + } break;
  36121. +
  36122. + case VCHIQ_IOC_QUEUE_BULK_TRANSMIT:
  36123. + case VCHIQ_IOC_QUEUE_BULK_RECEIVE: {
  36124. + VCHIQ_QUEUE_BULK_TRANSFER_T args;
  36125. + struct bulk_waiter_node *waiter = NULL;
  36126. + VCHIQ_BULK_DIR_T dir =
  36127. + (cmd == VCHIQ_IOC_QUEUE_BULK_TRANSMIT) ?
  36128. + VCHIQ_BULK_TRANSMIT : VCHIQ_BULK_RECEIVE;
  36129. +
  36130. + if (copy_from_user
  36131. + (&args, (const void __user *)arg,
  36132. + sizeof(args)) != 0) {
  36133. + ret = -EFAULT;
  36134. + break;
  36135. + }
  36136. +
  36137. + service = find_service_for_instance(instance, args.handle);
  36138. + if (!service) {
  36139. + ret = -EINVAL;
  36140. + break;
  36141. + }
  36142. +
  36143. + if (args.mode == VCHIQ_BULK_MODE_BLOCKING) {
  36144. + waiter = kzalloc(sizeof(struct bulk_waiter_node),
  36145. + GFP_KERNEL);
  36146. + if (!waiter) {
  36147. + ret = -ENOMEM;
  36148. + break;
  36149. + }
  36150. + args.userdata = &waiter->bulk_waiter;
  36151. + } else if (args.mode == VCHIQ_BULK_MODE_WAITING) {
  36152. + struct list_head *pos;
  36153. + mutex_lock(&instance->bulk_waiter_list_mutex);
  36154. + list_for_each(pos, &instance->bulk_waiter_list) {
  36155. + if (list_entry(pos, struct bulk_waiter_node,
  36156. + list)->pid == current->pid) {
  36157. + waiter = list_entry(pos,
  36158. + struct bulk_waiter_node,
  36159. + list);
  36160. + list_del(pos);
  36161. + break;
  36162. + }
  36163. +
  36164. + }
  36165. + mutex_unlock(&instance->bulk_waiter_list_mutex);
  36166. + if (!waiter) {
  36167. + vchiq_log_error(vchiq_arm_log_level,
  36168. + "no bulk_waiter found for pid %d",
  36169. + current->pid);
  36170. + ret = -ESRCH;
  36171. + break;
  36172. + }
  36173. + vchiq_log_info(vchiq_arm_log_level,
  36174. + "found bulk_waiter %x for pid %d",
  36175. + (unsigned int)waiter, current->pid);
  36176. + args.userdata = &waiter->bulk_waiter;
  36177. + }
  36178. + status = vchiq_bulk_transfer
  36179. + (args.handle,
  36180. + VCHI_MEM_HANDLE_INVALID,
  36181. + args.data, args.size,
  36182. + args.userdata, args.mode,
  36183. + dir);
  36184. + if (!waiter)
  36185. + break;
  36186. + if ((status != VCHIQ_RETRY) || fatal_signal_pending(current) ||
  36187. + !waiter->bulk_waiter.bulk) {
  36188. + if (waiter->bulk_waiter.bulk) {
  36189. + /* Cancel the signal when the transfer
  36190. + ** completes. */
  36191. + spin_lock(&bulk_waiter_spinlock);
  36192. + waiter->bulk_waiter.bulk->userdata = NULL;
  36193. + spin_unlock(&bulk_waiter_spinlock);
  36194. + }
  36195. + kfree(waiter);
  36196. + } else {
  36197. + const VCHIQ_BULK_MODE_T mode_waiting =
  36198. + VCHIQ_BULK_MODE_WAITING;
  36199. + waiter->pid = current->pid;
  36200. + mutex_lock(&instance->bulk_waiter_list_mutex);
  36201. + list_add(&waiter->list, &instance->bulk_waiter_list);
  36202. + mutex_unlock(&instance->bulk_waiter_list_mutex);
  36203. + vchiq_log_info(vchiq_arm_log_level,
  36204. + "saved bulk_waiter %x for pid %d",
  36205. + (unsigned int)waiter, current->pid);
  36206. +
  36207. + if (copy_to_user((void __user *)
  36208. + &(((VCHIQ_QUEUE_BULK_TRANSFER_T __user *)
  36209. + arg)->mode),
  36210. + (const void *)&mode_waiting,
  36211. + sizeof(mode_waiting)) != 0)
  36212. + ret = -EFAULT;
  36213. + }
  36214. + } break;
  36215. +
  36216. + case VCHIQ_IOC_AWAIT_COMPLETION: {
  36217. + VCHIQ_AWAIT_COMPLETION_T args;
  36218. +
  36219. + DEBUG_TRACE(AWAIT_COMPLETION_LINE);
  36220. + if (!instance->connected) {
  36221. + ret = -ENOTCONN;
  36222. + break;
  36223. + }
  36224. +
  36225. + if (copy_from_user(&args, (const void __user *)arg,
  36226. + sizeof(args)) != 0) {
  36227. + ret = -EFAULT;
  36228. + break;
  36229. + }
  36230. +
  36231. + mutex_lock(&instance->completion_mutex);
  36232. +
  36233. + DEBUG_TRACE(AWAIT_COMPLETION_LINE);
  36234. + while ((instance->completion_remove ==
  36235. + instance->completion_insert)
  36236. + && !instance->closing) {
  36237. + int rc;
  36238. + DEBUG_TRACE(AWAIT_COMPLETION_LINE);
  36239. + mutex_unlock(&instance->completion_mutex);
  36240. + rc = down_interruptible(&instance->insert_event);
  36241. + mutex_lock(&instance->completion_mutex);
  36242. + if (rc != 0) {
  36243. + DEBUG_TRACE(AWAIT_COMPLETION_LINE);
  36244. + vchiq_log_info(vchiq_arm_log_level,
  36245. + "AWAIT_COMPLETION interrupted");
  36246. + ret = -EINTR;
  36247. + break;
  36248. + }
  36249. + }
  36250. + DEBUG_TRACE(AWAIT_COMPLETION_LINE);
  36251. +
  36252. + /* A read memory barrier is needed to stop prefetch of a stale
  36253. + ** completion record
  36254. + */
  36255. + rmb();
  36256. +
  36257. + if (ret == 0) {
  36258. + int msgbufcount = args.msgbufcount;
  36259. + for (ret = 0; ret < args.count; ret++) {
  36260. + VCHIQ_COMPLETION_DATA_T *completion;
  36261. + VCHIQ_SERVICE_T *service;
  36262. + USER_SERVICE_T *user_service;
  36263. + VCHIQ_HEADER_T *header;
  36264. + if (instance->completion_remove ==
  36265. + instance->completion_insert)
  36266. + break;
  36267. + completion = &instance->completions[
  36268. + instance->completion_remove &
  36269. + (MAX_COMPLETIONS - 1)];
  36270. +
  36271. + service = completion->service_userdata;
  36272. + user_service = service->base.userdata;
  36273. + completion->service_userdata =
  36274. + user_service->userdata;
  36275. +
  36276. + header = completion->header;
  36277. + if (header) {
  36278. + void __user *msgbuf;
  36279. + int msglen;
  36280. +
  36281. + msglen = header->size +
  36282. + sizeof(VCHIQ_HEADER_T);
  36283. + /* This must be a VCHIQ-style service */
  36284. + if (args.msgbufsize < msglen) {
  36285. + vchiq_log_error(
  36286. + vchiq_arm_log_level,
  36287. + "header %x: msgbufsize"
  36288. + " %x < msglen %x",
  36289. + (unsigned int)header,
  36290. + args.msgbufsize,
  36291. + msglen);
  36292. + WARN(1, "invalid message "
  36293. + "size\n");
  36294. + if (ret == 0)
  36295. + ret = -EMSGSIZE;
  36296. + break;
  36297. + }
  36298. + if (msgbufcount <= 0)
  36299. + /* Stall here for lack of a
  36300. + ** buffer for the message. */
  36301. + break;
  36302. + /* Get the pointer from user space */
  36303. + msgbufcount--;
  36304. + if (copy_from_user(&msgbuf,
  36305. + (const void __user *)
  36306. + &args.msgbufs[msgbufcount],
  36307. + sizeof(msgbuf)) != 0) {
  36308. + if (ret == 0)
  36309. + ret = -EFAULT;
  36310. + break;
  36311. + }
  36312. +
  36313. + /* Copy the message to user space */
  36314. + if (copy_to_user(msgbuf, header,
  36315. + msglen) != 0) {
  36316. + if (ret == 0)
  36317. + ret = -EFAULT;
  36318. + break;
  36319. + }
  36320. +
  36321. + /* Now it has been copied, the message
  36322. + ** can be released. */
  36323. + vchiq_release_message(service->handle,
  36324. + header);
  36325. +
  36326. + /* The completion must point to the
  36327. + ** msgbuf. */
  36328. + completion->header = msgbuf;
  36329. + }
  36330. +
  36331. + if ((completion->reason ==
  36332. + VCHIQ_SERVICE_CLOSED) &&
  36333. + !instance->use_close_delivered)
  36334. + unlock_service(service);
  36335. +
  36336. + if (copy_to_user((void __user *)(
  36337. + (size_t)args.buf +
  36338. + ret * sizeof(VCHIQ_COMPLETION_DATA_T)),
  36339. + completion,
  36340. + sizeof(VCHIQ_COMPLETION_DATA_T)) != 0) {
  36341. + if (ret == 0)
  36342. + ret = -EFAULT;
  36343. + break;
  36344. + }
  36345. +
  36346. + instance->completion_remove++;
  36347. + }
  36348. +
  36349. + if (msgbufcount != args.msgbufcount) {
  36350. + if (copy_to_user((void __user *)
  36351. + &((VCHIQ_AWAIT_COMPLETION_T *)arg)->
  36352. + msgbufcount,
  36353. + &msgbufcount,
  36354. + sizeof(msgbufcount)) != 0) {
  36355. + ret = -EFAULT;
  36356. + }
  36357. + }
  36358. + }
  36359. +
  36360. + if (ret != 0)
  36361. + up(&instance->remove_event);
  36362. + mutex_unlock(&instance->completion_mutex);
  36363. + DEBUG_TRACE(AWAIT_COMPLETION_LINE);
  36364. + } break;
  36365. +
  36366. + case VCHIQ_IOC_DEQUEUE_MESSAGE: {
  36367. + VCHIQ_DEQUEUE_MESSAGE_T args;
  36368. + USER_SERVICE_T *user_service;
  36369. + VCHIQ_HEADER_T *header;
  36370. +
  36371. + DEBUG_TRACE(DEQUEUE_MESSAGE_LINE);
  36372. + if (copy_from_user
  36373. + (&args, (const void __user *)arg,
  36374. + sizeof(args)) != 0) {
  36375. + ret = -EFAULT;
  36376. + break;
  36377. + }
  36378. + service = find_service_for_instance(instance, args.handle);
  36379. + if (!service) {
  36380. + ret = -EINVAL;
  36381. + break;
  36382. + }
  36383. + user_service = (USER_SERVICE_T *)service->base.userdata;
  36384. + if (user_service->is_vchi == 0) {
  36385. + ret = -EINVAL;
  36386. + break;
  36387. + }
  36388. +
  36389. + spin_lock(&msg_queue_spinlock);
  36390. + if (user_service->msg_remove == user_service->msg_insert) {
  36391. + if (!args.blocking) {
  36392. + spin_unlock(&msg_queue_spinlock);
  36393. + DEBUG_TRACE(DEQUEUE_MESSAGE_LINE);
  36394. + ret = -EWOULDBLOCK;
  36395. + break;
  36396. + }
  36397. + user_service->dequeue_pending = 1;
  36398. + do {
  36399. + spin_unlock(&msg_queue_spinlock);
  36400. + DEBUG_TRACE(DEQUEUE_MESSAGE_LINE);
  36401. + if (down_interruptible(
  36402. + &user_service->insert_event) != 0) {
  36403. + vchiq_log_info(vchiq_arm_log_level,
  36404. + "DEQUEUE_MESSAGE interrupted");
  36405. + ret = -EINTR;
  36406. + break;
  36407. + }
  36408. + spin_lock(&msg_queue_spinlock);
  36409. + } while (user_service->msg_remove ==
  36410. + user_service->msg_insert);
  36411. +
  36412. + if (ret)
  36413. + break;
  36414. + }
  36415. +
  36416. + BUG_ON((int)(user_service->msg_insert -
  36417. + user_service->msg_remove) < 0);
  36418. +
  36419. + header = user_service->msg_queue[user_service->msg_remove &
  36420. + (MSG_QUEUE_SIZE - 1)];
  36421. + user_service->msg_remove++;
  36422. + spin_unlock(&msg_queue_spinlock);
  36423. +
  36424. + up(&user_service->remove_event);
  36425. + if (header == NULL)
  36426. + ret = -ENOTCONN;
  36427. + else if (header->size <= args.bufsize) {
  36428. + /* Copy to user space if msgbuf is not NULL */
  36429. + if ((args.buf == NULL) ||
  36430. + (copy_to_user((void __user *)args.buf,
  36431. + header->data,
  36432. + header->size) == 0)) {
  36433. + ret = header->size;
  36434. + vchiq_release_message(
  36435. + service->handle,
  36436. + header);
  36437. + } else
  36438. + ret = -EFAULT;
  36439. + } else {
  36440. + vchiq_log_error(vchiq_arm_log_level,
  36441. + "header %x: bufsize %x < size %x",
  36442. + (unsigned int)header, args.bufsize,
  36443. + header->size);
  36444. + WARN(1, "invalid size\n");
  36445. + ret = -EMSGSIZE;
  36446. + }
  36447. + DEBUG_TRACE(DEQUEUE_MESSAGE_LINE);
  36448. + } break;
  36449. +
  36450. + case VCHIQ_IOC_GET_CLIENT_ID: {
  36451. + VCHIQ_SERVICE_HANDLE_T handle = (VCHIQ_SERVICE_HANDLE_T)arg;
  36452. +
  36453. + ret = vchiq_get_client_id(handle);
  36454. + } break;
  36455. +
  36456. + case VCHIQ_IOC_GET_CONFIG: {
  36457. + VCHIQ_GET_CONFIG_T args;
  36458. + VCHIQ_CONFIG_T config;
  36459. +
  36460. + if (copy_from_user(&args, (const void __user *)arg,
  36461. + sizeof(args)) != 0) {
  36462. + ret = -EFAULT;
  36463. + break;
  36464. + }
  36465. + if (args.config_size > sizeof(config)) {
  36466. + ret = -EINVAL;
  36467. + break;
  36468. + }
  36469. + status = vchiq_get_config(instance, args.config_size, &config);
  36470. + if (status == VCHIQ_SUCCESS) {
  36471. + if (copy_to_user((void __user *)args.pconfig,
  36472. + &config, args.config_size) != 0) {
  36473. + ret = -EFAULT;
  36474. + break;
  36475. + }
  36476. + }
  36477. + } break;
  36478. +
  36479. + case VCHIQ_IOC_SET_SERVICE_OPTION: {
  36480. + VCHIQ_SET_SERVICE_OPTION_T args;
  36481. +
  36482. + if (copy_from_user(
  36483. + &args, (const void __user *)arg,
  36484. + sizeof(args)) != 0) {
  36485. + ret = -EFAULT;
  36486. + break;
  36487. + }
  36488. +
  36489. + service = find_service_for_instance(instance, args.handle);
  36490. + if (!service) {
  36491. + ret = -EINVAL;
  36492. + break;
  36493. + }
  36494. +
  36495. + status = vchiq_set_service_option(
  36496. + args.handle, args.option, args.value);
  36497. + } break;
  36498. +
  36499. + case VCHIQ_IOC_DUMP_PHYS_MEM: {
  36500. + VCHIQ_DUMP_MEM_T args;
  36501. +
  36502. + if (copy_from_user
  36503. + (&args, (const void __user *)arg,
  36504. + sizeof(args)) != 0) {
  36505. + ret = -EFAULT;
  36506. + break;
  36507. + }
  36508. + dump_phys_mem(args.virt_addr, args.num_bytes);
  36509. + } break;
  36510. +
  36511. + case VCHIQ_IOC_LIB_VERSION: {
  36512. + unsigned int lib_version = (unsigned int)arg;
  36513. +
  36514. + if (lib_version < VCHIQ_VERSION_MIN)
  36515. + ret = -EINVAL;
  36516. + else if (lib_version >= VCHIQ_VERSION_CLOSE_DELIVERED)
  36517. + instance->use_close_delivered = 1;
  36518. + } break;
  36519. +
  36520. + case VCHIQ_IOC_CLOSE_DELIVERED: {
  36521. + VCHIQ_SERVICE_HANDLE_T handle = (VCHIQ_SERVICE_HANDLE_T)arg;
  36522. +
  36523. + service = find_closed_service_for_instance(instance, handle);
  36524. + if (service != NULL) {
  36525. + USER_SERVICE_T *user_service =
  36526. + (USER_SERVICE_T *)service->base.userdata;
  36527. + close_delivered(user_service);
  36528. + }
  36529. + else
  36530. + ret = -EINVAL;
  36531. + } break;
  36532. +
  36533. + default:
  36534. + ret = -ENOTTY;
  36535. + break;
  36536. + }
  36537. +
  36538. + if (service)
  36539. + unlock_service(service);
  36540. +
  36541. + if (ret == 0) {
  36542. + if (status == VCHIQ_ERROR)
  36543. + ret = -EIO;
  36544. + else if (status == VCHIQ_RETRY)
  36545. + ret = -EINTR;
  36546. + }
  36547. +
  36548. + if ((status == VCHIQ_SUCCESS) && (ret < 0) && (ret != -EINTR) &&
  36549. + (ret != -EWOULDBLOCK))
  36550. + vchiq_log_info(vchiq_arm_log_level,
  36551. + " ioctl instance %lx, cmd %s -> status %d, %ld",
  36552. + (unsigned long)instance,
  36553. + (_IOC_NR(cmd) <= VCHIQ_IOC_MAX) ?
  36554. + ioctl_names[_IOC_NR(cmd)] :
  36555. + "<invalid>",
  36556. + status, ret);
  36557. + else
  36558. + vchiq_log_trace(vchiq_arm_log_level,
  36559. + " ioctl instance %lx, cmd %s -> status %d, %ld",
  36560. + (unsigned long)instance,
  36561. + (_IOC_NR(cmd) <= VCHIQ_IOC_MAX) ?
  36562. + ioctl_names[_IOC_NR(cmd)] :
  36563. + "<invalid>",
  36564. + status, ret);
  36565. +
  36566. + return ret;
  36567. +}
  36568. +
  36569. +/****************************************************************************
  36570. +*
  36571. +* vchiq_open
  36572. +*
  36573. +***************************************************************************/
  36574. +
  36575. +static int
  36576. +vchiq_open(struct inode *inode, struct file *file)
  36577. +{
  36578. + int dev = iminor(inode) & 0x0f;
  36579. + vchiq_log_info(vchiq_arm_log_level, "vchiq_open");
  36580. + switch (dev) {
  36581. + case VCHIQ_MINOR: {
  36582. + int ret;
  36583. + VCHIQ_STATE_T *state = vchiq_get_state();
  36584. + VCHIQ_INSTANCE_T instance;
  36585. +
  36586. + if (!state) {
  36587. + vchiq_log_error(vchiq_arm_log_level,
  36588. + "vchiq has no connection to VideoCore");
  36589. + return -ENOTCONN;
  36590. + }
  36591. +
  36592. + instance = kzalloc(sizeof(*instance), GFP_KERNEL);
  36593. + if (!instance)
  36594. + return -ENOMEM;
  36595. +
  36596. + instance->state = state;
  36597. + instance->pid = current->tgid;
  36598. +
  36599. + ret = vchiq_debugfs_add_instance(instance);
  36600. + if (ret != 0) {
  36601. + kfree(instance);
  36602. + return ret;
  36603. + }
  36604. +
  36605. + sema_init(&instance->insert_event, 0);
  36606. + sema_init(&instance->remove_event, 0);
  36607. + mutex_init(&instance->completion_mutex);
  36608. + mutex_init(&instance->bulk_waiter_list_mutex);
  36609. + INIT_LIST_HEAD(&instance->bulk_waiter_list);
  36610. +
  36611. + file->private_data = instance;
  36612. + } break;
  36613. +
  36614. + default:
  36615. + vchiq_log_error(vchiq_arm_log_level,
  36616. + "Unknown minor device: %d", dev);
  36617. + return -ENXIO;
  36618. + }
  36619. +
  36620. + return 0;
  36621. +}
  36622. +
  36623. +/****************************************************************************
  36624. +*
  36625. +* vchiq_release
  36626. +*
  36627. +***************************************************************************/
  36628. +
  36629. +static int
  36630. +vchiq_release(struct inode *inode, struct file *file)
  36631. +{
  36632. + int dev = iminor(inode) & 0x0f;
  36633. + int ret = 0;
  36634. + switch (dev) {
  36635. + case VCHIQ_MINOR: {
  36636. + VCHIQ_INSTANCE_T instance = file->private_data;
  36637. + VCHIQ_STATE_T *state = vchiq_get_state();
  36638. + VCHIQ_SERVICE_T *service;
  36639. + int i;
  36640. +
  36641. + vchiq_log_info(vchiq_arm_log_level,
  36642. + "vchiq_release: instance=%lx",
  36643. + (unsigned long)instance);
  36644. +
  36645. + if (!state) {
  36646. + ret = -EPERM;
  36647. + goto out;
  36648. + }
  36649. +
  36650. + /* Ensure videocore is awake to allow termination. */
  36651. + vchiq_use_internal(instance->state, NULL,
  36652. + USE_TYPE_VCHIQ);
  36653. +
  36654. + mutex_lock(&instance->completion_mutex);
  36655. +
  36656. + /* Wake the completion thread and ask it to exit */
  36657. + instance->closing = 1;
  36658. + up(&instance->insert_event);
  36659. +
  36660. + mutex_unlock(&instance->completion_mutex);
  36661. +
  36662. + /* Wake the slot handler if the completion queue is full. */
  36663. + up(&instance->remove_event);
  36664. +
  36665. + /* Mark all services for termination... */
  36666. + i = 0;
  36667. + while ((service = next_service_by_instance(state, instance,
  36668. + &i)) != NULL) {
  36669. + USER_SERVICE_T *user_service = service->base.userdata;
  36670. +
  36671. + /* Wake the slot handler if the msg queue is full. */
  36672. + up(&user_service->remove_event);
  36673. +
  36674. + vchiq_terminate_service_internal(service);
  36675. + unlock_service(service);
  36676. + }
  36677. +
  36678. + /* ...and wait for them to die */
  36679. + i = 0;
  36680. + while ((service = next_service_by_instance(state, instance, &i))
  36681. + != NULL) {
  36682. + USER_SERVICE_T *user_service = service->base.userdata;
  36683. +
  36684. + down(&service->remove_event);
  36685. +
  36686. + BUG_ON(service->srvstate != VCHIQ_SRVSTATE_FREE);
  36687. +
  36688. + spin_lock(&msg_queue_spinlock);
  36689. +
  36690. + while (user_service->msg_remove !=
  36691. + user_service->msg_insert) {
  36692. + VCHIQ_HEADER_T *header = user_service->
  36693. + msg_queue[user_service->msg_remove &
  36694. + (MSG_QUEUE_SIZE - 1)];
  36695. + user_service->msg_remove++;
  36696. + spin_unlock(&msg_queue_spinlock);
  36697. +
  36698. + if (header)
  36699. + vchiq_release_message(
  36700. + service->handle,
  36701. + header);
  36702. + spin_lock(&msg_queue_spinlock);
  36703. + }
  36704. +
  36705. + spin_unlock(&msg_queue_spinlock);
  36706. +
  36707. + unlock_service(service);
  36708. + }
  36709. +
  36710. + /* Release any closed services */
  36711. + while (instance->completion_remove !=
  36712. + instance->completion_insert) {
  36713. + VCHIQ_COMPLETION_DATA_T *completion;
  36714. + VCHIQ_SERVICE_T *service;
  36715. + completion = &instance->completions[
  36716. + instance->completion_remove &
  36717. + (MAX_COMPLETIONS - 1)];
  36718. + service = completion->service_userdata;
  36719. + if (completion->reason == VCHIQ_SERVICE_CLOSED)
  36720. + {
  36721. + USER_SERVICE_T *user_service =
  36722. + service->base.userdata;
  36723. +
  36724. + /* Wake any blocked user-thread */
  36725. + if (instance->use_close_delivered)
  36726. + up(&user_service->close_event);
  36727. + unlock_service(service);
  36728. + }
  36729. + instance->completion_remove++;
  36730. + }
  36731. +
  36732. + /* Release the PEER service count. */
  36733. + vchiq_release_internal(instance->state, NULL);
  36734. +
  36735. + {
  36736. + struct list_head *pos, *next;
  36737. + list_for_each_safe(pos, next,
  36738. + &instance->bulk_waiter_list) {
  36739. + struct bulk_waiter_node *waiter;
  36740. + waiter = list_entry(pos,
  36741. + struct bulk_waiter_node,
  36742. + list);
  36743. + list_del(pos);
  36744. + vchiq_log_info(vchiq_arm_log_level,
  36745. + "bulk_waiter - cleaned up %x "
  36746. + "for pid %d",
  36747. + (unsigned int)waiter, waiter->pid);
  36748. + kfree(waiter);
  36749. + }
  36750. + }
  36751. +
  36752. + vchiq_debugfs_remove_instance(instance);
  36753. +
  36754. + kfree(instance);
  36755. + file->private_data = NULL;
  36756. + } break;
  36757. +
  36758. + default:
  36759. + vchiq_log_error(vchiq_arm_log_level,
  36760. + "Unknown minor device: %d", dev);
  36761. + ret = -ENXIO;
  36762. + }
  36763. +
  36764. +out:
  36765. + return ret;
  36766. +}
  36767. +
  36768. +/****************************************************************************
  36769. +*
  36770. +* vchiq_dump
  36771. +*
  36772. +***************************************************************************/
  36773. +
  36774. +void
  36775. +vchiq_dump(void *dump_context, const char *str, int len)
  36776. +{
  36777. + DUMP_CONTEXT_T *context = (DUMP_CONTEXT_T *)dump_context;
  36778. +
  36779. + if (context->actual < context->space) {
  36780. + int copy_bytes;
  36781. + if (context->offset > 0) {
  36782. + int skip_bytes = min(len, (int)context->offset);
  36783. + str += skip_bytes;
  36784. + len -= skip_bytes;
  36785. + context->offset -= skip_bytes;
  36786. + if (context->offset > 0)
  36787. + return;
  36788. + }
  36789. + copy_bytes = min(len, (int)(context->space - context->actual));
  36790. + if (copy_bytes == 0)
  36791. + return;
  36792. + if (copy_to_user(context->buf + context->actual, str,
  36793. + copy_bytes))
  36794. + context->actual = -EFAULT;
  36795. + context->actual += copy_bytes;
  36796. + len -= copy_bytes;
  36797. +
  36798. + /* If tne terminating NUL is included in the length, then it
  36799. + ** marks the end of a line and should be replaced with a
  36800. + ** carriage return. */
  36801. + if ((len == 0) && (str[copy_bytes - 1] == '\0')) {
  36802. + char cr = '\n';
  36803. + if (copy_to_user(context->buf + context->actual - 1,
  36804. + &cr, 1))
  36805. + context->actual = -EFAULT;
  36806. + }
  36807. + }
  36808. +}
  36809. +
  36810. +/****************************************************************************
  36811. +*
  36812. +* vchiq_dump_platform_instance_state
  36813. +*
  36814. +***************************************************************************/
  36815. +
  36816. +void
  36817. +vchiq_dump_platform_instances(void *dump_context)
  36818. +{
  36819. + VCHIQ_STATE_T *state = vchiq_get_state();
  36820. + char buf[80];
  36821. + int len;
  36822. + int i;
  36823. +
  36824. + /* There is no list of instances, so instead scan all services,
  36825. + marking those that have been dumped. */
  36826. +
  36827. + for (i = 0; i < state->unused_service; i++) {
  36828. + VCHIQ_SERVICE_T *service = state->services[i];
  36829. + VCHIQ_INSTANCE_T instance;
  36830. +
  36831. + if (service && (service->base.callback == service_callback)) {
  36832. + instance = service->instance;
  36833. + if (instance)
  36834. + instance->mark = 0;
  36835. + }
  36836. + }
  36837. +
  36838. + for (i = 0; i < state->unused_service; i++) {
  36839. + VCHIQ_SERVICE_T *service = state->services[i];
  36840. + VCHIQ_INSTANCE_T instance;
  36841. +
  36842. + if (service && (service->base.callback == service_callback)) {
  36843. + instance = service->instance;
  36844. + if (instance && !instance->mark) {
  36845. + len = snprintf(buf, sizeof(buf),
  36846. + "Instance %x: pid %d,%s completions "
  36847. + "%d/%d",
  36848. + (unsigned int)instance, instance->pid,
  36849. + instance->connected ? " connected, " :
  36850. + "",
  36851. + instance->completion_insert -
  36852. + instance->completion_remove,
  36853. + MAX_COMPLETIONS);
  36854. +
  36855. + vchiq_dump(dump_context, buf, len + 1);
  36856. +
  36857. + instance->mark = 1;
  36858. + }
  36859. + }
  36860. + }
  36861. +}
  36862. +
  36863. +/****************************************************************************
  36864. +*
  36865. +* vchiq_dump_platform_service_state
  36866. +*
  36867. +***************************************************************************/
  36868. +
  36869. +void
  36870. +vchiq_dump_platform_service_state(void *dump_context, VCHIQ_SERVICE_T *service)
  36871. +{
  36872. + USER_SERVICE_T *user_service = (USER_SERVICE_T *)service->base.userdata;
  36873. + char buf[80];
  36874. + int len;
  36875. +
  36876. + len = snprintf(buf, sizeof(buf), " instance %x",
  36877. + (unsigned int)service->instance);
  36878. +
  36879. + if ((service->base.callback == service_callback) &&
  36880. + user_service->is_vchi) {
  36881. + len += snprintf(buf + len, sizeof(buf) - len,
  36882. + ", %d/%d messages",
  36883. + user_service->msg_insert - user_service->msg_remove,
  36884. + MSG_QUEUE_SIZE);
  36885. +
  36886. + if (user_service->dequeue_pending)
  36887. + len += snprintf(buf + len, sizeof(buf) - len,
  36888. + " (dequeue pending)");
  36889. + }
  36890. +
  36891. + vchiq_dump(dump_context, buf, len + 1);
  36892. +}
  36893. +
  36894. +/****************************************************************************
  36895. +*
  36896. +* dump_user_mem
  36897. +*
  36898. +***************************************************************************/
  36899. +
  36900. +static void
  36901. +dump_phys_mem(void *virt_addr, uint32_t num_bytes)
  36902. +{
  36903. + int rc;
  36904. + uint8_t *end_virt_addr = virt_addr + num_bytes;
  36905. + int num_pages;
  36906. + int offset;
  36907. + int end_offset;
  36908. + int page_idx;
  36909. + int prev_idx;
  36910. + struct page *page;
  36911. + struct page **pages;
  36912. + uint8_t *kmapped_virt_ptr;
  36913. +
  36914. + /* Align virtAddr and endVirtAddr to 16 byte boundaries. */
  36915. +
  36916. + virt_addr = (void *)((unsigned long)virt_addr & ~0x0fuL);
  36917. + end_virt_addr = (void *)(((unsigned long)end_virt_addr + 15uL) &
  36918. + ~0x0fuL);
  36919. +
  36920. + offset = (int)(long)virt_addr & (PAGE_SIZE - 1);
  36921. + end_offset = (int)(long)end_virt_addr & (PAGE_SIZE - 1);
  36922. +
  36923. + num_pages = (offset + num_bytes + PAGE_SIZE - 1) / PAGE_SIZE;
  36924. +
  36925. + pages = kmalloc(sizeof(struct page *) * num_pages, GFP_KERNEL);
  36926. + if (pages == NULL) {
  36927. + vchiq_log_error(vchiq_arm_log_level,
  36928. + "Unable to allocation memory for %d pages\n",
  36929. + num_pages);
  36930. + return;
  36931. + }
  36932. +
  36933. + down_read(&current->mm->mmap_sem);
  36934. + rc = get_user_pages(current, /* task */
  36935. + current->mm, /* mm */
  36936. + (unsigned long)virt_addr, /* start */
  36937. + num_pages, /* len */
  36938. + 0, /* write */
  36939. + 0, /* force */
  36940. + pages, /* pages (array of page pointers) */
  36941. + NULL); /* vmas */
  36942. + up_read(&current->mm->mmap_sem);
  36943. +
  36944. + prev_idx = -1;
  36945. + page = NULL;
  36946. +
  36947. + while (offset < end_offset) {
  36948. +
  36949. + int page_offset = offset % PAGE_SIZE;
  36950. + page_idx = offset / PAGE_SIZE;
  36951. +
  36952. + if (page_idx != prev_idx) {
  36953. +
  36954. + if (page != NULL)
  36955. + kunmap(page);
  36956. + page = pages[page_idx];
  36957. + kmapped_virt_ptr = kmap(page);
  36958. +
  36959. + prev_idx = page_idx;
  36960. + }
  36961. +
  36962. + if (vchiq_arm_log_level >= VCHIQ_LOG_TRACE)
  36963. + vchiq_log_dump_mem("ph",
  36964. + (uint32_t)(unsigned long)&kmapped_virt_ptr[
  36965. + page_offset],
  36966. + &kmapped_virt_ptr[page_offset], 16);
  36967. +
  36968. + offset += 16;
  36969. + }
  36970. + if (page != NULL)
  36971. + kunmap(page);
  36972. +
  36973. + for (page_idx = 0; page_idx < num_pages; page_idx++)
  36974. + page_cache_release(pages[page_idx]);
  36975. +
  36976. + kfree(pages);
  36977. +}
  36978. +
  36979. +/****************************************************************************
  36980. +*
  36981. +* vchiq_read
  36982. +*
  36983. +***************************************************************************/
  36984. +
  36985. +static ssize_t
  36986. +vchiq_read(struct file *file, char __user *buf,
  36987. + size_t count, loff_t *ppos)
  36988. +{
  36989. + DUMP_CONTEXT_T context;
  36990. + context.buf = buf;
  36991. + context.actual = 0;
  36992. + context.space = count;
  36993. + context.offset = *ppos;
  36994. +
  36995. + vchiq_dump_state(&context, &g_state);
  36996. +
  36997. + *ppos += context.actual;
  36998. +
  36999. + return context.actual;
  37000. +}
  37001. +
  37002. +VCHIQ_STATE_T *
  37003. +vchiq_get_state(void)
  37004. +{
  37005. +
  37006. + if (g_state.remote == NULL)
  37007. + printk(KERN_ERR "%s: g_state.remote == NULL\n", __func__);
  37008. + else if (g_state.remote->initialised != 1)
  37009. + printk(KERN_NOTICE "%s: g_state.remote->initialised != 1 (%d)\n",
  37010. + __func__, g_state.remote->initialised);
  37011. +
  37012. + return ((g_state.remote != NULL) &&
  37013. + (g_state.remote->initialised == 1)) ? &g_state : NULL;
  37014. +}
  37015. +
  37016. +static const struct file_operations
  37017. +vchiq_fops = {
  37018. + .owner = THIS_MODULE,
  37019. + .unlocked_ioctl = vchiq_ioctl,
  37020. + .open = vchiq_open,
  37021. + .release = vchiq_release,
  37022. + .read = vchiq_read
  37023. +};
  37024. +
  37025. +/*
  37026. + * Autosuspend related functionality
  37027. + */
  37028. +
  37029. +int
  37030. +vchiq_videocore_wanted(VCHIQ_STATE_T *state)
  37031. +{
  37032. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  37033. + if (!arm_state)
  37034. + /* autosuspend not supported - always return wanted */
  37035. + return 1;
  37036. + else if (arm_state->blocked_count)
  37037. + return 1;
  37038. + else if (!arm_state->videocore_use_count)
  37039. + /* usage count zero - check for override unless we're forcing */
  37040. + if (arm_state->resume_blocked)
  37041. + return 0;
  37042. + else
  37043. + return vchiq_platform_videocore_wanted(state);
  37044. + else
  37045. + /* non-zero usage count - videocore still required */
  37046. + return 1;
  37047. +}
  37048. +
  37049. +static VCHIQ_STATUS_T
  37050. +vchiq_keepalive_vchiq_callback(VCHIQ_REASON_T reason,
  37051. + VCHIQ_HEADER_T *header,
  37052. + VCHIQ_SERVICE_HANDLE_T service_user,
  37053. + void *bulk_user)
  37054. +{
  37055. + vchiq_log_error(vchiq_susp_log_level,
  37056. + "%s callback reason %d", __func__, reason);
  37057. + return 0;
  37058. +}
  37059. +
  37060. +static int
  37061. +vchiq_keepalive_thread_func(void *v)
  37062. +{
  37063. + VCHIQ_STATE_T *state = (VCHIQ_STATE_T *) v;
  37064. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  37065. +
  37066. + VCHIQ_STATUS_T status;
  37067. + VCHIQ_INSTANCE_T instance;
  37068. + VCHIQ_SERVICE_HANDLE_T ka_handle;
  37069. +
  37070. + VCHIQ_SERVICE_PARAMS_T params = {
  37071. + .fourcc = VCHIQ_MAKE_FOURCC('K', 'E', 'E', 'P'),
  37072. + .callback = vchiq_keepalive_vchiq_callback,
  37073. + .version = KEEPALIVE_VER,
  37074. + .version_min = KEEPALIVE_VER_MIN
  37075. + };
  37076. +
  37077. + status = vchiq_initialise(&instance);
  37078. + if (status != VCHIQ_SUCCESS) {
  37079. + vchiq_log_error(vchiq_susp_log_level,
  37080. + "%s vchiq_initialise failed %d", __func__, status);
  37081. + goto exit;
  37082. + }
  37083. +
  37084. + status = vchiq_connect(instance);
  37085. + if (status != VCHIQ_SUCCESS) {
  37086. + vchiq_log_error(vchiq_susp_log_level,
  37087. + "%s vchiq_connect failed %d", __func__, status);
  37088. + goto shutdown;
  37089. + }
  37090. +
  37091. + status = vchiq_add_service(instance, &params, &ka_handle);
  37092. + if (status != VCHIQ_SUCCESS) {
  37093. + vchiq_log_error(vchiq_susp_log_level,
  37094. + "%s vchiq_open_service failed %d", __func__, status);
  37095. + goto shutdown;
  37096. + }
  37097. +
  37098. + while (1) {
  37099. + long rc = 0, uc = 0;
  37100. + if (wait_for_completion_interruptible(&arm_state->ka_evt)
  37101. + != 0) {
  37102. + vchiq_log_error(vchiq_susp_log_level,
  37103. + "%s interrupted", __func__);
  37104. + flush_signals(current);
  37105. + continue;
  37106. + }
  37107. +
  37108. + /* read and clear counters. Do release_count then use_count to
  37109. + * prevent getting more releases than uses */
  37110. + rc = atomic_xchg(&arm_state->ka_release_count, 0);
  37111. + uc = atomic_xchg(&arm_state->ka_use_count, 0);
  37112. +
  37113. + /* Call use/release service the requisite number of times.
  37114. + * Process use before release so use counts don't go negative */
  37115. + while (uc--) {
  37116. + atomic_inc(&arm_state->ka_use_ack_count);
  37117. + status = vchiq_use_service(ka_handle);
  37118. + if (status != VCHIQ_SUCCESS) {
  37119. + vchiq_log_error(vchiq_susp_log_level,
  37120. + "%s vchiq_use_service error %d",
  37121. + __func__, status);
  37122. + }
  37123. + }
  37124. + while (rc--) {
  37125. + status = vchiq_release_service(ka_handle);
  37126. + if (status != VCHIQ_SUCCESS) {
  37127. + vchiq_log_error(vchiq_susp_log_level,
  37128. + "%s vchiq_release_service error %d",
  37129. + __func__, status);
  37130. + }
  37131. + }
  37132. + }
  37133. +
  37134. +shutdown:
  37135. + vchiq_shutdown(instance);
  37136. +exit:
  37137. + return 0;
  37138. +}
  37139. +
  37140. +
  37141. +
  37142. +VCHIQ_STATUS_T
  37143. +vchiq_arm_init_state(VCHIQ_STATE_T *state, VCHIQ_ARM_STATE_T *arm_state)
  37144. +{
  37145. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  37146. +
  37147. + if (arm_state) {
  37148. + rwlock_init(&arm_state->susp_res_lock);
  37149. +
  37150. + init_completion(&arm_state->ka_evt);
  37151. + atomic_set(&arm_state->ka_use_count, 0);
  37152. + atomic_set(&arm_state->ka_use_ack_count, 0);
  37153. + atomic_set(&arm_state->ka_release_count, 0);
  37154. +
  37155. + init_completion(&arm_state->vc_suspend_complete);
  37156. +
  37157. + init_completion(&arm_state->vc_resume_complete);
  37158. + /* Initialise to 'done' state. We only want to block on resume
  37159. + * completion while videocore is suspended. */
  37160. + set_resume_state(arm_state, VC_RESUME_RESUMED);
  37161. +
  37162. + init_completion(&arm_state->resume_blocker);
  37163. + /* Initialise to 'done' state. We only want to block on this
  37164. + * completion while resume is blocked */
  37165. + complete_all(&arm_state->resume_blocker);
  37166. +
  37167. + init_completion(&arm_state->blocked_blocker);
  37168. + /* Initialise to 'done' state. We only want to block on this
  37169. + * completion while things are waiting on the resume blocker */
  37170. + complete_all(&arm_state->blocked_blocker);
  37171. +
  37172. + arm_state->suspend_timer_timeout = SUSPEND_TIMER_TIMEOUT_MS;
  37173. + arm_state->suspend_timer_running = 0;
  37174. + init_timer(&arm_state->suspend_timer);
  37175. + arm_state->suspend_timer.data = (unsigned long)(state);
  37176. + arm_state->suspend_timer.function = suspend_timer_callback;
  37177. +
  37178. + arm_state->first_connect = 0;
  37179. +
  37180. + }
  37181. + return status;
  37182. +}
  37183. +
  37184. +/*
  37185. +** Functions to modify the state variables;
  37186. +** set_suspend_state
  37187. +** set_resume_state
  37188. +**
  37189. +** There are more state variables than we might like, so ensure they remain in
  37190. +** step. Suspend and resume state are maintained separately, since most of
  37191. +** these state machines can operate independently. However, there are a few
  37192. +** states where state transitions in one state machine cause a reset to the
  37193. +** other state machine. In addition, there are some completion events which
  37194. +** need to occur on state machine reset and end-state(s), so these are also
  37195. +** dealt with in these functions.
  37196. +**
  37197. +** In all states we set the state variable according to the input, but in some
  37198. +** cases we perform additional steps outlined below;
  37199. +**
  37200. +** VC_SUSPEND_IDLE - Initialise the suspend completion at the same time.
  37201. +** The suspend completion is completed after any suspend
  37202. +** attempt. When we reset the state machine we also reset
  37203. +** the completion. This reset occurs when videocore is
  37204. +** resumed, and also if we initiate suspend after a suspend
  37205. +** failure.
  37206. +**
  37207. +** VC_SUSPEND_IN_PROGRESS - This state is considered the point of no return for
  37208. +** suspend - ie from this point on we must try to suspend
  37209. +** before resuming can occur. We therefore also reset the
  37210. +** resume state machine to VC_RESUME_IDLE in this state.
  37211. +**
  37212. +** VC_SUSPEND_SUSPENDED - Suspend has completed successfully. Also call
  37213. +** complete_all on the suspend completion to notify
  37214. +** anything waiting for suspend to happen.
  37215. +**
  37216. +** VC_SUSPEND_REJECTED - Videocore rejected suspend. Videocore will also
  37217. +** initiate resume, so no need to alter resume state.
  37218. +** We call complete_all on the suspend completion to notify
  37219. +** of suspend rejection.
  37220. +**
  37221. +** VC_SUSPEND_FAILED - We failed to initiate videocore suspend. We notify the
  37222. +** suspend completion and reset the resume state machine.
  37223. +**
  37224. +** VC_RESUME_IDLE - Initialise the resume completion at the same time. The
  37225. +** resume completion is in it's 'done' state whenever
  37226. +** videcore is running. Therfore, the VC_RESUME_IDLE state
  37227. +** implies that videocore is suspended.
  37228. +** Hence, any thread which needs to wait until videocore is
  37229. +** running can wait on this completion - it will only block
  37230. +** if videocore is suspended.
  37231. +**
  37232. +** VC_RESUME_RESUMED - Resume has completed successfully. Videocore is running.
  37233. +** Call complete_all on the resume completion to unblock
  37234. +** any threads waiting for resume. Also reset the suspend
  37235. +** state machine to it's idle state.
  37236. +**
  37237. +** VC_RESUME_FAILED - Currently unused - no mechanism to fail resume exists.
  37238. +*/
  37239. +
  37240. +inline void
  37241. +set_suspend_state(VCHIQ_ARM_STATE_T *arm_state,
  37242. + enum vc_suspend_status new_state)
  37243. +{
  37244. + /* set the state in all cases */
  37245. + arm_state->vc_suspend_state = new_state;
  37246. +
  37247. + /* state specific additional actions */
  37248. + switch (new_state) {
  37249. + case VC_SUSPEND_FORCE_CANCELED:
  37250. + complete_all(&arm_state->vc_suspend_complete);
  37251. + break;
  37252. + case VC_SUSPEND_REJECTED:
  37253. + complete_all(&arm_state->vc_suspend_complete);
  37254. + break;
  37255. + case VC_SUSPEND_FAILED:
  37256. + complete_all(&arm_state->vc_suspend_complete);
  37257. + arm_state->vc_resume_state = VC_RESUME_RESUMED;
  37258. + complete_all(&arm_state->vc_resume_complete);
  37259. + break;
  37260. + case VC_SUSPEND_IDLE:
  37261. + reinit_completion(&arm_state->vc_suspend_complete);
  37262. + break;
  37263. + case VC_SUSPEND_REQUESTED:
  37264. + break;
  37265. + case VC_SUSPEND_IN_PROGRESS:
  37266. + set_resume_state(arm_state, VC_RESUME_IDLE);
  37267. + break;
  37268. + case VC_SUSPEND_SUSPENDED:
  37269. + complete_all(&arm_state->vc_suspend_complete);
  37270. + break;
  37271. + default:
  37272. + BUG();
  37273. + break;
  37274. + }
  37275. +}
  37276. +
  37277. +inline void
  37278. +set_resume_state(VCHIQ_ARM_STATE_T *arm_state,
  37279. + enum vc_resume_status new_state)
  37280. +{
  37281. + /* set the state in all cases */
  37282. + arm_state->vc_resume_state = new_state;
  37283. +
  37284. + /* state specific additional actions */
  37285. + switch (new_state) {
  37286. + case VC_RESUME_FAILED:
  37287. + break;
  37288. + case VC_RESUME_IDLE:
  37289. + reinit_completion(&arm_state->vc_resume_complete);
  37290. + break;
  37291. + case VC_RESUME_REQUESTED:
  37292. + break;
  37293. + case VC_RESUME_IN_PROGRESS:
  37294. + break;
  37295. + case VC_RESUME_RESUMED:
  37296. + complete_all(&arm_state->vc_resume_complete);
  37297. + set_suspend_state(arm_state, VC_SUSPEND_IDLE);
  37298. + break;
  37299. + default:
  37300. + BUG();
  37301. + break;
  37302. + }
  37303. +}
  37304. +
  37305. +
  37306. +/* should be called with the write lock held */
  37307. +inline void
  37308. +start_suspend_timer(VCHIQ_ARM_STATE_T *arm_state)
  37309. +{
  37310. + del_timer(&arm_state->suspend_timer);
  37311. + arm_state->suspend_timer.expires = jiffies +
  37312. + msecs_to_jiffies(arm_state->
  37313. + suspend_timer_timeout);
  37314. + add_timer(&arm_state->suspend_timer);
  37315. + arm_state->suspend_timer_running = 1;
  37316. +}
  37317. +
  37318. +/* should be called with the write lock held */
  37319. +static inline void
  37320. +stop_suspend_timer(VCHIQ_ARM_STATE_T *arm_state)
  37321. +{
  37322. + if (arm_state->suspend_timer_running) {
  37323. + del_timer(&arm_state->suspend_timer);
  37324. + arm_state->suspend_timer_running = 0;
  37325. + }
  37326. +}
  37327. +
  37328. +static inline int
  37329. +need_resume(VCHIQ_STATE_T *state)
  37330. +{
  37331. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  37332. + return (arm_state->vc_suspend_state > VC_SUSPEND_IDLE) &&
  37333. + (arm_state->vc_resume_state < VC_RESUME_REQUESTED) &&
  37334. + vchiq_videocore_wanted(state);
  37335. +}
  37336. +
  37337. +static int
  37338. +block_resume(VCHIQ_ARM_STATE_T *arm_state)
  37339. +{
  37340. + int status = VCHIQ_SUCCESS;
  37341. + const unsigned long timeout_val =
  37342. + msecs_to_jiffies(FORCE_SUSPEND_TIMEOUT_MS);
  37343. + int resume_count = 0;
  37344. +
  37345. + /* Allow any threads which were blocked by the last force suspend to
  37346. + * complete if they haven't already. Only give this one shot; if
  37347. + * blocked_count is incremented after blocked_blocker is completed
  37348. + * (which only happens when blocked_count hits 0) then those threads
  37349. + * will have to wait until next time around */
  37350. + if (arm_state->blocked_count) {
  37351. + reinit_completion(&arm_state->blocked_blocker);
  37352. + write_unlock_bh(&arm_state->susp_res_lock);
  37353. + vchiq_log_info(vchiq_susp_log_level, "%s wait for previously "
  37354. + "blocked clients", __func__);
  37355. + if (wait_for_completion_interruptible_timeout(
  37356. + &arm_state->blocked_blocker, timeout_val)
  37357. + <= 0) {
  37358. + vchiq_log_error(vchiq_susp_log_level, "%s wait for "
  37359. + "previously blocked clients failed" , __func__);
  37360. + status = VCHIQ_ERROR;
  37361. + write_lock_bh(&arm_state->susp_res_lock);
  37362. + goto out;
  37363. + }
  37364. + vchiq_log_info(vchiq_susp_log_level, "%s previously blocked "
  37365. + "clients resumed", __func__);
  37366. + write_lock_bh(&arm_state->susp_res_lock);
  37367. + }
  37368. +
  37369. + /* We need to wait for resume to complete if it's in process */
  37370. + while (arm_state->vc_resume_state != VC_RESUME_RESUMED &&
  37371. + arm_state->vc_resume_state > VC_RESUME_IDLE) {
  37372. + if (resume_count > 1) {
  37373. + status = VCHIQ_ERROR;
  37374. + vchiq_log_error(vchiq_susp_log_level, "%s waited too "
  37375. + "many times for resume" , __func__);
  37376. + goto out;
  37377. + }
  37378. + write_unlock_bh(&arm_state->susp_res_lock);
  37379. + vchiq_log_info(vchiq_susp_log_level, "%s wait for resume",
  37380. + __func__);
  37381. + if (wait_for_completion_interruptible_timeout(
  37382. + &arm_state->vc_resume_complete, timeout_val)
  37383. + <= 0) {
  37384. + vchiq_log_error(vchiq_susp_log_level, "%s wait for "
  37385. + "resume failed (%s)", __func__,
  37386. + resume_state_names[arm_state->vc_resume_state +
  37387. + VC_RESUME_NUM_OFFSET]);
  37388. + status = VCHIQ_ERROR;
  37389. + write_lock_bh(&arm_state->susp_res_lock);
  37390. + goto out;
  37391. + }
  37392. + vchiq_log_info(vchiq_susp_log_level, "%s resumed", __func__);
  37393. + write_lock_bh(&arm_state->susp_res_lock);
  37394. + resume_count++;
  37395. + }
  37396. + reinit_completion(&arm_state->resume_blocker);
  37397. + arm_state->resume_blocked = 1;
  37398. +
  37399. +out:
  37400. + return status;
  37401. +}
  37402. +
  37403. +static inline void
  37404. +unblock_resume(VCHIQ_ARM_STATE_T *arm_state)
  37405. +{
  37406. + complete_all(&arm_state->resume_blocker);
  37407. + arm_state->resume_blocked = 0;
  37408. +}
  37409. +
  37410. +/* Initiate suspend via slot handler. Should be called with the write lock
  37411. + * held */
  37412. +VCHIQ_STATUS_T
  37413. +vchiq_arm_vcsuspend(VCHIQ_STATE_T *state)
  37414. +{
  37415. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  37416. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  37417. +
  37418. + if (!arm_state)
  37419. + goto out;
  37420. +
  37421. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  37422. + status = VCHIQ_SUCCESS;
  37423. +
  37424. +
  37425. + switch (arm_state->vc_suspend_state) {
  37426. + case VC_SUSPEND_REQUESTED:
  37427. + vchiq_log_info(vchiq_susp_log_level, "%s: suspend already "
  37428. + "requested", __func__);
  37429. + break;
  37430. + case VC_SUSPEND_IN_PROGRESS:
  37431. + vchiq_log_info(vchiq_susp_log_level, "%s: suspend already in "
  37432. + "progress", __func__);
  37433. + break;
  37434. +
  37435. + default:
  37436. + /* We don't expect to be in other states, so log but continue
  37437. + * anyway */
  37438. + vchiq_log_error(vchiq_susp_log_level,
  37439. + "%s unexpected suspend state %s", __func__,
  37440. + suspend_state_names[arm_state->vc_suspend_state +
  37441. + VC_SUSPEND_NUM_OFFSET]);
  37442. + /* fall through */
  37443. + case VC_SUSPEND_REJECTED:
  37444. + case VC_SUSPEND_FAILED:
  37445. + /* Ensure any idle state actions have been run */
  37446. + set_suspend_state(arm_state, VC_SUSPEND_IDLE);
  37447. + /* fall through */
  37448. + case VC_SUSPEND_IDLE:
  37449. + vchiq_log_info(vchiq_susp_log_level,
  37450. + "%s: suspending", __func__);
  37451. + set_suspend_state(arm_state, VC_SUSPEND_REQUESTED);
  37452. + /* kick the slot handler thread to initiate suspend */
  37453. + request_poll(state, NULL, 0);
  37454. + break;
  37455. + }
  37456. +
  37457. +out:
  37458. + vchiq_log_trace(vchiq_susp_log_level, "%s exit %d", __func__, status);
  37459. + return status;
  37460. +}
  37461. +
  37462. +void
  37463. +vchiq_platform_check_suspend(VCHIQ_STATE_T *state)
  37464. +{
  37465. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  37466. + int susp = 0;
  37467. +
  37468. + if (!arm_state)
  37469. + goto out;
  37470. +
  37471. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  37472. +
  37473. + write_lock_bh(&arm_state->susp_res_lock);
  37474. + if (arm_state->vc_suspend_state == VC_SUSPEND_REQUESTED &&
  37475. + arm_state->vc_resume_state == VC_RESUME_RESUMED) {
  37476. + set_suspend_state(arm_state, VC_SUSPEND_IN_PROGRESS);
  37477. + susp = 1;
  37478. + }
  37479. + write_unlock_bh(&arm_state->susp_res_lock);
  37480. +
  37481. + if (susp)
  37482. + vchiq_platform_suspend(state);
  37483. +
  37484. +out:
  37485. + vchiq_log_trace(vchiq_susp_log_level, "%s exit", __func__);
  37486. + return;
  37487. +}
  37488. +
  37489. +
  37490. +static void
  37491. +output_timeout_error(VCHIQ_STATE_T *state)
  37492. +{
  37493. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  37494. + char service_err[50] = "";
  37495. + int vc_use_count = arm_state->videocore_use_count;
  37496. + int active_services = state->unused_service;
  37497. + int i;
  37498. +
  37499. + if (!arm_state->videocore_use_count) {
  37500. + snprintf(service_err, 50, " Videocore usecount is 0");
  37501. + goto output_msg;
  37502. + }
  37503. + for (i = 0; i < active_services; i++) {
  37504. + VCHIQ_SERVICE_T *service_ptr = state->services[i];
  37505. + if (service_ptr && service_ptr->service_use_count &&
  37506. + (service_ptr->srvstate != VCHIQ_SRVSTATE_FREE)) {
  37507. + snprintf(service_err, 50, " %c%c%c%c(%d) service has "
  37508. + "use count %d%s", VCHIQ_FOURCC_AS_4CHARS(
  37509. + service_ptr->base.fourcc),
  37510. + service_ptr->client_id,
  37511. + service_ptr->service_use_count,
  37512. + service_ptr->service_use_count ==
  37513. + vc_use_count ? "" : " (+ more)");
  37514. + break;
  37515. + }
  37516. + }
  37517. +
  37518. +output_msg:
  37519. + vchiq_log_error(vchiq_susp_log_level,
  37520. + "timed out waiting for vc suspend (%d).%s",
  37521. + arm_state->autosuspend_override, service_err);
  37522. +
  37523. +}
  37524. +
  37525. +/* Try to get videocore into suspended state, regardless of autosuspend state.
  37526. +** We don't actually force suspend, since videocore may get into a bad state
  37527. +** if we force suspend at a bad time. Instead, we wait for autosuspend to
  37528. +** determine a good point to suspend. If this doesn't happen within 100ms we
  37529. +** report failure.
  37530. +**
  37531. +** Returns VCHIQ_SUCCESS if videocore suspended successfully, VCHIQ_RETRY if
  37532. +** videocore failed to suspend in time or VCHIQ_ERROR if interrupted.
  37533. +*/
  37534. +VCHIQ_STATUS_T
  37535. +vchiq_arm_force_suspend(VCHIQ_STATE_T *state)
  37536. +{
  37537. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  37538. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  37539. + long rc = 0;
  37540. + int repeat = -1;
  37541. +
  37542. + if (!arm_state)
  37543. + goto out;
  37544. +
  37545. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  37546. +
  37547. + write_lock_bh(&arm_state->susp_res_lock);
  37548. +
  37549. + status = block_resume(arm_state);
  37550. + if (status != VCHIQ_SUCCESS)
  37551. + goto unlock;
  37552. + if (arm_state->vc_suspend_state == VC_SUSPEND_SUSPENDED) {
  37553. + /* Already suspended - just block resume and exit */
  37554. + vchiq_log_info(vchiq_susp_log_level, "%s already suspended",
  37555. + __func__);
  37556. + status = VCHIQ_SUCCESS;
  37557. + goto unlock;
  37558. + } else if (arm_state->vc_suspend_state <= VC_SUSPEND_IDLE) {
  37559. + /* initiate suspend immediately in the case that we're waiting
  37560. + * for the timeout */
  37561. + stop_suspend_timer(arm_state);
  37562. + if (!vchiq_videocore_wanted(state)) {
  37563. + vchiq_log_info(vchiq_susp_log_level, "%s videocore "
  37564. + "idle, initiating suspend", __func__);
  37565. + status = vchiq_arm_vcsuspend(state);
  37566. + } else if (arm_state->autosuspend_override <
  37567. + FORCE_SUSPEND_FAIL_MAX) {
  37568. + vchiq_log_info(vchiq_susp_log_level, "%s letting "
  37569. + "videocore go idle", __func__);
  37570. + status = VCHIQ_SUCCESS;
  37571. + } else {
  37572. + vchiq_log_warning(vchiq_susp_log_level, "%s failed too "
  37573. + "many times - attempting suspend", __func__);
  37574. + status = vchiq_arm_vcsuspend(state);
  37575. + }
  37576. + } else {
  37577. + vchiq_log_info(vchiq_susp_log_level, "%s videocore suspend "
  37578. + "in progress - wait for completion", __func__);
  37579. + status = VCHIQ_SUCCESS;
  37580. + }
  37581. +
  37582. + /* Wait for suspend to happen due to system idle (not forced..) */
  37583. + if (status != VCHIQ_SUCCESS)
  37584. + goto unblock_resume;
  37585. +
  37586. + do {
  37587. + write_unlock_bh(&arm_state->susp_res_lock);
  37588. +
  37589. + rc = wait_for_completion_interruptible_timeout(
  37590. + &arm_state->vc_suspend_complete,
  37591. + msecs_to_jiffies(FORCE_SUSPEND_TIMEOUT_MS));
  37592. +
  37593. + write_lock_bh(&arm_state->susp_res_lock);
  37594. + if (rc < 0) {
  37595. + vchiq_log_warning(vchiq_susp_log_level, "%s "
  37596. + "interrupted waiting for suspend", __func__);
  37597. + status = VCHIQ_ERROR;
  37598. + goto unblock_resume;
  37599. + } else if (rc == 0) {
  37600. + if (arm_state->vc_suspend_state > VC_SUSPEND_IDLE) {
  37601. + /* Repeat timeout once if in progress */
  37602. + if (repeat < 0) {
  37603. + repeat = 1;
  37604. + continue;
  37605. + }
  37606. + }
  37607. + arm_state->autosuspend_override++;
  37608. + output_timeout_error(state);
  37609. +
  37610. + status = VCHIQ_RETRY;
  37611. + goto unblock_resume;
  37612. + }
  37613. + } while (0 < (repeat--));
  37614. +
  37615. + /* Check and report state in case we need to abort ARM suspend */
  37616. + if (arm_state->vc_suspend_state != VC_SUSPEND_SUSPENDED) {
  37617. + status = VCHIQ_RETRY;
  37618. + vchiq_log_error(vchiq_susp_log_level,
  37619. + "%s videocore suspend failed (state %s)", __func__,
  37620. + suspend_state_names[arm_state->vc_suspend_state +
  37621. + VC_SUSPEND_NUM_OFFSET]);
  37622. + /* Reset the state only if it's still in an error state.
  37623. + * Something could have already initiated another suspend. */
  37624. + if (arm_state->vc_suspend_state < VC_SUSPEND_IDLE)
  37625. + set_suspend_state(arm_state, VC_SUSPEND_IDLE);
  37626. +
  37627. + goto unblock_resume;
  37628. + }
  37629. +
  37630. + /* successfully suspended - unlock and exit */
  37631. + goto unlock;
  37632. +
  37633. +unblock_resume:
  37634. + /* all error states need to unblock resume before exit */
  37635. + unblock_resume(arm_state);
  37636. +
  37637. +unlock:
  37638. + write_unlock_bh(&arm_state->susp_res_lock);
  37639. +
  37640. +out:
  37641. + vchiq_log_trace(vchiq_susp_log_level, "%s exit %d", __func__, status);
  37642. + return status;
  37643. +}
  37644. +
  37645. +void
  37646. +vchiq_check_suspend(VCHIQ_STATE_T *state)
  37647. +{
  37648. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  37649. +
  37650. + if (!arm_state)
  37651. + goto out;
  37652. +
  37653. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  37654. +
  37655. + write_lock_bh(&arm_state->susp_res_lock);
  37656. + if (arm_state->vc_suspend_state != VC_SUSPEND_SUSPENDED &&
  37657. + arm_state->first_connect &&
  37658. + !vchiq_videocore_wanted(state)) {
  37659. + vchiq_arm_vcsuspend(state);
  37660. + }
  37661. + write_unlock_bh(&arm_state->susp_res_lock);
  37662. +
  37663. +out:
  37664. + vchiq_log_trace(vchiq_susp_log_level, "%s exit", __func__);
  37665. + return;
  37666. +}
  37667. +
  37668. +
  37669. +int
  37670. +vchiq_arm_allow_resume(VCHIQ_STATE_T *state)
  37671. +{
  37672. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  37673. + int resume = 0;
  37674. + int ret = -1;
  37675. +
  37676. + if (!arm_state)
  37677. + goto out;
  37678. +
  37679. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  37680. +
  37681. + write_lock_bh(&arm_state->susp_res_lock);
  37682. + unblock_resume(arm_state);
  37683. + resume = vchiq_check_resume(state);
  37684. + write_unlock_bh(&arm_state->susp_res_lock);
  37685. +
  37686. + if (resume) {
  37687. + if (wait_for_completion_interruptible(
  37688. + &arm_state->vc_resume_complete) < 0) {
  37689. + vchiq_log_error(vchiq_susp_log_level,
  37690. + "%s interrupted", __func__);
  37691. + /* failed, cannot accurately derive suspend
  37692. + * state, so exit early. */
  37693. + goto out;
  37694. + }
  37695. + }
  37696. +
  37697. + read_lock_bh(&arm_state->susp_res_lock);
  37698. + if (arm_state->vc_suspend_state == VC_SUSPEND_SUSPENDED) {
  37699. + vchiq_log_info(vchiq_susp_log_level,
  37700. + "%s: Videocore remains suspended", __func__);
  37701. + } else {
  37702. + vchiq_log_info(vchiq_susp_log_level,
  37703. + "%s: Videocore resumed", __func__);
  37704. + ret = 0;
  37705. + }
  37706. + read_unlock_bh(&arm_state->susp_res_lock);
  37707. +out:
  37708. + vchiq_log_trace(vchiq_susp_log_level, "%s exit %d", __func__, ret);
  37709. + return ret;
  37710. +}
  37711. +
  37712. +/* This function should be called with the write lock held */
  37713. +int
  37714. +vchiq_check_resume(VCHIQ_STATE_T *state)
  37715. +{
  37716. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  37717. + int resume = 0;
  37718. +
  37719. + if (!arm_state)
  37720. + goto out;
  37721. +
  37722. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  37723. +
  37724. + if (need_resume(state)) {
  37725. + set_resume_state(arm_state, VC_RESUME_REQUESTED);
  37726. + request_poll(state, NULL, 0);
  37727. + resume = 1;
  37728. + }
  37729. +
  37730. +out:
  37731. + vchiq_log_trace(vchiq_susp_log_level, "%s exit", __func__);
  37732. + return resume;
  37733. +}
  37734. +
  37735. +void
  37736. +vchiq_platform_check_resume(VCHIQ_STATE_T *state)
  37737. +{
  37738. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  37739. + int res = 0;
  37740. +
  37741. + if (!arm_state)
  37742. + goto out;
  37743. +
  37744. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  37745. +
  37746. + write_lock_bh(&arm_state->susp_res_lock);
  37747. + if (arm_state->wake_address == 0) {
  37748. + vchiq_log_info(vchiq_susp_log_level,
  37749. + "%s: already awake", __func__);
  37750. + goto unlock;
  37751. + }
  37752. + if (arm_state->vc_resume_state == VC_RESUME_IN_PROGRESS) {
  37753. + vchiq_log_info(vchiq_susp_log_level,
  37754. + "%s: already resuming", __func__);
  37755. + goto unlock;
  37756. + }
  37757. +
  37758. + if (arm_state->vc_resume_state == VC_RESUME_REQUESTED) {
  37759. + set_resume_state(arm_state, VC_RESUME_IN_PROGRESS);
  37760. + res = 1;
  37761. + } else
  37762. + vchiq_log_trace(vchiq_susp_log_level,
  37763. + "%s: not resuming (resume state %s)", __func__,
  37764. + resume_state_names[arm_state->vc_resume_state +
  37765. + VC_RESUME_NUM_OFFSET]);
  37766. +
  37767. +unlock:
  37768. + write_unlock_bh(&arm_state->susp_res_lock);
  37769. +
  37770. + if (res)
  37771. + vchiq_platform_resume(state);
  37772. +
  37773. +out:
  37774. + vchiq_log_trace(vchiq_susp_log_level, "%s exit", __func__);
  37775. + return;
  37776. +
  37777. +}
  37778. +
  37779. +
  37780. +
  37781. +VCHIQ_STATUS_T
  37782. +vchiq_use_internal(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service,
  37783. + enum USE_TYPE_E use_type)
  37784. +{
  37785. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  37786. + VCHIQ_STATUS_T ret = VCHIQ_SUCCESS;
  37787. + char entity[16];
  37788. + int *entity_uc;
  37789. + int local_uc, local_entity_uc;
  37790. +
  37791. + if (!arm_state)
  37792. + goto out;
  37793. +
  37794. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  37795. +
  37796. + if (use_type == USE_TYPE_VCHIQ) {
  37797. + sprintf(entity, "VCHIQ: ");
  37798. + entity_uc = &arm_state->peer_use_count;
  37799. + } else if (service) {
  37800. + sprintf(entity, "%c%c%c%c:%03d",
  37801. + VCHIQ_FOURCC_AS_4CHARS(service->base.fourcc),
  37802. + service->client_id);
  37803. + entity_uc = &service->service_use_count;
  37804. + } else {
  37805. + vchiq_log_error(vchiq_susp_log_level, "%s null service "
  37806. + "ptr", __func__);
  37807. + ret = VCHIQ_ERROR;
  37808. + goto out;
  37809. + }
  37810. +
  37811. + write_lock_bh(&arm_state->susp_res_lock);
  37812. + while (arm_state->resume_blocked) {
  37813. + /* If we call 'use' while force suspend is waiting for suspend,
  37814. + * then we're about to block the thread which the force is
  37815. + * waiting to complete, so we're bound to just time out. In this
  37816. + * case, set the suspend state such that the wait will be
  37817. + * canceled, so we can complete as quickly as possible. */
  37818. + if (arm_state->resume_blocked && arm_state->vc_suspend_state ==
  37819. + VC_SUSPEND_IDLE) {
  37820. + set_suspend_state(arm_state, VC_SUSPEND_FORCE_CANCELED);
  37821. + break;
  37822. + }
  37823. + /* If suspend is already in progress then we need to block */
  37824. + if (!try_wait_for_completion(&arm_state->resume_blocker)) {
  37825. + /* Indicate that there are threads waiting on the resume
  37826. + * blocker. These need to be allowed to complete before
  37827. + * a _second_ call to force suspend can complete,
  37828. + * otherwise low priority threads might never actually
  37829. + * continue */
  37830. + arm_state->blocked_count++;
  37831. + write_unlock_bh(&arm_state->susp_res_lock);
  37832. + vchiq_log_info(vchiq_susp_log_level, "%s %s resume "
  37833. + "blocked - waiting...", __func__, entity);
  37834. + if (wait_for_completion_killable(
  37835. + &arm_state->resume_blocker) != 0) {
  37836. + vchiq_log_error(vchiq_susp_log_level, "%s %s "
  37837. + "wait for resume blocker interrupted",
  37838. + __func__, entity);
  37839. + ret = VCHIQ_ERROR;
  37840. + write_lock_bh(&arm_state->susp_res_lock);
  37841. + arm_state->blocked_count--;
  37842. + write_unlock_bh(&arm_state->susp_res_lock);
  37843. + goto out;
  37844. + }
  37845. + vchiq_log_info(vchiq_susp_log_level, "%s %s resume "
  37846. + "unblocked", __func__, entity);
  37847. + write_lock_bh(&arm_state->susp_res_lock);
  37848. + if (--arm_state->blocked_count == 0)
  37849. + complete_all(&arm_state->blocked_blocker);
  37850. + }
  37851. + }
  37852. +
  37853. + stop_suspend_timer(arm_state);
  37854. +
  37855. + local_uc = ++arm_state->videocore_use_count;
  37856. + local_entity_uc = ++(*entity_uc);
  37857. +
  37858. + /* If there's a pending request which hasn't yet been serviced then
  37859. + * just clear it. If we're past VC_SUSPEND_REQUESTED state then
  37860. + * vc_resume_complete will block until we either resume or fail to
  37861. + * suspend */
  37862. + if (arm_state->vc_suspend_state <= VC_SUSPEND_REQUESTED)
  37863. + set_suspend_state(arm_state, VC_SUSPEND_IDLE);
  37864. +
  37865. + if ((use_type != USE_TYPE_SERVICE_NO_RESUME) && need_resume(state)) {
  37866. + set_resume_state(arm_state, VC_RESUME_REQUESTED);
  37867. + vchiq_log_info(vchiq_susp_log_level,
  37868. + "%s %s count %d, state count %d",
  37869. + __func__, entity, local_entity_uc, local_uc);
  37870. + request_poll(state, NULL, 0);
  37871. + } else
  37872. + vchiq_log_trace(vchiq_susp_log_level,
  37873. + "%s %s count %d, state count %d",
  37874. + __func__, entity, *entity_uc, local_uc);
  37875. +
  37876. +
  37877. + write_unlock_bh(&arm_state->susp_res_lock);
  37878. +
  37879. + /* Completion is in a done state when we're not suspended, so this won't
  37880. + * block for the non-suspended case. */
  37881. + if (!try_wait_for_completion(&arm_state->vc_resume_complete)) {
  37882. + vchiq_log_info(vchiq_susp_log_level, "%s %s wait for resume",
  37883. + __func__, entity);
  37884. + if (wait_for_completion_killable(
  37885. + &arm_state->vc_resume_complete) != 0) {
  37886. + vchiq_log_error(vchiq_susp_log_level, "%s %s wait for "
  37887. + "resume interrupted", __func__, entity);
  37888. + ret = VCHIQ_ERROR;
  37889. + goto out;
  37890. + }
  37891. + vchiq_log_info(vchiq_susp_log_level, "%s %s resumed", __func__,
  37892. + entity);
  37893. + }
  37894. +
  37895. + if (ret == VCHIQ_SUCCESS) {
  37896. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  37897. + long ack_cnt = atomic_xchg(&arm_state->ka_use_ack_count, 0);
  37898. + while (ack_cnt && (status == VCHIQ_SUCCESS)) {
  37899. + /* Send the use notify to videocore */
  37900. + status = vchiq_send_remote_use_active(state);
  37901. + if (status == VCHIQ_SUCCESS)
  37902. + ack_cnt--;
  37903. + else
  37904. + atomic_add(ack_cnt,
  37905. + &arm_state->ka_use_ack_count);
  37906. + }
  37907. + }
  37908. +
  37909. +out:
  37910. + vchiq_log_trace(vchiq_susp_log_level, "%s exit %d", __func__, ret);
  37911. + return ret;
  37912. +}
  37913. +
  37914. +VCHIQ_STATUS_T
  37915. +vchiq_release_internal(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service)
  37916. +{
  37917. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  37918. + VCHIQ_STATUS_T ret = VCHIQ_SUCCESS;
  37919. + char entity[16];
  37920. + int *entity_uc;
  37921. + int local_uc, local_entity_uc;
  37922. +
  37923. + if (!arm_state)
  37924. + goto out;
  37925. +
  37926. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  37927. +
  37928. + if (service) {
  37929. + sprintf(entity, "%c%c%c%c:%03d",
  37930. + VCHIQ_FOURCC_AS_4CHARS(service->base.fourcc),
  37931. + service->client_id);
  37932. + entity_uc = &service->service_use_count;
  37933. + } else {
  37934. + sprintf(entity, "PEER: ");
  37935. + entity_uc = &arm_state->peer_use_count;
  37936. + }
  37937. +
  37938. + write_lock_bh(&arm_state->susp_res_lock);
  37939. + if (!arm_state->videocore_use_count || !(*entity_uc)) {
  37940. + /* Don't use BUG_ON - don't allow user thread to crash kernel */
  37941. + WARN_ON(!arm_state->videocore_use_count);
  37942. + WARN_ON(!(*entity_uc));
  37943. + ret = VCHIQ_ERROR;
  37944. + goto unlock;
  37945. + }
  37946. + local_uc = --arm_state->videocore_use_count;
  37947. + local_entity_uc = --(*entity_uc);
  37948. +
  37949. + if (!vchiq_videocore_wanted(state)) {
  37950. + if (vchiq_platform_use_suspend_timer() &&
  37951. + !arm_state->resume_blocked) {
  37952. + /* Only use the timer if we're not trying to force
  37953. + * suspend (=> resume_blocked) */
  37954. + start_suspend_timer(arm_state);
  37955. + } else {
  37956. + vchiq_log_info(vchiq_susp_log_level,
  37957. + "%s %s count %d, state count %d - suspending",
  37958. + __func__, entity, *entity_uc,
  37959. + arm_state->videocore_use_count);
  37960. + vchiq_arm_vcsuspend(state);
  37961. + }
  37962. + } else
  37963. + vchiq_log_trace(vchiq_susp_log_level,
  37964. + "%s %s count %d, state count %d",
  37965. + __func__, entity, *entity_uc,
  37966. + arm_state->videocore_use_count);
  37967. +
  37968. +unlock:
  37969. + write_unlock_bh(&arm_state->susp_res_lock);
  37970. +
  37971. +out:
  37972. + vchiq_log_trace(vchiq_susp_log_level, "%s exit %d", __func__, ret);
  37973. + return ret;
  37974. +}
  37975. +
  37976. +void
  37977. +vchiq_on_remote_use(VCHIQ_STATE_T *state)
  37978. +{
  37979. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  37980. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  37981. + atomic_inc(&arm_state->ka_use_count);
  37982. + complete(&arm_state->ka_evt);
  37983. +}
  37984. +
  37985. +void
  37986. +vchiq_on_remote_release(VCHIQ_STATE_T *state)
  37987. +{
  37988. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  37989. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  37990. + atomic_inc(&arm_state->ka_release_count);
  37991. + complete(&arm_state->ka_evt);
  37992. +}
  37993. +
  37994. +VCHIQ_STATUS_T
  37995. +vchiq_use_service_internal(VCHIQ_SERVICE_T *service)
  37996. +{
  37997. + return vchiq_use_internal(service->state, service, USE_TYPE_SERVICE);
  37998. +}
  37999. +
  38000. +VCHIQ_STATUS_T
  38001. +vchiq_release_service_internal(VCHIQ_SERVICE_T *service)
  38002. +{
  38003. + return vchiq_release_internal(service->state, service);
  38004. +}
  38005. +
  38006. +VCHIQ_DEBUGFS_NODE_T *
  38007. +vchiq_instance_get_debugfs_node(VCHIQ_INSTANCE_T instance)
  38008. +{
  38009. + return &instance->debugfs_node;
  38010. +}
  38011. +
  38012. +int
  38013. +vchiq_instance_get_use_count(VCHIQ_INSTANCE_T instance)
  38014. +{
  38015. + VCHIQ_SERVICE_T *service;
  38016. + int use_count = 0, i;
  38017. + i = 0;
  38018. + while ((service = next_service_by_instance(instance->state,
  38019. + instance, &i)) != NULL) {
  38020. + use_count += service->service_use_count;
  38021. + unlock_service(service);
  38022. + }
  38023. + return use_count;
  38024. +}
  38025. +
  38026. +int
  38027. +vchiq_instance_get_pid(VCHIQ_INSTANCE_T instance)
  38028. +{
  38029. + return instance->pid;
  38030. +}
  38031. +
  38032. +int
  38033. +vchiq_instance_get_trace(VCHIQ_INSTANCE_T instance)
  38034. +{
  38035. + return instance->trace;
  38036. +}
  38037. +
  38038. +void
  38039. +vchiq_instance_set_trace(VCHIQ_INSTANCE_T instance, int trace)
  38040. +{
  38041. + VCHIQ_SERVICE_T *service;
  38042. + int i;
  38043. + i = 0;
  38044. + while ((service = next_service_by_instance(instance->state,
  38045. + instance, &i)) != NULL) {
  38046. + service->trace = trace;
  38047. + unlock_service(service);
  38048. + }
  38049. + instance->trace = (trace != 0);
  38050. +}
  38051. +
  38052. +static void suspend_timer_callback(unsigned long context)
  38053. +{
  38054. + VCHIQ_STATE_T *state = (VCHIQ_STATE_T *)context;
  38055. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  38056. + if (!arm_state)
  38057. + goto out;
  38058. + vchiq_log_info(vchiq_susp_log_level,
  38059. + "%s - suspend timer expired - check suspend", __func__);
  38060. + vchiq_check_suspend(state);
  38061. +out:
  38062. + return;
  38063. +}
  38064. +
  38065. +VCHIQ_STATUS_T
  38066. +vchiq_use_service_no_resume(VCHIQ_SERVICE_HANDLE_T handle)
  38067. +{
  38068. + VCHIQ_STATUS_T ret = VCHIQ_ERROR;
  38069. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  38070. + if (service) {
  38071. + ret = vchiq_use_internal(service->state, service,
  38072. + USE_TYPE_SERVICE_NO_RESUME);
  38073. + unlock_service(service);
  38074. + }
  38075. + return ret;
  38076. +}
  38077. +
  38078. +VCHIQ_STATUS_T
  38079. +vchiq_use_service(VCHIQ_SERVICE_HANDLE_T handle)
  38080. +{
  38081. + VCHIQ_STATUS_T ret = VCHIQ_ERROR;
  38082. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  38083. + if (service) {
  38084. + ret = vchiq_use_internal(service->state, service,
  38085. + USE_TYPE_SERVICE);
  38086. + unlock_service(service);
  38087. + }
  38088. + return ret;
  38089. +}
  38090. +
  38091. +VCHIQ_STATUS_T
  38092. +vchiq_release_service(VCHIQ_SERVICE_HANDLE_T handle)
  38093. +{
  38094. + VCHIQ_STATUS_T ret = VCHIQ_ERROR;
  38095. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  38096. + if (service) {
  38097. + ret = vchiq_release_internal(service->state, service);
  38098. + unlock_service(service);
  38099. + }
  38100. + return ret;
  38101. +}
  38102. +
  38103. +void
  38104. +vchiq_dump_service_use_state(VCHIQ_STATE_T *state)
  38105. +{
  38106. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  38107. + int i, j = 0;
  38108. + /* Only dump 64 services */
  38109. + static const int local_max_services = 64;
  38110. + /* If there's more than 64 services, only dump ones with
  38111. + * non-zero counts */
  38112. + int only_nonzero = 0;
  38113. + static const char *nz = "<-- preventing suspend";
  38114. +
  38115. + enum vc_suspend_status vc_suspend_state;
  38116. + enum vc_resume_status vc_resume_state;
  38117. + int peer_count;
  38118. + int vc_use_count;
  38119. + int active_services;
  38120. + struct service_data_struct {
  38121. + int fourcc;
  38122. + int clientid;
  38123. + int use_count;
  38124. + } service_data[local_max_services];
  38125. +
  38126. + if (!arm_state)
  38127. + return;
  38128. +
  38129. + read_lock_bh(&arm_state->susp_res_lock);
  38130. + vc_suspend_state = arm_state->vc_suspend_state;
  38131. + vc_resume_state = arm_state->vc_resume_state;
  38132. + peer_count = arm_state->peer_use_count;
  38133. + vc_use_count = arm_state->videocore_use_count;
  38134. + active_services = state->unused_service;
  38135. + if (active_services > local_max_services)
  38136. + only_nonzero = 1;
  38137. +
  38138. + for (i = 0; (i < active_services) && (j < local_max_services); i++) {
  38139. + VCHIQ_SERVICE_T *service_ptr = state->services[i];
  38140. + if (!service_ptr)
  38141. + continue;
  38142. +
  38143. + if (only_nonzero && !service_ptr->service_use_count)
  38144. + continue;
  38145. +
  38146. + if (service_ptr->srvstate != VCHIQ_SRVSTATE_FREE) {
  38147. + service_data[j].fourcc = service_ptr->base.fourcc;
  38148. + service_data[j].clientid = service_ptr->client_id;
  38149. + service_data[j++].use_count = service_ptr->
  38150. + service_use_count;
  38151. + }
  38152. + }
  38153. +
  38154. + read_unlock_bh(&arm_state->susp_res_lock);
  38155. +
  38156. + vchiq_log_warning(vchiq_susp_log_level,
  38157. + "-- Videcore suspend state: %s --",
  38158. + suspend_state_names[vc_suspend_state + VC_SUSPEND_NUM_OFFSET]);
  38159. + vchiq_log_warning(vchiq_susp_log_level,
  38160. + "-- Videcore resume state: %s --",
  38161. + resume_state_names[vc_resume_state + VC_RESUME_NUM_OFFSET]);
  38162. +
  38163. + if (only_nonzero)
  38164. + vchiq_log_warning(vchiq_susp_log_level, "Too many active "
  38165. + "services (%d). Only dumping up to first %d services "
  38166. + "with non-zero use-count", active_services,
  38167. + local_max_services);
  38168. +
  38169. + for (i = 0; i < j; i++) {
  38170. + vchiq_log_warning(vchiq_susp_log_level,
  38171. + "----- %c%c%c%c:%d service count %d %s",
  38172. + VCHIQ_FOURCC_AS_4CHARS(service_data[i].fourcc),
  38173. + service_data[i].clientid,
  38174. + service_data[i].use_count,
  38175. + service_data[i].use_count ? nz : "");
  38176. + }
  38177. + vchiq_log_warning(vchiq_susp_log_level,
  38178. + "----- VCHIQ use count count %d", peer_count);
  38179. + vchiq_log_warning(vchiq_susp_log_level,
  38180. + "--- Overall vchiq instance use count %d", vc_use_count);
  38181. +
  38182. + vchiq_dump_platform_use_state(state);
  38183. +}
  38184. +
  38185. +VCHIQ_STATUS_T
  38186. +vchiq_check_service(VCHIQ_SERVICE_T *service)
  38187. +{
  38188. + VCHIQ_ARM_STATE_T *arm_state;
  38189. + VCHIQ_STATUS_T ret = VCHIQ_ERROR;
  38190. +
  38191. + if (!service || !service->state)
  38192. + goto out;
  38193. +
  38194. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  38195. +
  38196. + arm_state = vchiq_platform_get_arm_state(service->state);
  38197. +
  38198. + read_lock_bh(&arm_state->susp_res_lock);
  38199. + if (service->service_use_count)
  38200. + ret = VCHIQ_SUCCESS;
  38201. + read_unlock_bh(&arm_state->susp_res_lock);
  38202. +
  38203. + if (ret == VCHIQ_ERROR) {
  38204. + vchiq_log_error(vchiq_susp_log_level,
  38205. + "%s ERROR - %c%c%c%c:%d service count %d, "
  38206. + "state count %d, videocore suspend state %s", __func__,
  38207. + VCHIQ_FOURCC_AS_4CHARS(service->base.fourcc),
  38208. + service->client_id, service->service_use_count,
  38209. + arm_state->videocore_use_count,
  38210. + suspend_state_names[arm_state->vc_suspend_state +
  38211. + VC_SUSPEND_NUM_OFFSET]);
  38212. + vchiq_dump_service_use_state(service->state);
  38213. + }
  38214. +out:
  38215. + return ret;
  38216. +}
  38217. +
  38218. +/* stub functions */
  38219. +void vchiq_on_remote_use_active(VCHIQ_STATE_T *state)
  38220. +{
  38221. + (void)state;
  38222. +}
  38223. +
  38224. +void vchiq_platform_conn_state_changed(VCHIQ_STATE_T *state,
  38225. + VCHIQ_CONNSTATE_T oldstate, VCHIQ_CONNSTATE_T newstate)
  38226. +{
  38227. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  38228. + vchiq_log_info(vchiq_susp_log_level, "%d: %s->%s", state->id,
  38229. + get_conn_state_name(oldstate), get_conn_state_name(newstate));
  38230. + if (state->conn_state == VCHIQ_CONNSTATE_CONNECTED) {
  38231. + write_lock_bh(&arm_state->susp_res_lock);
  38232. + if (!arm_state->first_connect) {
  38233. + char threadname[10];
  38234. + arm_state->first_connect = 1;
  38235. + write_unlock_bh(&arm_state->susp_res_lock);
  38236. + snprintf(threadname, sizeof(threadname), "VCHIQka-%d",
  38237. + state->id);
  38238. + arm_state->ka_thread = kthread_create(
  38239. + &vchiq_keepalive_thread_func,
  38240. + (void *)state,
  38241. + threadname);
  38242. + if (arm_state->ka_thread == NULL) {
  38243. + vchiq_log_error(vchiq_susp_log_level,
  38244. + "vchiq: FATAL: couldn't create thread %s",
  38245. + threadname);
  38246. + } else {
  38247. + wake_up_process(arm_state->ka_thread);
  38248. + }
  38249. + } else
  38250. + write_unlock_bh(&arm_state->susp_res_lock);
  38251. + }
  38252. +}
  38253. +
  38254. +
  38255. +/****************************************************************************
  38256. +*
  38257. +* vchiq_init - called when the module is loaded.
  38258. +*
  38259. +***************************************************************************/
  38260. +
  38261. +static int __init
  38262. +vchiq_init(void)
  38263. +{
  38264. + int err;
  38265. + void *ptr_err;
  38266. +
  38267. + /* create debugfs entries */
  38268. + err = vchiq_debugfs_init();
  38269. + if (err != 0)
  38270. + goto failed_debugfs_init;
  38271. +
  38272. + err = alloc_chrdev_region(&vchiq_devid, VCHIQ_MINOR, 1, DEVICE_NAME);
  38273. + if (err != 0) {
  38274. + vchiq_log_error(vchiq_arm_log_level,
  38275. + "Unable to allocate device number");
  38276. + goto failed_alloc_chrdev;
  38277. + }
  38278. + cdev_init(&vchiq_cdev, &vchiq_fops);
  38279. + vchiq_cdev.owner = THIS_MODULE;
  38280. + err = cdev_add(&vchiq_cdev, vchiq_devid, 1);
  38281. + if (err != 0) {
  38282. + vchiq_log_error(vchiq_arm_log_level,
  38283. + "Unable to register device");
  38284. + goto failed_cdev_add;
  38285. + }
  38286. +
  38287. + /* create sysfs entries */
  38288. + vchiq_class = class_create(THIS_MODULE, DEVICE_NAME);
  38289. + ptr_err = vchiq_class;
  38290. + if (IS_ERR(ptr_err))
  38291. + goto failed_class_create;
  38292. +
  38293. + vchiq_dev = device_create(vchiq_class, NULL,
  38294. + vchiq_devid, NULL, "vchiq");
  38295. + ptr_err = vchiq_dev;
  38296. + if (IS_ERR(ptr_err))
  38297. + goto failed_device_create;
  38298. +
  38299. + err = vchiq_platform_init(&g_state);
  38300. + if (err != 0)
  38301. + goto failed_platform_init;
  38302. +
  38303. + vchiq_log_info(vchiq_arm_log_level,
  38304. + "vchiq: initialised - version %d (min %d), device %d.%d",
  38305. + VCHIQ_VERSION, VCHIQ_VERSION_MIN,
  38306. + MAJOR(vchiq_devid), MINOR(vchiq_devid));
  38307. +
  38308. + return 0;
  38309. +
  38310. +failed_platform_init:
  38311. + device_destroy(vchiq_class, vchiq_devid);
  38312. +failed_device_create:
  38313. + class_destroy(vchiq_class);
  38314. +failed_class_create:
  38315. + cdev_del(&vchiq_cdev);
  38316. + err = PTR_ERR(ptr_err);
  38317. +failed_cdev_add:
  38318. + unregister_chrdev_region(vchiq_devid, 1);
  38319. +failed_alloc_chrdev:
  38320. + vchiq_debugfs_deinit();
  38321. +failed_debugfs_init:
  38322. + vchiq_log_warning(vchiq_arm_log_level, "could not load vchiq");
  38323. + return err;
  38324. +}
  38325. +
  38326. +/****************************************************************************
  38327. +*
  38328. +* vchiq_exit - called when the module is unloaded.
  38329. +*
  38330. +***************************************************************************/
  38331. +
  38332. +static void __exit
  38333. +vchiq_exit(void)
  38334. +{
  38335. + vchiq_platform_exit(&g_state);
  38336. + device_destroy(vchiq_class, vchiq_devid);
  38337. + class_destroy(vchiq_class);
  38338. + cdev_del(&vchiq_cdev);
  38339. + unregister_chrdev_region(vchiq_devid, 1);
  38340. +}
  38341. +
  38342. +module_init(vchiq_init);
  38343. +module_exit(vchiq_exit);
  38344. +MODULE_LICENSE("GPL");
  38345. +MODULE_AUTHOR("Broadcom Corporation");
  38346. diff -Nur linux-3.18.8/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.h
  38347. --- linux-3.18.8/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.h 1970-01-01 01:00:00.000000000 +0100
  38348. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.h 2015-03-05 14:40:14.401715819 +0100
  38349. @@ -0,0 +1,223 @@
  38350. +/**
  38351. + * Copyright (c) 2014 Raspberry Pi (Trading) Ltd. All rights reserved.
  38352. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  38353. + *
  38354. + * Redistribution and use in source and binary forms, with or without
  38355. + * modification, are permitted provided that the following conditions
  38356. + * are met:
  38357. + * 1. Redistributions of source code must retain the above copyright
  38358. + * notice, this list of conditions, and the following disclaimer,
  38359. + * without modification.
  38360. + * 2. Redistributions in binary form must reproduce the above copyright
  38361. + * notice, this list of conditions and the following disclaimer in the
  38362. + * documentation and/or other materials provided with the distribution.
  38363. + * 3. The names of the above-listed copyright holders may not be used
  38364. + * to endorse or promote products derived from this software without
  38365. + * specific prior written permission.
  38366. + *
  38367. + * ALTERNATIVELY, this software may be distributed under the terms of the
  38368. + * GNU General Public License ("GPL") version 2, as published by the Free
  38369. + * Software Foundation.
  38370. + *
  38371. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  38372. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  38373. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  38374. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  38375. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  38376. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  38377. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  38378. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  38379. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  38380. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  38381. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38382. + */
  38383. +
  38384. +#ifndef VCHIQ_ARM_H
  38385. +#define VCHIQ_ARM_H
  38386. +
  38387. +#include <linux/mutex.h>
  38388. +#include <linux/semaphore.h>
  38389. +#include <linux/atomic.h>
  38390. +#include "vchiq_core.h"
  38391. +#include "vchiq_debugfs.h"
  38392. +
  38393. +
  38394. +enum vc_suspend_status {
  38395. + VC_SUSPEND_FORCE_CANCELED = -3, /* Force suspend canceled, too busy */
  38396. + VC_SUSPEND_REJECTED = -2, /* Videocore rejected suspend request */
  38397. + VC_SUSPEND_FAILED = -1, /* Videocore suspend failed */
  38398. + VC_SUSPEND_IDLE = 0, /* VC active, no suspend actions */
  38399. + VC_SUSPEND_REQUESTED, /* User has requested suspend */
  38400. + VC_SUSPEND_IN_PROGRESS, /* Slot handler has recvd suspend request */
  38401. + VC_SUSPEND_SUSPENDED /* Videocore suspend succeeded */
  38402. +};
  38403. +
  38404. +enum vc_resume_status {
  38405. + VC_RESUME_FAILED = -1, /* Videocore resume failed */
  38406. + VC_RESUME_IDLE = 0, /* VC suspended, no resume actions */
  38407. + VC_RESUME_REQUESTED, /* User has requested resume */
  38408. + VC_RESUME_IN_PROGRESS, /* Slot handler has received resume request */
  38409. + VC_RESUME_RESUMED /* Videocore resumed successfully (active) */
  38410. +};
  38411. +
  38412. +
  38413. +enum USE_TYPE_E {
  38414. + USE_TYPE_SERVICE,
  38415. + USE_TYPE_SERVICE_NO_RESUME,
  38416. + USE_TYPE_VCHIQ
  38417. +};
  38418. +
  38419. +
  38420. +
  38421. +typedef struct vchiq_arm_state_struct {
  38422. + /* Keepalive-related data */
  38423. + struct task_struct *ka_thread;
  38424. + struct completion ka_evt;
  38425. + atomic_t ka_use_count;
  38426. + atomic_t ka_use_ack_count;
  38427. + atomic_t ka_release_count;
  38428. +
  38429. + struct completion vc_suspend_complete;
  38430. + struct completion vc_resume_complete;
  38431. +
  38432. + rwlock_t susp_res_lock;
  38433. + enum vc_suspend_status vc_suspend_state;
  38434. + enum vc_resume_status vc_resume_state;
  38435. +
  38436. + unsigned int wake_address;
  38437. +
  38438. + struct timer_list suspend_timer;
  38439. + int suspend_timer_timeout;
  38440. + int suspend_timer_running;
  38441. +
  38442. + /* Global use count for videocore.
  38443. + ** This is equal to the sum of the use counts for all services. When
  38444. + ** this hits zero the videocore suspend procedure will be initiated.
  38445. + */
  38446. + int videocore_use_count;
  38447. +
  38448. + /* Use count to track requests from videocore peer.
  38449. + ** This use count is not associated with a service, so needs to be
  38450. + ** tracked separately with the state.
  38451. + */
  38452. + int peer_use_count;
  38453. +
  38454. + /* Flag to indicate whether resume is blocked. This happens when the
  38455. + ** ARM is suspending
  38456. + */
  38457. + struct completion resume_blocker;
  38458. + int resume_blocked;
  38459. + struct completion blocked_blocker;
  38460. + int blocked_count;
  38461. +
  38462. + int autosuspend_override;
  38463. +
  38464. + /* Flag to indicate that the first vchiq connect has made it through.
  38465. + ** This means that both sides should be fully ready, and we should
  38466. + ** be able to suspend after this point.
  38467. + */
  38468. + int first_connect;
  38469. +
  38470. + unsigned long long suspend_start_time;
  38471. + unsigned long long sleep_start_time;
  38472. + unsigned long long resume_start_time;
  38473. + unsigned long long last_wake_time;
  38474. +
  38475. +} VCHIQ_ARM_STATE_T;
  38476. +
  38477. +extern int vchiq_arm_log_level;
  38478. +extern int vchiq_susp_log_level;
  38479. +
  38480. +extern int __init
  38481. +vchiq_platform_init(VCHIQ_STATE_T *state);
  38482. +
  38483. +extern void __exit
  38484. +vchiq_platform_exit(VCHIQ_STATE_T *state);
  38485. +
  38486. +extern VCHIQ_STATE_T *
  38487. +vchiq_get_state(void);
  38488. +
  38489. +extern VCHIQ_STATUS_T
  38490. +vchiq_arm_vcsuspend(VCHIQ_STATE_T *state);
  38491. +
  38492. +extern VCHIQ_STATUS_T
  38493. +vchiq_arm_force_suspend(VCHIQ_STATE_T *state);
  38494. +
  38495. +extern int
  38496. +vchiq_arm_allow_resume(VCHIQ_STATE_T *state);
  38497. +
  38498. +extern VCHIQ_STATUS_T
  38499. +vchiq_arm_vcresume(VCHIQ_STATE_T *state);
  38500. +
  38501. +extern VCHIQ_STATUS_T
  38502. +vchiq_arm_init_state(VCHIQ_STATE_T *state, VCHIQ_ARM_STATE_T *arm_state);
  38503. +
  38504. +extern int
  38505. +vchiq_check_resume(VCHIQ_STATE_T *state);
  38506. +
  38507. +extern void
  38508. +vchiq_check_suspend(VCHIQ_STATE_T *state);
  38509. + VCHIQ_STATUS_T
  38510. +vchiq_use_service(VCHIQ_SERVICE_HANDLE_T handle);
  38511. +
  38512. +extern VCHIQ_STATUS_T
  38513. +vchiq_release_service(VCHIQ_SERVICE_HANDLE_T handle);
  38514. +
  38515. +extern VCHIQ_STATUS_T
  38516. +vchiq_check_service(VCHIQ_SERVICE_T *service);
  38517. +
  38518. +extern VCHIQ_STATUS_T
  38519. +vchiq_platform_suspend(VCHIQ_STATE_T *state);
  38520. +
  38521. +extern int
  38522. +vchiq_platform_videocore_wanted(VCHIQ_STATE_T *state);
  38523. +
  38524. +extern int
  38525. +vchiq_platform_use_suspend_timer(void);
  38526. +
  38527. +extern void
  38528. +vchiq_dump_platform_use_state(VCHIQ_STATE_T *state);
  38529. +
  38530. +extern void
  38531. +vchiq_dump_service_use_state(VCHIQ_STATE_T *state);
  38532. +
  38533. +extern VCHIQ_ARM_STATE_T*
  38534. +vchiq_platform_get_arm_state(VCHIQ_STATE_T *state);
  38535. +
  38536. +extern int
  38537. +vchiq_videocore_wanted(VCHIQ_STATE_T *state);
  38538. +
  38539. +extern VCHIQ_STATUS_T
  38540. +vchiq_use_internal(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service,
  38541. + enum USE_TYPE_E use_type);
  38542. +extern VCHIQ_STATUS_T
  38543. +vchiq_release_internal(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service);
  38544. +
  38545. +extern VCHIQ_DEBUGFS_NODE_T *
  38546. +vchiq_instance_get_debugfs_node(VCHIQ_INSTANCE_T instance);
  38547. +
  38548. +extern int
  38549. +vchiq_instance_get_use_count(VCHIQ_INSTANCE_T instance);
  38550. +
  38551. +extern int
  38552. +vchiq_instance_get_pid(VCHIQ_INSTANCE_T instance);
  38553. +
  38554. +extern int
  38555. +vchiq_instance_get_trace(VCHIQ_INSTANCE_T instance);
  38556. +
  38557. +extern void
  38558. +vchiq_instance_set_trace(VCHIQ_INSTANCE_T instance, int trace);
  38559. +
  38560. +extern void
  38561. +set_suspend_state(VCHIQ_ARM_STATE_T *arm_state,
  38562. + enum vc_suspend_status new_state);
  38563. +
  38564. +extern void
  38565. +set_resume_state(VCHIQ_ARM_STATE_T *arm_state,
  38566. + enum vc_resume_status new_state);
  38567. +
  38568. +extern void
  38569. +start_suspend_timer(VCHIQ_ARM_STATE_T *arm_state);
  38570. +
  38571. +
  38572. +#endif /* VCHIQ_ARM_H */
  38573. diff -Nur linux-3.18.8/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_build_info.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_build_info.h
  38574. --- linux-3.18.8/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_build_info.h 1970-01-01 01:00:00.000000000 +0100
  38575. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_build_info.h 2015-03-05 14:40:14.401715819 +0100
  38576. @@ -0,0 +1,37 @@
  38577. +/**
  38578. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  38579. + *
  38580. + * Redistribution and use in source and binary forms, with or without
  38581. + * modification, are permitted provided that the following conditions
  38582. + * are met:
  38583. + * 1. Redistributions of source code must retain the above copyright
  38584. + * notice, this list of conditions, and the following disclaimer,
  38585. + * without modification.
  38586. + * 2. Redistributions in binary form must reproduce the above copyright
  38587. + * notice, this list of conditions and the following disclaimer in the
  38588. + * documentation and/or other materials provided with the distribution.
  38589. + * 3. The names of the above-listed copyright holders may not be used
  38590. + * to endorse or promote products derived from this software without
  38591. + * specific prior written permission.
  38592. + *
  38593. + * ALTERNATIVELY, this software may be distributed under the terms of the
  38594. + * GNU General Public License ("GPL") version 2, as published by the Free
  38595. + * Software Foundation.
  38596. + *
  38597. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  38598. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  38599. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  38600. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  38601. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  38602. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  38603. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  38604. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  38605. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  38606. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  38607. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38608. + */
  38609. +
  38610. +const char *vchiq_get_build_hostname(void);
  38611. +const char *vchiq_get_build_version(void);
  38612. +const char *vchiq_get_build_time(void);
  38613. +const char *vchiq_get_build_date(void);
  38614. diff -Nur linux-3.18.8/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_cfg.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_cfg.h
  38615. --- linux-3.18.8/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_cfg.h 1970-01-01 01:00:00.000000000 +0100
  38616. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_cfg.h 2015-03-05 14:40:14.401715819 +0100
  38617. @@ -0,0 +1,69 @@
  38618. +/**
  38619. + * Copyright (c) 2010-2014 Broadcom. All rights reserved.
  38620. + *
  38621. + * Redistribution and use in source and binary forms, with or without
  38622. + * modification, are permitted provided that the following conditions
  38623. + * are met:
  38624. + * 1. Redistributions of source code must retain the above copyright
  38625. + * notice, this list of conditions, and the following disclaimer,
  38626. + * without modification.
  38627. + * 2. Redistributions in binary form must reproduce the above copyright
  38628. + * notice, this list of conditions and the following disclaimer in the
  38629. + * documentation and/or other materials provided with the distribution.
  38630. + * 3. The names of the above-listed copyright holders may not be used
  38631. + * to endorse or promote products derived from this software without
  38632. + * specific prior written permission.
  38633. + *
  38634. + * ALTERNATIVELY, this software may be distributed under the terms of the
  38635. + * GNU General Public License ("GPL") version 2, as published by the Free
  38636. + * Software Foundation.
  38637. + *
  38638. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  38639. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  38640. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  38641. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  38642. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  38643. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  38644. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  38645. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  38646. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  38647. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  38648. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38649. + */
  38650. +
  38651. +#ifndef VCHIQ_CFG_H
  38652. +#define VCHIQ_CFG_H
  38653. +
  38654. +#define VCHIQ_MAGIC VCHIQ_MAKE_FOURCC('V', 'C', 'H', 'I')
  38655. +/* The version of VCHIQ - change with any non-trivial change */
  38656. +#define VCHIQ_VERSION 8
  38657. +/* The minimum compatible version - update to match VCHIQ_VERSION with any
  38658. +** incompatible change */
  38659. +#define VCHIQ_VERSION_MIN 3
  38660. +
  38661. +/* The version that introduced the VCHIQ_IOC_LIB_VERSION ioctl */
  38662. +#define VCHIQ_VERSION_LIB_VERSION 7
  38663. +
  38664. +/* The version that introduced the VCHIQ_IOC_CLOSE_DELIVERED ioctl */
  38665. +#define VCHIQ_VERSION_CLOSE_DELIVERED 7
  38666. +
  38667. +/* The version that made it safe to use SYNCHRONOUS mode */
  38668. +#define VCHIQ_VERSION_SYNCHRONOUS_MODE 8
  38669. +
  38670. +#define VCHIQ_MAX_STATES 1
  38671. +#define VCHIQ_MAX_SERVICES 4096
  38672. +#define VCHIQ_MAX_SLOTS 128
  38673. +#define VCHIQ_MAX_SLOTS_PER_SIDE 64
  38674. +
  38675. +#define VCHIQ_NUM_CURRENT_BULKS 32
  38676. +#define VCHIQ_NUM_SERVICE_BULKS 4
  38677. +
  38678. +#ifndef VCHIQ_ENABLE_DEBUG
  38679. +#define VCHIQ_ENABLE_DEBUG 1
  38680. +#endif
  38681. +
  38682. +#ifndef VCHIQ_ENABLE_STATS
  38683. +#define VCHIQ_ENABLE_STATS 1
  38684. +#endif
  38685. +
  38686. +#endif /* VCHIQ_CFG_H */
  38687. diff -Nur linux-3.18.8/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.c linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.c
  38688. --- linux-3.18.8/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.c 1970-01-01 01:00:00.000000000 +0100
  38689. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.c 2015-03-05 14:40:14.401715819 +0100
  38690. @@ -0,0 +1,120 @@
  38691. +/**
  38692. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  38693. + *
  38694. + * Redistribution and use in source and binary forms, with or without
  38695. + * modification, are permitted provided that the following conditions
  38696. + * are met:
  38697. + * 1. Redistributions of source code must retain the above copyright
  38698. + * notice, this list of conditions, and the following disclaimer,
  38699. + * without modification.
  38700. + * 2. Redistributions in binary form must reproduce the above copyright
  38701. + * notice, this list of conditions and the following disclaimer in the
  38702. + * documentation and/or other materials provided with the distribution.
  38703. + * 3. The names of the above-listed copyright holders may not be used
  38704. + * to endorse or promote products derived from this software without
  38705. + * specific prior written permission.
  38706. + *
  38707. + * ALTERNATIVELY, this software may be distributed under the terms of the
  38708. + * GNU General Public License ("GPL") version 2, as published by the Free
  38709. + * Software Foundation.
  38710. + *
  38711. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  38712. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  38713. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  38714. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  38715. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  38716. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  38717. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  38718. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  38719. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  38720. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  38721. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38722. + */
  38723. +
  38724. +#include "vchiq_connected.h"
  38725. +#include "vchiq_core.h"
  38726. +#include "vchiq_killable.h"
  38727. +#include <linux/module.h>
  38728. +#include <linux/mutex.h>
  38729. +
  38730. +#define MAX_CALLBACKS 10
  38731. +
  38732. +static int g_connected;
  38733. +static int g_num_deferred_callbacks;
  38734. +static VCHIQ_CONNECTED_CALLBACK_T g_deferred_callback[MAX_CALLBACKS];
  38735. +static int g_once_init;
  38736. +static struct mutex g_connected_mutex;
  38737. +
  38738. +/****************************************************************************
  38739. +*
  38740. +* Function to initialize our lock.
  38741. +*
  38742. +***************************************************************************/
  38743. +
  38744. +static void connected_init(void)
  38745. +{
  38746. + if (!g_once_init) {
  38747. + mutex_init(&g_connected_mutex);
  38748. + g_once_init = 1;
  38749. + }
  38750. +}
  38751. +
  38752. +/****************************************************************************
  38753. +*
  38754. +* This function is used to defer initialization until the vchiq stack is
  38755. +* initialized. If the stack is already initialized, then the callback will
  38756. +* be made immediately, otherwise it will be deferred until
  38757. +* vchiq_call_connected_callbacks is called.
  38758. +*
  38759. +***************************************************************************/
  38760. +
  38761. +void vchiq_add_connected_callback(VCHIQ_CONNECTED_CALLBACK_T callback)
  38762. +{
  38763. + connected_init();
  38764. +
  38765. + if (mutex_lock_interruptible(&g_connected_mutex) != 0)
  38766. + return;
  38767. +
  38768. + if (g_connected)
  38769. + /* We're already connected. Call the callback immediately. */
  38770. +
  38771. + callback();
  38772. + else {
  38773. + if (g_num_deferred_callbacks >= MAX_CALLBACKS)
  38774. + vchiq_log_error(vchiq_core_log_level,
  38775. + "There already %d callback registered - "
  38776. + "please increase MAX_CALLBACKS",
  38777. + g_num_deferred_callbacks);
  38778. + else {
  38779. + g_deferred_callback[g_num_deferred_callbacks] =
  38780. + callback;
  38781. + g_num_deferred_callbacks++;
  38782. + }
  38783. + }
  38784. + mutex_unlock(&g_connected_mutex);
  38785. +}
  38786. +
  38787. +/****************************************************************************
  38788. +*
  38789. +* This function is called by the vchiq stack once it has been connected to
  38790. +* the videocore and clients can start to use the stack.
  38791. +*
  38792. +***************************************************************************/
  38793. +
  38794. +void vchiq_call_connected_callbacks(void)
  38795. +{
  38796. + int i;
  38797. +
  38798. + connected_init();
  38799. +
  38800. + if (mutex_lock_interruptible(&g_connected_mutex) != 0)
  38801. + return;
  38802. +
  38803. + for (i = 0; i < g_num_deferred_callbacks; i++)
  38804. + g_deferred_callback[i]();
  38805. +
  38806. + g_num_deferred_callbacks = 0;
  38807. + g_connected = 1;
  38808. + mutex_unlock(&g_connected_mutex);
  38809. +}
  38810. +EXPORT_SYMBOL(vchiq_add_connected_callback);
  38811. diff -Nur linux-3.18.8/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.h
  38812. --- linux-3.18.8/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.h 1970-01-01 01:00:00.000000000 +0100
  38813. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.h 2015-03-05 14:40:14.401715819 +0100
  38814. @@ -0,0 +1,50 @@
  38815. +/**
  38816. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  38817. + *
  38818. + * Redistribution and use in source and binary forms, with or without
  38819. + * modification, are permitted provided that the following conditions
  38820. + * are met:
  38821. + * 1. Redistributions of source code must retain the above copyright
  38822. + * notice, this list of conditions, and the following disclaimer,
  38823. + * without modification.
  38824. + * 2. Redistributions in binary form must reproduce the above copyright
  38825. + * notice, this list of conditions and the following disclaimer in the
  38826. + * documentation and/or other materials provided with the distribution.
  38827. + * 3. The names of the above-listed copyright holders may not be used
  38828. + * to endorse or promote products derived from this software without
  38829. + * specific prior written permission.
  38830. + *
  38831. + * ALTERNATIVELY, this software may be distributed under the terms of the
  38832. + * GNU General Public License ("GPL") version 2, as published by the Free
  38833. + * Software Foundation.
  38834. + *
  38835. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  38836. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  38837. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  38838. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  38839. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  38840. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  38841. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  38842. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  38843. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  38844. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  38845. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38846. + */
  38847. +
  38848. +#ifndef VCHIQ_CONNECTED_H
  38849. +#define VCHIQ_CONNECTED_H
  38850. +
  38851. +/* ---- Include Files ----------------------------------------------------- */
  38852. +
  38853. +/* ---- Constants and Types ---------------------------------------------- */
  38854. +
  38855. +typedef void (*VCHIQ_CONNECTED_CALLBACK_T)(void);
  38856. +
  38857. +/* ---- Variable Externs ------------------------------------------------- */
  38858. +
  38859. +/* ---- Function Prototypes ---------------------------------------------- */
  38860. +
  38861. +void vchiq_add_connected_callback(VCHIQ_CONNECTED_CALLBACK_T callback);
  38862. +void vchiq_call_connected_callbacks(void);
  38863. +
  38864. +#endif /* VCHIQ_CONNECTED_H */
  38865. diff -Nur linux-3.18.8/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.c linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.c
  38866. --- linux-3.18.8/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.c 1970-01-01 01:00:00.000000000 +0100
  38867. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.c 2015-03-05 14:40:14.401715819 +0100
  38868. @@ -0,0 +1,3934 @@
  38869. +/**
  38870. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  38871. + *
  38872. + * Redistribution and use in source and binary forms, with or without
  38873. + * modification, are permitted provided that the following conditions
  38874. + * are met:
  38875. + * 1. Redistributions of source code must retain the above copyright
  38876. + * notice, this list of conditions, and the following disclaimer,
  38877. + * without modification.
  38878. + * 2. Redistributions in binary form must reproduce the above copyright
  38879. + * notice, this list of conditions and the following disclaimer in the
  38880. + * documentation and/or other materials provided with the distribution.
  38881. + * 3. The names of the above-listed copyright holders may not be used
  38882. + * to endorse or promote products derived from this software without
  38883. + * specific prior written permission.
  38884. + *
  38885. + * ALTERNATIVELY, this software may be distributed under the terms of the
  38886. + * GNU General Public License ("GPL") version 2, as published by the Free
  38887. + * Software Foundation.
  38888. + *
  38889. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  38890. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  38891. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  38892. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  38893. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  38894. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  38895. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  38896. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  38897. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  38898. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  38899. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38900. + */
  38901. +
  38902. +#include "vchiq_core.h"
  38903. +#include "vchiq_killable.h"
  38904. +
  38905. +#define VCHIQ_SLOT_HANDLER_STACK 8192
  38906. +
  38907. +#define HANDLE_STATE_SHIFT 12
  38908. +
  38909. +#define SLOT_INFO_FROM_INDEX(state, index) (state->slot_info + (index))
  38910. +#define SLOT_DATA_FROM_INDEX(state, index) (state->slot_data + (index))
  38911. +#define SLOT_INDEX_FROM_DATA(state, data) \
  38912. + (((unsigned int)((char *)data - (char *)state->slot_data)) / \
  38913. + VCHIQ_SLOT_SIZE)
  38914. +#define SLOT_INDEX_FROM_INFO(state, info) \
  38915. + ((unsigned int)(info - state->slot_info))
  38916. +#define SLOT_QUEUE_INDEX_FROM_POS(pos) \
  38917. + ((int)((unsigned int)(pos) / VCHIQ_SLOT_SIZE))
  38918. +
  38919. +#define BULK_INDEX(x) (x & (VCHIQ_NUM_SERVICE_BULKS - 1))
  38920. +
  38921. +#define SRVTRACE_LEVEL(srv) \
  38922. + (((srv) && (srv)->trace) ? VCHIQ_LOG_TRACE : vchiq_core_msg_log_level)
  38923. +#define SRVTRACE_ENABLED(srv, lev) \
  38924. + (((srv) && (srv)->trace) || (vchiq_core_msg_log_level >= (lev)))
  38925. +
  38926. +struct vchiq_open_payload {
  38927. + int fourcc;
  38928. + int client_id;
  38929. + short version;
  38930. + short version_min;
  38931. +};
  38932. +
  38933. +struct vchiq_openack_payload {
  38934. + short version;
  38935. +};
  38936. +
  38937. +enum
  38938. +{
  38939. + QMFLAGS_IS_BLOCKING = (1 << 0),
  38940. + QMFLAGS_NO_MUTEX_LOCK = (1 << 1),
  38941. + QMFLAGS_NO_MUTEX_UNLOCK = (1 << 2)
  38942. +};
  38943. +
  38944. +/* we require this for consistency between endpoints */
  38945. +vchiq_static_assert(sizeof(VCHIQ_HEADER_T) == 8);
  38946. +vchiq_static_assert(IS_POW2(sizeof(VCHIQ_HEADER_T)));
  38947. +vchiq_static_assert(IS_POW2(VCHIQ_NUM_CURRENT_BULKS));
  38948. +vchiq_static_assert(IS_POW2(VCHIQ_NUM_SERVICE_BULKS));
  38949. +vchiq_static_assert(IS_POW2(VCHIQ_MAX_SERVICES));
  38950. +vchiq_static_assert(VCHIQ_VERSION >= VCHIQ_VERSION_MIN);
  38951. +
  38952. +/* Run time control of log level, based on KERN_XXX level. */
  38953. +int vchiq_core_log_level = VCHIQ_LOG_DEFAULT;
  38954. +int vchiq_core_msg_log_level = VCHIQ_LOG_DEFAULT;
  38955. +int vchiq_sync_log_level = VCHIQ_LOG_DEFAULT;
  38956. +
  38957. +static atomic_t pause_bulks_count = ATOMIC_INIT(0);
  38958. +
  38959. +static DEFINE_SPINLOCK(service_spinlock);
  38960. +DEFINE_SPINLOCK(bulk_waiter_spinlock);
  38961. +DEFINE_SPINLOCK(quota_spinlock);
  38962. +
  38963. +VCHIQ_STATE_T *vchiq_states[VCHIQ_MAX_STATES];
  38964. +static unsigned int handle_seq;
  38965. +
  38966. +static const char *const srvstate_names[] = {
  38967. + "FREE",
  38968. + "HIDDEN",
  38969. + "LISTENING",
  38970. + "OPENING",
  38971. + "OPEN",
  38972. + "OPENSYNC",
  38973. + "CLOSESENT",
  38974. + "CLOSERECVD",
  38975. + "CLOSEWAIT",
  38976. + "CLOSED"
  38977. +};
  38978. +
  38979. +static const char *const reason_names[] = {
  38980. + "SERVICE_OPENED",
  38981. + "SERVICE_CLOSED",
  38982. + "MESSAGE_AVAILABLE",
  38983. + "BULK_TRANSMIT_DONE",
  38984. + "BULK_RECEIVE_DONE",
  38985. + "BULK_TRANSMIT_ABORTED",
  38986. + "BULK_RECEIVE_ABORTED"
  38987. +};
  38988. +
  38989. +static const char *const conn_state_names[] = {
  38990. + "DISCONNECTED",
  38991. + "CONNECTING",
  38992. + "CONNECTED",
  38993. + "PAUSING",
  38994. + "PAUSE_SENT",
  38995. + "PAUSED",
  38996. + "RESUMING",
  38997. + "PAUSE_TIMEOUT",
  38998. + "RESUME_TIMEOUT"
  38999. +};
  39000. +
  39001. +
  39002. +static void
  39003. +release_message_sync(VCHIQ_STATE_T *state, VCHIQ_HEADER_T *header);
  39004. +
  39005. +static const char *msg_type_str(unsigned int msg_type)
  39006. +{
  39007. + switch (msg_type) {
  39008. + case VCHIQ_MSG_PADDING: return "PADDING";
  39009. + case VCHIQ_MSG_CONNECT: return "CONNECT";
  39010. + case VCHIQ_MSG_OPEN: return "OPEN";
  39011. + case VCHIQ_MSG_OPENACK: return "OPENACK";
  39012. + case VCHIQ_MSG_CLOSE: return "CLOSE";
  39013. + case VCHIQ_MSG_DATA: return "DATA";
  39014. + case VCHIQ_MSG_BULK_RX: return "BULK_RX";
  39015. + case VCHIQ_MSG_BULK_TX: return "BULK_TX";
  39016. + case VCHIQ_MSG_BULK_RX_DONE: return "BULK_RX_DONE";
  39017. + case VCHIQ_MSG_BULK_TX_DONE: return "BULK_TX_DONE";
  39018. + case VCHIQ_MSG_PAUSE: return "PAUSE";
  39019. + case VCHIQ_MSG_RESUME: return "RESUME";
  39020. + case VCHIQ_MSG_REMOTE_USE: return "REMOTE_USE";
  39021. + case VCHIQ_MSG_REMOTE_RELEASE: return "REMOTE_RELEASE";
  39022. + case VCHIQ_MSG_REMOTE_USE_ACTIVE: return "REMOTE_USE_ACTIVE";
  39023. + }
  39024. + return "???";
  39025. +}
  39026. +
  39027. +static inline void
  39028. +vchiq_set_service_state(VCHIQ_SERVICE_T *service, int newstate)
  39029. +{
  39030. + vchiq_log_info(vchiq_core_log_level, "%d: srv:%d %s->%s",
  39031. + service->state->id, service->localport,
  39032. + srvstate_names[service->srvstate],
  39033. + srvstate_names[newstate]);
  39034. + service->srvstate = newstate;
  39035. +}
  39036. +
  39037. +VCHIQ_SERVICE_T *
  39038. +find_service_by_handle(VCHIQ_SERVICE_HANDLE_T handle)
  39039. +{
  39040. + VCHIQ_SERVICE_T *service;
  39041. +
  39042. + spin_lock(&service_spinlock);
  39043. + service = handle_to_service(handle);
  39044. + if (service && (service->srvstate != VCHIQ_SRVSTATE_FREE) &&
  39045. + (service->handle == handle)) {
  39046. + BUG_ON(service->ref_count == 0);
  39047. + service->ref_count++;
  39048. + } else
  39049. + service = NULL;
  39050. + spin_unlock(&service_spinlock);
  39051. +
  39052. + if (!service)
  39053. + vchiq_log_info(vchiq_core_log_level,
  39054. + "Invalid service handle 0x%x", handle);
  39055. +
  39056. + return service;
  39057. +}
  39058. +
  39059. +VCHIQ_SERVICE_T *
  39060. +find_service_by_port(VCHIQ_STATE_T *state, int localport)
  39061. +{
  39062. + VCHIQ_SERVICE_T *service = NULL;
  39063. + if ((unsigned int)localport <= VCHIQ_PORT_MAX) {
  39064. + spin_lock(&service_spinlock);
  39065. + service = state->services[localport];
  39066. + if (service && (service->srvstate != VCHIQ_SRVSTATE_FREE)) {
  39067. + BUG_ON(service->ref_count == 0);
  39068. + service->ref_count++;
  39069. + } else
  39070. + service = NULL;
  39071. + spin_unlock(&service_spinlock);
  39072. + }
  39073. +
  39074. + if (!service)
  39075. + vchiq_log_info(vchiq_core_log_level,
  39076. + "Invalid port %d", localport);
  39077. +
  39078. + return service;
  39079. +}
  39080. +
  39081. +VCHIQ_SERVICE_T *
  39082. +find_service_for_instance(VCHIQ_INSTANCE_T instance,
  39083. + VCHIQ_SERVICE_HANDLE_T handle) {
  39084. + VCHIQ_SERVICE_T *service;
  39085. +
  39086. + spin_lock(&service_spinlock);
  39087. + service = handle_to_service(handle);
  39088. + if (service && (service->srvstate != VCHIQ_SRVSTATE_FREE) &&
  39089. + (service->handle == handle) &&
  39090. + (service->instance == instance)) {
  39091. + BUG_ON(service->ref_count == 0);
  39092. + service->ref_count++;
  39093. + } else
  39094. + service = NULL;
  39095. + spin_unlock(&service_spinlock);
  39096. +
  39097. + if (!service)
  39098. + vchiq_log_info(vchiq_core_log_level,
  39099. + "Invalid service handle 0x%x", handle);
  39100. +
  39101. + return service;
  39102. +}
  39103. +
  39104. +VCHIQ_SERVICE_T *
  39105. +find_closed_service_for_instance(VCHIQ_INSTANCE_T instance,
  39106. + VCHIQ_SERVICE_HANDLE_T handle) {
  39107. + VCHIQ_SERVICE_T *service;
  39108. +
  39109. + spin_lock(&service_spinlock);
  39110. + service = handle_to_service(handle);
  39111. + if (service &&
  39112. + ((service->srvstate == VCHIQ_SRVSTATE_FREE) ||
  39113. + (service->srvstate == VCHIQ_SRVSTATE_CLOSED)) &&
  39114. + (service->handle == handle) &&
  39115. + (service->instance == instance)) {
  39116. + BUG_ON(service->ref_count == 0);
  39117. + service->ref_count++;
  39118. + } else
  39119. + service = NULL;
  39120. + spin_unlock(&service_spinlock);
  39121. +
  39122. + if (!service)
  39123. + vchiq_log_info(vchiq_core_log_level,
  39124. + "Invalid service handle 0x%x", handle);
  39125. +
  39126. + return service;
  39127. +}
  39128. +
  39129. +VCHIQ_SERVICE_T *
  39130. +next_service_by_instance(VCHIQ_STATE_T *state, VCHIQ_INSTANCE_T instance,
  39131. + int *pidx)
  39132. +{
  39133. + VCHIQ_SERVICE_T *service = NULL;
  39134. + int idx = *pidx;
  39135. +
  39136. + spin_lock(&service_spinlock);
  39137. + while (idx < state->unused_service) {
  39138. + VCHIQ_SERVICE_T *srv = state->services[idx++];
  39139. + if (srv && (srv->srvstate != VCHIQ_SRVSTATE_FREE) &&
  39140. + (srv->instance == instance)) {
  39141. + service = srv;
  39142. + BUG_ON(service->ref_count == 0);
  39143. + service->ref_count++;
  39144. + break;
  39145. + }
  39146. + }
  39147. + spin_unlock(&service_spinlock);
  39148. +
  39149. + *pidx = idx;
  39150. +
  39151. + return service;
  39152. +}
  39153. +
  39154. +void
  39155. +lock_service(VCHIQ_SERVICE_T *service)
  39156. +{
  39157. + spin_lock(&service_spinlock);
  39158. + BUG_ON(!service || (service->ref_count == 0));
  39159. + if (service)
  39160. + service->ref_count++;
  39161. + spin_unlock(&service_spinlock);
  39162. +}
  39163. +
  39164. +void
  39165. +unlock_service(VCHIQ_SERVICE_T *service)
  39166. +{
  39167. + VCHIQ_STATE_T *state = service->state;
  39168. + spin_lock(&service_spinlock);
  39169. + BUG_ON(!service || (service->ref_count == 0));
  39170. + if (service && service->ref_count) {
  39171. + service->ref_count--;
  39172. + if (!service->ref_count) {
  39173. + BUG_ON(service->srvstate != VCHIQ_SRVSTATE_FREE);
  39174. + state->services[service->localport] = NULL;
  39175. + } else
  39176. + service = NULL;
  39177. + }
  39178. + spin_unlock(&service_spinlock);
  39179. +
  39180. + if (service && service->userdata_term)
  39181. + service->userdata_term(service->base.userdata);
  39182. +
  39183. + kfree(service);
  39184. +}
  39185. +
  39186. +int
  39187. +vchiq_get_client_id(VCHIQ_SERVICE_HANDLE_T handle)
  39188. +{
  39189. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  39190. + int id;
  39191. +
  39192. + id = service ? service->client_id : 0;
  39193. + if (service)
  39194. + unlock_service(service);
  39195. +
  39196. + return id;
  39197. +}
  39198. +
  39199. +void *
  39200. +vchiq_get_service_userdata(VCHIQ_SERVICE_HANDLE_T handle)
  39201. +{
  39202. + VCHIQ_SERVICE_T *service = handle_to_service(handle);
  39203. +
  39204. + return service ? service->base.userdata : NULL;
  39205. +}
  39206. +
  39207. +int
  39208. +vchiq_get_service_fourcc(VCHIQ_SERVICE_HANDLE_T handle)
  39209. +{
  39210. + VCHIQ_SERVICE_T *service = handle_to_service(handle);
  39211. +
  39212. + return service ? service->base.fourcc : 0;
  39213. +}
  39214. +
  39215. +static void
  39216. +mark_service_closing_internal(VCHIQ_SERVICE_T *service, int sh_thread)
  39217. +{
  39218. + VCHIQ_STATE_T *state = service->state;
  39219. + VCHIQ_SERVICE_QUOTA_T *service_quota;
  39220. +
  39221. + service->closing = 1;
  39222. +
  39223. + /* Synchronise with other threads. */
  39224. + mutex_lock(&state->recycle_mutex);
  39225. + mutex_unlock(&state->recycle_mutex);
  39226. + if (!sh_thread || (state->conn_state != VCHIQ_CONNSTATE_PAUSE_SENT)) {
  39227. + /* If we're pausing then the slot_mutex is held until resume
  39228. + * by the slot handler. Therefore don't try to acquire this
  39229. + * mutex if we're the slot handler and in the pause sent state.
  39230. + * We don't need to in this case anyway. */
  39231. + mutex_lock(&state->slot_mutex);
  39232. + mutex_unlock(&state->slot_mutex);
  39233. + }
  39234. +
  39235. + /* Unblock any sending thread. */
  39236. + service_quota = &state->service_quotas[service->localport];
  39237. + up(&service_quota->quota_event);
  39238. +}
  39239. +
  39240. +static void
  39241. +mark_service_closing(VCHIQ_SERVICE_T *service)
  39242. +{
  39243. + mark_service_closing_internal(service, 0);
  39244. +}
  39245. +
  39246. +static inline VCHIQ_STATUS_T
  39247. +make_service_callback(VCHIQ_SERVICE_T *service, VCHIQ_REASON_T reason,
  39248. + VCHIQ_HEADER_T *header, void *bulk_userdata)
  39249. +{
  39250. + VCHIQ_STATUS_T status;
  39251. + vchiq_log_trace(vchiq_core_log_level, "%d: callback:%d (%s, %x, %x)",
  39252. + service->state->id, service->localport, reason_names[reason],
  39253. + (unsigned int)header, (unsigned int)bulk_userdata);
  39254. + status = service->base.callback(reason, header, service->handle,
  39255. + bulk_userdata);
  39256. + if (status == VCHIQ_ERROR) {
  39257. + vchiq_log_warning(vchiq_core_log_level,
  39258. + "%d: ignoring ERROR from callback to service %x",
  39259. + service->state->id, service->handle);
  39260. + status = VCHIQ_SUCCESS;
  39261. + }
  39262. + return status;
  39263. +}
  39264. +
  39265. +inline void
  39266. +vchiq_set_conn_state(VCHIQ_STATE_T *state, VCHIQ_CONNSTATE_T newstate)
  39267. +{
  39268. + VCHIQ_CONNSTATE_T oldstate = state->conn_state;
  39269. + vchiq_log_info(vchiq_core_log_level, "%d: %s->%s", state->id,
  39270. + conn_state_names[oldstate],
  39271. + conn_state_names[newstate]);
  39272. + state->conn_state = newstate;
  39273. + vchiq_platform_conn_state_changed(state, oldstate, newstate);
  39274. +}
  39275. +
  39276. +static inline void
  39277. +remote_event_create(REMOTE_EVENT_T *event)
  39278. +{
  39279. + event->armed = 0;
  39280. + /* Don't clear the 'fired' flag because it may already have been set
  39281. + ** by the other side. */
  39282. + sema_init(event->event, 0);
  39283. +}
  39284. +
  39285. +static inline void
  39286. +remote_event_destroy(REMOTE_EVENT_T *event)
  39287. +{
  39288. + (void)event;
  39289. +}
  39290. +
  39291. +static inline int
  39292. +remote_event_wait(REMOTE_EVENT_T *event)
  39293. +{
  39294. + if (!event->fired) {
  39295. + event->armed = 1;
  39296. + dsb();
  39297. + if (!event->fired) {
  39298. + if (down_interruptible(event->event) != 0) {
  39299. + event->armed = 0;
  39300. + return 0;
  39301. + }
  39302. + }
  39303. + event->armed = 0;
  39304. + wmb();
  39305. + }
  39306. +
  39307. + event->fired = 0;
  39308. + return 1;
  39309. +}
  39310. +
  39311. +static inline void
  39312. +remote_event_signal_local(REMOTE_EVENT_T *event)
  39313. +{
  39314. + event->armed = 0;
  39315. + up(event->event);
  39316. +}
  39317. +
  39318. +static inline void
  39319. +remote_event_poll(REMOTE_EVENT_T *event)
  39320. +{
  39321. + if (event->fired && event->armed)
  39322. + remote_event_signal_local(event);
  39323. +}
  39324. +
  39325. +void
  39326. +remote_event_pollall(VCHIQ_STATE_T *state)
  39327. +{
  39328. + remote_event_poll(&state->local->sync_trigger);
  39329. + remote_event_poll(&state->local->sync_release);
  39330. + remote_event_poll(&state->local->trigger);
  39331. + remote_event_poll(&state->local->recycle);
  39332. +}
  39333. +
  39334. +/* Round up message sizes so that any space at the end of a slot is always big
  39335. +** enough for a header. This relies on header size being a power of two, which
  39336. +** has been verified earlier by a static assertion. */
  39337. +
  39338. +static inline unsigned int
  39339. +calc_stride(unsigned int size)
  39340. +{
  39341. + /* Allow room for the header */
  39342. + size += sizeof(VCHIQ_HEADER_T);
  39343. +
  39344. + /* Round up */
  39345. + return (size + sizeof(VCHIQ_HEADER_T) - 1) & ~(sizeof(VCHIQ_HEADER_T)
  39346. + - 1);
  39347. +}
  39348. +
  39349. +/* Called by the slot handler thread */
  39350. +static VCHIQ_SERVICE_T *
  39351. +get_listening_service(VCHIQ_STATE_T *state, int fourcc)
  39352. +{
  39353. + int i;
  39354. +
  39355. + WARN_ON(fourcc == VCHIQ_FOURCC_INVALID);
  39356. +
  39357. + for (i = 0; i < state->unused_service; i++) {
  39358. + VCHIQ_SERVICE_T *service = state->services[i];
  39359. + if (service &&
  39360. + (service->public_fourcc == fourcc) &&
  39361. + ((service->srvstate == VCHIQ_SRVSTATE_LISTENING) ||
  39362. + ((service->srvstate == VCHIQ_SRVSTATE_OPEN) &&
  39363. + (service->remoteport == VCHIQ_PORT_FREE)))) {
  39364. + lock_service(service);
  39365. + return service;
  39366. + }
  39367. + }
  39368. +
  39369. + return NULL;
  39370. +}
  39371. +
  39372. +/* Called by the slot handler thread */
  39373. +static VCHIQ_SERVICE_T *
  39374. +get_connected_service(VCHIQ_STATE_T *state, unsigned int port)
  39375. +{
  39376. + int i;
  39377. + for (i = 0; i < state->unused_service; i++) {
  39378. + VCHIQ_SERVICE_T *service = state->services[i];
  39379. + if (service && (service->srvstate == VCHIQ_SRVSTATE_OPEN)
  39380. + && (service->remoteport == port)) {
  39381. + lock_service(service);
  39382. + return service;
  39383. + }
  39384. + }
  39385. + return NULL;
  39386. +}
  39387. +
  39388. +inline void
  39389. +request_poll(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service, int poll_type)
  39390. +{
  39391. + uint32_t value;
  39392. +
  39393. + if (service) {
  39394. + do {
  39395. + value = atomic_read(&service->poll_flags);
  39396. + } while (atomic_cmpxchg(&service->poll_flags, value,
  39397. + value | (1 << poll_type)) != value);
  39398. +
  39399. + do {
  39400. + value = atomic_read(&state->poll_services[
  39401. + service->localport>>5]);
  39402. + } while (atomic_cmpxchg(
  39403. + &state->poll_services[service->localport>>5],
  39404. + value, value | (1 << (service->localport & 0x1f)))
  39405. + != value);
  39406. + }
  39407. +
  39408. + state->poll_needed = 1;
  39409. + wmb();
  39410. +
  39411. + /* ... and ensure the slot handler runs. */
  39412. + remote_event_signal_local(&state->local->trigger);
  39413. +}
  39414. +
  39415. +/* Called from queue_message, by the slot handler and application threads,
  39416. +** with slot_mutex held */
  39417. +static VCHIQ_HEADER_T *
  39418. +reserve_space(VCHIQ_STATE_T *state, int space, int is_blocking)
  39419. +{
  39420. + VCHIQ_SHARED_STATE_T *local = state->local;
  39421. + int tx_pos = state->local_tx_pos;
  39422. + int slot_space = VCHIQ_SLOT_SIZE - (tx_pos & VCHIQ_SLOT_MASK);
  39423. +
  39424. + if (space > slot_space) {
  39425. + VCHIQ_HEADER_T *header;
  39426. + /* Fill the remaining space with padding */
  39427. + WARN_ON(state->tx_data == NULL);
  39428. + header = (VCHIQ_HEADER_T *)
  39429. + (state->tx_data + (tx_pos & VCHIQ_SLOT_MASK));
  39430. + header->msgid = VCHIQ_MSGID_PADDING;
  39431. + header->size = slot_space - sizeof(VCHIQ_HEADER_T);
  39432. +
  39433. + tx_pos += slot_space;
  39434. + }
  39435. +
  39436. + /* If necessary, get the next slot. */
  39437. + if ((tx_pos & VCHIQ_SLOT_MASK) == 0) {
  39438. + int slot_index;
  39439. +
  39440. + /* If there is no free slot... */
  39441. +
  39442. + if (down_trylock(&state->slot_available_event) != 0) {
  39443. + /* ...wait for one. */
  39444. +
  39445. + VCHIQ_STATS_INC(state, slot_stalls);
  39446. +
  39447. + /* But first, flush through the last slot. */
  39448. + state->local_tx_pos = tx_pos;
  39449. + local->tx_pos = tx_pos;
  39450. + remote_event_signal(&state->remote->trigger);
  39451. +
  39452. + if (!is_blocking ||
  39453. + (down_interruptible(
  39454. + &state->slot_available_event) != 0))
  39455. + return NULL; /* No space available */
  39456. + }
  39457. +
  39458. + BUG_ON(tx_pos ==
  39459. + (state->slot_queue_available * VCHIQ_SLOT_SIZE));
  39460. +
  39461. + slot_index = local->slot_queue[
  39462. + SLOT_QUEUE_INDEX_FROM_POS(tx_pos) &
  39463. + VCHIQ_SLOT_QUEUE_MASK];
  39464. + state->tx_data =
  39465. + (char *)SLOT_DATA_FROM_INDEX(state, slot_index);
  39466. + }
  39467. +
  39468. + state->local_tx_pos = tx_pos + space;
  39469. +
  39470. + return (VCHIQ_HEADER_T *)(state->tx_data + (tx_pos & VCHIQ_SLOT_MASK));
  39471. +}
  39472. +
  39473. +/* Called by the recycle thread. */
  39474. +static void
  39475. +process_free_queue(VCHIQ_STATE_T *state)
  39476. +{
  39477. + VCHIQ_SHARED_STATE_T *local = state->local;
  39478. + BITSET_T service_found[BITSET_SIZE(VCHIQ_MAX_SERVICES)];
  39479. + int slot_queue_available;
  39480. +
  39481. + /* Use a read memory barrier to ensure that any state that may have
  39482. + ** been modified by another thread is not masked by stale prefetched
  39483. + ** values. */
  39484. + rmb();
  39485. +
  39486. + /* Find slots which have been freed by the other side, and return them
  39487. + ** to the available queue. */
  39488. + slot_queue_available = state->slot_queue_available;
  39489. +
  39490. + while (slot_queue_available != local->slot_queue_recycle) {
  39491. + unsigned int pos;
  39492. + int slot_index = local->slot_queue[slot_queue_available++ &
  39493. + VCHIQ_SLOT_QUEUE_MASK];
  39494. + char *data = (char *)SLOT_DATA_FROM_INDEX(state, slot_index);
  39495. + int data_found = 0;
  39496. +
  39497. + vchiq_log_trace(vchiq_core_log_level, "%d: pfq %d=%x %x %x",
  39498. + state->id, slot_index, (unsigned int)data,
  39499. + local->slot_queue_recycle, slot_queue_available);
  39500. +
  39501. + /* Initialise the bitmask for services which have used this
  39502. + ** slot */
  39503. + BITSET_ZERO(service_found);
  39504. +
  39505. + pos = 0;
  39506. +
  39507. + while (pos < VCHIQ_SLOT_SIZE) {
  39508. + VCHIQ_HEADER_T *header =
  39509. + (VCHIQ_HEADER_T *)(data + pos);
  39510. + int msgid = header->msgid;
  39511. + if (VCHIQ_MSG_TYPE(msgid) == VCHIQ_MSG_DATA) {
  39512. + int port = VCHIQ_MSG_SRCPORT(msgid);
  39513. + VCHIQ_SERVICE_QUOTA_T *service_quota =
  39514. + &state->service_quotas[port];
  39515. + int count;
  39516. + spin_lock(&quota_spinlock);
  39517. + count = service_quota->message_use_count;
  39518. + if (count > 0)
  39519. + service_quota->message_use_count =
  39520. + count - 1;
  39521. + spin_unlock(&quota_spinlock);
  39522. +
  39523. + if (count == service_quota->message_quota)
  39524. + /* Signal the service that it
  39525. + ** has dropped below its quota
  39526. + */
  39527. + up(&service_quota->quota_event);
  39528. + else if (count == 0) {
  39529. + vchiq_log_error(vchiq_core_log_level,
  39530. + "service %d "
  39531. + "message_use_count=%d "
  39532. + "(header %x, msgid %x, "
  39533. + "header->msgid %x, "
  39534. + "header->size %x)",
  39535. + port,
  39536. + service_quota->
  39537. + message_use_count,
  39538. + (unsigned int)header, msgid,
  39539. + header->msgid,
  39540. + header->size);
  39541. + WARN(1, "invalid message use count\n");
  39542. + }
  39543. + if (!BITSET_IS_SET(service_found, port)) {
  39544. + /* Set the found bit for this service */
  39545. + BITSET_SET(service_found, port);
  39546. +
  39547. + spin_lock(&quota_spinlock);
  39548. + count = service_quota->slot_use_count;
  39549. + if (count > 0)
  39550. + service_quota->slot_use_count =
  39551. + count - 1;
  39552. + spin_unlock(&quota_spinlock);
  39553. +
  39554. + if (count > 0) {
  39555. + /* Signal the service in case
  39556. + ** it has dropped below its
  39557. + ** quota */
  39558. + up(&service_quota->quota_event);
  39559. + vchiq_log_trace(
  39560. + vchiq_core_log_level,
  39561. + "%d: pfq:%d %x@%x - "
  39562. + "slot_use->%d",
  39563. + state->id, port,
  39564. + header->size,
  39565. + (unsigned int)header,
  39566. + count - 1);
  39567. + } else {
  39568. + vchiq_log_error(
  39569. + vchiq_core_log_level,
  39570. + "service %d "
  39571. + "slot_use_count"
  39572. + "=%d (header %x"
  39573. + ", msgid %x, "
  39574. + "header->msgid"
  39575. + " %x, header->"
  39576. + "size %x)",
  39577. + port, count,
  39578. + (unsigned int)header,
  39579. + msgid,
  39580. + header->msgid,
  39581. + header->size);
  39582. + WARN(1, "bad slot use count\n");
  39583. + }
  39584. + }
  39585. +
  39586. + data_found = 1;
  39587. + }
  39588. +
  39589. + pos += calc_stride(header->size);
  39590. + if (pos > VCHIQ_SLOT_SIZE) {
  39591. + vchiq_log_error(vchiq_core_log_level,
  39592. + "pfq - pos %x: header %x, msgid %x, "
  39593. + "header->msgid %x, header->size %x",
  39594. + pos, (unsigned int)header, msgid,
  39595. + header->msgid, header->size);
  39596. + WARN(1, "invalid slot position\n");
  39597. + }
  39598. + }
  39599. +
  39600. + if (data_found) {
  39601. + int count;
  39602. + spin_lock(&quota_spinlock);
  39603. + count = state->data_use_count;
  39604. + if (count > 0)
  39605. + state->data_use_count =
  39606. + count - 1;
  39607. + spin_unlock(&quota_spinlock);
  39608. + if (count == state->data_quota)
  39609. + up(&state->data_quota_event);
  39610. + }
  39611. +
  39612. + state->slot_queue_available = slot_queue_available;
  39613. + up(&state->slot_available_event);
  39614. + }
  39615. +}
  39616. +
  39617. +/* Called by the slot handler and application threads */
  39618. +static VCHIQ_STATUS_T
  39619. +queue_message(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service,
  39620. + int msgid, const VCHIQ_ELEMENT_T *elements,
  39621. + int count, int size, int flags)
  39622. +{
  39623. + VCHIQ_SHARED_STATE_T *local;
  39624. + VCHIQ_SERVICE_QUOTA_T *service_quota = NULL;
  39625. + VCHIQ_HEADER_T *header;
  39626. + int type = VCHIQ_MSG_TYPE(msgid);
  39627. +
  39628. + unsigned int stride;
  39629. +
  39630. + local = state->local;
  39631. +
  39632. + stride = calc_stride(size);
  39633. +
  39634. + WARN_ON(!(stride <= VCHIQ_SLOT_SIZE));
  39635. +
  39636. + if (!(flags & QMFLAGS_NO_MUTEX_LOCK) &&
  39637. + (mutex_lock_interruptible(&state->slot_mutex) != 0))
  39638. + return VCHIQ_RETRY;
  39639. +
  39640. + if (type == VCHIQ_MSG_DATA) {
  39641. + int tx_end_index;
  39642. +
  39643. + BUG_ON(!service);
  39644. + BUG_ON((flags & (QMFLAGS_NO_MUTEX_LOCK |
  39645. + QMFLAGS_NO_MUTEX_UNLOCK)) != 0);
  39646. +
  39647. + if (service->closing) {
  39648. + /* The service has been closed */
  39649. + mutex_unlock(&state->slot_mutex);
  39650. + return VCHIQ_ERROR;
  39651. + }
  39652. +
  39653. + service_quota = &state->service_quotas[service->localport];
  39654. +
  39655. + spin_lock(&quota_spinlock);
  39656. +
  39657. + /* Ensure this service doesn't use more than its quota of
  39658. + ** messages or slots */
  39659. + tx_end_index = SLOT_QUEUE_INDEX_FROM_POS(
  39660. + state->local_tx_pos + stride - 1);
  39661. +
  39662. + /* Ensure data messages don't use more than their quota of
  39663. + ** slots */
  39664. + while ((tx_end_index != state->previous_data_index) &&
  39665. + (state->data_use_count == state->data_quota)) {
  39666. + VCHIQ_STATS_INC(state, data_stalls);
  39667. + spin_unlock(&quota_spinlock);
  39668. + mutex_unlock(&state->slot_mutex);
  39669. +
  39670. + if (down_interruptible(&state->data_quota_event)
  39671. + != 0)
  39672. + return VCHIQ_RETRY;
  39673. +
  39674. + mutex_lock(&state->slot_mutex);
  39675. + spin_lock(&quota_spinlock);
  39676. + tx_end_index = SLOT_QUEUE_INDEX_FROM_POS(
  39677. + state->local_tx_pos + stride - 1);
  39678. + if ((tx_end_index == state->previous_data_index) ||
  39679. + (state->data_use_count < state->data_quota)) {
  39680. + /* Pass the signal on to other waiters */
  39681. + up(&state->data_quota_event);
  39682. + break;
  39683. + }
  39684. + }
  39685. +
  39686. + while ((service_quota->message_use_count ==
  39687. + service_quota->message_quota) ||
  39688. + ((tx_end_index != service_quota->previous_tx_index) &&
  39689. + (service_quota->slot_use_count ==
  39690. + service_quota->slot_quota))) {
  39691. + spin_unlock(&quota_spinlock);
  39692. + vchiq_log_trace(vchiq_core_log_level,
  39693. + "%d: qm:%d %s,%x - quota stall "
  39694. + "(msg %d, slot %d)",
  39695. + state->id, service->localport,
  39696. + msg_type_str(type), size,
  39697. + service_quota->message_use_count,
  39698. + service_quota->slot_use_count);
  39699. + VCHIQ_SERVICE_STATS_INC(service, quota_stalls);
  39700. + mutex_unlock(&state->slot_mutex);
  39701. + if (down_interruptible(&service_quota->quota_event)
  39702. + != 0)
  39703. + return VCHIQ_RETRY;
  39704. + if (service->closing)
  39705. + return VCHIQ_ERROR;
  39706. + if (mutex_lock_interruptible(&state->slot_mutex) != 0)
  39707. + return VCHIQ_RETRY;
  39708. + if (service->srvstate != VCHIQ_SRVSTATE_OPEN) {
  39709. + /* The service has been closed */
  39710. + mutex_unlock(&state->slot_mutex);
  39711. + return VCHIQ_ERROR;
  39712. + }
  39713. + spin_lock(&quota_spinlock);
  39714. + tx_end_index = SLOT_QUEUE_INDEX_FROM_POS(
  39715. + state->local_tx_pos + stride - 1);
  39716. + }
  39717. +
  39718. + spin_unlock(&quota_spinlock);
  39719. + }
  39720. +
  39721. + header = reserve_space(state, stride, flags & QMFLAGS_IS_BLOCKING);
  39722. +
  39723. + if (!header) {
  39724. + if (service)
  39725. + VCHIQ_SERVICE_STATS_INC(service, slot_stalls);
  39726. + /* In the event of a failure, return the mutex to the
  39727. + state it was in */
  39728. + if (!(flags & QMFLAGS_NO_MUTEX_LOCK))
  39729. + mutex_unlock(&state->slot_mutex);
  39730. + return VCHIQ_RETRY;
  39731. + }
  39732. +
  39733. + if (type == VCHIQ_MSG_DATA) {
  39734. + int i, pos;
  39735. + int tx_end_index;
  39736. + int slot_use_count;
  39737. +
  39738. + vchiq_log_info(vchiq_core_log_level,
  39739. + "%d: qm %s@%x,%x (%d->%d)",
  39740. + state->id,
  39741. + msg_type_str(VCHIQ_MSG_TYPE(msgid)),
  39742. + (unsigned int)header, size,
  39743. + VCHIQ_MSG_SRCPORT(msgid),
  39744. + VCHIQ_MSG_DSTPORT(msgid));
  39745. +
  39746. + BUG_ON(!service);
  39747. + BUG_ON((flags & (QMFLAGS_NO_MUTEX_LOCK |
  39748. + QMFLAGS_NO_MUTEX_UNLOCK)) != 0);
  39749. +
  39750. + for (i = 0, pos = 0; i < (unsigned int)count;
  39751. + pos += elements[i++].size)
  39752. + if (elements[i].size) {
  39753. + if (vchiq_copy_from_user
  39754. + (header->data + pos, elements[i].data,
  39755. + (size_t) elements[i].size) !=
  39756. + VCHIQ_SUCCESS) {
  39757. + mutex_unlock(&state->slot_mutex);
  39758. + VCHIQ_SERVICE_STATS_INC(service,
  39759. + error_count);
  39760. + return VCHIQ_ERROR;
  39761. + }
  39762. + if (i == 0) {
  39763. + if (SRVTRACE_ENABLED(service,
  39764. + VCHIQ_LOG_INFO))
  39765. + vchiq_log_dump_mem("Sent", 0,
  39766. + header->data + pos,
  39767. + min(64u,
  39768. + elements[0].size));
  39769. + }
  39770. + }
  39771. +
  39772. + spin_lock(&quota_spinlock);
  39773. + service_quota->message_use_count++;
  39774. +
  39775. + tx_end_index =
  39776. + SLOT_QUEUE_INDEX_FROM_POS(state->local_tx_pos - 1);
  39777. +
  39778. + /* If this transmission can't fit in the last slot used by any
  39779. + ** service, the data_use_count must be increased. */
  39780. + if (tx_end_index != state->previous_data_index) {
  39781. + state->previous_data_index = tx_end_index;
  39782. + state->data_use_count++;
  39783. + }
  39784. +
  39785. + /* If this isn't the same slot last used by this service,
  39786. + ** the service's slot_use_count must be increased. */
  39787. + if (tx_end_index != service_quota->previous_tx_index) {
  39788. + service_quota->previous_tx_index = tx_end_index;
  39789. + slot_use_count = ++service_quota->slot_use_count;
  39790. + } else {
  39791. + slot_use_count = 0;
  39792. + }
  39793. +
  39794. + spin_unlock(&quota_spinlock);
  39795. +
  39796. + if (slot_use_count)
  39797. + vchiq_log_trace(vchiq_core_log_level,
  39798. + "%d: qm:%d %s,%x - slot_use->%d (hdr %p)",
  39799. + state->id, service->localport,
  39800. + msg_type_str(VCHIQ_MSG_TYPE(msgid)), size,
  39801. + slot_use_count, header);
  39802. +
  39803. + VCHIQ_SERVICE_STATS_INC(service, ctrl_tx_count);
  39804. + VCHIQ_SERVICE_STATS_ADD(service, ctrl_tx_bytes, size);
  39805. + } else {
  39806. + vchiq_log_info(vchiq_core_log_level,
  39807. + "%d: qm %s@%x,%x (%d->%d)", state->id,
  39808. + msg_type_str(VCHIQ_MSG_TYPE(msgid)),
  39809. + (unsigned int)header, size,
  39810. + VCHIQ_MSG_SRCPORT(msgid),
  39811. + VCHIQ_MSG_DSTPORT(msgid));
  39812. + if (size != 0) {
  39813. + WARN_ON(!((count == 1) && (size == elements[0].size)));
  39814. + memcpy(header->data, elements[0].data,
  39815. + elements[0].size);
  39816. + }
  39817. + VCHIQ_STATS_INC(state, ctrl_tx_count);
  39818. + }
  39819. +
  39820. + header->msgid = msgid;
  39821. + header->size = size;
  39822. +
  39823. + {
  39824. + int svc_fourcc;
  39825. +
  39826. + svc_fourcc = service
  39827. + ? service->base.fourcc
  39828. + : VCHIQ_MAKE_FOURCC('?', '?', '?', '?');
  39829. +
  39830. + vchiq_log_info(SRVTRACE_LEVEL(service),
  39831. + "Sent Msg %s(%u) to %c%c%c%c s:%u d:%d len:%d",
  39832. + msg_type_str(VCHIQ_MSG_TYPE(msgid)),
  39833. + VCHIQ_MSG_TYPE(msgid),
  39834. + VCHIQ_FOURCC_AS_4CHARS(svc_fourcc),
  39835. + VCHIQ_MSG_SRCPORT(msgid),
  39836. + VCHIQ_MSG_DSTPORT(msgid),
  39837. + size);
  39838. + }
  39839. +
  39840. + /* Make sure the new header is visible to the peer. */
  39841. + wmb();
  39842. +
  39843. + /* Make the new tx_pos visible to the peer. */
  39844. + local->tx_pos = state->local_tx_pos;
  39845. + wmb();
  39846. +
  39847. + if (service && (type == VCHIQ_MSG_CLOSE))
  39848. + vchiq_set_service_state(service, VCHIQ_SRVSTATE_CLOSESENT);
  39849. +
  39850. + if (!(flags & QMFLAGS_NO_MUTEX_UNLOCK))
  39851. + mutex_unlock(&state->slot_mutex);
  39852. +
  39853. + remote_event_signal(&state->remote->trigger);
  39854. +
  39855. + return VCHIQ_SUCCESS;
  39856. +}
  39857. +
  39858. +/* Called by the slot handler and application threads */
  39859. +static VCHIQ_STATUS_T
  39860. +queue_message_sync(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service,
  39861. + int msgid, const VCHIQ_ELEMENT_T *elements,
  39862. + int count, int size, int is_blocking)
  39863. +{
  39864. + VCHIQ_SHARED_STATE_T *local;
  39865. + VCHIQ_HEADER_T *header;
  39866. +
  39867. + local = state->local;
  39868. +
  39869. + if ((VCHIQ_MSG_TYPE(msgid) != VCHIQ_MSG_RESUME) &&
  39870. + (mutex_lock_interruptible(&state->sync_mutex) != 0))
  39871. + return VCHIQ_RETRY;
  39872. +
  39873. + remote_event_wait(&local->sync_release);
  39874. +
  39875. + rmb();
  39876. +
  39877. + header = (VCHIQ_HEADER_T *)SLOT_DATA_FROM_INDEX(state,
  39878. + local->slot_sync);
  39879. +
  39880. + {
  39881. + int oldmsgid = header->msgid;
  39882. + if (oldmsgid != VCHIQ_MSGID_PADDING)
  39883. + vchiq_log_error(vchiq_core_log_level,
  39884. + "%d: qms - msgid %x, not PADDING",
  39885. + state->id, oldmsgid);
  39886. + }
  39887. +
  39888. + if (service) {
  39889. + int i, pos;
  39890. +
  39891. + vchiq_log_info(vchiq_sync_log_level,
  39892. + "%d: qms %s@%x,%x (%d->%d)", state->id,
  39893. + msg_type_str(VCHIQ_MSG_TYPE(msgid)),
  39894. + (unsigned int)header, size,
  39895. + VCHIQ_MSG_SRCPORT(msgid),
  39896. + VCHIQ_MSG_DSTPORT(msgid));
  39897. +
  39898. + for (i = 0, pos = 0; i < (unsigned int)count;
  39899. + pos += elements[i++].size)
  39900. + if (elements[i].size) {
  39901. + if (vchiq_copy_from_user
  39902. + (header->data + pos, elements[i].data,
  39903. + (size_t) elements[i].size) !=
  39904. + VCHIQ_SUCCESS) {
  39905. + mutex_unlock(&state->sync_mutex);
  39906. + VCHIQ_SERVICE_STATS_INC(service,
  39907. + error_count);
  39908. + return VCHIQ_ERROR;
  39909. + }
  39910. + if (i == 0) {
  39911. + if (vchiq_sync_log_level >=
  39912. + VCHIQ_LOG_TRACE)
  39913. + vchiq_log_dump_mem("Sent Sync",
  39914. + 0, header->data + pos,
  39915. + min(64u,
  39916. + elements[0].size));
  39917. + }
  39918. + }
  39919. +
  39920. + VCHIQ_SERVICE_STATS_INC(service, ctrl_tx_count);
  39921. + VCHIQ_SERVICE_STATS_ADD(service, ctrl_tx_bytes, size);
  39922. + } else {
  39923. + vchiq_log_info(vchiq_sync_log_level,
  39924. + "%d: qms %s@%x,%x (%d->%d)", state->id,
  39925. + msg_type_str(VCHIQ_MSG_TYPE(msgid)),
  39926. + (unsigned int)header, size,
  39927. + VCHIQ_MSG_SRCPORT(msgid),
  39928. + VCHIQ_MSG_DSTPORT(msgid));
  39929. + if (size != 0) {
  39930. + WARN_ON(!((count == 1) && (size == elements[0].size)));
  39931. + memcpy(header->data, elements[0].data,
  39932. + elements[0].size);
  39933. + }
  39934. + VCHIQ_STATS_INC(state, ctrl_tx_count);
  39935. + }
  39936. +
  39937. + header->size = size;
  39938. + header->msgid = msgid;
  39939. +
  39940. + if (vchiq_sync_log_level >= VCHIQ_LOG_TRACE) {
  39941. + int svc_fourcc;
  39942. +
  39943. + svc_fourcc = service
  39944. + ? service->base.fourcc
  39945. + : VCHIQ_MAKE_FOURCC('?', '?', '?', '?');
  39946. +
  39947. + vchiq_log_trace(vchiq_sync_log_level,
  39948. + "Sent Sync Msg %s(%u) to %c%c%c%c s:%u d:%d len:%d",
  39949. + msg_type_str(VCHIQ_MSG_TYPE(msgid)),
  39950. + VCHIQ_MSG_TYPE(msgid),
  39951. + VCHIQ_FOURCC_AS_4CHARS(svc_fourcc),
  39952. + VCHIQ_MSG_SRCPORT(msgid),
  39953. + VCHIQ_MSG_DSTPORT(msgid),
  39954. + size);
  39955. + }
  39956. +
  39957. + /* Make sure the new header is visible to the peer. */
  39958. + wmb();
  39959. +
  39960. + remote_event_signal(&state->remote->sync_trigger);
  39961. +
  39962. + if (VCHIQ_MSG_TYPE(msgid) != VCHIQ_MSG_PAUSE)
  39963. + mutex_unlock(&state->sync_mutex);
  39964. +
  39965. + return VCHIQ_SUCCESS;
  39966. +}
  39967. +
  39968. +static inline void
  39969. +claim_slot(VCHIQ_SLOT_INFO_T *slot)
  39970. +{
  39971. + slot->use_count++;
  39972. +}
  39973. +
  39974. +static void
  39975. +release_slot(VCHIQ_STATE_T *state, VCHIQ_SLOT_INFO_T *slot_info,
  39976. + VCHIQ_HEADER_T *header, VCHIQ_SERVICE_T *service)
  39977. +{
  39978. + int release_count;
  39979. +
  39980. + mutex_lock(&state->recycle_mutex);
  39981. +
  39982. + if (header) {
  39983. + int msgid = header->msgid;
  39984. + if (((msgid & VCHIQ_MSGID_CLAIMED) == 0) ||
  39985. + (service && service->closing)) {
  39986. + mutex_unlock(&state->recycle_mutex);
  39987. + return;
  39988. + }
  39989. +
  39990. + /* Rewrite the message header to prevent a double
  39991. + ** release */
  39992. + header->msgid = msgid & ~VCHIQ_MSGID_CLAIMED;
  39993. + }
  39994. +
  39995. + release_count = slot_info->release_count;
  39996. + slot_info->release_count = ++release_count;
  39997. +
  39998. + if (release_count == slot_info->use_count) {
  39999. + int slot_queue_recycle;
  40000. + /* Add to the freed queue */
  40001. +
  40002. + /* A read barrier is necessary here to prevent speculative
  40003. + ** fetches of remote->slot_queue_recycle from overtaking the
  40004. + ** mutex. */
  40005. + rmb();
  40006. +
  40007. + slot_queue_recycle = state->remote->slot_queue_recycle;
  40008. + state->remote->slot_queue[slot_queue_recycle &
  40009. + VCHIQ_SLOT_QUEUE_MASK] =
  40010. + SLOT_INDEX_FROM_INFO(state, slot_info);
  40011. + state->remote->slot_queue_recycle = slot_queue_recycle + 1;
  40012. + vchiq_log_info(vchiq_core_log_level,
  40013. + "%d: release_slot %d - recycle->%x",
  40014. + state->id, SLOT_INDEX_FROM_INFO(state, slot_info),
  40015. + state->remote->slot_queue_recycle);
  40016. +
  40017. + /* A write barrier is necessary, but remote_event_signal
  40018. + ** contains one. */
  40019. + remote_event_signal(&state->remote->recycle);
  40020. + }
  40021. +
  40022. + mutex_unlock(&state->recycle_mutex);
  40023. +}
  40024. +
  40025. +/* Called by the slot handler - don't hold the bulk mutex */
  40026. +static VCHIQ_STATUS_T
  40027. +notify_bulks(VCHIQ_SERVICE_T *service, VCHIQ_BULK_QUEUE_T *queue,
  40028. + int retry_poll)
  40029. +{
  40030. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  40031. +
  40032. + vchiq_log_trace(vchiq_core_log_level,
  40033. + "%d: nb:%d %cx - p=%x rn=%x r=%x",
  40034. + service->state->id, service->localport,
  40035. + (queue == &service->bulk_tx) ? 't' : 'r',
  40036. + queue->process, queue->remote_notify, queue->remove);
  40037. +
  40038. + if (service->state->is_master) {
  40039. + while (queue->remote_notify != queue->process) {
  40040. + VCHIQ_BULK_T *bulk =
  40041. + &queue->bulks[BULK_INDEX(queue->remote_notify)];
  40042. + int msgtype = (bulk->dir == VCHIQ_BULK_TRANSMIT) ?
  40043. + VCHIQ_MSG_BULK_RX_DONE : VCHIQ_MSG_BULK_TX_DONE;
  40044. + int msgid = VCHIQ_MAKE_MSG(msgtype, service->localport,
  40045. + service->remoteport);
  40046. + VCHIQ_ELEMENT_T element = { &bulk->actual, 4 };
  40047. + /* Only reply to non-dummy bulk requests */
  40048. + if (bulk->remote_data) {
  40049. + status = queue_message(service->state, NULL,
  40050. + msgid, &element, 1, 4, 0);
  40051. + if (status != VCHIQ_SUCCESS)
  40052. + break;
  40053. + }
  40054. + queue->remote_notify++;
  40055. + }
  40056. + } else {
  40057. + queue->remote_notify = queue->process;
  40058. + }
  40059. +
  40060. + if (status == VCHIQ_SUCCESS) {
  40061. + while (queue->remove != queue->remote_notify) {
  40062. + VCHIQ_BULK_T *bulk =
  40063. + &queue->bulks[BULK_INDEX(queue->remove)];
  40064. +
  40065. + /* Only generate callbacks for non-dummy bulk
  40066. + ** requests, and non-terminated services */
  40067. + if (bulk->data && service->instance) {
  40068. + if (bulk->actual != VCHIQ_BULK_ACTUAL_ABORTED) {
  40069. + if (bulk->dir == VCHIQ_BULK_TRANSMIT) {
  40070. + VCHIQ_SERVICE_STATS_INC(service,
  40071. + bulk_tx_count);
  40072. + VCHIQ_SERVICE_STATS_ADD(service,
  40073. + bulk_tx_bytes,
  40074. + bulk->actual);
  40075. + } else {
  40076. + VCHIQ_SERVICE_STATS_INC(service,
  40077. + bulk_rx_count);
  40078. + VCHIQ_SERVICE_STATS_ADD(service,
  40079. + bulk_rx_bytes,
  40080. + bulk->actual);
  40081. + }
  40082. + } else {
  40083. + VCHIQ_SERVICE_STATS_INC(service,
  40084. + bulk_aborted_count);
  40085. + }
  40086. + if (bulk->mode == VCHIQ_BULK_MODE_BLOCKING) {
  40087. + struct bulk_waiter *waiter;
  40088. + spin_lock(&bulk_waiter_spinlock);
  40089. + waiter = bulk->userdata;
  40090. + if (waiter) {
  40091. + waiter->actual = bulk->actual;
  40092. + up(&waiter->event);
  40093. + }
  40094. + spin_unlock(&bulk_waiter_spinlock);
  40095. + } else if (bulk->mode ==
  40096. + VCHIQ_BULK_MODE_CALLBACK) {
  40097. + VCHIQ_REASON_T reason = (bulk->dir ==
  40098. + VCHIQ_BULK_TRANSMIT) ?
  40099. + ((bulk->actual ==
  40100. + VCHIQ_BULK_ACTUAL_ABORTED) ?
  40101. + VCHIQ_BULK_TRANSMIT_ABORTED :
  40102. + VCHIQ_BULK_TRANSMIT_DONE) :
  40103. + ((bulk->actual ==
  40104. + VCHIQ_BULK_ACTUAL_ABORTED) ?
  40105. + VCHIQ_BULK_RECEIVE_ABORTED :
  40106. + VCHIQ_BULK_RECEIVE_DONE);
  40107. + status = make_service_callback(service,
  40108. + reason, NULL, bulk->userdata);
  40109. + if (status == VCHIQ_RETRY)
  40110. + break;
  40111. + }
  40112. + }
  40113. +
  40114. + queue->remove++;
  40115. + up(&service->bulk_remove_event);
  40116. + }
  40117. + if (!retry_poll)
  40118. + status = VCHIQ_SUCCESS;
  40119. + }
  40120. +
  40121. + if (status == VCHIQ_RETRY)
  40122. + request_poll(service->state, service,
  40123. + (queue == &service->bulk_tx) ?
  40124. + VCHIQ_POLL_TXNOTIFY : VCHIQ_POLL_RXNOTIFY);
  40125. +
  40126. + return status;
  40127. +}
  40128. +
  40129. +/* Called by the slot handler thread */
  40130. +static void
  40131. +poll_services(VCHIQ_STATE_T *state)
  40132. +{
  40133. + int group, i;
  40134. +
  40135. + for (group = 0; group < BITSET_SIZE(state->unused_service); group++) {
  40136. + uint32_t flags;
  40137. + flags = atomic_xchg(&state->poll_services[group], 0);
  40138. + for (i = 0; flags; i++) {
  40139. + if (flags & (1 << i)) {
  40140. + VCHIQ_SERVICE_T *service =
  40141. + find_service_by_port(state,
  40142. + (group<<5) + i);
  40143. + uint32_t service_flags;
  40144. + flags &= ~(1 << i);
  40145. + if (!service)
  40146. + continue;
  40147. + service_flags =
  40148. + atomic_xchg(&service->poll_flags, 0);
  40149. + if (service_flags &
  40150. + (1 << VCHIQ_POLL_REMOVE)) {
  40151. + vchiq_log_info(vchiq_core_log_level,
  40152. + "%d: ps - remove %d<->%d",
  40153. + state->id, service->localport,
  40154. + service->remoteport);
  40155. +
  40156. + /* Make it look like a client, because
  40157. + it must be removed and not left in
  40158. + the LISTENING state. */
  40159. + service->public_fourcc =
  40160. + VCHIQ_FOURCC_INVALID;
  40161. +
  40162. + if (vchiq_close_service_internal(
  40163. + service, 0/*!close_recvd*/) !=
  40164. + VCHIQ_SUCCESS)
  40165. + request_poll(state, service,
  40166. + VCHIQ_POLL_REMOVE);
  40167. + } else if (service_flags &
  40168. + (1 << VCHIQ_POLL_TERMINATE)) {
  40169. + vchiq_log_info(vchiq_core_log_level,
  40170. + "%d: ps - terminate %d<->%d",
  40171. + state->id, service->localport,
  40172. + service->remoteport);
  40173. + if (vchiq_close_service_internal(
  40174. + service, 0/*!close_recvd*/) !=
  40175. + VCHIQ_SUCCESS)
  40176. + request_poll(state, service,
  40177. + VCHIQ_POLL_TERMINATE);
  40178. + }
  40179. + if (service_flags & (1 << VCHIQ_POLL_TXNOTIFY))
  40180. + notify_bulks(service,
  40181. + &service->bulk_tx,
  40182. + 1/*retry_poll*/);
  40183. + if (service_flags & (1 << VCHIQ_POLL_RXNOTIFY))
  40184. + notify_bulks(service,
  40185. + &service->bulk_rx,
  40186. + 1/*retry_poll*/);
  40187. + unlock_service(service);
  40188. + }
  40189. + }
  40190. + }
  40191. +}
  40192. +
  40193. +/* Called by the slot handler or application threads, holding the bulk mutex. */
  40194. +static int
  40195. +resolve_bulks(VCHIQ_SERVICE_T *service, VCHIQ_BULK_QUEUE_T *queue)
  40196. +{
  40197. + VCHIQ_STATE_T *state = service->state;
  40198. + int resolved = 0;
  40199. + int rc;
  40200. +
  40201. + while ((queue->process != queue->local_insert) &&
  40202. + (queue->process != queue->remote_insert)) {
  40203. + VCHIQ_BULK_T *bulk = &queue->bulks[BULK_INDEX(queue->process)];
  40204. +
  40205. + vchiq_log_trace(vchiq_core_log_level,
  40206. + "%d: rb:%d %cx - li=%x ri=%x p=%x",
  40207. + state->id, service->localport,
  40208. + (queue == &service->bulk_tx) ? 't' : 'r',
  40209. + queue->local_insert, queue->remote_insert,
  40210. + queue->process);
  40211. +
  40212. + WARN_ON(!((int)(queue->local_insert - queue->process) > 0));
  40213. + WARN_ON(!((int)(queue->remote_insert - queue->process) > 0));
  40214. +
  40215. + rc = mutex_lock_interruptible(&state->bulk_transfer_mutex);
  40216. + if (rc != 0)
  40217. + break;
  40218. +
  40219. + vchiq_transfer_bulk(bulk);
  40220. + mutex_unlock(&state->bulk_transfer_mutex);
  40221. +
  40222. + if (SRVTRACE_ENABLED(service, VCHIQ_LOG_INFO)) {
  40223. + const char *header = (queue == &service->bulk_tx) ?
  40224. + "Send Bulk to" : "Recv Bulk from";
  40225. + if (bulk->actual != VCHIQ_BULK_ACTUAL_ABORTED)
  40226. + vchiq_log_info(SRVTRACE_LEVEL(service),
  40227. + "%s %c%c%c%c d:%d len:%d %x<->%x",
  40228. + header,
  40229. + VCHIQ_FOURCC_AS_4CHARS(
  40230. + service->base.fourcc),
  40231. + service->remoteport,
  40232. + bulk->size,
  40233. + (unsigned int)bulk->data,
  40234. + (unsigned int)bulk->remote_data);
  40235. + else
  40236. + vchiq_log_info(SRVTRACE_LEVEL(service),
  40237. + "%s %c%c%c%c d:%d ABORTED - tx len:%d,"
  40238. + " rx len:%d %x<->%x",
  40239. + header,
  40240. + VCHIQ_FOURCC_AS_4CHARS(
  40241. + service->base.fourcc),
  40242. + service->remoteport,
  40243. + bulk->size,
  40244. + bulk->remote_size,
  40245. + (unsigned int)bulk->data,
  40246. + (unsigned int)bulk->remote_data);
  40247. + }
  40248. +
  40249. + vchiq_complete_bulk(bulk);
  40250. + queue->process++;
  40251. + resolved++;
  40252. + }
  40253. + return resolved;
  40254. +}
  40255. +
  40256. +/* Called with the bulk_mutex held */
  40257. +static void
  40258. +abort_outstanding_bulks(VCHIQ_SERVICE_T *service, VCHIQ_BULK_QUEUE_T *queue)
  40259. +{
  40260. + int is_tx = (queue == &service->bulk_tx);
  40261. + vchiq_log_trace(vchiq_core_log_level,
  40262. + "%d: aob:%d %cx - li=%x ri=%x p=%x",
  40263. + service->state->id, service->localport, is_tx ? 't' : 'r',
  40264. + queue->local_insert, queue->remote_insert, queue->process);
  40265. +
  40266. + WARN_ON(!((int)(queue->local_insert - queue->process) >= 0));
  40267. + WARN_ON(!((int)(queue->remote_insert - queue->process) >= 0));
  40268. +
  40269. + while ((queue->process != queue->local_insert) ||
  40270. + (queue->process != queue->remote_insert)) {
  40271. + VCHIQ_BULK_T *bulk = &queue->bulks[BULK_INDEX(queue->process)];
  40272. +
  40273. + if (queue->process == queue->remote_insert) {
  40274. + /* fabricate a matching dummy bulk */
  40275. + bulk->remote_data = NULL;
  40276. + bulk->remote_size = 0;
  40277. + queue->remote_insert++;
  40278. + }
  40279. +
  40280. + if (queue->process != queue->local_insert) {
  40281. + vchiq_complete_bulk(bulk);
  40282. +
  40283. + vchiq_log_info(SRVTRACE_LEVEL(service),
  40284. + "%s %c%c%c%c d:%d ABORTED - tx len:%d, "
  40285. + "rx len:%d",
  40286. + is_tx ? "Send Bulk to" : "Recv Bulk from",
  40287. + VCHIQ_FOURCC_AS_4CHARS(service->base.fourcc),
  40288. + service->remoteport,
  40289. + bulk->size,
  40290. + bulk->remote_size);
  40291. + } else {
  40292. + /* fabricate a matching dummy bulk */
  40293. + bulk->data = NULL;
  40294. + bulk->size = 0;
  40295. + bulk->actual = VCHIQ_BULK_ACTUAL_ABORTED;
  40296. + bulk->dir = is_tx ? VCHIQ_BULK_TRANSMIT :
  40297. + VCHIQ_BULK_RECEIVE;
  40298. + queue->local_insert++;
  40299. + }
  40300. +
  40301. + queue->process++;
  40302. + }
  40303. +}
  40304. +
  40305. +/* Called from the slot handler thread */
  40306. +static void
  40307. +pause_bulks(VCHIQ_STATE_T *state)
  40308. +{
  40309. + if (unlikely(atomic_inc_return(&pause_bulks_count) != 1)) {
  40310. + WARN_ON_ONCE(1);
  40311. + atomic_set(&pause_bulks_count, 1);
  40312. + return;
  40313. + }
  40314. +
  40315. + /* Block bulk transfers from all services */
  40316. + mutex_lock(&state->bulk_transfer_mutex);
  40317. +}
  40318. +
  40319. +/* Called from the slot handler thread */
  40320. +static void
  40321. +resume_bulks(VCHIQ_STATE_T *state)
  40322. +{
  40323. + int i;
  40324. + if (unlikely(atomic_dec_return(&pause_bulks_count) != 0)) {
  40325. + WARN_ON_ONCE(1);
  40326. + atomic_set(&pause_bulks_count, 0);
  40327. + return;
  40328. + }
  40329. +
  40330. + /* Allow bulk transfers from all services */
  40331. + mutex_unlock(&state->bulk_transfer_mutex);
  40332. +
  40333. + if (state->deferred_bulks == 0)
  40334. + return;
  40335. +
  40336. + /* Deal with any bulks which had to be deferred due to being in
  40337. + * paused state. Don't try to match up to number of deferred bulks
  40338. + * in case we've had something come and close the service in the
  40339. + * interim - just process all bulk queues for all services */
  40340. + vchiq_log_info(vchiq_core_log_level, "%s: processing %d deferred bulks",
  40341. + __func__, state->deferred_bulks);
  40342. +
  40343. + for (i = 0; i < state->unused_service; i++) {
  40344. + VCHIQ_SERVICE_T *service = state->services[i];
  40345. + int resolved_rx = 0;
  40346. + int resolved_tx = 0;
  40347. + if (!service || (service->srvstate != VCHIQ_SRVSTATE_OPEN))
  40348. + continue;
  40349. +
  40350. + mutex_lock(&service->bulk_mutex);
  40351. + resolved_rx = resolve_bulks(service, &service->bulk_rx);
  40352. + resolved_tx = resolve_bulks(service, &service->bulk_tx);
  40353. + mutex_unlock(&service->bulk_mutex);
  40354. + if (resolved_rx)
  40355. + notify_bulks(service, &service->bulk_rx, 1);
  40356. + if (resolved_tx)
  40357. + notify_bulks(service, &service->bulk_tx, 1);
  40358. + }
  40359. + state->deferred_bulks = 0;
  40360. +}
  40361. +
  40362. +static int
  40363. +parse_open(VCHIQ_STATE_T *state, VCHIQ_HEADER_T *header)
  40364. +{
  40365. + VCHIQ_SERVICE_T *service = NULL;
  40366. + int msgid, size;
  40367. + int type;
  40368. + unsigned int localport, remoteport;
  40369. +
  40370. + msgid = header->msgid;
  40371. + size = header->size;
  40372. + type = VCHIQ_MSG_TYPE(msgid);
  40373. + localport = VCHIQ_MSG_DSTPORT(msgid);
  40374. + remoteport = VCHIQ_MSG_SRCPORT(msgid);
  40375. + if (size >= sizeof(struct vchiq_open_payload)) {
  40376. + const struct vchiq_open_payload *payload =
  40377. + (struct vchiq_open_payload *)header->data;
  40378. + unsigned int fourcc;
  40379. +
  40380. + fourcc = payload->fourcc;
  40381. + vchiq_log_info(vchiq_core_log_level,
  40382. + "%d: prs OPEN@%x (%d->'%c%c%c%c')",
  40383. + state->id, (unsigned int)header,
  40384. + localport,
  40385. + VCHIQ_FOURCC_AS_4CHARS(fourcc));
  40386. +
  40387. + service = get_listening_service(state, fourcc);
  40388. +
  40389. + if (service) {
  40390. + /* A matching service exists */
  40391. + short version = payload->version;
  40392. + short version_min = payload->version_min;
  40393. + if ((service->version < version_min) ||
  40394. + (version < service->version_min)) {
  40395. + /* Version mismatch */
  40396. + vchiq_loud_error_header();
  40397. + vchiq_loud_error("%d: service %d (%c%c%c%c) "
  40398. + "version mismatch - local (%d, min %d)"
  40399. + " vs. remote (%d, min %d)",
  40400. + state->id, service->localport,
  40401. + VCHIQ_FOURCC_AS_4CHARS(fourcc),
  40402. + service->version, service->version_min,
  40403. + version, version_min);
  40404. + vchiq_loud_error_footer();
  40405. + unlock_service(service);
  40406. + service = NULL;
  40407. + goto fail_open;
  40408. + }
  40409. + service->peer_version = version;
  40410. +
  40411. + if (service->srvstate == VCHIQ_SRVSTATE_LISTENING) {
  40412. + struct vchiq_openack_payload ack_payload = {
  40413. + service->version
  40414. + };
  40415. + VCHIQ_ELEMENT_T body = {
  40416. + &ack_payload,
  40417. + sizeof(ack_payload)
  40418. + };
  40419. +
  40420. + if (state->version_common <
  40421. + VCHIQ_VERSION_SYNCHRONOUS_MODE)
  40422. + service->sync = 0;
  40423. +
  40424. + /* Acknowledge the OPEN */
  40425. + if (service->sync &&
  40426. + (state->version_common >=
  40427. + VCHIQ_VERSION_SYNCHRONOUS_MODE)) {
  40428. + if (queue_message_sync(state, NULL,
  40429. + VCHIQ_MAKE_MSG(
  40430. + VCHIQ_MSG_OPENACK,
  40431. + service->localport,
  40432. + remoteport),
  40433. + &body, 1, sizeof(ack_payload),
  40434. + 0) == VCHIQ_RETRY)
  40435. + goto bail_not_ready;
  40436. + } else {
  40437. + if (queue_message(state, NULL,
  40438. + VCHIQ_MAKE_MSG(
  40439. + VCHIQ_MSG_OPENACK,
  40440. + service->localport,
  40441. + remoteport),
  40442. + &body, 1, sizeof(ack_payload),
  40443. + 0) == VCHIQ_RETRY)
  40444. + goto bail_not_ready;
  40445. + }
  40446. +
  40447. + /* The service is now open */
  40448. + vchiq_set_service_state(service,
  40449. + service->sync ? VCHIQ_SRVSTATE_OPENSYNC
  40450. + : VCHIQ_SRVSTATE_OPEN);
  40451. + }
  40452. +
  40453. + service->remoteport = remoteport;
  40454. + service->client_id = ((int *)header->data)[1];
  40455. + if (make_service_callback(service, VCHIQ_SERVICE_OPENED,
  40456. + NULL, NULL) == VCHIQ_RETRY) {
  40457. + /* Bail out if not ready */
  40458. + service->remoteport = VCHIQ_PORT_FREE;
  40459. + goto bail_not_ready;
  40460. + }
  40461. +
  40462. + /* Success - the message has been dealt with */
  40463. + unlock_service(service);
  40464. + return 1;
  40465. + }
  40466. + }
  40467. +
  40468. +fail_open:
  40469. + /* No available service, or an invalid request - send a CLOSE */
  40470. + if (queue_message(state, NULL,
  40471. + VCHIQ_MAKE_MSG(VCHIQ_MSG_CLOSE, 0, VCHIQ_MSG_SRCPORT(msgid)),
  40472. + NULL, 0, 0, 0) == VCHIQ_RETRY)
  40473. + goto bail_not_ready;
  40474. +
  40475. + return 1;
  40476. +
  40477. +bail_not_ready:
  40478. + if (service)
  40479. + unlock_service(service);
  40480. +
  40481. + return 0;
  40482. +}
  40483. +
  40484. +/* Called by the slot handler thread */
  40485. +static void
  40486. +parse_rx_slots(VCHIQ_STATE_T *state)
  40487. +{
  40488. + VCHIQ_SHARED_STATE_T *remote = state->remote;
  40489. + VCHIQ_SERVICE_T *service = NULL;
  40490. + int tx_pos;
  40491. + DEBUG_INITIALISE(state->local)
  40492. +
  40493. + tx_pos = remote->tx_pos;
  40494. +
  40495. + while (state->rx_pos != tx_pos) {
  40496. + VCHIQ_HEADER_T *header;
  40497. + int msgid, size;
  40498. + int type;
  40499. + unsigned int localport, remoteport;
  40500. +
  40501. + DEBUG_TRACE(PARSE_LINE);
  40502. + if (!state->rx_data) {
  40503. + int rx_index;
  40504. + WARN_ON(!((state->rx_pos & VCHIQ_SLOT_MASK) == 0));
  40505. + rx_index = remote->slot_queue[
  40506. + SLOT_QUEUE_INDEX_FROM_POS(state->rx_pos) &
  40507. + VCHIQ_SLOT_QUEUE_MASK];
  40508. + state->rx_data = (char *)SLOT_DATA_FROM_INDEX(state,
  40509. + rx_index);
  40510. + state->rx_info = SLOT_INFO_FROM_INDEX(state, rx_index);
  40511. +
  40512. + /* Initialise use_count to one, and increment
  40513. + ** release_count at the end of the slot to avoid
  40514. + ** releasing the slot prematurely. */
  40515. + state->rx_info->use_count = 1;
  40516. + state->rx_info->release_count = 0;
  40517. + }
  40518. +
  40519. + header = (VCHIQ_HEADER_T *)(state->rx_data +
  40520. + (state->rx_pos & VCHIQ_SLOT_MASK));
  40521. + DEBUG_VALUE(PARSE_HEADER, (int)header);
  40522. + msgid = header->msgid;
  40523. + DEBUG_VALUE(PARSE_MSGID, msgid);
  40524. + size = header->size;
  40525. + type = VCHIQ_MSG_TYPE(msgid);
  40526. + localport = VCHIQ_MSG_DSTPORT(msgid);
  40527. + remoteport = VCHIQ_MSG_SRCPORT(msgid);
  40528. +
  40529. + if (type != VCHIQ_MSG_DATA)
  40530. + VCHIQ_STATS_INC(state, ctrl_rx_count);
  40531. +
  40532. + switch (type) {
  40533. + case VCHIQ_MSG_OPENACK:
  40534. + case VCHIQ_MSG_CLOSE:
  40535. + case VCHIQ_MSG_DATA:
  40536. + case VCHIQ_MSG_BULK_RX:
  40537. + case VCHIQ_MSG_BULK_TX:
  40538. + case VCHIQ_MSG_BULK_RX_DONE:
  40539. + case VCHIQ_MSG_BULK_TX_DONE:
  40540. + service = find_service_by_port(state, localport);
  40541. + if ((!service ||
  40542. + ((service->remoteport != remoteport) &&
  40543. + (service->remoteport != VCHIQ_PORT_FREE))) &&
  40544. + (localport == 0) &&
  40545. + (type == VCHIQ_MSG_CLOSE)) {
  40546. + /* This could be a CLOSE from a client which
  40547. + hadn't yet received the OPENACK - look for
  40548. + the connected service */
  40549. + if (service)
  40550. + unlock_service(service);
  40551. + service = get_connected_service(state,
  40552. + remoteport);
  40553. + if (service)
  40554. + vchiq_log_warning(vchiq_core_log_level,
  40555. + "%d: prs %s@%x (%d->%d) - "
  40556. + "found connected service %d",
  40557. + state->id, msg_type_str(type),
  40558. + (unsigned int)header,
  40559. + remoteport, localport,
  40560. + service->localport);
  40561. + }
  40562. +
  40563. + if (!service) {
  40564. + vchiq_log_error(vchiq_core_log_level,
  40565. + "%d: prs %s@%x (%d->%d) - "
  40566. + "invalid/closed service %d",
  40567. + state->id, msg_type_str(type),
  40568. + (unsigned int)header,
  40569. + remoteport, localport, localport);
  40570. + goto skip_message;
  40571. + }
  40572. + break;
  40573. + default:
  40574. + break;
  40575. + }
  40576. +
  40577. + if (SRVTRACE_ENABLED(service, VCHIQ_LOG_INFO)) {
  40578. + int svc_fourcc;
  40579. +
  40580. + svc_fourcc = service
  40581. + ? service->base.fourcc
  40582. + : VCHIQ_MAKE_FOURCC('?', '?', '?', '?');
  40583. + vchiq_log_info(SRVTRACE_LEVEL(service),
  40584. + "Rcvd Msg %s(%u) from %c%c%c%c s:%d d:%d "
  40585. + "len:%d",
  40586. + msg_type_str(type), type,
  40587. + VCHIQ_FOURCC_AS_4CHARS(svc_fourcc),
  40588. + remoteport, localport, size);
  40589. + if (size > 0)
  40590. + vchiq_log_dump_mem("Rcvd", 0, header->data,
  40591. + min(64, size));
  40592. + }
  40593. +
  40594. + if (((unsigned int)header & VCHIQ_SLOT_MASK) + calc_stride(size)
  40595. + > VCHIQ_SLOT_SIZE) {
  40596. + vchiq_log_error(vchiq_core_log_level,
  40597. + "header %x (msgid %x) - size %x too big for "
  40598. + "slot",
  40599. + (unsigned int)header, (unsigned int)msgid,
  40600. + (unsigned int)size);
  40601. + WARN(1, "oversized for slot\n");
  40602. + }
  40603. +
  40604. + switch (type) {
  40605. + case VCHIQ_MSG_OPEN:
  40606. + WARN_ON(!(VCHIQ_MSG_DSTPORT(msgid) == 0));
  40607. + if (!parse_open(state, header))
  40608. + goto bail_not_ready;
  40609. + break;
  40610. + case VCHIQ_MSG_OPENACK:
  40611. + if (size >= sizeof(struct vchiq_openack_payload)) {
  40612. + const struct vchiq_openack_payload *payload =
  40613. + (struct vchiq_openack_payload *)
  40614. + header->data;
  40615. + service->peer_version = payload->version;
  40616. + }
  40617. + vchiq_log_info(vchiq_core_log_level,
  40618. + "%d: prs OPENACK@%x,%x (%d->%d) v:%d",
  40619. + state->id, (unsigned int)header, size,
  40620. + remoteport, localport, service->peer_version);
  40621. + if (service->srvstate ==
  40622. + VCHIQ_SRVSTATE_OPENING) {
  40623. + service->remoteport = remoteport;
  40624. + vchiq_set_service_state(service,
  40625. + VCHIQ_SRVSTATE_OPEN);
  40626. + up(&service->remove_event);
  40627. + } else
  40628. + vchiq_log_error(vchiq_core_log_level,
  40629. + "OPENACK received in state %s",
  40630. + srvstate_names[service->srvstate]);
  40631. + break;
  40632. + case VCHIQ_MSG_CLOSE:
  40633. + WARN_ON(size != 0); /* There should be no data */
  40634. +
  40635. + vchiq_log_info(vchiq_core_log_level,
  40636. + "%d: prs CLOSE@%x (%d->%d)",
  40637. + state->id, (unsigned int)header,
  40638. + remoteport, localport);
  40639. +
  40640. + mark_service_closing_internal(service, 1);
  40641. +
  40642. + if (vchiq_close_service_internal(service,
  40643. + 1/*close_recvd*/) == VCHIQ_RETRY)
  40644. + goto bail_not_ready;
  40645. +
  40646. + vchiq_log_info(vchiq_core_log_level,
  40647. + "Close Service %c%c%c%c s:%u d:%d",
  40648. + VCHIQ_FOURCC_AS_4CHARS(service->base.fourcc),
  40649. + service->localport,
  40650. + service->remoteport);
  40651. + break;
  40652. + case VCHIQ_MSG_DATA:
  40653. + vchiq_log_trace(vchiq_core_log_level,
  40654. + "%d: prs DATA@%x,%x (%d->%d)",
  40655. + state->id, (unsigned int)header, size,
  40656. + remoteport, localport);
  40657. +
  40658. + if ((service->remoteport == remoteport)
  40659. + && (service->srvstate ==
  40660. + VCHIQ_SRVSTATE_OPEN)) {
  40661. + header->msgid = msgid | VCHIQ_MSGID_CLAIMED;
  40662. + claim_slot(state->rx_info);
  40663. + DEBUG_TRACE(PARSE_LINE);
  40664. + if (make_service_callback(service,
  40665. + VCHIQ_MESSAGE_AVAILABLE, header,
  40666. + NULL) == VCHIQ_RETRY) {
  40667. + DEBUG_TRACE(PARSE_LINE);
  40668. + goto bail_not_ready;
  40669. + }
  40670. + VCHIQ_SERVICE_STATS_INC(service, ctrl_rx_count);
  40671. + VCHIQ_SERVICE_STATS_ADD(service, ctrl_rx_bytes,
  40672. + size);
  40673. + } else {
  40674. + VCHIQ_STATS_INC(state, error_count);
  40675. + }
  40676. + break;
  40677. + case VCHIQ_MSG_CONNECT:
  40678. + vchiq_log_info(vchiq_core_log_level,
  40679. + "%d: prs CONNECT@%x",
  40680. + state->id, (unsigned int)header);
  40681. + state->version_common = ((VCHIQ_SLOT_ZERO_T *)
  40682. + state->slot_data)->version;
  40683. + up(&state->connect);
  40684. + break;
  40685. + case VCHIQ_MSG_BULK_RX:
  40686. + case VCHIQ_MSG_BULK_TX: {
  40687. + VCHIQ_BULK_QUEUE_T *queue;
  40688. + WARN_ON(!state->is_master);
  40689. + queue = (type == VCHIQ_MSG_BULK_RX) ?
  40690. + &service->bulk_tx : &service->bulk_rx;
  40691. + if ((service->remoteport == remoteport)
  40692. + && (service->srvstate ==
  40693. + VCHIQ_SRVSTATE_OPEN)) {
  40694. + VCHIQ_BULK_T *bulk;
  40695. + int resolved = 0;
  40696. +
  40697. + DEBUG_TRACE(PARSE_LINE);
  40698. + if (mutex_lock_interruptible(
  40699. + &service->bulk_mutex) != 0) {
  40700. + DEBUG_TRACE(PARSE_LINE);
  40701. + goto bail_not_ready;
  40702. + }
  40703. +
  40704. + WARN_ON(!(queue->remote_insert < queue->remove +
  40705. + VCHIQ_NUM_SERVICE_BULKS));
  40706. + bulk = &queue->bulks[
  40707. + BULK_INDEX(queue->remote_insert)];
  40708. + bulk->remote_data =
  40709. + (void *)((int *)header->data)[0];
  40710. + bulk->remote_size = ((int *)header->data)[1];
  40711. + wmb();
  40712. +
  40713. + vchiq_log_info(vchiq_core_log_level,
  40714. + "%d: prs %s@%x (%d->%d) %x@%x",
  40715. + state->id, msg_type_str(type),
  40716. + (unsigned int)header,
  40717. + remoteport, localport,
  40718. + bulk->remote_size,
  40719. + (unsigned int)bulk->remote_data);
  40720. +
  40721. + queue->remote_insert++;
  40722. +
  40723. + if (atomic_read(&pause_bulks_count)) {
  40724. + state->deferred_bulks++;
  40725. + vchiq_log_info(vchiq_core_log_level,
  40726. + "%s: deferring bulk (%d)",
  40727. + __func__,
  40728. + state->deferred_bulks);
  40729. + if (state->conn_state !=
  40730. + VCHIQ_CONNSTATE_PAUSE_SENT)
  40731. + vchiq_log_error(
  40732. + vchiq_core_log_level,
  40733. + "%s: bulks paused in "
  40734. + "unexpected state %s",
  40735. + __func__,
  40736. + conn_state_names[
  40737. + state->conn_state]);
  40738. + } else if (state->conn_state ==
  40739. + VCHIQ_CONNSTATE_CONNECTED) {
  40740. + DEBUG_TRACE(PARSE_LINE);
  40741. + resolved = resolve_bulks(service,
  40742. + queue);
  40743. + }
  40744. +
  40745. + mutex_unlock(&service->bulk_mutex);
  40746. + if (resolved)
  40747. + notify_bulks(service, queue,
  40748. + 1/*retry_poll*/);
  40749. + }
  40750. + } break;
  40751. + case VCHIQ_MSG_BULK_RX_DONE:
  40752. + case VCHIQ_MSG_BULK_TX_DONE:
  40753. + WARN_ON(state->is_master);
  40754. + if ((service->remoteport == remoteport)
  40755. + && (service->srvstate !=
  40756. + VCHIQ_SRVSTATE_FREE)) {
  40757. + VCHIQ_BULK_QUEUE_T *queue;
  40758. + VCHIQ_BULK_T *bulk;
  40759. +
  40760. + queue = (type == VCHIQ_MSG_BULK_RX_DONE) ?
  40761. + &service->bulk_rx : &service->bulk_tx;
  40762. +
  40763. + DEBUG_TRACE(PARSE_LINE);
  40764. + if (mutex_lock_interruptible(
  40765. + &service->bulk_mutex) != 0) {
  40766. + DEBUG_TRACE(PARSE_LINE);
  40767. + goto bail_not_ready;
  40768. + }
  40769. + if ((int)(queue->remote_insert -
  40770. + queue->local_insert) >= 0) {
  40771. + vchiq_log_error(vchiq_core_log_level,
  40772. + "%d: prs %s@%x (%d->%d) "
  40773. + "unexpected (ri=%d,li=%d)",
  40774. + state->id, msg_type_str(type),
  40775. + (unsigned int)header,
  40776. + remoteport, localport,
  40777. + queue->remote_insert,
  40778. + queue->local_insert);
  40779. + mutex_unlock(&service->bulk_mutex);
  40780. + break;
  40781. + }
  40782. +
  40783. + BUG_ON(queue->process == queue->local_insert);
  40784. + BUG_ON(queue->process != queue->remote_insert);
  40785. +
  40786. + bulk = &queue->bulks[
  40787. + BULK_INDEX(queue->remote_insert)];
  40788. + bulk->actual = *(int *)header->data;
  40789. + queue->remote_insert++;
  40790. +
  40791. + vchiq_log_info(vchiq_core_log_level,
  40792. + "%d: prs %s@%x (%d->%d) %x@%x",
  40793. + state->id, msg_type_str(type),
  40794. + (unsigned int)header,
  40795. + remoteport, localport,
  40796. + bulk->actual, (unsigned int)bulk->data);
  40797. +
  40798. + vchiq_log_trace(vchiq_core_log_level,
  40799. + "%d: prs:%d %cx li=%x ri=%x p=%x",
  40800. + state->id, localport,
  40801. + (type == VCHIQ_MSG_BULK_RX_DONE) ?
  40802. + 'r' : 't',
  40803. + queue->local_insert,
  40804. + queue->remote_insert, queue->process);
  40805. +
  40806. + DEBUG_TRACE(PARSE_LINE);
  40807. + WARN_ON(queue->process == queue->local_insert);
  40808. + vchiq_complete_bulk(bulk);
  40809. + queue->process++;
  40810. + mutex_unlock(&service->bulk_mutex);
  40811. + DEBUG_TRACE(PARSE_LINE);
  40812. + notify_bulks(service, queue, 1/*retry_poll*/);
  40813. + DEBUG_TRACE(PARSE_LINE);
  40814. + }
  40815. + break;
  40816. + case VCHIQ_MSG_PADDING:
  40817. + vchiq_log_trace(vchiq_core_log_level,
  40818. + "%d: prs PADDING@%x,%x",
  40819. + state->id, (unsigned int)header, size);
  40820. + break;
  40821. + case VCHIQ_MSG_PAUSE:
  40822. + /* If initiated, signal the application thread */
  40823. + vchiq_log_trace(vchiq_core_log_level,
  40824. + "%d: prs PAUSE@%x,%x",
  40825. + state->id, (unsigned int)header, size);
  40826. + if (state->conn_state == VCHIQ_CONNSTATE_PAUSED) {
  40827. + vchiq_log_error(vchiq_core_log_level,
  40828. + "%d: PAUSE received in state PAUSED",
  40829. + state->id);
  40830. + break;
  40831. + }
  40832. + if (state->conn_state != VCHIQ_CONNSTATE_PAUSE_SENT) {
  40833. + /* Send a PAUSE in response */
  40834. + if (queue_message(state, NULL,
  40835. + VCHIQ_MAKE_MSG(VCHIQ_MSG_PAUSE, 0, 0),
  40836. + NULL, 0, 0, QMFLAGS_NO_MUTEX_UNLOCK)
  40837. + == VCHIQ_RETRY)
  40838. + goto bail_not_ready;
  40839. + if (state->is_master)
  40840. + pause_bulks(state);
  40841. + }
  40842. + /* At this point slot_mutex is held */
  40843. + vchiq_set_conn_state(state, VCHIQ_CONNSTATE_PAUSED);
  40844. + vchiq_platform_paused(state);
  40845. + break;
  40846. + case VCHIQ_MSG_RESUME:
  40847. + vchiq_log_trace(vchiq_core_log_level,
  40848. + "%d: prs RESUME@%x,%x",
  40849. + state->id, (unsigned int)header, size);
  40850. + /* Release the slot mutex */
  40851. + mutex_unlock(&state->slot_mutex);
  40852. + if (state->is_master)
  40853. + resume_bulks(state);
  40854. + vchiq_set_conn_state(state, VCHIQ_CONNSTATE_CONNECTED);
  40855. + vchiq_platform_resumed(state);
  40856. + break;
  40857. +
  40858. + case VCHIQ_MSG_REMOTE_USE:
  40859. + vchiq_on_remote_use(state);
  40860. + break;
  40861. + case VCHIQ_MSG_REMOTE_RELEASE:
  40862. + vchiq_on_remote_release(state);
  40863. + break;
  40864. + case VCHIQ_MSG_REMOTE_USE_ACTIVE:
  40865. + vchiq_on_remote_use_active(state);
  40866. + break;
  40867. +
  40868. + default:
  40869. + vchiq_log_error(vchiq_core_log_level,
  40870. + "%d: prs invalid msgid %x@%x,%x",
  40871. + state->id, msgid, (unsigned int)header, size);
  40872. + WARN(1, "invalid message\n");
  40873. + break;
  40874. + }
  40875. +
  40876. +skip_message:
  40877. + if (service) {
  40878. + unlock_service(service);
  40879. + service = NULL;
  40880. + }
  40881. +
  40882. + state->rx_pos += calc_stride(size);
  40883. +
  40884. + DEBUG_TRACE(PARSE_LINE);
  40885. + /* Perform some housekeeping when the end of the slot is
  40886. + ** reached. */
  40887. + if ((state->rx_pos & VCHIQ_SLOT_MASK) == 0) {
  40888. + /* Remove the extra reference count. */
  40889. + release_slot(state, state->rx_info, NULL, NULL);
  40890. + state->rx_data = NULL;
  40891. + }
  40892. + }
  40893. +
  40894. +bail_not_ready:
  40895. + if (service)
  40896. + unlock_service(service);
  40897. +}
  40898. +
  40899. +/* Called by the slot handler thread */
  40900. +static int
  40901. +slot_handler_func(void *v)
  40902. +{
  40903. + VCHIQ_STATE_T *state = (VCHIQ_STATE_T *) v;
  40904. + VCHIQ_SHARED_STATE_T *local = state->local;
  40905. + DEBUG_INITIALISE(local)
  40906. +
  40907. + while (1) {
  40908. + DEBUG_COUNT(SLOT_HANDLER_COUNT);
  40909. + DEBUG_TRACE(SLOT_HANDLER_LINE);
  40910. + remote_event_wait(&local->trigger);
  40911. +
  40912. + rmb();
  40913. +
  40914. + DEBUG_TRACE(SLOT_HANDLER_LINE);
  40915. + if (state->poll_needed) {
  40916. + /* Check if we need to suspend - may change our
  40917. + * conn_state */
  40918. + vchiq_platform_check_suspend(state);
  40919. +
  40920. + state->poll_needed = 0;
  40921. +
  40922. + /* Handle service polling and other rare conditions here
  40923. + ** out of the mainline code */
  40924. + switch (state->conn_state) {
  40925. + case VCHIQ_CONNSTATE_CONNECTED:
  40926. + /* Poll the services as requested */
  40927. + poll_services(state);
  40928. + break;
  40929. +
  40930. + case VCHIQ_CONNSTATE_PAUSING:
  40931. + if (state->is_master)
  40932. + pause_bulks(state);
  40933. + if (queue_message(state, NULL,
  40934. + VCHIQ_MAKE_MSG(VCHIQ_MSG_PAUSE, 0, 0),
  40935. + NULL, 0, 0,
  40936. + QMFLAGS_NO_MUTEX_UNLOCK)
  40937. + != VCHIQ_RETRY) {
  40938. + vchiq_set_conn_state(state,
  40939. + VCHIQ_CONNSTATE_PAUSE_SENT);
  40940. + } else {
  40941. + if (state->is_master)
  40942. + resume_bulks(state);
  40943. + /* Retry later */
  40944. + state->poll_needed = 1;
  40945. + }
  40946. + break;
  40947. +
  40948. + case VCHIQ_CONNSTATE_PAUSED:
  40949. + vchiq_platform_resume(state);
  40950. + break;
  40951. +
  40952. + case VCHIQ_CONNSTATE_RESUMING:
  40953. + if (queue_message(state, NULL,
  40954. + VCHIQ_MAKE_MSG(VCHIQ_MSG_RESUME, 0, 0),
  40955. + NULL, 0, 0, QMFLAGS_NO_MUTEX_LOCK)
  40956. + != VCHIQ_RETRY) {
  40957. + if (state->is_master)
  40958. + resume_bulks(state);
  40959. + vchiq_set_conn_state(state,
  40960. + VCHIQ_CONNSTATE_CONNECTED);
  40961. + vchiq_platform_resumed(state);
  40962. + } else {
  40963. + /* This should really be impossible,
  40964. + ** since the PAUSE should have flushed
  40965. + ** through outstanding messages. */
  40966. + vchiq_log_error(vchiq_core_log_level,
  40967. + "Failed to send RESUME "
  40968. + "message");
  40969. + BUG();
  40970. + }
  40971. + break;
  40972. +
  40973. + case VCHIQ_CONNSTATE_PAUSE_TIMEOUT:
  40974. + case VCHIQ_CONNSTATE_RESUME_TIMEOUT:
  40975. + vchiq_platform_handle_timeout(state);
  40976. + break;
  40977. + default:
  40978. + break;
  40979. + }
  40980. +
  40981. +
  40982. + }
  40983. +
  40984. + DEBUG_TRACE(SLOT_HANDLER_LINE);
  40985. + parse_rx_slots(state);
  40986. + }
  40987. + return 0;
  40988. +}
  40989. +
  40990. +
  40991. +/* Called by the recycle thread */
  40992. +static int
  40993. +recycle_func(void *v)
  40994. +{
  40995. + VCHIQ_STATE_T *state = (VCHIQ_STATE_T *) v;
  40996. + VCHIQ_SHARED_STATE_T *local = state->local;
  40997. +
  40998. + while (1) {
  40999. + remote_event_wait(&local->recycle);
  41000. +
  41001. + process_free_queue(state);
  41002. + }
  41003. + return 0;
  41004. +}
  41005. +
  41006. +
  41007. +/* Called by the sync thread */
  41008. +static int
  41009. +sync_func(void *v)
  41010. +{
  41011. + VCHIQ_STATE_T *state = (VCHIQ_STATE_T *) v;
  41012. + VCHIQ_SHARED_STATE_T *local = state->local;
  41013. + VCHIQ_HEADER_T *header = (VCHIQ_HEADER_T *)SLOT_DATA_FROM_INDEX(state,
  41014. + state->remote->slot_sync);
  41015. +
  41016. + while (1) {
  41017. + VCHIQ_SERVICE_T *service;
  41018. + int msgid, size;
  41019. + int type;
  41020. + unsigned int localport, remoteport;
  41021. +
  41022. + remote_event_wait(&local->sync_trigger);
  41023. +
  41024. + rmb();
  41025. +
  41026. + msgid = header->msgid;
  41027. + size = header->size;
  41028. + type = VCHIQ_MSG_TYPE(msgid);
  41029. + localport = VCHIQ_MSG_DSTPORT(msgid);
  41030. + remoteport = VCHIQ_MSG_SRCPORT(msgid);
  41031. +
  41032. + service = find_service_by_port(state, localport);
  41033. +
  41034. + if (!service) {
  41035. + vchiq_log_error(vchiq_sync_log_level,
  41036. + "%d: sf %s@%x (%d->%d) - "
  41037. + "invalid/closed service %d",
  41038. + state->id, msg_type_str(type),
  41039. + (unsigned int)header,
  41040. + remoteport, localport, localport);
  41041. + release_message_sync(state, header);
  41042. + continue;
  41043. + }
  41044. +
  41045. + if (vchiq_sync_log_level >= VCHIQ_LOG_TRACE) {
  41046. + int svc_fourcc;
  41047. +
  41048. + svc_fourcc = service
  41049. + ? service->base.fourcc
  41050. + : VCHIQ_MAKE_FOURCC('?', '?', '?', '?');
  41051. + vchiq_log_trace(vchiq_sync_log_level,
  41052. + "Rcvd Msg %s from %c%c%c%c s:%d d:%d len:%d",
  41053. + msg_type_str(type),
  41054. + VCHIQ_FOURCC_AS_4CHARS(svc_fourcc),
  41055. + remoteport, localport, size);
  41056. + if (size > 0)
  41057. + vchiq_log_dump_mem("Rcvd", 0, header->data,
  41058. + min(64, size));
  41059. + }
  41060. +
  41061. + switch (type) {
  41062. + case VCHIQ_MSG_OPENACK:
  41063. + if (size >= sizeof(struct vchiq_openack_payload)) {
  41064. + const struct vchiq_openack_payload *payload =
  41065. + (struct vchiq_openack_payload *)
  41066. + header->data;
  41067. + service->peer_version = payload->version;
  41068. + }
  41069. + vchiq_log_info(vchiq_sync_log_level,
  41070. + "%d: sf OPENACK@%x,%x (%d->%d) v:%d",
  41071. + state->id, (unsigned int)header, size,
  41072. + remoteport, localport, service->peer_version);
  41073. + if (service->srvstate == VCHIQ_SRVSTATE_OPENING) {
  41074. + service->remoteport = remoteport;
  41075. + vchiq_set_service_state(service,
  41076. + VCHIQ_SRVSTATE_OPENSYNC);
  41077. + service->sync = 1;
  41078. + up(&service->remove_event);
  41079. + }
  41080. + release_message_sync(state, header);
  41081. + break;
  41082. +
  41083. + case VCHIQ_MSG_DATA:
  41084. + vchiq_log_trace(vchiq_sync_log_level,
  41085. + "%d: sf DATA@%x,%x (%d->%d)",
  41086. + state->id, (unsigned int)header, size,
  41087. + remoteport, localport);
  41088. +
  41089. + if ((service->remoteport == remoteport) &&
  41090. + (service->srvstate ==
  41091. + VCHIQ_SRVSTATE_OPENSYNC)) {
  41092. + if (make_service_callback(service,
  41093. + VCHIQ_MESSAGE_AVAILABLE, header,
  41094. + NULL) == VCHIQ_RETRY)
  41095. + vchiq_log_error(vchiq_sync_log_level,
  41096. + "synchronous callback to "
  41097. + "service %d returns "
  41098. + "VCHIQ_RETRY",
  41099. + localport);
  41100. + }
  41101. + break;
  41102. +
  41103. + default:
  41104. + vchiq_log_error(vchiq_sync_log_level,
  41105. + "%d: sf unexpected msgid %x@%x,%x",
  41106. + state->id, msgid, (unsigned int)header, size);
  41107. + release_message_sync(state, header);
  41108. + break;
  41109. + }
  41110. +
  41111. + unlock_service(service);
  41112. + }
  41113. +
  41114. + return 0;
  41115. +}
  41116. +
  41117. +
  41118. +static void
  41119. +init_bulk_queue(VCHIQ_BULK_QUEUE_T *queue)
  41120. +{
  41121. + queue->local_insert = 0;
  41122. + queue->remote_insert = 0;
  41123. + queue->process = 0;
  41124. + queue->remote_notify = 0;
  41125. + queue->remove = 0;
  41126. +}
  41127. +
  41128. +
  41129. +inline const char *
  41130. +get_conn_state_name(VCHIQ_CONNSTATE_T conn_state)
  41131. +{
  41132. + return conn_state_names[conn_state];
  41133. +}
  41134. +
  41135. +
  41136. +VCHIQ_SLOT_ZERO_T *
  41137. +vchiq_init_slots(void *mem_base, int mem_size)
  41138. +{
  41139. + int mem_align = (VCHIQ_SLOT_SIZE - (int)mem_base) & VCHIQ_SLOT_MASK;
  41140. + VCHIQ_SLOT_ZERO_T *slot_zero =
  41141. + (VCHIQ_SLOT_ZERO_T *)((char *)mem_base + mem_align);
  41142. + int num_slots = (mem_size - mem_align)/VCHIQ_SLOT_SIZE;
  41143. + int first_data_slot = VCHIQ_SLOT_ZERO_SLOTS;
  41144. +
  41145. + /* Ensure there is enough memory to run an absolutely minimum system */
  41146. + num_slots -= first_data_slot;
  41147. +
  41148. + if (num_slots < 4) {
  41149. + vchiq_log_error(vchiq_core_log_level,
  41150. + "vchiq_init_slots - insufficient memory %x bytes",
  41151. + mem_size);
  41152. + return NULL;
  41153. + }
  41154. +
  41155. + memset(slot_zero, 0, sizeof(VCHIQ_SLOT_ZERO_T));
  41156. +
  41157. + slot_zero->magic = VCHIQ_MAGIC;
  41158. + slot_zero->version = VCHIQ_VERSION;
  41159. + slot_zero->version_min = VCHIQ_VERSION_MIN;
  41160. + slot_zero->slot_zero_size = sizeof(VCHIQ_SLOT_ZERO_T);
  41161. + slot_zero->slot_size = VCHIQ_SLOT_SIZE;
  41162. + slot_zero->max_slots = VCHIQ_MAX_SLOTS;
  41163. + slot_zero->max_slots_per_side = VCHIQ_MAX_SLOTS_PER_SIDE;
  41164. +
  41165. + slot_zero->master.slot_sync = first_data_slot;
  41166. + slot_zero->master.slot_first = first_data_slot + 1;
  41167. + slot_zero->master.slot_last = first_data_slot + (num_slots/2) - 1;
  41168. + slot_zero->slave.slot_sync = first_data_slot + (num_slots/2);
  41169. + slot_zero->slave.slot_first = first_data_slot + (num_slots/2) + 1;
  41170. + slot_zero->slave.slot_last = first_data_slot + num_slots - 1;
  41171. +
  41172. + return slot_zero;
  41173. +}
  41174. +
  41175. +VCHIQ_STATUS_T
  41176. +vchiq_init_state(VCHIQ_STATE_T *state, VCHIQ_SLOT_ZERO_T *slot_zero,
  41177. + int is_master)
  41178. +{
  41179. + VCHIQ_SHARED_STATE_T *local;
  41180. + VCHIQ_SHARED_STATE_T *remote;
  41181. + VCHIQ_STATUS_T status;
  41182. + char threadname[10];
  41183. + static int id;
  41184. + int i;
  41185. +
  41186. + vchiq_log_warning(vchiq_core_log_level,
  41187. + "%s: slot_zero = 0x%08lx, is_master = %d",
  41188. + __func__, (unsigned long)slot_zero, is_master);
  41189. +
  41190. + /* Check the input configuration */
  41191. +
  41192. + if (slot_zero->magic != VCHIQ_MAGIC) {
  41193. + vchiq_loud_error_header();
  41194. + vchiq_loud_error("Invalid VCHIQ magic value found.");
  41195. + vchiq_loud_error("slot_zero=%x: magic=%x (expected %x)",
  41196. + (unsigned int)slot_zero, slot_zero->magic, VCHIQ_MAGIC);
  41197. + vchiq_loud_error_footer();
  41198. + return VCHIQ_ERROR;
  41199. + }
  41200. +
  41201. + if (slot_zero->version < VCHIQ_VERSION_MIN) {
  41202. + vchiq_loud_error_header();
  41203. + vchiq_loud_error("Incompatible VCHIQ versions found.");
  41204. + vchiq_loud_error("slot_zero=%x: VideoCore version=%d "
  41205. + "(minimum %d)",
  41206. + (unsigned int)slot_zero, slot_zero->version,
  41207. + VCHIQ_VERSION_MIN);
  41208. + vchiq_loud_error("Restart with a newer VideoCore image.");
  41209. + vchiq_loud_error_footer();
  41210. + return VCHIQ_ERROR;
  41211. + }
  41212. +
  41213. + if (VCHIQ_VERSION < slot_zero->version_min) {
  41214. + vchiq_loud_error_header();
  41215. + vchiq_loud_error("Incompatible VCHIQ versions found.");
  41216. + vchiq_loud_error("slot_zero=%x: version=%d (VideoCore "
  41217. + "minimum %d)",
  41218. + (unsigned int)slot_zero, VCHIQ_VERSION,
  41219. + slot_zero->version_min);
  41220. + vchiq_loud_error("Restart with a newer kernel.");
  41221. + vchiq_loud_error_footer();
  41222. + return VCHIQ_ERROR;
  41223. + }
  41224. +
  41225. + if ((slot_zero->slot_zero_size != sizeof(VCHIQ_SLOT_ZERO_T)) ||
  41226. + (slot_zero->slot_size != VCHIQ_SLOT_SIZE) ||
  41227. + (slot_zero->max_slots != VCHIQ_MAX_SLOTS) ||
  41228. + (slot_zero->max_slots_per_side != VCHIQ_MAX_SLOTS_PER_SIDE)) {
  41229. + vchiq_loud_error_header();
  41230. + if (slot_zero->slot_zero_size != sizeof(VCHIQ_SLOT_ZERO_T))
  41231. + vchiq_loud_error("slot_zero=%x: slot_zero_size=%x "
  41232. + "(expected %x)",
  41233. + (unsigned int)slot_zero,
  41234. + slot_zero->slot_zero_size,
  41235. + sizeof(VCHIQ_SLOT_ZERO_T));
  41236. + if (slot_zero->slot_size != VCHIQ_SLOT_SIZE)
  41237. + vchiq_loud_error("slot_zero=%x: slot_size=%d "
  41238. + "(expected %d",
  41239. + (unsigned int)slot_zero, slot_zero->slot_size,
  41240. + VCHIQ_SLOT_SIZE);
  41241. + if (slot_zero->max_slots != VCHIQ_MAX_SLOTS)
  41242. + vchiq_loud_error("slot_zero=%x: max_slots=%d "
  41243. + "(expected %d)",
  41244. + (unsigned int)slot_zero, slot_zero->max_slots,
  41245. + VCHIQ_MAX_SLOTS);
  41246. + if (slot_zero->max_slots_per_side != VCHIQ_MAX_SLOTS_PER_SIDE)
  41247. + vchiq_loud_error("slot_zero=%x: max_slots_per_side=%d "
  41248. + "(expected %d)",
  41249. + (unsigned int)slot_zero,
  41250. + slot_zero->max_slots_per_side,
  41251. + VCHIQ_MAX_SLOTS_PER_SIDE);
  41252. + vchiq_loud_error_footer();
  41253. + return VCHIQ_ERROR;
  41254. + }
  41255. +
  41256. + if (VCHIQ_VERSION < slot_zero->version)
  41257. + slot_zero->version = VCHIQ_VERSION;
  41258. +
  41259. + if (is_master) {
  41260. + local = &slot_zero->master;
  41261. + remote = &slot_zero->slave;
  41262. + } else {
  41263. + local = &slot_zero->slave;
  41264. + remote = &slot_zero->master;
  41265. + }
  41266. +
  41267. + if (local->initialised) {
  41268. + vchiq_loud_error_header();
  41269. + if (remote->initialised)
  41270. + vchiq_loud_error("local state has already been "
  41271. + "initialised");
  41272. + else
  41273. + vchiq_loud_error("master/slave mismatch - two %ss",
  41274. + is_master ? "master" : "slave");
  41275. + vchiq_loud_error_footer();
  41276. + return VCHIQ_ERROR;
  41277. + }
  41278. +
  41279. + memset(state, 0, sizeof(VCHIQ_STATE_T));
  41280. +
  41281. + state->id = id++;
  41282. + state->is_master = is_master;
  41283. +
  41284. + /*
  41285. + initialize shared state pointers
  41286. + */
  41287. +
  41288. + state->local = local;
  41289. + state->remote = remote;
  41290. + state->slot_data = (VCHIQ_SLOT_T *)slot_zero;
  41291. +
  41292. + /*
  41293. + initialize events and mutexes
  41294. + */
  41295. +
  41296. + sema_init(&state->connect, 0);
  41297. + mutex_init(&state->mutex);
  41298. + sema_init(&state->trigger_event, 0);
  41299. + sema_init(&state->recycle_event, 0);
  41300. + sema_init(&state->sync_trigger_event, 0);
  41301. + sema_init(&state->sync_release_event, 0);
  41302. +
  41303. + mutex_init(&state->slot_mutex);
  41304. + mutex_init(&state->recycle_mutex);
  41305. + mutex_init(&state->sync_mutex);
  41306. + mutex_init(&state->bulk_transfer_mutex);
  41307. +
  41308. + sema_init(&state->slot_available_event, 0);
  41309. + sema_init(&state->slot_remove_event, 0);
  41310. + sema_init(&state->data_quota_event, 0);
  41311. +
  41312. + state->slot_queue_available = 0;
  41313. +
  41314. + for (i = 0; i < VCHIQ_MAX_SERVICES; i++) {
  41315. + VCHIQ_SERVICE_QUOTA_T *service_quota =
  41316. + &state->service_quotas[i];
  41317. + sema_init(&service_quota->quota_event, 0);
  41318. + }
  41319. +
  41320. + for (i = local->slot_first; i <= local->slot_last; i++) {
  41321. + local->slot_queue[state->slot_queue_available++] = i;
  41322. + up(&state->slot_available_event);
  41323. + }
  41324. +
  41325. + state->default_slot_quota = state->slot_queue_available/2;
  41326. + state->default_message_quota =
  41327. + min((unsigned short)(state->default_slot_quota * 256),
  41328. + (unsigned short)~0);
  41329. +
  41330. + state->previous_data_index = -1;
  41331. + state->data_use_count = 0;
  41332. + state->data_quota = state->slot_queue_available - 1;
  41333. +
  41334. + local->trigger.event = &state->trigger_event;
  41335. + remote_event_create(&local->trigger);
  41336. + local->tx_pos = 0;
  41337. +
  41338. + local->recycle.event = &state->recycle_event;
  41339. + remote_event_create(&local->recycle);
  41340. + local->slot_queue_recycle = state->slot_queue_available;
  41341. +
  41342. + local->sync_trigger.event = &state->sync_trigger_event;
  41343. + remote_event_create(&local->sync_trigger);
  41344. +
  41345. + local->sync_release.event = &state->sync_release_event;
  41346. + remote_event_create(&local->sync_release);
  41347. +
  41348. + /* At start-of-day, the slot is empty and available */
  41349. + ((VCHIQ_HEADER_T *)SLOT_DATA_FROM_INDEX(state, local->slot_sync))->msgid
  41350. + = VCHIQ_MSGID_PADDING;
  41351. + remote_event_signal_local(&local->sync_release);
  41352. +
  41353. + local->debug[DEBUG_ENTRIES] = DEBUG_MAX;
  41354. +
  41355. + status = vchiq_platform_init_state(state);
  41356. +
  41357. + /*
  41358. + bring up slot handler thread
  41359. + */
  41360. + snprintf(threadname, sizeof(threadname), "VCHIQ-%d", state->id);
  41361. + state->slot_handler_thread = kthread_create(&slot_handler_func,
  41362. + (void *)state,
  41363. + threadname);
  41364. +
  41365. + if (state->slot_handler_thread == NULL) {
  41366. + vchiq_loud_error_header();
  41367. + vchiq_loud_error("couldn't create thread %s", threadname);
  41368. + vchiq_loud_error_footer();
  41369. + return VCHIQ_ERROR;
  41370. + }
  41371. + set_user_nice(state->slot_handler_thread, -19);
  41372. + wake_up_process(state->slot_handler_thread);
  41373. +
  41374. + snprintf(threadname, sizeof(threadname), "VCHIQr-%d", state->id);
  41375. + state->recycle_thread = kthread_create(&recycle_func,
  41376. + (void *)state,
  41377. + threadname);
  41378. + if (state->recycle_thread == NULL) {
  41379. + vchiq_loud_error_header();
  41380. + vchiq_loud_error("couldn't create thread %s", threadname);
  41381. + vchiq_loud_error_footer();
  41382. + return VCHIQ_ERROR;
  41383. + }
  41384. + set_user_nice(state->recycle_thread, -19);
  41385. + wake_up_process(state->recycle_thread);
  41386. +
  41387. + snprintf(threadname, sizeof(threadname), "VCHIQs-%d", state->id);
  41388. + state->sync_thread = kthread_create(&sync_func,
  41389. + (void *)state,
  41390. + threadname);
  41391. + if (state->sync_thread == NULL) {
  41392. + vchiq_loud_error_header();
  41393. + vchiq_loud_error("couldn't create thread %s", threadname);
  41394. + vchiq_loud_error_footer();
  41395. + return VCHIQ_ERROR;
  41396. + }
  41397. + set_user_nice(state->sync_thread, -20);
  41398. + wake_up_process(state->sync_thread);
  41399. +
  41400. + BUG_ON(state->id >= VCHIQ_MAX_STATES);
  41401. + vchiq_states[state->id] = state;
  41402. +
  41403. + /* Indicate readiness to the other side */
  41404. + local->initialised = 1;
  41405. +
  41406. + return status;
  41407. +}
  41408. +
  41409. +/* Called from application thread when a client or server service is created. */
  41410. +VCHIQ_SERVICE_T *
  41411. +vchiq_add_service_internal(VCHIQ_STATE_T *state,
  41412. + const VCHIQ_SERVICE_PARAMS_T *params, int srvstate,
  41413. + VCHIQ_INSTANCE_T instance, VCHIQ_USERDATA_TERM_T userdata_term)
  41414. +{
  41415. + VCHIQ_SERVICE_T *service;
  41416. +
  41417. + service = kmalloc(sizeof(VCHIQ_SERVICE_T), GFP_KERNEL);
  41418. + if (service) {
  41419. + service->base.fourcc = params->fourcc;
  41420. + service->base.callback = params->callback;
  41421. + service->base.userdata = params->userdata;
  41422. + service->handle = VCHIQ_SERVICE_HANDLE_INVALID;
  41423. + service->ref_count = 1;
  41424. + service->srvstate = VCHIQ_SRVSTATE_FREE;
  41425. + service->userdata_term = userdata_term;
  41426. + service->localport = VCHIQ_PORT_FREE;
  41427. + service->remoteport = VCHIQ_PORT_FREE;
  41428. +
  41429. + service->public_fourcc = (srvstate == VCHIQ_SRVSTATE_OPENING) ?
  41430. + VCHIQ_FOURCC_INVALID : params->fourcc;
  41431. + service->client_id = 0;
  41432. + service->auto_close = 1;
  41433. + service->sync = 0;
  41434. + service->closing = 0;
  41435. + service->trace = 0;
  41436. + atomic_set(&service->poll_flags, 0);
  41437. + service->version = params->version;
  41438. + service->version_min = params->version_min;
  41439. + service->state = state;
  41440. + service->instance = instance;
  41441. + service->service_use_count = 0;
  41442. + init_bulk_queue(&service->bulk_tx);
  41443. + init_bulk_queue(&service->bulk_rx);
  41444. + sema_init(&service->remove_event, 0);
  41445. + sema_init(&service->bulk_remove_event, 0);
  41446. + mutex_init(&service->bulk_mutex);
  41447. + memset(&service->stats, 0, sizeof(service->stats));
  41448. + } else {
  41449. + vchiq_log_error(vchiq_core_log_level,
  41450. + "Out of memory");
  41451. + }
  41452. +
  41453. + if (service) {
  41454. + VCHIQ_SERVICE_T **pservice = NULL;
  41455. + int i;
  41456. +
  41457. + /* Although it is perfectly possible to use service_spinlock
  41458. + ** to protect the creation of services, it is overkill as it
  41459. + ** disables interrupts while the array is searched.
  41460. + ** The only danger is of another thread trying to create a
  41461. + ** service - service deletion is safe.
  41462. + ** Therefore it is preferable to use state->mutex which,
  41463. + ** although slower to claim, doesn't block interrupts while
  41464. + ** it is held.
  41465. + */
  41466. +
  41467. + mutex_lock(&state->mutex);
  41468. +
  41469. + /* Prepare to use a previously unused service */
  41470. + if (state->unused_service < VCHIQ_MAX_SERVICES)
  41471. + pservice = &state->services[state->unused_service];
  41472. +
  41473. + if (srvstate == VCHIQ_SRVSTATE_OPENING) {
  41474. + for (i = 0; i < state->unused_service; i++) {
  41475. + VCHIQ_SERVICE_T *srv = state->services[i];
  41476. + if (!srv) {
  41477. + pservice = &state->services[i];
  41478. + break;
  41479. + }
  41480. + }
  41481. + } else {
  41482. + for (i = (state->unused_service - 1); i >= 0; i--) {
  41483. + VCHIQ_SERVICE_T *srv = state->services[i];
  41484. + if (!srv)
  41485. + pservice = &state->services[i];
  41486. + else if ((srv->public_fourcc == params->fourcc)
  41487. + && ((srv->instance != instance) ||
  41488. + (srv->base.callback !=
  41489. + params->callback))) {
  41490. + /* There is another server using this
  41491. + ** fourcc which doesn't match. */
  41492. + pservice = NULL;
  41493. + break;
  41494. + }
  41495. + }
  41496. + }
  41497. +
  41498. + if (pservice) {
  41499. + service->localport = (pservice - state->services);
  41500. + if (!handle_seq)
  41501. + handle_seq = VCHIQ_MAX_STATES *
  41502. + VCHIQ_MAX_SERVICES;
  41503. + service->handle = handle_seq |
  41504. + (state->id * VCHIQ_MAX_SERVICES) |
  41505. + service->localport;
  41506. + handle_seq += VCHIQ_MAX_STATES * VCHIQ_MAX_SERVICES;
  41507. + *pservice = service;
  41508. + if (pservice == &state->services[state->unused_service])
  41509. + state->unused_service++;
  41510. + }
  41511. +
  41512. + mutex_unlock(&state->mutex);
  41513. +
  41514. + if (!pservice) {
  41515. + kfree(service);
  41516. + service = NULL;
  41517. + }
  41518. + }
  41519. +
  41520. + if (service) {
  41521. + VCHIQ_SERVICE_QUOTA_T *service_quota =
  41522. + &state->service_quotas[service->localport];
  41523. + service_quota->slot_quota = state->default_slot_quota;
  41524. + service_quota->message_quota = state->default_message_quota;
  41525. + if (service_quota->slot_use_count == 0)
  41526. + service_quota->previous_tx_index =
  41527. + SLOT_QUEUE_INDEX_FROM_POS(state->local_tx_pos)
  41528. + - 1;
  41529. +
  41530. + /* Bring this service online */
  41531. + vchiq_set_service_state(service, srvstate);
  41532. +
  41533. + vchiq_log_info(vchiq_core_msg_log_level,
  41534. + "%s Service %c%c%c%c SrcPort:%d",
  41535. + (srvstate == VCHIQ_SRVSTATE_OPENING)
  41536. + ? "Open" : "Add",
  41537. + VCHIQ_FOURCC_AS_4CHARS(params->fourcc),
  41538. + service->localport);
  41539. + }
  41540. +
  41541. + /* Don't unlock the service - leave it with a ref_count of 1. */
  41542. +
  41543. + return service;
  41544. +}
  41545. +
  41546. +VCHIQ_STATUS_T
  41547. +vchiq_open_service_internal(VCHIQ_SERVICE_T *service, int client_id)
  41548. +{
  41549. + struct vchiq_open_payload payload = {
  41550. + service->base.fourcc,
  41551. + client_id,
  41552. + service->version,
  41553. + service->version_min
  41554. + };
  41555. + VCHIQ_ELEMENT_T body = { &payload, sizeof(payload) };
  41556. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  41557. +
  41558. + service->client_id = client_id;
  41559. + vchiq_use_service_internal(service);
  41560. + status = queue_message(service->state, NULL,
  41561. + VCHIQ_MAKE_MSG(VCHIQ_MSG_OPEN, service->localport, 0),
  41562. + &body, 1, sizeof(payload), QMFLAGS_IS_BLOCKING);
  41563. + if (status == VCHIQ_SUCCESS) {
  41564. + /* Wait for the ACK/NAK */
  41565. + if (down_interruptible(&service->remove_event) != 0) {
  41566. + status = VCHIQ_RETRY;
  41567. + vchiq_release_service_internal(service);
  41568. + } else if ((service->srvstate != VCHIQ_SRVSTATE_OPEN) &&
  41569. + (service->srvstate != VCHIQ_SRVSTATE_OPENSYNC)) {
  41570. + if (service->srvstate != VCHIQ_SRVSTATE_CLOSEWAIT)
  41571. + vchiq_log_error(vchiq_core_log_level,
  41572. + "%d: osi - srvstate = %s (ref %d)",
  41573. + service->state->id,
  41574. + srvstate_names[service->srvstate],
  41575. + service->ref_count);
  41576. + status = VCHIQ_ERROR;
  41577. + VCHIQ_SERVICE_STATS_INC(service, error_count);
  41578. + vchiq_release_service_internal(service);
  41579. + }
  41580. + }
  41581. + return status;
  41582. +}
  41583. +
  41584. +static void
  41585. +release_service_messages(VCHIQ_SERVICE_T *service)
  41586. +{
  41587. + VCHIQ_STATE_T *state = service->state;
  41588. + int slot_last = state->remote->slot_last;
  41589. + int i;
  41590. +
  41591. + /* Release any claimed messages aimed at this service */
  41592. +
  41593. + if (service->sync) {
  41594. + VCHIQ_HEADER_T *header =
  41595. + (VCHIQ_HEADER_T *)SLOT_DATA_FROM_INDEX(state,
  41596. + state->remote->slot_sync);
  41597. + if (VCHIQ_MSG_DSTPORT(header->msgid) == service->localport)
  41598. + release_message_sync(state, header);
  41599. +
  41600. + return;
  41601. + }
  41602. +
  41603. + for (i = state->remote->slot_first; i <= slot_last; i++) {
  41604. + VCHIQ_SLOT_INFO_T *slot_info =
  41605. + SLOT_INFO_FROM_INDEX(state, i);
  41606. + if (slot_info->release_count != slot_info->use_count) {
  41607. + char *data =
  41608. + (char *)SLOT_DATA_FROM_INDEX(state, i);
  41609. + unsigned int pos, end;
  41610. +
  41611. + end = VCHIQ_SLOT_SIZE;
  41612. + if (data == state->rx_data)
  41613. + /* This buffer is still being read from - stop
  41614. + ** at the current read position */
  41615. + end = state->rx_pos & VCHIQ_SLOT_MASK;
  41616. +
  41617. + pos = 0;
  41618. +
  41619. + while (pos < end) {
  41620. + VCHIQ_HEADER_T *header =
  41621. + (VCHIQ_HEADER_T *)(data + pos);
  41622. + int msgid = header->msgid;
  41623. + int port = VCHIQ_MSG_DSTPORT(msgid);
  41624. + if ((port == service->localport) &&
  41625. + (msgid & VCHIQ_MSGID_CLAIMED)) {
  41626. + vchiq_log_info(vchiq_core_log_level,
  41627. + " fsi - hdr %x",
  41628. + (unsigned int)header);
  41629. + release_slot(state, slot_info, header,
  41630. + NULL);
  41631. + }
  41632. + pos += calc_stride(header->size);
  41633. + if (pos > VCHIQ_SLOT_SIZE) {
  41634. + vchiq_log_error(vchiq_core_log_level,
  41635. + "fsi - pos %x: header %x, "
  41636. + "msgid %x, header->msgid %x, "
  41637. + "header->size %x",
  41638. + pos, (unsigned int)header,
  41639. + msgid, header->msgid,
  41640. + header->size);
  41641. + WARN(1, "invalid slot position\n");
  41642. + }
  41643. + }
  41644. + }
  41645. + }
  41646. +}
  41647. +
  41648. +static int
  41649. +do_abort_bulks(VCHIQ_SERVICE_T *service)
  41650. +{
  41651. + VCHIQ_STATUS_T status;
  41652. +
  41653. + /* Abort any outstanding bulk transfers */
  41654. + if (mutex_lock_interruptible(&service->bulk_mutex) != 0)
  41655. + return 0;
  41656. + abort_outstanding_bulks(service, &service->bulk_tx);
  41657. + abort_outstanding_bulks(service, &service->bulk_rx);
  41658. + mutex_unlock(&service->bulk_mutex);
  41659. +
  41660. + status = notify_bulks(service, &service->bulk_tx, 0/*!retry_poll*/);
  41661. + if (status == VCHIQ_SUCCESS)
  41662. + status = notify_bulks(service, &service->bulk_rx,
  41663. + 0/*!retry_poll*/);
  41664. + return (status == VCHIQ_SUCCESS);
  41665. +}
  41666. +
  41667. +static VCHIQ_STATUS_T
  41668. +close_service_complete(VCHIQ_SERVICE_T *service, int failstate)
  41669. +{
  41670. + VCHIQ_STATUS_T status;
  41671. + int is_server = (service->public_fourcc != VCHIQ_FOURCC_INVALID);
  41672. + int newstate;
  41673. +
  41674. + switch (service->srvstate) {
  41675. + case VCHIQ_SRVSTATE_OPEN:
  41676. + case VCHIQ_SRVSTATE_CLOSESENT:
  41677. + case VCHIQ_SRVSTATE_CLOSERECVD:
  41678. + if (is_server) {
  41679. + if (service->auto_close) {
  41680. + service->client_id = 0;
  41681. + service->remoteport = VCHIQ_PORT_FREE;
  41682. + newstate = VCHIQ_SRVSTATE_LISTENING;
  41683. + } else
  41684. + newstate = VCHIQ_SRVSTATE_CLOSEWAIT;
  41685. + } else
  41686. + newstate = VCHIQ_SRVSTATE_CLOSED;
  41687. + vchiq_set_service_state(service, newstate);
  41688. + break;
  41689. + case VCHIQ_SRVSTATE_LISTENING:
  41690. + break;
  41691. + default:
  41692. + vchiq_log_error(vchiq_core_log_level,
  41693. + "close_service_complete(%x) called in state %s",
  41694. + service->handle, srvstate_names[service->srvstate]);
  41695. + WARN(1, "close_service_complete in unexpected state\n");
  41696. + return VCHIQ_ERROR;
  41697. + }
  41698. +
  41699. + status = make_service_callback(service,
  41700. + VCHIQ_SERVICE_CLOSED, NULL, NULL);
  41701. +
  41702. + if (status != VCHIQ_RETRY) {
  41703. + int uc = service->service_use_count;
  41704. + int i;
  41705. + /* Complete the close process */
  41706. + for (i = 0; i < uc; i++)
  41707. + /* cater for cases where close is forced and the
  41708. + ** client may not close all it's handles */
  41709. + vchiq_release_service_internal(service);
  41710. +
  41711. + service->client_id = 0;
  41712. + service->remoteport = VCHIQ_PORT_FREE;
  41713. +
  41714. + if (service->srvstate == VCHIQ_SRVSTATE_CLOSED)
  41715. + vchiq_free_service_internal(service);
  41716. + else if (service->srvstate != VCHIQ_SRVSTATE_CLOSEWAIT) {
  41717. + if (is_server)
  41718. + service->closing = 0;
  41719. +
  41720. + up(&service->remove_event);
  41721. + }
  41722. + } else
  41723. + vchiq_set_service_state(service, failstate);
  41724. +
  41725. + return status;
  41726. +}
  41727. +
  41728. +/* Called by the slot handler */
  41729. +VCHIQ_STATUS_T
  41730. +vchiq_close_service_internal(VCHIQ_SERVICE_T *service, int close_recvd)
  41731. +{
  41732. + VCHIQ_STATE_T *state = service->state;
  41733. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  41734. + int is_server = (service->public_fourcc != VCHIQ_FOURCC_INVALID);
  41735. +
  41736. + vchiq_log_info(vchiq_core_log_level, "%d: csi:%d,%d (%s)",
  41737. + service->state->id, service->localport, close_recvd,
  41738. + srvstate_names[service->srvstate]);
  41739. +
  41740. + switch (service->srvstate) {
  41741. + case VCHIQ_SRVSTATE_CLOSED:
  41742. + case VCHIQ_SRVSTATE_HIDDEN:
  41743. + case VCHIQ_SRVSTATE_LISTENING:
  41744. + case VCHIQ_SRVSTATE_CLOSEWAIT:
  41745. + if (close_recvd)
  41746. + vchiq_log_error(vchiq_core_log_level,
  41747. + "vchiq_close_service_internal(1) called "
  41748. + "in state %s",
  41749. + srvstate_names[service->srvstate]);
  41750. + else if (is_server) {
  41751. + if (service->srvstate == VCHIQ_SRVSTATE_LISTENING) {
  41752. + status = VCHIQ_ERROR;
  41753. + } else {
  41754. + service->client_id = 0;
  41755. + service->remoteport = VCHIQ_PORT_FREE;
  41756. + if (service->srvstate ==
  41757. + VCHIQ_SRVSTATE_CLOSEWAIT)
  41758. + vchiq_set_service_state(service,
  41759. + VCHIQ_SRVSTATE_LISTENING);
  41760. + }
  41761. + up(&service->remove_event);
  41762. + } else
  41763. + vchiq_free_service_internal(service);
  41764. + break;
  41765. + case VCHIQ_SRVSTATE_OPENING:
  41766. + if (close_recvd) {
  41767. + /* The open was rejected - tell the user */
  41768. + vchiq_set_service_state(service,
  41769. + VCHIQ_SRVSTATE_CLOSEWAIT);
  41770. + up(&service->remove_event);
  41771. + } else {
  41772. + /* Shutdown mid-open - let the other side know */
  41773. + status = queue_message(state, service,
  41774. + VCHIQ_MAKE_MSG
  41775. + (VCHIQ_MSG_CLOSE,
  41776. + service->localport,
  41777. + VCHIQ_MSG_DSTPORT(service->remoteport)),
  41778. + NULL, 0, 0, 0);
  41779. + }
  41780. + break;
  41781. +
  41782. + case VCHIQ_SRVSTATE_OPENSYNC:
  41783. + mutex_lock(&state->sync_mutex);
  41784. + /* Drop through */
  41785. +
  41786. + case VCHIQ_SRVSTATE_OPEN:
  41787. + if (state->is_master || close_recvd) {
  41788. + if (!do_abort_bulks(service))
  41789. + status = VCHIQ_RETRY;
  41790. + }
  41791. +
  41792. + release_service_messages(service);
  41793. +
  41794. + if (status == VCHIQ_SUCCESS)
  41795. + status = queue_message(state, service,
  41796. + VCHIQ_MAKE_MSG
  41797. + (VCHIQ_MSG_CLOSE,
  41798. + service->localport,
  41799. + VCHIQ_MSG_DSTPORT(service->remoteport)),
  41800. + NULL, 0, 0, QMFLAGS_NO_MUTEX_UNLOCK);
  41801. +
  41802. + if (status == VCHIQ_SUCCESS) {
  41803. + if (!close_recvd) {
  41804. + /* Change the state while the mutex is
  41805. + still held */
  41806. + vchiq_set_service_state(service,
  41807. + VCHIQ_SRVSTATE_CLOSESENT);
  41808. + mutex_unlock(&state->slot_mutex);
  41809. + if (service->sync)
  41810. + mutex_unlock(&state->sync_mutex);
  41811. + break;
  41812. + }
  41813. + } else if (service->srvstate == VCHIQ_SRVSTATE_OPENSYNC) {
  41814. + mutex_unlock(&state->sync_mutex);
  41815. + break;
  41816. + } else
  41817. + break;
  41818. +
  41819. + /* Change the state while the mutex is still held */
  41820. + vchiq_set_service_state(service, VCHIQ_SRVSTATE_CLOSERECVD);
  41821. + mutex_unlock(&state->slot_mutex);
  41822. + if (service->sync)
  41823. + mutex_unlock(&state->sync_mutex);
  41824. +
  41825. + status = close_service_complete(service,
  41826. + VCHIQ_SRVSTATE_CLOSERECVD);
  41827. + break;
  41828. +
  41829. + case VCHIQ_SRVSTATE_CLOSESENT:
  41830. + if (!close_recvd)
  41831. + /* This happens when a process is killed mid-close */
  41832. + break;
  41833. +
  41834. + if (!state->is_master) {
  41835. + if (!do_abort_bulks(service)) {
  41836. + status = VCHIQ_RETRY;
  41837. + break;
  41838. + }
  41839. + }
  41840. +
  41841. + if (status == VCHIQ_SUCCESS)
  41842. + status = close_service_complete(service,
  41843. + VCHIQ_SRVSTATE_CLOSERECVD);
  41844. + break;
  41845. +
  41846. + case VCHIQ_SRVSTATE_CLOSERECVD:
  41847. + if (!close_recvd && is_server)
  41848. + /* Force into LISTENING mode */
  41849. + vchiq_set_service_state(service,
  41850. + VCHIQ_SRVSTATE_LISTENING);
  41851. + status = close_service_complete(service,
  41852. + VCHIQ_SRVSTATE_CLOSERECVD);
  41853. + break;
  41854. +
  41855. + default:
  41856. + vchiq_log_error(vchiq_core_log_level,
  41857. + "vchiq_close_service_internal(%d) called in state %s",
  41858. + close_recvd, srvstate_names[service->srvstate]);
  41859. + break;
  41860. + }
  41861. +
  41862. + return status;
  41863. +}
  41864. +
  41865. +/* Called from the application process upon process death */
  41866. +void
  41867. +vchiq_terminate_service_internal(VCHIQ_SERVICE_T *service)
  41868. +{
  41869. + VCHIQ_STATE_T *state = service->state;
  41870. +
  41871. + vchiq_log_info(vchiq_core_log_level, "%d: tsi - (%d<->%d)",
  41872. + state->id, service->localport, service->remoteport);
  41873. +
  41874. + mark_service_closing(service);
  41875. +
  41876. + /* Mark the service for removal by the slot handler */
  41877. + request_poll(state, service, VCHIQ_POLL_REMOVE);
  41878. +}
  41879. +
  41880. +/* Called from the slot handler */
  41881. +void
  41882. +vchiq_free_service_internal(VCHIQ_SERVICE_T *service)
  41883. +{
  41884. + VCHIQ_STATE_T *state = service->state;
  41885. +
  41886. + vchiq_log_info(vchiq_core_log_level, "%d: fsi - (%d)",
  41887. + state->id, service->localport);
  41888. +
  41889. + switch (service->srvstate) {
  41890. + case VCHIQ_SRVSTATE_OPENING:
  41891. + case VCHIQ_SRVSTATE_CLOSED:
  41892. + case VCHIQ_SRVSTATE_HIDDEN:
  41893. + case VCHIQ_SRVSTATE_LISTENING:
  41894. + case VCHIQ_SRVSTATE_CLOSEWAIT:
  41895. + break;
  41896. + default:
  41897. + vchiq_log_error(vchiq_core_log_level,
  41898. + "%d: fsi - (%d) in state %s",
  41899. + state->id, service->localport,
  41900. + srvstate_names[service->srvstate]);
  41901. + return;
  41902. + }
  41903. +
  41904. + vchiq_set_service_state(service, VCHIQ_SRVSTATE_FREE);
  41905. +
  41906. + up(&service->remove_event);
  41907. +
  41908. + /* Release the initial lock */
  41909. + unlock_service(service);
  41910. +}
  41911. +
  41912. +VCHIQ_STATUS_T
  41913. +vchiq_connect_internal(VCHIQ_STATE_T *state, VCHIQ_INSTANCE_T instance)
  41914. +{
  41915. + VCHIQ_SERVICE_T *service;
  41916. + int i;
  41917. +
  41918. + /* Find all services registered to this client and enable them. */
  41919. + i = 0;
  41920. + while ((service = next_service_by_instance(state, instance,
  41921. + &i)) != NULL) {
  41922. + if (service->srvstate == VCHIQ_SRVSTATE_HIDDEN)
  41923. + vchiq_set_service_state(service,
  41924. + VCHIQ_SRVSTATE_LISTENING);
  41925. + unlock_service(service);
  41926. + }
  41927. +
  41928. + if (state->conn_state == VCHIQ_CONNSTATE_DISCONNECTED) {
  41929. + if (queue_message(state, NULL,
  41930. + VCHIQ_MAKE_MSG(VCHIQ_MSG_CONNECT, 0, 0), NULL, 0,
  41931. + 0, QMFLAGS_IS_BLOCKING) == VCHIQ_RETRY)
  41932. + return VCHIQ_RETRY;
  41933. +
  41934. + vchiq_set_conn_state(state, VCHIQ_CONNSTATE_CONNECTING);
  41935. + }
  41936. +
  41937. + if (state->conn_state == VCHIQ_CONNSTATE_CONNECTING) {
  41938. + if (down_interruptible(&state->connect) != 0)
  41939. + return VCHIQ_RETRY;
  41940. +
  41941. + vchiq_set_conn_state(state, VCHIQ_CONNSTATE_CONNECTED);
  41942. + up(&state->connect);
  41943. + }
  41944. +
  41945. + return VCHIQ_SUCCESS;
  41946. +}
  41947. +
  41948. +VCHIQ_STATUS_T
  41949. +vchiq_shutdown_internal(VCHIQ_STATE_T *state, VCHIQ_INSTANCE_T instance)
  41950. +{
  41951. + VCHIQ_SERVICE_T *service;
  41952. + int i;
  41953. +
  41954. + /* Find all services registered to this client and enable them. */
  41955. + i = 0;
  41956. + while ((service = next_service_by_instance(state, instance,
  41957. + &i)) != NULL) {
  41958. + (void)vchiq_remove_service(service->handle);
  41959. + unlock_service(service);
  41960. + }
  41961. +
  41962. + return VCHIQ_SUCCESS;
  41963. +}
  41964. +
  41965. +VCHIQ_STATUS_T
  41966. +vchiq_pause_internal(VCHIQ_STATE_T *state)
  41967. +{
  41968. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  41969. +
  41970. + switch (state->conn_state) {
  41971. + case VCHIQ_CONNSTATE_CONNECTED:
  41972. + /* Request a pause */
  41973. + vchiq_set_conn_state(state, VCHIQ_CONNSTATE_PAUSING);
  41974. + request_poll(state, NULL, 0);
  41975. + break;
  41976. + default:
  41977. + vchiq_log_error(vchiq_core_log_level,
  41978. + "vchiq_pause_internal in state %s\n",
  41979. + conn_state_names[state->conn_state]);
  41980. + status = VCHIQ_ERROR;
  41981. + VCHIQ_STATS_INC(state, error_count);
  41982. + break;
  41983. + }
  41984. +
  41985. + return status;
  41986. +}
  41987. +
  41988. +VCHIQ_STATUS_T
  41989. +vchiq_resume_internal(VCHIQ_STATE_T *state)
  41990. +{
  41991. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  41992. +
  41993. + if (state->conn_state == VCHIQ_CONNSTATE_PAUSED) {
  41994. + vchiq_set_conn_state(state, VCHIQ_CONNSTATE_RESUMING);
  41995. + request_poll(state, NULL, 0);
  41996. + } else {
  41997. + status = VCHIQ_ERROR;
  41998. + VCHIQ_STATS_INC(state, error_count);
  41999. + }
  42000. +
  42001. + return status;
  42002. +}
  42003. +
  42004. +VCHIQ_STATUS_T
  42005. +vchiq_close_service(VCHIQ_SERVICE_HANDLE_T handle)
  42006. +{
  42007. + /* Unregister the service */
  42008. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  42009. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  42010. +
  42011. + if (!service)
  42012. + return VCHIQ_ERROR;
  42013. +
  42014. + vchiq_log_info(vchiq_core_log_level,
  42015. + "%d: close_service:%d",
  42016. + service->state->id, service->localport);
  42017. +
  42018. + if ((service->srvstate == VCHIQ_SRVSTATE_FREE) ||
  42019. + (service->srvstate == VCHIQ_SRVSTATE_LISTENING) ||
  42020. + (service->srvstate == VCHIQ_SRVSTATE_HIDDEN)) {
  42021. + unlock_service(service);
  42022. + return VCHIQ_ERROR;
  42023. + }
  42024. +
  42025. + mark_service_closing(service);
  42026. +
  42027. + if (current == service->state->slot_handler_thread) {
  42028. + status = vchiq_close_service_internal(service,
  42029. + 0/*!close_recvd*/);
  42030. + BUG_ON(status == VCHIQ_RETRY);
  42031. + } else {
  42032. + /* Mark the service for termination by the slot handler */
  42033. + request_poll(service->state, service, VCHIQ_POLL_TERMINATE);
  42034. + }
  42035. +
  42036. + while (1) {
  42037. + if (down_interruptible(&service->remove_event) != 0) {
  42038. + status = VCHIQ_RETRY;
  42039. + break;
  42040. + }
  42041. +
  42042. + if ((service->srvstate == VCHIQ_SRVSTATE_FREE) ||
  42043. + (service->srvstate == VCHIQ_SRVSTATE_LISTENING) ||
  42044. + (service->srvstate == VCHIQ_SRVSTATE_OPEN))
  42045. + break;
  42046. +
  42047. + vchiq_log_warning(vchiq_core_log_level,
  42048. + "%d: close_service:%d - waiting in state %s",
  42049. + service->state->id, service->localport,
  42050. + srvstate_names[service->srvstate]);
  42051. + }
  42052. +
  42053. + if ((status == VCHIQ_SUCCESS) &&
  42054. + (service->srvstate != VCHIQ_SRVSTATE_FREE) &&
  42055. + (service->srvstate != VCHIQ_SRVSTATE_LISTENING))
  42056. + status = VCHIQ_ERROR;
  42057. +
  42058. + unlock_service(service);
  42059. +
  42060. + return status;
  42061. +}
  42062. +
  42063. +VCHIQ_STATUS_T
  42064. +vchiq_remove_service(VCHIQ_SERVICE_HANDLE_T handle)
  42065. +{
  42066. + /* Unregister the service */
  42067. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  42068. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  42069. +
  42070. + if (!service)
  42071. + return VCHIQ_ERROR;
  42072. +
  42073. + vchiq_log_info(vchiq_core_log_level,
  42074. + "%d: remove_service:%d",
  42075. + service->state->id, service->localport);
  42076. +
  42077. + if (service->srvstate == VCHIQ_SRVSTATE_FREE) {
  42078. + unlock_service(service);
  42079. + return VCHIQ_ERROR;
  42080. + }
  42081. +
  42082. + mark_service_closing(service);
  42083. +
  42084. + if ((service->srvstate == VCHIQ_SRVSTATE_HIDDEN) ||
  42085. + (current == service->state->slot_handler_thread)) {
  42086. + /* Make it look like a client, because it must be removed and
  42087. + not left in the LISTENING state. */
  42088. + service->public_fourcc = VCHIQ_FOURCC_INVALID;
  42089. +
  42090. + status = vchiq_close_service_internal(service,
  42091. + 0/*!close_recvd*/);
  42092. + BUG_ON(status == VCHIQ_RETRY);
  42093. + } else {
  42094. + /* Mark the service for removal by the slot handler */
  42095. + request_poll(service->state, service, VCHIQ_POLL_REMOVE);
  42096. + }
  42097. + while (1) {
  42098. + if (down_interruptible(&service->remove_event) != 0) {
  42099. + status = VCHIQ_RETRY;
  42100. + break;
  42101. + }
  42102. +
  42103. + if ((service->srvstate == VCHIQ_SRVSTATE_FREE) ||
  42104. + (service->srvstate == VCHIQ_SRVSTATE_OPEN))
  42105. + break;
  42106. +
  42107. + vchiq_log_warning(vchiq_core_log_level,
  42108. + "%d: remove_service:%d - waiting in state %s",
  42109. + service->state->id, service->localport,
  42110. + srvstate_names[service->srvstate]);
  42111. + }
  42112. +
  42113. + if ((status == VCHIQ_SUCCESS) &&
  42114. + (service->srvstate != VCHIQ_SRVSTATE_FREE))
  42115. + status = VCHIQ_ERROR;
  42116. +
  42117. + unlock_service(service);
  42118. +
  42119. + return status;
  42120. +}
  42121. +
  42122. +
  42123. +/* This function may be called by kernel threads or user threads.
  42124. + * User threads may receive VCHIQ_RETRY to indicate that a signal has been
  42125. + * received and the call should be retried after being returned to user
  42126. + * context.
  42127. + * When called in blocking mode, the userdata field points to a bulk_waiter
  42128. + * structure.
  42129. + */
  42130. +VCHIQ_STATUS_T
  42131. +vchiq_bulk_transfer(VCHIQ_SERVICE_HANDLE_T handle,
  42132. + VCHI_MEM_HANDLE_T memhandle, void *offset, int size, void *userdata,
  42133. + VCHIQ_BULK_MODE_T mode, VCHIQ_BULK_DIR_T dir)
  42134. +{
  42135. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  42136. + VCHIQ_BULK_QUEUE_T *queue;
  42137. + VCHIQ_BULK_T *bulk;
  42138. + VCHIQ_STATE_T *state;
  42139. + struct bulk_waiter *bulk_waiter = NULL;
  42140. + const char dir_char = (dir == VCHIQ_BULK_TRANSMIT) ? 't' : 'r';
  42141. + const int dir_msgtype = (dir == VCHIQ_BULK_TRANSMIT) ?
  42142. + VCHIQ_MSG_BULK_TX : VCHIQ_MSG_BULK_RX;
  42143. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  42144. +
  42145. + if (!service ||
  42146. + (service->srvstate != VCHIQ_SRVSTATE_OPEN) ||
  42147. + ((memhandle == VCHI_MEM_HANDLE_INVALID) && (offset == NULL)) ||
  42148. + (vchiq_check_service(service) != VCHIQ_SUCCESS))
  42149. + goto error_exit;
  42150. +
  42151. + switch (mode) {
  42152. + case VCHIQ_BULK_MODE_NOCALLBACK:
  42153. + case VCHIQ_BULK_MODE_CALLBACK:
  42154. + break;
  42155. + case VCHIQ_BULK_MODE_BLOCKING:
  42156. + bulk_waiter = (struct bulk_waiter *)userdata;
  42157. + sema_init(&bulk_waiter->event, 0);
  42158. + bulk_waiter->actual = 0;
  42159. + bulk_waiter->bulk = NULL;
  42160. + break;
  42161. + case VCHIQ_BULK_MODE_WAITING:
  42162. + bulk_waiter = (struct bulk_waiter *)userdata;
  42163. + bulk = bulk_waiter->bulk;
  42164. + goto waiting;
  42165. + default:
  42166. + goto error_exit;
  42167. + }
  42168. +
  42169. + state = service->state;
  42170. +
  42171. + queue = (dir == VCHIQ_BULK_TRANSMIT) ?
  42172. + &service->bulk_tx : &service->bulk_rx;
  42173. +
  42174. + if (mutex_lock_interruptible(&service->bulk_mutex) != 0) {
  42175. + status = VCHIQ_RETRY;
  42176. + goto error_exit;
  42177. + }
  42178. +
  42179. + if (queue->local_insert == queue->remove + VCHIQ_NUM_SERVICE_BULKS) {
  42180. + VCHIQ_SERVICE_STATS_INC(service, bulk_stalls);
  42181. + do {
  42182. + mutex_unlock(&service->bulk_mutex);
  42183. + if (down_interruptible(&service->bulk_remove_event)
  42184. + != 0) {
  42185. + status = VCHIQ_RETRY;
  42186. + goto error_exit;
  42187. + }
  42188. + if (mutex_lock_interruptible(&service->bulk_mutex)
  42189. + != 0) {
  42190. + status = VCHIQ_RETRY;
  42191. + goto error_exit;
  42192. + }
  42193. + } while (queue->local_insert == queue->remove +
  42194. + VCHIQ_NUM_SERVICE_BULKS);
  42195. + }
  42196. +
  42197. + bulk = &queue->bulks[BULK_INDEX(queue->local_insert)];
  42198. +
  42199. + bulk->mode = mode;
  42200. + bulk->dir = dir;
  42201. + bulk->userdata = userdata;
  42202. + bulk->size = size;
  42203. + bulk->actual = VCHIQ_BULK_ACTUAL_ABORTED;
  42204. +
  42205. + if (vchiq_prepare_bulk_data(bulk, memhandle, offset, size, dir) !=
  42206. + VCHIQ_SUCCESS)
  42207. + goto unlock_error_exit;
  42208. +
  42209. + wmb();
  42210. +
  42211. + vchiq_log_info(vchiq_core_log_level,
  42212. + "%d: bt (%d->%d) %cx %x@%x %x",
  42213. + state->id,
  42214. + service->localport, service->remoteport, dir_char,
  42215. + size, (unsigned int)bulk->data, (unsigned int)userdata);
  42216. +
  42217. + /* The slot mutex must be held when the service is being closed, so
  42218. + claim it here to ensure that isn't happening */
  42219. + if (mutex_lock_interruptible(&state->slot_mutex) != 0) {
  42220. + status = VCHIQ_RETRY;
  42221. + goto cancel_bulk_error_exit;
  42222. + }
  42223. +
  42224. + if (service->srvstate != VCHIQ_SRVSTATE_OPEN)
  42225. + goto unlock_both_error_exit;
  42226. +
  42227. + if (state->is_master) {
  42228. + queue->local_insert++;
  42229. + if (resolve_bulks(service, queue))
  42230. + request_poll(state, service,
  42231. + (dir == VCHIQ_BULK_TRANSMIT) ?
  42232. + VCHIQ_POLL_TXNOTIFY : VCHIQ_POLL_RXNOTIFY);
  42233. + } else {
  42234. + int payload[2] = { (int)bulk->data, bulk->size };
  42235. + VCHIQ_ELEMENT_T element = { payload, sizeof(payload) };
  42236. +
  42237. + status = queue_message(state, NULL,
  42238. + VCHIQ_MAKE_MSG(dir_msgtype,
  42239. + service->localport, service->remoteport),
  42240. + &element, 1, sizeof(payload),
  42241. + QMFLAGS_IS_BLOCKING |
  42242. + QMFLAGS_NO_MUTEX_LOCK |
  42243. + QMFLAGS_NO_MUTEX_UNLOCK);
  42244. + if (status != VCHIQ_SUCCESS) {
  42245. + goto unlock_both_error_exit;
  42246. + }
  42247. + queue->local_insert++;
  42248. + }
  42249. +
  42250. + mutex_unlock(&state->slot_mutex);
  42251. + mutex_unlock(&service->bulk_mutex);
  42252. +
  42253. + vchiq_log_trace(vchiq_core_log_level,
  42254. + "%d: bt:%d %cx li=%x ri=%x p=%x",
  42255. + state->id,
  42256. + service->localport, dir_char,
  42257. + queue->local_insert, queue->remote_insert, queue->process);
  42258. +
  42259. +waiting:
  42260. + unlock_service(service);
  42261. +
  42262. + status = VCHIQ_SUCCESS;
  42263. +
  42264. + if (bulk_waiter) {
  42265. + bulk_waiter->bulk = bulk;
  42266. + if (down_interruptible(&bulk_waiter->event) != 0)
  42267. + status = VCHIQ_RETRY;
  42268. + else if (bulk_waiter->actual == VCHIQ_BULK_ACTUAL_ABORTED)
  42269. + status = VCHIQ_ERROR;
  42270. + }
  42271. +
  42272. + return status;
  42273. +
  42274. +unlock_both_error_exit:
  42275. + mutex_unlock(&state->slot_mutex);
  42276. +cancel_bulk_error_exit:
  42277. + vchiq_complete_bulk(bulk);
  42278. +unlock_error_exit:
  42279. + mutex_unlock(&service->bulk_mutex);
  42280. +
  42281. +error_exit:
  42282. + if (service)
  42283. + unlock_service(service);
  42284. + return status;
  42285. +}
  42286. +
  42287. +VCHIQ_STATUS_T
  42288. +vchiq_queue_message(VCHIQ_SERVICE_HANDLE_T handle,
  42289. + const VCHIQ_ELEMENT_T *elements, unsigned int count)
  42290. +{
  42291. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  42292. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  42293. +
  42294. + unsigned int size = 0;
  42295. + unsigned int i;
  42296. +
  42297. + if (!service ||
  42298. + (vchiq_check_service(service) != VCHIQ_SUCCESS))
  42299. + goto error_exit;
  42300. +
  42301. + for (i = 0; i < (unsigned int)count; i++) {
  42302. + if (elements[i].size) {
  42303. + if (elements[i].data == NULL) {
  42304. + VCHIQ_SERVICE_STATS_INC(service, error_count);
  42305. + goto error_exit;
  42306. + }
  42307. + size += elements[i].size;
  42308. + }
  42309. + }
  42310. +
  42311. + if (size > VCHIQ_MAX_MSG_SIZE) {
  42312. + VCHIQ_SERVICE_STATS_INC(service, error_count);
  42313. + goto error_exit;
  42314. + }
  42315. +
  42316. + switch (service->srvstate) {
  42317. + case VCHIQ_SRVSTATE_OPEN:
  42318. + status = queue_message(service->state, service,
  42319. + VCHIQ_MAKE_MSG(VCHIQ_MSG_DATA,
  42320. + service->localport,
  42321. + service->remoteport),
  42322. + elements, count, size, 1);
  42323. + break;
  42324. + case VCHIQ_SRVSTATE_OPENSYNC:
  42325. + status = queue_message_sync(service->state, service,
  42326. + VCHIQ_MAKE_MSG(VCHIQ_MSG_DATA,
  42327. + service->localport,
  42328. + service->remoteport),
  42329. + elements, count, size, 1);
  42330. + break;
  42331. + default:
  42332. + status = VCHIQ_ERROR;
  42333. + break;
  42334. + }
  42335. +
  42336. +error_exit:
  42337. + if (service)
  42338. + unlock_service(service);
  42339. +
  42340. + return status;
  42341. +}
  42342. +
  42343. +void
  42344. +vchiq_release_message(VCHIQ_SERVICE_HANDLE_T handle, VCHIQ_HEADER_T *header)
  42345. +{
  42346. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  42347. + VCHIQ_SHARED_STATE_T *remote;
  42348. + VCHIQ_STATE_T *state;
  42349. + int slot_index;
  42350. +
  42351. + if (!service)
  42352. + return;
  42353. +
  42354. + state = service->state;
  42355. + remote = state->remote;
  42356. +
  42357. + slot_index = SLOT_INDEX_FROM_DATA(state, (void *)header);
  42358. +
  42359. + if ((slot_index >= remote->slot_first) &&
  42360. + (slot_index <= remote->slot_last)) {
  42361. + int msgid = header->msgid;
  42362. + if (msgid & VCHIQ_MSGID_CLAIMED) {
  42363. + VCHIQ_SLOT_INFO_T *slot_info =
  42364. + SLOT_INFO_FROM_INDEX(state, slot_index);
  42365. +
  42366. + release_slot(state, slot_info, header, service);
  42367. + }
  42368. + } else if (slot_index == remote->slot_sync)
  42369. + release_message_sync(state, header);
  42370. +
  42371. + unlock_service(service);
  42372. +}
  42373. +
  42374. +static void
  42375. +release_message_sync(VCHIQ_STATE_T *state, VCHIQ_HEADER_T *header)
  42376. +{
  42377. + header->msgid = VCHIQ_MSGID_PADDING;
  42378. + wmb();
  42379. + remote_event_signal(&state->remote->sync_release);
  42380. +}
  42381. +
  42382. +VCHIQ_STATUS_T
  42383. +vchiq_get_peer_version(VCHIQ_SERVICE_HANDLE_T handle, short *peer_version)
  42384. +{
  42385. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  42386. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  42387. +
  42388. + if (!service ||
  42389. + (vchiq_check_service(service) != VCHIQ_SUCCESS) ||
  42390. + !peer_version)
  42391. + goto exit;
  42392. + *peer_version = service->peer_version;
  42393. + status = VCHIQ_SUCCESS;
  42394. +
  42395. +exit:
  42396. + if (service)
  42397. + unlock_service(service);
  42398. + return status;
  42399. +}
  42400. +
  42401. +VCHIQ_STATUS_T
  42402. +vchiq_get_config(VCHIQ_INSTANCE_T instance,
  42403. + int config_size, VCHIQ_CONFIG_T *pconfig)
  42404. +{
  42405. + VCHIQ_CONFIG_T config;
  42406. +
  42407. + (void)instance;
  42408. +
  42409. + config.max_msg_size = VCHIQ_MAX_MSG_SIZE;
  42410. + config.bulk_threshold = VCHIQ_MAX_MSG_SIZE;
  42411. + config.max_outstanding_bulks = VCHIQ_NUM_SERVICE_BULKS;
  42412. + config.max_services = VCHIQ_MAX_SERVICES;
  42413. + config.version = VCHIQ_VERSION;
  42414. + config.version_min = VCHIQ_VERSION_MIN;
  42415. +
  42416. + if (config_size > sizeof(VCHIQ_CONFIG_T))
  42417. + return VCHIQ_ERROR;
  42418. +
  42419. + memcpy(pconfig, &config,
  42420. + min(config_size, (int)(sizeof(VCHIQ_CONFIG_T))));
  42421. +
  42422. + return VCHIQ_SUCCESS;
  42423. +}
  42424. +
  42425. +VCHIQ_STATUS_T
  42426. +vchiq_set_service_option(VCHIQ_SERVICE_HANDLE_T handle,
  42427. + VCHIQ_SERVICE_OPTION_T option, int value)
  42428. +{
  42429. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  42430. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  42431. +
  42432. + if (service) {
  42433. + switch (option) {
  42434. + case VCHIQ_SERVICE_OPTION_AUTOCLOSE:
  42435. + service->auto_close = value;
  42436. + status = VCHIQ_SUCCESS;
  42437. + break;
  42438. +
  42439. + case VCHIQ_SERVICE_OPTION_SLOT_QUOTA: {
  42440. + VCHIQ_SERVICE_QUOTA_T *service_quota =
  42441. + &service->state->service_quotas[
  42442. + service->localport];
  42443. + if (value == 0)
  42444. + value = service->state->default_slot_quota;
  42445. + if ((value >= service_quota->slot_use_count) &&
  42446. + (value < (unsigned short)~0)) {
  42447. + service_quota->slot_quota = value;
  42448. + if ((value >= service_quota->slot_use_count) &&
  42449. + (service_quota->message_quota >=
  42450. + service_quota->message_use_count)) {
  42451. + /* Signal the service that it may have
  42452. + ** dropped below its quota */
  42453. + up(&service_quota->quota_event);
  42454. + }
  42455. + status = VCHIQ_SUCCESS;
  42456. + }
  42457. + } break;
  42458. +
  42459. + case VCHIQ_SERVICE_OPTION_MESSAGE_QUOTA: {
  42460. + VCHIQ_SERVICE_QUOTA_T *service_quota =
  42461. + &service->state->service_quotas[
  42462. + service->localport];
  42463. + if (value == 0)
  42464. + value = service->state->default_message_quota;
  42465. + if ((value >= service_quota->message_use_count) &&
  42466. + (value < (unsigned short)~0)) {
  42467. + service_quota->message_quota = value;
  42468. + if ((value >=
  42469. + service_quota->message_use_count) &&
  42470. + (service_quota->slot_quota >=
  42471. + service_quota->slot_use_count))
  42472. + /* Signal the service that it may have
  42473. + ** dropped below its quota */
  42474. + up(&service_quota->quota_event);
  42475. + status = VCHIQ_SUCCESS;
  42476. + }
  42477. + } break;
  42478. +
  42479. + case VCHIQ_SERVICE_OPTION_SYNCHRONOUS:
  42480. + if ((service->srvstate == VCHIQ_SRVSTATE_HIDDEN) ||
  42481. + (service->srvstate ==
  42482. + VCHIQ_SRVSTATE_LISTENING)) {
  42483. + service->sync = value;
  42484. + status = VCHIQ_SUCCESS;
  42485. + }
  42486. + break;
  42487. +
  42488. + case VCHIQ_SERVICE_OPTION_TRACE:
  42489. + service->trace = value;
  42490. + status = VCHIQ_SUCCESS;
  42491. + break;
  42492. +
  42493. + default:
  42494. + break;
  42495. + }
  42496. + unlock_service(service);
  42497. + }
  42498. +
  42499. + return status;
  42500. +}
  42501. +
  42502. +void
  42503. +vchiq_dump_shared_state(void *dump_context, VCHIQ_STATE_T *state,
  42504. + VCHIQ_SHARED_STATE_T *shared, const char *label)
  42505. +{
  42506. + static const char *const debug_names[] = {
  42507. + "<entries>",
  42508. + "SLOT_HANDLER_COUNT",
  42509. + "SLOT_HANDLER_LINE",
  42510. + "PARSE_LINE",
  42511. + "PARSE_HEADER",
  42512. + "PARSE_MSGID",
  42513. + "AWAIT_COMPLETION_LINE",
  42514. + "DEQUEUE_MESSAGE_LINE",
  42515. + "SERVICE_CALLBACK_LINE",
  42516. + "MSG_QUEUE_FULL_COUNT",
  42517. + "COMPLETION_QUEUE_FULL_COUNT"
  42518. + };
  42519. + int i;
  42520. +
  42521. + char buf[80];
  42522. + int len;
  42523. + len = snprintf(buf, sizeof(buf),
  42524. + " %s: slots %d-%d tx_pos=%x recycle=%x",
  42525. + label, shared->slot_first, shared->slot_last,
  42526. + shared->tx_pos, shared->slot_queue_recycle);
  42527. + vchiq_dump(dump_context, buf, len + 1);
  42528. +
  42529. + len = snprintf(buf, sizeof(buf),
  42530. + " Slots claimed:");
  42531. + vchiq_dump(dump_context, buf, len + 1);
  42532. +
  42533. + for (i = shared->slot_first; i <= shared->slot_last; i++) {
  42534. + VCHIQ_SLOT_INFO_T slot_info = *SLOT_INFO_FROM_INDEX(state, i);
  42535. + if (slot_info.use_count != slot_info.release_count) {
  42536. + len = snprintf(buf, sizeof(buf),
  42537. + " %d: %d/%d", i, slot_info.use_count,
  42538. + slot_info.release_count);
  42539. + vchiq_dump(dump_context, buf, len + 1);
  42540. + }
  42541. + }
  42542. +
  42543. + for (i = 1; i < shared->debug[DEBUG_ENTRIES]; i++) {
  42544. + len = snprintf(buf, sizeof(buf), " DEBUG: %s = %d(%x)",
  42545. + debug_names[i], shared->debug[i], shared->debug[i]);
  42546. + vchiq_dump(dump_context, buf, len + 1);
  42547. + }
  42548. +}
  42549. +
  42550. +void
  42551. +vchiq_dump_state(void *dump_context, VCHIQ_STATE_T *state)
  42552. +{
  42553. + char buf[80];
  42554. + int len;
  42555. + int i;
  42556. +
  42557. + len = snprintf(buf, sizeof(buf), "State %d: %s", state->id,
  42558. + conn_state_names[state->conn_state]);
  42559. + vchiq_dump(dump_context, buf, len + 1);
  42560. +
  42561. + len = snprintf(buf, sizeof(buf),
  42562. + " tx_pos=%x(@%x), rx_pos=%x(@%x)",
  42563. + state->local->tx_pos,
  42564. + (uint32_t)state->tx_data +
  42565. + (state->local_tx_pos & VCHIQ_SLOT_MASK),
  42566. + state->rx_pos,
  42567. + (uint32_t)state->rx_data +
  42568. + (state->rx_pos & VCHIQ_SLOT_MASK));
  42569. + vchiq_dump(dump_context, buf, len + 1);
  42570. +
  42571. + len = snprintf(buf, sizeof(buf),
  42572. + " Version: %d (min %d)",
  42573. + VCHIQ_VERSION, VCHIQ_VERSION_MIN);
  42574. + vchiq_dump(dump_context, buf, len + 1);
  42575. +
  42576. + if (VCHIQ_ENABLE_STATS) {
  42577. + len = snprintf(buf, sizeof(buf),
  42578. + " Stats: ctrl_tx_count=%d, ctrl_rx_count=%d, "
  42579. + "error_count=%d",
  42580. + state->stats.ctrl_tx_count, state->stats.ctrl_rx_count,
  42581. + state->stats.error_count);
  42582. + vchiq_dump(dump_context, buf, len + 1);
  42583. + }
  42584. +
  42585. + len = snprintf(buf, sizeof(buf),
  42586. + " Slots: %d available (%d data), %d recyclable, %d stalls "
  42587. + "(%d data)",
  42588. + ((state->slot_queue_available * VCHIQ_SLOT_SIZE) -
  42589. + state->local_tx_pos) / VCHIQ_SLOT_SIZE,
  42590. + state->data_quota - state->data_use_count,
  42591. + state->local->slot_queue_recycle - state->slot_queue_available,
  42592. + state->stats.slot_stalls, state->stats.data_stalls);
  42593. + vchiq_dump(dump_context, buf, len + 1);
  42594. +
  42595. + vchiq_dump_platform_state(dump_context);
  42596. +
  42597. + vchiq_dump_shared_state(dump_context, state, state->local, "Local");
  42598. + vchiq_dump_shared_state(dump_context, state, state->remote, "Remote");
  42599. +
  42600. + vchiq_dump_platform_instances(dump_context);
  42601. +
  42602. + for (i = 0; i < state->unused_service; i++) {
  42603. + VCHIQ_SERVICE_T *service = find_service_by_port(state, i);
  42604. +
  42605. + if (service) {
  42606. + vchiq_dump_service_state(dump_context, service);
  42607. + unlock_service(service);
  42608. + }
  42609. + }
  42610. +}
  42611. +
  42612. +void
  42613. +vchiq_dump_service_state(void *dump_context, VCHIQ_SERVICE_T *service)
  42614. +{
  42615. + char buf[80];
  42616. + int len;
  42617. +
  42618. + len = snprintf(buf, sizeof(buf), "Service %d: %s (ref %u)",
  42619. + service->localport, srvstate_names[service->srvstate],
  42620. + service->ref_count - 1); /*Don't include the lock just taken*/
  42621. +
  42622. + if (service->srvstate != VCHIQ_SRVSTATE_FREE) {
  42623. + char remoteport[30];
  42624. + VCHIQ_SERVICE_QUOTA_T *service_quota =
  42625. + &service->state->service_quotas[service->localport];
  42626. + int fourcc = service->base.fourcc;
  42627. + int tx_pending, rx_pending;
  42628. + if (service->remoteport != VCHIQ_PORT_FREE) {
  42629. + int len2 = snprintf(remoteport, sizeof(remoteport),
  42630. + "%d", service->remoteport);
  42631. + if (service->public_fourcc != VCHIQ_FOURCC_INVALID)
  42632. + snprintf(remoteport + len2,
  42633. + sizeof(remoteport) - len2,
  42634. + " (client %x)", service->client_id);
  42635. + } else
  42636. + strcpy(remoteport, "n/a");
  42637. +
  42638. + len += snprintf(buf + len, sizeof(buf) - len,
  42639. + " '%c%c%c%c' remote %s (msg use %d/%d, slot use %d/%d)",
  42640. + VCHIQ_FOURCC_AS_4CHARS(fourcc),
  42641. + remoteport,
  42642. + service_quota->message_use_count,
  42643. + service_quota->message_quota,
  42644. + service_quota->slot_use_count,
  42645. + service_quota->slot_quota);
  42646. +
  42647. + vchiq_dump(dump_context, buf, len + 1);
  42648. +
  42649. + tx_pending = service->bulk_tx.local_insert -
  42650. + service->bulk_tx.remote_insert;
  42651. +
  42652. + rx_pending = service->bulk_rx.local_insert -
  42653. + service->bulk_rx.remote_insert;
  42654. +
  42655. + len = snprintf(buf, sizeof(buf),
  42656. + " Bulk: tx_pending=%d (size %d),"
  42657. + " rx_pending=%d (size %d)",
  42658. + tx_pending,
  42659. + tx_pending ? service->bulk_tx.bulks[
  42660. + BULK_INDEX(service->bulk_tx.remove)].size : 0,
  42661. + rx_pending,
  42662. + rx_pending ? service->bulk_rx.bulks[
  42663. + BULK_INDEX(service->bulk_rx.remove)].size : 0);
  42664. +
  42665. + if (VCHIQ_ENABLE_STATS) {
  42666. + vchiq_dump(dump_context, buf, len + 1);
  42667. +
  42668. + len = snprintf(buf, sizeof(buf),
  42669. + " Ctrl: tx_count=%d, tx_bytes=%llu, "
  42670. + "rx_count=%d, rx_bytes=%llu",
  42671. + service->stats.ctrl_tx_count,
  42672. + service->stats.ctrl_tx_bytes,
  42673. + service->stats.ctrl_rx_count,
  42674. + service->stats.ctrl_rx_bytes);
  42675. + vchiq_dump(dump_context, buf, len + 1);
  42676. +
  42677. + len = snprintf(buf, sizeof(buf),
  42678. + " Bulk: tx_count=%d, tx_bytes=%llu, "
  42679. + "rx_count=%d, rx_bytes=%llu",
  42680. + service->stats.bulk_tx_count,
  42681. + service->stats.bulk_tx_bytes,
  42682. + service->stats.bulk_rx_count,
  42683. + service->stats.bulk_rx_bytes);
  42684. + vchiq_dump(dump_context, buf, len + 1);
  42685. +
  42686. + len = snprintf(buf, sizeof(buf),
  42687. + " %d quota stalls, %d slot stalls, "
  42688. + "%d bulk stalls, %d aborted, %d errors",
  42689. + service->stats.quota_stalls,
  42690. + service->stats.slot_stalls,
  42691. + service->stats.bulk_stalls,
  42692. + service->stats.bulk_aborted_count,
  42693. + service->stats.error_count);
  42694. + }
  42695. + }
  42696. +
  42697. + vchiq_dump(dump_context, buf, len + 1);
  42698. +
  42699. + if (service->srvstate != VCHIQ_SRVSTATE_FREE)
  42700. + vchiq_dump_platform_service_state(dump_context, service);
  42701. +}
  42702. +
  42703. +
  42704. +void
  42705. +vchiq_loud_error_header(void)
  42706. +{
  42707. + vchiq_log_error(vchiq_core_log_level,
  42708. + "============================================================"
  42709. + "================");
  42710. + vchiq_log_error(vchiq_core_log_level,
  42711. + "============================================================"
  42712. + "================");
  42713. + vchiq_log_error(vchiq_core_log_level, "=====");
  42714. +}
  42715. +
  42716. +void
  42717. +vchiq_loud_error_footer(void)
  42718. +{
  42719. + vchiq_log_error(vchiq_core_log_level, "=====");
  42720. + vchiq_log_error(vchiq_core_log_level,
  42721. + "============================================================"
  42722. + "================");
  42723. + vchiq_log_error(vchiq_core_log_level,
  42724. + "============================================================"
  42725. + "================");
  42726. +}
  42727. +
  42728. +
  42729. +VCHIQ_STATUS_T vchiq_send_remote_use(VCHIQ_STATE_T *state)
  42730. +{
  42731. + VCHIQ_STATUS_T status = VCHIQ_RETRY;
  42732. + if (state->conn_state != VCHIQ_CONNSTATE_DISCONNECTED)
  42733. + status = queue_message(state, NULL,
  42734. + VCHIQ_MAKE_MSG(VCHIQ_MSG_REMOTE_USE, 0, 0),
  42735. + NULL, 0, 0, 0);
  42736. + return status;
  42737. +}
  42738. +
  42739. +VCHIQ_STATUS_T vchiq_send_remote_release(VCHIQ_STATE_T *state)
  42740. +{
  42741. + VCHIQ_STATUS_T status = VCHIQ_RETRY;
  42742. + if (state->conn_state != VCHIQ_CONNSTATE_DISCONNECTED)
  42743. + status = queue_message(state, NULL,
  42744. + VCHIQ_MAKE_MSG(VCHIQ_MSG_REMOTE_RELEASE, 0, 0),
  42745. + NULL, 0, 0, 0);
  42746. + return status;
  42747. +}
  42748. +
  42749. +VCHIQ_STATUS_T vchiq_send_remote_use_active(VCHIQ_STATE_T *state)
  42750. +{
  42751. + VCHIQ_STATUS_T status = VCHIQ_RETRY;
  42752. + if (state->conn_state != VCHIQ_CONNSTATE_DISCONNECTED)
  42753. + status = queue_message(state, NULL,
  42754. + VCHIQ_MAKE_MSG(VCHIQ_MSG_REMOTE_USE_ACTIVE, 0, 0),
  42755. + NULL, 0, 0, 0);
  42756. + return status;
  42757. +}
  42758. +
  42759. +void vchiq_log_dump_mem(const char *label, uint32_t addr, const void *voidMem,
  42760. + size_t numBytes)
  42761. +{
  42762. + const uint8_t *mem = (const uint8_t *)voidMem;
  42763. + size_t offset;
  42764. + char lineBuf[100];
  42765. + char *s;
  42766. +
  42767. + while (numBytes > 0) {
  42768. + s = lineBuf;
  42769. +
  42770. + for (offset = 0; offset < 16; offset++) {
  42771. + if (offset < numBytes)
  42772. + s += snprintf(s, 4, "%02x ", mem[offset]);
  42773. + else
  42774. + s += snprintf(s, 4, " ");
  42775. + }
  42776. +
  42777. + for (offset = 0; offset < 16; offset++) {
  42778. + if (offset < numBytes) {
  42779. + uint8_t ch = mem[offset];
  42780. +
  42781. + if ((ch < ' ') || (ch > '~'))
  42782. + ch = '.';
  42783. + *s++ = (char)ch;
  42784. + }
  42785. + }
  42786. + *s++ = '\0';
  42787. +
  42788. + if ((label != NULL) && (*label != '\0'))
  42789. + vchiq_log_trace(VCHIQ_LOG_TRACE,
  42790. + "%s: %08x: %s", label, addr, lineBuf);
  42791. + else
  42792. + vchiq_log_trace(VCHIQ_LOG_TRACE,
  42793. + "%08x: %s", addr, lineBuf);
  42794. +
  42795. + addr += 16;
  42796. + mem += 16;
  42797. + if (numBytes > 16)
  42798. + numBytes -= 16;
  42799. + else
  42800. + numBytes = 0;
  42801. + }
  42802. +}
  42803. diff -Nur linux-3.18.8/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.h
  42804. --- linux-3.18.8/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.h 1970-01-01 01:00:00.000000000 +0100
  42805. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.h 2015-03-05 14:40:14.401715819 +0100
  42806. @@ -0,0 +1,712 @@
  42807. +/**
  42808. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  42809. + *
  42810. + * Redistribution and use in source and binary forms, with or without
  42811. + * modification, are permitted provided that the following conditions
  42812. + * are met:
  42813. + * 1. Redistributions of source code must retain the above copyright
  42814. + * notice, this list of conditions, and the following disclaimer,
  42815. + * without modification.
  42816. + * 2. Redistributions in binary form must reproduce the above copyright
  42817. + * notice, this list of conditions and the following disclaimer in the
  42818. + * documentation and/or other materials provided with the distribution.
  42819. + * 3. The names of the above-listed copyright holders may not be used
  42820. + * to endorse or promote products derived from this software without
  42821. + * specific prior written permission.
  42822. + *
  42823. + * ALTERNATIVELY, this software may be distributed under the terms of the
  42824. + * GNU General Public License ("GPL") version 2, as published by the Free
  42825. + * Software Foundation.
  42826. + *
  42827. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  42828. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  42829. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  42830. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  42831. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  42832. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  42833. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  42834. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  42835. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  42836. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  42837. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  42838. + */
  42839. +
  42840. +#ifndef VCHIQ_CORE_H
  42841. +#define VCHIQ_CORE_H
  42842. +
  42843. +#include <linux/mutex.h>
  42844. +#include <linux/semaphore.h>
  42845. +#include <linux/kthread.h>
  42846. +
  42847. +#include "vchiq_cfg.h"
  42848. +
  42849. +#include "vchiq.h"
  42850. +
  42851. +/* Run time control of log level, based on KERN_XXX level. */
  42852. +#define VCHIQ_LOG_DEFAULT 4
  42853. +#define VCHIQ_LOG_ERROR 3
  42854. +#define VCHIQ_LOG_WARNING 4
  42855. +#define VCHIQ_LOG_INFO 6
  42856. +#define VCHIQ_LOG_TRACE 7
  42857. +
  42858. +#define VCHIQ_LOG_PREFIX KERN_INFO "vchiq: "
  42859. +
  42860. +#ifndef vchiq_log_error
  42861. +#define vchiq_log_error(cat, fmt, ...) \
  42862. + do { if (cat >= VCHIQ_LOG_ERROR) \
  42863. + printk(VCHIQ_LOG_PREFIX fmt "\n", ##__VA_ARGS__); } while (0)
  42864. +#endif
  42865. +#ifndef vchiq_log_warning
  42866. +#define vchiq_log_warning(cat, fmt, ...) \
  42867. + do { if (cat >= VCHIQ_LOG_WARNING) \
  42868. + printk(VCHIQ_LOG_PREFIX fmt "\n", ##__VA_ARGS__); } while (0)
  42869. +#endif
  42870. +#ifndef vchiq_log_info
  42871. +#define vchiq_log_info(cat, fmt, ...) \
  42872. + do { if (cat >= VCHIQ_LOG_INFO) \
  42873. + printk(VCHIQ_LOG_PREFIX fmt "\n", ##__VA_ARGS__); } while (0)
  42874. +#endif
  42875. +#ifndef vchiq_log_trace
  42876. +#define vchiq_log_trace(cat, fmt, ...) \
  42877. + do { if (cat >= VCHIQ_LOG_TRACE) \
  42878. + printk(VCHIQ_LOG_PREFIX fmt "\n", ##__VA_ARGS__); } while (0)
  42879. +#endif
  42880. +
  42881. +#define vchiq_loud_error(...) \
  42882. + vchiq_log_error(vchiq_core_log_level, "===== " __VA_ARGS__)
  42883. +
  42884. +#ifndef vchiq_static_assert
  42885. +#define vchiq_static_assert(cond) __attribute__((unused)) \
  42886. + extern int vchiq_static_assert[(cond) ? 1 : -1]
  42887. +#endif
  42888. +
  42889. +#define IS_POW2(x) (x && ((x & (x - 1)) == 0))
  42890. +
  42891. +/* Ensure that the slot size and maximum number of slots are powers of 2 */
  42892. +vchiq_static_assert(IS_POW2(VCHIQ_SLOT_SIZE));
  42893. +vchiq_static_assert(IS_POW2(VCHIQ_MAX_SLOTS));
  42894. +vchiq_static_assert(IS_POW2(VCHIQ_MAX_SLOTS_PER_SIDE));
  42895. +
  42896. +#define VCHIQ_SLOT_MASK (VCHIQ_SLOT_SIZE - 1)
  42897. +#define VCHIQ_SLOT_QUEUE_MASK (VCHIQ_MAX_SLOTS_PER_SIDE - 1)
  42898. +#define VCHIQ_SLOT_ZERO_SLOTS ((sizeof(VCHIQ_SLOT_ZERO_T) + \
  42899. + VCHIQ_SLOT_SIZE - 1) / VCHIQ_SLOT_SIZE)
  42900. +
  42901. +#define VCHIQ_MSG_PADDING 0 /* - */
  42902. +#define VCHIQ_MSG_CONNECT 1 /* - */
  42903. +#define VCHIQ_MSG_OPEN 2 /* + (srcport, -), fourcc, client_id */
  42904. +#define VCHIQ_MSG_OPENACK 3 /* + (srcport, dstport) */
  42905. +#define VCHIQ_MSG_CLOSE 4 /* + (srcport, dstport) */
  42906. +#define VCHIQ_MSG_DATA 5 /* + (srcport, dstport) */
  42907. +#define VCHIQ_MSG_BULK_RX 6 /* + (srcport, dstport), data, size */
  42908. +#define VCHIQ_MSG_BULK_TX 7 /* + (srcport, dstport), data, size */
  42909. +#define VCHIQ_MSG_BULK_RX_DONE 8 /* + (srcport, dstport), actual */
  42910. +#define VCHIQ_MSG_BULK_TX_DONE 9 /* + (srcport, dstport), actual */
  42911. +#define VCHIQ_MSG_PAUSE 10 /* - */
  42912. +#define VCHIQ_MSG_RESUME 11 /* - */
  42913. +#define VCHIQ_MSG_REMOTE_USE 12 /* - */
  42914. +#define VCHIQ_MSG_REMOTE_RELEASE 13 /* - */
  42915. +#define VCHIQ_MSG_REMOTE_USE_ACTIVE 14 /* - */
  42916. +
  42917. +#define VCHIQ_PORT_MAX (VCHIQ_MAX_SERVICES - 1)
  42918. +#define VCHIQ_PORT_FREE 0x1000
  42919. +#define VCHIQ_PORT_IS_VALID(port) (port < VCHIQ_PORT_FREE)
  42920. +#define VCHIQ_MAKE_MSG(type, srcport, dstport) \
  42921. + ((type<<24) | (srcport<<12) | (dstport<<0))
  42922. +#define VCHIQ_MSG_TYPE(msgid) ((unsigned int)msgid >> 24)
  42923. +#define VCHIQ_MSG_SRCPORT(msgid) \
  42924. + (unsigned short)(((unsigned int)msgid >> 12) & 0xfff)
  42925. +#define VCHIQ_MSG_DSTPORT(msgid) \
  42926. + ((unsigned short)msgid & 0xfff)
  42927. +
  42928. +#define VCHIQ_FOURCC_AS_4CHARS(fourcc) \
  42929. + ((fourcc) >> 24) & 0xff, \
  42930. + ((fourcc) >> 16) & 0xff, \
  42931. + ((fourcc) >> 8) & 0xff, \
  42932. + (fourcc) & 0xff
  42933. +
  42934. +/* Ensure the fields are wide enough */
  42935. +vchiq_static_assert(VCHIQ_MSG_SRCPORT(VCHIQ_MAKE_MSG(0, 0, VCHIQ_PORT_MAX))
  42936. + == 0);
  42937. +vchiq_static_assert(VCHIQ_MSG_TYPE(VCHIQ_MAKE_MSG(0, VCHIQ_PORT_MAX, 0)) == 0);
  42938. +vchiq_static_assert((unsigned int)VCHIQ_PORT_MAX <
  42939. + (unsigned int)VCHIQ_PORT_FREE);
  42940. +
  42941. +#define VCHIQ_MSGID_PADDING VCHIQ_MAKE_MSG(VCHIQ_MSG_PADDING, 0, 0)
  42942. +#define VCHIQ_MSGID_CLAIMED 0x40000000
  42943. +
  42944. +#define VCHIQ_FOURCC_INVALID 0x00000000
  42945. +#define VCHIQ_FOURCC_IS_LEGAL(fourcc) (fourcc != VCHIQ_FOURCC_INVALID)
  42946. +
  42947. +#define VCHIQ_BULK_ACTUAL_ABORTED -1
  42948. +
  42949. +typedef uint32_t BITSET_T;
  42950. +
  42951. +vchiq_static_assert((sizeof(BITSET_T) * 8) == 32);
  42952. +
  42953. +#define BITSET_SIZE(b) ((b + 31) >> 5)
  42954. +#define BITSET_WORD(b) (b >> 5)
  42955. +#define BITSET_BIT(b) (1 << (b & 31))
  42956. +#define BITSET_ZERO(bs) memset(bs, 0, sizeof(bs))
  42957. +#define BITSET_IS_SET(bs, b) (bs[BITSET_WORD(b)] & BITSET_BIT(b))
  42958. +#define BITSET_SET(bs, b) (bs[BITSET_WORD(b)] |= BITSET_BIT(b))
  42959. +#define BITSET_CLR(bs, b) (bs[BITSET_WORD(b)] &= ~BITSET_BIT(b))
  42960. +
  42961. +#if VCHIQ_ENABLE_STATS
  42962. +#define VCHIQ_STATS_INC(state, stat) (state->stats. stat++)
  42963. +#define VCHIQ_SERVICE_STATS_INC(service, stat) (service->stats. stat++)
  42964. +#define VCHIQ_SERVICE_STATS_ADD(service, stat, addend) \
  42965. + (service->stats. stat += addend)
  42966. +#else
  42967. +#define VCHIQ_STATS_INC(state, stat) ((void)0)
  42968. +#define VCHIQ_SERVICE_STATS_INC(service, stat) ((void)0)
  42969. +#define VCHIQ_SERVICE_STATS_ADD(service, stat, addend) ((void)0)
  42970. +#endif
  42971. +
  42972. +enum {
  42973. + DEBUG_ENTRIES,
  42974. +#if VCHIQ_ENABLE_DEBUG
  42975. + DEBUG_SLOT_HANDLER_COUNT,
  42976. + DEBUG_SLOT_HANDLER_LINE,
  42977. + DEBUG_PARSE_LINE,
  42978. + DEBUG_PARSE_HEADER,
  42979. + DEBUG_PARSE_MSGID,
  42980. + DEBUG_AWAIT_COMPLETION_LINE,
  42981. + DEBUG_DEQUEUE_MESSAGE_LINE,
  42982. + DEBUG_SERVICE_CALLBACK_LINE,
  42983. + DEBUG_MSG_QUEUE_FULL_COUNT,
  42984. + DEBUG_COMPLETION_QUEUE_FULL_COUNT,
  42985. +#endif
  42986. + DEBUG_MAX
  42987. +};
  42988. +
  42989. +#if VCHIQ_ENABLE_DEBUG
  42990. +
  42991. +#define DEBUG_INITIALISE(local) int *debug_ptr = (local)->debug;
  42992. +#define DEBUG_TRACE(d) \
  42993. + do { debug_ptr[DEBUG_ ## d] = __LINE__; dsb(); } while (0)
  42994. +#define DEBUG_VALUE(d, v) \
  42995. + do { debug_ptr[DEBUG_ ## d] = (v); dsb(); } while (0)
  42996. +#define DEBUG_COUNT(d) \
  42997. + do { debug_ptr[DEBUG_ ## d]++; dsb(); } while (0)
  42998. +
  42999. +#else /* VCHIQ_ENABLE_DEBUG */
  43000. +
  43001. +#define DEBUG_INITIALISE(local)
  43002. +#define DEBUG_TRACE(d)
  43003. +#define DEBUG_VALUE(d, v)
  43004. +#define DEBUG_COUNT(d)
  43005. +
  43006. +#endif /* VCHIQ_ENABLE_DEBUG */
  43007. +
  43008. +typedef enum {
  43009. + VCHIQ_CONNSTATE_DISCONNECTED,
  43010. + VCHIQ_CONNSTATE_CONNECTING,
  43011. + VCHIQ_CONNSTATE_CONNECTED,
  43012. + VCHIQ_CONNSTATE_PAUSING,
  43013. + VCHIQ_CONNSTATE_PAUSE_SENT,
  43014. + VCHIQ_CONNSTATE_PAUSED,
  43015. + VCHIQ_CONNSTATE_RESUMING,
  43016. + VCHIQ_CONNSTATE_PAUSE_TIMEOUT,
  43017. + VCHIQ_CONNSTATE_RESUME_TIMEOUT
  43018. +} VCHIQ_CONNSTATE_T;
  43019. +
  43020. +enum {
  43021. + VCHIQ_SRVSTATE_FREE,
  43022. + VCHIQ_SRVSTATE_HIDDEN,
  43023. + VCHIQ_SRVSTATE_LISTENING,
  43024. + VCHIQ_SRVSTATE_OPENING,
  43025. + VCHIQ_SRVSTATE_OPEN,
  43026. + VCHIQ_SRVSTATE_OPENSYNC,
  43027. + VCHIQ_SRVSTATE_CLOSESENT,
  43028. + VCHIQ_SRVSTATE_CLOSERECVD,
  43029. + VCHIQ_SRVSTATE_CLOSEWAIT,
  43030. + VCHIQ_SRVSTATE_CLOSED
  43031. +};
  43032. +
  43033. +enum {
  43034. + VCHIQ_POLL_TERMINATE,
  43035. + VCHIQ_POLL_REMOVE,
  43036. + VCHIQ_POLL_TXNOTIFY,
  43037. + VCHIQ_POLL_RXNOTIFY,
  43038. + VCHIQ_POLL_COUNT
  43039. +};
  43040. +
  43041. +typedef enum {
  43042. + VCHIQ_BULK_TRANSMIT,
  43043. + VCHIQ_BULK_RECEIVE
  43044. +} VCHIQ_BULK_DIR_T;
  43045. +
  43046. +typedef void (*VCHIQ_USERDATA_TERM_T)(void *userdata);
  43047. +
  43048. +typedef struct vchiq_bulk_struct {
  43049. + short mode;
  43050. + short dir;
  43051. + void *userdata;
  43052. + VCHI_MEM_HANDLE_T handle;
  43053. + void *data;
  43054. + int size;
  43055. + void *remote_data;
  43056. + int remote_size;
  43057. + int actual;
  43058. +} VCHIQ_BULK_T;
  43059. +
  43060. +typedef struct vchiq_bulk_queue_struct {
  43061. + int local_insert; /* Where to insert the next local bulk */
  43062. + int remote_insert; /* Where to insert the next remote bulk (master) */
  43063. + int process; /* Bulk to transfer next */
  43064. + int remote_notify; /* Bulk to notify the remote client of next (mstr) */
  43065. + int remove; /* Bulk to notify the local client of, and remove,
  43066. + ** next */
  43067. + VCHIQ_BULK_T bulks[VCHIQ_NUM_SERVICE_BULKS];
  43068. +} VCHIQ_BULK_QUEUE_T;
  43069. +
  43070. +typedef struct remote_event_struct {
  43071. + int armed;
  43072. + int fired;
  43073. + struct semaphore *event;
  43074. +} REMOTE_EVENT_T;
  43075. +
  43076. +typedef struct opaque_platform_state_t *VCHIQ_PLATFORM_STATE_T;
  43077. +
  43078. +typedef struct vchiq_state_struct VCHIQ_STATE_T;
  43079. +
  43080. +typedef struct vchiq_slot_struct {
  43081. + char data[VCHIQ_SLOT_SIZE];
  43082. +} VCHIQ_SLOT_T;
  43083. +
  43084. +typedef struct vchiq_slot_info_struct {
  43085. + /* Use two counters rather than one to avoid the need for a mutex. */
  43086. + short use_count;
  43087. + short release_count;
  43088. +} VCHIQ_SLOT_INFO_T;
  43089. +
  43090. +typedef struct vchiq_service_struct {
  43091. + VCHIQ_SERVICE_BASE_T base;
  43092. + VCHIQ_SERVICE_HANDLE_T handle;
  43093. + unsigned int ref_count;
  43094. + int srvstate;
  43095. + VCHIQ_USERDATA_TERM_T userdata_term;
  43096. + unsigned int localport;
  43097. + unsigned int remoteport;
  43098. + int public_fourcc;
  43099. + int client_id;
  43100. + char auto_close;
  43101. + char sync;
  43102. + char closing;
  43103. + char trace;
  43104. + atomic_t poll_flags;
  43105. + short version;
  43106. + short version_min;
  43107. + short peer_version;
  43108. +
  43109. + VCHIQ_STATE_T *state;
  43110. + VCHIQ_INSTANCE_T instance;
  43111. +
  43112. + int service_use_count;
  43113. +
  43114. + VCHIQ_BULK_QUEUE_T bulk_tx;
  43115. + VCHIQ_BULK_QUEUE_T bulk_rx;
  43116. +
  43117. + struct semaphore remove_event;
  43118. + struct semaphore bulk_remove_event;
  43119. + struct mutex bulk_mutex;
  43120. +
  43121. + struct service_stats_struct {
  43122. + int quota_stalls;
  43123. + int slot_stalls;
  43124. + int bulk_stalls;
  43125. + int error_count;
  43126. + int ctrl_tx_count;
  43127. + int ctrl_rx_count;
  43128. + int bulk_tx_count;
  43129. + int bulk_rx_count;
  43130. + int bulk_aborted_count;
  43131. + uint64_t ctrl_tx_bytes;
  43132. + uint64_t ctrl_rx_bytes;
  43133. + uint64_t bulk_tx_bytes;
  43134. + uint64_t bulk_rx_bytes;
  43135. + } stats;
  43136. +} VCHIQ_SERVICE_T;
  43137. +
  43138. +/* The quota information is outside VCHIQ_SERVICE_T so that it can be
  43139. + statically allocated, since for accounting reasons a service's slot
  43140. + usage is carried over between users of the same port number.
  43141. + */
  43142. +typedef struct vchiq_service_quota_struct {
  43143. + unsigned short slot_quota;
  43144. + unsigned short slot_use_count;
  43145. + unsigned short message_quota;
  43146. + unsigned short message_use_count;
  43147. + struct semaphore quota_event;
  43148. + int previous_tx_index;
  43149. +} VCHIQ_SERVICE_QUOTA_T;
  43150. +
  43151. +typedef struct vchiq_shared_state_struct {
  43152. +
  43153. + /* A non-zero value here indicates that the content is valid. */
  43154. + int initialised;
  43155. +
  43156. + /* The first and last (inclusive) slots allocated to the owner. */
  43157. + int slot_first;
  43158. + int slot_last;
  43159. +
  43160. + /* The slot allocated to synchronous messages from the owner. */
  43161. + int slot_sync;
  43162. +
  43163. + /* Signalling this event indicates that owner's slot handler thread
  43164. + ** should run. */
  43165. + REMOTE_EVENT_T trigger;
  43166. +
  43167. + /* Indicates the byte position within the stream where the next message
  43168. + ** will be written. The least significant bits are an index into the
  43169. + ** slot. The next bits are the index of the slot in slot_queue. */
  43170. + int tx_pos;
  43171. +
  43172. + /* This event should be signalled when a slot is recycled. */
  43173. + REMOTE_EVENT_T recycle;
  43174. +
  43175. + /* The slot_queue index where the next recycled slot will be written. */
  43176. + int slot_queue_recycle;
  43177. +
  43178. + /* This event should be signalled when a synchronous message is sent. */
  43179. + REMOTE_EVENT_T sync_trigger;
  43180. +
  43181. + /* This event should be signalled when a synchronous message has been
  43182. + ** released. */
  43183. + REMOTE_EVENT_T sync_release;
  43184. +
  43185. + /* A circular buffer of slot indexes. */
  43186. + int slot_queue[VCHIQ_MAX_SLOTS_PER_SIDE];
  43187. +
  43188. + /* Debugging state */
  43189. + int debug[DEBUG_MAX];
  43190. +} VCHIQ_SHARED_STATE_T;
  43191. +
  43192. +typedef struct vchiq_slot_zero_struct {
  43193. + int magic;
  43194. + short version;
  43195. + short version_min;
  43196. + int slot_zero_size;
  43197. + int slot_size;
  43198. + int max_slots;
  43199. + int max_slots_per_side;
  43200. + int platform_data[2];
  43201. + VCHIQ_SHARED_STATE_T master;
  43202. + VCHIQ_SHARED_STATE_T slave;
  43203. + VCHIQ_SLOT_INFO_T slots[VCHIQ_MAX_SLOTS];
  43204. +} VCHIQ_SLOT_ZERO_T;
  43205. +
  43206. +struct vchiq_state_struct {
  43207. + int id;
  43208. + int initialised;
  43209. + VCHIQ_CONNSTATE_T conn_state;
  43210. + int is_master;
  43211. + short version_common;
  43212. +
  43213. + VCHIQ_SHARED_STATE_T *local;
  43214. + VCHIQ_SHARED_STATE_T *remote;
  43215. + VCHIQ_SLOT_T *slot_data;
  43216. +
  43217. + unsigned short default_slot_quota;
  43218. + unsigned short default_message_quota;
  43219. +
  43220. + /* Event indicating connect message received */
  43221. + struct semaphore connect;
  43222. +
  43223. + /* Mutex protecting services */
  43224. + struct mutex mutex;
  43225. + VCHIQ_INSTANCE_T *instance;
  43226. +
  43227. + /* Processes incoming messages */
  43228. + struct task_struct *slot_handler_thread;
  43229. +
  43230. + /* Processes recycled slots */
  43231. + struct task_struct *recycle_thread;
  43232. +
  43233. + /* Processes synchronous messages */
  43234. + struct task_struct *sync_thread;
  43235. +
  43236. + /* Local implementation of the trigger remote event */
  43237. + struct semaphore trigger_event;
  43238. +
  43239. + /* Local implementation of the recycle remote event */
  43240. + struct semaphore recycle_event;
  43241. +
  43242. + /* Local implementation of the sync trigger remote event */
  43243. + struct semaphore sync_trigger_event;
  43244. +
  43245. + /* Local implementation of the sync release remote event */
  43246. + struct semaphore sync_release_event;
  43247. +
  43248. + char *tx_data;
  43249. + char *rx_data;
  43250. + VCHIQ_SLOT_INFO_T *rx_info;
  43251. +
  43252. + struct mutex slot_mutex;
  43253. +
  43254. + struct mutex recycle_mutex;
  43255. +
  43256. + struct mutex sync_mutex;
  43257. +
  43258. + struct mutex bulk_transfer_mutex;
  43259. +
  43260. + /* Indicates the byte position within the stream from where the next
  43261. + ** message will be read. The least significant bits are an index into
  43262. + ** the slot.The next bits are the index of the slot in
  43263. + ** remote->slot_queue. */
  43264. + int rx_pos;
  43265. +
  43266. + /* A cached copy of local->tx_pos. Only write to local->tx_pos, and read
  43267. + from remote->tx_pos. */
  43268. + int local_tx_pos;
  43269. +
  43270. + /* The slot_queue index of the slot to become available next. */
  43271. + int slot_queue_available;
  43272. +
  43273. + /* A flag to indicate if any poll has been requested */
  43274. + int poll_needed;
  43275. +
  43276. + /* Ths index of the previous slot used for data messages. */
  43277. + int previous_data_index;
  43278. +
  43279. + /* The number of slots occupied by data messages. */
  43280. + unsigned short data_use_count;
  43281. +
  43282. + /* The maximum number of slots to be occupied by data messages. */
  43283. + unsigned short data_quota;
  43284. +
  43285. + /* An array of bit sets indicating which services must be polled. */
  43286. + atomic_t poll_services[BITSET_SIZE(VCHIQ_MAX_SERVICES)];
  43287. +
  43288. + /* The number of the first unused service */
  43289. + int unused_service;
  43290. +
  43291. + /* Signalled when a free slot becomes available. */
  43292. + struct semaphore slot_available_event;
  43293. +
  43294. + struct semaphore slot_remove_event;
  43295. +
  43296. + /* Signalled when a free data slot becomes available. */
  43297. + struct semaphore data_quota_event;
  43298. +
  43299. + /* Incremented when there are bulk transfers which cannot be processed
  43300. + * whilst paused and must be processed on resume */
  43301. + int deferred_bulks;
  43302. +
  43303. + struct state_stats_struct {
  43304. + int slot_stalls;
  43305. + int data_stalls;
  43306. + int ctrl_tx_count;
  43307. + int ctrl_rx_count;
  43308. + int error_count;
  43309. + } stats;
  43310. +
  43311. + VCHIQ_SERVICE_T * services[VCHIQ_MAX_SERVICES];
  43312. + VCHIQ_SERVICE_QUOTA_T service_quotas[VCHIQ_MAX_SERVICES];
  43313. + VCHIQ_SLOT_INFO_T slot_info[VCHIQ_MAX_SLOTS];
  43314. +
  43315. + VCHIQ_PLATFORM_STATE_T platform_state;
  43316. +};
  43317. +
  43318. +struct bulk_waiter {
  43319. + VCHIQ_BULK_T *bulk;
  43320. + struct semaphore event;
  43321. + int actual;
  43322. +};
  43323. +
  43324. +extern spinlock_t bulk_waiter_spinlock;
  43325. +
  43326. +extern int vchiq_core_log_level;
  43327. +extern int vchiq_core_msg_log_level;
  43328. +extern int vchiq_sync_log_level;
  43329. +
  43330. +extern VCHIQ_STATE_T *vchiq_states[VCHIQ_MAX_STATES];
  43331. +
  43332. +extern const char *
  43333. +get_conn_state_name(VCHIQ_CONNSTATE_T conn_state);
  43334. +
  43335. +extern VCHIQ_SLOT_ZERO_T *
  43336. +vchiq_init_slots(void *mem_base, int mem_size);
  43337. +
  43338. +extern VCHIQ_STATUS_T
  43339. +vchiq_init_state(VCHIQ_STATE_T *state, VCHIQ_SLOT_ZERO_T *slot_zero,
  43340. + int is_master);
  43341. +
  43342. +extern VCHIQ_STATUS_T
  43343. +vchiq_connect_internal(VCHIQ_STATE_T *state, VCHIQ_INSTANCE_T instance);
  43344. +
  43345. +extern VCHIQ_SERVICE_T *
  43346. +vchiq_add_service_internal(VCHIQ_STATE_T *state,
  43347. + const VCHIQ_SERVICE_PARAMS_T *params, int srvstate,
  43348. + VCHIQ_INSTANCE_T instance, VCHIQ_USERDATA_TERM_T userdata_term);
  43349. +
  43350. +extern VCHIQ_STATUS_T
  43351. +vchiq_open_service_internal(VCHIQ_SERVICE_T *service, int client_id);
  43352. +
  43353. +extern VCHIQ_STATUS_T
  43354. +vchiq_close_service_internal(VCHIQ_SERVICE_T *service, int close_recvd);
  43355. +
  43356. +extern void
  43357. +vchiq_terminate_service_internal(VCHIQ_SERVICE_T *service);
  43358. +
  43359. +extern void
  43360. +vchiq_free_service_internal(VCHIQ_SERVICE_T *service);
  43361. +
  43362. +extern VCHIQ_STATUS_T
  43363. +vchiq_shutdown_internal(VCHIQ_STATE_T *state, VCHIQ_INSTANCE_T instance);
  43364. +
  43365. +extern VCHIQ_STATUS_T
  43366. +vchiq_pause_internal(VCHIQ_STATE_T *state);
  43367. +
  43368. +extern VCHIQ_STATUS_T
  43369. +vchiq_resume_internal(VCHIQ_STATE_T *state);
  43370. +
  43371. +extern void
  43372. +remote_event_pollall(VCHIQ_STATE_T *state);
  43373. +
  43374. +extern VCHIQ_STATUS_T
  43375. +vchiq_bulk_transfer(VCHIQ_SERVICE_HANDLE_T handle,
  43376. + VCHI_MEM_HANDLE_T memhandle, void *offset, int size, void *userdata,
  43377. + VCHIQ_BULK_MODE_T mode, VCHIQ_BULK_DIR_T dir);
  43378. +
  43379. +extern void
  43380. +vchiq_dump_state(void *dump_context, VCHIQ_STATE_T *state);
  43381. +
  43382. +extern void
  43383. +vchiq_dump_service_state(void *dump_context, VCHIQ_SERVICE_T *service);
  43384. +
  43385. +extern void
  43386. +vchiq_loud_error_header(void);
  43387. +
  43388. +extern void
  43389. +vchiq_loud_error_footer(void);
  43390. +
  43391. +extern void
  43392. +request_poll(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service, int poll_type);
  43393. +
  43394. +static inline VCHIQ_SERVICE_T *
  43395. +handle_to_service(VCHIQ_SERVICE_HANDLE_T handle)
  43396. +{
  43397. + VCHIQ_STATE_T *state = vchiq_states[(handle / VCHIQ_MAX_SERVICES) &
  43398. + (VCHIQ_MAX_STATES - 1)];
  43399. + if (!state)
  43400. + return NULL;
  43401. +
  43402. + return state->services[handle & (VCHIQ_MAX_SERVICES - 1)];
  43403. +}
  43404. +
  43405. +extern VCHIQ_SERVICE_T *
  43406. +find_service_by_handle(VCHIQ_SERVICE_HANDLE_T handle);
  43407. +
  43408. +extern VCHIQ_SERVICE_T *
  43409. +find_service_by_port(VCHIQ_STATE_T *state, int localport);
  43410. +
  43411. +extern VCHIQ_SERVICE_T *
  43412. +find_service_for_instance(VCHIQ_INSTANCE_T instance,
  43413. + VCHIQ_SERVICE_HANDLE_T handle);
  43414. +
  43415. +extern VCHIQ_SERVICE_T *
  43416. +find_closed_service_for_instance(VCHIQ_INSTANCE_T instance,
  43417. + VCHIQ_SERVICE_HANDLE_T handle);
  43418. +
  43419. +extern VCHIQ_SERVICE_T *
  43420. +next_service_by_instance(VCHIQ_STATE_T *state, VCHIQ_INSTANCE_T instance,
  43421. + int *pidx);
  43422. +
  43423. +extern void
  43424. +lock_service(VCHIQ_SERVICE_T *service);
  43425. +
  43426. +extern void
  43427. +unlock_service(VCHIQ_SERVICE_T *service);
  43428. +
  43429. +/* The following functions are called from vchiq_core, and external
  43430. +** implementations must be provided. */
  43431. +
  43432. +extern VCHIQ_STATUS_T
  43433. +vchiq_prepare_bulk_data(VCHIQ_BULK_T *bulk,
  43434. + VCHI_MEM_HANDLE_T memhandle, void *offset, int size, int dir);
  43435. +
  43436. +extern void
  43437. +vchiq_transfer_bulk(VCHIQ_BULK_T *bulk);
  43438. +
  43439. +extern void
  43440. +vchiq_complete_bulk(VCHIQ_BULK_T *bulk);
  43441. +
  43442. +extern VCHIQ_STATUS_T
  43443. +vchiq_copy_from_user(void *dst, const void *src, int size);
  43444. +
  43445. +extern void
  43446. +remote_event_signal(REMOTE_EVENT_T *event);
  43447. +
  43448. +void
  43449. +vchiq_platform_check_suspend(VCHIQ_STATE_T *state);
  43450. +
  43451. +extern void
  43452. +vchiq_platform_paused(VCHIQ_STATE_T *state);
  43453. +
  43454. +extern VCHIQ_STATUS_T
  43455. +vchiq_platform_resume(VCHIQ_STATE_T *state);
  43456. +
  43457. +extern void
  43458. +vchiq_platform_resumed(VCHIQ_STATE_T *state);
  43459. +
  43460. +extern void
  43461. +vchiq_dump(void *dump_context, const char *str, int len);
  43462. +
  43463. +extern void
  43464. +vchiq_dump_platform_state(void *dump_context);
  43465. +
  43466. +extern void
  43467. +vchiq_dump_platform_instances(void *dump_context);
  43468. +
  43469. +extern void
  43470. +vchiq_dump_platform_service_state(void *dump_context,
  43471. + VCHIQ_SERVICE_T *service);
  43472. +
  43473. +extern VCHIQ_STATUS_T
  43474. +vchiq_use_service_internal(VCHIQ_SERVICE_T *service);
  43475. +
  43476. +extern VCHIQ_STATUS_T
  43477. +vchiq_release_service_internal(VCHIQ_SERVICE_T *service);
  43478. +
  43479. +extern void
  43480. +vchiq_on_remote_use(VCHIQ_STATE_T *state);
  43481. +
  43482. +extern void
  43483. +vchiq_on_remote_release(VCHIQ_STATE_T *state);
  43484. +
  43485. +extern VCHIQ_STATUS_T
  43486. +vchiq_platform_init_state(VCHIQ_STATE_T *state);
  43487. +
  43488. +extern VCHIQ_STATUS_T
  43489. +vchiq_check_service(VCHIQ_SERVICE_T *service);
  43490. +
  43491. +extern void
  43492. +vchiq_on_remote_use_active(VCHIQ_STATE_T *state);
  43493. +
  43494. +extern VCHIQ_STATUS_T
  43495. +vchiq_send_remote_use(VCHIQ_STATE_T *state);
  43496. +
  43497. +extern VCHIQ_STATUS_T
  43498. +vchiq_send_remote_release(VCHIQ_STATE_T *state);
  43499. +
  43500. +extern VCHIQ_STATUS_T
  43501. +vchiq_send_remote_use_active(VCHIQ_STATE_T *state);
  43502. +
  43503. +extern void
  43504. +vchiq_platform_conn_state_changed(VCHIQ_STATE_T *state,
  43505. + VCHIQ_CONNSTATE_T oldstate, VCHIQ_CONNSTATE_T newstate);
  43506. +
  43507. +extern void
  43508. +vchiq_platform_handle_timeout(VCHIQ_STATE_T *state);
  43509. +
  43510. +extern void
  43511. +vchiq_set_conn_state(VCHIQ_STATE_T *state, VCHIQ_CONNSTATE_T newstate);
  43512. +
  43513. +
  43514. +extern void
  43515. +vchiq_log_dump_mem(const char *label, uint32_t addr, const void *voidMem,
  43516. + size_t numBytes);
  43517. +
  43518. +#endif
  43519. diff -Nur linux-3.18.8/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_debugfs.c linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_debugfs.c
  43520. --- linux-3.18.8/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_debugfs.c 1970-01-01 01:00:00.000000000 +0100
  43521. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_debugfs.c 2015-03-05 14:40:14.401715819 +0100
  43522. @@ -0,0 +1,383 @@
  43523. +/**
  43524. + * Copyright (c) 2014 Raspberry Pi (Trading) Ltd. All rights reserved.
  43525. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  43526. + *
  43527. + * Redistribution and use in source and binary forms, with or without
  43528. + * modification, are permitted provided that the following conditions
  43529. + * are met:
  43530. + * 1. Redistributions of source code must retain the above copyright
  43531. + * notice, this list of conditions, and the following disclaimer,
  43532. + * without modification.
  43533. + * 2. Redistributions in binary form must reproduce the above copyright
  43534. + * notice, this list of conditions and the following disclaimer in the
  43535. + * documentation and/or other materials provided with the distribution.
  43536. + * 3. The names of the above-listed copyright holders may not be used
  43537. + * to endorse or promote products derived from this software without
  43538. + * specific prior written permission.
  43539. + *
  43540. + * ALTERNATIVELY, this software may be distributed under the terms of the
  43541. + * GNU General Public License ("GPL") version 2, as published by the Free
  43542. + * Software Foundation.
  43543. + *
  43544. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  43545. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  43546. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  43547. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  43548. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  43549. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  43550. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  43551. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  43552. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  43553. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  43554. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  43555. + */
  43556. +
  43557. +
  43558. +#include <linux/debugfs.h>
  43559. +#include "vchiq_core.h"
  43560. +#include "vchiq_arm.h"
  43561. +#include "vchiq_debugfs.h"
  43562. +
  43563. +#ifdef CONFIG_DEBUG_FS
  43564. +
  43565. +/****************************************************************************
  43566. +*
  43567. +* log category entries
  43568. +*
  43569. +***************************************************************************/
  43570. +#define DEBUGFS_WRITE_BUF_SIZE 256
  43571. +
  43572. +#define VCHIQ_LOG_ERROR_STR "error"
  43573. +#define VCHIQ_LOG_WARNING_STR "warning"
  43574. +#define VCHIQ_LOG_INFO_STR "info"
  43575. +#define VCHIQ_LOG_TRACE_STR "trace"
  43576. +
  43577. +
  43578. +/* Top-level debug info */
  43579. +struct vchiq_debugfs_info {
  43580. + /* Global 'vchiq' debugfs entry used by all instances */
  43581. + struct dentry *vchiq_cfg_dir;
  43582. +
  43583. + /* one entry per client process */
  43584. + struct dentry *clients;
  43585. +
  43586. + /* log categories */
  43587. + struct dentry *log_categories;
  43588. +};
  43589. +
  43590. +static struct vchiq_debugfs_info debugfs_info;
  43591. +
  43592. +/* Log category debugfs entries */
  43593. +struct vchiq_debugfs_log_entry {
  43594. + const char *name;
  43595. + int *plevel;
  43596. + struct dentry *dir;
  43597. +};
  43598. +
  43599. +static struct vchiq_debugfs_log_entry vchiq_debugfs_log_entries[] = {
  43600. + { "core", &vchiq_core_log_level },
  43601. + { "msg", &vchiq_core_msg_log_level },
  43602. + { "sync", &vchiq_sync_log_level },
  43603. + { "susp", &vchiq_susp_log_level },
  43604. + { "arm", &vchiq_arm_log_level },
  43605. +};
  43606. +static int n_log_entries =
  43607. + sizeof(vchiq_debugfs_log_entries)/sizeof(vchiq_debugfs_log_entries[0]);
  43608. +
  43609. +
  43610. +static struct dentry *vchiq_clients_top(void);
  43611. +static struct dentry *vchiq_debugfs_top(void);
  43612. +
  43613. +static int debugfs_log_show(struct seq_file *f, void *offset)
  43614. +{
  43615. + int *levp = f->private;
  43616. + char *log_value = NULL;
  43617. +
  43618. + switch (*levp) {
  43619. + case VCHIQ_LOG_ERROR:
  43620. + log_value = VCHIQ_LOG_ERROR_STR;
  43621. + break;
  43622. + case VCHIQ_LOG_WARNING:
  43623. + log_value = VCHIQ_LOG_WARNING_STR;
  43624. + break;
  43625. + case VCHIQ_LOG_INFO:
  43626. + log_value = VCHIQ_LOG_INFO_STR;
  43627. + break;
  43628. + case VCHIQ_LOG_TRACE:
  43629. + log_value = VCHIQ_LOG_TRACE_STR;
  43630. + break;
  43631. + default:
  43632. + break;
  43633. + }
  43634. +
  43635. + seq_printf(f, "%s\n", log_value ? log_value : "(null)");
  43636. +
  43637. + return 0;
  43638. +}
  43639. +
  43640. +static int debugfs_log_open(struct inode *inode, struct file *file)
  43641. +{
  43642. + return single_open(file, debugfs_log_show, inode->i_private);
  43643. +}
  43644. +
  43645. +static int debugfs_log_write(struct file *file,
  43646. + const char __user *buffer,
  43647. + size_t count, loff_t *ppos)
  43648. +{
  43649. + struct seq_file *f = (struct seq_file *)file->private_data;
  43650. + int *levp = f->private;
  43651. + char kbuf[DEBUGFS_WRITE_BUF_SIZE + 1];
  43652. +
  43653. + memset(kbuf, 0, DEBUGFS_WRITE_BUF_SIZE + 1);
  43654. + if (count >= DEBUGFS_WRITE_BUF_SIZE)
  43655. + count = DEBUGFS_WRITE_BUF_SIZE;
  43656. +
  43657. + if (copy_from_user(kbuf, buffer, count) != 0)
  43658. + return -EFAULT;
  43659. + kbuf[count - 1] = 0;
  43660. +
  43661. + if (strncmp("error", kbuf, strlen("error")) == 0)
  43662. + *levp = VCHIQ_LOG_ERROR;
  43663. + else if (strncmp("warning", kbuf, strlen("warning")) == 0)
  43664. + *levp = VCHIQ_LOG_WARNING;
  43665. + else if (strncmp("info", kbuf, strlen("info")) == 0)
  43666. + *levp = VCHIQ_LOG_INFO;
  43667. + else if (strncmp("trace", kbuf, strlen("trace")) == 0)
  43668. + *levp = VCHIQ_LOG_TRACE;
  43669. + else
  43670. + *levp = VCHIQ_LOG_DEFAULT;
  43671. +
  43672. + *ppos += count;
  43673. +
  43674. + return count;
  43675. +}
  43676. +
  43677. +static const struct file_operations debugfs_log_fops = {
  43678. + .owner = THIS_MODULE,
  43679. + .open = debugfs_log_open,
  43680. + .write = debugfs_log_write,
  43681. + .read = seq_read,
  43682. + .llseek = seq_lseek,
  43683. + .release = single_release,
  43684. +};
  43685. +
  43686. +/* create an entry under <debugfs>/vchiq/log for each log category */
  43687. +static int vchiq_debugfs_create_log_entries(struct dentry *top)
  43688. +{
  43689. + struct dentry *dir;
  43690. + size_t i;
  43691. + int ret = 0;
  43692. + dir = debugfs_create_dir("log", vchiq_debugfs_top());
  43693. + if (!dir)
  43694. + return -ENOMEM;
  43695. + debugfs_info.log_categories = dir;
  43696. +
  43697. + for (i = 0; i < n_log_entries; i++) {
  43698. + void *levp = (void *)vchiq_debugfs_log_entries[i].plevel;
  43699. + dir = debugfs_create_file(vchiq_debugfs_log_entries[i].name,
  43700. + 0644,
  43701. + debugfs_info.log_categories,
  43702. + levp,
  43703. + &debugfs_log_fops);
  43704. + if (!dir) {
  43705. + ret = -ENOMEM;
  43706. + break;
  43707. + }
  43708. +
  43709. + vchiq_debugfs_log_entries[i].dir = dir;
  43710. + }
  43711. + return ret;
  43712. +}
  43713. +
  43714. +static int debugfs_usecount_show(struct seq_file *f, void *offset)
  43715. +{
  43716. + VCHIQ_INSTANCE_T instance = f->private;
  43717. + int use_count;
  43718. +
  43719. + use_count = vchiq_instance_get_use_count(instance);
  43720. + seq_printf(f, "%d\n", use_count);
  43721. +
  43722. + return 0;
  43723. +}
  43724. +
  43725. +static int debugfs_usecount_open(struct inode *inode, struct file *file)
  43726. +{
  43727. + return single_open(file, debugfs_usecount_show, inode->i_private);
  43728. +}
  43729. +
  43730. +static const struct file_operations debugfs_usecount_fops = {
  43731. + .owner = THIS_MODULE,
  43732. + .open = debugfs_usecount_open,
  43733. + .read = seq_read,
  43734. + .llseek = seq_lseek,
  43735. + .release = single_release,
  43736. +};
  43737. +
  43738. +static int debugfs_trace_show(struct seq_file *f, void *offset)
  43739. +{
  43740. + VCHIQ_INSTANCE_T instance = f->private;
  43741. + int trace;
  43742. +
  43743. + trace = vchiq_instance_get_trace(instance);
  43744. + seq_printf(f, "%s\n", trace ? "Y" : "N");
  43745. +
  43746. + return 0;
  43747. +}
  43748. +
  43749. +static int debugfs_trace_open(struct inode *inode, struct file *file)
  43750. +{
  43751. + return single_open(file, debugfs_trace_show, inode->i_private);
  43752. +}
  43753. +
  43754. +static int debugfs_trace_write(struct file *file,
  43755. + const char __user *buffer,
  43756. + size_t count, loff_t *ppos)
  43757. +{
  43758. + struct seq_file *f = (struct seq_file *)file->private_data;
  43759. + VCHIQ_INSTANCE_T instance = f->private;
  43760. + char firstchar;
  43761. +
  43762. + if (copy_from_user(&firstchar, buffer, 1) != 0)
  43763. + return -EFAULT;
  43764. +
  43765. + switch (firstchar) {
  43766. + case 'Y':
  43767. + case 'y':
  43768. + case '1':
  43769. + vchiq_instance_set_trace(instance, 1);
  43770. + break;
  43771. + case 'N':
  43772. + case 'n':
  43773. + case '0':
  43774. + vchiq_instance_set_trace(instance, 0);
  43775. + break;
  43776. + default:
  43777. + break;
  43778. + }
  43779. +
  43780. + *ppos += count;
  43781. +
  43782. + return count;
  43783. +}
  43784. +
  43785. +static const struct file_operations debugfs_trace_fops = {
  43786. + .owner = THIS_MODULE,
  43787. + .open = debugfs_trace_open,
  43788. + .write = debugfs_trace_write,
  43789. + .read = seq_read,
  43790. + .llseek = seq_lseek,
  43791. + .release = single_release,
  43792. +};
  43793. +
  43794. +/* add an instance (process) to the debugfs entries */
  43795. +int vchiq_debugfs_add_instance(VCHIQ_INSTANCE_T instance)
  43796. +{
  43797. + char pidstr[16];
  43798. + struct dentry *top, *use_count, *trace;
  43799. + struct dentry *clients = vchiq_clients_top();
  43800. +
  43801. + snprintf(pidstr, sizeof(pidstr), "%d",
  43802. + vchiq_instance_get_pid(instance));
  43803. +
  43804. + top = debugfs_create_dir(pidstr, clients);
  43805. + if (!top)
  43806. + goto fail_top;
  43807. +
  43808. + use_count = debugfs_create_file("use_count",
  43809. + 0444, top,
  43810. + instance,
  43811. + &debugfs_usecount_fops);
  43812. + if (!use_count)
  43813. + goto fail_use_count;
  43814. +
  43815. + trace = debugfs_create_file("trace",
  43816. + 0644, top,
  43817. + instance,
  43818. + &debugfs_trace_fops);
  43819. + if (!trace)
  43820. + goto fail_trace;
  43821. +
  43822. + vchiq_instance_get_debugfs_node(instance)->dentry = top;
  43823. +
  43824. + return 0;
  43825. +
  43826. +fail_trace:
  43827. + debugfs_remove(use_count);
  43828. +fail_use_count:
  43829. + debugfs_remove(top);
  43830. +fail_top:
  43831. + return -ENOMEM;
  43832. +}
  43833. +
  43834. +void vchiq_debugfs_remove_instance(VCHIQ_INSTANCE_T instance)
  43835. +{
  43836. + VCHIQ_DEBUGFS_NODE_T *node = vchiq_instance_get_debugfs_node(instance);
  43837. + debugfs_remove_recursive(node->dentry);
  43838. +}
  43839. +
  43840. +
  43841. +int vchiq_debugfs_init(void)
  43842. +{
  43843. + BUG_ON(debugfs_info.vchiq_cfg_dir != NULL);
  43844. +
  43845. + debugfs_info.vchiq_cfg_dir = debugfs_create_dir("vchiq", NULL);
  43846. + if (debugfs_info.vchiq_cfg_dir == NULL)
  43847. + goto fail;
  43848. +
  43849. + debugfs_info.clients = debugfs_create_dir("clients",
  43850. + vchiq_debugfs_top());
  43851. + if (!debugfs_info.clients)
  43852. + goto fail;
  43853. +
  43854. + if (vchiq_debugfs_create_log_entries(vchiq_debugfs_top()) != 0)
  43855. + goto fail;
  43856. +
  43857. + return 0;
  43858. +
  43859. +fail:
  43860. + vchiq_debugfs_deinit();
  43861. + vchiq_log_error(vchiq_arm_log_level,
  43862. + "%s: failed to create debugfs directory",
  43863. + __func__);
  43864. +
  43865. + return -ENOMEM;
  43866. +}
  43867. +
  43868. +/* remove all the debugfs entries */
  43869. +void vchiq_debugfs_deinit(void)
  43870. +{
  43871. + debugfs_remove_recursive(vchiq_debugfs_top());
  43872. +}
  43873. +
  43874. +static struct dentry *vchiq_clients_top(void)
  43875. +{
  43876. + return debugfs_info.clients;
  43877. +}
  43878. +
  43879. +static struct dentry *vchiq_debugfs_top(void)
  43880. +{
  43881. + BUG_ON(debugfs_info.vchiq_cfg_dir == NULL);
  43882. + return debugfs_info.vchiq_cfg_dir;
  43883. +}
  43884. +
  43885. +#else /* CONFIG_DEBUG_FS */
  43886. +
  43887. +int vchiq_debugfs_init(void)
  43888. +{
  43889. + return 0;
  43890. +}
  43891. +
  43892. +void vchiq_debugfs_deinit(void)
  43893. +{
  43894. +}
  43895. +
  43896. +int vchiq_debugfs_add_instance(VCHIQ_INSTANCE_T instance)
  43897. +{
  43898. + return 0;
  43899. +}
  43900. +
  43901. +void vchiq_debugfs_remove_instance(VCHIQ_INSTANCE_T instance)
  43902. +{
  43903. +}
  43904. +
  43905. +#endif /* CONFIG_DEBUG_FS */
  43906. diff -Nur linux-3.18.8/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_debugfs.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_debugfs.h
  43907. --- linux-3.18.8/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_debugfs.h 1970-01-01 01:00:00.000000000 +0100
  43908. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_debugfs.h 2015-03-05 14:40:14.401715819 +0100
  43909. @@ -0,0 +1,52 @@
  43910. +/**
  43911. + * Copyright (c) 2014 Raspberry Pi (Trading) Ltd. All rights reserved.
  43912. + *
  43913. + * Redistribution and use in source and binary forms, with or without
  43914. + * modification, are permitted provided that the following conditions
  43915. + * are met:
  43916. + * 1. Redistributions of source code must retain the above copyright
  43917. + * notice, this list of conditions, and the following disclaimer,
  43918. + * without modification.
  43919. + * 2. Redistributions in binary form must reproduce the above copyright
  43920. + * notice, this list of conditions and the following disclaimer in the
  43921. + * documentation and/or other materials provided with the distribution.
  43922. + * 3. The names of the above-listed copyright holders may not be used
  43923. + * to endorse or promote products derived from this software without
  43924. + * specific prior written permission.
  43925. + *
  43926. + * ALTERNATIVELY, this software may be distributed under the terms of the
  43927. + * GNU General Public License ("GPL") version 2, as published by the Free
  43928. + * Software Foundation.
  43929. + *
  43930. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  43931. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  43932. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  43933. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  43934. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  43935. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  43936. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  43937. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  43938. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  43939. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  43940. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  43941. + */
  43942. +
  43943. +#ifndef VCHIQ_DEBUGFS_H
  43944. +#define VCHIQ_DEBUGFS_H
  43945. +
  43946. +#include "vchiq_core.h"
  43947. +
  43948. +typedef struct vchiq_debugfs_node_struct
  43949. +{
  43950. + struct dentry *dentry;
  43951. +} VCHIQ_DEBUGFS_NODE_T;
  43952. +
  43953. +int vchiq_debugfs_init(void);
  43954. +
  43955. +void vchiq_debugfs_deinit(void);
  43956. +
  43957. +int vchiq_debugfs_add_instance(VCHIQ_INSTANCE_T instance);
  43958. +
  43959. +void vchiq_debugfs_remove_instance(VCHIQ_INSTANCE_T instance);
  43960. +
  43961. +#endif /* VCHIQ_DEBUGFS_H */
  43962. diff -Nur linux-3.18.8/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_genversion linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_genversion
  43963. --- linux-3.18.8/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_genversion 1970-01-01 01:00:00.000000000 +0100
  43964. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_genversion 2015-03-05 14:40:14.401715819 +0100
  43965. @@ -0,0 +1,87 @@
  43966. +#!/usr/bin/perl -w
  43967. +
  43968. +use strict;
  43969. +
  43970. +#
  43971. +# Generate a version from available information
  43972. +#
  43973. +
  43974. +my $prefix = shift @ARGV;
  43975. +my $root = shift @ARGV;
  43976. +
  43977. +
  43978. +if ( not defined $root ) {
  43979. + die "usage: $0 prefix root-dir\n";
  43980. +}
  43981. +
  43982. +if ( ! -d $root ) {
  43983. + die "root directory $root not found\n";
  43984. +}
  43985. +
  43986. +my $version = "unknown";
  43987. +my $tainted = "";
  43988. +
  43989. +if ( -d "$root/.git" ) {
  43990. + # attempt to work out git version. only do so
  43991. + # on a linux build host, as cygwin builds are
  43992. + # already slow enough
  43993. +
  43994. + if ( -f "/usr/bin/git" || -f "/usr/local/bin/git" ) {
  43995. + if (not open(F, "git --git-dir $root/.git rev-parse --verify HEAD|")) {
  43996. + $version = "no git version";
  43997. + }
  43998. + else {
  43999. + $version = <F>;
  44000. + $version =~ s/[ \r\n]*$//; # chomp may not be enough (cygwin).
  44001. + $version =~ s/^[ \r\n]*//; # chomp may not be enough (cygwin).
  44002. + }
  44003. +
  44004. + if (open(G, "git --git-dir $root/.git status --porcelain|")) {
  44005. + $tainted = <G>;
  44006. + $tainted =~ s/[ \r\n]*$//; # chomp may not be enough (cygwin).
  44007. + $tainted =~ s/^[ \r\n]*//; # chomp may not be enough (cygwin).
  44008. + if (length $tainted) {
  44009. + $version = join ' ', $version, "(tainted)";
  44010. + }
  44011. + else {
  44012. + $version = join ' ', $version, "(clean)";
  44013. + }
  44014. + }
  44015. + }
  44016. +}
  44017. +
  44018. +my $hostname = `hostname`;
  44019. +$hostname =~ s/[ \r\n]*$//; # chomp may not be enough (cygwin).
  44020. +$hostname =~ s/^[ \r\n]*//; # chomp may not be enough (cygwin).
  44021. +
  44022. +
  44023. +print STDERR "Version $version\n";
  44024. +print <<EOF;
  44025. +#include "${prefix}_build_info.h"
  44026. +#include <linux/broadcom/vc_debug_sym.h>
  44027. +
  44028. +VC_DEBUG_DECLARE_STRING_VAR( ${prefix}_build_hostname, "$hostname" );
  44029. +VC_DEBUG_DECLARE_STRING_VAR( ${prefix}_build_version, "$version" );
  44030. +VC_DEBUG_DECLARE_STRING_VAR( ${prefix}_build_time, __TIME__ );
  44031. +VC_DEBUG_DECLARE_STRING_VAR( ${prefix}_build_date, __DATE__ );
  44032. +
  44033. +const char *vchiq_get_build_hostname( void )
  44034. +{
  44035. + return vchiq_build_hostname;
  44036. +}
  44037. +
  44038. +const char *vchiq_get_build_version( void )
  44039. +{
  44040. + return vchiq_build_version;
  44041. +}
  44042. +
  44043. +const char *vchiq_get_build_date( void )
  44044. +{
  44045. + return vchiq_build_date;
  44046. +}
  44047. +
  44048. +const char *vchiq_get_build_time( void )
  44049. +{
  44050. + return vchiq_build_time;
  44051. +}
  44052. +EOF
  44053. diff -Nur linux-3.18.8/drivers/misc/vc04_services/interface/vchiq_arm/vchiq.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq.h
  44054. --- linux-3.18.8/drivers/misc/vc04_services/interface/vchiq_arm/vchiq.h 1970-01-01 01:00:00.000000000 +0100
  44055. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq.h 2015-03-05 14:40:14.401715819 +0100
  44056. @@ -0,0 +1,40 @@
  44057. +/**
  44058. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  44059. + *
  44060. + * Redistribution and use in source and binary forms, with or without
  44061. + * modification, are permitted provided that the following conditions
  44062. + * are met:
  44063. + * 1. Redistributions of source code must retain the above copyright
  44064. + * notice, this list of conditions, and the following disclaimer,
  44065. + * without modification.
  44066. + * 2. Redistributions in binary form must reproduce the above copyright
  44067. + * notice, this list of conditions and the following disclaimer in the
  44068. + * documentation and/or other materials provided with the distribution.
  44069. + * 3. The names of the above-listed copyright holders may not be used
  44070. + * to endorse or promote products derived from this software without
  44071. + * specific prior written permission.
  44072. + *
  44073. + * ALTERNATIVELY, this software may be distributed under the terms of the
  44074. + * GNU General Public License ("GPL") version 2, as published by the Free
  44075. + * Software Foundation.
  44076. + *
  44077. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  44078. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  44079. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  44080. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  44081. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  44082. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  44083. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  44084. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  44085. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  44086. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  44087. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  44088. + */
  44089. +
  44090. +#ifndef VCHIQ_VCHIQ_H
  44091. +#define VCHIQ_VCHIQ_H
  44092. +
  44093. +#include "vchiq_if.h"
  44094. +#include "vchiq_util.h"
  44095. +
  44096. +#endif
  44097. diff -Nur linux-3.18.8/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_if.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_if.h
  44098. --- linux-3.18.8/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_if.h 1970-01-01 01:00:00.000000000 +0100
  44099. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_if.h 2015-03-05 14:40:14.401715819 +0100
  44100. @@ -0,0 +1,189 @@
  44101. +/**
  44102. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  44103. + *
  44104. + * Redistribution and use in source and binary forms, with or without
  44105. + * modification, are permitted provided that the following conditions
  44106. + * are met:
  44107. + * 1. Redistributions of source code must retain the above copyright
  44108. + * notice, this list of conditions, and the following disclaimer,
  44109. + * without modification.
  44110. + * 2. Redistributions in binary form must reproduce the above copyright
  44111. + * notice, this list of conditions and the following disclaimer in the
  44112. + * documentation and/or other materials provided with the distribution.
  44113. + * 3. The names of the above-listed copyright holders may not be used
  44114. + * to endorse or promote products derived from this software without
  44115. + * specific prior written permission.
  44116. + *
  44117. + * ALTERNATIVELY, this software may be distributed under the terms of the
  44118. + * GNU General Public License ("GPL") version 2, as published by the Free
  44119. + * Software Foundation.
  44120. + *
  44121. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  44122. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  44123. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  44124. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  44125. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  44126. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  44127. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  44128. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  44129. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  44130. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  44131. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  44132. + */
  44133. +
  44134. +#ifndef VCHIQ_IF_H
  44135. +#define VCHIQ_IF_H
  44136. +
  44137. +#include "interface/vchi/vchi_mh.h"
  44138. +
  44139. +#define VCHIQ_SERVICE_HANDLE_INVALID 0
  44140. +
  44141. +#define VCHIQ_SLOT_SIZE 4096
  44142. +#define VCHIQ_MAX_MSG_SIZE (VCHIQ_SLOT_SIZE - sizeof(VCHIQ_HEADER_T))
  44143. +#define VCHIQ_CHANNEL_SIZE VCHIQ_MAX_MSG_SIZE /* For backwards compatibility */
  44144. +
  44145. +#define VCHIQ_MAKE_FOURCC(x0, x1, x2, x3) \
  44146. + (((x0) << 24) | ((x1) << 16) | ((x2) << 8) | (x3))
  44147. +#define VCHIQ_GET_SERVICE_USERDATA(service) vchiq_get_service_userdata(service)
  44148. +#define VCHIQ_GET_SERVICE_FOURCC(service) vchiq_get_service_fourcc(service)
  44149. +
  44150. +typedef enum {
  44151. + VCHIQ_SERVICE_OPENED, /* service, -, - */
  44152. + VCHIQ_SERVICE_CLOSED, /* service, -, - */
  44153. + VCHIQ_MESSAGE_AVAILABLE, /* service, header, - */
  44154. + VCHIQ_BULK_TRANSMIT_DONE, /* service, -, bulk_userdata */
  44155. + VCHIQ_BULK_RECEIVE_DONE, /* service, -, bulk_userdata */
  44156. + VCHIQ_BULK_TRANSMIT_ABORTED, /* service, -, bulk_userdata */
  44157. + VCHIQ_BULK_RECEIVE_ABORTED /* service, -, bulk_userdata */
  44158. +} VCHIQ_REASON_T;
  44159. +
  44160. +typedef enum {
  44161. + VCHIQ_ERROR = -1,
  44162. + VCHIQ_SUCCESS = 0,
  44163. + VCHIQ_RETRY = 1
  44164. +} VCHIQ_STATUS_T;
  44165. +
  44166. +typedef enum {
  44167. + VCHIQ_BULK_MODE_CALLBACK,
  44168. + VCHIQ_BULK_MODE_BLOCKING,
  44169. + VCHIQ_BULK_MODE_NOCALLBACK,
  44170. + VCHIQ_BULK_MODE_WAITING /* Reserved for internal use */
  44171. +} VCHIQ_BULK_MODE_T;
  44172. +
  44173. +typedef enum {
  44174. + VCHIQ_SERVICE_OPTION_AUTOCLOSE,
  44175. + VCHIQ_SERVICE_OPTION_SLOT_QUOTA,
  44176. + VCHIQ_SERVICE_OPTION_MESSAGE_QUOTA,
  44177. + VCHIQ_SERVICE_OPTION_SYNCHRONOUS,
  44178. + VCHIQ_SERVICE_OPTION_TRACE
  44179. +} VCHIQ_SERVICE_OPTION_T;
  44180. +
  44181. +typedef struct vchiq_header_struct {
  44182. + /* The message identifier - opaque to applications. */
  44183. + int msgid;
  44184. +
  44185. + /* Size of message data. */
  44186. + unsigned int size;
  44187. +
  44188. + char data[0]; /* message */
  44189. +} VCHIQ_HEADER_T;
  44190. +
  44191. +typedef struct {
  44192. + const void *data;
  44193. + unsigned int size;
  44194. +} VCHIQ_ELEMENT_T;
  44195. +
  44196. +typedef unsigned int VCHIQ_SERVICE_HANDLE_T;
  44197. +
  44198. +typedef VCHIQ_STATUS_T (*VCHIQ_CALLBACK_T)(VCHIQ_REASON_T, VCHIQ_HEADER_T *,
  44199. + VCHIQ_SERVICE_HANDLE_T, void *);
  44200. +
  44201. +typedef struct vchiq_service_base_struct {
  44202. + int fourcc;
  44203. + VCHIQ_CALLBACK_T callback;
  44204. + void *userdata;
  44205. +} VCHIQ_SERVICE_BASE_T;
  44206. +
  44207. +typedef struct vchiq_service_params_struct {
  44208. + int fourcc;
  44209. + VCHIQ_CALLBACK_T callback;
  44210. + void *userdata;
  44211. + short version; /* Increment for non-trivial changes */
  44212. + short version_min; /* Update for incompatible changes */
  44213. +} VCHIQ_SERVICE_PARAMS_T;
  44214. +
  44215. +typedef struct vchiq_config_struct {
  44216. + unsigned int max_msg_size;
  44217. + unsigned int bulk_threshold; /* The message size above which it
  44218. + is better to use a bulk transfer
  44219. + (<= max_msg_size) */
  44220. + unsigned int max_outstanding_bulks;
  44221. + unsigned int max_services;
  44222. + short version; /* The version of VCHIQ */
  44223. + short version_min; /* The minimum compatible version of VCHIQ */
  44224. +} VCHIQ_CONFIG_T;
  44225. +
  44226. +typedef struct vchiq_instance_struct *VCHIQ_INSTANCE_T;
  44227. +typedef void (*VCHIQ_REMOTE_USE_CALLBACK_T)(void *cb_arg);
  44228. +
  44229. +extern VCHIQ_STATUS_T vchiq_initialise(VCHIQ_INSTANCE_T *pinstance);
  44230. +extern VCHIQ_STATUS_T vchiq_shutdown(VCHIQ_INSTANCE_T instance);
  44231. +extern VCHIQ_STATUS_T vchiq_connect(VCHIQ_INSTANCE_T instance);
  44232. +extern VCHIQ_STATUS_T vchiq_add_service(VCHIQ_INSTANCE_T instance,
  44233. + const VCHIQ_SERVICE_PARAMS_T *params,
  44234. + VCHIQ_SERVICE_HANDLE_T *pservice);
  44235. +extern VCHIQ_STATUS_T vchiq_open_service(VCHIQ_INSTANCE_T instance,
  44236. + const VCHIQ_SERVICE_PARAMS_T *params,
  44237. + VCHIQ_SERVICE_HANDLE_T *pservice);
  44238. +extern VCHIQ_STATUS_T vchiq_close_service(VCHIQ_SERVICE_HANDLE_T service);
  44239. +extern VCHIQ_STATUS_T vchiq_remove_service(VCHIQ_SERVICE_HANDLE_T service);
  44240. +extern VCHIQ_STATUS_T vchiq_use_service(VCHIQ_SERVICE_HANDLE_T service);
  44241. +extern VCHIQ_STATUS_T vchiq_use_service_no_resume(
  44242. + VCHIQ_SERVICE_HANDLE_T service);
  44243. +extern VCHIQ_STATUS_T vchiq_release_service(VCHIQ_SERVICE_HANDLE_T service);
  44244. +
  44245. +extern VCHIQ_STATUS_T vchiq_queue_message(VCHIQ_SERVICE_HANDLE_T service,
  44246. + const VCHIQ_ELEMENT_T *elements, unsigned int count);
  44247. +extern void vchiq_release_message(VCHIQ_SERVICE_HANDLE_T service,
  44248. + VCHIQ_HEADER_T *header);
  44249. +extern VCHIQ_STATUS_T vchiq_queue_bulk_transmit(VCHIQ_SERVICE_HANDLE_T service,
  44250. + const void *data, unsigned int size, void *userdata);
  44251. +extern VCHIQ_STATUS_T vchiq_queue_bulk_receive(VCHIQ_SERVICE_HANDLE_T service,
  44252. + void *data, unsigned int size, void *userdata);
  44253. +extern VCHIQ_STATUS_T vchiq_queue_bulk_transmit_handle(
  44254. + VCHIQ_SERVICE_HANDLE_T service, VCHI_MEM_HANDLE_T handle,
  44255. + const void *offset, unsigned int size, void *userdata);
  44256. +extern VCHIQ_STATUS_T vchiq_queue_bulk_receive_handle(
  44257. + VCHIQ_SERVICE_HANDLE_T service, VCHI_MEM_HANDLE_T handle,
  44258. + void *offset, unsigned int size, void *userdata);
  44259. +extern VCHIQ_STATUS_T vchiq_bulk_transmit(VCHIQ_SERVICE_HANDLE_T service,
  44260. + const void *data, unsigned int size, void *userdata,
  44261. + VCHIQ_BULK_MODE_T mode);
  44262. +extern VCHIQ_STATUS_T vchiq_bulk_receive(VCHIQ_SERVICE_HANDLE_T service,
  44263. + void *data, unsigned int size, void *userdata,
  44264. + VCHIQ_BULK_MODE_T mode);
  44265. +extern VCHIQ_STATUS_T vchiq_bulk_transmit_handle(VCHIQ_SERVICE_HANDLE_T service,
  44266. + VCHI_MEM_HANDLE_T handle, const void *offset, unsigned int size,
  44267. + void *userdata, VCHIQ_BULK_MODE_T mode);
  44268. +extern VCHIQ_STATUS_T vchiq_bulk_receive_handle(VCHIQ_SERVICE_HANDLE_T service,
  44269. + VCHI_MEM_HANDLE_T handle, void *offset, unsigned int size,
  44270. + void *userdata, VCHIQ_BULK_MODE_T mode);
  44271. +extern int vchiq_get_client_id(VCHIQ_SERVICE_HANDLE_T service);
  44272. +extern void *vchiq_get_service_userdata(VCHIQ_SERVICE_HANDLE_T service);
  44273. +extern int vchiq_get_service_fourcc(VCHIQ_SERVICE_HANDLE_T service);
  44274. +extern VCHIQ_STATUS_T vchiq_get_config(VCHIQ_INSTANCE_T instance,
  44275. + int config_size, VCHIQ_CONFIG_T *pconfig);
  44276. +extern VCHIQ_STATUS_T vchiq_set_service_option(VCHIQ_SERVICE_HANDLE_T service,
  44277. + VCHIQ_SERVICE_OPTION_T option, int value);
  44278. +
  44279. +extern VCHIQ_STATUS_T vchiq_remote_use(VCHIQ_INSTANCE_T instance,
  44280. + VCHIQ_REMOTE_USE_CALLBACK_T callback, void *cb_arg);
  44281. +extern VCHIQ_STATUS_T vchiq_remote_release(VCHIQ_INSTANCE_T instance);
  44282. +
  44283. +extern VCHIQ_STATUS_T vchiq_dump_phys_mem(VCHIQ_SERVICE_HANDLE_T service,
  44284. + void *ptr, size_t num_bytes);
  44285. +
  44286. +extern VCHIQ_STATUS_T vchiq_get_peer_version(VCHIQ_SERVICE_HANDLE_T handle,
  44287. + short *peer_version);
  44288. +
  44289. +#endif /* VCHIQ_IF_H */
  44290. diff -Nur linux-3.18.8/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_ioctl.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_ioctl.h
  44291. --- linux-3.18.8/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_ioctl.h 1970-01-01 01:00:00.000000000 +0100
  44292. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_ioctl.h 2015-03-05 14:40:14.405715819 +0100
  44293. @@ -0,0 +1,131 @@
  44294. +/**
  44295. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  44296. + *
  44297. + * Redistribution and use in source and binary forms, with or without
  44298. + * modification, are permitted provided that the following conditions
  44299. + * are met:
  44300. + * 1. Redistributions of source code must retain the above copyright
  44301. + * notice, this list of conditions, and the following disclaimer,
  44302. + * without modification.
  44303. + * 2. Redistributions in binary form must reproduce the above copyright
  44304. + * notice, this list of conditions and the following disclaimer in the
  44305. + * documentation and/or other materials provided with the distribution.
  44306. + * 3. The names of the above-listed copyright holders may not be used
  44307. + * to endorse or promote products derived from this software without
  44308. + * specific prior written permission.
  44309. + *
  44310. + * ALTERNATIVELY, this software may be distributed under the terms of the
  44311. + * GNU General Public License ("GPL") version 2, as published by the Free
  44312. + * Software Foundation.
  44313. + *
  44314. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  44315. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  44316. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  44317. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  44318. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  44319. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  44320. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  44321. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  44322. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  44323. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  44324. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  44325. + */
  44326. +
  44327. +#ifndef VCHIQ_IOCTLS_H
  44328. +#define VCHIQ_IOCTLS_H
  44329. +
  44330. +#include <linux/ioctl.h>
  44331. +#include "vchiq_if.h"
  44332. +
  44333. +#define VCHIQ_IOC_MAGIC 0xc4
  44334. +#define VCHIQ_INVALID_HANDLE (~0)
  44335. +
  44336. +typedef struct {
  44337. + VCHIQ_SERVICE_PARAMS_T params;
  44338. + int is_open;
  44339. + int is_vchi;
  44340. + unsigned int handle; /* OUT */
  44341. +} VCHIQ_CREATE_SERVICE_T;
  44342. +
  44343. +typedef struct {
  44344. + unsigned int handle;
  44345. + unsigned int count;
  44346. + const VCHIQ_ELEMENT_T *elements;
  44347. +} VCHIQ_QUEUE_MESSAGE_T;
  44348. +
  44349. +typedef struct {
  44350. + unsigned int handle;
  44351. + void *data;
  44352. + unsigned int size;
  44353. + void *userdata;
  44354. + VCHIQ_BULK_MODE_T mode;
  44355. +} VCHIQ_QUEUE_BULK_TRANSFER_T;
  44356. +
  44357. +typedef struct {
  44358. + VCHIQ_REASON_T reason;
  44359. + VCHIQ_HEADER_T *header;
  44360. + void *service_userdata;
  44361. + void *bulk_userdata;
  44362. +} VCHIQ_COMPLETION_DATA_T;
  44363. +
  44364. +typedef struct {
  44365. + unsigned int count;
  44366. + VCHIQ_COMPLETION_DATA_T *buf;
  44367. + unsigned int msgbufsize;
  44368. + unsigned int msgbufcount; /* IN/OUT */
  44369. + void **msgbufs;
  44370. +} VCHIQ_AWAIT_COMPLETION_T;
  44371. +
  44372. +typedef struct {
  44373. + unsigned int handle;
  44374. + int blocking;
  44375. + unsigned int bufsize;
  44376. + void *buf;
  44377. +} VCHIQ_DEQUEUE_MESSAGE_T;
  44378. +
  44379. +typedef struct {
  44380. + unsigned int config_size;
  44381. + VCHIQ_CONFIG_T *pconfig;
  44382. +} VCHIQ_GET_CONFIG_T;
  44383. +
  44384. +typedef struct {
  44385. + unsigned int handle;
  44386. + VCHIQ_SERVICE_OPTION_T option;
  44387. + int value;
  44388. +} VCHIQ_SET_SERVICE_OPTION_T;
  44389. +
  44390. +typedef struct {
  44391. + void *virt_addr;
  44392. + size_t num_bytes;
  44393. +} VCHIQ_DUMP_MEM_T;
  44394. +
  44395. +#define VCHIQ_IOC_CONNECT _IO(VCHIQ_IOC_MAGIC, 0)
  44396. +#define VCHIQ_IOC_SHUTDOWN _IO(VCHIQ_IOC_MAGIC, 1)
  44397. +#define VCHIQ_IOC_CREATE_SERVICE \
  44398. + _IOWR(VCHIQ_IOC_MAGIC, 2, VCHIQ_CREATE_SERVICE_T)
  44399. +#define VCHIQ_IOC_REMOVE_SERVICE _IO(VCHIQ_IOC_MAGIC, 3)
  44400. +#define VCHIQ_IOC_QUEUE_MESSAGE \
  44401. + _IOW(VCHIQ_IOC_MAGIC, 4, VCHIQ_QUEUE_MESSAGE_T)
  44402. +#define VCHIQ_IOC_QUEUE_BULK_TRANSMIT \
  44403. + _IOWR(VCHIQ_IOC_MAGIC, 5, VCHIQ_QUEUE_BULK_TRANSFER_T)
  44404. +#define VCHIQ_IOC_QUEUE_BULK_RECEIVE \
  44405. + _IOWR(VCHIQ_IOC_MAGIC, 6, VCHIQ_QUEUE_BULK_TRANSFER_T)
  44406. +#define VCHIQ_IOC_AWAIT_COMPLETION \
  44407. + _IOWR(VCHIQ_IOC_MAGIC, 7, VCHIQ_AWAIT_COMPLETION_T)
  44408. +#define VCHIQ_IOC_DEQUEUE_MESSAGE \
  44409. + _IOWR(VCHIQ_IOC_MAGIC, 8, VCHIQ_DEQUEUE_MESSAGE_T)
  44410. +#define VCHIQ_IOC_GET_CLIENT_ID _IO(VCHIQ_IOC_MAGIC, 9)
  44411. +#define VCHIQ_IOC_GET_CONFIG \
  44412. + _IOWR(VCHIQ_IOC_MAGIC, 10, VCHIQ_GET_CONFIG_T)
  44413. +#define VCHIQ_IOC_CLOSE_SERVICE _IO(VCHIQ_IOC_MAGIC, 11)
  44414. +#define VCHIQ_IOC_USE_SERVICE _IO(VCHIQ_IOC_MAGIC, 12)
  44415. +#define VCHIQ_IOC_RELEASE_SERVICE _IO(VCHIQ_IOC_MAGIC, 13)
  44416. +#define VCHIQ_IOC_SET_SERVICE_OPTION \
  44417. + _IOW(VCHIQ_IOC_MAGIC, 14, VCHIQ_SET_SERVICE_OPTION_T)
  44418. +#define VCHIQ_IOC_DUMP_PHYS_MEM \
  44419. + _IOW(VCHIQ_IOC_MAGIC, 15, VCHIQ_DUMP_MEM_T)
  44420. +#define VCHIQ_IOC_LIB_VERSION _IO(VCHIQ_IOC_MAGIC, 16)
  44421. +#define VCHIQ_IOC_CLOSE_DELIVERED _IO(VCHIQ_IOC_MAGIC, 17)
  44422. +#define VCHIQ_IOC_MAX 17
  44423. +
  44424. +#endif
  44425. diff -Nur linux-3.18.8/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_kern_lib.c linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_kern_lib.c
  44426. --- linux-3.18.8/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_kern_lib.c 1970-01-01 01:00:00.000000000 +0100
  44427. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_kern_lib.c 2015-03-05 14:40:14.405715819 +0100
  44428. @@ -0,0 +1,458 @@
  44429. +/**
  44430. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  44431. + *
  44432. + * Redistribution and use in source and binary forms, with or without
  44433. + * modification, are permitted provided that the following conditions
  44434. + * are met:
  44435. + * 1. Redistributions of source code must retain the above copyright
  44436. + * notice, this list of conditions, and the following disclaimer,
  44437. + * without modification.
  44438. + * 2. Redistributions in binary form must reproduce the above copyright
  44439. + * notice, this list of conditions and the following disclaimer in the
  44440. + * documentation and/or other materials provided with the distribution.
  44441. + * 3. The names of the above-listed copyright holders may not be used
  44442. + * to endorse or promote products derived from this software without
  44443. + * specific prior written permission.
  44444. + *
  44445. + * ALTERNATIVELY, this software may be distributed under the terms of the
  44446. + * GNU General Public License ("GPL") version 2, as published by the Free
  44447. + * Software Foundation.
  44448. + *
  44449. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  44450. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  44451. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  44452. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  44453. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  44454. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  44455. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  44456. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  44457. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  44458. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  44459. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  44460. + */
  44461. +
  44462. +/* ---- Include Files ---------------------------------------------------- */
  44463. +
  44464. +#include <linux/kernel.h>
  44465. +#include <linux/module.h>
  44466. +#include <linux/mutex.h>
  44467. +
  44468. +#include "vchiq_core.h"
  44469. +#include "vchiq_arm.h"
  44470. +#include "vchiq_killable.h"
  44471. +
  44472. +/* ---- Public Variables ------------------------------------------------- */
  44473. +
  44474. +/* ---- Private Constants and Types -------------------------------------- */
  44475. +
  44476. +struct bulk_waiter_node {
  44477. + struct bulk_waiter bulk_waiter;
  44478. + int pid;
  44479. + struct list_head list;
  44480. +};
  44481. +
  44482. +struct vchiq_instance_struct {
  44483. + VCHIQ_STATE_T *state;
  44484. +
  44485. + int connected;
  44486. +
  44487. + struct list_head bulk_waiter_list;
  44488. + struct mutex bulk_waiter_list_mutex;
  44489. +};
  44490. +
  44491. +static VCHIQ_STATUS_T
  44492. +vchiq_blocking_bulk_transfer(VCHIQ_SERVICE_HANDLE_T handle, void *data,
  44493. + unsigned int size, VCHIQ_BULK_DIR_T dir);
  44494. +
  44495. +/****************************************************************************
  44496. +*
  44497. +* vchiq_initialise
  44498. +*
  44499. +***************************************************************************/
  44500. +#define VCHIQ_INIT_RETRIES 10
  44501. +VCHIQ_STATUS_T vchiq_initialise(VCHIQ_INSTANCE_T *instanceOut)
  44502. +{
  44503. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  44504. + VCHIQ_STATE_T *state;
  44505. + VCHIQ_INSTANCE_T instance = NULL;
  44506. + int i;
  44507. +
  44508. + vchiq_log_trace(vchiq_core_log_level, "%s called", __func__);
  44509. +
  44510. + /* VideoCore may not be ready due to boot up timing.
  44511. + It may never be ready if kernel and firmware are mismatched, so don't block forever. */
  44512. + for (i=0; i<VCHIQ_INIT_RETRIES; i++) {
  44513. + state = vchiq_get_state();
  44514. + if (state)
  44515. + break;
  44516. + udelay(500);
  44517. + }
  44518. + if (i==VCHIQ_INIT_RETRIES) {
  44519. + vchiq_log_error(vchiq_core_log_level,
  44520. + "%s: videocore not initialized\n", __func__);
  44521. + goto failed;
  44522. + } else if (i>0) {
  44523. + vchiq_log_warning(vchiq_core_log_level,
  44524. + "%s: videocore initialized after %d retries\n", __func__, i);
  44525. + }
  44526. +
  44527. + instance = kzalloc(sizeof(*instance), GFP_KERNEL);
  44528. + if (!instance) {
  44529. + vchiq_log_error(vchiq_core_log_level,
  44530. + "%s: error allocating vchiq instance\n", __func__);
  44531. + goto failed;
  44532. + }
  44533. +
  44534. + instance->connected = 0;
  44535. + instance->state = state;
  44536. + mutex_init(&instance->bulk_waiter_list_mutex);
  44537. + INIT_LIST_HEAD(&instance->bulk_waiter_list);
  44538. +
  44539. + *instanceOut = instance;
  44540. +
  44541. + status = VCHIQ_SUCCESS;
  44542. +
  44543. +failed:
  44544. + vchiq_log_trace(vchiq_core_log_level,
  44545. + "%s(%p): returning %d", __func__, instance, status);
  44546. +
  44547. + return status;
  44548. +}
  44549. +EXPORT_SYMBOL(vchiq_initialise);
  44550. +
  44551. +/****************************************************************************
  44552. +*
  44553. +* vchiq_shutdown
  44554. +*
  44555. +***************************************************************************/
  44556. +
  44557. +VCHIQ_STATUS_T vchiq_shutdown(VCHIQ_INSTANCE_T instance)
  44558. +{
  44559. + VCHIQ_STATUS_T status;
  44560. + VCHIQ_STATE_T *state = instance->state;
  44561. +
  44562. + vchiq_log_trace(vchiq_core_log_level,
  44563. + "%s(%p) called", __func__, instance);
  44564. +
  44565. + if (mutex_lock_interruptible(&state->mutex) != 0)
  44566. + return VCHIQ_RETRY;
  44567. +
  44568. + /* Remove all services */
  44569. + status = vchiq_shutdown_internal(state, instance);
  44570. +
  44571. + mutex_unlock(&state->mutex);
  44572. +
  44573. + vchiq_log_trace(vchiq_core_log_level,
  44574. + "%s(%p): returning %d", __func__, instance, status);
  44575. +
  44576. + if (status == VCHIQ_SUCCESS) {
  44577. + struct list_head *pos, *next;
  44578. + list_for_each_safe(pos, next,
  44579. + &instance->bulk_waiter_list) {
  44580. + struct bulk_waiter_node *waiter;
  44581. + waiter = list_entry(pos,
  44582. + struct bulk_waiter_node,
  44583. + list);
  44584. + list_del(pos);
  44585. + vchiq_log_info(vchiq_arm_log_level,
  44586. + "bulk_waiter - cleaned up %x "
  44587. + "for pid %d",
  44588. + (unsigned int)waiter, waiter->pid);
  44589. + kfree(waiter);
  44590. + }
  44591. + kfree(instance);
  44592. + }
  44593. +
  44594. + return status;
  44595. +}
  44596. +EXPORT_SYMBOL(vchiq_shutdown);
  44597. +
  44598. +/****************************************************************************
  44599. +*
  44600. +* vchiq_is_connected
  44601. +*
  44602. +***************************************************************************/
  44603. +
  44604. +int vchiq_is_connected(VCHIQ_INSTANCE_T instance)
  44605. +{
  44606. + return instance->connected;
  44607. +}
  44608. +
  44609. +/****************************************************************************
  44610. +*
  44611. +* vchiq_connect
  44612. +*
  44613. +***************************************************************************/
  44614. +
  44615. +VCHIQ_STATUS_T vchiq_connect(VCHIQ_INSTANCE_T instance)
  44616. +{
  44617. + VCHIQ_STATUS_T status;
  44618. + VCHIQ_STATE_T *state = instance->state;
  44619. +
  44620. + vchiq_log_trace(vchiq_core_log_level,
  44621. + "%s(%p) called", __func__, instance);
  44622. +
  44623. + if (mutex_lock_interruptible(&state->mutex) != 0) {
  44624. + vchiq_log_trace(vchiq_core_log_level,
  44625. + "%s: call to mutex_lock failed", __func__);
  44626. + status = VCHIQ_RETRY;
  44627. + goto failed;
  44628. + }
  44629. + status = vchiq_connect_internal(state, instance);
  44630. +
  44631. + if (status == VCHIQ_SUCCESS)
  44632. + instance->connected = 1;
  44633. +
  44634. + mutex_unlock(&state->mutex);
  44635. +
  44636. +failed:
  44637. + vchiq_log_trace(vchiq_core_log_level,
  44638. + "%s(%p): returning %d", __func__, instance, status);
  44639. +
  44640. + return status;
  44641. +}
  44642. +EXPORT_SYMBOL(vchiq_connect);
  44643. +
  44644. +/****************************************************************************
  44645. +*
  44646. +* vchiq_add_service
  44647. +*
  44648. +***************************************************************************/
  44649. +
  44650. +VCHIQ_STATUS_T vchiq_add_service(
  44651. + VCHIQ_INSTANCE_T instance,
  44652. + const VCHIQ_SERVICE_PARAMS_T *params,
  44653. + VCHIQ_SERVICE_HANDLE_T *phandle)
  44654. +{
  44655. + VCHIQ_STATUS_T status;
  44656. + VCHIQ_STATE_T *state = instance->state;
  44657. + VCHIQ_SERVICE_T *service = NULL;
  44658. + int srvstate;
  44659. +
  44660. + vchiq_log_trace(vchiq_core_log_level,
  44661. + "%s(%p) called", __func__, instance);
  44662. +
  44663. + *phandle = VCHIQ_SERVICE_HANDLE_INVALID;
  44664. +
  44665. + srvstate = vchiq_is_connected(instance)
  44666. + ? VCHIQ_SRVSTATE_LISTENING
  44667. + : VCHIQ_SRVSTATE_HIDDEN;
  44668. +
  44669. + service = vchiq_add_service_internal(
  44670. + state,
  44671. + params,
  44672. + srvstate,
  44673. + instance,
  44674. + NULL);
  44675. +
  44676. + if (service) {
  44677. + *phandle = service->handle;
  44678. + status = VCHIQ_SUCCESS;
  44679. + } else
  44680. + status = VCHIQ_ERROR;
  44681. +
  44682. + vchiq_log_trace(vchiq_core_log_level,
  44683. + "%s(%p): returning %d", __func__, instance, status);
  44684. +
  44685. + return status;
  44686. +}
  44687. +EXPORT_SYMBOL(vchiq_add_service);
  44688. +
  44689. +/****************************************************************************
  44690. +*
  44691. +* vchiq_open_service
  44692. +*
  44693. +***************************************************************************/
  44694. +
  44695. +VCHIQ_STATUS_T vchiq_open_service(
  44696. + VCHIQ_INSTANCE_T instance,
  44697. + const VCHIQ_SERVICE_PARAMS_T *params,
  44698. + VCHIQ_SERVICE_HANDLE_T *phandle)
  44699. +{
  44700. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  44701. + VCHIQ_STATE_T *state = instance->state;
  44702. + VCHIQ_SERVICE_T *service = NULL;
  44703. +
  44704. + vchiq_log_trace(vchiq_core_log_level,
  44705. + "%s(%p) called", __func__, instance);
  44706. +
  44707. + *phandle = VCHIQ_SERVICE_HANDLE_INVALID;
  44708. +
  44709. + if (!vchiq_is_connected(instance))
  44710. + goto failed;
  44711. +
  44712. + service = vchiq_add_service_internal(state,
  44713. + params,
  44714. + VCHIQ_SRVSTATE_OPENING,
  44715. + instance,
  44716. + NULL);
  44717. +
  44718. + if (service) {
  44719. + *phandle = service->handle;
  44720. + status = vchiq_open_service_internal(service, current->pid);
  44721. + if (status != VCHIQ_SUCCESS) {
  44722. + vchiq_remove_service(service->handle);
  44723. + *phandle = VCHIQ_SERVICE_HANDLE_INVALID;
  44724. + }
  44725. + }
  44726. +
  44727. +failed:
  44728. + vchiq_log_trace(vchiq_core_log_level,
  44729. + "%s(%p): returning %d", __func__, instance, status);
  44730. +
  44731. + return status;
  44732. +}
  44733. +EXPORT_SYMBOL(vchiq_open_service);
  44734. +
  44735. +VCHIQ_STATUS_T
  44736. +vchiq_queue_bulk_transmit(VCHIQ_SERVICE_HANDLE_T handle,
  44737. + const void *data, unsigned int size, void *userdata)
  44738. +{
  44739. + return vchiq_bulk_transfer(handle,
  44740. + VCHI_MEM_HANDLE_INVALID, (void *)data, size, userdata,
  44741. + VCHIQ_BULK_MODE_CALLBACK, VCHIQ_BULK_TRANSMIT);
  44742. +}
  44743. +EXPORT_SYMBOL(vchiq_queue_bulk_transmit);
  44744. +
  44745. +VCHIQ_STATUS_T
  44746. +vchiq_queue_bulk_receive(VCHIQ_SERVICE_HANDLE_T handle, void *data,
  44747. + unsigned int size, void *userdata)
  44748. +{
  44749. + return vchiq_bulk_transfer(handle,
  44750. + VCHI_MEM_HANDLE_INVALID, data, size, userdata,
  44751. + VCHIQ_BULK_MODE_CALLBACK, VCHIQ_BULK_RECEIVE);
  44752. +}
  44753. +EXPORT_SYMBOL(vchiq_queue_bulk_receive);
  44754. +
  44755. +VCHIQ_STATUS_T
  44756. +vchiq_bulk_transmit(VCHIQ_SERVICE_HANDLE_T handle, const void *data,
  44757. + unsigned int size, void *userdata, VCHIQ_BULK_MODE_T mode)
  44758. +{
  44759. + VCHIQ_STATUS_T status;
  44760. +
  44761. + switch (mode) {
  44762. + case VCHIQ_BULK_MODE_NOCALLBACK:
  44763. + case VCHIQ_BULK_MODE_CALLBACK:
  44764. + status = vchiq_bulk_transfer(handle,
  44765. + VCHI_MEM_HANDLE_INVALID, (void *)data, size, userdata,
  44766. + mode, VCHIQ_BULK_TRANSMIT);
  44767. + break;
  44768. + case VCHIQ_BULK_MODE_BLOCKING:
  44769. + status = vchiq_blocking_bulk_transfer(handle,
  44770. + (void *)data, size, VCHIQ_BULK_TRANSMIT);
  44771. + break;
  44772. + default:
  44773. + return VCHIQ_ERROR;
  44774. + }
  44775. +
  44776. + return status;
  44777. +}
  44778. +EXPORT_SYMBOL(vchiq_bulk_transmit);
  44779. +
  44780. +VCHIQ_STATUS_T
  44781. +vchiq_bulk_receive(VCHIQ_SERVICE_HANDLE_T handle, void *data,
  44782. + unsigned int size, void *userdata, VCHIQ_BULK_MODE_T mode)
  44783. +{
  44784. + VCHIQ_STATUS_T status;
  44785. +
  44786. + switch (mode) {
  44787. + case VCHIQ_BULK_MODE_NOCALLBACK:
  44788. + case VCHIQ_BULK_MODE_CALLBACK:
  44789. + status = vchiq_bulk_transfer(handle,
  44790. + VCHI_MEM_HANDLE_INVALID, data, size, userdata,
  44791. + mode, VCHIQ_BULK_RECEIVE);
  44792. + break;
  44793. + case VCHIQ_BULK_MODE_BLOCKING:
  44794. + status = vchiq_blocking_bulk_transfer(handle,
  44795. + (void *)data, size, VCHIQ_BULK_RECEIVE);
  44796. + break;
  44797. + default:
  44798. + return VCHIQ_ERROR;
  44799. + }
  44800. +
  44801. + return status;
  44802. +}
  44803. +EXPORT_SYMBOL(vchiq_bulk_receive);
  44804. +
  44805. +static VCHIQ_STATUS_T
  44806. +vchiq_blocking_bulk_transfer(VCHIQ_SERVICE_HANDLE_T handle, void *data,
  44807. + unsigned int size, VCHIQ_BULK_DIR_T dir)
  44808. +{
  44809. + VCHIQ_INSTANCE_T instance;
  44810. + VCHIQ_SERVICE_T *service;
  44811. + VCHIQ_STATUS_T status;
  44812. + struct bulk_waiter_node *waiter = NULL;
  44813. + struct list_head *pos;
  44814. +
  44815. + service = find_service_by_handle(handle);
  44816. + if (!service)
  44817. + return VCHIQ_ERROR;
  44818. +
  44819. + instance = service->instance;
  44820. +
  44821. + unlock_service(service);
  44822. +
  44823. + mutex_lock(&instance->bulk_waiter_list_mutex);
  44824. + list_for_each(pos, &instance->bulk_waiter_list) {
  44825. + if (list_entry(pos, struct bulk_waiter_node,
  44826. + list)->pid == current->pid) {
  44827. + waiter = list_entry(pos,
  44828. + struct bulk_waiter_node,
  44829. + list);
  44830. + list_del(pos);
  44831. + break;
  44832. + }
  44833. + }
  44834. + mutex_unlock(&instance->bulk_waiter_list_mutex);
  44835. +
  44836. + if (waiter) {
  44837. + VCHIQ_BULK_T *bulk = waiter->bulk_waiter.bulk;
  44838. + if (bulk) {
  44839. + /* This thread has an outstanding bulk transfer. */
  44840. + if ((bulk->data != data) ||
  44841. + (bulk->size != size)) {
  44842. + /* This is not a retry of the previous one.
  44843. + ** Cancel the signal when the transfer
  44844. + ** completes. */
  44845. + spin_lock(&bulk_waiter_spinlock);
  44846. + bulk->userdata = NULL;
  44847. + spin_unlock(&bulk_waiter_spinlock);
  44848. + }
  44849. + }
  44850. + }
  44851. +
  44852. + if (!waiter) {
  44853. + waiter = kzalloc(sizeof(struct bulk_waiter_node), GFP_KERNEL);
  44854. + if (!waiter) {
  44855. + vchiq_log_error(vchiq_core_log_level,
  44856. + "%s - out of memory", __func__);
  44857. + return VCHIQ_ERROR;
  44858. + }
  44859. + }
  44860. +
  44861. + status = vchiq_bulk_transfer(handle, VCHI_MEM_HANDLE_INVALID,
  44862. + data, size, &waiter->bulk_waiter, VCHIQ_BULK_MODE_BLOCKING,
  44863. + dir);
  44864. + if ((status != VCHIQ_RETRY) || fatal_signal_pending(current) ||
  44865. + !waiter->bulk_waiter.bulk) {
  44866. + VCHIQ_BULK_T *bulk = waiter->bulk_waiter.bulk;
  44867. + if (bulk) {
  44868. + /* Cancel the signal when the transfer
  44869. + ** completes. */
  44870. + spin_lock(&bulk_waiter_spinlock);
  44871. + bulk->userdata = NULL;
  44872. + spin_unlock(&bulk_waiter_spinlock);
  44873. + }
  44874. + kfree(waiter);
  44875. + } else {
  44876. + waiter->pid = current->pid;
  44877. + mutex_lock(&instance->bulk_waiter_list_mutex);
  44878. + list_add(&waiter->list, &instance->bulk_waiter_list);
  44879. + mutex_unlock(&instance->bulk_waiter_list_mutex);
  44880. + vchiq_log_info(vchiq_arm_log_level,
  44881. + "saved bulk_waiter %x for pid %d",
  44882. + (unsigned int)waiter, current->pid);
  44883. + }
  44884. +
  44885. + return status;
  44886. +}
  44887. diff -Nur linux-3.18.8/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_killable.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_killable.h
  44888. --- linux-3.18.8/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_killable.h 1970-01-01 01:00:00.000000000 +0100
  44889. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_killable.h 2015-03-05 14:40:14.405715819 +0100
  44890. @@ -0,0 +1,69 @@
  44891. +/**
  44892. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  44893. + *
  44894. + * Redistribution and use in source and binary forms, with or without
  44895. + * modification, are permitted provided that the following conditions
  44896. + * are met:
  44897. + * 1. Redistributions of source code must retain the above copyright
  44898. + * notice, this list of conditions, and the following disclaimer,
  44899. + * without modification.
  44900. + * 2. Redistributions in binary form must reproduce the above copyright
  44901. + * notice, this list of conditions and the following disclaimer in the
  44902. + * documentation and/or other materials provided with the distribution.
  44903. + * 3. The names of the above-listed copyright holders may not be used
  44904. + * to endorse or promote products derived from this software without
  44905. + * specific prior written permission.
  44906. + *
  44907. + * ALTERNATIVELY, this software may be distributed under the terms of the
  44908. + * GNU General Public License ("GPL") version 2, as published by the Free
  44909. + * Software Foundation.
  44910. + *
  44911. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  44912. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  44913. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  44914. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  44915. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  44916. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  44917. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  44918. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  44919. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  44920. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  44921. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  44922. + */
  44923. +
  44924. +#ifndef VCHIQ_KILLABLE_H
  44925. +#define VCHIQ_KILLABLE_H
  44926. +
  44927. +#include <linux/mutex.h>
  44928. +#include <linux/semaphore.h>
  44929. +
  44930. +#define SHUTDOWN_SIGS (sigmask(SIGKILL) | sigmask(SIGINT) | sigmask(SIGQUIT) | sigmask(SIGTRAP) | sigmask(SIGSTOP) | sigmask(SIGCONT))
  44931. +
  44932. +static inline int __must_check down_interruptible_killable(struct semaphore *sem)
  44933. +{
  44934. + /* Allow interception of killable signals only. We don't want to be interrupted by harmless signals like SIGALRM */
  44935. + int ret;
  44936. + sigset_t blocked, oldset;
  44937. + siginitsetinv(&blocked, SHUTDOWN_SIGS);
  44938. + sigprocmask(SIG_SETMASK, &blocked, &oldset);
  44939. + ret = down_interruptible(sem);
  44940. + sigprocmask(SIG_SETMASK, &oldset, NULL);
  44941. + return ret;
  44942. +}
  44943. +#define down_interruptible down_interruptible_killable
  44944. +
  44945. +
  44946. +static inline int __must_check mutex_lock_interruptible_killable(struct mutex *lock)
  44947. +{
  44948. + /* Allow interception of killable signals only. We don't want to be interrupted by harmless signals like SIGALRM */
  44949. + int ret;
  44950. + sigset_t blocked, oldset;
  44951. + siginitsetinv(&blocked, SHUTDOWN_SIGS);
  44952. + sigprocmask(SIG_SETMASK, &blocked, &oldset);
  44953. + ret = mutex_lock_interruptible(lock);
  44954. + sigprocmask(SIG_SETMASK, &oldset, NULL);
  44955. + return ret;
  44956. +}
  44957. +#define mutex_lock_interruptible mutex_lock_interruptible_killable
  44958. +
  44959. +#endif
  44960. diff -Nur linux-3.18.8/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_memdrv.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_memdrv.h
  44961. --- linux-3.18.8/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_memdrv.h 1970-01-01 01:00:00.000000000 +0100
  44962. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_memdrv.h 2015-03-05 14:40:14.405715819 +0100
  44963. @@ -0,0 +1,71 @@
  44964. +/**
  44965. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  44966. + *
  44967. + * Redistribution and use in source and binary forms, with or without
  44968. + * modification, are permitted provided that the following conditions
  44969. + * are met:
  44970. + * 1. Redistributions of source code must retain the above copyright
  44971. + * notice, this list of conditions, and the following disclaimer,
  44972. + * without modification.
  44973. + * 2. Redistributions in binary form must reproduce the above copyright
  44974. + * notice, this list of conditions and the following disclaimer in the
  44975. + * documentation and/or other materials provided with the distribution.
  44976. + * 3. The names of the above-listed copyright holders may not be used
  44977. + * to endorse or promote products derived from this software without
  44978. + * specific prior written permission.
  44979. + *
  44980. + * ALTERNATIVELY, this software may be distributed under the terms of the
  44981. + * GNU General Public License ("GPL") version 2, as published by the Free
  44982. + * Software Foundation.
  44983. + *
  44984. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  44985. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  44986. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  44987. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  44988. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  44989. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  44990. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  44991. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  44992. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  44993. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  44994. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  44995. + */
  44996. +
  44997. +#ifndef VCHIQ_MEMDRV_H
  44998. +#define VCHIQ_MEMDRV_H
  44999. +
  45000. +/* ---- Include Files ----------------------------------------------------- */
  45001. +
  45002. +#include <linux/kernel.h>
  45003. +#include "vchiq_if.h"
  45004. +
  45005. +/* ---- Constants and Types ---------------------------------------------- */
  45006. +
  45007. +typedef struct {
  45008. + void *armSharedMemVirt;
  45009. + dma_addr_t armSharedMemPhys;
  45010. + size_t armSharedMemSize;
  45011. +
  45012. + void *vcSharedMemVirt;
  45013. + dma_addr_t vcSharedMemPhys;
  45014. + size_t vcSharedMemSize;
  45015. +} VCHIQ_SHARED_MEM_INFO_T;
  45016. +
  45017. +/* ---- Variable Externs ------------------------------------------------- */
  45018. +
  45019. +/* ---- Function Prototypes ---------------------------------------------- */
  45020. +
  45021. +void vchiq_get_shared_mem_info(VCHIQ_SHARED_MEM_INFO_T *info);
  45022. +
  45023. +VCHIQ_STATUS_T vchiq_memdrv_initialise(void);
  45024. +
  45025. +VCHIQ_STATUS_T vchiq_userdrv_create_instance(
  45026. + const VCHIQ_PLATFORM_DATA_T * platform_data);
  45027. +
  45028. +VCHIQ_STATUS_T vchiq_userdrv_suspend(
  45029. + const VCHIQ_PLATFORM_DATA_T * platform_data);
  45030. +
  45031. +VCHIQ_STATUS_T vchiq_userdrv_resume(
  45032. + const VCHIQ_PLATFORM_DATA_T * platform_data);
  45033. +
  45034. +#endif
  45035. diff -Nur linux-3.18.8/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_pagelist.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_pagelist.h
  45036. --- linux-3.18.8/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_pagelist.h 1970-01-01 01:00:00.000000000 +0100
  45037. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_pagelist.h 2015-03-05 14:40:14.405715819 +0100
  45038. @@ -0,0 +1,58 @@
  45039. +/**
  45040. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  45041. + *
  45042. + * Redistribution and use in source and binary forms, with or without
  45043. + * modification, are permitted provided that the following conditions
  45044. + * are met:
  45045. + * 1. Redistributions of source code must retain the above copyright
  45046. + * notice, this list of conditions, and the following disclaimer,
  45047. + * without modification.
  45048. + * 2. Redistributions in binary form must reproduce the above copyright
  45049. + * notice, this list of conditions and the following disclaimer in the
  45050. + * documentation and/or other materials provided with the distribution.
  45051. + * 3. The names of the above-listed copyright holders may not be used
  45052. + * to endorse or promote products derived from this software without
  45053. + * specific prior written permission.
  45054. + *
  45055. + * ALTERNATIVELY, this software may be distributed under the terms of the
  45056. + * GNU General Public License ("GPL") version 2, as published by the Free
  45057. + * Software Foundation.
  45058. + *
  45059. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  45060. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  45061. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  45062. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  45063. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  45064. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  45065. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  45066. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  45067. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  45068. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  45069. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  45070. + */
  45071. +
  45072. +#ifndef VCHIQ_PAGELIST_H
  45073. +#define VCHIQ_PAGELIST_H
  45074. +
  45075. +#ifndef PAGE_SIZE
  45076. +#define PAGE_SIZE 4096
  45077. +#endif
  45078. +#define CACHE_LINE_SIZE 32
  45079. +#define PAGELIST_WRITE 0
  45080. +#define PAGELIST_READ 1
  45081. +#define PAGELIST_READ_WITH_FRAGMENTS 2
  45082. +
  45083. +typedef struct pagelist_struct {
  45084. + unsigned long length;
  45085. + unsigned short type;
  45086. + unsigned short offset;
  45087. + unsigned long addrs[1]; /* N.B. 12 LSBs hold the number of following
  45088. + pages at consecutive addresses. */
  45089. +} PAGELIST_T;
  45090. +
  45091. +typedef struct fragments_struct {
  45092. + char headbuf[CACHE_LINE_SIZE];
  45093. + char tailbuf[CACHE_LINE_SIZE];
  45094. +} FRAGMENTS_T;
  45095. +
  45096. +#endif /* VCHIQ_PAGELIST_H */
  45097. diff -Nur linux-3.18.8/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_shim.c linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_shim.c
  45098. --- linux-3.18.8/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_shim.c 1970-01-01 01:00:00.000000000 +0100
  45099. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_shim.c 2015-03-05 14:40:14.405715819 +0100
  45100. @@ -0,0 +1,860 @@
  45101. +/**
  45102. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  45103. + *
  45104. + * Redistribution and use in source and binary forms, with or without
  45105. + * modification, are permitted provided that the following conditions
  45106. + * are met:
  45107. + * 1. Redistributions of source code must retain the above copyright
  45108. + * notice, this list of conditions, and the following disclaimer,
  45109. + * without modification.
  45110. + * 2. Redistributions in binary form must reproduce the above copyright
  45111. + * notice, this list of conditions and the following disclaimer in the
  45112. + * documentation and/or other materials provided with the distribution.
  45113. + * 3. The names of the above-listed copyright holders may not be used
  45114. + * to endorse or promote products derived from this software without
  45115. + * specific prior written permission.
  45116. + *
  45117. + * ALTERNATIVELY, this software may be distributed under the terms of the
  45118. + * GNU General Public License ("GPL") version 2, as published by the Free
  45119. + * Software Foundation.
  45120. + *
  45121. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  45122. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  45123. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  45124. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  45125. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  45126. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  45127. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  45128. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  45129. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  45130. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  45131. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  45132. + */
  45133. +#include <linux/module.h>
  45134. +#include <linux/types.h>
  45135. +
  45136. +#include "interface/vchi/vchi.h"
  45137. +#include "vchiq.h"
  45138. +#include "vchiq_core.h"
  45139. +
  45140. +#include "vchiq_util.h"
  45141. +
  45142. +#include <stddef.h>
  45143. +
  45144. +#define vchiq_status_to_vchi(status) ((int32_t)status)
  45145. +
  45146. +typedef struct {
  45147. + VCHIQ_SERVICE_HANDLE_T handle;
  45148. +
  45149. + VCHIU_QUEUE_T queue;
  45150. +
  45151. + VCHI_CALLBACK_T callback;
  45152. + void *callback_param;
  45153. +} SHIM_SERVICE_T;
  45154. +
  45155. +/* ----------------------------------------------------------------------
  45156. + * return pointer to the mphi message driver function table
  45157. + * -------------------------------------------------------------------- */
  45158. +const VCHI_MESSAGE_DRIVER_T *
  45159. +vchi_mphi_message_driver_func_table(void)
  45160. +{
  45161. + return NULL;
  45162. +}
  45163. +
  45164. +/* ----------------------------------------------------------------------
  45165. + * return a pointer to the 'single' connection driver fops
  45166. + * -------------------------------------------------------------------- */
  45167. +const VCHI_CONNECTION_API_T *
  45168. +single_get_func_table(void)
  45169. +{
  45170. + return NULL;
  45171. +}
  45172. +
  45173. +VCHI_CONNECTION_T *vchi_create_connection(
  45174. + const VCHI_CONNECTION_API_T *function_table,
  45175. + const VCHI_MESSAGE_DRIVER_T *low_level)
  45176. +{
  45177. + (void)function_table;
  45178. + (void)low_level;
  45179. + return NULL;
  45180. +}
  45181. +
  45182. +/***********************************************************
  45183. + * Name: vchi_msg_peek
  45184. + *
  45185. + * Arguments: const VCHI_SERVICE_HANDLE_T handle,
  45186. + * void **data,
  45187. + * uint32_t *msg_size,
  45188. +
  45189. +
  45190. + * VCHI_FLAGS_T flags
  45191. + *
  45192. + * Description: Routine to return a pointer to the current message (to allow in
  45193. + * place processing). The message can be removed using
  45194. + * vchi_msg_remove when you're finished
  45195. + *
  45196. + * Returns: int32_t - success == 0
  45197. + *
  45198. + ***********************************************************/
  45199. +int32_t vchi_msg_peek(VCHI_SERVICE_HANDLE_T handle,
  45200. + void **data,
  45201. + uint32_t *msg_size,
  45202. + VCHI_FLAGS_T flags)
  45203. +{
  45204. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  45205. + VCHIQ_HEADER_T *header;
  45206. +
  45207. + WARN_ON((flags != VCHI_FLAGS_NONE) &&
  45208. + (flags != VCHI_FLAGS_BLOCK_UNTIL_OP_COMPLETE));
  45209. +
  45210. + if (flags == VCHI_FLAGS_NONE)
  45211. + if (vchiu_queue_is_empty(&service->queue))
  45212. + return -1;
  45213. +
  45214. + header = vchiu_queue_peek(&service->queue);
  45215. +
  45216. + *data = header->data;
  45217. + *msg_size = header->size;
  45218. +
  45219. + return 0;
  45220. +}
  45221. +EXPORT_SYMBOL(vchi_msg_peek);
  45222. +
  45223. +/***********************************************************
  45224. + * Name: vchi_msg_remove
  45225. + *
  45226. + * Arguments: const VCHI_SERVICE_HANDLE_T handle,
  45227. + *
  45228. + * Description: Routine to remove a message (after it has been read with
  45229. + * vchi_msg_peek)
  45230. + *
  45231. + * Returns: int32_t - success == 0
  45232. + *
  45233. + ***********************************************************/
  45234. +int32_t vchi_msg_remove(VCHI_SERVICE_HANDLE_T handle)
  45235. +{
  45236. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  45237. + VCHIQ_HEADER_T *header;
  45238. +
  45239. + header = vchiu_queue_pop(&service->queue);
  45240. +
  45241. + vchiq_release_message(service->handle, header);
  45242. +
  45243. + return 0;
  45244. +}
  45245. +EXPORT_SYMBOL(vchi_msg_remove);
  45246. +
  45247. +/***********************************************************
  45248. + * Name: vchi_msg_queue
  45249. + *
  45250. + * Arguments: VCHI_SERVICE_HANDLE_T handle,
  45251. + * const void *data,
  45252. + * uint32_t data_size,
  45253. + * VCHI_FLAGS_T flags,
  45254. + * void *msg_handle,
  45255. + *
  45256. + * Description: Thin wrapper to queue a message onto a connection
  45257. + *
  45258. + * Returns: int32_t - success == 0
  45259. + *
  45260. + ***********************************************************/
  45261. +int32_t vchi_msg_queue(VCHI_SERVICE_HANDLE_T handle,
  45262. + const void *data,
  45263. + uint32_t data_size,
  45264. + VCHI_FLAGS_T flags,
  45265. + void *msg_handle)
  45266. +{
  45267. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  45268. + VCHIQ_ELEMENT_T element = {data, data_size};
  45269. + VCHIQ_STATUS_T status;
  45270. +
  45271. + (void)msg_handle;
  45272. +
  45273. + WARN_ON(flags != VCHI_FLAGS_BLOCK_UNTIL_QUEUED);
  45274. +
  45275. + status = vchiq_queue_message(service->handle, &element, 1);
  45276. +
  45277. + /* vchiq_queue_message() may return VCHIQ_RETRY, so we need to
  45278. + ** implement a retry mechanism since this function is supposed
  45279. + ** to block until queued
  45280. + */
  45281. + while (status == VCHIQ_RETRY) {
  45282. + msleep(1);
  45283. + status = vchiq_queue_message(service->handle, &element, 1);
  45284. + }
  45285. +
  45286. + return vchiq_status_to_vchi(status);
  45287. +}
  45288. +EXPORT_SYMBOL(vchi_msg_queue);
  45289. +
  45290. +/***********************************************************
  45291. + * Name: vchi_bulk_queue_receive
  45292. + *
  45293. + * Arguments: VCHI_BULK_HANDLE_T handle,
  45294. + * void *data_dst,
  45295. + * const uint32_t data_size,
  45296. + * VCHI_FLAGS_T flags
  45297. + * void *bulk_handle
  45298. + *
  45299. + * Description: Routine to setup a rcv buffer
  45300. + *
  45301. + * Returns: int32_t - success == 0
  45302. + *
  45303. + ***********************************************************/
  45304. +int32_t vchi_bulk_queue_receive(VCHI_SERVICE_HANDLE_T handle,
  45305. + void *data_dst,
  45306. + uint32_t data_size,
  45307. + VCHI_FLAGS_T flags,
  45308. + void *bulk_handle)
  45309. +{
  45310. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  45311. + VCHIQ_BULK_MODE_T mode;
  45312. + VCHIQ_STATUS_T status;
  45313. +
  45314. + switch ((int)flags) {
  45315. + case VCHI_FLAGS_CALLBACK_WHEN_OP_COMPLETE
  45316. + | VCHI_FLAGS_BLOCK_UNTIL_QUEUED:
  45317. + WARN_ON(!service->callback);
  45318. + mode = VCHIQ_BULK_MODE_CALLBACK;
  45319. + break;
  45320. + case VCHI_FLAGS_BLOCK_UNTIL_OP_COMPLETE:
  45321. + mode = VCHIQ_BULK_MODE_BLOCKING;
  45322. + break;
  45323. + case VCHI_FLAGS_BLOCK_UNTIL_QUEUED:
  45324. + case VCHI_FLAGS_NONE:
  45325. + mode = VCHIQ_BULK_MODE_NOCALLBACK;
  45326. + break;
  45327. + default:
  45328. + WARN(1, "unsupported message\n");
  45329. + return vchiq_status_to_vchi(VCHIQ_ERROR);
  45330. + }
  45331. +
  45332. + status = vchiq_bulk_receive(service->handle, data_dst, data_size,
  45333. + bulk_handle, mode);
  45334. +
  45335. + /* vchiq_bulk_receive() may return VCHIQ_RETRY, so we need to
  45336. + ** implement a retry mechanism since this function is supposed
  45337. + ** to block until queued
  45338. + */
  45339. + while (status == VCHIQ_RETRY) {
  45340. + msleep(1);
  45341. + status = vchiq_bulk_receive(service->handle, data_dst,
  45342. + data_size, bulk_handle, mode);
  45343. + }
  45344. +
  45345. + return vchiq_status_to_vchi(status);
  45346. +}
  45347. +EXPORT_SYMBOL(vchi_bulk_queue_receive);
  45348. +
  45349. +/***********************************************************
  45350. + * Name: vchi_bulk_queue_transmit
  45351. + *
  45352. + * Arguments: VCHI_BULK_HANDLE_T handle,
  45353. + * const void *data_src,
  45354. + * uint32_t data_size,
  45355. + * VCHI_FLAGS_T flags,
  45356. + * void *bulk_handle
  45357. + *
  45358. + * Description: Routine to transmit some data
  45359. + *
  45360. + * Returns: int32_t - success == 0
  45361. + *
  45362. + ***********************************************************/
  45363. +int32_t vchi_bulk_queue_transmit(VCHI_SERVICE_HANDLE_T handle,
  45364. + const void *data_src,
  45365. + uint32_t data_size,
  45366. + VCHI_FLAGS_T flags,
  45367. + void *bulk_handle)
  45368. +{
  45369. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  45370. + VCHIQ_BULK_MODE_T mode;
  45371. + VCHIQ_STATUS_T status;
  45372. +
  45373. + switch ((int)flags) {
  45374. + case VCHI_FLAGS_CALLBACK_WHEN_OP_COMPLETE
  45375. + | VCHI_FLAGS_BLOCK_UNTIL_QUEUED:
  45376. + WARN_ON(!service->callback);
  45377. + mode = VCHIQ_BULK_MODE_CALLBACK;
  45378. + break;
  45379. + case VCHI_FLAGS_BLOCK_UNTIL_DATA_READ:
  45380. + case VCHI_FLAGS_BLOCK_UNTIL_OP_COMPLETE:
  45381. + mode = VCHIQ_BULK_MODE_BLOCKING;
  45382. + break;
  45383. + case VCHI_FLAGS_BLOCK_UNTIL_QUEUED:
  45384. + case VCHI_FLAGS_NONE:
  45385. + mode = VCHIQ_BULK_MODE_NOCALLBACK;
  45386. + break;
  45387. + default:
  45388. + WARN(1, "unsupported message\n");
  45389. + return vchiq_status_to_vchi(VCHIQ_ERROR);
  45390. + }
  45391. +
  45392. + status = vchiq_bulk_transmit(service->handle, data_src, data_size,
  45393. + bulk_handle, mode);
  45394. +
  45395. + /* vchiq_bulk_transmit() may return VCHIQ_RETRY, so we need to
  45396. + ** implement a retry mechanism since this function is supposed
  45397. + ** to block until queued
  45398. + */
  45399. + while (status == VCHIQ_RETRY) {
  45400. + msleep(1);
  45401. + status = vchiq_bulk_transmit(service->handle, data_src,
  45402. + data_size, bulk_handle, mode);
  45403. + }
  45404. +
  45405. + return vchiq_status_to_vchi(status);
  45406. +}
  45407. +EXPORT_SYMBOL(vchi_bulk_queue_transmit);
  45408. +
  45409. +/***********************************************************
  45410. + * Name: vchi_msg_dequeue
  45411. + *
  45412. + * Arguments: VCHI_SERVICE_HANDLE_T handle,
  45413. + * void *data,
  45414. + * uint32_t max_data_size_to_read,
  45415. + * uint32_t *actual_msg_size
  45416. + * VCHI_FLAGS_T flags
  45417. + *
  45418. + * Description: Routine to dequeue a message into the supplied buffer
  45419. + *
  45420. + * Returns: int32_t - success == 0
  45421. + *
  45422. + ***********************************************************/
  45423. +int32_t vchi_msg_dequeue(VCHI_SERVICE_HANDLE_T handle,
  45424. + void *data,
  45425. + uint32_t max_data_size_to_read,
  45426. + uint32_t *actual_msg_size,
  45427. + VCHI_FLAGS_T flags)
  45428. +{
  45429. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  45430. + VCHIQ_HEADER_T *header;
  45431. +
  45432. + WARN_ON((flags != VCHI_FLAGS_NONE) &&
  45433. + (flags != VCHI_FLAGS_BLOCK_UNTIL_OP_COMPLETE));
  45434. +
  45435. + if (flags == VCHI_FLAGS_NONE)
  45436. + if (vchiu_queue_is_empty(&service->queue))
  45437. + return -1;
  45438. +
  45439. + header = vchiu_queue_pop(&service->queue);
  45440. +
  45441. + memcpy(data, header->data, header->size < max_data_size_to_read ?
  45442. + header->size : max_data_size_to_read);
  45443. +
  45444. + *actual_msg_size = header->size;
  45445. +
  45446. + vchiq_release_message(service->handle, header);
  45447. +
  45448. + return 0;
  45449. +}
  45450. +EXPORT_SYMBOL(vchi_msg_dequeue);
  45451. +
  45452. +/***********************************************************
  45453. + * Name: vchi_msg_queuev
  45454. + *
  45455. + * Arguments: VCHI_SERVICE_HANDLE_T handle,
  45456. + * VCHI_MSG_VECTOR_T *vector,
  45457. + * uint32_t count,
  45458. + * VCHI_FLAGS_T flags,
  45459. + * void *msg_handle
  45460. + *
  45461. + * Description: Thin wrapper to queue a message onto a connection
  45462. + *
  45463. + * Returns: int32_t - success == 0
  45464. + *
  45465. + ***********************************************************/
  45466. +
  45467. +vchiq_static_assert(sizeof(VCHI_MSG_VECTOR_T) == sizeof(VCHIQ_ELEMENT_T));
  45468. +vchiq_static_assert(offsetof(VCHI_MSG_VECTOR_T, vec_base) ==
  45469. + offsetof(VCHIQ_ELEMENT_T, data));
  45470. +vchiq_static_assert(offsetof(VCHI_MSG_VECTOR_T, vec_len) ==
  45471. + offsetof(VCHIQ_ELEMENT_T, size));
  45472. +
  45473. +int32_t vchi_msg_queuev(VCHI_SERVICE_HANDLE_T handle,
  45474. + VCHI_MSG_VECTOR_T *vector,
  45475. + uint32_t count,
  45476. + VCHI_FLAGS_T flags,
  45477. + void *msg_handle)
  45478. +{
  45479. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  45480. +
  45481. + (void)msg_handle;
  45482. +
  45483. + WARN_ON(flags != VCHI_FLAGS_BLOCK_UNTIL_QUEUED);
  45484. +
  45485. + return vchiq_status_to_vchi(vchiq_queue_message(service->handle,
  45486. + (const VCHIQ_ELEMENT_T *)vector, count));
  45487. +}
  45488. +EXPORT_SYMBOL(vchi_msg_queuev);
  45489. +
  45490. +/***********************************************************
  45491. + * Name: vchi_held_msg_release
  45492. + *
  45493. + * Arguments: VCHI_HELD_MSG_T *message
  45494. + *
  45495. + * Description: Routine to release a held message (after it has been read with
  45496. + * vchi_msg_hold)
  45497. + *
  45498. + * Returns: int32_t - success == 0
  45499. + *
  45500. + ***********************************************************/
  45501. +int32_t vchi_held_msg_release(VCHI_HELD_MSG_T *message)
  45502. +{
  45503. + vchiq_release_message((VCHIQ_SERVICE_HANDLE_T)message->service,
  45504. + (VCHIQ_HEADER_T *)message->message);
  45505. +
  45506. + return 0;
  45507. +}
  45508. +EXPORT_SYMBOL(vchi_held_msg_release);
  45509. +
  45510. +/***********************************************************
  45511. + * Name: vchi_msg_hold
  45512. + *
  45513. + * Arguments: VCHI_SERVICE_HANDLE_T handle,
  45514. + * void **data,
  45515. + * uint32_t *msg_size,
  45516. + * VCHI_FLAGS_T flags,
  45517. + * VCHI_HELD_MSG_T *message_handle
  45518. + *
  45519. + * Description: Routine to return a pointer to the current message (to allow
  45520. + * in place processing). The message is dequeued - don't forget
  45521. + * to release the message using vchi_held_msg_release when you're
  45522. + * finished.
  45523. + *
  45524. + * Returns: int32_t - success == 0
  45525. + *
  45526. + ***********************************************************/
  45527. +int32_t vchi_msg_hold(VCHI_SERVICE_HANDLE_T handle,
  45528. + void **data,
  45529. + uint32_t *msg_size,
  45530. + VCHI_FLAGS_T flags,
  45531. + VCHI_HELD_MSG_T *message_handle)
  45532. +{
  45533. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  45534. + VCHIQ_HEADER_T *header;
  45535. +
  45536. + WARN_ON((flags != VCHI_FLAGS_NONE) &&
  45537. + (flags != VCHI_FLAGS_BLOCK_UNTIL_OP_COMPLETE));
  45538. +
  45539. + if (flags == VCHI_FLAGS_NONE)
  45540. + if (vchiu_queue_is_empty(&service->queue))
  45541. + return -1;
  45542. +
  45543. + header = vchiu_queue_pop(&service->queue);
  45544. +
  45545. + *data = header->data;
  45546. + *msg_size = header->size;
  45547. +
  45548. + message_handle->service =
  45549. + (struct opaque_vchi_service_t *)service->handle;
  45550. + message_handle->message = header;
  45551. +
  45552. + return 0;
  45553. +}
  45554. +EXPORT_SYMBOL(vchi_msg_hold);
  45555. +
  45556. +/***********************************************************
  45557. + * Name: vchi_initialise
  45558. + *
  45559. + * Arguments: VCHI_INSTANCE_T *instance_handle
  45560. + *
  45561. + * Description: Initialises the hardware but does not transmit anything
  45562. + * When run as a Host App this will be called twice hence the need
  45563. + * to malloc the state information
  45564. + *
  45565. + * Returns: 0 if successful, failure otherwise
  45566. + *
  45567. + ***********************************************************/
  45568. +
  45569. +int32_t vchi_initialise(VCHI_INSTANCE_T *instance_handle)
  45570. +{
  45571. + VCHIQ_INSTANCE_T instance;
  45572. + VCHIQ_STATUS_T status;
  45573. +
  45574. + status = vchiq_initialise(&instance);
  45575. +
  45576. + *instance_handle = (VCHI_INSTANCE_T)instance;
  45577. +
  45578. + return vchiq_status_to_vchi(status);
  45579. +}
  45580. +EXPORT_SYMBOL(vchi_initialise);
  45581. +
  45582. +/***********************************************************
  45583. + * Name: vchi_connect
  45584. + *
  45585. + * Arguments: VCHI_CONNECTION_T **connections
  45586. + * const uint32_t num_connections
  45587. + * VCHI_INSTANCE_T instance_handle)
  45588. + *
  45589. + * Description: Starts the command service on each connection,
  45590. + * causing INIT messages to be pinged back and forth
  45591. + *
  45592. + * Returns: 0 if successful, failure otherwise
  45593. + *
  45594. + ***********************************************************/
  45595. +int32_t vchi_connect(VCHI_CONNECTION_T **connections,
  45596. + const uint32_t num_connections,
  45597. + VCHI_INSTANCE_T instance_handle)
  45598. +{
  45599. + VCHIQ_INSTANCE_T instance = (VCHIQ_INSTANCE_T)instance_handle;
  45600. +
  45601. + (void)connections;
  45602. + (void)num_connections;
  45603. +
  45604. + return vchiq_connect(instance);
  45605. +}
  45606. +EXPORT_SYMBOL(vchi_connect);
  45607. +
  45608. +
  45609. +/***********************************************************
  45610. + * Name: vchi_disconnect
  45611. + *
  45612. + * Arguments: VCHI_INSTANCE_T instance_handle
  45613. + *
  45614. + * Description: Stops the command service on each connection,
  45615. + * causing DE-INIT messages to be pinged back and forth
  45616. + *
  45617. + * Returns: 0 if successful, failure otherwise
  45618. + *
  45619. + ***********************************************************/
  45620. +int32_t vchi_disconnect(VCHI_INSTANCE_T instance_handle)
  45621. +{
  45622. + VCHIQ_INSTANCE_T instance = (VCHIQ_INSTANCE_T)instance_handle;
  45623. + return vchiq_status_to_vchi(vchiq_shutdown(instance));
  45624. +}
  45625. +EXPORT_SYMBOL(vchi_disconnect);
  45626. +
  45627. +
  45628. +/***********************************************************
  45629. + * Name: vchi_service_open
  45630. + * Name: vchi_service_create
  45631. + *
  45632. + * Arguments: VCHI_INSTANCE_T *instance_handle
  45633. + * SERVICE_CREATION_T *setup,
  45634. + * VCHI_SERVICE_HANDLE_T *handle
  45635. + *
  45636. + * Description: Routine to open a service
  45637. + *
  45638. + * Returns: int32_t - success == 0
  45639. + *
  45640. + ***********************************************************/
  45641. +
  45642. +static VCHIQ_STATUS_T shim_callback(VCHIQ_REASON_T reason,
  45643. + VCHIQ_HEADER_T *header, VCHIQ_SERVICE_HANDLE_T handle, void *bulk_user)
  45644. +{
  45645. + SHIM_SERVICE_T *service =
  45646. + (SHIM_SERVICE_T *)VCHIQ_GET_SERVICE_USERDATA(handle);
  45647. +
  45648. + if (!service->callback)
  45649. + goto release;
  45650. +
  45651. + switch (reason) {
  45652. + case VCHIQ_MESSAGE_AVAILABLE:
  45653. + vchiu_queue_push(&service->queue, header);
  45654. +
  45655. + service->callback(service->callback_param,
  45656. + VCHI_CALLBACK_MSG_AVAILABLE, NULL);
  45657. +
  45658. + goto done;
  45659. + break;
  45660. +
  45661. + case VCHIQ_BULK_TRANSMIT_DONE:
  45662. + service->callback(service->callback_param,
  45663. + VCHI_CALLBACK_BULK_SENT, bulk_user);
  45664. + break;
  45665. +
  45666. + case VCHIQ_BULK_RECEIVE_DONE:
  45667. + service->callback(service->callback_param,
  45668. + VCHI_CALLBACK_BULK_RECEIVED, bulk_user);
  45669. + break;
  45670. +
  45671. + case VCHIQ_SERVICE_CLOSED:
  45672. + service->callback(service->callback_param,
  45673. + VCHI_CALLBACK_SERVICE_CLOSED, NULL);
  45674. + break;
  45675. +
  45676. + case VCHIQ_SERVICE_OPENED:
  45677. + /* No equivalent VCHI reason */
  45678. + break;
  45679. +
  45680. + case VCHIQ_BULK_TRANSMIT_ABORTED:
  45681. + service->callback(service->callback_param,
  45682. + VCHI_CALLBACK_BULK_TRANSMIT_ABORTED,
  45683. + bulk_user);
  45684. + break;
  45685. +
  45686. + case VCHIQ_BULK_RECEIVE_ABORTED:
  45687. + service->callback(service->callback_param,
  45688. + VCHI_CALLBACK_BULK_RECEIVE_ABORTED,
  45689. + bulk_user);
  45690. + break;
  45691. +
  45692. + default:
  45693. + WARN(1, "not supported\n");
  45694. + break;
  45695. + }
  45696. +
  45697. +release:
  45698. + vchiq_release_message(service->handle, header);
  45699. +done:
  45700. + return VCHIQ_SUCCESS;
  45701. +}
  45702. +
  45703. +static SHIM_SERVICE_T *service_alloc(VCHIQ_INSTANCE_T instance,
  45704. + SERVICE_CREATION_T *setup)
  45705. +{
  45706. + SHIM_SERVICE_T *service = kzalloc(sizeof(SHIM_SERVICE_T), GFP_KERNEL);
  45707. +
  45708. + (void)instance;
  45709. +
  45710. + if (service) {
  45711. + if (vchiu_queue_init(&service->queue, 64)) {
  45712. + service->callback = setup->callback;
  45713. + service->callback_param = setup->callback_param;
  45714. + } else {
  45715. + kfree(service);
  45716. + service = NULL;
  45717. + }
  45718. + }
  45719. +
  45720. + return service;
  45721. +}
  45722. +
  45723. +static void service_free(SHIM_SERVICE_T *service)
  45724. +{
  45725. + if (service) {
  45726. + vchiu_queue_delete(&service->queue);
  45727. + kfree(service);
  45728. + }
  45729. +}
  45730. +
  45731. +int32_t vchi_service_open(VCHI_INSTANCE_T instance_handle,
  45732. + SERVICE_CREATION_T *setup,
  45733. + VCHI_SERVICE_HANDLE_T *handle)
  45734. +{
  45735. + VCHIQ_INSTANCE_T instance = (VCHIQ_INSTANCE_T)instance_handle;
  45736. + SHIM_SERVICE_T *service = service_alloc(instance, setup);
  45737. +
  45738. + *handle = (VCHI_SERVICE_HANDLE_T)service;
  45739. +
  45740. + if (service) {
  45741. + VCHIQ_SERVICE_PARAMS_T params;
  45742. + VCHIQ_STATUS_T status;
  45743. +
  45744. + memset(&params, 0, sizeof(params));
  45745. + params.fourcc = setup->service_id;
  45746. + params.callback = shim_callback;
  45747. + params.userdata = service;
  45748. + params.version = setup->version.version;
  45749. + params.version_min = setup->version.version_min;
  45750. +
  45751. + status = vchiq_open_service(instance, &params,
  45752. + &service->handle);
  45753. + if (status != VCHIQ_SUCCESS) {
  45754. + service_free(service);
  45755. + service = NULL;
  45756. + *handle = NULL;
  45757. + }
  45758. + }
  45759. +
  45760. + return (service != NULL) ? 0 : -1;
  45761. +}
  45762. +EXPORT_SYMBOL(vchi_service_open);
  45763. +
  45764. +int32_t vchi_service_create(VCHI_INSTANCE_T instance_handle,
  45765. + SERVICE_CREATION_T *setup,
  45766. + VCHI_SERVICE_HANDLE_T *handle)
  45767. +{
  45768. + VCHIQ_INSTANCE_T instance = (VCHIQ_INSTANCE_T)instance_handle;
  45769. + SHIM_SERVICE_T *service = service_alloc(instance, setup);
  45770. +
  45771. + *handle = (VCHI_SERVICE_HANDLE_T)service;
  45772. +
  45773. + if (service) {
  45774. + VCHIQ_SERVICE_PARAMS_T params;
  45775. + VCHIQ_STATUS_T status;
  45776. +
  45777. + memset(&params, 0, sizeof(params));
  45778. + params.fourcc = setup->service_id;
  45779. + params.callback = shim_callback;
  45780. + params.userdata = service;
  45781. + params.version = setup->version.version;
  45782. + params.version_min = setup->version.version_min;
  45783. + status = vchiq_add_service(instance, &params, &service->handle);
  45784. +
  45785. + if (status != VCHIQ_SUCCESS) {
  45786. + service_free(service);
  45787. + service = NULL;
  45788. + *handle = NULL;
  45789. + }
  45790. + }
  45791. +
  45792. + return (service != NULL) ? 0 : -1;
  45793. +}
  45794. +EXPORT_SYMBOL(vchi_service_create);
  45795. +
  45796. +int32_t vchi_service_close(const VCHI_SERVICE_HANDLE_T handle)
  45797. +{
  45798. + int32_t ret = -1;
  45799. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  45800. + if (service) {
  45801. + VCHIQ_STATUS_T status = vchiq_close_service(service->handle);
  45802. + if (status == VCHIQ_SUCCESS) {
  45803. + service_free(service);
  45804. + service = NULL;
  45805. + }
  45806. +
  45807. + ret = vchiq_status_to_vchi(status);
  45808. + }
  45809. + return ret;
  45810. +}
  45811. +EXPORT_SYMBOL(vchi_service_close);
  45812. +
  45813. +int32_t vchi_service_destroy(const VCHI_SERVICE_HANDLE_T handle)
  45814. +{
  45815. + int32_t ret = -1;
  45816. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  45817. + if (service) {
  45818. + VCHIQ_STATUS_T status = vchiq_remove_service(service->handle);
  45819. + if (status == VCHIQ_SUCCESS) {
  45820. + service_free(service);
  45821. + service = NULL;
  45822. + }
  45823. +
  45824. + ret = vchiq_status_to_vchi(status);
  45825. + }
  45826. + return ret;
  45827. +}
  45828. +EXPORT_SYMBOL(vchi_service_destroy);
  45829. +
  45830. +int32_t vchi_service_set_option(const VCHI_SERVICE_HANDLE_T handle,
  45831. + VCHI_SERVICE_OPTION_T option,
  45832. + int value)
  45833. +{
  45834. + int32_t ret = -1;
  45835. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  45836. + VCHIQ_SERVICE_OPTION_T vchiq_option;
  45837. + switch (option) {
  45838. + case VCHI_SERVICE_OPTION_TRACE:
  45839. + vchiq_option = VCHIQ_SERVICE_OPTION_TRACE;
  45840. + break;
  45841. + case VCHI_SERVICE_OPTION_SYNCHRONOUS:
  45842. + vchiq_option = VCHIQ_SERVICE_OPTION_SYNCHRONOUS;
  45843. + break;
  45844. + default:
  45845. + service = NULL;
  45846. + break;
  45847. + }
  45848. + if (service) {
  45849. + VCHIQ_STATUS_T status =
  45850. + vchiq_set_service_option(service->handle,
  45851. + vchiq_option,
  45852. + value);
  45853. +
  45854. + ret = vchiq_status_to_vchi(status);
  45855. + }
  45856. + return ret;
  45857. +}
  45858. +EXPORT_SYMBOL(vchi_service_set_option);
  45859. +
  45860. +int32_t vchi_get_peer_version( const VCHI_SERVICE_HANDLE_T handle, short *peer_version )
  45861. +{
  45862. + int32_t ret = -1;
  45863. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  45864. + if(service)
  45865. + {
  45866. + VCHIQ_STATUS_T status = vchiq_get_peer_version(service->handle, peer_version);
  45867. + ret = vchiq_status_to_vchi( status );
  45868. + }
  45869. + return ret;
  45870. +}
  45871. +EXPORT_SYMBOL(vchi_get_peer_version);
  45872. +
  45873. +/* ----------------------------------------------------------------------
  45874. + * read a uint32_t from buffer.
  45875. + * network format is defined to be little endian
  45876. + * -------------------------------------------------------------------- */
  45877. +uint32_t
  45878. +vchi_readbuf_uint32(const void *_ptr)
  45879. +{
  45880. + const unsigned char *ptr = _ptr;
  45881. + return ptr[0] | (ptr[1] << 8) | (ptr[2] << 16) | (ptr[3] << 24);
  45882. +}
  45883. +
  45884. +/* ----------------------------------------------------------------------
  45885. + * write a uint32_t to buffer.
  45886. + * network format is defined to be little endian
  45887. + * -------------------------------------------------------------------- */
  45888. +void
  45889. +vchi_writebuf_uint32(void *_ptr, uint32_t value)
  45890. +{
  45891. + unsigned char *ptr = _ptr;
  45892. + ptr[0] = (unsigned char)((value >> 0) & 0xFF);
  45893. + ptr[1] = (unsigned char)((value >> 8) & 0xFF);
  45894. + ptr[2] = (unsigned char)((value >> 16) & 0xFF);
  45895. + ptr[3] = (unsigned char)((value >> 24) & 0xFF);
  45896. +}
  45897. +
  45898. +/* ----------------------------------------------------------------------
  45899. + * read a uint16_t from buffer.
  45900. + * network format is defined to be little endian
  45901. + * -------------------------------------------------------------------- */
  45902. +uint16_t
  45903. +vchi_readbuf_uint16(const void *_ptr)
  45904. +{
  45905. + const unsigned char *ptr = _ptr;
  45906. + return ptr[0] | (ptr[1] << 8);
  45907. +}
  45908. +
  45909. +/* ----------------------------------------------------------------------
  45910. + * write a uint16_t into the buffer.
  45911. + * network format is defined to be little endian
  45912. + * -------------------------------------------------------------------- */
  45913. +void
  45914. +vchi_writebuf_uint16(void *_ptr, uint16_t value)
  45915. +{
  45916. + unsigned char *ptr = _ptr;
  45917. + ptr[0] = (value >> 0) & 0xFF;
  45918. + ptr[1] = (value >> 8) & 0xFF;
  45919. +}
  45920. +
  45921. +/***********************************************************
  45922. + * Name: vchi_service_use
  45923. + *
  45924. + * Arguments: const VCHI_SERVICE_HANDLE_T handle
  45925. + *
  45926. + * Description: Routine to increment refcount on a service
  45927. + *
  45928. + * Returns: void
  45929. + *
  45930. + ***********************************************************/
  45931. +int32_t vchi_service_use(const VCHI_SERVICE_HANDLE_T handle)
  45932. +{
  45933. + int32_t ret = -1;
  45934. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  45935. + if (service)
  45936. + ret = vchiq_status_to_vchi(vchiq_use_service(service->handle));
  45937. + return ret;
  45938. +}
  45939. +EXPORT_SYMBOL(vchi_service_use);
  45940. +
  45941. +/***********************************************************
  45942. + * Name: vchi_service_release
  45943. + *
  45944. + * Arguments: const VCHI_SERVICE_HANDLE_T handle
  45945. + *
  45946. + * Description: Routine to decrement refcount on a service
  45947. + *
  45948. + * Returns: void
  45949. + *
  45950. + ***********************************************************/
  45951. +int32_t vchi_service_release(const VCHI_SERVICE_HANDLE_T handle)
  45952. +{
  45953. + int32_t ret = -1;
  45954. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  45955. + if (service)
  45956. + ret = vchiq_status_to_vchi(
  45957. + vchiq_release_service(service->handle));
  45958. + return ret;
  45959. +}
  45960. +EXPORT_SYMBOL(vchi_service_release);
  45961. diff -Nur linux-3.18.8/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.c linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.c
  45962. --- linux-3.18.8/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.c 1970-01-01 01:00:00.000000000 +0100
  45963. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.c 2015-03-05 14:40:14.405715819 +0100
  45964. @@ -0,0 +1,152 @@
  45965. +/**
  45966. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  45967. + *
  45968. + * Redistribution and use in source and binary forms, with or without
  45969. + * modification, are permitted provided that the following conditions
  45970. + * are met:
  45971. + * 1. Redistributions of source code must retain the above copyright
  45972. + * notice, this list of conditions, and the following disclaimer,
  45973. + * without modification.
  45974. + * 2. Redistributions in binary form must reproduce the above copyright
  45975. + * notice, this list of conditions and the following disclaimer in the
  45976. + * documentation and/or other materials provided with the distribution.
  45977. + * 3. The names of the above-listed copyright holders may not be used
  45978. + * to endorse or promote products derived from this software without
  45979. + * specific prior written permission.
  45980. + *
  45981. + * ALTERNATIVELY, this software may be distributed under the terms of the
  45982. + * GNU General Public License ("GPL") version 2, as published by the Free
  45983. + * Software Foundation.
  45984. + *
  45985. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  45986. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  45987. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  45988. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  45989. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  45990. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  45991. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  45992. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  45993. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  45994. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  45995. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  45996. + */
  45997. +
  45998. +#include "vchiq_util.h"
  45999. +#include "vchiq_killable.h"
  46000. +
  46001. +static inline int is_pow2(int i)
  46002. +{
  46003. + return i && !(i & (i - 1));
  46004. +}
  46005. +
  46006. +int vchiu_queue_init(VCHIU_QUEUE_T *queue, int size)
  46007. +{
  46008. + WARN_ON(!is_pow2(size));
  46009. +
  46010. + queue->size = size;
  46011. + queue->read = 0;
  46012. + queue->write = 0;
  46013. +
  46014. + sema_init(&queue->pop, 0);
  46015. + sema_init(&queue->push, 0);
  46016. +
  46017. + queue->storage = kzalloc(size * sizeof(VCHIQ_HEADER_T *), GFP_KERNEL);
  46018. + if (queue->storage == NULL) {
  46019. + vchiu_queue_delete(queue);
  46020. + return 0;
  46021. + }
  46022. + return 1;
  46023. +}
  46024. +
  46025. +void vchiu_queue_delete(VCHIU_QUEUE_T *queue)
  46026. +{
  46027. + if (queue->storage != NULL)
  46028. + kfree(queue->storage);
  46029. +}
  46030. +
  46031. +int vchiu_queue_is_empty(VCHIU_QUEUE_T *queue)
  46032. +{
  46033. + return queue->read == queue->write;
  46034. +}
  46035. +
  46036. +int vchiu_queue_is_full(VCHIU_QUEUE_T *queue)
  46037. +{
  46038. + return queue->write == queue->read + queue->size;
  46039. +}
  46040. +
  46041. +void vchiu_queue_push(VCHIU_QUEUE_T *queue, VCHIQ_HEADER_T *header)
  46042. +{
  46043. + while (queue->write == queue->read + queue->size) {
  46044. + if (down_interruptible(&queue->pop) != 0) {
  46045. + flush_signals(current);
  46046. + }
  46047. + }
  46048. +
  46049. + /*
  46050. + * Write to queue->storage must be visible after read from
  46051. + * queue->read
  46052. + */
  46053. + smp_mb();
  46054. +
  46055. + queue->storage[queue->write & (queue->size - 1)] = header;
  46056. +
  46057. + /*
  46058. + * Write to queue->storage must be visible before write to
  46059. + * queue->write
  46060. + */
  46061. + smp_wmb();
  46062. +
  46063. + queue->write++;
  46064. +
  46065. + up(&queue->push);
  46066. +}
  46067. +
  46068. +VCHIQ_HEADER_T *vchiu_queue_peek(VCHIU_QUEUE_T *queue)
  46069. +{
  46070. + while (queue->write == queue->read) {
  46071. + if (down_interruptible(&queue->push) != 0) {
  46072. + flush_signals(current);
  46073. + }
  46074. + }
  46075. +
  46076. + up(&queue->push); // We haven't removed anything from the queue.
  46077. +
  46078. + /*
  46079. + * Read from queue->storage must be visible after read from
  46080. + * queue->write
  46081. + */
  46082. + smp_rmb();
  46083. +
  46084. + return queue->storage[queue->read & (queue->size - 1)];
  46085. +}
  46086. +
  46087. +VCHIQ_HEADER_T *vchiu_queue_pop(VCHIU_QUEUE_T *queue)
  46088. +{
  46089. + VCHIQ_HEADER_T *header;
  46090. +
  46091. + while (queue->write == queue->read) {
  46092. + if (down_interruptible(&queue->push) != 0) {
  46093. + flush_signals(current);
  46094. + }
  46095. + }
  46096. +
  46097. + /*
  46098. + * Read from queue->storage must be visible after read from
  46099. + * queue->write
  46100. + */
  46101. + smp_rmb();
  46102. +
  46103. + header = queue->storage[queue->read & (queue->size - 1)];
  46104. +
  46105. + /*
  46106. + * Read from queue->storage must be visible before write to
  46107. + * queue->read
  46108. + */
  46109. + smp_mb();
  46110. +
  46111. + queue->read++;
  46112. +
  46113. + up(&queue->pop);
  46114. +
  46115. + return header;
  46116. +}
  46117. diff -Nur linux-3.18.8/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.h
  46118. --- linux-3.18.8/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.h 1970-01-01 01:00:00.000000000 +0100
  46119. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.h 2015-03-05 14:40:14.405715819 +0100
  46120. @@ -0,0 +1,81 @@
  46121. +/**
  46122. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  46123. + *
  46124. + * Redistribution and use in source and binary forms, with or without
  46125. + * modification, are permitted provided that the following conditions
  46126. + * are met:
  46127. + * 1. Redistributions of source code must retain the above copyright
  46128. + * notice, this list of conditions, and the following disclaimer,
  46129. + * without modification.
  46130. + * 2. Redistributions in binary form must reproduce the above copyright
  46131. + * notice, this list of conditions and the following disclaimer in the
  46132. + * documentation and/or other materials provided with the distribution.
  46133. + * 3. The names of the above-listed copyright holders may not be used
  46134. + * to endorse or promote products derived from this software without
  46135. + * specific prior written permission.
  46136. + *
  46137. + * ALTERNATIVELY, this software may be distributed under the terms of the
  46138. + * GNU General Public License ("GPL") version 2, as published by the Free
  46139. + * Software Foundation.
  46140. + *
  46141. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  46142. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  46143. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  46144. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  46145. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  46146. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  46147. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  46148. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  46149. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  46150. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  46151. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  46152. + */
  46153. +
  46154. +#ifndef VCHIQ_UTIL_H
  46155. +#define VCHIQ_UTIL_H
  46156. +
  46157. +#include <linux/types.h>
  46158. +#include <linux/semaphore.h>
  46159. +#include <linux/mutex.h>
  46160. +#include <linux/bitops.h>
  46161. +#include <linux/kthread.h>
  46162. +#include <linux/wait.h>
  46163. +#include <linux/vmalloc.h>
  46164. +#include <linux/jiffies.h>
  46165. +#include <linux/delay.h>
  46166. +#include <linux/string.h>
  46167. +#include <linux/types.h>
  46168. +#include <linux/interrupt.h>
  46169. +#include <linux/random.h>
  46170. +#include <linux/sched.h>
  46171. +#include <linux/ctype.h>
  46172. +#include <linux/uaccess.h>
  46173. +#include <linux/time.h> /* for time_t */
  46174. +#include <linux/slab.h>
  46175. +#include <linux/vmalloc.h>
  46176. +
  46177. +#include "vchiq_if.h"
  46178. +
  46179. +typedef struct {
  46180. + int size;
  46181. + int read;
  46182. + int write;
  46183. +
  46184. + struct semaphore pop;
  46185. + struct semaphore push;
  46186. +
  46187. + VCHIQ_HEADER_T **storage;
  46188. +} VCHIU_QUEUE_T;
  46189. +
  46190. +extern int vchiu_queue_init(VCHIU_QUEUE_T *queue, int size);
  46191. +extern void vchiu_queue_delete(VCHIU_QUEUE_T *queue);
  46192. +
  46193. +extern int vchiu_queue_is_empty(VCHIU_QUEUE_T *queue);
  46194. +extern int vchiu_queue_is_full(VCHIU_QUEUE_T *queue);
  46195. +
  46196. +extern void vchiu_queue_push(VCHIU_QUEUE_T *queue, VCHIQ_HEADER_T *header);
  46197. +
  46198. +extern VCHIQ_HEADER_T *vchiu_queue_peek(VCHIU_QUEUE_T *queue);
  46199. +extern VCHIQ_HEADER_T *vchiu_queue_pop(VCHIU_QUEUE_T *queue);
  46200. +
  46201. +#endif
  46202. diff -Nur linux-3.18.8/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_version.c linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_version.c
  46203. --- linux-3.18.8/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_version.c 1970-01-01 01:00:00.000000000 +0100
  46204. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_version.c 2015-03-05 14:40:14.405715819 +0100
  46205. @@ -0,0 +1,59 @@
  46206. +/**
  46207. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  46208. + *
  46209. + * Redistribution and use in source and binary forms, with or without
  46210. + * modification, are permitted provided that the following conditions
  46211. + * are met:
  46212. + * 1. Redistributions of source code must retain the above copyright
  46213. + * notice, this list of conditions, and the following disclaimer,
  46214. + * without modification.
  46215. + * 2. Redistributions in binary form must reproduce the above copyright
  46216. + * notice, this list of conditions and the following disclaimer in the
  46217. + * documentation and/or other materials provided with the distribution.
  46218. + * 3. The names of the above-listed copyright holders may not be used
  46219. + * to endorse or promote products derived from this software without
  46220. + * specific prior written permission.
  46221. + *
  46222. + * ALTERNATIVELY, this software may be distributed under the terms of the
  46223. + * GNU General Public License ("GPL") version 2, as published by the Free
  46224. + * Software Foundation.
  46225. + *
  46226. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  46227. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  46228. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  46229. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  46230. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  46231. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  46232. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  46233. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  46234. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  46235. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  46236. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  46237. + */
  46238. +#include "vchiq_build_info.h"
  46239. +#include <linux/broadcom/vc_debug_sym.h>
  46240. +
  46241. +VC_DEBUG_DECLARE_STRING_VAR( vchiq_build_hostname, "dc4-arm-01" );
  46242. +VC_DEBUG_DECLARE_STRING_VAR( vchiq_build_version, "9245b4c35b99b3870e1f7dc598c5692b3c66a6f0 (tainted)" );
  46243. +VC_DEBUG_DECLARE_STRING_VAR( vchiq_build_time, __TIME__ );
  46244. +VC_DEBUG_DECLARE_STRING_VAR( vchiq_build_date, __DATE__ );
  46245. +
  46246. +const char *vchiq_get_build_hostname( void )
  46247. +{
  46248. + return vchiq_build_hostname;
  46249. +}
  46250. +
  46251. +const char *vchiq_get_build_version( void )
  46252. +{
  46253. + return vchiq_build_version;
  46254. +}
  46255. +
  46256. +const char *vchiq_get_build_date( void )
  46257. +{
  46258. + return vchiq_build_date;
  46259. +}
  46260. +
  46261. +const char *vchiq_get_build_time( void )
  46262. +{
  46263. + return vchiq_build_time;
  46264. +}
  46265. diff -Nur linux-3.18.8/drivers/misc/vc04_services/Kconfig linux-rpi/drivers/misc/vc04_services/Kconfig
  46266. --- linux-3.18.8/drivers/misc/vc04_services/Kconfig 1970-01-01 01:00:00.000000000 +0100
  46267. +++ linux-rpi/drivers/misc/vc04_services/Kconfig 2015-03-05 14:40:14.401715819 +0100
  46268. @@ -0,0 +1,9 @@
  46269. +config BCM2708_VCHIQ
  46270. + tristate "Videocore VCHIQ"
  46271. + depends on MACH_BCM2708 || MACH_BCM2709
  46272. + default y
  46273. + help
  46274. + Kernel to VideoCore communication interface for the
  46275. + BCM2708 family of products.
  46276. + Defaults to Y when the Broadcom Videocore services
  46277. + are included in the build, N otherwise.
  46278. diff -Nur linux-3.18.8/drivers/misc/vc04_services/Makefile linux-rpi/drivers/misc/vc04_services/Makefile
  46279. --- linux-3.18.8/drivers/misc/vc04_services/Makefile 1970-01-01 01:00:00.000000000 +0100
  46280. +++ linux-rpi/drivers/misc/vc04_services/Makefile 2015-03-05 14:40:14.401715819 +0100
  46281. @@ -0,0 +1,14 @@
  46282. +obj-$(CONFIG_BCM2708_VCHIQ) += vchiq.o
  46283. +
  46284. +vchiq-objs := \
  46285. + interface/vchiq_arm/vchiq_core.o \
  46286. + interface/vchiq_arm/vchiq_arm.o \
  46287. + interface/vchiq_arm/vchiq_kern_lib.o \
  46288. + interface/vchiq_arm/vchiq_2835_arm.o \
  46289. + interface/vchiq_arm/vchiq_debugfs.o \
  46290. + interface/vchiq_arm/vchiq_shim.o \
  46291. + interface/vchiq_arm/vchiq_util.o \
  46292. + interface/vchiq_arm/vchiq_connected.o \
  46293. +
  46294. +ccflags-y += -DVCOS_VERIFY_BKPTS=1 -Idrivers/misc/vc04_services -DUSE_VCHIQ_ARM -D__VCCOREVER__=0x04000000
  46295. +
  46296. diff -Nur linux-3.18.8/drivers/mmc/core/quirks.c linux-rpi/drivers/mmc/core/quirks.c
  46297. --- linux-3.18.8/drivers/mmc/core/quirks.c 2015-02-27 02:49:36.000000000 +0100
  46298. +++ linux-rpi/drivers/mmc/core/quirks.c 2015-03-05 14:40:14.409715819 +0100
  46299. @@ -95,5 +95,9 @@
  46300. f->vendor_fixup(card, f->data);
  46301. }
  46302. }
  46303. + /* SDHCI on BCM2708 - bug causes a certain sequence of CMD23 operations to fail.
  46304. + * Disable this flag for all cards (fall-back to CMD25/CMD18 multi-block transfers).
  46305. + */
  46306. + card->quirks |= MMC_QUIRK_BLK_NO_CMD23;
  46307. }
  46308. EXPORT_SYMBOL(mmc_fixup_device);
  46309. diff -Nur linux-3.18.8/drivers/mmc/host/bcm2835-mmc.c linux-rpi/drivers/mmc/host/bcm2835-mmc.c
  46310. --- linux-3.18.8/drivers/mmc/host/bcm2835-mmc.c 1970-01-01 01:00:00.000000000 +0100
  46311. +++ linux-rpi/drivers/mmc/host/bcm2835-mmc.c 2015-03-05 14:40:14.409715819 +0100
  46312. @@ -0,0 +1,1557 @@
  46313. +/*
  46314. + * BCM2835 MMC host driver.
  46315. + *
  46316. + * Author: Gellert Weisz <gellert@raspberrypi.org>
  46317. + * Copyright 2014
  46318. + *
  46319. + * Based on
  46320. + * sdhci-bcm2708.c by Broadcom
  46321. + * sdhci-bcm2835.c by Stephen Warren and Oleksandr Tymoshenko
  46322. + * sdhci.c and sdhci-pci.c by Pierre Ossman
  46323. + *
  46324. + * This program is free software; you can redistribute it and/or modify it
  46325. + * under the terms and conditions of the GNU General Public License,
  46326. + * version 2, as published by the Free Software Foundation.
  46327. + *
  46328. + * This program is distributed in the hope it will be useful, but WITHOUT
  46329. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  46330. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  46331. + * more details.
  46332. + *
  46333. + * You should have received a copy of the GNU General Public License
  46334. + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  46335. + */
  46336. +
  46337. +#include <linux/delay.h>
  46338. +#include <linux/module.h>
  46339. +#include <linux/io.h>
  46340. +#include <linux/mmc/mmc.h>
  46341. +#include <linux/mmc/host.h>
  46342. +#include <linux/mmc/sd.h>
  46343. +#include <linux/scatterlist.h>
  46344. +#include <linux/of_address.h>
  46345. +#include <linux/of_irq.h>
  46346. +#include <linux/clk.h>
  46347. +#include <linux/platform_device.h>
  46348. +#include <linux/err.h>
  46349. +#include <linux/blkdev.h>
  46350. +#include <linux/dmaengine.h>
  46351. +#include <linux/dma-mapping.h>
  46352. +#include <linux/of_dma.h>
  46353. +
  46354. +#include "sdhci.h"
  46355. +
  46356. +
  46357. +#ifndef CONFIG_ARCH_BCM2835
  46358. + #define BCM2835_CLOCK_FREQ 250000000
  46359. +#endif
  46360. +
  46361. +#define DRIVER_NAME "mmc-bcm2835"
  46362. +
  46363. +#define DBG(f, x...) \
  46364. +pr_debug(DRIVER_NAME " [%s()]: " f, __func__, ## x)
  46365. +
  46366. +#ifndef CONFIG_MMC_BCM2835_DMA
  46367. + #define FORCE_PIO
  46368. +#endif
  46369. +
  46370. +
  46371. +/* the inclusive limit in bytes under which PIO will be used instead of DMA */
  46372. +#ifdef CONFIG_MMC_BCM2835_PIO_DMA_BARRIER
  46373. +#define PIO_DMA_BARRIER CONFIG_MMC_BCM2835_PIO_DMA_BARRIER
  46374. +#else
  46375. +#define PIO_DMA_BARRIER 00
  46376. +#endif
  46377. +
  46378. +#define MIN_FREQ 400000
  46379. +#define TIMEOUT_VAL 0xE
  46380. +#define BCM2835_SDHCI_WRITE_DELAY(f) (((2 * 1000000) / f) + 1)
  46381. +
  46382. +#ifndef BCM2708_PERI_BASE
  46383. + #define BCM2708_PERI_BASE 0x20000000
  46384. +#endif
  46385. +
  46386. +/* FIXME: Needs IOMMU support */
  46387. +#define BCM2835_VCMMU_SHIFT (0x7E000000 - BCM2708_PERI_BASE)
  46388. +
  46389. +
  46390. +struct bcm2835_host {
  46391. + spinlock_t lock;
  46392. +
  46393. + void __iomem *ioaddr;
  46394. + u32 phys_addr;
  46395. +
  46396. + struct mmc_host *mmc;
  46397. +
  46398. + u32 timeout;
  46399. +
  46400. + int clock; /* Current clock speed */
  46401. + u8 pwr; /* Current voltage */
  46402. +
  46403. + unsigned int max_clk; /* Max possible freq */
  46404. + unsigned int timeout_clk; /* Timeout freq (KHz) */
  46405. + unsigned int clk_mul; /* Clock Muliplier value */
  46406. +
  46407. + struct tasklet_struct finish_tasklet; /* Tasklet structures */
  46408. +
  46409. + struct timer_list timer; /* Timer for timeouts */
  46410. +
  46411. + struct sg_mapping_iter sg_miter; /* SG state for PIO */
  46412. + unsigned int blocks; /* remaining PIO blocks */
  46413. +
  46414. + int irq; /* Device IRQ */
  46415. +
  46416. +
  46417. + u32 ier; /* cached registers */
  46418. +
  46419. + struct mmc_request *mrq; /* Current request */
  46420. + struct mmc_command *cmd; /* Current command */
  46421. + struct mmc_data *data; /* Current data request */
  46422. + unsigned int data_early:1; /* Data finished before cmd */
  46423. +
  46424. + wait_queue_head_t buf_ready_int; /* Waitqueue for Buffer Read Ready interrupt */
  46425. +
  46426. + u32 thread_isr;
  46427. +
  46428. + u32 shadow;
  46429. +
  46430. + /*DMA part*/
  46431. + struct dma_chan *dma_chan_rx; /* DMA channel for reads */
  46432. + struct dma_chan *dma_chan_tx; /* DMA channel for writes */
  46433. + struct dma_async_tx_descriptor *tx_desc; /* descriptor */
  46434. +
  46435. + bool have_dma;
  46436. + bool use_dma;
  46437. + /*end of DMA part*/
  46438. +
  46439. + int max_delay; /* maximum length of time spent waiting */
  46440. +
  46441. + int flags; /* Host attributes */
  46442. +#define SDHCI_USE_SDMA (1<<0) /* Host is SDMA capable */
  46443. +#define SDHCI_USE_ADMA (1<<1) /* Host is ADMA capable */
  46444. +#define SDHCI_REQ_USE_DMA (1<<2) /* Use DMA for this req. */
  46445. +#define SDHCI_DEVICE_DEAD (1<<3) /* Device unresponsive */
  46446. +#define SDHCI_AUTO_CMD12 (1<<6) /* Auto CMD12 support */
  46447. +#define SDHCI_AUTO_CMD23 (1<<7) /* Auto CMD23 support */
  46448. +#define SDHCI_PV_ENABLED (1<<8) /* Preset value enabled */
  46449. +#define SDHCI_SDIO_IRQ_ENABLED (1<<9) /* SDIO irq enabled */
  46450. +#define SDHCI_USE_PLATDMA (1<<12) /* Host uses 3rd party DMA */
  46451. +};
  46452. +
  46453. +
  46454. +static inline void bcm2835_mmc_writel(struct bcm2835_host *host, u32 val, int reg)
  46455. +{
  46456. + writel(val, host->ioaddr + reg);
  46457. + udelay(BCM2835_SDHCI_WRITE_DELAY(max(host->clock, MIN_FREQ)));
  46458. +}
  46459. +
  46460. +static inline void mmc_raw_writel(struct bcm2835_host *host, u32 val, int reg)
  46461. +{
  46462. + writel(val, host->ioaddr + reg);
  46463. +}
  46464. +
  46465. +static inline u32 bcm2835_mmc_readl(struct bcm2835_host *host, int reg)
  46466. +{
  46467. + return readl(host->ioaddr + reg);
  46468. +}
  46469. +
  46470. +static inline void bcm2835_mmc_writew(struct bcm2835_host *host, u16 val, int reg)
  46471. +{
  46472. + u32 oldval = (reg == SDHCI_COMMAND) ? host->shadow :
  46473. + bcm2835_mmc_readl(host, reg & ~3);
  46474. + u32 word_num = (reg >> 1) & 1;
  46475. + u32 word_shift = word_num * 16;
  46476. + u32 mask = 0xffff << word_shift;
  46477. + u32 newval = (oldval & ~mask) | (val << word_shift);
  46478. +
  46479. + if (reg == SDHCI_TRANSFER_MODE)
  46480. + host->shadow = newval;
  46481. + else
  46482. + bcm2835_mmc_writel(host, newval, reg & ~3);
  46483. +
  46484. +}
  46485. +
  46486. +static inline void bcm2835_mmc_writeb(struct bcm2835_host *host, u8 val, int reg)
  46487. +{
  46488. + u32 oldval = bcm2835_mmc_readl(host, reg & ~3);
  46489. + u32 byte_num = reg & 3;
  46490. + u32 byte_shift = byte_num * 8;
  46491. + u32 mask = 0xff << byte_shift;
  46492. + u32 newval = (oldval & ~mask) | (val << byte_shift);
  46493. +
  46494. + bcm2835_mmc_writel(host, newval, reg & ~3);
  46495. +}
  46496. +
  46497. +
  46498. +static inline u16 bcm2835_mmc_readw(struct bcm2835_host *host, int reg)
  46499. +{
  46500. + u32 val = bcm2835_mmc_readl(host, (reg & ~3));
  46501. + u32 word_num = (reg >> 1) & 1;
  46502. + u32 word_shift = word_num * 16;
  46503. + u32 word = (val >> word_shift) & 0xffff;
  46504. +
  46505. + return word;
  46506. +}
  46507. +
  46508. +static inline u8 bcm2835_mmc_readb(struct bcm2835_host *host, int reg)
  46509. +{
  46510. + u32 val = bcm2835_mmc_readl(host, (reg & ~3));
  46511. + u32 byte_num = reg & 3;
  46512. + u32 byte_shift = byte_num * 8;
  46513. + u32 byte = (val >> byte_shift) & 0xff;
  46514. +
  46515. + return byte;
  46516. +}
  46517. +
  46518. +static void bcm2835_mmc_unsignal_irqs(struct bcm2835_host *host, u32 clear)
  46519. +{
  46520. + u32 ier;
  46521. +
  46522. + ier = bcm2835_mmc_readl(host, SDHCI_SIGNAL_ENABLE);
  46523. + ier &= ~clear;
  46524. + /* change which requests generate IRQs - makes no difference to
  46525. + the content of SDHCI_INT_STATUS, or the need to acknowledge IRQs */
  46526. + bcm2835_mmc_writel(host, ier, SDHCI_SIGNAL_ENABLE);
  46527. +}
  46528. +
  46529. +
  46530. +static void bcm2835_mmc_dumpregs(struct bcm2835_host *host)
  46531. +{
  46532. + pr_debug(DRIVER_NAME ": =========== REGISTER DUMP (%s)===========\n",
  46533. + mmc_hostname(host->mmc));
  46534. +
  46535. + pr_debug(DRIVER_NAME ": Sys addr: 0x%08x | Version: 0x%08x\n",
  46536. + bcm2835_mmc_readl(host, SDHCI_DMA_ADDRESS),
  46537. + bcm2835_mmc_readw(host, SDHCI_HOST_VERSION));
  46538. + pr_debug(DRIVER_NAME ": Blk size: 0x%08x | Blk cnt: 0x%08x\n",
  46539. + bcm2835_mmc_readw(host, SDHCI_BLOCK_SIZE),
  46540. + bcm2835_mmc_readw(host, SDHCI_BLOCK_COUNT));
  46541. + pr_debug(DRIVER_NAME ": Argument: 0x%08x | Trn mode: 0x%08x\n",
  46542. + bcm2835_mmc_readl(host, SDHCI_ARGUMENT),
  46543. + bcm2835_mmc_readw(host, SDHCI_TRANSFER_MODE));
  46544. + pr_debug(DRIVER_NAME ": Present: 0x%08x | Host ctl: 0x%08x\n",
  46545. + bcm2835_mmc_readl(host, SDHCI_PRESENT_STATE),
  46546. + bcm2835_mmc_readb(host, SDHCI_HOST_CONTROL));
  46547. + pr_debug(DRIVER_NAME ": Power: 0x%08x | Blk gap: 0x%08x\n",
  46548. + bcm2835_mmc_readb(host, SDHCI_POWER_CONTROL),
  46549. + bcm2835_mmc_readb(host, SDHCI_BLOCK_GAP_CONTROL));
  46550. + pr_debug(DRIVER_NAME ": Wake-up: 0x%08x | Clock: 0x%08x\n",
  46551. + bcm2835_mmc_readb(host, SDHCI_WAKE_UP_CONTROL),
  46552. + bcm2835_mmc_readw(host, SDHCI_CLOCK_CONTROL));
  46553. + pr_debug(DRIVER_NAME ": Timeout: 0x%08x | Int stat: 0x%08x\n",
  46554. + bcm2835_mmc_readb(host, SDHCI_TIMEOUT_CONTROL),
  46555. + bcm2835_mmc_readl(host, SDHCI_INT_STATUS));
  46556. + pr_debug(DRIVER_NAME ": Int enab: 0x%08x | Sig enab: 0x%08x\n",
  46557. + bcm2835_mmc_readl(host, SDHCI_INT_ENABLE),
  46558. + bcm2835_mmc_readl(host, SDHCI_SIGNAL_ENABLE));
  46559. + pr_debug(DRIVER_NAME ": AC12 err: 0x%08x | Slot int: 0x%08x\n",
  46560. + bcm2835_mmc_readw(host, SDHCI_ACMD12_ERR),
  46561. + bcm2835_mmc_readw(host, SDHCI_SLOT_INT_STATUS));
  46562. + pr_debug(DRIVER_NAME ": Caps: 0x%08x | Caps_1: 0x%08x\n",
  46563. + bcm2835_mmc_readl(host, SDHCI_CAPABILITIES),
  46564. + bcm2835_mmc_readl(host, SDHCI_CAPABILITIES_1));
  46565. + pr_debug(DRIVER_NAME ": Cmd: 0x%08x | Max curr: 0x%08x\n",
  46566. + bcm2835_mmc_readw(host, SDHCI_COMMAND),
  46567. + bcm2835_mmc_readl(host, SDHCI_MAX_CURRENT));
  46568. + pr_debug(DRIVER_NAME ": Host ctl2: 0x%08x\n",
  46569. + bcm2835_mmc_readw(host, SDHCI_HOST_CONTROL2));
  46570. +
  46571. + pr_debug(DRIVER_NAME ": ===========================================\n");
  46572. +}
  46573. +
  46574. +
  46575. +static void bcm2835_mmc_reset(struct bcm2835_host *host, u8 mask)
  46576. +{
  46577. + unsigned long timeout;
  46578. +
  46579. + bcm2835_mmc_writeb(host, mask, SDHCI_SOFTWARE_RESET);
  46580. +
  46581. + if (mask & SDHCI_RESET_ALL)
  46582. + host->clock = 0;
  46583. +
  46584. + /* Wait max 100 ms */
  46585. + timeout = 100;
  46586. +
  46587. + /* hw clears the bit when it's done */
  46588. + while (bcm2835_mmc_readb(host, SDHCI_SOFTWARE_RESET) & mask) {
  46589. + if (timeout == 0) {
  46590. + pr_err("%s: Reset 0x%x never completed.\n",
  46591. + mmc_hostname(host->mmc), (int)mask);
  46592. + bcm2835_mmc_dumpregs(host);
  46593. + return;
  46594. + }
  46595. + timeout--;
  46596. + mdelay(1);
  46597. + }
  46598. +
  46599. + if (100-timeout > 10 && 100-timeout > host->max_delay) {
  46600. + host->max_delay = 100-timeout;
  46601. + pr_warning("Warning: MMC controller hung for %d ms\n", host->max_delay);
  46602. + }
  46603. +}
  46604. +
  46605. +static void bcm2835_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios);
  46606. +
  46607. +static void bcm2835_mmc_init(struct bcm2835_host *host, int soft)
  46608. +{
  46609. + if (soft)
  46610. + bcm2835_mmc_reset(host, SDHCI_RESET_CMD|SDHCI_RESET_DATA);
  46611. + else
  46612. + bcm2835_mmc_reset(host, SDHCI_RESET_ALL);
  46613. +
  46614. + host->ier = SDHCI_INT_BUS_POWER | SDHCI_INT_DATA_END_BIT |
  46615. + SDHCI_INT_DATA_CRC | SDHCI_INT_DATA_TIMEOUT |
  46616. + SDHCI_INT_INDEX | SDHCI_INT_END_BIT | SDHCI_INT_CRC |
  46617. + SDHCI_INT_TIMEOUT | SDHCI_INT_DATA_END |
  46618. + SDHCI_INT_RESPONSE;
  46619. +
  46620. + bcm2835_mmc_writel(host, host->ier, SDHCI_INT_ENABLE);
  46621. + bcm2835_mmc_writel(host, host->ier, SDHCI_SIGNAL_ENABLE);
  46622. +
  46623. + if (soft) {
  46624. + /* force clock reconfiguration */
  46625. + host->clock = 0;
  46626. + bcm2835_mmc_set_ios(host->mmc, &host->mmc->ios);
  46627. + }
  46628. +}
  46629. +
  46630. +
  46631. +
  46632. +static void bcm2835_mmc_finish_data(struct bcm2835_host *host);
  46633. +
  46634. +static void bcm2835_mmc_dma_complete(void *param)
  46635. +{
  46636. + struct bcm2835_host *host = param;
  46637. + struct dma_chan *dma_chan;
  46638. + unsigned long flags;
  46639. + u32 dir_data;
  46640. +
  46641. + spin_lock_irqsave(&host->lock, flags);
  46642. +
  46643. + if (host->data && !(host->data->flags & MMC_DATA_WRITE)) {
  46644. + /* otherwise handled in SDHCI IRQ */
  46645. + dma_chan = host->dma_chan_rx;
  46646. + dir_data = DMA_FROM_DEVICE;
  46647. +
  46648. + dma_unmap_sg(dma_chan->device->dev,
  46649. + host->data->sg, host->data->sg_len,
  46650. + dir_data);
  46651. +
  46652. + bcm2835_mmc_finish_data(host);
  46653. + }
  46654. +
  46655. + spin_unlock_irqrestore(&host->lock, flags);
  46656. +}
  46657. +
  46658. +static void bcm2835_bcm2835_mmc_read_block_pio(struct bcm2835_host *host)
  46659. +{
  46660. + unsigned long flags;
  46661. + size_t blksize, len, chunk;
  46662. +
  46663. + u32 uninitialized_var(scratch);
  46664. + u8 *buf;
  46665. +
  46666. + blksize = host->data->blksz;
  46667. + chunk = 0;
  46668. +
  46669. + local_irq_save(flags);
  46670. +
  46671. + while (blksize) {
  46672. + if (!sg_miter_next(&host->sg_miter))
  46673. + BUG();
  46674. +
  46675. + len = min(host->sg_miter.length, blksize);
  46676. +
  46677. + blksize -= len;
  46678. + host->sg_miter.consumed = len;
  46679. +
  46680. + buf = host->sg_miter.addr;
  46681. +
  46682. + while (len) {
  46683. + if (chunk == 0) {
  46684. + scratch = bcm2835_mmc_readl(host, SDHCI_BUFFER);
  46685. + chunk = 4;
  46686. + }
  46687. +
  46688. + *buf = scratch & 0xFF;
  46689. +
  46690. + buf++;
  46691. + scratch >>= 8;
  46692. + chunk--;
  46693. + len--;
  46694. + }
  46695. + }
  46696. +
  46697. + sg_miter_stop(&host->sg_miter);
  46698. +
  46699. + local_irq_restore(flags);
  46700. +}
  46701. +
  46702. +static void bcm2835_bcm2835_mmc_write_block_pio(struct bcm2835_host *host)
  46703. +{
  46704. + unsigned long flags;
  46705. + size_t blksize, len, chunk;
  46706. + u32 scratch;
  46707. + u8 *buf;
  46708. +
  46709. + blksize = host->data->blksz;
  46710. + chunk = 0;
  46711. + chunk = 0;
  46712. + scratch = 0;
  46713. +
  46714. + local_irq_save(flags);
  46715. +
  46716. + while (blksize) {
  46717. + if (!sg_miter_next(&host->sg_miter))
  46718. + BUG();
  46719. +
  46720. + len = min(host->sg_miter.length, blksize);
  46721. +
  46722. + blksize -= len;
  46723. + host->sg_miter.consumed = len;
  46724. +
  46725. + buf = host->sg_miter.addr;
  46726. +
  46727. + while (len) {
  46728. + scratch |= (u32)*buf << (chunk * 8);
  46729. +
  46730. + buf++;
  46731. + chunk++;
  46732. + len--;
  46733. +
  46734. + if ((chunk == 4) || ((len == 0) && (blksize == 0))) {
  46735. + mmc_raw_writel(host, scratch, SDHCI_BUFFER);
  46736. + chunk = 0;
  46737. + scratch = 0;
  46738. + }
  46739. + }
  46740. + }
  46741. +
  46742. + sg_miter_stop(&host->sg_miter);
  46743. +
  46744. + local_irq_restore(flags);
  46745. +}
  46746. +
  46747. +
  46748. +static void bcm2835_mmc_transfer_pio(struct bcm2835_host *host)
  46749. +{
  46750. + u32 mask;
  46751. +
  46752. + BUG_ON(!host->data);
  46753. +
  46754. + if (host->blocks == 0)
  46755. + return;
  46756. +
  46757. + if (host->data->flags & MMC_DATA_READ)
  46758. + mask = SDHCI_DATA_AVAILABLE;
  46759. + else
  46760. + mask = SDHCI_SPACE_AVAILABLE;
  46761. +
  46762. + while (bcm2835_mmc_readl(host, SDHCI_PRESENT_STATE) & mask) {
  46763. +
  46764. + if (host->data->flags & MMC_DATA_READ)
  46765. + bcm2835_bcm2835_mmc_read_block_pio(host);
  46766. + else
  46767. + bcm2835_bcm2835_mmc_write_block_pio(host);
  46768. +
  46769. + host->blocks--;
  46770. +
  46771. + /* QUIRK used in sdhci.c removes the 'if' */
  46772. + /* but it seems this is unnecessary */
  46773. + if (host->blocks == 0)
  46774. + break;
  46775. +
  46776. +
  46777. + }
  46778. +}
  46779. +
  46780. +
  46781. +static void bcm2835_mmc_transfer_dma(struct bcm2835_host *host)
  46782. +{
  46783. + u32 len, dir_data, dir_slave;
  46784. + struct dma_async_tx_descriptor *desc = NULL;
  46785. + struct dma_chan *dma_chan;
  46786. +
  46787. +
  46788. + WARN_ON(!host->data);
  46789. +
  46790. + if (!host->data)
  46791. + return;
  46792. +
  46793. + if (host->blocks == 0)
  46794. + return;
  46795. +
  46796. + if (host->data->flags & MMC_DATA_READ) {
  46797. + dma_chan = host->dma_chan_rx;
  46798. + dir_data = DMA_FROM_DEVICE;
  46799. + dir_slave = DMA_DEV_TO_MEM;
  46800. + } else {
  46801. + dma_chan = host->dma_chan_tx;
  46802. + dir_data = DMA_TO_DEVICE;
  46803. + dir_slave = DMA_MEM_TO_DEV;
  46804. + }
  46805. +
  46806. + BUG_ON(!dma_chan->device);
  46807. + BUG_ON(!dma_chan->device->dev);
  46808. + BUG_ON(!host->data->sg);
  46809. +
  46810. + len = dma_map_sg(dma_chan->device->dev, host->data->sg,
  46811. + host->data->sg_len, dir_data);
  46812. + if (len > 0) {
  46813. + desc = dmaengine_prep_slave_sg(dma_chan, host->data->sg,
  46814. + len, dir_slave,
  46815. + DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
  46816. + } else {
  46817. + dev_err(mmc_dev(host->mmc), "dma_map_sg returned zero length\n");
  46818. + }
  46819. + if (desc) {
  46820. + bcm2835_mmc_unsignal_irqs(host, SDHCI_INT_DATA_AVAIL |
  46821. + SDHCI_INT_SPACE_AVAIL);
  46822. + host->tx_desc = desc;
  46823. + desc->callback = bcm2835_mmc_dma_complete;
  46824. + desc->callback_param = host;
  46825. + dmaengine_submit(desc);
  46826. + dma_async_issue_pending(dma_chan);
  46827. + }
  46828. +
  46829. +}
  46830. +
  46831. +
  46832. +
  46833. +static void bcm2835_mmc_set_transfer_irqs(struct bcm2835_host *host)
  46834. +{
  46835. + u32 pio_irqs = SDHCI_INT_DATA_AVAIL | SDHCI_INT_SPACE_AVAIL;
  46836. + u32 dma_irqs = SDHCI_INT_DMA_END | SDHCI_INT_ADMA_ERROR;
  46837. +
  46838. + if (host->use_dma)
  46839. + host->ier = (host->ier & ~pio_irqs) | dma_irqs;
  46840. + else
  46841. + host->ier = (host->ier & ~dma_irqs) | pio_irqs;
  46842. +
  46843. + bcm2835_mmc_writel(host, host->ier, SDHCI_INT_ENABLE);
  46844. + bcm2835_mmc_writel(host, host->ier, SDHCI_SIGNAL_ENABLE);
  46845. +}
  46846. +
  46847. +
  46848. +static void bcm2835_mmc_prepare_data(struct bcm2835_host *host, struct mmc_command *cmd)
  46849. +{
  46850. + u8 count;
  46851. + struct mmc_data *data = cmd->data;
  46852. +
  46853. + WARN_ON(host->data);
  46854. +
  46855. + if (data || (cmd->flags & MMC_RSP_BUSY)) {
  46856. + count = TIMEOUT_VAL;
  46857. + bcm2835_mmc_writeb(host, count, SDHCI_TIMEOUT_CONTROL);
  46858. + }
  46859. +
  46860. + if (!data)
  46861. + return;
  46862. +
  46863. + /* Sanity checks */
  46864. + BUG_ON(data->blksz * data->blocks > 524288);
  46865. + BUG_ON(data->blksz > host->mmc->max_blk_size);
  46866. + BUG_ON(data->blocks > 65535);
  46867. +
  46868. + host->data = data;
  46869. + host->data_early = 0;
  46870. + host->data->bytes_xfered = 0;
  46871. +
  46872. +
  46873. + if (!(host->flags & SDHCI_REQ_USE_DMA)) {
  46874. + int flags;
  46875. +
  46876. + flags = SG_MITER_ATOMIC;
  46877. + if (host->data->flags & MMC_DATA_READ)
  46878. + flags |= SG_MITER_TO_SG;
  46879. + else
  46880. + flags |= SG_MITER_FROM_SG;
  46881. + sg_miter_start(&host->sg_miter, data->sg, data->sg_len, flags);
  46882. + host->blocks = data->blocks;
  46883. + }
  46884. +
  46885. + host->use_dma = host->have_dma && data->blocks > PIO_DMA_BARRIER;
  46886. +
  46887. + bcm2835_mmc_set_transfer_irqs(host);
  46888. +
  46889. + /* Set the DMA boundary value and block size */
  46890. + bcm2835_mmc_writew(host, SDHCI_MAKE_BLKSZ(SDHCI_DEFAULT_BOUNDARY_ARG,
  46891. + data->blksz), SDHCI_BLOCK_SIZE);
  46892. + bcm2835_mmc_writew(host, data->blocks, SDHCI_BLOCK_COUNT);
  46893. +
  46894. + BUG_ON(!host->data);
  46895. +}
  46896. +
  46897. +static void bcm2835_mmc_set_transfer_mode(struct bcm2835_host *host,
  46898. + struct mmc_command *cmd)
  46899. +{
  46900. + u16 mode;
  46901. + struct mmc_data *data = cmd->data;
  46902. +
  46903. + if (data == NULL) {
  46904. + /* clear Auto CMD settings for no data CMDs */
  46905. + mode = bcm2835_mmc_readw(host, SDHCI_TRANSFER_MODE);
  46906. + bcm2835_mmc_writew(host, mode & ~(SDHCI_TRNS_AUTO_CMD12 |
  46907. + SDHCI_TRNS_AUTO_CMD23), SDHCI_TRANSFER_MODE);
  46908. + return;
  46909. + }
  46910. +
  46911. + WARN_ON(!host->data);
  46912. +
  46913. + mode = SDHCI_TRNS_BLK_CNT_EN;
  46914. +
  46915. + if ((mmc_op_multi(cmd->opcode) || data->blocks > 1)) {
  46916. + mode |= SDHCI_TRNS_MULTI;
  46917. +
  46918. + /*
  46919. + * If we are sending CMD23, CMD12 never gets sent
  46920. + * on successful completion (so no Auto-CMD12).
  46921. + */
  46922. + if (!host->mrq->sbc && (host->flags & SDHCI_AUTO_CMD12))
  46923. + mode |= SDHCI_TRNS_AUTO_CMD12;
  46924. + else if (host->mrq->sbc && (host->flags & SDHCI_AUTO_CMD23)) {
  46925. + mode |= SDHCI_TRNS_AUTO_CMD23;
  46926. + bcm2835_mmc_writel(host, host->mrq->sbc->arg, SDHCI_ARGUMENT2);
  46927. + }
  46928. + }
  46929. +
  46930. + if (data->flags & MMC_DATA_READ)
  46931. + mode |= SDHCI_TRNS_READ;
  46932. + if (host->flags & SDHCI_REQ_USE_DMA)
  46933. + mode |= SDHCI_TRNS_DMA;
  46934. +
  46935. + bcm2835_mmc_writew(host, mode, SDHCI_TRANSFER_MODE);
  46936. +}
  46937. +
  46938. +void bcm2835_mmc_send_command(struct bcm2835_host *host, struct mmc_command *cmd)
  46939. +{
  46940. + int flags;
  46941. + u32 mask;
  46942. + unsigned long timeout;
  46943. +
  46944. + WARN_ON(host->cmd);
  46945. +
  46946. + /* Wait max 10 ms */
  46947. + timeout = 1000;
  46948. +
  46949. + mask = SDHCI_CMD_INHIBIT;
  46950. + if ((cmd->data != NULL) || (cmd->flags & MMC_RSP_BUSY))
  46951. + mask |= SDHCI_DATA_INHIBIT;
  46952. +
  46953. + /* We shouldn't wait for data inihibit for stop commands, even
  46954. + though they might use busy signaling */
  46955. + if (host->mrq->data && (cmd == host->mrq->data->stop))
  46956. + mask &= ~SDHCI_DATA_INHIBIT;
  46957. +
  46958. + while (bcm2835_mmc_readl(host, SDHCI_PRESENT_STATE) & mask) {
  46959. + if (timeout == 0) {
  46960. + pr_err("%s: Controller never released inhibit bit(s).\n",
  46961. + mmc_hostname(host->mmc));
  46962. + bcm2835_mmc_dumpregs(host);
  46963. + cmd->error = -EIO;
  46964. + tasklet_schedule(&host->finish_tasklet);
  46965. + return;
  46966. + }
  46967. + timeout--;
  46968. + udelay(10);
  46969. + }
  46970. +
  46971. + if ((1000-timeout)/100 > 1 && (1000-timeout)/100 > host->max_delay) {
  46972. + host->max_delay = (1000-timeout)/100;
  46973. + pr_warning("Warning: MMC controller hung for %d ms\n", host->max_delay);
  46974. + }
  46975. +
  46976. + timeout = jiffies;
  46977. +#ifdef CONFIG_ARCH_BCM2835
  46978. + if (!cmd->data && cmd->busy_timeout > 9000)
  46979. + timeout += DIV_ROUND_UP(cmd->busy_timeout, 1000) * HZ + HZ;
  46980. + else
  46981. +#endif
  46982. + timeout += 10 * HZ;
  46983. + mod_timer(&host->timer, timeout);
  46984. +
  46985. + host->cmd = cmd;
  46986. +
  46987. + bcm2835_mmc_prepare_data(host, cmd);
  46988. +
  46989. + bcm2835_mmc_writel(host, cmd->arg, SDHCI_ARGUMENT);
  46990. +
  46991. + bcm2835_mmc_set_transfer_mode(host, cmd);
  46992. +
  46993. + if ((cmd->flags & MMC_RSP_136) && (cmd->flags & MMC_RSP_BUSY)) {
  46994. + pr_err("%s: Unsupported response type!\n",
  46995. + mmc_hostname(host->mmc));
  46996. + cmd->error = -EINVAL;
  46997. + tasklet_schedule(&host->finish_tasklet);
  46998. + return;
  46999. + }
  47000. +
  47001. + if (!(cmd->flags & MMC_RSP_PRESENT))
  47002. + flags = SDHCI_CMD_RESP_NONE;
  47003. + else if (cmd->flags & MMC_RSP_136)
  47004. + flags = SDHCI_CMD_RESP_LONG;
  47005. + else if (cmd->flags & MMC_RSP_BUSY)
  47006. + flags = SDHCI_CMD_RESP_SHORT_BUSY;
  47007. + else
  47008. + flags = SDHCI_CMD_RESP_SHORT;
  47009. +
  47010. + if (cmd->flags & MMC_RSP_CRC)
  47011. + flags |= SDHCI_CMD_CRC;
  47012. + if (cmd->flags & MMC_RSP_OPCODE)
  47013. + flags |= SDHCI_CMD_INDEX;
  47014. +
  47015. + if (cmd->data)
  47016. + flags |= SDHCI_CMD_DATA;
  47017. +
  47018. + bcm2835_mmc_writew(host, SDHCI_MAKE_CMD(cmd->opcode, flags), SDHCI_COMMAND);
  47019. +}
  47020. +
  47021. +
  47022. +static void bcm2835_mmc_finish_data(struct bcm2835_host *host)
  47023. +{
  47024. + struct mmc_data *data;
  47025. +
  47026. + BUG_ON(!host->data);
  47027. +
  47028. + data = host->data;
  47029. + host->data = NULL;
  47030. +
  47031. + if (data->error)
  47032. + data->bytes_xfered = 0;
  47033. + else
  47034. + data->bytes_xfered = data->blksz * data->blocks;
  47035. +
  47036. + /*
  47037. + * Need to send CMD12 if -
  47038. + * a) open-ended multiblock transfer (no CMD23)
  47039. + * b) error in multiblock transfer
  47040. + */
  47041. + if (data->stop &&
  47042. + (data->error ||
  47043. + !host->mrq->sbc)) {
  47044. +
  47045. + /*
  47046. + * The controller needs a reset of internal state machines
  47047. + * upon error conditions.
  47048. + */
  47049. + if (data->error) {
  47050. + bcm2835_mmc_reset(host, SDHCI_RESET_CMD);
  47051. + bcm2835_mmc_reset(host, SDHCI_RESET_DATA);
  47052. + }
  47053. +
  47054. + bcm2835_mmc_send_command(host, data->stop);
  47055. + } else
  47056. + tasklet_schedule(&host->finish_tasklet);
  47057. +}
  47058. +
  47059. +static void bcm2835_mmc_finish_command(struct bcm2835_host *host)
  47060. +{
  47061. + int i;
  47062. +
  47063. + BUG_ON(host->cmd == NULL);
  47064. +
  47065. + if (host->cmd->flags & MMC_RSP_PRESENT) {
  47066. + if (host->cmd->flags & MMC_RSP_136) {
  47067. + /* CRC is stripped so we need to do some shifting. */
  47068. + for (i = 0; i < 4; i++) {
  47069. + host->cmd->resp[i] = bcm2835_mmc_readl(host,
  47070. + SDHCI_RESPONSE + (3-i)*4) << 8;
  47071. + if (i != 3)
  47072. + host->cmd->resp[i] |=
  47073. + bcm2835_mmc_readb(host,
  47074. + SDHCI_RESPONSE + (3-i)*4-1);
  47075. + }
  47076. + } else {
  47077. + host->cmd->resp[0] = bcm2835_mmc_readl(host, SDHCI_RESPONSE);
  47078. + }
  47079. + }
  47080. +
  47081. + host->cmd->error = 0;
  47082. +
  47083. + /* Finished CMD23, now send actual command. */
  47084. + if (host->cmd == host->mrq->sbc) {
  47085. + host->cmd = NULL;
  47086. + bcm2835_mmc_send_command(host, host->mrq->cmd);
  47087. +
  47088. + if (host->mrq->cmd->data && host->use_dma) {
  47089. + /* DMA transfer starts now, PIO starts after interrupt */
  47090. + bcm2835_mmc_transfer_dma(host);
  47091. + }
  47092. + } else {
  47093. +
  47094. + /* Processed actual command. */
  47095. + if (host->data && host->data_early)
  47096. + bcm2835_mmc_finish_data(host);
  47097. +
  47098. + if (!host->cmd->data)
  47099. + tasklet_schedule(&host->finish_tasklet);
  47100. +
  47101. + host->cmd = NULL;
  47102. + }
  47103. +}
  47104. +
  47105. +
  47106. +static void bcm2835_mmc_timeout_timer(unsigned long data)
  47107. +{
  47108. + struct bcm2835_host *host;
  47109. + unsigned long flags;
  47110. +
  47111. + host = (struct bcm2835_host *)data;
  47112. +
  47113. + spin_lock_irqsave(&host->lock, flags);
  47114. +
  47115. + if (host->mrq) {
  47116. + pr_err("%s: Timeout waiting for hardware interrupt.\n",
  47117. + mmc_hostname(host->mmc));
  47118. + bcm2835_mmc_dumpregs(host);
  47119. +
  47120. + if (host->data) {
  47121. + host->data->error = -ETIMEDOUT;
  47122. + bcm2835_mmc_finish_data(host);
  47123. + } else {
  47124. + if (host->cmd)
  47125. + host->cmd->error = -ETIMEDOUT;
  47126. + else
  47127. + host->mrq->cmd->error = -ETIMEDOUT;
  47128. +
  47129. + tasklet_schedule(&host->finish_tasklet);
  47130. + }
  47131. + }
  47132. +
  47133. + mmiowb();
  47134. + spin_unlock_irqrestore(&host->lock, flags);
  47135. +}
  47136. +
  47137. +
  47138. +static void bcm2835_mmc_enable_sdio_irq_nolock(struct bcm2835_host *host, int enable)
  47139. +{
  47140. + if (!(host->flags & SDHCI_DEVICE_DEAD)) {
  47141. + if (enable)
  47142. + host->ier |= SDHCI_INT_CARD_INT;
  47143. + else
  47144. + host->ier &= ~SDHCI_INT_CARD_INT;
  47145. +
  47146. + bcm2835_mmc_writel(host, host->ier, SDHCI_INT_ENABLE);
  47147. + bcm2835_mmc_writel(host, host->ier, SDHCI_SIGNAL_ENABLE);
  47148. + mmiowb();
  47149. + }
  47150. +}
  47151. +
  47152. +static void bcm2835_mmc_enable_sdio_irq(struct mmc_host *mmc, int enable)
  47153. +{
  47154. + struct bcm2835_host *host = mmc_priv(mmc);
  47155. + unsigned long flags;
  47156. +
  47157. + spin_lock_irqsave(&host->lock, flags);
  47158. + if (enable)
  47159. + host->flags |= SDHCI_SDIO_IRQ_ENABLED;
  47160. + else
  47161. + host->flags &= ~SDHCI_SDIO_IRQ_ENABLED;
  47162. +
  47163. + bcm2835_mmc_enable_sdio_irq_nolock(host, enable);
  47164. + spin_unlock_irqrestore(&host->lock, flags);
  47165. +}
  47166. +
  47167. +static void bcm2835_mmc_cmd_irq(struct bcm2835_host *host, u32 intmask)
  47168. +{
  47169. +
  47170. + BUG_ON(intmask == 0);
  47171. +
  47172. + if (!host->cmd) {
  47173. + pr_err("%s: Got command interrupt 0x%08x even "
  47174. + "though no command operation was in progress.\n",
  47175. + mmc_hostname(host->mmc), (unsigned)intmask);
  47176. + bcm2835_mmc_dumpregs(host);
  47177. + return;
  47178. + }
  47179. +
  47180. + if (intmask & SDHCI_INT_TIMEOUT)
  47181. + host->cmd->error = -ETIMEDOUT;
  47182. + else if (intmask & (SDHCI_INT_CRC | SDHCI_INT_END_BIT |
  47183. + SDHCI_INT_INDEX)) {
  47184. + host->cmd->error = -EILSEQ;
  47185. + }
  47186. +
  47187. + if (host->cmd->error) {
  47188. + tasklet_schedule(&host->finish_tasklet);
  47189. + return;
  47190. + }
  47191. +
  47192. + if (intmask & SDHCI_INT_RESPONSE)
  47193. + bcm2835_mmc_finish_command(host);
  47194. +
  47195. +}
  47196. +
  47197. +static void bcm2835_mmc_data_irq(struct bcm2835_host *host, u32 intmask)
  47198. +{
  47199. + struct dma_chan *dma_chan;
  47200. + u32 dir_data;
  47201. +
  47202. + BUG_ON(intmask == 0);
  47203. +
  47204. + if (!host->data) {
  47205. + /*
  47206. + * The "data complete" interrupt is also used to
  47207. + * indicate that a busy state has ended. See comment
  47208. + * above in sdhci_cmd_irq().
  47209. + */
  47210. + if (host->cmd && (host->cmd->flags & MMC_RSP_BUSY)) {
  47211. + if (intmask & SDHCI_INT_DATA_END) {
  47212. + bcm2835_mmc_finish_command(host);
  47213. + return;
  47214. + }
  47215. + }
  47216. +
  47217. + pr_debug("%s: Got data interrupt 0x%08x even "
  47218. + "though no data operation was in progress.\n",
  47219. + mmc_hostname(host->mmc), (unsigned)intmask);
  47220. + bcm2835_mmc_dumpregs(host);
  47221. +
  47222. + return;
  47223. + }
  47224. +
  47225. + if (intmask & SDHCI_INT_DATA_TIMEOUT)
  47226. + host->data->error = -ETIMEDOUT;
  47227. + else if (intmask & SDHCI_INT_DATA_END_BIT)
  47228. + host->data->error = -EILSEQ;
  47229. + else if ((intmask & SDHCI_INT_DATA_CRC) &&
  47230. + SDHCI_GET_CMD(bcm2835_mmc_readw(host, SDHCI_COMMAND))
  47231. + != MMC_BUS_TEST_R)
  47232. + host->data->error = -EILSEQ;
  47233. +
  47234. + if (host->use_dma) {
  47235. + if (host->data->flags & MMC_DATA_WRITE) {
  47236. + /* IRQ handled here */
  47237. +
  47238. + dma_chan = host->dma_chan_tx;
  47239. + dir_data = DMA_TO_DEVICE;
  47240. + dma_unmap_sg(dma_chan->device->dev,
  47241. + host->data->sg, host->data->sg_len,
  47242. + dir_data);
  47243. +
  47244. + bcm2835_mmc_finish_data(host);
  47245. + }
  47246. +
  47247. + } else {
  47248. + if (host->data->error)
  47249. + bcm2835_mmc_finish_data(host);
  47250. + else {
  47251. + if (intmask & (SDHCI_INT_DATA_AVAIL | SDHCI_INT_SPACE_AVAIL))
  47252. + bcm2835_mmc_transfer_pio(host);
  47253. +
  47254. + if (intmask & SDHCI_INT_DATA_END) {
  47255. + if (host->cmd) {
  47256. + /*
  47257. + * Data managed to finish before the
  47258. + * command completed. Make sure we do
  47259. + * things in the proper order.
  47260. + */
  47261. + host->data_early = 1;
  47262. + } else {
  47263. + bcm2835_mmc_finish_data(host);
  47264. + }
  47265. + }
  47266. + }
  47267. + }
  47268. +}
  47269. +
  47270. +
  47271. +static irqreturn_t bcm2835_mmc_irq(int irq, void *dev_id)
  47272. +{
  47273. + irqreturn_t result = IRQ_NONE;
  47274. + struct bcm2835_host *host = dev_id;
  47275. + u32 intmask, mask, unexpected = 0;
  47276. + int max_loops = 16;
  47277. +#ifndef CONFIG_ARCH_BCM2835
  47278. + int cardint = 0;
  47279. +#endif
  47280. +
  47281. + spin_lock(&host->lock);
  47282. +
  47283. + intmask = bcm2835_mmc_readl(host, SDHCI_INT_STATUS);
  47284. +
  47285. + if (!intmask || intmask == 0xffffffff) {
  47286. + result = IRQ_NONE;
  47287. + goto out;
  47288. + }
  47289. +
  47290. + do {
  47291. + /* Clear selected interrupts. */
  47292. + mask = intmask & (SDHCI_INT_CMD_MASK | SDHCI_INT_DATA_MASK |
  47293. + SDHCI_INT_BUS_POWER);
  47294. + bcm2835_mmc_writel(host, mask, SDHCI_INT_STATUS);
  47295. +
  47296. +
  47297. + if (intmask & SDHCI_INT_CMD_MASK)
  47298. + bcm2835_mmc_cmd_irq(host, intmask & SDHCI_INT_CMD_MASK);
  47299. +
  47300. + if (intmask & SDHCI_INT_DATA_MASK)
  47301. + bcm2835_mmc_data_irq(host, intmask & SDHCI_INT_DATA_MASK);
  47302. +
  47303. + if (intmask & SDHCI_INT_BUS_POWER)
  47304. + pr_err("%s: Card is consuming too much power!\n",
  47305. + mmc_hostname(host->mmc));
  47306. +
  47307. + if (intmask & SDHCI_INT_CARD_INT) {
  47308. +#ifndef CONFIG_ARCH_BCM2835
  47309. + cardint = 1;
  47310. +#else
  47311. + bcm2835_mmc_enable_sdio_irq_nolock(host, false);
  47312. + host->thread_isr |= SDHCI_INT_CARD_INT;
  47313. + result = IRQ_WAKE_THREAD;
  47314. +#endif
  47315. + }
  47316. +
  47317. + intmask &= ~(SDHCI_INT_CARD_INSERT | SDHCI_INT_CARD_REMOVE |
  47318. + SDHCI_INT_CMD_MASK | SDHCI_INT_DATA_MASK |
  47319. + SDHCI_INT_ERROR | SDHCI_INT_BUS_POWER |
  47320. + SDHCI_INT_CARD_INT);
  47321. +
  47322. + if (intmask) {
  47323. + unexpected |= intmask;
  47324. + bcm2835_mmc_writel(host, intmask, SDHCI_INT_STATUS);
  47325. + }
  47326. +
  47327. + if (result == IRQ_NONE)
  47328. + result = IRQ_HANDLED;
  47329. +
  47330. + intmask = bcm2835_mmc_readl(host, SDHCI_INT_STATUS);
  47331. + } while (intmask && --max_loops);
  47332. +out:
  47333. + spin_unlock(&host->lock);
  47334. +
  47335. + if (unexpected) {
  47336. + pr_err("%s: Unexpected interrupt 0x%08x.\n",
  47337. + mmc_hostname(host->mmc), unexpected);
  47338. + bcm2835_mmc_dumpregs(host);
  47339. + }
  47340. +
  47341. +#ifndef CONFIG_ARCH_BCM2835
  47342. + if (cardint)
  47343. + mmc_signal_sdio_irq(host->mmc);
  47344. +#endif
  47345. +
  47346. + return result;
  47347. +}
  47348. +
  47349. +#ifdef CONFIG_ARCH_BCM2835
  47350. +static irqreturn_t bcm2835_mmc_thread_irq(int irq, void *dev_id)
  47351. +{
  47352. + struct bcm2835_host *host = dev_id;
  47353. + unsigned long flags;
  47354. + u32 isr;
  47355. +
  47356. + spin_lock_irqsave(&host->lock, flags);
  47357. + isr = host->thread_isr;
  47358. + host->thread_isr = 0;
  47359. + spin_unlock_irqrestore(&host->lock, flags);
  47360. +
  47361. + if (isr & SDHCI_INT_CARD_INT) {
  47362. + sdio_run_irqs(host->mmc);
  47363. +
  47364. + spin_lock_irqsave(&host->lock, flags);
  47365. + if (host->flags & SDHCI_SDIO_IRQ_ENABLED)
  47366. + bcm2835_mmc_enable_sdio_irq_nolock(host, true);
  47367. + spin_unlock_irqrestore(&host->lock, flags);
  47368. + }
  47369. +
  47370. + return isr ? IRQ_HANDLED : IRQ_NONE;
  47371. +}
  47372. +#endif
  47373. +
  47374. +
  47375. +
  47376. +void bcm2835_mmc_set_clock(struct bcm2835_host *host, unsigned int clock)
  47377. +{
  47378. + int div = 0; /* Initialized for compiler warning */
  47379. + int real_div = div, clk_mul = 1;
  47380. + u16 clk = 0;
  47381. + unsigned long timeout;
  47382. +
  47383. +
  47384. + host->mmc->actual_clock = 0;
  47385. +
  47386. + bcm2835_mmc_writew(host, 0, SDHCI_CLOCK_CONTROL);
  47387. +
  47388. + if (clock == 0)
  47389. + return;
  47390. +
  47391. + /* Version 3.00 divisors must be a multiple of 2. */
  47392. + if (host->max_clk <= clock)
  47393. + div = 1;
  47394. + else {
  47395. + for (div = 2; div < SDHCI_MAX_DIV_SPEC_300;
  47396. + div += 2) {
  47397. + if ((host->max_clk / div) <= clock)
  47398. + break;
  47399. + }
  47400. + }
  47401. +
  47402. + real_div = div;
  47403. + div >>= 1;
  47404. +
  47405. + if (real_div)
  47406. + host->mmc->actual_clock = (host->max_clk * clk_mul) / real_div;
  47407. +
  47408. + clk |= (div & SDHCI_DIV_MASK) << SDHCI_DIVIDER_SHIFT;
  47409. + clk |= ((div & SDHCI_DIV_HI_MASK) >> SDHCI_DIV_MASK_LEN)
  47410. + << SDHCI_DIVIDER_HI_SHIFT;
  47411. + clk |= SDHCI_CLOCK_INT_EN;
  47412. + bcm2835_mmc_writew(host, clk, SDHCI_CLOCK_CONTROL);
  47413. +
  47414. + /* Wait max 20 ms */
  47415. + timeout = 20;
  47416. + while (!((clk = bcm2835_mmc_readw(host, SDHCI_CLOCK_CONTROL))
  47417. + & SDHCI_CLOCK_INT_STABLE)) {
  47418. + if (timeout == 0) {
  47419. + pr_err("%s: Internal clock never "
  47420. + "stabilised.\n", mmc_hostname(host->mmc));
  47421. + bcm2835_mmc_dumpregs(host);
  47422. + return;
  47423. + }
  47424. + timeout--;
  47425. + mdelay(1);
  47426. + }
  47427. +
  47428. + if (20-timeout > 10 && 20-timeout > host->max_delay) {
  47429. + host->max_delay = 20-timeout;
  47430. + pr_warning("Warning: MMC controller hung for %d ms\n", host->max_delay);
  47431. + }
  47432. +
  47433. + clk |= SDHCI_CLOCK_CARD_EN;
  47434. + bcm2835_mmc_writew(host, clk, SDHCI_CLOCK_CONTROL);
  47435. +}
  47436. +
  47437. +static void bcm2835_mmc_request(struct mmc_host *mmc, struct mmc_request *mrq)
  47438. +{
  47439. + struct bcm2835_host *host;
  47440. + unsigned long flags;
  47441. +
  47442. + host = mmc_priv(mmc);
  47443. +
  47444. + spin_lock_irqsave(&host->lock, flags);
  47445. +
  47446. + WARN_ON(host->mrq != NULL);
  47447. +
  47448. + host->mrq = mrq;
  47449. +
  47450. + if (mrq->sbc && !(host->flags & SDHCI_AUTO_CMD23))
  47451. + bcm2835_mmc_send_command(host, mrq->sbc);
  47452. + else
  47453. + bcm2835_mmc_send_command(host, mrq->cmd);
  47454. +
  47455. + mmiowb();
  47456. + spin_unlock_irqrestore(&host->lock, flags);
  47457. +
  47458. + if (!(mrq->sbc && !(host->flags & SDHCI_AUTO_CMD23)) && mrq->cmd->data && host->use_dma) {
  47459. + /* DMA transfer starts now, PIO starts after interrupt */
  47460. + bcm2835_mmc_transfer_dma(host);
  47461. + }
  47462. +}
  47463. +
  47464. +
  47465. +static void bcm2835_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
  47466. +{
  47467. +
  47468. + struct bcm2835_host *host = mmc_priv(mmc);
  47469. + unsigned long flags;
  47470. + u8 ctrl;
  47471. + u16 clk, ctrl_2;
  47472. +
  47473. +
  47474. + spin_lock_irqsave(&host->lock, flags);
  47475. +
  47476. + if (!ios->clock || ios->clock != host->clock) {
  47477. + bcm2835_mmc_set_clock(host, ios->clock);
  47478. + host->clock = ios->clock;
  47479. + }
  47480. +
  47481. + if (host->pwr != SDHCI_POWER_330) {
  47482. + host->pwr = SDHCI_POWER_330;
  47483. + bcm2835_mmc_writeb(host, SDHCI_POWER_330 | SDHCI_POWER_ON, SDHCI_POWER_CONTROL);
  47484. + }
  47485. +
  47486. + ctrl = bcm2835_mmc_readb(host, SDHCI_HOST_CONTROL);
  47487. +
  47488. + /* set bus width */
  47489. + ctrl &= ~SDHCI_CTRL_8BITBUS;
  47490. + if (ios->bus_width == MMC_BUS_WIDTH_4)
  47491. + ctrl |= SDHCI_CTRL_4BITBUS;
  47492. + else
  47493. + ctrl &= ~SDHCI_CTRL_4BITBUS;
  47494. +
  47495. + ctrl &= ~SDHCI_CTRL_HISPD; /* NO_HISPD_BIT */
  47496. +
  47497. +
  47498. + bcm2835_mmc_writeb(host, ctrl, SDHCI_HOST_CONTROL);
  47499. + /*
  47500. + * We only need to set Driver Strength if the
  47501. + * preset value enable is not set.
  47502. + */
  47503. + ctrl_2 = bcm2835_mmc_readw(host, SDHCI_HOST_CONTROL2);
  47504. + ctrl_2 &= ~SDHCI_CTRL_DRV_TYPE_MASK;
  47505. + if (ios->drv_type == MMC_SET_DRIVER_TYPE_A)
  47506. + ctrl_2 |= SDHCI_CTRL_DRV_TYPE_A;
  47507. + else if (ios->drv_type == MMC_SET_DRIVER_TYPE_C)
  47508. + ctrl_2 |= SDHCI_CTRL_DRV_TYPE_C;
  47509. +
  47510. + bcm2835_mmc_writew(host, ctrl_2, SDHCI_HOST_CONTROL2);
  47511. +
  47512. + /* Reset SD Clock Enable */
  47513. + clk = bcm2835_mmc_readw(host, SDHCI_CLOCK_CONTROL);
  47514. + clk &= ~SDHCI_CLOCK_CARD_EN;
  47515. + bcm2835_mmc_writew(host, clk, SDHCI_CLOCK_CONTROL);
  47516. +
  47517. + /* Re-enable SD Clock */
  47518. + bcm2835_mmc_set_clock(host, host->clock);
  47519. + bcm2835_mmc_writeb(host, ctrl, SDHCI_HOST_CONTROL);
  47520. +
  47521. + mmiowb();
  47522. +
  47523. + spin_unlock_irqrestore(&host->lock, flags);
  47524. +}
  47525. +
  47526. +
  47527. +static struct mmc_host_ops bcm2835_ops = {
  47528. + .request = bcm2835_mmc_request,
  47529. + .set_ios = bcm2835_mmc_set_ios,
  47530. + .enable_sdio_irq = bcm2835_mmc_enable_sdio_irq,
  47531. +};
  47532. +
  47533. +
  47534. +static void bcm2835_mmc_tasklet_finish(unsigned long param)
  47535. +{
  47536. + struct bcm2835_host *host;
  47537. + unsigned long flags;
  47538. + struct mmc_request *mrq;
  47539. +
  47540. + host = (struct bcm2835_host *)param;
  47541. +
  47542. + spin_lock_irqsave(&host->lock, flags);
  47543. +
  47544. + /*
  47545. + * If this tasklet gets rescheduled while running, it will
  47546. + * be run again afterwards but without any active request.
  47547. + */
  47548. + if (!host->mrq) {
  47549. + spin_unlock_irqrestore(&host->lock, flags);
  47550. + return;
  47551. + }
  47552. +
  47553. + del_timer(&host->timer);
  47554. +
  47555. + mrq = host->mrq;
  47556. +
  47557. + /*
  47558. + * The controller needs a reset of internal state machines
  47559. + * upon error conditions.
  47560. + */
  47561. + if (!(host->flags & SDHCI_DEVICE_DEAD) &&
  47562. + ((mrq->cmd && mrq->cmd->error) ||
  47563. + (mrq->data && (mrq->data->error ||
  47564. + (mrq->data->stop && mrq->data->stop->error))))) {
  47565. +
  47566. + bcm2835_mmc_reset(host, SDHCI_RESET_CMD);
  47567. + bcm2835_mmc_reset(host, SDHCI_RESET_DATA);
  47568. + }
  47569. +
  47570. + host->mrq = NULL;
  47571. + host->cmd = NULL;
  47572. + host->data = NULL;
  47573. +
  47574. + mmiowb();
  47575. +
  47576. + spin_unlock_irqrestore(&host->lock, flags);
  47577. + mmc_request_done(host->mmc, mrq);
  47578. +}
  47579. +
  47580. +
  47581. +
  47582. +int bcm2835_mmc_add_host(struct bcm2835_host *host)
  47583. +{
  47584. + struct mmc_host *mmc;
  47585. +#ifndef FORCE_PIO
  47586. + struct dma_slave_config cfg;
  47587. +#endif
  47588. + int ret;
  47589. +
  47590. + mmc = host->mmc;
  47591. +
  47592. + bcm2835_mmc_reset(host, SDHCI_RESET_ALL);
  47593. +
  47594. + host->clk_mul = 0;
  47595. +
  47596. + mmc->ops = &bcm2835_ops;
  47597. + mmc->f_max = host->max_clk;
  47598. + mmc->f_max = host->max_clk;
  47599. + mmc->f_min = host->max_clk / SDHCI_MAX_DIV_SPEC_300;
  47600. +
  47601. + /* SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK */
  47602. + host->timeout_clk = mmc->f_max / 1000;
  47603. +#ifdef CONFIG_ARCH_BCM2835
  47604. + mmc->max_busy_timeout = (1 << 27) / host->timeout_clk;
  47605. +#endif
  47606. + /* host controller capabilities */
  47607. + mmc->caps = MMC_CAP_CMD23 | MMC_CAP_ERASE | MMC_CAP_NEEDS_POLL | MMC_CAP_SDIO_IRQ |
  47608. + MMC_CAP_SD_HIGHSPEED | MMC_CAP_MMC_HIGHSPEED | MMC_CAP_4_BIT_DATA;
  47609. +
  47610. + host->flags = SDHCI_AUTO_CMD23;
  47611. +
  47612. + spin_lock_init(&host->lock);
  47613. +
  47614. +
  47615. +#ifdef FORCE_PIO
  47616. + pr_info("Forcing PIO mode\n");
  47617. + host->have_dma = false;
  47618. +#else
  47619. + if (!host->dma_chan_tx || !host->dma_chan_rx ||
  47620. + IS_ERR(host->dma_chan_tx) || IS_ERR(host->dma_chan_rx)) {
  47621. + pr_err("%s: Unable to initialise DMA channels. Falling back to PIO\n", DRIVER_NAME);
  47622. + host->have_dma = false;
  47623. + } else {
  47624. + pr_info("DMA channels allocated for the MMC driver");
  47625. + host->have_dma = true;
  47626. +
  47627. + cfg.src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
  47628. + cfg.dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
  47629. + cfg.slave_id = 11; /* DREQ channel */
  47630. +
  47631. + cfg.direction = DMA_MEM_TO_DEV;
  47632. + cfg.src_addr = 0;
  47633. + cfg.dst_addr = host->phys_addr + SDHCI_BUFFER;
  47634. + ret = dmaengine_slave_config(host->dma_chan_tx, &cfg);
  47635. +
  47636. + cfg.direction = DMA_DEV_TO_MEM;
  47637. + cfg.src_addr = host->phys_addr + SDHCI_BUFFER;
  47638. + cfg.dst_addr = 0;
  47639. + ret = dmaengine_slave_config(host->dma_chan_rx, &cfg);
  47640. + }
  47641. +#endif
  47642. +
  47643. +
  47644. + mmc->max_segs = 128;
  47645. + mmc->max_req_size = 524288;
  47646. + mmc->max_seg_size = mmc->max_req_size;
  47647. + mmc->max_blk_size = 512;
  47648. + mmc->max_blk_count = 65535;
  47649. +
  47650. + /* report supported voltage ranges */
  47651. + mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34;
  47652. +
  47653. + tasklet_init(&host->finish_tasklet,
  47654. + bcm2835_mmc_tasklet_finish, (unsigned long)host);
  47655. +
  47656. + setup_timer(&host->timer, bcm2835_mmc_timeout_timer, (unsigned long)host);
  47657. + init_waitqueue_head(&host->buf_ready_int);
  47658. +
  47659. + bcm2835_mmc_init(host, 0);
  47660. +#ifndef CONFIG_ARCH_BCM2835
  47661. + ret = request_irq(host->irq, bcm2835_mmc_irq, 0 /*IRQF_SHARED*/,
  47662. + mmc_hostname(mmc), host);
  47663. +#else
  47664. + ret = request_threaded_irq(host->irq, bcm2835_mmc_irq, bcm2835_mmc_thread_irq,
  47665. + IRQF_SHARED, mmc_hostname(mmc), host);
  47666. +#endif
  47667. + if (ret) {
  47668. + pr_err("%s: Failed to request IRQ %d: %d\n",
  47669. + mmc_hostname(mmc), host->irq, ret);
  47670. + goto untasklet;
  47671. + }
  47672. +
  47673. + mmiowb();
  47674. + mmc_add_host(mmc);
  47675. +
  47676. + pr_info("Load BCM2835 MMC driver\n");
  47677. +
  47678. + return 0;
  47679. +
  47680. +untasklet:
  47681. + tasklet_kill(&host->finish_tasklet);
  47682. +
  47683. + return ret;
  47684. +}
  47685. +
  47686. +static int bcm2835_mmc_probe(struct platform_device *pdev)
  47687. +{
  47688. + struct device *dev = &pdev->dev;
  47689. +#ifdef CONFIG_ARCH_BCM2835
  47690. + struct device_node *node = dev->of_node;
  47691. + struct clk *clk;
  47692. +#endif
  47693. + struct resource *iomem;
  47694. + struct bcm2835_host *host = NULL;
  47695. +
  47696. + int ret;
  47697. + struct mmc_host *mmc;
  47698. +#if !defined(CONFIG_ARCH_BCM2835) && !defined(FORCE_PIO)
  47699. + dma_cap_mask_t mask;
  47700. +#endif
  47701. +
  47702. + iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  47703. + if (!iomem) {
  47704. + ret = -ENOMEM;
  47705. + goto err;
  47706. + }
  47707. +
  47708. + if (resource_size(iomem) < 0x100)
  47709. + dev_err(&pdev->dev, "Invalid iomem size!\n");
  47710. +
  47711. + mmc = mmc_alloc_host(sizeof(struct bcm2835_host), dev);
  47712. + host = mmc_priv(mmc);
  47713. + host->mmc = mmc;
  47714. +
  47715. +
  47716. + if (IS_ERR(host)) {
  47717. + ret = PTR_ERR(host);
  47718. + goto err;
  47719. + }
  47720. +
  47721. + host->phys_addr = iomem->start + BCM2835_VCMMU_SHIFT;
  47722. +
  47723. +#ifndef CONFIG_ARCH_BCM2835
  47724. +#ifndef FORCE_PIO
  47725. + dma_cap_zero(mask);
  47726. + /* we don't care about the channel, any would work */
  47727. + dma_cap_set(DMA_SLAVE, mask);
  47728. +
  47729. + host->dma_chan_tx = dma_request_channel(mask, NULL, NULL);
  47730. + host->dma_chan_rx = dma_request_channel(mask, NULL, NULL);
  47731. +#endif
  47732. + host->max_clk = BCM2835_CLOCK_FREQ;
  47733. +
  47734. +#else
  47735. +#ifndef FORCE_PIO
  47736. + host->dma_chan_tx = of_dma_request_slave_channel(node, "tx");
  47737. + host->dma_chan_rx = of_dma_request_slave_channel(node, "rx");
  47738. +#endif
  47739. + clk = of_clk_get(node, 0);
  47740. + if (IS_ERR(clk)) {
  47741. + dev_err(dev, "get CLOCK failed\n");
  47742. + ret = PTR_ERR(clk);
  47743. + goto out;
  47744. + }
  47745. + host->max_clk = (clk_get_rate(clk));
  47746. +#endif
  47747. + host->irq = platform_get_irq(pdev, 0);
  47748. +
  47749. + if (!request_mem_region(iomem->start, resource_size(iomem),
  47750. + mmc_hostname(host->mmc))) {
  47751. + dev_err(&pdev->dev, "cannot request region\n");
  47752. + ret = -EBUSY;
  47753. + goto err_request;
  47754. + }
  47755. +
  47756. + host->ioaddr = ioremap(iomem->start, resource_size(iomem));
  47757. + if (!host->ioaddr) {
  47758. + dev_err(&pdev->dev, "failed to remap registers\n");
  47759. + ret = -ENOMEM;
  47760. + goto err_remap;
  47761. + }
  47762. +
  47763. + platform_set_drvdata(pdev, host);
  47764. +
  47765. +
  47766. + if (host->irq <= 0) {
  47767. + dev_err(dev, "get IRQ failed\n");
  47768. + ret = -EINVAL;
  47769. + goto out;
  47770. + }
  47771. +
  47772. +
  47773. +#ifndef CONFIG_ARCH_BCM2835
  47774. + mmc->caps |= MMC_CAP_4_BIT_DATA;
  47775. +#else
  47776. + mmc_of_parse(mmc);
  47777. +#endif
  47778. + host->timeout = msecs_to_jiffies(1000);
  47779. + spin_lock_init(&host->lock);
  47780. + mmc->ops = &bcm2835_ops;
  47781. + return bcm2835_mmc_add_host(host);
  47782. +
  47783. +
  47784. +err_remap:
  47785. + release_mem_region(iomem->start, resource_size(iomem));
  47786. +err_request:
  47787. + mmc_free_host(host->mmc);
  47788. +err:
  47789. + dev_err(&pdev->dev, "%s failed %d\n", __func__, ret);
  47790. + return ret;
  47791. +out:
  47792. + if (mmc)
  47793. + mmc_free_host(mmc);
  47794. + return ret;
  47795. +}
  47796. +
  47797. +static int bcm2835_mmc_remove(struct platform_device *pdev)
  47798. +{
  47799. + struct bcm2835_host *host = platform_get_drvdata(pdev);
  47800. + struct resource *iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  47801. + unsigned long flags;
  47802. + int dead;
  47803. + u32 scratch;
  47804. +
  47805. + dead = 0;
  47806. + scratch = bcm2835_mmc_readl(host, SDHCI_INT_STATUS);
  47807. + if (scratch == (u32)-1)
  47808. + dead = 1;
  47809. +
  47810. +
  47811. + if (dead) {
  47812. + spin_lock_irqsave(&host->lock, flags);
  47813. +
  47814. + host->flags |= SDHCI_DEVICE_DEAD;
  47815. +
  47816. + if (host->mrq) {
  47817. + pr_err("%s: Controller removed during "
  47818. + " transfer!\n", mmc_hostname(host->mmc));
  47819. +
  47820. + host->mrq->cmd->error = -ENOMEDIUM;
  47821. + tasklet_schedule(&host->finish_tasklet);
  47822. + }
  47823. +
  47824. + spin_unlock_irqrestore(&host->lock, flags);
  47825. + }
  47826. +
  47827. + mmc_remove_host(host->mmc);
  47828. +
  47829. + if (!dead)
  47830. + bcm2835_mmc_reset(host, SDHCI_RESET_ALL);
  47831. +
  47832. + free_irq(host->irq, host);
  47833. +
  47834. + del_timer_sync(&host->timer);
  47835. +
  47836. + tasklet_kill(&host->finish_tasklet);
  47837. +
  47838. + iounmap(host->ioaddr);
  47839. + release_mem_region(iomem->start, resource_size(iomem));
  47840. + mmc_free_host(host->mmc);
  47841. + platform_set_drvdata(pdev, NULL);
  47842. +
  47843. + return 0;
  47844. +}
  47845. +
  47846. +
  47847. +static const struct of_device_id bcm2835_mmc_match[] = {
  47848. + { .compatible = "brcm,bcm2835-mmc" },
  47849. + { }
  47850. +};
  47851. +MODULE_DEVICE_TABLE(of, bcm2835_mmc_match);
  47852. +
  47853. +
  47854. +
  47855. +static struct platform_driver bcm2835_mmc_driver = {
  47856. + .probe = bcm2835_mmc_probe,
  47857. + .remove = bcm2835_mmc_remove,
  47858. + .driver = {
  47859. + .name = DRIVER_NAME,
  47860. + .owner = THIS_MODULE,
  47861. + .of_match_table = bcm2835_mmc_match,
  47862. + },
  47863. +};
  47864. +module_platform_driver(bcm2835_mmc_driver);
  47865. +
  47866. +MODULE_ALIAS("platform:mmc-bcm2835");
  47867. +MODULE_DESCRIPTION("BCM2835 SDHCI driver");
  47868. +MODULE_LICENSE("GPL v2");
  47869. +MODULE_AUTHOR("Gellert Weisz");
  47870. diff -Nur linux-3.18.8/drivers/mmc/host/Kconfig linux-rpi/drivers/mmc/host/Kconfig
  47871. --- linux-3.18.8/drivers/mmc/host/Kconfig 2015-02-27 02:49:36.000000000 +0100
  47872. +++ linux-rpi/drivers/mmc/host/Kconfig 2015-03-05 14:40:14.409715819 +0100
  47873. @@ -281,17 +281,6 @@
  47874. If you have a controller with this interface, say Y or M here.
  47875. -config MMC_SDHCI_BCM2835
  47876. - tristate "SDHCI platform support for the BCM2835 SD/MMC Controller"
  47877. - depends on ARCH_BCM2835
  47878. - depends on MMC_SDHCI_PLTFM
  47879. - select MMC_SDHCI_IO_ACCESSORS
  47880. - help
  47881. - This selects the BCM2835 SD/MMC controller. If you have a BCM2835
  47882. - platform with SD or MMC devices, say Y or M here.
  47883. -
  47884. - If unsure, say N.
  47885. -
  47886. config MMC_MOXART
  47887. tristate "MOXART SD/MMC Host Controller support"
  47888. depends on ARCH_MOXART && MMC
  47889. @@ -313,6 +302,35 @@
  47890. If you have a controller with this interface, say Y or M here.
  47891. If unsure, say N.
  47892. +config MMC_BCM2835
  47893. + tristate "MMC support on BCM2835"
  47894. + depends on (MACH_BCM2708 || MACH_BCM2709)
  47895. + help
  47896. + This selects the MMC Interface on BCM2835.
  47897. +
  47898. + If you have a controller with this interface, say Y or M here.
  47899. +
  47900. + If unsure, say N.
  47901. +
  47902. +config MMC_BCM2835_DMA
  47903. + bool "DMA support on BCM2835 Arasan controller"
  47904. + depends on MMC_BCM2835
  47905. + help
  47906. + Enable DMA support on the Arasan SDHCI controller in Broadcom 2708
  47907. + based chips.
  47908. +
  47909. + If unsure, say N.
  47910. +
  47911. +config MMC_BCM2835_PIO_DMA_BARRIER
  47912. + int "Block count limit for PIO transfers"
  47913. + depends on MMC_BCM2835 && MMC_BCM2835_DMA
  47914. + range 0 256
  47915. + default 2
  47916. + help
  47917. + The inclusive limit in bytes under which PIO will be used instead of DMA
  47918. +
  47919. + If unsure, say 2 here.
  47920. +
  47921. config MMC_OMAP
  47922. tristate "TI OMAP Multimedia Card Interface support"
  47923. depends on ARCH_OMAP
  47924. diff -Nur linux-3.18.8/drivers/mmc/host/Makefile linux-rpi/drivers/mmc/host/Makefile
  47925. --- linux-3.18.8/drivers/mmc/host/Makefile 2015-02-27 02:49:36.000000000 +0100
  47926. +++ linux-rpi/drivers/mmc/host/Makefile 2015-03-05 14:40:14.409715819 +0100
  47927. @@ -17,6 +17,7 @@
  47928. obj-$(CONFIG_MMC_SDHCI_S3C) += sdhci-s3c.o
  47929. obj-$(CONFIG_MMC_SDHCI_SIRF) += sdhci-sirf.o
  47930. obj-$(CONFIG_MMC_SDHCI_SPEAR) += sdhci-spear.o
  47931. +obj-$(CONFIG_MMC_BCM2835) += bcm2835-mmc.o
  47932. obj-$(CONFIG_MMC_WBSD) += wbsd.o
  47933. obj-$(CONFIG_MMC_AU1X) += au1xmmc.o
  47934. obj-$(CONFIG_MMC_OMAP) += omap.o
  47935. diff -Nur linux-3.18.8/drivers/net/ethernet/microchip/enc28j60.c linux-rpi/drivers/net/ethernet/microchip/enc28j60.c
  47936. --- linux-3.18.8/drivers/net/ethernet/microchip/enc28j60.c 2015-02-27 02:49:36.000000000 +0100
  47937. +++ linux-rpi/drivers/net/ethernet/microchip/enc28j60.c 2015-03-05 14:40:14.717715817 +0100
  47938. @@ -1630,10 +1630,21 @@
  47939. return 0;
  47940. }
  47941. +#ifdef CONFIG_OF
  47942. +static const struct of_device_id enc28j60_of_match[] = {
  47943. + { .compatible = "microchip,enc28j60", },
  47944. + { /* sentinel */ }
  47945. +};
  47946. +MODULE_DEVICE_TABLE(of, enc28j60_of_match);
  47947. +#endif
  47948. +
  47949. static struct spi_driver enc28j60_driver = {
  47950. .driver = {
  47951. .name = DRV_NAME,
  47952. .owner = THIS_MODULE,
  47953. +#ifdef CONFIG_OF
  47954. + .of_match_table = enc28j60_of_match,
  47955. +#endif
  47956. },
  47957. .probe = enc28j60_probe,
  47958. .remove = enc28j60_remove,
  47959. diff -Nur linux-3.18.8/drivers/net/usb/smsc95xx.c linux-rpi/drivers/net/usb/smsc95xx.c
  47960. --- linux-3.18.8/drivers/net/usb/smsc95xx.c 2015-02-27 02:49:36.000000000 +0100
  47961. +++ linux-rpi/drivers/net/usb/smsc95xx.c 2015-03-05 14:40:14.813715817 +0100
  47962. @@ -59,6 +59,7 @@
  47963. #define SUSPEND_SUSPEND3 (0x08)
  47964. #define SUSPEND_ALLMODES (SUSPEND_SUSPEND0 | SUSPEND_SUSPEND1 | \
  47965. SUSPEND_SUSPEND2 | SUSPEND_SUSPEND3)
  47966. +#define MAC_ADDR_LEN (6)
  47967. struct smsc95xx_priv {
  47968. u32 mac_cr;
  47969. @@ -74,6 +75,10 @@
  47970. module_param(turbo_mode, bool, 0644);
  47971. MODULE_PARM_DESC(turbo_mode, "Enable multiple frames per Rx transaction");
  47972. +static char *macaddr = ":";
  47973. +module_param(macaddr, charp, 0);
  47974. +MODULE_PARM_DESC(macaddr, "MAC address");
  47975. +
  47976. static int __must_check __smsc95xx_read_reg(struct usbnet *dev, u32 index,
  47977. u32 *data, int in_pm)
  47978. {
  47979. @@ -763,8 +768,59 @@
  47980. return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL);
  47981. }
  47982. +/* Check the macaddr module parameter for a MAC address */
  47983. +static int smsc95xx_is_macaddr_param(struct usbnet *dev, u8 *dev_mac)
  47984. +{
  47985. + int i, j, got_num, num;
  47986. + u8 mtbl[MAC_ADDR_LEN];
  47987. +
  47988. + if (macaddr[0] == ':')
  47989. + return 0;
  47990. +
  47991. + i = 0;
  47992. + j = 0;
  47993. + num = 0;
  47994. + got_num = 0;
  47995. + while (j < MAC_ADDR_LEN) {
  47996. + if (macaddr[i] && macaddr[i] != ':') {
  47997. + got_num++;
  47998. + if ('0' <= macaddr[i] && macaddr[i] <= '9')
  47999. + num = num * 16 + macaddr[i] - '0';
  48000. + else if ('A' <= macaddr[i] && macaddr[i] <= 'F')
  48001. + num = num * 16 + 10 + macaddr[i] - 'A';
  48002. + else if ('a' <= macaddr[i] && macaddr[i] <= 'f')
  48003. + num = num * 16 + 10 + macaddr[i] - 'a';
  48004. + else
  48005. + break;
  48006. + i++;
  48007. + } else if (got_num == 2) {
  48008. + mtbl[j++] = (u8) num;
  48009. + num = 0;
  48010. + got_num = 0;
  48011. + i++;
  48012. + } else {
  48013. + break;
  48014. + }
  48015. + }
  48016. +
  48017. + if (j == MAC_ADDR_LEN) {
  48018. + netif_dbg(dev, ifup, dev->net, "Overriding MAC address with: "
  48019. + "%02x:%02x:%02x:%02x:%02x:%02x\n", mtbl[0], mtbl[1], mtbl[2],
  48020. + mtbl[3], mtbl[4], mtbl[5]);
  48021. + for (i = 0; i < MAC_ADDR_LEN; i++)
  48022. + dev_mac[i] = mtbl[i];
  48023. + return 1;
  48024. + } else {
  48025. + return 0;
  48026. + }
  48027. +}
  48028. +
  48029. static void smsc95xx_init_mac_address(struct usbnet *dev)
  48030. {
  48031. + /* Check module parameters */
  48032. + if (smsc95xx_is_macaddr_param(dev, dev->net->dev_addr))
  48033. + return;
  48034. +
  48035. /* try reading mac address from EEPROM */
  48036. if (smsc95xx_read_eeprom(dev, EEPROM_MAC_OFFSET, ETH_ALEN,
  48037. dev->net->dev_addr) == 0) {
  48038. diff -Nur linux-3.18.8/drivers/of/fdt.c linux-rpi/drivers/of/fdt.c
  48039. --- linux-3.18.8/drivers/of/fdt.c 2015-02-27 02:49:36.000000000 +0100
  48040. +++ linux-rpi/drivers/of/fdt.c 2015-03-05 14:40:15.653715812 +0100
  48041. @@ -901,19 +901,38 @@
  48042. /* Retrieve command line */
  48043. p = of_get_flat_dt_prop(node, "bootargs", &l);
  48044. - if (p != NULL && l > 0)
  48045. - strlcpy(data, p, min((int)l, COMMAND_LINE_SIZE));
  48046. /*
  48047. * CONFIG_CMDLINE is meant to be a default in case nothing else
  48048. * managed to set the command line, unless CONFIG_CMDLINE_FORCE
  48049. * is set in which case we override whatever was found earlier.
  48050. + *
  48051. + * However, it can be useful to be able to treat the default as
  48052. + * a starting point to be extended using CONFIG_CMDLINE_EXTEND.
  48053. */
  48054. + ((char *)data)[0] = '\0';
  48055. +
  48056. #ifdef CONFIG_CMDLINE
  48057. -#ifndef CONFIG_CMDLINE_FORCE
  48058. - if (!((char *)data)[0])
  48059. + strlcpy(data, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
  48060. +
  48061. + if (p != NULL && l > 0) {
  48062. +#if defined(CONFIG_CMDLINE_EXTEND)
  48063. + int len = strlen(data);
  48064. + if (len > 0) {
  48065. + strlcat(data, " ", COMMAND_LINE_SIZE);
  48066. + len++;
  48067. + }
  48068. + strlcpy((char *)data + len, p, min((int)l, COMMAND_LINE_SIZE - len));
  48069. +#elif defined(CONFIG_CMDLINE_FORCE)
  48070. + pr_warning("Ignoring bootargs property (using the default kernel command line)\n");
  48071. +#else
  48072. + /* Neither extend nor force - just override */
  48073. + strlcpy(data, p, min((int)l, COMMAND_LINE_SIZE));
  48074. #endif
  48075. - strlcpy(data, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
  48076. + }
  48077. +#else /* CONFIG_CMDLINE */
  48078. + if (p != NULL && l > 0) {
  48079. + strlcpy(data, p, min((int)l, COMMAND_LINE_SIZE));
  48080. #endif /* CONFIG_CMDLINE */
  48081. pr_debug("Command line is: %s\n", (char*)data);
  48082. @@ -1083,8 +1102,12 @@
  48083. static int __init of_flat_dt_debugfs_export_fdt(void)
  48084. {
  48085. - struct dentry *d = debugfs_create_dir("device-tree", NULL);
  48086. + struct dentry *d;
  48087. +
  48088. + if (!initial_boot_params)
  48089. + return -ENOENT;
  48090. + d = debugfs_create_dir("device-tree", NULL);
  48091. if (!d)
  48092. return -ENOENT;
  48093. diff -Nur linux-3.18.8/drivers/pinctrl/pinctrl-bcm2835.c linux-rpi/drivers/pinctrl/pinctrl-bcm2835.c
  48094. --- linux-3.18.8/drivers/pinctrl/pinctrl-bcm2835.c 2015-02-27 02:49:36.000000000 +0100
  48095. +++ linux-rpi/drivers/pinctrl/pinctrl-bcm2835.c 2015-03-05 14:40:15.737715811 +0100
  48096. @@ -47,6 +47,7 @@
  48097. #define MODULE_NAME "pinctrl-bcm2835"
  48098. #define BCM2835_NUM_GPIOS 54
  48099. #define BCM2835_NUM_BANKS 2
  48100. +#define BCM2835_NUM_IRQS 3
  48101. #define BCM2835_PIN_BITMAP_SZ \
  48102. DIV_ROUND_UP(BCM2835_NUM_GPIOS, sizeof(unsigned long) * 8)
  48103. @@ -88,13 +89,13 @@
  48104. struct bcm2835_gpio_irqdata {
  48105. struct bcm2835_pinctrl *pc;
  48106. - int bank;
  48107. + int irqgroup;
  48108. };
  48109. struct bcm2835_pinctrl {
  48110. struct device *dev;
  48111. void __iomem *base;
  48112. - int irq[BCM2835_NUM_BANKS];
  48113. + int irq[BCM2835_NUM_IRQS];
  48114. /* note: locking assumes each bank will have its own unsigned long */
  48115. unsigned long enabled_irq_map[BCM2835_NUM_BANKS];
  48116. @@ -105,7 +106,7 @@
  48117. struct gpio_chip gpio_chip;
  48118. struct pinctrl_gpio_range gpio_range;
  48119. - struct bcm2835_gpio_irqdata irq_data[BCM2835_NUM_BANKS];
  48120. + struct bcm2835_gpio_irqdata irq_data[BCM2835_NUM_IRQS];
  48121. spinlock_t irq_lock[BCM2835_NUM_BANKS];
  48122. };
  48123. @@ -355,7 +356,14 @@
  48124. static int bcm2835_gpio_direction_output(struct gpio_chip *chip,
  48125. unsigned offset, int value)
  48126. {
  48127. - return pinctrl_gpio_direction_output(chip->base + offset);
  48128. + struct bcm2835_pinctrl *pc = dev_get_drvdata(chip->dev);
  48129. + int ret;
  48130. +
  48131. + ret = pinctrl_gpio_direction_output(chip->base + offset);
  48132. + if (ret >= 0)
  48133. + bcm2835_gpio_set_bit(pc, value ? GPSET0 : GPCLR0, offset);
  48134. +
  48135. + return ret;
  48136. }
  48137. static void bcm2835_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
  48138. @@ -382,22 +390,21 @@
  48139. .get = bcm2835_gpio_get,
  48140. .set = bcm2835_gpio_set,
  48141. .to_irq = bcm2835_gpio_to_irq,
  48142. - .base = -1,
  48143. + .base = 0,
  48144. .ngpio = BCM2835_NUM_GPIOS,
  48145. .can_sleep = false,
  48146. };
  48147. -static irqreturn_t bcm2835_gpio_irq_handler(int irq, void *dev_id)
  48148. +static int bcm2835_gpio_irq_handle_bank(struct bcm2835_pinctrl *pc,
  48149. + unsigned int bank, u32 mask)
  48150. {
  48151. - struct bcm2835_gpio_irqdata *irqdata = dev_id;
  48152. - struct bcm2835_pinctrl *pc = irqdata->pc;
  48153. - int bank = irqdata->bank;
  48154. unsigned long events;
  48155. unsigned offset;
  48156. unsigned gpio;
  48157. unsigned int type;
  48158. events = bcm2835_gpio_rd(pc, GPEDS0 + bank * 4);
  48159. + events &= mask;
  48160. events &= pc->enabled_irq_map[bank];
  48161. for_each_set_bit(offset, &events, 32) {
  48162. gpio = (32 * bank) + offset;
  48163. @@ -413,7 +420,30 @@
  48164. if (type & IRQ_TYPE_LEVEL_MASK)
  48165. bcm2835_gpio_set_bit(pc, GPEDS0, gpio);
  48166. }
  48167. - return events ? IRQ_HANDLED : IRQ_NONE;
  48168. +
  48169. + return (events != 0);
  48170. +}
  48171. +
  48172. +static irqreturn_t bcm2835_gpio_irq_handler(int irq, void *dev_id)
  48173. +{
  48174. + struct bcm2835_gpio_irqdata *irqdata = dev_id;
  48175. + struct bcm2835_pinctrl *pc = irqdata->pc;
  48176. + int handled = 0;
  48177. +
  48178. + switch (irqdata->irqgroup) {
  48179. + case 0: /* IRQ0 covers GPIOs 0-27 */
  48180. + handled = bcm2835_gpio_irq_handle_bank(pc, 0, 0x0fffffff);
  48181. + break;
  48182. + case 1: /* IRQ1 covers GPIOs 28-45 */
  48183. + handled = bcm2835_gpio_irq_handle_bank(pc, 0, 0xf0000000) |
  48184. + bcm2835_gpio_irq_handle_bank(pc, 1, 0x00003fff);
  48185. + break;
  48186. + case 2: /* IRQ2 covers GPIOs 46-53 */
  48187. + handled = bcm2835_gpio_irq_handle_bank(pc, 1, 0x003fc000);
  48188. + break;
  48189. + }
  48190. +
  48191. + return handled ? IRQ_HANDLED : IRQ_NONE;
  48192. }
  48193. static inline void __bcm2835_gpio_irq_config(struct bcm2835_pinctrl *pc,
  48194. @@ -985,8 +1015,6 @@
  48195. for (i = 0; i < BCM2835_NUM_BANKS; i++) {
  48196. unsigned long events;
  48197. unsigned offset;
  48198. - int len;
  48199. - char *name;
  48200. /* clear event detection flags */
  48201. bcm2835_gpio_wr(pc, GPREN0 + i * 4, 0);
  48202. @@ -1001,10 +1029,17 @@
  48203. for_each_set_bit(offset, &events, 32)
  48204. bcm2835_gpio_wr(pc, GPEDS0 + i * 4, BIT(offset));
  48205. + spin_lock_init(&pc->irq_lock[i]);
  48206. + }
  48207. +
  48208. + for (i = 0; i < BCM2835_NUM_IRQS; i++) {
  48209. + int len;
  48210. + char *name;
  48211. pc->irq[i] = irq_of_parse_and_map(np, i);
  48212. + if (pc->irq[i] == 0)
  48213. + break;
  48214. pc->irq_data[i].pc = pc;
  48215. - pc->irq_data[i].bank = i;
  48216. - spin_lock_init(&pc->irq_lock[i]);
  48217. + pc->irq_data[i].irqgroup = i;
  48218. len = strlen(dev_name(pc->dev)) + 16;
  48219. name = devm_kzalloc(pc->dev, len, GFP_KERNEL);
  48220. diff -Nur linux-3.18.8/drivers/rtc/rtc-ds1307.c linux-rpi/drivers/rtc/rtc-ds1307.c
  48221. --- linux-3.18.8/drivers/rtc/rtc-ds1307.c 2015-02-27 02:49:36.000000000 +0100
  48222. +++ linux-rpi/drivers/rtc/rtc-ds1307.c 2015-03-05 14:40:15.957715810 +0100
  48223. @@ -1241,6 +1241,14 @@
  48224. return 0;
  48225. }
  48226. +#ifdef CONFIG_OF
  48227. +static const struct of_device_id ds1307_of_match[] = {
  48228. + { .compatible = "maxim,ds1307" },
  48229. + { }
  48230. +};
  48231. +MODULE_DEVICE_TABLE(of, ds1307_of_match);
  48232. +#endif
  48233. +
  48234. static struct i2c_driver ds1307_driver = {
  48235. .driver = {
  48236. .name = "rtc-ds1307",
  48237. diff -Nur linux-3.18.8/drivers/spi/Kconfig linux-rpi/drivers/spi/Kconfig
  48238. --- linux-3.18.8/drivers/spi/Kconfig 2015-02-27 02:49:36.000000000 +0100
  48239. +++ linux-rpi/drivers/spi/Kconfig 2015-03-05 14:40:16.297715808 +0100
  48240. @@ -77,7 +77,7 @@
  48241. config SPI_BCM2835
  48242. tristate "BCM2835 SPI controller"
  48243. - depends on ARCH_BCM2835 || COMPILE_TEST
  48244. + depends on ARCH_BCM2835 || ARCH_BCM2708 || ARCH_BCM2709 || COMPILE_TEST
  48245. help
  48246. This selects a driver for the Broadcom BCM2835 SPI master.
  48247. @@ -86,6 +86,14 @@
  48248. is for the regular SPI controller. Slave mode operation is not also
  48249. not supported.
  48250. +config SPI_BCM2708
  48251. + tristate "BCM2708 SPI controller driver (SPI0)"
  48252. + depends on MACH_BCM2708 || MACH_BCM2709
  48253. + help
  48254. + This selects a driver for the Broadcom BCM2708 SPI master (SPI0). This
  48255. + driver is not compatible with the "Universal SPI Master" or the SPI slave
  48256. + device.
  48257. +
  48258. config SPI_BFIN5XX
  48259. tristate "SPI controller driver for ADI Blackfin5xx"
  48260. depends on BLACKFIN && !BF60x
  48261. diff -Nur linux-3.18.8/drivers/spi/Makefile linux-rpi/drivers/spi/Makefile
  48262. --- linux-3.18.8/drivers/spi/Makefile 2015-02-27 02:49:36.000000000 +0100
  48263. +++ linux-rpi/drivers/spi/Makefile 2015-03-05 14:40:16.297715808 +0100
  48264. @@ -20,6 +20,7 @@
  48265. obj-$(CONFIG_SPI_BCM63XX_HSSPI) += spi-bcm63xx-hsspi.o
  48266. obj-$(CONFIG_SPI_BFIN5XX) += spi-bfin5xx.o
  48267. obj-$(CONFIG_SPI_ADI_V3) += spi-adi-v3.o
  48268. +obj-$(CONFIG_SPI_BCM2708) += spi-bcm2708.o
  48269. obj-$(CONFIG_SPI_BFIN_SPORT) += spi-bfin-sport.o
  48270. obj-$(CONFIG_SPI_BITBANG) += spi-bitbang.o
  48271. obj-$(CONFIG_SPI_BUTTERFLY) += spi-butterfly.o
  48272. diff -Nur linux-3.18.8/drivers/spi/spi-bcm2708.c linux-rpi/drivers/spi/spi-bcm2708.c
  48273. --- linux-3.18.8/drivers/spi/spi-bcm2708.c 1970-01-01 01:00:00.000000000 +0100
  48274. +++ linux-rpi/drivers/spi/spi-bcm2708.c 2015-03-05 14:40:16.297715808 +0100
  48275. @@ -0,0 +1,635 @@
  48276. +/*
  48277. + * Driver for Broadcom BCM2708 SPI Controllers
  48278. + *
  48279. + * Copyright (C) 2012 Chris Boot
  48280. + *
  48281. + * This driver is inspired by:
  48282. + * spi-ath79.c, Copyright (C) 2009-2011 Gabor Juhos <juhosg@openwrt.org>
  48283. + * spi-atmel.c, Copyright (C) 2006 Atmel Corporation
  48284. + *
  48285. + * This program is free software; you can redistribute it and/or modify
  48286. + * it under the terms of the GNU General Public License as published by
  48287. + * the Free Software Foundation; either version 2 of the License, or
  48288. + * (at your option) any later version.
  48289. + *
  48290. + * This program is distributed in the hope that it will be useful,
  48291. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  48292. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  48293. + * GNU General Public License for more details.
  48294. + *
  48295. + * You should have received a copy of the GNU General Public License
  48296. + * along with this program; if not, write to the Free Software
  48297. + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  48298. + */
  48299. +
  48300. +#include <linux/kernel.h>
  48301. +#include <linux/module.h>
  48302. +#include <linux/spinlock.h>
  48303. +#include <linux/clk.h>
  48304. +#include <linux/err.h>
  48305. +#include <linux/platform_device.h>
  48306. +#include <linux/io.h>
  48307. +#include <linux/spi/spi.h>
  48308. +#include <linux/interrupt.h>
  48309. +#include <linux/delay.h>
  48310. +#include <linux/log2.h>
  48311. +#include <linux/sched.h>
  48312. +#include <linux/wait.h>
  48313. +
  48314. +/* SPI register offsets */
  48315. +#define SPI_CS 0x00
  48316. +#define SPI_FIFO 0x04
  48317. +#define SPI_CLK 0x08
  48318. +#define SPI_DLEN 0x0c
  48319. +#define SPI_LTOH 0x10
  48320. +#define SPI_DC 0x14
  48321. +
  48322. +/* Bitfields in CS */
  48323. +#define SPI_CS_LEN_LONG 0x02000000
  48324. +#define SPI_CS_DMA_LEN 0x01000000
  48325. +#define SPI_CS_CSPOL2 0x00800000
  48326. +#define SPI_CS_CSPOL1 0x00400000
  48327. +#define SPI_CS_CSPOL0 0x00200000
  48328. +#define SPI_CS_RXF 0x00100000
  48329. +#define SPI_CS_RXR 0x00080000
  48330. +#define SPI_CS_TXD 0x00040000
  48331. +#define SPI_CS_RXD 0x00020000
  48332. +#define SPI_CS_DONE 0x00010000
  48333. +#define SPI_CS_LEN 0x00002000
  48334. +#define SPI_CS_REN 0x00001000
  48335. +#define SPI_CS_ADCS 0x00000800
  48336. +#define SPI_CS_INTR 0x00000400
  48337. +#define SPI_CS_INTD 0x00000200
  48338. +#define SPI_CS_DMAEN 0x00000100
  48339. +#define SPI_CS_TA 0x00000080
  48340. +#define SPI_CS_CSPOL 0x00000040
  48341. +#define SPI_CS_CLEAR_RX 0x00000020
  48342. +#define SPI_CS_CLEAR_TX 0x00000010
  48343. +#define SPI_CS_CPOL 0x00000008
  48344. +#define SPI_CS_CPHA 0x00000004
  48345. +#define SPI_CS_CS_10 0x00000002
  48346. +#define SPI_CS_CS_01 0x00000001
  48347. +
  48348. +#define SPI_TIMEOUT_MS 150
  48349. +
  48350. +#define DRV_NAME "bcm2708_spi"
  48351. +
  48352. +struct bcm2708_spi {
  48353. + spinlock_t lock;
  48354. + void __iomem *base;
  48355. + int irq;
  48356. + struct clk *clk;
  48357. + bool stopping;
  48358. +
  48359. + struct list_head queue;
  48360. + struct workqueue_struct *workq;
  48361. + struct work_struct work;
  48362. + struct completion done;
  48363. +
  48364. + const u8 *tx_buf;
  48365. + u8 *rx_buf;
  48366. + int len;
  48367. +};
  48368. +
  48369. +struct bcm2708_spi_state {
  48370. + u32 cs;
  48371. + u16 cdiv;
  48372. +};
  48373. +
  48374. +/*
  48375. + * This function sets the ALT mode on the SPI pins so that we can use them with
  48376. + * the SPI hardware.
  48377. + *
  48378. + * FIXME: This is a hack. Use pinmux / pinctrl.
  48379. + */
  48380. +static void bcm2708_init_pinmode(void)
  48381. +{
  48382. +#define INP_GPIO(g) *(gpio+((g)/10)) &= ~(7<<(((g)%10)*3))
  48383. +#define SET_GPIO_ALT(g,a) *(gpio+(((g)/10))) |= (((a)<=3?(a)+4:(a)==4?3:2)<<(((g)%10)*3))
  48384. +
  48385. + int pin;
  48386. + u32 *gpio = ioremap(GPIO_BASE, SZ_16K);
  48387. +
  48388. + /* SPI is on GPIO 7..11 */
  48389. + for (pin = 7; pin <= 11; pin++) {
  48390. + INP_GPIO(pin); /* set mode to GPIO input first */
  48391. + SET_GPIO_ALT(pin, 0); /* set mode to ALT 0 */
  48392. + }
  48393. +
  48394. + iounmap(gpio);
  48395. +
  48396. +#undef INP_GPIO
  48397. +#undef SET_GPIO_ALT
  48398. +}
  48399. +
  48400. +static inline u32 bcm2708_rd(struct bcm2708_spi *bs, unsigned reg)
  48401. +{
  48402. + return readl(bs->base + reg);
  48403. +}
  48404. +
  48405. +static inline void bcm2708_wr(struct bcm2708_spi *bs, unsigned reg, u32 val)
  48406. +{
  48407. + writel(val, bs->base + reg);
  48408. +}
  48409. +
  48410. +static inline void bcm2708_rd_fifo(struct bcm2708_spi *bs, int len)
  48411. +{
  48412. + u8 byte;
  48413. +
  48414. + while (len--) {
  48415. + byte = bcm2708_rd(bs, SPI_FIFO);
  48416. + if (bs->rx_buf)
  48417. + *bs->rx_buf++ = byte;
  48418. + }
  48419. +}
  48420. +
  48421. +static inline void bcm2708_wr_fifo(struct bcm2708_spi *bs, int len)
  48422. +{
  48423. + u8 byte;
  48424. + u16 val;
  48425. +
  48426. + if (len > bs->len)
  48427. + len = bs->len;
  48428. +
  48429. + if (unlikely(bcm2708_rd(bs, SPI_CS) & SPI_CS_LEN)) {
  48430. + /* LoSSI mode */
  48431. + if (unlikely(len % 2)) {
  48432. + printk(KERN_ERR"bcm2708_wr_fifo: length must be even, skipping.\n");
  48433. + bs->len = 0;
  48434. + return;
  48435. + }
  48436. + while (len) {
  48437. + if (bs->tx_buf) {
  48438. + val = *(const u16 *)bs->tx_buf;
  48439. + bs->tx_buf += 2;
  48440. + } else
  48441. + val = 0;
  48442. + bcm2708_wr(bs, SPI_FIFO, val);
  48443. + bs->len -= 2;
  48444. + len -= 2;
  48445. + }
  48446. + return;
  48447. + }
  48448. +
  48449. + while (len--) {
  48450. + byte = bs->tx_buf ? *bs->tx_buf++ : 0;
  48451. + bcm2708_wr(bs, SPI_FIFO, byte);
  48452. + bs->len--;
  48453. + }
  48454. +}
  48455. +
  48456. +static irqreturn_t bcm2708_spi_interrupt(int irq, void *dev_id)
  48457. +{
  48458. + struct spi_master *master = dev_id;
  48459. + struct bcm2708_spi *bs = spi_master_get_devdata(master);
  48460. + u32 cs;
  48461. +
  48462. + spin_lock(&bs->lock);
  48463. +
  48464. + cs = bcm2708_rd(bs, SPI_CS);
  48465. +
  48466. + if (cs & SPI_CS_DONE) {
  48467. + if (bs->len) { /* first interrupt in a transfer */
  48468. + /* fill the TX fifo with up to 16 bytes */
  48469. + bcm2708_wr_fifo(bs, 16);
  48470. + } else { /* transfer complete */
  48471. + /* disable interrupts */
  48472. + cs &= ~(SPI_CS_INTR | SPI_CS_INTD);
  48473. + bcm2708_wr(bs, SPI_CS, cs);
  48474. +
  48475. + /* drain RX FIFO */
  48476. + while (cs & SPI_CS_RXD) {
  48477. + bcm2708_rd_fifo(bs, 1);
  48478. + cs = bcm2708_rd(bs, SPI_CS);
  48479. + }
  48480. +
  48481. + /* wake up our bh */
  48482. + complete(&bs->done);
  48483. + }
  48484. + } else if (cs & SPI_CS_RXR) {
  48485. + /* read 12 bytes of data */
  48486. + bcm2708_rd_fifo(bs, 12);
  48487. +
  48488. + /* write up to 12 bytes */
  48489. + bcm2708_wr_fifo(bs, 12);
  48490. + }
  48491. +
  48492. + spin_unlock(&bs->lock);
  48493. +
  48494. + return IRQ_HANDLED;
  48495. +}
  48496. +
  48497. +static int bcm2708_setup_state(struct spi_master *master,
  48498. + struct device *dev, struct bcm2708_spi_state *state,
  48499. + u32 hz, u8 csel, u8 mode, u8 bpw)
  48500. +{
  48501. + struct bcm2708_spi *bs = spi_master_get_devdata(master);
  48502. + int cdiv;
  48503. + unsigned long bus_hz;
  48504. + u32 cs = 0;
  48505. +
  48506. + bus_hz = clk_get_rate(bs->clk);
  48507. +
  48508. + if (hz >= bus_hz) {
  48509. + cdiv = 2; /* bus_hz / 2 is as fast as we can go */
  48510. + } else if (hz) {
  48511. + cdiv = DIV_ROUND_UP(bus_hz, hz);
  48512. +
  48513. + /* CDIV must be a power of 2, so round up */
  48514. + cdiv = roundup_pow_of_two(cdiv);
  48515. +
  48516. + if (cdiv > 65536) {
  48517. + dev_dbg(dev,
  48518. + "setup: %d Hz too slow, cdiv %u; min %ld Hz\n",
  48519. + hz, cdiv, bus_hz / 65536);
  48520. + return -EINVAL;
  48521. + } else if (cdiv == 65536) {
  48522. + cdiv = 0;
  48523. + } else if (cdiv == 1) {
  48524. + cdiv = 2; /* 1 gets rounded down to 0; == 65536 */
  48525. + }
  48526. + } else {
  48527. + cdiv = 0;
  48528. + }
  48529. +
  48530. + switch (bpw) {
  48531. + case 8:
  48532. + break;
  48533. + case 9:
  48534. + /* Reading in LoSSI mode is a special case. See 'BCM2835 ARM Peripherals' datasheet */
  48535. + cs |= SPI_CS_LEN;
  48536. + break;
  48537. + default:
  48538. + dev_dbg(dev, "setup: invalid bits_per_word %u (must be 8 or 9)\n",
  48539. + bpw);
  48540. + return -EINVAL;
  48541. + }
  48542. +
  48543. + if (mode & SPI_CPOL)
  48544. + cs |= SPI_CS_CPOL;
  48545. + if (mode & SPI_CPHA)
  48546. + cs |= SPI_CS_CPHA;
  48547. +
  48548. + if (!(mode & SPI_NO_CS)) {
  48549. + if (mode & SPI_CS_HIGH) {
  48550. + cs |= SPI_CS_CSPOL;
  48551. + cs |= SPI_CS_CSPOL0 << csel;
  48552. + }
  48553. +
  48554. + cs |= csel;
  48555. + } else {
  48556. + cs |= SPI_CS_CS_10 | SPI_CS_CS_01;
  48557. + }
  48558. +
  48559. + if (state) {
  48560. + state->cs = cs;
  48561. + state->cdiv = cdiv;
  48562. + dev_dbg(dev, "setup: want %d Hz; "
  48563. + "bus_hz=%lu / cdiv=%u == %lu Hz; "
  48564. + "mode %u: cs 0x%08X\n",
  48565. + hz, bus_hz, cdiv, bus_hz/cdiv, mode, cs);
  48566. + }
  48567. +
  48568. + return 0;
  48569. +}
  48570. +
  48571. +static int bcm2708_process_transfer(struct bcm2708_spi *bs,
  48572. + struct spi_message *msg, struct spi_transfer *xfer)
  48573. +{
  48574. + struct spi_device *spi = msg->spi;
  48575. + struct bcm2708_spi_state state, *stp;
  48576. + int ret;
  48577. + u32 cs;
  48578. +
  48579. + if (bs->stopping)
  48580. + return -ESHUTDOWN;
  48581. +
  48582. + if (xfer->bits_per_word || xfer->speed_hz) {
  48583. + ret = bcm2708_setup_state(spi->master, &spi->dev, &state,
  48584. + xfer->speed_hz ? xfer->speed_hz : spi->max_speed_hz,
  48585. + spi->chip_select, spi->mode,
  48586. + xfer->bits_per_word ? xfer->bits_per_word :
  48587. + spi->bits_per_word);
  48588. + if (ret)
  48589. + return ret;
  48590. +
  48591. + stp = &state;
  48592. + } else {
  48593. + stp = spi->controller_state;
  48594. + }
  48595. +
  48596. + reinit_completion(&bs->done);
  48597. + bs->tx_buf = xfer->tx_buf;
  48598. + bs->rx_buf = xfer->rx_buf;
  48599. + bs->len = xfer->len;
  48600. +
  48601. + cs = stp->cs | SPI_CS_INTR | SPI_CS_INTD | SPI_CS_TA;
  48602. +
  48603. + bcm2708_wr(bs, SPI_CLK, stp->cdiv);
  48604. + bcm2708_wr(bs, SPI_CS, cs);
  48605. +
  48606. + ret = wait_for_completion_timeout(&bs->done,
  48607. + msecs_to_jiffies(SPI_TIMEOUT_MS));
  48608. + if (ret == 0) {
  48609. + dev_err(&spi->dev, "transfer timed out\n");
  48610. + return -ETIMEDOUT;
  48611. + }
  48612. +
  48613. + if (xfer->delay_usecs)
  48614. + udelay(xfer->delay_usecs);
  48615. +
  48616. + if (list_is_last(&xfer->transfer_list, &msg->transfers) ||
  48617. + xfer->cs_change) {
  48618. + /* clear TA and interrupt flags */
  48619. + bcm2708_wr(bs, SPI_CS, stp->cs);
  48620. + }
  48621. +
  48622. + msg->actual_length += (xfer->len - bs->len);
  48623. +
  48624. + return 0;
  48625. +}
  48626. +
  48627. +static void bcm2708_work(struct work_struct *work)
  48628. +{
  48629. + struct bcm2708_spi *bs = container_of(work, struct bcm2708_spi, work);
  48630. + unsigned long flags;
  48631. + struct spi_message *msg;
  48632. + struct spi_transfer *xfer;
  48633. + int status = 0;
  48634. +
  48635. + spin_lock_irqsave(&bs->lock, flags);
  48636. + while (!list_empty(&bs->queue)) {
  48637. + msg = list_first_entry(&bs->queue, struct spi_message, queue);
  48638. + list_del_init(&msg->queue);
  48639. + spin_unlock_irqrestore(&bs->lock, flags);
  48640. +
  48641. + list_for_each_entry(xfer, &msg->transfers, transfer_list) {
  48642. + status = bcm2708_process_transfer(bs, msg, xfer);
  48643. + if (status)
  48644. + break;
  48645. + }
  48646. +
  48647. + msg->status = status;
  48648. + msg->complete(msg->context);
  48649. +
  48650. + spin_lock_irqsave(&bs->lock, flags);
  48651. + }
  48652. + spin_unlock_irqrestore(&bs->lock, flags);
  48653. +}
  48654. +
  48655. +static int bcm2708_spi_setup(struct spi_device *spi)
  48656. +{
  48657. + struct bcm2708_spi *bs = spi_master_get_devdata(spi->master);
  48658. + struct bcm2708_spi_state *state;
  48659. + int ret;
  48660. +
  48661. + if (bs->stopping)
  48662. + return -ESHUTDOWN;
  48663. +
  48664. + if (!(spi->mode & SPI_NO_CS) &&
  48665. + (spi->chip_select > spi->master->num_chipselect)) {
  48666. + dev_dbg(&spi->dev,
  48667. + "setup: invalid chipselect %u (%u defined)\n",
  48668. + spi->chip_select, spi->master->num_chipselect);
  48669. + return -EINVAL;
  48670. + }
  48671. +
  48672. + state = spi->controller_state;
  48673. + if (!state) {
  48674. + state = kzalloc(sizeof(*state), GFP_KERNEL);
  48675. + if (!state)
  48676. + return -ENOMEM;
  48677. +
  48678. + spi->controller_state = state;
  48679. + }
  48680. +
  48681. + ret = bcm2708_setup_state(spi->master, &spi->dev, state,
  48682. + spi->max_speed_hz, spi->chip_select, spi->mode,
  48683. + spi->bits_per_word);
  48684. + if (ret < 0) {
  48685. + kfree(state);
  48686. + spi->controller_state = NULL;
  48687. + return ret;
  48688. + }
  48689. +
  48690. + dev_dbg(&spi->dev,
  48691. + "setup: cd %d: %d Hz, bpw %u, mode 0x%x -> CS=%08x CDIV=%04x\n",
  48692. + spi->chip_select, spi->max_speed_hz, spi->bits_per_word,
  48693. + spi->mode, state->cs, state->cdiv);
  48694. +
  48695. + return 0;
  48696. +}
  48697. +
  48698. +static int bcm2708_spi_transfer(struct spi_device *spi, struct spi_message *msg)
  48699. +{
  48700. + struct bcm2708_spi *bs = spi_master_get_devdata(spi->master);
  48701. + struct spi_transfer *xfer;
  48702. + int ret;
  48703. + unsigned long flags;
  48704. +
  48705. + if (unlikely(list_empty(&msg->transfers)))
  48706. + return -EINVAL;
  48707. +
  48708. + if (bs->stopping)
  48709. + return -ESHUTDOWN;
  48710. +
  48711. + list_for_each_entry(xfer, &msg->transfers, transfer_list) {
  48712. + if (!(xfer->tx_buf || xfer->rx_buf) && xfer->len) {
  48713. + dev_dbg(&spi->dev, "missing rx or tx buf\n");
  48714. + return -EINVAL;
  48715. + }
  48716. +
  48717. + if (!xfer->bits_per_word || xfer->speed_hz)
  48718. + continue;
  48719. +
  48720. + ret = bcm2708_setup_state(spi->master, &spi->dev, NULL,
  48721. + xfer->speed_hz ? xfer->speed_hz : spi->max_speed_hz,
  48722. + spi->chip_select, spi->mode,
  48723. + xfer->bits_per_word ? xfer->bits_per_word :
  48724. + spi->bits_per_word);
  48725. + if (ret)
  48726. + return ret;
  48727. + }
  48728. +
  48729. + msg->status = -EINPROGRESS;
  48730. + msg->actual_length = 0;
  48731. +
  48732. + spin_lock_irqsave(&bs->lock, flags);
  48733. + list_add_tail(&msg->queue, &bs->queue);
  48734. + queue_work(bs->workq, &bs->work);
  48735. + spin_unlock_irqrestore(&bs->lock, flags);
  48736. +
  48737. + return 0;
  48738. +}
  48739. +
  48740. +static void bcm2708_spi_cleanup(struct spi_device *spi)
  48741. +{
  48742. + if (spi->controller_state) {
  48743. + kfree(spi->controller_state);
  48744. + spi->controller_state = NULL;
  48745. + }
  48746. +}
  48747. +
  48748. +static int bcm2708_spi_probe(struct platform_device *pdev)
  48749. +{
  48750. + struct resource *regs;
  48751. + int irq, err = -ENOMEM;
  48752. + struct clk *clk;
  48753. + struct spi_master *master;
  48754. + struct bcm2708_spi *bs;
  48755. +
  48756. + regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  48757. + if (!regs) {
  48758. + dev_err(&pdev->dev, "could not get IO memory\n");
  48759. + return -ENXIO;
  48760. + }
  48761. +
  48762. + irq = platform_get_irq(pdev, 0);
  48763. + if (irq < 0) {
  48764. + dev_err(&pdev->dev, "could not get IRQ\n");
  48765. + return irq;
  48766. + }
  48767. +
  48768. + clk = clk_get(&pdev->dev, NULL);
  48769. + if (IS_ERR(clk)) {
  48770. + dev_err(&pdev->dev, "could not find clk: %ld\n", PTR_ERR(clk));
  48771. + return PTR_ERR(clk);
  48772. + }
  48773. +
  48774. + bcm2708_init_pinmode();
  48775. +
  48776. + master = spi_alloc_master(&pdev->dev, sizeof(*bs));
  48777. + if (!master) {
  48778. + dev_err(&pdev->dev, "spi_alloc_master() failed\n");
  48779. + goto out_clk_put;
  48780. + }
  48781. +
  48782. + /* the spi->mode bits understood by this driver: */
  48783. + master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH | SPI_NO_CS;
  48784. +
  48785. + master->bus_num = pdev->id;
  48786. + master->num_chipselect = 3;
  48787. + master->setup = bcm2708_spi_setup;
  48788. + master->transfer = bcm2708_spi_transfer;
  48789. + master->cleanup = bcm2708_spi_cleanup;
  48790. + master->dev.of_node = pdev->dev.of_node;
  48791. + platform_set_drvdata(pdev, master);
  48792. +
  48793. + bs = spi_master_get_devdata(master);
  48794. +
  48795. + spin_lock_init(&bs->lock);
  48796. + INIT_LIST_HEAD(&bs->queue);
  48797. + init_completion(&bs->done);
  48798. + INIT_WORK(&bs->work, bcm2708_work);
  48799. +
  48800. + bs->base = ioremap(regs->start, resource_size(regs));
  48801. + if (!bs->base) {
  48802. + dev_err(&pdev->dev, "could not remap memory\n");
  48803. + goto out_master_put;
  48804. + }
  48805. +
  48806. + bs->workq = create_singlethread_workqueue(dev_name(&pdev->dev));
  48807. + if (!bs->workq) {
  48808. + dev_err(&pdev->dev, "could not create workqueue\n");
  48809. + goto out_iounmap;
  48810. + }
  48811. +
  48812. + bs->irq = irq;
  48813. + bs->clk = clk;
  48814. + bs->stopping = false;
  48815. +
  48816. + err = request_irq(irq, bcm2708_spi_interrupt, 0, dev_name(&pdev->dev),
  48817. + master);
  48818. + if (err) {
  48819. + dev_err(&pdev->dev, "could not request IRQ: %d\n", err);
  48820. + goto out_workqueue;
  48821. + }
  48822. +
  48823. + /* initialise the hardware */
  48824. + clk_prepare_enable(clk);
  48825. + bcm2708_wr(bs, SPI_CS, SPI_CS_REN | SPI_CS_CLEAR_RX | SPI_CS_CLEAR_TX);
  48826. +
  48827. + err = spi_register_master(master);
  48828. + if (err) {
  48829. + dev_err(&pdev->dev, "could not register SPI master: %d\n", err);
  48830. + goto out_free_irq;
  48831. + }
  48832. +
  48833. + dev_info(&pdev->dev, "SPI Controller at 0x%08lx (irq %d)\n",
  48834. + (unsigned long)regs->start, irq);
  48835. +
  48836. + return 0;
  48837. +
  48838. +out_free_irq:
  48839. + free_irq(bs->irq, master);
  48840. + clk_disable_unprepare(bs->clk);
  48841. +out_workqueue:
  48842. + destroy_workqueue(bs->workq);
  48843. +out_iounmap:
  48844. + iounmap(bs->base);
  48845. +out_master_put:
  48846. + spi_master_put(master);
  48847. +out_clk_put:
  48848. + clk_put(clk);
  48849. + return err;
  48850. +}
  48851. +
  48852. +static int bcm2708_spi_remove(struct platform_device *pdev)
  48853. +{
  48854. + struct spi_master *master = platform_get_drvdata(pdev);
  48855. + struct bcm2708_spi *bs = spi_master_get_devdata(master);
  48856. +
  48857. + /* reset the hardware and block queue progress */
  48858. + spin_lock_irq(&bs->lock);
  48859. + bs->stopping = true;
  48860. + bcm2708_wr(bs, SPI_CS, SPI_CS_CLEAR_RX | SPI_CS_CLEAR_TX);
  48861. + spin_unlock_irq(&bs->lock);
  48862. +
  48863. + flush_work(&bs->work);
  48864. +
  48865. + clk_disable_unprepare(bs->clk);
  48866. + clk_put(bs->clk);
  48867. + free_irq(bs->irq, master);
  48868. + iounmap(bs->base);
  48869. +
  48870. + spi_unregister_master(master);
  48871. +
  48872. + return 0;
  48873. +}
  48874. +
  48875. +static const struct of_device_id bcm2708_spi_match[] = {
  48876. + { .compatible = "brcm,bcm2708-spi", },
  48877. + {}
  48878. +};
  48879. +MODULE_DEVICE_TABLE(of, bcm2708_spi_match);
  48880. +
  48881. +static struct platform_driver bcm2708_spi_driver = {
  48882. + .driver = {
  48883. + .name = DRV_NAME,
  48884. + .owner = THIS_MODULE,
  48885. + .of_match_table = bcm2708_spi_match,
  48886. + },
  48887. + .probe = bcm2708_spi_probe,
  48888. + .remove = bcm2708_spi_remove,
  48889. +};
  48890. +
  48891. +
  48892. +static int __init bcm2708_spi_init(void)
  48893. +{
  48894. + return platform_driver_probe(&bcm2708_spi_driver, bcm2708_spi_probe);
  48895. +}
  48896. +module_init(bcm2708_spi_init);
  48897. +
  48898. +static void __exit bcm2708_spi_exit(void)
  48899. +{
  48900. + platform_driver_unregister(&bcm2708_spi_driver);
  48901. +}
  48902. +module_exit(bcm2708_spi_exit);
  48903. +
  48904. +
  48905. +//module_platform_driver(bcm2708_spi_driver);
  48906. +
  48907. +MODULE_DESCRIPTION("SPI controller driver for Broadcom BCM2708");
  48908. +MODULE_AUTHOR("Chris Boot <bootc@bootc.net>");
  48909. +MODULE_LICENSE("GPL v2");
  48910. +MODULE_ALIAS("platform:" DRV_NAME);
  48911. diff -Nur linux-3.18.8/drivers/staging/fbtft/fb_agm1264k-fl.c linux-rpi/drivers/staging/fbtft/fb_agm1264k-fl.c
  48912. --- linux-3.18.8/drivers/staging/fbtft/fb_agm1264k-fl.c 1970-01-01 01:00:00.000000000 +0100
  48913. +++ linux-rpi/drivers/staging/fbtft/fb_agm1264k-fl.c 2015-03-05 14:40:16.341715808 +0100
  48914. @@ -0,0 +1,462 @@
  48915. +/*
  48916. + * FB driver for Two KS0108 LCD controllers in AGM1264K-FL display
  48917. + *
  48918. + * Copyright (C) 2014 ololoshka2871
  48919. + *
  48920. + * This program is free software; you can redistribute it and/or modify
  48921. + * it under the terms of the GNU General Public License as published by
  48922. + * the Free Software Foundation; either version 2 of the License, or
  48923. + * (at your option) any later version.
  48924. + *
  48925. + * This program is distributed in the hope that it will be useful,
  48926. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  48927. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  48928. + * GNU General Public License for more details.
  48929. + */
  48930. +
  48931. +#include <linux/module.h>
  48932. +#include <linux/kernel.h>
  48933. +#include <linux/init.h>
  48934. +#include <linux/gpio.h>
  48935. +#include <linux/delay.h>
  48936. +#include <linux/slab.h>
  48937. +
  48938. +#include "fbtft.h"
  48939. +
  48940. +/* Uncomment text line to use negative image on display */
  48941. +/*#define NEGATIVE*/
  48942. +
  48943. +#define WHITE 0xff
  48944. +#define BLACK 0
  48945. +
  48946. +#define DRVNAME "fb_agm1264k-fl"
  48947. +#define WIDTH 64
  48948. +#define HEIGHT 64
  48949. +#define TOTALWIDTH (WIDTH * 2) /* because 2 x ks0108 in one display */
  48950. +#define FPS 20
  48951. +
  48952. +#define EPIN gpio.wr
  48953. +#define RS gpio.dc
  48954. +#define RW gpio.aux[2]
  48955. +#define CS0 gpio.aux[0]
  48956. +#define CS1 gpio.aux[1]
  48957. +
  48958. +
  48959. +/* diffusing error (“Floyd-Steinberg”) */
  48960. +#define DIFFUSING_MATRIX_WIDTH 2
  48961. +#define DIFFUSING_MATRIX_HEIGHT 2
  48962. +
  48963. +static const signed char
  48964. +diffusing_matrix[DIFFUSING_MATRIX_WIDTH][DIFFUSING_MATRIX_HEIGHT] = {
  48965. + {-1, 3},
  48966. + {3, 2},
  48967. +};
  48968. +
  48969. +static const unsigned char gamma_correction_table[] = {
  48970. +0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1,
  48971. +1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6,
  48972. +6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 11, 11, 11, 12, 12, 13,
  48973. +13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21,
  48974. +22, 22, 23, 23, 24, 25, 25, 26, 26, 27, 28, 28, 29, 30, 30, 31, 32,
  48975. +33, 33, 34, 35, 35, 36, 37, 38, 39, 39, 40, 41, 42, 43, 43, 44, 45,
  48976. +46, 47, 48, 49, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61,
  48977. +62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 73, 74, 75, 76, 77, 78, 79, 81,
  48978. +82, 83, 84, 85, 87, 88, 89, 90, 91, 93, 94, 95, 97, 98, 99, 100, 102,
  48979. +103, 105, 106, 107, 109, 110, 111, 113, 114, 116, 117, 119, 120, 121,
  48980. +123, 124, 126, 127, 129, 130, 132, 133, 135, 137, 138, 140, 141, 143,
  48981. +145, 146, 148, 149, 151, 153, 154, 156, 158, 159, 161, 163, 165, 166,
  48982. +168, 170, 172, 173, 175, 177, 179, 181, 182, 184, 186, 188, 190, 192,
  48983. +194, 196, 197, 199, 201, 203, 205, 207, 209, 211, 213, 215, 217, 219,
  48984. +221, 223, 225, 227, 229, 231, 234, 236, 238, 240, 242, 244, 246, 248,
  48985. +251, 253, 255
  48986. +};
  48987. +
  48988. +static int init_display(struct fbtft_par *par)
  48989. +{
  48990. + u8 i;
  48991. +
  48992. + fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
  48993. +
  48994. + par->fbtftops.reset(par);
  48995. +
  48996. + for (i = 0; i < 2; ++i) {
  48997. + write_reg(par, i, 0x3f); /* display on */
  48998. + write_reg(par, i, 0x40); /* set x to 0 */
  48999. + write_reg(par, i, 0xb0); /* set page to 0 */
  49000. + write_reg(par, i, 0xc0); /* set start line to 0 */
  49001. + }
  49002. +
  49003. + return 0;
  49004. +}
  49005. +
  49006. +static void reset(struct fbtft_par *par)
  49007. +{
  49008. + if (par->gpio.reset == -1)
  49009. + return;
  49010. +
  49011. + fbtft_dev_dbg(DEBUG_RESET, par, par->info->device, "%s()\n", __func__);
  49012. +
  49013. + gpio_set_value(par->gpio.reset, 0);
  49014. + udelay(20);
  49015. + gpio_set_value(par->gpio.reset, 1);
  49016. + mdelay(120);
  49017. +}
  49018. +
  49019. +/* Check if all necessary GPIOS defined */
  49020. +static int verify_gpios(struct fbtft_par *par)
  49021. +{
  49022. + int i;
  49023. +
  49024. + fbtft_dev_dbg(DEBUG_VERIFY_GPIOS, par, par->info->device,
  49025. + "%s()\n", __func__);
  49026. +
  49027. + if (par->EPIN < 0) {
  49028. + dev_err(par->info->device,
  49029. + "Missing info about 'wr' (aka E) gpio. Aborting.\n");
  49030. + return -EINVAL;
  49031. + }
  49032. + for (i = 0; i < 8; ++i) {
  49033. + if (par->gpio.db[i] < 0) {
  49034. + dev_err(par->info->device,
  49035. + "Missing info about 'db[%i]' gpio. Aborting.\n",
  49036. + i);
  49037. + return -EINVAL;
  49038. + }
  49039. + }
  49040. + if (par->CS0 < 0) {
  49041. + dev_err(par->info->device,
  49042. + "Missing info about 'cs0' gpio. Aborting.\n");
  49043. + return -EINVAL;
  49044. + }
  49045. + if (par->CS1 < 0) {
  49046. + dev_err(par->info->device,
  49047. + "Missing info about 'cs1' gpio. Aborting.\n");
  49048. + return -EINVAL;
  49049. + }
  49050. + if (par->RW < 0) {
  49051. + dev_err(par->info->device,
  49052. + "Missing info about 'rw' gpio. Aborting.\n");
  49053. + return -EINVAL;
  49054. + }
  49055. +
  49056. + return 0;
  49057. +}
  49058. +
  49059. +static unsigned long
  49060. +request_gpios_match(struct fbtft_par *par, const struct fbtft_gpio *gpio)
  49061. +{
  49062. + fbtft_dev_dbg(DEBUG_REQUEST_GPIOS_MATCH, par, par->info->device,
  49063. + "%s('%s')\n", __func__, gpio->name);
  49064. +
  49065. + if (strcasecmp(gpio->name, "wr") == 0) {
  49066. + /* left ks0108 E pin */
  49067. + par->EPIN = gpio->gpio;
  49068. + return GPIOF_OUT_INIT_LOW;
  49069. + } else if (strcasecmp(gpio->name, "cs0") == 0) {
  49070. + /* left ks0108 controller pin */
  49071. + par->CS0 = gpio->gpio;
  49072. + return GPIOF_OUT_INIT_HIGH;
  49073. + } else if (strcasecmp(gpio->name, "cs1") == 0) {
  49074. + /* right ks0108 controller pin */
  49075. + par->CS1 = gpio->gpio;
  49076. + return GPIOF_OUT_INIT_HIGH;
  49077. + }
  49078. +
  49079. + /* if write (rw = 0) e(1->0) perform write */
  49080. + /* if read (rw = 1) e(0->1) set data on D0-7*/
  49081. + else if (strcasecmp(gpio->name, "rw") == 0) {
  49082. + par->RW = gpio->gpio;
  49083. + return GPIOF_OUT_INIT_LOW;
  49084. + }
  49085. +
  49086. + return FBTFT_GPIO_NO_MATCH;
  49087. +}
  49088. +
  49089. +/* This function oses to enter commands
  49090. + * first byte - destination controller 0 or 1
  49091. + * folowing - commands
  49092. + */
  49093. +static void write_reg8_bus8(struct fbtft_par *par, int len, ...)
  49094. +{
  49095. + va_list args;
  49096. + int i, ret;
  49097. + u8 *buf = (u8 *)par->buf;
  49098. +
  49099. + if (unlikely(par->debug & DEBUG_WRITE_REGISTER)) {
  49100. + va_start(args, len);
  49101. + for (i = 0; i < len; i++)
  49102. + buf[i] = (u8)va_arg(args, unsigned int);
  49103. +
  49104. + va_end(args);
  49105. + fbtft_par_dbg_hex(DEBUG_WRITE_REGISTER, par,
  49106. + par->info->device, u8, buf, len, "%s: ", __func__);
  49107. + }
  49108. +
  49109. + va_start(args, len);
  49110. +
  49111. + *buf = (u8)va_arg(args, unsigned int);
  49112. +
  49113. + if (*buf > 1) {
  49114. + va_end(args);
  49115. + dev_err(par->info->device, "%s: Incorrect chip sellect request (%d)\n",
  49116. + __func__, *buf);
  49117. + return;
  49118. + }
  49119. +
  49120. + /* select chip */
  49121. + if (*buf) {
  49122. + /* cs1 */
  49123. + gpio_set_value(par->CS0, 1);
  49124. + gpio_set_value(par->CS1, 0);
  49125. + } else {
  49126. + /* cs0 */
  49127. + gpio_set_value(par->CS0, 0);
  49128. + gpio_set_value(par->CS1, 1);
  49129. + }
  49130. +
  49131. + gpio_set_value(par->RS, 0); /* RS->0 (command mode) */
  49132. + len--;
  49133. +
  49134. + if (len) {
  49135. + i = len;
  49136. + while (i--)
  49137. + *buf++ = (u8)va_arg(args, unsigned int);
  49138. + ret = par->fbtftops.write(par, par->buf, len * (sizeof(u8)));
  49139. + if (ret < 0) {
  49140. + va_end(args);
  49141. + dev_err(par->info->device, "%s: write() failed and returned %d\n",
  49142. + __func__, ret);
  49143. + return;
  49144. + }
  49145. + }
  49146. +
  49147. + va_end(args);
  49148. +}
  49149. +
  49150. +static struct
  49151. +{
  49152. + int xs, ys_page, xe, ye_page;
  49153. +} addr_win;
  49154. +
  49155. +/* save display writing zone */
  49156. +static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
  49157. +{
  49158. + addr_win.xs = xs;
  49159. + addr_win.ys_page = ys / 8;
  49160. + addr_win.xe = xe;
  49161. + addr_win.ye_page = ye / 8;
  49162. +
  49163. + fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par,
  49164. + "%s(xs=%d, ys_page=%d, xe=%d, ye_page=%d)\n", __func__,
  49165. + addr_win.xs, addr_win.ys_page, addr_win.xe, addr_win.ye_page);
  49166. +}
  49167. +
  49168. +static void
  49169. +construct_line_bitmap(struct fbtft_par *par, u8 *dest, signed short *src,
  49170. + int xs, int xe, int y)
  49171. +{
  49172. + int x, i;
  49173. +
  49174. + for (x = xs; x < xe; ++x) {
  49175. + u8 res = 0;
  49176. +
  49177. + for (i = 0; i < 8; i++)
  49178. + if (src[(y * 8 + i) * par->info->var.xres + x])
  49179. + res |= 1 << i;
  49180. +#ifdef NEGATIVE
  49181. + *dest++ = res;
  49182. +#else
  49183. + *dest++ = ~res;
  49184. +#endif
  49185. + }
  49186. +}
  49187. +
  49188. +static int write_vmem(struct fbtft_par *par, size_t offset, size_t len)
  49189. +{
  49190. + u16 *vmem16 = (u16 *)par->info->screen_base;
  49191. + u8 *buf = par->txbuf.buf;
  49192. + int x, y;
  49193. + int ret = 0;
  49194. +
  49195. + /* buffer to convert RGB565 -> grayscale16 -> Ditherd image 1bpp */
  49196. + signed short *convert_buf = kmalloc(par->info->var.xres *
  49197. + par->info->var.yres * sizeof(signed short), GFP_NOIO);
  49198. +
  49199. + fbtft_par_dbg(DEBUG_WRITE_VMEM, par, "%s()\n", __func__);
  49200. +
  49201. + /* converting to grayscale16 */
  49202. + for (x = 0; x < par->info->var.xres; ++x)
  49203. + for (y = 0; y < par->info->var.yres; ++y) {
  49204. + u16 pixel = vmem16[y * par->info->var.xres + x];
  49205. + u16 b = pixel & 0x1f;
  49206. + u16 g = (pixel & (0x3f << 5)) >> 5;
  49207. + u16 r = (pixel & (0x1f << (5 + 6))) >> (5 + 6);
  49208. +
  49209. + pixel = (299 * r + 587 * g + 114 * b) / 200;
  49210. + if (pixel > 255)
  49211. + pixel = 255;
  49212. +
  49213. + /* gamma-correction by table */
  49214. + convert_buf[y * par->info->var.xres + x] =
  49215. + (signed short)gamma_correction_table[pixel];
  49216. + }
  49217. +
  49218. + /* Image Dithering */
  49219. + for (x = 0; x < par->info->var.xres; ++x)
  49220. + for (y = 0; y < par->info->var.yres; ++y) {
  49221. + signed short pixel =
  49222. + convert_buf[y * par->info->var.xres + x];
  49223. + signed short error_b = pixel - BLACK;
  49224. + signed short error_w = pixel - WHITE;
  49225. + signed short error;
  49226. + u16 i, j;
  49227. +
  49228. + /* what color close? */
  49229. + if (abs(error_b) >= abs(error_w)) {
  49230. + /* white */
  49231. + error = error_w;
  49232. + pixel = 0xff;
  49233. + } else {
  49234. + /* black */
  49235. + error = error_b;
  49236. + pixel = 0;
  49237. + }
  49238. +
  49239. + error /= 8;
  49240. +
  49241. + /* diffusion matrix row */
  49242. + for (i = 0; i < DIFFUSING_MATRIX_WIDTH; ++i)
  49243. + /* diffusion matrix column */
  49244. + for (j = 0; j < DIFFUSING_MATRIX_HEIGHT; ++j) {
  49245. + signed short *write_pos;
  49246. + signed char coeff;
  49247. +
  49248. + /* skip pixels out of zone */
  49249. + if (x + i < 0 ||
  49250. + x + i >= par->info->var.xres
  49251. + || y + j >= par->info->var.yres)
  49252. + continue;
  49253. + write_pos = &convert_buf[
  49254. + (y + j) * par->info->var.xres +
  49255. + x + i];
  49256. + coeff = diffusing_matrix[i][j];
  49257. + if (coeff == -1)
  49258. + /* pixel itself */
  49259. + *write_pos = pixel;
  49260. + else {
  49261. + signed short p = *write_pos +
  49262. + error * coeff;
  49263. +
  49264. + if (p > WHITE)
  49265. + p = WHITE;
  49266. + if (p < BLACK)
  49267. + p = BLACK;
  49268. + *write_pos = p;
  49269. + }
  49270. + }
  49271. + }
  49272. +
  49273. + /* 1 string = 2 pages */
  49274. + for (y = addr_win.ys_page; y <= addr_win.ye_page; ++y) {
  49275. + /* left half of display */
  49276. + if (addr_win.xs < par->info->var.xres / 2) {
  49277. + construct_line_bitmap(par, buf, convert_buf,
  49278. + addr_win.xs, par->info->var.xres / 2, y);
  49279. +
  49280. + len = par->info->var.xres / 2 - addr_win.xs;
  49281. +
  49282. + /* select left side (sc0)
  49283. + * set addr
  49284. + */
  49285. + write_reg(par, 0x00, (1 << 6) | (u8)addr_win.xs);
  49286. + write_reg(par, 0x00, (0x17 << 3) | (u8)y);
  49287. +
  49288. + /* write bitmap */
  49289. + gpio_set_value(par->RS, 1); /* RS->1 (data mode) */
  49290. + ret = par->fbtftops.write(par, buf, len);
  49291. + if (ret < 0)
  49292. + dev_err(par->info->device,
  49293. + "%s: write failed and returned: %d\n",
  49294. + __func__, ret);
  49295. + }
  49296. + /* right half of display */
  49297. + if (addr_win.xe >= par->info->var.xres / 2) {
  49298. + construct_line_bitmap(par, buf,
  49299. + convert_buf, par->info->var.xres / 2,
  49300. + addr_win.xe + 1, y);
  49301. +
  49302. + len = addr_win.xe + 1 - par->info->var.xres / 2;
  49303. +
  49304. + /* select right side (sc1)
  49305. + * set addr
  49306. + */
  49307. + write_reg(par, 0x01, (1 << 6));
  49308. + write_reg(par, 0x01, (0x17 << 3) | (u8)y);
  49309. +
  49310. + /* write bitmap */
  49311. + gpio_set_value(par->RS, 1); /* RS->1 (data mode) */
  49312. + par->fbtftops.write(par, buf, len);
  49313. + if (ret < 0)
  49314. + dev_err(par->info->device,
  49315. + "%s: write failed and returned: %d\n",
  49316. + __func__, ret);
  49317. + }
  49318. + }
  49319. + kfree(convert_buf);
  49320. +
  49321. + gpio_set_value(par->CS0, 1);
  49322. + gpio_set_value(par->CS1, 1);
  49323. +
  49324. + return ret;
  49325. +}
  49326. +
  49327. +static int write(struct fbtft_par *par, void *buf, size_t len)
  49328. +{
  49329. + fbtft_par_dbg_hex(DEBUG_WRITE, par, par->info->device, u8, buf, len,
  49330. + "%s(len=%d): ", __func__, len);
  49331. +
  49332. + gpio_set_value(par->RW, 0); /* set write mode */
  49333. +
  49334. +
  49335. + while (len--) {
  49336. + u8 i, data;
  49337. +
  49338. + data = *(u8 *) buf++;
  49339. +
  49340. + /* set data bus */
  49341. + for (i = 0; i < 8; ++i)
  49342. + gpio_set_value(par->gpio.db[i], data & (1 << i));
  49343. + /* set E */
  49344. + gpio_set_value(par->EPIN, 1);
  49345. + udelay(5);
  49346. + /* unset E - write */
  49347. + gpio_set_value(par->EPIN, 0);
  49348. + udelay(1);
  49349. + }
  49350. +
  49351. + return 0;
  49352. +}
  49353. +
  49354. +static struct fbtft_display display = {
  49355. + .regwidth = 8,
  49356. + .width = TOTALWIDTH,
  49357. + .height = HEIGHT,
  49358. + .fps = FPS,
  49359. + .fbtftops = {
  49360. + .init_display = init_display,
  49361. + .set_addr_win = set_addr_win,
  49362. + .verify_gpios = verify_gpios,
  49363. + .request_gpios_match = request_gpios_match,
  49364. + .reset = reset,
  49365. + .write = write,
  49366. + .write_register = write_reg8_bus8,
  49367. + .write_vmem = write_vmem,
  49368. + },
  49369. +};
  49370. +FBTFT_REGISTER_DRIVER(DRVNAME, "displaytronic,fb_agm1264k-fl", &display);
  49371. +
  49372. +MODULE_ALIAS("platform:" DRVNAME);
  49373. +
  49374. +MODULE_DESCRIPTION("Two KS0108 LCD controllers in AGM1264K-FL display");
  49375. +MODULE_AUTHOR("ololoshka2871");
  49376. +MODULE_LICENSE("GPL");
  49377. diff -Nur linux-3.18.8/drivers/staging/fbtft/fb_bd663474.c linux-rpi/drivers/staging/fbtft/fb_bd663474.c
  49378. --- linux-3.18.8/drivers/staging/fbtft/fb_bd663474.c 1970-01-01 01:00:00.000000000 +0100
  49379. +++ linux-rpi/drivers/staging/fbtft/fb_bd663474.c 2015-03-05 14:40:16.341715808 +0100
  49380. @@ -0,0 +1,193 @@
  49381. +/*
  49382. + * FB driver for the uPD161704 LCD Controller
  49383. + *
  49384. + * Copyright (C) 2014 Seong-Woo Kim
  49385. + *
  49386. + * Based on fb_ili9325.c by Noralf Tronnes
  49387. + * Based on ili9325.c by Jeroen Domburg
  49388. + * Init code from UTFT library by Henning Karlsen
  49389. + *
  49390. + * This program is free software; you can redistribute it and/or modify
  49391. + * it under the terms of the GNU General Public License as published by
  49392. + * the Free Software Foundation; either version 2 of the License, or
  49393. + * (at your option) any later version.
  49394. + *
  49395. + * This program is distributed in the hope that it will be useful,
  49396. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  49397. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  49398. + * GNU General Public License for more details.
  49399. + *
  49400. + * You should have received a copy of the GNU General Public License
  49401. + * along with this program; if not, write to the Free Software
  49402. + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  49403. + */
  49404. +
  49405. +#include <linux/module.h>
  49406. +#include <linux/kernel.h>
  49407. +#include <linux/init.h>
  49408. +#include <linux/gpio.h>
  49409. +#include <linux/delay.h>
  49410. +
  49411. +#include "fbtft.h"
  49412. +
  49413. +#define DRVNAME "fb_bd663474"
  49414. +#define WIDTH 240
  49415. +#define HEIGHT 320
  49416. +#define BPP 16
  49417. +
  49418. +static int init_display(struct fbtft_par *par)
  49419. +{
  49420. + fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
  49421. +
  49422. + if (par->gpio.cs != -1)
  49423. + gpio_set_value(par->gpio.cs, 0); /* Activate chip */
  49424. +
  49425. + par->fbtftops.reset(par);
  49426. +
  49427. + /* Initialization sequence from Lib_UTFT */
  49428. +
  49429. + /* oscillator start */
  49430. + write_reg(par, 0x000,0x0001); /*oscillator 0: stop, 1: operation */
  49431. + mdelay(10);
  49432. +
  49433. + /* Power settings */
  49434. + write_reg(par, 0x100, 0x0000 ); /* power supply setup */
  49435. + write_reg(par, 0x101, 0x0000 );
  49436. + write_reg(par, 0x102, 0x3110 );
  49437. + write_reg(par, 0x103, 0xe200 );
  49438. + write_reg(par, 0x110, 0x009d );
  49439. + write_reg(par, 0x111, 0x0022 );
  49440. + write_reg(par, 0x100, 0x0120 );
  49441. + mdelay( 20 );
  49442. +
  49443. + write_reg(par, 0x100, 0x3120 );
  49444. + mdelay( 80 );
  49445. + /* Display control */
  49446. + write_reg(par, 0x001, 0x0100 );
  49447. + write_reg(par, 0x002, 0x0000 );
  49448. + write_reg(par, 0x003, 0x1230 );
  49449. + write_reg(par, 0x006, 0x0000 );
  49450. + write_reg(par, 0x007, 0x0101 );
  49451. + write_reg(par, 0x008, 0x0808 );
  49452. + write_reg(par, 0x009, 0x0000 );
  49453. + write_reg(par, 0x00b, 0x0000 );
  49454. + write_reg(par, 0x00c, 0x0000 );
  49455. + write_reg(par, 0x00d, 0x0018 );
  49456. + /* LTPS control settings */
  49457. + write_reg(par, 0x012, 0x0000 );
  49458. + write_reg(par, 0x013, 0x0000 );
  49459. + write_reg(par, 0x018, 0x0000 );
  49460. + write_reg(par, 0x019, 0x0000 );
  49461. +
  49462. + write_reg(par, 0x203, 0x0000 );
  49463. + write_reg(par, 0x204, 0x0000 );
  49464. +
  49465. + write_reg(par, 0x210, 0x0000 );
  49466. + write_reg(par, 0x211, 0x00ef );
  49467. + write_reg(par, 0x212, 0x0000 );
  49468. + write_reg(par, 0x213, 0x013f );
  49469. + write_reg(par, 0x214, 0x0000 );
  49470. + write_reg(par, 0x215, 0x0000 );
  49471. + write_reg(par, 0x216, 0x0000 );
  49472. + write_reg(par, 0x217, 0x0000 );
  49473. +
  49474. + /* Gray scale settings */
  49475. + write_reg(par, 0x300, 0x5343);
  49476. + write_reg(par, 0x301, 0x1021);
  49477. + write_reg(par, 0x302, 0x0003);
  49478. + write_reg(par, 0x303, 0x0011);
  49479. + write_reg(par, 0x304, 0x050a);
  49480. + write_reg(par, 0x305, 0x4342);
  49481. + write_reg(par, 0x306, 0x1100);
  49482. + write_reg(par, 0x307, 0x0003);
  49483. + write_reg(par, 0x308, 0x1201);
  49484. + write_reg(par, 0x309, 0x050a);
  49485. +
  49486. + /* RAM access settings */
  49487. + write_reg(par, 0x400, 0x4027 );
  49488. + write_reg(par, 0x401, 0x0000 );
  49489. + write_reg(par, 0x402, 0x0000 ); /* First screen drive position (1) */
  49490. + write_reg(par, 0x403, 0x013f ); /* First screen drive position (2) */
  49491. + write_reg(par, 0x404, 0x0000 );
  49492. +
  49493. + write_reg(par, 0x200, 0x0000 );
  49494. + write_reg(par, 0x201, 0x0000 );
  49495. + write_reg(par, 0x100, 0x7120 );
  49496. + write_reg(par, 0x007, 0x0103 );
  49497. + mdelay( 10 );
  49498. + write_reg(par, 0x007, 0x0113 );
  49499. +
  49500. + return 0;
  49501. +}
  49502. +
  49503. +static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
  49504. +{
  49505. + fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par,
  49506. + "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye);
  49507. + switch (par->info->var.rotate) {
  49508. + /* R200h = Horizontal GRAM Start Address */
  49509. + /* R201h = Vertical GRAM Start Address */
  49510. + case 0:
  49511. + write_reg(par, 0x0200, xs);
  49512. + write_reg(par, 0x0201, ys);
  49513. + break;
  49514. + case 180:
  49515. + write_reg(par, 0x0200, WIDTH - 1 - xs);
  49516. + write_reg(par, 0x0201, HEIGHT - 1 - ys);
  49517. + break;
  49518. + case 270:
  49519. + write_reg(par, 0x0200, WIDTH - 1 - ys);
  49520. + write_reg(par, 0x0201, xs);
  49521. + break;
  49522. + case 90:
  49523. + write_reg(par, 0x0200, ys);
  49524. + write_reg(par, 0x0201, HEIGHT - 1 - xs);
  49525. + break;
  49526. + }
  49527. + write_reg(par, 0x202); /* Write Data to GRAM */
  49528. +}
  49529. +
  49530. +static int set_var(struct fbtft_par *par)
  49531. +{
  49532. + fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
  49533. +
  49534. + switch (par->info->var.rotate) {
  49535. + /* AM: GRAM update direction */
  49536. + case 0:
  49537. + write_reg(par, 0x003, 0x1230);
  49538. + break;
  49539. + case 180:
  49540. + write_reg(par, 0x003, 0x1200);
  49541. + break;
  49542. + case 270:
  49543. + write_reg(par, 0x003, 0x1228);
  49544. + break;
  49545. + case 90:
  49546. + write_reg(par, 0x003, 0x1218);
  49547. + break;
  49548. + }
  49549. +
  49550. + return 0;
  49551. +}
  49552. +
  49553. +static struct fbtft_display display = {
  49554. + .regwidth = 16,
  49555. + .width = WIDTH,
  49556. + .height = HEIGHT,
  49557. + .bpp = BPP,
  49558. + .fbtftops = {
  49559. + .init_display = init_display,
  49560. + .set_addr_win = set_addr_win,
  49561. + .set_var = set_var,
  49562. + },
  49563. +};
  49564. +FBTFT_REGISTER_DRIVER(DRVNAME, "hitachi,bd663474", &display);
  49565. +
  49566. +MODULE_ALIAS("spi:" DRVNAME);
  49567. +MODULE_ALIAS("platform:" DRVNAME);
  49568. +MODULE_ALIAS("spi:bd663474");
  49569. +MODULE_ALIAS("platform:bd663474");
  49570. +
  49571. +MODULE_DESCRIPTION("FB driver for the uPD161704 LCD Controller");
  49572. +MODULE_AUTHOR("Seong-Woo Kim");
  49573. +MODULE_LICENSE("GPL");
  49574. diff -Nur linux-3.18.8/drivers/staging/fbtft/fb_hx8340bn.c linux-rpi/drivers/staging/fbtft/fb_hx8340bn.c
  49575. --- linux-3.18.8/drivers/staging/fbtft/fb_hx8340bn.c 1970-01-01 01:00:00.000000000 +0100
  49576. +++ linux-rpi/drivers/staging/fbtft/fb_hx8340bn.c 2015-03-05 14:40:16.341715808 +0100
  49577. @@ -0,0 +1,229 @@
  49578. +/*
  49579. + * FB driver for the HX8340BN LCD Controller
  49580. + *
  49581. + * This display uses 9-bit SPI: Data/Command bit + 8 data bits
  49582. + * For platforms that doesn't support 9-bit, the driver is capable
  49583. + * of emulating this using 8-bit transfer.
  49584. + * This is done by transfering eight 9-bit words in 9 bytes.
  49585. + *
  49586. + * Copyright (C) 2013 Noralf Tronnes
  49587. + *
  49588. + * This program is free software; you can redistribute it and/or modify
  49589. + * it under the terms of the GNU General Public License as published by
  49590. + * the Free Software Foundation; either version 2 of the License, or
  49591. + * (at your option) any later version.
  49592. + *
  49593. + * This program is distributed in the hope that it will be useful,
  49594. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  49595. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  49596. + * GNU General Public License for more details.
  49597. + *
  49598. + * You should have received a copy of the GNU General Public License
  49599. + * along with this program; if not, write to the Free Software
  49600. + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  49601. + */
  49602. +
  49603. +#include <linux/module.h>
  49604. +#include <linux/kernel.h>
  49605. +#include <linux/init.h>
  49606. +#include <linux/vmalloc.h>
  49607. +#include <linux/spi/spi.h>
  49608. +#include <linux/delay.h>
  49609. +
  49610. +#include "fbtft.h"
  49611. +
  49612. +#define DRVNAME "fb_hx8340bn"
  49613. +#define WIDTH 176
  49614. +#define HEIGHT 220
  49615. +#define TXBUFLEN (4 * PAGE_SIZE)
  49616. +#define DEFAULT_GAMMA "1 3 0E 5 0 2 09 0 6 1 7 1 0 2 2\n" \
  49617. + "3 3 17 8 4 7 05 7 6 0 3 1 6 0 0 "
  49618. +
  49619. +
  49620. +static bool emulate;
  49621. +module_param(emulate, bool, 0);
  49622. +MODULE_PARM_DESC(emulate, "Force emulation in 9-bit mode");
  49623. +
  49624. +
  49625. +static int init_display(struct fbtft_par *par)
  49626. +{
  49627. + fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
  49628. +
  49629. + par->fbtftops.reset(par);
  49630. +
  49631. + /* BTL221722-276L startup sequence, from datasheet */
  49632. +
  49633. + /* SETEXTCOM: Set extended command set (C1h)
  49634. + This command is used to set extended command set access enable.
  49635. + Enable: After command (C1h), must write: ffh,83h,40h */
  49636. + write_reg(par, 0xC1, 0xFF, 0x83, 0x40);
  49637. +
  49638. + /* Sleep out
  49639. + This command turns off sleep mode.
  49640. + In this mode the DC/DC converter is enabled, Internal oscillator
  49641. + is started, and panel scanning is started. */
  49642. + write_reg(par, 0x11);
  49643. + mdelay(150);
  49644. +
  49645. + /* Undoc'd register? */
  49646. + write_reg(par, 0xCA, 0x70, 0x00, 0xD9);
  49647. +
  49648. + /* SETOSC: Set Internal Oscillator (B0h)
  49649. + This command is used to set internal oscillator related settings */
  49650. + /* OSC_EN: Enable internal oscillator */
  49651. + /* Internal oscillator frequency: 125% x 2.52MHz */
  49652. + write_reg(par, 0xB0, 0x01, 0x11);
  49653. +
  49654. + /* Drive ability setting */
  49655. + write_reg(par, 0xC9, 0x90, 0x49, 0x10, 0x28, 0x28, 0x10, 0x00, 0x06);
  49656. + mdelay(20);
  49657. +
  49658. + /* SETPWCTR5: Set Power Control 5(B5h)
  49659. + This command is used to set VCOM Low and VCOM High Voltage */
  49660. + /* VCOMH 0110101 : 3.925 */
  49661. + /* VCOML 0100000 : -1.700 */
  49662. + /* 45h=69 VCOMH: "VMH" + 5d VCOML: "VMH" + 5d */
  49663. + write_reg(par, 0xB5, 0x35, 0x20, 0x45);
  49664. +
  49665. + /* SETPWCTR4: Set Power Control 4(B4h)
  49666. + VRH[4:0]: Specify the VREG1 voltage adjusting.
  49667. + VREG1 voltage is for gamma voltage setting.
  49668. + BT[2:0]: Switch the output factor of step-up circuit 2
  49669. + for VGH and VGL voltage generation. */
  49670. + write_reg(par, 0xB4, 0x33, 0x25, 0x4C);
  49671. + mdelay(10);
  49672. +
  49673. + /* Interface Pixel Format (3Ah)
  49674. + This command is used to define the format of RGB picture data,
  49675. + which is to be transfer via the system and RGB interface. */
  49676. + /* RGB interface: 16 Bit/Pixel */
  49677. + write_reg(par, 0x3A, 0x05);
  49678. +
  49679. + /* Display on (29h)
  49680. + This command is used to recover from DISPLAY OFF mode.
  49681. + Output from the Frame Memory is enabled. */
  49682. + write_reg(par, 0x29);
  49683. + mdelay(10);
  49684. +
  49685. + return 0;
  49686. +}
  49687. +
  49688. +void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
  49689. +{
  49690. + fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par,
  49691. + "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye);
  49692. +
  49693. + write_reg(par, FBTFT_CASET, 0x00, xs, 0x00, xe);
  49694. + write_reg(par, FBTFT_RASET, 0x00, ys, 0x00, ye);
  49695. + write_reg(par, FBTFT_RAMWR);
  49696. +}
  49697. +
  49698. +static int set_var(struct fbtft_par *par)
  49699. +{
  49700. + fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
  49701. +
  49702. + /* MADCTL - Memory data access control */
  49703. + /* RGB/BGR can be set with H/W pin SRGB and MADCTL BGR bit */
  49704. +#define MY (1 << 7)
  49705. +#define MX (1 << 6)
  49706. +#define MV (1 << 5)
  49707. + switch (par->info->var.rotate) {
  49708. + case 0:
  49709. + write_reg(par, 0x36, (par->bgr << 3));
  49710. + break;
  49711. + case 270:
  49712. + write_reg(par, 0x36, MX | MV | (par->bgr << 3));
  49713. + break;
  49714. + case 180:
  49715. + write_reg(par, 0x36, MX | MY | (par->bgr << 3));
  49716. + break;
  49717. + case 90:
  49718. + write_reg(par, 0x36, MY | MV | (par->bgr << 3));
  49719. + break;
  49720. + }
  49721. +
  49722. + return 0;
  49723. +}
  49724. +
  49725. +/*
  49726. + Gamma Curve selection, GC (only GC0 can be customized):
  49727. + 0 = 2.2, 1 = 1.8, 2 = 2.5, 3 = 1.0
  49728. + Gamma string format:
  49729. + OP0 OP1 CP0 CP1 CP2 CP3 CP4 MP0 MP1 MP2 MP3 MP4 MP5 CGM0 CGM1
  49730. + ON0 ON1 CN0 CN1 CN2 CN3 CN4 MN0 MN1 MN2 MN3 MN4 MN5 XXXX GC
  49731. +*/
  49732. +#define CURVE(num, idx) curves[num*par->gamma.num_values + idx]
  49733. +static int set_gamma(struct fbtft_par *par, unsigned long *curves)
  49734. +{
  49735. + unsigned long mask[] = {
  49736. + 0b1111, 0b1111, 0b11111, 0b1111, 0b1111, 0b1111, 0b11111,
  49737. + 0b111, 0b111, 0b111, 0b111, 0b111, 0b111, 0b11, 0b11,
  49738. + 0b1111, 0b1111, 0b11111, 0b1111, 0b1111, 0b1111, 0b11111,
  49739. + 0b111, 0b111, 0b111, 0b111, 0b111, 0b111, 0b0, 0b0 };
  49740. + int i, j;
  49741. +
  49742. + fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
  49743. +
  49744. + /* apply mask */
  49745. + for (i = 0; i < par->gamma.num_curves; i++)
  49746. + for (j = 0; j < par->gamma.num_values; j++)
  49747. + CURVE(i, j) &= mask[i * par->gamma.num_values + j];
  49748. +
  49749. + write_reg(par, 0x26, 1 << CURVE(1, 14)); /* Gamma Set (26h) */
  49750. +
  49751. + if (CURVE(1, 14))
  49752. + return 0; /* only GC0 can be customized */
  49753. +
  49754. + write_reg(par, 0xC2,
  49755. + (CURVE(0, 8) << 4) | CURVE(0, 7),
  49756. + (CURVE(0, 10) << 4) | CURVE(0, 9),
  49757. + (CURVE(0, 12) << 4) | CURVE(0, 11),
  49758. + CURVE(0, 2),
  49759. + (CURVE(0, 4) << 4) | CURVE(0, 3),
  49760. + CURVE(0, 5),
  49761. + CURVE(0, 6),
  49762. + (CURVE(0, 1) << 4) | CURVE(0, 0),
  49763. + (CURVE(0, 14) << 2) | CURVE(0, 13));
  49764. +
  49765. + write_reg(par, 0xC3,
  49766. + (CURVE(1, 8) << 4) | CURVE(1, 7),
  49767. + (CURVE(1, 10) << 4) | CURVE(1, 9),
  49768. + (CURVE(1, 12) << 4) | CURVE(1, 11),
  49769. + CURVE(1, 2),
  49770. + (CURVE(1, 4) << 4) | CURVE(1, 3),
  49771. + CURVE(1, 5),
  49772. + CURVE(1, 6),
  49773. + (CURVE(1, 1) << 4) | CURVE(1, 0));
  49774. +
  49775. + mdelay(10);
  49776. +
  49777. + return 0;
  49778. +}
  49779. +#undef CURVE
  49780. +
  49781. +
  49782. +static struct fbtft_display display = {
  49783. + .regwidth = 8,
  49784. + .width = WIDTH,
  49785. + .height = HEIGHT,
  49786. + .txbuflen = TXBUFLEN,
  49787. + .gamma_num = 2,
  49788. + .gamma_len = 15,
  49789. + .gamma = DEFAULT_GAMMA,
  49790. + .fbtftops = {
  49791. + .init_display = init_display,
  49792. + .set_addr_win = set_addr_win,
  49793. + .set_var = set_var,
  49794. + .set_gamma = set_gamma,
  49795. + },
  49796. +};
  49797. +FBTFT_REGISTER_DRIVER(DRVNAME, "himax,hx8340bn", &display);
  49798. +
  49799. +MODULE_ALIAS("spi:" DRVNAME);
  49800. +MODULE_ALIAS("platform:" DRVNAME);
  49801. +MODULE_ALIAS("spi:hx8340bn");
  49802. +MODULE_ALIAS("platform:hx8340bn");
  49803. +
  49804. +MODULE_DESCRIPTION("FB driver for the HX8340BN LCD Controller");
  49805. +MODULE_AUTHOR("Noralf Tronnes");
  49806. +MODULE_LICENSE("GPL");
  49807. diff -Nur linux-3.18.8/drivers/staging/fbtft/fb_hx8347d.c linux-rpi/drivers/staging/fbtft/fb_hx8347d.c
  49808. --- linux-3.18.8/drivers/staging/fbtft/fb_hx8347d.c 1970-01-01 01:00:00.000000000 +0100
  49809. +++ linux-rpi/drivers/staging/fbtft/fb_hx8347d.c 2015-03-05 14:40:16.341715808 +0100
  49810. @@ -0,0 +1,181 @@
  49811. +/*
  49812. + * FB driver for the HX8347D LCD Controller
  49813. + *
  49814. + * Copyright (C) 2013 Christian Vogelgsang
  49815. + *
  49816. + * Based on driver code found here: https://github.com/watterott/r61505u-Adapter
  49817. + *
  49818. + * This program is free software; you can redistribute it and/or modify
  49819. + * it under the terms of the GNU General Public License as published by
  49820. + * the Free Software Foundation; either version 2 of the License, or
  49821. + * (at your option) any later version.
  49822. + *
  49823. + * This program is distributed in the hope that it will be useful,
  49824. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  49825. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  49826. + * GNU General Public License for more details.
  49827. + *
  49828. + * You should have received a copy of the GNU General Public License
  49829. + * along with this program; if not, write to the Free Software
  49830. + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  49831. + */
  49832. +
  49833. +#include <linux/module.h>
  49834. +#include <linux/kernel.h>
  49835. +#include <linux/init.h>
  49836. +#include <linux/delay.h>
  49837. +
  49838. +#include "fbtft.h"
  49839. +
  49840. +#define DRVNAME "fb_hx8347d"
  49841. +#define WIDTH 320
  49842. +#define HEIGHT 240
  49843. +#define DEFAULT_GAMMA "0 0 0 0 0 0 0 0 0 0 0 0 0 0\n" \
  49844. + "0 0 0 0 0 0 0 0 0 0 0 0 0 0"
  49845. +
  49846. +
  49847. +static int init_display(struct fbtft_par *par)
  49848. +{
  49849. + fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
  49850. +
  49851. + par->fbtftops.reset(par);
  49852. +
  49853. + /* driving ability */
  49854. + write_reg(par, 0xEA, 0x00);
  49855. + write_reg(par, 0xEB, 0x20);
  49856. + write_reg(par, 0xEC, 0x0C);
  49857. + write_reg(par, 0xED, 0xC4);
  49858. + write_reg(par, 0xE8, 0x40);
  49859. + write_reg(par, 0xE9, 0x38);
  49860. + write_reg(par, 0xF1, 0x01);
  49861. + write_reg(par, 0xF2, 0x10);
  49862. + write_reg(par, 0x27, 0xA3);
  49863. +
  49864. + /* power voltage */
  49865. + write_reg(par, 0x1B, 0x1B);
  49866. + write_reg(par, 0x1A, 0x01);
  49867. + write_reg(par, 0x24, 0x2F);
  49868. + write_reg(par, 0x25, 0x57);
  49869. +
  49870. + /* VCOM offset */
  49871. + write_reg(par, 0x23, 0x8D); /* for flicker adjust */
  49872. +
  49873. + /* power on */
  49874. + write_reg(par, 0x18, 0x36);
  49875. + write_reg(par, 0x19, 0x01); /* start osc */
  49876. + write_reg(par, 0x01, 0x00); /* wakeup */
  49877. + write_reg(par, 0x1F, 0x88);
  49878. + mdelay(5);
  49879. + write_reg(par, 0x1F, 0x80);
  49880. + mdelay(5);
  49881. + write_reg(par, 0x1F, 0x90);
  49882. + mdelay(5);
  49883. + write_reg(par, 0x1F, 0xD0);
  49884. + mdelay(5);
  49885. +
  49886. + /* color selection */
  49887. + write_reg(par, 0x17, 0x05); /* 65k */
  49888. +
  49889. + /*panel characteristic */
  49890. + write_reg(par, 0x36, 0x00);
  49891. +
  49892. + /*display on */
  49893. + write_reg(par, 0x28, 0x38);
  49894. + mdelay(40);
  49895. + write_reg(par, 0x28, 0x3C);
  49896. +
  49897. + /* orientation */
  49898. + write_reg(par, 0x16, 0x60 | (par->bgr << 3));
  49899. +
  49900. + return 0;
  49901. +}
  49902. +
  49903. +static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
  49904. +{
  49905. + fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par,
  49906. + "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye);
  49907. +
  49908. + write_reg(par, 0x02, (xs >> 8) & 0xFF);
  49909. + write_reg(par, 0x03, xs & 0xFF);
  49910. + write_reg(par, 0x04, (xe >> 8) & 0xFF);
  49911. + write_reg(par, 0x05, xe & 0xFF);
  49912. + write_reg(par, 0x06, (ys >> 8) & 0xFF);
  49913. + write_reg(par, 0x07, ys & 0xFF);
  49914. + write_reg(par, 0x08, (ye >> 8) & 0xFF);
  49915. + write_reg(par, 0x09, ye & 0xFF);
  49916. + write_reg(par, 0x22);
  49917. +}
  49918. +
  49919. +/*
  49920. + Gamma string format:
  49921. + VRP0 VRP1 VRP2 VRP3 VRP4 VRP5 PRP0 PRP1 PKP0 PKP1 PKP2 PKP3 PKP4 CGM
  49922. + VRN0 VRN1 VRN2 VRN3 VRN4 VRN5 PRN0 PRN1 PKN0 PKN1 PKN2 PKN3 PKN4 CGM
  49923. +*/
  49924. +#define CURVE(num, idx) curves[num*par->gamma.num_values + idx]
  49925. +static int set_gamma(struct fbtft_par *par, unsigned long *curves)
  49926. +{
  49927. + unsigned long mask[] = {
  49928. + 0b111111, 0b111111, 0b111111, 0b111111, 0b111111, 0b111111,
  49929. + 0b1111111, 0b1111111,
  49930. + 0b11111, 0b11111, 0b11111, 0b11111, 0b11111,
  49931. + 0b1111};
  49932. + int i, j;
  49933. + int acc = 0;
  49934. +
  49935. + fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
  49936. +
  49937. + /* apply mask */
  49938. + for (i = 0; i < par->gamma.num_curves; i++)
  49939. + for (j = 0; j < par->gamma.num_values; j++) {
  49940. + acc += CURVE(i, j);
  49941. + CURVE(i, j) &= mask[j];
  49942. + }
  49943. +
  49944. + if (acc == 0) /* skip if all values are zero */
  49945. + return 0;
  49946. +
  49947. + for (i = 0; i < par->gamma.num_curves; i++) {
  49948. + write_reg(par, 0x40 + (i * 0x10), CURVE(i, 0));
  49949. + write_reg(par, 0x41 + (i * 0x10), CURVE(i, 1));
  49950. + write_reg(par, 0x42 + (i * 0x10), CURVE(i, 2));
  49951. + write_reg(par, 0x43 + (i * 0x10), CURVE(i, 3));
  49952. + write_reg(par, 0x44 + (i * 0x10), CURVE(i, 4));
  49953. + write_reg(par, 0x45 + (i * 0x10), CURVE(i, 5));
  49954. + write_reg(par, 0x46 + (i * 0x10), CURVE(i, 6));
  49955. + write_reg(par, 0x47 + (i * 0x10), CURVE(i, 7));
  49956. + write_reg(par, 0x48 + (i * 0x10), CURVE(i, 8));
  49957. + write_reg(par, 0x49 + (i * 0x10), CURVE(i, 9));
  49958. + write_reg(par, 0x4A + (i * 0x10), CURVE(i, 10));
  49959. + write_reg(par, 0x4B + (i * 0x10), CURVE(i, 11));
  49960. + write_reg(par, 0x4C + (i * 0x10), CURVE(i, 12));
  49961. + }
  49962. + write_reg(par, 0x5D, (CURVE(1, 0) << 4) | CURVE(0, 0));
  49963. +
  49964. + return 0;
  49965. +}
  49966. +#undef CURVE
  49967. +
  49968. +
  49969. +static struct fbtft_display display = {
  49970. + .regwidth = 8,
  49971. + .width = WIDTH,
  49972. + .height = HEIGHT,
  49973. + .gamma_num = 2,
  49974. + .gamma_len = 14,
  49975. + .gamma = DEFAULT_GAMMA,
  49976. + .fbtftops = {
  49977. + .init_display = init_display,
  49978. + .set_addr_win = set_addr_win,
  49979. + .set_gamma = set_gamma,
  49980. + },
  49981. +};
  49982. +FBTFT_REGISTER_DRIVER(DRVNAME, "himax,hx8347d", &display);
  49983. +
  49984. +MODULE_ALIAS("spi:" DRVNAME);
  49985. +MODULE_ALIAS("platform:" DRVNAME);
  49986. +MODULE_ALIAS("spi:hx8347d");
  49987. +MODULE_ALIAS("platform:hx8347d");
  49988. +
  49989. +MODULE_DESCRIPTION("FB driver for the HX8347D LCD Controller");
  49990. +MODULE_AUTHOR("Christian Vogelgsang");
  49991. +MODULE_LICENSE("GPL");
  49992. diff -Nur linux-3.18.8/drivers/staging/fbtft/fb_hx8353d.c linux-rpi/drivers/staging/fbtft/fb_hx8353d.c
  49993. --- linux-3.18.8/drivers/staging/fbtft/fb_hx8353d.c 1970-01-01 01:00:00.000000000 +0100
  49994. +++ linux-rpi/drivers/staging/fbtft/fb_hx8353d.c 2015-03-05 14:40:16.341715808 +0100
  49995. @@ -0,0 +1,166 @@
  49996. +/*
  49997. + * FB driver for the HX8353D LCD Controller
  49998. + *
  49999. + * Copyright (c) 2014 Petr Olivka
  50000. + * Copyright (c) 2013 Noralf Tronnes
  50001. + *
  50002. + * This program is free software; you can redistribute it and/or modify
  50003. + * it under the terms of the GNU General Public License as published by
  50004. + * the Free Software Foundation; either version 2 of the License, or
  50005. + * (at your option) any later version.
  50006. + *
  50007. + * This program is distributed in the hope that it will be useful,
  50008. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  50009. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  50010. + * GNU General Public License for more details.
  50011. + *
  50012. + * You should have received a copy of the GNU General Public License
  50013. + * along with this program; if not, write to the Free Software
  50014. + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  50015. + */
  50016. +
  50017. +#include <linux/module.h>
  50018. +#include <linux/kernel.h>
  50019. +#include <linux/init.h>
  50020. +#include <linux/delay.h>
  50021. +
  50022. +#include "fbtft.h"
  50023. +
  50024. +#define DRVNAME "fb_hx8353d"
  50025. +#define DEFAULT_GAMMA "50 77 40 08 BF 00 03 0F 00 01 73 00 72 03 B0 0F 08 00 0F"
  50026. +
  50027. +static int init_display(struct fbtft_par *par)
  50028. +{
  50029. +
  50030. + fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
  50031. +
  50032. + par->fbtftops.reset(par);
  50033. + mdelay(150);
  50034. +
  50035. + /* SETEXTC */
  50036. + write_reg(par, 0xB9, 0xFF, 0x83, 0x53);
  50037. +
  50038. + /* RADJ */
  50039. + write_reg(par, 0xB0, 0x3C, 0x01);
  50040. +
  50041. + /* VCOM */
  50042. + write_reg(par, 0xB6, 0x94, 0x6C, 0x50);
  50043. +
  50044. + /* PWR */
  50045. + write_reg(par, 0xB1, 0x00, 0x01, 0x1B, 0x03, 0x01, 0x08, 0x77, 0x89);
  50046. +
  50047. + /* COLMOD */
  50048. + write_reg(par, 0x3A, 0x05);
  50049. +
  50050. + /* MEM ACCESS */
  50051. + write_reg(par, 0x36, 0xC0);
  50052. +
  50053. + /* SLPOUT - Sleep out & booster on */
  50054. + write_reg(par, 0x11);
  50055. + mdelay(150);
  50056. +
  50057. + /* DISPON - Display On */
  50058. + write_reg(par, 0x29);
  50059. +
  50060. + /* RGBSET */
  50061. + write_reg(par, 0x2D,
  50062. + 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30,
  50063. + 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62,
  50064. + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
  50065. + 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
  50066. + 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
  50067. + 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
  50068. + 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30,
  50069. + 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62);
  50070. +
  50071. + return 0;
  50072. +};
  50073. +
  50074. +static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
  50075. +{
  50076. + fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par,
  50077. + "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye);
  50078. +
  50079. + /* column address */
  50080. + write_reg(par, 0x2a, xs >> 8, xs & 0xff, xe >> 8, xe & 0xff);
  50081. +
  50082. + /* row adress */
  50083. + write_reg(par, 0x2b, ys >> 8, ys & 0xff, ye >> 8, ye & 0xff);
  50084. +
  50085. + /* memory write */
  50086. + write_reg(par, 0x2c);
  50087. +}
  50088. +
  50089. +#define my (1 << 7)
  50090. +#define mx (1 << 6)
  50091. +#define mv (1 << 5)
  50092. +static int set_var(struct fbtft_par *par)
  50093. +{
  50094. + fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
  50095. +
  50096. + /* madctl - memory data access control
  50097. + rgb/bgr:
  50098. + 1. mode selection pin srgb
  50099. + rgb h/w pin for color filter setting: 0=rgb, 1=bgr
  50100. + 2. madctl rgb bit
  50101. + rgb-bgr order color filter panel: 0=rgb, 1=bgr */
  50102. + switch (par->info->var.rotate) {
  50103. + case 0:
  50104. + write_reg(par, 0x36, mx | my | (par->bgr << 3));
  50105. + break;
  50106. + case 270:
  50107. + write_reg(par, 0x36, my | mv | (par->bgr << 3));
  50108. + break;
  50109. + case 180:
  50110. + write_reg(par, 0x36, (par->bgr << 3));
  50111. + break;
  50112. + case 90:
  50113. + write_reg(par, 0x36, mx | mv | (par->bgr << 3));
  50114. + break;
  50115. + }
  50116. +
  50117. + return 0;
  50118. +}
  50119. +
  50120. +/*
  50121. + gamma string format:
  50122. +*/
  50123. +static int set_gamma(struct fbtft_par *par, unsigned long *curves)
  50124. +{
  50125. + fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
  50126. +
  50127. + write_reg(par, 0xE0,
  50128. + curves[0], curves[1], curves[2], curves[3],
  50129. + curves[4], curves[5], curves[6], curves[7],
  50130. + curves[8], curves[9], curves[10], curves[11],
  50131. + curves[12], curves[13], curves[14], curves[15],
  50132. + curves[16], curves[17], curves[18]);
  50133. +
  50134. + return 0;
  50135. +}
  50136. +
  50137. +
  50138. +static struct fbtft_display display = {
  50139. + .regwidth = 8,
  50140. + .width = 128,
  50141. + .height = 160,
  50142. + .gamma_num = 1,
  50143. + .gamma_len = 19,
  50144. + .gamma = DEFAULT_GAMMA,
  50145. + .fbtftops = {
  50146. + .init_display = init_display,
  50147. + .set_addr_win = set_addr_win,
  50148. + .set_var = set_var,
  50149. + .set_gamma = set_gamma,
  50150. + },
  50151. +};
  50152. +FBTFT_REGISTER_DRIVER(DRVNAME, "himax,hx8353d", &display);
  50153. +
  50154. +MODULE_ALIAS("spi:" DRVNAME);
  50155. +MODULE_ALIAS("platform:" DRVNAME);
  50156. +MODULE_ALIAS("spi:hx8353d");
  50157. +MODULE_ALIAS("platform:hx8353d");
  50158. +
  50159. +MODULE_DESCRIPTION("FB driver for the HX8353D LCD Controller");
  50160. +MODULE_AUTHOR("Petr Olivka");
  50161. +MODULE_LICENSE("GPL");
  50162. diff -Nur linux-3.18.8/drivers/staging/fbtft/fb_ili9320.c linux-rpi/drivers/staging/fbtft/fb_ili9320.c
  50163. --- linux-3.18.8/drivers/staging/fbtft/fb_ili9320.c 1970-01-01 01:00:00.000000000 +0100
  50164. +++ linux-rpi/drivers/staging/fbtft/fb_ili9320.c 2015-03-05 14:40:16.341715808 +0100
  50165. @@ -0,0 +1,234 @@
  50166. +/*
  50167. + * FB driver for the ILI9320 LCD Controller
  50168. + *
  50169. + * Copyright (C) 2013 Noralf Tronnes
  50170. + *
  50171. + * This program is free software; you can redistribute it and/or modify
  50172. + * it under the terms of the GNU General Public License as published by
  50173. + * the Free Software Foundation; either version 2 of the License, or
  50174. + * (at your option) any later version.
  50175. + *
  50176. + * This program is distributed in the hope that it will be useful,
  50177. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  50178. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  50179. + * GNU General Public License for more details.
  50180. + *
  50181. + * You should have received a copy of the GNU General Public License
  50182. + * along with this program; if not, write to the Free Software
  50183. + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  50184. + */
  50185. +
  50186. +#include <linux/module.h>
  50187. +#include <linux/kernel.h>
  50188. +#include <linux/init.h>
  50189. +#include <linux/gpio.h>
  50190. +#include <linux/spi/spi.h>
  50191. +#include <linux/delay.h>
  50192. +
  50193. +#include "fbtft.h"
  50194. +
  50195. +#define DRVNAME "fb_ili9320"
  50196. +#define WIDTH 240
  50197. +#define HEIGHT 320
  50198. +#define DEFAULT_GAMMA "07 07 6 0 0 0 5 5 4 0\n" \
  50199. + "07 08 4 7 5 1 2 0 7 7"
  50200. +
  50201. +
  50202. +static unsigned read_devicecode(struct fbtft_par *par)
  50203. +{
  50204. + int ret;
  50205. + u8 rxbuf[8] = {0, };
  50206. +
  50207. + write_reg(par, 0x0000);
  50208. + ret = par->fbtftops.read(par, rxbuf, 4);
  50209. + return (rxbuf[2] << 8) | rxbuf[3];
  50210. +}
  50211. +
  50212. +static int init_display(struct fbtft_par *par)
  50213. +{
  50214. + unsigned devcode;
  50215. + fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
  50216. +
  50217. + par->fbtftops.reset(par);
  50218. +
  50219. + devcode = read_devicecode(par);
  50220. + fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "Device code: 0x%04X\n",
  50221. + devcode);
  50222. + if ((devcode != 0x0000) && (devcode != 0x9320))
  50223. + dev_warn(par->info->device,
  50224. + "Unrecognized Device code: 0x%04X (expected 0x9320)\n",
  50225. + devcode);
  50226. +
  50227. + /* Initialization sequence from ILI9320 Application Notes */
  50228. +
  50229. + /* *********** Start Initial Sequence ********* */
  50230. + write_reg(par, 0x00E5, 0x8000); /* Set the Vcore voltage and this setting is must. */
  50231. + write_reg(par, 0x0000, 0x0001); /* Start internal OSC. */
  50232. + write_reg(par, 0x0001, 0x0100); /* set SS and SM bit */
  50233. + write_reg(par, 0x0002, 0x0700); /* set 1 line inversion */
  50234. + write_reg(par, 0x0004, 0x0000); /* Resize register */
  50235. + write_reg(par, 0x0008, 0x0202); /* set the back and front porch */
  50236. + write_reg(par, 0x0009, 0x0000); /* set non-display area refresh cycle */
  50237. + write_reg(par, 0x000A, 0x0000); /* FMARK function */
  50238. + write_reg(par, 0x000C, 0x0000); /* RGB interface setting */
  50239. + write_reg(par, 0x000D, 0x0000); /* Frame marker Position */
  50240. + write_reg(par, 0x000F, 0x0000); /* RGB interface polarity */
  50241. +
  50242. + /* ***********Power On sequence *************** */
  50243. + write_reg(par, 0x0010, 0x0000); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
  50244. + write_reg(par, 0x0011, 0x0007); /* DC1[2:0], DC0[2:0], VC[2:0] */
  50245. + write_reg(par, 0x0012, 0x0000); /* VREG1OUT voltage */
  50246. + write_reg(par, 0x0013, 0x0000); /* VDV[4:0] for VCOM amplitude */
  50247. + mdelay(200); /* Dis-charge capacitor power voltage */
  50248. + write_reg(par, 0x0010, 0x17B0); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
  50249. + write_reg(par, 0x0011, 0x0031); /* R11h=0x0031 at VCI=3.3V DC1[2:0], DC0[2:0], VC[2:0] */
  50250. + mdelay(50);
  50251. + write_reg(par, 0x0012, 0x0138); /* R12h=0x0138 at VCI=3.3V VREG1OUT voltage */
  50252. + mdelay(50);
  50253. + write_reg(par, 0x0013, 0x1800); /* R13h=0x1800 at VCI=3.3V VDV[4:0] for VCOM amplitude */
  50254. + write_reg(par, 0x0029, 0x0008); /* R29h=0x0008 at VCI=3.3V VCM[4:0] for VCOMH */
  50255. + mdelay(50);
  50256. + write_reg(par, 0x0020, 0x0000); /* GRAM horizontal Address */
  50257. + write_reg(par, 0x0021, 0x0000); /* GRAM Vertical Address */
  50258. +
  50259. + /* ------------------ Set GRAM area --------------- */
  50260. + write_reg(par, 0x0050, 0x0000); /* Horizontal GRAM Start Address */
  50261. + write_reg(par, 0x0051, 0x00EF); /* Horizontal GRAM End Address */
  50262. + write_reg(par, 0x0052, 0x0000); /* Vertical GRAM Start Address */
  50263. + write_reg(par, 0x0053, 0x013F); /* Vertical GRAM Start Address */
  50264. + write_reg(par, 0x0060, 0x2700); /* Gate Scan Line */
  50265. + write_reg(par, 0x0061, 0x0001); /* NDL,VLE, REV */
  50266. + write_reg(par, 0x006A, 0x0000); /* set scrolling line */
  50267. +
  50268. + /* -------------- Partial Display Control --------- */
  50269. + write_reg(par, 0x0080, 0x0000);
  50270. + write_reg(par, 0x0081, 0x0000);
  50271. + write_reg(par, 0x0082, 0x0000);
  50272. + write_reg(par, 0x0083, 0x0000);
  50273. + write_reg(par, 0x0084, 0x0000);
  50274. + write_reg(par, 0x0085, 0x0000);
  50275. +
  50276. + /* -------------- Panel Control ------------------- */
  50277. + write_reg(par, 0x0090, 0x0010);
  50278. + write_reg(par, 0x0092, 0x0000);
  50279. + write_reg(par, 0x0093, 0x0003);
  50280. + write_reg(par, 0x0095, 0x0110);
  50281. + write_reg(par, 0x0097, 0x0000);
  50282. + write_reg(par, 0x0098, 0x0000);
  50283. + write_reg(par, 0x0007, 0x0173); /* 262K color and display ON */
  50284. +
  50285. + return 0;
  50286. +}
  50287. +
  50288. +static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
  50289. +{
  50290. + fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par,
  50291. + "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye);
  50292. +
  50293. + switch (par->info->var.rotate) {
  50294. + /* R20h = Horizontal GRAM Start Address */
  50295. + /* R21h = Vertical GRAM Start Address */
  50296. + case 0:
  50297. + write_reg(par, 0x0020, xs);
  50298. + write_reg(par, 0x0021, ys);
  50299. + break;
  50300. + case 180:
  50301. + write_reg(par, 0x0020, WIDTH - 1 - xs);
  50302. + write_reg(par, 0x0021, HEIGHT - 1 - ys);
  50303. + break;
  50304. + case 270:
  50305. + write_reg(par, 0x0020, WIDTH - 1 - ys);
  50306. + write_reg(par, 0x0021, xs);
  50307. + break;
  50308. + case 90:
  50309. + write_reg(par, 0x0020, ys);
  50310. + write_reg(par, 0x0021, HEIGHT - 1 - xs);
  50311. + break;
  50312. + }
  50313. + write_reg(par, 0x0022); /* Write Data to GRAM */
  50314. +}
  50315. +
  50316. +static int set_var(struct fbtft_par *par)
  50317. +{
  50318. + fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
  50319. +
  50320. + switch (par->info->var.rotate) {
  50321. + case 0:
  50322. + write_reg(par, 0x3, (par->bgr << 12) | 0x30);
  50323. + break;
  50324. + case 270:
  50325. + write_reg(par, 0x3, (par->bgr << 12) | 0x28);
  50326. + break;
  50327. + case 180:
  50328. + write_reg(par, 0x3, (par->bgr << 12) | 0x00);
  50329. + break;
  50330. + case 90:
  50331. + write_reg(par, 0x3, (par->bgr << 12) | 0x18);
  50332. + break;
  50333. + }
  50334. + return 0;
  50335. +}
  50336. +
  50337. +/*
  50338. + Gamma string format:
  50339. + VRP0 VRP1 RP0 RP1 KP0 KP1 KP2 KP3 KP4 KP5
  50340. + VRN0 VRN1 RN0 RN1 KN0 KN1 KN2 KN3 KN4 KN5
  50341. +*/
  50342. +#define CURVE(num, idx) curves[num*par->gamma.num_values + idx]
  50343. +static int set_gamma(struct fbtft_par *par, unsigned long *curves)
  50344. +{
  50345. + unsigned long mask[] = {
  50346. + 0b11111, 0b11111, 0b111, 0b111, 0b111,
  50347. + 0b111, 0b111, 0b111, 0b111, 0b111,
  50348. + 0b11111, 0b11111, 0b111, 0b111, 0b111,
  50349. + 0b111, 0b111, 0b111, 0b111, 0b111 };
  50350. + int i, j;
  50351. +
  50352. + fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
  50353. +
  50354. + /* apply mask */
  50355. + for (i = 0; i < 2; i++)
  50356. + for (j = 0; j < 10; j++)
  50357. + CURVE(i, j) &= mask[i*par->gamma.num_values + j];
  50358. +
  50359. + write_reg(par, 0x0030, CURVE(0, 5) << 8 | CURVE(0, 4));
  50360. + write_reg(par, 0x0031, CURVE(0, 7) << 8 | CURVE(0, 6));
  50361. + write_reg(par, 0x0032, CURVE(0, 9) << 8 | CURVE(0, 8));
  50362. + write_reg(par, 0x0035, CURVE(0, 3) << 8 | CURVE(0, 2));
  50363. + write_reg(par, 0x0036, CURVE(0, 1) << 8 | CURVE(0, 0));
  50364. +
  50365. + write_reg(par, 0x0037, CURVE(1, 5) << 8 | CURVE(1, 4));
  50366. + write_reg(par, 0x0038, CURVE(1, 7) << 8 | CURVE(1, 6));
  50367. + write_reg(par, 0x0039, CURVE(1, 9) << 8 | CURVE(1, 8));
  50368. + write_reg(par, 0x003C, CURVE(1, 3) << 8 | CURVE(1, 2));
  50369. + write_reg(par, 0x003D, CURVE(1, 1) << 8 | CURVE(1, 0));
  50370. +
  50371. + return 0;
  50372. +}
  50373. +#undef CURVE
  50374. +
  50375. +
  50376. +static struct fbtft_display display = {
  50377. + .regwidth = 16,
  50378. + .width = WIDTH,
  50379. + .height = HEIGHT,
  50380. + .gamma_num = 2,
  50381. + .gamma_len = 10,
  50382. + .gamma = DEFAULT_GAMMA,
  50383. + .fbtftops = {
  50384. + .init_display = init_display,
  50385. + .set_addr_win = set_addr_win,
  50386. + .set_var = set_var,
  50387. + .set_gamma = set_gamma,
  50388. + },
  50389. +};
  50390. +FBTFT_REGISTER_DRIVER(DRVNAME, "ilitek,ili9320", &display);
  50391. +
  50392. +MODULE_ALIAS("spi:" DRVNAME);
  50393. +MODULE_ALIAS("platform:" DRVNAME);
  50394. +MODULE_ALIAS("spi:ili9320");
  50395. +MODULE_ALIAS("platform:ili9320");
  50396. +
  50397. +MODULE_DESCRIPTION("FB driver for the ILI9320 LCD Controller");
  50398. +MODULE_AUTHOR("Noralf Tronnes");
  50399. +MODULE_LICENSE("GPL");
  50400. diff -Nur linux-3.18.8/drivers/staging/fbtft/fb_ili9325.c linux-rpi/drivers/staging/fbtft/fb_ili9325.c
  50401. --- linux-3.18.8/drivers/staging/fbtft/fb_ili9325.c 1970-01-01 01:00:00.000000000 +0100
  50402. +++ linux-rpi/drivers/staging/fbtft/fb_ili9325.c 2015-03-05 14:40:16.341715808 +0100
  50403. @@ -0,0 +1,291 @@
  50404. +/*
  50405. + * FB driver for the ILI9325 LCD Controller
  50406. + *
  50407. + * Copyright (C) 2013 Noralf Tronnes
  50408. + *
  50409. + * Based on ili9325.c by Jeroen Domburg
  50410. + *
  50411. + * This program is free software; you can redistribute it and/or modify
  50412. + * it under the terms of the GNU General Public License as published by
  50413. + * the Free Software Foundation; either version 2 of the License, or
  50414. + * (at your option) any later version.
  50415. + *
  50416. + * This program is distributed in the hope that it will be useful,
  50417. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  50418. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  50419. + * GNU General Public License for more details.
  50420. + *
  50421. + * You should have received a copy of the GNU General Public License
  50422. + * along with this program; if not, write to the Free Software
  50423. + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  50424. + */
  50425. +
  50426. +#include <linux/module.h>
  50427. +#include <linux/kernel.h>
  50428. +#include <linux/init.h>
  50429. +#include <linux/gpio.h>
  50430. +#include <linux/delay.h>
  50431. +
  50432. +#include "fbtft.h"
  50433. +
  50434. +#define DRVNAME "fb_ili9325"
  50435. +#define WIDTH 240
  50436. +#define HEIGHT 320
  50437. +#define BPP 16
  50438. +#define FPS 20
  50439. +#define DEFAULT_GAMMA "0F 00 7 2 0 0 6 5 4 1\n" \
  50440. + "04 16 2 7 6 3 2 1 7 7"
  50441. +
  50442. +
  50443. +static unsigned bt = 6; /* VGL=Vci*4 , VGH=Vci*4 */
  50444. +module_param(bt, uint, 0);
  50445. +MODULE_PARM_DESC(bt, "Sets the factor used in the step-up circuits");
  50446. +
  50447. +static unsigned vc = 0b011; /* Vci1=Vci*0.80 */
  50448. +module_param(vc, uint, 0);
  50449. +MODULE_PARM_DESC(vc,
  50450. +"Sets the ratio factor of Vci to generate the reference voltages Vci1");
  50451. +
  50452. +static unsigned vrh = 0b1101; /* VREG1OUT=Vci*1.85 */
  50453. +module_param(vrh, uint, 0);
  50454. +MODULE_PARM_DESC(vrh,
  50455. +"Set the amplifying rate (1.6 ~ 1.9) of Vci applied to output the VREG1OUT");
  50456. +
  50457. +static unsigned vdv = 0b10010; /* VCOMH amplitude=VREG1OUT*0.98 */
  50458. +module_param(vdv, uint, 0);
  50459. +MODULE_PARM_DESC(vdv,
  50460. +"Select the factor of VREG1OUT to set the amplitude of Vcom");
  50461. +
  50462. +static unsigned vcm = 0b001010; /* VCOMH=VREG1OUT*0.735 */
  50463. +module_param(vcm, uint, 0);
  50464. +MODULE_PARM_DESC(vcm, "Set the internal VcomH voltage");
  50465. +
  50466. +
  50467. +/*
  50468. +Verify that this configuration is within the Voltage limits
  50469. +
  50470. +Display module configuration: Vcc = IOVcc = Vci = 3.3V
  50471. +
  50472. + Voltages
  50473. +----------
  50474. +Vci = 3.3
  50475. +Vci1 = Vci * 0.80 = 2.64
  50476. +DDVDH = Vci1 * 2 = 5.28
  50477. +VCL = -Vci1 = -2.64
  50478. +VREG1OUT = Vci * 1.85 = 4.88
  50479. +VCOMH = VREG1OUT * 0.735 = 3.59
  50480. +VCOM amplitude = VREG1OUT * 0.98 = 4.79
  50481. +VGH = Vci * 4 = 13.2
  50482. +VGL = -Vci * 4 = -13.2
  50483. +
  50484. + Limits
  50485. +--------
  50486. +Power supplies
  50487. +1.65 < IOVcc < 3.30 => 1.65 < 3.3 < 3.30
  50488. +2.40 < Vcc < 3.30 => 2.40 < 3.3 < 3.30
  50489. +2.50 < Vci < 3.30 => 2.50 < 3.3 < 3.30
  50490. +
  50491. +Source/VCOM power supply voltage
  50492. + 4.50 < DDVDH < 6.0 => 4.50 < 5.28 < 6.0
  50493. +-3.0 < VCL < -2.0 => -3.0 < -2.64 < -2.0
  50494. +VCI - VCL < 6.0 => 5.94 < 6.0
  50495. +
  50496. +Gate driver output voltage
  50497. + 10 < VGH < 20 => 10 < 13.2 < 20
  50498. +-15 < VGL < -5 => -15 < -13.2 < -5
  50499. +VGH - VGL < 32 => 26.4 < 32
  50500. +
  50501. +VCOM driver output voltage
  50502. +VCOMH - VCOML < 6.0 => 4.79 < 6.0
  50503. +*/
  50504. +
  50505. +static int init_display(struct fbtft_par *par)
  50506. +{
  50507. + fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
  50508. +
  50509. + par->fbtftops.reset(par);
  50510. +
  50511. + if (par->gpio.cs != -1)
  50512. + gpio_set_value(par->gpio.cs, 0); /* Activate chip */
  50513. +
  50514. + bt &= 0b111;
  50515. + vc &= 0b111;
  50516. + vrh &= 0b1111;
  50517. + vdv &= 0b11111;
  50518. + vcm &= 0b111111;
  50519. +
  50520. + /* Initialization sequence from ILI9325 Application Notes */
  50521. +
  50522. + /* ----------- Start Initial Sequence ----------- */
  50523. + write_reg(par, 0x00E3, 0x3008); /* Set internal timing */
  50524. + write_reg(par, 0x00E7, 0x0012); /* Set internal timing */
  50525. + write_reg(par, 0x00EF, 0x1231); /* Set internal timing */
  50526. + write_reg(par, 0x0001, 0x0100); /* set SS and SM bit */
  50527. + write_reg(par, 0x0002, 0x0700); /* set 1 line inversion */
  50528. + write_reg(par, 0x0004, 0x0000); /* Resize register */
  50529. + write_reg(par, 0x0008, 0x0207); /* set the back porch and front porch */
  50530. + write_reg(par, 0x0009, 0x0000); /* set non-display area refresh cycle */
  50531. + write_reg(par, 0x000A, 0x0000); /* FMARK function */
  50532. + write_reg(par, 0x000C, 0x0000); /* RGB interface setting */
  50533. + write_reg(par, 0x000D, 0x0000); /* Frame marker Position */
  50534. + write_reg(par, 0x000F, 0x0000); /* RGB interface polarity */
  50535. +
  50536. + /* ----------- Power On sequence ----------- */
  50537. + write_reg(par, 0x0010, 0x0000); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
  50538. + write_reg(par, 0x0011, 0x0007); /* DC1[2:0], DC0[2:0], VC[2:0] */
  50539. + write_reg(par, 0x0012, 0x0000); /* VREG1OUT voltage */
  50540. + write_reg(par, 0x0013, 0x0000); /* VDV[4:0] for VCOM amplitude */
  50541. + mdelay(200); /* Dis-charge capacitor power voltage */
  50542. + write_reg(par, 0x0010, /* SAP, BT[3:0], AP, DSTB, SLP, STB */
  50543. + (1 << 12) | (bt << 8) | (1 << 7) | (0b001 << 4));
  50544. + write_reg(par, 0x0011, 0x220 | vc); /* DC1[2:0], DC0[2:0], VC[2:0] */
  50545. + mdelay(50); /* Delay 50ms */
  50546. + write_reg(par, 0x0012, vrh); /* Internal reference voltage= Vci; */
  50547. + mdelay(50); /* Delay 50ms */
  50548. + write_reg(par, 0x0013, vdv << 8); /* Set VDV[4:0] for VCOM amplitude */
  50549. + write_reg(par, 0x0029, vcm); /* Set VCM[5:0] for VCOMH */
  50550. + write_reg(par, 0x002B, 0x000C); /* Set Frame Rate */
  50551. + mdelay(50); /* Delay 50ms */
  50552. + write_reg(par, 0x0020, 0x0000); /* GRAM horizontal Address */
  50553. + write_reg(par, 0x0021, 0x0000); /* GRAM Vertical Address */
  50554. +
  50555. + /*------------------ Set GRAM area --------------- */
  50556. + write_reg(par, 0x0050, 0x0000); /* Horizontal GRAM Start Address */
  50557. + write_reg(par, 0x0051, 0x00EF); /* Horizontal GRAM End Address */
  50558. + write_reg(par, 0x0052, 0x0000); /* Vertical GRAM Start Address */
  50559. + write_reg(par, 0x0053, 0x013F); /* Vertical GRAM Start Address */
  50560. + write_reg(par, 0x0060, 0xA700); /* Gate Scan Line */
  50561. + write_reg(par, 0x0061, 0x0001); /* NDL,VLE, REV */
  50562. + write_reg(par, 0x006A, 0x0000); /* set scrolling line */
  50563. +
  50564. + /*-------------- Partial Display Control --------- */
  50565. + write_reg(par, 0x0080, 0x0000);
  50566. + write_reg(par, 0x0081, 0x0000);
  50567. + write_reg(par, 0x0082, 0x0000);
  50568. + write_reg(par, 0x0083, 0x0000);
  50569. + write_reg(par, 0x0084, 0x0000);
  50570. + write_reg(par, 0x0085, 0x0000);
  50571. +
  50572. + /*-------------- Panel Control ------------------- */
  50573. + write_reg(par, 0x0090, 0x0010);
  50574. + write_reg(par, 0x0092, 0x0600);
  50575. + write_reg(par, 0x0007, 0x0133); /* 262K color and display ON */
  50576. +
  50577. + return 0;
  50578. +}
  50579. +
  50580. +static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
  50581. +{
  50582. + fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par,
  50583. + "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye);
  50584. + switch (par->info->var.rotate) {
  50585. + /* R20h = Horizontal GRAM Start Address */
  50586. + /* R21h = Vertical GRAM Start Address */
  50587. + case 0:
  50588. + write_reg(par, 0x0020, xs);
  50589. + write_reg(par, 0x0021, ys);
  50590. + break;
  50591. + case 180:
  50592. + write_reg(par, 0x0020, WIDTH - 1 - xs);
  50593. + write_reg(par, 0x0021, HEIGHT - 1 - ys);
  50594. + break;
  50595. + case 270:
  50596. + write_reg(par, 0x0020, WIDTH - 1 - ys);
  50597. + write_reg(par, 0x0021, xs);
  50598. + break;
  50599. + case 90:
  50600. + write_reg(par, 0x0020, ys);
  50601. + write_reg(par, 0x0021, HEIGHT - 1 - xs);
  50602. + break;
  50603. + }
  50604. + write_reg(par, 0x0022); /* Write Data to GRAM */
  50605. +}
  50606. +
  50607. +static int set_var(struct fbtft_par *par)
  50608. +{
  50609. + fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
  50610. +
  50611. + switch (par->info->var.rotate) {
  50612. + /* AM: GRAM update direction */
  50613. + case 0:
  50614. + write_reg(par, 0x03, 0x0030 | (par->bgr << 12));
  50615. + break;
  50616. + case 180:
  50617. + write_reg(par, 0x03, 0x0000 | (par->bgr << 12));
  50618. + break;
  50619. + case 270:
  50620. + write_reg(par, 0x03, 0x0028 | (par->bgr << 12));
  50621. + break;
  50622. + case 90:
  50623. + write_reg(par, 0x03, 0x0018 | (par->bgr << 12));
  50624. + break;
  50625. + }
  50626. +
  50627. + return 0;
  50628. +}
  50629. +
  50630. +/*
  50631. + Gamma string format:
  50632. + VRP0 VRP1 RP0 RP1 KP0 KP1 KP2 KP3 KP4 KP5
  50633. + VRN0 VRN1 RN0 RN1 KN0 KN1 KN2 KN3 KN4 KN5
  50634. +*/
  50635. +#define CURVE(num, idx) curves[num*par->gamma.num_values + idx]
  50636. +static int set_gamma(struct fbtft_par *par, unsigned long *curves)
  50637. +{
  50638. + unsigned long mask[] = {
  50639. + 0b11111, 0b11111, 0b111, 0b111, 0b111,
  50640. + 0b111, 0b111, 0b111, 0b111, 0b111,
  50641. + 0b11111, 0b11111, 0b111, 0b111, 0b111,
  50642. + 0b111, 0b111, 0b111, 0b111, 0b111 };
  50643. + int i, j;
  50644. +
  50645. + fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
  50646. +
  50647. + /* apply mask */
  50648. + for (i = 0; i < 2; i++)
  50649. + for (j = 0; j < 10; j++)
  50650. + CURVE(i, j) &= mask[i*par->gamma.num_values + j];
  50651. +
  50652. + write_reg(par, 0x0030, CURVE(0, 5) << 8 | CURVE(0, 4));
  50653. + write_reg(par, 0x0031, CURVE(0, 7) << 8 | CURVE(0, 6));
  50654. + write_reg(par, 0x0032, CURVE(0, 9) << 8 | CURVE(0, 8));
  50655. + write_reg(par, 0x0035, CURVE(0, 3) << 8 | CURVE(0, 2));
  50656. + write_reg(par, 0x0036, CURVE(0, 1) << 8 | CURVE(0, 0));
  50657. +
  50658. + write_reg(par, 0x0037, CURVE(1, 5) << 8 | CURVE(1, 4));
  50659. + write_reg(par, 0x0038, CURVE(1, 7) << 8 | CURVE(1, 6));
  50660. + write_reg(par, 0x0039, CURVE(1, 9) << 8 | CURVE(1, 8));
  50661. + write_reg(par, 0x003C, CURVE(1, 3) << 8 | CURVE(1, 2));
  50662. + write_reg(par, 0x003D, CURVE(1, 1) << 8 | CURVE(1, 0));
  50663. +
  50664. + return 0;
  50665. +}
  50666. +#undef CURVE
  50667. +
  50668. +
  50669. +static struct fbtft_display display = {
  50670. + .regwidth = 16,
  50671. + .width = WIDTH,
  50672. + .height = HEIGHT,
  50673. + .bpp = BPP,
  50674. + .fps = FPS,
  50675. + .gamma_num = 2,
  50676. + .gamma_len = 10,
  50677. + .gamma = DEFAULT_GAMMA,
  50678. + .fbtftops = {
  50679. + .init_display = init_display,
  50680. + .set_addr_win = set_addr_win,
  50681. + .set_var = set_var,
  50682. + .set_gamma = set_gamma,
  50683. + },
  50684. +};
  50685. +FBTFT_REGISTER_DRIVER(DRVNAME, "ilitek,ili9325", &display);
  50686. +
  50687. +MODULE_ALIAS("spi:" DRVNAME);
  50688. +MODULE_ALIAS("platform:" DRVNAME);
  50689. +MODULE_ALIAS("spi:ili9325");
  50690. +MODULE_ALIAS("platform:ili9325");
  50691. +
  50692. +MODULE_DESCRIPTION("FB driver for the ILI9325 LCD Controller");
  50693. +MODULE_AUTHOR("Noralf Tronnes");
  50694. +MODULE_LICENSE("GPL");
  50695. diff -Nur linux-3.18.8/drivers/staging/fbtft/fb_ili9340.c linux-rpi/drivers/staging/fbtft/fb_ili9340.c
  50696. --- linux-3.18.8/drivers/staging/fbtft/fb_ili9340.c 1970-01-01 01:00:00.000000000 +0100
  50697. +++ linux-rpi/drivers/staging/fbtft/fb_ili9340.c 2015-03-05 14:40:16.341715808 +0100
  50698. @@ -0,0 +1,163 @@
  50699. +/*
  50700. + * FB driver for the ILI9340 LCD Controller
  50701. + *
  50702. + * Copyright (C) 2013 Noralf Tronnes
  50703. + *
  50704. + * This program is free software; you can redistribute it and/or modify
  50705. + * it under the terms of the GNU General Public License as published by
  50706. + * the Free Software Foundation; either version 2 of the License, or
  50707. + * (at your option) any later version.
  50708. + *
  50709. + * This program is distributed in the hope that it will be useful,
  50710. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  50711. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  50712. + * GNU General Public License for more details.
  50713. + *
  50714. + * You should have received a copy of the GNU General Public License
  50715. + * along with this program; if not, write to the Free Software
  50716. + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  50717. + */
  50718. +
  50719. +#include <linux/module.h>
  50720. +#include <linux/kernel.h>
  50721. +#include <linux/init.h>
  50722. +#include <linux/gpio.h>
  50723. +#include <linux/delay.h>
  50724. +
  50725. +#include "fbtft.h"
  50726. +
  50727. +#define DRVNAME "fb_ili9340"
  50728. +#define WIDTH 240
  50729. +#define HEIGHT 320
  50730. +
  50731. +
  50732. +/* Init sequence taken from: Arduino Library for the Adafruit 2.2" display */
  50733. +static int init_display(struct fbtft_par *par)
  50734. +{
  50735. + fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
  50736. +
  50737. + par->fbtftops.reset(par);
  50738. +
  50739. + write_reg(par, 0xEF, 0x03, 0x80, 0x02);
  50740. + write_reg(par, 0xCF, 0x00 , 0XC1 , 0X30);
  50741. + write_reg(par, 0xED, 0x64 , 0x03 , 0X12 , 0X81);
  50742. + write_reg(par, 0xE8, 0x85 , 0x00 , 0x78);
  50743. + write_reg(par, 0xCB, 0x39 , 0x2C , 0x00 , 0x34 , 0x02);
  50744. + write_reg(par, 0xF7, 0x20);
  50745. + write_reg(par, 0xEA, 0x00 , 0x00);
  50746. +
  50747. + /* Power Control 1 */
  50748. + write_reg(par, 0xC0, 0x23);
  50749. +
  50750. + /* Power Control 2 */
  50751. + write_reg(par, 0xC1, 0x10);
  50752. +
  50753. + /* VCOM Control 1 */
  50754. + write_reg(par, 0xC5, 0x3e, 0x28);
  50755. +
  50756. + /* VCOM Control 2 */
  50757. + write_reg(par, 0xC7, 0x86);
  50758. +
  50759. + /* COLMOD: Pixel Format Set */
  50760. + /* 16 bits/pixel */
  50761. + write_reg(par, 0x3A, 0x55);
  50762. +
  50763. + /* Frame Rate Control */
  50764. + /* Division ratio = fosc, Frame Rate = 79Hz */
  50765. + write_reg(par, 0xB1, 0x00, 0x18);
  50766. +
  50767. + /* Display Function Control */
  50768. + write_reg(par, 0xB6, 0x08, 0x82, 0x27);
  50769. +
  50770. + /* Gamma Function Disable */
  50771. + write_reg(par, 0xF2, 0x00);
  50772. +
  50773. + /* Gamma curve selected */
  50774. + write_reg(par, 0x26, 0x01);
  50775. +
  50776. + /* Positive Gamma Correction */
  50777. + write_reg(par, 0xE0,
  50778. + 0x0F, 0x31, 0x2B, 0x0C, 0x0E, 0x08, 0x4E, 0xF1,
  50779. + 0x37, 0x07, 0x10, 0x03, 0x0E, 0x09, 0x00);
  50780. +
  50781. + /* Negative Gamma Correction */
  50782. + write_reg(par, 0xE1,
  50783. + 0x00, 0x0E, 0x14, 0x03, 0x11, 0x07, 0x31, 0xC1,
  50784. + 0x48, 0x08, 0x0F, 0x0C, 0x31, 0x36, 0x0F);
  50785. +
  50786. + /* Sleep OUT */
  50787. + write_reg(par, 0x11);
  50788. +
  50789. + mdelay(120);
  50790. +
  50791. + /* Display ON */
  50792. + write_reg(par, 0x29);
  50793. +
  50794. + return 0;
  50795. +}
  50796. +
  50797. +static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
  50798. +{
  50799. + fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par,
  50800. + "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye);
  50801. +
  50802. + /* Column address */
  50803. + write_reg(par, 0x2A, xs >> 8, xs & 0xFF, xe >> 8, xe & 0xFF);
  50804. +
  50805. + /* Row adress */
  50806. + write_reg(par, 0x2B, ys >> 8, ys & 0xFF, ye >> 8, ye & 0xFF);
  50807. +
  50808. + /* Memory write */
  50809. + write_reg(par, 0x2C);
  50810. +}
  50811. +
  50812. +#define ILI9340_MADCTL_MV 0x20
  50813. +#define ILI9340_MADCTL_MX 0x40
  50814. +#define ILI9340_MADCTL_MY 0x80
  50815. +static int set_var(struct fbtft_par *par)
  50816. +{
  50817. + u8 val;
  50818. +
  50819. + fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
  50820. +
  50821. + switch (par->info->var.rotate) {
  50822. + case 270:
  50823. + val = ILI9340_MADCTL_MV;
  50824. + break;
  50825. + case 180:
  50826. + val = ILI9340_MADCTL_MY;
  50827. + break;
  50828. + case 90:
  50829. + val = ILI9340_MADCTL_MV | ILI9340_MADCTL_MY | ILI9340_MADCTL_MX;
  50830. + break;
  50831. + default:
  50832. + val = ILI9340_MADCTL_MX;
  50833. + break;
  50834. + }
  50835. + /* Memory Access Control */
  50836. + write_reg(par, 0x36, val | (par->bgr << 3));
  50837. +
  50838. + return 0;
  50839. +}
  50840. +
  50841. +
  50842. +static struct fbtft_display display = {
  50843. + .regwidth = 8,
  50844. + .width = WIDTH,
  50845. + .height = HEIGHT,
  50846. + .fbtftops = {
  50847. + .init_display = init_display,
  50848. + .set_addr_win = set_addr_win,
  50849. + .set_var = set_var,
  50850. + },
  50851. +};
  50852. +FBTFT_REGISTER_DRIVER(DRVNAME, "ilitek,ili9340", &display);
  50853. +
  50854. +MODULE_ALIAS("spi:" DRVNAME);
  50855. +MODULE_ALIAS("platform:" DRVNAME);
  50856. +MODULE_ALIAS("spi:ili9340");
  50857. +MODULE_ALIAS("platform:ili9340");
  50858. +
  50859. +MODULE_DESCRIPTION("FB driver for the ILI9340 LCD Controller");
  50860. +MODULE_AUTHOR("Noralf Tronnes");
  50861. +MODULE_LICENSE("GPL");
  50862. diff -Nur linux-3.18.8/drivers/staging/fbtft/fb_ili9341.c linux-rpi/drivers/staging/fbtft/fb_ili9341.c
  50863. --- linux-3.18.8/drivers/staging/fbtft/fb_ili9341.c 1970-01-01 01:00:00.000000000 +0100
  50864. +++ linux-rpi/drivers/staging/fbtft/fb_ili9341.c 2015-03-05 14:40:16.341715808 +0100
  50865. @@ -0,0 +1,179 @@
  50866. +/*
  50867. + * FB driver for the ILI9341 LCD display controller
  50868. + *
  50869. + * This display uses 9-bit SPI: Data/Command bit + 8 data bits
  50870. + * For platforms that doesn't support 9-bit, the driver is capable
  50871. + * of emulating this using 8-bit transfer.
  50872. + * This is done by transfering eight 9-bit words in 9 bytes.
  50873. + *
  50874. + * Copyright (C) 2013 Christian Vogelgsang
  50875. + * Based on adafruit22fb.c by Noralf Tronnes
  50876. + *
  50877. + * This program is free software; you can redistribute it and/or modify
  50878. + * it under the terms of the GNU General Public License as published by
  50879. + * the Free Software Foundation; either version 2 of the License, or
  50880. + * (at your option) any later version.
  50881. + *
  50882. + * This program is distributed in the hope that it will be useful,
  50883. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  50884. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  50885. + * GNU General Public License for more details.
  50886. + *
  50887. + * You should have received a copy of the GNU General Public License
  50888. + * along with this program; if not, write to the Free Software
  50889. + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  50890. + */
  50891. +
  50892. +#include <linux/module.h>
  50893. +#include <linux/kernel.h>
  50894. +#include <linux/init.h>
  50895. +#include <linux/delay.h>
  50896. +
  50897. +#include "fbtft.h"
  50898. +
  50899. +#define DRVNAME "fb_ili9341"
  50900. +#define WIDTH 240
  50901. +#define HEIGHT 320
  50902. +#define TXBUFLEN (4 * PAGE_SIZE)
  50903. +#define DEFAULT_GAMMA "1F 1A 18 0A 0F 06 45 87 32 0A 07 02 07 05 00\n" \
  50904. + "00 25 27 05 10 09 3A 78 4D 05 18 0D 38 3A 1F"
  50905. +
  50906. +
  50907. +static int init_display(struct fbtft_par *par)
  50908. +{
  50909. + fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
  50910. +
  50911. + par->fbtftops.reset(par);
  50912. +
  50913. + /* startup sequence for MI0283QT-9A */
  50914. + write_reg(par, 0x01); /* software reset */
  50915. + mdelay(5);
  50916. + write_reg(par, 0x28); /* display off */
  50917. + /* --------------------------------------------------------- */
  50918. + write_reg(par, 0xCF, 0x00, 0x83, 0x30);
  50919. + write_reg(par, 0xED, 0x64, 0x03, 0x12, 0x81);
  50920. + write_reg(par, 0xE8, 0x85, 0x01, 0x79);
  50921. + write_reg(par, 0xCB, 0x39, 0X2C, 0x00, 0x34, 0x02);
  50922. + write_reg(par, 0xF7, 0x20);
  50923. + write_reg(par, 0xEA, 0x00, 0x00);
  50924. + /* ------------power control-------------------------------- */
  50925. + write_reg(par, 0xC0, 0x26);
  50926. + write_reg(par, 0xC1, 0x11);
  50927. + /* ------------VCOM --------- */
  50928. + write_reg(par, 0xC5, 0x35, 0x3E);
  50929. + write_reg(par, 0xC7, 0xBE);
  50930. + /* ------------memory access control------------------------ */
  50931. + write_reg(par, 0x3A, 0x55); /* 16bit pixel */
  50932. + /* ------------frame rate----------------------------------- */
  50933. + write_reg(par, 0xB1, 0x00, 0x1B);
  50934. + /* ------------Gamma---------------------------------------- */
  50935. + /* write_reg(par, 0xF2, 0x08); */ /* Gamma Function Disable */
  50936. + write_reg(par, 0x26, 0x01);
  50937. + /* ------------display-------------------------------------- */
  50938. + write_reg(par, 0xB7, 0x07); /* entry mode set */
  50939. + write_reg(par, 0xB6, 0x0A, 0x82, 0x27, 0x00);
  50940. + write_reg(par, 0x11); /* sleep out */
  50941. + mdelay(100);
  50942. + write_reg(par, 0x29); /* display on */
  50943. + mdelay(20);
  50944. +
  50945. + return 0;
  50946. +}
  50947. +
  50948. +static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
  50949. +{
  50950. + fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par,
  50951. + "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye);
  50952. +
  50953. + /* Column address set */
  50954. + write_reg(par, 0x2A,
  50955. + (xs >> 8) & 0xFF, xs & 0xFF, (xe >> 8) & 0xFF, xe & 0xFF);
  50956. +
  50957. + /* Row adress set */
  50958. + write_reg(par, 0x2B,
  50959. + (ys >> 8) & 0xFF, ys & 0xFF, (ye >> 8) & 0xFF, ye & 0xFF);
  50960. +
  50961. + /* Memory write */
  50962. + write_reg(par, 0x2C);
  50963. +}
  50964. +
  50965. +#define MEM_Y (7) /* MY row address order */
  50966. +#define MEM_X (6) /* MX column address order */
  50967. +#define MEM_V (5) /* MV row / column exchange */
  50968. +#define MEM_L (4) /* ML vertical refresh order */
  50969. +#define MEM_H (2) /* MH horizontal refresh order */
  50970. +#define MEM_BGR (3) /* RGB-BGR Order */
  50971. +static int set_var(struct fbtft_par *par)
  50972. +{
  50973. + fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
  50974. +
  50975. + switch (par->info->var.rotate) {
  50976. + case 0:
  50977. + write_reg(par, 0x36, (1 << MEM_X) | (par->bgr << MEM_BGR));
  50978. + break;
  50979. + case 270:
  50980. + write_reg(par, 0x36,
  50981. + (1<<MEM_V) | (1 << MEM_L) | (par->bgr << MEM_BGR));
  50982. + break;
  50983. + case 180:
  50984. + write_reg(par, 0x36, (1 << MEM_Y) | (par->bgr << MEM_BGR));
  50985. + break;
  50986. + case 90:
  50987. + write_reg(par, 0x36, (1 << MEM_Y) | (1 << MEM_X) |
  50988. + (1 << MEM_V) | (par->bgr << MEM_BGR));
  50989. + break;
  50990. + }
  50991. +
  50992. + return 0;
  50993. +}
  50994. +
  50995. +/*
  50996. + Gamma string format:
  50997. + Positive: Par1 Par2 [...] Par15
  50998. + Negative: Par1 Par2 [...] Par15
  50999. +*/
  51000. +#define CURVE(num, idx) curves[num*par->gamma.num_values + idx]
  51001. +static int set_gamma(struct fbtft_par *par, unsigned long *curves)
  51002. +{
  51003. + int i;
  51004. +
  51005. + fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
  51006. +
  51007. + for (i = 0; i < par->gamma.num_curves; i++)
  51008. + write_reg(par, 0xE0 + i,
  51009. + CURVE(i, 0), CURVE(i, 1), CURVE(i, 2),
  51010. + CURVE(i, 3), CURVE(i, 4), CURVE(i, 5),
  51011. + CURVE(i, 6), CURVE(i, 7), CURVE(i, 8),
  51012. + CURVE(i, 9), CURVE(i, 10), CURVE(i, 11),
  51013. + CURVE(i, 12), CURVE(i, 13), CURVE(i, 14));
  51014. +
  51015. + return 0;
  51016. +}
  51017. +#undef CURVE
  51018. +
  51019. +
  51020. +static struct fbtft_display display = {
  51021. + .regwidth = 8,
  51022. + .width = WIDTH,
  51023. + .height = HEIGHT,
  51024. + .txbuflen = TXBUFLEN,
  51025. + .gamma_num = 2,
  51026. + .gamma_len = 15,
  51027. + .gamma = DEFAULT_GAMMA,
  51028. + .fbtftops = {
  51029. + .init_display = init_display,
  51030. + .set_addr_win = set_addr_win,
  51031. + .set_var = set_var,
  51032. + .set_gamma = set_gamma,
  51033. + },
  51034. +};
  51035. +FBTFT_REGISTER_DRIVER(DRVNAME, "ilitek,ili9341", &display);
  51036. +
  51037. +MODULE_ALIAS("spi:" DRVNAME);
  51038. +MODULE_ALIAS("platform:" DRVNAME);
  51039. +MODULE_ALIAS("spi:ili9341");
  51040. +MODULE_ALIAS("platform:ili9341");
  51041. +
  51042. +MODULE_DESCRIPTION("FB driver for the ILI9341 LCD display controller");
  51043. +MODULE_AUTHOR("Christian Vogelgsang");
  51044. +MODULE_LICENSE("GPL");
  51045. diff -Nur linux-3.18.8/drivers/staging/fbtft/fb_ili9481.c linux-rpi/drivers/staging/fbtft/fb_ili9481.c
  51046. --- linux-3.18.8/drivers/staging/fbtft/fb_ili9481.c 1970-01-01 01:00:00.000000000 +0100
  51047. +++ linux-rpi/drivers/staging/fbtft/fb_ili9481.c 2015-03-05 14:40:16.341715808 +0100
  51048. @@ -0,0 +1,117 @@
  51049. +/*
  51050. + * FB driver for the ILI9481 LCD Controller
  51051. + *
  51052. + * Copyright (c) 2014 Petr Olivka
  51053. + * Copyright (c) 2013 Noralf Tronnes
  51054. + *
  51055. + * This program is free software; you can redistribute it and/or modify
  51056. + * it under the terms of the GNU General Public License as published by
  51057. + * the Free Software Foundation; either version 2 of the License, or
  51058. + * (at your option) any later version.
  51059. + *
  51060. + * This program is distributed in the hope that it will be useful,
  51061. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  51062. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  51063. + * GNU General Public License for more details.
  51064. + *
  51065. + * You should have received a copy of the GNU General Public License
  51066. + * along with this program; if not, write to the Free Software
  51067. + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  51068. + */
  51069. +
  51070. +#include <linux/module.h>
  51071. +#include <linux/kernel.h>
  51072. +#include <linux/init.h>
  51073. +#include <linux/delay.h>
  51074. +
  51075. +#include "fbtft.h"
  51076. +
  51077. +#define DRVNAME "fb_ili9481"
  51078. +#define WIDTH 320
  51079. +#define HEIGHT 480
  51080. +
  51081. +static int default_init_sequence[] = {
  51082. +
  51083. + /* SLP_OUT - Sleep out */
  51084. + -1, 0x11,
  51085. + -2, 50,
  51086. + /* Power setting */
  51087. + -1, 0xD0, 0x07, 0x42, 0x18,
  51088. + /* VCOM */
  51089. + -1, 0xD1, 0x00, 0x07, 0x10,
  51090. + /* Power setting for norm. mode */
  51091. + -1, 0xD2, 0x01, 0x02,
  51092. + /* Panel driving setting */
  51093. + -1, 0xC0, 0x10, 0x3B, 0x00, 0x02, 0x11,
  51094. + /* Frame rate & inv. */
  51095. + -1, 0xC5, 0x03,
  51096. + /* Pixel format */
  51097. + -1, 0x3A, 0x55,
  51098. + /* Gamma */
  51099. + -1, 0xC8, 0x00, 0x32, 0x36, 0x45, 0x06, 0x16,
  51100. + 0x37, 0x75, 0x77, 0x54, 0x0C, 0x00,
  51101. + /* DISP_ON */
  51102. + -1, 0x29,
  51103. + -3
  51104. +};
  51105. +
  51106. +static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
  51107. +{
  51108. + fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par,
  51109. + "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye);
  51110. +
  51111. + /* column address */
  51112. + write_reg(par, 0x2a, xs >> 8, xs & 0xff, xe >> 8, xe & 0xff);
  51113. +
  51114. + /* row adress */
  51115. + write_reg(par, 0x2b, ys >> 8, ys & 0xff, ye >> 8, ye & 0xff);
  51116. +
  51117. + /* memory write */
  51118. + write_reg(par, 0x2c);
  51119. +}
  51120. +
  51121. +#define HFLIP 0x01
  51122. +#define VFLIP 0x02
  51123. +#define ROWxCOL 0x20
  51124. +static int set_var(struct fbtft_par *par)
  51125. +{
  51126. + fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
  51127. +
  51128. + switch (par->info->var.rotate) {
  51129. + case 270:
  51130. + write_reg(par, 0x36, ROWxCOL | HFLIP | VFLIP | (par->bgr << 3));
  51131. + break;
  51132. + case 180:
  51133. + write_reg(par, 0x36, VFLIP | (par->bgr << 3));
  51134. + break;
  51135. + case 90:
  51136. + write_reg(par, 0x36, ROWxCOL | (par->bgr << 3));
  51137. + break;
  51138. + default:
  51139. + write_reg(par, 0x36, HFLIP | (par->bgr << 3));
  51140. + break;
  51141. + }
  51142. +
  51143. + return 0;
  51144. +}
  51145. +
  51146. +static struct fbtft_display display = {
  51147. + .regwidth = 8,
  51148. + .width = WIDTH,
  51149. + .height = HEIGHT,
  51150. + .init_sequence = default_init_sequence,
  51151. + .fbtftops = {
  51152. + .set_addr_win = set_addr_win,
  51153. + .set_var = set_var,
  51154. + },
  51155. +};
  51156. +FBTFT_REGISTER_DRIVER(DRVNAME, "ilitek,ili9481", &display);
  51157. +
  51158. +MODULE_ALIAS("spi:" DRVNAME);
  51159. +MODULE_ALIAS("platform:" DRVNAME);
  51160. +MODULE_ALIAS("spi:ili9481");
  51161. +MODULE_ALIAS("platform:ili9481");
  51162. +
  51163. +MODULE_DESCRIPTION("FB driver for the ILI9481 LCD Controller");
  51164. +MODULE_AUTHOR("Petr Olivka");
  51165. +MODULE_LICENSE("GPL");
  51166. diff -Nur linux-3.18.8/drivers/staging/fbtft/fb_ili9486.c linux-rpi/drivers/staging/fbtft/fb_ili9486.c
  51167. --- linux-3.18.8/drivers/staging/fbtft/fb_ili9486.c 1970-01-01 01:00:00.000000000 +0100
  51168. +++ linux-rpi/drivers/staging/fbtft/fb_ili9486.c 2015-03-05 14:40:16.341715808 +0100
  51169. @@ -0,0 +1,121 @@
  51170. +/*
  51171. + * FB driver for the ILI9486 LCD Controller
  51172. + *
  51173. + * Copyright (C) 2014 Noralf Tronnes
  51174. + *
  51175. + * This program is free software; you can redistribute it and/or modify
  51176. + * it under the terms of the GNU General Public License as published by
  51177. + * the Free Software Foundation; either version 2 of the License, or
  51178. + * (at your option) any later version.
  51179. + *
  51180. + * This program is distributed in the hope that it will be useful,
  51181. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  51182. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  51183. + * GNU General Public License for more details.
  51184. + *
  51185. + * You should have received a copy of the GNU General Public License
  51186. + * along with this program; if not, write to the Free Software
  51187. + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  51188. + */
  51189. +
  51190. +#include <linux/module.h>
  51191. +#include <linux/kernel.h>
  51192. +#include <linux/init.h>
  51193. +
  51194. +#include "fbtft.h"
  51195. +
  51196. +#define DRVNAME "fb_ili9486"
  51197. +#define WIDTH 320
  51198. +#define HEIGHT 480
  51199. +
  51200. +
  51201. +/* this init sequence matches PiScreen */
  51202. +static int default_init_sequence[] = {
  51203. + /* Interface Mode Control */
  51204. + -1, 0xb0, 0x0,
  51205. + /* Sleep OUT */
  51206. + -1, 0x11,
  51207. + -2, 250,
  51208. + /* Interface Pixel Format */
  51209. + -1, 0x3A, 0x55,
  51210. + /* Power Control 3 */
  51211. + -1, 0xC2, 0x44,
  51212. + /* VCOM Control 1 */
  51213. + -1, 0xC5, 0x00, 0x00, 0x00, 0x00,
  51214. + /* PGAMCTRL(Positive Gamma Control) */
  51215. + -1, 0xE0, 0x0F, 0x1F, 0x1C, 0x0C, 0x0F, 0x08, 0x48, 0x98,
  51216. + 0x37, 0x0A, 0x13, 0x04, 0x11, 0x0D, 0x00,
  51217. + /* NGAMCTRL(Negative Gamma Control) */
  51218. + -1, 0xE1, 0x0F, 0x32, 0x2E, 0x0B, 0x0D, 0x05, 0x47, 0x75,
  51219. + 0x37, 0x06, 0x10, 0x03, 0x24, 0x20, 0x00,
  51220. + /* Digital Gamma Control 1 */
  51221. + -1, 0xE2, 0x0F, 0x32, 0x2E, 0x0B, 0x0D, 0x05, 0x47, 0x75,
  51222. + 0x37, 0x06, 0x10, 0x03, 0x24, 0x20, 0x00,
  51223. + /* Sleep OUT */
  51224. + -1, 0x11,
  51225. + /* Display ON */
  51226. + -1, 0x29,
  51227. + /* end marker */
  51228. + -3
  51229. +};
  51230. +
  51231. +static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
  51232. +{
  51233. + fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par,
  51234. + "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye);
  51235. +
  51236. + /* Column address */
  51237. + write_reg(par, 0x2A, xs >> 8, xs & 0xFF, xe >> 8, xe & 0xFF);
  51238. +
  51239. + /* Row adress */
  51240. + write_reg(par, 0x2B, ys >> 8, ys & 0xFF, ye >> 8, ye & 0xFF);
  51241. +
  51242. + /* Memory write */
  51243. + write_reg(par, 0x2C);
  51244. +}
  51245. +
  51246. +static int set_var(struct fbtft_par *par)
  51247. +{
  51248. + fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
  51249. +
  51250. + switch (par->info->var.rotate) {
  51251. + case 0:
  51252. + write_reg(par, 0x36, 0x80 | (par->bgr << 3));
  51253. + break;
  51254. + case 90:
  51255. + write_reg(par, 0x36, 0x20 | (par->bgr << 3));
  51256. + break;
  51257. + case 180:
  51258. + write_reg(par, 0x36, 0x40 | (par->bgr << 3));
  51259. + break;
  51260. + case 270:
  51261. + write_reg(par, 0x36, 0xE0 | (par->bgr << 3));
  51262. + break;
  51263. + default:
  51264. + break;
  51265. + }
  51266. +
  51267. + return 0;
  51268. +}
  51269. +
  51270. +
  51271. +static struct fbtft_display display = {
  51272. + .regwidth = 8,
  51273. + .width = WIDTH,
  51274. + .height = HEIGHT,
  51275. + .init_sequence = default_init_sequence,
  51276. + .fbtftops = {
  51277. + .set_addr_win = set_addr_win,
  51278. + .set_var = set_var,
  51279. + },
  51280. +};
  51281. +FBTFT_REGISTER_DRIVER(DRVNAME, "ilitek,ili9486", &display);
  51282. +
  51283. +MODULE_ALIAS("spi:" DRVNAME);
  51284. +MODULE_ALIAS("platform:" DRVNAME);
  51285. +MODULE_ALIAS("spi:ili9486");
  51286. +MODULE_ALIAS("platform:ili9486");
  51287. +
  51288. +MODULE_DESCRIPTION("FB driver for the ILI9486 LCD Controller");
  51289. +MODULE_AUTHOR("Noralf Tronnes");
  51290. +MODULE_LICENSE("GPL");
  51291. diff -Nur linux-3.18.8/drivers/staging/fbtft/fb_pcd8544.c linux-rpi/drivers/staging/fbtft/fb_pcd8544.c
  51292. --- linux-3.18.8/drivers/staging/fbtft/fb_pcd8544.c 1970-01-01 01:00:00.000000000 +0100
  51293. +++ linux-rpi/drivers/staging/fbtft/fb_pcd8544.c 2015-03-05 14:40:16.341715808 +0100
  51294. @@ -0,0 +1,177 @@
  51295. +/*
  51296. + * FB driver for the PCD8544 LCD Controller
  51297. + *
  51298. + * The display is monochrome and the video memory is RGB565.
  51299. + * Any pixel value except 0 turns the pixel on.
  51300. + *
  51301. + * Copyright (C) 2013 Noralf Tronnes
  51302. + *
  51303. + * This program is free software; you can redistribute it and/or modify
  51304. + * it under the terms of the GNU General Public License as published by
  51305. + * the Free Software Foundation; either version 2 of the License, or
  51306. + * (at your option) any later version.
  51307. + *
  51308. + * This program is distributed in the hope that it will be useful,
  51309. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  51310. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  51311. + * GNU General Public License for more details.
  51312. + *
  51313. + * You should have received a copy of the GNU General Public License
  51314. + * along with this program; if not, write to the Free Software
  51315. + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  51316. + */
  51317. +
  51318. +#include <linux/module.h>
  51319. +#include <linux/kernel.h>
  51320. +#include <linux/init.h>
  51321. +#include <linux/gpio.h>
  51322. +#include <linux/spi/spi.h>
  51323. +#include <linux/delay.h>
  51324. +
  51325. +#include "fbtft.h"
  51326. +
  51327. +#define DRVNAME "fb_pcd8544"
  51328. +#define WIDTH 84
  51329. +#define HEIGHT 48
  51330. +#define TXBUFLEN (84*6)
  51331. +#define DEFAULT_GAMMA "40" /* gamma is used to control contrast in this driver */
  51332. +
  51333. +static unsigned tc;
  51334. +module_param(tc, uint, 0);
  51335. +MODULE_PARM_DESC(tc, "TC[1:0] Temperature coefficient: 0-3 (default: 0)");
  51336. +
  51337. +static unsigned bs = 4;
  51338. +module_param(bs, uint, 0);
  51339. +MODULE_PARM_DESC(bs, "BS[2:0] Bias voltage level: 0-7 (default: 4)");
  51340. +
  51341. +
  51342. +static int init_display(struct fbtft_par *par)
  51343. +{
  51344. + fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
  51345. +
  51346. + par->fbtftops.reset(par);
  51347. +
  51348. + /* Function set */
  51349. + write_reg(par, 0x21); /* 5:1 1
  51350. + 2:0 PD - Powerdown control: chip is active
  51351. + 1:0 V - Entry mode: horizontal addressing
  51352. + 0:1 H - Extended instruction set control: extended
  51353. + */
  51354. +
  51355. + /* H=1 Temperature control */
  51356. + write_reg(par, 0x04 | (tc & 0x3)); /*
  51357. + 2:1 1
  51358. + 1:x TC1 - Temperature Coefficient: 0x10
  51359. + 0:x TC0
  51360. + */
  51361. +
  51362. + /* H=1 Bias system */
  51363. + write_reg(par, 0x10 | (bs & 0x7)); /*
  51364. + 4:1 1
  51365. + 3:0 0
  51366. + 2:x BS2 - Bias System
  51367. + 1:x BS1
  51368. + 0:x BS0
  51369. + */
  51370. +
  51371. + /* Function set */
  51372. + write_reg(par, 0x22); /* 5:1 1
  51373. + 2:0 PD - Powerdown control: chip is active
  51374. + 1:1 V - Entry mode: vertical addressing
  51375. + 0:0 H - Extended instruction set control: basic
  51376. + */
  51377. +
  51378. + /* H=0 Display control */
  51379. + write_reg(par, 0x08 | 4); /*
  51380. + 3:1 1
  51381. + 2:1 D - DE: 10=normal mode
  51382. + 1:0 0
  51383. + 0:0 E
  51384. + */
  51385. +
  51386. + return 0;
  51387. +}
  51388. +
  51389. +static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
  51390. +{
  51391. + fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par, "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye);
  51392. +
  51393. + /* H=0 Set X address of RAM */
  51394. + write_reg(par, 0x80); /* 7:1 1
  51395. + 6-0: X[6:0] - 0x00
  51396. + */
  51397. +
  51398. + /* H=0 Set Y address of RAM */
  51399. + write_reg(par, 0x40); /* 7:0 0
  51400. + 6:1 1
  51401. + 2-0: Y[2:0] - 0x0
  51402. + */
  51403. +}
  51404. +
  51405. +static int write_vmem(struct fbtft_par *par, size_t offset, size_t len)
  51406. +{
  51407. + u16 *vmem16 = (u16 *)par->info->screen_base;
  51408. + u8 *buf = par->txbuf.buf;
  51409. + int x, y, i;
  51410. + int ret = 0;
  51411. +
  51412. + fbtft_par_dbg(DEBUG_WRITE_VMEM, par, "%s()\n", __func__);
  51413. +
  51414. + for (x = 0; x < 84; x++) {
  51415. + for (y = 0; y < 6; y++) {
  51416. + *buf = 0x00;
  51417. + for (i = 0; i < 8; i++) {
  51418. + *buf |= (vmem16[(y*8+i)*84+x] ? 1 : 0) << i;
  51419. + }
  51420. + buf++;
  51421. + }
  51422. + }
  51423. +
  51424. + /* Write data */
  51425. + gpio_set_value(par->gpio.dc, 1);
  51426. + ret = par->fbtftops.write(par, par->txbuf.buf, 6*84);
  51427. + if (ret < 0)
  51428. + dev_err(par->info->device, "%s: write failed and returned: %d\n", __func__, ret);
  51429. +
  51430. + return ret;
  51431. +}
  51432. +
  51433. +static int set_gamma(struct fbtft_par *par, unsigned long *curves)
  51434. +{
  51435. + fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
  51436. +
  51437. + /* apply mask */
  51438. + curves[0] &= 0x7F;
  51439. +
  51440. + write_reg(par, 0x23); /* turn on extended instruction set */
  51441. + write_reg(par, 0x80 | curves[0]);
  51442. + write_reg(par, 0x22); /* turn off extended instruction set */
  51443. +
  51444. + return 0;
  51445. +}
  51446. +
  51447. +
  51448. +static struct fbtft_display display = {
  51449. + .regwidth = 8,
  51450. + .width = WIDTH,
  51451. + .height = HEIGHT,
  51452. + .txbuflen = TXBUFLEN,
  51453. + .gamma_num = 1,
  51454. + .gamma_len = 1,
  51455. + .gamma = DEFAULT_GAMMA,
  51456. + .fbtftops = {
  51457. + .init_display = init_display,
  51458. + .set_addr_win = set_addr_win,
  51459. + .write_vmem = write_vmem,
  51460. + .set_gamma = set_gamma,
  51461. + },
  51462. + .backlight = 1,
  51463. +};
  51464. +FBTFT_REGISTER_DRIVER(DRVNAME, "philips,pdc8544", &display);
  51465. +
  51466. +MODULE_ALIAS("spi:" DRVNAME);
  51467. +MODULE_ALIAS("spi:pdc8544");
  51468. +
  51469. +MODULE_DESCRIPTION("FB driver for the PCD8544 LCD Controller");
  51470. +MODULE_AUTHOR("Noralf Tronnes");
  51471. +MODULE_LICENSE("GPL");
  51472. diff -Nur linux-3.18.8/drivers/staging/fbtft/fb_ra8875.c linux-rpi/drivers/staging/fbtft/fb_ra8875.c
  51473. --- linux-3.18.8/drivers/staging/fbtft/fb_ra8875.c 1970-01-01 01:00:00.000000000 +0100
  51474. +++ linux-rpi/drivers/staging/fbtft/fb_ra8875.c 2015-03-05 14:40:16.341715808 +0100
  51475. @@ -0,0 +1,331 @@
  51476. +/******************************************************************************
  51477. +
  51478. + ProjectName: FBTFT driver ***** *****
  51479. + for the RA8875 LCD Controller * * ************
  51480. + * ** ** * *
  51481. + Copyright © by Pf@nne & NOTRO * * * * * **** *
  51482. + * * * * * * *
  51483. + Last modification by: * * * * **** *
  51484. + - Pf@nne (pf@nne-mail.de) * * ***** *
  51485. + * * * *******
  51486. + ***** * *
  51487. + Date : 10.06.2014 * *
  51488. + Version : V1.13 *****
  51489. + Revison : 5
  51490. +
  51491. +*******************************************************************************
  51492. + * This program is free software; you can redistribute it and/or modify
  51493. + * it under the terms of the GNU General Public License as published by
  51494. + * the Free Software Foundation; either version 2 of the License, or
  51495. + * (at your option) any later version.
  51496. + *
  51497. + * This program is distributed in the hope that it will be useful,
  51498. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  51499. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  51500. + * GNU General Public License for more details.
  51501. + *
  51502. + * You should have received a copy of the GNU General Public License
  51503. + * along with this program; if not, write to the Free Software
  51504. + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  51505. + */
  51506. +
  51507. +#include <linux/module.h>
  51508. +#include <linux/kernel.h>
  51509. +#include <linux/init.h>
  51510. +#include <linux/delay.h>
  51511. +
  51512. +#include <linux/gpio.h>
  51513. +#include "fbtft.h"
  51514. +
  51515. +#define DRVNAME "fb_ra8875"
  51516. +
  51517. +static int write_spi(struct fbtft_par *par, void *buf, size_t len)
  51518. +{
  51519. + struct spi_transfer t = {
  51520. + .tx_buf = buf,
  51521. + .len = len,
  51522. + .speed_hz = 1000000,
  51523. + };
  51524. + struct spi_message m;
  51525. +
  51526. + fbtft_par_dbg_hex(DEBUG_WRITE, par, par->info->device, u8, buf, len,
  51527. + "%s(len=%d): ", __func__, len);
  51528. +
  51529. + if (!par->spi) {
  51530. + dev_err(par->info->device,
  51531. + "%s: par->spi is unexpectedly NULL\n", __func__);
  51532. + return -1;
  51533. + }
  51534. +
  51535. + spi_message_init(&m);
  51536. + if (par->txbuf.dma && buf == par->txbuf.buf) {
  51537. + t.tx_dma = par->txbuf.dma;
  51538. + m.is_dma_mapped = 1;
  51539. + }
  51540. + spi_message_add_tail(&t, &m);
  51541. + return spi_sync(par->spi, &m);
  51542. +}
  51543. +
  51544. +static int init_display(struct fbtft_par *par)
  51545. +{
  51546. + gpio_set_value(par->gpio.dc, 1);
  51547. +
  51548. + fbtft_par_dbg(DEBUG_INIT_DISPLAY, par,
  51549. + "%s()\n", __func__);
  51550. + fbtft_par_dbg(DEBUG_INIT_DISPLAY, par,
  51551. + "display size %dx%d\n", par->info->var.xres, par->info->var.yres);
  51552. +
  51553. + par->fbtftops.reset(par);
  51554. +
  51555. + if ((par->info->var.xres == 320) && (par->info->var.yres == 240)) {
  51556. + /* PLL clock frequency */
  51557. + write_reg(par, 0x88 , 0x0A);
  51558. + write_reg(par, 0x89 , 0x02);
  51559. + mdelay(10);
  51560. + /* color deep / MCU Interface */
  51561. + write_reg(par, 0x10 , 0x0C);
  51562. + /* pixel clock period */
  51563. + write_reg(par, 0x04 , 0x03);
  51564. + mdelay(1);
  51565. + /* horizontal settings */
  51566. + write_reg(par, 0x14 , 0x27);
  51567. + write_reg(par, 0x15 , 0x00);
  51568. + write_reg(par, 0x16 , 0x05);
  51569. + write_reg(par, 0x17 , 0x04);
  51570. + write_reg(par, 0x18 , 0x03);
  51571. + /* vertical settings */
  51572. + write_reg(par, 0x19 , 0xEF);
  51573. + write_reg(par, 0x1A , 0x00);
  51574. + write_reg(par, 0x1B , 0x05);
  51575. + write_reg(par, 0x1C , 0x00);
  51576. + write_reg(par, 0x1D , 0x0E);
  51577. + write_reg(par, 0x1E , 0x00);
  51578. + write_reg(par, 0x1F , 0x02);
  51579. + } else if ((par->info->var.xres == 480) && (par->info->var.yres == 272)) {
  51580. + /* PLL clock frequency */
  51581. + write_reg(par, 0x88 , 0x0A);
  51582. + write_reg(par, 0x89 , 0x02);
  51583. + mdelay(10);
  51584. + /* color deep / MCU Interface */
  51585. + write_reg(par, 0x10 , 0x0C);
  51586. + /* pixel clock period */
  51587. + write_reg(par, 0x04 , 0x82);
  51588. + mdelay(1);
  51589. + /* horizontal settings */
  51590. + write_reg(par, 0x14 , 0x3B);
  51591. + write_reg(par, 0x15 , 0x00);
  51592. + write_reg(par, 0x16 , 0x01);
  51593. + write_reg(par, 0x17 , 0x00);
  51594. + write_reg(par, 0x18 , 0x05);
  51595. + /* vertical settings */
  51596. + write_reg(par, 0x19 , 0x0F);
  51597. + write_reg(par, 0x1A , 0x01);
  51598. + write_reg(par, 0x1B , 0x02);
  51599. + write_reg(par, 0x1C , 0x00);
  51600. + write_reg(par, 0x1D , 0x07);
  51601. + write_reg(par, 0x1E , 0x00);
  51602. + write_reg(par, 0x1F , 0x09);
  51603. + } else if ((par->info->var.xres == 640) && (par->info->var.yres == 480)) {
  51604. + /* PLL clock frequency */
  51605. + write_reg(par, 0x88 , 0x0B);
  51606. + write_reg(par, 0x89 , 0x02);
  51607. + mdelay(10);
  51608. + /* color deep / MCU Interface */
  51609. + write_reg(par, 0x10 , 0x0C);
  51610. + /* pixel clock period */
  51611. + write_reg(par, 0x04 , 0x01);
  51612. + mdelay(1);
  51613. + /* horizontal settings */
  51614. + write_reg(par, 0x14 , 0x4F);
  51615. + write_reg(par, 0x15 , 0x05);
  51616. + write_reg(par, 0x16 , 0x0F);
  51617. + write_reg(par, 0x17 , 0x01);
  51618. + write_reg(par, 0x18 , 0x00);
  51619. + /* vertical settings */
  51620. + write_reg(par, 0x19 , 0xDF);
  51621. + write_reg(par, 0x1A , 0x01);
  51622. + write_reg(par, 0x1B , 0x0A);
  51623. + write_reg(par, 0x1C , 0x00);
  51624. + write_reg(par, 0x1D , 0x0E);
  51625. + write_reg(par, 0x1E , 0x00);
  51626. + write_reg(par, 0x1F , 0x01);
  51627. + } else if ((par->info->var.xres == 800) && (par->info->var.yres == 480)) {
  51628. + /* PLL clock frequency */
  51629. + write_reg(par, 0x88 , 0x0B);
  51630. + write_reg(par, 0x89 , 0x02);
  51631. + mdelay(10);
  51632. + /* color deep / MCU Interface */
  51633. + write_reg(par, 0x10 , 0x0C);
  51634. + /* pixel clock period */
  51635. + write_reg(par, 0x04 , 0x81);
  51636. + mdelay(1);
  51637. + /* horizontal settings */
  51638. + write_reg(par, 0x14 , 0x63);
  51639. + write_reg(par, 0x15 , 0x03);
  51640. + write_reg(par, 0x16 , 0x03);
  51641. + write_reg(par, 0x17 , 0x02);
  51642. + write_reg(par, 0x18 , 0x00);
  51643. + /* vertical settings */
  51644. + write_reg(par, 0x19 , 0xDF);
  51645. + write_reg(par, 0x1A , 0x01);
  51646. + write_reg(par, 0x1B , 0x14);
  51647. + write_reg(par, 0x1C , 0x00);
  51648. + write_reg(par, 0x1D , 0x06);
  51649. + write_reg(par, 0x1E , 0x00);
  51650. + write_reg(par, 0x1F , 0x01);
  51651. + } else {
  51652. + dev_err(par->info->device, "display size is not supported!!");
  51653. + return -1;
  51654. + }
  51655. +
  51656. + /* PWM clock */
  51657. + write_reg(par, 0x8a , 0x81);
  51658. + write_reg(par, 0x8b , 0xFF);
  51659. + mdelay(10);
  51660. +
  51661. + /* Display ON */
  51662. + write_reg(par, 0x01 , 0x80);
  51663. + mdelay(10);
  51664. +
  51665. + return 0;
  51666. +}
  51667. +
  51668. +static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
  51669. +{
  51670. + fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par,
  51671. + "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye);
  51672. +
  51673. + /* Set_Active_Window */
  51674. + write_reg(par, 0x30 , xs & 0x00FF);
  51675. + write_reg(par, 0x31 , (xs & 0xFF00) >> 8);
  51676. + write_reg(par, 0x32 , ys & 0x00FF);
  51677. + write_reg(par, 0x33 , (ys & 0xFF00) >> 8);
  51678. + write_reg(par, 0x34 , (xs+xe) & 0x00FF);
  51679. + write_reg(par, 0x35 , ((xs+xe) & 0xFF00) >> 8);
  51680. + write_reg(par, 0x36 , (ys+ye) & 0x00FF);
  51681. + write_reg(par, 0x37 , ((ys+ye) & 0xFF00) >> 8);
  51682. +
  51683. + /* Set_Memory_Write_Cursor */
  51684. + write_reg(par, 0x46, xs & 0xff);
  51685. + write_reg(par, 0x47, (xs >> 8) & 0x03);
  51686. + write_reg(par, 0x48, ys & 0xff);
  51687. + write_reg(par, 0x49, (ys >> 8) & 0x01);
  51688. +
  51689. + write_reg(par, 0x02);
  51690. +}
  51691. +
  51692. +static void write_reg8_bus8(struct fbtft_par *par, int len, ...)
  51693. +{
  51694. + va_list args;
  51695. + int i, ret;
  51696. + u8 *buf = (u8 *)par->buf;
  51697. +
  51698. + /* slow down spi-speed for writing registers */
  51699. + par->fbtftops.write = write_spi;
  51700. +
  51701. + if (unlikely(par->debug & DEBUG_WRITE_REGISTER)) {
  51702. + va_start(args, len);
  51703. + for (i = 0; i < len; i++)
  51704. + buf[i] = (u8)va_arg(args, unsigned int);
  51705. + va_end(args);
  51706. + fbtft_par_dbg_hex(DEBUG_WRITE_REGISTER, par, par->info->device,
  51707. + u8, buf, len, "%s: ", __func__);
  51708. + }
  51709. +
  51710. + va_start(args, len);
  51711. + *buf++ = 0x80;
  51712. + *buf = (u8)va_arg(args, unsigned int);
  51713. + ret = par->fbtftops.write(par, par->buf, 2);
  51714. + if (ret < 0) {
  51715. + va_end(args);
  51716. + dev_err(par->info->device, "%s: write() failed and returned %dn",
  51717. + __func__, ret);
  51718. + return;
  51719. + }
  51720. + len--;
  51721. +
  51722. + udelay(100);
  51723. +
  51724. + if (len) {
  51725. + buf = (u8 *)par->buf;
  51726. + *buf++ = 0x00;
  51727. + i = len;
  51728. + while (i--)
  51729. + *buf++ = (u8)va_arg(args, unsigned int);
  51730. +
  51731. + ret = par->fbtftops.write(par, par->buf, len + 1);
  51732. + if (ret < 0) {
  51733. + va_end(args);
  51734. + dev_err(par->info->device, "%s: write() failed and returned %dn",
  51735. + __func__, ret);
  51736. + return;
  51737. + }
  51738. + }
  51739. + va_end(args);
  51740. +
  51741. + /* restore user spi-speed */
  51742. + par->fbtftops.write = fbtft_write_spi;
  51743. + udelay(100);
  51744. +}
  51745. +
  51746. +static int write_vmem16_bus8(struct fbtft_par *par, size_t offset, size_t len)
  51747. +{
  51748. + u16 *vmem16;
  51749. + u16 *txbuf16 = (u16 *)par->txbuf.buf;
  51750. + size_t remain;
  51751. + size_t to_copy;
  51752. + size_t tx_array_size;
  51753. + int i;
  51754. + int ret = 0;
  51755. + size_t startbyte_size = 0;
  51756. +
  51757. + fbtft_par_dbg(DEBUG_WRITE_VMEM, par, "%s(offset=%zu, len=%zu)\n",
  51758. + __func__, offset, len);
  51759. +
  51760. + remain = len / 2;
  51761. + vmem16 = (u16 *)(par->info->screen_base + offset);
  51762. + tx_array_size = par->txbuf.len / 2;
  51763. + txbuf16 = (u16 *)(par->txbuf.buf + 1);
  51764. + tx_array_size -= 2;
  51765. + *(u8 *)(par->txbuf.buf) = 0x00;
  51766. + startbyte_size = 1;
  51767. +
  51768. + while (remain) {
  51769. + to_copy = remain > tx_array_size ? tx_array_size : remain;
  51770. + dev_dbg(par->info->device, " to_copy=%zu, remain=%zu\n",
  51771. + to_copy, remain - to_copy);
  51772. +
  51773. + for (i = 0; i < to_copy; i++)
  51774. + txbuf16[i] = cpu_to_be16(vmem16[i]);
  51775. +
  51776. + vmem16 = vmem16 + to_copy;
  51777. + ret = par->fbtftops.write(par, par->txbuf.buf,
  51778. + startbyte_size + to_copy * 2);
  51779. + if (ret < 0)
  51780. + return ret;
  51781. + remain -= to_copy;
  51782. + }
  51783. +
  51784. + return ret;
  51785. +}
  51786. +
  51787. +static struct fbtft_display display = {
  51788. + .regwidth = 8,
  51789. + .fbtftops = {
  51790. + .init_display = init_display,
  51791. + .set_addr_win = set_addr_win,
  51792. + .write_register = write_reg8_bus8,
  51793. + .write_vmem = write_vmem16_bus8,
  51794. + .write = write_spi,
  51795. + },
  51796. +};
  51797. +FBTFT_REGISTER_DRIVER(DRVNAME, "raio,ra8875", &display);
  51798. +
  51799. +MODULE_ALIAS("spi:" DRVNAME);
  51800. +MODULE_ALIAS("platform:" DRVNAME);
  51801. +MODULE_ALIAS("spi:ra8875");
  51802. +MODULE_ALIAS("platform:ra8875");
  51803. +
  51804. +MODULE_DESCRIPTION("FB driver for the RA8875 LCD Controller");
  51805. +MODULE_AUTHOR("Pf@nne");
  51806. +MODULE_LICENSE("GPL");
  51807. diff -Nur linux-3.18.8/drivers/staging/fbtft/fb_s6d02a1.c linux-rpi/drivers/staging/fbtft/fb_s6d02a1.c
  51808. --- linux-3.18.8/drivers/staging/fbtft/fb_s6d02a1.c 1970-01-01 01:00:00.000000000 +0100
  51809. +++ linux-rpi/drivers/staging/fbtft/fb_s6d02a1.c 2015-03-05 14:40:16.341715808 +0100
  51810. @@ -0,0 +1,168 @@
  51811. +/*
  51812. + * FB driver for the S6D02A1 LCD Controller
  51813. + *
  51814. + * Based on fb_st7735r.c by Noralf Tronnes
  51815. + * Init code from UTFT library by Henning Karlsen
  51816. + *
  51817. + * This program is free software; you can redistribute it and/or modify
  51818. + * it under the terms of the GNU General Public License as published by
  51819. + * the Free Software Foundation; either version 2 of the License, or
  51820. + * (at your option) any later version.
  51821. + *
  51822. + * This program is distributed in the hope that it will be useful,
  51823. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  51824. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  51825. + * GNU General Public License for more details.
  51826. + *
  51827. + * You should have received a copy of the GNU General Public License
  51828. + * along with this program; if not, write to the Free Software
  51829. + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  51830. + */
  51831. +
  51832. +#include <linux/module.h>
  51833. +#include <linux/kernel.h>
  51834. +#include <linux/init.h>
  51835. +
  51836. +#include "fbtft.h"
  51837. +
  51838. +#define DRVNAME "fb_s6d02a1"
  51839. +
  51840. +static int default_init_sequence[] = {
  51841. +
  51842. + -1, 0xf0, 0x5a, 0x5a,
  51843. +
  51844. + -1, 0xfc, 0x5a, 0x5a,
  51845. +
  51846. + -1, 0xfa, 0x02, 0x1f, 0x00, 0x10, 0x22, 0x30, 0x38, 0x3A, 0x3A, 0x3A, 0x3A, 0x3A, 0x3d, 0x02, 0x01,
  51847. +
  51848. + -1, 0xfb, 0x21, 0x00, 0x02, 0x04, 0x07, 0x0a, 0x0b, 0x0c, 0x0c, 0x16, 0x1e, 0x30, 0x3f, 0x01, 0x02,
  51849. +
  51850. + /* power setting sequence */
  51851. + -1, 0xfd, 0x00, 0x00, 0x00, 0x17, 0x10, 0x00, 0x01, 0x01, 0x00, 0x1f, 0x1f,
  51852. +
  51853. + -1, 0xf4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x3f, 0x07, 0x00, 0x3C, 0x36, 0x00, 0x3C, 0x36, 0x00,
  51854. +
  51855. + -1, 0xf5, 0x00, 0x70, 0x66, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6d, 0x66, 0x06,
  51856. +
  51857. + -1, 0xf6, 0x02, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x02, 0x00, 0x06, 0x01, 0x00,
  51858. +
  51859. + -1, 0xf2, 0x00, 0x01, 0x03, 0x08, 0x08, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x04, 0x08, 0x08,
  51860. +
  51861. + -1, 0xf8, 0x11,
  51862. +
  51863. + -1, 0xf7, 0xc8, 0x20, 0x00, 0x00,
  51864. +
  51865. + -1, 0xf3, 0x00, 0x00,
  51866. +
  51867. + -1, 0x11,
  51868. + -2, 50,
  51869. +
  51870. + -1, 0xf3, 0x00, 0x01,
  51871. + -2, 50,
  51872. + -1, 0xf3, 0x00, 0x03,
  51873. + -2, 50,
  51874. + -1, 0xf3, 0x00, 0x07,
  51875. + -2, 50,
  51876. + -1, 0xf3, 0x00, 0x0f,
  51877. + -2, 50,
  51878. +
  51879. + -1, 0xf4, 0x00, 0x04, 0x00, 0x00, 0x00, 0x3f, 0x3f, 0x07, 0x00, 0x3C, 0x36, 0x00, 0x3C, 0x36, 0x00,
  51880. + -2, 50,
  51881. +
  51882. + -1, 0xf3, 0x00, 0x1f,
  51883. + -2, 50,
  51884. + -1, 0xf3, 0x00, 0x7f,
  51885. + -2, 50,
  51886. +
  51887. + -1, 0xf3, 0x00, 0xff,
  51888. + -2, 50,
  51889. +
  51890. + -1, 0xfd, 0x00, 0x00, 0x00, 0x17, 0x10, 0x00, 0x00, 0x01, 0x00, 0x16, 0x16,
  51891. +
  51892. + -1, 0xf4, 0x00, 0x09, 0x00, 0x00, 0x00, 0x3f, 0x3f, 0x07, 0x00, 0x3C, 0x36, 0x00, 0x3C, 0x36, 0x00,
  51893. +
  51894. + /* initializing sequence */
  51895. +
  51896. + -1, 0x36, 0x08,
  51897. +
  51898. + -1, 0x35, 0x00,
  51899. +
  51900. + -1, 0x3a, 0x05,
  51901. +
  51902. + /* gamma setting sequence */
  51903. + -1, 0x26, 0x01, /* preset gamma curves, possible values 0x01, 0x02, 0x04, 0x08 */
  51904. +
  51905. + -2, 150,
  51906. + -1, 0x29,
  51907. + -1, 0x2c,
  51908. + /* end marker */
  51909. + -3
  51910. +
  51911. +};
  51912. +
  51913. +static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
  51914. +{
  51915. + fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par,
  51916. + "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye);
  51917. +
  51918. + /* Column address */
  51919. + write_reg(par, 0x2A, xs >> 8, xs & 0xFF, xe >> 8, xe & 0xFF);
  51920. +
  51921. + /* Row adress */
  51922. + write_reg(par, 0x2B, ys >> 8, ys & 0xFF, ye >> 8, ye & 0xFF);
  51923. +
  51924. + /* Memory write */
  51925. + write_reg(par, 0x2C);
  51926. +}
  51927. +
  51928. +#define MY (1 << 7)
  51929. +#define MX (1 << 6)
  51930. +#define MV (1 << 5)
  51931. +static int set_var(struct fbtft_par *par)
  51932. +{
  51933. + fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
  51934. +
  51935. + /* MADCTL - Memory data access control
  51936. + RGB/BGR:
  51937. + 1. Mode selection pin SRGB
  51938. + RGB H/W pin for color filter setting: 0=RGB, 1=BGR
  51939. + 2. MADCTL RGB bit
  51940. + RGB-BGR ORDER color filter panel: 0=RGB, 1=BGR */
  51941. + switch (par->info->var.rotate) {
  51942. + case 0:
  51943. + write_reg(par, 0x36, MX | MY | (par->bgr << 3));
  51944. + break;
  51945. + case 270:
  51946. + write_reg(par, 0x36, MY | MV | (par->bgr << 3));
  51947. + break;
  51948. + case 180:
  51949. + write_reg(par, 0x36, (par->bgr << 3));
  51950. + break;
  51951. + case 90:
  51952. + write_reg(par, 0x36, MX | MV | (par->bgr << 3));
  51953. + break;
  51954. + }
  51955. +
  51956. + return 0;
  51957. +}
  51958. +
  51959. +static struct fbtft_display display = {
  51960. + .regwidth = 8,
  51961. + .width = 128,
  51962. + .height = 160,
  51963. + .init_sequence = default_init_sequence,
  51964. + .fbtftops = {
  51965. + .set_addr_win = set_addr_win,
  51966. + .set_var = set_var,
  51967. + },
  51968. +};
  51969. +FBTFT_REGISTER_DRIVER(DRVNAME, "samsung,s6d02a1", &display);
  51970. +
  51971. +MODULE_ALIAS("spi:" DRVNAME);
  51972. +MODULE_ALIAS("platform:" DRVNAME);
  51973. +MODULE_ALIAS("spi:s6d02a1");
  51974. +MODULE_ALIAS("platform:s6d02a1");
  51975. +
  51976. +MODULE_DESCRIPTION("FB driver for the S6D02A1 LCD Controller");
  51977. +MODULE_AUTHOR("WOLFGANG BUENING");
  51978. +MODULE_LICENSE("GPL");
  51979. diff -Nur linux-3.18.8/drivers/staging/fbtft/fb_s6d1121.c linux-rpi/drivers/staging/fbtft/fb_s6d1121.c
  51980. --- linux-3.18.8/drivers/staging/fbtft/fb_s6d1121.c 1970-01-01 01:00:00.000000000 +0100
  51981. +++ linux-rpi/drivers/staging/fbtft/fb_s6d1121.c 2015-03-05 14:40:16.341715808 +0100
  51982. @@ -0,0 +1,208 @@
  51983. +/*
  51984. + * FB driver for the S6D1121 LCD Controller
  51985. + *
  51986. + * Copyright (C) 2013 Roman Rolinsky
  51987. + *
  51988. + * Based on fb_ili9325.c by Noralf Tronnes
  51989. + * Based on ili9325.c by Jeroen Domburg
  51990. + * Init code from UTFT library by Henning Karlsen
  51991. + *
  51992. + * This program is free software; you can redistribute it and/or modify
  51993. + * it under the terms of the GNU General Public License as published by
  51994. + * the Free Software Foundation; either version 2 of the License, or
  51995. + * (at your option) any later version.
  51996. + *
  51997. + * This program is distributed in the hope that it will be useful,
  51998. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  51999. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  52000. + * GNU General Public License for more details.
  52001. + *
  52002. + * You should have received a copy of the GNU General Public License
  52003. + * along with this program; if not, write to the Free Software
  52004. + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  52005. + */
  52006. +
  52007. +#include <linux/module.h>
  52008. +#include <linux/kernel.h>
  52009. +#include <linux/init.h>
  52010. +#include <linux/gpio.h>
  52011. +#include <linux/delay.h>
  52012. +
  52013. +#include "fbtft.h"
  52014. +
  52015. +#define DRVNAME "fb_s6d1121"
  52016. +#define WIDTH 240
  52017. +#define HEIGHT 320
  52018. +#define BPP 16
  52019. +#define FPS 20
  52020. +#define DEFAULT_GAMMA "26 09 24 2C 1F 23 24 25 22 26 25 23 0D 00\n" \
  52021. + "1C 1A 13 1D 0B 11 12 10 13 15 36 19 00 0D"
  52022. +
  52023. +static int init_display(struct fbtft_par *par)
  52024. +{
  52025. + fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
  52026. +
  52027. + par->fbtftops.reset(par);
  52028. +
  52029. + if (par->gpio.cs != -1)
  52030. + gpio_set_value(par->gpio.cs, 0); /* Activate chip */
  52031. +
  52032. + /* Initialization sequence from Lib_UTFT */
  52033. +
  52034. + write_reg(par, 0x0011, 0x2004);
  52035. + write_reg(par, 0x0013, 0xCC00);
  52036. + write_reg(par, 0x0015, 0x2600);
  52037. + write_reg(par, 0x0014, 0x252A);
  52038. + write_reg(par, 0x0012, 0x0033);
  52039. + write_reg(par, 0x0013, 0xCC04);
  52040. + write_reg(par, 0x0013, 0xCC06);
  52041. + write_reg(par, 0x0013, 0xCC4F);
  52042. + write_reg(par, 0x0013, 0x674F);
  52043. + write_reg(par, 0x0011, 0x2003);
  52044. + write_reg(par, 0x0016, 0x0007);
  52045. + write_reg(par, 0x0002, 0x0013);
  52046. + write_reg(par, 0x0003, 0x0003);
  52047. + write_reg(par, 0x0001, 0x0127);
  52048. + write_reg(par, 0x0008, 0x0303);
  52049. + write_reg(par, 0x000A, 0x000B);
  52050. + write_reg(par, 0x000B, 0x0003);
  52051. + write_reg(par, 0x000C, 0x0000);
  52052. + write_reg(par, 0x0041, 0x0000);
  52053. + write_reg(par, 0x0050, 0x0000);
  52054. + write_reg(par, 0x0060, 0x0005);
  52055. + write_reg(par, 0x0070, 0x000B);
  52056. + write_reg(par, 0x0071, 0x0000);
  52057. + write_reg(par, 0x0078, 0x0000);
  52058. + write_reg(par, 0x007A, 0x0000);
  52059. + write_reg(par, 0x0079, 0x0007);
  52060. + write_reg(par, 0x0007, 0x0051);
  52061. + write_reg(par, 0x0007, 0x0053);
  52062. + write_reg(par, 0x0079, 0x0000);
  52063. +
  52064. + write_reg(par, 0x0022); /* Write Data to GRAM */
  52065. +
  52066. + return 0;
  52067. +}
  52068. +
  52069. +static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
  52070. +{
  52071. + fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par,
  52072. + "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye);
  52073. + switch (par->info->var.rotate) {
  52074. + /* R20h = Horizontal GRAM Start Address */
  52075. + /* R21h = Vertical GRAM Start Address */
  52076. + case 0:
  52077. + write_reg(par, 0x0020, xs);
  52078. + write_reg(par, 0x0021, ys);
  52079. + break;
  52080. + case 180:
  52081. + write_reg(par, 0x0020, WIDTH - 1 - xs);
  52082. + write_reg(par, 0x0021, HEIGHT - 1 - ys);
  52083. + break;
  52084. + case 270:
  52085. + write_reg(par, 0x0020, WIDTH - 1 - ys);
  52086. + write_reg(par, 0x0021, xs);
  52087. + break;
  52088. + case 90:
  52089. + write_reg(par, 0x0020, ys);
  52090. + write_reg(par, 0x0021, HEIGHT - 1 - xs);
  52091. + break;
  52092. + }
  52093. + write_reg(par, 0x0022); /* Write Data to GRAM */
  52094. +}
  52095. +
  52096. +static int set_var(struct fbtft_par *par)
  52097. +{
  52098. + fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
  52099. +
  52100. + switch (par->info->var.rotate) {
  52101. + /* AM: GRAM update direction */
  52102. + case 0:
  52103. + write_reg(par, 0x03, 0x0003 | (par->bgr << 12));
  52104. + break;
  52105. + case 180:
  52106. + write_reg(par, 0x03, 0x0000 | (par->bgr << 12));
  52107. + break;
  52108. + case 270:
  52109. + write_reg(par, 0x03, 0x000A | (par->bgr << 12));
  52110. + break;
  52111. + case 90:
  52112. + write_reg(par, 0x03, 0x0009 | (par->bgr << 12));
  52113. + break;
  52114. + }
  52115. +
  52116. + return 0;
  52117. +}
  52118. +
  52119. +/*
  52120. + Gamma string format:
  52121. + PKP0 PKP1 PKP2 PKP3 PKP4 PKP5 PKP6 PKP7 PKP8 PKP9 PKP10 PKP11 VRP0 VRP1
  52122. + PKN0 PKN1 PKN2 PKN3 PKN4 PKN5 PKN6 PKN7 PRN8 PRN9 PRN10 PRN11 VRN0 VRN1
  52123. +*/
  52124. +#define CURVE(num, idx) curves[num*par->gamma.num_values + idx]
  52125. +static int set_gamma(struct fbtft_par *par, unsigned long *curves)
  52126. +{
  52127. + unsigned long mask[] = {
  52128. + 0b111111, 0b111111, 0b111111, 0b111111, 0b111111, 0b111111,
  52129. + 0b111111, 0b111111, 0b111111, 0b111111, 0b111111, 0b111111,
  52130. + 0b11111, 0b11111,
  52131. + 0b111111, 0b111111, 0b111111, 0b111111, 0b111111, 0b111111,
  52132. + 0b111111, 0b111111, 0b111111, 0b111111, 0b111111, 0b111111,
  52133. + 0b11111, 0b11111 };
  52134. + int i, j;
  52135. +
  52136. + fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
  52137. +
  52138. + /* apply mask */
  52139. + for (i = 0; i < 2; i++)
  52140. + for (j = 0; j < 14; j++)
  52141. + CURVE(i, j) &= mask[i*par->gamma.num_values + j];
  52142. +
  52143. + write_reg(par, 0x0030, CURVE(0, 1) << 8 | CURVE(0, 0));
  52144. + write_reg(par, 0x0031, CURVE(0, 3) << 8 | CURVE(0, 2));
  52145. + write_reg(par, 0x0032, CURVE(0, 5) << 8 | CURVE(0, 3));
  52146. + write_reg(par, 0x0033, CURVE(0, 7) << 8 | CURVE(0, 6));
  52147. + write_reg(par, 0x0034, CURVE(0, 9) << 8 | CURVE(0, 8));
  52148. + write_reg(par, 0x0035, CURVE(0, 11) << 8 | CURVE(0, 10));
  52149. +
  52150. + write_reg(par, 0x0036, CURVE(1, 1) << 8 | CURVE(1, 0));
  52151. + write_reg(par, 0x0037, CURVE(1, 3) << 8 | CURVE(1, 2));
  52152. + write_reg(par, 0x0038, CURVE(1, 5) << 8 | CURVE(1, 4));
  52153. + write_reg(par, 0x0039, CURVE(1, 7) << 8 | CURVE(1, 6));
  52154. + write_reg(par, 0x003A, CURVE(1, 9) << 8 | CURVE(1, 8));
  52155. + write_reg(par, 0x003B, CURVE(1, 11) << 8 | CURVE(1, 10));
  52156. +
  52157. + write_reg(par, 0x003C, CURVE(0, 13) << 8 | CURVE(0, 12));
  52158. + write_reg(par, 0x003D, CURVE(1, 13) << 8 | CURVE(1, 12));
  52159. +
  52160. + return 0;
  52161. +}
  52162. +#undef CURVE
  52163. +
  52164. +
  52165. +static struct fbtft_display display = {
  52166. + .regwidth = 16,
  52167. + .width = WIDTH,
  52168. + .height = HEIGHT,
  52169. + .bpp = BPP,
  52170. + .fps = FPS,
  52171. + .gamma_num = 2,
  52172. + .gamma_len = 14,
  52173. + .gamma = DEFAULT_GAMMA,
  52174. + .fbtftops = {
  52175. + .init_display = init_display,
  52176. + .set_addr_win = set_addr_win,
  52177. + .set_var = set_var,
  52178. + .set_gamma = set_gamma,
  52179. + },
  52180. +};
  52181. +FBTFT_REGISTER_DRIVER(DRVNAME, "samsung,s6d1121", &display);
  52182. +
  52183. +MODULE_ALIAS("spi:" DRVNAME);
  52184. +MODULE_ALIAS("platform:" DRVNAME);
  52185. +MODULE_ALIAS("spi:s6d1121");
  52186. +MODULE_ALIAS("platform:s6d1121");
  52187. +
  52188. +MODULE_DESCRIPTION("FB driver for the S6D1121 LCD Controller");
  52189. +MODULE_AUTHOR("Roman Rolinsky");
  52190. +MODULE_LICENSE("GPL");
  52191. diff -Nur linux-3.18.8/drivers/staging/fbtft/fb_ssd1289.c linux-rpi/drivers/staging/fbtft/fb_ssd1289.c
  52192. --- linux-3.18.8/drivers/staging/fbtft/fb_ssd1289.c 1970-01-01 01:00:00.000000000 +0100
  52193. +++ linux-rpi/drivers/staging/fbtft/fb_ssd1289.c 2015-03-05 14:40:16.341715808 +0100
  52194. @@ -0,0 +1,206 @@
  52195. +/*
  52196. + * FB driver for the SSD1289 LCD Controller
  52197. + *
  52198. + * Copyright (C) 2013 Noralf Tronnes
  52199. + *
  52200. + * Init sequence taken from ITDB02_Graph16.cpp - (C)2010-2011 Henning Karlsen
  52201. + *
  52202. + * This program is free software; you can redistribute it and/or modify
  52203. + * it under the terms of the GNU General Public License as published by
  52204. + * the Free Software Foundation; either version 2 of the License, or
  52205. + * (at your option) any later version.
  52206. + *
  52207. + * This program is distributed in the hope that it will be useful,
  52208. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  52209. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  52210. + * GNU General Public License for more details.
  52211. + *
  52212. + * You should have received a copy of the GNU General Public License
  52213. + * along with this program; if not, write to the Free Software
  52214. + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  52215. + */
  52216. +
  52217. +#include <linux/module.h>
  52218. +#include <linux/kernel.h>
  52219. +#include <linux/init.h>
  52220. +#include <linux/gpio.h>
  52221. +
  52222. +#include "fbtft.h"
  52223. +
  52224. +#define DRVNAME "fb_ssd1289"
  52225. +#define WIDTH 240
  52226. +#define HEIGHT 320
  52227. +#define DEFAULT_GAMMA "02 03 2 5 7 7 4 2 4 2\n" \
  52228. + "02 03 2 5 7 5 4 2 4 2"
  52229. +
  52230. +static unsigned reg11 = 0x6040;
  52231. +module_param(reg11, uint, 0);
  52232. +MODULE_PARM_DESC(reg11, "Register 11h value");
  52233. +
  52234. +
  52235. +static int init_display(struct fbtft_par *par)
  52236. +{
  52237. + fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
  52238. +
  52239. + par->fbtftops.reset(par);
  52240. +
  52241. + if (par->gpio.cs != -1)
  52242. + gpio_set_value(par->gpio.cs, 0); /* Activate chip */
  52243. +
  52244. + write_reg(par, 0x00, 0x0001);
  52245. + write_reg(par, 0x03, 0xA8A4);
  52246. + write_reg(par, 0x0C, 0x0000);
  52247. + write_reg(par, 0x0D, 0x080C);
  52248. + write_reg(par, 0x0E, 0x2B00);
  52249. + write_reg(par, 0x1E, 0x00B7);
  52250. + write_reg(par, 0x01,
  52251. + (1 << 13) | (par->bgr << 11) | (1 << 9) | (HEIGHT - 1));
  52252. + write_reg(par, 0x02, 0x0600);
  52253. + write_reg(par, 0x10, 0x0000);
  52254. + write_reg(par, 0x05, 0x0000);
  52255. + write_reg(par, 0x06, 0x0000);
  52256. + write_reg(par, 0x16, 0xEF1C);
  52257. + write_reg(par, 0x17, 0x0003);
  52258. + write_reg(par, 0x07, 0x0233);
  52259. + write_reg(par, 0x0B, 0x0000);
  52260. + write_reg(par, 0x0F, 0x0000);
  52261. + write_reg(par, 0x41, 0x0000);
  52262. + write_reg(par, 0x42, 0x0000);
  52263. + write_reg(par, 0x48, 0x0000);
  52264. + write_reg(par, 0x49, 0x013F);
  52265. + write_reg(par, 0x4A, 0x0000);
  52266. + write_reg(par, 0x4B, 0x0000);
  52267. + write_reg(par, 0x44, 0xEF00);
  52268. + write_reg(par, 0x45, 0x0000);
  52269. + write_reg(par, 0x46, 0x013F);
  52270. + write_reg(par, 0x23, 0x0000);
  52271. + write_reg(par, 0x24, 0x0000);
  52272. + write_reg(par, 0x25, 0x8000);
  52273. + write_reg(par, 0x4f, 0x0000);
  52274. + write_reg(par, 0x4e, 0x0000);
  52275. + write_reg(par, 0x22);
  52276. + return 0;
  52277. +}
  52278. +
  52279. +static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
  52280. +{
  52281. + fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par,
  52282. + "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye);
  52283. +
  52284. + switch (par->info->var.rotate) {
  52285. + /* R4Eh - Set GDDRAM X address counter */
  52286. + /* R4Fh - Set GDDRAM Y address counter */
  52287. + case 0:
  52288. + write_reg(par, 0x4e, xs);
  52289. + write_reg(par, 0x4f, ys);
  52290. + break;
  52291. + case 180:
  52292. + write_reg(par, 0x4e, par->info->var.xres - 1 - xs);
  52293. + write_reg(par, 0x4f, par->info->var.yres - 1 - ys);
  52294. + break;
  52295. + case 270:
  52296. + write_reg(par, 0x4e, par->info->var.yres - 1 - ys);
  52297. + write_reg(par, 0x4f, xs);
  52298. + break;
  52299. + case 90:
  52300. + write_reg(par, 0x4e, ys);
  52301. + write_reg(par, 0x4f, par->info->var.xres - 1 - xs);
  52302. + break;
  52303. + }
  52304. +
  52305. + /* R22h - RAM data write */
  52306. + write_reg(par, 0x22);
  52307. +}
  52308. +
  52309. +static int set_var(struct fbtft_par *par)
  52310. +{
  52311. + fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
  52312. +
  52313. + if (par->fbtftops.init_display != init_display) {
  52314. + /* don't risk messing up register 11h */
  52315. + fbtft_par_dbg(DEBUG_INIT_DISPLAY, par,
  52316. + "%s: skipping since custom init_display() is used\n",
  52317. + __func__);
  52318. + return 0;
  52319. + }
  52320. +
  52321. + switch (par->info->var.rotate) {
  52322. + case 0:
  52323. + write_reg(par, 0x11, reg11 | 0b110000);
  52324. + break;
  52325. + case 270:
  52326. + write_reg(par, 0x11, reg11 | 0b101000);
  52327. + break;
  52328. + case 180:
  52329. + write_reg(par, 0x11, reg11 | 0b000000);
  52330. + break;
  52331. + case 90:
  52332. + write_reg(par, 0x11, reg11 | 0b011000);
  52333. + break;
  52334. + }
  52335. +
  52336. + return 0;
  52337. +}
  52338. +
  52339. +/*
  52340. + Gamma string format:
  52341. + VRP0 VRP1 PRP0 PRP1 PKP0 PKP1 PKP2 PKP3 PKP4 PKP5
  52342. + VRN0 VRN1 PRN0 PRN1 PKN0 PKN1 PKN2 PKN3 PKN4 PKN5
  52343. +*/
  52344. +#define CURVE(num, idx) curves[num*par->gamma.num_values + idx]
  52345. +static int set_gamma(struct fbtft_par *par, unsigned long *curves)
  52346. +{
  52347. + unsigned long mask[] = {
  52348. + 0b11111, 0b11111, 0b111, 0b111, 0b111,
  52349. + 0b111, 0b111, 0b111, 0b111, 0b111,
  52350. + 0b11111, 0b11111, 0b111, 0b111, 0b111,
  52351. + 0b111, 0b111, 0b111, 0b111, 0b111 };
  52352. + int i, j;
  52353. +
  52354. + fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
  52355. +
  52356. + /* apply mask */
  52357. + for (i = 0; i < 2; i++)
  52358. + for (j = 0; j < 10; j++)
  52359. + CURVE(i, j) &= mask[i*par->gamma.num_values + j];
  52360. +
  52361. + write_reg(par, 0x0030, CURVE(0, 5) << 8 | CURVE(0, 4));
  52362. + write_reg(par, 0x0031, CURVE(0, 7) << 8 | CURVE(0, 6));
  52363. + write_reg(par, 0x0032, CURVE(0, 9) << 8 | CURVE(0, 8));
  52364. + write_reg(par, 0x0033, CURVE(0, 3) << 8 | CURVE(0, 2));
  52365. + write_reg(par, 0x0034, CURVE(1, 5) << 8 | CURVE(1, 4));
  52366. + write_reg(par, 0x0035, CURVE(1, 7) << 8 | CURVE(1, 6));
  52367. + write_reg(par, 0x0036, CURVE(1, 9) << 8 | CURVE(1, 8));
  52368. + write_reg(par, 0x0037, CURVE(1, 3) << 8 | CURVE(1, 2));
  52369. + write_reg(par, 0x003A, CURVE(0, 1) << 8 | CURVE(0, 0));
  52370. + write_reg(par, 0x003B, CURVE(1, 1) << 8 | CURVE(1, 0));
  52371. +
  52372. + return 0;
  52373. +}
  52374. +#undef CURVE
  52375. +
  52376. +
  52377. +static struct fbtft_display display = {
  52378. + .regwidth = 16,
  52379. + .width = WIDTH,
  52380. + .height = HEIGHT,
  52381. + .gamma_num = 2,
  52382. + .gamma_len = 10,
  52383. + .gamma = DEFAULT_GAMMA,
  52384. + .fbtftops = {
  52385. + .init_display = init_display,
  52386. + .set_addr_win = set_addr_win,
  52387. + .set_var = set_var,
  52388. + .set_gamma = set_gamma,
  52389. + },
  52390. +};
  52391. +FBTFT_REGISTER_DRIVER(DRVNAME, "solomon,ssd1289", &display);
  52392. +
  52393. +MODULE_ALIAS("spi:" DRVNAME);
  52394. +MODULE_ALIAS("platform:" DRVNAME);
  52395. +MODULE_ALIAS("spi:ssd1289");
  52396. +MODULE_ALIAS("platform:ssd1289");
  52397. +
  52398. +MODULE_DESCRIPTION("FB driver for the SSD1289 LCD Controller");
  52399. +MODULE_AUTHOR("Noralf Tronnes");
  52400. +MODULE_LICENSE("GPL");
  52401. diff -Nur linux-3.18.8/drivers/staging/fbtft/fb_ssd1306.c linux-rpi/drivers/staging/fbtft/fb_ssd1306.c
  52402. --- linux-3.18.8/drivers/staging/fbtft/fb_ssd1306.c 1970-01-01 01:00:00.000000000 +0100
  52403. +++ linux-rpi/drivers/staging/fbtft/fb_ssd1306.c 2015-03-05 14:40:16.341715808 +0100
  52404. @@ -0,0 +1,229 @@
  52405. +/*
  52406. + * FB driver for the SSD1306 OLED Controller
  52407. + *
  52408. + * Copyright (C) 2013 Noralf Tronnes
  52409. + *
  52410. + * This program is free software; you can redistribute it and/or modify
  52411. + * it under the terms of the GNU General Public License as published by
  52412. + * the Free Software Foundation; either version 2 of the License, or
  52413. + * (at your option) any later version.
  52414. + *
  52415. + * This program is distributed in the hope that it will be useful,
  52416. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  52417. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  52418. + * GNU General Public License for more details.
  52419. + *
  52420. + * You should have received a copy of the GNU General Public License
  52421. + * along with this program; if not, write to the Free Software
  52422. + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  52423. + */
  52424. +
  52425. +#include <linux/module.h>
  52426. +#include <linux/kernel.h>
  52427. +#include <linux/init.h>
  52428. +#include <linux/gpio.h>
  52429. +#include <linux/delay.h>
  52430. +
  52431. +#include "fbtft.h"
  52432. +
  52433. +#define DRVNAME "fb_ssd1306"
  52434. +#define WIDTH 128
  52435. +#define HEIGHT 64
  52436. +
  52437. +
  52438. +/*
  52439. + write_reg() caveat:
  52440. +
  52441. + This doesn't work because D/C has to be LOW for both values:
  52442. + write_reg(par, val1, val2);
  52443. +
  52444. + Do it like this:
  52445. + write_reg(par, val1);
  52446. + write_reg(par, val2);
  52447. +*/
  52448. +
  52449. +/* Init sequence taken from the Adafruit SSD1306 Arduino library */
  52450. +static int init_display(struct fbtft_par *par)
  52451. +{
  52452. + fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
  52453. +
  52454. + par->fbtftops.reset(par);
  52455. +
  52456. + if (par->gamma.curves[0] == 0) {
  52457. + mutex_lock(&par->gamma.lock);
  52458. + if (par->info->var.yres == 64)
  52459. + par->gamma.curves[0] = 0xCF;
  52460. + else
  52461. + par->gamma.curves[0] = 0x8F;
  52462. + mutex_unlock(&par->gamma.lock);
  52463. + }
  52464. +
  52465. + /* Set Display OFF */
  52466. + write_reg(par, 0xAE);
  52467. +
  52468. + /* Set Display Clock Divide Ratio/ Oscillator Frequency */
  52469. + write_reg(par, 0xD5);
  52470. + write_reg(par, 0x80);
  52471. +
  52472. + /* Set Multiplex Ratio */
  52473. + write_reg(par, 0xA8);
  52474. + if (par->info->var.yres == 64)
  52475. + write_reg(par, 0x3F);
  52476. + else
  52477. + write_reg(par, 0x1F);
  52478. +
  52479. + /* Set Display Offset */
  52480. + write_reg(par, 0xD3);
  52481. + write_reg(par, 0x0);
  52482. +
  52483. + /* Set Display Start Line */
  52484. + write_reg(par, 0x40 | 0x0);
  52485. +
  52486. + /* Charge Pump Setting */
  52487. + write_reg(par, 0x8D);
  52488. + /* A[2] = 1b, Enable charge pump during display on */
  52489. + write_reg(par, 0x14);
  52490. +
  52491. + /* Set Memory Addressing Mode */
  52492. + write_reg(par, 0x20);
  52493. + /* Vertical addressing mode */
  52494. + write_reg(par, 0x01);
  52495. +
  52496. + /*Set Segment Re-map */
  52497. + /* column address 127 is mapped to SEG0 */
  52498. + write_reg(par, 0xA0 | 0x1);
  52499. +
  52500. + /* Set COM Output Scan Direction */
  52501. + /* remapped mode. Scan from COM[N-1] to COM0 */
  52502. + write_reg(par, 0xC8);
  52503. +
  52504. + /* Set COM Pins Hardware Configuration */
  52505. + write_reg(par, 0xDA);
  52506. + if (par->info->var.yres == 64)
  52507. + /* A[4]=1b, Alternative COM pin configuration */
  52508. + write_reg(par, 0x12);
  52509. + else
  52510. + /* A[4]=0b, Sequential COM pin configuration */
  52511. + write_reg(par, 0x02);
  52512. +
  52513. + /* Set Pre-charge Period */
  52514. + write_reg(par, 0xD9);
  52515. + write_reg(par, 0xF1);
  52516. +
  52517. + /* Set VCOMH Deselect Level */
  52518. + write_reg(par, 0xDB);
  52519. + /* according to the datasheet, this value is out of bounds */
  52520. + write_reg(par, 0x40);
  52521. +
  52522. + /* Entire Display ON */
  52523. + /* Resume to RAM content display. Output follows RAM content */
  52524. + write_reg(par, 0xA4);
  52525. +
  52526. + /* Set Normal Display
  52527. + 0 in RAM: OFF in display panel
  52528. + 1 in RAM: ON in display panel */
  52529. + write_reg(par, 0xA6);
  52530. +
  52531. + /* Set Display ON */
  52532. + write_reg(par, 0xAF);
  52533. +
  52534. + return 0;
  52535. +}
  52536. +
  52537. +static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
  52538. +{
  52539. + fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par,
  52540. + "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye);
  52541. +
  52542. + /* Set Lower Column Start Address for Page Addressing Mode */
  52543. + write_reg(par, 0x00 | 0x0);
  52544. + /* Set Higher Column Start Address for Page Addressing Mode */
  52545. + write_reg(par, 0x10 | 0x0);
  52546. + /* Set Display Start Line */
  52547. + write_reg(par, 0x40 | 0x0);
  52548. +}
  52549. +
  52550. +static int blank(struct fbtft_par *par, bool on)
  52551. +{
  52552. + fbtft_par_dbg(DEBUG_BLANK, par, "%s(blank=%s)\n",
  52553. + __func__, on ? "true" : "false");
  52554. +
  52555. + if (on)
  52556. + write_reg(par, 0xAE);
  52557. + else
  52558. + write_reg(par, 0xAF);
  52559. + return 0;
  52560. +}
  52561. +
  52562. +/* Gamma is used to control Contrast */
  52563. +static int set_gamma(struct fbtft_par *par, unsigned long *curves)
  52564. +{
  52565. + fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
  52566. +
  52567. + /* apply mask */
  52568. + curves[0] &= 0xFF;
  52569. +
  52570. + /* Set Contrast Control for BANK0 */
  52571. + write_reg(par, 0x81);
  52572. + write_reg(par, curves[0]);
  52573. +
  52574. + return 0;
  52575. +}
  52576. +
  52577. +static int write_vmem(struct fbtft_par *par, size_t offset, size_t len)
  52578. +{
  52579. + u16 *vmem16 = (u16 *)par->info->screen_base;
  52580. + u8 *buf = par->txbuf.buf;
  52581. + int x, y, i;
  52582. + int ret = 0;
  52583. +
  52584. + fbtft_par_dbg(DEBUG_WRITE_VMEM, par, "%s()\n", __func__);
  52585. +
  52586. + for (x = 0; x < par->info->var.xres; x++) {
  52587. + for (y = 0; y < par->info->var.yres/8; y++) {
  52588. + *buf = 0x00;
  52589. + for (i = 0; i < 8; i++)
  52590. + *buf |= (vmem16[(y*8+i)*par->info->var.xres+x] ? 1 : 0) << i;
  52591. + buf++;
  52592. + }
  52593. + }
  52594. +
  52595. + /* Write data */
  52596. + gpio_set_value(par->gpio.dc, 1);
  52597. + ret = par->fbtftops.write(par, par->txbuf.buf,
  52598. + par->info->var.xres*par->info->var.yres/8);
  52599. + if (ret < 0)
  52600. + dev_err(par->info->device,
  52601. + "%s: write failed and returned: %d\n", __func__, ret);
  52602. +
  52603. + return ret;
  52604. +}
  52605. +
  52606. +
  52607. +static struct fbtft_display display = {
  52608. + .regwidth = 8,
  52609. + .width = WIDTH,
  52610. + .height = HEIGHT,
  52611. + .gamma_num = 1,
  52612. + .gamma_len = 1,
  52613. + .gamma = "00",
  52614. + .fbtftops = {
  52615. + .write_vmem = write_vmem,
  52616. + .init_display = init_display,
  52617. + .set_addr_win = set_addr_win,
  52618. + .blank = blank,
  52619. + .set_gamma = set_gamma,
  52620. + },
  52621. +};
  52622. +
  52623. +
  52624. +FBTFT_REGISTER_DRIVER(DRVNAME, "solomon,ssd1306", &display);
  52625. +
  52626. +MODULE_ALIAS("spi:" DRVNAME);
  52627. +MODULE_ALIAS("platform:" DRVNAME);
  52628. +MODULE_ALIAS("spi:ssd1306");
  52629. +MODULE_ALIAS("platform:ssd1306");
  52630. +
  52631. +MODULE_DESCRIPTION("SSD1306 OLED Driver");
  52632. +MODULE_AUTHOR("Noralf Tronnes");
  52633. +MODULE_LICENSE("GPL");
  52634. diff -Nur linux-3.18.8/drivers/staging/fbtft/fb_ssd1331.c linux-rpi/drivers/staging/fbtft/fb_ssd1331.c
  52635. --- linux-3.18.8/drivers/staging/fbtft/fb_ssd1331.c 1970-01-01 01:00:00.000000000 +0100
  52636. +++ linux-rpi/drivers/staging/fbtft/fb_ssd1331.c 2015-03-05 14:40:16.345715808 +0100
  52637. @@ -0,0 +1,205 @@
  52638. +#include <linux/module.h>
  52639. +#include <linux/kernel.h>
  52640. +#include <linux/init.h>
  52641. +#include <linux/gpio.h>
  52642. +#include <linux/spi/spi.h>
  52643. +#include <linux/delay.h>
  52644. +
  52645. +#include "fbtft.h"
  52646. +
  52647. +#define DRVNAME "fb_ssd1331"
  52648. +#define WIDTH 96
  52649. +#define HEIGHT 64
  52650. +#define GAMMA_NUM 1
  52651. +#define GAMMA_LEN 63
  52652. +#define DEFAULT_GAMMA "0 2 2 2 2 2 2 2 " \
  52653. + "2 2 2 2 2 2 2 2 " \
  52654. + "2 2 2 2 2 2 2 2 " \
  52655. + "2 2 2 2 2 2 2 2 " \
  52656. + "2 2 2 2 2 2 2 2 " \
  52657. + "2 2 2 2 2 2 2 2 " \
  52658. + "2 2 2 2 2 2 2 2 " \
  52659. + "2 2 2 2 2 2 2" \
  52660. +
  52661. +static int init_display(struct fbtft_par *par)
  52662. +{
  52663. + fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
  52664. +
  52665. + par->fbtftops.reset(par);
  52666. +
  52667. + write_reg(par, 0xae); /* Display Off */
  52668. + write_reg(par, 0xa0, 0x70 | (par->bgr << 2)); /* Set Colour Depth */
  52669. + write_reg(par, 0x72); // RGB colour
  52670. + write_reg(par, 0xa1, 0x00); /* Set Display Start Line */
  52671. + write_reg(par, 0xa2, 0x00); /* Set Display Offset */
  52672. + write_reg(par, 0xa4); /* NORMALDISPLAY */
  52673. + write_reg(par, 0xa8, 0x3f); // Set multiplex
  52674. + write_reg(par, 0xad, 0x8e); // Set master
  52675. + // write_reg(par, 0xb0, 0x0b); // Set power mode
  52676. + write_reg(par, 0xb1, 0x31); // Precharge
  52677. + write_reg(par, 0xb3, 0xf0); // Clock div
  52678. + write_reg(par, 0x8a, 0x64); // Precharge A
  52679. + write_reg(par, 0x8b, 0x78); // Precharge B
  52680. + write_reg(par, 0x8c, 0x64); // Precharge C
  52681. + write_reg(par, 0xbb, 0x3a); // Precharge level
  52682. + write_reg(par, 0xbe, 0x3e); // vcomh
  52683. + write_reg(par, 0x87, 0x06); // Master current
  52684. + write_reg(par, 0x81, 0x91); // Contrast A
  52685. + write_reg(par, 0x82, 0x50); // Contrast B
  52686. + write_reg(par, 0x83, 0x7d); // Contrast C
  52687. + write_reg(par, 0xaf); /* Set Sleep Mode Display On */
  52688. +
  52689. + return 0;
  52690. +}
  52691. +
  52692. +static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
  52693. +{
  52694. + fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par,
  52695. + "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye);
  52696. +
  52697. + write_reg(par, 0x15, xs, xe);
  52698. + write_reg(par, 0x75, ys, ye);
  52699. +}
  52700. +
  52701. +static void write_reg8_bus8(struct fbtft_par *par, int len, ...)
  52702. +{
  52703. + va_list args;
  52704. + int i, ret;
  52705. + u8 *buf = (u8 *)par->buf;
  52706. +
  52707. + if (unlikely(par->debug & DEBUG_WRITE_REGISTER)) {
  52708. + va_start(args, len);
  52709. + for (i = 0; i < len; i++) {
  52710. + buf[i] = (u8)va_arg(args, unsigned int);
  52711. + }
  52712. + va_end(args);
  52713. + fbtft_par_dbg_hex(DEBUG_WRITE_REGISTER, par, par->info->device, u8, buf, len, "%s: ", __func__);
  52714. + }
  52715. +
  52716. + va_start(args, len);
  52717. +
  52718. + *buf = (u8)va_arg(args, unsigned int);
  52719. + if (par->gpio.dc != -1)
  52720. + gpio_set_value(par->gpio.dc, 0);
  52721. + ret = par->fbtftops.write(par, par->buf, sizeof(u8));
  52722. + if (ret < 0) {
  52723. + va_end(args);
  52724. + dev_err(par->info->device, "%s: write() failed and returned %d\n", __func__, ret);
  52725. + return;
  52726. + }
  52727. + len--;
  52728. +
  52729. + if (len) {
  52730. + i = len;
  52731. + while (i--) {
  52732. + *buf++ = (u8)va_arg(args, unsigned int);
  52733. + }
  52734. + ret = par->fbtftops.write(par, par->buf, len * (sizeof(u8)));
  52735. + if (ret < 0) {
  52736. + va_end(args);
  52737. + dev_err(par->info->device, "%s: write() failed and returned %d\n", __func__, ret);
  52738. + return;
  52739. + }
  52740. + }
  52741. + if (par->gpio.dc != -1)
  52742. + gpio_set_value(par->gpio.dc, 1);
  52743. + va_end(args);
  52744. +}
  52745. +
  52746. +/*
  52747. + Grayscale Lookup Table
  52748. + GS1 - GS63
  52749. + The driver Gamma curve contains the relative values between the entries
  52750. + in the Lookup table.
  52751. +
  52752. + From datasheet:
  52753. + 8.8 Gray Scale Decoder
  52754. +
  52755. + there are total 180 Gamma Settings (Setting 0 to Setting 180)
  52756. + available for the Gray Scale table.
  52757. +
  52758. + The gray scale is defined in incremental way, with reference
  52759. + to the length of previous table entry:
  52760. + Setting of GS1 has to be >= 0
  52761. + Setting of GS2 has to be > Setting of GS1 +1
  52762. + Setting of GS3 has to be > Setting of GS2 +1
  52763. + :
  52764. + Setting of GS63 has to be > Setting of GS62 +1
  52765. +
  52766. +
  52767. +*/
  52768. +static int set_gamma(struct fbtft_par *par, unsigned long *curves)
  52769. +{
  52770. + unsigned long tmp[GAMMA_NUM * GAMMA_LEN];
  52771. + int i, acc = 0;
  52772. +
  52773. + fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
  52774. +
  52775. + for (i = 0; i < 63; i++) {
  52776. + if (i > 0 && curves[i] < 2) {
  52777. + dev_err(par->info->device,
  52778. + "Illegal value in Grayscale Lookup Table at index %d. " \
  52779. + "Must be greater than 1\n", i);
  52780. + return -EINVAL;
  52781. + }
  52782. + acc += curves[i];
  52783. + tmp[i] = acc;
  52784. + if (acc > 180) {
  52785. + dev_err(par->info->device,
  52786. + "Illegal value(s) in Grayscale Lookup Table. " \
  52787. + "At index=%d, the accumulated value has exceeded 180\n", i);
  52788. + return -EINVAL;
  52789. + }
  52790. + }
  52791. +
  52792. + write_reg(par, 0xB8,
  52793. + tmp[0], tmp[1], tmp[2], tmp[3], tmp[4], tmp[5], tmp[6], tmp[7],
  52794. + tmp[8], tmp[9], tmp[10], tmp[11], tmp[12], tmp[13], tmp[14], tmp[15],
  52795. + tmp[16], tmp[17], tmp[18], tmp[19], tmp[20], tmp[21], tmp[22], tmp[23],
  52796. + tmp[24], tmp[25], tmp[26], tmp[27], tmp[28], tmp[29], tmp[30], tmp[31],
  52797. + tmp[32], tmp[33], tmp[34], tmp[35], tmp[36], tmp[37], tmp[38], tmp[39],
  52798. + tmp[40], tmp[41], tmp[42], tmp[43], tmp[44], tmp[45], tmp[46], tmp[47],
  52799. + tmp[48], tmp[49], tmp[50], tmp[51], tmp[52], tmp[53], tmp[54], tmp[55],
  52800. + tmp[56], tmp[57], tmp[58], tmp[59], tmp[60], tmp[61], tmp[62]);
  52801. +
  52802. + return 0;
  52803. +}
  52804. +
  52805. +static int blank(struct fbtft_par *par, bool on)
  52806. +{
  52807. + fbtft_par_dbg(DEBUG_BLANK, par, "%s(blank=%s)\n",
  52808. + __func__, on ? "true" : "false");
  52809. + if (on)
  52810. + write_reg(par, 0xAE);
  52811. + else
  52812. + write_reg(par, 0xAF);
  52813. + return 0;
  52814. +}
  52815. +
  52816. +
  52817. +static struct fbtft_display display = {
  52818. + .regwidth = 8,
  52819. + .width = WIDTH,
  52820. + .height = HEIGHT,
  52821. + .gamma_num = GAMMA_NUM,
  52822. + .gamma_len = GAMMA_LEN,
  52823. + .gamma = DEFAULT_GAMMA,
  52824. + .fbtftops = {
  52825. + .write_register = write_reg8_bus8,
  52826. + .init_display = init_display,
  52827. + .set_addr_win = set_addr_win,
  52828. + .set_gamma = set_gamma,
  52829. + .blank = blank,
  52830. + },
  52831. +};
  52832. +
  52833. +FBTFT_REGISTER_DRIVER(DRVNAME, "solomon,ssd1331", &display);
  52834. +
  52835. +MODULE_ALIAS("spi:" DRVNAME);
  52836. +MODULE_ALIAS("platform:" DRVNAME);
  52837. +MODULE_ALIAS("spi:ssd1331");
  52838. +MODULE_ALIAS("platform:ssd1331");
  52839. +
  52840. +MODULE_DESCRIPTION("SSD1331 OLED Driver");
  52841. +MODULE_AUTHOR("Alec Smecher (adapted from SSD1351 by James Davies)");
  52842. +MODULE_LICENSE("GPL");
  52843. diff -Nur linux-3.18.8/drivers/staging/fbtft/fb_ssd1351.c linux-rpi/drivers/staging/fbtft/fb_ssd1351.c
  52844. --- linux-3.18.8/drivers/staging/fbtft/fb_ssd1351.c 1970-01-01 01:00:00.000000000 +0100
  52845. +++ linux-rpi/drivers/staging/fbtft/fb_ssd1351.c 2015-03-05 14:40:16.345715808 +0100
  52846. @@ -0,0 +1,258 @@
  52847. +#include <linux/module.h>
  52848. +#include <linux/kernel.h>
  52849. +#include <linux/init.h>
  52850. +#include <linux/gpio.h>
  52851. +#include <linux/spi/spi.h>
  52852. +#include <linux/delay.h>
  52853. +
  52854. +#include "fbtft.h"
  52855. +
  52856. +#define DRVNAME "fb_ssd1351"
  52857. +#define WIDTH 128
  52858. +#define HEIGHT 128
  52859. +#define GAMMA_NUM 1
  52860. +#define GAMMA_LEN 63
  52861. +#define DEFAULT_GAMMA "0 2 2 2 2 2 2 2 " \
  52862. + "2 2 2 2 2 2 2 2 " \
  52863. + "2 2 2 2 2 2 2 2 " \
  52864. + "2 2 2 2 2 2 2 2 " \
  52865. + "2 2 2 2 2 2 2 2 " \
  52866. + "2 2 2 2 2 2 2 2 " \
  52867. + "2 2 2 2 2 2 2 2 " \
  52868. + "2 2 2 2 2 2 2" \
  52869. +
  52870. +static void register_onboard_backlight(struct fbtft_par *par);
  52871. +
  52872. +static int init_display(struct fbtft_par *par)
  52873. +{
  52874. + fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
  52875. +
  52876. + if (par->pdata
  52877. + && par->pdata->display.backlight == FBTFT_ONBOARD_BACKLIGHT) {
  52878. + /* module uses onboard GPIO for panel power */
  52879. + par->fbtftops.register_backlight = register_onboard_backlight;
  52880. + }
  52881. +
  52882. + par->fbtftops.reset(par);
  52883. +
  52884. + write_reg(par, 0xfd, 0x12); /* Command Lock */
  52885. + write_reg(par, 0xfd, 0xb1); /* Command Lock */
  52886. + write_reg(par, 0xae); /* Display Off */
  52887. + write_reg(par, 0xb3, 0xf1); /* Front Clock Div */
  52888. + write_reg(par, 0xca, 0x7f); /* Set Mux Ratio */
  52889. + write_reg(par, 0x15, 0x00, 0x7f); /* Set Column Address */
  52890. + write_reg(par, 0x75, 0x00, 0x7f); /* Set Row Address */
  52891. + write_reg(par, 0xa1, 0x00); /* Set Display Start Line */
  52892. + write_reg(par, 0xa2, 0x00); /* Set Display Offset */
  52893. + write_reg(par, 0xb5, 0x00); /* Set GPIO */
  52894. + write_reg(par, 0xab, 0x01); /* Set Function Selection */
  52895. + write_reg(par, 0xb1, 0x32); /* Set Phase Length */
  52896. + write_reg(par, 0xb4, 0xa0, 0xb5, 0x55); /* Set Segment Low Voltage */
  52897. + write_reg(par, 0xbb, 0x17); /* Set Precharge Voltage */
  52898. + write_reg(par, 0xbe, 0x05); /* Set VComH Voltage */
  52899. + write_reg(par, 0xc1, 0xc8, 0x80, 0xc8); /* Set Contrast */
  52900. + write_reg(par, 0xc7, 0x0f); /* Set Master Contrast */
  52901. + write_reg(par, 0xb6, 0x01); /* Set Second Precharge Period */
  52902. + write_reg(par, 0xa6); /* Set Display Mode Reset */
  52903. + write_reg(par, 0xaf); /* Set Sleep Mode Display On */
  52904. +
  52905. + return 0;
  52906. +}
  52907. +
  52908. +static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
  52909. +{
  52910. + fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par,
  52911. + "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye);
  52912. +
  52913. + write_reg(par, 0x15, xs, xe);
  52914. + write_reg(par, 0x75, ys, ye);
  52915. + write_reg(par, 0x5c);
  52916. +}
  52917. +
  52918. +static int set_var(struct fbtft_par *par)
  52919. +{
  52920. + unsigned remap;
  52921. + fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
  52922. +
  52923. + if (par->fbtftops.init_display != init_display) {
  52924. + /* don't risk messing up register A0h */
  52925. + fbtft_par_dbg(DEBUG_INIT_DISPLAY, par,
  52926. + "%s: skipping since custom init_display() is used\n",
  52927. + __func__);
  52928. + return 0;
  52929. + }
  52930. +
  52931. + remap = 0x60 | (par->bgr << 2); /* Set Colour Depth */
  52932. +
  52933. + switch (par->info->var.rotate) {
  52934. + case 0:
  52935. + write_reg(par, 0xA0, remap | 0b00 | 1<<4);
  52936. + break;
  52937. + case 270:
  52938. + write_reg(par, 0xA0, remap | 0b11 | 1<<4);
  52939. + break;
  52940. + case 180:
  52941. + write_reg(par, 0xA0, remap | 0b10);
  52942. + break;
  52943. + case 90:
  52944. + write_reg(par, 0xA0, remap | 0b01);
  52945. + break;
  52946. + }
  52947. +
  52948. + return 0;
  52949. +}
  52950. +
  52951. +/*
  52952. + Grayscale Lookup Table
  52953. + GS1 - GS63
  52954. + The driver Gamma curve contains the relative values between the entries
  52955. + in the Lookup table.
  52956. +
  52957. + From datasheet:
  52958. + 8.8 Gray Scale Decoder
  52959. +
  52960. + there are total 180 Gamma Settings (Setting 0 to Setting 180)
  52961. + available for the Gray Scale table.
  52962. +
  52963. + The gray scale is defined in incremental way, with reference
  52964. + to the length of previous table entry:
  52965. + Setting of GS1 has to be >= 0
  52966. + Setting of GS2 has to be > Setting of GS1 +1
  52967. + Setting of GS3 has to be > Setting of GS2 +1
  52968. + :
  52969. + Setting of GS63 has to be > Setting of GS62 +1
  52970. +
  52971. +
  52972. +*/
  52973. +static int set_gamma(struct fbtft_par *par, unsigned long *curves)
  52974. +{
  52975. + unsigned long tmp[GAMMA_NUM * GAMMA_LEN];
  52976. + int i, acc = 0;
  52977. +
  52978. + fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
  52979. +
  52980. + for (i = 0; i < 63; i++) {
  52981. + if (i > 0 && curves[i] < 2) {
  52982. + dev_err(par->info->device,
  52983. + "Illegal value in Grayscale Lookup Table at index %d. " \
  52984. + "Must be greater than 1\n", i);
  52985. + return -EINVAL;
  52986. + }
  52987. + acc += curves[i];
  52988. + tmp[i] = acc;
  52989. + if (acc > 180) {
  52990. + dev_err(par->info->device,
  52991. + "Illegal value(s) in Grayscale Lookup Table. " \
  52992. + "At index=%d, the accumulated value has exceeded 180\n", i);
  52993. + return -EINVAL;
  52994. + }
  52995. + }
  52996. +
  52997. + write_reg(par, 0xB8,
  52998. + tmp[0], tmp[1], tmp[2], tmp[3], tmp[4], tmp[5], tmp[6], tmp[7],
  52999. + tmp[8], tmp[9], tmp[10], tmp[11], tmp[12], tmp[13], tmp[14], tmp[15],
  53000. + tmp[16], tmp[17], tmp[18], tmp[19], tmp[20], tmp[21], tmp[22], tmp[23],
  53001. + tmp[24], tmp[25], tmp[26], tmp[27], tmp[28], tmp[29], tmp[30], tmp[31],
  53002. + tmp[32], tmp[33], tmp[34], tmp[35], tmp[36], tmp[37], tmp[38], tmp[39],
  53003. + tmp[40], tmp[41], tmp[42], tmp[43], tmp[44], tmp[45], tmp[46], tmp[47],
  53004. + tmp[48], tmp[49], tmp[50], tmp[51], tmp[52], tmp[53], tmp[54], tmp[55],
  53005. + tmp[56], tmp[57], tmp[58], tmp[59], tmp[60], tmp[61], tmp[62]);
  53006. +
  53007. + return 0;
  53008. +}
  53009. +
  53010. +static int blank(struct fbtft_par *par, bool on)
  53011. +{
  53012. + fbtft_par_dbg(DEBUG_BLANK, par, "%s(blank=%s)\n",
  53013. + __func__, on ? "true" : "false");
  53014. + if (on)
  53015. + write_reg(par, 0xAE);
  53016. + else
  53017. + write_reg(par, 0xAF);
  53018. + return 0;
  53019. +}
  53020. +
  53021. +
  53022. +static struct fbtft_display display = {
  53023. + .regwidth = 8,
  53024. + .width = WIDTH,
  53025. + .height = HEIGHT,
  53026. + .gamma_num = GAMMA_NUM,
  53027. + .gamma_len = GAMMA_LEN,
  53028. + .gamma = DEFAULT_GAMMA,
  53029. + .fbtftops = {
  53030. + .init_display = init_display,
  53031. + .set_addr_win = set_addr_win,
  53032. + .set_var = set_var,
  53033. + .set_gamma = set_gamma,
  53034. + .blank = blank,
  53035. + },
  53036. +};
  53037. +
  53038. +#ifdef CONFIG_FB_BACKLIGHT
  53039. +static int update_onboard_backlight(struct backlight_device *bd)
  53040. +{
  53041. + struct fbtft_par *par = bl_get_data(bd);
  53042. + bool on;
  53043. +
  53044. + fbtft_par_dbg(DEBUG_BACKLIGHT, par,
  53045. + "%s: power=%d, fb_blank=%d\n",
  53046. + __func__, bd->props.power, bd->props.fb_blank);
  53047. +
  53048. + on = (bd->props.power == FB_BLANK_UNBLANK)
  53049. + && (bd->props.fb_blank == FB_BLANK_UNBLANK);
  53050. + /* Onboard backlight connected to GPIO0 on SSD1351, GPIO1 unused */
  53051. + write_reg(par, 0xB5, on ? 0x03 : 0x02);
  53052. +
  53053. + return 0;
  53054. +}
  53055. +
  53056. +static void register_onboard_backlight(struct fbtft_par *par)
  53057. +{
  53058. + struct backlight_device *bd;
  53059. + struct backlight_properties bl_props = { 0, };
  53060. + struct backlight_ops *bl_ops;
  53061. +
  53062. + fbtft_par_dbg(DEBUG_BACKLIGHT, par, "%s()\n", __func__);
  53063. +
  53064. + bl_ops = devm_kzalloc(par->info->device, sizeof(struct backlight_ops),
  53065. + GFP_KERNEL);
  53066. + if (!bl_ops) {
  53067. + dev_err(par->info->device,
  53068. + "%s: could not allocate memory for backlight operations.\n",
  53069. + __func__);
  53070. + return;
  53071. + }
  53072. +
  53073. + bl_ops->update_status = update_onboard_backlight;
  53074. + bl_props.type = BACKLIGHT_RAW;
  53075. + bl_props.power = FB_BLANK_POWERDOWN;
  53076. +
  53077. + bd = backlight_device_register(dev_driver_string(par->info->device),
  53078. + par->info->device, par, bl_ops, &bl_props);
  53079. + if (IS_ERR(bd)) {
  53080. + dev_err(par->info->device,
  53081. + "cannot register backlight device (%ld)\n",
  53082. + PTR_ERR(bd));
  53083. + return;
  53084. + }
  53085. + par->info->bl_dev = bd;
  53086. +
  53087. + if (!par->fbtftops.unregister_backlight)
  53088. + par->fbtftops.unregister_backlight = fbtft_unregister_backlight;
  53089. +}
  53090. +#else
  53091. +static void register_onboard_backlight(struct fbtft_par *par) { };
  53092. +#endif
  53093. +
  53094. +
  53095. +FBTFT_REGISTER_DRIVER(DRVNAME, "solomon,ssd1351", &display);
  53096. +
  53097. +MODULE_ALIAS("spi:" DRVNAME);
  53098. +MODULE_ALIAS("platform:" DRVNAME);
  53099. +MODULE_ALIAS("spi:ssd1351");
  53100. +MODULE_ALIAS("platform:ssd1351");
  53101. +
  53102. +MODULE_DESCRIPTION("SSD1351 OLED Driver");
  53103. +MODULE_AUTHOR("James Davies");
  53104. +MODULE_LICENSE("GPL");
  53105. diff -Nur linux-3.18.8/drivers/staging/fbtft/fb_st7735r.c linux-rpi/drivers/staging/fbtft/fb_st7735r.c
  53106. --- linux-3.18.8/drivers/staging/fbtft/fb_st7735r.c 1970-01-01 01:00:00.000000000 +0100
  53107. +++ linux-rpi/drivers/staging/fbtft/fb_st7735r.c 2015-03-05 14:40:16.345715808 +0100
  53108. @@ -0,0 +1,195 @@
  53109. +/*
  53110. + * FB driver for the ST7735R LCD Controller
  53111. + *
  53112. + * Copyright (C) 2013 Noralf Tronnes
  53113. + *
  53114. + * This program is free software; you can redistribute it and/or modify
  53115. + * it under the terms of the GNU General Public License as published by
  53116. + * the Free Software Foundation; either version 2 of the License, or
  53117. + * (at your option) any later version.
  53118. + *
  53119. + * This program is distributed in the hope that it will be useful,
  53120. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  53121. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  53122. + * GNU General Public License for more details.
  53123. + *
  53124. + * You should have received a copy of the GNU General Public License
  53125. + * along with this program; if not, write to the Free Software
  53126. + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  53127. + */
  53128. +
  53129. +#include <linux/module.h>
  53130. +#include <linux/kernel.h>
  53131. +#include <linux/init.h>
  53132. +
  53133. +#include "fbtft.h"
  53134. +
  53135. +#define DRVNAME "fb_st7735r"
  53136. +#define DEFAULT_GAMMA "0F 1A 0F 18 2F 28 20 22 1F 1B 23 37 00 07 02 10\n" \
  53137. + "0F 1B 0F 17 33 2C 29 2E 30 30 39 3F 00 07 03 10"
  53138. +
  53139. +
  53140. +static int default_init_sequence[] = {
  53141. + /* SWRESET - Software reset */
  53142. + -1, 0x01,
  53143. + -2, 150, /* delay */
  53144. +
  53145. + /* SLPOUT - Sleep out & booster on */
  53146. + -1, 0x11,
  53147. + -2, 500, /* delay */
  53148. +
  53149. + /* FRMCTR1 - frame rate control: normal mode
  53150. + frame rate = fosc / (1 x 2 + 40) * (LINE + 2C + 2D) */
  53151. + -1, 0xB1, 0x01, 0x2C, 0x2D,
  53152. +
  53153. + /* FRMCTR2 - frame rate control: idle mode
  53154. + frame rate = fosc / (1 x 2 + 40) * (LINE + 2C + 2D) */
  53155. + -1, 0xB2, 0x01, 0x2C, 0x2D,
  53156. +
  53157. + /* FRMCTR3 - frame rate control - partial mode
  53158. + dot inversion mode, line inversion mode */
  53159. + -1, 0xB3, 0x01, 0x2C, 0x2D, 0x01, 0x2C, 0x2D,
  53160. +
  53161. + /* INVCTR - display inversion control
  53162. + no inversion */
  53163. + -1, 0xB4, 0x07,
  53164. +
  53165. + /* PWCTR1 - Power Control
  53166. + -4.6V, AUTO mode */
  53167. + -1, 0xC0, 0xA2, 0x02, 0x84,
  53168. +
  53169. + /* PWCTR2 - Power Control
  53170. + VGH25 = 2.4C VGSEL = -10 VGH = 3 * AVDD */
  53171. + -1, 0xC1, 0xC5,
  53172. +
  53173. + /* PWCTR3 - Power Control
  53174. + Opamp current small, Boost frequency */
  53175. + -1, 0xC2, 0x0A, 0x00,
  53176. +
  53177. + /* PWCTR4 - Power Control
  53178. + BCLK/2, Opamp current small & Medium low */
  53179. + -1, 0xC3,0x8A,0x2A,
  53180. +
  53181. + /* PWCTR5 - Power Control */
  53182. + -1, 0xC4, 0x8A, 0xEE,
  53183. +
  53184. + /* VMCTR1 - Power Control */
  53185. + -1, 0xC5, 0x0E,
  53186. +
  53187. + /* INVOFF - Display inversion off */
  53188. + -1, 0x20,
  53189. +
  53190. + /* COLMOD - Interface pixel format */
  53191. + -1, 0x3A, 0x05,
  53192. +
  53193. + /* DISPON - Display On */
  53194. + -1, 0x29,
  53195. + -2, 100, /* delay */
  53196. +
  53197. + /* NORON - Partial off (Normal) */
  53198. + -1, 0x13,
  53199. + -2, 10, /* delay */
  53200. +
  53201. + /* end marker */
  53202. + -3
  53203. +};
  53204. +
  53205. +static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
  53206. +{
  53207. + fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par,
  53208. + "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye);
  53209. +
  53210. + /* Column address */
  53211. + write_reg(par, 0x2A, xs >> 8, xs & 0xFF, xe >> 8, xe & 0xFF);
  53212. +
  53213. + /* Row adress */
  53214. + write_reg(par, 0x2B, ys >> 8, ys & 0xFF, ye >> 8, ye & 0xFF);
  53215. +
  53216. + /* Memory write */
  53217. + write_reg(par, 0x2C);
  53218. +}
  53219. +
  53220. +#define MY (1 << 7)
  53221. +#define MX (1 << 6)
  53222. +#define MV (1 << 5)
  53223. +static int set_var(struct fbtft_par *par)
  53224. +{
  53225. + fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
  53226. +
  53227. + /* MADCTL - Memory data access control
  53228. + RGB/BGR:
  53229. + 1. Mode selection pin SRGB
  53230. + RGB H/W pin for color filter setting: 0=RGB, 1=BGR
  53231. + 2. MADCTL RGB bit
  53232. + RGB-BGR ORDER color filter panel: 0=RGB, 1=BGR */
  53233. + switch (par->info->var.rotate) {
  53234. + case 0:
  53235. + write_reg(par, 0x36, MX | MY | (par->bgr << 3));
  53236. + break;
  53237. + case 270:
  53238. + write_reg(par, 0x36, MY | MV | (par->bgr << 3));
  53239. + break;
  53240. + case 180:
  53241. + write_reg(par, 0x36, (par->bgr << 3));
  53242. + break;
  53243. + case 90:
  53244. + write_reg(par, 0x36, MX | MV | (par->bgr << 3));
  53245. + break;
  53246. + }
  53247. +
  53248. + return 0;
  53249. +}
  53250. +
  53251. +/*
  53252. + Gamma string format:
  53253. + VRF0P VOS0P PK0P PK1P PK2P PK3P PK4P PK5P PK6P PK7P PK8P PK9P SELV0P SELV1P SELV62P SELV63P
  53254. + VRF0N VOS0N PK0N PK1N PK2N PK3N PK4N PK5N PK6N PK7N PK8N PK9N SELV0N SELV1N SELV62N SELV63N
  53255. +*/
  53256. +#define CURVE(num, idx) curves[num*par->gamma.num_values + idx]
  53257. +static int set_gamma(struct fbtft_par *par, unsigned long *curves)
  53258. +{
  53259. + int i,j;
  53260. +
  53261. + fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
  53262. +
  53263. + /* apply mask */
  53264. + for (i = 0; i < par->gamma.num_curves; i++)
  53265. + for (j = 0; j < par->gamma.num_values; j++)
  53266. + CURVE(i,j) &= 0b111111;
  53267. +
  53268. + for (i = 0; i < par->gamma.num_curves; i++)
  53269. + write_reg(par, 0xE0 + i,
  53270. + CURVE(i, 0), CURVE(i, 1), CURVE(i, 2), CURVE(i, 3),
  53271. + CURVE(i, 4), CURVE(i, 5), CURVE(i, 6), CURVE(i, 7),
  53272. + CURVE(i, 8), CURVE(i, 9), CURVE(i, 10), CURVE(i, 11),
  53273. + CURVE(i, 12), CURVE(i, 13), CURVE(i, 14), CURVE(i,15));
  53274. +
  53275. + return 0;
  53276. +}
  53277. +#undef CURVE
  53278. +
  53279. +
  53280. +static struct fbtft_display display = {
  53281. + .regwidth = 8,
  53282. + .width = 128,
  53283. + .height = 160,
  53284. + .init_sequence = default_init_sequence,
  53285. + .gamma_num = 2,
  53286. + .gamma_len = 16,
  53287. + .gamma = DEFAULT_GAMMA,
  53288. + .fbtftops = {
  53289. + .set_addr_win = set_addr_win,
  53290. + .set_var = set_var,
  53291. + .set_gamma = set_gamma,
  53292. + },
  53293. +};
  53294. +FBTFT_REGISTER_DRIVER(DRVNAME, "sitronix,st7735r", &display);
  53295. +
  53296. +MODULE_ALIAS("spi:" DRVNAME);
  53297. +MODULE_ALIAS("platform:" DRVNAME);
  53298. +MODULE_ALIAS("spi:st7735r");
  53299. +MODULE_ALIAS("platform:st7735r");
  53300. +
  53301. +MODULE_DESCRIPTION("FB driver for the ST7735R LCD Controller");
  53302. +MODULE_AUTHOR("Noralf Tronnes");
  53303. +MODULE_LICENSE("GPL");
  53304. diff -Nur linux-3.18.8/drivers/staging/fbtft/fbtft-bus.c linux-rpi/drivers/staging/fbtft/fbtft-bus.c
  53305. --- linux-3.18.8/drivers/staging/fbtft/fbtft-bus.c 1970-01-01 01:00:00.000000000 +0100
  53306. +++ linux-rpi/drivers/staging/fbtft/fbtft-bus.c 2015-03-05 14:40:16.345715808 +0100
  53307. @@ -0,0 +1,256 @@
  53308. +#include <linux/export.h>
  53309. +#include <linux/errno.h>
  53310. +#include <linux/gpio.h>
  53311. +#include <linux/spi/spi.h>
  53312. +#include "fbtft.h"
  53313. +
  53314. +
  53315. +
  53316. +
  53317. +/*****************************************************************************
  53318. + *
  53319. + * void (*write_reg)(struct fbtft_par *par, int len, ...);
  53320. + *
  53321. + *****************************************************************************/
  53322. +
  53323. +#define define_fbtft_write_reg(func, type, modifier) \
  53324. +void func(struct fbtft_par *par, int len, ...) \
  53325. +{ \
  53326. + va_list args; \
  53327. + int i, ret; \
  53328. + int offset = 0; \
  53329. + type *buf = (type *)par->buf; \
  53330. + \
  53331. + if (unlikely(par->debug & DEBUG_WRITE_REGISTER)) { \
  53332. + va_start(args, len); \
  53333. + for (i = 0; i < len; i++) { \
  53334. + buf[i] = (type)va_arg(args, unsigned int); \
  53335. + } \
  53336. + va_end(args); \
  53337. + fbtft_par_dbg_hex(DEBUG_WRITE_REGISTER, par, par->info->device, type, buf, len, "%s: ", __func__); \
  53338. + } \
  53339. + \
  53340. + va_start(args, len); \
  53341. + \
  53342. + if (par->startbyte) { \
  53343. + *(u8 *)par->buf = par->startbyte; \
  53344. + buf = (type *)(par->buf + 1); \
  53345. + offset = 1; \
  53346. + } \
  53347. + \
  53348. + *buf = modifier((type)va_arg(args, unsigned int)); \
  53349. + if (par->gpio.dc != -1) \
  53350. + gpio_set_value(par->gpio.dc, 0); \
  53351. + ret = par->fbtftops.write(par, par->buf, sizeof(type)+offset); \
  53352. + if (ret < 0) { \
  53353. + va_end(args); \
  53354. + dev_err(par->info->device, "%s: write() failed and returned %d\n", __func__, ret); \
  53355. + return; \
  53356. + } \
  53357. + len--; \
  53358. + \
  53359. + if (par->startbyte) \
  53360. + *(u8 *)par->buf = par->startbyte | 0x2; \
  53361. + \
  53362. + if (len) { \
  53363. + i = len; \
  53364. + while (i--) { \
  53365. + *buf++ = modifier((type)va_arg(args, unsigned int)); \
  53366. + } \
  53367. + if (par->gpio.dc != -1) \
  53368. + gpio_set_value(par->gpio.dc, 1); \
  53369. + ret = par->fbtftops.write(par, par->buf, len * (sizeof(type)+offset)); \
  53370. + if (ret < 0) { \
  53371. + va_end(args); \
  53372. + dev_err(par->info->device, "%s: write() failed and returned %d\n", __func__, ret); \
  53373. + return; \
  53374. + } \
  53375. + } \
  53376. + va_end(args); \
  53377. +} \
  53378. +EXPORT_SYMBOL(func);
  53379. +
  53380. +define_fbtft_write_reg(fbtft_write_reg8_bus8, u8, )
  53381. +define_fbtft_write_reg(fbtft_write_reg16_bus8, u16, cpu_to_be16)
  53382. +define_fbtft_write_reg(fbtft_write_reg16_bus16, u16, )
  53383. +
  53384. +void fbtft_write_reg8_bus9(struct fbtft_par *par, int len, ...)
  53385. +{
  53386. + va_list args;
  53387. + int i, ret;
  53388. + int pad = 0;
  53389. + u16 *buf = (u16 *)par->buf;
  53390. +
  53391. + if (unlikely(par->debug & DEBUG_WRITE_REGISTER)) {
  53392. + va_start(args, len);
  53393. + for (i = 0; i < len; i++)
  53394. + *(((u8 *)buf) + i) = (u8)va_arg(args, unsigned int);
  53395. + va_end(args);
  53396. + fbtft_par_dbg_hex(DEBUG_WRITE_REGISTER, par,
  53397. + par->info->device, u8, buf, len, "%s: ", __func__);
  53398. + }
  53399. + if (len <= 0)
  53400. + return;
  53401. +
  53402. + if (par->spi && (par->spi->bits_per_word == 8)) {
  53403. + /* we're emulating 9-bit, pad start of buffer with no-ops
  53404. + (assuming here that zero is a no-op) */
  53405. + pad = (len % 4) ? 4 - (len % 4) : 0;
  53406. + for (i = 0; i < pad; i++)
  53407. + *buf++ = 0x000;
  53408. + }
  53409. +
  53410. + va_start(args, len);
  53411. + *buf++ = (u8)va_arg(args, unsigned int);
  53412. + i = len - 1;
  53413. + while (i--) {
  53414. + *buf = (u8)va_arg(args, unsigned int);
  53415. + *buf++ |= 0x100; /* dc=1 */
  53416. + }
  53417. + va_end(args);
  53418. + ret = par->fbtftops.write(par, par->buf, (len + pad) * sizeof(u16));
  53419. + if (ret < 0) {
  53420. + dev_err(par->info->device,
  53421. + "%s: write() failed and returned %d\n", __func__, ret);
  53422. + return;
  53423. + }
  53424. +}
  53425. +EXPORT_SYMBOL(fbtft_write_reg8_bus9);
  53426. +
  53427. +
  53428. +
  53429. +
  53430. +/*****************************************************************************
  53431. + *
  53432. + * int (*write_vmem)(struct fbtft_par *par);
  53433. + *
  53434. + *****************************************************************************/
  53435. +
  53436. +/* 16 bit pixel over 8-bit databus */
  53437. +int fbtft_write_vmem16_bus8(struct fbtft_par *par, size_t offset, size_t len)
  53438. +{
  53439. + u16 *vmem16;
  53440. + u16 *txbuf16 = (u16 *)par->txbuf.buf;
  53441. + size_t remain;
  53442. + size_t to_copy;
  53443. + size_t tx_array_size;
  53444. + int i;
  53445. + int ret = 0;
  53446. + size_t startbyte_size = 0;
  53447. +
  53448. + fbtft_par_dbg(DEBUG_WRITE_VMEM, par, "%s(offset=%zu, len=%zu)\n",
  53449. + __func__, offset, len);
  53450. +
  53451. + remain = len / 2;
  53452. + vmem16 = (u16 *)(par->info->screen_base + offset);
  53453. +
  53454. + if (par->gpio.dc != -1)
  53455. + gpio_set_value(par->gpio.dc, 1);
  53456. +
  53457. + /* non buffered write */
  53458. + if (!par->txbuf.buf)
  53459. + return par->fbtftops.write(par, vmem16, len);
  53460. +
  53461. + /* buffered write */
  53462. + tx_array_size = par->txbuf.len / 2;
  53463. +
  53464. + if (par->startbyte) {
  53465. + txbuf16 = (u16 *)(par->txbuf.buf + 1);
  53466. + tx_array_size -= 2;
  53467. + *(u8 *)(par->txbuf.buf) = par->startbyte | 0x2;
  53468. + startbyte_size = 1;
  53469. + }
  53470. +
  53471. + while (remain) {
  53472. + to_copy = remain > tx_array_size ? tx_array_size : remain;
  53473. + dev_dbg(par->info->device, " to_copy=%zu, remain=%zu\n",
  53474. + to_copy, remain - to_copy);
  53475. +
  53476. + for (i = 0; i < to_copy; i++)
  53477. + txbuf16[i] = cpu_to_be16(vmem16[i]);
  53478. +
  53479. + vmem16 = vmem16 + to_copy;
  53480. + ret = par->fbtftops.write(par, par->txbuf.buf,
  53481. + startbyte_size + to_copy * 2);
  53482. + if (ret < 0)
  53483. + return ret;
  53484. + remain -= to_copy;
  53485. + }
  53486. +
  53487. + return ret;
  53488. +}
  53489. +EXPORT_SYMBOL(fbtft_write_vmem16_bus8);
  53490. +
  53491. +/* 16 bit pixel over 9-bit SPI bus: dc + high byte, dc + low byte */
  53492. +int fbtft_write_vmem16_bus9(struct fbtft_par *par, size_t offset, size_t len)
  53493. +{
  53494. + u8 *vmem8;
  53495. + u16 *txbuf16 = par->txbuf.buf;
  53496. + size_t remain;
  53497. + size_t to_copy;
  53498. + size_t tx_array_size;
  53499. + int i;
  53500. + int ret = 0;
  53501. +
  53502. + fbtft_par_dbg(DEBUG_WRITE_VMEM, par, "%s(offset=%zu, len=%zu)\n",
  53503. + __func__, offset, len);
  53504. +
  53505. + if (!par->txbuf.buf) {
  53506. + dev_err(par->info->device, "%s: txbuf.buf is NULL\n", __func__);
  53507. + return -1;
  53508. + }
  53509. +
  53510. + remain = len;
  53511. + vmem8 = par->info->screen_base + offset;
  53512. +
  53513. + tx_array_size = par->txbuf.len / 2;
  53514. +
  53515. + while (remain) {
  53516. + to_copy = remain > tx_array_size ? tx_array_size : remain;
  53517. + dev_dbg(par->info->device, " to_copy=%zu, remain=%zu\n",
  53518. + to_copy, remain - to_copy);
  53519. +
  53520. +#ifdef __LITTLE_ENDIAN
  53521. + for (i = 0; i < to_copy; i += 2) {
  53522. + txbuf16[i] = 0x0100 | vmem8[i+1];
  53523. + txbuf16[i+1] = 0x0100 | vmem8[i];
  53524. + }
  53525. +#else
  53526. + for (i = 0; i < to_copy; i++)
  53527. + txbuf16[i] = 0x0100 | vmem8[i];
  53528. +#endif
  53529. + vmem8 = vmem8 + to_copy;
  53530. + ret = par->fbtftops.write(par, par->txbuf.buf, to_copy*2);
  53531. + if (ret < 0)
  53532. + return ret;
  53533. + remain -= to_copy;
  53534. + }
  53535. +
  53536. + return ret;
  53537. +}
  53538. +EXPORT_SYMBOL(fbtft_write_vmem16_bus9);
  53539. +
  53540. +int fbtft_write_vmem8_bus8(struct fbtft_par *par, size_t offset, size_t len)
  53541. +{
  53542. + dev_err(par->info->device, "%s: function not implemented\n", __func__);
  53543. + return -1;
  53544. +}
  53545. +EXPORT_SYMBOL(fbtft_write_vmem8_bus8);
  53546. +
  53547. +/* 16 bit pixel over 16-bit databus */
  53548. +int fbtft_write_vmem16_bus16(struct fbtft_par *par, size_t offset, size_t len)
  53549. +{
  53550. + u16 *vmem16;
  53551. +
  53552. + fbtft_par_dbg(DEBUG_WRITE_VMEM, par, "%s(offset=%zu, len=%zu)\n",
  53553. + __func__, offset, len);
  53554. +
  53555. + vmem16 = (u16 *)(par->info->screen_base + offset);
  53556. +
  53557. + if (par->gpio.dc != -1)
  53558. + gpio_set_value(par->gpio.dc, 1);
  53559. +
  53560. + /* no need for buffered write with 16-bit bus */
  53561. + return par->fbtftops.write(par, vmem16, len);
  53562. +}
  53563. +EXPORT_SYMBOL(fbtft_write_vmem16_bus16);
  53564. diff -Nur linux-3.18.8/drivers/staging/fbtft/fbtft-core.c linux-rpi/drivers/staging/fbtft/fbtft-core.c
  53565. --- linux-3.18.8/drivers/staging/fbtft/fbtft-core.c 1970-01-01 01:00:00.000000000 +0100
  53566. +++ linux-rpi/drivers/staging/fbtft/fbtft-core.c 2015-03-05 14:40:16.345715808 +0100
  53567. @@ -0,0 +1,1521 @@
  53568. +/*
  53569. + * Copyright (C) 2013 Noralf Tronnes
  53570. + *
  53571. + * This driver is inspired by:
  53572. + * st7735fb.c, Copyright (C) 2011, Matt Porter
  53573. + * broadsheetfb.c, Copyright (C) 2008, Jaya Kumar
  53574. + *
  53575. + * This program is free software; you can redistribute it and/or modify
  53576. + * it under the terms of the GNU General Public License as published by
  53577. + * the Free Software Foundation; either version 2 of the License, or
  53578. + * (at your option) any later version.
  53579. + *
  53580. + * This program is distributed in the hope that it will be useful,
  53581. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  53582. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  53583. + * GNU General Public License for more details.
  53584. + *
  53585. + * You should have received a copy of the GNU General Public License
  53586. + * along with this program; if not, write to the Free Software
  53587. + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  53588. + */
  53589. +
  53590. +#include <linux/module.h>
  53591. +#include <linux/kernel.h>
  53592. +#include <linux/errno.h>
  53593. +#include <linux/string.h>
  53594. +#include <linux/mm.h>
  53595. +#include <linux/vmalloc.h>
  53596. +#include <linux/slab.h>
  53597. +#include <linux/init.h>
  53598. +#include <linux/fb.h>
  53599. +#include <linux/gpio.h>
  53600. +#include <linux/spi/spi.h>
  53601. +#include <linux/delay.h>
  53602. +#include <linux/uaccess.h>
  53603. +#include <linux/backlight.h>
  53604. +#include <linux/platform_device.h>
  53605. +#include <linux/spinlock.h>
  53606. +#include <linux/dma-mapping.h>
  53607. +#include <linux/of.h>
  53608. +#include <linux/of_gpio.h>
  53609. +
  53610. +#include "fbtft.h"
  53611. +
  53612. +extern void fbtft_sysfs_init(struct fbtft_par *par);
  53613. +extern void fbtft_sysfs_exit(struct fbtft_par *par);
  53614. +extern void fbtft_expand_debug_value(unsigned long *debug);
  53615. +extern int fbtft_gamma_parse_str(struct fbtft_par *par, unsigned long *curves,
  53616. + const char *str, int size);
  53617. +
  53618. +static unsigned long debug;
  53619. +module_param(debug, ulong , 0);
  53620. +MODULE_PARM_DESC(debug, "override device debug level");
  53621. +
  53622. +static bool dma = true;
  53623. +module_param(dma, bool, 0);
  53624. +MODULE_PARM_DESC(dma, "Use DMA buffer");
  53625. +
  53626. +
  53627. +void fbtft_dbg_hex(const struct device *dev, int groupsize,
  53628. + void *buf, size_t len, const char *fmt, ...)
  53629. +{
  53630. + va_list args;
  53631. + static char textbuf[512];
  53632. + char *text = textbuf;
  53633. + size_t text_len;
  53634. +
  53635. + va_start(args, fmt);
  53636. + text_len = vscnprintf(text, sizeof(textbuf), fmt, args);
  53637. + va_end(args);
  53638. +
  53639. + hex_dump_to_buffer(buf, len, 32, groupsize, text + text_len,
  53640. + 512 - text_len, false);
  53641. +
  53642. + if (len > 32)
  53643. + dev_info(dev, "%s ...\n", text);
  53644. + else
  53645. + dev_info(dev, "%s\n", text);
  53646. +}
  53647. +EXPORT_SYMBOL(fbtft_dbg_hex);
  53648. +
  53649. +static unsigned long fbtft_request_gpios_match(struct fbtft_par *par,
  53650. + const struct fbtft_gpio *gpio)
  53651. +{
  53652. + int ret;
  53653. + long val;
  53654. +
  53655. + fbtft_par_dbg(DEBUG_REQUEST_GPIOS_MATCH, par, "%s('%s')\n",
  53656. + __func__, gpio->name);
  53657. +
  53658. + if (strcasecmp(gpio->name, "reset") == 0) {
  53659. + par->gpio.reset = gpio->gpio;
  53660. + return GPIOF_OUT_INIT_HIGH;
  53661. + } else if (strcasecmp(gpio->name, "dc") == 0) {
  53662. + par->gpio.dc = gpio->gpio;
  53663. + return GPIOF_OUT_INIT_LOW;
  53664. + } else if (strcasecmp(gpio->name, "cs") == 0) {
  53665. + par->gpio.cs = gpio->gpio;
  53666. + return GPIOF_OUT_INIT_HIGH;
  53667. + } else if (strcasecmp(gpio->name, "wr") == 0) {
  53668. + par->gpio.wr = gpio->gpio;
  53669. + return GPIOF_OUT_INIT_HIGH;
  53670. + } else if (strcasecmp(gpio->name, "rd") == 0) {
  53671. + par->gpio.rd = gpio->gpio;
  53672. + return GPIOF_OUT_INIT_HIGH;
  53673. + } else if (strcasecmp(gpio->name, "latch") == 0) {
  53674. + par->gpio.latch = gpio->gpio;
  53675. + return GPIOF_OUT_INIT_LOW;
  53676. + } else if (gpio->name[0] == 'd' && gpio->name[1] == 'b') {
  53677. + ret = kstrtol(&gpio->name[2], 10, &val);
  53678. + if (ret == 0 && val < 16) {
  53679. + par->gpio.db[val] = gpio->gpio;
  53680. + return GPIOF_OUT_INIT_LOW;
  53681. + }
  53682. + } else if (strcasecmp(gpio->name, "led") == 0) {
  53683. + par->gpio.led[0] = gpio->gpio;
  53684. + return GPIOF_OUT_INIT_LOW;
  53685. + } else if (strcasecmp(gpio->name, "led_") == 0) {
  53686. + par->gpio.led[0] = gpio->gpio;
  53687. + return GPIOF_OUT_INIT_HIGH;
  53688. + }
  53689. +
  53690. + return FBTFT_GPIO_NO_MATCH;
  53691. +}
  53692. +
  53693. +static int fbtft_request_gpios(struct fbtft_par *par)
  53694. +{
  53695. + struct fbtft_platform_data *pdata = par->pdata;
  53696. + const struct fbtft_gpio *gpio;
  53697. + unsigned long flags;
  53698. + int ret;
  53699. +
  53700. + if (pdata && pdata->gpios) {
  53701. + gpio = pdata->gpios;
  53702. + while (gpio->name[0]) {
  53703. + flags = FBTFT_GPIO_NO_MATCH;
  53704. + /* if driver provides match function, try it first,
  53705. + if no match use our own */
  53706. + if (par->fbtftops.request_gpios_match)
  53707. + flags = par->fbtftops.request_gpios_match(par, gpio);
  53708. + if (flags == FBTFT_GPIO_NO_MATCH)
  53709. + flags = fbtft_request_gpios_match(par, gpio);
  53710. + if (flags != FBTFT_GPIO_NO_MATCH) {
  53711. + ret = devm_gpio_request_one(par->info->device,
  53712. + gpio->gpio, flags,
  53713. + par->info->device->driver->name);
  53714. + if (ret < 0) {
  53715. + dev_err(par->info->device,
  53716. + "%s: gpio_request_one('%s'=%d) failed with %d\n",
  53717. + __func__, gpio->name,
  53718. + gpio->gpio, ret);
  53719. + return ret;
  53720. + }
  53721. + fbtft_par_dbg(DEBUG_REQUEST_GPIOS, par,
  53722. + "%s: '%s' = GPIO%d\n",
  53723. + __func__, gpio->name, gpio->gpio);
  53724. + }
  53725. + gpio++;
  53726. + }
  53727. + }
  53728. +
  53729. + return 0;
  53730. +}
  53731. +
  53732. +#ifdef CONFIG_OF
  53733. +static int fbtft_request_one_gpio(struct fbtft_par *par,
  53734. + const char *name, int index, int *gpiop)
  53735. +{
  53736. + struct device *dev = par->info->device;
  53737. + struct device_node *node = dev->of_node;
  53738. + int gpio, flags, ret = 0;
  53739. + enum of_gpio_flags of_flags;
  53740. +
  53741. + if (of_find_property(node, name, NULL)) {
  53742. + gpio = of_get_named_gpio_flags(node, name, index, &of_flags);
  53743. + if (gpio == -ENOENT)
  53744. + return 0;
  53745. + if (gpio == -EPROBE_DEFER)
  53746. + return gpio;
  53747. + if (gpio < 0) {
  53748. + dev_err(dev,
  53749. + "failed to get '%s' from DT\n", name);
  53750. + return gpio;
  53751. + }
  53752. +
  53753. + /* active low translates to initially low */
  53754. + flags = (of_flags & OF_GPIO_ACTIVE_LOW) ? GPIOF_OUT_INIT_LOW :
  53755. + GPIOF_OUT_INIT_HIGH;
  53756. + ret = devm_gpio_request_one(dev, gpio, flags,
  53757. + dev->driver->name);
  53758. + if (ret) {
  53759. + dev_err(dev,
  53760. + "gpio_request_one('%s'=%d) failed with %d\n",
  53761. + name, gpio, ret);
  53762. + return ret;
  53763. + }
  53764. + if (gpiop)
  53765. + *gpiop = gpio;
  53766. + fbtft_par_dbg(DEBUG_REQUEST_GPIOS, par, "%s: '%s' = GPIO%d\n",
  53767. + __func__, name, gpio);
  53768. + }
  53769. +
  53770. + return ret;
  53771. +}
  53772. +
  53773. +static int fbtft_request_gpios_dt(struct fbtft_par *par)
  53774. +{
  53775. + int i;
  53776. + int ret;
  53777. +
  53778. + if (!par->info->device->of_node)
  53779. + return -EINVAL;
  53780. +
  53781. + ret = fbtft_request_one_gpio(par, "reset-gpios", 0, &par->gpio.reset);
  53782. + if (ret)
  53783. + return ret;
  53784. + ret = fbtft_request_one_gpio(par, "dc-gpios", 0, &par->gpio.dc);
  53785. + if (ret)
  53786. + return ret;
  53787. + ret = fbtft_request_one_gpio(par, "rd-gpios", 0, &par->gpio.rd);
  53788. + if (ret)
  53789. + return ret;
  53790. + ret = fbtft_request_one_gpio(par, "wr-gpios", 0, &par->gpio.wr);
  53791. + if (ret)
  53792. + return ret;
  53793. + ret = fbtft_request_one_gpio(par, "cs-gpios", 0, &par->gpio.cs);
  53794. + if (ret)
  53795. + return ret;
  53796. + ret = fbtft_request_one_gpio(par, "latch-gpios", 0, &par->gpio.latch);
  53797. + if (ret)
  53798. + return ret;
  53799. + for (i = 0; i < 16; i++) {
  53800. + ret = fbtft_request_one_gpio(par, "db-gpios", i,
  53801. + &par->gpio.db[i]);
  53802. + if (ret)
  53803. + return ret;
  53804. + ret = fbtft_request_one_gpio(par, "led-gpios", i,
  53805. + &par->gpio.led[i]);
  53806. + if (ret)
  53807. + return ret;
  53808. + ret = fbtft_request_one_gpio(par, "aux-gpios", i,
  53809. + &par->gpio.aux[i]);
  53810. + if (ret)
  53811. + return ret;
  53812. + }
  53813. +
  53814. + return 0;
  53815. +}
  53816. +#endif
  53817. +
  53818. +#ifdef CONFIG_FB_BACKLIGHT
  53819. +static int fbtft_backlight_update_status(struct backlight_device *bd)
  53820. +{
  53821. + struct fbtft_par *par = bl_get_data(bd);
  53822. + bool polarity = !!(bd->props.state & BL_CORE_DRIVER1);
  53823. +
  53824. + fbtft_par_dbg(DEBUG_BACKLIGHT, par,
  53825. + "%s: polarity=%d, power=%d, fb_blank=%d\n",
  53826. + __func__, polarity, bd->props.power, bd->props.fb_blank);
  53827. +
  53828. + if ((bd->props.power == FB_BLANK_UNBLANK) && (bd->props.fb_blank == FB_BLANK_UNBLANK))
  53829. + gpio_set_value(par->gpio.led[0], polarity);
  53830. + else
  53831. + gpio_set_value(par->gpio.led[0], !polarity);
  53832. +
  53833. + return 0;
  53834. +}
  53835. +
  53836. +static int fbtft_backlight_get_brightness(struct backlight_device *bd)
  53837. +{
  53838. + return bd->props.brightness;
  53839. +}
  53840. +
  53841. +void fbtft_unregister_backlight(struct fbtft_par *par)
  53842. +{
  53843. + const struct backlight_ops *bl_ops;
  53844. +
  53845. + fbtft_par_dbg(DEBUG_BACKLIGHT, par, "%s()\n", __func__);
  53846. +
  53847. + if (par->info->bl_dev) {
  53848. + par->info->bl_dev->props.power = FB_BLANK_POWERDOWN;
  53849. + backlight_update_status(par->info->bl_dev);
  53850. + bl_ops = par->info->bl_dev->ops;
  53851. + backlight_device_unregister(par->info->bl_dev);
  53852. + par->info->bl_dev = NULL;
  53853. + }
  53854. +}
  53855. +
  53856. +void fbtft_register_backlight(struct fbtft_par *par)
  53857. +{
  53858. + struct backlight_device *bd;
  53859. + struct backlight_properties bl_props = { 0, };
  53860. + struct backlight_ops *bl_ops;
  53861. +
  53862. + fbtft_par_dbg(DEBUG_BACKLIGHT, par, "%s()\n", __func__);
  53863. +
  53864. + if (par->gpio.led[0] == -1) {
  53865. + fbtft_par_dbg(DEBUG_BACKLIGHT, par,
  53866. + "%s(): led pin not set, exiting.\n", __func__);
  53867. + return;
  53868. + }
  53869. +
  53870. + bl_ops = devm_kzalloc(par->info->device, sizeof(struct backlight_ops),
  53871. + GFP_KERNEL);
  53872. + if (!bl_ops) {
  53873. + dev_err(par->info->device,
  53874. + "%s: could not allocate memeory for backlight operations.\n",
  53875. + __func__);
  53876. + return;
  53877. + }
  53878. +
  53879. + bl_ops->get_brightness = fbtft_backlight_get_brightness;
  53880. + bl_ops->update_status = fbtft_backlight_update_status;
  53881. + bl_props.type = BACKLIGHT_RAW;
  53882. + /* Assume backlight is off, get polarity from current state of pin */
  53883. + bl_props.power = FB_BLANK_POWERDOWN;
  53884. + if (!gpio_get_value(par->gpio.led[0]))
  53885. + bl_props.state |= BL_CORE_DRIVER1;
  53886. +
  53887. + bd = backlight_device_register(dev_driver_string(par->info->device),
  53888. + par->info->device, par, bl_ops, &bl_props);
  53889. + if (IS_ERR(bd)) {
  53890. + dev_err(par->info->device,
  53891. + "cannot register backlight device (%ld)\n",
  53892. + PTR_ERR(bd));
  53893. + return;
  53894. + }
  53895. + par->info->bl_dev = bd;
  53896. +
  53897. + if (!par->fbtftops.unregister_backlight)
  53898. + par->fbtftops.unregister_backlight = fbtft_unregister_backlight;
  53899. +}
  53900. +#else
  53901. +void fbtft_register_backlight(struct fbtft_par *par) { };
  53902. +void fbtft_unregister_backlight(struct fbtft_par *par) { };
  53903. +#endif
  53904. +EXPORT_SYMBOL(fbtft_register_backlight);
  53905. +EXPORT_SYMBOL(fbtft_unregister_backlight);
  53906. +
  53907. +static void fbtft_set_addr_win(struct fbtft_par *par, int xs, int ys, int xe,
  53908. + int ye)
  53909. +{
  53910. + fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par,
  53911. + "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye);
  53912. +
  53913. + /* Column address set */
  53914. + write_reg(par, 0x2A,
  53915. + (xs >> 8) & 0xFF, xs & 0xFF, (xe >> 8) & 0xFF, xe & 0xFF);
  53916. +
  53917. + /* Row adress set */
  53918. + write_reg(par, 0x2B,
  53919. + (ys >> 8) & 0xFF, ys & 0xFF, (ye >> 8) & 0xFF, ye & 0xFF);
  53920. +
  53921. + /* Memory write */
  53922. + write_reg(par, 0x2C);
  53923. +}
  53924. +
  53925. +
  53926. +static void fbtft_reset(struct fbtft_par *par)
  53927. +{
  53928. + if (par->gpio.reset == -1)
  53929. + return;
  53930. + fbtft_par_dbg(DEBUG_RESET, par, "%s()\n", __func__);
  53931. + gpio_set_value(par->gpio.reset, 0);
  53932. + udelay(20);
  53933. + gpio_set_value(par->gpio.reset, 1);
  53934. + mdelay(120);
  53935. +}
  53936. +
  53937. +
  53938. +static void fbtft_update_display(struct fbtft_par *par, unsigned start_line,
  53939. + unsigned end_line)
  53940. +{
  53941. + size_t offset, len;
  53942. + struct timespec ts_start, ts_end, ts_fps, ts_duration;
  53943. + long fps_ms, fps_us, duration_ms, duration_us;
  53944. + long fps, throughput;
  53945. + bool timeit = false;
  53946. + int ret = 0;
  53947. +
  53948. + if (unlikely(par->debug & (DEBUG_TIME_FIRST_UPDATE | DEBUG_TIME_EACH_UPDATE))) {
  53949. + if ((par->debug & DEBUG_TIME_EACH_UPDATE) || \
  53950. + ((par->debug & DEBUG_TIME_FIRST_UPDATE) && !par->first_update_done)) {
  53951. + getnstimeofday(&ts_start);
  53952. + timeit = true;
  53953. + }
  53954. + }
  53955. +
  53956. + /* Sanity checks */
  53957. + if (start_line > end_line) {
  53958. + dev_warn(par->info->device,
  53959. + "%s: start_line=%u is larger than end_line=%u. Shouldn't happen, will do full display update\n",
  53960. + __func__, start_line, end_line);
  53961. + start_line = 0;
  53962. + end_line = par->info->var.yres - 1;
  53963. + }
  53964. + if (start_line > par->info->var.yres - 1 || end_line > par->info->var.yres - 1) {
  53965. + dev_warn(par->info->device,
  53966. + "%s: start_line=%u or end_line=%u is larger than max=%d. Shouldn't happen, will do full display update\n",
  53967. + __func__, start_line, end_line, par->info->var.yres - 1);
  53968. + start_line = 0;
  53969. + end_line = par->info->var.yres - 1;
  53970. + }
  53971. +
  53972. + fbtft_par_dbg(DEBUG_UPDATE_DISPLAY, par, "%s(start_line=%u, end_line=%u)\n",
  53973. + __func__, start_line, end_line);
  53974. +
  53975. + if (par->fbtftops.set_addr_win)
  53976. + par->fbtftops.set_addr_win(par, 0, start_line,
  53977. + par->info->var.xres-1, end_line);
  53978. +
  53979. + offset = start_line * par->info->fix.line_length;
  53980. + len = (end_line - start_line + 1) * par->info->fix.line_length;
  53981. + ret = par->fbtftops.write_vmem(par, offset, len);
  53982. + if (ret < 0)
  53983. + dev_err(par->info->device,
  53984. + "%s: write_vmem failed to update display buffer\n",
  53985. + __func__);
  53986. +
  53987. + if (unlikely(timeit)) {
  53988. + getnstimeofday(&ts_end);
  53989. + if (par->update_time.tv_nsec == 0 && par->update_time.tv_sec == 0) {
  53990. + par->update_time.tv_sec = ts_start.tv_sec;
  53991. + par->update_time.tv_nsec = ts_start.tv_nsec;
  53992. + }
  53993. + ts_fps = timespec_sub(ts_start, par->update_time);
  53994. + par->update_time.tv_sec = ts_start.tv_sec;
  53995. + par->update_time.tv_nsec = ts_start.tv_nsec;
  53996. + fps_ms = (ts_fps.tv_sec * 1000) + ((ts_fps.tv_nsec / 1000000) % 1000);
  53997. + fps_us = (ts_fps.tv_nsec / 1000) % 1000;
  53998. + fps = fps_ms * 1000 + fps_us;
  53999. + fps = fps ? 1000000 / fps : 0;
  54000. +
  54001. + ts_duration = timespec_sub(ts_end, ts_start);
  54002. + duration_ms = (ts_duration.tv_sec * 1000) + ((ts_duration.tv_nsec / 1000000) % 1000);
  54003. + duration_us = (ts_duration.tv_nsec / 1000) % 1000;
  54004. + throughput = duration_ms * 1000 + duration_us;
  54005. + throughput = throughput ? (len * 1000) / throughput : 0;
  54006. + throughput = throughput * 1000 / 1024;
  54007. +
  54008. + dev_info(par->info->device,
  54009. + "Display update: %ld kB/s (%ld.%.3ld ms), fps=%ld (%ld.%.3ld ms)\n",
  54010. + throughput, duration_ms, duration_us,
  54011. + fps, fps_ms, fps_us);
  54012. + par->first_update_done = true;
  54013. + }
  54014. +}
  54015. +
  54016. +
  54017. +static void fbtft_mkdirty(struct fb_info *info, int y, int height)
  54018. +{
  54019. + struct fbtft_par *par = info->par;
  54020. + struct fb_deferred_io *fbdefio = info->fbdefio;
  54021. +
  54022. + /* special case, needed ? */
  54023. + if (y == -1) {
  54024. + y = 0;
  54025. + height = info->var.yres - 1;
  54026. + }
  54027. +
  54028. + /* Mark display lines/area as dirty */
  54029. + spin_lock(&par->dirty_lock);
  54030. + if (y < par->dirty_lines_start)
  54031. + par->dirty_lines_start = y;
  54032. + if (y + height - 1 > par->dirty_lines_end)
  54033. + par->dirty_lines_end = y + height - 1;
  54034. + spin_unlock(&par->dirty_lock);
  54035. +
  54036. + /* Schedule deferred_io to update display (no-op if already on queue)*/
  54037. + schedule_delayed_work(&info->deferred_work, fbdefio->delay);
  54038. +}
  54039. +
  54040. +static void fbtft_deferred_io(struct fb_info *info, struct list_head *pagelist)
  54041. +{
  54042. + struct fbtft_par *par = info->par;
  54043. + unsigned dirty_lines_start, dirty_lines_end;
  54044. + struct page *page;
  54045. + unsigned long index;
  54046. + unsigned y_low = 0, y_high = 0;
  54047. + int count = 0;
  54048. +
  54049. + spin_lock(&par->dirty_lock);
  54050. + dirty_lines_start = par->dirty_lines_start;
  54051. + dirty_lines_end = par->dirty_lines_end;
  54052. + /* set display line markers as clean */
  54053. + par->dirty_lines_start = par->info->var.yres - 1;
  54054. + par->dirty_lines_end = 0;
  54055. + spin_unlock(&par->dirty_lock);
  54056. +
  54057. + /* Mark display lines as dirty */
  54058. + list_for_each_entry(page, pagelist, lru) {
  54059. + count++;
  54060. + index = page->index << PAGE_SHIFT;
  54061. + y_low = index / info->fix.line_length;
  54062. + y_high = (index + PAGE_SIZE - 1) / info->fix.line_length;
  54063. + fbtft_dev_dbg(DEBUG_DEFERRED_IO, par, info->device,
  54064. + "page->index=%lu y_low=%d y_high=%d\n",
  54065. + page->index, y_low, y_high);
  54066. + if (y_high > info->var.yres - 1)
  54067. + y_high = info->var.yres - 1;
  54068. + if (y_low < dirty_lines_start)
  54069. + dirty_lines_start = y_low;
  54070. + if (y_high > dirty_lines_end)
  54071. + dirty_lines_end = y_high;
  54072. + }
  54073. +
  54074. + par->fbtftops.update_display(info->par,
  54075. + dirty_lines_start, dirty_lines_end);
  54076. +}
  54077. +
  54078. +
  54079. +static void fbtft_fb_fillrect(struct fb_info *info,
  54080. + const struct fb_fillrect *rect)
  54081. +{
  54082. + struct fbtft_par *par = info->par;
  54083. +
  54084. + fbtft_dev_dbg(DEBUG_FB_FILLRECT, par, info->dev,
  54085. + "%s: dx=%d, dy=%d, width=%d, height=%d\n",
  54086. + __func__, rect->dx, rect->dy, rect->width, rect->height);
  54087. + sys_fillrect(info, rect);
  54088. +
  54089. + par->fbtftops.mkdirty(info, rect->dy, rect->height);
  54090. +}
  54091. +
  54092. +static void fbtft_fb_copyarea(struct fb_info *info,
  54093. + const struct fb_copyarea *area)
  54094. +{
  54095. + struct fbtft_par *par = info->par;
  54096. +
  54097. + fbtft_dev_dbg(DEBUG_FB_COPYAREA, par, info->dev,
  54098. + "%s: dx=%d, dy=%d, width=%d, height=%d\n",
  54099. + __func__, area->dx, area->dy, area->width, area->height);
  54100. + sys_copyarea(info, area);
  54101. +
  54102. + par->fbtftops.mkdirty(info, area->dy, area->height);
  54103. +}
  54104. +
  54105. +static void fbtft_fb_imageblit(struct fb_info *info,
  54106. + const struct fb_image *image)
  54107. +{
  54108. + struct fbtft_par *par = info->par;
  54109. +
  54110. + fbtft_dev_dbg(DEBUG_FB_IMAGEBLIT, par, info->dev,
  54111. + "%s: dx=%d, dy=%d, width=%d, height=%d\n",
  54112. + __func__, image->dx, image->dy, image->width, image->height);
  54113. + sys_imageblit(info, image);
  54114. +
  54115. + par->fbtftops.mkdirty(info, image->dy, image->height);
  54116. +}
  54117. +
  54118. +static ssize_t fbtft_fb_write(struct fb_info *info, const char __user *buf,
  54119. + size_t count, loff_t *ppos)
  54120. +{
  54121. + struct fbtft_par *par = info->par;
  54122. + ssize_t res;
  54123. +
  54124. + fbtft_dev_dbg(DEBUG_FB_WRITE, par, info->dev,
  54125. + "%s: count=%zd, ppos=%llu\n", __func__, count, *ppos);
  54126. + res = fb_sys_write(info, buf, count, ppos);
  54127. +
  54128. + /* TODO: only mark changed area
  54129. + update all for now */
  54130. + par->fbtftops.mkdirty(info, -1, 0);
  54131. +
  54132. + return res;
  54133. +}
  54134. +
  54135. +/* from pxafb.c */
  54136. +static unsigned int chan_to_field(unsigned chan, struct fb_bitfield *bf)
  54137. +{
  54138. + chan &= 0xffff;
  54139. + chan >>= 16 - bf->length;
  54140. + return chan << bf->offset;
  54141. +}
  54142. +
  54143. +static int fbtft_fb_setcolreg(unsigned regno, unsigned red, unsigned green,
  54144. + unsigned blue, unsigned transp,
  54145. + struct fb_info *info)
  54146. +{
  54147. + struct fbtft_par *par = info->par;
  54148. + unsigned val;
  54149. + int ret = 1;
  54150. +
  54151. + fbtft_dev_dbg(DEBUG_FB_SETCOLREG, par, info->dev,
  54152. + "%s(regno=%u, red=0x%X, green=0x%X, blue=0x%X, trans=0x%X)\n",
  54153. + __func__, regno, red, green, blue, transp);
  54154. +
  54155. + switch (info->fix.visual) {
  54156. + case FB_VISUAL_TRUECOLOR:
  54157. + if (regno < 16) {
  54158. + u32 *pal = info->pseudo_palette;
  54159. +
  54160. + val = chan_to_field(red, &info->var.red);
  54161. + val |= chan_to_field(green, &info->var.green);
  54162. + val |= chan_to_field(blue, &info->var.blue);
  54163. +
  54164. + pal[regno] = val;
  54165. + ret = 0;
  54166. + }
  54167. + break;
  54168. +
  54169. + }
  54170. + return ret;
  54171. +}
  54172. +
  54173. +static int fbtft_fb_blank(int blank, struct fb_info *info)
  54174. +{
  54175. + struct fbtft_par *par = info->par;
  54176. + int ret = -EINVAL;
  54177. +
  54178. + fbtft_dev_dbg(DEBUG_FB_BLANK, par, info->dev, "%s(blank=%d)\n",
  54179. + __func__, blank);
  54180. +
  54181. + if (!par->fbtftops.blank)
  54182. + return ret;
  54183. +
  54184. + switch (blank) {
  54185. + case FB_BLANK_POWERDOWN:
  54186. + case FB_BLANK_VSYNC_SUSPEND:
  54187. + case FB_BLANK_HSYNC_SUSPEND:
  54188. + case FB_BLANK_NORMAL:
  54189. + ret = par->fbtftops.blank(par, true);
  54190. + break;
  54191. + case FB_BLANK_UNBLANK:
  54192. + ret = par->fbtftops.blank(par, false);
  54193. + break;
  54194. + }
  54195. + return ret;
  54196. +}
  54197. +
  54198. +static void fbtft_merge_fbtftops(struct fbtft_ops *dst, struct fbtft_ops *src)
  54199. +{
  54200. + if (src->write)
  54201. + dst->write = src->write;
  54202. + if (src->read)
  54203. + dst->read = src->read;
  54204. + if (src->write_vmem)
  54205. + dst->write_vmem = src->write_vmem;
  54206. + if (src->write_register)
  54207. + dst->write_register = src->write_register;
  54208. + if (src->set_addr_win)
  54209. + dst->set_addr_win = src->set_addr_win;
  54210. + if (src->reset)
  54211. + dst->reset = src->reset;
  54212. + if (src->mkdirty)
  54213. + dst->mkdirty = src->mkdirty;
  54214. + if (src->update_display)
  54215. + dst->update_display = src->update_display;
  54216. + if (src->init_display)
  54217. + dst->init_display = src->init_display;
  54218. + if (src->blank)
  54219. + dst->blank = src->blank;
  54220. + if (src->request_gpios_match)
  54221. + dst->request_gpios_match = src->request_gpios_match;
  54222. + if (src->request_gpios)
  54223. + dst->request_gpios = src->request_gpios;
  54224. + if (src->verify_gpios)
  54225. + dst->verify_gpios = src->verify_gpios;
  54226. + if (src->register_backlight)
  54227. + dst->register_backlight = src->register_backlight;
  54228. + if (src->unregister_backlight)
  54229. + dst->unregister_backlight = src->unregister_backlight;
  54230. + if (src->set_var)
  54231. + dst->set_var = src->set_var;
  54232. + if (src->set_gamma)
  54233. + dst->set_gamma = src->set_gamma;
  54234. +}
  54235. +
  54236. +/**
  54237. + * fbtft_framebuffer_alloc - creates a new frame buffer info structure
  54238. + *
  54239. + * @display: pointer to structure describing the display
  54240. + * @dev: pointer to the device for this fb, this can be NULL
  54241. + *
  54242. + * Creates a new frame buffer info structure.
  54243. + *
  54244. + * Also creates and populates the following structures:
  54245. + * info->fbops
  54246. + * info->fbdefio
  54247. + * info->pseudo_palette
  54248. + * par->fbtftops
  54249. + * par->txbuf
  54250. + *
  54251. + * Returns the new structure, or NULL if an error occurred.
  54252. + *
  54253. + */
  54254. +struct fb_info *fbtft_framebuffer_alloc(struct fbtft_display *display,
  54255. + struct device *dev)
  54256. +{
  54257. + struct fb_info *info;
  54258. + struct fbtft_par *par;
  54259. + struct fb_ops *fbops = NULL;
  54260. + struct fb_deferred_io *fbdefio = NULL;
  54261. + struct fbtft_platform_data *pdata = dev->platform_data;
  54262. + u8 *vmem = NULL;
  54263. + void *txbuf = NULL;
  54264. + void *buf = NULL;
  54265. + unsigned width;
  54266. + unsigned height;
  54267. + int txbuflen = display->txbuflen;
  54268. + unsigned bpp = display->bpp;
  54269. + unsigned fps = display->fps;
  54270. + int vmem_size, i;
  54271. + int *init_sequence = display->init_sequence;
  54272. + char *gamma = display->gamma;
  54273. + unsigned long *gamma_curves = NULL;
  54274. +
  54275. + /* sanity check */
  54276. + if (display->gamma_num * display->gamma_len > FBTFT_GAMMA_MAX_VALUES_TOTAL) {
  54277. + dev_err(dev,
  54278. + "%s: FBTFT_GAMMA_MAX_VALUES_TOTAL=%d is exceeded\n",
  54279. + __func__, FBTFT_GAMMA_MAX_VALUES_TOTAL);
  54280. + return NULL;
  54281. + }
  54282. +
  54283. + /* defaults */
  54284. + if (!fps)
  54285. + fps = 20;
  54286. + if (!bpp)
  54287. + bpp = 16;
  54288. +
  54289. + if (!pdata) {
  54290. + dev_err(dev, "platform data is missing\n");
  54291. + return NULL;
  54292. + }
  54293. +
  54294. + /* override driver values? */
  54295. + if (pdata->fps)
  54296. + fps = pdata->fps;
  54297. + if (pdata->txbuflen)
  54298. + txbuflen = pdata->txbuflen;
  54299. + if (pdata->display.init_sequence)
  54300. + init_sequence = pdata->display.init_sequence;
  54301. + if (pdata->gamma)
  54302. + gamma = pdata->gamma;
  54303. + if (pdata->display.debug)
  54304. + display->debug = pdata->display.debug;
  54305. + if (pdata->display.backlight)
  54306. + display->backlight = pdata->display.backlight;
  54307. + if (pdata->display.width)
  54308. + display->width = pdata->display.width;
  54309. + if (pdata->display.height)
  54310. + display->height = pdata->display.height;
  54311. + if (pdata->display.buswidth)
  54312. + display->buswidth = pdata->display.buswidth;
  54313. + if (pdata->display.regwidth)
  54314. + display->regwidth = pdata->display.regwidth;
  54315. +
  54316. + display->debug |= debug;
  54317. + fbtft_expand_debug_value(&display->debug);
  54318. +
  54319. + switch (pdata->rotate) {
  54320. + case 90:
  54321. + case 270:
  54322. + width = display->height;
  54323. + height = display->width;
  54324. + break;
  54325. + default:
  54326. + width = display->width;
  54327. + height = display->height;
  54328. + }
  54329. +
  54330. + vmem_size = display->width * display->height * bpp / 8;
  54331. + vmem = vzalloc(vmem_size);
  54332. + if (!vmem)
  54333. + goto alloc_fail;
  54334. +
  54335. + fbops = devm_kzalloc(dev, sizeof(struct fb_ops), GFP_KERNEL);
  54336. + if (!fbops)
  54337. + goto alloc_fail;
  54338. +
  54339. + fbdefio = devm_kzalloc(dev, sizeof(struct fb_deferred_io), GFP_KERNEL);
  54340. + if (!fbdefio)
  54341. + goto alloc_fail;
  54342. +
  54343. + buf = devm_kzalloc(dev, 128, GFP_KERNEL);
  54344. + if (!buf)
  54345. + goto alloc_fail;
  54346. +
  54347. + if (display->gamma_num && display->gamma_len) {
  54348. + gamma_curves = devm_kzalloc(dev, display->gamma_num * display->gamma_len * sizeof(gamma_curves[0]),
  54349. + GFP_KERNEL);
  54350. + if (!gamma_curves)
  54351. + goto alloc_fail;
  54352. + }
  54353. +
  54354. + info = framebuffer_alloc(sizeof(struct fbtft_par), dev);
  54355. + if (!info)
  54356. + goto alloc_fail;
  54357. +
  54358. + info->screen_base = (u8 __force __iomem *)vmem;
  54359. + info->fbops = fbops;
  54360. + info->fbdefio = fbdefio;
  54361. +
  54362. + fbops->owner = dev->driver->owner;
  54363. + fbops->fb_read = fb_sys_read;
  54364. + fbops->fb_write = fbtft_fb_write;
  54365. + fbops->fb_fillrect = fbtft_fb_fillrect;
  54366. + fbops->fb_copyarea = fbtft_fb_copyarea;
  54367. + fbops->fb_imageblit = fbtft_fb_imageblit;
  54368. + fbops->fb_setcolreg = fbtft_fb_setcolreg;
  54369. + fbops->fb_blank = fbtft_fb_blank;
  54370. +
  54371. + fbdefio->delay = HZ/fps;
  54372. + fbdefio->deferred_io = fbtft_deferred_io;
  54373. + fb_deferred_io_init(info);
  54374. +
  54375. + strncpy(info->fix.id, dev->driver->name, 16);
  54376. + info->fix.type = FB_TYPE_PACKED_PIXELS;
  54377. + info->fix.visual = FB_VISUAL_TRUECOLOR;
  54378. + info->fix.xpanstep = 0;
  54379. + info->fix.ypanstep = 0;
  54380. + info->fix.ywrapstep = 0;
  54381. + info->fix.line_length = width*bpp/8;
  54382. + info->fix.accel = FB_ACCEL_NONE;
  54383. + info->fix.smem_len = vmem_size;
  54384. +
  54385. + info->var.rotate = pdata->rotate;
  54386. + info->var.xres = width;
  54387. + info->var.yres = height;
  54388. + info->var.xres_virtual = info->var.xres;
  54389. + info->var.yres_virtual = info->var.yres;
  54390. + info->var.bits_per_pixel = bpp;
  54391. + info->var.nonstd = 1;
  54392. +
  54393. + /* RGB565 */
  54394. + info->var.red.offset = 11;
  54395. + info->var.red.length = 5;
  54396. + info->var.green.offset = 5;
  54397. + info->var.green.length = 6;
  54398. + info->var.blue.offset = 0;
  54399. + info->var.blue.length = 5;
  54400. + info->var.transp.offset = 0;
  54401. + info->var.transp.length = 0;
  54402. +
  54403. + info->flags = FBINFO_FLAG_DEFAULT | FBINFO_VIRTFB;
  54404. +
  54405. + par = info->par;
  54406. + par->info = info;
  54407. + par->pdata = dev->platform_data;
  54408. + par->debug = display->debug;
  54409. + par->buf = buf;
  54410. + spin_lock_init(&par->dirty_lock);
  54411. + par->bgr = pdata->bgr;
  54412. + par->startbyte = pdata->startbyte;
  54413. + par->init_sequence = init_sequence;
  54414. + par->gamma.curves = gamma_curves;
  54415. + par->gamma.num_curves = display->gamma_num;
  54416. + par->gamma.num_values = display->gamma_len;
  54417. + mutex_init(&par->gamma.lock);
  54418. + info->pseudo_palette = par->pseudo_palette;
  54419. +
  54420. + if (par->gamma.curves && gamma) {
  54421. + if (fbtft_gamma_parse_str(par,
  54422. + par->gamma.curves, gamma, strlen(gamma)))
  54423. + goto alloc_fail;
  54424. + }
  54425. +
  54426. + /* Transmit buffer */
  54427. + if (txbuflen == -1)
  54428. + txbuflen = vmem_size + 2; /* add in case startbyte is used */
  54429. +
  54430. +#ifdef __LITTLE_ENDIAN
  54431. + if ((!txbuflen) && (bpp > 8))
  54432. + txbuflen = PAGE_SIZE; /* need buffer for byteswapping */
  54433. +#endif
  54434. +
  54435. + if (txbuflen > 0) {
  54436. + if (dma) {
  54437. + dev->coherent_dma_mask = ~0;
  54438. + txbuf = dmam_alloc_coherent(dev, txbuflen, &par->txbuf.dma, GFP_DMA);
  54439. + } else {
  54440. + txbuf = devm_kzalloc(par->info->device, txbuflen, GFP_KERNEL);
  54441. + }
  54442. + if (!txbuf)
  54443. + goto alloc_fail;
  54444. + par->txbuf.buf = txbuf;
  54445. + par->txbuf.len = txbuflen;
  54446. + }
  54447. +
  54448. + /* Initialize gpios to disabled */
  54449. + par->gpio.reset = -1;
  54450. + par->gpio.dc = -1;
  54451. + par->gpio.rd = -1;
  54452. + par->gpio.wr = -1;
  54453. + par->gpio.cs = -1;
  54454. + par->gpio.latch = -1;
  54455. + for (i = 0; i < 16; i++) {
  54456. + par->gpio.db[i] = -1;
  54457. + par->gpio.led[i] = -1;
  54458. + par->gpio.aux[i] = -1;
  54459. + }
  54460. +
  54461. + /* default fbtft operations */
  54462. + par->fbtftops.write = fbtft_write_spi;
  54463. + par->fbtftops.read = fbtft_read_spi;
  54464. + par->fbtftops.write_vmem = fbtft_write_vmem16_bus8;
  54465. + par->fbtftops.write_register = fbtft_write_reg8_bus8;
  54466. + par->fbtftops.set_addr_win = fbtft_set_addr_win;
  54467. + par->fbtftops.reset = fbtft_reset;
  54468. + par->fbtftops.mkdirty = fbtft_mkdirty;
  54469. + par->fbtftops.update_display = fbtft_update_display;
  54470. + par->fbtftops.request_gpios = fbtft_request_gpios;
  54471. + if (display->backlight)
  54472. + par->fbtftops.register_backlight = fbtft_register_backlight;
  54473. +
  54474. + /* use driver provided functions */
  54475. + fbtft_merge_fbtftops(&par->fbtftops, &display->fbtftops);
  54476. +
  54477. + return info;
  54478. +
  54479. +alloc_fail:
  54480. + vfree(vmem);
  54481. +
  54482. + return NULL;
  54483. +}
  54484. +EXPORT_SYMBOL(fbtft_framebuffer_alloc);
  54485. +
  54486. +/**
  54487. + * fbtft_framebuffer_release - frees up all memory used by the framebuffer
  54488. + *
  54489. + * @info: frame buffer info structure
  54490. + *
  54491. + */
  54492. +void fbtft_framebuffer_release(struct fb_info *info)
  54493. +{
  54494. + fb_deferred_io_cleanup(info);
  54495. + vfree(info->screen_base);
  54496. + framebuffer_release(info);
  54497. +}
  54498. +EXPORT_SYMBOL(fbtft_framebuffer_release);
  54499. +
  54500. +/**
  54501. + * fbtft_register_framebuffer - registers a tft frame buffer device
  54502. + * @fb_info: frame buffer info structure
  54503. + *
  54504. + * Sets SPI driverdata if needed
  54505. + * Requests needed gpios.
  54506. + * Initializes display
  54507. + * Updates display.
  54508. + * Registers a frame buffer device @fb_info.
  54509. + *
  54510. + * Returns negative errno on error, or zero for success.
  54511. + *
  54512. + */
  54513. +int fbtft_register_framebuffer(struct fb_info *fb_info)
  54514. +{
  54515. + int ret;
  54516. + char text1[50] = "";
  54517. + char text2[50] = "";
  54518. + struct fbtft_par *par = fb_info->par;
  54519. + struct spi_device *spi = par->spi;
  54520. +
  54521. + /* sanity checks */
  54522. + if (!par->fbtftops.init_display) {
  54523. + dev_err(fb_info->device, "missing fbtftops.init_display()\n");
  54524. + return -EINVAL;
  54525. + }
  54526. +
  54527. + if (spi)
  54528. + spi_set_drvdata(spi, fb_info);
  54529. + if (par->pdev)
  54530. + platform_set_drvdata(par->pdev, fb_info);
  54531. +
  54532. + ret = par->fbtftops.request_gpios(par);
  54533. + if (ret < 0)
  54534. + goto reg_fail;
  54535. +
  54536. + if (par->fbtftops.verify_gpios) {
  54537. + ret = par->fbtftops.verify_gpios(par);
  54538. + if (ret < 0)
  54539. + goto reg_fail;
  54540. + }
  54541. +
  54542. + ret = par->fbtftops.init_display(par);
  54543. + if (ret < 0)
  54544. + goto reg_fail;
  54545. + if (par->fbtftops.set_var) {
  54546. + ret = par->fbtftops.set_var(par);
  54547. + if (ret < 0)
  54548. + goto reg_fail;
  54549. + }
  54550. +
  54551. + /* update the entire display */
  54552. + par->fbtftops.update_display(par, 0, par->info->var.yres - 1);
  54553. +
  54554. + if (par->fbtftops.set_gamma && par->gamma.curves) {
  54555. + ret = par->fbtftops.set_gamma(par, par->gamma.curves);
  54556. + if (ret)
  54557. + goto reg_fail;
  54558. + }
  54559. +
  54560. + if (par->fbtftops.register_backlight)
  54561. + par->fbtftops.register_backlight(par);
  54562. +
  54563. + ret = register_framebuffer(fb_info);
  54564. + if (ret < 0)
  54565. + goto reg_fail;
  54566. +
  54567. + fbtft_sysfs_init(par);
  54568. +
  54569. + if (par->txbuf.buf)
  54570. + sprintf(text1, ", %d KiB %sbuffer memory",
  54571. + par->txbuf.len >> 10, par->txbuf.dma ? "DMA " : "");
  54572. + if (spi)
  54573. + sprintf(text2, ", spi%d.%d at %d MHz", spi->master->bus_num,
  54574. + spi->chip_select, spi->max_speed_hz/1000000);
  54575. + dev_info(fb_info->dev,
  54576. + "%s frame buffer, %dx%d, %d KiB video memory%s, fps=%lu%s\n",
  54577. + fb_info->fix.id, fb_info->var.xres, fb_info->var.yres,
  54578. + fb_info->fix.smem_len >> 10, text1,
  54579. + HZ/fb_info->fbdefio->delay, text2);
  54580. +
  54581. +#ifdef CONFIG_FB_BACKLIGHT
  54582. + /* Turn on backlight if available */
  54583. + if (fb_info->bl_dev) {
  54584. + fb_info->bl_dev->props.power = FB_BLANK_UNBLANK;
  54585. + fb_info->bl_dev->ops->update_status(fb_info->bl_dev);
  54586. + }
  54587. +#endif
  54588. +
  54589. + return 0;
  54590. +
  54591. +reg_fail:
  54592. + if (par->fbtftops.unregister_backlight)
  54593. + par->fbtftops.unregister_backlight(par);
  54594. + if (spi)
  54595. + spi_set_drvdata(spi, NULL);
  54596. + if (par->pdev)
  54597. + platform_set_drvdata(par->pdev, NULL);
  54598. +
  54599. + return ret;
  54600. +}
  54601. +EXPORT_SYMBOL(fbtft_register_framebuffer);
  54602. +
  54603. +/**
  54604. + * fbtft_unregister_framebuffer - releases a tft frame buffer device
  54605. + * @fb_info: frame buffer info structure
  54606. + *
  54607. + * Frees SPI driverdata if needed
  54608. + * Frees gpios.
  54609. + * Unregisters frame buffer device.
  54610. + *
  54611. + */
  54612. +int fbtft_unregister_framebuffer(struct fb_info *fb_info)
  54613. +{
  54614. + struct fbtft_par *par = fb_info->par;
  54615. + struct spi_device *spi = par->spi;
  54616. + int ret;
  54617. +
  54618. + if (spi)
  54619. + spi_set_drvdata(spi, NULL);
  54620. + if (par->pdev)
  54621. + platform_set_drvdata(par->pdev, NULL);
  54622. + if (par->fbtftops.unregister_backlight)
  54623. + par->fbtftops.unregister_backlight(par);
  54624. + fbtft_sysfs_exit(par);
  54625. + ret = unregister_framebuffer(fb_info);
  54626. + return ret;
  54627. +}
  54628. +EXPORT_SYMBOL(fbtft_unregister_framebuffer);
  54629. +
  54630. +#ifdef CONFIG_OF
  54631. +/**
  54632. + * fbtft_init_display_dt() - Device Tree init_display() function
  54633. + * @par: Driver data
  54634. + *
  54635. + * Return: 0 if successful, negative if error
  54636. + */
  54637. +static int fbtft_init_display_dt(struct fbtft_par *par)
  54638. +{
  54639. + struct device_node *node = par->info->device->of_node;
  54640. + struct property *prop;
  54641. + const __be32 *p;
  54642. + u32 val;
  54643. + int buf[64], i, j;
  54644. + char msg[128];
  54645. + char str[16];
  54646. +
  54647. + fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
  54648. +
  54649. + if (!node)
  54650. + return -EINVAL;
  54651. +
  54652. + prop = of_find_property(node, "init", NULL);
  54653. + p = of_prop_next_u32(prop, NULL, &val);
  54654. + if (!p)
  54655. + return -EINVAL;
  54656. + while (p) {
  54657. + if (val & FBTFT_OF_INIT_CMD) {
  54658. + val &= 0xFFFF;
  54659. + i = 0;
  54660. + while (p && !(val & 0xFFFF0000)) {
  54661. + if (i > 63) {
  54662. + dev_err(par->info->device,
  54663. + "%s: Maximum register values exceeded\n",
  54664. + __func__);
  54665. + return -EINVAL;
  54666. + }
  54667. + buf[i++] = val;
  54668. + p = of_prop_next_u32(prop, p, &val);
  54669. + }
  54670. + /* make debug message */
  54671. + msg[0] = '\0';
  54672. + for (j = 0; j < i; j++) {
  54673. + snprintf(str, 128, " %02X", buf[j]);
  54674. + strcat(msg, str);
  54675. + }
  54676. + fbtft_par_dbg(DEBUG_INIT_DISPLAY, par,
  54677. + "init: write_register:%s\n", msg);
  54678. +
  54679. + par->fbtftops.write_register(par, i,
  54680. + buf[0], buf[1], buf[2], buf[3],
  54681. + buf[4], buf[5], buf[6], buf[7],
  54682. + buf[8], buf[9], buf[10], buf[11],
  54683. + buf[12], buf[13], buf[14], buf[15],
  54684. + buf[16], buf[17], buf[18], buf[19],
  54685. + buf[20], buf[21], buf[22], buf[23],
  54686. + buf[24], buf[25], buf[26], buf[27],
  54687. + buf[28], buf[29], buf[30], buf[31],
  54688. + buf[32], buf[33], buf[34], buf[35],
  54689. + buf[36], buf[37], buf[38], buf[39],
  54690. + buf[40], buf[41], buf[42], buf[43],
  54691. + buf[44], buf[45], buf[46], buf[47],
  54692. + buf[48], buf[49], buf[50], buf[51],
  54693. + buf[52], buf[53], buf[54], buf[55],
  54694. + buf[56], buf[57], buf[58], buf[59],
  54695. + buf[60], buf[61], buf[62], buf[63]);
  54696. + } else if (val & FBTFT_OF_INIT_DELAY) {
  54697. + fbtft_par_dbg(DEBUG_INIT_DISPLAY, par,
  54698. + "init: msleep(%u)\n", val & 0xFFFF);
  54699. + msleep(val & 0xFFFF);
  54700. + p = of_prop_next_u32(prop, p, &val);
  54701. + } else {
  54702. + dev_err(par->info->device, "illegal init value 0x%X\n",
  54703. + val);
  54704. + return -EINVAL;
  54705. + }
  54706. + }
  54707. +
  54708. + return 0;
  54709. +}
  54710. +#endif
  54711. +
  54712. +/**
  54713. + * fbtft_init_display() - Generic init_display() function
  54714. + * @par: Driver data
  54715. + *
  54716. + * Uses par->init_sequence to do the initialization
  54717. + *
  54718. + * Return: 0 if successful, negative if error
  54719. + */
  54720. +int fbtft_init_display(struct fbtft_par *par)
  54721. +{
  54722. + int buf[64];
  54723. + char msg[128];
  54724. + char str[16];
  54725. + int i = 0;
  54726. + int j;
  54727. +
  54728. + fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
  54729. +
  54730. + /* sanity check */
  54731. + if (!par->init_sequence) {
  54732. + dev_err(par->info->device,
  54733. + "error: init_sequence is not set\n");
  54734. + return -EINVAL;
  54735. + }
  54736. +
  54737. + /* make sure stop marker exists */
  54738. + for (i = 0; i < FBTFT_MAX_INIT_SEQUENCE; i++)
  54739. + if (par->init_sequence[i] == -3)
  54740. + break;
  54741. + if (i == FBTFT_MAX_INIT_SEQUENCE) {
  54742. + dev_err(par->info->device,
  54743. + "missing stop marker at end of init sequence\n");
  54744. + return -EINVAL;
  54745. + }
  54746. +
  54747. + par->fbtftops.reset(par);
  54748. + if (par->gpio.cs != -1)
  54749. + gpio_set_value(par->gpio.cs, 0); /* Activate chip */
  54750. +
  54751. + i = 0;
  54752. + while (i < FBTFT_MAX_INIT_SEQUENCE) {
  54753. + if (par->init_sequence[i] == -3) {
  54754. + /* done */
  54755. + return 0;
  54756. + }
  54757. + if (par->init_sequence[i] >= 0) {
  54758. + dev_err(par->info->device,
  54759. + "missing delimiter at position %d\n", i);
  54760. + return -EINVAL;
  54761. + }
  54762. + if (par->init_sequence[i+1] < 0) {
  54763. + dev_err(par->info->device,
  54764. + "missing value after delimiter %d at position %d\n",
  54765. + par->init_sequence[i], i);
  54766. + return -EINVAL;
  54767. + }
  54768. + switch (par->init_sequence[i]) {
  54769. + case -1:
  54770. + i++;
  54771. + /* make debug message */
  54772. + strcpy(msg, "");
  54773. + j = i + 1;
  54774. + while (par->init_sequence[j] >= 0) {
  54775. + sprintf(str, "0x%02X ", par->init_sequence[j]);
  54776. + strcat(msg, str);
  54777. + j++;
  54778. + }
  54779. + fbtft_par_dbg(DEBUG_INIT_DISPLAY, par,
  54780. + "init: write(0x%02X) %s\n",
  54781. + par->init_sequence[i], msg);
  54782. +
  54783. + /* Write */
  54784. + j = 0;
  54785. + while (par->init_sequence[i] >= 0) {
  54786. + if (j > 63) {
  54787. + dev_err(par->info->device,
  54788. + "%s: Maximum register values exceeded\n",
  54789. + __func__);
  54790. + return -EINVAL;
  54791. + }
  54792. + buf[j++] = par->init_sequence[i++];
  54793. + }
  54794. + par->fbtftops.write_register(par, j,
  54795. + buf[0], buf[1], buf[2], buf[3],
  54796. + buf[4], buf[5], buf[6], buf[7],
  54797. + buf[8], buf[9], buf[10], buf[11],
  54798. + buf[12], buf[13], buf[14], buf[15],
  54799. + buf[16], buf[17], buf[18], buf[19],
  54800. + buf[20], buf[21], buf[22], buf[23],
  54801. + buf[24], buf[25], buf[26], buf[27],
  54802. + buf[28], buf[29], buf[30], buf[31],
  54803. + buf[32], buf[33], buf[34], buf[35],
  54804. + buf[36], buf[37], buf[38], buf[39],
  54805. + buf[40], buf[41], buf[42], buf[43],
  54806. + buf[44], buf[45], buf[46], buf[47],
  54807. + buf[48], buf[49], buf[50], buf[51],
  54808. + buf[52], buf[53], buf[54], buf[55],
  54809. + buf[56], buf[57], buf[58], buf[59],
  54810. + buf[60], buf[61], buf[62], buf[63]);
  54811. + break;
  54812. + case -2:
  54813. + i++;
  54814. + fbtft_par_dbg(DEBUG_INIT_DISPLAY, par,
  54815. + "init: mdelay(%d)\n", par->init_sequence[i]);
  54816. + mdelay(par->init_sequence[i++]);
  54817. + break;
  54818. + default:
  54819. + dev_err(par->info->device,
  54820. + "unknown delimiter %d at position %d\n",
  54821. + par->init_sequence[i], i);
  54822. + return -EINVAL;
  54823. + }
  54824. + }
  54825. +
  54826. + dev_err(par->info->device,
  54827. + "%s: something is wrong. Shouldn't get here.\n", __func__);
  54828. + return -EINVAL;
  54829. +}
  54830. +EXPORT_SYMBOL(fbtft_init_display);
  54831. +
  54832. +/**
  54833. + * fbtft_verify_gpios() - Generic verify_gpios() function
  54834. + * @par: Driver data
  54835. + *
  54836. + * Uses @spi, @pdev and @buswidth to determine which GPIOs is needed
  54837. + *
  54838. + * Return: 0 if successful, negative if error
  54839. + */
  54840. +static int fbtft_verify_gpios(struct fbtft_par *par)
  54841. +{
  54842. + struct fbtft_platform_data *pdata;
  54843. + int i;
  54844. +
  54845. + fbtft_par_dbg(DEBUG_VERIFY_GPIOS, par, "%s()\n", __func__);
  54846. +
  54847. + pdata = par->info->device->platform_data;
  54848. + if (pdata->display.buswidth != 9 && par->startbyte == 0 && \
  54849. + par->gpio.dc < 0) {
  54850. + dev_err(par->info->device,
  54851. + "Missing info about 'dc' gpio. Aborting.\n");
  54852. + return -EINVAL;
  54853. + }
  54854. +
  54855. + if (!par->pdev)
  54856. + return 0;
  54857. +
  54858. + if (par->gpio.wr < 0) {
  54859. + dev_err(par->info->device, "Missing 'wr' gpio. Aborting.\n");
  54860. + return -EINVAL;
  54861. + }
  54862. + for (i = 0; i < pdata->display.buswidth; i++) {
  54863. + if (par->gpio.db[i] < 0) {
  54864. + dev_err(par->info->device,
  54865. + "Missing 'db%02d' gpio. Aborting.\n", i);
  54866. + return -EINVAL;
  54867. + }
  54868. + }
  54869. +
  54870. + return 0;
  54871. +}
  54872. +
  54873. +#ifdef CONFIG_OF
  54874. +/* returns 0 if the property is not present */
  54875. +static u32 fbtft_of_value(struct device_node *node, const char *propname)
  54876. +{
  54877. + int ret;
  54878. + u32 val = 0;
  54879. +
  54880. + ret = of_property_read_u32(node, propname, &val);
  54881. + if (ret == 0)
  54882. + pr_info("%s: %s = %u\n", __func__, propname, val);
  54883. +
  54884. + return val;
  54885. +}
  54886. +
  54887. +static struct fbtft_platform_data *fbtft_probe_dt(struct device *dev)
  54888. +{
  54889. + struct device_node *node = dev->of_node;
  54890. + struct fbtft_platform_data *pdata;
  54891. +
  54892. + if (!node) {
  54893. + dev_err(dev, "Missing platform data or DT\n");
  54894. + return ERR_PTR(-EINVAL);
  54895. + }
  54896. +
  54897. + pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
  54898. + if (!pdata)
  54899. + return ERR_PTR(-ENOMEM);
  54900. +
  54901. + pdata->display.width = fbtft_of_value(node, "width");
  54902. + pdata->display.height = fbtft_of_value(node, "height");
  54903. + pdata->display.regwidth = fbtft_of_value(node, "regwidth");
  54904. + pdata->display.buswidth = fbtft_of_value(node, "buswidth");
  54905. + pdata->display.backlight = fbtft_of_value(node, "backlight");
  54906. + pdata->display.bpp = fbtft_of_value(node, "bpp");
  54907. + pdata->display.debug = fbtft_of_value(node, "debug");
  54908. + pdata->rotate = fbtft_of_value(node, "rotate");
  54909. + pdata->bgr = of_property_read_bool(node, "bgr");
  54910. + pdata->fps = fbtft_of_value(node, "fps");
  54911. + pdata->txbuflen = fbtft_of_value(node, "txbuflen");
  54912. + pdata->startbyte = fbtft_of_value(node, "startbyte");
  54913. + of_property_read_string(node, "gamma", (const char **)&pdata->gamma);
  54914. +
  54915. + if (of_find_property(node, "led-gpios", NULL))
  54916. + pdata->display.backlight = 1;
  54917. + if (of_find_property(node, "init", NULL))
  54918. + pdata->display.fbtftops.init_display = fbtft_init_display_dt;
  54919. + pdata->display.fbtftops.request_gpios = fbtft_request_gpios_dt;
  54920. +
  54921. + return pdata;
  54922. +}
  54923. +#else
  54924. +static struct fbtft_platform_data *fbtft_probe_dt(struct device *dev)
  54925. +{
  54926. + dev_err(dev, "Missing platform data\n");
  54927. + return ERR_PTR(-EINVAL);
  54928. +}
  54929. +#endif
  54930. +
  54931. +/**
  54932. + * fbtft_probe_common() - Generic device probe() helper function
  54933. + * @display: Display properties
  54934. + * @sdev: SPI device
  54935. + * @pdev: Platform device
  54936. + *
  54937. + * Allocates, initializes and registers a framebuffer
  54938. + *
  54939. + * Either @sdev or @pdev should be NULL
  54940. + *
  54941. + * Return: 0 if successful, negative if error
  54942. + */
  54943. +int fbtft_probe_common(struct fbtft_display *display,
  54944. + struct spi_device *sdev, struct platform_device *pdev)
  54945. +{
  54946. + struct device *dev;
  54947. + struct fb_info *info;
  54948. + struct fbtft_par *par;
  54949. + struct fbtft_platform_data *pdata;
  54950. + int ret;
  54951. +
  54952. + if (sdev)
  54953. + dev = &sdev->dev;
  54954. + else
  54955. + dev = &pdev->dev;
  54956. +
  54957. + if (unlikely(display->debug & DEBUG_DRIVER_INIT_FUNCTIONS))
  54958. + dev_info(dev, "%s()\n", __func__);
  54959. +
  54960. + pdata = dev->platform_data;
  54961. + if (!pdata) {
  54962. + pdata = fbtft_probe_dt(dev);
  54963. + if (IS_ERR(pdata))
  54964. + return PTR_ERR(pdata);
  54965. + dev->platform_data = pdata;
  54966. + }
  54967. +
  54968. + info = fbtft_framebuffer_alloc(display, dev);
  54969. + if (!info)
  54970. + return -ENOMEM;
  54971. +
  54972. + par = info->par;
  54973. + par->spi = sdev;
  54974. + par->pdev = pdev;
  54975. +
  54976. + if (display->buswidth == 0) {
  54977. + dev_err(dev, "buswidth is not set\n");
  54978. + return -EINVAL;
  54979. + }
  54980. +
  54981. + /* write register functions */
  54982. + if (display->regwidth == 8 && display->buswidth == 8) {
  54983. + par->fbtftops.write_register = fbtft_write_reg8_bus8;
  54984. + } else
  54985. + if (display->regwidth == 8 && display->buswidth == 9 && par->spi) {
  54986. + par->fbtftops.write_register = fbtft_write_reg8_bus9;
  54987. + } else if (display->regwidth == 16 && display->buswidth == 8) {
  54988. + par->fbtftops.write_register = fbtft_write_reg16_bus8;
  54989. + } else if (display->regwidth == 16 && display->buswidth == 16) {
  54990. + par->fbtftops.write_register = fbtft_write_reg16_bus16;
  54991. + } else {
  54992. + dev_warn(dev,
  54993. + "no default functions for regwidth=%d and buswidth=%d\n",
  54994. + display->regwidth, display->buswidth);
  54995. + }
  54996. +
  54997. + /* write_vmem() functions */
  54998. + if (display->buswidth == 8)
  54999. + par->fbtftops.write_vmem = fbtft_write_vmem16_bus8;
  55000. + else if (display->buswidth == 9)
  55001. + par->fbtftops.write_vmem = fbtft_write_vmem16_bus9;
  55002. + else if (display->buswidth == 16)
  55003. + par->fbtftops.write_vmem = fbtft_write_vmem16_bus16;
  55004. +
  55005. + /* GPIO write() functions */
  55006. + if (par->pdev) {
  55007. + if (display->buswidth == 8)
  55008. + par->fbtftops.write = fbtft_write_gpio8_wr;
  55009. + else if (display->buswidth == 16)
  55010. + par->fbtftops.write = fbtft_write_gpio16_wr;
  55011. + }
  55012. +
  55013. + /* 9-bit SPI setup */
  55014. + if (par->spi && display->buswidth == 9) {
  55015. + par->spi->bits_per_word = 9;
  55016. + ret = par->spi->master->setup(par->spi);
  55017. + if (ret) {
  55018. + dev_warn(&par->spi->dev,
  55019. + "9-bit SPI not available, emulating using 8-bit.\n");
  55020. + par->spi->bits_per_word = 8;
  55021. + ret = par->spi->master->setup(par->spi);
  55022. + if (ret)
  55023. + goto out_release;
  55024. + /* allocate buffer with room for dc bits */
  55025. + par->extra = devm_kzalloc(par->info->device,
  55026. + par->txbuf.len + (par->txbuf.len / 8) + 8,
  55027. + GFP_KERNEL);
  55028. + if (!par->extra) {
  55029. + ret = -ENOMEM;
  55030. + goto out_release;
  55031. + }
  55032. + par->fbtftops.write = fbtft_write_spi_emulate_9;
  55033. + }
  55034. + }
  55035. +
  55036. + if (!par->fbtftops.verify_gpios)
  55037. + par->fbtftops.verify_gpios = fbtft_verify_gpios;
  55038. +
  55039. + /* make sure we still use the driver provided functions */
  55040. + fbtft_merge_fbtftops(&par->fbtftops, &display->fbtftops);
  55041. +
  55042. + /* use init_sequence if provided */
  55043. + if (par->init_sequence)
  55044. + par->fbtftops.init_display = fbtft_init_display;
  55045. +
  55046. + /* use platform_data provided functions above all */
  55047. + fbtft_merge_fbtftops(&par->fbtftops, &pdata->display.fbtftops);
  55048. +
  55049. + ret = fbtft_register_framebuffer(info);
  55050. + if (ret < 0)
  55051. + goto out_release;
  55052. +
  55053. + return 0;
  55054. +
  55055. +out_release:
  55056. + fbtft_framebuffer_release(info);
  55057. +
  55058. + return ret;
  55059. +}
  55060. +EXPORT_SYMBOL(fbtft_probe_common);
  55061. +
  55062. +/**
  55063. + * fbtft_remove_common() - Generic device remove() helper function
  55064. + * @dev: Device
  55065. + * @info: Framebuffer
  55066. + *
  55067. + * Unregisters and releases the framebuffer
  55068. + *
  55069. + * Return: 0 if successful, negative if error
  55070. + */
  55071. +int fbtft_remove_common(struct device *dev, struct fb_info *info)
  55072. +{
  55073. + struct fbtft_par *par;
  55074. +
  55075. + if (!info)
  55076. + return -EINVAL;
  55077. + par = info->par;
  55078. + if (par)
  55079. + fbtft_par_dbg(DEBUG_DRIVER_INIT_FUNCTIONS, par,
  55080. + "%s()\n", __func__);
  55081. + fbtft_unregister_framebuffer(info);
  55082. + fbtft_framebuffer_release(info);
  55083. +
  55084. + return 0;
  55085. +}
  55086. +EXPORT_SYMBOL(fbtft_remove_common);
  55087. +
  55088. +MODULE_LICENSE("GPL");
  55089. diff -Nur linux-3.18.8/drivers/staging/fbtft/fbtft_device.c linux-rpi/drivers/staging/fbtft/fbtft_device.c
  55090. --- linux-3.18.8/drivers/staging/fbtft/fbtft_device.c 1970-01-01 01:00:00.000000000 +0100
  55091. +++ linux-rpi/drivers/staging/fbtft/fbtft_device.c 2015-03-05 14:40:16.345715808 +0100
  55092. @@ -0,0 +1,1444 @@
  55093. +/*
  55094. + *
  55095. + * Copyright (C) 2013, Noralf Tronnes
  55096. + *
  55097. + * This program is free software; you can redistribute it and/or modify
  55098. + * it under the terms of the GNU General Public License as published by
  55099. + * the Free Software Foundation; either version 2 of the License, or
  55100. + * (at your option) any later version.
  55101. + *
  55102. + * This program is distributed in the hope that it will be useful,
  55103. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  55104. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  55105. + * GNU General Public License for more details.
  55106. + *
  55107. + * You should have received a copy of the GNU General Public License
  55108. + * along with this program; if not, write to the Free Software
  55109. + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  55110. + */
  55111. +
  55112. +#include <linux/module.h>
  55113. +#include <linux/kernel.h>
  55114. +#include <linux/init.h>
  55115. +#include <linux/gpio.h>
  55116. +#include <linux/spi/spi.h>
  55117. +
  55118. +#include "fbtft.h"
  55119. +
  55120. +#define DRVNAME "fbtft_device"
  55121. +
  55122. +#define MAX_GPIOS 32
  55123. +
  55124. +struct spi_device *spi_device;
  55125. +struct platform_device *p_device;
  55126. +
  55127. +static char *name;
  55128. +module_param(name, charp, 0);
  55129. +MODULE_PARM_DESC(name, "Devicename (required). " \
  55130. +"name=list => list all supported devices.");
  55131. +
  55132. +static unsigned rotate;
  55133. +module_param(rotate, uint, 0);
  55134. +MODULE_PARM_DESC(rotate,
  55135. +"Angle to rotate display counter clockwise: 0, 90, 180, 270");
  55136. +
  55137. +static unsigned busnum;
  55138. +module_param(busnum, uint, 0);
  55139. +MODULE_PARM_DESC(busnum, "SPI bus number (default=0)");
  55140. +
  55141. +static unsigned cs;
  55142. +module_param(cs, uint, 0);
  55143. +MODULE_PARM_DESC(cs, "SPI chip select (default=0)");
  55144. +
  55145. +static unsigned speed;
  55146. +module_param(speed, uint, 0);
  55147. +MODULE_PARM_DESC(speed, "SPI speed (override device default)");
  55148. +
  55149. +static int mode = -1;
  55150. +module_param(mode, int, 0);
  55151. +MODULE_PARM_DESC(mode, "SPI mode (override device default)");
  55152. +
  55153. +static char *gpios;
  55154. +module_param(gpios, charp, 0);
  55155. +MODULE_PARM_DESC(gpios,
  55156. +"List of gpios. Comma separated with the form: reset:23,dc:24 " \
  55157. +"(when overriding the default, all gpios must be specified)");
  55158. +
  55159. +static unsigned fps;
  55160. +module_param(fps, uint, 0);
  55161. +MODULE_PARM_DESC(fps, "Frames per second (override driver default)");
  55162. +
  55163. +static char *gamma;
  55164. +module_param(gamma, charp, 0);
  55165. +MODULE_PARM_DESC(gamma,
  55166. +"String representation of Gamma Curve(s). Driver specific.");
  55167. +
  55168. +static int txbuflen;
  55169. +module_param(txbuflen, int, 0);
  55170. +MODULE_PARM_DESC(txbuflen, "txbuflen (override driver default)");
  55171. +
  55172. +static int bgr = -1;
  55173. +module_param(bgr, int, 0);
  55174. +MODULE_PARM_DESC(bgr,
  55175. +"BGR bit (supported by some drivers).");
  55176. +
  55177. +static unsigned startbyte;
  55178. +module_param(startbyte, uint, 0);
  55179. +MODULE_PARM_DESC(startbyte, "Sets the Start byte used by some SPI displays.");
  55180. +
  55181. +static bool custom;
  55182. +module_param(custom, bool, 0);
  55183. +MODULE_PARM_DESC(custom, "Add a custom display device. " \
  55184. +"Use speed= argument to make it a SPI device, else platform_device");
  55185. +
  55186. +static unsigned width;
  55187. +module_param(width, uint, 0);
  55188. +MODULE_PARM_DESC(width, "Display width, used with the custom argument");
  55189. +
  55190. +static unsigned height;
  55191. +module_param(height, uint, 0);
  55192. +MODULE_PARM_DESC(height, "Display height, used with the custom argument");
  55193. +
  55194. +static unsigned buswidth = 8;
  55195. +module_param(buswidth, uint, 0);
  55196. +MODULE_PARM_DESC(buswidth, "Display bus width, used with the custom argument");
  55197. +
  55198. +static int init[FBTFT_MAX_INIT_SEQUENCE];
  55199. +static int init_num;
  55200. +module_param_array(init, int, &init_num, 0);
  55201. +MODULE_PARM_DESC(init, "Init sequence, used with the custom argument");
  55202. +
  55203. +static unsigned long debug;
  55204. +module_param(debug, ulong , 0);
  55205. +MODULE_PARM_DESC(debug,
  55206. +"level: 0-7 (the remaining 29 bits is for advanced usage)");
  55207. +
  55208. +static unsigned verbose = 3;
  55209. +module_param(verbose, uint, 0);
  55210. +MODULE_PARM_DESC(verbose,
  55211. +"0 silent, >0 show gpios, >1 show devices, >2 show devices before (default=3)");
  55212. +
  55213. +
  55214. +struct fbtft_device_display {
  55215. + char *name;
  55216. + struct spi_board_info *spi;
  55217. + struct platform_device *pdev;
  55218. +};
  55219. +
  55220. +static void fbtft_device_pdev_release(struct device *dev);
  55221. +
  55222. +static int write_gpio16_wr_slow(struct fbtft_par *par, void *buf, size_t len);
  55223. +static void adafruit18_green_tab_set_addr_win(struct fbtft_par *par,
  55224. + int xs, int ys, int xe, int ye);
  55225. +
  55226. +#define ADAFRUIT18_GAMMA \
  55227. + "02 1c 07 12 37 32 29 2d 29 25 2B 39 00 01 03 10\n" \
  55228. + "03 1d 07 06 2E 2C 29 2D 2E 2E 37 3F 00 00 02 10"
  55229. +
  55230. +static int hy28b_init_sequence[] = {
  55231. + -1,0x00e7,0x0010,-1,0x0000,0x0001,-1,0x0001,0x0100,-1,0x0002,0x0700,
  55232. + -1,0x0003,0x1030,-1,0x0004,0x0000,-1,0x0008,0x0207,-1,0x0009,0x0000,
  55233. + -1,0x000a,0x0000,-1,0x000c,0x0001,-1,0x000d,0x0000,-1,0x000f,0x0000,
  55234. + -1,0x0010,0x0000,-1,0x0011,0x0007,-1,0x0012,0x0000,-1,0x0013,0x0000,
  55235. + -2,50,-1,0x0010,0x1590,-1,0x0011,0x0227,-2,50,-1,0x0012,0x009c,-2,50,
  55236. + -1,0x0013,0x1900,-1,0x0029,0x0023,-1,0x002b,0x000e,-2,50,
  55237. + -1,0x0020,0x0000,-1,0x0021,0x0000,-2,50,-1,0x0050,0x0000,
  55238. + -1,0x0051,0x00ef,-1,0x0052,0x0000,-1,0x0053,0x013f,-1,0x0060,0xa700,
  55239. + -1,0x0061,0x0001,-1,0x006a,0x0000,-1,0x0080,0x0000,-1,0x0081,0x0000,
  55240. + -1,0x0082,0x0000,-1,0x0083,0x0000,-1,0x0084,0x0000,-1,0x0085,0x0000,
  55241. + -1,0x0090,0x0010,-1,0x0092,0x0000,-1,0x0093,0x0003,-1,0x0095,0x0110,
  55242. + -1,0x0097,0x0000,-1,0x0098,0x0000,-1,0x0007,0x0133,-1,0x0020,0x0000,
  55243. + -1,0x0021,0x0000,-2,100,-3 };
  55244. +
  55245. +#define HY28B_GAMMA \
  55246. + "04 1F 4 7 7 0 7 7 6 0\n" \
  55247. + "0F 00 1 7 4 0 0 0 6 7"
  55248. +
  55249. +static int pitft_init_sequence[] = {
  55250. + -1,0x01,-2,5,-1,0x28,-1,0xEF,0x03,0x80,0x02,-1,0xCF,0x00,0xC1,0x30,
  55251. + -1,0xED,0x64,0x03,0x12,0x81,-1,0xE8,0x85,0x00,0x78,
  55252. + -1,0xCB,0x39,0x2C,0x00,0x34,0x02,-1,0xF7,0x20,-1,0xEA,0x00,0x00,
  55253. + -1,0xC0,0x23,-1,0xC1,0x10,-1,0xC5,0x3e,0x28,-1,0xC7,0x86,-1,0x3A,0x55,
  55254. + -1,0xB1,0x00,0x18,-1,0xB6,0x08,0x82,0x27,-1,0xF2,0x00,-1,0x26,0x01,
  55255. + -1,0xE0,0x0F,0x31,0x2B,0x0C,0x0E,0x08,0x4E,0xF1,0x37,0x07,0x10,0x03,
  55256. + 0x0E,0x09,0x00,-1,0xE1,0x00,0x0E,0x14,0x03,0x11,0x07,0x31,0xC1,0x48,
  55257. + 0x08,0x0F,0x0C,0x31,0x36,0x0F,-1,0x11,-2,100,-1,0x29,-2,20,-3 };
  55258. +
  55259. +static int waveshare32b_init_sequence[] = {
  55260. + -1,0xCB,0x39,0x2C,0x00,0x34,0x02,-1,0xCF,0x00,0xC1,0x30,
  55261. + -1,0xE8,0x85,0x00,0x78,-1,0xEA,0x00,0x00,-1,0xED,0x64,0x03,0x12,0x81,
  55262. + -1,0xF7,0x20,-1,0xC0,0x23,-1,0xC1,0x10,-1,0xC5,0x3e,0x28,-1,0xC7,0x86,
  55263. + -1,0x36,0x28,-1,0x3A,0x55,-1,0xB1,0x00,0x18,-1,0xB6,0x08,0x82,0x27,
  55264. + -1,0xF2,0x00,-1,0x26,0x01,
  55265. + -1,0xE0,0x0F,0x31,0x2B,0x0C,0x0E,0x08,0x4E,0xF1,0x37,0x07,0x10,0x03,0x0E,0x09,0x00,
  55266. + -1,0xE1,0x00,0x0E,0x14,0x03,0x11,0x07,0x31,0xC1,0x48,0x08,0x0F,0x0C,0x31,0x36,0x0F,
  55267. + -1,0x11,-2,120,-1,0x29,-1,0x2c,-3 };
  55268. +
  55269. +/* Supported displays in alphabetical order */
  55270. +static struct fbtft_device_display displays[] = {
  55271. + {
  55272. + .name = "adafruit18",
  55273. + .spi = &(struct spi_board_info) {
  55274. + .modalias = "fb_st7735r",
  55275. + .max_speed_hz = 32000000,
  55276. + .mode = SPI_MODE_0,
  55277. + .platform_data = &(struct fbtft_platform_data) {
  55278. + .display = {
  55279. + .buswidth = 8,
  55280. + .backlight = 1,
  55281. + },
  55282. + .gpios = (const struct fbtft_gpio []) {
  55283. + { "reset", 25 },
  55284. + { "dc", 24 },
  55285. + { "led", 18 },
  55286. + {},
  55287. + },
  55288. + .gamma = ADAFRUIT18_GAMMA,
  55289. + }
  55290. + }
  55291. + }, {
  55292. + .name = "adafruit18_green",
  55293. + .spi = &(struct spi_board_info) {
  55294. + .modalias = "fb_st7735r",
  55295. + .max_speed_hz = 4000000,
  55296. + .mode = SPI_MODE_0,
  55297. + .platform_data = &(struct fbtft_platform_data) {
  55298. + .display = {
  55299. + .buswidth = 8,
  55300. + .backlight = 1,
  55301. + .fbtftops.set_addr_win = \
  55302. + adafruit18_green_tab_set_addr_win,
  55303. + },
  55304. + .bgr = true,
  55305. + .gpios = (const struct fbtft_gpio []) {
  55306. + { "reset", 25 },
  55307. + { "dc", 24 },
  55308. + { "led", 18 },
  55309. + {},
  55310. + },
  55311. + .gamma = ADAFRUIT18_GAMMA,
  55312. + }
  55313. + }
  55314. + }, {
  55315. + .name = "adafruit22",
  55316. + .spi = &(struct spi_board_info) {
  55317. + .modalias = "fb_hx8340bn",
  55318. + .max_speed_hz = 32000000,
  55319. + .mode = SPI_MODE_0,
  55320. + .platform_data = &(struct fbtft_platform_data) {
  55321. + .display = {
  55322. + .buswidth = 9,
  55323. + .backlight = 1,
  55324. + },
  55325. + .bgr = true,
  55326. + .gpios = (const struct fbtft_gpio []) {
  55327. + { "reset", 25 },
  55328. + { "led", 23 },
  55329. + {},
  55330. + },
  55331. + }
  55332. + }
  55333. + }, {
  55334. + .name = "adafruit22a",
  55335. + .spi = &(struct spi_board_info) {
  55336. + .modalias = "fb_ili9340",
  55337. + .max_speed_hz = 32000000,
  55338. + .mode = SPI_MODE_0,
  55339. + .platform_data = &(struct fbtft_platform_data) {
  55340. + .display = {
  55341. + .buswidth = 8,
  55342. + .backlight = 1,
  55343. + },
  55344. + .bgr = true,
  55345. + .gpios = (const struct fbtft_gpio []) {
  55346. + { "reset", 25 },
  55347. + { "dc", 24 },
  55348. + { "led", 18 },
  55349. + {},
  55350. + },
  55351. + }
  55352. + }
  55353. + }, {
  55354. + .name = "adafruit28",
  55355. + .spi = &(struct spi_board_info) {
  55356. + .modalias = "fb_ili9341",
  55357. + .max_speed_hz = 32000000,
  55358. + .mode = SPI_MODE_0,
  55359. + .platform_data = &(struct fbtft_platform_data) {
  55360. + .display = {
  55361. + .buswidth = 8,
  55362. + .backlight = 1,
  55363. + },
  55364. + .bgr = true,
  55365. + .gpios = (const struct fbtft_gpio []) {
  55366. + { "reset", 25 },
  55367. + { "dc", 24 },
  55368. + { "led", 18 },
  55369. + {},
  55370. + },
  55371. + }
  55372. + }
  55373. + }, {
  55374. + .name = "adafruit13m",
  55375. + .spi = &(struct spi_board_info) {
  55376. + .modalias = "fb_ssd1306",
  55377. + .max_speed_hz = 16000000,
  55378. + .mode = SPI_MODE_0,
  55379. + .platform_data = &(struct fbtft_platform_data) {
  55380. + .display = {
  55381. + .buswidth = 8,
  55382. + },
  55383. + .gpios = (const struct fbtft_gpio []) {
  55384. + { "reset", 25 },
  55385. + { "dc", 24 },
  55386. + {},
  55387. + },
  55388. + }
  55389. + }
  55390. + }, {
  55391. + .name = "agm1264k-fl",
  55392. + .pdev = &(struct platform_device) {
  55393. + .name = "fb_agm1264k-fl",
  55394. + .id = 0,
  55395. + .dev = {
  55396. + .release = fbtft_device_pdev_release,
  55397. + .platform_data = &(struct fbtft_platform_data) {
  55398. + .display = {
  55399. + .buswidth = 8,
  55400. + .backlight = FBTFT_ONBOARD_BACKLIGHT,
  55401. + },
  55402. + .gpios = (const struct fbtft_gpio []) {
  55403. + {},
  55404. + },
  55405. + },
  55406. + }
  55407. + }
  55408. + }, {
  55409. + .name = "dogs102",
  55410. + .spi = &(struct spi_board_info) {
  55411. + .modalias = "fb_uc1701",
  55412. + .max_speed_hz = 8000000,
  55413. + .mode = SPI_MODE_0,
  55414. + .platform_data = &(struct fbtft_platform_data) {
  55415. + .display = {
  55416. + .buswidth = 8,
  55417. + },
  55418. + .bgr = true,
  55419. + .gpios = (const struct fbtft_gpio []) {
  55420. + { "reset", 13 },
  55421. + { "dc", 6 },
  55422. + {},
  55423. + },
  55424. + }
  55425. + }
  55426. + }, {
  55427. + .name = "er_tftm050_2",
  55428. + .spi = &(struct spi_board_info) {
  55429. + .modalias = "fb_ra8875",
  55430. + .max_speed_hz = 5000000,
  55431. + .mode = SPI_MODE_3,
  55432. + .platform_data = &(struct fbtft_platform_data) {
  55433. + .display = {
  55434. + .buswidth = 8,
  55435. + .backlight = 1,
  55436. + .width = 480,
  55437. + .height = 272,
  55438. + },
  55439. + .bgr = true,
  55440. + .gpios = (const struct fbtft_gpio []) {
  55441. + { "reset", 25 },
  55442. + { "dc", 24 },
  55443. + {},
  55444. + },
  55445. + }
  55446. + }
  55447. + }, {
  55448. + .name = "er_tftm070_5",
  55449. + .spi = &(struct spi_board_info) {
  55450. + .modalias = "fb_ra8875",
  55451. + .max_speed_hz = 5000000,
  55452. + .mode = SPI_MODE_3,
  55453. + .platform_data = &(struct fbtft_platform_data) {
  55454. + .display = {
  55455. + .buswidth = 8,
  55456. + .backlight = 1,
  55457. + .width = 800,
  55458. + .height = 480,
  55459. + },
  55460. + .bgr = true,
  55461. + .gpios = (const struct fbtft_gpio []) {
  55462. + { "reset", 25 },
  55463. + { "dc", 24 },
  55464. + {},
  55465. + },
  55466. + }
  55467. + }
  55468. + }, {
  55469. + .name = "flexfb",
  55470. + .spi = &(struct spi_board_info) {
  55471. + .modalias = "flexfb",
  55472. + .max_speed_hz = 32000000,
  55473. + .mode = SPI_MODE_0,
  55474. + .platform_data = &(struct fbtft_platform_data) {
  55475. + .gpios = (const struct fbtft_gpio []) {
  55476. + { "reset", 25 },
  55477. + { "dc", 24 },
  55478. + {},
  55479. + },
  55480. + }
  55481. + }
  55482. + }, {
  55483. + .name = "flexpfb",
  55484. + .pdev = &(struct platform_device) {
  55485. + .name = "flexpfb",
  55486. + .id = 0,
  55487. + .dev = {
  55488. + .release = fbtft_device_pdev_release,
  55489. + .platform_data = &(struct fbtft_platform_data) {
  55490. + .gpios = (const struct fbtft_gpio []) {
  55491. + { "reset", 17 },
  55492. + { "dc", 1 },
  55493. + { "wr", 0 },
  55494. + { "cs", 21 },
  55495. + { "db00", 9 },
  55496. + { "db01", 11 },
  55497. + { "db02", 18 },
  55498. + { "db03", 23 },
  55499. + { "db04", 24 },
  55500. + { "db05", 25 },
  55501. + { "db06", 8 },
  55502. + { "db07", 7 },
  55503. + { "led", 4 },
  55504. + {},
  55505. + },
  55506. + },
  55507. + }
  55508. + }
  55509. + }, {
  55510. + .name = "freetronicsoled128",
  55511. + .spi = &(struct spi_board_info) {
  55512. + .modalias = "fb_ssd1351",
  55513. + .max_speed_hz = 20000000,
  55514. + .mode = SPI_MODE_0,
  55515. + .platform_data = &(struct fbtft_platform_data) {
  55516. + .display = {
  55517. + .buswidth = 8,
  55518. + .backlight = FBTFT_ONBOARD_BACKLIGHT,
  55519. + },
  55520. + .bgr = true,
  55521. + .gpios = (const struct fbtft_gpio []) {
  55522. + { "reset", 24 },
  55523. + { "dc", 25 },
  55524. + {},
  55525. + },
  55526. + }
  55527. + }
  55528. + }, {
  55529. + .name = "hx8353d",
  55530. + .spi = &(struct spi_board_info) {
  55531. + .modalias = "fb_hx8353d",
  55532. + .max_speed_hz = 16000000,
  55533. + .mode = SPI_MODE_0,
  55534. + .platform_data = &(struct fbtft_platform_data) {
  55535. + .display = {
  55536. + .buswidth = 8,
  55537. + .backlight = 1,
  55538. + },
  55539. + .gpios = (const struct fbtft_gpio []) {
  55540. + { "reset", 25 },
  55541. + { "dc", 24 },
  55542. + { "led", 23 },
  55543. + {},
  55544. + },
  55545. + }
  55546. + }
  55547. + }, {
  55548. + .name = "hy28a",
  55549. + .spi = &(struct spi_board_info) {
  55550. + .modalias = "fb_ili9320",
  55551. + .max_speed_hz = 32000000,
  55552. + .mode = SPI_MODE_3,
  55553. + .platform_data = &(struct fbtft_platform_data) {
  55554. + .display = {
  55555. + .buswidth = 8,
  55556. + .backlight = 1,
  55557. + },
  55558. + .startbyte = 0b01110000,
  55559. + .bgr = true,
  55560. + .gpios = (const struct fbtft_gpio []) {
  55561. + { "reset", 25 },
  55562. + { "led", 18 },
  55563. + {},
  55564. + },
  55565. + }
  55566. + }
  55567. + }, {
  55568. + .name = "hy28b",
  55569. + .spi = &(struct spi_board_info) {
  55570. + .modalias = "fb_ili9325",
  55571. + .max_speed_hz = 48000000,
  55572. + .mode = SPI_MODE_3,
  55573. + .platform_data = &(struct fbtft_platform_data) {
  55574. + .display = {
  55575. + .buswidth = 8,
  55576. + .backlight = 1,
  55577. + .init_sequence = hy28b_init_sequence,
  55578. + },
  55579. + .startbyte = 0b01110000,
  55580. + .bgr = true,
  55581. + .fps= 50,
  55582. + .gpios = (const struct fbtft_gpio []) {
  55583. + { "reset", 25 },
  55584. + { "led", 18 },
  55585. + {},
  55586. + },
  55587. + .gamma = HY28B_GAMMA,
  55588. + }
  55589. + }
  55590. + }, {
  55591. + .name = "ili9481",
  55592. + .spi = &(struct spi_board_info) {
  55593. + .modalias = "fb_ili9481",
  55594. + .max_speed_hz = 32000000,
  55595. + .mode = SPI_MODE_0,
  55596. + .platform_data = &(struct fbtft_platform_data) {
  55597. + .display = {
  55598. + .regwidth = 16,
  55599. + .buswidth = 8,
  55600. + .backlight = 1,
  55601. + },
  55602. + .bgr = true,
  55603. + .gpios = (const struct fbtft_gpio []) {
  55604. + { "reset", 25 },
  55605. + { "dc", 24 },
  55606. + { "led", 22 },
  55607. + {},
  55608. + },
  55609. + }
  55610. + }
  55611. + }, {
  55612. + .name = "itdb24",
  55613. + .pdev = &(struct platform_device) {
  55614. + .name = "fb_s6d1121",
  55615. + .id = 0,
  55616. + .dev = {
  55617. + .release = fbtft_device_pdev_release,
  55618. + .platform_data = &(struct fbtft_platform_data) {
  55619. + .display = {
  55620. + .buswidth = 8,
  55621. + .backlight = 1,
  55622. + },
  55623. + .bgr = false,
  55624. + .gpios = (const struct fbtft_gpio []) {
  55625. + /* Wiring for LCD adapter kit */
  55626. + { "reset", 7 },
  55627. + { "dc", 0 }, /* rev 2: 2 */
  55628. + { "wr", 1 }, /* rev 2: 3 */
  55629. + { "cs", 8 },
  55630. + { "db00", 17 },
  55631. + { "db01", 18 },
  55632. + { "db02", 21 }, /* rev 2: 27 */
  55633. + { "db03", 22 },
  55634. + { "db04", 23 },
  55635. + { "db05", 24 },
  55636. + { "db06", 25 },
  55637. + { "db07", 4 },
  55638. + {}
  55639. + },
  55640. + },
  55641. + }
  55642. + }
  55643. + }, {
  55644. + .name = "itdb28",
  55645. + .pdev = &(struct platform_device) {
  55646. + .name = "fb_ili9325",
  55647. + .id = 0,
  55648. + .dev = {
  55649. + .release = fbtft_device_pdev_release,
  55650. + .platform_data = &(struct fbtft_platform_data) {
  55651. + .display = {
  55652. + .buswidth = 8,
  55653. + .backlight = 1,
  55654. + },
  55655. + .bgr = true,
  55656. + .gpios = (const struct fbtft_gpio []) {
  55657. + {},
  55658. + },
  55659. + },
  55660. + }
  55661. + }
  55662. + }, {
  55663. + .name = "itdb28_spi",
  55664. + .spi = &(struct spi_board_info) {
  55665. + .modalias = "fb_ili9325",
  55666. + .max_speed_hz = 32000000,
  55667. + .mode = SPI_MODE_0,
  55668. + .platform_data = &(struct fbtft_platform_data) {
  55669. + .display = {
  55670. + .buswidth = 8,
  55671. + .backlight = 1,
  55672. + },
  55673. + .bgr = true,
  55674. + .gpios = (const struct fbtft_gpio []) {
  55675. + { "reset", 25 },
  55676. + { "dc", 24 },
  55677. + {},
  55678. + },
  55679. + }
  55680. + }
  55681. + }, {
  55682. + .name = "mi0283qt-2",
  55683. + .spi = &(struct spi_board_info) {
  55684. + .modalias = "fb_hx8347d",
  55685. + .max_speed_hz = 32000000,
  55686. + .mode = SPI_MODE_0,
  55687. + .platform_data = &(struct fbtft_platform_data) {
  55688. + .display = {
  55689. + .buswidth = 8,
  55690. + .backlight = 1,
  55691. + },
  55692. + .startbyte = 0b01110000,
  55693. + .bgr = true,
  55694. + .gpios = (const struct fbtft_gpio []) {
  55695. + { "reset", 25 },
  55696. + { "dc", 24 },
  55697. + { "led", 18 },
  55698. + {},
  55699. + },
  55700. + }
  55701. + }
  55702. + }, {
  55703. + .name = "mi0283qt-9a",
  55704. + .spi = &(struct spi_board_info) {
  55705. + .modalias = "fb_ili9341",
  55706. + .max_speed_hz = 32000000,
  55707. + .mode = SPI_MODE_0,
  55708. + .platform_data = &(struct fbtft_platform_data) {
  55709. + .display = {
  55710. + .buswidth = 9,
  55711. + .backlight = 1,
  55712. + },
  55713. + .bgr = true,
  55714. + .gpios = (const struct fbtft_gpio []) {
  55715. + { "reset", 25 },
  55716. + { "led", 18 },
  55717. + {},
  55718. + },
  55719. + }
  55720. + }
  55721. + }, {
  55722. + .name = "mi0283qt-v2",
  55723. + .spi = &(struct spi_board_info) {
  55724. + .modalias = "fb_watterott",
  55725. + .max_speed_hz = 4000000,
  55726. + .mode = SPI_MODE_3,
  55727. + .platform_data = &(struct fbtft_platform_data) {
  55728. + .gpios = (const struct fbtft_gpio []) {
  55729. + { "reset", 25 },
  55730. + {},
  55731. + },
  55732. + }
  55733. + }
  55734. + }, {
  55735. + .name = "nokia3310",
  55736. + .spi = &(struct spi_board_info) {
  55737. + .modalias = "fb_pcd8544",
  55738. + .max_speed_hz = 400000,
  55739. + .mode = SPI_MODE_0,
  55740. + .platform_data = &(struct fbtft_platform_data) {
  55741. + .display = {
  55742. + .buswidth = 8,
  55743. + },
  55744. + .gpios = (const struct fbtft_gpio []) {
  55745. + { "reset", 25 },
  55746. + { "dc", 24 },
  55747. + { "led", 23 },
  55748. + {},
  55749. + },
  55750. + }
  55751. + }
  55752. + }, {
  55753. + .name = "nokia3310a",
  55754. + .spi = &(struct spi_board_info) {
  55755. + .modalias = "fb_tls8204",
  55756. + .max_speed_hz = 1000000,
  55757. + .mode = SPI_MODE_0,
  55758. + .platform_data = &(struct fbtft_platform_data) {
  55759. + .display = {
  55760. + .buswidth = 8,
  55761. + },
  55762. + .gpios = (const struct fbtft_gpio []) {
  55763. + { "reset", 25 },
  55764. + { "dc", 24 },
  55765. + { "led", 23 },
  55766. + {},
  55767. + },
  55768. + }
  55769. + }
  55770. + }, {
  55771. + .name = "piscreen",
  55772. + .spi = &(struct spi_board_info) {
  55773. + .modalias = "fb_ili9486",
  55774. + .max_speed_hz = 32000000,
  55775. + .mode = SPI_MODE_0,
  55776. + .platform_data = &(struct fbtft_platform_data) {
  55777. + .display = {
  55778. + .regwidth = 16,
  55779. + .buswidth = 8,
  55780. + .backlight = 1,
  55781. + },
  55782. + .bgr = true,
  55783. + .gpios = (const struct fbtft_gpio []) {
  55784. + { "reset", 25 },
  55785. + { "dc", 24 },
  55786. + { "led", 22 },
  55787. + {},
  55788. + },
  55789. + }
  55790. + }
  55791. + }, {
  55792. + .name = "pitft",
  55793. + .spi = &(struct spi_board_info) {
  55794. + .modalias = "fb_ili9340",
  55795. + .max_speed_hz = 32000000,
  55796. + .mode = SPI_MODE_0,
  55797. + .chip_select = 0,
  55798. + .platform_data = &(struct fbtft_platform_data) {
  55799. + .display = {
  55800. + .buswidth = 8,
  55801. + .backlight = 1,
  55802. + .init_sequence = pitft_init_sequence,
  55803. + },
  55804. + .bgr = true,
  55805. + .gpios = (const struct fbtft_gpio []) {
  55806. + { "dc", 25 },
  55807. + {},
  55808. + },
  55809. + }
  55810. + }
  55811. + }, {
  55812. + .name = "pioled",
  55813. + .spi = &(struct spi_board_info) {
  55814. + .modalias = "fb_ssd1351",
  55815. + .max_speed_hz = 20000000,
  55816. + .mode = SPI_MODE_0,
  55817. + .platform_data = &(struct fbtft_platform_data) {
  55818. + .display = {
  55819. + .buswidth = 8,
  55820. + },
  55821. + .bgr = true,
  55822. + .gpios = (const struct fbtft_gpio []) {
  55823. + { "reset", 24 },
  55824. + { "dc", 25 },
  55825. + {},
  55826. + },
  55827. + .gamma = "0 2 2 2 2 2 2 2 " \
  55828. + "2 2 2 2 2 2 2 2 " \
  55829. + "2 2 2 2 2 2 2 2 " \
  55830. + "2 2 2 2 2 2 2 3 " \
  55831. + "3 3 3 3 3 3 3 3 " \
  55832. + "3 3 3 3 3 3 3 3 " \
  55833. + "3 3 3 4 4 4 4 4 " \
  55834. + "4 4 4 4 4 4 4"
  55835. + }
  55836. + }
  55837. + }, {
  55838. + .name = "rpi-display",
  55839. + .spi = &(struct spi_board_info) {
  55840. + .modalias = "fb_ili9341",
  55841. + .max_speed_hz = 32000000,
  55842. + .mode = SPI_MODE_0,
  55843. + .platform_data = &(struct fbtft_platform_data) {
  55844. + .display = {
  55845. + .buswidth = 8,
  55846. + .backlight = 1,
  55847. + },
  55848. + .bgr = true,
  55849. + .gpios = (const struct fbtft_gpio []) {
  55850. + { "reset", 23 },
  55851. + { "dc", 24 },
  55852. + { "led", 18 },
  55853. + {},
  55854. + },
  55855. + }
  55856. + }
  55857. + }, {
  55858. + .name = "s6d02a1",
  55859. + .spi = &(struct spi_board_info) {
  55860. + .modalias = "fb_s6d02a1",
  55861. + .max_speed_hz = 32000000,
  55862. + .mode = SPI_MODE_0,
  55863. + .platform_data = &(struct fbtft_platform_data) {
  55864. + .display = {
  55865. + .buswidth = 8,
  55866. + .backlight = 1,
  55867. + },
  55868. + .bgr = true,
  55869. + .gpios = (const struct fbtft_gpio []) {
  55870. + { "reset", 25 },
  55871. + { "dc", 24 },
  55872. + { "led", 23 },
  55873. + {},
  55874. + },
  55875. + }
  55876. + }
  55877. + }, {
  55878. + .name = "sainsmart18",
  55879. + .spi = &(struct spi_board_info) {
  55880. + .modalias = "fb_st7735r",
  55881. + .max_speed_hz = 32000000,
  55882. + .mode = SPI_MODE_0,
  55883. + .platform_data = &(struct fbtft_platform_data) {
  55884. + .display = {
  55885. + .buswidth = 8,
  55886. + },
  55887. + .gpios = (const struct fbtft_gpio []) {
  55888. + { "reset", 25 },
  55889. + { "dc", 24 },
  55890. + {},
  55891. + },
  55892. + }
  55893. + }
  55894. + }, {
  55895. + .name = "sainsmart32",
  55896. + .pdev = &(struct platform_device) {
  55897. + .name = "fb_ssd1289",
  55898. + .id = 0,
  55899. + .dev = {
  55900. + .release = fbtft_device_pdev_release,
  55901. + .platform_data = &(struct fbtft_platform_data) {
  55902. + .display = {
  55903. + .buswidth = 16,
  55904. + .txbuflen = -2, /* disable buffer */
  55905. + .backlight = 1,
  55906. + .fbtftops.write = write_gpio16_wr_slow,
  55907. + },
  55908. + .bgr = true,
  55909. + .gpios = (const struct fbtft_gpio []) {
  55910. + {},
  55911. + },
  55912. + },
  55913. + },
  55914. + }
  55915. + }, {
  55916. + .name = "sainsmart32_fast",
  55917. + .pdev = &(struct platform_device) {
  55918. + .name = "fb_ssd1289",
  55919. + .id = 0,
  55920. + .dev = {
  55921. + .release = fbtft_device_pdev_release,
  55922. + .platform_data = &(struct fbtft_platform_data) {
  55923. + .display = {
  55924. + .buswidth = 16,
  55925. + .txbuflen = -2, /* disable buffer */
  55926. + .backlight = 1,
  55927. + },
  55928. + .bgr = true,
  55929. + .gpios = (const struct fbtft_gpio []) {
  55930. + {},
  55931. + },
  55932. + },
  55933. + },
  55934. + }
  55935. + }, {
  55936. + .name = "sainsmart32_latched",
  55937. + .pdev = &(struct platform_device) {
  55938. + .name = "fb_ssd1289",
  55939. + .id = 0,
  55940. + .dev = {
  55941. + .release = fbtft_device_pdev_release,
  55942. + .platform_data = &(struct fbtft_platform_data) {
  55943. + .display = {
  55944. + .buswidth = 16,
  55945. + .txbuflen = -2, /* disable buffer */
  55946. + .backlight = 1,
  55947. + .fbtftops.write = \
  55948. + fbtft_write_gpio16_wr_latched,
  55949. + },
  55950. + .bgr = true,
  55951. + .gpios = (const struct fbtft_gpio []) {
  55952. + {},
  55953. + },
  55954. + },
  55955. + },
  55956. + }
  55957. + }, {
  55958. + .name = "sainsmart32_spi",
  55959. + .spi = &(struct spi_board_info) {
  55960. + .modalias = "fb_ssd1289",
  55961. + .max_speed_hz = 16000000,
  55962. + .mode = SPI_MODE_0,
  55963. + .platform_data = &(struct fbtft_platform_data) {
  55964. + .display = {
  55965. + .buswidth = 8,
  55966. + .backlight = 1,
  55967. + },
  55968. + .bgr = true,
  55969. + .gpios = (const struct fbtft_gpio []) {
  55970. + { "reset", 25 },
  55971. + { "dc", 24 },
  55972. + {},
  55973. + },
  55974. + }
  55975. + }
  55976. + }, {
  55977. + .name = "spidev",
  55978. + .spi = &(struct spi_board_info) {
  55979. + .modalias = "spidev",
  55980. + .max_speed_hz = 500000,
  55981. + .bus_num = 0,
  55982. + .chip_select = 0,
  55983. + .mode = SPI_MODE_0,
  55984. + .platform_data = &(struct fbtft_platform_data) {
  55985. + .gpios = (const struct fbtft_gpio []) {
  55986. + {},
  55987. + },
  55988. + }
  55989. + }
  55990. + }, {
  55991. + .name = "ssd1331",
  55992. + .spi = &(struct spi_board_info) {
  55993. + .modalias = "fb_ssd1331",
  55994. + .max_speed_hz = 20000000,
  55995. + .mode = SPI_MODE_3,
  55996. + .platform_data = &(struct fbtft_platform_data) {
  55997. + .display = {
  55998. + .buswidth = 8,
  55999. + },
  56000. + .gpios = (const struct fbtft_gpio []) {
  56001. + { "reset", 24 },
  56002. + { "dc", 25 },
  56003. + {},
  56004. + },
  56005. + }
  56006. + }
  56007. + }, {
  56008. + .name = "tinylcd35",
  56009. + .spi = &(struct spi_board_info) {
  56010. + .modalias = "fb_tinylcd",
  56011. + .max_speed_hz = 32000000,
  56012. + .mode = SPI_MODE_0,
  56013. + .platform_data = &(struct fbtft_platform_data) {
  56014. + .display = {
  56015. + .buswidth = 8,
  56016. + .backlight = 1,
  56017. + },
  56018. + .bgr = true,
  56019. + .gpios = (const struct fbtft_gpio []) {
  56020. + { "reset", 25 },
  56021. + { "dc", 24 },
  56022. + { "led", 18 },
  56023. + {},
  56024. + },
  56025. + }
  56026. + }
  56027. + }, {
  56028. + .name = "tm022hdh26",
  56029. + .spi = &(struct spi_board_info) {
  56030. + .modalias = "fb_ili9341",
  56031. + .max_speed_hz = 32000000,
  56032. + .mode = SPI_MODE_0,
  56033. + .platform_data = &(struct fbtft_platform_data) {
  56034. + .display = {
  56035. + .buswidth = 8,
  56036. + .backlight = 1,
  56037. + },
  56038. + .bgr = true,
  56039. + .gpios = (const struct fbtft_gpio []) {
  56040. + { "reset", 25 },
  56041. + { "dc", 24 },
  56042. + { "led", 18 },
  56043. + {},
  56044. + },
  56045. + }
  56046. + }
  56047. + }, {
  56048. + .name = "tontec35_9481", /* boards before 02 July 2014 */
  56049. + .spi = &(struct spi_board_info) {
  56050. + .modalias = "fb_ili9481",
  56051. + .max_speed_hz = 128000000,
  56052. + .mode = SPI_MODE_3,
  56053. + .platform_data = &(struct fbtft_platform_data) {
  56054. + .display = {
  56055. + .buswidth = 8,
  56056. + .backlight = 1,
  56057. + },
  56058. + .bgr = true,
  56059. + .gpios = (const struct fbtft_gpio []) {
  56060. + { "reset", 15 },
  56061. + { "dc", 25 },
  56062. + { "led_", 18 },
  56063. + {},
  56064. + },
  56065. + }
  56066. + }
  56067. + }, {
  56068. + .name = "tontec35_9486", /* boards after 02 July 2014 */
  56069. + .spi = &(struct spi_board_info) {
  56070. + .modalias = "fb_ili9486",
  56071. + .max_speed_hz = 128000000,
  56072. + .mode = SPI_MODE_3,
  56073. + .platform_data = &(struct fbtft_platform_data) {
  56074. + .display = {
  56075. + .buswidth = 8,
  56076. + .backlight = 1,
  56077. + },
  56078. + .bgr = true,
  56079. + .gpios = (const struct fbtft_gpio []) {
  56080. + { "reset", 15 },
  56081. + { "dc", 25 },
  56082. + { "led_", 18 },
  56083. + {},
  56084. + },
  56085. + }
  56086. + }
  56087. + }, {
  56088. + .name = "upd161704",
  56089. + .spi = &(struct spi_board_info) {
  56090. + .modalias = "fb_upd161704",
  56091. + .max_speed_hz = 32000000,
  56092. + .mode = SPI_MODE_0,
  56093. + .platform_data = &(struct fbtft_platform_data) {
  56094. + .display = {
  56095. + .buswidth = 8,
  56096. + },
  56097. + .gpios = (const struct fbtft_gpio []) {
  56098. + { "reset", 24 },
  56099. + { "dc", 25 },
  56100. + {},
  56101. + },
  56102. + }
  56103. + }
  56104. + }, {
  56105. + .name = "waveshare32b",
  56106. + .spi = &(struct spi_board_info) {
  56107. + .modalias = "fb_ili9340",
  56108. + .max_speed_hz = 48000000,
  56109. + .mode = SPI_MODE_0,
  56110. + .platform_data = &(struct fbtft_platform_data) {
  56111. + .display = {
  56112. + .buswidth = 8,
  56113. + .backlight = 1,
  56114. + .init_sequence = waveshare32b_init_sequence,
  56115. + },
  56116. + .bgr = true,
  56117. + .gpios = (const struct fbtft_gpio []) {
  56118. + { "reset", 27 },
  56119. + { "dc", 22 },
  56120. + {},
  56121. + },
  56122. + }
  56123. + }
  56124. + }, {
  56125. + .name = "waveshare22",
  56126. + .spi = &(struct spi_board_info) {
  56127. + .modalias = "fb_bd663474",
  56128. + .max_speed_hz = 32000000,
  56129. + .mode = SPI_MODE_3,
  56130. + .platform_data = &(struct fbtft_platform_data) {
  56131. + .display = {
  56132. + .buswidth = 8,
  56133. + },
  56134. + .gpios = (const struct fbtft_gpio []) {
  56135. + { "reset", 24 },
  56136. + { "dc", 25 },
  56137. + {},
  56138. + },
  56139. + }
  56140. + }
  56141. + }, {
  56142. + /* This should be the last item.
  56143. + Used with the custom argument */
  56144. + .name = "",
  56145. + .spi = &(struct spi_board_info) {
  56146. + .modalias = "",
  56147. + .max_speed_hz = 0,
  56148. + .mode = SPI_MODE_0,
  56149. + .platform_data = &(struct fbtft_platform_data) {
  56150. + .gpios = (const struct fbtft_gpio []) {
  56151. + {},
  56152. + },
  56153. + }
  56154. + },
  56155. + .pdev = &(struct platform_device) {
  56156. + .name = "",
  56157. + .id = 0,
  56158. + .dev = {
  56159. + .release = fbtft_device_pdev_release,
  56160. + .platform_data = &(struct fbtft_platform_data) {
  56161. + .gpios = (const struct fbtft_gpio []) {
  56162. + {},
  56163. + },
  56164. + },
  56165. + },
  56166. + },
  56167. + }
  56168. +};
  56169. +
  56170. +static int write_gpio16_wr_slow(struct fbtft_par *par, void *buf, size_t len)
  56171. +{
  56172. + u16 data;
  56173. + int i;
  56174. +#ifndef DO_NOT_OPTIMIZE_FBTFT_WRITE_GPIO
  56175. + static u16 prev_data;
  56176. +#endif
  56177. +
  56178. + fbtft_par_dbg_hex(DEBUG_WRITE, par, par->info->device, u8, buf, len,
  56179. + "%s(len=%d): ", __func__, len);
  56180. +
  56181. + while (len) {
  56182. + data = *(u16 *) buf;
  56183. +
  56184. + /* Start writing by pulling down /WR */
  56185. + gpio_set_value(par->gpio.wr, 0);
  56186. +
  56187. + /* Set data */
  56188. +#ifndef DO_NOT_OPTIMIZE_FBTFT_WRITE_GPIO
  56189. + if (data == prev_data) {
  56190. + gpio_set_value(par->gpio.wr, 0); /* used as delay */
  56191. + } else {
  56192. + for (i = 0; i < 16; i++) {
  56193. + if ((data & 1) != (prev_data & 1))
  56194. + gpio_set_value(par->gpio.db[i],
  56195. + (data & 1));
  56196. + data >>= 1;
  56197. + prev_data >>= 1;
  56198. + }
  56199. + }
  56200. +#else
  56201. + for (i = 0; i < 16; i++) {
  56202. + gpio_set_value(par->gpio.db[i], (data & 1));
  56203. + data >>= 1;
  56204. + }
  56205. +#endif
  56206. +
  56207. + /* Pullup /WR */
  56208. + gpio_set_value(par->gpio.wr, 1);
  56209. +
  56210. +#ifndef DO_NOT_OPTIMIZE_FBTFT_WRITE_GPIO
  56211. + prev_data = *(u16 *) buf;
  56212. +#endif
  56213. + buf += 2;
  56214. + len -= 2;
  56215. + }
  56216. +
  56217. + return 0;
  56218. +}
  56219. +
  56220. +static void adafruit18_green_tab_set_addr_win(struct fbtft_par *par,
  56221. + int xs, int ys, int xe, int ye)
  56222. +{
  56223. + fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par,
  56224. + "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye);
  56225. + write_reg(par, 0x2A, 0, xs + 2, 0, xe + 2);
  56226. + write_reg(par, 0x2B, 0, ys + 1, 0, ye + 1);
  56227. + write_reg(par, 0x2C);
  56228. +}
  56229. +
  56230. +/* used if gpios parameter is present */
  56231. +static struct fbtft_gpio fbtft_device_param_gpios[MAX_GPIOS+1] = { };
  56232. +
  56233. +static void fbtft_device_pdev_release(struct device *dev)
  56234. +{
  56235. +/* Needed to silence this message:
  56236. +Device 'xxx' does not have a release() function, it is broken and must be fixed
  56237. +*/
  56238. +}
  56239. +
  56240. +static int spi_device_found(struct device *dev, void *data)
  56241. +{
  56242. + struct spi_device *spi = container_of(dev, struct spi_device, dev);
  56243. +
  56244. + pr_info(DRVNAME": %s %s %dkHz %d bits mode=0x%02X\n",
  56245. + spi->modalias, dev_name(dev), spi->max_speed_hz/1000,
  56246. + spi->bits_per_word, spi->mode);
  56247. +
  56248. + return 0;
  56249. +}
  56250. +
  56251. +static void pr_spi_devices(void)
  56252. +{
  56253. + pr_info(DRVNAME": SPI devices registered:\n");
  56254. + bus_for_each_dev(&spi_bus_type, NULL, NULL, spi_device_found);
  56255. +}
  56256. +
  56257. +static int p_device_found(struct device *dev, void *data)
  56258. +{
  56259. + struct platform_device
  56260. + *pdev = container_of(dev, struct platform_device, dev);
  56261. +
  56262. + if (strstr(pdev->name, "fb"))
  56263. + pr_info(DRVNAME": %s id=%d pdata? %s\n",
  56264. + pdev->name, pdev->id,
  56265. + pdev->dev.platform_data ? "yes" : "no");
  56266. +
  56267. + return 0;
  56268. +}
  56269. +
  56270. +static void pr_p_devices(void)
  56271. +{
  56272. + pr_info(DRVNAME": 'fb' Platform devices registered:\n");
  56273. + bus_for_each_dev(&platform_bus_type, NULL, NULL, p_device_found);
  56274. +}
  56275. +
  56276. +#ifdef MODULE
  56277. +static void fbtft_device_spi_delete(struct spi_master *master, unsigned cs)
  56278. +{
  56279. + struct device *dev;
  56280. + char str[32];
  56281. +
  56282. + snprintf(str, sizeof(str), "%s.%u", dev_name(&master->dev), cs);
  56283. +
  56284. + dev = bus_find_device_by_name(&spi_bus_type, NULL, str);
  56285. + if (dev) {
  56286. + if (verbose)
  56287. + pr_info(DRVNAME": Deleting %s\n", str);
  56288. + device_del(dev);
  56289. + }
  56290. +}
  56291. +
  56292. +static int fbtft_device_spi_device_register(struct spi_board_info *spi)
  56293. +{
  56294. + struct spi_master *master;
  56295. +
  56296. + master = spi_busnum_to_master(spi->bus_num);
  56297. + if (!master) {
  56298. + pr_err(DRVNAME ": spi_busnum_to_master(%d) returned NULL\n",
  56299. + spi->bus_num);
  56300. + return -EINVAL;
  56301. + }
  56302. + /* make sure it's available */
  56303. + fbtft_device_spi_delete(master, spi->chip_select);
  56304. + spi_device = spi_new_device(master, spi);
  56305. + put_device(&master->dev);
  56306. + if (!spi_device) {
  56307. + pr_err(DRVNAME ": spi_new_device() returned NULL\n");
  56308. + return -EPERM;
  56309. + }
  56310. + return 0;
  56311. +}
  56312. +#else
  56313. +static int fbtft_device_spi_device_register(struct spi_board_info *spi)
  56314. +{
  56315. + return spi_register_board_info(spi, 1);
  56316. +}
  56317. +#endif
  56318. +
  56319. +static int __init fbtft_device_init(void)
  56320. +{
  56321. + struct spi_board_info *spi = NULL;
  56322. + struct fbtft_platform_data *pdata;
  56323. + const struct fbtft_gpio *gpio = NULL;
  56324. + char *p_gpio, *p_name, *p_num;
  56325. + bool found = false;
  56326. + int i = 0;
  56327. + long val;
  56328. + int ret = 0;
  56329. +
  56330. + pr_debug("\n\n"DRVNAME": init\n");
  56331. +
  56332. + if (name == NULL) {
  56333. +#ifdef MODULE
  56334. + pr_err(DRVNAME": missing module parameter: 'name'\n");
  56335. + return -EINVAL;
  56336. +#else
  56337. + return 0;
  56338. +#endif
  56339. + }
  56340. +
  56341. + if (init_num > FBTFT_MAX_INIT_SEQUENCE) {
  56342. + pr_err(DRVNAME \
  56343. + ": init parameter: exceeded max array size: %d\n",
  56344. + FBTFT_MAX_INIT_SEQUENCE);
  56345. + return -EINVAL;
  56346. + }
  56347. +
  56348. + /* parse module parameter: gpios */
  56349. + while ((p_gpio = strsep(&gpios, ","))) {
  56350. + if (strchr(p_gpio, ':') == NULL) {
  56351. + pr_err(DRVNAME \
  56352. + ": error: missing ':' in gpios parameter: %s\n",
  56353. + p_gpio);
  56354. + return -EINVAL;
  56355. + }
  56356. + p_num = p_gpio;
  56357. + p_name = strsep(&p_num, ":");
  56358. + if (p_name == NULL || p_num == NULL) {
  56359. + pr_err(DRVNAME \
  56360. + ": something bad happened parsing gpios parameter: %s\n",
  56361. + p_gpio);
  56362. + return -EINVAL;
  56363. + }
  56364. + ret = kstrtol(p_num, 10, &val);
  56365. + if (ret) {
  56366. + pr_err(DRVNAME \
  56367. + ": could not parse number in gpios parameter: %s:%s\n",
  56368. + p_name, p_num);
  56369. + return -EINVAL;
  56370. + }
  56371. + strcpy(fbtft_device_param_gpios[i].name, p_name);
  56372. + fbtft_device_param_gpios[i++].gpio = (int) val;
  56373. + if (i == MAX_GPIOS) {
  56374. + pr_err(DRVNAME \
  56375. + ": gpios parameter: exceeded max array size: %d\n",
  56376. + MAX_GPIOS);
  56377. + return -EINVAL;
  56378. + }
  56379. + }
  56380. + if (fbtft_device_param_gpios[0].name[0])
  56381. + gpio = fbtft_device_param_gpios;
  56382. +
  56383. + if (verbose > 2)
  56384. + pr_spi_devices(); /* print list of registered SPI devices */
  56385. +
  56386. + if (verbose > 2)
  56387. + pr_p_devices(); /* print list of 'fb' platform devices */
  56388. +
  56389. + pr_debug(DRVNAME": name='%s', busnum=%d, cs=%d\n", name, busnum, cs);
  56390. +
  56391. + if (rotate > 0 && rotate < 4) {
  56392. + rotate = (4 - rotate) * 90;
  56393. + pr_warn("argument 'rotate' should be an angle. Values 1-3 is deprecated. Setting it to %d.\n",
  56394. + rotate);
  56395. + }
  56396. + if (rotate != 0 && rotate != 90 && rotate != 180 && rotate != 270) {
  56397. + pr_warn("argument 'rotate' illegal value: %d. Setting it to 0.\n",
  56398. + rotate);
  56399. + rotate = 0;
  56400. + }
  56401. +
  56402. + /* name=list lists all supported displays */
  56403. + if (strncmp(name, "list", 32) == 0) {
  56404. + pr_info(DRVNAME": Supported displays:\n");
  56405. +
  56406. + for (i = 0; i < ARRAY_SIZE(displays); i++)
  56407. + pr_info(DRVNAME": %s\n", displays[i].name);
  56408. + return -ECANCELED;
  56409. + }
  56410. +
  56411. + if (custom) {
  56412. + i = ARRAY_SIZE(displays) - 1;
  56413. + displays[i].name = name;
  56414. + if (speed == 0) {
  56415. + displays[i].pdev->name = name;
  56416. + displays[i].spi = NULL;
  56417. + } else {
  56418. + strncpy(displays[i].spi->modalias, name, SPI_NAME_SIZE);
  56419. + displays[i].pdev = NULL;
  56420. + }
  56421. + }
  56422. +
  56423. + for (i = 0; i < ARRAY_SIZE(displays); i++) {
  56424. + if (strncmp(name, displays[i].name, 32) == 0) {
  56425. + if (displays[i].spi) {
  56426. + spi = displays[i].spi;
  56427. + spi->chip_select = cs;
  56428. + spi->bus_num = busnum;
  56429. + if (speed)
  56430. + spi->max_speed_hz = speed;
  56431. + if (mode != -1)
  56432. + spi->mode = mode;
  56433. + pdata = (void *)spi->platform_data;
  56434. + } else if (displays[i].pdev) {
  56435. + p_device = displays[i].pdev;
  56436. + pdata = p_device->dev.platform_data;
  56437. + } else {
  56438. + pr_err(DRVNAME": broken displays array\n");
  56439. + return -EINVAL;
  56440. + }
  56441. +
  56442. + pdata->rotate = rotate;
  56443. + if (bgr == 0)
  56444. + pdata->bgr = false;
  56445. + else if (bgr == 1)
  56446. + pdata->bgr = true;
  56447. + if (startbyte)
  56448. + pdata->startbyte = startbyte;
  56449. + if (gamma)
  56450. + pdata->gamma = gamma;
  56451. + pdata->display.debug = debug;
  56452. + if (fps)
  56453. + pdata->fps = fps;
  56454. + if (txbuflen)
  56455. + pdata->txbuflen = txbuflen;
  56456. + if (init_num)
  56457. + pdata->display.init_sequence = init;
  56458. + if (gpio)
  56459. + pdata->gpios = gpio;
  56460. + if (custom) {
  56461. + pdata->display.width = width;
  56462. + pdata->display.height = height;
  56463. + pdata->display.buswidth = buswidth;
  56464. + pdata->display.backlight = 1;
  56465. + }
  56466. +
  56467. + if (displays[i].spi) {
  56468. + ret = fbtft_device_spi_device_register(spi);
  56469. + if (ret) {
  56470. + pr_err(DRVNAME \
  56471. + ": failed to register SPI device\n");
  56472. + return ret;
  56473. + }
  56474. + found = true;
  56475. + break;
  56476. + } else {
  56477. + ret = platform_device_register(p_device);
  56478. + if (ret < 0) {
  56479. + pr_err(DRVNAME \
  56480. + ": platform_device_register() returned %d\n",
  56481. + ret);
  56482. + return ret;
  56483. + }
  56484. + found = true;
  56485. + break;
  56486. + }
  56487. + }
  56488. + }
  56489. +
  56490. + if (!found) {
  56491. + pr_err(DRVNAME": display not supported: '%s'\n", name);
  56492. + return -EINVAL;
  56493. + }
  56494. +
  56495. + if (verbose && pdata && pdata->gpios) {
  56496. + gpio = pdata->gpios;
  56497. + pr_info(DRVNAME": GPIOS used by '%s':\n", name);
  56498. + found = false;
  56499. + while (verbose && gpio->name[0]) {
  56500. + pr_info(DRVNAME": '%s' = GPIO%d\n",
  56501. + gpio->name, gpio->gpio);
  56502. + gpio++;
  56503. + found = true;
  56504. + }
  56505. + if (!found)
  56506. + pr_info(DRVNAME": (none)\n");
  56507. + }
  56508. +
  56509. + if (spi_device && (verbose > 1))
  56510. + pr_spi_devices();
  56511. + if (p_device && (verbose > 1))
  56512. + pr_p_devices();
  56513. +
  56514. + return 0;
  56515. +}
  56516. +
  56517. +static void __exit fbtft_device_exit(void)
  56518. +{
  56519. + pr_debug(DRVNAME" - exit\n");
  56520. +
  56521. + if (spi_device) {
  56522. + device_del(&spi_device->dev);
  56523. + kfree(spi_device);
  56524. + }
  56525. +
  56526. + if (p_device)
  56527. + platform_device_unregister(p_device);
  56528. +
  56529. +}
  56530. +
  56531. +arch_initcall(fbtft_device_init);
  56532. +module_exit(fbtft_device_exit);
  56533. +
  56534. +MODULE_DESCRIPTION("Add a FBTFT device.");
  56535. +MODULE_AUTHOR("Noralf Tronnes");
  56536. +MODULE_LICENSE("GPL");
  56537. diff -Nur linux-3.18.8/drivers/staging/fbtft/fbtft.h linux-rpi/drivers/staging/fbtft/fbtft.h
  56538. --- linux-3.18.8/drivers/staging/fbtft/fbtft.h 1970-01-01 01:00:00.000000000 +0100
  56539. +++ linux-rpi/drivers/staging/fbtft/fbtft.h 2015-03-05 14:40:16.345715808 +0100
  56540. @@ -0,0 +1,447 @@
  56541. +/*
  56542. + * Copyright (C) 2013 Noralf Tronnes
  56543. + *
  56544. + * This program is free software; you can redistribute it and/or modify
  56545. + * it under the terms of the GNU General Public License as published by
  56546. + * the Free Software Foundation; either version 2 of the License, or
  56547. + * (at your option) any later version.
  56548. + *
  56549. + * This program is distributed in the hope that it will be useful,
  56550. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  56551. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  56552. + * GNU General Public License for more details.
  56553. + *
  56554. + * You should have received a copy of the GNU General Public License
  56555. + * along with this program; if not, write to the Free Software
  56556. + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  56557. + */
  56558. +
  56559. +#ifndef __LINUX_FBTFT_H
  56560. +#define __LINUX_FBTFT_H
  56561. +
  56562. +#include <linux/fb.h>
  56563. +#include <linux/spinlock.h>
  56564. +#include <linux/spi/spi.h>
  56565. +#include <linux/platform_device.h>
  56566. +
  56567. +
  56568. +#define FBTFT_NOP 0x00
  56569. +#define FBTFT_SWRESET 0x01
  56570. +#define FBTFT_RDDID 0x04
  56571. +#define FBTFT_RDDST 0x09
  56572. +#define FBTFT_CASET 0x2A
  56573. +#define FBTFT_RASET 0x2B
  56574. +#define FBTFT_RAMWR 0x2C
  56575. +
  56576. +#define FBTFT_ONBOARD_BACKLIGHT 2
  56577. +
  56578. +#define FBTFT_GPIO_NO_MATCH 0xFFFF
  56579. +#define FBTFT_GPIO_NAME_SIZE 32
  56580. +#define FBTFT_MAX_INIT_SEQUENCE 512
  56581. +#define FBTFT_GAMMA_MAX_VALUES_TOTAL 128
  56582. +
  56583. +#define FBTFT_OF_INIT_CMD BIT(24)
  56584. +#define FBTFT_OF_INIT_DELAY BIT(25)
  56585. +
  56586. +/**
  56587. + * struct fbtft_gpio - Structure that holds one pinname to gpio mapping
  56588. + * @name: pinname (reset, dc, etc.)
  56589. + * @gpio: GPIO number
  56590. + *
  56591. + */
  56592. +struct fbtft_gpio {
  56593. + char name[FBTFT_GPIO_NAME_SIZE];
  56594. + unsigned gpio;
  56595. +};
  56596. +
  56597. +struct fbtft_par;
  56598. +
  56599. +/**
  56600. + * struct fbtft_ops - FBTFT operations structure
  56601. + * @write: Writes to interface bus
  56602. + * @read: Reads from interface bus
  56603. + * @write_vmem: Writes video memory to display
  56604. + * @write_reg: Writes to controller register
  56605. + * @set_addr_win: Set the GRAM update window
  56606. + * @reset: Reset the LCD controller
  56607. + * @mkdirty: Marks display lines for update
  56608. + * @update_display: Updates the display
  56609. + * @init_display: Initializes the display
  56610. + * @blank: Blank the display (optional)
  56611. + * @request_gpios_match: Do pinname to gpio matching
  56612. + * @request_gpios: Request gpios from the kernel
  56613. + * @free_gpios: Free previously requested gpios
  56614. + * @verify_gpios: Verify that necessary gpios is present (optional)
  56615. + * @register_backlight: Used to register backlight device (optional)
  56616. + * @unregister_backlight: Unregister backlight device (optional)
  56617. + * @set_var: Configure LCD with values from variables like @rotate and @bgr
  56618. + * (optional)
  56619. + * @set_gamma: Set Gamma curve (optional)
  56620. + *
  56621. + * Most of these operations have default functions assigned to them in
  56622. + * fbtft_framebuffer_alloc()
  56623. + */
  56624. +struct fbtft_ops {
  56625. + int (*write)(struct fbtft_par *par, void *buf, size_t len);
  56626. + int (*read)(struct fbtft_par *par, void *buf, size_t len);
  56627. + int (*write_vmem)(struct fbtft_par *par, size_t offset, size_t len);
  56628. + void (*write_register)(struct fbtft_par *par, int len, ...);
  56629. +
  56630. + void (*set_addr_win)(struct fbtft_par *par,
  56631. + int xs, int ys, int xe, int ye);
  56632. + void (*reset)(struct fbtft_par *par);
  56633. + void (*mkdirty)(struct fb_info *info, int from, int to);
  56634. + void (*update_display)(struct fbtft_par *par,
  56635. + unsigned start_line, unsigned end_line);
  56636. + int (*init_display)(struct fbtft_par *par);
  56637. + int (*blank)(struct fbtft_par *par, bool on);
  56638. +
  56639. + unsigned long (*request_gpios_match)(struct fbtft_par *par,
  56640. + const struct fbtft_gpio *gpio);
  56641. + int (*request_gpios)(struct fbtft_par *par);
  56642. + int (*verify_gpios)(struct fbtft_par *par);
  56643. +
  56644. + void (*register_backlight)(struct fbtft_par *par);
  56645. + void (*unregister_backlight)(struct fbtft_par *par);
  56646. +
  56647. + int (*set_var)(struct fbtft_par *par);
  56648. + int (*set_gamma)(struct fbtft_par *par, unsigned long *curves);
  56649. +};
  56650. +
  56651. +/**
  56652. + * struct fbtft_display - Describes the display properties
  56653. + * @width: Width of display in pixels
  56654. + * @height: Height of display in pixels
  56655. + * @regwidth: LCD Controller Register width in bits
  56656. + * @buswidth: Display interface bus width in bits
  56657. + * @backlight: Backlight type.
  56658. + * @fbtftops: FBTFT operations provided by driver or device (platform_data)
  56659. + * @bpp: Bits per pixel
  56660. + * @fps: Frames per second
  56661. + * @txbuflen: Size of transmit buffer
  56662. + * @init_sequence: Pointer to LCD initialization array
  56663. + * @gamma: String representation of Gamma curve(s)
  56664. + * @gamma_num: Number of Gamma curves
  56665. + * @gamma_len: Number of values per Gamma curve
  56666. + * @debug: Initial debug value
  56667. + *
  56668. + * This structure is not stored by FBTFT except for init_sequence.
  56669. + */
  56670. +struct fbtft_display {
  56671. + unsigned width;
  56672. + unsigned height;
  56673. + unsigned regwidth;
  56674. + unsigned buswidth;
  56675. + unsigned backlight;
  56676. + struct fbtft_ops fbtftops;
  56677. + unsigned bpp;
  56678. + unsigned fps;
  56679. + int txbuflen;
  56680. + int *init_sequence;
  56681. + char *gamma;
  56682. + int gamma_num;
  56683. + int gamma_len;
  56684. + unsigned long debug;
  56685. +};
  56686. +
  56687. +/**
  56688. + * struct fbtft_platform_data - Passes display specific data to the driver
  56689. + * @display: Display properties
  56690. + * @gpios: Pointer to an array of piname to gpio mappings
  56691. + * @rotate: Display rotation angle
  56692. + * @bgr: LCD Controller BGR bit
  56693. + * @fps: Frames per second (this will go away, use @fps in @fbtft_display)
  56694. + * @txbuflen: Size of transmit buffer
  56695. + * @startbyte: When set, enables use of Startbyte in transfers
  56696. + * @gamma: String representation of Gamma curve(s)
  56697. + * @extra: A way to pass extra info
  56698. + */
  56699. +struct fbtft_platform_data {
  56700. + struct fbtft_display display;
  56701. + const struct fbtft_gpio *gpios;
  56702. + unsigned rotate;
  56703. + bool bgr;
  56704. + unsigned fps;
  56705. + int txbuflen;
  56706. + u8 startbyte;
  56707. + char *gamma;
  56708. + void *extra;
  56709. +};
  56710. +
  56711. +/**
  56712. + * struct fbtft_par - Main FBTFT data structure
  56713. + *
  56714. + * This structure holds all relevant data to operate the display
  56715. + *
  56716. + * See sourcefile for documentation since nested structs is not
  56717. + * supported by kernel-doc.
  56718. + *
  56719. + */
  56720. +/* @spi: Set if it is a SPI device
  56721. + * @pdev: Set if it is a platform device
  56722. + * @info: Pointer to framebuffer fb_info structure
  56723. + * @pdata: Pointer to platform data
  56724. + * @ssbuf: Not used
  56725. + * @pseudo_palette: Used by fb_set_colreg()
  56726. + * @txbuf.buf: Transmit buffer
  56727. + * @txbuf.len: Transmit buffer length
  56728. + * @buf: Small buffer used when writing init data over SPI
  56729. + * @startbyte: Used by some controllers when in SPI mode.
  56730. + * Format: 6 bit Device id + RS bit + RW bit
  56731. + * @fbtftops: FBTFT operations provided by driver or device (platform_data)
  56732. + * @dirty_lock: Protects dirty_lines_start and dirty_lines_end
  56733. + * @dirty_lines_start: Where to begin updating display
  56734. + * @dirty_lines_end: Where to end updating display
  56735. + * @gpio.reset: GPIO used to reset display
  56736. + * @gpio.dc: Data/Command signal, also known as RS
  56737. + * @gpio.rd: Read latching signal
  56738. + * @gpio.wr: Write latching signal
  56739. + * @gpio.latch: Bus latch signal, eg. 16->8 bit bus latch
  56740. + * @gpio.cs: LCD Chip Select with parallel interface bus
  56741. + * @gpio.db[16]: Parallel databus
  56742. + * @gpio.led[16]: Led control signals
  56743. + * @gpio.aux[16]: Auxillary signals, not used by core
  56744. + * @init_sequence: Pointer to LCD initialization array
  56745. + * @gamma.lock: Mutex for Gamma curve locking
  56746. + * @gamma.curves: Pointer to Gamma curve array
  56747. + * @gamma.num_values: Number of values per Gamma curve
  56748. + * @gamma.num_curves: Number of Gamma curves
  56749. + * @debug: Pointer to debug value
  56750. + * @current_debug:
  56751. + * @first_update_done: Used to only time the first display update
  56752. + * @update_time: Used to calculate 'fps' in debug output
  56753. + * @bgr: BGR mode/\n
  56754. + * @extra: Extra info needed by driver
  56755. + */
  56756. +struct fbtft_par {
  56757. + struct spi_device *spi;
  56758. + struct platform_device *pdev;
  56759. + struct fb_info *info;
  56760. + struct fbtft_platform_data *pdata;
  56761. + u16 *ssbuf;
  56762. + u32 pseudo_palette[16];
  56763. + struct {
  56764. + void *buf;
  56765. + dma_addr_t dma;
  56766. + size_t len;
  56767. + } txbuf;
  56768. + u8 *buf;
  56769. + u8 startbyte;
  56770. + struct fbtft_ops fbtftops;
  56771. + spinlock_t dirty_lock;
  56772. + unsigned dirty_lines_start;
  56773. + unsigned dirty_lines_end;
  56774. + struct {
  56775. + int reset;
  56776. + int dc;
  56777. + int rd;
  56778. + int wr;
  56779. + int latch;
  56780. + int cs;
  56781. + int db[16];
  56782. + int led[16];
  56783. + int aux[16];
  56784. + } gpio;
  56785. + int *init_sequence;
  56786. + struct {
  56787. + struct mutex lock;
  56788. + unsigned long *curves;
  56789. + int num_values;
  56790. + int num_curves;
  56791. + } gamma;
  56792. + unsigned long debug;
  56793. + bool first_update_done;
  56794. + struct timespec update_time;
  56795. + bool bgr;
  56796. + void *extra;
  56797. +};
  56798. +
  56799. +#define NUMARGS(...) (sizeof((int[]){__VA_ARGS__})/sizeof(int))
  56800. +
  56801. +#define write_reg(par, ...) \
  56802. +do { \
  56803. + par->fbtftops.write_register(par, NUMARGS(__VA_ARGS__), __VA_ARGS__); \
  56804. +} while (0)
  56805. +
  56806. +/* fbtft-core.c */
  56807. +extern void fbtft_dbg_hex(const struct device *dev,
  56808. + int groupsize, void *buf, size_t len, const char *fmt, ...);
  56809. +extern struct fb_info *fbtft_framebuffer_alloc(struct fbtft_display *display,
  56810. + struct device *dev);
  56811. +extern void fbtft_framebuffer_release(struct fb_info *info);
  56812. +extern int fbtft_register_framebuffer(struct fb_info *fb_info);
  56813. +extern int fbtft_unregister_framebuffer(struct fb_info *fb_info);
  56814. +extern void fbtft_register_backlight(struct fbtft_par *par);
  56815. +extern void fbtft_unregister_backlight(struct fbtft_par *par);
  56816. +extern int fbtft_init_display(struct fbtft_par *par);
  56817. +extern int fbtft_probe_common(struct fbtft_display *display,
  56818. + struct spi_device *sdev, struct platform_device *pdev);
  56819. +extern int fbtft_remove_common(struct device *dev, struct fb_info *info);
  56820. +
  56821. +/* fbtft-io.c */
  56822. +extern int fbtft_write_spi(struct fbtft_par *par, void *buf, size_t len);
  56823. +extern int fbtft_write_spi_emulate_9(struct fbtft_par *par,
  56824. + void *buf, size_t len);
  56825. +extern int fbtft_read_spi(struct fbtft_par *par, void *buf, size_t len);
  56826. +extern int fbtft_write_gpio8_wr(struct fbtft_par *par, void *buf, size_t len);
  56827. +extern int fbtft_write_gpio16_wr(struct fbtft_par *par, void *buf, size_t len);
  56828. +extern int fbtft_write_gpio16_wr_latched(struct fbtft_par *par,
  56829. + void *buf, size_t len);
  56830. +
  56831. +/* fbtft-bus.c */
  56832. +extern int fbtft_write_vmem8_bus8(struct fbtft_par *par, size_t offset, size_t len);
  56833. +extern int fbtft_write_vmem16_bus16(struct fbtft_par *par, size_t offset, size_t len);
  56834. +extern int fbtft_write_vmem16_bus8(struct fbtft_par *par, size_t offset, size_t len);
  56835. +extern int fbtft_write_vmem16_bus9(struct fbtft_par *par, size_t offset, size_t len);
  56836. +extern void fbtft_write_reg8_bus8(struct fbtft_par *par, int len, ...);
  56837. +extern void fbtft_write_reg8_bus9(struct fbtft_par *par, int len, ...);
  56838. +extern void fbtft_write_reg16_bus8(struct fbtft_par *par, int len, ...);
  56839. +extern void fbtft_write_reg16_bus16(struct fbtft_par *par, int len, ...);
  56840. +
  56841. +
  56842. +#define FBTFT_REGISTER_DRIVER(_name, _compatible, _display) \
  56843. + \
  56844. +static int fbtft_driver_probe_spi(struct spi_device *spi) \
  56845. +{ \
  56846. + return fbtft_probe_common(_display, spi, NULL); \
  56847. +} \
  56848. + \
  56849. +static int fbtft_driver_remove_spi(struct spi_device *spi) \
  56850. +{ \
  56851. + struct fb_info *info = spi_get_drvdata(spi); \
  56852. + \
  56853. + return fbtft_remove_common(&spi->dev, info); \
  56854. +} \
  56855. + \
  56856. +static int fbtft_driver_probe_pdev(struct platform_device *pdev) \
  56857. +{ \
  56858. + return fbtft_probe_common(_display, NULL, pdev); \
  56859. +} \
  56860. + \
  56861. +static int fbtft_driver_remove_pdev(struct platform_device *pdev) \
  56862. +{ \
  56863. + struct fb_info *info = platform_get_drvdata(pdev); \
  56864. + \
  56865. + return fbtft_remove_common(&pdev->dev, info); \
  56866. +} \
  56867. + \
  56868. +static const struct of_device_id dt_ids[] = { \
  56869. + { .compatible = _compatible }, \
  56870. + {}, \
  56871. +}; \
  56872. + \
  56873. +MODULE_DEVICE_TABLE(of, dt_ids); \
  56874. + \
  56875. + \
  56876. +static struct spi_driver fbtft_driver_spi_driver = { \
  56877. + .driver = { \
  56878. + .name = _name, \
  56879. + .owner = THIS_MODULE, \
  56880. + .of_match_table = of_match_ptr(dt_ids), \
  56881. + }, \
  56882. + .probe = fbtft_driver_probe_spi, \
  56883. + .remove = fbtft_driver_remove_spi, \
  56884. +}; \
  56885. + \
  56886. +static struct platform_driver fbtft_driver_platform_driver = { \
  56887. + .driver = { \
  56888. + .name = _name, \
  56889. + .owner = THIS_MODULE, \
  56890. + .of_match_table = of_match_ptr(dt_ids), \
  56891. + }, \
  56892. + .probe = fbtft_driver_probe_pdev, \
  56893. + .remove = fbtft_driver_remove_pdev, \
  56894. +}; \
  56895. + \
  56896. +static int __init fbtft_driver_module_init(void) \
  56897. +{ \
  56898. + int ret; \
  56899. + \
  56900. + ret = spi_register_driver(&fbtft_driver_spi_driver); \
  56901. + if (ret < 0) \
  56902. + return ret; \
  56903. + return platform_driver_register(&fbtft_driver_platform_driver); \
  56904. +} \
  56905. + \
  56906. +static void __exit fbtft_driver_module_exit(void) \
  56907. +{ \
  56908. + spi_unregister_driver(&fbtft_driver_spi_driver); \
  56909. + platform_driver_unregister(&fbtft_driver_platform_driver); \
  56910. +} \
  56911. + \
  56912. +module_init(fbtft_driver_module_init); \
  56913. +module_exit(fbtft_driver_module_exit);
  56914. +
  56915. +
  56916. +/* Debug macros */
  56917. +
  56918. +/* shorthand debug levels */
  56919. +#define DEBUG_LEVEL_1 DEBUG_REQUEST_GPIOS
  56920. +#define DEBUG_LEVEL_2 (DEBUG_LEVEL_1 | DEBUG_DRIVER_INIT_FUNCTIONS | DEBUG_TIME_FIRST_UPDATE)
  56921. +#define DEBUG_LEVEL_3 (DEBUG_LEVEL_2 | DEBUG_RESET | DEBUG_INIT_DISPLAY | DEBUG_BLANK | DEBUG_REQUEST_GPIOS | DEBUG_FREE_GPIOS | DEBUG_VERIFY_GPIOS | DEBUG_BACKLIGHT | DEBUG_SYSFS)
  56922. +#define DEBUG_LEVEL_4 (DEBUG_LEVEL_2 | DEBUG_FB_READ | DEBUG_FB_WRITE | DEBUG_FB_FILLRECT | DEBUG_FB_COPYAREA | DEBUG_FB_IMAGEBLIT | DEBUG_FB_BLANK)
  56923. +#define DEBUG_LEVEL_5 (DEBUG_LEVEL_3 | DEBUG_UPDATE_DISPLAY)
  56924. +#define DEBUG_LEVEL_6 (DEBUG_LEVEL_4 | DEBUG_LEVEL_5)
  56925. +#define DEBUG_LEVEL_7 0xFFFFFFFF
  56926. +
  56927. +#define DEBUG_DRIVER_INIT_FUNCTIONS (1<<3)
  56928. +#define DEBUG_TIME_FIRST_UPDATE (1<<4)
  56929. +#define DEBUG_TIME_EACH_UPDATE (1<<5)
  56930. +#define DEBUG_DEFERRED_IO (1<<6)
  56931. +#define DEBUG_FBTFT_INIT_FUNCTIONS (1<<7)
  56932. +
  56933. +/* fbops */
  56934. +#define DEBUG_FB_READ (1<<8)
  56935. +#define DEBUG_FB_WRITE (1<<9)
  56936. +#define DEBUG_FB_FILLRECT (1<<10)
  56937. +#define DEBUG_FB_COPYAREA (1<<11)
  56938. +#define DEBUG_FB_IMAGEBLIT (1<<12)
  56939. +#define DEBUG_FB_SETCOLREG (1<<13)
  56940. +#define DEBUG_FB_BLANK (1<<14)
  56941. +
  56942. +#define DEBUG_SYSFS (1<<16)
  56943. +
  56944. +/* fbtftops */
  56945. +#define DEBUG_BACKLIGHT (1<<17)
  56946. +#define DEBUG_READ (1<<18)
  56947. +#define DEBUG_WRITE (1<<19)
  56948. +#define DEBUG_WRITE_VMEM (1<<20)
  56949. +#define DEBUG_WRITE_REGISTER (1<<21)
  56950. +#define DEBUG_SET_ADDR_WIN (1<<22)
  56951. +#define DEBUG_RESET (1<<23)
  56952. +#define DEBUG_MKDIRTY (1<<24)
  56953. +#define DEBUG_UPDATE_DISPLAY (1<<25)
  56954. +#define DEBUG_INIT_DISPLAY (1<<26)
  56955. +#define DEBUG_BLANK (1<<27)
  56956. +#define DEBUG_REQUEST_GPIOS (1<<28)
  56957. +#define DEBUG_FREE_GPIOS (1<<29)
  56958. +#define DEBUG_REQUEST_GPIOS_MATCH (1<<30)
  56959. +#define DEBUG_VERIFY_GPIOS (1<<31)
  56960. +
  56961. +
  56962. +#define fbtft_init_dbg(dev, format, arg...) \
  56963. +do { \
  56964. + if (unlikely((dev)->platform_data && \
  56965. + (((struct fbtft_platform_data *)(dev)->platform_data)->display.debug & DEBUG_DRIVER_INIT_FUNCTIONS))) \
  56966. + dev_info(dev, format, ##arg); \
  56967. +} while (0)
  56968. +
  56969. +#define fbtft_par_dbg(level, par, format, arg...) \
  56970. +do { \
  56971. + if (unlikely(par->debug & level)) \
  56972. + dev_info(par->info->device, format, ##arg); \
  56973. +} while (0)
  56974. +
  56975. +#define fbtft_dev_dbg(level, par, dev, format, arg...) \
  56976. +do { \
  56977. + if (unlikely(par->debug & level)) \
  56978. + dev_info(dev, format, ##arg); \
  56979. +} while (0)
  56980. +
  56981. +#define fbtft_par_dbg_hex(level, par, dev, type, buf, num, format, arg...) \
  56982. +do { \
  56983. + if (unlikely(par->debug & level)) \
  56984. + fbtft_dbg_hex(dev, sizeof(type), buf, num * sizeof(type), format, ##arg); \
  56985. +} while (0)
  56986. +
  56987. +#endif /* __LINUX_FBTFT_H */
  56988. diff -Nur linux-3.18.8/drivers/staging/fbtft/fbtft-io.c linux-rpi/drivers/staging/fbtft/fbtft-io.c
  56989. --- linux-3.18.8/drivers/staging/fbtft/fbtft-io.c 1970-01-01 01:00:00.000000000 +0100
  56990. +++ linux-rpi/drivers/staging/fbtft/fbtft-io.c 2015-03-05 14:40:16.345715808 +0100
  56991. @@ -0,0 +1,239 @@
  56992. +#include <linux/export.h>
  56993. +#include <linux/errno.h>
  56994. +#include <linux/gpio.h>
  56995. +#include <linux/spi/spi.h>
  56996. +#include "fbtft.h"
  56997. +
  56998. +int fbtft_write_spi(struct fbtft_par *par, void *buf, size_t len)
  56999. +{
  57000. + struct spi_transfer t = {
  57001. + .tx_buf = buf,
  57002. + .len = len,
  57003. + };
  57004. + struct spi_message m;
  57005. +
  57006. + fbtft_par_dbg_hex(DEBUG_WRITE, par, par->info->device, u8, buf, len,
  57007. + "%s(len=%d): ", __func__, len);
  57008. +
  57009. + if (!par->spi) {
  57010. + dev_err(par->info->device,
  57011. + "%s: par->spi is unexpectedly NULL\n", __func__);
  57012. + return -1;
  57013. + }
  57014. +
  57015. + spi_message_init(&m);
  57016. + if (par->txbuf.dma && buf == par->txbuf.buf) {
  57017. + t.tx_dma = par->txbuf.dma;
  57018. + m.is_dma_mapped = 1;
  57019. + }
  57020. + spi_message_add_tail(&t, &m);
  57021. + return spi_sync(par->spi, &m);
  57022. +}
  57023. +EXPORT_SYMBOL(fbtft_write_spi);
  57024. +
  57025. +/**
  57026. + * fbtft_write_spi_emulate_9() - write SPI emulating 9-bit
  57027. + * @par: Driver data
  57028. + * @buf: Buffer to write
  57029. + * @len: Length of buffer (must be divisible by 8)
  57030. + *
  57031. + * When 9-bit SPI is not available, this function can be used to emulate that.
  57032. + * par->extra must hold a transformation buffer used for transfer.
  57033. + */
  57034. +int fbtft_write_spi_emulate_9(struct fbtft_par *par, void *buf, size_t len)
  57035. +{
  57036. + u16 *src = buf;
  57037. + u8 *dst = par->extra;
  57038. + size_t size = len / 2;
  57039. + size_t added = 0;
  57040. + int bits, i, j;
  57041. + u64 val, dc, tmp;
  57042. +
  57043. + fbtft_par_dbg_hex(DEBUG_WRITE, par, par->info->device, u8, buf, len,
  57044. + "%s(len=%d): ", __func__, len);
  57045. +
  57046. + if (!par->extra) {
  57047. + dev_err(par->info->device, "%s: error: par->extra is NULL\n",
  57048. + __func__);
  57049. + return -EINVAL;
  57050. + }
  57051. + if ((len % 8) != 0) {
  57052. + dev_err(par->info->device,
  57053. + "%s: error: len=%d must be divisible by 8\n",
  57054. + __func__, len);
  57055. + return -EINVAL;
  57056. + }
  57057. +
  57058. + for (i = 0; i < size; i += 8) {
  57059. + tmp = 0;
  57060. + bits = 63;
  57061. + for (j = 0; j < 7; j++) {
  57062. + dc = (*src & 0x0100) ? 1 : 0;
  57063. + val = *src & 0x00FF;
  57064. + tmp |= dc << bits;
  57065. + bits -= 8;
  57066. + tmp |= val << bits--;
  57067. + src++;
  57068. + }
  57069. + tmp |= ((*src & 0x0100) ? 1 : 0);
  57070. + *(u64 *)dst = cpu_to_be64(tmp);
  57071. + dst += 8;
  57072. + *dst++ = (u8)(*src++ & 0x00FF);
  57073. + added++;
  57074. + }
  57075. +
  57076. + return spi_write(par->spi, par->extra, size + added);
  57077. +}
  57078. +EXPORT_SYMBOL(fbtft_write_spi_emulate_9);
  57079. +
  57080. +int fbtft_read_spi(struct fbtft_par *par, void *buf, size_t len)
  57081. +{
  57082. + int ret;
  57083. + u8 txbuf[32] = { 0, };
  57084. + struct spi_transfer t = {
  57085. + .speed_hz = 2000000,
  57086. + .rx_buf = buf,
  57087. + .len = len,
  57088. + };
  57089. + struct spi_message m;
  57090. +
  57091. + if (!par->spi) {
  57092. + dev_err(par->info->device,
  57093. + "%s: par->spi is unexpectedly NULL\n", __func__);
  57094. + return -ENODEV;
  57095. + }
  57096. +
  57097. + if (par->startbyte) {
  57098. + if (len > 32) {
  57099. + dev_err(par->info->device,
  57100. + "%s: len=%d can't be larger than 32 when using 'startbyte'\n",
  57101. + __func__, len);
  57102. + return -EINVAL;
  57103. + }
  57104. + txbuf[0] = par->startbyte | 0x3;
  57105. + t.tx_buf = txbuf;
  57106. + fbtft_par_dbg_hex(DEBUG_READ, par, par->info->device, u8,
  57107. + txbuf, len, "%s(len=%d) txbuf => ", __func__, len);
  57108. + }
  57109. +
  57110. + spi_message_init(&m);
  57111. + spi_message_add_tail(&t, &m);
  57112. + ret = spi_sync(par->spi, &m);
  57113. + fbtft_par_dbg_hex(DEBUG_READ, par, par->info->device, u8, buf, len,
  57114. + "%s(len=%d) buf <= ", __func__, len);
  57115. +
  57116. + return ret;
  57117. +}
  57118. +EXPORT_SYMBOL(fbtft_read_spi);
  57119. +
  57120. +/*
  57121. + * Optimized use of gpiolib is twice as fast as no optimization
  57122. + * only one driver can use the optimized version at a time
  57123. + */
  57124. +int fbtft_write_gpio8_wr(struct fbtft_par *par, void *buf, size_t len)
  57125. +{
  57126. + u8 data;
  57127. + int i;
  57128. +#ifndef DO_NOT_OPTIMIZE_FBTFT_WRITE_GPIO
  57129. + static u8 prev_data;
  57130. +#endif
  57131. +
  57132. + fbtft_par_dbg_hex(DEBUG_WRITE, par, par->info->device, u8, buf, len,
  57133. + "%s(len=%d): ", __func__, len);
  57134. +
  57135. + while (len--) {
  57136. + data = *(u8 *) buf;
  57137. +
  57138. + /* Start writing by pulling down /WR */
  57139. + gpio_set_value(par->gpio.wr, 0);
  57140. +
  57141. + /* Set data */
  57142. +#ifndef DO_NOT_OPTIMIZE_FBTFT_WRITE_GPIO
  57143. + if (data == prev_data) {
  57144. + gpio_set_value(par->gpio.wr, 0); /* used as delay */
  57145. + } else {
  57146. + for (i = 0; i < 8; i++) {
  57147. + if ((data & 1) != (prev_data & 1))
  57148. + gpio_set_value(par->gpio.db[i],
  57149. + (data & 1));
  57150. + data >>= 1;
  57151. + prev_data >>= 1;
  57152. + }
  57153. + }
  57154. +#else
  57155. + for (i = 0; i < 8; i++) {
  57156. + gpio_set_value(par->gpio.db[i], (data & 1));
  57157. + data >>= 1;
  57158. + }
  57159. +#endif
  57160. +
  57161. + /* Pullup /WR */
  57162. + gpio_set_value(par->gpio.wr, 1);
  57163. +
  57164. +#ifndef DO_NOT_OPTIMIZE_FBTFT_WRITE_GPIO
  57165. + prev_data = *(u8 *) buf;
  57166. +#endif
  57167. + buf++;
  57168. + }
  57169. +
  57170. + return 0;
  57171. +}
  57172. +EXPORT_SYMBOL(fbtft_write_gpio8_wr);
  57173. +
  57174. +int fbtft_write_gpio16_wr(struct fbtft_par *par, void *buf, size_t len)
  57175. +{
  57176. + u16 data;
  57177. + int i;
  57178. +#ifndef DO_NOT_OPTIMIZE_FBTFT_WRITE_GPIO
  57179. + static u16 prev_data;
  57180. +#endif
  57181. +
  57182. + fbtft_par_dbg_hex(DEBUG_WRITE, par, par->info->device, u8, buf, len,
  57183. + "%s(len=%d): ", __func__, len);
  57184. +
  57185. + while (len) {
  57186. + data = *(u16 *) buf;
  57187. +
  57188. + /* Start writing by pulling down /WR */
  57189. + gpio_set_value(par->gpio.wr, 0);
  57190. +
  57191. + /* Set data */
  57192. +#ifndef DO_NOT_OPTIMIZE_FBTFT_WRITE_GPIO
  57193. + if (data == prev_data) {
  57194. + gpio_set_value(par->gpio.wr, 0); /* used as delay */
  57195. + } else {
  57196. + for (i = 0; i < 16; i++) {
  57197. + if ((data & 1) != (prev_data & 1))
  57198. + gpio_set_value(par->gpio.db[i],
  57199. + (data & 1));
  57200. + data >>= 1;
  57201. + prev_data >>= 1;
  57202. + }
  57203. + }
  57204. +#else
  57205. + for (i = 0; i < 16; i++) {
  57206. + gpio_set_value(par->gpio.db[i], (data & 1));
  57207. + data >>= 1;
  57208. + }
  57209. +#endif
  57210. +
  57211. + /* Pullup /WR */
  57212. + gpio_set_value(par->gpio.wr, 1);
  57213. +
  57214. +#ifndef DO_NOT_OPTIMIZE_FBTFT_WRITE_GPIO
  57215. + prev_data = *(u16 *) buf;
  57216. +#endif
  57217. + buf += 2;
  57218. + len -= 2;
  57219. + }
  57220. +
  57221. + return 0;
  57222. +}
  57223. +EXPORT_SYMBOL(fbtft_write_gpio16_wr);
  57224. +
  57225. +int fbtft_write_gpio16_wr_latched(struct fbtft_par *par, void *buf, size_t len)
  57226. +{
  57227. + dev_err(par->info->device, "%s: function not implemented\n", __func__);
  57228. + return -1;
  57229. +}
  57230. +EXPORT_SYMBOL(fbtft_write_gpio16_wr_latched);
  57231. diff -Nur linux-3.18.8/drivers/staging/fbtft/fbtft-sysfs.c linux-rpi/drivers/staging/fbtft/fbtft-sysfs.c
  57232. --- linux-3.18.8/drivers/staging/fbtft/fbtft-sysfs.c 1970-01-01 01:00:00.000000000 +0100
  57233. +++ linux-rpi/drivers/staging/fbtft/fbtft-sysfs.c 2015-03-05 14:40:16.345715808 +0100
  57234. @@ -0,0 +1,222 @@
  57235. +#include "fbtft.h"
  57236. +
  57237. +
  57238. +static int get_next_ulong(char **str_p, unsigned long *val, char *sep, int base)
  57239. +{
  57240. + char *p_val;
  57241. + int ret;
  57242. +
  57243. + if (!str_p || !(*str_p))
  57244. + return -EINVAL;
  57245. +
  57246. + p_val = strsep(str_p, sep);
  57247. +
  57248. + if (!p_val)
  57249. + return -EINVAL;
  57250. +
  57251. + ret = kstrtoul(p_val, base, val);
  57252. + if (ret)
  57253. + return -EINVAL;
  57254. +
  57255. + return 0;
  57256. +}
  57257. +
  57258. +int fbtft_gamma_parse_str(struct fbtft_par *par, unsigned long *curves,
  57259. + const char *str, int size)
  57260. +{
  57261. + char *str_p, *curve_p = NULL;
  57262. + char *tmp;
  57263. + unsigned long val = 0;
  57264. + int ret = 0;
  57265. + int curve_counter, value_counter;
  57266. +
  57267. + fbtft_par_dbg(DEBUG_SYSFS, par, "%s() str=\n", __func__);
  57268. +
  57269. + if (!str || !curves)
  57270. + return -EINVAL;
  57271. +
  57272. + fbtft_par_dbg(DEBUG_SYSFS, par, "%s\n", str);
  57273. +
  57274. + tmp = kmalloc(size+1, GFP_KERNEL);
  57275. + if (!tmp)
  57276. + return -ENOMEM;
  57277. + memcpy(tmp, str, size+1);
  57278. +
  57279. + /* replace optional separators */
  57280. + str_p = tmp;
  57281. + while (*str_p) {
  57282. + if (*str_p == ',')
  57283. + *str_p = ' ';
  57284. + if (*str_p == ';')
  57285. + *str_p = '\n';
  57286. + str_p++;
  57287. + }
  57288. +
  57289. + str_p = strim(tmp);
  57290. +
  57291. + curve_counter = 0;
  57292. + while (str_p) {
  57293. + if (curve_counter == par->gamma.num_curves) {
  57294. + dev_err(par->info->device, "Gamma: Too many curves\n");
  57295. + ret = -EINVAL;
  57296. + goto out;
  57297. + }
  57298. + curve_p = strsep(&str_p, "\n");
  57299. + value_counter = 0;
  57300. + while (curve_p) {
  57301. + if (value_counter == par->gamma.num_values) {
  57302. + dev_err(par->info->device,
  57303. + "Gamma: Too many values\n");
  57304. + ret = -EINVAL;
  57305. + goto out;
  57306. + }
  57307. + ret = get_next_ulong(&curve_p, &val, " ", 16);
  57308. + if (ret)
  57309. + goto out;
  57310. + curves[curve_counter * par->gamma.num_values + value_counter] = val;
  57311. + value_counter++;
  57312. + }
  57313. + if (value_counter != par->gamma.num_values) {
  57314. + dev_err(par->info->device, "Gamma: Too few values\n");
  57315. + ret = -EINVAL;
  57316. + goto out;
  57317. + }
  57318. + curve_counter++;
  57319. + }
  57320. + if (curve_counter != par->gamma.num_curves) {
  57321. + dev_err(par->info->device, "Gamma: Too few curves\n");
  57322. + ret = -EINVAL;
  57323. + goto out;
  57324. + }
  57325. +
  57326. +out:
  57327. + kfree(tmp);
  57328. + return ret;
  57329. +}
  57330. +
  57331. +static ssize_t
  57332. +sprintf_gamma(struct fbtft_par *par, unsigned long *curves, char *buf)
  57333. +{
  57334. + ssize_t len = 0;
  57335. + unsigned int i, j;
  57336. +
  57337. + mutex_lock(&par->gamma.lock);
  57338. + for (i = 0; i < par->gamma.num_curves; i++) {
  57339. + for (j = 0; j < par->gamma.num_values; j++)
  57340. + len += scnprintf(&buf[len], PAGE_SIZE,
  57341. + "%04lx ", curves[i*par->gamma.num_values + j]);
  57342. + buf[len-1] = '\n';
  57343. + }
  57344. + mutex_unlock(&par->gamma.lock);
  57345. +
  57346. + return len;
  57347. +}
  57348. +
  57349. +static ssize_t store_gamma_curve(struct device *device,
  57350. + struct device_attribute *attr,
  57351. + const char *buf, size_t count)
  57352. +{
  57353. + struct fb_info *fb_info = dev_get_drvdata(device);
  57354. + struct fbtft_par *par = fb_info->par;
  57355. + unsigned long tmp_curves[FBTFT_GAMMA_MAX_VALUES_TOTAL];
  57356. + int ret;
  57357. +
  57358. + ret = fbtft_gamma_parse_str(par, tmp_curves, buf, count);
  57359. + if (ret)
  57360. + return ret;
  57361. +
  57362. + ret = par->fbtftops.set_gamma(par, tmp_curves);
  57363. + if (ret)
  57364. + return ret;
  57365. +
  57366. + mutex_lock(&par->gamma.lock);
  57367. + memcpy(par->gamma.curves, tmp_curves,
  57368. + par->gamma.num_curves * par->gamma.num_values * sizeof(tmp_curves[0]));
  57369. + mutex_unlock(&par->gamma.lock);
  57370. +
  57371. + return count;
  57372. +}
  57373. +
  57374. +static ssize_t show_gamma_curve(struct device *device,
  57375. + struct device_attribute *attr, char *buf)
  57376. +{
  57377. + struct fb_info *fb_info = dev_get_drvdata(device);
  57378. + struct fbtft_par *par = fb_info->par;
  57379. +
  57380. + return sprintf_gamma(par, par->gamma.curves, buf);
  57381. +}
  57382. +
  57383. +static struct device_attribute gamma_device_attrs[] = {
  57384. + __ATTR(gamma, 0660, show_gamma_curve, store_gamma_curve),
  57385. +};
  57386. +
  57387. +
  57388. +void fbtft_expand_debug_value(unsigned long *debug)
  57389. +{
  57390. + switch (*debug & 0b111) {
  57391. + case 1:
  57392. + *debug |= DEBUG_LEVEL_1;
  57393. + break;
  57394. + case 2:
  57395. + *debug |= DEBUG_LEVEL_2;
  57396. + break;
  57397. + case 3:
  57398. + *debug |= DEBUG_LEVEL_3;
  57399. + break;
  57400. + case 4:
  57401. + *debug |= DEBUG_LEVEL_4;
  57402. + break;
  57403. + case 5:
  57404. + *debug |= DEBUG_LEVEL_5;
  57405. + break;
  57406. + case 6:
  57407. + *debug |= DEBUG_LEVEL_6;
  57408. + break;
  57409. + case 7:
  57410. + *debug = 0xFFFFFFFF;
  57411. + break;
  57412. + }
  57413. +}
  57414. +
  57415. +static ssize_t store_debug(struct device *device,
  57416. + struct device_attribute *attr,
  57417. + const char *buf, size_t count)
  57418. +{
  57419. + struct fb_info *fb_info = dev_get_drvdata(device);
  57420. + struct fbtft_par *par = fb_info->par;
  57421. + int ret;
  57422. +
  57423. + ret = kstrtoul(buf, 10, &par->debug);
  57424. + if (ret)
  57425. + return ret;
  57426. + fbtft_expand_debug_value(&par->debug);
  57427. +
  57428. + return count;
  57429. +}
  57430. +
  57431. +static ssize_t show_debug(struct device *device,
  57432. + struct device_attribute *attr, char *buf)
  57433. +{
  57434. + struct fb_info *fb_info = dev_get_drvdata(device);
  57435. + struct fbtft_par *par = fb_info->par;
  57436. +
  57437. + return snprintf(buf, PAGE_SIZE, "%lu\n", par->debug);
  57438. +}
  57439. +
  57440. +static struct device_attribute debug_device_attr = \
  57441. + __ATTR(debug, 0660, show_debug, store_debug);
  57442. +
  57443. +
  57444. +void fbtft_sysfs_init(struct fbtft_par *par)
  57445. +{
  57446. + device_create_file(par->info->dev, &debug_device_attr);
  57447. + if (par->gamma.curves && par->fbtftops.set_gamma)
  57448. + device_create_file(par->info->dev, &gamma_device_attrs[0]);
  57449. +}
  57450. +
  57451. +void fbtft_sysfs_exit(struct fbtft_par *par)
  57452. +{
  57453. + device_remove_file(par->info->dev, &debug_device_attr);
  57454. + if (par->gamma.curves && par->fbtftops.set_gamma)
  57455. + device_remove_file(par->info->dev, &gamma_device_attrs[0]);
  57456. +}
  57457. diff -Nur linux-3.18.8/drivers/staging/fbtft/fb_tinylcd.c linux-rpi/drivers/staging/fbtft/fb_tinylcd.c
  57458. --- linux-3.18.8/drivers/staging/fbtft/fb_tinylcd.c 1970-01-01 01:00:00.000000000 +0100
  57459. +++ linux-rpi/drivers/staging/fbtft/fb_tinylcd.c 2015-03-05 14:40:16.345715808 +0100
  57460. @@ -0,0 +1,124 @@
  57461. +/*
  57462. + * Custom FB driver for tinylcd.com display
  57463. + *
  57464. + * Copyright (C) 2013 Noralf Tronnes
  57465. + *
  57466. + * This program is free software; you can redistribute it and/or modify
  57467. + * it under the terms of the GNU General Public License as published by
  57468. + * the Free Software Foundation; either version 2 of the License, or
  57469. + * (at your option) any later version.
  57470. + *
  57471. + * This program is distributed in the hope that it will be useful,
  57472. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  57473. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  57474. + * GNU General Public License for more details.
  57475. + *
  57476. + * You should have received a copy of the GNU General Public License
  57477. + * along with this program; if not, write to the Free Software
  57478. + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  57479. + */
  57480. +
  57481. +#include <linux/module.h>
  57482. +#include <linux/kernel.h>
  57483. +#include <linux/init.h>
  57484. +#include <linux/delay.h>
  57485. +
  57486. +#include "fbtft.h"
  57487. +
  57488. +#define DRVNAME "fb_tinylcd"
  57489. +#define WIDTH 320
  57490. +#define HEIGHT 480
  57491. +
  57492. +
  57493. +static int init_display(struct fbtft_par *par)
  57494. +{
  57495. + fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
  57496. +
  57497. + par->fbtftops.reset(par);
  57498. +
  57499. + write_reg(par, 0xB0, 0x80);
  57500. + write_reg(par, 0xC0, 0x0A, 0x0A);
  57501. + write_reg(par, 0xC1, 0x45, 0x07);
  57502. + write_reg(par, 0xC2, 0x33);
  57503. + write_reg(par, 0xC5, 0x00, 0x42, 0x80);
  57504. + write_reg(par, 0xB1, 0xD0, 0x11);
  57505. + write_reg(par, 0xB4, 0x02);
  57506. + write_reg(par, 0xB6, 0x00, 0x22, 0x3B);
  57507. + write_reg(par, 0xB7, 0x07);
  57508. + write_reg(par, 0x36, 0x58);
  57509. + write_reg(par, 0xF0, 0x36, 0xA5, 0xD3);
  57510. + write_reg(par, 0xE5, 0x80);
  57511. + write_reg(par, 0xE5, 0x01);
  57512. + write_reg(par, 0xB3, 0x00);
  57513. + write_reg(par, 0xE5, 0x00);
  57514. + write_reg(par, 0xF0, 0x36, 0xA5, 0x53);
  57515. + write_reg(par, 0xE0, 0x00, 0x35, 0x33, 0x00, 0x00, 0x00,
  57516. + 0x00, 0x35, 0x33, 0x00, 0x00, 0x00);
  57517. + write_reg(par, 0x3A, 0x55);
  57518. + write_reg(par, 0x11);
  57519. + udelay(250);
  57520. + write_reg(par, 0x29);
  57521. +
  57522. + return 0;
  57523. +}
  57524. +
  57525. +static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
  57526. +{
  57527. + fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par,
  57528. + "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye);
  57529. +
  57530. + /* Column address */
  57531. + write_reg(par, 0x2A, xs >> 8, xs & 0xFF, xe >> 8, xe & 0xFF);
  57532. +
  57533. + /* Row adress */
  57534. + write_reg(par, 0x2B, ys >> 8, ys & 0xFF, ye >> 8, ye & 0xFF);
  57535. +
  57536. + /* Memory write */
  57537. + write_reg(par, 0x2C);
  57538. +}
  57539. +
  57540. +static int set_var(struct fbtft_par *par)
  57541. +{
  57542. + fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
  57543. +
  57544. + switch (par->info->var.rotate) {
  57545. + case 270:
  57546. + write_reg(par, 0xB6, 0x00, 0x02, 0x3B);
  57547. + write_reg(par, 0x36, 0x28);
  57548. + break;
  57549. + case 180:
  57550. + write_reg(par, 0xB6, 0x00, 0x22, 0x3B);
  57551. + write_reg(par, 0x36, 0x58);
  57552. + break;
  57553. + case 90:
  57554. + write_reg(par, 0xB6, 0x00, 0x22, 0x3B);
  57555. + write_reg(par, 0x36, 0x38);
  57556. + break;
  57557. + default:
  57558. + write_reg(par, 0xB6, 0x00, 0x22, 0x3B);
  57559. + write_reg(par, 0x36, 0x08);
  57560. + break;
  57561. + }
  57562. +
  57563. + return 0;
  57564. +}
  57565. +
  57566. +
  57567. +static struct fbtft_display display = {
  57568. + .regwidth = 8,
  57569. + .width = WIDTH,
  57570. + .height = HEIGHT,
  57571. + .fbtftops = {
  57572. + .init_display = init_display,
  57573. + .set_addr_win = set_addr_win,
  57574. + .set_var = set_var,
  57575. + },
  57576. +};
  57577. +FBTFT_REGISTER_DRIVER(DRVNAME, "neosec,tinylcd", &display);
  57578. +
  57579. +MODULE_ALIAS("spi:" DRVNAME);
  57580. +MODULE_ALIAS("spi:tinylcd");
  57581. +
  57582. +MODULE_DESCRIPTION("Custom FB driver for tinylcd.com display");
  57583. +MODULE_AUTHOR("Noralf Tronnes");
  57584. +MODULE_LICENSE("GPL");
  57585. diff -Nur linux-3.18.8/drivers/staging/fbtft/fb_tls8204.c linux-rpi/drivers/staging/fbtft/fb_tls8204.c
  57586. --- linux-3.18.8/drivers/staging/fbtft/fb_tls8204.c 1970-01-01 01:00:00.000000000 +0100
  57587. +++ linux-rpi/drivers/staging/fbtft/fb_tls8204.c 2015-03-05 14:40:16.345715808 +0100
  57588. @@ -0,0 +1,176 @@
  57589. +/*
  57590. + * FB driver for the TLS8204 LCD Controller
  57591. + *
  57592. + * The display is monochrome and the video memory is RGB565.
  57593. + * Any pixel value except 0 turns the pixel on.
  57594. + *
  57595. + * Copyright (C) 2013 Noralf Tronnes
  57596. + * Copyright (C) 2014 Michael Hope (adapted for the TLS8204)
  57597. + *
  57598. + * This program is free software; you can redistribute it and/or modify
  57599. + * it under the terms of the GNU General Public License as published by
  57600. + * the Free Software Foundation; either version 2 of the License, or
  57601. + * (at your option) any later version.
  57602. + *
  57603. + * This program is distributed in the hope that it will be useful,
  57604. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  57605. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  57606. + * GNU General Public License for more details.
  57607. + *
  57608. + * You should have received a copy of the GNU General Public License
  57609. + * along with this program; if not, write to the Free Software
  57610. + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  57611. + */
  57612. +
  57613. +#include <linux/module.h>
  57614. +#include <linux/kernel.h>
  57615. +#include <linux/init.h>
  57616. +#include <linux/gpio.h>
  57617. +#include <linux/spi/spi.h>
  57618. +#include <linux/delay.h>
  57619. +
  57620. +#include "fbtft.h"
  57621. +
  57622. +#define DRVNAME "fb_tls8204"
  57623. +#define WIDTH 84
  57624. +#define HEIGHT 48
  57625. +#define TXBUFLEN WIDTH
  57626. +#define DEFAULT_GAMMA "40" /* gamma is used to control contrast in this driver */
  57627. +
  57628. +static unsigned bs = 4;
  57629. +module_param(bs, uint, 0);
  57630. +MODULE_PARM_DESC(bs, "BS[2:0] Bias voltage level: 0-7 (default: 4)");
  57631. +
  57632. +static int init_display(struct fbtft_par *par)
  57633. +{
  57634. + fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
  57635. +
  57636. + par->fbtftops.reset(par);
  57637. +
  57638. + /* Enter extended command mode */
  57639. + write_reg(par, 0x21); /* 5:1 1
  57640. + 2:0 PD - Powerdown control: chip is active
  57641. + 1:0 V - Entry mode: horizontal addressing
  57642. + 0:1 H - Extended instruction set control: extended
  57643. + */
  57644. +
  57645. + /* H=1 Bias system */
  57646. + write_reg(par, 0x10 | (bs & 0x7)); /*
  57647. + 4:1 1
  57648. + 3:0 0
  57649. + 2:x BS2 - Bias System
  57650. + 1:x BS1
  57651. + 0:x BS0
  57652. + */
  57653. +
  57654. + /* Set the address of the first display line. */
  57655. + write_reg(par, 0x04 | (64 >> 6));
  57656. + write_reg(par, 0x40 | (64 & 0x3F));
  57657. +
  57658. + /* Enter H=0 standard command mode */
  57659. + write_reg(par, 0x20);
  57660. +
  57661. + /* H=0 Display control */
  57662. + write_reg(par, 0x08 | 4); /*
  57663. + 3:1 1
  57664. + 2:1 D - DE: 10=normal mode
  57665. + 1:0 0
  57666. + 0:0 E
  57667. + */
  57668. +
  57669. + return 0;
  57670. +}
  57671. +
  57672. +static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
  57673. +{
  57674. + fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par, "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye);
  57675. +
  57676. + /* H=0 Set X address of RAM */
  57677. + write_reg(par, 0x80); /* 7:1 1
  57678. + 6-0: X[6:0] - 0x00
  57679. + */
  57680. +
  57681. + /* H=0 Set Y address of RAM */
  57682. + write_reg(par, 0x40); /* 7:0 0
  57683. + 6:1 1
  57684. + 2-0: Y[2:0] - 0x0
  57685. + */
  57686. +}
  57687. +
  57688. +static int write_vmem(struct fbtft_par *par, size_t offset, size_t len)
  57689. +{
  57690. + u16 *vmem16 = (u16 *)par->info->screen_base;
  57691. + int x, y, i;
  57692. + int ret = 0;
  57693. +
  57694. + fbtft_par_dbg(DEBUG_WRITE_VMEM, par, "%s()\n", __func__);
  57695. +
  57696. + for (y = 0; y < HEIGHT/8; y++) {
  57697. + u8 *buf = par->txbuf.buf;
  57698. + /* The display is 102x68 but the LCD is 84x48. Set
  57699. + the write pointer at the start of each row. */
  57700. + gpio_set_value(par->gpio.dc, 0);
  57701. + write_reg(par, 0x80 | 0);
  57702. + write_reg(par, 0x40 | y);
  57703. +
  57704. + for (x = 0; x < WIDTH; x++) {
  57705. + u8 ch = 0;
  57706. + for (i = 0; i < 8*WIDTH; i += WIDTH) {
  57707. + ch >>= 1;
  57708. + if (vmem16[(y*8*WIDTH)+i+x])
  57709. + ch |= 0x80;
  57710. + }
  57711. + *buf++ = ch;
  57712. + }
  57713. + /* Write the row */
  57714. + gpio_set_value(par->gpio.dc, 1);
  57715. + ret = par->fbtftops.write(par, par->txbuf.buf, WIDTH);
  57716. + if (ret < 0) {
  57717. + dev_err(par->info->device,
  57718. + "%s: write failed and returned: %d\n", __func__, ret);
  57719. + break;
  57720. + }
  57721. + }
  57722. +
  57723. + return ret;
  57724. +}
  57725. +
  57726. +static int set_gamma(struct fbtft_par *par, unsigned long *curves)
  57727. +{
  57728. + fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
  57729. +
  57730. + /* apply mask */
  57731. + curves[0] &= 0x7F;
  57732. +
  57733. + write_reg(par, 0x21); /* turn on extended instruction set */
  57734. + write_reg(par, 0x80 | curves[0]);
  57735. + write_reg(par, 0x20); /* turn off extended instruction set */
  57736. +
  57737. + return 0;
  57738. +}
  57739. +
  57740. +
  57741. +static struct fbtft_display display = {
  57742. + .regwidth = 8,
  57743. + .width = WIDTH,
  57744. + .height = HEIGHT,
  57745. + .txbuflen = TXBUFLEN,
  57746. + .gamma_num = 1,
  57747. + .gamma_len = 1,
  57748. + .gamma = DEFAULT_GAMMA,
  57749. + .fbtftops = {
  57750. + .init_display = init_display,
  57751. + .set_addr_win = set_addr_win,
  57752. + .write_vmem = write_vmem,
  57753. + .set_gamma = set_gamma,
  57754. + },
  57755. + .backlight = 1,
  57756. +};
  57757. +FBTFT_REGISTER_DRIVER(DRVNAME, "teralane,tls8204", &display);
  57758. +
  57759. +MODULE_ALIAS("spi:" DRVNAME);
  57760. +MODULE_ALIAS("spi:tls8204");
  57761. +
  57762. +MODULE_DESCRIPTION("FB driver for the TLS8204 LCD Controller");
  57763. +MODULE_AUTHOR("Michael Hope");
  57764. +MODULE_LICENSE("GPL");
  57765. diff -Nur linux-3.18.8/drivers/staging/fbtft/fb_uc1701.c linux-rpi/drivers/staging/fbtft/fb_uc1701.c
  57766. --- linux-3.18.8/drivers/staging/fbtft/fb_uc1701.c 1970-01-01 01:00:00.000000000 +0100
  57767. +++ linux-rpi/drivers/staging/fbtft/fb_uc1701.c 2015-03-05 14:40:16.345715808 +0100
  57768. @@ -0,0 +1,210 @@
  57769. +/*
  57770. + * FB driver for the UC1701 LCD Controller
  57771. + *
  57772. + * The display is monochrome and the video memory is RGB565.
  57773. + * Any pixel value except 0 turns the pixel on.
  57774. + *
  57775. + * Copyright (C) 2014 Juergen Holzmann
  57776. + *
  57777. + * This program is free software; you can redistribute it and/or modify
  57778. + * it under the terms of the GNU General Public License as published by
  57779. + * the Free Software Foundation; either version 2 of the License, or
  57780. + * (at your option) any later version.
  57781. + *
  57782. + * This program is distributed in the hope that it will be useful,
  57783. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  57784. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  57785. + * GNU General Public License for more details.
  57786. + *
  57787. + * You should have received a copy of the GNU General Public License
  57788. + * along with this program; if not, write to the Free Software
  57789. + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  57790. + */
  57791. +
  57792. +#include <linux/module.h>
  57793. +#include <linux/kernel.h>
  57794. +#include <linux/init.h>
  57795. +#include <linux/gpio.h>
  57796. +#include <linux/spi/spi.h>
  57797. +#include <linux/delay.h>
  57798. +
  57799. +#include "fbtft.h"
  57800. +
  57801. +#define DRVNAME "fb_uc1701"
  57802. +#define WIDTH 102
  57803. +#define HEIGHT 64
  57804. +#define PAGES (HEIGHT/8)
  57805. +
  57806. +/* 1: Display on/off */
  57807. +#define LCD_DISPLAY_ENABLE 0xAE
  57808. +/* 2: display start line set */
  57809. +#define LCD_START_LINE 0x40
  57810. +/* 3: Page address set (lower 4 bits select one of the pages) */
  57811. +#define LCD_PAGE_ADDRESS 0xB0
  57812. +/* 4: column address */
  57813. +#define LCD_COL_ADDRESS 0x10
  57814. +/* 8: select orientation */
  57815. +#define LCD_BOTTOMVIEW 0xA0
  57816. +/* 9: inverted display */
  57817. +#define LCD_DISPLAY_INVERT 0xA6
  57818. +/* 10: show memory content or switch all pixels on */
  57819. +#define LCD_ALL_PIXEL 0xA4
  57820. +/* 11: lcd bias set */
  57821. +#define LCD_BIAS 0xA2
  57822. +/* 14: Reset Controller */
  57823. +#define LCD_RESET_CMD 0xE2
  57824. +/* 15: output mode select (turns display upside-down) */
  57825. +#define LCD_SCAN_DIR 0xC0
  57826. +/* 16: power control set */
  57827. +#define LCD_POWER_CONTROL 0x28
  57828. +/* 17: voltage regulator resistor ratio set */
  57829. +#define LCD_VOLTAGE 0x20
  57830. +/* 18: Volume mode set */
  57831. +#define LCD_VOLUME_MODE 0x81
  57832. +/* 22: NOP command */
  57833. +#define LCD_NO_OP 0xE3
  57834. +/* 25: advanced program control */
  57835. +#define LCD_ADV_PROG_CTRL 0xFA
  57836. +/* 25: advanced program control2 */
  57837. +#define LCD_ADV_PROG_CTRL2 0x10
  57838. +#define LCD_TEMPCOMP_HIGH 0x80
  57839. +/* column offset for normal orientation */
  57840. +#define SHIFT_ADDR_NORMAL 0
  57841. +/* column offset for bottom view orientation */
  57842. +#define SHIFT_ADDR_TOPVIEW 30
  57843. +
  57844. +
  57845. +static int init_display(struct fbtft_par *par)
  57846. +{
  57847. + fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
  57848. +
  57849. + par->fbtftops.reset(par);
  57850. +
  57851. + /* softreset of LCD */
  57852. + write_reg(par, LCD_RESET_CMD);
  57853. + mdelay(10);
  57854. +
  57855. + /* set startpoint */
  57856. + /* LCD_START_LINE | (pos & 0x3F) */
  57857. + write_reg(par, LCD_START_LINE);
  57858. +
  57859. + /* select orientation BOTTOMVIEW */
  57860. + write_reg(par, LCD_BOTTOMVIEW | 1);
  57861. + /* output mode select (turns display upside-down) */
  57862. + write_reg(par, LCD_SCAN_DIR | 0x00);
  57863. +
  57864. + /* Normal Pixel mode */
  57865. + write_reg(par, LCD_ALL_PIXEL | 0);
  57866. +
  57867. + /* positive display */
  57868. + write_reg(par, LCD_DISPLAY_INVERT | 0);
  57869. +
  57870. + /* bias 1/9 */
  57871. + write_reg(par, LCD_BIAS | 0);
  57872. +
  57873. + /* power control mode: all features on */
  57874. + /* LCD_POWER_CONTROL | (val&0x07) */
  57875. + write_reg(par, LCD_POWER_CONTROL | 0x07);
  57876. +
  57877. + /* set voltage regulator R/R */
  57878. + /* LCD_VOLTAGE | (val&0x07) */
  57879. + write_reg(par, LCD_VOLTAGE | 0x07);
  57880. +
  57881. + /* volume mode set */
  57882. + /* LCD_VOLUME_MODE,val&0x3f,LCD_NO_OP */
  57883. + write_reg(par, LCD_VOLUME_MODE);
  57884. + /* LCD_VOLUME_MODE,val&0x3f,LCD_NO_OP */
  57885. + write_reg(par, 0x09);
  57886. + /* ???? */
  57887. + /* LCD_VOLUME_MODE,val&0x3f,LCD_NO_OP */
  57888. + write_reg(par, LCD_NO_OP);
  57889. +
  57890. + /* advanced program control */
  57891. + write_reg(par, LCD_ADV_PROG_CTRL);
  57892. + write_reg(par, LCD_ADV_PROG_CTRL2|LCD_TEMPCOMP_HIGH);
  57893. +
  57894. + /* enable display */
  57895. + write_reg(par, LCD_DISPLAY_ENABLE | 1);
  57896. +
  57897. + return 0;
  57898. +}
  57899. +
  57900. +static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
  57901. +{
  57902. + fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par, "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye);
  57903. +
  57904. + /* goto address */
  57905. + /* LCD_PAGE_ADDRESS | ((page) & 0x1F),
  57906. + (((col)+SHIFT_ADDR_NORMAL) & 0x0F),
  57907. + LCD_COL_ADDRESS | ((((col)+SHIFT_ADDR_NORMAL)>>4) & 0x0F) */
  57908. + write_reg(par, LCD_PAGE_ADDRESS);
  57909. + /* LCD_PAGE_ADDRESS | ((page) & 0x1F),
  57910. + (((col)+SHIFT_ADDR_NORMAL) & 0x0F),
  57911. + LCD_COL_ADDRESS | ((((col)+SHIFT_ADDR_NORMAL)>>4) & 0x0F) */
  57912. + write_reg(par, 0x00);
  57913. + /* LCD_PAGE_ADDRESS | ((page) & 0x1F),
  57914. + (((col)+SHIFT_ADDR_NORMAL) & 0x0F),
  57915. + LCD_COL_ADDRESS | ((((col)+SHIFT_ADDR_NORMAL)>>4) & 0x0F) */
  57916. + write_reg(par, LCD_COL_ADDRESS);
  57917. +}
  57918. +
  57919. +static int write_vmem(struct fbtft_par *par, size_t offset, size_t len)
  57920. +{
  57921. + u16 *vmem16 = (u16 *)par->info->screen_base;
  57922. + u8 *buf = par->txbuf.buf;
  57923. + int x, y, i;
  57924. + int ret = 0;
  57925. +
  57926. + fbtft_par_dbg(DEBUG_WRITE_VMEM, par, "%s()\n", __func__);
  57927. +
  57928. + for (y = 0; y < PAGES; y++) {
  57929. + buf = par->txbuf.buf;
  57930. + for (x = 0; x < WIDTH; x++) {
  57931. + *buf = 0x00;
  57932. + for (i = 0; i < 8; i++)
  57933. + *buf |= (vmem16[((y*8*WIDTH)+(i*WIDTH))+x] ? 1 : 0) << i;
  57934. + buf++;
  57935. + }
  57936. + /* LCD_PAGE_ADDRESS | ((page) & 0x1F),
  57937. + (((col)+SHIFT_ADDR_NORMAL) & 0x0F),
  57938. + LCD_COL_ADDRESS | ((((col)+SHIFT_ADDR_NORMAL)>>4) & 0x0F) */
  57939. + write_reg(par, LCD_PAGE_ADDRESS|(u8)y);
  57940. + /* LCD_PAGE_ADDRESS | ((page) & 0x1F),
  57941. + (((col)+SHIFT_ADDR_NORMAL) & 0x0F),
  57942. + LCD_COL_ADDRESS | ((((col)+SHIFT_ADDR_NORMAL)>>4) & 0x0F) */
  57943. + write_reg(par, 0x00);
  57944. + /* LCD_PAGE_ADDRESS | ((page) & 0x1F),
  57945. + (((col)+SHIFT_ADDR_NORMAL) & 0x0F),
  57946. + LCD_COL_ADDRESS | ((((col)+SHIFT_ADDR_NORMAL)>>4) & 0x0F) */
  57947. + write_reg(par, LCD_COL_ADDRESS);
  57948. + gpio_set_value(par->gpio.dc, 1);
  57949. + ret = par->fbtftops.write(par, par->txbuf.buf, WIDTH);
  57950. + gpio_set_value(par->gpio.dc, 0);
  57951. + }
  57952. +
  57953. + if (ret < 0)
  57954. + dev_err(par->info->device, "%s: write failed and returned: %d\n", __func__, ret);
  57955. +
  57956. + return ret;
  57957. +}
  57958. +
  57959. +
  57960. +static struct fbtft_display display = {
  57961. + .regwidth = 8,
  57962. + .width = WIDTH,
  57963. + .height = HEIGHT,
  57964. + .fbtftops = {
  57965. + .init_display = init_display,
  57966. + .set_addr_win = set_addr_win,
  57967. + .write_vmem = write_vmem,
  57968. + },
  57969. + .backlight = 1,
  57970. +};
  57971. +FBTFT_REGISTER_DRIVER(DRVNAME, "UltraChip,uc1701", &display);
  57972. +
  57973. +MODULE_ALIAS("spi:" DRVNAME);
  57974. +MODULE_ALIAS("spi:uc1701");
  57975. +
  57976. +MODULE_DESCRIPTION("FB driver for the UC1701 LCD Controller");
  57977. +MODULE_AUTHOR("Juergen Holzmann");
  57978. +MODULE_LICENSE("GPL");
  57979. diff -Nur linux-3.18.8/drivers/staging/fbtft/fb_upd161704.c linux-rpi/drivers/staging/fbtft/fb_upd161704.c
  57980. --- linux-3.18.8/drivers/staging/fbtft/fb_upd161704.c 1970-01-01 01:00:00.000000000 +0100
  57981. +++ linux-rpi/drivers/staging/fbtft/fb_upd161704.c 2015-03-05 14:40:16.345715808 +0100
  57982. @@ -0,0 +1,206 @@
  57983. +/*
  57984. + * FB driver for the uPD161704 LCD Controller
  57985. + *
  57986. + * Copyright (C) 2014 Seong-Woo Kim
  57987. + *
  57988. + * Based on fb_ili9325.c by Noralf Tronnes
  57989. + * Based on ili9325.c by Jeroen Domburg
  57990. + * Init code from UTFT library by Henning Karlsen
  57991. + *
  57992. + * This program is free software; you can redistribute it and/or modify
  57993. + * it under the terms of the GNU General Public License as published by
  57994. + * the Free Software Foundation; either version 2 of the License, or
  57995. + * (at your option) any later version.
  57996. + *
  57997. + * This program is distributed in the hope that it will be useful,
  57998. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  57999. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  58000. + * GNU General Public License for more details.
  58001. + *
  58002. + * You should have received a copy of the GNU General Public License
  58003. + * along with this program; if not, write to the Free Software
  58004. + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  58005. + */
  58006. +
  58007. +#include <linux/module.h>
  58008. +#include <linux/kernel.h>
  58009. +#include <linux/init.h>
  58010. +#include <linux/gpio.h>
  58011. +#include <linux/delay.h>
  58012. +
  58013. +#include "fbtft.h"
  58014. +
  58015. +#define DRVNAME "fb_upd161704"
  58016. +#define WIDTH 240
  58017. +#define HEIGHT 320
  58018. +#define BPP 16
  58019. +
  58020. +static int init_display(struct fbtft_par *par)
  58021. +{
  58022. + fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
  58023. +
  58024. + par->fbtftops.reset(par);
  58025. +
  58026. + if (par->gpio.cs != -1)
  58027. + gpio_set_value(par->gpio.cs, 0); /* Activate chip */
  58028. +
  58029. + /* Initialization sequence from Lib_UTFT */
  58030. +
  58031. + /* register reset */
  58032. + write_reg(par, 0x0003,0x0001); /* Soft reset */
  58033. +
  58034. + /* oscillator start */
  58035. + write_reg(par, 0x003A,0x0001); /*Oscillator 0: stop, 1: operation */
  58036. + udelay(100);
  58037. +
  58038. + /* y-setting */
  58039. + write_reg(par, 0x0024,0x007B); /* amplitude setting */
  58040. + udelay(10);
  58041. + write_reg(par, 0x0025,0x003B); /* amplitude setting */
  58042. + write_reg(par, 0x0026,0x0034); /* amplitude setting */
  58043. + udelay(10);
  58044. + write_reg(par, 0x0027,0x0004); /* amplitude setting */
  58045. + write_reg(par, 0x0052,0x0025); /* circuit setting 1 */
  58046. + udelay(10);
  58047. + write_reg(par, 0x0053,0x0033); /* circuit setting 2 */
  58048. + write_reg(par, 0x0061,0x001C); /* adjustment V10 positive polarity */
  58049. + udelay(10);
  58050. + write_reg(par, 0x0062,0x002C); /* adjustment V9 negative polarity */
  58051. + write_reg(par, 0x0063,0x0022); /* adjustment V34 positive polarity */
  58052. + udelay(10);
  58053. + write_reg(par, 0x0064,0x0027); /* adjustment V31 negative polarity */
  58054. + udelay(10);
  58055. + write_reg(par, 0x0065,0x0014); /* adjustment V61 negative polarity */
  58056. + udelay(10);
  58057. + write_reg(par, 0x0066,0x0010); /* adjustment V61 negative polarity */
  58058. +
  58059. + /* Basical clock for 1 line (BASECOUNT[7:0]) number specified */
  58060. + write_reg(par, 0x002E,0x002D);
  58061. +
  58062. + /* Power supply setting */
  58063. + write_reg(par, 0x0019,0x0000); /* DC/DC output setting */
  58064. + udelay(200);
  58065. + write_reg(par, 0x001A,0x1000); /* DC/DC frequency setting */
  58066. + write_reg(par, 0x001B,0x0023); /* DC/DC rising setting */
  58067. + write_reg(par, 0x001C,0x0C01); /* Regulator voltage setting */
  58068. + write_reg(par, 0x001D,0x0000); /* Regulator current setting */
  58069. + write_reg(par, 0x001E,0x0009); /* VCOM output setting */
  58070. + write_reg(par, 0x001F,0x0035); /* VCOM amplitude setting */
  58071. + write_reg(par, 0x0020,0x0015); /* VCOMM cencter setting */
  58072. + write_reg(par, 0x0018,0x1E7B); /* DC/DC operation setting */
  58073. +
  58074. + /* windows setting */
  58075. + write_reg(par, 0x0008,0x0000); /* Minimum X address */
  58076. + write_reg(par, 0x0009,0x00EF); /* Maximum X address */
  58077. + write_reg(par, 0x000a,0x0000); /* Minimum Y address */
  58078. + write_reg(par, 0x000b,0x013F); /* Maximum Y address */
  58079. +
  58080. + /* LCD display area setting */
  58081. + write_reg(par, 0x0029,0x0000); /* [LCDSIZE] X MIN. size set */
  58082. + write_reg(par, 0x002A,0x0000); /* [LCDSIZE] Y MIN. size set */
  58083. + write_reg(par, 0x002B,0x00EF); /* [LCDSIZE] X MAX. size set */
  58084. + write_reg(par, 0x002C,0x013F); /* [LCDSIZE] Y MAX. size set */
  58085. +
  58086. + /* Gate scan setting */
  58087. + write_reg(par, 0x0032,0x0002);
  58088. +
  58089. + /* n line inversion line number */
  58090. + write_reg(par, 0x0033,0x0000);
  58091. +
  58092. + /* Line inversion/frame inversion/interlace setting */
  58093. + write_reg(par, 0x0037,0x0000);
  58094. +
  58095. + /* Gate scan operation setting register */
  58096. + write_reg(par, 0x003B,0x0001);
  58097. +
  58098. + /* Color mode */
  58099. + /*GS = 0: 260-k color (64 gray scale), GS = 1: 8 color (2 gray scale) */
  58100. + write_reg(par, 0x0004,0x0000);
  58101. +
  58102. + /* RAM control register */
  58103. + write_reg(par, 0x0005,0x0000); /*Window access 00:Normal, 10:Window */
  58104. +
  58105. + /* Display setting register 2 */
  58106. + write_reg(par, 0x0001,0x0000);
  58107. +
  58108. + /* display setting */
  58109. + write_reg(par, 0x0000,0x0000); /* display on */
  58110. +
  58111. + return 0;
  58112. +}
  58113. +
  58114. +static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
  58115. +{
  58116. + fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par,
  58117. + "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye);
  58118. + switch (par->info->var.rotate) {
  58119. + /* R20h = Horizontal GRAM Start Address */
  58120. + /* R21h = Vertical GRAM Start Address */
  58121. + case 0:
  58122. + write_reg(par, 0x0006, xs);
  58123. + write_reg(par, 0x0007, ys);
  58124. + break;
  58125. + case 180:
  58126. + write_reg(par, 0x0006, WIDTH - 1 - xs);
  58127. + write_reg(par, 0x0007, HEIGHT - 1 - ys);
  58128. + break;
  58129. + case 270:
  58130. + write_reg(par, 0x0006, WIDTH - 1 - ys);
  58131. + write_reg(par, 0x0007, xs);
  58132. + break;
  58133. + case 90:
  58134. + write_reg(par, 0x0006, ys);
  58135. + write_reg(par, 0x0007, HEIGHT - 1 - xs);
  58136. + break;
  58137. + }
  58138. +
  58139. + write_reg(par, 0x0e); /* Write Data to GRAM */
  58140. +}
  58141. +
  58142. +static int set_var(struct fbtft_par *par)
  58143. +{
  58144. + fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
  58145. +
  58146. + switch (par->info->var.rotate) {
  58147. + /* AM: GRAM update direction */
  58148. + case 0:
  58149. + write_reg(par, 0x01, 0x0000);
  58150. + write_reg(par, 0x05, 0x0000);
  58151. + break;
  58152. + case 180:
  58153. + write_reg(par, 0x01, 0x00C0);
  58154. + write_reg(par, 0x05, 0x0000);
  58155. + break;
  58156. + case 270:
  58157. + write_reg(par, 0x01, 0x0080);
  58158. + write_reg(par, 0x05, 0x0001);
  58159. + break;
  58160. + case 90:
  58161. + write_reg(par, 0x01, 0x0040);
  58162. + write_reg(par, 0x05, 0x0001);
  58163. + break;
  58164. + }
  58165. +
  58166. + return 0;
  58167. +}
  58168. +
  58169. +static struct fbtft_display display = {
  58170. + .regwidth = 16,
  58171. + .width = WIDTH,
  58172. + .height = HEIGHT,
  58173. + .fbtftops = {
  58174. + .init_display = init_display,
  58175. + .set_addr_win = set_addr_win,
  58176. + .set_var = set_var,
  58177. + },
  58178. +};
  58179. +FBTFT_REGISTER_DRIVER(DRVNAME, "nec,upd161704", &display);
  58180. +
  58181. +MODULE_ALIAS("spi:" DRVNAME);
  58182. +MODULE_ALIAS("platform:" DRVNAME);
  58183. +MODULE_ALIAS("spi:upd161704");
  58184. +MODULE_ALIAS("platform:upd161704");
  58185. +
  58186. +MODULE_DESCRIPTION("FB driver for the uPD161704 LCD Controller");
  58187. +MODULE_AUTHOR("Seong-Woo Kim");
  58188. +MODULE_LICENSE("GPL");
  58189. diff -Nur linux-3.18.8/drivers/staging/fbtft/fb_watterott.c linux-rpi/drivers/staging/fbtft/fb_watterott.c
  58190. --- linux-3.18.8/drivers/staging/fbtft/fb_watterott.c 1970-01-01 01:00:00.000000000 +0100
  58191. +++ linux-rpi/drivers/staging/fbtft/fb_watterott.c 2015-03-05 14:40:16.345715808 +0100
  58192. @@ -0,0 +1,324 @@
  58193. +/*
  58194. + * FB driver for the Watterott LCD Controller
  58195. + *
  58196. + * Copyright (C) 2013 Noralf Tronnes
  58197. + *
  58198. + * This program is free software; you can redistribute it and/or modify
  58199. + * it under the terms of the GNU General Public License as published by
  58200. + * the Free Software Foundation; either version 2 of the License, or
  58201. + * (at your option) any later version.
  58202. + *
  58203. + * This program is distributed in the hope that it will be useful,
  58204. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  58205. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  58206. + * GNU General Public License for more details.
  58207. + *
  58208. + * You should have received a copy of the GNU General Public License
  58209. + * along with this program; if not, write to the Free Software
  58210. + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  58211. + */
  58212. +
  58213. +#include <linux/module.h>
  58214. +#include <linux/kernel.h>
  58215. +#include <linux/init.h>
  58216. +#include <linux/gpio.h>
  58217. +#include <linux/delay.h>
  58218. +
  58219. +#include "fbtft.h"
  58220. +
  58221. +#define DRVNAME "fb_watterott"
  58222. +#define WIDTH 320
  58223. +#define HEIGHT 240
  58224. +#define FPS 5
  58225. +#define TXBUFLEN 1024
  58226. +#define DEFAULT_BRIGHTNESS 50
  58227. +
  58228. +#define CMD_VERSION 0x01
  58229. +#define CMD_LCD_LED 0x10
  58230. +#define CMD_LCD_RESET 0x11
  58231. +#define CMD_LCD_ORIENTATION 0x20
  58232. +#define CMD_LCD_DRAWIMAGE 0x27
  58233. +#define COLOR_RGB323 8
  58234. +#define COLOR_RGB332 9
  58235. +#define COLOR_RGB233 10
  58236. +#define COLOR_RGB565 16
  58237. +
  58238. +
  58239. +static short mode = 565;
  58240. +module_param(mode, short, 0);
  58241. +MODULE_PARM_DESC(mode, "RGB color transfer mode: 332, 565 (default)");
  58242. +
  58243. +static void write_reg8_bus8(struct fbtft_par *par, int len, ...)
  58244. +{
  58245. + va_list args;
  58246. + int i, ret;
  58247. + u8 *buf = par->buf;
  58248. +
  58249. + va_start(args, len);
  58250. + for (i = 0; i < len; i++)
  58251. + *buf++ = (u8)va_arg(args, unsigned int);
  58252. + va_end(args);
  58253. +
  58254. + fbtft_par_dbg_hex(DEBUG_WRITE_REGISTER, par,
  58255. + par->info->device, u8, par->buf, len, "%s: ", __func__);
  58256. +
  58257. + ret = par->fbtftops.write(par, par->buf, len);
  58258. + if (ret < 0) {
  58259. + dev_err(par->info->device,
  58260. + "%s: write() failed and returned %d\n", __func__, ret);
  58261. + return;
  58262. + }
  58263. +}
  58264. +
  58265. +static int write_vmem(struct fbtft_par *par, size_t offset, size_t len)
  58266. +{
  58267. + unsigned start_line, end_line;
  58268. + u16 *vmem16 = (u16 *)(par->info->screen_base + offset);
  58269. + u16 *pos = par->txbuf.buf + 1;
  58270. + u16 *buf16 = par->txbuf.buf + 10;
  58271. + int i, j;
  58272. + int ret = 0;
  58273. +
  58274. + fbtft_par_dbg(DEBUG_WRITE_VMEM, par, "%s()\n", __func__);
  58275. +
  58276. + start_line = offset / par->info->fix.line_length;
  58277. + end_line = start_line + (len / par->info->fix.line_length) - 1;
  58278. +
  58279. + /* Set command header. pos: x, y, w, h */
  58280. + ((u8 *)par->txbuf.buf)[0] = CMD_LCD_DRAWIMAGE;
  58281. + pos[0] = 0;
  58282. + pos[2] = cpu_to_be16(par->info->var.xres);
  58283. + pos[3] = cpu_to_be16(1);
  58284. + ((u8 *)par->txbuf.buf)[9] = COLOR_RGB565;
  58285. +
  58286. + for (i = start_line; i <= end_line; i++) {
  58287. + pos[1] = cpu_to_be16(i);
  58288. + for (j = 0; j < par->info->var.xres; j++)
  58289. + buf16[j] = cpu_to_be16(*vmem16++);
  58290. + ret = par->fbtftops.write(par,
  58291. + par->txbuf.buf, 10 + par->info->fix.line_length);
  58292. + if (ret < 0)
  58293. + return ret;
  58294. + udelay(300);
  58295. + }
  58296. +
  58297. + return 0;
  58298. +}
  58299. +
  58300. +#define RGB565toRGB323(c) (((c&0xE000)>>8) | ((c&0600)>>6) | ((c&0x001C)>>2))
  58301. +#define RGB565toRGB332(c) (((c&0xE000)>>8) | ((c&0700)>>6) | ((c&0x0018)>>3))
  58302. +#define RGB565toRGB233(c) (((c&0xC000)>>8) | ((c&0700)>>5) | ((c&0x001C)>>2))
  58303. +
  58304. +static int write_vmem_8bit(struct fbtft_par *par, size_t offset, size_t len)
  58305. +{
  58306. + unsigned start_line, end_line;
  58307. + u16 *vmem16 = (u16 *)(par->info->screen_base + offset);
  58308. + u16 *pos = par->txbuf.buf + 1;
  58309. + u8 *buf8 = par->txbuf.buf + 10;
  58310. + int i, j;
  58311. + int ret = 0;
  58312. +
  58313. + fbtft_par_dbg(DEBUG_WRITE_VMEM, par, "%s()\n", __func__);
  58314. +
  58315. + start_line = offset / par->info->fix.line_length;
  58316. + end_line = start_line + (len / par->info->fix.line_length) - 1;
  58317. +
  58318. + /* Set command header. pos: x, y, w, h */
  58319. + ((u8 *)par->txbuf.buf)[0] = CMD_LCD_DRAWIMAGE;
  58320. + pos[0] = 0;
  58321. + pos[2] = cpu_to_be16(par->info->var.xres);
  58322. + pos[3] = cpu_to_be16(1);
  58323. + ((u8 *)par->txbuf.buf)[9] = COLOR_RGB332;
  58324. +
  58325. + for (i = start_line; i <= end_line; i++) {
  58326. + pos[1] = cpu_to_be16(i);
  58327. + for (j = 0; j < par->info->var.xres; j++) {
  58328. + buf8[j] = RGB565toRGB332(*vmem16);
  58329. + vmem16++;
  58330. + }
  58331. + ret = par->fbtftops.write(par,
  58332. + par->txbuf.buf, 10 + par->info->var.xres);
  58333. + if (ret < 0)
  58334. + return ret;
  58335. + udelay(700);
  58336. + }
  58337. +
  58338. + return 0;
  58339. +}
  58340. +
  58341. +static unsigned firmware_version(struct fbtft_par *par)
  58342. +{
  58343. + u8 rxbuf[4] = {0, };
  58344. +
  58345. + write_reg(par, CMD_VERSION);
  58346. + par->fbtftops.read(par, rxbuf, 4);
  58347. + if (rxbuf[1] != '.')
  58348. + return 0;
  58349. +
  58350. + return (rxbuf[0] - '0') << 8 | (rxbuf[2] - '0') << 4 | (rxbuf[3] - '0');
  58351. +}
  58352. +
  58353. +static int init_display(struct fbtft_par *par)
  58354. +{
  58355. + int ret;
  58356. + unsigned version;
  58357. + u8 save_mode;
  58358. +
  58359. + fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
  58360. +
  58361. + /* enable SPI interface by having CS and MOSI low during reset */
  58362. + save_mode = par->spi->mode;
  58363. + par->spi->mode |= SPI_CS_HIGH;
  58364. + ret = par->spi->master->setup(par->spi); /* set CS inactive low */
  58365. + if (ret) {
  58366. + dev_err(par->info->device, "Could not set SPI_CS_HIGH\n");
  58367. + return ret;
  58368. + }
  58369. + write_reg(par, 0x00); /* make sure mode is set */
  58370. +
  58371. + mdelay(50);
  58372. + par->fbtftops.reset(par);
  58373. + mdelay(1000);
  58374. + par->spi->mode = save_mode;
  58375. + ret = par->spi->master->setup(par->spi);
  58376. + if (ret) {
  58377. + dev_err(par->info->device, "Could not restore SPI mode\n");
  58378. + return ret;
  58379. + }
  58380. + write_reg(par, 0x00);
  58381. +
  58382. + version = firmware_version(par);
  58383. + fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "Firmware version: %x.%02x\n",
  58384. + version >> 8, version & 0xFF);
  58385. +
  58386. + if (mode == 332)
  58387. + par->fbtftops.write_vmem = write_vmem_8bit;
  58388. + return 0;
  58389. +}
  58390. +
  58391. +static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
  58392. +{
  58393. + /* not used on this controller */
  58394. +}
  58395. +
  58396. +static int set_var(struct fbtft_par *par)
  58397. +{
  58398. + u8 rotate;
  58399. +
  58400. + fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
  58401. +
  58402. + /* this controller rotates clock wise */
  58403. + switch (par->info->var.rotate) {
  58404. + case 90:
  58405. + rotate = 27;
  58406. + break;
  58407. + case 180:
  58408. + rotate = 18;
  58409. + break;
  58410. + case 270:
  58411. + rotate = 9;
  58412. + break;
  58413. + default:
  58414. + rotate = 0;
  58415. + }
  58416. + write_reg(par, CMD_LCD_ORIENTATION, rotate);
  58417. +
  58418. + return 0;
  58419. +}
  58420. +
  58421. +static int verify_gpios(struct fbtft_par *par)
  58422. +{
  58423. + if (par->gpio.reset < 0) {
  58424. + dev_err(par->info->device, "Missing 'reset' gpio. Aborting.\n");
  58425. + return -EINVAL;
  58426. + }
  58427. + return 0;
  58428. +}
  58429. +
  58430. +#ifdef CONFIG_FB_BACKLIGHT
  58431. +static int backlight_chip_update_status(struct backlight_device *bd)
  58432. +{
  58433. + struct fbtft_par *par = bl_get_data(bd);
  58434. + int brightness = bd->props.brightness;
  58435. +
  58436. + fbtft_par_dbg(DEBUG_BACKLIGHT, par,
  58437. + "%s: brightness=%d, power=%d, fb_blank=%d\n",
  58438. + __func__, bd->props.brightness, bd->props.power,
  58439. + bd->props.fb_blank);
  58440. +
  58441. + if (bd->props.power != FB_BLANK_UNBLANK)
  58442. + brightness = 0;
  58443. +
  58444. + if (bd->props.fb_blank != FB_BLANK_UNBLANK)
  58445. + brightness = 0;
  58446. +
  58447. + write_reg(par, CMD_LCD_LED, brightness);
  58448. +
  58449. + return 0;
  58450. +}
  58451. +
  58452. +static void register_chip_backlight(struct fbtft_par *par)
  58453. +{
  58454. + struct backlight_device *bd;
  58455. + struct backlight_properties bl_props = { 0, };
  58456. + struct backlight_ops *bl_ops;
  58457. +
  58458. + fbtft_par_dbg(DEBUG_BACKLIGHT, par, "%s()\n", __func__);
  58459. +
  58460. + bl_ops = devm_kzalloc(par->info->device, sizeof(struct backlight_ops),
  58461. + GFP_KERNEL);
  58462. + if (!bl_ops) {
  58463. + dev_err(par->info->device,
  58464. + "%s: could not allocate memory for backlight operations.\n",
  58465. + __func__);
  58466. + return;
  58467. + }
  58468. +
  58469. + bl_ops->update_status = backlight_chip_update_status;
  58470. + bl_props.type = BACKLIGHT_RAW;
  58471. + bl_props.power = FB_BLANK_POWERDOWN;
  58472. + bl_props.max_brightness = 100;
  58473. + bl_props.brightness = DEFAULT_BRIGHTNESS;
  58474. +
  58475. + bd = backlight_device_register(dev_driver_string(par->info->device),
  58476. + par->info->device, par, bl_ops, &bl_props);
  58477. + if (IS_ERR(bd)) {
  58478. + dev_err(par->info->device,
  58479. + "cannot register backlight device (%ld)\n",
  58480. + PTR_ERR(bd));
  58481. + return;
  58482. + }
  58483. + par->info->bl_dev = bd;
  58484. +
  58485. + if (!par->fbtftops.unregister_backlight)
  58486. + par->fbtftops.unregister_backlight = fbtft_unregister_backlight;
  58487. +}
  58488. +#else
  58489. +#define register_chip_backlight NULL
  58490. +#endif
  58491. +
  58492. +
  58493. +static struct fbtft_display display = {
  58494. + .regwidth = 8,
  58495. + .buswidth = 8,
  58496. + .width = WIDTH,
  58497. + .height = HEIGHT,
  58498. + .fps = FPS,
  58499. + .txbuflen = TXBUFLEN,
  58500. + .fbtftops = {
  58501. + .write_register = write_reg8_bus8,
  58502. + .write_vmem = write_vmem,
  58503. + .init_display = init_display,
  58504. + .set_addr_win = set_addr_win,
  58505. + .set_var = set_var,
  58506. + .verify_gpios = verify_gpios,
  58507. + .register_backlight = register_chip_backlight,
  58508. + },
  58509. +};
  58510. +FBTFT_REGISTER_DRIVER(DRVNAME, "watterott,openlcd", &display);
  58511. +
  58512. +MODULE_ALIAS("spi:" DRVNAME);
  58513. +
  58514. +MODULE_DESCRIPTION("FB driver for the Watterott LCD Controller");
  58515. +MODULE_AUTHOR("Noralf Tronnes");
  58516. +MODULE_LICENSE("GPL");
  58517. diff -Nur linux-3.18.8/drivers/staging/fbtft/flexfb.c linux-rpi/drivers/staging/fbtft/flexfb.c
  58518. --- linux-3.18.8/drivers/staging/fbtft/flexfb.c 1970-01-01 01:00:00.000000000 +0100
  58519. +++ linux-rpi/drivers/staging/fbtft/flexfb.c 2015-03-05 14:40:16.345715808 +0100
  58520. @@ -0,0 +1,592 @@
  58521. +/*
  58522. + * Generic FB driver for TFT LCD displays
  58523. + *
  58524. + * Copyright (C) 2013 Noralf Tronnes
  58525. + *
  58526. + * This program is free software; you can redistribute it and/or modify
  58527. + * it under the terms of the GNU General Public License as published by
  58528. + * the Free Software Foundation; either version 2 of the License, or
  58529. + * (at your option) any later version.
  58530. + *
  58531. + * This program is distributed in the hope that it will be useful,
  58532. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  58533. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  58534. + * GNU General Public License for more details.
  58535. + *
  58536. + * You should have received a copy of the GNU General Public License
  58537. + * along with this program; if not, write to the Free Software
  58538. + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  58539. + */
  58540. +
  58541. +#include <linux/module.h>
  58542. +#include <linux/kernel.h>
  58543. +#include <linux/init.h>
  58544. +#include <linux/vmalloc.h>
  58545. +#include <linux/gpio.h>
  58546. +#include <linux/spi/spi.h>
  58547. +#include <linux/delay.h>
  58548. +
  58549. +#include "fbtft.h"
  58550. +
  58551. +#define DRVNAME "flexfb"
  58552. +
  58553. +
  58554. +static char *chip;
  58555. +module_param(chip, charp, 0);
  58556. +MODULE_PARM_DESC(chip, "LCD controller");
  58557. +
  58558. +static unsigned int width;
  58559. +module_param(width, uint, 0);
  58560. +MODULE_PARM_DESC(width, "Display width");
  58561. +
  58562. +static unsigned int height;
  58563. +module_param(height, uint, 0);
  58564. +MODULE_PARM_DESC(height, "Display height");
  58565. +
  58566. +static int init[512];
  58567. +static int init_num;
  58568. +module_param_array(init, int, &init_num, 0);
  58569. +MODULE_PARM_DESC(init, "Init sequence");
  58570. +
  58571. +static unsigned int setaddrwin;
  58572. +module_param(setaddrwin, uint, 0);
  58573. +MODULE_PARM_DESC(setaddrwin, "Which set_addr_win() implementation to use");
  58574. +
  58575. +static unsigned int buswidth = 8;
  58576. +module_param(buswidth, uint, 0);
  58577. +MODULE_PARM_DESC(buswidth, "Width of databus (default: 8)");
  58578. +
  58579. +static unsigned int regwidth = 8;
  58580. +module_param(regwidth, uint, 0);
  58581. +MODULE_PARM_DESC(regwidth, "Width of controller register (default: 8)");
  58582. +
  58583. +static bool nobacklight;
  58584. +module_param(nobacklight, bool, 0);
  58585. +MODULE_PARM_DESC(nobacklight, "Turn off backlight functionality.");
  58586. +
  58587. +static bool latched;
  58588. +module_param(latched, bool, 0);
  58589. +MODULE_PARM_DESC(latched, "Use with latched 16-bit databus");
  58590. +
  58591. +
  58592. +static int *initp;
  58593. +static int initp_num;
  58594. +
  58595. +/* default init sequences */
  58596. +static int st7735r_init[] = { \
  58597. +-1,0x01,-2,150,-1,0x11,-2,500,-1,0xB1,0x01,0x2C,0x2D,-1,0xB2,0x01,0x2C,0x2D,-1,0xB3,0x01,0x2C,0x2D,0x01,0x2C,0x2D, \
  58598. +-1,0xB4,0x07,-1,0xC0,0xA2,0x02,0x84,-1,0xC1,0xC5,-1,0xC2,0x0A,0x00,-1,0xC3,0x8A,0x2A,-1,0xC4,0x8A,0xEE,-1,0xC5,0x0E, \
  58599. +-1,0x20,-1,0x36,0xC0,-1,0x3A,0x05,-1,0xE0,0x0f,0x1a,0x0f,0x18,0x2f,0x28,0x20,0x22,0x1f,0x1b,0x23,0x37,0x00,0x07,0x02,0x10, \
  58600. +-1,0xE1,0x0f,0x1b,0x0f,0x17,0x33,0x2c,0x29,0x2e,0x30,0x30,0x39,0x3f,0x00,0x07,0x03,0x10,-1,0x29,-2,100,-1,0x13,-2,10,-3 };
  58601. +
  58602. +static int ssd1289_init[] = { \
  58603. +-1,0x00,0x0001,-1,0x03,0xA8A4,-1,0x0C,0x0000,-1,0x0D,0x080C,-1,0x0E,0x2B00,-1,0x1E,0x00B7,-1,0x01,0x2B3F,-1,0x02,0x0600, \
  58604. +-1,0x10,0x0000,-1,0x11,0x6070,-1,0x05,0x0000,-1,0x06,0x0000,-1,0x16,0xEF1C,-1,0x17,0x0003,-1,0x07,0x0233,-1,0x0B,0x0000, \
  58605. +-1,0x0F,0x0000,-1,0x41,0x0000,-1,0x42,0x0000,-1,0x48,0x0000,-1,0x49,0x013F,-1,0x4A,0x0000,-1,0x4B,0x0000,-1,0x44,0xEF00, \
  58606. +-1,0x45,0x0000,-1,0x46,0x013F,-1,0x30,0x0707,-1,0x31,0x0204,-1,0x32,0x0204,-1,0x33,0x0502,-1,0x34,0x0507,-1,0x35,0x0204, \
  58607. +-1,0x36,0x0204,-1,0x37,0x0502,-1,0x3A,0x0302,-1,0x3B,0x0302,-1,0x23,0x0000,-1,0x24,0x0000,-1,0x25,0x8000,-1,0x4f,0x0000, \
  58608. +-1,0x4e,0x0000,-1,0x22,-3 };
  58609. +
  58610. +static int hx8340bn_init[] = { \
  58611. +-1,0xC1,0xFF,0x83,0x40,-1,0x11,-2,150,-1,0xCA,0x70,0x00,0xD9,-1,0xB0,0x01,0x11, \
  58612. +-1,0xC9,0x90,0x49,0x10,0x28,0x28,0x10,0x00,0x06,-2,20,-1,0xC2,0x60,0x71,0x01,0x0E,0x05,0x02,0x09,0x31,0x0A, \
  58613. +-1,0xC3,0x67,0x30,0x61,0x17,0x48,0x07,0x05,0x33,-2,10,-1,0xB5,0x35,0x20,0x45,-1,0xB4,0x33,0x25,0x4C,-2,10, \
  58614. +-1,0x3A,0x05,-1,0x29,-2,10,-3 };
  58615. +
  58616. +static int ili9225_init[] = { \
  58617. +-1,0x0001,0x011C,-1,0x0002,0x0100,-1,0x0003,0x1030,-1,0x0008,0x0808,-1,0x000C,0x0000,-1,0x000F,0x0A01,-1,0x0020,0x0000, \
  58618. +-1,0x0021,0x0000,-2,50,-1,0x0010,0x0A00,-1,0x0011,0x1038,-2,50,-1,0x0012,0x1121,-1,0x0013,0x004E,-1,0x0014,0x676F, \
  58619. +-1,0x0030,0x0000,-1,0x0031,0x00DB,-1,0x0032,0x0000,-1,0x0033,0x0000,-1,0x0034,0x00DB,-1,0x0035,0x0000,-1,0x0036,0x00AF, \
  58620. +-1,0x0037,0x0000,-1,0x0038,0x00DB,-1,0x0039,0x0000,-1,0x0050,0x0000,-1,0x0051,0x060A,-1,0x0052,0x0D0A,-1,0x0053,0x0303, \
  58621. +-1,0x0054,0x0A0D,-1,0x0055,0x0A06,-1,0x0056,0x0000,-1,0x0057,0x0303,-1,0x0058,0x0000,-1,0x0059,0x0000,-2,50, \
  58622. +-1,0x0007,0x1017,-2,50,-3 };
  58623. +
  58624. +static int ili9320_init[] = { \
  58625. +-1,0x00E5,0x8000,-1,0x0000,0x0001,-1,0x0001,0x0100,-1,0x0002,0x0700,-1,0x0003,0x1030,-1,0x0004,0x0000,-1,0x0008,0x0202, \
  58626. +-1,0x0009,0x0000,-1,0x000A,0x0000,-1,0x000C,0x0000,-1,0x000D,0x0000,-1,0x000F,0x0000,-1,0x0010,0x0000,-1,0x0011,0x0007, \
  58627. +-1,0x0012,0x0000,-1,0x0013,0x0000,-2,200,-1,0x0010,0x17B0,-1,0x0011,0x0031,-2,50,-1,0x0012,0x0138,-2,50,-1,0x0013,0x1800, \
  58628. +-1,0x0029,0x0008,-2,50,-1,0x0020,0x0000,-1,0x0021,0x0000,-1,0x0030,0x0000,-1,0x0031,0x0505,-1,0x0032,0x0004, \
  58629. +-1,0x0035,0x0006,-1,0x0036,0x0707,-1,0x0037,0x0105,-1,0x0038,0x0002,-1,0x0039,0x0707,-1,0x003C,0x0704,-1,0x003D,0x0807, \
  58630. +-1,0x0050,0x0000,-1,0x0051,0x00EF,-1,0x0052,0x0000,-1,0x0053,0x013F,-1,0x0060,0x2700,-1,0x0061,0x0001,-1,0x006A,0x0000, \
  58631. +-1,0x0080,0x0000,-1,0x0081,0x0000,-1,0x0082,0x0000,-1,0x0083,0x0000,-1,0x0084,0x0000,-1,0x0085,0x0000,-1,0x0090,0x0010, \
  58632. +-1,0x0092,0x0000,-1,0x0093,0x0003,-1,0x0095,0x0110,-1,0x0097,0x0000,-1,0x0098,0x0000,-1,0x0007,0x0173,-3 };
  58633. +
  58634. +static int ili9325_init[] = { \
  58635. +-1,0x00E3,0x3008,-1,0x00E7,0x0012,-1,0x00EF,0x1231,-1,0x0001,0x0100,-1,0x0002,0x0700,-1,0x0003,0x1030,-1,0x0004,0x0000, \
  58636. +-1,0x0008,0x0207,-1,0x0009,0x0000,-1,0x000A,0x0000,-1,0x000C,0x0000,-1,0x000D,0x0000,-1,0x000F,0x0000,-1,0x0010,0x0000, \
  58637. +-1,0x0011,0x0007,-1,0x0012,0x0000,-1,0x0013,0x0000,-2,200,-1,0x0010,0x1690,-1,0x0011,0x0223,-2,50,-1,0x0012,0x000D,-2,50, \
  58638. +-1,0x0013,0x1200,-1,0x0029,0x000A,-1,0x002B,0x000C,-2,50,-1,0x0020,0x0000,-1,0x0021,0x0000,-1,0x0030,0x0000, \
  58639. +-1,0x0031,0x0506,-1,0x0032,0x0104,-1,0x0035,0x0207,-1,0x0036,0x000F,-1,0x0037,0x0306,-1,0x0038,0x0102,-1,0x0039,0x0707, \
  58640. +-1,0x003C,0x0702,-1,0x003D,0x1604,-1,0x0050,0x0000,-1,0x0051,0x00EF,-1,0x0052,0x0000,-1,0x0053,0x013F,-1,0x0060,0xA700, \
  58641. +-1,0x0061,0x0001,-1,0x006A,0x0000,-1,0x0080,0x0000,-1,0x0081,0x0000,-1,0x0082,0x0000,-1,0x0083,0x0000,-1,0x0084,0x0000, \
  58642. +-1,0x0085,0x0000,-1,0x0090,0x0010,-1,0x0092,0x0600,-1,0x0007,0x0133,-3 };
  58643. +
  58644. +static int ili9341_init[] = { \
  58645. +-1,0x28,-2,20,-1,0xCF,0x00,0x83,0x30,-1,0xED,0x64,0x03,0x12,0x81,-1,0xE8,0x85,0x01,0x79, \
  58646. +-1,0xCB,0x39,0x2c,0x00,0x34,0x02,-1,0xF7,0x20,-1,0xEA,0x00,0x00,-1,0xC0,0x26,-1,0xC1,0x11, \
  58647. +-1,0xC5,0x35,0x3E,-1,0xC7,0xBE,-1,0xB1,0x00,0x1B,-1,0xB6,0x0a,0x82,0x27,0x00,-1,0xB7,0x07, \
  58648. +-1,0x3A,0x55,-1,0x36,0x48,-1,0x11,-2,120,-1,0x29,-2,20,-3 };
  58649. +
  58650. +static int ssd1351_init[] = { -1,0xfd,0x12,-1,0xfd,0xb1,-1,0xae,-1,0xb3,0xf1,-1,0xca,0x7f,-1,0xa0,0x74, \
  58651. + -1,0x15,0x00,0x7f,-1,0x75,0x00,0x7f,-1,0xa1,0x00,-1,0xa2,0x00,-1,0xb5,0x00, \
  58652. + -1,0xab,0x01,-1,0xb1,0x32,-1,0xb4,0xa0,0xb5,0x55,-1,0xbb,0x17,-1,0xbe,0x05, \
  58653. + -1,0xc1,0xc8,0x80,0xc8,-1,0xc7,0x0f,-1,0xb6,0x01,-1,0xa6,-1,0xaf,-3 };
  58654. +
  58655. +
  58656. +/* ili9320, ili9325 */
  58657. +static void flexfb_set_addr_win_1(struct fbtft_par *par, int xs, int ys, int xe, int ye)
  58658. +{
  58659. + fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par, "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye);
  58660. + switch (par->info->var.rotate) {
  58661. + /* R20h = Horizontal GRAM Start Address */
  58662. + /* R21h = Vertical GRAM Start Address */
  58663. + case 0:
  58664. + write_reg(par, 0x0020, xs);
  58665. + write_reg(par, 0x0021, ys);
  58666. + break;
  58667. + case 180:
  58668. + write_reg(par, 0x0020, width - 1 - xs);
  58669. + write_reg(par, 0x0021, height - 1 - ys);
  58670. + break;
  58671. + case 270:
  58672. + write_reg(par, 0x0020, width - 1 - ys);
  58673. + write_reg(par, 0x0021, xs);
  58674. + break;
  58675. + case 90:
  58676. + write_reg(par, 0x0020, ys);
  58677. + write_reg(par, 0x0021, height - 1 - xs);
  58678. + break;
  58679. + }
  58680. + write_reg(par, 0x0022); /* Write Data to GRAM */
  58681. +}
  58682. +
  58683. +/* ssd1289 */
  58684. +static void flexfb_set_addr_win_2(struct fbtft_par *par, int xs, int ys, int xe, int ye)
  58685. +{
  58686. + fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par, "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye);
  58687. +
  58688. + switch (par->info->var.rotate) {
  58689. + /* R4Eh - Set GDDRAM X address counter */
  58690. + /* R4Fh - Set GDDRAM Y address counter */
  58691. + case 0:
  58692. + write_reg(par, 0x4e, xs);
  58693. + write_reg(par, 0x4f, ys);
  58694. + break;
  58695. + case 180:
  58696. + write_reg(par, 0x4e, par->info->var.xres - 1 - xs);
  58697. + write_reg(par, 0x4f, par->info->var.yres - 1 - ys);
  58698. + break;
  58699. + case 270:
  58700. + write_reg(par, 0x4e, par->info->var.yres - 1 - ys);
  58701. + write_reg(par, 0x4f, xs);
  58702. + break;
  58703. + case 90:
  58704. + write_reg(par, 0x4e, ys);
  58705. + write_reg(par, 0x4f, par->info->var.xres - 1 - xs);
  58706. + break;
  58707. + }
  58708. +
  58709. + /* R22h - RAM data write */
  58710. + write_reg(par, 0x22, 0);
  58711. +}
  58712. +
  58713. +/* ssd1351 */
  58714. +static void set_addr_win_3(struct fbtft_par *par, int xs, int ys, int xe, int ye)
  58715. +{
  58716. + fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par, "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye);
  58717. +
  58718. + write_reg(par, 0x15, xs, xe);
  58719. + write_reg(par, 0x75, ys, ye);
  58720. + write_reg(par, 0x5C);
  58721. +}
  58722. +
  58723. +static int flexfb_verify_gpios_dc(struct fbtft_par *par)
  58724. +{
  58725. + fbtft_par_dbg(DEBUG_VERIFY_GPIOS, par, "%s()\n", __func__);
  58726. +
  58727. + if (par->gpio.dc < 0) {
  58728. + dev_err(par->info->device, "Missing info about 'dc' gpio. Aborting.\n");
  58729. + return -EINVAL;
  58730. + }
  58731. +
  58732. + return 0;
  58733. +}
  58734. +
  58735. +static int flexfb_verify_gpios_db(struct fbtft_par *par)
  58736. +{
  58737. + int i;
  58738. + int num_db = buswidth;
  58739. +
  58740. + fbtft_par_dbg(DEBUG_VERIFY_GPIOS, par, "%s()\n", __func__);
  58741. +
  58742. + if (par->gpio.dc < 0) {
  58743. + dev_err(par->info->device, "Missing info about 'dc' gpio. Aborting.\n");
  58744. + return -EINVAL;
  58745. + }
  58746. + if (par->gpio.wr < 0) {
  58747. + dev_err(par->info->device, "Missing info about 'wr' gpio. Aborting.\n");
  58748. + return -EINVAL;
  58749. + }
  58750. + if (latched && (par->gpio.latch < 0)) {
  58751. + dev_err(par->info->device, "Missing info about 'latch' gpio. Aborting.\n");
  58752. + return -EINVAL;
  58753. + }
  58754. + if (latched)
  58755. + num_db=buswidth/2;
  58756. + for (i=0;i < num_db;i++) {
  58757. + if (par->gpio.db[i] < 0) {
  58758. + dev_err(par->info->device, "Missing info about 'db%02d' gpio. Aborting.\n", i);
  58759. + return -EINVAL;
  58760. + }
  58761. + }
  58762. +
  58763. + return 0;
  58764. +}
  58765. +
  58766. +static struct fbtft_display flex_display = { };
  58767. +
  58768. +static int flexfb_probe_common(struct spi_device *sdev, struct platform_device *pdev)
  58769. +{
  58770. + struct device *dev;
  58771. + struct fb_info *info;
  58772. + struct fbtft_par *par;
  58773. + int ret;
  58774. +
  58775. + initp = init;
  58776. + initp_num = init_num;
  58777. +
  58778. + if (sdev)
  58779. + dev = &sdev->dev;
  58780. + else
  58781. + dev = &pdev->dev;
  58782. +
  58783. + fbtft_init_dbg(dev, "%s(%s)\n", __func__, sdev ? "'SPI device'" : "'Platform device'");
  58784. +
  58785. + if (chip) {
  58786. +
  58787. + if (!strcmp(chip, "st7735r")) {
  58788. + if (!width)
  58789. + width = 128;
  58790. + if (!height)
  58791. + height = 160;
  58792. + if (init_num == 0) {
  58793. + initp = st7735r_init;
  58794. + initp_num = ARRAY_SIZE(st7735r_init);
  58795. + }
  58796. +
  58797. +
  58798. + } else if (!strcmp(chip, "hx8340bn")) {
  58799. + if (!width)
  58800. + width = 176;
  58801. + if (!height)
  58802. + height = 220;
  58803. + setaddrwin = 0;
  58804. + if (init_num == 0) {
  58805. + initp = hx8340bn_init;
  58806. + initp_num = ARRAY_SIZE(hx8340bn_init);
  58807. + }
  58808. +
  58809. +
  58810. + } else if (!strcmp(chip, "ili9225")) {
  58811. + if (!width)
  58812. + width = 176;
  58813. + if (!height)
  58814. + height = 220;
  58815. + setaddrwin = 0;
  58816. + regwidth = 16;
  58817. + if (init_num == 0) {
  58818. + initp = ili9225_init;
  58819. + initp_num = ARRAY_SIZE(ili9225_init);
  58820. + }
  58821. +
  58822. +
  58823. +
  58824. + } else if (!strcmp(chip, "ili9320")) {
  58825. + if (!width)
  58826. + width = 240;
  58827. + if (!height)
  58828. + height = 320;
  58829. + setaddrwin = 1;
  58830. + regwidth = 16;
  58831. + if (init_num == 0) {
  58832. + initp = ili9320_init;
  58833. + initp_num = ARRAY_SIZE(ili9320_init);
  58834. + }
  58835. +
  58836. +
  58837. + } else if (!strcmp(chip, "ili9325")) {
  58838. + if (!width)
  58839. + width = 240;
  58840. + if (!height)
  58841. + height = 320;
  58842. + setaddrwin = 1;
  58843. + regwidth = 16;
  58844. + if (init_num == 0) {
  58845. + initp = ili9325_init;
  58846. + initp_num = ARRAY_SIZE(ili9325_init);
  58847. + }
  58848. +
  58849. + } else if (!strcmp(chip, "ili9341")) {
  58850. + if (!width)
  58851. + width = 240;
  58852. + if (!height)
  58853. + height = 320;
  58854. + setaddrwin = 0;
  58855. + regwidth = 8;
  58856. + if (init_num == 0) {
  58857. + initp = ili9341_init;
  58858. + initp_num = ARRAY_SIZE(ili9341_init);
  58859. + }
  58860. +
  58861. +
  58862. + } else if (!strcmp(chip, "ssd1289")) {
  58863. + if (!width)
  58864. + width = 240;
  58865. + if (!height)
  58866. + height = 320;
  58867. + setaddrwin = 2;
  58868. + regwidth = 16;
  58869. + if (init_num == 0) {
  58870. + initp = ssd1289_init;
  58871. + initp_num = ARRAY_SIZE(ssd1289_init);
  58872. + }
  58873. +
  58874. +
  58875. +
  58876. + } else if (!strcmp(chip, "ssd1351")) {
  58877. + if (!width)
  58878. + width = 128;
  58879. + if (!height)
  58880. + height = 128;
  58881. + setaddrwin = 3;
  58882. + if (init_num == 0) {
  58883. + initp = ssd1351_init;
  58884. + initp_num = ARRAY_SIZE(ssd1351_init);
  58885. + }
  58886. + } else {
  58887. + dev_err(dev, "chip=%s is not supported\n", chip);
  58888. + return -EINVAL;
  58889. + }
  58890. + }
  58891. +
  58892. + if (width == 0 || height == 0) {
  58893. + dev_err(dev, "argument(s) missing: width and height has to be set.\n");
  58894. + return -EINVAL;
  58895. + }
  58896. + flex_display.width = width;
  58897. + flex_display.height = height;
  58898. + fbtft_init_dbg(dev, "Display resolution: %dx%d\n", width, height);
  58899. + fbtft_init_dbg(dev, "chip = %s\n", chip ? chip : "not set");
  58900. + fbtft_init_dbg(dev, "setaddrwin = %d\n", setaddrwin);
  58901. + fbtft_init_dbg(dev, "regwidth = %d\n", regwidth);
  58902. + fbtft_init_dbg(dev, "buswidth = %d\n", buswidth);
  58903. +
  58904. + info = fbtft_framebuffer_alloc(&flex_display, dev);
  58905. + if (!info)
  58906. + return -ENOMEM;
  58907. +
  58908. + par = info->par;
  58909. + if (sdev)
  58910. + par->spi = sdev;
  58911. + else
  58912. + par->pdev = pdev;
  58913. + if (!par->init_sequence)
  58914. + par->init_sequence = initp;
  58915. + par->fbtftops.init_display = fbtft_init_display;
  58916. +
  58917. + /* registerwrite functions */
  58918. + switch (regwidth) {
  58919. + case 8:
  58920. + par->fbtftops.write_register = fbtft_write_reg8_bus8;
  58921. + break;
  58922. + case 16:
  58923. + par->fbtftops.write_register = fbtft_write_reg16_bus8;
  58924. + break;
  58925. + default:
  58926. + dev_err(dev, "argument 'regwidth': %d is not supported.\n", regwidth);
  58927. + return -EINVAL;
  58928. + }
  58929. +
  58930. + /* bus functions */
  58931. + if (sdev) {
  58932. + par->fbtftops.write = fbtft_write_spi;
  58933. + switch (buswidth) {
  58934. + case 8:
  58935. + par->fbtftops.write_vmem = fbtft_write_vmem16_bus8;
  58936. + if (!par->startbyte)
  58937. + par->fbtftops.verify_gpios = flexfb_verify_gpios_dc;
  58938. + break;
  58939. + case 9:
  58940. + if (regwidth == 16) {
  58941. + dev_err(dev, "argument 'regwidth': %d is not supported with buswidth=%d and SPI.\n", regwidth, buswidth);
  58942. + return -EINVAL;
  58943. + }
  58944. + par->fbtftops.write_register = fbtft_write_reg8_bus9;
  58945. + par->fbtftops.write_vmem = fbtft_write_vmem16_bus9;
  58946. + sdev->bits_per_word=9;
  58947. + ret = sdev->master->setup(sdev);
  58948. + if (ret) {
  58949. + dev_warn(dev,
  58950. + "9-bit SPI not available, emulating using 8-bit.\n");
  58951. + sdev->bits_per_word = 8;
  58952. + ret = sdev->master->setup(sdev);
  58953. + if (ret)
  58954. + goto out_release;
  58955. + /* allocate buffer with room for dc bits */
  58956. + par->extra = devm_kzalloc(par->info->device,
  58957. + par->txbuf.len + (par->txbuf.len / 8) + 8,
  58958. + GFP_KERNEL);
  58959. + if (!par->extra) {
  58960. + ret = -ENOMEM;
  58961. + goto out_release;
  58962. + }
  58963. + par->fbtftops.write = fbtft_write_spi_emulate_9;
  58964. + }
  58965. + break;
  58966. + default:
  58967. + dev_err(dev, "argument 'buswidth': %d is not supported with SPI.\n", buswidth);
  58968. + return -EINVAL;
  58969. + }
  58970. + } else {
  58971. + par->fbtftops.verify_gpios = flexfb_verify_gpios_db;
  58972. + switch (buswidth) {
  58973. + case 8:
  58974. + par->fbtftops.write = fbtft_write_gpio8_wr;
  58975. + par->fbtftops.write_vmem = fbtft_write_vmem16_bus8;
  58976. + break;
  58977. + case 16:
  58978. + par->fbtftops.write_register = fbtft_write_reg16_bus16;
  58979. + if (latched)
  58980. + par->fbtftops.write = fbtft_write_gpio16_wr_latched;
  58981. + else
  58982. + par->fbtftops.write = fbtft_write_gpio16_wr;
  58983. + par->fbtftops.write_vmem = fbtft_write_vmem16_bus16;
  58984. + break;
  58985. + default:
  58986. + dev_err(dev, "argument 'buswidth': %d is not supported with parallel.\n", buswidth);
  58987. + return -EINVAL;
  58988. + }
  58989. + }
  58990. +
  58991. + /* set_addr_win function */
  58992. + switch (setaddrwin) {
  58993. + case 0:
  58994. + /* use default */
  58995. + break;
  58996. + case 1:
  58997. + par->fbtftops.set_addr_win = flexfb_set_addr_win_1;
  58998. + break;
  58999. + case 2:
  59000. + par->fbtftops.set_addr_win = flexfb_set_addr_win_2;
  59001. + break;
  59002. + case 3:
  59003. + par->fbtftops.set_addr_win = set_addr_win_3;
  59004. + break;
  59005. + default:
  59006. + dev_err(dev, "argument 'setaddrwin': unknown value %d.\n", setaddrwin);
  59007. + return -EINVAL;
  59008. + }
  59009. +
  59010. + if (!nobacklight)
  59011. + par->fbtftops.register_backlight = fbtft_register_backlight;
  59012. +
  59013. + ret = fbtft_register_framebuffer(info);
  59014. + if (ret < 0)
  59015. + goto out_release;
  59016. +
  59017. + return 0;
  59018. +
  59019. +out_release:
  59020. + fbtft_framebuffer_release(info);
  59021. +
  59022. + return ret;
  59023. +}
  59024. +
  59025. +static int flexfb_remove_common(struct device *dev, struct fb_info *info)
  59026. +{
  59027. + struct fbtft_par *par;
  59028. +
  59029. + if (!info)
  59030. + return -EINVAL;
  59031. + par = info->par;
  59032. + if (par)
  59033. + fbtft_par_dbg(DEBUG_DRIVER_INIT_FUNCTIONS, par,
  59034. + "%s()\n", __func__);
  59035. + fbtft_unregister_framebuffer(info);
  59036. + fbtft_framebuffer_release(info);
  59037. +
  59038. + return 0;
  59039. +}
  59040. +
  59041. +static int flexfb_probe_spi(struct spi_device *spi)
  59042. +{
  59043. + return flexfb_probe_common(spi, NULL);
  59044. +}
  59045. +
  59046. +static int flexfb_remove_spi(struct spi_device *spi)
  59047. +{
  59048. + struct fb_info *info = spi_get_drvdata(spi);
  59049. +
  59050. + return flexfb_remove_common(&spi->dev, info);
  59051. +}
  59052. +
  59053. +static int flexfb_probe_pdev(struct platform_device *pdev)
  59054. +{
  59055. + return flexfb_probe_common(NULL, pdev);
  59056. +}
  59057. +
  59058. +static int flexfb_remove_pdev(struct platform_device *pdev)
  59059. +{
  59060. + struct fb_info *info = platform_get_drvdata(pdev);
  59061. +
  59062. + return flexfb_remove_common(&pdev->dev, info);
  59063. +}
  59064. +
  59065. +static struct spi_driver flexfb_spi_driver = {
  59066. + .driver = {
  59067. + .name = DRVNAME,
  59068. + .owner = THIS_MODULE,
  59069. + },
  59070. + .probe = flexfb_probe_spi,
  59071. + .remove = flexfb_remove_spi,
  59072. +};
  59073. +
  59074. +static const struct platform_device_id flexfb_platform_ids[] = {
  59075. + { "flexpfb", 0 },
  59076. + { },
  59077. +};
  59078. +
  59079. +static struct platform_driver flexfb_platform_driver = {
  59080. + .driver = {
  59081. + .name = DRVNAME,
  59082. + },
  59083. + .id_table = flexfb_platform_ids,
  59084. + .probe = flexfb_probe_pdev,
  59085. + .remove = flexfb_remove_pdev,
  59086. +};
  59087. +
  59088. +static int __init flexfb_init(void)
  59089. +{
  59090. + int ret, ret2;
  59091. +
  59092. + ret = spi_register_driver(&flexfb_spi_driver);
  59093. + ret2 = platform_driver_register(&flexfb_platform_driver);
  59094. + if (ret < 0)
  59095. + return ret;
  59096. + return ret2;
  59097. +}
  59098. +
  59099. +static void __exit flexfb_exit(void)
  59100. +{
  59101. + spi_unregister_driver(&flexfb_spi_driver);
  59102. + platform_driver_unregister(&flexfb_platform_driver);
  59103. +}
  59104. +
  59105. +/* ------------------------------------------------------------------------- */
  59106. +
  59107. +module_init(flexfb_init);
  59108. +module_exit(flexfb_exit);
  59109. +
  59110. +MODULE_DESCRIPTION("Generic FB driver for TFT LCD displays");
  59111. +MODULE_AUTHOR("Noralf Tronnes");
  59112. +MODULE_LICENSE("GPL");
  59113. diff -Nur linux-3.18.8/drivers/staging/fbtft/Kconfig linux-rpi/drivers/staging/fbtft/Kconfig
  59114. --- linux-3.18.8/drivers/staging/fbtft/Kconfig 1970-01-01 01:00:00.000000000 +0100
  59115. +++ linux-rpi/drivers/staging/fbtft/Kconfig 2015-03-05 14:40:16.341715808 +0100
  59116. @@ -0,0 +1,169 @@
  59117. +menuconfig FB_TFT
  59118. + tristate "Support for small TFT LCD display modules"
  59119. + depends on FB && SPI && GPIOLIB
  59120. + select FB_SYS_FILLRECT
  59121. + select FB_SYS_COPYAREA
  59122. + select FB_SYS_IMAGEBLIT
  59123. + select FB_SYS_FOPS
  59124. + select FB_DEFERRED_IO
  59125. + select FB_BACKLIGHT
  59126. +
  59127. +config FB_TFT_AGM1264K_FL
  59128. + tristate "FB driver for the AGM1264K-FL LCD display"
  59129. + depends on FB_TFT
  59130. + help
  59131. + Framebuffer support for the AGM1264K-FL LCD display (two Samsung KS0108 compatable chips)
  59132. +
  59133. +config FB_TFT_BD663474
  59134. + tristate "FB driver for the BD663474 LCD Controller"
  59135. + depends on FB_TFT
  59136. + help
  59137. + Generic Framebuffer support for BD663474
  59138. +
  59139. +config FB_TFT_HX8340BN
  59140. + tristate "FB driver for the HX8340BN LCD Controller"
  59141. + depends on FB_TFT
  59142. + help
  59143. + Generic Framebuffer support for HX8340BN
  59144. +
  59145. +config FB_TFT_HX8347D
  59146. + tristate "FB driver for the HX8347D LCD Controller"
  59147. + depends on FB_TFT
  59148. + help
  59149. + Generic Framebuffer support for HX8347D
  59150. +
  59151. +config FB_TFT_HX8353D
  59152. + tristate "FB driver for the HX8353D LCD Controller"
  59153. + depends on FB_TFT
  59154. + help
  59155. + Generic Framebuffer support for HX8353D
  59156. +
  59157. +config FB_TFT_ILI9320
  59158. + tristate "FB driver for the ILI9320 LCD Controller"
  59159. + depends on FB_TFT
  59160. + help
  59161. + Generic Framebuffer support for ILI9320
  59162. +
  59163. +config FB_TFT_ILI9325
  59164. + tristate "FB driver for the ILI9325 LCD Controller"
  59165. + depends on FB_TFT
  59166. + help
  59167. + Generic Framebuffer support for ILI9325
  59168. +
  59169. +config FB_TFT_ILI9340
  59170. + tristate "FB driver for the ILI9340 LCD Controller"
  59171. + depends on FB_TFT
  59172. + help
  59173. + Generic Framebuffer support for ILI9340
  59174. +
  59175. +config FB_TFT_ILI9341
  59176. + tristate "FB driver for the ILI9341 LCD Controller"
  59177. + depends on FB_TFT
  59178. + help
  59179. + Generic Framebuffer support for ILI9341
  59180. +
  59181. +config FB_TFT_ILI9481
  59182. + tristate "FB driver for the ILI9481 LCD Controller"
  59183. + depends on FB_TFT
  59184. + help
  59185. + Generic Framebuffer support for ILI9481
  59186. +
  59187. +config FB_TFT_ILI9486
  59188. + tristate "FB driver for the ILI9486 LCD Controller"
  59189. + depends on FB_TFT
  59190. + help
  59191. + Generic Framebuffer support for ILI9486
  59192. +
  59193. +config FB_TFT_PCD8544
  59194. + tristate "FB driver for the PCD8544 LCD Controller"
  59195. + depends on FB_TFT
  59196. + help
  59197. + Generic Framebuffer support for PCD8544
  59198. +
  59199. +config FB_TFT_RA8875
  59200. + tristate "FB driver for the RA8875 LCD Controller"
  59201. + depends on FB_TFT
  59202. + help
  59203. + Generic Framebuffer support for RA8875
  59204. +
  59205. +config FB_TFT_S6D02A1
  59206. + tristate "FB driver for the S6D02A1 LCD Controller"
  59207. + depends on FB_TFT
  59208. + help
  59209. + Generic Framebuffer support for S6D02A1
  59210. +
  59211. +config FB_TFT_S6D1121
  59212. + tristate "FB driver for the S6D1211 LCD Controller"
  59213. + depends on FB_TFT
  59214. + help
  59215. + Generic Framebuffer support for S6D1121
  59216. +
  59217. +config FB_TFT_SSD1289
  59218. + tristate "FB driver for the SSD1289 LCD Controller"
  59219. + depends on FB_TFT
  59220. + help
  59221. + Framebuffer support for SSD1289
  59222. +
  59223. +config FB_TFT_SSD1306
  59224. + tristate "FB driver for the SSD1306 OLED Controller"
  59225. + depends on FB_TFT
  59226. + help
  59227. + Framebuffer support for SSD1306
  59228. +
  59229. +config FB_TFT_SSD1331
  59230. + tristate "FB driver for the SSD1331 LCD Controller"
  59231. + depends on FB_TFT
  59232. + help
  59233. + Framebuffer support for SSD1331
  59234. +
  59235. +config FB_TFT_SSD1351
  59236. + tristate "FB driver for the SSD1351 LCD Controller"
  59237. + depends on FB_TFT
  59238. + help
  59239. + Framebuffer support for SSD1351
  59240. +
  59241. +config FB_TFT_ST7735R
  59242. + tristate "FB driver for the ST7735R LCD Controller"
  59243. + depends on FB_TFT
  59244. + help
  59245. + Generic Framebuffer support for ST7735R
  59246. +
  59247. +config FB_TFT_TINYLCD
  59248. + tristate "FB driver for tinylcd.com display"
  59249. + depends on FB_TFT
  59250. + help
  59251. + Custom Framebuffer support for tinylcd.com display
  59252. +
  59253. +config FB_TFT_TLS8204
  59254. + tristate "FB driver for the TLS8204 LCD Controller"
  59255. + depends on FB_TFT
  59256. + help
  59257. + Generic Framebuffer support for TLS8204
  59258. +
  59259. +config FB_TFT_UC1701
  59260. + tristate "FB driver for the UC1701 LCD Controller"
  59261. + depends on FB_TFT
  59262. + help
  59263. + Generic Framebuffer support for UC1701
  59264. +
  59265. +config FB_TFT_UPD161704
  59266. + tristate "FB driver for the uPD161704 LCD Controller"
  59267. + depends on FB_TFT
  59268. + help
  59269. + Generic Framebuffer support for uPD161704
  59270. +
  59271. +config FB_TFT_WATTEROTT
  59272. + tristate "FB driver for the WATTEROTT LCD Controller"
  59273. + depends on FB_TFT
  59274. + help
  59275. + Generic Framebuffer support for WATTEROTT
  59276. +
  59277. +config FB_FLEX
  59278. + tristate "Generic FB driver for TFT LCD displays"
  59279. + depends on FB_TFT
  59280. + help
  59281. + Generic Framebuffer support for TFT LCD displays.
  59282. +
  59283. +config FB_TFT_FBTFT_DEVICE
  59284. + tristate "Module to for adding FBTFT devices"
  59285. + depends on FB_TFT
  59286. diff -Nur linux-3.18.8/drivers/staging/fbtft/Makefile linux-rpi/drivers/staging/fbtft/Makefile
  59287. --- linux-3.18.8/drivers/staging/fbtft/Makefile 1970-01-01 01:00:00.000000000 +0100
  59288. +++ linux-rpi/drivers/staging/fbtft/Makefile 2015-03-05 14:40:16.341715808 +0100
  59289. @@ -0,0 +1,34 @@
  59290. +# Core module
  59291. +obj-$(CONFIG_FB_TFT) += fbtft.o
  59292. +fbtft-y += fbtft-core.o fbtft-sysfs.o fbtft-bus.o fbtft-io.o
  59293. +
  59294. +# drivers
  59295. +obj-$(CONFIG_FB_TFT_AGM1264K_FL) += fb_agm1264k-fl.o
  59296. +obj-$(CONFIG_FB_TFT_BD663474) += fb_bd663474.o
  59297. +obj-$(CONFIG_FB_TFT_HX8340BN) += fb_hx8340bn.o
  59298. +obj-$(CONFIG_FB_TFT_HX8347D) += fb_hx8347d.o
  59299. +obj-$(CONFIG_FB_TFT_HX8353D) += fb_hx8353d.o
  59300. +obj-$(CONFIG_FB_TFT_ILI9320) += fb_ili9320.o
  59301. +obj-$(CONFIG_FB_TFT_ILI9325) += fb_ili9325.o
  59302. +obj-$(CONFIG_FB_TFT_ILI9340) += fb_ili9340.o
  59303. +obj-$(CONFIG_FB_TFT_ILI9341) += fb_ili9341.o
  59304. +obj-$(CONFIG_FB_TFT_ILI9481) += fb_ili9481.o
  59305. +obj-$(CONFIG_FB_TFT_ILI9486) += fb_ili9486.o
  59306. +obj-$(CONFIG_FB_TFT_PCD8544) += fb_pcd8544.o
  59307. +obj-$(CONFIG_FB_TFT_RA8875) += fb_ra8875.o
  59308. +obj-$(CONFIG_FB_TFT_S6D02A1) += fb_s6d02a1.o
  59309. +obj-$(CONFIG_FB_TFT_S6D1121) += fb_s6d1121.o
  59310. +obj-$(CONFIG_FB_TFT_SSD1289) += fb_ssd1289.o
  59311. +obj-$(CONFIG_FB_TFT_SSD1306) += fb_ssd1306.o
  59312. +obj-$(CONFIG_FB_TFT_SSD1331) += fb_ssd1331.o
  59313. +obj-$(CONFIG_FB_TFT_SSD1351) += fb_ssd1351.o
  59314. +obj-$(CONFIG_FB_TFT_ST7735R) += fb_st7735r.o
  59315. +obj-$(CONFIG_FB_TFT_TINYLCD) += fb_tinylcd.o
  59316. +obj-$(CONFIG_FB_TFT_TLS8204) += fb_tls8204.o
  59317. +obj-$(CONFIG_FB_TFT_UC1701) += fb_uc1701.o
  59318. +obj-$(CONFIG_FB_TFT_UPD161704) += fb_upd161704.o
  59319. +obj-$(CONFIG_FB_TFT_WATTEROTT) += fb_watterott.o
  59320. +obj-$(CONFIG_FB_FLEX) += flexfb.o
  59321. +
  59322. +# Device modules
  59323. +obj-$(CONFIG_FB_TFT_FBTFT_DEVICE) += fbtft_device.o
  59324. diff -Nur linux-3.18.8/drivers/staging/fbtft/README linux-rpi/drivers/staging/fbtft/README
  59325. --- linux-3.18.8/drivers/staging/fbtft/README 1970-01-01 01:00:00.000000000 +0100
  59326. +++ linux-rpi/drivers/staging/fbtft/README 2015-03-05 14:40:16.341715808 +0100
  59327. @@ -0,0 +1,32 @@
  59328. + FBTFT
  59329. +=========
  59330. +
  59331. +Linux Framebuffer drivers for small TFT LCD display modules.
  59332. +The module 'fbtft' makes writing drivers for some of these displays very easy.
  59333. +
  59334. +Development is done on a Raspberry Pi running the Raspbian "wheezy" distribution.
  59335. +
  59336. +INSTALLATION
  59337. + Download kernel sources
  59338. +
  59339. + From Linux 3.15
  59340. + cd drivers/video/fbdev/fbtft
  59341. + git clone https://github.com/notro/fbtft.git
  59342. +
  59343. + Add to drivers/video/fbdev/Kconfig: source "drivers/video/fbdev/fbtft/Kconfig"
  59344. + Add to drivers/video/fbdev/Makefile: obj-y += fbtft/
  59345. +
  59346. + Before Linux 3.15
  59347. + cd drivers/video
  59348. + git clone https://github.com/notro/fbtft.git
  59349. +
  59350. + Add to drivers/video/Kconfig: source "drivers/video/fbtft/Kconfig"
  59351. + Add to drivers/video/Makefile: obj-y += fbtft/
  59352. +
  59353. + Enable driver(s) in menuconfig and build the kernel
  59354. +
  59355. +
  59356. +See wiki for more information: https://github.com/notro/fbtft/wiki
  59357. +
  59358. +
  59359. +Source: https://github.com/notro/fbtft/
  59360. diff -Nur linux-3.18.8/drivers/staging/Kconfig linux-rpi/drivers/staging/Kconfig
  59361. --- linux-3.18.8/drivers/staging/Kconfig 2015-02-27 02:49:36.000000000 +0100
  59362. +++ linux-rpi/drivers/staging/Kconfig 2015-03-05 14:40:16.309715808 +0100
  59363. @@ -108,4 +108,6 @@
  59364. source "drivers/staging/unisys/Kconfig"
  59365. +source "drivers/staging/fbtft/Kconfig"
  59366. +
  59367. endif # STAGING
  59368. diff -Nur linux-3.18.8/drivers/staging/Makefile linux-rpi/drivers/staging/Makefile
  59369. --- linux-3.18.8/drivers/staging/Makefile 2015-02-27 02:49:36.000000000 +0100
  59370. +++ linux-rpi/drivers/staging/Makefile 2015-03-05 14:40:16.309715808 +0100
  59371. @@ -46,3 +46,4 @@
  59372. obj-$(CONFIG_GS_FPGABOOT) += gs_fpgaboot/
  59373. obj-$(CONFIG_CRYPTO_SKEIN) += skein/
  59374. obj-$(CONFIG_UNISYSSPAR) += unisys/
  59375. +obj-$(CONFIG_FB_TFT) += fbtft/
  59376. diff -Nur linux-3.18.8/drivers/staging/media/lirc/Kconfig linux-rpi/drivers/staging/media/lirc/Kconfig
  59377. --- linux-3.18.8/drivers/staging/media/lirc/Kconfig 2015-02-27 02:49:36.000000000 +0100
  59378. +++ linux-rpi/drivers/staging/media/lirc/Kconfig 2015-03-05 14:40:16.401715807 +0100
  59379. @@ -38,6 +38,12 @@
  59380. help
  59381. Driver for Homebrew Parallel Port Receivers
  59382. +config LIRC_RPI
  59383. + tristate "Homebrew GPIO Port Receiver/Transmitter for the RaspberryPi"
  59384. + depends on LIRC
  59385. + help
  59386. + Driver for Homebrew GPIO Port Receiver/Transmitter for the RaspberryPi
  59387. +
  59388. config LIRC_SASEM
  59389. tristate "Sasem USB IR Remote"
  59390. depends on LIRC && USB
  59391. diff -Nur linux-3.18.8/drivers/staging/media/lirc/lirc_rpi.c linux-rpi/drivers/staging/media/lirc/lirc_rpi.c
  59392. --- linux-3.18.8/drivers/staging/media/lirc/lirc_rpi.c 1970-01-01 01:00:00.000000000 +0100
  59393. +++ linux-rpi/drivers/staging/media/lirc/lirc_rpi.c 2015-03-05 14:40:16.401715807 +0100
  59394. @@ -0,0 +1,765 @@
  59395. +/*
  59396. + * lirc_rpi.c
  59397. + *
  59398. + * lirc_rpi - Device driver that records pulse- and pause-lengths
  59399. + * (space-lengths) (just like the lirc_serial driver does)
  59400. + * between GPIO interrupt events on the Raspberry Pi.
  59401. + * Lots of code has been taken from the lirc_serial module,
  59402. + * so I would like say thanks to the authors.
  59403. + *
  59404. + * Copyright (C) 2012 Aron Robert Szabo <aron@reon.hu>,
  59405. + * Michael Bishop <cleverca22@gmail.com>
  59406. + * This program is free software; you can redistribute it and/or modify
  59407. + * it under the terms of the GNU General Public License as published by
  59408. + * the Free Software Foundation; either version 2 of the License, or
  59409. + * (at your option) any later version.
  59410. + *
  59411. + * This program is distributed in the hope that it will be useful,
  59412. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  59413. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  59414. + * GNU General Public License for more details.
  59415. + *
  59416. + * You should have received a copy of the GNU General Public License
  59417. + * along with this program; if not, write to the Free Software
  59418. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  59419. + */
  59420. +
  59421. +#include <linux/module.h>
  59422. +#include <linux/errno.h>
  59423. +#include <linux/interrupt.h>
  59424. +#include <linux/sched.h>
  59425. +#include <linux/kernel.h>
  59426. +#include <linux/time.h>
  59427. +#include <linux/timex.h>
  59428. +#include <linux/timekeeping.h>
  59429. +#include <linux/string.h>
  59430. +#include <linux/delay.h>
  59431. +#include <linux/platform_device.h>
  59432. +#include <linux/irq.h>
  59433. +#include <linux/spinlock.h>
  59434. +#include <media/lirc.h>
  59435. +#include <media/lirc_dev.h>
  59436. +#include <mach/gpio.h>
  59437. +#include <linux/gpio.h>
  59438. +#include <linux/of_platform.h>
  59439. +
  59440. +#include <linux/platform_data/bcm2708.h>
  59441. +
  59442. +#define LIRC_DRIVER_NAME "lirc_rpi"
  59443. +#define RBUF_LEN 256
  59444. +#define LIRC_TRANSMITTER_LATENCY 50
  59445. +
  59446. +#ifndef MAX_UDELAY_MS
  59447. +#define MAX_UDELAY_US 5000
  59448. +#else
  59449. +#define MAX_UDELAY_US (MAX_UDELAY_MS*1000)
  59450. +#endif
  59451. +
  59452. +#define dprintk(fmt, args...) \
  59453. + do { \
  59454. + if (debug) \
  59455. + printk(KERN_DEBUG LIRC_DRIVER_NAME ": " \
  59456. + fmt, ## args); \
  59457. + } while (0)
  59458. +
  59459. +/* module parameters */
  59460. +
  59461. +/* set the default GPIO input pin */
  59462. +static int gpio_in_pin = 18;
  59463. +/* set the default pull behaviour for input pin */
  59464. +static int gpio_in_pull = BCM2708_PULL_DOWN;
  59465. +/* set the default GPIO output pin */
  59466. +static int gpio_out_pin = 17;
  59467. +/* enable debugging messages */
  59468. +static bool debug;
  59469. +/* -1 = auto, 0 = active high, 1 = active low */
  59470. +static int sense = -1;
  59471. +/* use softcarrier by default */
  59472. +static bool softcarrier = 1;
  59473. +/* 0 = do not invert output, 1 = invert output */
  59474. +static bool invert = 0;
  59475. +
  59476. +struct gpio_chip *gpiochip;
  59477. +static int irq_num;
  59478. +
  59479. +/* forward declarations */
  59480. +static long send_pulse(unsigned long length);
  59481. +static void send_space(long length);
  59482. +static void lirc_rpi_exit(void);
  59483. +
  59484. +static struct platform_device *lirc_rpi_dev;
  59485. +static struct timeval lasttv = { 0, 0 };
  59486. +static struct lirc_buffer rbuf;
  59487. +static spinlock_t lock;
  59488. +
  59489. +/* initialized/set in init_timing_params() */
  59490. +static unsigned int freq = 38000;
  59491. +static unsigned int duty_cycle = 50;
  59492. +static unsigned long period;
  59493. +static unsigned long pulse_width;
  59494. +static unsigned long space_width;
  59495. +
  59496. +static void safe_udelay(unsigned long usecs)
  59497. +{
  59498. + while (usecs > MAX_UDELAY_US) {
  59499. + udelay(MAX_UDELAY_US);
  59500. + usecs -= MAX_UDELAY_US;
  59501. + }
  59502. + udelay(usecs);
  59503. +}
  59504. +
  59505. +static unsigned long read_current_us(void)
  59506. +{
  59507. + struct timespec now;
  59508. + getnstimeofday(&now);
  59509. + return (now.tv_sec * 1000000) + (now.tv_nsec/1000);
  59510. +}
  59511. +
  59512. +static int init_timing_params(unsigned int new_duty_cycle,
  59513. + unsigned int new_freq)
  59514. +{
  59515. + if (1000 * 1000000L / new_freq * new_duty_cycle / 100 <=
  59516. + LIRC_TRANSMITTER_LATENCY)
  59517. + return -EINVAL;
  59518. + if (1000 * 1000000L / new_freq * (100 - new_duty_cycle) / 100 <=
  59519. + LIRC_TRANSMITTER_LATENCY)
  59520. + return -EINVAL;
  59521. + duty_cycle = new_duty_cycle;
  59522. + freq = new_freq;
  59523. + period = 1000 * 1000000L / freq;
  59524. + pulse_width = period * duty_cycle / 100;
  59525. + space_width = period - pulse_width;
  59526. + dprintk("in init_timing_params, freq=%d pulse=%ld, "
  59527. + "space=%ld\n", freq, pulse_width, space_width);
  59528. + return 0;
  59529. +}
  59530. +
  59531. +static long send_pulse_softcarrier(unsigned long length)
  59532. +{
  59533. + int flag;
  59534. + unsigned long actual, target;
  59535. + unsigned long actual_us, initial_us, target_us;
  59536. +
  59537. + length *= 1000;
  59538. +
  59539. + actual = 0; target = 0; flag = 0;
  59540. + actual_us = read_current_us();
  59541. +
  59542. + while (actual < length) {
  59543. + if (flag) {
  59544. + gpiochip->set(gpiochip, gpio_out_pin, invert);
  59545. + target += space_width;
  59546. + } else {
  59547. + gpiochip->set(gpiochip, gpio_out_pin, !invert);
  59548. + target += pulse_width;
  59549. + }
  59550. + initial_us = actual_us;
  59551. + target_us = actual_us + (target - actual) / 1000;
  59552. + /*
  59553. + * Note - we've checked in ioctl that the pulse/space
  59554. + * widths are big enough so that d is > 0
  59555. + */
  59556. + if ((int)(target_us - actual_us) > 0)
  59557. + udelay(target_us - actual_us);
  59558. + actual_us = read_current_us();
  59559. + actual += (actual_us - initial_us) * 1000;
  59560. + flag = !flag;
  59561. + }
  59562. + return (actual-length) / 1000;
  59563. +}
  59564. +
  59565. +static long send_pulse(unsigned long length)
  59566. +{
  59567. + if (length <= 0)
  59568. + return 0;
  59569. +
  59570. + if (softcarrier) {
  59571. + return send_pulse_softcarrier(length);
  59572. + } else {
  59573. + gpiochip->set(gpiochip, gpio_out_pin, !invert);
  59574. + safe_udelay(length);
  59575. + return 0;
  59576. + }
  59577. +}
  59578. +
  59579. +static void send_space(long length)
  59580. +{
  59581. + gpiochip->set(gpiochip, gpio_out_pin, invert);
  59582. + if (length <= 0)
  59583. + return;
  59584. + safe_udelay(length);
  59585. +}
  59586. +
  59587. +static void rbwrite(int l)
  59588. +{
  59589. + if (lirc_buffer_full(&rbuf)) {
  59590. + /* no new signals will be accepted */
  59591. + dprintk("Buffer overrun\n");
  59592. + return;
  59593. + }
  59594. + lirc_buffer_write(&rbuf, (void *)&l);
  59595. +}
  59596. +
  59597. +static void frbwrite(int l)
  59598. +{
  59599. + /* simple noise filter */
  59600. + static int pulse, space;
  59601. + static unsigned int ptr;
  59602. +
  59603. + if (ptr > 0 && (l & PULSE_BIT)) {
  59604. + pulse += l & PULSE_MASK;
  59605. + if (pulse > 250) {
  59606. + rbwrite(space);
  59607. + rbwrite(pulse | PULSE_BIT);
  59608. + ptr = 0;
  59609. + pulse = 0;
  59610. + }
  59611. + return;
  59612. + }
  59613. + if (!(l & PULSE_BIT)) {
  59614. + if (ptr == 0) {
  59615. + if (l > 20000) {
  59616. + space = l;
  59617. + ptr++;
  59618. + return;
  59619. + }
  59620. + } else {
  59621. + if (l > 20000) {
  59622. + space += pulse;
  59623. + if (space > PULSE_MASK)
  59624. + space = PULSE_MASK;
  59625. + space += l;
  59626. + if (space > PULSE_MASK)
  59627. + space = PULSE_MASK;
  59628. + pulse = 0;
  59629. + return;
  59630. + }
  59631. + rbwrite(space);
  59632. + rbwrite(pulse | PULSE_BIT);
  59633. + ptr = 0;
  59634. + pulse = 0;
  59635. + }
  59636. + }
  59637. + rbwrite(l);
  59638. +}
  59639. +
  59640. +static irqreturn_t irq_handler(int i, void *blah, struct pt_regs *regs)
  59641. +{
  59642. + struct timeval tv;
  59643. + long deltv;
  59644. + int data;
  59645. + int signal;
  59646. +
  59647. + /* use the GPIO signal level */
  59648. + signal = gpiochip->get(gpiochip, gpio_in_pin);
  59649. +
  59650. + if (sense != -1) {
  59651. + /* get current time */
  59652. + do_gettimeofday(&tv);
  59653. +
  59654. + /* calc time since last interrupt in microseconds */
  59655. + deltv = tv.tv_sec-lasttv.tv_sec;
  59656. + if (tv.tv_sec < lasttv.tv_sec ||
  59657. + (tv.tv_sec == lasttv.tv_sec &&
  59658. + tv.tv_usec < lasttv.tv_usec)) {
  59659. + printk(KERN_WARNING LIRC_DRIVER_NAME
  59660. + ": AIEEEE: your clock just jumped backwards\n");
  59661. + printk(KERN_WARNING LIRC_DRIVER_NAME
  59662. + ": %d %d %lx %lx %lx %lx\n", signal, sense,
  59663. + tv.tv_sec, lasttv.tv_sec,
  59664. + tv.tv_usec, lasttv.tv_usec);
  59665. + data = PULSE_MASK;
  59666. + } else if (deltv > 15) {
  59667. + data = PULSE_MASK; /* really long time */
  59668. + if (!(signal^sense)) {
  59669. + /* sanity check */
  59670. + printk(KERN_WARNING LIRC_DRIVER_NAME
  59671. + ": AIEEEE: %d %d %lx %lx %lx %lx\n",
  59672. + signal, sense, tv.tv_sec, lasttv.tv_sec,
  59673. + tv.tv_usec, lasttv.tv_usec);
  59674. + /*
  59675. + * detecting pulse while this
  59676. + * MUST be a space!
  59677. + */
  59678. + sense = sense ? 0 : 1;
  59679. + }
  59680. + } else {
  59681. + data = (int) (deltv*1000000 +
  59682. + (tv.tv_usec - lasttv.tv_usec));
  59683. + }
  59684. + frbwrite(signal^sense ? data : (data|PULSE_BIT));
  59685. + lasttv = tv;
  59686. + wake_up_interruptible(&rbuf.wait_poll);
  59687. + }
  59688. +
  59689. + return IRQ_HANDLED;
  59690. +}
  59691. +
  59692. +static int is_right_chip(struct gpio_chip *chip, void *data)
  59693. +{
  59694. + dprintk("is_right_chip %s %d\n", chip->label, strcmp(data, chip->label));
  59695. +
  59696. + if (strcmp(data, chip->label) == 0)
  59697. + return 1;
  59698. + return 0;
  59699. +}
  59700. +
  59701. +static inline int read_bool_property(const struct device_node *np,
  59702. + const char *propname,
  59703. + bool *out_value)
  59704. +{
  59705. + u32 value = 0;
  59706. + int err = of_property_read_u32(np, propname, &value);
  59707. + if (err == 0)
  59708. + *out_value = (value != 0);
  59709. + return err;
  59710. +}
  59711. +
  59712. +static void read_pin_settings(struct device_node *node)
  59713. +{
  59714. + u32 pin;
  59715. + int index;
  59716. +
  59717. + for (index = 0;
  59718. + of_property_read_u32_index(
  59719. + node,
  59720. + "brcm,pins",
  59721. + index,
  59722. + &pin) == 0;
  59723. + index++) {
  59724. + u32 function;
  59725. + int err;
  59726. + err = of_property_read_u32_index(
  59727. + node,
  59728. + "brcm,function",
  59729. + index,
  59730. + &function);
  59731. + if (err == 0) {
  59732. + if (function == 1) /* Output */
  59733. + gpio_out_pin = pin;
  59734. + else if (function == 0) /* Input */
  59735. + gpio_in_pin = pin;
  59736. + }
  59737. + }
  59738. +}
  59739. +
  59740. +static int init_port(void)
  59741. +{
  59742. + int i, nlow, nhigh, ret;
  59743. + struct device_node *node;
  59744. +
  59745. + node = lirc_rpi_dev->dev.of_node;
  59746. +
  59747. + gpiochip = gpiochip_find("bcm2708_gpio", is_right_chip);
  59748. +
  59749. + /*
  59750. + * Because of the lack of a setpull function, only support
  59751. + * pinctrl-bcm2835 if using device tree.
  59752. + */
  59753. + if (!gpiochip && node)
  59754. + gpiochip = gpiochip_find("pinctrl-bcm2835", is_right_chip);
  59755. +
  59756. + if (!gpiochip) {
  59757. + pr_err(LIRC_DRIVER_NAME ": gpio chip not found!\n");
  59758. + return -ENODEV;
  59759. + }
  59760. +
  59761. + if (node) {
  59762. + struct device_node *pins_node;
  59763. +
  59764. + pins_node = of_parse_phandle(node, "pinctrl-0", 0);
  59765. + if (!pins_node) {
  59766. + printk(KERN_ERR LIRC_DRIVER_NAME
  59767. + ": pinctrl settings not found!\n");
  59768. + ret = -EINVAL;
  59769. + goto exit_init_port;
  59770. + }
  59771. +
  59772. + read_pin_settings(pins_node);
  59773. +
  59774. + of_property_read_u32(node, "rpi,sense", &sense);
  59775. +
  59776. + read_bool_property(node, "rpi,softcarrier", &softcarrier);
  59777. +
  59778. + read_bool_property(node, "rpi,invert", &invert);
  59779. +
  59780. + read_bool_property(node, "rpi,debug", &debug);
  59781. +
  59782. + }
  59783. + else
  59784. + {
  59785. + if (gpio_in_pin >= BCM2708_NR_GPIOS ||
  59786. + gpio_out_pin >= BCM2708_NR_GPIOS) {
  59787. + ret = -EINVAL;
  59788. + printk(KERN_ERR LIRC_DRIVER_NAME
  59789. + ": invalid GPIO pin(s) specified!\n");
  59790. + goto exit_init_port;
  59791. + }
  59792. +
  59793. + if (gpio_request(gpio_out_pin, LIRC_DRIVER_NAME " ir/out")) {
  59794. + printk(KERN_ALERT LIRC_DRIVER_NAME
  59795. + ": cant claim gpio pin %d\n", gpio_out_pin);
  59796. + ret = -ENODEV;
  59797. + goto exit_init_port;
  59798. + }
  59799. +
  59800. + if (gpio_request(gpio_in_pin, LIRC_DRIVER_NAME " ir/in")) {
  59801. + printk(KERN_ALERT LIRC_DRIVER_NAME
  59802. + ": cant claim gpio pin %d\n", gpio_in_pin);
  59803. + ret = -ENODEV;
  59804. + goto exit_gpio_free_out_pin;
  59805. + }
  59806. +
  59807. + bcm2708_gpio_setpull(gpiochip, gpio_in_pin, gpio_in_pull);
  59808. + gpiochip->direction_input(gpiochip, gpio_in_pin);
  59809. + gpiochip->direction_output(gpiochip, gpio_out_pin, 1);
  59810. + }
  59811. +
  59812. + gpiochip->set(gpiochip, gpio_out_pin, invert);
  59813. +
  59814. + irq_num = gpiochip->to_irq(gpiochip, gpio_in_pin);
  59815. + dprintk("to_irq %d\n", irq_num);
  59816. +
  59817. + /* if pin is high, then this must be an active low receiver. */
  59818. + if (sense == -1) {
  59819. + /* wait 1/2 sec for the power supply */
  59820. + msleep(500);
  59821. +
  59822. + /*
  59823. + * probe 9 times every 0.04s, collect "votes" for
  59824. + * active high/low
  59825. + */
  59826. + nlow = 0;
  59827. + nhigh = 0;
  59828. + for (i = 0; i < 9; i++) {
  59829. + if (gpiochip->get(gpiochip, gpio_in_pin))
  59830. + nlow++;
  59831. + else
  59832. + nhigh++;
  59833. + msleep(40);
  59834. + }
  59835. + sense = (nlow >= nhigh ? 1 : 0);
  59836. + printk(KERN_INFO LIRC_DRIVER_NAME
  59837. + ": auto-detected active %s receiver on GPIO pin %d\n",
  59838. + sense ? "low" : "high", gpio_in_pin);
  59839. + } else {
  59840. + printk(KERN_INFO LIRC_DRIVER_NAME
  59841. + ": manually using active %s receiver on GPIO pin %d\n",
  59842. + sense ? "low" : "high", gpio_in_pin);
  59843. + }
  59844. +
  59845. + return 0;
  59846. +
  59847. + exit_gpio_free_out_pin:
  59848. + gpio_free(gpio_out_pin);
  59849. +
  59850. + exit_init_port:
  59851. + return ret;
  59852. +}
  59853. +
  59854. +// called when the character device is opened
  59855. +static int set_use_inc(void *data)
  59856. +{
  59857. + int result;
  59858. +
  59859. + /* initialize timestamp */
  59860. + do_gettimeofday(&lasttv);
  59861. +
  59862. + result = request_irq(irq_num,
  59863. + (irq_handler_t) irq_handler,
  59864. + IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING,
  59865. + LIRC_DRIVER_NAME, (void*) 0);
  59866. +
  59867. + switch (result) {
  59868. + case -EBUSY:
  59869. + printk(KERN_ERR LIRC_DRIVER_NAME
  59870. + ": IRQ %d is busy\n",
  59871. + irq_num);
  59872. + return -EBUSY;
  59873. + case -EINVAL:
  59874. + printk(KERN_ERR LIRC_DRIVER_NAME
  59875. + ": Bad irq number or handler\n");
  59876. + return -EINVAL;
  59877. + default:
  59878. + dprintk("Interrupt %d obtained\n",
  59879. + irq_num);
  59880. + break;
  59881. + };
  59882. +
  59883. + /* initialize pulse/space widths */
  59884. + init_timing_params(duty_cycle, freq);
  59885. +
  59886. + return 0;
  59887. +}
  59888. +
  59889. +static void set_use_dec(void *data)
  59890. +{
  59891. + /* GPIO Pin Falling/Rising Edge Detect Disable */
  59892. + irq_set_irq_type(irq_num, 0);
  59893. + disable_irq(irq_num);
  59894. +
  59895. + free_irq(irq_num, (void *) 0);
  59896. +
  59897. + dprintk(KERN_INFO LIRC_DRIVER_NAME
  59898. + ": freed IRQ %d\n", irq_num);
  59899. +}
  59900. +
  59901. +static ssize_t lirc_write(struct file *file, const char *buf,
  59902. + size_t n, loff_t *ppos)
  59903. +{
  59904. + int i, count;
  59905. + unsigned long flags;
  59906. + long delta = 0;
  59907. + int *wbuf;
  59908. +
  59909. + count = n / sizeof(int);
  59910. + if (n % sizeof(int) || count % 2 == 0)
  59911. + return -EINVAL;
  59912. + wbuf = memdup_user(buf, n);
  59913. + if (IS_ERR(wbuf))
  59914. + return PTR_ERR(wbuf);
  59915. + spin_lock_irqsave(&lock, flags);
  59916. +
  59917. + for (i = 0; i < count; i++) {
  59918. + if (i%2)
  59919. + send_space(wbuf[i] - delta);
  59920. + else
  59921. + delta = send_pulse(wbuf[i]);
  59922. + }
  59923. + gpiochip->set(gpiochip, gpio_out_pin, invert);
  59924. +
  59925. + spin_unlock_irqrestore(&lock, flags);
  59926. + kfree(wbuf);
  59927. + return n;
  59928. +}
  59929. +
  59930. +static long lirc_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
  59931. +{
  59932. + int result;
  59933. + __u32 value;
  59934. +
  59935. + switch (cmd) {
  59936. + case LIRC_GET_SEND_MODE:
  59937. + return -ENOIOCTLCMD;
  59938. + break;
  59939. +
  59940. + case LIRC_SET_SEND_MODE:
  59941. + result = get_user(value, (__u32 *) arg);
  59942. + if (result)
  59943. + return result;
  59944. + /* only LIRC_MODE_PULSE supported */
  59945. + if (value != LIRC_MODE_PULSE)
  59946. + return -ENOSYS;
  59947. + break;
  59948. +
  59949. + case LIRC_GET_LENGTH:
  59950. + return -ENOSYS;
  59951. + break;
  59952. +
  59953. + case LIRC_SET_SEND_DUTY_CYCLE:
  59954. + dprintk("SET_SEND_DUTY_CYCLE\n");
  59955. + result = get_user(value, (__u32 *) arg);
  59956. + if (result)
  59957. + return result;
  59958. + if (value <= 0 || value > 100)
  59959. + return -EINVAL;
  59960. + return init_timing_params(value, freq);
  59961. + break;
  59962. +
  59963. + case LIRC_SET_SEND_CARRIER:
  59964. + dprintk("SET_SEND_CARRIER\n");
  59965. + result = get_user(value, (__u32 *) arg);
  59966. + if (result)
  59967. + return result;
  59968. + if (value > 500000 || value < 20000)
  59969. + return -EINVAL;
  59970. + return init_timing_params(duty_cycle, value);
  59971. + break;
  59972. +
  59973. + default:
  59974. + return lirc_dev_fop_ioctl(filep, cmd, arg);
  59975. + }
  59976. + return 0;
  59977. +}
  59978. +
  59979. +static const struct file_operations lirc_fops = {
  59980. + .owner = THIS_MODULE,
  59981. + .write = lirc_write,
  59982. + .unlocked_ioctl = lirc_ioctl,
  59983. + .read = lirc_dev_fop_read,
  59984. + .poll = lirc_dev_fop_poll,
  59985. + .open = lirc_dev_fop_open,
  59986. + .release = lirc_dev_fop_close,
  59987. + .llseek = no_llseek,
  59988. +};
  59989. +
  59990. +static struct lirc_driver driver = {
  59991. + .name = LIRC_DRIVER_NAME,
  59992. + .minor = -1,
  59993. + .code_length = 1,
  59994. + .sample_rate = 0,
  59995. + .data = NULL,
  59996. + .add_to_buf = NULL,
  59997. + .rbuf = &rbuf,
  59998. + .set_use_inc = set_use_inc,
  59999. + .set_use_dec = set_use_dec,
  60000. + .fops = &lirc_fops,
  60001. + .dev = NULL,
  60002. + .owner = THIS_MODULE,
  60003. +};
  60004. +
  60005. +static const struct of_device_id lirc_rpi_of_match[] = {
  60006. + { .compatible = "rpi,lirc-rpi", },
  60007. + {},
  60008. +};
  60009. +MODULE_DEVICE_TABLE(of, lirc_rpi_of_match);
  60010. +
  60011. +static struct platform_driver lirc_rpi_driver = {
  60012. + .driver = {
  60013. + .name = LIRC_DRIVER_NAME,
  60014. + .owner = THIS_MODULE,
  60015. + .of_match_table = of_match_ptr(lirc_rpi_of_match),
  60016. + },
  60017. +};
  60018. +
  60019. +static int __init lirc_rpi_init(void)
  60020. +{
  60021. + struct device_node *node;
  60022. + int result;
  60023. +
  60024. + /* Init read buffer. */
  60025. + result = lirc_buffer_init(&rbuf, sizeof(int), RBUF_LEN);
  60026. + if (result < 0)
  60027. + return -ENOMEM;
  60028. +
  60029. + result = platform_driver_register(&lirc_rpi_driver);
  60030. + if (result) {
  60031. + printk(KERN_ERR LIRC_DRIVER_NAME
  60032. + ": lirc register returned %d\n", result);
  60033. + goto exit_buffer_free;
  60034. + }
  60035. +
  60036. + node = of_find_compatible_node(NULL, NULL,
  60037. + lirc_rpi_of_match[0].compatible);
  60038. +
  60039. + if (node) {
  60040. + /* DT-enabled */
  60041. + lirc_rpi_dev = of_find_device_by_node(node);
  60042. + WARN_ON(lirc_rpi_dev->dev.of_node != node);
  60043. + of_node_put(node);
  60044. + }
  60045. + else {
  60046. + lirc_rpi_dev = platform_device_alloc(LIRC_DRIVER_NAME, 0);
  60047. + if (!lirc_rpi_dev) {
  60048. + result = -ENOMEM;
  60049. + goto exit_driver_unregister;
  60050. + }
  60051. +
  60052. + result = platform_device_add(lirc_rpi_dev);
  60053. + if (result)
  60054. + goto exit_device_put;
  60055. + }
  60056. +
  60057. + return 0;
  60058. +
  60059. + exit_device_put:
  60060. + platform_device_put(lirc_rpi_dev);
  60061. +
  60062. + exit_driver_unregister:
  60063. + platform_driver_unregister(&lirc_rpi_driver);
  60064. +
  60065. + exit_buffer_free:
  60066. + lirc_buffer_free(&rbuf);
  60067. +
  60068. + return result;
  60069. +}
  60070. +
  60071. +static void lirc_rpi_exit(void)
  60072. +{
  60073. + if (!lirc_rpi_dev->dev.of_node)
  60074. + platform_device_unregister(lirc_rpi_dev);
  60075. + platform_driver_unregister(&lirc_rpi_driver);
  60076. + lirc_buffer_free(&rbuf);
  60077. +}
  60078. +
  60079. +static int __init lirc_rpi_init_module(void)
  60080. +{
  60081. + int result;
  60082. +
  60083. + result = lirc_rpi_init();
  60084. + if (result)
  60085. + return result;
  60086. +
  60087. + result = init_port();
  60088. + if (result < 0)
  60089. + goto exit_rpi;
  60090. +
  60091. + driver.features = LIRC_CAN_SET_SEND_DUTY_CYCLE |
  60092. + LIRC_CAN_SET_SEND_CARRIER |
  60093. + LIRC_CAN_SEND_PULSE |
  60094. + LIRC_CAN_REC_MODE2;
  60095. +
  60096. + driver.dev = &lirc_rpi_dev->dev;
  60097. + driver.minor = lirc_register_driver(&driver);
  60098. +
  60099. + if (driver.minor < 0) {
  60100. + printk(KERN_ERR LIRC_DRIVER_NAME
  60101. + ": device registration failed with %d\n", result);
  60102. + result = -EIO;
  60103. + goto exit_rpi;
  60104. + }
  60105. +
  60106. + printk(KERN_INFO LIRC_DRIVER_NAME ": driver registered!\n");
  60107. +
  60108. + return 0;
  60109. +
  60110. + exit_rpi:
  60111. + lirc_rpi_exit();
  60112. +
  60113. + return result;
  60114. +}
  60115. +
  60116. +static void __exit lirc_rpi_exit_module(void)
  60117. +{
  60118. + lirc_unregister_driver(driver.minor);
  60119. +
  60120. + gpio_free(gpio_out_pin);
  60121. + gpio_free(gpio_in_pin);
  60122. +
  60123. + lirc_rpi_exit();
  60124. +
  60125. + printk(KERN_INFO LIRC_DRIVER_NAME ": cleaned up module\n");
  60126. +}
  60127. +
  60128. +module_init(lirc_rpi_init_module);
  60129. +module_exit(lirc_rpi_exit_module);
  60130. +
  60131. +MODULE_DESCRIPTION("Infra-red receiver and blaster driver for Raspberry Pi GPIO.");
  60132. +MODULE_AUTHOR("Aron Robert Szabo <aron@reon.hu>");
  60133. +MODULE_AUTHOR("Michael Bishop <cleverca22@gmail.com>");
  60134. +MODULE_LICENSE("GPL");
  60135. +
  60136. +module_param(gpio_out_pin, int, S_IRUGO);
  60137. +MODULE_PARM_DESC(gpio_out_pin, "GPIO output/transmitter pin number of the BCM"
  60138. + " processor. (default 17");
  60139. +
  60140. +module_param(gpio_in_pin, int, S_IRUGO);
  60141. +MODULE_PARM_DESC(gpio_in_pin, "GPIO input pin number of the BCM processor."
  60142. + " (default 18");
  60143. +
  60144. +module_param(gpio_in_pull, int, S_IRUGO);
  60145. +MODULE_PARM_DESC(gpio_in_pull, "GPIO input pin pull configuration."
  60146. + " (0 = off, 1 = up, 2 = down, default down)");
  60147. +
  60148. +module_param(sense, int, S_IRUGO);
  60149. +MODULE_PARM_DESC(sense, "Override autodetection of IR receiver circuit"
  60150. + " (0 = active high, 1 = active low )");
  60151. +
  60152. +module_param(softcarrier, bool, S_IRUGO);
  60153. +MODULE_PARM_DESC(softcarrier, "Software carrier (0 = off, 1 = on, default on)");
  60154. +
  60155. +module_param(invert, bool, S_IRUGO);
  60156. +MODULE_PARM_DESC(invert, "Invert output (0 = off, 1 = on, default off");
  60157. +
  60158. +module_param(debug, bool, S_IRUGO | S_IWUSR);
  60159. +MODULE_PARM_DESC(debug, "Enable debugging messages");
  60160. diff -Nur linux-3.18.8/drivers/staging/media/lirc/Makefile linux-rpi/drivers/staging/media/lirc/Makefile
  60161. --- linux-3.18.8/drivers/staging/media/lirc/Makefile 2015-02-27 02:49:36.000000000 +0100
  60162. +++ linux-rpi/drivers/staging/media/lirc/Makefile 2015-03-05 14:40:16.401715807 +0100
  60163. @@ -7,6 +7,7 @@
  60164. obj-$(CONFIG_LIRC_IGORPLUGUSB) += lirc_igorplugusb.o
  60165. obj-$(CONFIG_LIRC_IMON) += lirc_imon.o
  60166. obj-$(CONFIG_LIRC_PARALLEL) += lirc_parallel.o
  60167. +obj-$(CONFIG_LIRC_RPI) += lirc_rpi.o
  60168. obj-$(CONFIG_LIRC_SASEM) += lirc_sasem.o
  60169. obj-$(CONFIG_LIRC_SERIAL) += lirc_serial.o
  60170. obj-$(CONFIG_LIRC_SIR) += lirc_sir.o
  60171. diff -Nur linux-3.18.8/drivers/thermal/bcm2835-thermal.c linux-rpi/drivers/thermal/bcm2835-thermal.c
  60172. --- linux-3.18.8/drivers/thermal/bcm2835-thermal.c 1970-01-01 01:00:00.000000000 +0100
  60173. +++ linux-rpi/drivers/thermal/bcm2835-thermal.c 2015-03-05 14:40:16.489715807 +0100
  60174. @@ -0,0 +1,184 @@
  60175. +/*****************************************************************************
  60176. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  60177. +*
  60178. +* Unless you and Broadcom execute a separate written software license
  60179. +* agreement governing use of this software, this software is licensed to you
  60180. +* under the terms of the GNU General Public License version 2, available at
  60181. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  60182. +*
  60183. +* Notwithstanding the above, under no circumstances may you combine this
  60184. +* software in any way with any other Broadcom software provided under a
  60185. +* license other than the GPL, without Broadcom's express prior written
  60186. +* consent.
  60187. +*****************************************************************************/
  60188. +
  60189. +#include <linux/kernel.h>
  60190. +#include <linux/module.h>
  60191. +#include <linux/init.h>
  60192. +#include <linux/platform_device.h>
  60193. +#include <linux/slab.h>
  60194. +#include <linux/sysfs.h>
  60195. +#include <mach/vcio.h>
  60196. +#include <linux/thermal.h>
  60197. +
  60198. +
  60199. +/* --- DEFINITIONS --- */
  60200. +#define MODULE_NAME "bcm2835_thermal"
  60201. +
  60202. +/*#define THERMAL_DEBUG_ENABLE*/
  60203. +
  60204. +#ifdef THERMAL_DEBUG_ENABLE
  60205. +#define print_debug(fmt,...) printk(KERN_INFO "%s:%s:%d: "fmt"\n", MODULE_NAME, __func__, __LINE__, ##__VA_ARGS__)
  60206. +#else
  60207. +#define print_debug(fmt,...)
  60208. +#endif
  60209. +#define print_err(fmt,...) printk(KERN_ERR "%s:%s:%d: "fmt"\n", MODULE_NAME, __func__,__LINE__, ##__VA_ARGS__)
  60210. +
  60211. +#define VC_TAG_GET_TEMP 0x00030006
  60212. +#define VC_TAG_GET_MAX_TEMP 0x0003000A
  60213. +
  60214. +typedef enum {
  60215. + TEMP,
  60216. + MAX_TEMP,
  60217. +} temp_type;
  60218. +
  60219. +/* --- STRUCTS --- */
  60220. +/* tag part of the message */
  60221. +struct vc_msg_tag {
  60222. + uint32_t tag_id; /* the tag ID for the temperature */
  60223. + uint32_t buffer_size; /* size of the buffer (should be 8) */
  60224. + uint32_t request_code; /* identifies message as a request (should be 0) */
  60225. + uint32_t id; /* extra ID field (should be 0) */
  60226. + uint32_t val; /* returned value of the temperature */
  60227. +};
  60228. +
  60229. +/* message structure to be sent to videocore */
  60230. +struct vc_msg {
  60231. + uint32_t msg_size; /* simply, sizeof(struct vc_msg) */
  60232. + uint32_t request_code; /* holds various information like the success and number of bytes returned (refer to mailboxes wiki) */
  60233. + struct vc_msg_tag tag; /* the tag structure above to make */
  60234. + uint32_t end_tag; /* an end identifier, should be set to NULL */
  60235. +};
  60236. +
  60237. +struct bcm2835_thermal_data {
  60238. + struct thermal_zone_device *thermal_dev;
  60239. + struct vc_msg msg;
  60240. +};
  60241. +
  60242. +/* --- GLOBALS --- */
  60243. +static struct bcm2835_thermal_data bcm2835_data;
  60244. +
  60245. +/* Thermal Device Operations */
  60246. +static struct thermal_zone_device_ops ops;
  60247. +
  60248. +/* --- FUNCTIONS --- */
  60249. +
  60250. +static int bcm2835_get_temp_or_max(struct thermal_zone_device *thermal_dev, unsigned long *temp, unsigned tag_id)
  60251. +{
  60252. + int result = -1, retry = 3;
  60253. + print_debug("IN");
  60254. +
  60255. + *temp = 0;
  60256. + while (result != 0 && retry-- > 0) {
  60257. + /* wipe all previous message data */
  60258. + memset(&bcm2835_data.msg, 0, sizeof bcm2835_data.msg);
  60259. +
  60260. + /* prepare message */
  60261. + bcm2835_data.msg.msg_size = sizeof bcm2835_data.msg;
  60262. + bcm2835_data.msg.tag.buffer_size = 8;
  60263. + bcm2835_data.msg.tag.tag_id = tag_id;
  60264. +
  60265. + /* send the message */
  60266. + result = bcm_mailbox_property(&bcm2835_data.msg, sizeof bcm2835_data.msg);
  60267. + 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);
  60268. + if (!(bcm2835_data.msg.request_code & 0x80000000))
  60269. + result = -1;
  60270. + }
  60271. +
  60272. + /* check if it was all ok and return the rate in milli degrees C */
  60273. + if (result == 0)
  60274. + *temp = (uint)bcm2835_data.msg.tag.val;
  60275. + else
  60276. + print_err("Failed to get temperature! (%x:%d)\n", tag_id, result);
  60277. + print_debug("OUT");
  60278. + return result;
  60279. +}
  60280. +
  60281. +static int bcm2835_get_temp(struct thermal_zone_device *thermal_dev, unsigned long *temp)
  60282. +{
  60283. + return bcm2835_get_temp_or_max(thermal_dev, temp, VC_TAG_GET_TEMP);
  60284. +}
  60285. +
  60286. +static int bcm2835_get_max_temp(struct thermal_zone_device *thermal_dev, int trip_num, unsigned long *temp)
  60287. +{
  60288. + return bcm2835_get_temp_or_max(thermal_dev, temp, VC_TAG_GET_MAX_TEMP);
  60289. +}
  60290. +
  60291. +static int bcm2835_get_trip_type(struct thermal_zone_device * thermal_dev, int trip_num, enum thermal_trip_type *trip_type)
  60292. +{
  60293. + *trip_type = THERMAL_TRIP_HOT;
  60294. + return 0;
  60295. +}
  60296. +
  60297. +
  60298. +static int bcm2835_get_mode(struct thermal_zone_device *thermal_dev, enum thermal_device_mode *dev_mode)
  60299. +{
  60300. + *dev_mode = THERMAL_DEVICE_ENABLED;
  60301. + return 0;
  60302. +}
  60303. +
  60304. +
  60305. +static int bcm2835_thermal_probe(struct platform_device *pdev)
  60306. +{
  60307. + print_debug("IN");
  60308. + print_debug("THERMAL Driver has been probed!");
  60309. +
  60310. + /* check that the device isn't null!*/
  60311. + if(pdev == NULL)
  60312. + {
  60313. + print_debug("Platform device is empty!");
  60314. + return -ENODEV;
  60315. + }
  60316. +
  60317. + if(!(bcm2835_data.thermal_dev = thermal_zone_device_register("bcm2835_thermal", 1, 0, NULL, &ops, NULL, 0, 0)))
  60318. + {
  60319. + print_debug("Unable to register the thermal device!");
  60320. + return -EFAULT;
  60321. + }
  60322. + return 0;
  60323. +}
  60324. +
  60325. +
  60326. +static int bcm2835_thermal_remove(struct platform_device *pdev)
  60327. +{
  60328. + print_debug("IN");
  60329. +
  60330. + thermal_zone_device_unregister(bcm2835_data.thermal_dev);
  60331. +
  60332. + print_debug("OUT");
  60333. +
  60334. + return 0;
  60335. +}
  60336. +
  60337. +static struct thermal_zone_device_ops ops = {
  60338. + .get_temp = bcm2835_get_temp,
  60339. + .get_trip_temp = bcm2835_get_max_temp,
  60340. + .get_trip_type = bcm2835_get_trip_type,
  60341. + .get_mode = bcm2835_get_mode,
  60342. +};
  60343. +
  60344. +/* Thermal Driver */
  60345. +static struct platform_driver bcm2835_thermal_driver = {
  60346. + .probe = bcm2835_thermal_probe,
  60347. + .remove = bcm2835_thermal_remove,
  60348. + .driver = {
  60349. + .name = "bcm2835_thermal",
  60350. + .owner = THIS_MODULE,
  60351. + },
  60352. +};
  60353. +
  60354. +MODULE_LICENSE("GPL");
  60355. +MODULE_AUTHOR("Dorian Peake");
  60356. +MODULE_DESCRIPTION("Thermal driver for bcm2835 chip");
  60357. +
  60358. +module_platform_driver(bcm2835_thermal_driver);
  60359. diff -Nur linux-3.18.8/drivers/thermal/Kconfig linux-rpi/drivers/thermal/Kconfig
  60360. --- linux-3.18.8/drivers/thermal/Kconfig 2015-02-27 02:49:36.000000000 +0100
  60361. +++ linux-rpi/drivers/thermal/Kconfig 2015-03-05 14:40:16.489715807 +0100
  60362. @@ -206,6 +206,12 @@
  60363. enforce idle time which results in more package C-state residency. The
  60364. user interface is exposed via generic thermal framework.
  60365. +config THERMAL_BCM2835
  60366. + tristate "BCM2835 Thermal Driver"
  60367. + help
  60368. + This will enable temperature monitoring for the Broadcom BCM2835
  60369. + chip. If built as a module, it will be called 'bcm2835-thermal'.
  60370. +
  60371. config X86_PKG_TEMP_THERMAL
  60372. tristate "X86 package temperature thermal driver"
  60373. depends on X86_THERMAL_VECTOR
  60374. diff -Nur linux-3.18.8/drivers/thermal/Makefile linux-rpi/drivers/thermal/Makefile
  60375. --- linux-3.18.8/drivers/thermal/Makefile 2015-02-27 02:49:36.000000000 +0100
  60376. +++ linux-rpi/drivers/thermal/Makefile 2015-03-05 14:40:16.489715807 +0100
  60377. @@ -29,6 +29,7 @@
  60378. obj-$(CONFIG_IMX_THERMAL) += imx_thermal.o
  60379. obj-$(CONFIG_DB8500_CPUFREQ_COOLING) += db8500_cpufreq_cooling.o
  60380. obj-$(CONFIG_INTEL_POWERCLAMP) += intel_powerclamp.o
  60381. +obj-$(CONFIG_THERMAL_BCM2835) += bcm2835-thermal.o
  60382. obj-$(CONFIG_X86_PKG_TEMP_THERMAL) += x86_pkg_temp_thermal.o
  60383. obj-$(CONFIG_INTEL_SOC_DTS_THERMAL) += intel_soc_dts_thermal.o
  60384. obj-$(CONFIG_TI_SOC_THERMAL) += ti-soc-thermal/
  60385. diff -Nur linux-3.18.8/drivers/tty/serial/amba-pl011.c linux-rpi/drivers/tty/serial/amba-pl011.c
  60386. --- linux-3.18.8/drivers/tty/serial/amba-pl011.c 2015-02-27 02:49:36.000000000 +0100
  60387. +++ linux-rpi/drivers/tty/serial/amba-pl011.c 2015-03-05 14:40:16.505715807 +0100
  60388. @@ -58,6 +58,7 @@
  60389. #include <linux/pinctrl/consumer.h>
  60390. #include <linux/sizes.h>
  60391. #include <linux/io.h>
  60392. +#include <linux/workqueue.h>
  60393. #define UART_NR 14
  60394. @@ -84,7 +85,7 @@
  60395. static unsigned int get_fifosize_arm(struct amba_device *dev)
  60396. {
  60397. - return amba_rev(dev) < 3 ? 16 : 32;
  60398. + return 16; //TODO: fix: amba_rev(dev) < 3 ? 16 : 32;
  60399. }
  60400. static struct vendor_data vendor_arm = {
  60401. @@ -156,7 +157,9 @@
  60402. unsigned int lcrh_tx; /* vendor-specific */
  60403. unsigned int lcrh_rx; /* vendor-specific */
  60404. unsigned int old_cr; /* state during shutdown */
  60405. + struct delayed_work tx_softirq_work;
  60406. bool autorts;
  60407. + unsigned int tx_irq_seen; /* 0=none, 1=1, 2=2 or more */
  60408. char type[12];
  60409. #ifdef CONFIG_DMA_ENGINE
  60410. /* DMA stuff */
  60411. @@ -408,8 +411,9 @@
  60412. dma_release_channel(uap->dmarx.chan);
  60413. }
  60414. -/* Forward declare this for the refill routine */
  60415. +/* Forward declare these for the refill routine */
  60416. static int pl011_dma_tx_refill(struct uart_amba_port *uap);
  60417. +static void pl011_start_tx_pio(struct uart_amba_port *uap);
  60418. /*
  60419. * The current DMA TX buffer has been sent.
  60420. @@ -447,14 +451,13 @@
  60421. return;
  60422. }
  60423. - if (pl011_dma_tx_refill(uap) <= 0) {
  60424. + if (pl011_dma_tx_refill(uap) <= 0)
  60425. /*
  60426. * We didn't queue a DMA buffer for some reason, but we
  60427. * have data pending to be sent. Re-enable the TX IRQ.
  60428. */
  60429. - uap->im |= UART011_TXIM;
  60430. - writew(uap->im, uap->port.membase + UART011_IMSC);
  60431. - }
  60432. + pl011_start_tx_pio(uap);
  60433. +
  60434. spin_unlock_irqrestore(&uap->port.lock, flags);
  60435. }
  60436. @@ -628,12 +631,10 @@
  60437. if (!uap->dmatx.queued) {
  60438. if (pl011_dma_tx_refill(uap) > 0) {
  60439. uap->im &= ~UART011_TXIM;
  60440. - ret = true;
  60441. - } else {
  60442. - uap->im |= UART011_TXIM;
  60443. + writew(uap->im, uap->port.membase +
  60444. + UART011_IMSC);
  60445. + } else
  60446. ret = false;
  60447. - }
  60448. - writew(uap->im, uap->port.membase + UART011_IMSC);
  60449. } else if (!(uap->dmacr & UART011_TXDMAE)) {
  60450. uap->dmacr |= UART011_TXDMAE;
  60451. writew(uap->dmacr,
  60452. @@ -1172,15 +1173,24 @@
  60453. pl011_dma_tx_stop(uap);
  60454. }
  60455. +static bool pl011_tx_chars(struct uart_amba_port *uap);
  60456. +
  60457. +/* Start TX with programmed I/O only (no DMA) */
  60458. +static void pl011_start_tx_pio(struct uart_amba_port *uap)
  60459. +{
  60460. + uap->im |= UART011_TXIM;
  60461. + writew(uap->im, uap->port.membase + UART011_IMSC);
  60462. + if (!uap->tx_irq_seen)
  60463. + pl011_tx_chars(uap);
  60464. +}
  60465. +
  60466. static void pl011_start_tx(struct uart_port *port)
  60467. {
  60468. struct uart_amba_port *uap =
  60469. container_of(port, struct uart_amba_port, port);
  60470. - if (!pl011_dma_tx_start(uap)) {
  60471. - uap->im |= UART011_TXIM;
  60472. - writew(uap->im, uap->port.membase + UART011_IMSC);
  60473. - }
  60474. + if (!pl011_dma_tx_start(uap))
  60475. + pl011_start_tx_pio(uap);
  60476. }
  60477. static void pl011_stop_rx(struct uart_port *port)
  60478. @@ -1238,40 +1248,87 @@
  60479. spin_lock(&uap->port.lock);
  60480. }
  60481. -static void pl011_tx_chars(struct uart_amba_port *uap)
  60482. +/*
  60483. + * Transmit a character
  60484. + * There must be at least one free entry in the TX FIFO to accept the char.
  60485. + *
  60486. + * Returns true if the FIFO might have space in it afterwards;
  60487. + * returns false if the FIFO definitely became full.
  60488. + */
  60489. +static bool pl011_tx_char(struct uart_amba_port *uap, unsigned char c)
  60490. +{
  60491. + writew(c, uap->port.membase + UART01x_DR);
  60492. + uap->port.icount.tx++;
  60493. +
  60494. + if (likely(uap->tx_irq_seen > 1))
  60495. + return true;
  60496. +
  60497. + return !(readw(uap->port.membase + UART01x_FR) & UART01x_FR_TXFF);
  60498. +}
  60499. +
  60500. +static bool pl011_tx_chars(struct uart_amba_port *uap)
  60501. {
  60502. struct circ_buf *xmit = &uap->port.state->xmit;
  60503. int count;
  60504. + if (unlikely(uap->tx_irq_seen < 2))
  60505. + /*
  60506. + * Initial FIFO fill level unknown: we must check TXFF
  60507. + * after each write, so just try to fill up the FIFO.
  60508. + */
  60509. + count = uap->fifosize;
  60510. + else /* tx_irq_seen >= 2 */
  60511. + /*
  60512. + * FIFO initially at least half-empty, so we can simply
  60513. + * write half the FIFO without polling TXFF.
  60514. +
  60515. + * Note: the *first* TX IRQ can still race with
  60516. + * pl011_start_tx_pio(), which can result in the FIFO
  60517. + * being fuller than expected in that case.
  60518. + */
  60519. + count = uap->fifosize >> 1;
  60520. +
  60521. + /*
  60522. + * If the FIFO is full we're guaranteed a TX IRQ at some later point,
  60523. + * and can't transmit immediately in any case:
  60524. + */
  60525. + if (unlikely(uap->tx_irq_seen < 2 &&
  60526. + readw(uap->port.membase + UART01x_FR) & UART01x_FR_TXFF))
  60527. + return false;
  60528. +
  60529. if (uap->port.x_char) {
  60530. - writew(uap->port.x_char, uap->port.membase + UART01x_DR);
  60531. - uap->port.icount.tx++;
  60532. + pl011_tx_char(uap, uap->port.x_char);
  60533. uap->port.x_char = 0;
  60534. - return;
  60535. + --count;
  60536. }
  60537. if (uart_circ_empty(xmit) || uart_tx_stopped(&uap->port)) {
  60538. pl011_stop_tx(&uap->port);
  60539. - return;
  60540. + goto done;
  60541. }
  60542. /* If we are using DMA mode, try to send some characters. */
  60543. if (pl011_dma_tx_irq(uap))
  60544. - return;
  60545. + goto done;
  60546. - count = uap->fifosize >> 1;
  60547. - do {
  60548. - writew(xmit->buf[xmit->tail], uap->port.membase + UART01x_DR);
  60549. + while (count-- > 0 && pl011_tx_char(uap, xmit->buf[xmit->tail])) {
  60550. xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
  60551. - uap->port.icount.tx++;
  60552. if (uart_circ_empty(xmit))
  60553. break;
  60554. - } while (--count > 0);
  60555. + }
  60556. if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
  60557. uart_write_wakeup(&uap->port);
  60558. - if (uart_circ_empty(xmit))
  60559. + if (uart_circ_empty(xmit)) {
  60560. pl011_stop_tx(&uap->port);
  60561. + goto done;
  60562. + }
  60563. +
  60564. + if (unlikely(!uap->tx_irq_seen))
  60565. + schedule_delayed_work(&uap->tx_softirq_work, uap->port.timeout);
  60566. +
  60567. +done:
  60568. + return false;
  60569. }
  60570. static void pl011_modem_status(struct uart_amba_port *uap)
  60571. @@ -1298,6 +1355,28 @@
  60572. wake_up_interruptible(&uap->port.state->port.delta_msr_wait);
  60573. }
  60574. +static void pl011_tx_softirq(struct work_struct *work)
  60575. +{
  60576. + struct delayed_work *dwork = to_delayed_work(work);
  60577. + struct uart_amba_port *uap =
  60578. + container_of(dwork, struct uart_amba_port, tx_softirq_work);
  60579. +
  60580. + spin_lock(&uap->port.lock);
  60581. + while (pl011_tx_chars(uap)) ;
  60582. + spin_unlock(&uap->port.lock);
  60583. +}
  60584. +
  60585. +static void pl011_tx_irq_seen(struct uart_amba_port *uap)
  60586. +{
  60587. + if (likely(uap->tx_irq_seen > 1))
  60588. + return;
  60589. +
  60590. + uap->tx_irq_seen++;
  60591. + if (uap->tx_irq_seen < 2)
  60592. + /* first TX IRQ */
  60593. + cancel_delayed_work(&uap->tx_softirq_work);
  60594. +}
  60595. +
  60596. static irqreturn_t pl011_int(int irq, void *dev_id)
  60597. {
  60598. struct uart_amba_port *uap = dev_id;
  60599. @@ -1336,8 +1415,10 @@
  60600. if (status & (UART011_DSRMIS|UART011_DCDMIS|
  60601. UART011_CTSMIS|UART011_RIMIS))
  60602. pl011_modem_status(uap);
  60603. - if (status & UART011_TXIS)
  60604. + if (status & UART011_TXIS) {
  60605. + pl011_tx_irq_seen(uap);
  60606. pl011_tx_chars(uap);
  60607. + }
  60608. if (pass_counter-- == 0)
  60609. break;
  60610. @@ -1541,7 +1622,7 @@
  60611. {
  60612. struct uart_amba_port *uap =
  60613. container_of(port, struct uart_amba_port, port);
  60614. - unsigned int cr, lcr_h, fbrd, ibrd;
  60615. + unsigned int cr;
  60616. int retval;
  60617. retval = pl011_hwinit(port);
  60618. @@ -1559,30 +1640,8 @@
  60619. writew(uap->vendor->ifls, uap->port.membase + UART011_IFLS);
  60620. - /*
  60621. - * Provoke TX FIFO interrupt into asserting. Taking care to preserve
  60622. - * baud rate and data format specified by FBRD, IBRD and LCRH as the
  60623. - * UART may already be in use as a console.
  60624. - */
  60625. spin_lock_irq(&uap->port.lock);
  60626. - fbrd = readw(uap->port.membase + UART011_FBRD);
  60627. - ibrd = readw(uap->port.membase + UART011_IBRD);
  60628. - lcr_h = readw(uap->port.membase + uap->lcrh_rx);
  60629. -
  60630. - cr = UART01x_CR_UARTEN | UART011_CR_TXE | UART011_CR_LBE;
  60631. - writew(cr, uap->port.membase + UART011_CR);
  60632. - writew(0, uap->port.membase + UART011_FBRD);
  60633. - writew(1, uap->port.membase + UART011_IBRD);
  60634. - pl011_write_lcr_h(uap, 0);
  60635. - writew(0, uap->port.membase + UART01x_DR);
  60636. - while (readw(uap->port.membase + UART01x_FR) & UART01x_FR_BUSY)
  60637. - barrier();
  60638. -
  60639. - writew(fbrd, uap->port.membase + UART011_FBRD);
  60640. - writew(ibrd, uap->port.membase + UART011_IBRD);
  60641. - pl011_write_lcr_h(uap, lcr_h);
  60642. -
  60643. /* restore RTS and DTR */
  60644. cr = uap->old_cr & (UART011_CR_RTS | UART011_CR_DTR);
  60645. cr |= UART01x_CR_UARTEN | UART011_CR_RXE | UART011_CR_TXE;
  60646. @@ -1636,13 +1695,15 @@
  60647. container_of(port, struct uart_amba_port, port);
  60648. unsigned int cr;
  60649. + cancel_delayed_work_sync(&uap->tx_softirq_work);
  60650. +
  60651. /*
  60652. * disable all interrupts
  60653. */
  60654. spin_lock_irq(&uap->port.lock);
  60655. uap->im = 0;
  60656. writew(uap->im, uap->port.membase + UART011_IMSC);
  60657. - writew(0xffff, uap->port.membase + UART011_ICR);
  60658. + writew(0xffff & ~UART011_TXIS, uap->port.membase + UART011_ICR);
  60659. spin_unlock_irq(&uap->port.lock);
  60660. pl011_dma_shutdown(uap);
  60661. @@ -2180,6 +2241,7 @@
  60662. uap->port.ops = &amba_pl011_pops;
  60663. uap->port.flags = UPF_BOOT_AUTOCONF;
  60664. uap->port.line = i;
  60665. + INIT_DELAYED_WORK(&uap->tx_softirq_work, pl011_tx_softirq);
  60666. pl011_dma_probe(&dev->dev, uap);
  60667. /* Ensure interrupts from this UART are masked and cleared */
  60668. diff -Nur linux-3.18.8/drivers/usb/core/generic.c linux-rpi/drivers/usb/core/generic.c
  60669. --- linux-3.18.8/drivers/usb/core/generic.c 2015-02-27 02:49:36.000000000 +0100
  60670. +++ linux-rpi/drivers/usb/core/generic.c 2015-03-05 14:40:16.529715806 +0100
  60671. @@ -152,6 +152,7 @@
  60672. dev_warn(&udev->dev,
  60673. "no configuration chosen from %d choice%s\n",
  60674. num_configs, plural(num_configs));
  60675. + dev_warn(&udev->dev, "No support over %dmA\n", udev->bus_mA);
  60676. }
  60677. return i;
  60678. }
  60679. diff -Nur linux-3.18.8/drivers/usb/core/hub.c linux-rpi/drivers/usb/core/hub.c
  60680. --- linux-3.18.8/drivers/usb/core/hub.c 2015-02-27 02:49:36.000000000 +0100
  60681. +++ linux-rpi/drivers/usb/core/hub.c 2015-03-05 14:40:16.533715806 +0100
  60682. @@ -4923,7 +4923,7 @@
  60683. if (portchange & USB_PORT_STAT_C_OVERCURRENT) {
  60684. u16 status = 0, unused;
  60685. - dev_dbg(&port_dev->dev, "over-current change\n");
  60686. + dev_notice(&port_dev->dev, "over-current change\n");
  60687. usb_clear_port_feature(hdev, port1,
  60688. USB_PORT_FEAT_C_OVER_CURRENT);
  60689. msleep(100); /* Cool down */
  60690. diff -Nur linux-3.18.8/drivers/usb/core/message.c linux-rpi/drivers/usb/core/message.c
  60691. --- linux-3.18.8/drivers/usb/core/message.c 2015-02-27 02:49:36.000000000 +0100
  60692. +++ linux-rpi/drivers/usb/core/message.c 2015-03-05 14:40:16.533715806 +0100
  60693. @@ -1889,6 +1889,85 @@
  60694. if (cp->string == NULL &&
  60695. !(dev->quirks & USB_QUIRK_CONFIG_INTF_STRINGS))
  60696. cp->string = usb_cache_string(dev, cp->desc.iConfiguration);
  60697. +/* Uncomment this define to enable the HS Electrical Test support */
  60698. +#define DWC_HS_ELECT_TST 1
  60699. +#ifdef DWC_HS_ELECT_TST
  60700. + /* Here we implement the HS Electrical Test support. The
  60701. + * tester uses a vendor ID of 0x1A0A to indicate we should
  60702. + * run a special test sequence. The product ID tells us
  60703. + * which sequence to run. We invoke the test sequence by
  60704. + * sending a non-standard SetFeature command to our root
  60705. + * hub port. Our dwc_otg_hcd_hub_control() routine will
  60706. + * recognize the command and perform the desired test
  60707. + * sequence.
  60708. + */
  60709. + if (dev->descriptor.idVendor == 0x1A0A) {
  60710. + /* HSOTG Electrical Test */
  60711. + dev_warn(&dev->dev, "VID from HSOTG Electrical Test Fixture\n");
  60712. +
  60713. + if (dev->bus && dev->bus->root_hub) {
  60714. + struct usb_device *hdev = dev->bus->root_hub;
  60715. + dev_warn(&dev->dev, "Got PID 0x%x\n", dev->descriptor.idProduct);
  60716. +
  60717. + switch (dev->descriptor.idProduct) {
  60718. + case 0x0101: /* TEST_SE0_NAK */
  60719. + dev_warn(&dev->dev, "TEST_SE0_NAK\n");
  60720. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  60721. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  60722. + USB_PORT_FEAT_TEST, 0x300, NULL, 0, HZ);
  60723. + break;
  60724. +
  60725. + case 0x0102: /* TEST_J */
  60726. + dev_warn(&dev->dev, "TEST_J\n");
  60727. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  60728. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  60729. + USB_PORT_FEAT_TEST, 0x100, NULL, 0, HZ);
  60730. + break;
  60731. +
  60732. + case 0x0103: /* TEST_K */
  60733. + dev_warn(&dev->dev, "TEST_K\n");
  60734. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  60735. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  60736. + USB_PORT_FEAT_TEST, 0x200, NULL, 0, HZ);
  60737. + break;
  60738. +
  60739. + case 0x0104: /* TEST_PACKET */
  60740. + dev_warn(&dev->dev, "TEST_PACKET\n");
  60741. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  60742. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  60743. + USB_PORT_FEAT_TEST, 0x400, NULL, 0, HZ);
  60744. + break;
  60745. +
  60746. + case 0x0105: /* TEST_FORCE_ENABLE */
  60747. + dev_warn(&dev->dev, "TEST_FORCE_ENABLE\n");
  60748. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  60749. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  60750. + USB_PORT_FEAT_TEST, 0x500, NULL, 0, HZ);
  60751. + break;
  60752. +
  60753. + case 0x0106: /* HS_HOST_PORT_SUSPEND_RESUME */
  60754. + dev_warn(&dev->dev, "HS_HOST_PORT_SUSPEND_RESUME\n");
  60755. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  60756. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  60757. + USB_PORT_FEAT_TEST, 0x600, NULL, 0, 40 * HZ);
  60758. + break;
  60759. +
  60760. + case 0x0107: /* SINGLE_STEP_GET_DEVICE_DESCRIPTOR setup */
  60761. + dev_warn(&dev->dev, "SINGLE_STEP_GET_DEVICE_DESCRIPTOR setup\n");
  60762. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  60763. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  60764. + USB_PORT_FEAT_TEST, 0x700, NULL, 0, 40 * HZ);
  60765. + break;
  60766. +
  60767. + case 0x0108: /* SINGLE_STEP_GET_DEVICE_DESCRIPTOR execute */
  60768. + dev_warn(&dev->dev, "SINGLE_STEP_GET_DEVICE_DESCRIPTOR execute\n");
  60769. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  60770. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  60771. + USB_PORT_FEAT_TEST, 0x800, NULL, 0, 40 * HZ);
  60772. + }
  60773. + }
  60774. + }
  60775. +#endif /* DWC_HS_ELECT_TST */
  60776. /* Now that the interfaces are installed, re-enable LPM. */
  60777. usb_unlocked_enable_lpm(dev);
  60778. diff -Nur linux-3.18.8/drivers/usb/core/otg_whitelist.h linux-rpi/drivers/usb/core/otg_whitelist.h
  60779. --- linux-3.18.8/drivers/usb/core/otg_whitelist.h 2015-02-27 02:49:36.000000000 +0100
  60780. +++ linux-rpi/drivers/usb/core/otg_whitelist.h 2015-03-05 14:40:16.533715806 +0100
  60781. @@ -19,33 +19,82 @@
  60782. static struct usb_device_id whitelist_table [] = {
  60783. /* hubs are optional in OTG, but very handy ... */
  60784. +#define CERT_WITHOUT_HUBS
  60785. +#if defined(CERT_WITHOUT_HUBS)
  60786. +{ USB_DEVICE( 0x0000, 0x0000 ), }, /* Root HUB Only*/
  60787. +#else
  60788. { USB_DEVICE_INFO(USB_CLASS_HUB, 0, 0), },
  60789. { USB_DEVICE_INFO(USB_CLASS_HUB, 0, 1), },
  60790. +{ USB_DEVICE_INFO(USB_CLASS_HUB, 0, 2), },
  60791. +#endif
  60792. #ifdef CONFIG_USB_PRINTER /* ignoring nonstatic linkage! */
  60793. /* FIXME actually, printers are NOT supposed to use device classes;
  60794. * they're supposed to use interface classes...
  60795. */
  60796. -{ USB_DEVICE_INFO(7, 1, 1) },
  60797. -{ USB_DEVICE_INFO(7, 1, 2) },
  60798. -{ USB_DEVICE_INFO(7, 1, 3) },
  60799. +//{ USB_DEVICE_INFO(7, 1, 1) },
  60800. +//{ USB_DEVICE_INFO(7, 1, 2) },
  60801. +//{ USB_DEVICE_INFO(7, 1, 3) },
  60802. #endif
  60803. #ifdef CONFIG_USB_NET_CDCETHER
  60804. /* Linux-USB CDC Ethernet gadget */
  60805. -{ USB_DEVICE(0x0525, 0xa4a1), },
  60806. +//{ USB_DEVICE(0x0525, 0xa4a1), },
  60807. /* Linux-USB CDC Ethernet + RNDIS gadget */
  60808. -{ USB_DEVICE(0x0525, 0xa4a2), },
  60809. +//{ USB_DEVICE(0x0525, 0xa4a2), },
  60810. #endif
  60811. #if defined(CONFIG_USB_TEST) || defined(CONFIG_USB_TEST_MODULE)
  60812. /* gadget zero, for testing */
  60813. -{ USB_DEVICE(0x0525, 0xa4a0), },
  60814. +//{ USB_DEVICE(0x0525, 0xa4a0), },
  60815. #endif
  60816. +/* OPT Tester */
  60817. +{ USB_DEVICE( 0x1a0a, 0x0101 ), }, /* TEST_SE0_NAK */
  60818. +{ USB_DEVICE( 0x1a0a, 0x0102 ), }, /* Test_J */
  60819. +{ USB_DEVICE( 0x1a0a, 0x0103 ), }, /* Test_K */
  60820. +{ USB_DEVICE( 0x1a0a, 0x0104 ), }, /* Test_PACKET */
  60821. +{ USB_DEVICE( 0x1a0a, 0x0105 ), }, /* Test_FORCE_ENABLE */
  60822. +{ USB_DEVICE( 0x1a0a, 0x0106 ), }, /* HS_PORT_SUSPEND_RESUME */
  60823. +{ USB_DEVICE( 0x1a0a, 0x0107 ), }, /* SINGLE_STEP_GET_DESCRIPTOR setup */
  60824. +{ USB_DEVICE( 0x1a0a, 0x0108 ), }, /* SINGLE_STEP_GET_DESCRIPTOR execute */
  60825. +
  60826. +/* Sony cameras */
  60827. +{ USB_DEVICE_VER(0x054c,0x0010,0x0410, 0x0500), },
  60828. +
  60829. +/* Memory Devices */
  60830. +//{ USB_DEVICE( 0x0781, 0x5150 ), }, /* SanDisk */
  60831. +//{ USB_DEVICE( 0x05DC, 0x0080 ), }, /* Lexar */
  60832. +//{ USB_DEVICE( 0x4146, 0x9281 ), }, /* IOMEGA */
  60833. +//{ USB_DEVICE( 0x067b, 0x2507 ), }, /* Hammer 20GB External HD */
  60834. +{ USB_DEVICE( 0x0EA0, 0x2168 ), }, /* Ours Technology Inc. (BUFFALO ClipDrive)*/
  60835. +//{ USB_DEVICE( 0x0457, 0x0150 ), }, /* Silicon Integrated Systems Corp. */
  60836. +
  60837. +/* HP Printers */
  60838. +//{ USB_DEVICE( 0x03F0, 0x1102 ), }, /* HP Photosmart 245 */
  60839. +//{ USB_DEVICE( 0x03F0, 0x1302 ), }, /* HP Photosmart 370 Series */
  60840. +
  60841. +/* Speakers */
  60842. +//{ USB_DEVICE( 0x0499, 0x3002 ), }, /* YAMAHA YST-MS35D USB Speakers */
  60843. +//{ USB_DEVICE( 0x0672, 0x1041 ), }, /* Labtec USB Headset */
  60844. +
  60845. { } /* Terminating entry */
  60846. };
  60847. +static inline void report_errors(struct usb_device *dev)
  60848. +{
  60849. + /* OTG MESSAGE: report errors here, customize to match your product */
  60850. + dev_info(&dev->dev, "device Vendor:%04x Product:%04x is not supported\n",
  60851. + le16_to_cpu(dev->descriptor.idVendor),
  60852. + le16_to_cpu(dev->descriptor.idProduct));
  60853. + if (USB_CLASS_HUB == dev->descriptor.bDeviceClass){
  60854. + dev_printk(KERN_CRIT, &dev->dev, "Unsupported Hub Topology\n");
  60855. + } else {
  60856. + dev_printk(KERN_CRIT, &dev->dev, "Attached Device is not Supported\n");
  60857. + }
  60858. +}
  60859. +
  60860. +
  60861. static int is_targeted(struct usb_device *dev)
  60862. {
  60863. struct usb_device_id *id = whitelist_table;
  60864. @@ -95,16 +144,57 @@
  60865. continue;
  60866. return 1;
  60867. - }
  60868. + /* NOTE: can't use usb_match_id() since interface caches
  60869. + * aren't set up yet. this is cut/paste from that code.
  60870. + */
  60871. + for (id = whitelist_table; id->match_flags; id++) {
  60872. +#ifdef DEBUG
  60873. + dev_dbg(&dev->dev,
  60874. + "ID: V:%04x P:%04x DC:%04x SC:%04x PR:%04x \n",
  60875. + id->idVendor,
  60876. + id->idProduct,
  60877. + id->bDeviceClass,
  60878. + id->bDeviceSubClass,
  60879. + id->bDeviceProtocol);
  60880. +#endif
  60881. - /* add other match criteria here ... */
  60882. + if ((id->match_flags & USB_DEVICE_ID_MATCH_VENDOR) &&
  60883. + id->idVendor != le16_to_cpu(dev->descriptor.idVendor))
  60884. + continue;
  60885. +
  60886. + if ((id->match_flags & USB_DEVICE_ID_MATCH_PRODUCT) &&
  60887. + id->idProduct != le16_to_cpu(dev->descriptor.idProduct))
  60888. + continue;
  60889. +
  60890. + /* No need to test id->bcdDevice_lo != 0, since 0 is never
  60891. + greater than any unsigned number. */
  60892. + if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_LO) &&
  60893. + (id->bcdDevice_lo > le16_to_cpu(dev->descriptor.bcdDevice)))
  60894. + continue;
  60895. +
  60896. + if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_HI) &&
  60897. + (id->bcdDevice_hi < le16_to_cpu(dev->descriptor.bcdDevice)))
  60898. + continue;
  60899. +
  60900. + if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_CLASS) &&
  60901. + (id->bDeviceClass != dev->descriptor.bDeviceClass))
  60902. + continue;
  60903. +
  60904. + if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_SUBCLASS) &&
  60905. + (id->bDeviceSubClass != dev->descriptor.bDeviceSubClass))
  60906. + continue;
  60907. +
  60908. + if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_PROTOCOL) &&
  60909. + (id->bDeviceProtocol != dev->descriptor.bDeviceProtocol))
  60910. + continue;
  60911. + return 1;
  60912. + }
  60913. + }
  60914. - /* OTG MESSAGE: report errors here, customize to match your product */
  60915. - dev_err(&dev->dev, "device v%04x p%04x is not supported\n",
  60916. - le16_to_cpu(dev->descriptor.idVendor),
  60917. - le16_to_cpu(dev->descriptor.idProduct));
  60918. + /* add other match criteria here ... */
  60919. + report_errors(dev);
  60920. return 0;
  60921. }
  60922. diff -Nur linux-3.18.8/drivers/usb/gadget/file_storage.c linux-rpi/drivers/usb/gadget/file_storage.c
  60923. --- linux-3.18.8/drivers/usb/gadget/file_storage.c 1970-01-01 01:00:00.000000000 +0100
  60924. +++ linux-rpi/drivers/usb/gadget/file_storage.c 2015-03-05 14:40:16.541715806 +0100
  60925. @@ -0,0 +1,3676 @@
  60926. +/*
  60927. + * file_storage.c -- File-backed USB Storage Gadget, for USB development
  60928. + *
  60929. + * Copyright (C) 2003-2008 Alan Stern
  60930. + * All rights reserved.
  60931. + *
  60932. + * Redistribution and use in source and binary forms, with or without
  60933. + * modification, are permitted provided that the following conditions
  60934. + * are met:
  60935. + * 1. Redistributions of source code must retain the above copyright
  60936. + * notice, this list of conditions, and the following disclaimer,
  60937. + * without modification.
  60938. + * 2. Redistributions in binary form must reproduce the above copyright
  60939. + * notice, this list of conditions and the following disclaimer in the
  60940. + * documentation and/or other materials provided with the distribution.
  60941. + * 3. The names of the above-listed copyright holders may not be used
  60942. + * to endorse or promote products derived from this software without
  60943. + * specific prior written permission.
  60944. + *
  60945. + * ALTERNATIVELY, this software may be distributed under the terms of the
  60946. + * GNU General Public License ("GPL") as published by the Free Software
  60947. + * Foundation, either version 2 of that License or (at your option) any
  60948. + * later version.
  60949. + *
  60950. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  60951. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  60952. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  60953. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  60954. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  60955. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  60956. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  60957. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  60958. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  60959. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  60960. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  60961. + */
  60962. +
  60963. +
  60964. +/*
  60965. + * The File-backed Storage Gadget acts as a USB Mass Storage device,
  60966. + * appearing to the host as a disk drive or as a CD-ROM drive. In addition
  60967. + * to providing an example of a genuinely useful gadget driver for a USB
  60968. + * device, it also illustrates a technique of double-buffering for increased
  60969. + * throughput. Last but not least, it gives an easy way to probe the
  60970. + * behavior of the Mass Storage drivers in a USB host.
  60971. + *
  60972. + * Backing storage is provided by a regular file or a block device, specified
  60973. + * by the "file" module parameter. Access can be limited to read-only by
  60974. + * setting the optional "ro" module parameter. (For CD-ROM emulation,
  60975. + * access is always read-only.) The gadget will indicate that it has
  60976. + * removable media if the optional "removable" module parameter is set.
  60977. + *
  60978. + * The gadget supports the Control-Bulk (CB), Control-Bulk-Interrupt (CBI),
  60979. + * and Bulk-Only (also known as Bulk-Bulk-Bulk or BBB) transports, selected
  60980. + * by the optional "transport" module parameter. It also supports the
  60981. + * following protocols: RBC (0x01), ATAPI or SFF-8020i (0x02), QIC-157 (0c03),
  60982. + * UFI (0x04), SFF-8070i (0x05), and transparent SCSI (0x06), selected by
  60983. + * the optional "protocol" module parameter. In addition, the default
  60984. + * Vendor ID, Product ID, release number and serial number can be overridden.
  60985. + *
  60986. + * There is support for multiple logical units (LUNs), each of which has
  60987. + * its own backing file. The number of LUNs can be set using the optional
  60988. + * "luns" module parameter (anywhere from 1 to 8), and the corresponding
  60989. + * files are specified using comma-separated lists for "file" and "ro".
  60990. + * The default number of LUNs is taken from the number of "file" elements;
  60991. + * it is 1 if "file" is not given. If "removable" is not set then a backing
  60992. + * file must be specified for each LUN. If it is set, then an unspecified
  60993. + * or empty backing filename means the LUN's medium is not loaded. Ideally
  60994. + * each LUN would be settable independently as a disk drive or a CD-ROM
  60995. + * drive, but currently all LUNs have to be the same type. The CD-ROM
  60996. + * emulation includes a single data track and no audio tracks; hence there
  60997. + * need be only one backing file per LUN.
  60998. + *
  60999. + * Requirements are modest; only a bulk-in and a bulk-out endpoint are
  61000. + * needed (an interrupt-out endpoint is also needed for CBI). The memory
  61001. + * requirement amounts to two 16K buffers, size configurable by a parameter.
  61002. + * Support is included for both full-speed and high-speed operation.
  61003. + *
  61004. + * Note that the driver is slightly non-portable in that it assumes a
  61005. + * single memory/DMA buffer will be useable for bulk-in, bulk-out, and
  61006. + * interrupt-in endpoints. With most device controllers this isn't an
  61007. + * issue, but there may be some with hardware restrictions that prevent
  61008. + * a buffer from being used by more than one endpoint.
  61009. + *
  61010. + * Module options:
  61011. + *
  61012. + * file=filename[,filename...]
  61013. + * Required if "removable" is not set, names of
  61014. + * the files or block devices used for
  61015. + * backing storage
  61016. + * serial=HHHH... Required serial number (string of hex chars)
  61017. + * ro=b[,b...] Default false, booleans for read-only access
  61018. + * removable Default false, boolean for removable media
  61019. + * luns=N Default N = number of filenames, number of
  61020. + * LUNs to support
  61021. + * nofua=b[,b...] Default false, booleans for ignore FUA flag
  61022. + * in SCSI WRITE(10,12) commands
  61023. + * stall Default determined according to the type of
  61024. + * USB device controller (usually true),
  61025. + * boolean to permit the driver to halt
  61026. + * bulk endpoints
  61027. + * cdrom Default false, boolean for whether to emulate
  61028. + * a CD-ROM drive
  61029. + * transport=XXX Default BBB, transport name (CB, CBI, or BBB)
  61030. + * protocol=YYY Default SCSI, protocol name (RBC, 8020 or
  61031. + * ATAPI, QIC, UFI, 8070, or SCSI;
  61032. + * also 1 - 6)
  61033. + * vendor=0xVVVV Default 0x0525 (NetChip), USB Vendor ID
  61034. + * product=0xPPPP Default 0xa4a5 (FSG), USB Product ID
  61035. + * release=0xRRRR Override the USB release number (bcdDevice)
  61036. + * buflen=N Default N=16384, buffer size used (will be
  61037. + * rounded down to a multiple of
  61038. + * PAGE_CACHE_SIZE)
  61039. + *
  61040. + * If CONFIG_USB_FILE_STORAGE_TEST is not set, only the "file", "serial", "ro",
  61041. + * "removable", "luns", "nofua", "stall", and "cdrom" options are available;
  61042. + * default values are used for everything else.
  61043. + *
  61044. + * The pathnames of the backing files and the ro settings are available in
  61045. + * the attribute files "file", "nofua", and "ro" in the lun<n> subdirectory of
  61046. + * the gadget's sysfs directory. If the "removable" option is set, writing to
  61047. + * these files will simulate ejecting/loading the medium (writing an empty
  61048. + * line means eject) and adjusting a write-enable tab. Changes to the ro
  61049. + * setting are not allowed when the medium is loaded or if CD-ROM emulation
  61050. + * is being used.
  61051. + *
  61052. + * This gadget driver is heavily based on "Gadget Zero" by David Brownell.
  61053. + * The driver's SCSI command interface was based on the "Information
  61054. + * technology - Small Computer System Interface - 2" document from
  61055. + * X3T9.2 Project 375D, Revision 10L, 7-SEP-93, available at
  61056. + * <http://www.t10.org/ftp/t10/drafts/s2/s2-r10l.pdf>. The single exception
  61057. + * is opcode 0x23 (READ FORMAT CAPACITIES), which was based on the
  61058. + * "Universal Serial Bus Mass Storage Class UFI Command Specification"
  61059. + * document, Revision 1.0, December 14, 1998, available at
  61060. + * <http://www.usb.org/developers/devclass_docs/usbmass-ufi10.pdf>.
  61061. + */
  61062. +
  61063. +
  61064. +/*
  61065. + * Driver Design
  61066. + *
  61067. + * The FSG driver is fairly straightforward. There is a main kernel
  61068. + * thread that handles most of the work. Interrupt routines field
  61069. + * callbacks from the controller driver: bulk- and interrupt-request
  61070. + * completion notifications, endpoint-0 events, and disconnect events.
  61071. + * Completion events are passed to the main thread by wakeup calls. Many
  61072. + * ep0 requests are handled at interrupt time, but SetInterface,
  61073. + * SetConfiguration, and device reset requests are forwarded to the
  61074. + * thread in the form of "exceptions" using SIGUSR1 signals (since they
  61075. + * should interrupt any ongoing file I/O operations).
  61076. + *
  61077. + * The thread's main routine implements the standard command/data/status
  61078. + * parts of a SCSI interaction. It and its subroutines are full of tests
  61079. + * for pending signals/exceptions -- all this polling is necessary since
  61080. + * the kernel has no setjmp/longjmp equivalents. (Maybe this is an
  61081. + * indication that the driver really wants to be running in userspace.)
  61082. + * An important point is that so long as the thread is alive it keeps an
  61083. + * open reference to the backing file. This will prevent unmounting
  61084. + * the backing file's underlying filesystem and could cause problems
  61085. + * during system shutdown, for example. To prevent such problems, the
  61086. + * thread catches INT, TERM, and KILL signals and converts them into
  61087. + * an EXIT exception.
  61088. + *
  61089. + * In normal operation the main thread is started during the gadget's
  61090. + * fsg_bind() callback and stopped during fsg_unbind(). But it can also
  61091. + * exit when it receives a signal, and there's no point leaving the
  61092. + * gadget running when the thread is dead. So just before the thread
  61093. + * exits, it deregisters the gadget driver. This makes things a little
  61094. + * tricky: The driver is deregistered at two places, and the exiting
  61095. + * thread can indirectly call fsg_unbind() which in turn can tell the
  61096. + * thread to exit. The first problem is resolved through the use of the
  61097. + * REGISTERED atomic bitflag; the driver will only be deregistered once.
  61098. + * The second problem is resolved by having fsg_unbind() check
  61099. + * fsg->state; it won't try to stop the thread if the state is already
  61100. + * FSG_STATE_TERMINATED.
  61101. + *
  61102. + * To provide maximum throughput, the driver uses a circular pipeline of
  61103. + * buffer heads (struct fsg_buffhd). In principle the pipeline can be
  61104. + * arbitrarily long; in practice the benefits don't justify having more
  61105. + * than 2 stages (i.e., double buffering). But it helps to think of the
  61106. + * pipeline as being a long one. Each buffer head contains a bulk-in and
  61107. + * a bulk-out request pointer (since the buffer can be used for both
  61108. + * output and input -- directions always are given from the host's
  61109. + * point of view) as well as a pointer to the buffer and various state
  61110. + * variables.
  61111. + *
  61112. + * Use of the pipeline follows a simple protocol. There is a variable
  61113. + * (fsg->next_buffhd_to_fill) that points to the next buffer head to use.
  61114. + * At any time that buffer head may still be in use from an earlier
  61115. + * request, so each buffer head has a state variable indicating whether
  61116. + * it is EMPTY, FULL, or BUSY. Typical use involves waiting for the
  61117. + * buffer head to be EMPTY, filling the buffer either by file I/O or by
  61118. + * USB I/O (during which the buffer head is BUSY), and marking the buffer
  61119. + * head FULL when the I/O is complete. Then the buffer will be emptied
  61120. + * (again possibly by USB I/O, during which it is marked BUSY) and
  61121. + * finally marked EMPTY again (possibly by a completion routine).
  61122. + *
  61123. + * A module parameter tells the driver to avoid stalling the bulk
  61124. + * endpoints wherever the transport specification allows. This is
  61125. + * necessary for some UDCs like the SuperH, which cannot reliably clear a
  61126. + * halt on a bulk endpoint. However, under certain circumstances the
  61127. + * Bulk-only specification requires a stall. In such cases the driver
  61128. + * will halt the endpoint and set a flag indicating that it should clear
  61129. + * the halt in software during the next device reset. Hopefully this
  61130. + * will permit everything to work correctly. Furthermore, although the
  61131. + * specification allows the bulk-out endpoint to halt when the host sends
  61132. + * too much data, implementing this would cause an unavoidable race.
  61133. + * The driver will always use the "no-stall" approach for OUT transfers.
  61134. + *
  61135. + * One subtle point concerns sending status-stage responses for ep0
  61136. + * requests. Some of these requests, such as device reset, can involve
  61137. + * interrupting an ongoing file I/O operation, which might take an
  61138. + * arbitrarily long time. During that delay the host might give up on
  61139. + * the original ep0 request and issue a new one. When that happens the
  61140. + * driver should not notify the host about completion of the original
  61141. + * request, as the host will no longer be waiting for it. So the driver
  61142. + * assigns to each ep0 request a unique tag, and it keeps track of the
  61143. + * tag value of the request associated with a long-running exception
  61144. + * (device-reset, interface-change, or configuration-change). When the
  61145. + * exception handler is finished, the status-stage response is submitted
  61146. + * only if the current ep0 request tag is equal to the exception request
  61147. + * tag. Thus only the most recently received ep0 request will get a
  61148. + * status-stage response.
  61149. + *
  61150. + * Warning: This driver source file is too long. It ought to be split up
  61151. + * into a header file plus about 3 separate .c files, to handle the details
  61152. + * of the Gadget, USB Mass Storage, and SCSI protocols.
  61153. + */
  61154. +
  61155. +
  61156. +/* #define VERBOSE_DEBUG */
  61157. +/* #define DUMP_MSGS */
  61158. +
  61159. +
  61160. +#include <linux/blkdev.h>
  61161. +#include <linux/completion.h>
  61162. +#include <linux/dcache.h>
  61163. +#include <linux/delay.h>
  61164. +#include <linux/device.h>
  61165. +#include <linux/fcntl.h>
  61166. +#include <linux/file.h>
  61167. +#include <linux/fs.h>
  61168. +#include <linux/kref.h>
  61169. +#include <linux/kthread.h>
  61170. +#include <linux/limits.h>
  61171. +#include <linux/module.h>
  61172. +#include <linux/rwsem.h>
  61173. +#include <linux/slab.h>
  61174. +#include <linux/spinlock.h>
  61175. +#include <linux/string.h>
  61176. +#include <linux/freezer.h>
  61177. +#include <linux/utsname.h>
  61178. +
  61179. +#include <linux/usb/ch9.h>
  61180. +#include <linux/usb/gadget.h>
  61181. +
  61182. +#include "gadget_chips.h"
  61183. +
  61184. +
  61185. +
  61186. +/*
  61187. + * Kbuild is not very cooperative with respect to linking separately
  61188. + * compiled library objects into one module. So for now we won't use
  61189. + * separate compilation ... ensuring init/exit sections work to shrink
  61190. + * the runtime footprint, and giving us at least some parts of what
  61191. + * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
  61192. + */
  61193. +#include "usbstring.c"
  61194. +#include "config.c"
  61195. +#include "epautoconf.c"
  61196. +
  61197. +/*-------------------------------------------------------------------------*/
  61198. +
  61199. +#define DRIVER_DESC "File-backed Storage Gadget"
  61200. +#define DRIVER_NAME "g_file_storage"
  61201. +#define DRIVER_VERSION "1 September 2010"
  61202. +
  61203. +static char fsg_string_manufacturer[64];
  61204. +static const char fsg_string_product[] = DRIVER_DESC;
  61205. +static const char fsg_string_config[] = "Self-powered";
  61206. +static const char fsg_string_interface[] = "Mass Storage";
  61207. +
  61208. +
  61209. +#include "storage_common.c"
  61210. +
  61211. +
  61212. +MODULE_DESCRIPTION(DRIVER_DESC);
  61213. +MODULE_AUTHOR("Alan Stern");
  61214. +MODULE_LICENSE("Dual BSD/GPL");
  61215. +
  61216. +/*
  61217. + * This driver assumes self-powered hardware and has no way for users to
  61218. + * trigger remote wakeup. It uses autoconfiguration to select endpoints
  61219. + * and endpoint addresses.
  61220. + */
  61221. +
  61222. +
  61223. +/*-------------------------------------------------------------------------*/
  61224. +
  61225. +
  61226. +/* Encapsulate the module parameter settings */
  61227. +
  61228. +static struct {
  61229. + char *file[FSG_MAX_LUNS];
  61230. + char *serial;
  61231. + bool ro[FSG_MAX_LUNS];
  61232. + bool nofua[FSG_MAX_LUNS];
  61233. + unsigned int num_filenames;
  61234. + unsigned int num_ros;
  61235. + unsigned int num_nofuas;
  61236. + unsigned int nluns;
  61237. +
  61238. + bool removable;
  61239. + bool can_stall;
  61240. + bool cdrom;
  61241. +
  61242. + char *transport_parm;
  61243. + char *protocol_parm;
  61244. + unsigned short vendor;
  61245. + unsigned short product;
  61246. + unsigned short release;
  61247. + unsigned int buflen;
  61248. +
  61249. + int transport_type;
  61250. + char *transport_name;
  61251. + int protocol_type;
  61252. + char *protocol_name;
  61253. +
  61254. +} mod_data = { // Default values
  61255. + .transport_parm = "BBB",
  61256. + .protocol_parm = "SCSI",
  61257. + .removable = 0,
  61258. + .can_stall = 1,
  61259. + .cdrom = 0,
  61260. + .vendor = FSG_VENDOR_ID,
  61261. + .product = FSG_PRODUCT_ID,
  61262. + .release = 0xffff, // Use controller chip type
  61263. + .buflen = 16384,
  61264. + };
  61265. +
  61266. +
  61267. +module_param_array_named(file, mod_data.file, charp, &mod_data.num_filenames,
  61268. + S_IRUGO);
  61269. +MODULE_PARM_DESC(file, "names of backing files or devices");
  61270. +
  61271. +module_param_named(serial, mod_data.serial, charp, S_IRUGO);
  61272. +MODULE_PARM_DESC(serial, "USB serial number");
  61273. +
  61274. +module_param_array_named(ro, mod_data.ro, bool, &mod_data.num_ros, S_IRUGO);
  61275. +MODULE_PARM_DESC(ro, "true to force read-only");
  61276. +
  61277. +module_param_array_named(nofua, mod_data.nofua, bool, &mod_data.num_nofuas,
  61278. + S_IRUGO);
  61279. +MODULE_PARM_DESC(nofua, "true to ignore SCSI WRITE(10,12) FUA bit");
  61280. +
  61281. +module_param_named(luns, mod_data.nluns, uint, S_IRUGO);
  61282. +MODULE_PARM_DESC(luns, "number of LUNs");
  61283. +
  61284. +module_param_named(removable, mod_data.removable, bool, S_IRUGO);
  61285. +MODULE_PARM_DESC(removable, "true to simulate removable media");
  61286. +
  61287. +module_param_named(stall, mod_data.can_stall, bool, S_IRUGO);
  61288. +MODULE_PARM_DESC(stall, "false to prevent bulk stalls");
  61289. +
  61290. +module_param_named(cdrom, mod_data.cdrom, bool, S_IRUGO);
  61291. +MODULE_PARM_DESC(cdrom, "true to emulate cdrom instead of disk");
  61292. +
  61293. +/* In the non-TEST version, only the module parameters listed above
  61294. + * are available. */
  61295. +#ifdef CONFIG_USB_FILE_STORAGE_TEST
  61296. +
  61297. +module_param_named(transport, mod_data.transport_parm, charp, S_IRUGO);
  61298. +MODULE_PARM_DESC(transport, "type of transport (BBB, CBI, or CB)");
  61299. +
  61300. +module_param_named(protocol, mod_data.protocol_parm, charp, S_IRUGO);
  61301. +MODULE_PARM_DESC(protocol, "type of protocol (RBC, 8020, QIC, UFI, "
  61302. + "8070, or SCSI)");
  61303. +
  61304. +module_param_named(vendor, mod_data.vendor, ushort, S_IRUGO);
  61305. +MODULE_PARM_DESC(vendor, "USB Vendor ID");
  61306. +
  61307. +module_param_named(product, mod_data.product, ushort, S_IRUGO);
  61308. +MODULE_PARM_DESC(product, "USB Product ID");
  61309. +
  61310. +module_param_named(release, mod_data.release, ushort, S_IRUGO);
  61311. +MODULE_PARM_DESC(release, "USB release number");
  61312. +
  61313. +module_param_named(buflen, mod_data.buflen, uint, S_IRUGO);
  61314. +MODULE_PARM_DESC(buflen, "I/O buffer size");
  61315. +
  61316. +#endif /* CONFIG_USB_FILE_STORAGE_TEST */
  61317. +
  61318. +
  61319. +/*
  61320. + * These definitions will permit the compiler to avoid generating code for
  61321. + * parts of the driver that aren't used in the non-TEST version. Even gcc
  61322. + * can recognize when a test of a constant expression yields a dead code
  61323. + * path.
  61324. + */
  61325. +
  61326. +#ifdef CONFIG_USB_FILE_STORAGE_TEST
  61327. +
  61328. +#define transport_is_bbb() (mod_data.transport_type == USB_PR_BULK)
  61329. +#define transport_is_cbi() (mod_data.transport_type == USB_PR_CBI)
  61330. +#define protocol_is_scsi() (mod_data.protocol_type == USB_SC_SCSI)
  61331. +
  61332. +#else
  61333. +
  61334. +#define transport_is_bbb() 1
  61335. +#define transport_is_cbi() 0
  61336. +#define protocol_is_scsi() 1
  61337. +
  61338. +#endif /* CONFIG_USB_FILE_STORAGE_TEST */
  61339. +
  61340. +
  61341. +/*-------------------------------------------------------------------------*/
  61342. +
  61343. +
  61344. +struct fsg_dev {
  61345. + /* lock protects: state, all the req_busy's, and cbbuf_cmnd */
  61346. + spinlock_t lock;
  61347. + struct usb_gadget *gadget;
  61348. +
  61349. + /* filesem protects: backing files in use */
  61350. + struct rw_semaphore filesem;
  61351. +
  61352. + /* reference counting: wait until all LUNs are released */
  61353. + struct kref ref;
  61354. +
  61355. + struct usb_ep *ep0; // Handy copy of gadget->ep0
  61356. + struct usb_request *ep0req; // For control responses
  61357. + unsigned int ep0_req_tag;
  61358. + const char *ep0req_name;
  61359. +
  61360. + struct usb_request *intreq; // For interrupt responses
  61361. + int intreq_busy;
  61362. + struct fsg_buffhd *intr_buffhd;
  61363. +
  61364. + unsigned int bulk_out_maxpacket;
  61365. + enum fsg_state state; // For exception handling
  61366. + unsigned int exception_req_tag;
  61367. +
  61368. + u8 config, new_config;
  61369. +
  61370. + unsigned int running : 1;
  61371. + unsigned int bulk_in_enabled : 1;
  61372. + unsigned int bulk_out_enabled : 1;
  61373. + unsigned int intr_in_enabled : 1;
  61374. + unsigned int phase_error : 1;
  61375. + unsigned int short_packet_received : 1;
  61376. + unsigned int bad_lun_okay : 1;
  61377. +
  61378. + unsigned long atomic_bitflags;
  61379. +#define REGISTERED 0
  61380. +#define IGNORE_BULK_OUT 1
  61381. +#define SUSPENDED 2
  61382. +
  61383. + struct usb_ep *bulk_in;
  61384. + struct usb_ep *bulk_out;
  61385. + struct usb_ep *intr_in;
  61386. +
  61387. + struct fsg_buffhd *next_buffhd_to_fill;
  61388. + struct fsg_buffhd *next_buffhd_to_drain;
  61389. +
  61390. + int thread_wakeup_needed;
  61391. + struct completion thread_notifier;
  61392. + struct task_struct *thread_task;
  61393. +
  61394. + int cmnd_size;
  61395. + u8 cmnd[MAX_COMMAND_SIZE];
  61396. + enum data_direction data_dir;
  61397. + u32 data_size;
  61398. + u32 data_size_from_cmnd;
  61399. + u32 tag;
  61400. + unsigned int lun;
  61401. + u32 residue;
  61402. + u32 usb_amount_left;
  61403. +
  61404. + /* The CB protocol offers no way for a host to know when a command
  61405. + * has completed. As a result the next command may arrive early,
  61406. + * and we will still have to handle it. For that reason we need
  61407. + * a buffer to store new commands when using CB (or CBI, which
  61408. + * does not oblige a host to wait for command completion either). */
  61409. + int cbbuf_cmnd_size;
  61410. + u8 cbbuf_cmnd[MAX_COMMAND_SIZE];
  61411. +
  61412. + unsigned int nluns;
  61413. + struct fsg_lun *luns;
  61414. + struct fsg_lun *curlun;
  61415. + /* Must be the last entry */
  61416. + struct fsg_buffhd buffhds[];
  61417. +};
  61418. +
  61419. +typedef void (*fsg_routine_t)(struct fsg_dev *);
  61420. +
  61421. +static int exception_in_progress(struct fsg_dev *fsg)
  61422. +{
  61423. + return (fsg->state > FSG_STATE_IDLE);
  61424. +}
  61425. +
  61426. +/* Make bulk-out requests be divisible by the maxpacket size */
  61427. +static void set_bulk_out_req_length(struct fsg_dev *fsg,
  61428. + struct fsg_buffhd *bh, unsigned int length)
  61429. +{
  61430. + unsigned int rem;
  61431. +
  61432. + bh->bulk_out_intended_length = length;
  61433. + rem = length % fsg->bulk_out_maxpacket;
  61434. + if (rem > 0)
  61435. + length += fsg->bulk_out_maxpacket - rem;
  61436. + bh->outreq->length = length;
  61437. +}
  61438. +
  61439. +static struct fsg_dev *the_fsg;
  61440. +static struct usb_gadget_driver fsg_driver;
  61441. +
  61442. +
  61443. +/*-------------------------------------------------------------------------*/
  61444. +
  61445. +static int fsg_set_halt(struct fsg_dev *fsg, struct usb_ep *ep)
  61446. +{
  61447. + const char *name;
  61448. +
  61449. + if (ep == fsg->bulk_in)
  61450. + name = "bulk-in";
  61451. + else if (ep == fsg->bulk_out)
  61452. + name = "bulk-out";
  61453. + else
  61454. + name = ep->name;
  61455. + DBG(fsg, "%s set halt\n", name);
  61456. + return usb_ep_set_halt(ep);
  61457. +}
  61458. +
  61459. +
  61460. +/*-------------------------------------------------------------------------*/
  61461. +
  61462. +/*
  61463. + * DESCRIPTORS ... most are static, but strings and (full) configuration
  61464. + * descriptors are built on demand. Also the (static) config and interface
  61465. + * descriptors are adjusted during fsg_bind().
  61466. + */
  61467. +
  61468. +/* There is only one configuration. */
  61469. +#define CONFIG_VALUE 1
  61470. +
  61471. +static struct usb_device_descriptor
  61472. +device_desc = {
  61473. + .bLength = sizeof device_desc,
  61474. + .bDescriptorType = USB_DT_DEVICE,
  61475. +
  61476. + .bcdUSB = cpu_to_le16(0x0200),
  61477. + .bDeviceClass = USB_CLASS_PER_INTERFACE,
  61478. +
  61479. + /* The next three values can be overridden by module parameters */
  61480. + .idVendor = cpu_to_le16(FSG_VENDOR_ID),
  61481. + .idProduct = cpu_to_le16(FSG_PRODUCT_ID),
  61482. + .bcdDevice = cpu_to_le16(0xffff),
  61483. +
  61484. + .iManufacturer = FSG_STRING_MANUFACTURER,
  61485. + .iProduct = FSG_STRING_PRODUCT,
  61486. + .iSerialNumber = FSG_STRING_SERIAL,
  61487. + .bNumConfigurations = 1,
  61488. +};
  61489. +
  61490. +static struct usb_config_descriptor
  61491. +config_desc = {
  61492. + .bLength = sizeof config_desc,
  61493. + .bDescriptorType = USB_DT_CONFIG,
  61494. +
  61495. + /* wTotalLength computed by usb_gadget_config_buf() */
  61496. + .bNumInterfaces = 1,
  61497. + .bConfigurationValue = CONFIG_VALUE,
  61498. + .iConfiguration = FSG_STRING_CONFIG,
  61499. + .bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER,
  61500. + .bMaxPower = CONFIG_USB_GADGET_VBUS_DRAW / 2,
  61501. +};
  61502. +
  61503. +
  61504. +static struct usb_qualifier_descriptor
  61505. +dev_qualifier = {
  61506. + .bLength = sizeof dev_qualifier,
  61507. + .bDescriptorType = USB_DT_DEVICE_QUALIFIER,
  61508. +
  61509. + .bcdUSB = cpu_to_le16(0x0200),
  61510. + .bDeviceClass = USB_CLASS_PER_INTERFACE,
  61511. +
  61512. + .bNumConfigurations = 1,
  61513. +};
  61514. +
  61515. +static int populate_bos(struct fsg_dev *fsg, u8 *buf)
  61516. +{
  61517. + memcpy(buf, &fsg_bos_desc, USB_DT_BOS_SIZE);
  61518. + buf += USB_DT_BOS_SIZE;
  61519. +
  61520. + memcpy(buf, &fsg_ext_cap_desc, USB_DT_USB_EXT_CAP_SIZE);
  61521. + buf += USB_DT_USB_EXT_CAP_SIZE;
  61522. +
  61523. + memcpy(buf, &fsg_ss_cap_desc, USB_DT_USB_SS_CAP_SIZE);
  61524. +
  61525. + return USB_DT_BOS_SIZE + USB_DT_USB_SS_CAP_SIZE
  61526. + + USB_DT_USB_EXT_CAP_SIZE;
  61527. +}
  61528. +
  61529. +/*
  61530. + * Config descriptors must agree with the code that sets configurations
  61531. + * and with code managing interfaces and their altsettings. They must
  61532. + * also handle different speeds and other-speed requests.
  61533. + */
  61534. +static int populate_config_buf(struct usb_gadget *gadget,
  61535. + u8 *buf, u8 type, unsigned index)
  61536. +{
  61537. + enum usb_device_speed speed = gadget->speed;
  61538. + int len;
  61539. + const struct usb_descriptor_header **function;
  61540. +
  61541. + if (index > 0)
  61542. + return -EINVAL;
  61543. +
  61544. + if (gadget_is_dualspeed(gadget) && type == USB_DT_OTHER_SPEED_CONFIG)
  61545. + speed = (USB_SPEED_FULL + USB_SPEED_HIGH) - speed;
  61546. + function = gadget_is_dualspeed(gadget) && speed == USB_SPEED_HIGH
  61547. + ? (const struct usb_descriptor_header **)fsg_hs_function
  61548. + : (const struct usb_descriptor_header **)fsg_fs_function;
  61549. +
  61550. + /* for now, don't advertise srp-only devices */
  61551. + if (!gadget_is_otg(gadget))
  61552. + function++;
  61553. +
  61554. + len = usb_gadget_config_buf(&config_desc, buf, EP0_BUFSIZE, function);
  61555. + ((struct usb_config_descriptor *) buf)->bDescriptorType = type;
  61556. + return len;
  61557. +}
  61558. +
  61559. +
  61560. +/*-------------------------------------------------------------------------*/
  61561. +
  61562. +/* These routines may be called in process context or in_irq */
  61563. +
  61564. +/* Caller must hold fsg->lock */
  61565. +static void wakeup_thread(struct fsg_dev *fsg)
  61566. +{
  61567. + /* Tell the main thread that something has happened */
  61568. + fsg->thread_wakeup_needed = 1;
  61569. + if (fsg->thread_task)
  61570. + wake_up_process(fsg->thread_task);
  61571. +}
  61572. +
  61573. +
  61574. +static void raise_exception(struct fsg_dev *fsg, enum fsg_state new_state)
  61575. +{
  61576. + unsigned long flags;
  61577. +
  61578. + /* Do nothing if a higher-priority exception is already in progress.
  61579. + * If a lower-or-equal priority exception is in progress, preempt it
  61580. + * and notify the main thread by sending it a signal. */
  61581. + spin_lock_irqsave(&fsg->lock, flags);
  61582. + if (fsg->state <= new_state) {
  61583. + fsg->exception_req_tag = fsg->ep0_req_tag;
  61584. + fsg->state = new_state;
  61585. + if (fsg->thread_task)
  61586. + send_sig_info(SIGUSR1, SEND_SIG_FORCED,
  61587. + fsg->thread_task);
  61588. + }
  61589. + spin_unlock_irqrestore(&fsg->lock, flags);
  61590. +}
  61591. +
  61592. +
  61593. +/*-------------------------------------------------------------------------*/
  61594. +
  61595. +/* The disconnect callback and ep0 routines. These always run in_irq,
  61596. + * except that ep0_queue() is called in the main thread to acknowledge
  61597. + * completion of various requests: set config, set interface, and
  61598. + * Bulk-only device reset. */
  61599. +
  61600. +static void fsg_disconnect(struct usb_gadget *gadget)
  61601. +{
  61602. + struct fsg_dev *fsg = get_gadget_data(gadget);
  61603. +
  61604. + DBG(fsg, "disconnect or port reset\n");
  61605. + raise_exception(fsg, FSG_STATE_DISCONNECT);
  61606. +}
  61607. +
  61608. +
  61609. +static int ep0_queue(struct fsg_dev *fsg)
  61610. +{
  61611. + int rc;
  61612. +
  61613. + rc = usb_ep_queue(fsg->ep0, fsg->ep0req, GFP_ATOMIC);
  61614. + if (rc != 0 && rc != -ESHUTDOWN) {
  61615. +
  61616. + /* We can't do much more than wait for a reset */
  61617. + WARNING(fsg, "error in submission: %s --> %d\n",
  61618. + fsg->ep0->name, rc);
  61619. + }
  61620. + return rc;
  61621. +}
  61622. +
  61623. +static void ep0_complete(struct usb_ep *ep, struct usb_request *req)
  61624. +{
  61625. + struct fsg_dev *fsg = ep->driver_data;
  61626. +
  61627. + if (req->actual > 0)
  61628. + dump_msg(fsg, fsg->ep0req_name, req->buf, req->actual);
  61629. + if (req->status || req->actual != req->length)
  61630. + DBG(fsg, "%s --> %d, %u/%u\n", __func__,
  61631. + req->status, req->actual, req->length);
  61632. + if (req->status == -ECONNRESET) // Request was cancelled
  61633. + usb_ep_fifo_flush(ep);
  61634. +
  61635. + if (req->status == 0 && req->context)
  61636. + ((fsg_routine_t) (req->context))(fsg);
  61637. +}
  61638. +
  61639. +
  61640. +/*-------------------------------------------------------------------------*/
  61641. +
  61642. +/* Bulk and interrupt endpoint completion handlers.
  61643. + * These always run in_irq. */
  61644. +
  61645. +static void bulk_in_complete(struct usb_ep *ep, struct usb_request *req)
  61646. +{
  61647. + struct fsg_dev *fsg = ep->driver_data;
  61648. + struct fsg_buffhd *bh = req->context;
  61649. +
  61650. + if (req->status || req->actual != req->length)
  61651. + DBG(fsg, "%s --> %d, %u/%u\n", __func__,
  61652. + req->status, req->actual, req->length);
  61653. + if (req->status == -ECONNRESET) // Request was cancelled
  61654. + usb_ep_fifo_flush(ep);
  61655. +
  61656. + /* Hold the lock while we update the request and buffer states */
  61657. + smp_wmb();
  61658. + spin_lock(&fsg->lock);
  61659. + bh->inreq_busy = 0;
  61660. + bh->state = BUF_STATE_EMPTY;
  61661. + wakeup_thread(fsg);
  61662. + spin_unlock(&fsg->lock);
  61663. +}
  61664. +
  61665. +static void bulk_out_complete(struct usb_ep *ep, struct usb_request *req)
  61666. +{
  61667. + struct fsg_dev *fsg = ep->driver_data;
  61668. + struct fsg_buffhd *bh = req->context;
  61669. +
  61670. + dump_msg(fsg, "bulk-out", req->buf, req->actual);
  61671. + if (req->status || req->actual != bh->bulk_out_intended_length)
  61672. + DBG(fsg, "%s --> %d, %u/%u\n", __func__,
  61673. + req->status, req->actual,
  61674. + bh->bulk_out_intended_length);
  61675. + if (req->status == -ECONNRESET) // Request was cancelled
  61676. + usb_ep_fifo_flush(ep);
  61677. +
  61678. + /* Hold the lock while we update the request and buffer states */
  61679. + smp_wmb();
  61680. + spin_lock(&fsg->lock);
  61681. + bh->outreq_busy = 0;
  61682. + bh->state = BUF_STATE_FULL;
  61683. + wakeup_thread(fsg);
  61684. + spin_unlock(&fsg->lock);
  61685. +}
  61686. +
  61687. +
  61688. +#ifdef CONFIG_USB_FILE_STORAGE_TEST
  61689. +static void intr_in_complete(struct usb_ep *ep, struct usb_request *req)
  61690. +{
  61691. + struct fsg_dev *fsg = ep->driver_data;
  61692. + struct fsg_buffhd *bh = req->context;
  61693. +
  61694. + if (req->status || req->actual != req->length)
  61695. + DBG(fsg, "%s --> %d, %u/%u\n", __func__,
  61696. + req->status, req->actual, req->length);
  61697. + if (req->status == -ECONNRESET) // Request was cancelled
  61698. + usb_ep_fifo_flush(ep);
  61699. +
  61700. + /* Hold the lock while we update the request and buffer states */
  61701. + smp_wmb();
  61702. + spin_lock(&fsg->lock);
  61703. + fsg->intreq_busy = 0;
  61704. + bh->state = BUF_STATE_EMPTY;
  61705. + wakeup_thread(fsg);
  61706. + spin_unlock(&fsg->lock);
  61707. +}
  61708. +
  61709. +#else
  61710. +static void intr_in_complete(struct usb_ep *ep, struct usb_request *req)
  61711. +{}
  61712. +#endif /* CONFIG_USB_FILE_STORAGE_TEST */
  61713. +
  61714. +
  61715. +/*-------------------------------------------------------------------------*/
  61716. +
  61717. +/* Ep0 class-specific handlers. These always run in_irq. */
  61718. +
  61719. +#ifdef CONFIG_USB_FILE_STORAGE_TEST
  61720. +static void received_cbi_adsc(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  61721. +{
  61722. + struct usb_request *req = fsg->ep0req;
  61723. + static u8 cbi_reset_cmnd[6] = {
  61724. + SEND_DIAGNOSTIC, 4, 0xff, 0xff, 0xff, 0xff};
  61725. +
  61726. + /* Error in command transfer? */
  61727. + if (req->status || req->length != req->actual ||
  61728. + req->actual < 6 || req->actual > MAX_COMMAND_SIZE) {
  61729. +
  61730. + /* Not all controllers allow a protocol stall after
  61731. + * receiving control-out data, but we'll try anyway. */
  61732. + fsg_set_halt(fsg, fsg->ep0);
  61733. + return; // Wait for reset
  61734. + }
  61735. +
  61736. + /* Is it the special reset command? */
  61737. + if (req->actual >= sizeof cbi_reset_cmnd &&
  61738. + memcmp(req->buf, cbi_reset_cmnd,
  61739. + sizeof cbi_reset_cmnd) == 0) {
  61740. +
  61741. + /* Raise an exception to stop the current operation
  61742. + * and reinitialize our state. */
  61743. + DBG(fsg, "cbi reset request\n");
  61744. + raise_exception(fsg, FSG_STATE_RESET);
  61745. + return;
  61746. + }
  61747. +
  61748. + VDBG(fsg, "CB[I] accept device-specific command\n");
  61749. + spin_lock(&fsg->lock);
  61750. +
  61751. + /* Save the command for later */
  61752. + if (fsg->cbbuf_cmnd_size)
  61753. + WARNING(fsg, "CB[I] overwriting previous command\n");
  61754. + fsg->cbbuf_cmnd_size = req->actual;
  61755. + memcpy(fsg->cbbuf_cmnd, req->buf, fsg->cbbuf_cmnd_size);
  61756. +
  61757. + wakeup_thread(fsg);
  61758. + spin_unlock(&fsg->lock);
  61759. +}
  61760. +
  61761. +#else
  61762. +static void received_cbi_adsc(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  61763. +{}
  61764. +#endif /* CONFIG_USB_FILE_STORAGE_TEST */
  61765. +
  61766. +
  61767. +static int class_setup_req(struct fsg_dev *fsg,
  61768. + const struct usb_ctrlrequest *ctrl)
  61769. +{
  61770. + struct usb_request *req = fsg->ep0req;
  61771. + int value = -EOPNOTSUPP;
  61772. + u16 w_index = le16_to_cpu(ctrl->wIndex);
  61773. + u16 w_value = le16_to_cpu(ctrl->wValue);
  61774. + u16 w_length = le16_to_cpu(ctrl->wLength);
  61775. +
  61776. + if (!fsg->config)
  61777. + return value;
  61778. +
  61779. + /* Handle Bulk-only class-specific requests */
  61780. + if (transport_is_bbb()) {
  61781. + switch (ctrl->bRequest) {
  61782. +
  61783. + case US_BULK_RESET_REQUEST:
  61784. + if (ctrl->bRequestType != (USB_DIR_OUT |
  61785. + USB_TYPE_CLASS | USB_RECIP_INTERFACE))
  61786. + break;
  61787. + if (w_index != 0 || w_value != 0 || w_length != 0) {
  61788. + value = -EDOM;
  61789. + break;
  61790. + }
  61791. +
  61792. + /* Raise an exception to stop the current operation
  61793. + * and reinitialize our state. */
  61794. + DBG(fsg, "bulk reset request\n");
  61795. + raise_exception(fsg, FSG_STATE_RESET);
  61796. + value = DELAYED_STATUS;
  61797. + break;
  61798. +
  61799. + case US_BULK_GET_MAX_LUN:
  61800. + if (ctrl->bRequestType != (USB_DIR_IN |
  61801. + USB_TYPE_CLASS | USB_RECIP_INTERFACE))
  61802. + break;
  61803. + if (w_index != 0 || w_value != 0 || w_length != 1) {
  61804. + value = -EDOM;
  61805. + break;
  61806. + }
  61807. + VDBG(fsg, "get max LUN\n");
  61808. + *(u8 *) req->buf = fsg->nluns - 1;
  61809. + value = 1;
  61810. + break;
  61811. + }
  61812. + }
  61813. +
  61814. + /* Handle CBI class-specific requests */
  61815. + else {
  61816. + switch (ctrl->bRequest) {
  61817. +
  61818. + case USB_CBI_ADSC_REQUEST:
  61819. + if (ctrl->bRequestType != (USB_DIR_OUT |
  61820. + USB_TYPE_CLASS | USB_RECIP_INTERFACE))
  61821. + break;
  61822. + if (w_index != 0 || w_value != 0) {
  61823. + value = -EDOM;
  61824. + break;
  61825. + }
  61826. + if (w_length > MAX_COMMAND_SIZE) {
  61827. + value = -EOVERFLOW;
  61828. + break;
  61829. + }
  61830. + value = w_length;
  61831. + fsg->ep0req->context = received_cbi_adsc;
  61832. + break;
  61833. + }
  61834. + }
  61835. +
  61836. + if (value == -EOPNOTSUPP)
  61837. + VDBG(fsg,
  61838. + "unknown class-specific control req "
  61839. + "%02x.%02x v%04x i%04x l%u\n",
  61840. + ctrl->bRequestType, ctrl->bRequest,
  61841. + le16_to_cpu(ctrl->wValue), w_index, w_length);
  61842. + return value;
  61843. +}
  61844. +
  61845. +
  61846. +/*-------------------------------------------------------------------------*/
  61847. +
  61848. +/* Ep0 standard request handlers. These always run in_irq. */
  61849. +
  61850. +static int standard_setup_req(struct fsg_dev *fsg,
  61851. + const struct usb_ctrlrequest *ctrl)
  61852. +{
  61853. + struct usb_request *req = fsg->ep0req;
  61854. + int value = -EOPNOTSUPP;
  61855. + u16 w_index = le16_to_cpu(ctrl->wIndex);
  61856. + u16 w_value = le16_to_cpu(ctrl->wValue);
  61857. +
  61858. + /* Usually this just stores reply data in the pre-allocated ep0 buffer,
  61859. + * but config change events will also reconfigure hardware. */
  61860. + switch (ctrl->bRequest) {
  61861. +
  61862. + case USB_REQ_GET_DESCRIPTOR:
  61863. + if (ctrl->bRequestType != (USB_DIR_IN | USB_TYPE_STANDARD |
  61864. + USB_RECIP_DEVICE))
  61865. + break;
  61866. + switch (w_value >> 8) {
  61867. +
  61868. + case USB_DT_DEVICE:
  61869. + VDBG(fsg, "get device descriptor\n");
  61870. + device_desc.bMaxPacketSize0 = fsg->ep0->maxpacket;
  61871. + value = sizeof device_desc;
  61872. + memcpy(req->buf, &device_desc, value);
  61873. + break;
  61874. + case USB_DT_DEVICE_QUALIFIER:
  61875. + VDBG(fsg, "get device qualifier\n");
  61876. + if (!gadget_is_dualspeed(fsg->gadget) ||
  61877. + fsg->gadget->speed == USB_SPEED_SUPER)
  61878. + break;
  61879. + /*
  61880. + * Assume ep0 uses the same maxpacket value for both
  61881. + * speeds
  61882. + */
  61883. + dev_qualifier.bMaxPacketSize0 = fsg->ep0->maxpacket;
  61884. + value = sizeof dev_qualifier;
  61885. + memcpy(req->buf, &dev_qualifier, value);
  61886. + break;
  61887. +
  61888. + case USB_DT_OTHER_SPEED_CONFIG:
  61889. + VDBG(fsg, "get other-speed config descriptor\n");
  61890. + if (!gadget_is_dualspeed(fsg->gadget) ||
  61891. + fsg->gadget->speed == USB_SPEED_SUPER)
  61892. + break;
  61893. + goto get_config;
  61894. + case USB_DT_CONFIG:
  61895. + VDBG(fsg, "get configuration descriptor\n");
  61896. +get_config:
  61897. + value = populate_config_buf(fsg->gadget,
  61898. + req->buf,
  61899. + w_value >> 8,
  61900. + w_value & 0xff);
  61901. + break;
  61902. +
  61903. + case USB_DT_STRING:
  61904. + VDBG(fsg, "get string descriptor\n");
  61905. +
  61906. + /* wIndex == language code */
  61907. + value = usb_gadget_get_string(&fsg_stringtab,
  61908. + w_value & 0xff, req->buf);
  61909. + break;
  61910. +
  61911. + case USB_DT_BOS:
  61912. + VDBG(fsg, "get bos descriptor\n");
  61913. +
  61914. + if (gadget_is_superspeed(fsg->gadget))
  61915. + value = populate_bos(fsg, req->buf);
  61916. + break;
  61917. + }
  61918. +
  61919. + break;
  61920. +
  61921. + /* One config, two speeds */
  61922. + case USB_REQ_SET_CONFIGURATION:
  61923. + if (ctrl->bRequestType != (USB_DIR_OUT | USB_TYPE_STANDARD |
  61924. + USB_RECIP_DEVICE))
  61925. + break;
  61926. + VDBG(fsg, "set configuration\n");
  61927. + if (w_value == CONFIG_VALUE || w_value == 0) {
  61928. + fsg->new_config = w_value;
  61929. +
  61930. + /* Raise an exception to wipe out previous transaction
  61931. + * state (queued bufs, etc) and set the new config. */
  61932. + raise_exception(fsg, FSG_STATE_CONFIG_CHANGE);
  61933. + value = DELAYED_STATUS;
  61934. + }
  61935. + break;
  61936. + case USB_REQ_GET_CONFIGURATION:
  61937. + if (ctrl->bRequestType != (USB_DIR_IN | USB_TYPE_STANDARD |
  61938. + USB_RECIP_DEVICE))
  61939. + break;
  61940. + VDBG(fsg, "get configuration\n");
  61941. + *(u8 *) req->buf = fsg->config;
  61942. + value = 1;
  61943. + break;
  61944. +
  61945. + case USB_REQ_SET_INTERFACE:
  61946. + if (ctrl->bRequestType != (USB_DIR_OUT| USB_TYPE_STANDARD |
  61947. + USB_RECIP_INTERFACE))
  61948. + break;
  61949. + if (fsg->config && w_index == 0) {
  61950. +
  61951. + /* Raise an exception to wipe out previous transaction
  61952. + * state (queued bufs, etc) and install the new
  61953. + * interface altsetting. */
  61954. + raise_exception(fsg, FSG_STATE_INTERFACE_CHANGE);
  61955. + value = DELAYED_STATUS;
  61956. + }
  61957. + break;
  61958. + case USB_REQ_GET_INTERFACE:
  61959. + if (ctrl->bRequestType != (USB_DIR_IN | USB_TYPE_STANDARD |
  61960. + USB_RECIP_INTERFACE))
  61961. + break;
  61962. + if (!fsg->config)
  61963. + break;
  61964. + if (w_index != 0) {
  61965. + value = -EDOM;
  61966. + break;
  61967. + }
  61968. + VDBG(fsg, "get interface\n");
  61969. + *(u8 *) req->buf = 0;
  61970. + value = 1;
  61971. + break;
  61972. +
  61973. + default:
  61974. + VDBG(fsg,
  61975. + "unknown control req %02x.%02x v%04x i%04x l%u\n",
  61976. + ctrl->bRequestType, ctrl->bRequest,
  61977. + w_value, w_index, le16_to_cpu(ctrl->wLength));
  61978. + }
  61979. +
  61980. + return value;
  61981. +}
  61982. +
  61983. +
  61984. +static int fsg_setup(struct usb_gadget *gadget,
  61985. + const struct usb_ctrlrequest *ctrl)
  61986. +{
  61987. + struct fsg_dev *fsg = get_gadget_data(gadget);
  61988. + int rc;
  61989. + int w_length = le16_to_cpu(ctrl->wLength);
  61990. +
  61991. + ++fsg->ep0_req_tag; // Record arrival of a new request
  61992. + fsg->ep0req->context = NULL;
  61993. + fsg->ep0req->length = 0;
  61994. + dump_msg(fsg, "ep0-setup", (u8 *) ctrl, sizeof(*ctrl));
  61995. +
  61996. + if ((ctrl->bRequestType & USB_TYPE_MASK) == USB_TYPE_CLASS)
  61997. + rc = class_setup_req(fsg, ctrl);
  61998. + else
  61999. + rc = standard_setup_req(fsg, ctrl);
  62000. +
  62001. + /* Respond with data/status or defer until later? */
  62002. + if (rc >= 0 && rc != DELAYED_STATUS) {
  62003. + rc = min(rc, w_length);
  62004. + fsg->ep0req->length = rc;
  62005. + fsg->ep0req->zero = rc < w_length;
  62006. + fsg->ep0req_name = (ctrl->bRequestType & USB_DIR_IN ?
  62007. + "ep0-in" : "ep0-out");
  62008. + rc = ep0_queue(fsg);
  62009. + }
  62010. +
  62011. + /* Device either stalls (rc < 0) or reports success */
  62012. + return rc;
  62013. +}
  62014. +
  62015. +
  62016. +/*-------------------------------------------------------------------------*/
  62017. +
  62018. +/* All the following routines run in process context */
  62019. +
  62020. +
  62021. +/* Use this for bulk or interrupt transfers, not ep0 */
  62022. +static void start_transfer(struct fsg_dev *fsg, struct usb_ep *ep,
  62023. + struct usb_request *req, int *pbusy,
  62024. + enum fsg_buffer_state *state)
  62025. +{
  62026. + int rc;
  62027. +
  62028. + if (ep == fsg->bulk_in)
  62029. + dump_msg(fsg, "bulk-in", req->buf, req->length);
  62030. + else if (ep == fsg->intr_in)
  62031. + dump_msg(fsg, "intr-in", req->buf, req->length);
  62032. +
  62033. + spin_lock_irq(&fsg->lock);
  62034. + *pbusy = 1;
  62035. + *state = BUF_STATE_BUSY;
  62036. + spin_unlock_irq(&fsg->lock);
  62037. + rc = usb_ep_queue(ep, req, GFP_KERNEL);
  62038. + if (rc != 0) {
  62039. + *pbusy = 0;
  62040. + *state = BUF_STATE_EMPTY;
  62041. +
  62042. + /* We can't do much more than wait for a reset */
  62043. +
  62044. + /* Note: currently the net2280 driver fails zero-length
  62045. + * submissions if DMA is enabled. */
  62046. + if (rc != -ESHUTDOWN && !(rc == -EOPNOTSUPP &&
  62047. + req->length == 0))
  62048. + WARNING(fsg, "error in submission: %s --> %d\n",
  62049. + ep->name, rc);
  62050. + }
  62051. +}
  62052. +
  62053. +
  62054. +static int sleep_thread(struct fsg_dev *fsg)
  62055. +{
  62056. + int rc = 0;
  62057. +
  62058. + /* Wait until a signal arrives or we are woken up */
  62059. + for (;;) {
  62060. + try_to_freeze();
  62061. + set_current_state(TASK_INTERRUPTIBLE);
  62062. + if (signal_pending(current)) {
  62063. + rc = -EINTR;
  62064. + break;
  62065. + }
  62066. + if (fsg->thread_wakeup_needed)
  62067. + break;
  62068. + schedule();
  62069. + }
  62070. + __set_current_state(TASK_RUNNING);
  62071. + fsg->thread_wakeup_needed = 0;
  62072. + return rc;
  62073. +}
  62074. +
  62075. +
  62076. +/*-------------------------------------------------------------------------*/
  62077. +
  62078. +static int do_read(struct fsg_dev *fsg)
  62079. +{
  62080. + struct fsg_lun *curlun = fsg->curlun;
  62081. + u32 lba;
  62082. + struct fsg_buffhd *bh;
  62083. + int rc;
  62084. + u32 amount_left;
  62085. + loff_t file_offset, file_offset_tmp;
  62086. + unsigned int amount;
  62087. + ssize_t nread;
  62088. +
  62089. + /* Get the starting Logical Block Address and check that it's
  62090. + * not too big */
  62091. + if (fsg->cmnd[0] == READ_6)
  62092. + lba = get_unaligned_be24(&fsg->cmnd[1]);
  62093. + else {
  62094. + lba = get_unaligned_be32(&fsg->cmnd[2]);
  62095. +
  62096. + /* We allow DPO (Disable Page Out = don't save data in the
  62097. + * cache) and FUA (Force Unit Access = don't read from the
  62098. + * cache), but we don't implement them. */
  62099. + if ((fsg->cmnd[1] & ~0x18) != 0) {
  62100. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  62101. + return -EINVAL;
  62102. + }
  62103. + }
  62104. + if (lba >= curlun->num_sectors) {
  62105. + curlun->sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  62106. + return -EINVAL;
  62107. + }
  62108. + file_offset = ((loff_t) lba) << curlun->blkbits;
  62109. +
  62110. + /* Carry out the file reads */
  62111. + amount_left = fsg->data_size_from_cmnd;
  62112. + if (unlikely(amount_left == 0))
  62113. + return -EIO; // No default reply
  62114. +
  62115. + for (;;) {
  62116. +
  62117. + /* Figure out how much we need to read:
  62118. + * Try to read the remaining amount.
  62119. + * But don't read more than the buffer size.
  62120. + * And don't try to read past the end of the file.
  62121. + */
  62122. + amount = min((unsigned int) amount_left, mod_data.buflen);
  62123. + amount = min((loff_t) amount,
  62124. + curlun->file_length - file_offset);
  62125. +
  62126. + /* Wait for the next buffer to become available */
  62127. + bh = fsg->next_buffhd_to_fill;
  62128. + while (bh->state != BUF_STATE_EMPTY) {
  62129. + rc = sleep_thread(fsg);
  62130. + if (rc)
  62131. + return rc;
  62132. + }
  62133. +
  62134. + /* If we were asked to read past the end of file,
  62135. + * end with an empty buffer. */
  62136. + if (amount == 0) {
  62137. + curlun->sense_data =
  62138. + SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  62139. + curlun->sense_data_info = file_offset >> curlun->blkbits;
  62140. + curlun->info_valid = 1;
  62141. + bh->inreq->length = 0;
  62142. + bh->state = BUF_STATE_FULL;
  62143. + break;
  62144. + }
  62145. +
  62146. + /* Perform the read */
  62147. + file_offset_tmp = file_offset;
  62148. + nread = vfs_read(curlun->filp,
  62149. + (char __user *) bh->buf,
  62150. + amount, &file_offset_tmp);
  62151. + VLDBG(curlun, "file read %u @ %llu -> %d\n", amount,
  62152. + (unsigned long long) file_offset,
  62153. + (int) nread);
  62154. + if (signal_pending(current))
  62155. + return -EINTR;
  62156. +
  62157. + if (nread < 0) {
  62158. + LDBG(curlun, "error in file read: %d\n",
  62159. + (int) nread);
  62160. + nread = 0;
  62161. + } else if (nread < amount) {
  62162. + LDBG(curlun, "partial file read: %d/%u\n",
  62163. + (int) nread, amount);
  62164. + nread = round_down(nread, curlun->blksize);
  62165. + }
  62166. + file_offset += nread;
  62167. + amount_left -= nread;
  62168. + fsg->residue -= nread;
  62169. +
  62170. + /* Except at the end of the transfer, nread will be
  62171. + * equal to the buffer size, which is divisible by the
  62172. + * bulk-in maxpacket size.
  62173. + */
  62174. + bh->inreq->length = nread;
  62175. + bh->state = BUF_STATE_FULL;
  62176. +
  62177. + /* If an error occurred, report it and its position */
  62178. + if (nread < amount) {
  62179. + curlun->sense_data = SS_UNRECOVERED_READ_ERROR;
  62180. + curlun->sense_data_info = file_offset >> curlun->blkbits;
  62181. + curlun->info_valid = 1;
  62182. + break;
  62183. + }
  62184. +
  62185. + if (amount_left == 0)
  62186. + break; // No more left to read
  62187. +
  62188. + /* Send this buffer and go read some more */
  62189. + bh->inreq->zero = 0;
  62190. + start_transfer(fsg, fsg->bulk_in, bh->inreq,
  62191. + &bh->inreq_busy, &bh->state);
  62192. + fsg->next_buffhd_to_fill = bh->next;
  62193. + }
  62194. +
  62195. + return -EIO; // No default reply
  62196. +}
  62197. +
  62198. +
  62199. +/*-------------------------------------------------------------------------*/
  62200. +
  62201. +static int do_write(struct fsg_dev *fsg)
  62202. +{
  62203. + struct fsg_lun *curlun = fsg->curlun;
  62204. + u32 lba;
  62205. + struct fsg_buffhd *bh;
  62206. + int get_some_more;
  62207. + u32 amount_left_to_req, amount_left_to_write;
  62208. + loff_t usb_offset, file_offset, file_offset_tmp;
  62209. + unsigned int amount;
  62210. + ssize_t nwritten;
  62211. + int rc;
  62212. +
  62213. + if (curlun->ro) {
  62214. + curlun->sense_data = SS_WRITE_PROTECTED;
  62215. + return -EINVAL;
  62216. + }
  62217. + spin_lock(&curlun->filp->f_lock);
  62218. + curlun->filp->f_flags &= ~O_SYNC; // Default is not to wait
  62219. + spin_unlock(&curlun->filp->f_lock);
  62220. +
  62221. + /* Get the starting Logical Block Address and check that it's
  62222. + * not too big */
  62223. + if (fsg->cmnd[0] == WRITE_6)
  62224. + lba = get_unaligned_be24(&fsg->cmnd[1]);
  62225. + else {
  62226. + lba = get_unaligned_be32(&fsg->cmnd[2]);
  62227. +
  62228. + /* We allow DPO (Disable Page Out = don't save data in the
  62229. + * cache) and FUA (Force Unit Access = write directly to the
  62230. + * medium). We don't implement DPO; we implement FUA by
  62231. + * performing synchronous output. */
  62232. + if ((fsg->cmnd[1] & ~0x18) != 0) {
  62233. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  62234. + return -EINVAL;
  62235. + }
  62236. + /* FUA */
  62237. + if (!curlun->nofua && (fsg->cmnd[1] & 0x08)) {
  62238. + spin_lock(&curlun->filp->f_lock);
  62239. + curlun->filp->f_flags |= O_DSYNC;
  62240. + spin_unlock(&curlun->filp->f_lock);
  62241. + }
  62242. + }
  62243. + if (lba >= curlun->num_sectors) {
  62244. + curlun->sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  62245. + return -EINVAL;
  62246. + }
  62247. +
  62248. + /* Carry out the file writes */
  62249. + get_some_more = 1;
  62250. + file_offset = usb_offset = ((loff_t) lba) << curlun->blkbits;
  62251. + amount_left_to_req = amount_left_to_write = fsg->data_size_from_cmnd;
  62252. +
  62253. + while (amount_left_to_write > 0) {
  62254. +
  62255. + /* Queue a request for more data from the host */
  62256. + bh = fsg->next_buffhd_to_fill;
  62257. + if (bh->state == BUF_STATE_EMPTY && get_some_more) {
  62258. +
  62259. + /* Figure out how much we want to get:
  62260. + * Try to get the remaining amount,
  62261. + * but not more than the buffer size.
  62262. + */
  62263. + amount = min(amount_left_to_req, mod_data.buflen);
  62264. +
  62265. + /* Beyond the end of the backing file? */
  62266. + if (usb_offset >= curlun->file_length) {
  62267. + get_some_more = 0;
  62268. + curlun->sense_data =
  62269. + SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  62270. + curlun->sense_data_info = usb_offset >> curlun->blkbits;
  62271. + curlun->info_valid = 1;
  62272. + continue;
  62273. + }
  62274. +
  62275. + /* Get the next buffer */
  62276. + usb_offset += amount;
  62277. + fsg->usb_amount_left -= amount;
  62278. + amount_left_to_req -= amount;
  62279. + if (amount_left_to_req == 0)
  62280. + get_some_more = 0;
  62281. +
  62282. + /* Except at the end of the transfer, amount will be
  62283. + * equal to the buffer size, which is divisible by
  62284. + * the bulk-out maxpacket size.
  62285. + */
  62286. + set_bulk_out_req_length(fsg, bh, amount);
  62287. + start_transfer(fsg, fsg->bulk_out, bh->outreq,
  62288. + &bh->outreq_busy, &bh->state);
  62289. + fsg->next_buffhd_to_fill = bh->next;
  62290. + continue;
  62291. + }
  62292. +
  62293. + /* Write the received data to the backing file */
  62294. + bh = fsg->next_buffhd_to_drain;
  62295. + if (bh->state == BUF_STATE_EMPTY && !get_some_more)
  62296. + break; // We stopped early
  62297. + if (bh->state == BUF_STATE_FULL) {
  62298. + smp_rmb();
  62299. + fsg->next_buffhd_to_drain = bh->next;
  62300. + bh->state = BUF_STATE_EMPTY;
  62301. +
  62302. + /* Did something go wrong with the transfer? */
  62303. + if (bh->outreq->status != 0) {
  62304. + curlun->sense_data = SS_COMMUNICATION_FAILURE;
  62305. + curlun->sense_data_info = file_offset >> curlun->blkbits;
  62306. + curlun->info_valid = 1;
  62307. + break;
  62308. + }
  62309. +
  62310. + amount = bh->outreq->actual;
  62311. + if (curlun->file_length - file_offset < amount) {
  62312. + LERROR(curlun,
  62313. + "write %u @ %llu beyond end %llu\n",
  62314. + amount, (unsigned long long) file_offset,
  62315. + (unsigned long long) curlun->file_length);
  62316. + amount = curlun->file_length - file_offset;
  62317. + }
  62318. +
  62319. + /* Don't accept excess data. The spec doesn't say
  62320. + * what to do in this case. We'll ignore the error.
  62321. + */
  62322. + amount = min(amount, bh->bulk_out_intended_length);
  62323. +
  62324. + /* Don't write a partial block */
  62325. + amount = round_down(amount, curlun->blksize);
  62326. + if (amount == 0)
  62327. + goto empty_write;
  62328. +
  62329. + /* Perform the write */
  62330. + file_offset_tmp = file_offset;
  62331. + nwritten = vfs_write(curlun->filp,
  62332. + (char __user *) bh->buf,
  62333. + amount, &file_offset_tmp);
  62334. + VLDBG(curlun, "file write %u @ %llu -> %d\n", amount,
  62335. + (unsigned long long) file_offset,
  62336. + (int) nwritten);
  62337. + if (signal_pending(current))
  62338. + return -EINTR; // Interrupted!
  62339. +
  62340. + if (nwritten < 0) {
  62341. + LDBG(curlun, "error in file write: %d\n",
  62342. + (int) nwritten);
  62343. + nwritten = 0;
  62344. + } else if (nwritten < amount) {
  62345. + LDBG(curlun, "partial file write: %d/%u\n",
  62346. + (int) nwritten, amount);
  62347. + nwritten = round_down(nwritten, curlun->blksize);
  62348. + }
  62349. + file_offset += nwritten;
  62350. + amount_left_to_write -= nwritten;
  62351. + fsg->residue -= nwritten;
  62352. +
  62353. + /* If an error occurred, report it and its position */
  62354. + if (nwritten < amount) {
  62355. + curlun->sense_data = SS_WRITE_ERROR;
  62356. + curlun->sense_data_info = file_offset >> curlun->blkbits;
  62357. + curlun->info_valid = 1;
  62358. + break;
  62359. + }
  62360. +
  62361. + empty_write:
  62362. + /* Did the host decide to stop early? */
  62363. + if (bh->outreq->actual < bh->bulk_out_intended_length) {
  62364. + fsg->short_packet_received = 1;
  62365. + break;
  62366. + }
  62367. + continue;
  62368. + }
  62369. +
  62370. + /* Wait for something to happen */
  62371. + rc = sleep_thread(fsg);
  62372. + if (rc)
  62373. + return rc;
  62374. + }
  62375. +
  62376. + return -EIO; // No default reply
  62377. +}
  62378. +
  62379. +
  62380. +/*-------------------------------------------------------------------------*/
  62381. +
  62382. +static int do_synchronize_cache(struct fsg_dev *fsg)
  62383. +{
  62384. + struct fsg_lun *curlun = fsg->curlun;
  62385. + int rc;
  62386. +
  62387. + /* We ignore the requested LBA and write out all file's
  62388. + * dirty data buffers. */
  62389. + rc = fsg_lun_fsync_sub(curlun);
  62390. + if (rc)
  62391. + curlun->sense_data = SS_WRITE_ERROR;
  62392. + return 0;
  62393. +}
  62394. +
  62395. +
  62396. +/*-------------------------------------------------------------------------*/
  62397. +
  62398. +static void invalidate_sub(struct fsg_lun *curlun)
  62399. +{
  62400. + struct file *filp = curlun->filp;
  62401. + struct inode *inode = filp->f_path.dentry->d_inode;
  62402. + unsigned long rc;
  62403. +
  62404. + rc = invalidate_mapping_pages(inode->i_mapping, 0, -1);
  62405. + VLDBG(curlun, "invalidate_mapping_pages -> %ld\n", rc);
  62406. +}
  62407. +
  62408. +static int do_verify(struct fsg_dev *fsg)
  62409. +{
  62410. + struct fsg_lun *curlun = fsg->curlun;
  62411. + u32 lba;
  62412. + u32 verification_length;
  62413. + struct fsg_buffhd *bh = fsg->next_buffhd_to_fill;
  62414. + loff_t file_offset, file_offset_tmp;
  62415. + u32 amount_left;
  62416. + unsigned int amount;
  62417. + ssize_t nread;
  62418. +
  62419. + /* Get the starting Logical Block Address and check that it's
  62420. + * not too big */
  62421. + lba = get_unaligned_be32(&fsg->cmnd[2]);
  62422. + if (lba >= curlun->num_sectors) {
  62423. + curlun->sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  62424. + return -EINVAL;
  62425. + }
  62426. +
  62427. + /* We allow DPO (Disable Page Out = don't save data in the
  62428. + * cache) but we don't implement it. */
  62429. + if ((fsg->cmnd[1] & ~0x10) != 0) {
  62430. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  62431. + return -EINVAL;
  62432. + }
  62433. +
  62434. + verification_length = get_unaligned_be16(&fsg->cmnd[7]);
  62435. + if (unlikely(verification_length == 0))
  62436. + return -EIO; // No default reply
  62437. +
  62438. + /* Prepare to carry out the file verify */
  62439. + amount_left = verification_length << curlun->blkbits;
  62440. + file_offset = ((loff_t) lba) << curlun->blkbits;
  62441. +
  62442. + /* Write out all the dirty buffers before invalidating them */
  62443. + fsg_lun_fsync_sub(curlun);
  62444. + if (signal_pending(current))
  62445. + return -EINTR;
  62446. +
  62447. + invalidate_sub(curlun);
  62448. + if (signal_pending(current))
  62449. + return -EINTR;
  62450. +
  62451. + /* Just try to read the requested blocks */
  62452. + while (amount_left > 0) {
  62453. +
  62454. + /* Figure out how much we need to read:
  62455. + * Try to read the remaining amount, but not more than
  62456. + * the buffer size.
  62457. + * And don't try to read past the end of the file.
  62458. + */
  62459. + amount = min((unsigned int) amount_left, mod_data.buflen);
  62460. + amount = min((loff_t) amount,
  62461. + curlun->file_length - file_offset);
  62462. + if (amount == 0) {
  62463. + curlun->sense_data =
  62464. + SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  62465. + curlun->sense_data_info = file_offset >> curlun->blkbits;
  62466. + curlun->info_valid = 1;
  62467. + break;
  62468. + }
  62469. +
  62470. + /* Perform the read */
  62471. + file_offset_tmp = file_offset;
  62472. + nread = vfs_read(curlun->filp,
  62473. + (char __user *) bh->buf,
  62474. + amount, &file_offset_tmp);
  62475. + VLDBG(curlun, "file read %u @ %llu -> %d\n", amount,
  62476. + (unsigned long long) file_offset,
  62477. + (int) nread);
  62478. + if (signal_pending(current))
  62479. + return -EINTR;
  62480. +
  62481. + if (nread < 0) {
  62482. + LDBG(curlun, "error in file verify: %d\n",
  62483. + (int) nread);
  62484. + nread = 0;
  62485. + } else if (nread < amount) {
  62486. + LDBG(curlun, "partial file verify: %d/%u\n",
  62487. + (int) nread, amount);
  62488. + nread = round_down(nread, curlun->blksize);
  62489. + }
  62490. + if (nread == 0) {
  62491. + curlun->sense_data = SS_UNRECOVERED_READ_ERROR;
  62492. + curlun->sense_data_info = file_offset >> curlun->blkbits;
  62493. + curlun->info_valid = 1;
  62494. + break;
  62495. + }
  62496. + file_offset += nread;
  62497. + amount_left -= nread;
  62498. + }
  62499. + return 0;
  62500. +}
  62501. +
  62502. +
  62503. +/*-------------------------------------------------------------------------*/
  62504. +
  62505. +static int do_inquiry(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  62506. +{
  62507. + u8 *buf = (u8 *) bh->buf;
  62508. +
  62509. + static char vendor_id[] = "Linux ";
  62510. + static char product_disk_id[] = "File-Stor Gadget";
  62511. + static char product_cdrom_id[] = "File-CD Gadget ";
  62512. +
  62513. + if (!fsg->curlun) { // Unsupported LUNs are okay
  62514. + fsg->bad_lun_okay = 1;
  62515. + memset(buf, 0, 36);
  62516. + buf[0] = 0x7f; // Unsupported, no device-type
  62517. + buf[4] = 31; // Additional length
  62518. + return 36;
  62519. + }
  62520. +
  62521. + memset(buf, 0, 8);
  62522. + buf[0] = (mod_data.cdrom ? TYPE_ROM : TYPE_DISK);
  62523. + if (mod_data.removable)
  62524. + buf[1] = 0x80;
  62525. + buf[2] = 2; // ANSI SCSI level 2
  62526. + buf[3] = 2; // SCSI-2 INQUIRY data format
  62527. + buf[4] = 31; // Additional length
  62528. + // No special options
  62529. + sprintf(buf + 8, "%-8s%-16s%04x", vendor_id,
  62530. + (mod_data.cdrom ? product_cdrom_id :
  62531. + product_disk_id),
  62532. + mod_data.release);
  62533. + return 36;
  62534. +}
  62535. +
  62536. +
  62537. +static int do_request_sense(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  62538. +{
  62539. + struct fsg_lun *curlun = fsg->curlun;
  62540. + u8 *buf = (u8 *) bh->buf;
  62541. + u32 sd, sdinfo;
  62542. + int valid;
  62543. +
  62544. + /*
  62545. + * From the SCSI-2 spec., section 7.9 (Unit attention condition):
  62546. + *
  62547. + * If a REQUEST SENSE command is received from an initiator
  62548. + * with a pending unit attention condition (before the target
  62549. + * generates the contingent allegiance condition), then the
  62550. + * target shall either:
  62551. + * a) report any pending sense data and preserve the unit
  62552. + * attention condition on the logical unit, or,
  62553. + * b) report the unit attention condition, may discard any
  62554. + * pending sense data, and clear the unit attention
  62555. + * condition on the logical unit for that initiator.
  62556. + *
  62557. + * FSG normally uses option a); enable this code to use option b).
  62558. + */
  62559. +#if 0
  62560. + if (curlun && curlun->unit_attention_data != SS_NO_SENSE) {
  62561. + curlun->sense_data = curlun->unit_attention_data;
  62562. + curlun->unit_attention_data = SS_NO_SENSE;
  62563. + }
  62564. +#endif
  62565. +
  62566. + if (!curlun) { // Unsupported LUNs are okay
  62567. + fsg->bad_lun_okay = 1;
  62568. + sd = SS_LOGICAL_UNIT_NOT_SUPPORTED;
  62569. + sdinfo = 0;
  62570. + valid = 0;
  62571. + } else {
  62572. + sd = curlun->sense_data;
  62573. + sdinfo = curlun->sense_data_info;
  62574. + valid = curlun->info_valid << 7;
  62575. + curlun->sense_data = SS_NO_SENSE;
  62576. + curlun->sense_data_info = 0;
  62577. + curlun->info_valid = 0;
  62578. + }
  62579. +
  62580. + memset(buf, 0, 18);
  62581. + buf[0] = valid | 0x70; // Valid, current error
  62582. + buf[2] = SK(sd);
  62583. + put_unaligned_be32(sdinfo, &buf[3]); /* Sense information */
  62584. + buf[7] = 18 - 8; // Additional sense length
  62585. + buf[12] = ASC(sd);
  62586. + buf[13] = ASCQ(sd);
  62587. + return 18;
  62588. +}
  62589. +
  62590. +
  62591. +static int do_read_capacity(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  62592. +{
  62593. + struct fsg_lun *curlun = fsg->curlun;
  62594. + u32 lba = get_unaligned_be32(&fsg->cmnd[2]);
  62595. + int pmi = fsg->cmnd[8];
  62596. + u8 *buf = (u8 *) bh->buf;
  62597. +
  62598. + /* Check the PMI and LBA fields */
  62599. + if (pmi > 1 || (pmi == 0 && lba != 0)) {
  62600. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  62601. + return -EINVAL;
  62602. + }
  62603. +
  62604. + put_unaligned_be32(curlun->num_sectors - 1, &buf[0]);
  62605. + /* Max logical block */
  62606. + put_unaligned_be32(curlun->blksize, &buf[4]); /* Block length */
  62607. + return 8;
  62608. +}
  62609. +
  62610. +
  62611. +static int do_read_header(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  62612. +{
  62613. + struct fsg_lun *curlun = fsg->curlun;
  62614. + int msf = fsg->cmnd[1] & 0x02;
  62615. + u32 lba = get_unaligned_be32(&fsg->cmnd[2]);
  62616. + u8 *buf = (u8 *) bh->buf;
  62617. +
  62618. + if ((fsg->cmnd[1] & ~0x02) != 0) { /* Mask away MSF */
  62619. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  62620. + return -EINVAL;
  62621. + }
  62622. + if (lba >= curlun->num_sectors) {
  62623. + curlun->sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  62624. + return -EINVAL;
  62625. + }
  62626. +
  62627. + memset(buf, 0, 8);
  62628. + buf[0] = 0x01; /* 2048 bytes of user data, rest is EC */
  62629. + store_cdrom_address(&buf[4], msf, lba);
  62630. + return 8;
  62631. +}
  62632. +
  62633. +
  62634. +static int do_read_toc(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  62635. +{
  62636. + struct fsg_lun *curlun = fsg->curlun;
  62637. + int msf = fsg->cmnd[1] & 0x02;
  62638. + int start_track = fsg->cmnd[6];
  62639. + u8 *buf = (u8 *) bh->buf;
  62640. +
  62641. + if ((fsg->cmnd[1] & ~0x02) != 0 || /* Mask away MSF */
  62642. + start_track > 1) {
  62643. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  62644. + return -EINVAL;
  62645. + }
  62646. +
  62647. + memset(buf, 0, 20);
  62648. + buf[1] = (20-2); /* TOC data length */
  62649. + buf[2] = 1; /* First track number */
  62650. + buf[3] = 1; /* Last track number */
  62651. + buf[5] = 0x16; /* Data track, copying allowed */
  62652. + buf[6] = 0x01; /* Only track is number 1 */
  62653. + store_cdrom_address(&buf[8], msf, 0);
  62654. +
  62655. + buf[13] = 0x16; /* Lead-out track is data */
  62656. + buf[14] = 0xAA; /* Lead-out track number */
  62657. + store_cdrom_address(&buf[16], msf, curlun->num_sectors);
  62658. + return 20;
  62659. +}
  62660. +
  62661. +
  62662. +static int do_mode_sense(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  62663. +{
  62664. + struct fsg_lun *curlun = fsg->curlun;
  62665. + int mscmnd = fsg->cmnd[0];
  62666. + u8 *buf = (u8 *) bh->buf;
  62667. + u8 *buf0 = buf;
  62668. + int pc, page_code;
  62669. + int changeable_values, all_pages;
  62670. + int valid_page = 0;
  62671. + int len, limit;
  62672. +
  62673. + if ((fsg->cmnd[1] & ~0x08) != 0) { // Mask away DBD
  62674. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  62675. + return -EINVAL;
  62676. + }
  62677. + pc = fsg->cmnd[2] >> 6;
  62678. + page_code = fsg->cmnd[2] & 0x3f;
  62679. + if (pc == 3) {
  62680. + curlun->sense_data = SS_SAVING_PARAMETERS_NOT_SUPPORTED;
  62681. + return -EINVAL;
  62682. + }
  62683. + changeable_values = (pc == 1);
  62684. + all_pages = (page_code == 0x3f);
  62685. +
  62686. + /* Write the mode parameter header. Fixed values are: default
  62687. + * medium type, no cache control (DPOFUA), and no block descriptors.
  62688. + * The only variable value is the WriteProtect bit. We will fill in
  62689. + * the mode data length later. */
  62690. + memset(buf, 0, 8);
  62691. + if (mscmnd == MODE_SENSE) {
  62692. + buf[2] = (curlun->ro ? 0x80 : 0x00); // WP, DPOFUA
  62693. + buf += 4;
  62694. + limit = 255;
  62695. + } else { // MODE_SENSE_10
  62696. + buf[3] = (curlun->ro ? 0x80 : 0x00); // WP, DPOFUA
  62697. + buf += 8;
  62698. + limit = 65535; // Should really be mod_data.buflen
  62699. + }
  62700. +
  62701. + /* No block descriptors */
  62702. +
  62703. + /* The mode pages, in numerical order. The only page we support
  62704. + * is the Caching page. */
  62705. + if (page_code == 0x08 || all_pages) {
  62706. + valid_page = 1;
  62707. + buf[0] = 0x08; // Page code
  62708. + buf[1] = 10; // Page length
  62709. + memset(buf+2, 0, 10); // None of the fields are changeable
  62710. +
  62711. + if (!changeable_values) {
  62712. + buf[2] = 0x04; // Write cache enable,
  62713. + // Read cache not disabled
  62714. + // No cache retention priorities
  62715. + put_unaligned_be16(0xffff, &buf[4]);
  62716. + /* Don't disable prefetch */
  62717. + /* Minimum prefetch = 0 */
  62718. + put_unaligned_be16(0xffff, &buf[8]);
  62719. + /* Maximum prefetch */
  62720. + put_unaligned_be16(0xffff, &buf[10]);
  62721. + /* Maximum prefetch ceiling */
  62722. + }
  62723. + buf += 12;
  62724. + }
  62725. +
  62726. + /* Check that a valid page was requested and the mode data length
  62727. + * isn't too long. */
  62728. + len = buf - buf0;
  62729. + if (!valid_page || len > limit) {
  62730. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  62731. + return -EINVAL;
  62732. + }
  62733. +
  62734. + /* Store the mode data length */
  62735. + if (mscmnd == MODE_SENSE)
  62736. + buf0[0] = len - 1;
  62737. + else
  62738. + put_unaligned_be16(len - 2, buf0);
  62739. + return len;
  62740. +}
  62741. +
  62742. +
  62743. +static int do_start_stop(struct fsg_dev *fsg)
  62744. +{
  62745. + struct fsg_lun *curlun = fsg->curlun;
  62746. + int loej, start;
  62747. +
  62748. + if (!mod_data.removable) {
  62749. + curlun->sense_data = SS_INVALID_COMMAND;
  62750. + return -EINVAL;
  62751. + }
  62752. +
  62753. + // int immed = fsg->cmnd[1] & 0x01;
  62754. + loej = fsg->cmnd[4] & 0x02;
  62755. + start = fsg->cmnd[4] & 0x01;
  62756. +
  62757. +#ifdef CONFIG_USB_FILE_STORAGE_TEST
  62758. + if ((fsg->cmnd[1] & ~0x01) != 0 || // Mask away Immed
  62759. + (fsg->cmnd[4] & ~0x03) != 0) { // Mask LoEj, Start
  62760. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  62761. + return -EINVAL;
  62762. + }
  62763. +
  62764. + if (!start) {
  62765. +
  62766. + /* Are we allowed to unload the media? */
  62767. + if (curlun->prevent_medium_removal) {
  62768. + LDBG(curlun, "unload attempt prevented\n");
  62769. + curlun->sense_data = SS_MEDIUM_REMOVAL_PREVENTED;
  62770. + return -EINVAL;
  62771. + }
  62772. + if (loej) { // Simulate an unload/eject
  62773. + up_read(&fsg->filesem);
  62774. + down_write(&fsg->filesem);
  62775. + fsg_lun_close(curlun);
  62776. + up_write(&fsg->filesem);
  62777. + down_read(&fsg->filesem);
  62778. + }
  62779. + } else {
  62780. +
  62781. + /* Our emulation doesn't support mounting; the medium is
  62782. + * available for use as soon as it is loaded. */
  62783. + if (!fsg_lun_is_open(curlun)) {
  62784. + curlun->sense_data = SS_MEDIUM_NOT_PRESENT;
  62785. + return -EINVAL;
  62786. + }
  62787. + }
  62788. +#endif
  62789. + return 0;
  62790. +}
  62791. +
  62792. +
  62793. +static int do_prevent_allow(struct fsg_dev *fsg)
  62794. +{
  62795. + struct fsg_lun *curlun = fsg->curlun;
  62796. + int prevent;
  62797. +
  62798. + if (!mod_data.removable) {
  62799. + curlun->sense_data = SS_INVALID_COMMAND;
  62800. + return -EINVAL;
  62801. + }
  62802. +
  62803. + prevent = fsg->cmnd[4] & 0x01;
  62804. + if ((fsg->cmnd[4] & ~0x01) != 0) { // Mask away Prevent
  62805. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  62806. + return -EINVAL;
  62807. + }
  62808. +
  62809. + if (curlun->prevent_medium_removal && !prevent)
  62810. + fsg_lun_fsync_sub(curlun);
  62811. + curlun->prevent_medium_removal = prevent;
  62812. + return 0;
  62813. +}
  62814. +
  62815. +
  62816. +static int do_read_format_capacities(struct fsg_dev *fsg,
  62817. + struct fsg_buffhd *bh)
  62818. +{
  62819. + struct fsg_lun *curlun = fsg->curlun;
  62820. + u8 *buf = (u8 *) bh->buf;
  62821. +
  62822. + buf[0] = buf[1] = buf[2] = 0;
  62823. + buf[3] = 8; // Only the Current/Maximum Capacity Descriptor
  62824. + buf += 4;
  62825. +
  62826. + put_unaligned_be32(curlun->num_sectors, &buf[0]);
  62827. + /* Number of blocks */
  62828. + put_unaligned_be32(curlun->blksize, &buf[4]); /* Block length */
  62829. + buf[4] = 0x02; /* Current capacity */
  62830. + return 12;
  62831. +}
  62832. +
  62833. +
  62834. +static int do_mode_select(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  62835. +{
  62836. + struct fsg_lun *curlun = fsg->curlun;
  62837. +
  62838. + /* We don't support MODE SELECT */
  62839. + curlun->sense_data = SS_INVALID_COMMAND;
  62840. + return -EINVAL;
  62841. +}
  62842. +
  62843. +
  62844. +/*-------------------------------------------------------------------------*/
  62845. +
  62846. +static int halt_bulk_in_endpoint(struct fsg_dev *fsg)
  62847. +{
  62848. + int rc;
  62849. +
  62850. + rc = fsg_set_halt(fsg, fsg->bulk_in);
  62851. + if (rc == -EAGAIN)
  62852. + VDBG(fsg, "delayed bulk-in endpoint halt\n");
  62853. + while (rc != 0) {
  62854. + if (rc != -EAGAIN) {
  62855. + WARNING(fsg, "usb_ep_set_halt -> %d\n", rc);
  62856. + rc = 0;
  62857. + break;
  62858. + }
  62859. +
  62860. + /* Wait for a short time and then try again */
  62861. + if (msleep_interruptible(100) != 0)
  62862. + return -EINTR;
  62863. + rc = usb_ep_set_halt(fsg->bulk_in);
  62864. + }
  62865. + return rc;
  62866. +}
  62867. +
  62868. +static int wedge_bulk_in_endpoint(struct fsg_dev *fsg)
  62869. +{
  62870. + int rc;
  62871. +
  62872. + DBG(fsg, "bulk-in set wedge\n");
  62873. + rc = usb_ep_set_wedge(fsg->bulk_in);
  62874. + if (rc == -EAGAIN)
  62875. + VDBG(fsg, "delayed bulk-in endpoint wedge\n");
  62876. + while (rc != 0) {
  62877. + if (rc != -EAGAIN) {
  62878. + WARNING(fsg, "usb_ep_set_wedge -> %d\n", rc);
  62879. + rc = 0;
  62880. + break;
  62881. + }
  62882. +
  62883. + /* Wait for a short time and then try again */
  62884. + if (msleep_interruptible(100) != 0)
  62885. + return -EINTR;
  62886. + rc = usb_ep_set_wedge(fsg->bulk_in);
  62887. + }
  62888. + return rc;
  62889. +}
  62890. +
  62891. +static int throw_away_data(struct fsg_dev *fsg)
  62892. +{
  62893. + struct fsg_buffhd *bh;
  62894. + u32 amount;
  62895. + int rc;
  62896. +
  62897. + while ((bh = fsg->next_buffhd_to_drain)->state != BUF_STATE_EMPTY ||
  62898. + fsg->usb_amount_left > 0) {
  62899. +
  62900. + /* Throw away the data in a filled buffer */
  62901. + if (bh->state == BUF_STATE_FULL) {
  62902. + smp_rmb();
  62903. + bh->state = BUF_STATE_EMPTY;
  62904. + fsg->next_buffhd_to_drain = bh->next;
  62905. +
  62906. + /* A short packet or an error ends everything */
  62907. + if (bh->outreq->actual < bh->bulk_out_intended_length ||
  62908. + bh->outreq->status != 0) {
  62909. + raise_exception(fsg, FSG_STATE_ABORT_BULK_OUT);
  62910. + return -EINTR;
  62911. + }
  62912. + continue;
  62913. + }
  62914. +
  62915. + /* Try to submit another request if we need one */
  62916. + bh = fsg->next_buffhd_to_fill;
  62917. + if (bh->state == BUF_STATE_EMPTY && fsg->usb_amount_left > 0) {
  62918. + amount = min(fsg->usb_amount_left,
  62919. + (u32) mod_data.buflen);
  62920. +
  62921. + /* Except at the end of the transfer, amount will be
  62922. + * equal to the buffer size, which is divisible by
  62923. + * the bulk-out maxpacket size.
  62924. + */
  62925. + set_bulk_out_req_length(fsg, bh, amount);
  62926. + start_transfer(fsg, fsg->bulk_out, bh->outreq,
  62927. + &bh->outreq_busy, &bh->state);
  62928. + fsg->next_buffhd_to_fill = bh->next;
  62929. + fsg->usb_amount_left -= amount;
  62930. + continue;
  62931. + }
  62932. +
  62933. + /* Otherwise wait for something to happen */
  62934. + rc = sleep_thread(fsg);
  62935. + if (rc)
  62936. + return rc;
  62937. + }
  62938. + return 0;
  62939. +}
  62940. +
  62941. +
  62942. +static int finish_reply(struct fsg_dev *fsg)
  62943. +{
  62944. + struct fsg_buffhd *bh = fsg->next_buffhd_to_fill;
  62945. + int rc = 0;
  62946. +
  62947. + switch (fsg->data_dir) {
  62948. + case DATA_DIR_NONE:
  62949. + break; // Nothing to send
  62950. +
  62951. + /* If we don't know whether the host wants to read or write,
  62952. + * this must be CB or CBI with an unknown command. We mustn't
  62953. + * try to send or receive any data. So stall both bulk pipes
  62954. + * if we can and wait for a reset. */
  62955. + case DATA_DIR_UNKNOWN:
  62956. + if (mod_data.can_stall) {
  62957. + fsg_set_halt(fsg, fsg->bulk_out);
  62958. + rc = halt_bulk_in_endpoint(fsg);
  62959. + }
  62960. + break;
  62961. +
  62962. + /* All but the last buffer of data must have already been sent */
  62963. + case DATA_DIR_TO_HOST:
  62964. + if (fsg->data_size == 0)
  62965. + ; // Nothing to send
  62966. +
  62967. + /* If there's no residue, simply send the last buffer */
  62968. + else if (fsg->residue == 0) {
  62969. + bh->inreq->zero = 0;
  62970. + start_transfer(fsg, fsg->bulk_in, bh->inreq,
  62971. + &bh->inreq_busy, &bh->state);
  62972. + fsg->next_buffhd_to_fill = bh->next;
  62973. + }
  62974. +
  62975. + /* There is a residue. For CB and CBI, simply mark the end
  62976. + * of the data with a short packet. However, if we are
  62977. + * allowed to stall, there was no data at all (residue ==
  62978. + * data_size), and the command failed (invalid LUN or
  62979. + * sense data is set), then halt the bulk-in endpoint
  62980. + * instead. */
  62981. + else if (!transport_is_bbb()) {
  62982. + if (mod_data.can_stall &&
  62983. + fsg->residue == fsg->data_size &&
  62984. + (!fsg->curlun || fsg->curlun->sense_data != SS_NO_SENSE)) {
  62985. + bh->state = BUF_STATE_EMPTY;
  62986. + rc = halt_bulk_in_endpoint(fsg);
  62987. + } else {
  62988. + bh->inreq->zero = 1;
  62989. + start_transfer(fsg, fsg->bulk_in, bh->inreq,
  62990. + &bh->inreq_busy, &bh->state);
  62991. + fsg->next_buffhd_to_fill = bh->next;
  62992. + }
  62993. + }
  62994. +
  62995. + /*
  62996. + * For Bulk-only, mark the end of the data with a short
  62997. + * packet. If we are allowed to stall, halt the bulk-in
  62998. + * endpoint. (Note: This violates the Bulk-Only Transport
  62999. + * specification, which requires us to pad the data if we
  63000. + * don't halt the endpoint. Presumably nobody will mind.)
  63001. + */
  63002. + else {
  63003. + bh->inreq->zero = 1;
  63004. + start_transfer(fsg, fsg->bulk_in, bh->inreq,
  63005. + &bh->inreq_busy, &bh->state);
  63006. + fsg->next_buffhd_to_fill = bh->next;
  63007. + if (mod_data.can_stall)
  63008. + rc = halt_bulk_in_endpoint(fsg);
  63009. + }
  63010. + break;
  63011. +
  63012. + /* We have processed all we want from the data the host has sent.
  63013. + * There may still be outstanding bulk-out requests. */
  63014. + case DATA_DIR_FROM_HOST:
  63015. + if (fsg->residue == 0)
  63016. + ; // Nothing to receive
  63017. +
  63018. + /* Did the host stop sending unexpectedly early? */
  63019. + else if (fsg->short_packet_received) {
  63020. + raise_exception(fsg, FSG_STATE_ABORT_BULK_OUT);
  63021. + rc = -EINTR;
  63022. + }
  63023. +
  63024. + /* We haven't processed all the incoming data. Even though
  63025. + * we may be allowed to stall, doing so would cause a race.
  63026. + * The controller may already have ACK'ed all the remaining
  63027. + * bulk-out packets, in which case the host wouldn't see a
  63028. + * STALL. Not realizing the endpoint was halted, it wouldn't
  63029. + * clear the halt -- leading to problems later on. */
  63030. +#if 0
  63031. + else if (mod_data.can_stall) {
  63032. + fsg_set_halt(fsg, fsg->bulk_out);
  63033. + raise_exception(fsg, FSG_STATE_ABORT_BULK_OUT);
  63034. + rc = -EINTR;
  63035. + }
  63036. +#endif
  63037. +
  63038. + /* We can't stall. Read in the excess data and throw it
  63039. + * all away. */
  63040. + else
  63041. + rc = throw_away_data(fsg);
  63042. + break;
  63043. + }
  63044. + return rc;
  63045. +}
  63046. +
  63047. +
  63048. +static int send_status(struct fsg_dev *fsg)
  63049. +{
  63050. + struct fsg_lun *curlun = fsg->curlun;
  63051. + struct fsg_buffhd *bh;
  63052. + int rc;
  63053. + u8 status = US_BULK_STAT_OK;
  63054. + u32 sd, sdinfo = 0;
  63055. +
  63056. + /* Wait for the next buffer to become available */
  63057. + bh = fsg->next_buffhd_to_fill;
  63058. + while (bh->state != BUF_STATE_EMPTY) {
  63059. + rc = sleep_thread(fsg);
  63060. + if (rc)
  63061. + return rc;
  63062. + }
  63063. +
  63064. + if (curlun) {
  63065. + sd = curlun->sense_data;
  63066. + sdinfo = curlun->sense_data_info;
  63067. + } else if (fsg->bad_lun_okay)
  63068. + sd = SS_NO_SENSE;
  63069. + else
  63070. + sd = SS_LOGICAL_UNIT_NOT_SUPPORTED;
  63071. +
  63072. + if (fsg->phase_error) {
  63073. + DBG(fsg, "sending phase-error status\n");
  63074. + status = US_BULK_STAT_PHASE;
  63075. + sd = SS_INVALID_COMMAND;
  63076. + } else if (sd != SS_NO_SENSE) {
  63077. + DBG(fsg, "sending command-failure status\n");
  63078. + status = US_BULK_STAT_FAIL;
  63079. + VDBG(fsg, " sense data: SK x%02x, ASC x%02x, ASCQ x%02x;"
  63080. + " info x%x\n",
  63081. + SK(sd), ASC(sd), ASCQ(sd), sdinfo);
  63082. + }
  63083. +
  63084. + if (transport_is_bbb()) {
  63085. + struct bulk_cs_wrap *csw = bh->buf;
  63086. +
  63087. + /* Store and send the Bulk-only CSW */
  63088. + csw->Signature = cpu_to_le32(US_BULK_CS_SIGN);
  63089. + csw->Tag = fsg->tag;
  63090. + csw->Residue = cpu_to_le32(fsg->residue);
  63091. + csw->Status = status;
  63092. +
  63093. + bh->inreq->length = US_BULK_CS_WRAP_LEN;
  63094. + bh->inreq->zero = 0;
  63095. + start_transfer(fsg, fsg->bulk_in, bh->inreq,
  63096. + &bh->inreq_busy, &bh->state);
  63097. +
  63098. + } else if (mod_data.transport_type == USB_PR_CB) {
  63099. +
  63100. + /* Control-Bulk transport has no status phase! */
  63101. + return 0;
  63102. +
  63103. + } else { // USB_PR_CBI
  63104. + struct interrupt_data *buf = bh->buf;
  63105. +
  63106. + /* Store and send the Interrupt data. UFI sends the ASC
  63107. + * and ASCQ bytes. Everything else sends a Type (which
  63108. + * is always 0) and the status Value. */
  63109. + if (mod_data.protocol_type == USB_SC_UFI) {
  63110. + buf->bType = ASC(sd);
  63111. + buf->bValue = ASCQ(sd);
  63112. + } else {
  63113. + buf->bType = 0;
  63114. + buf->bValue = status;
  63115. + }
  63116. + fsg->intreq->length = CBI_INTERRUPT_DATA_LEN;
  63117. +
  63118. + fsg->intr_buffhd = bh; // Point to the right buffhd
  63119. + fsg->intreq->buf = bh->inreq->buf;
  63120. + fsg->intreq->context = bh;
  63121. + start_transfer(fsg, fsg->intr_in, fsg->intreq,
  63122. + &fsg->intreq_busy, &bh->state);
  63123. + }
  63124. +
  63125. + fsg->next_buffhd_to_fill = bh->next;
  63126. + return 0;
  63127. +}
  63128. +
  63129. +
  63130. +/*-------------------------------------------------------------------------*/
  63131. +
  63132. +/* Check whether the command is properly formed and whether its data size
  63133. + * and direction agree with the values we already have. */
  63134. +static int check_command(struct fsg_dev *fsg, int cmnd_size,
  63135. + enum data_direction data_dir, unsigned int mask,
  63136. + int needs_medium, const char *name)
  63137. +{
  63138. + int i;
  63139. + int lun = fsg->cmnd[1] >> 5;
  63140. + static const char dirletter[4] = {'u', 'o', 'i', 'n'};
  63141. + char hdlen[20];
  63142. + struct fsg_lun *curlun;
  63143. +
  63144. + /* Adjust the expected cmnd_size for protocol encapsulation padding.
  63145. + * Transparent SCSI doesn't pad. */
  63146. + if (protocol_is_scsi())
  63147. + ;
  63148. +
  63149. + /* There's some disagreement as to whether RBC pads commands or not.
  63150. + * We'll play it safe and accept either form. */
  63151. + else if (mod_data.protocol_type == USB_SC_RBC) {
  63152. + if (fsg->cmnd_size == 12)
  63153. + cmnd_size = 12;
  63154. +
  63155. + /* All the other protocols pad to 12 bytes */
  63156. + } else
  63157. + cmnd_size = 12;
  63158. +
  63159. + hdlen[0] = 0;
  63160. + if (fsg->data_dir != DATA_DIR_UNKNOWN)
  63161. + sprintf(hdlen, ", H%c=%u", dirletter[(int) fsg->data_dir],
  63162. + fsg->data_size);
  63163. + VDBG(fsg, "SCSI command: %s; Dc=%d, D%c=%u; Hc=%d%s\n",
  63164. + name, cmnd_size, dirletter[(int) data_dir],
  63165. + fsg->data_size_from_cmnd, fsg->cmnd_size, hdlen);
  63166. +
  63167. + /* We can't reply at all until we know the correct data direction
  63168. + * and size. */
  63169. + if (fsg->data_size_from_cmnd == 0)
  63170. + data_dir = DATA_DIR_NONE;
  63171. + if (fsg->data_dir == DATA_DIR_UNKNOWN) { // CB or CBI
  63172. + fsg->data_dir = data_dir;
  63173. + fsg->data_size = fsg->data_size_from_cmnd;
  63174. +
  63175. + } else { // Bulk-only
  63176. + if (fsg->data_size < fsg->data_size_from_cmnd) {
  63177. +
  63178. + /* Host data size < Device data size is a phase error.
  63179. + * Carry out the command, but only transfer as much
  63180. + * as we are allowed. */
  63181. + fsg->data_size_from_cmnd = fsg->data_size;
  63182. + fsg->phase_error = 1;
  63183. + }
  63184. + }
  63185. + fsg->residue = fsg->usb_amount_left = fsg->data_size;
  63186. +
  63187. + /* Conflicting data directions is a phase error */
  63188. + if (fsg->data_dir != data_dir && fsg->data_size_from_cmnd > 0) {
  63189. + fsg->phase_error = 1;
  63190. + return -EINVAL;
  63191. + }
  63192. +
  63193. + /* Verify the length of the command itself */
  63194. + if (cmnd_size != fsg->cmnd_size) {
  63195. +
  63196. + /* Special case workaround: There are plenty of buggy SCSI
  63197. + * implementations. Many have issues with cbw->Length
  63198. + * field passing a wrong command size. For those cases we
  63199. + * always try to work around the problem by using the length
  63200. + * sent by the host side provided it is at least as large
  63201. + * as the correct command length.
  63202. + * Examples of such cases would be MS-Windows, which issues
  63203. + * REQUEST SENSE with cbw->Length == 12 where it should
  63204. + * be 6, and xbox360 issuing INQUIRY, TEST UNIT READY and
  63205. + * REQUEST SENSE with cbw->Length == 10 where it should
  63206. + * be 6 as well.
  63207. + */
  63208. + if (cmnd_size <= fsg->cmnd_size) {
  63209. + DBG(fsg, "%s is buggy! Expected length %d "
  63210. + "but we got %d\n", name,
  63211. + cmnd_size, fsg->cmnd_size);
  63212. + cmnd_size = fsg->cmnd_size;
  63213. + } else {
  63214. + fsg->phase_error = 1;
  63215. + return -EINVAL;
  63216. + }
  63217. + }
  63218. +
  63219. + /* Check that the LUN values are consistent */
  63220. + if (transport_is_bbb()) {
  63221. + if (fsg->lun != lun)
  63222. + DBG(fsg, "using LUN %d from CBW, "
  63223. + "not LUN %d from CDB\n",
  63224. + fsg->lun, lun);
  63225. + }
  63226. +
  63227. + /* Check the LUN */
  63228. + curlun = fsg->curlun;
  63229. + if (curlun) {
  63230. + if (fsg->cmnd[0] != REQUEST_SENSE) {
  63231. + curlun->sense_data = SS_NO_SENSE;
  63232. + curlun->sense_data_info = 0;
  63233. + curlun->info_valid = 0;
  63234. + }
  63235. + } else {
  63236. + fsg->bad_lun_okay = 0;
  63237. +
  63238. + /* INQUIRY and REQUEST SENSE commands are explicitly allowed
  63239. + * to use unsupported LUNs; all others may not. */
  63240. + if (fsg->cmnd[0] != INQUIRY &&
  63241. + fsg->cmnd[0] != REQUEST_SENSE) {
  63242. + DBG(fsg, "unsupported LUN %d\n", fsg->lun);
  63243. + return -EINVAL;
  63244. + }
  63245. + }
  63246. +
  63247. + /* If a unit attention condition exists, only INQUIRY and
  63248. + * REQUEST SENSE commands are allowed; anything else must fail. */
  63249. + if (curlun && curlun->unit_attention_data != SS_NO_SENSE &&
  63250. + fsg->cmnd[0] != INQUIRY &&
  63251. + fsg->cmnd[0] != REQUEST_SENSE) {
  63252. + curlun->sense_data = curlun->unit_attention_data;
  63253. + curlun->unit_attention_data = SS_NO_SENSE;
  63254. + return -EINVAL;
  63255. + }
  63256. +
  63257. + /* Check that only command bytes listed in the mask are non-zero */
  63258. + fsg->cmnd[1] &= 0x1f; // Mask away the LUN
  63259. + for (i = 1; i < cmnd_size; ++i) {
  63260. + if (fsg->cmnd[i] && !(mask & (1 << i))) {
  63261. + if (curlun)
  63262. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  63263. + return -EINVAL;
  63264. + }
  63265. + }
  63266. +
  63267. + /* If the medium isn't mounted and the command needs to access
  63268. + * it, return an error. */
  63269. + if (curlun && !fsg_lun_is_open(curlun) && needs_medium) {
  63270. + curlun->sense_data = SS_MEDIUM_NOT_PRESENT;
  63271. + return -EINVAL;
  63272. + }
  63273. +
  63274. + return 0;
  63275. +}
  63276. +
  63277. +/* wrapper of check_command for data size in blocks handling */
  63278. +static int check_command_size_in_blocks(struct fsg_dev *fsg, int cmnd_size,
  63279. + enum data_direction data_dir, unsigned int mask,
  63280. + int needs_medium, const char *name)
  63281. +{
  63282. + if (fsg->curlun)
  63283. + fsg->data_size_from_cmnd <<= fsg->curlun->blkbits;
  63284. + return check_command(fsg, cmnd_size, data_dir,
  63285. + mask, needs_medium, name);
  63286. +}
  63287. +
  63288. +static int do_scsi_command(struct fsg_dev *fsg)
  63289. +{
  63290. + struct fsg_buffhd *bh;
  63291. + int rc;
  63292. + int reply = -EINVAL;
  63293. + int i;
  63294. + static char unknown[16];
  63295. +
  63296. + dump_cdb(fsg);
  63297. +
  63298. + /* Wait for the next buffer to become available for data or status */
  63299. + bh = fsg->next_buffhd_to_drain = fsg->next_buffhd_to_fill;
  63300. + while (bh->state != BUF_STATE_EMPTY) {
  63301. + rc = sleep_thread(fsg);
  63302. + if (rc)
  63303. + return rc;
  63304. + }
  63305. + fsg->phase_error = 0;
  63306. + fsg->short_packet_received = 0;
  63307. +
  63308. + down_read(&fsg->filesem); // We're using the backing file
  63309. + switch (fsg->cmnd[0]) {
  63310. +
  63311. + case INQUIRY:
  63312. + fsg->data_size_from_cmnd = fsg->cmnd[4];
  63313. + if ((reply = check_command(fsg, 6, DATA_DIR_TO_HOST,
  63314. + (1<<4), 0,
  63315. + "INQUIRY")) == 0)
  63316. + reply = do_inquiry(fsg, bh);
  63317. + break;
  63318. +
  63319. + case MODE_SELECT:
  63320. + fsg->data_size_from_cmnd = fsg->cmnd[4];
  63321. + if ((reply = check_command(fsg, 6, DATA_DIR_FROM_HOST,
  63322. + (1<<1) | (1<<4), 0,
  63323. + "MODE SELECT(6)")) == 0)
  63324. + reply = do_mode_select(fsg, bh);
  63325. + break;
  63326. +
  63327. + case MODE_SELECT_10:
  63328. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  63329. + if ((reply = check_command(fsg, 10, DATA_DIR_FROM_HOST,
  63330. + (1<<1) | (3<<7), 0,
  63331. + "MODE SELECT(10)")) == 0)
  63332. + reply = do_mode_select(fsg, bh);
  63333. + break;
  63334. +
  63335. + case MODE_SENSE:
  63336. + fsg->data_size_from_cmnd = fsg->cmnd[4];
  63337. + if ((reply = check_command(fsg, 6, DATA_DIR_TO_HOST,
  63338. + (1<<1) | (1<<2) | (1<<4), 0,
  63339. + "MODE SENSE(6)")) == 0)
  63340. + reply = do_mode_sense(fsg, bh);
  63341. + break;
  63342. +
  63343. + case MODE_SENSE_10:
  63344. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  63345. + if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST,
  63346. + (1<<1) | (1<<2) | (3<<7), 0,
  63347. + "MODE SENSE(10)")) == 0)
  63348. + reply = do_mode_sense(fsg, bh);
  63349. + break;
  63350. +
  63351. + case ALLOW_MEDIUM_REMOVAL:
  63352. + fsg->data_size_from_cmnd = 0;
  63353. + if ((reply = check_command(fsg, 6, DATA_DIR_NONE,
  63354. + (1<<4), 0,
  63355. + "PREVENT-ALLOW MEDIUM REMOVAL")) == 0)
  63356. + reply = do_prevent_allow(fsg);
  63357. + break;
  63358. +
  63359. + case READ_6:
  63360. + i = fsg->cmnd[4];
  63361. + fsg->data_size_from_cmnd = (i == 0) ? 256 : i;
  63362. + if ((reply = check_command_size_in_blocks(fsg, 6,
  63363. + DATA_DIR_TO_HOST,
  63364. + (7<<1) | (1<<4), 1,
  63365. + "READ(6)")) == 0)
  63366. + reply = do_read(fsg);
  63367. + break;
  63368. +
  63369. + case READ_10:
  63370. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  63371. + if ((reply = check_command_size_in_blocks(fsg, 10,
  63372. + DATA_DIR_TO_HOST,
  63373. + (1<<1) | (0xf<<2) | (3<<7), 1,
  63374. + "READ(10)")) == 0)
  63375. + reply = do_read(fsg);
  63376. + break;
  63377. +
  63378. + case READ_12:
  63379. + fsg->data_size_from_cmnd = get_unaligned_be32(&fsg->cmnd[6]);
  63380. + if ((reply = check_command_size_in_blocks(fsg, 12,
  63381. + DATA_DIR_TO_HOST,
  63382. + (1<<1) | (0xf<<2) | (0xf<<6), 1,
  63383. + "READ(12)")) == 0)
  63384. + reply = do_read(fsg);
  63385. + break;
  63386. +
  63387. + case READ_CAPACITY:
  63388. + fsg->data_size_from_cmnd = 8;
  63389. + if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST,
  63390. + (0xf<<2) | (1<<8), 1,
  63391. + "READ CAPACITY")) == 0)
  63392. + reply = do_read_capacity(fsg, bh);
  63393. + break;
  63394. +
  63395. + case READ_HEADER:
  63396. + if (!mod_data.cdrom)
  63397. + goto unknown_cmnd;
  63398. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  63399. + if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST,
  63400. + (3<<7) | (0x1f<<1), 1,
  63401. + "READ HEADER")) == 0)
  63402. + reply = do_read_header(fsg, bh);
  63403. + break;
  63404. +
  63405. + case READ_TOC:
  63406. + if (!mod_data.cdrom)
  63407. + goto unknown_cmnd;
  63408. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  63409. + if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST,
  63410. + (7<<6) | (1<<1), 1,
  63411. + "READ TOC")) == 0)
  63412. + reply = do_read_toc(fsg, bh);
  63413. + break;
  63414. +
  63415. + case READ_FORMAT_CAPACITIES:
  63416. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  63417. + if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST,
  63418. + (3<<7), 1,
  63419. + "READ FORMAT CAPACITIES")) == 0)
  63420. + reply = do_read_format_capacities(fsg, bh);
  63421. + break;
  63422. +
  63423. + case REQUEST_SENSE:
  63424. + fsg->data_size_from_cmnd = fsg->cmnd[4];
  63425. + if ((reply = check_command(fsg, 6, DATA_DIR_TO_HOST,
  63426. + (1<<4), 0,
  63427. + "REQUEST SENSE")) == 0)
  63428. + reply = do_request_sense(fsg, bh);
  63429. + break;
  63430. +
  63431. + case START_STOP:
  63432. + fsg->data_size_from_cmnd = 0;
  63433. + if ((reply = check_command(fsg, 6, DATA_DIR_NONE,
  63434. + (1<<1) | (1<<4), 0,
  63435. + "START-STOP UNIT")) == 0)
  63436. + reply = do_start_stop(fsg);
  63437. + break;
  63438. +
  63439. + case SYNCHRONIZE_CACHE:
  63440. + fsg->data_size_from_cmnd = 0;
  63441. + if ((reply = check_command(fsg, 10, DATA_DIR_NONE,
  63442. + (0xf<<2) | (3<<7), 1,
  63443. + "SYNCHRONIZE CACHE")) == 0)
  63444. + reply = do_synchronize_cache(fsg);
  63445. + break;
  63446. +
  63447. + case TEST_UNIT_READY:
  63448. + fsg->data_size_from_cmnd = 0;
  63449. + reply = check_command(fsg, 6, DATA_DIR_NONE,
  63450. + 0, 1,
  63451. + "TEST UNIT READY");
  63452. + break;
  63453. +
  63454. + /* Although optional, this command is used by MS-Windows. We
  63455. + * support a minimal version: BytChk must be 0. */
  63456. + case VERIFY:
  63457. + fsg->data_size_from_cmnd = 0;
  63458. + if ((reply = check_command(fsg, 10, DATA_DIR_NONE,
  63459. + (1<<1) | (0xf<<2) | (3<<7), 1,
  63460. + "VERIFY")) == 0)
  63461. + reply = do_verify(fsg);
  63462. + break;
  63463. +
  63464. + case WRITE_6:
  63465. + i = fsg->cmnd[4];
  63466. + fsg->data_size_from_cmnd = (i == 0) ? 256 : i;
  63467. + if ((reply = check_command_size_in_blocks(fsg, 6,
  63468. + DATA_DIR_FROM_HOST,
  63469. + (7<<1) | (1<<4), 1,
  63470. + "WRITE(6)")) == 0)
  63471. + reply = do_write(fsg);
  63472. + break;
  63473. +
  63474. + case WRITE_10:
  63475. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  63476. + if ((reply = check_command_size_in_blocks(fsg, 10,
  63477. + DATA_DIR_FROM_HOST,
  63478. + (1<<1) | (0xf<<2) | (3<<7), 1,
  63479. + "WRITE(10)")) == 0)
  63480. + reply = do_write(fsg);
  63481. + break;
  63482. +
  63483. + case WRITE_12:
  63484. + fsg->data_size_from_cmnd = get_unaligned_be32(&fsg->cmnd[6]);
  63485. + if ((reply = check_command_size_in_blocks(fsg, 12,
  63486. + DATA_DIR_FROM_HOST,
  63487. + (1<<1) | (0xf<<2) | (0xf<<6), 1,
  63488. + "WRITE(12)")) == 0)
  63489. + reply = do_write(fsg);
  63490. + break;
  63491. +
  63492. + /* Some mandatory commands that we recognize but don't implement.
  63493. + * They don't mean much in this setting. It's left as an exercise
  63494. + * for anyone interested to implement RESERVE and RELEASE in terms
  63495. + * of Posix locks. */
  63496. + case FORMAT_UNIT:
  63497. + case RELEASE:
  63498. + case RESERVE:
  63499. + case SEND_DIAGNOSTIC:
  63500. + // Fall through
  63501. +
  63502. + default:
  63503. + unknown_cmnd:
  63504. + fsg->data_size_from_cmnd = 0;
  63505. + sprintf(unknown, "Unknown x%02x", fsg->cmnd[0]);
  63506. + if ((reply = check_command(fsg, fsg->cmnd_size,
  63507. + DATA_DIR_UNKNOWN, ~0, 0, unknown)) == 0) {
  63508. + fsg->curlun->sense_data = SS_INVALID_COMMAND;
  63509. + reply = -EINVAL;
  63510. + }
  63511. + break;
  63512. + }
  63513. + up_read(&fsg->filesem);
  63514. +
  63515. + if (reply == -EINTR || signal_pending(current))
  63516. + return -EINTR;
  63517. +
  63518. + /* Set up the single reply buffer for finish_reply() */
  63519. + if (reply == -EINVAL)
  63520. + reply = 0; // Error reply length
  63521. + if (reply >= 0 && fsg->data_dir == DATA_DIR_TO_HOST) {
  63522. + reply = min((u32) reply, fsg->data_size_from_cmnd);
  63523. + bh->inreq->length = reply;
  63524. + bh->state = BUF_STATE_FULL;
  63525. + fsg->residue -= reply;
  63526. + } // Otherwise it's already set
  63527. +
  63528. + return 0;
  63529. +}
  63530. +
  63531. +
  63532. +/*-------------------------------------------------------------------------*/
  63533. +
  63534. +static int received_cbw(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  63535. +{
  63536. + struct usb_request *req = bh->outreq;
  63537. + struct bulk_cb_wrap *cbw = req->buf;
  63538. +
  63539. + /* Was this a real packet? Should it be ignored? */
  63540. + if (req->status || test_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags))
  63541. + return -EINVAL;
  63542. +
  63543. + /* Is the CBW valid? */
  63544. + if (req->actual != US_BULK_CB_WRAP_LEN ||
  63545. + cbw->Signature != cpu_to_le32(
  63546. + US_BULK_CB_SIGN)) {
  63547. + DBG(fsg, "invalid CBW: len %u sig 0x%x\n",
  63548. + req->actual,
  63549. + le32_to_cpu(cbw->Signature));
  63550. +
  63551. + /* The Bulk-only spec says we MUST stall the IN endpoint
  63552. + * (6.6.1), so it's unavoidable. It also says we must
  63553. + * retain this state until the next reset, but there's
  63554. + * no way to tell the controller driver it should ignore
  63555. + * Clear-Feature(HALT) requests.
  63556. + *
  63557. + * We aren't required to halt the OUT endpoint; instead
  63558. + * we can simply accept and discard any data received
  63559. + * until the next reset. */
  63560. + wedge_bulk_in_endpoint(fsg);
  63561. + set_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags);
  63562. + return -EINVAL;
  63563. + }
  63564. +
  63565. + /* Is the CBW meaningful? */
  63566. + if (cbw->Lun >= FSG_MAX_LUNS || cbw->Flags & ~US_BULK_FLAG_IN ||
  63567. + cbw->Length <= 0 || cbw->Length > MAX_COMMAND_SIZE) {
  63568. + DBG(fsg, "non-meaningful CBW: lun = %u, flags = 0x%x, "
  63569. + "cmdlen %u\n",
  63570. + cbw->Lun, cbw->Flags, cbw->Length);
  63571. +
  63572. + /* We can do anything we want here, so let's stall the
  63573. + * bulk pipes if we are allowed to. */
  63574. + if (mod_data.can_stall) {
  63575. + fsg_set_halt(fsg, fsg->bulk_out);
  63576. + halt_bulk_in_endpoint(fsg);
  63577. + }
  63578. + return -EINVAL;
  63579. + }
  63580. +
  63581. + /* Save the command for later */
  63582. + fsg->cmnd_size = cbw->Length;
  63583. + memcpy(fsg->cmnd, cbw->CDB, fsg->cmnd_size);
  63584. + if (cbw->Flags & US_BULK_FLAG_IN)
  63585. + fsg->data_dir = DATA_DIR_TO_HOST;
  63586. + else
  63587. + fsg->data_dir = DATA_DIR_FROM_HOST;
  63588. + fsg->data_size = le32_to_cpu(cbw->DataTransferLength);
  63589. + if (fsg->data_size == 0)
  63590. + fsg->data_dir = DATA_DIR_NONE;
  63591. + fsg->lun = cbw->Lun;
  63592. + fsg->tag = cbw->Tag;
  63593. + return 0;
  63594. +}
  63595. +
  63596. +
  63597. +static int get_next_command(struct fsg_dev *fsg)
  63598. +{
  63599. + struct fsg_buffhd *bh;
  63600. + int rc = 0;
  63601. +
  63602. + if (transport_is_bbb()) {
  63603. +
  63604. + /* Wait for the next buffer to become available */
  63605. + bh = fsg->next_buffhd_to_fill;
  63606. + while (bh->state != BUF_STATE_EMPTY) {
  63607. + rc = sleep_thread(fsg);
  63608. + if (rc)
  63609. + return rc;
  63610. + }
  63611. +
  63612. + /* Queue a request to read a Bulk-only CBW */
  63613. + set_bulk_out_req_length(fsg, bh, US_BULK_CB_WRAP_LEN);
  63614. + start_transfer(fsg, fsg->bulk_out, bh->outreq,
  63615. + &bh->outreq_busy, &bh->state);
  63616. +
  63617. + /* We will drain the buffer in software, which means we
  63618. + * can reuse it for the next filling. No need to advance
  63619. + * next_buffhd_to_fill. */
  63620. +
  63621. + /* Wait for the CBW to arrive */
  63622. + while (bh->state != BUF_STATE_FULL) {
  63623. + rc = sleep_thread(fsg);
  63624. + if (rc)
  63625. + return rc;
  63626. + }
  63627. + smp_rmb();
  63628. + rc = received_cbw(fsg, bh);
  63629. + bh->state = BUF_STATE_EMPTY;
  63630. +
  63631. + } else { // USB_PR_CB or USB_PR_CBI
  63632. +
  63633. + /* Wait for the next command to arrive */
  63634. + while (fsg->cbbuf_cmnd_size == 0) {
  63635. + rc = sleep_thread(fsg);
  63636. + if (rc)
  63637. + return rc;
  63638. + }
  63639. +
  63640. + /* Is the previous status interrupt request still busy?
  63641. + * The host is allowed to skip reading the status,
  63642. + * so we must cancel it. */
  63643. + if (fsg->intreq_busy)
  63644. + usb_ep_dequeue(fsg->intr_in, fsg->intreq);
  63645. +
  63646. + /* Copy the command and mark the buffer empty */
  63647. + fsg->data_dir = DATA_DIR_UNKNOWN;
  63648. + spin_lock_irq(&fsg->lock);
  63649. + fsg->cmnd_size = fsg->cbbuf_cmnd_size;
  63650. + memcpy(fsg->cmnd, fsg->cbbuf_cmnd, fsg->cmnd_size);
  63651. + fsg->cbbuf_cmnd_size = 0;
  63652. + spin_unlock_irq(&fsg->lock);
  63653. +
  63654. + /* Use LUN from the command */
  63655. + fsg->lun = fsg->cmnd[1] >> 5;
  63656. + }
  63657. +
  63658. + /* Update current lun */
  63659. + if (fsg->lun >= 0 && fsg->lun < fsg->nluns)
  63660. + fsg->curlun = &fsg->luns[fsg->lun];
  63661. + else
  63662. + fsg->curlun = NULL;
  63663. +
  63664. + return rc;
  63665. +}
  63666. +
  63667. +
  63668. +/*-------------------------------------------------------------------------*/
  63669. +
  63670. +static int enable_endpoint(struct fsg_dev *fsg, struct usb_ep *ep,
  63671. + const struct usb_endpoint_descriptor *d)
  63672. +{
  63673. + int rc;
  63674. +
  63675. + ep->driver_data = fsg;
  63676. + ep->desc = d;
  63677. + rc = usb_ep_enable(ep);
  63678. + if (rc)
  63679. + ERROR(fsg, "can't enable %s, result %d\n", ep->name, rc);
  63680. + return rc;
  63681. +}
  63682. +
  63683. +static int alloc_request(struct fsg_dev *fsg, struct usb_ep *ep,
  63684. + struct usb_request **preq)
  63685. +{
  63686. + *preq = usb_ep_alloc_request(ep, GFP_ATOMIC);
  63687. + if (*preq)
  63688. + return 0;
  63689. + ERROR(fsg, "can't allocate request for %s\n", ep->name);
  63690. + return -ENOMEM;
  63691. +}
  63692. +
  63693. +/*
  63694. + * Reset interface setting and re-init endpoint state (toggle etc).
  63695. + * Call with altsetting < 0 to disable the interface. The only other
  63696. + * available altsetting is 0, which enables the interface.
  63697. + */
  63698. +static int do_set_interface(struct fsg_dev *fsg, int altsetting)
  63699. +{
  63700. + int rc = 0;
  63701. + int i;
  63702. + const struct usb_endpoint_descriptor *d;
  63703. +
  63704. + if (fsg->running)
  63705. + DBG(fsg, "reset interface\n");
  63706. +
  63707. +reset:
  63708. + /* Deallocate the requests */
  63709. + for (i = 0; i < fsg_num_buffers; ++i) {
  63710. + struct fsg_buffhd *bh = &fsg->buffhds[i];
  63711. +
  63712. + if (bh->inreq) {
  63713. + usb_ep_free_request(fsg->bulk_in, bh->inreq);
  63714. + bh->inreq = NULL;
  63715. + }
  63716. + if (bh->outreq) {
  63717. + usb_ep_free_request(fsg->bulk_out, bh->outreq);
  63718. + bh->outreq = NULL;
  63719. + }
  63720. + }
  63721. + if (fsg->intreq) {
  63722. + usb_ep_free_request(fsg->intr_in, fsg->intreq);
  63723. + fsg->intreq = NULL;
  63724. + }
  63725. +
  63726. + /* Disable the endpoints */
  63727. + if (fsg->bulk_in_enabled) {
  63728. + usb_ep_disable(fsg->bulk_in);
  63729. + fsg->bulk_in_enabled = 0;
  63730. + }
  63731. + if (fsg->bulk_out_enabled) {
  63732. + usb_ep_disable(fsg->bulk_out);
  63733. + fsg->bulk_out_enabled = 0;
  63734. + }
  63735. + if (fsg->intr_in_enabled) {
  63736. + usb_ep_disable(fsg->intr_in);
  63737. + fsg->intr_in_enabled = 0;
  63738. + }
  63739. +
  63740. + fsg->running = 0;
  63741. + if (altsetting < 0 || rc != 0)
  63742. + return rc;
  63743. +
  63744. + DBG(fsg, "set interface %d\n", altsetting);
  63745. +
  63746. + /* Enable the endpoints */
  63747. + d = fsg_ep_desc(fsg->gadget,
  63748. + &fsg_fs_bulk_in_desc, &fsg_hs_bulk_in_desc,
  63749. + &fsg_ss_bulk_in_desc);
  63750. + if ((rc = enable_endpoint(fsg, fsg->bulk_in, d)) != 0)
  63751. + goto reset;
  63752. + fsg->bulk_in_enabled = 1;
  63753. +
  63754. + d = fsg_ep_desc(fsg->gadget,
  63755. + &fsg_fs_bulk_out_desc, &fsg_hs_bulk_out_desc,
  63756. + &fsg_ss_bulk_out_desc);
  63757. + if ((rc = enable_endpoint(fsg, fsg->bulk_out, d)) != 0)
  63758. + goto reset;
  63759. + fsg->bulk_out_enabled = 1;
  63760. + fsg->bulk_out_maxpacket = usb_endpoint_maxp(d);
  63761. + clear_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags);
  63762. +
  63763. + if (transport_is_cbi()) {
  63764. + d = fsg_ep_desc(fsg->gadget,
  63765. + &fsg_fs_intr_in_desc, &fsg_hs_intr_in_desc,
  63766. + &fsg_ss_intr_in_desc);
  63767. + if ((rc = enable_endpoint(fsg, fsg->intr_in, d)) != 0)
  63768. + goto reset;
  63769. + fsg->intr_in_enabled = 1;
  63770. + }
  63771. +
  63772. + /* Allocate the requests */
  63773. + for (i = 0; i < fsg_num_buffers; ++i) {
  63774. + struct fsg_buffhd *bh = &fsg->buffhds[i];
  63775. +
  63776. + if ((rc = alloc_request(fsg, fsg->bulk_in, &bh->inreq)) != 0)
  63777. + goto reset;
  63778. + if ((rc = alloc_request(fsg, fsg->bulk_out, &bh->outreq)) != 0)
  63779. + goto reset;
  63780. + bh->inreq->buf = bh->outreq->buf = bh->buf;
  63781. + bh->inreq->context = bh->outreq->context = bh;
  63782. + bh->inreq->complete = bulk_in_complete;
  63783. + bh->outreq->complete = bulk_out_complete;
  63784. + }
  63785. + if (transport_is_cbi()) {
  63786. + if ((rc = alloc_request(fsg, fsg->intr_in, &fsg->intreq)) != 0)
  63787. + goto reset;
  63788. + fsg->intreq->complete = intr_in_complete;
  63789. + }
  63790. +
  63791. + fsg->running = 1;
  63792. + for (i = 0; i < fsg->nluns; ++i)
  63793. + fsg->luns[i].unit_attention_data = SS_RESET_OCCURRED;
  63794. + return rc;
  63795. +}
  63796. +
  63797. +
  63798. +/*
  63799. + * Change our operational configuration. This code must agree with the code
  63800. + * that returns config descriptors, and with interface altsetting code.
  63801. + *
  63802. + * It's also responsible for power management interactions. Some
  63803. + * configurations might not work with our current power sources.
  63804. + * For now we just assume the gadget is always self-powered.
  63805. + */
  63806. +static int do_set_config(struct fsg_dev *fsg, u8 new_config)
  63807. +{
  63808. + int rc = 0;
  63809. +
  63810. + /* Disable the single interface */
  63811. + if (fsg->config != 0) {
  63812. + DBG(fsg, "reset config\n");
  63813. + fsg->config = 0;
  63814. + rc = do_set_interface(fsg, -1);
  63815. + }
  63816. +
  63817. + /* Enable the interface */
  63818. + if (new_config != 0) {
  63819. + fsg->config = new_config;
  63820. + if ((rc = do_set_interface(fsg, 0)) != 0)
  63821. + fsg->config = 0; // Reset on errors
  63822. + else
  63823. + INFO(fsg, "%s config #%d\n",
  63824. + usb_speed_string(fsg->gadget->speed),
  63825. + fsg->config);
  63826. + }
  63827. + return rc;
  63828. +}
  63829. +
  63830. +
  63831. +/*-------------------------------------------------------------------------*/
  63832. +
  63833. +static void handle_exception(struct fsg_dev *fsg)
  63834. +{
  63835. + siginfo_t info;
  63836. + int sig;
  63837. + int i;
  63838. + int num_active;
  63839. + struct fsg_buffhd *bh;
  63840. + enum fsg_state old_state;
  63841. + u8 new_config;
  63842. + struct fsg_lun *curlun;
  63843. + unsigned int exception_req_tag;
  63844. + int rc;
  63845. +
  63846. + /* Clear the existing signals. Anything but SIGUSR1 is converted
  63847. + * into a high-priority EXIT exception. */
  63848. + for (;;) {
  63849. + sig = dequeue_signal_lock(current, &current->blocked, &info);
  63850. + if (!sig)
  63851. + break;
  63852. + if (sig != SIGUSR1) {
  63853. + if (fsg->state < FSG_STATE_EXIT)
  63854. + DBG(fsg, "Main thread exiting on signal\n");
  63855. + raise_exception(fsg, FSG_STATE_EXIT);
  63856. + }
  63857. + }
  63858. +
  63859. + /* Cancel all the pending transfers */
  63860. + if (fsg->intreq_busy)
  63861. + usb_ep_dequeue(fsg->intr_in, fsg->intreq);
  63862. + for (i = 0; i < fsg_num_buffers; ++i) {
  63863. + bh = &fsg->buffhds[i];
  63864. + if (bh->inreq_busy)
  63865. + usb_ep_dequeue(fsg->bulk_in, bh->inreq);
  63866. + if (bh->outreq_busy)
  63867. + usb_ep_dequeue(fsg->bulk_out, bh->outreq);
  63868. + }
  63869. +
  63870. + /* Wait until everything is idle */
  63871. + for (;;) {
  63872. + num_active = fsg->intreq_busy;
  63873. + for (i = 0; i < fsg_num_buffers; ++i) {
  63874. + bh = &fsg->buffhds[i];
  63875. + num_active += bh->inreq_busy + bh->outreq_busy;
  63876. + }
  63877. + if (num_active == 0)
  63878. + break;
  63879. + if (sleep_thread(fsg))
  63880. + return;
  63881. + }
  63882. +
  63883. + /* Clear out the controller's fifos */
  63884. + if (fsg->bulk_in_enabled)
  63885. + usb_ep_fifo_flush(fsg->bulk_in);
  63886. + if (fsg->bulk_out_enabled)
  63887. + usb_ep_fifo_flush(fsg->bulk_out);
  63888. + if (fsg->intr_in_enabled)
  63889. + usb_ep_fifo_flush(fsg->intr_in);
  63890. +
  63891. + /* Reset the I/O buffer states and pointers, the SCSI
  63892. + * state, and the exception. Then invoke the handler. */
  63893. + spin_lock_irq(&fsg->lock);
  63894. +
  63895. + for (i = 0; i < fsg_num_buffers; ++i) {
  63896. + bh = &fsg->buffhds[i];
  63897. + bh->state = BUF_STATE_EMPTY;
  63898. + }
  63899. + fsg->next_buffhd_to_fill = fsg->next_buffhd_to_drain =
  63900. + &fsg->buffhds[0];
  63901. +
  63902. + exception_req_tag = fsg->exception_req_tag;
  63903. + new_config = fsg->new_config;
  63904. + old_state = fsg->state;
  63905. +
  63906. + if (old_state == FSG_STATE_ABORT_BULK_OUT)
  63907. + fsg->state = FSG_STATE_STATUS_PHASE;
  63908. + else {
  63909. + for (i = 0; i < fsg->nluns; ++i) {
  63910. + curlun = &fsg->luns[i];
  63911. + curlun->prevent_medium_removal = 0;
  63912. + curlun->sense_data = curlun->unit_attention_data =
  63913. + SS_NO_SENSE;
  63914. + curlun->sense_data_info = 0;
  63915. + curlun->info_valid = 0;
  63916. + }
  63917. + fsg->state = FSG_STATE_IDLE;
  63918. + }
  63919. + spin_unlock_irq(&fsg->lock);
  63920. +
  63921. + /* Carry out any extra actions required for the exception */
  63922. + switch (old_state) {
  63923. + default:
  63924. + break;
  63925. +
  63926. + case FSG_STATE_ABORT_BULK_OUT:
  63927. + send_status(fsg);
  63928. + spin_lock_irq(&fsg->lock);
  63929. + if (fsg->state == FSG_STATE_STATUS_PHASE)
  63930. + fsg->state = FSG_STATE_IDLE;
  63931. + spin_unlock_irq(&fsg->lock);
  63932. + break;
  63933. +
  63934. + case FSG_STATE_RESET:
  63935. + /* In case we were forced against our will to halt a
  63936. + * bulk endpoint, clear the halt now. (The SuperH UDC
  63937. + * requires this.) */
  63938. + if (test_and_clear_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags))
  63939. + usb_ep_clear_halt(fsg->bulk_in);
  63940. +
  63941. + if (transport_is_bbb()) {
  63942. + if (fsg->ep0_req_tag == exception_req_tag)
  63943. + ep0_queue(fsg); // Complete the status stage
  63944. +
  63945. + } else if (transport_is_cbi())
  63946. + send_status(fsg); // Status by interrupt pipe
  63947. +
  63948. + /* Technically this should go here, but it would only be
  63949. + * a waste of time. Ditto for the INTERFACE_CHANGE and
  63950. + * CONFIG_CHANGE cases. */
  63951. + // for (i = 0; i < fsg->nluns; ++i)
  63952. + // fsg->luns[i].unit_attention_data = SS_RESET_OCCURRED;
  63953. + break;
  63954. +
  63955. + case FSG_STATE_INTERFACE_CHANGE:
  63956. + rc = do_set_interface(fsg, 0);
  63957. + if (fsg->ep0_req_tag != exception_req_tag)
  63958. + break;
  63959. + if (rc != 0) // STALL on errors
  63960. + fsg_set_halt(fsg, fsg->ep0);
  63961. + else // Complete the status stage
  63962. + ep0_queue(fsg);
  63963. + break;
  63964. +
  63965. + case FSG_STATE_CONFIG_CHANGE:
  63966. + rc = do_set_config(fsg, new_config);
  63967. + if (fsg->ep0_req_tag != exception_req_tag)
  63968. + break;
  63969. + if (rc != 0) // STALL on errors
  63970. + fsg_set_halt(fsg, fsg->ep0);
  63971. + else // Complete the status stage
  63972. + ep0_queue(fsg);
  63973. + break;
  63974. +
  63975. + case FSG_STATE_DISCONNECT:
  63976. + for (i = 0; i < fsg->nluns; ++i)
  63977. + fsg_lun_fsync_sub(fsg->luns + i);
  63978. + do_set_config(fsg, 0); // Unconfigured state
  63979. + break;
  63980. +
  63981. + case FSG_STATE_EXIT:
  63982. + case FSG_STATE_TERMINATED:
  63983. + do_set_config(fsg, 0); // Free resources
  63984. + spin_lock_irq(&fsg->lock);
  63985. + fsg->state = FSG_STATE_TERMINATED; // Stop the thread
  63986. + spin_unlock_irq(&fsg->lock);
  63987. + break;
  63988. + }
  63989. +}
  63990. +
  63991. +
  63992. +/*-------------------------------------------------------------------------*/
  63993. +
  63994. +static int fsg_main_thread(void *fsg_)
  63995. +{
  63996. + struct fsg_dev *fsg = fsg_;
  63997. +
  63998. + /* Allow the thread to be killed by a signal, but set the signal mask
  63999. + * to block everything but INT, TERM, KILL, and USR1. */
  64000. + allow_signal(SIGINT);
  64001. + allow_signal(SIGTERM);
  64002. + allow_signal(SIGKILL);
  64003. + allow_signal(SIGUSR1);
  64004. +
  64005. + /* Allow the thread to be frozen */
  64006. + set_freezable();
  64007. +
  64008. + /* Arrange for userspace references to be interpreted as kernel
  64009. + * pointers. That way we can pass a kernel pointer to a routine
  64010. + * that expects a __user pointer and it will work okay. */
  64011. + set_fs(get_ds());
  64012. +
  64013. + /* The main loop */
  64014. + while (fsg->state != FSG_STATE_TERMINATED) {
  64015. + if (exception_in_progress(fsg) || signal_pending(current)) {
  64016. + handle_exception(fsg);
  64017. + continue;
  64018. + }
  64019. +
  64020. + if (!fsg->running) {
  64021. + sleep_thread(fsg);
  64022. + continue;
  64023. + }
  64024. +
  64025. + if (get_next_command(fsg))
  64026. + continue;
  64027. +
  64028. + spin_lock_irq(&fsg->lock);
  64029. + if (!exception_in_progress(fsg))
  64030. + fsg->state = FSG_STATE_DATA_PHASE;
  64031. + spin_unlock_irq(&fsg->lock);
  64032. +
  64033. + if (do_scsi_command(fsg) || finish_reply(fsg))
  64034. + continue;
  64035. +
  64036. + spin_lock_irq(&fsg->lock);
  64037. + if (!exception_in_progress(fsg))
  64038. + fsg->state = FSG_STATE_STATUS_PHASE;
  64039. + spin_unlock_irq(&fsg->lock);
  64040. +
  64041. + if (send_status(fsg))
  64042. + continue;
  64043. +
  64044. + spin_lock_irq(&fsg->lock);
  64045. + if (!exception_in_progress(fsg))
  64046. + fsg->state = FSG_STATE_IDLE;
  64047. + spin_unlock_irq(&fsg->lock);
  64048. + }
  64049. +
  64050. + spin_lock_irq(&fsg->lock);
  64051. + fsg->thread_task = NULL;
  64052. + spin_unlock_irq(&fsg->lock);
  64053. +
  64054. + /* If we are exiting because of a signal, unregister the
  64055. + * gadget driver. */
  64056. + if (test_and_clear_bit(REGISTERED, &fsg->atomic_bitflags))
  64057. + usb_gadget_unregister_driver(&fsg_driver);
  64058. +
  64059. + /* Let the unbind and cleanup routines know the thread has exited */
  64060. + complete_and_exit(&fsg->thread_notifier, 0);
  64061. +}
  64062. +
  64063. +
  64064. +/*-------------------------------------------------------------------------*/
  64065. +
  64066. +
  64067. +/* The write permissions and store_xxx pointers are set in fsg_bind() */
  64068. +static DEVICE_ATTR(ro, 0444, fsg_show_ro, NULL);
  64069. +static DEVICE_ATTR(nofua, 0644, fsg_show_nofua, NULL);
  64070. +static DEVICE_ATTR(file, 0444, fsg_show_file, NULL);
  64071. +
  64072. +
  64073. +/*-------------------------------------------------------------------------*/
  64074. +
  64075. +static void fsg_release(struct kref *ref)
  64076. +{
  64077. + struct fsg_dev *fsg = container_of(ref, struct fsg_dev, ref);
  64078. +
  64079. + kfree(fsg->luns);
  64080. + kfree(fsg);
  64081. +}
  64082. +
  64083. +static void lun_release(struct device *dev)
  64084. +{
  64085. + struct rw_semaphore *filesem = dev_get_drvdata(dev);
  64086. + struct fsg_dev *fsg =
  64087. + container_of(filesem, struct fsg_dev, filesem);
  64088. +
  64089. + kref_put(&fsg->ref, fsg_release);
  64090. +}
  64091. +
  64092. +static void /* __init_or_exit */ fsg_unbind(struct usb_gadget *gadget)
  64093. +{
  64094. + struct fsg_dev *fsg = get_gadget_data(gadget);
  64095. + int i;
  64096. + struct fsg_lun *curlun;
  64097. + struct usb_request *req = fsg->ep0req;
  64098. +
  64099. + DBG(fsg, "unbind\n");
  64100. + clear_bit(REGISTERED, &fsg->atomic_bitflags);
  64101. +
  64102. + /* If the thread isn't already dead, tell it to exit now */
  64103. + if (fsg->state != FSG_STATE_TERMINATED) {
  64104. + raise_exception(fsg, FSG_STATE_EXIT);
  64105. + wait_for_completion(&fsg->thread_notifier);
  64106. +
  64107. + /* The cleanup routine waits for this completion also */
  64108. + complete(&fsg->thread_notifier);
  64109. + }
  64110. +
  64111. + /* Unregister the sysfs attribute files and the LUNs */
  64112. + for (i = 0; i < fsg->nluns; ++i) {
  64113. + curlun = &fsg->luns[i];
  64114. + if (curlun->registered) {
  64115. + device_remove_file(&curlun->dev, &dev_attr_nofua);
  64116. + device_remove_file(&curlun->dev, &dev_attr_ro);
  64117. + device_remove_file(&curlun->dev, &dev_attr_file);
  64118. + fsg_lun_close(curlun);
  64119. + device_unregister(&curlun->dev);
  64120. + curlun->registered = 0;
  64121. + }
  64122. + }
  64123. +
  64124. + /* Free the data buffers */
  64125. + for (i = 0; i < fsg_num_buffers; ++i)
  64126. + kfree(fsg->buffhds[i].buf);
  64127. +
  64128. + /* Free the request and buffer for endpoint 0 */
  64129. + if (req) {
  64130. + kfree(req->buf);
  64131. + usb_ep_free_request(fsg->ep0, req);
  64132. + }
  64133. +
  64134. + set_gadget_data(gadget, NULL);
  64135. +}
  64136. +
  64137. +
  64138. +static int __init check_parameters(struct fsg_dev *fsg)
  64139. +{
  64140. + int prot;
  64141. + int gcnum;
  64142. +
  64143. + /* Store the default values */
  64144. + mod_data.transport_type = USB_PR_BULK;
  64145. + mod_data.transport_name = "Bulk-only";
  64146. + mod_data.protocol_type = USB_SC_SCSI;
  64147. + mod_data.protocol_name = "Transparent SCSI";
  64148. +
  64149. + /* Some peripheral controllers are known not to be able to
  64150. + * halt bulk endpoints correctly. If one of them is present,
  64151. + * disable stalls.
  64152. + */
  64153. + if (gadget_is_at91(fsg->gadget))
  64154. + mod_data.can_stall = 0;
  64155. +
  64156. + if (mod_data.release == 0xffff) { // Parameter wasn't set
  64157. + gcnum = usb_gadget_controller_number(fsg->gadget);
  64158. + if (gcnum >= 0)
  64159. + mod_data.release = 0x0300 + gcnum;
  64160. + else {
  64161. + WARNING(fsg, "controller '%s' not recognized\n",
  64162. + fsg->gadget->name);
  64163. + mod_data.release = 0x0399;
  64164. + }
  64165. + }
  64166. +
  64167. + prot = simple_strtol(mod_data.protocol_parm, NULL, 0);
  64168. +
  64169. +#ifdef CONFIG_USB_FILE_STORAGE_TEST
  64170. + if (strnicmp(mod_data.transport_parm, "BBB", 10) == 0) {
  64171. + ; // Use default setting
  64172. + } else if (strnicmp(mod_data.transport_parm, "CB", 10) == 0) {
  64173. + mod_data.transport_type = USB_PR_CB;
  64174. + mod_data.transport_name = "Control-Bulk";
  64175. + } else if (strnicmp(mod_data.transport_parm, "CBI", 10) == 0) {
  64176. + mod_data.transport_type = USB_PR_CBI;
  64177. + mod_data.transport_name = "Control-Bulk-Interrupt";
  64178. + } else {
  64179. + ERROR(fsg, "invalid transport: %s\n", mod_data.transport_parm);
  64180. + return -EINVAL;
  64181. + }
  64182. +
  64183. + if (strnicmp(mod_data.protocol_parm, "SCSI", 10) == 0 ||
  64184. + prot == USB_SC_SCSI) {
  64185. + ; // Use default setting
  64186. + } else if (strnicmp(mod_data.protocol_parm, "RBC", 10) == 0 ||
  64187. + prot == USB_SC_RBC) {
  64188. + mod_data.protocol_type = USB_SC_RBC;
  64189. + mod_data.protocol_name = "RBC";
  64190. + } else if (strnicmp(mod_data.protocol_parm, "8020", 4) == 0 ||
  64191. + strnicmp(mod_data.protocol_parm, "ATAPI", 10) == 0 ||
  64192. + prot == USB_SC_8020) {
  64193. + mod_data.protocol_type = USB_SC_8020;
  64194. + mod_data.protocol_name = "8020i (ATAPI)";
  64195. + } else if (strnicmp(mod_data.protocol_parm, "QIC", 3) == 0 ||
  64196. + prot == USB_SC_QIC) {
  64197. + mod_data.protocol_type = USB_SC_QIC;
  64198. + mod_data.protocol_name = "QIC-157";
  64199. + } else if (strnicmp(mod_data.protocol_parm, "UFI", 10) == 0 ||
  64200. + prot == USB_SC_UFI) {
  64201. + mod_data.protocol_type = USB_SC_UFI;
  64202. + mod_data.protocol_name = "UFI";
  64203. + } else if (strnicmp(mod_data.protocol_parm, "8070", 4) == 0 ||
  64204. + prot == USB_SC_8070) {
  64205. + mod_data.protocol_type = USB_SC_8070;
  64206. + mod_data.protocol_name = "8070i";
  64207. + } else {
  64208. + ERROR(fsg, "invalid protocol: %s\n", mod_data.protocol_parm);
  64209. + return -EINVAL;
  64210. + }
  64211. +
  64212. + mod_data.buflen &= PAGE_CACHE_MASK;
  64213. + if (mod_data.buflen <= 0) {
  64214. + ERROR(fsg, "invalid buflen\n");
  64215. + return -ETOOSMALL;
  64216. + }
  64217. +
  64218. +#endif /* CONFIG_USB_FILE_STORAGE_TEST */
  64219. +
  64220. + /* Serial string handling.
  64221. + * On a real device, the serial string would be loaded
  64222. + * from permanent storage. */
  64223. + if (mod_data.serial) {
  64224. + const char *ch;
  64225. + unsigned len = 0;
  64226. +
  64227. + /* Sanity check :
  64228. + * The CB[I] specification limits the serial string to
  64229. + * 12 uppercase hexadecimal characters.
  64230. + * BBB need at least 12 uppercase hexadecimal characters,
  64231. + * with a maximum of 126. */
  64232. + for (ch = mod_data.serial; *ch; ++ch) {
  64233. + ++len;
  64234. + if ((*ch < '0' || *ch > '9') &&
  64235. + (*ch < 'A' || *ch > 'F')) { /* not uppercase hex */
  64236. + WARNING(fsg,
  64237. + "Invalid serial string character: %c\n",
  64238. + *ch);
  64239. + goto no_serial;
  64240. + }
  64241. + }
  64242. + if (len > 126 ||
  64243. + (mod_data.transport_type == USB_PR_BULK && len < 12) ||
  64244. + (mod_data.transport_type != USB_PR_BULK && len > 12)) {
  64245. + WARNING(fsg, "Invalid serial string length!\n");
  64246. + goto no_serial;
  64247. + }
  64248. + fsg_strings[FSG_STRING_SERIAL - 1].s = mod_data.serial;
  64249. + } else {
  64250. + WARNING(fsg, "No serial-number string provided!\n");
  64251. + no_serial:
  64252. + device_desc.iSerialNumber = 0;
  64253. + }
  64254. +
  64255. + return 0;
  64256. +}
  64257. +
  64258. +
  64259. +static int __init fsg_bind(struct usb_gadget *gadget)
  64260. +{
  64261. + struct fsg_dev *fsg = the_fsg;
  64262. + int rc;
  64263. + int i;
  64264. + struct fsg_lun *curlun;
  64265. + struct usb_ep *ep;
  64266. + struct usb_request *req;
  64267. + char *pathbuf, *p;
  64268. +
  64269. + fsg->gadget = gadget;
  64270. + set_gadget_data(gadget, fsg);
  64271. + fsg->ep0 = gadget->ep0;
  64272. + fsg->ep0->driver_data = fsg;
  64273. +
  64274. + if ((rc = check_parameters(fsg)) != 0)
  64275. + goto out;
  64276. +
  64277. + if (mod_data.removable) { // Enable the store_xxx attributes
  64278. + dev_attr_file.attr.mode = 0644;
  64279. + dev_attr_file.store = fsg_store_file;
  64280. + if (!mod_data.cdrom) {
  64281. + dev_attr_ro.attr.mode = 0644;
  64282. + dev_attr_ro.store = fsg_store_ro;
  64283. + }
  64284. + }
  64285. +
  64286. + /* Only for removable media? */
  64287. + dev_attr_nofua.attr.mode = 0644;
  64288. + dev_attr_nofua.store = fsg_store_nofua;
  64289. +
  64290. + /* Find out how many LUNs there should be */
  64291. + i = mod_data.nluns;
  64292. + if (i == 0)
  64293. + i = max(mod_data.num_filenames, 1u);
  64294. + if (i > FSG_MAX_LUNS) {
  64295. + ERROR(fsg, "invalid number of LUNs: %d\n", i);
  64296. + rc = -EINVAL;
  64297. + goto out;
  64298. + }
  64299. +
  64300. + /* Create the LUNs, open their backing files, and register the
  64301. + * LUN devices in sysfs. */
  64302. + fsg->luns = kzalloc(i * sizeof(struct fsg_lun), GFP_KERNEL);
  64303. + if (!fsg->luns) {
  64304. + rc = -ENOMEM;
  64305. + goto out;
  64306. + }
  64307. + fsg->nluns = i;
  64308. +
  64309. + for (i = 0; i < fsg->nluns; ++i) {
  64310. + curlun = &fsg->luns[i];
  64311. + curlun->cdrom = !!mod_data.cdrom;
  64312. + curlun->ro = mod_data.cdrom || mod_data.ro[i];
  64313. + curlun->initially_ro = curlun->ro;
  64314. + curlun->removable = mod_data.removable;
  64315. + curlun->nofua = mod_data.nofua[i];
  64316. + curlun->dev.release = lun_release;
  64317. + curlun->dev.parent = &gadget->dev;
  64318. + curlun->dev.driver = &fsg_driver.driver;
  64319. + dev_set_drvdata(&curlun->dev, &fsg->filesem);
  64320. + dev_set_name(&curlun->dev,"%s-lun%d",
  64321. + dev_name(&gadget->dev), i);
  64322. +
  64323. + kref_get(&fsg->ref);
  64324. + rc = device_register(&curlun->dev);
  64325. + if (rc) {
  64326. + INFO(fsg, "failed to register LUN%d: %d\n", i, rc);
  64327. + put_device(&curlun->dev);
  64328. + goto out;
  64329. + }
  64330. + curlun->registered = 1;
  64331. +
  64332. + rc = device_create_file(&curlun->dev, &dev_attr_ro);
  64333. + if (rc)
  64334. + goto out;
  64335. + rc = device_create_file(&curlun->dev, &dev_attr_nofua);
  64336. + if (rc)
  64337. + goto out;
  64338. + rc = device_create_file(&curlun->dev, &dev_attr_file);
  64339. + if (rc)
  64340. + goto out;
  64341. +
  64342. + if (mod_data.file[i] && *mod_data.file[i]) {
  64343. + rc = fsg_lun_open(curlun, mod_data.file[i]);
  64344. + if (rc)
  64345. + goto out;
  64346. + } else if (!mod_data.removable) {
  64347. + ERROR(fsg, "no file given for LUN%d\n", i);
  64348. + rc = -EINVAL;
  64349. + goto out;
  64350. + }
  64351. + }
  64352. +
  64353. + /* Find all the endpoints we will use */
  64354. + usb_ep_autoconfig_reset(gadget);
  64355. + ep = usb_ep_autoconfig(gadget, &fsg_fs_bulk_in_desc);
  64356. + if (!ep)
  64357. + goto autoconf_fail;
  64358. + ep->driver_data = fsg; // claim the endpoint
  64359. + fsg->bulk_in = ep;
  64360. +
  64361. + ep = usb_ep_autoconfig(gadget, &fsg_fs_bulk_out_desc);
  64362. + if (!ep)
  64363. + goto autoconf_fail;
  64364. + ep->driver_data = fsg; // claim the endpoint
  64365. + fsg->bulk_out = ep;
  64366. +
  64367. + if (transport_is_cbi()) {
  64368. + ep = usb_ep_autoconfig(gadget, &fsg_fs_intr_in_desc);
  64369. + if (!ep)
  64370. + goto autoconf_fail;
  64371. + ep->driver_data = fsg; // claim the endpoint
  64372. + fsg->intr_in = ep;
  64373. + }
  64374. +
  64375. + /* Fix up the descriptors */
  64376. + device_desc.idVendor = cpu_to_le16(mod_data.vendor);
  64377. + device_desc.idProduct = cpu_to_le16(mod_data.product);
  64378. + device_desc.bcdDevice = cpu_to_le16(mod_data.release);
  64379. +
  64380. + i = (transport_is_cbi() ? 3 : 2); // Number of endpoints
  64381. + fsg_intf_desc.bNumEndpoints = i;
  64382. + fsg_intf_desc.bInterfaceSubClass = mod_data.protocol_type;
  64383. + fsg_intf_desc.bInterfaceProtocol = mod_data.transport_type;
  64384. + fsg_fs_function[i + FSG_FS_FUNCTION_PRE_EP_ENTRIES] = NULL;
  64385. +
  64386. + if (gadget_is_dualspeed(gadget)) {
  64387. + fsg_hs_function[i + FSG_HS_FUNCTION_PRE_EP_ENTRIES] = NULL;
  64388. +
  64389. + /* Assume endpoint addresses are the same for both speeds */
  64390. + fsg_hs_bulk_in_desc.bEndpointAddress =
  64391. + fsg_fs_bulk_in_desc.bEndpointAddress;
  64392. + fsg_hs_bulk_out_desc.bEndpointAddress =
  64393. + fsg_fs_bulk_out_desc.bEndpointAddress;
  64394. + fsg_hs_intr_in_desc.bEndpointAddress =
  64395. + fsg_fs_intr_in_desc.bEndpointAddress;
  64396. + }
  64397. +
  64398. + if (gadget_is_superspeed(gadget)) {
  64399. + unsigned max_burst;
  64400. +
  64401. + fsg_ss_function[i + FSG_SS_FUNCTION_PRE_EP_ENTRIES] = NULL;
  64402. +
  64403. + /* Calculate bMaxBurst, we know packet size is 1024 */
  64404. + max_burst = min_t(unsigned, mod_data.buflen / 1024, 15);
  64405. +
  64406. + /* Assume endpoint addresses are the same for both speeds */
  64407. + fsg_ss_bulk_in_desc.bEndpointAddress =
  64408. + fsg_fs_bulk_in_desc.bEndpointAddress;
  64409. + fsg_ss_bulk_in_comp_desc.bMaxBurst = max_burst;
  64410. +
  64411. + fsg_ss_bulk_out_desc.bEndpointAddress =
  64412. + fsg_fs_bulk_out_desc.bEndpointAddress;
  64413. + fsg_ss_bulk_out_comp_desc.bMaxBurst = max_burst;
  64414. + }
  64415. +
  64416. + if (gadget_is_otg(gadget))
  64417. + fsg_otg_desc.bmAttributes |= USB_OTG_HNP;
  64418. +
  64419. + rc = -ENOMEM;
  64420. +
  64421. + /* Allocate the request and buffer for endpoint 0 */
  64422. + fsg->ep0req = req = usb_ep_alloc_request(fsg->ep0, GFP_KERNEL);
  64423. + if (!req)
  64424. + goto out;
  64425. + req->buf = kmalloc(EP0_BUFSIZE, GFP_KERNEL);
  64426. + if (!req->buf)
  64427. + goto out;
  64428. + req->complete = ep0_complete;
  64429. +
  64430. + /* Allocate the data buffers */
  64431. + for (i = 0; i < fsg_num_buffers; ++i) {
  64432. + struct fsg_buffhd *bh = &fsg->buffhds[i];
  64433. +
  64434. + /* Allocate for the bulk-in endpoint. We assume that
  64435. + * the buffer will also work with the bulk-out (and
  64436. + * interrupt-in) endpoint. */
  64437. + bh->buf = kmalloc(mod_data.buflen, GFP_KERNEL);
  64438. + if (!bh->buf)
  64439. + goto out;
  64440. + bh->next = bh + 1;
  64441. + }
  64442. + fsg->buffhds[fsg_num_buffers - 1].next = &fsg->buffhds[0];
  64443. +
  64444. + /* This should reflect the actual gadget power source */
  64445. + usb_gadget_set_selfpowered(gadget);
  64446. +
  64447. + snprintf(fsg_string_manufacturer, sizeof fsg_string_manufacturer,
  64448. + "%s %s with %s",
  64449. + init_utsname()->sysname, init_utsname()->release,
  64450. + gadget->name);
  64451. +
  64452. + fsg->thread_task = kthread_create(fsg_main_thread, fsg,
  64453. + "file-storage-gadget");
  64454. + if (IS_ERR(fsg->thread_task)) {
  64455. + rc = PTR_ERR(fsg->thread_task);
  64456. + goto out;
  64457. + }
  64458. +
  64459. + INFO(fsg, DRIVER_DESC ", version: " DRIVER_VERSION "\n");
  64460. + INFO(fsg, "NOTE: This driver is deprecated. "
  64461. + "Consider using g_mass_storage instead.\n");
  64462. + INFO(fsg, "Number of LUNs=%d\n", fsg->nluns);
  64463. +
  64464. + pathbuf = kmalloc(PATH_MAX, GFP_KERNEL);
  64465. + for (i = 0; i < fsg->nluns; ++i) {
  64466. + curlun = &fsg->luns[i];
  64467. + if (fsg_lun_is_open(curlun)) {
  64468. + p = NULL;
  64469. + if (pathbuf) {
  64470. + p = d_path(&curlun->filp->f_path,
  64471. + pathbuf, PATH_MAX);
  64472. + if (IS_ERR(p))
  64473. + p = NULL;
  64474. + }
  64475. + LINFO(curlun, "ro=%d, nofua=%d, file: %s\n",
  64476. + curlun->ro, curlun->nofua, (p ? p : "(error)"));
  64477. + }
  64478. + }
  64479. + kfree(pathbuf);
  64480. +
  64481. + DBG(fsg, "transport=%s (x%02x)\n",
  64482. + mod_data.transport_name, mod_data.transport_type);
  64483. + DBG(fsg, "protocol=%s (x%02x)\n",
  64484. + mod_data.protocol_name, mod_data.protocol_type);
  64485. + DBG(fsg, "VendorID=x%04x, ProductID=x%04x, Release=x%04x\n",
  64486. + mod_data.vendor, mod_data.product, mod_data.release);
  64487. + DBG(fsg, "removable=%d, stall=%d, cdrom=%d, buflen=%u\n",
  64488. + mod_data.removable, mod_data.can_stall,
  64489. + mod_data.cdrom, mod_data.buflen);
  64490. + DBG(fsg, "I/O thread pid: %d\n", task_pid_nr(fsg->thread_task));
  64491. +
  64492. + set_bit(REGISTERED, &fsg->atomic_bitflags);
  64493. +
  64494. + /* Tell the thread to start working */
  64495. + wake_up_process(fsg->thread_task);
  64496. + return 0;
  64497. +
  64498. +autoconf_fail:
  64499. + ERROR(fsg, "unable to autoconfigure all endpoints\n");
  64500. + rc = -ENOTSUPP;
  64501. +
  64502. +out:
  64503. + fsg->state = FSG_STATE_TERMINATED; // The thread is dead
  64504. + fsg_unbind(gadget);
  64505. + complete(&fsg->thread_notifier);
  64506. + return rc;
  64507. +}
  64508. +
  64509. +
  64510. +/*-------------------------------------------------------------------------*/
  64511. +
  64512. +static void fsg_suspend(struct usb_gadget *gadget)
  64513. +{
  64514. + struct fsg_dev *fsg = get_gadget_data(gadget);
  64515. +
  64516. + DBG(fsg, "suspend\n");
  64517. + set_bit(SUSPENDED, &fsg->atomic_bitflags);
  64518. +}
  64519. +
  64520. +static void fsg_resume(struct usb_gadget *gadget)
  64521. +{
  64522. + struct fsg_dev *fsg = get_gadget_data(gadget);
  64523. +
  64524. + DBG(fsg, "resume\n");
  64525. + clear_bit(SUSPENDED, &fsg->atomic_bitflags);
  64526. +}
  64527. +
  64528. +
  64529. +/*-------------------------------------------------------------------------*/
  64530. +
  64531. +static struct usb_gadget_driver fsg_driver = {
  64532. + .max_speed = USB_SPEED_SUPER,
  64533. + .function = (char *) fsg_string_product,
  64534. + .unbind = fsg_unbind,
  64535. + .disconnect = fsg_disconnect,
  64536. + .setup = fsg_setup,
  64537. + .suspend = fsg_suspend,
  64538. + .resume = fsg_resume,
  64539. +
  64540. + .driver = {
  64541. + .name = DRIVER_NAME,
  64542. + .owner = THIS_MODULE,
  64543. + // .release = ...
  64544. + // .suspend = ...
  64545. + // .resume = ...
  64546. + },
  64547. +};
  64548. +
  64549. +
  64550. +static int __init fsg_alloc(void)
  64551. +{
  64552. + struct fsg_dev *fsg;
  64553. +
  64554. + fsg = kzalloc(sizeof *fsg +
  64555. + fsg_num_buffers * sizeof *(fsg->buffhds), GFP_KERNEL);
  64556. +
  64557. + if (!fsg)
  64558. + return -ENOMEM;
  64559. + spin_lock_init(&fsg->lock);
  64560. + init_rwsem(&fsg->filesem);
  64561. + kref_init(&fsg->ref);
  64562. + init_completion(&fsg->thread_notifier);
  64563. +
  64564. + the_fsg = fsg;
  64565. + return 0;
  64566. +}
  64567. +
  64568. +
  64569. +static int __init fsg_init(void)
  64570. +{
  64571. + int rc;
  64572. + struct fsg_dev *fsg;
  64573. +
  64574. + rc = fsg_num_buffers_validate();
  64575. + if (rc != 0)
  64576. + return rc;
  64577. +
  64578. + if ((rc = fsg_alloc()) != 0)
  64579. + return rc;
  64580. + fsg = the_fsg;
  64581. + if ((rc = usb_gadget_probe_driver(&fsg_driver, fsg_bind)) != 0)
  64582. + kref_put(&fsg->ref, fsg_release);
  64583. + return rc;
  64584. +}
  64585. +module_init(fsg_init);
  64586. +
  64587. +
  64588. +static void __exit fsg_cleanup(void)
  64589. +{
  64590. + struct fsg_dev *fsg = the_fsg;
  64591. +
  64592. + /* Unregister the driver iff the thread hasn't already done so */
  64593. + if (test_and_clear_bit(REGISTERED, &fsg->atomic_bitflags))
  64594. + usb_gadget_unregister_driver(&fsg_driver);
  64595. +
  64596. + /* Wait for the thread to finish up */
  64597. + wait_for_completion(&fsg->thread_notifier);
  64598. +
  64599. + kref_put(&fsg->ref, fsg_release);
  64600. +}
  64601. +module_exit(fsg_cleanup);
  64602. diff -Nur linux-3.18.8/drivers/usb/host/dwc_common_port/changes.txt linux-rpi/drivers/usb/host/dwc_common_port/changes.txt
  64603. --- linux-3.18.8/drivers/usb/host/dwc_common_port/changes.txt 1970-01-01 01:00:00.000000000 +0100
  64604. +++ linux-rpi/drivers/usb/host/dwc_common_port/changes.txt 2015-03-05 14:40:16.553715806 +0100
  64605. @@ -0,0 +1,174 @@
  64606. +
  64607. +dwc_read_reg32() and friends now take an additional parameter, a pointer to an
  64608. +IO context struct. The IO context struct should live in an os-dependent struct
  64609. +in your driver. As an example, the dwc_usb3 driver has an os-dependent struct
  64610. +named 'os_dep' embedded in the main device struct. So there these calls look
  64611. +like this:
  64612. +
  64613. + dwc_read_reg32(&usb3_dev->os_dep.ioctx, &pcd->dev_global_regs->dcfg);
  64614. +
  64615. + dwc_write_reg32(&usb3_dev->os_dep.ioctx,
  64616. + &pcd->dev_global_regs->dcfg, 0);
  64617. +
  64618. +Note that for the existing Linux driver ports, it is not necessary to actually
  64619. +define the 'ioctx' member in the os-dependent struct. Since Linux does not
  64620. +require an IO context, its macros for dwc_read_reg32() and friends do not
  64621. +use the context pointer, so it is optimized away by the compiler. But it is
  64622. +necessary to add the pointer parameter to all of the call sites, to be ready
  64623. +for any future ports (such as FreeBSD) which do require an IO context.
  64624. +
  64625. +
  64626. +Similarly, dwc_alloc(), dwc_alloc_atomic(), dwc_strdup(), and dwc_free() now
  64627. +take an additional parameter, a pointer to a memory context. Examples:
  64628. +
  64629. + addr = dwc_alloc(&usb3_dev->os_dep.memctx, size);
  64630. +
  64631. + dwc_free(&usb3_dev->os_dep.memctx, addr);
  64632. +
  64633. +Again, for the Linux ports, it is not necessary to actually define the memctx
  64634. +member, but it is necessary to add the pointer parameter to all of the call
  64635. +sites.
  64636. +
  64637. +
  64638. +Same for dwc_dma_alloc() and dwc_dma_free(). Examples:
  64639. +
  64640. + virt_addr = dwc_dma_alloc(&usb3_dev->os_dep.dmactx, size, &phys_addr);
  64641. +
  64642. + dwc_dma_free(&usb3_dev->os_dep.dmactx, size, virt_addr, phys_addr);
  64643. +
  64644. +
  64645. +Same for dwc_mutex_alloc() and dwc_mutex_free(). Examples:
  64646. +
  64647. + mutex = dwc_mutex_alloc(&usb3_dev->os_dep.mtxctx);
  64648. +
  64649. + dwc_mutex_free(&usb3_dev->os_dep.mtxctx, mutex);
  64650. +
  64651. +
  64652. +Same for dwc_spinlock_alloc() and dwc_spinlock_free(). Examples:
  64653. +
  64654. + lock = dwc_spinlock_alloc(&usb3_dev->osdep.splctx);
  64655. +
  64656. + dwc_spinlock_free(&usb3_dev->osdep.splctx, lock);
  64657. +
  64658. +
  64659. +Same for dwc_timer_alloc(). Example:
  64660. +
  64661. + timer = dwc_timer_alloc(&usb3_dev->os_dep.tmrctx, "dwc_usb3_tmr1",
  64662. + cb_func, cb_data);
  64663. +
  64664. +
  64665. +Same for dwc_waitq_alloc(). Example:
  64666. +
  64667. + waitq = dwc_waitq_alloc(&usb3_dev->os_dep.wtqctx);
  64668. +
  64669. +
  64670. +Same for dwc_thread_run(). Example:
  64671. +
  64672. + thread = dwc_thread_run(&usb3_dev->os_dep.thdctx, func,
  64673. + "dwc_usb3_thd1", data);
  64674. +
  64675. +
  64676. +Same for dwc_workq_alloc(). Example:
  64677. +
  64678. + workq = dwc_workq_alloc(&usb3_dev->osdep.wkqctx, "dwc_usb3_wkq1");
  64679. +
  64680. +
  64681. +Same for dwc_task_alloc(). Example:
  64682. +
  64683. + task = dwc_task_alloc(&usb3_dev->os_dep.tskctx, "dwc_usb3_tsk1",
  64684. + cb_func, cb_data);
  64685. +
  64686. +
  64687. +In addition to the context pointer additions, a few core functions have had
  64688. +other changes made to their parameters:
  64689. +
  64690. +The 'flags' parameter to dwc_spinlock_irqsave() and dwc_spinunlock_irqrestore()
  64691. +has been changed from a uint64_t to a dwc_irqflags_t.
  64692. +
  64693. +dwc_thread_should_stop() now takes a 'dwc_thread_t *' parameter, because the
  64694. +FreeBSD equivalent of that function requires it.
  64695. +
  64696. +And, in addition to the context pointer, dwc_task_alloc() also adds a
  64697. +'char *name' parameter, to be consistent with dwc_thread_run() and
  64698. +dwc_workq_alloc(), and because the FreeBSD equivalent of that function
  64699. +requires a unique name.
  64700. +
  64701. +
  64702. +Here is a complete list of the core functions that now take a pointer to a
  64703. +context as their first parameter:
  64704. +
  64705. + dwc_read_reg32
  64706. + dwc_read_reg64
  64707. + dwc_write_reg32
  64708. + dwc_write_reg64
  64709. + dwc_modify_reg32
  64710. + dwc_modify_reg64
  64711. + dwc_alloc
  64712. + dwc_alloc_atomic
  64713. + dwc_strdup
  64714. + dwc_free
  64715. + dwc_dma_alloc
  64716. + dwc_dma_free
  64717. + dwc_mutex_alloc
  64718. + dwc_mutex_free
  64719. + dwc_spinlock_alloc
  64720. + dwc_spinlock_free
  64721. + dwc_timer_alloc
  64722. + dwc_waitq_alloc
  64723. + dwc_thread_run
  64724. + dwc_workq_alloc
  64725. + dwc_task_alloc Also adds a 'char *name' as its 2nd parameter
  64726. +
  64727. +And here are the core functions that have other changes to their parameters:
  64728. +
  64729. + dwc_spinlock_irqsave 'flags' param is now a 'dwc_irqflags_t *'
  64730. + dwc_spinunlock_irqrestore 'flags' param is now a 'dwc_irqflags_t'
  64731. + dwc_thread_should_stop Adds a 'dwc_thread_t *' parameter
  64732. +
  64733. +
  64734. +
  64735. +The changes to the core functions also require some of the other library
  64736. +functions to change:
  64737. +
  64738. + dwc_cc_if_alloc() and dwc_cc_if_free() now take a 'void *memctx'
  64739. + (for memory allocation) as the 1st param and a 'void *mtxctx'
  64740. + (for mutex allocation) as the 2nd param.
  64741. +
  64742. + dwc_cc_clear(), dwc_cc_add(), dwc_cc_change(), dwc_cc_remove(),
  64743. + dwc_cc_data_for_save(), and dwc_cc_restore_from_data() now take a
  64744. + 'void *memctx' as the 1st param.
  64745. +
  64746. + dwc_dh_modpow(), dwc_dh_pk(), and dwc_dh_derive_keys() now take a
  64747. + 'void *memctx' as the 1st param.
  64748. +
  64749. + dwc_modpow() now takes a 'void *memctx' as the 1st param.
  64750. +
  64751. + dwc_alloc_notification_manager() now takes a 'void *memctx' as the
  64752. + 1st param and a 'void *wkqctx' (for work queue allocation) as the 2nd
  64753. + param, and also now returns an integer value that is non-zero if
  64754. + allocation of its data structures or work queue fails.
  64755. +
  64756. + dwc_register_notifier() now takes a 'void *memctx' as the 1st param.
  64757. +
  64758. + dwc_memory_debug_start() now takes a 'void *mem_ctx' as the first
  64759. + param, and also now returns an integer value that is non-zero if
  64760. + allocation of its data structures fails.
  64761. +
  64762. +
  64763. +
  64764. +Other miscellaneous changes:
  64765. +
  64766. +The DEBUG_MEMORY and DEBUG_REGS #define's have been renamed to
  64767. +DWC_DEBUG_MEMORY and DWC_DEBUG_REGS.
  64768. +
  64769. +The following #define's have been added to allow selectively compiling library
  64770. +features:
  64771. +
  64772. + DWC_CCLIB
  64773. + DWC_CRYPTOLIB
  64774. + DWC_NOTIFYLIB
  64775. + DWC_UTFLIB
  64776. +
  64777. +A DWC_LIBMODULE #define has also been added. If this is not defined, then the
  64778. +module code in dwc_common_linux.c is not compiled in. This allows linking the
  64779. +library code directly into a driver module, instead of as a standalone module.
  64780. diff -Nur linux-3.18.8/drivers/usb/host/dwc_common_port/doc/doxygen.cfg linux-rpi/drivers/usb/host/dwc_common_port/doc/doxygen.cfg
  64781. --- linux-3.18.8/drivers/usb/host/dwc_common_port/doc/doxygen.cfg 1970-01-01 01:00:00.000000000 +0100
  64782. +++ linux-rpi/drivers/usb/host/dwc_common_port/doc/doxygen.cfg 2015-03-05 14:40:16.553715806 +0100
  64783. @@ -0,0 +1,270 @@
  64784. +# Doxyfile 1.4.5
  64785. +
  64786. +#---------------------------------------------------------------------------
  64787. +# Project related configuration options
  64788. +#---------------------------------------------------------------------------
  64789. +PROJECT_NAME = "Synopsys DWC Portability and Common Library for UWB"
  64790. +PROJECT_NUMBER =
  64791. +OUTPUT_DIRECTORY = doc
  64792. +CREATE_SUBDIRS = NO
  64793. +OUTPUT_LANGUAGE = English
  64794. +BRIEF_MEMBER_DESC = YES
  64795. +REPEAT_BRIEF = YES
  64796. +ABBREVIATE_BRIEF = "The $name class" \
  64797. + "The $name widget" \
  64798. + "The $name file" \
  64799. + is \
  64800. + provides \
  64801. + specifies \
  64802. + contains \
  64803. + represents \
  64804. + a \
  64805. + an \
  64806. + the
  64807. +ALWAYS_DETAILED_SEC = YES
  64808. +INLINE_INHERITED_MEMB = NO
  64809. +FULL_PATH_NAMES = NO
  64810. +STRIP_FROM_PATH = ..
  64811. +STRIP_FROM_INC_PATH =
  64812. +SHORT_NAMES = NO
  64813. +JAVADOC_AUTOBRIEF = YES
  64814. +MULTILINE_CPP_IS_BRIEF = NO
  64815. +DETAILS_AT_TOP = YES
  64816. +INHERIT_DOCS = YES
  64817. +SEPARATE_MEMBER_PAGES = NO
  64818. +TAB_SIZE = 8
  64819. +ALIASES =
  64820. +OPTIMIZE_OUTPUT_FOR_C = YES
  64821. +OPTIMIZE_OUTPUT_JAVA = NO
  64822. +BUILTIN_STL_SUPPORT = NO
  64823. +DISTRIBUTE_GROUP_DOC = NO
  64824. +SUBGROUPING = NO
  64825. +#---------------------------------------------------------------------------
  64826. +# Build related configuration options
  64827. +#---------------------------------------------------------------------------
  64828. +EXTRACT_ALL = NO
  64829. +EXTRACT_PRIVATE = NO
  64830. +EXTRACT_STATIC = YES
  64831. +EXTRACT_LOCAL_CLASSES = NO
  64832. +EXTRACT_LOCAL_METHODS = NO
  64833. +HIDE_UNDOC_MEMBERS = NO
  64834. +HIDE_UNDOC_CLASSES = NO
  64835. +HIDE_FRIEND_COMPOUNDS = NO
  64836. +HIDE_IN_BODY_DOCS = NO
  64837. +INTERNAL_DOCS = NO
  64838. +CASE_SENSE_NAMES = YES
  64839. +HIDE_SCOPE_NAMES = NO
  64840. +SHOW_INCLUDE_FILES = NO
  64841. +INLINE_INFO = YES
  64842. +SORT_MEMBER_DOCS = NO
  64843. +SORT_BRIEF_DOCS = NO
  64844. +SORT_BY_SCOPE_NAME = NO
  64845. +GENERATE_TODOLIST = YES
  64846. +GENERATE_TESTLIST = YES
  64847. +GENERATE_BUGLIST = YES
  64848. +GENERATE_DEPRECATEDLIST= YES
  64849. +ENABLED_SECTIONS =
  64850. +MAX_INITIALIZER_LINES = 30
  64851. +SHOW_USED_FILES = YES
  64852. +SHOW_DIRECTORIES = YES
  64853. +FILE_VERSION_FILTER =
  64854. +#---------------------------------------------------------------------------
  64855. +# configuration options related to warning and progress messages
  64856. +#---------------------------------------------------------------------------
  64857. +QUIET = YES
  64858. +WARNINGS = YES
  64859. +WARN_IF_UNDOCUMENTED = NO
  64860. +WARN_IF_DOC_ERROR = YES
  64861. +WARN_NO_PARAMDOC = YES
  64862. +WARN_FORMAT = "$file:$line: $text"
  64863. +WARN_LOGFILE =
  64864. +#---------------------------------------------------------------------------
  64865. +# configuration options related to the input files
  64866. +#---------------------------------------------------------------------------
  64867. +INPUT = .
  64868. +FILE_PATTERNS = *.c \
  64869. + *.cc \
  64870. + *.cxx \
  64871. + *.cpp \
  64872. + *.c++ \
  64873. + *.d \
  64874. + *.java \
  64875. + *.ii \
  64876. + *.ixx \
  64877. + *.ipp \
  64878. + *.i++ \
  64879. + *.inl \
  64880. + *.h \
  64881. + *.hh \
  64882. + *.hxx \
  64883. + *.hpp \
  64884. + *.h++ \
  64885. + *.idl \
  64886. + *.odl \
  64887. + *.cs \
  64888. + *.php \
  64889. + *.php3 \
  64890. + *.inc \
  64891. + *.m \
  64892. + *.mm \
  64893. + *.dox \
  64894. + *.py \
  64895. + *.C \
  64896. + *.CC \
  64897. + *.C++ \
  64898. + *.II \
  64899. + *.I++ \
  64900. + *.H \
  64901. + *.HH \
  64902. + *.H++ \
  64903. + *.CS \
  64904. + *.PHP \
  64905. + *.PHP3 \
  64906. + *.M \
  64907. + *.MM \
  64908. + *.PY
  64909. +RECURSIVE = NO
  64910. +EXCLUDE =
  64911. +EXCLUDE_SYMLINKS = NO
  64912. +EXCLUDE_PATTERNS =
  64913. +EXAMPLE_PATH =
  64914. +EXAMPLE_PATTERNS = *
  64915. +EXAMPLE_RECURSIVE = NO
  64916. +IMAGE_PATH =
  64917. +INPUT_FILTER =
  64918. +FILTER_PATTERNS =
  64919. +FILTER_SOURCE_FILES = NO
  64920. +#---------------------------------------------------------------------------
  64921. +# configuration options related to source browsing
  64922. +#---------------------------------------------------------------------------
  64923. +SOURCE_BROWSER = NO
  64924. +INLINE_SOURCES = NO
  64925. +STRIP_CODE_COMMENTS = YES
  64926. +REFERENCED_BY_RELATION = YES
  64927. +REFERENCES_RELATION = YES
  64928. +USE_HTAGS = NO
  64929. +VERBATIM_HEADERS = NO
  64930. +#---------------------------------------------------------------------------
  64931. +# configuration options related to the alphabetical class index
  64932. +#---------------------------------------------------------------------------
  64933. +ALPHABETICAL_INDEX = NO
  64934. +COLS_IN_ALPHA_INDEX = 5
  64935. +IGNORE_PREFIX =
  64936. +#---------------------------------------------------------------------------
  64937. +# configuration options related to the HTML output
  64938. +#---------------------------------------------------------------------------
  64939. +GENERATE_HTML = YES
  64940. +HTML_OUTPUT = html
  64941. +HTML_FILE_EXTENSION = .html
  64942. +HTML_HEADER =
  64943. +HTML_FOOTER =
  64944. +HTML_STYLESHEET =
  64945. +HTML_ALIGN_MEMBERS = YES
  64946. +GENERATE_HTMLHELP = NO
  64947. +CHM_FILE =
  64948. +HHC_LOCATION =
  64949. +GENERATE_CHI = NO
  64950. +BINARY_TOC = NO
  64951. +TOC_EXPAND = NO
  64952. +DISABLE_INDEX = NO
  64953. +ENUM_VALUES_PER_LINE = 4
  64954. +GENERATE_TREEVIEW = YES
  64955. +TREEVIEW_WIDTH = 250
  64956. +#---------------------------------------------------------------------------
  64957. +# configuration options related to the LaTeX output
  64958. +#---------------------------------------------------------------------------
  64959. +GENERATE_LATEX = NO
  64960. +LATEX_OUTPUT = latex
  64961. +LATEX_CMD_NAME = latex
  64962. +MAKEINDEX_CMD_NAME = makeindex
  64963. +COMPACT_LATEX = NO
  64964. +PAPER_TYPE = a4wide
  64965. +EXTRA_PACKAGES =
  64966. +LATEX_HEADER =
  64967. +PDF_HYPERLINKS = NO
  64968. +USE_PDFLATEX = NO
  64969. +LATEX_BATCHMODE = NO
  64970. +LATEX_HIDE_INDICES = NO
  64971. +#---------------------------------------------------------------------------
  64972. +# configuration options related to the RTF output
  64973. +#---------------------------------------------------------------------------
  64974. +GENERATE_RTF = NO
  64975. +RTF_OUTPUT = rtf
  64976. +COMPACT_RTF = NO
  64977. +RTF_HYPERLINKS = NO
  64978. +RTF_STYLESHEET_FILE =
  64979. +RTF_EXTENSIONS_FILE =
  64980. +#---------------------------------------------------------------------------
  64981. +# configuration options related to the man page output
  64982. +#---------------------------------------------------------------------------
  64983. +GENERATE_MAN = NO
  64984. +MAN_OUTPUT = man
  64985. +MAN_EXTENSION = .3
  64986. +MAN_LINKS = NO
  64987. +#---------------------------------------------------------------------------
  64988. +# configuration options related to the XML output
  64989. +#---------------------------------------------------------------------------
  64990. +GENERATE_XML = NO
  64991. +XML_OUTPUT = xml
  64992. +XML_SCHEMA =
  64993. +XML_DTD =
  64994. +XML_PROGRAMLISTING = YES
  64995. +#---------------------------------------------------------------------------
  64996. +# configuration options for the AutoGen Definitions output
  64997. +#---------------------------------------------------------------------------
  64998. +GENERATE_AUTOGEN_DEF = NO
  64999. +#---------------------------------------------------------------------------
  65000. +# configuration options related to the Perl module output
  65001. +#---------------------------------------------------------------------------
  65002. +GENERATE_PERLMOD = NO
  65003. +PERLMOD_LATEX = NO
  65004. +PERLMOD_PRETTY = YES
  65005. +PERLMOD_MAKEVAR_PREFIX =
  65006. +#---------------------------------------------------------------------------
  65007. +# Configuration options related to the preprocessor
  65008. +#---------------------------------------------------------------------------
  65009. +ENABLE_PREPROCESSING = YES
  65010. +MACRO_EXPANSION = NO
  65011. +EXPAND_ONLY_PREDEF = NO
  65012. +SEARCH_INCLUDES = YES
  65013. +INCLUDE_PATH =
  65014. +INCLUDE_FILE_PATTERNS =
  65015. +PREDEFINED = DEBUG DEBUG_MEMORY
  65016. +EXPAND_AS_DEFINED =
  65017. +SKIP_FUNCTION_MACROS = YES
  65018. +#---------------------------------------------------------------------------
  65019. +# Configuration::additions related to external references
  65020. +#---------------------------------------------------------------------------
  65021. +TAGFILES =
  65022. +GENERATE_TAGFILE =
  65023. +ALLEXTERNALS = NO
  65024. +EXTERNAL_GROUPS = YES
  65025. +PERL_PATH = /usr/bin/perl
  65026. +#---------------------------------------------------------------------------
  65027. +# Configuration options related to the dot tool
  65028. +#---------------------------------------------------------------------------
  65029. +CLASS_DIAGRAMS = YES
  65030. +HIDE_UNDOC_RELATIONS = YES
  65031. +HAVE_DOT = NO
  65032. +CLASS_GRAPH = YES
  65033. +COLLABORATION_GRAPH = YES
  65034. +GROUP_GRAPHS = YES
  65035. +UML_LOOK = NO
  65036. +TEMPLATE_RELATIONS = NO
  65037. +INCLUDE_GRAPH = NO
  65038. +INCLUDED_BY_GRAPH = YES
  65039. +CALL_GRAPH = NO
  65040. +GRAPHICAL_HIERARCHY = YES
  65041. +DIRECTORY_GRAPH = YES
  65042. +DOT_IMAGE_FORMAT = png
  65043. +DOT_PATH =
  65044. +DOTFILE_DIRS =
  65045. +MAX_DOT_GRAPH_DEPTH = 1000
  65046. +DOT_TRANSPARENT = NO
  65047. +DOT_MULTI_TARGETS = NO
  65048. +GENERATE_LEGEND = YES
  65049. +DOT_CLEANUP = YES
  65050. +#---------------------------------------------------------------------------
  65051. +# Configuration::additions related to the search engine
  65052. +#---------------------------------------------------------------------------
  65053. +SEARCHENGINE = NO
  65054. diff -Nur linux-3.18.8/drivers/usb/host/dwc_common_port/dwc_cc.c linux-rpi/drivers/usb/host/dwc_common_port/dwc_cc.c
  65055. --- linux-3.18.8/drivers/usb/host/dwc_common_port/dwc_cc.c 1970-01-01 01:00:00.000000000 +0100
  65056. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_cc.c 2015-03-05 14:40:16.553715806 +0100
  65057. @@ -0,0 +1,532 @@
  65058. +/* =========================================================================
  65059. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_cc.c $
  65060. + * $Revision: #4 $
  65061. + * $Date: 2010/11/04 $
  65062. + * $Change: 1621692 $
  65063. + *
  65064. + * Synopsys Portability Library Software and documentation
  65065. + * (hereinafter, "Software") is an Unsupported proprietary work of
  65066. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  65067. + * between Synopsys and you.
  65068. + *
  65069. + * The Software IS NOT an item of Licensed Software or Licensed Product
  65070. + * under any End User Software License Agreement or Agreement for
  65071. + * Licensed Product with Synopsys or any supplement thereto. You are
  65072. + * permitted to use and redistribute this Software in source and binary
  65073. + * forms, with or without modification, provided that redistributions
  65074. + * of source code must retain this notice. You may not view, use,
  65075. + * disclose, copy or distribute this file or any information contained
  65076. + * herein except pursuant to this license grant from Synopsys. If you
  65077. + * do not agree with this notice, including the disclaimer below, then
  65078. + * you are not authorized to use the Software.
  65079. + *
  65080. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  65081. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  65082. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  65083. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  65084. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  65085. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  65086. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  65087. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  65088. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  65089. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  65090. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  65091. + * DAMAGE.
  65092. + * ========================================================================= */
  65093. +#ifdef DWC_CCLIB
  65094. +
  65095. +#include "dwc_cc.h"
  65096. +
  65097. +typedef struct dwc_cc
  65098. +{
  65099. + uint32_t uid;
  65100. + uint8_t chid[16];
  65101. + uint8_t cdid[16];
  65102. + uint8_t ck[16];
  65103. + uint8_t *name;
  65104. + uint8_t length;
  65105. + DWC_CIRCLEQ_ENTRY(dwc_cc) list_entry;
  65106. +} dwc_cc_t;
  65107. +
  65108. +DWC_CIRCLEQ_HEAD(context_list, dwc_cc);
  65109. +
  65110. +/** The main structure for CC management. */
  65111. +struct dwc_cc_if
  65112. +{
  65113. + dwc_mutex_t *mutex;
  65114. + char *filename;
  65115. +
  65116. + unsigned is_host:1;
  65117. +
  65118. + dwc_notifier_t *notifier;
  65119. +
  65120. + struct context_list list;
  65121. +};
  65122. +
  65123. +#ifdef DEBUG
  65124. +static inline void dump_bytes(char *name, uint8_t *bytes, int len)
  65125. +{
  65126. + int i;
  65127. + DWC_PRINTF("%s: ", name);
  65128. + for (i=0; i<len; i++) {
  65129. + DWC_PRINTF("%02x ", bytes[i]);
  65130. + }
  65131. + DWC_PRINTF("\n");
  65132. +}
  65133. +#else
  65134. +#define dump_bytes(x...)
  65135. +#endif
  65136. +
  65137. +static dwc_cc_t *alloc_cc(void *mem_ctx, uint8_t *name, uint32_t length)
  65138. +{
  65139. + dwc_cc_t *cc = dwc_alloc(mem_ctx, sizeof(dwc_cc_t));
  65140. + if (!cc) {
  65141. + return NULL;
  65142. + }
  65143. + DWC_MEMSET(cc, 0, sizeof(dwc_cc_t));
  65144. +
  65145. + if (name) {
  65146. + cc->length = length;
  65147. + cc->name = dwc_alloc(mem_ctx, length);
  65148. + if (!cc->name) {
  65149. + dwc_free(mem_ctx, cc);
  65150. + return NULL;
  65151. + }
  65152. +
  65153. + DWC_MEMCPY(cc->name, name, length);
  65154. + }
  65155. +
  65156. + return cc;
  65157. +}
  65158. +
  65159. +static void free_cc(void *mem_ctx, dwc_cc_t *cc)
  65160. +{
  65161. + if (cc->name) {
  65162. + dwc_free(mem_ctx, cc->name);
  65163. + }
  65164. + dwc_free(mem_ctx, cc);
  65165. +}
  65166. +
  65167. +static uint32_t next_uid(dwc_cc_if_t *cc_if)
  65168. +{
  65169. + uint32_t uid = 0;
  65170. + dwc_cc_t *cc;
  65171. + DWC_CIRCLEQ_FOREACH(cc, &cc_if->list, list_entry) {
  65172. + if (cc->uid > uid) {
  65173. + uid = cc->uid;
  65174. + }
  65175. + }
  65176. +
  65177. + if (uid == 0) {
  65178. + uid = 255;
  65179. + }
  65180. +
  65181. + return uid + 1;
  65182. +}
  65183. +
  65184. +static dwc_cc_t *cc_find(dwc_cc_if_t *cc_if, uint32_t uid)
  65185. +{
  65186. + dwc_cc_t *cc;
  65187. + DWC_CIRCLEQ_FOREACH(cc, &cc_if->list, list_entry) {
  65188. + if (cc->uid == uid) {
  65189. + return cc;
  65190. + }
  65191. + }
  65192. + return NULL;
  65193. +}
  65194. +
  65195. +static unsigned int cc_data_size(dwc_cc_if_t *cc_if)
  65196. +{
  65197. + unsigned int size = 0;
  65198. + dwc_cc_t *cc;
  65199. + DWC_CIRCLEQ_FOREACH(cc, &cc_if->list, list_entry) {
  65200. + size += (48 + 1);
  65201. + if (cc->name) {
  65202. + size += cc->length;
  65203. + }
  65204. + }
  65205. + return size;
  65206. +}
  65207. +
  65208. +static uint32_t cc_match_chid(dwc_cc_if_t *cc_if, uint8_t *chid)
  65209. +{
  65210. + uint32_t uid = 0;
  65211. + dwc_cc_t *cc;
  65212. +
  65213. + DWC_CIRCLEQ_FOREACH(cc, &cc_if->list, list_entry) {
  65214. + if (DWC_MEMCMP(cc->chid, chid, 16) == 0) {
  65215. + uid = cc->uid;
  65216. + break;
  65217. + }
  65218. + }
  65219. + return uid;
  65220. +}
  65221. +static uint32_t cc_match_cdid(dwc_cc_if_t *cc_if, uint8_t *cdid)
  65222. +{
  65223. + uint32_t uid = 0;
  65224. + dwc_cc_t *cc;
  65225. +
  65226. + DWC_CIRCLEQ_FOREACH(cc, &cc_if->list, list_entry) {
  65227. + if (DWC_MEMCMP(cc->cdid, cdid, 16) == 0) {
  65228. + uid = cc->uid;
  65229. + break;
  65230. + }
  65231. + }
  65232. + return uid;
  65233. +}
  65234. +
  65235. +/* Internal cc_add */
  65236. +static int32_t cc_add(void *mem_ctx, dwc_cc_if_t *cc_if, uint8_t *chid,
  65237. + uint8_t *cdid, uint8_t *ck, uint8_t *name, uint8_t length)
  65238. +{
  65239. + dwc_cc_t *cc;
  65240. + uint32_t uid;
  65241. +
  65242. + if (cc_if->is_host) {
  65243. + uid = cc_match_cdid(cc_if, cdid);
  65244. + }
  65245. + else {
  65246. + uid = cc_match_chid(cc_if, chid);
  65247. + }
  65248. +
  65249. + if (uid) {
  65250. + DWC_DEBUGC("Replacing previous connection context id=%d name=%p name_len=%d", uid, name, length);
  65251. + cc = cc_find(cc_if, uid);
  65252. + }
  65253. + else {
  65254. + cc = alloc_cc(mem_ctx, name, length);
  65255. + cc->uid = next_uid(cc_if);
  65256. + DWC_CIRCLEQ_INSERT_TAIL(&cc_if->list, cc, list_entry);
  65257. + }
  65258. +
  65259. + DWC_MEMCPY(&(cc->chid[0]), chid, 16);
  65260. + DWC_MEMCPY(&(cc->cdid[0]), cdid, 16);
  65261. + DWC_MEMCPY(&(cc->ck[0]), ck, 16);
  65262. +
  65263. + DWC_DEBUGC("Added connection context id=%d name=%p name_len=%d", cc->uid, name, length);
  65264. + dump_bytes("CHID", cc->chid, 16);
  65265. + dump_bytes("CDID", cc->cdid, 16);
  65266. + dump_bytes("CK", cc->ck, 16);
  65267. + return cc->uid;
  65268. +}
  65269. +
  65270. +/* Internal cc_clear */
  65271. +static void cc_clear(void *mem_ctx, dwc_cc_if_t *cc_if)
  65272. +{
  65273. + while (!DWC_CIRCLEQ_EMPTY(&cc_if->list)) {
  65274. + dwc_cc_t *cc = DWC_CIRCLEQ_FIRST(&cc_if->list);
  65275. + DWC_CIRCLEQ_REMOVE_INIT(&cc_if->list, cc, list_entry);
  65276. + free_cc(mem_ctx, cc);
  65277. + }
  65278. +}
  65279. +
  65280. +dwc_cc_if_t *dwc_cc_if_alloc(void *mem_ctx, void *mtx_ctx,
  65281. + dwc_notifier_t *notifier, unsigned is_host)
  65282. +{
  65283. + dwc_cc_if_t *cc_if = NULL;
  65284. +
  65285. + /* Allocate a common_cc_if structure */
  65286. + cc_if = dwc_alloc(mem_ctx, sizeof(dwc_cc_if_t));
  65287. +
  65288. + if (!cc_if)
  65289. + return NULL;
  65290. +
  65291. +#if (defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES))
  65292. + DWC_MUTEX_ALLOC_LINUX_DEBUG(cc_if->mutex);
  65293. +#else
  65294. + cc_if->mutex = dwc_mutex_alloc(mtx_ctx);
  65295. +#endif
  65296. + if (!cc_if->mutex) {
  65297. + dwc_free(mem_ctx, cc_if);
  65298. + return NULL;
  65299. + }
  65300. +
  65301. + DWC_CIRCLEQ_INIT(&cc_if->list);
  65302. + cc_if->is_host = is_host;
  65303. + cc_if->notifier = notifier;
  65304. + return cc_if;
  65305. +}
  65306. +
  65307. +void dwc_cc_if_free(void *mem_ctx, void *mtx_ctx, dwc_cc_if_t *cc_if)
  65308. +{
  65309. +#if (defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES))
  65310. + DWC_MUTEX_FREE(cc_if->mutex);
  65311. +#else
  65312. + dwc_mutex_free(mtx_ctx, cc_if->mutex);
  65313. +#endif
  65314. + cc_clear(mem_ctx, cc_if);
  65315. + dwc_free(mem_ctx, cc_if);
  65316. +}
  65317. +
  65318. +static void cc_changed(dwc_cc_if_t *cc_if)
  65319. +{
  65320. + if (cc_if->notifier) {
  65321. + dwc_notify(cc_if->notifier, DWC_CC_LIST_CHANGED_NOTIFICATION, cc_if);
  65322. + }
  65323. +}
  65324. +
  65325. +void dwc_cc_clear(void *mem_ctx, dwc_cc_if_t *cc_if)
  65326. +{
  65327. + DWC_MUTEX_LOCK(cc_if->mutex);
  65328. + cc_clear(mem_ctx, cc_if);
  65329. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  65330. + cc_changed(cc_if);
  65331. +}
  65332. +
  65333. +int32_t dwc_cc_add(void *mem_ctx, dwc_cc_if_t *cc_if, uint8_t *chid,
  65334. + uint8_t *cdid, uint8_t *ck, uint8_t *name, uint8_t length)
  65335. +{
  65336. + uint32_t uid;
  65337. +
  65338. + DWC_MUTEX_LOCK(cc_if->mutex);
  65339. + uid = cc_add(mem_ctx, cc_if, chid, cdid, ck, name, length);
  65340. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  65341. + cc_changed(cc_if);
  65342. +
  65343. + return uid;
  65344. +}
  65345. +
  65346. +void dwc_cc_change(void *mem_ctx, dwc_cc_if_t *cc_if, int32_t id, uint8_t *chid,
  65347. + uint8_t *cdid, uint8_t *ck, uint8_t *name, uint8_t length)
  65348. +{
  65349. + dwc_cc_t* cc;
  65350. +
  65351. + DWC_DEBUGC("Change connection context %d", id);
  65352. +
  65353. + DWC_MUTEX_LOCK(cc_if->mutex);
  65354. + cc = cc_find(cc_if, id);
  65355. + if (!cc) {
  65356. + DWC_ERROR("Uid %d not found in cc list\n", id);
  65357. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  65358. + return;
  65359. + }
  65360. +
  65361. + if (chid) {
  65362. + DWC_MEMCPY(&(cc->chid[0]), chid, 16);
  65363. + }
  65364. + if (cdid) {
  65365. + DWC_MEMCPY(&(cc->cdid[0]), cdid, 16);
  65366. + }
  65367. + if (ck) {
  65368. + DWC_MEMCPY(&(cc->ck[0]), ck, 16);
  65369. + }
  65370. +
  65371. + if (name) {
  65372. + if (cc->name) {
  65373. + dwc_free(mem_ctx, cc->name);
  65374. + }
  65375. + cc->name = dwc_alloc(mem_ctx, length);
  65376. + if (!cc->name) {
  65377. + DWC_ERROR("Out of memory in dwc_cc_change()\n");
  65378. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  65379. + return;
  65380. + }
  65381. + cc->length = length;
  65382. + DWC_MEMCPY(cc->name, name, length);
  65383. + }
  65384. +
  65385. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  65386. +
  65387. + cc_changed(cc_if);
  65388. +
  65389. + DWC_DEBUGC("Changed connection context id=%d\n", id);
  65390. + dump_bytes("New CHID", cc->chid, 16);
  65391. + dump_bytes("New CDID", cc->cdid, 16);
  65392. + dump_bytes("New CK", cc->ck, 16);
  65393. +}
  65394. +
  65395. +void dwc_cc_remove(void *mem_ctx, dwc_cc_if_t *cc_if, int32_t id)
  65396. +{
  65397. + dwc_cc_t *cc;
  65398. +
  65399. + DWC_DEBUGC("Removing connection context %d", id);
  65400. +
  65401. + DWC_MUTEX_LOCK(cc_if->mutex);
  65402. + cc = cc_find(cc_if, id);
  65403. + if (!cc) {
  65404. + DWC_ERROR("Uid %d not found in cc list\n", id);
  65405. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  65406. + return;
  65407. + }
  65408. +
  65409. + DWC_CIRCLEQ_REMOVE_INIT(&cc_if->list, cc, list_entry);
  65410. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  65411. + free_cc(mem_ctx, cc);
  65412. +
  65413. + cc_changed(cc_if);
  65414. +}
  65415. +
  65416. +uint8_t *dwc_cc_data_for_save(void *mem_ctx, dwc_cc_if_t *cc_if, unsigned int *length)
  65417. +{
  65418. + uint8_t *buf, *x;
  65419. + uint8_t zero = 0;
  65420. + dwc_cc_t *cc;
  65421. +
  65422. + DWC_MUTEX_LOCK(cc_if->mutex);
  65423. + *length = cc_data_size(cc_if);
  65424. + if (!(*length)) {
  65425. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  65426. + return NULL;
  65427. + }
  65428. +
  65429. + DWC_DEBUGC("Creating data for saving (length=%d)", *length);
  65430. +
  65431. + buf = dwc_alloc(mem_ctx, *length);
  65432. + if (!buf) {
  65433. + *length = 0;
  65434. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  65435. + return NULL;
  65436. + }
  65437. +
  65438. + x = buf;
  65439. + DWC_CIRCLEQ_FOREACH(cc, &cc_if->list, list_entry) {
  65440. + DWC_MEMCPY(x, cc->chid, 16);
  65441. + x += 16;
  65442. + DWC_MEMCPY(x, cc->cdid, 16);
  65443. + x += 16;
  65444. + DWC_MEMCPY(x, cc->ck, 16);
  65445. + x += 16;
  65446. + if (cc->name) {
  65447. + DWC_MEMCPY(x, &cc->length, 1);
  65448. + x += 1;
  65449. + DWC_MEMCPY(x, cc->name, cc->length);
  65450. + x += cc->length;
  65451. + }
  65452. + else {
  65453. + DWC_MEMCPY(x, &zero, 1);
  65454. + x += 1;
  65455. + }
  65456. + }
  65457. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  65458. +
  65459. + return buf;
  65460. +}
  65461. +
  65462. +void dwc_cc_restore_from_data(void *mem_ctx, dwc_cc_if_t *cc_if, uint8_t *data, uint32_t length)
  65463. +{
  65464. + uint8_t name_length;
  65465. + uint8_t *name;
  65466. + uint8_t *chid;
  65467. + uint8_t *cdid;
  65468. + uint8_t *ck;
  65469. + uint32_t i = 0;
  65470. +
  65471. + DWC_MUTEX_LOCK(cc_if->mutex);
  65472. + cc_clear(mem_ctx, cc_if);
  65473. +
  65474. + while (i < length) {
  65475. + chid = &data[i];
  65476. + i += 16;
  65477. + cdid = &data[i];
  65478. + i += 16;
  65479. + ck = &data[i];
  65480. + i += 16;
  65481. +
  65482. + name_length = data[i];
  65483. + i ++;
  65484. +
  65485. + if (name_length) {
  65486. + name = &data[i];
  65487. + i += name_length;
  65488. + }
  65489. + else {
  65490. + name = NULL;
  65491. + }
  65492. +
  65493. + /* check to see if we haven't overflown the buffer */
  65494. + if (i > length) {
  65495. + DWC_ERROR("Data format error while attempting to load CCs "
  65496. + "(nlen=%d, iter=%d, buflen=%d).\n", name_length, i, length);
  65497. + break;
  65498. + }
  65499. +
  65500. + cc_add(mem_ctx, cc_if, chid, cdid, ck, name, name_length);
  65501. + }
  65502. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  65503. +
  65504. + cc_changed(cc_if);
  65505. +}
  65506. +
  65507. +uint32_t dwc_cc_match_chid(dwc_cc_if_t *cc_if, uint8_t *chid)
  65508. +{
  65509. + uint32_t uid = 0;
  65510. +
  65511. + DWC_MUTEX_LOCK(cc_if->mutex);
  65512. + uid = cc_match_chid(cc_if, chid);
  65513. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  65514. + return uid;
  65515. +}
  65516. +uint32_t dwc_cc_match_cdid(dwc_cc_if_t *cc_if, uint8_t *cdid)
  65517. +{
  65518. + uint32_t uid = 0;
  65519. +
  65520. + DWC_MUTEX_LOCK(cc_if->mutex);
  65521. + uid = cc_match_cdid(cc_if, cdid);
  65522. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  65523. + return uid;
  65524. +}
  65525. +
  65526. +uint8_t *dwc_cc_ck(dwc_cc_if_t *cc_if, int32_t id)
  65527. +{
  65528. + uint8_t *ck = NULL;
  65529. + dwc_cc_t *cc;
  65530. +
  65531. + DWC_MUTEX_LOCK(cc_if->mutex);
  65532. + cc = cc_find(cc_if, id);
  65533. + if (cc) {
  65534. + ck = cc->ck;
  65535. + }
  65536. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  65537. +
  65538. + return ck;
  65539. +
  65540. +}
  65541. +
  65542. +uint8_t *dwc_cc_chid(dwc_cc_if_t *cc_if, int32_t id)
  65543. +{
  65544. + uint8_t *retval = NULL;
  65545. + dwc_cc_t *cc;
  65546. +
  65547. + DWC_MUTEX_LOCK(cc_if->mutex);
  65548. + cc = cc_find(cc_if, id);
  65549. + if (cc) {
  65550. + retval = cc->chid;
  65551. + }
  65552. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  65553. +
  65554. + return retval;
  65555. +}
  65556. +
  65557. +uint8_t *dwc_cc_cdid(dwc_cc_if_t *cc_if, int32_t id)
  65558. +{
  65559. + uint8_t *retval = NULL;
  65560. + dwc_cc_t *cc;
  65561. +
  65562. + DWC_MUTEX_LOCK(cc_if->mutex);
  65563. + cc = cc_find(cc_if, id);
  65564. + if (cc) {
  65565. + retval = cc->cdid;
  65566. + }
  65567. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  65568. +
  65569. + return retval;
  65570. +}
  65571. +
  65572. +uint8_t *dwc_cc_name(dwc_cc_if_t *cc_if, int32_t id, uint8_t *length)
  65573. +{
  65574. + uint8_t *retval = NULL;
  65575. + dwc_cc_t *cc;
  65576. +
  65577. + DWC_MUTEX_LOCK(cc_if->mutex);
  65578. + *length = 0;
  65579. + cc = cc_find(cc_if, id);
  65580. + if (cc) {
  65581. + *length = cc->length;
  65582. + retval = cc->name;
  65583. + }
  65584. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  65585. +
  65586. + return retval;
  65587. +}
  65588. +
  65589. +#endif /* DWC_CCLIB */
  65590. diff -Nur linux-3.18.8/drivers/usb/host/dwc_common_port/dwc_cc.h linux-rpi/drivers/usb/host/dwc_common_port/dwc_cc.h
  65591. --- linux-3.18.8/drivers/usb/host/dwc_common_port/dwc_cc.h 1970-01-01 01:00:00.000000000 +0100
  65592. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_cc.h 2015-03-05 14:40:16.553715806 +0100
  65593. @@ -0,0 +1,224 @@
  65594. +/* =========================================================================
  65595. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_cc.h $
  65596. + * $Revision: #4 $
  65597. + * $Date: 2010/09/28 $
  65598. + * $Change: 1596182 $
  65599. + *
  65600. + * Synopsys Portability Library Software and documentation
  65601. + * (hereinafter, "Software") is an Unsupported proprietary work of
  65602. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  65603. + * between Synopsys and you.
  65604. + *
  65605. + * The Software IS NOT an item of Licensed Software or Licensed Product
  65606. + * under any End User Software License Agreement or Agreement for
  65607. + * Licensed Product with Synopsys or any supplement thereto. You are
  65608. + * permitted to use and redistribute this Software in source and binary
  65609. + * forms, with or without modification, provided that redistributions
  65610. + * of source code must retain this notice. You may not view, use,
  65611. + * disclose, copy or distribute this file or any information contained
  65612. + * herein except pursuant to this license grant from Synopsys. If you
  65613. + * do not agree with this notice, including the disclaimer below, then
  65614. + * you are not authorized to use the Software.
  65615. + *
  65616. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  65617. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  65618. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  65619. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  65620. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  65621. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  65622. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  65623. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  65624. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  65625. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  65626. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  65627. + * DAMAGE.
  65628. + * ========================================================================= */
  65629. +#ifndef _DWC_CC_H_
  65630. +#define _DWC_CC_H_
  65631. +
  65632. +#ifdef __cplusplus
  65633. +extern "C" {
  65634. +#endif
  65635. +
  65636. +/** @file
  65637. + *
  65638. + * This file defines the Context Context library.
  65639. + *
  65640. + * The main data structure is dwc_cc_if_t which is returned by either the
  65641. + * dwc_cc_if_alloc function or returned by the module to the user via a provided
  65642. + * function. The data structure is opaque and should only be manipulated via the
  65643. + * functions provied in this API.
  65644. + *
  65645. + * It manages a list of connection contexts and operations can be performed to
  65646. + * add, remove, query, search, and change, those contexts. Additionally,
  65647. + * a dwc_notifier_t object can be requested from the manager so that
  65648. + * the user can be notified whenever the context list has changed.
  65649. + */
  65650. +
  65651. +#include "dwc_os.h"
  65652. +#include "dwc_list.h"
  65653. +#include "dwc_notifier.h"
  65654. +
  65655. +
  65656. +/* Notifications */
  65657. +#define DWC_CC_LIST_CHANGED_NOTIFICATION "DWC_CC_LIST_CHANGED_NOTIFICATION"
  65658. +
  65659. +struct dwc_cc_if;
  65660. +typedef struct dwc_cc_if dwc_cc_if_t;
  65661. +
  65662. +
  65663. +/** @name Connection Context Operations */
  65664. +/** @{ */
  65665. +
  65666. +/** This function allocates memory for a dwc_cc_if_t structure, initializes
  65667. + * fields to default values, and returns a pointer to the structure or NULL on
  65668. + * error. */
  65669. +extern dwc_cc_if_t *dwc_cc_if_alloc(void *mem_ctx, void *mtx_ctx,
  65670. + dwc_notifier_t *notifier, unsigned is_host);
  65671. +
  65672. +/** Frees the memory for the specified CC structure allocated from
  65673. + * dwc_cc_if_alloc(). */
  65674. +extern void dwc_cc_if_free(void *mem_ctx, void *mtx_ctx, dwc_cc_if_t *cc_if);
  65675. +
  65676. +/** Removes all contexts from the connection context list */
  65677. +extern void dwc_cc_clear(void *mem_ctx, dwc_cc_if_t *cc_if);
  65678. +
  65679. +/** Adds a connection context (CHID, CK, CDID, Name) to the connection context list.
  65680. + * If a CHID already exists, the CK and name are overwritten. Statistics are
  65681. + * not overwritten.
  65682. + *
  65683. + * @param cc_if The cc_if structure.
  65684. + * @param chid A pointer to the 16-byte CHID. This value will be copied.
  65685. + * @param ck A pointer to the 16-byte CK. This value will be copied.
  65686. + * @param cdid A pointer to the 16-byte CDID. This value will be copied.
  65687. + * @param name An optional host friendly name as defined in the association model
  65688. + * spec. Must be a UTF16-LE unicode string. Can be NULL to indicated no name.
  65689. + * @param length The length othe unicode string.
  65690. + * @return A unique identifier used to refer to this context that is valid for
  65691. + * as long as this context is still in the list. */
  65692. +extern int32_t dwc_cc_add(void *mem_ctx, dwc_cc_if_t *cc_if, uint8_t *chid,
  65693. + uint8_t *cdid, uint8_t *ck, uint8_t *name,
  65694. + uint8_t length);
  65695. +
  65696. +/** Changes the CHID, CK, CDID, or Name values of a connection context in the
  65697. + * list, preserving any accumulated statistics. This would typically be called
  65698. + * if the host decideds to change the context with a SET_CONNECTION request.
  65699. + *
  65700. + * @param cc_if The cc_if structure.
  65701. + * @param id The identifier of the connection context.
  65702. + * @param chid A pointer to the 16-byte CHID. This value will be copied. NULL
  65703. + * indicates no change.
  65704. + * @param cdid A pointer to the 16-byte CDID. This value will be copied. NULL
  65705. + * indicates no change.
  65706. + * @param ck A pointer to the 16-byte CK. This value will be copied. NULL
  65707. + * indicates no change.
  65708. + * @param name Host friendly name UTF16-LE. NULL indicates no change.
  65709. + * @param length Length of name. */
  65710. +extern void dwc_cc_change(void *mem_ctx, dwc_cc_if_t *cc_if, int32_t id,
  65711. + uint8_t *chid, uint8_t *cdid, uint8_t *ck,
  65712. + uint8_t *name, uint8_t length);
  65713. +
  65714. +/** Remove the specified connection context.
  65715. + * @param cc_if The cc_if structure.
  65716. + * @param id The identifier of the connection context to remove. */
  65717. +extern void dwc_cc_remove(void *mem_ctx, dwc_cc_if_t *cc_if, int32_t id);
  65718. +
  65719. +/** Get a binary block of data for the connection context list and attributes.
  65720. + * This data can be used by the OS specific driver to save the connection
  65721. + * context list into non-volatile memory.
  65722. + *
  65723. + * @param cc_if The cc_if structure.
  65724. + * @param length Return the length of the data buffer.
  65725. + * @return A pointer to the data buffer. The memory for this buffer should be
  65726. + * freed with DWC_FREE() after use. */
  65727. +extern uint8_t *dwc_cc_data_for_save(void *mem_ctx, dwc_cc_if_t *cc_if,
  65728. + unsigned int *length);
  65729. +
  65730. +/** Restore the connection context list from the binary data that was previously
  65731. + * returned from a call to dwc_cc_data_for_save. This can be used by the OS specific
  65732. + * driver to load a connection context list from non-volatile memory.
  65733. + *
  65734. + * @param cc_if The cc_if structure.
  65735. + * @param data The data bytes as returned from dwc_cc_data_for_save.
  65736. + * @param length The length of the data. */
  65737. +extern void dwc_cc_restore_from_data(void *mem_ctx, dwc_cc_if_t *cc_if,
  65738. + uint8_t *data, unsigned int length);
  65739. +
  65740. +/** Find the connection context from the specified CHID.
  65741. + *
  65742. + * @param cc_if The cc_if structure.
  65743. + * @param chid A pointer to the CHID data.
  65744. + * @return A non-zero identifier of the connection context if the CHID matches.
  65745. + * Otherwise returns 0. */
  65746. +extern uint32_t dwc_cc_match_chid(dwc_cc_if_t *cc_if, uint8_t *chid);
  65747. +
  65748. +/** Find the connection context from the specified CDID.
  65749. + *
  65750. + * @param cc_if The cc_if structure.
  65751. + * @param cdid A pointer to the CDID data.
  65752. + * @return A non-zero identifier of the connection context if the CHID matches.
  65753. + * Otherwise returns 0. */
  65754. +extern uint32_t dwc_cc_match_cdid(dwc_cc_if_t *cc_if, uint8_t *cdid);
  65755. +
  65756. +/** Retrieve the CK from the specified connection context.
  65757. + *
  65758. + * @param cc_if The cc_if structure.
  65759. + * @param id The identifier of the connection context.
  65760. + * @return A pointer to the CK data. The memory does not need to be freed. */
  65761. +extern uint8_t *dwc_cc_ck(dwc_cc_if_t *cc_if, int32_t id);
  65762. +
  65763. +/** Retrieve the CHID from the specified connection context.
  65764. + *
  65765. + * @param cc_if The cc_if structure.
  65766. + * @param id The identifier of the connection context.
  65767. + * @return A pointer to the CHID data. The memory does not need to be freed. */
  65768. +extern uint8_t *dwc_cc_chid(dwc_cc_if_t *cc_if, int32_t id);
  65769. +
  65770. +/** Retrieve the CDID from the specified connection context.
  65771. + *
  65772. + * @param cc_if The cc_if structure.
  65773. + * @param id The identifier of the connection context.
  65774. + * @return A pointer to the CDID data. The memory does not need to be freed. */
  65775. +extern uint8_t *dwc_cc_cdid(dwc_cc_if_t *cc_if, int32_t id);
  65776. +
  65777. +extern uint8_t *dwc_cc_name(dwc_cc_if_t *cc_if, int32_t id, uint8_t *length);
  65778. +
  65779. +/** Checks a buffer for non-zero.
  65780. + * @param id A pointer to a 16 byte buffer.
  65781. + * @return true if the 16 byte value is non-zero. */
  65782. +static inline unsigned dwc_assoc_is_not_zero_id(uint8_t *id) {
  65783. + int i;
  65784. + for (i=0; i<16; i++) {
  65785. + if (id[i]) return 1;
  65786. + }
  65787. + return 0;
  65788. +}
  65789. +
  65790. +/** Checks a buffer for zero.
  65791. + * @param id A pointer to a 16 byte buffer.
  65792. + * @return true if the 16 byte value is zero. */
  65793. +static inline unsigned dwc_assoc_is_zero_id(uint8_t *id) {
  65794. + return !dwc_assoc_is_not_zero_id(id);
  65795. +}
  65796. +
  65797. +/** Prints an ASCII representation for the 16-byte chid, cdid, or ck, into
  65798. + * buffer. */
  65799. +static inline int dwc_print_id_string(char *buffer, uint8_t *id) {
  65800. + char *ptr = buffer;
  65801. + int i;
  65802. + for (i=0; i<16; i++) {
  65803. + ptr += DWC_SPRINTF(ptr, "%02x", id[i]);
  65804. + if (i < 15) {
  65805. + ptr += DWC_SPRINTF(ptr, " ");
  65806. + }
  65807. + }
  65808. + return ptr - buffer;
  65809. +}
  65810. +
  65811. +/** @} */
  65812. +
  65813. +#ifdef __cplusplus
  65814. +}
  65815. +#endif
  65816. +
  65817. +#endif /* _DWC_CC_H_ */
  65818. diff -Nur linux-3.18.8/drivers/usb/host/dwc_common_port/dwc_common_fbsd.c linux-rpi/drivers/usb/host/dwc_common_port/dwc_common_fbsd.c
  65819. --- linux-3.18.8/drivers/usb/host/dwc_common_port/dwc_common_fbsd.c 1970-01-01 01:00:00.000000000 +0100
  65820. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_common_fbsd.c 2015-03-05 14:40:16.553715806 +0100
  65821. @@ -0,0 +1,1308 @@
  65822. +#include "dwc_os.h"
  65823. +#include "dwc_list.h"
  65824. +
  65825. +#ifdef DWC_CCLIB
  65826. +# include "dwc_cc.h"
  65827. +#endif
  65828. +
  65829. +#ifdef DWC_CRYPTOLIB
  65830. +# include "dwc_modpow.h"
  65831. +# include "dwc_dh.h"
  65832. +# include "dwc_crypto.h"
  65833. +#endif
  65834. +
  65835. +#ifdef DWC_NOTIFYLIB
  65836. +# include "dwc_notifier.h"
  65837. +#endif
  65838. +
  65839. +/* OS-Level Implementations */
  65840. +
  65841. +/* This is the FreeBSD 7.0 kernel implementation of the DWC platform library. */
  65842. +
  65843. +
  65844. +/* MISC */
  65845. +
  65846. +void *DWC_MEMSET(void *dest, uint8_t byte, uint32_t size)
  65847. +{
  65848. + return memset(dest, byte, size);
  65849. +}
  65850. +
  65851. +void *DWC_MEMCPY(void *dest, void const *src, uint32_t size)
  65852. +{
  65853. + return memcpy(dest, src, size);
  65854. +}
  65855. +
  65856. +void *DWC_MEMMOVE(void *dest, void *src, uint32_t size)
  65857. +{
  65858. + bcopy(src, dest, size);
  65859. + return dest;
  65860. +}
  65861. +
  65862. +int DWC_MEMCMP(void *m1, void *m2, uint32_t size)
  65863. +{
  65864. + return memcmp(m1, m2, size);
  65865. +}
  65866. +
  65867. +int DWC_STRNCMP(void *s1, void *s2, uint32_t size)
  65868. +{
  65869. + return strncmp(s1, s2, size);
  65870. +}
  65871. +
  65872. +int DWC_STRCMP(void *s1, void *s2)
  65873. +{
  65874. + return strcmp(s1, s2);
  65875. +}
  65876. +
  65877. +int DWC_STRLEN(char const *str)
  65878. +{
  65879. + return strlen(str);
  65880. +}
  65881. +
  65882. +char *DWC_STRCPY(char *to, char const *from)
  65883. +{
  65884. + return strcpy(to, from);
  65885. +}
  65886. +
  65887. +char *DWC_STRDUP(char const *str)
  65888. +{
  65889. + int len = DWC_STRLEN(str) + 1;
  65890. + char *new = DWC_ALLOC_ATOMIC(len);
  65891. +
  65892. + if (!new) {
  65893. + return NULL;
  65894. + }
  65895. +
  65896. + DWC_MEMCPY(new, str, len);
  65897. + return new;
  65898. +}
  65899. +
  65900. +int DWC_ATOI(char *str, int32_t *value)
  65901. +{
  65902. + char *end = NULL;
  65903. +
  65904. + *value = strtol(str, &end, 0);
  65905. + if (*end == '\0') {
  65906. + return 0;
  65907. + }
  65908. +
  65909. + return -1;
  65910. +}
  65911. +
  65912. +int DWC_ATOUI(char *str, uint32_t *value)
  65913. +{
  65914. + char *end = NULL;
  65915. +
  65916. + *value = strtoul(str, &end, 0);
  65917. + if (*end == '\0') {
  65918. + return 0;
  65919. + }
  65920. +
  65921. + return -1;
  65922. +}
  65923. +
  65924. +
  65925. +#ifdef DWC_UTFLIB
  65926. +/* From usbstring.c */
  65927. +
  65928. +int DWC_UTF8_TO_UTF16LE(uint8_t const *s, uint16_t *cp, unsigned len)
  65929. +{
  65930. + int count = 0;
  65931. + u8 c;
  65932. + u16 uchar;
  65933. +
  65934. + /* this insists on correct encodings, though not minimal ones.
  65935. + * BUT it currently rejects legit 4-byte UTF-8 code points,
  65936. + * which need surrogate pairs. (Unicode 3.1 can use them.)
  65937. + */
  65938. + while (len != 0 && (c = (u8) *s++) != 0) {
  65939. + if (unlikely(c & 0x80)) {
  65940. + // 2-byte sequence:
  65941. + // 00000yyyyyxxxxxx = 110yyyyy 10xxxxxx
  65942. + if ((c & 0xe0) == 0xc0) {
  65943. + uchar = (c & 0x1f) << 6;
  65944. +
  65945. + c = (u8) *s++;
  65946. + if ((c & 0xc0) != 0xc0)
  65947. + goto fail;
  65948. + c &= 0x3f;
  65949. + uchar |= c;
  65950. +
  65951. + // 3-byte sequence (most CJKV characters):
  65952. + // zzzzyyyyyyxxxxxx = 1110zzzz 10yyyyyy 10xxxxxx
  65953. + } else if ((c & 0xf0) == 0xe0) {
  65954. + uchar = (c & 0x0f) << 12;
  65955. +
  65956. + c = (u8) *s++;
  65957. + if ((c & 0xc0) != 0xc0)
  65958. + goto fail;
  65959. + c &= 0x3f;
  65960. + uchar |= c << 6;
  65961. +
  65962. + c = (u8) *s++;
  65963. + if ((c & 0xc0) != 0xc0)
  65964. + goto fail;
  65965. + c &= 0x3f;
  65966. + uchar |= c;
  65967. +
  65968. + /* no bogus surrogates */
  65969. + if (0xd800 <= uchar && uchar <= 0xdfff)
  65970. + goto fail;
  65971. +
  65972. + // 4-byte sequence (surrogate pairs, currently rare):
  65973. + // 11101110wwwwzzzzyy + 110111yyyyxxxxxx
  65974. + // = 11110uuu 10uuzzzz 10yyyyyy 10xxxxxx
  65975. + // (uuuuu = wwww + 1)
  65976. + // FIXME accept the surrogate code points (only)
  65977. + } else
  65978. + goto fail;
  65979. + } else
  65980. + uchar = c;
  65981. + put_unaligned (cpu_to_le16 (uchar), cp++);
  65982. + count++;
  65983. + len--;
  65984. + }
  65985. + return count;
  65986. +fail:
  65987. + return -1;
  65988. +}
  65989. +
  65990. +#endif /* DWC_UTFLIB */
  65991. +
  65992. +
  65993. +/* dwc_debug.h */
  65994. +
  65995. +dwc_bool_t DWC_IN_IRQ(void)
  65996. +{
  65997. +// return in_irq();
  65998. + return 0;
  65999. +}
  66000. +
  66001. +dwc_bool_t DWC_IN_BH(void)
  66002. +{
  66003. +// return in_softirq();
  66004. + return 0;
  66005. +}
  66006. +
  66007. +void DWC_VPRINTF(char *format, va_list args)
  66008. +{
  66009. + vprintf(format, args);
  66010. +}
  66011. +
  66012. +int DWC_VSNPRINTF(char *str, int size, char *format, va_list args)
  66013. +{
  66014. + return vsnprintf(str, size, format, args);
  66015. +}
  66016. +
  66017. +void DWC_PRINTF(char *format, ...)
  66018. +{
  66019. + va_list args;
  66020. +
  66021. + va_start(args, format);
  66022. + DWC_VPRINTF(format, args);
  66023. + va_end(args);
  66024. +}
  66025. +
  66026. +int DWC_SPRINTF(char *buffer, char *format, ...)
  66027. +{
  66028. + int retval;
  66029. + va_list args;
  66030. +
  66031. + va_start(args, format);
  66032. + retval = vsprintf(buffer, format, args);
  66033. + va_end(args);
  66034. + return retval;
  66035. +}
  66036. +
  66037. +int DWC_SNPRINTF(char *buffer, int size, char *format, ...)
  66038. +{
  66039. + int retval;
  66040. + va_list args;
  66041. +
  66042. + va_start(args, format);
  66043. + retval = vsnprintf(buffer, size, format, args);
  66044. + va_end(args);
  66045. + return retval;
  66046. +}
  66047. +
  66048. +void __DWC_WARN(char *format, ...)
  66049. +{
  66050. + va_list args;
  66051. +
  66052. + va_start(args, format);
  66053. + DWC_VPRINTF(format, args);
  66054. + va_end(args);
  66055. +}
  66056. +
  66057. +void __DWC_ERROR(char *format, ...)
  66058. +{
  66059. + va_list args;
  66060. +
  66061. + va_start(args, format);
  66062. + DWC_VPRINTF(format, args);
  66063. + va_end(args);
  66064. +}
  66065. +
  66066. +void DWC_EXCEPTION(char *format, ...)
  66067. +{
  66068. + va_list args;
  66069. +
  66070. + va_start(args, format);
  66071. + DWC_VPRINTF(format, args);
  66072. + va_end(args);
  66073. +// BUG_ON(1); ???
  66074. +}
  66075. +
  66076. +#ifdef DEBUG
  66077. +void __DWC_DEBUG(char *format, ...)
  66078. +{
  66079. + va_list args;
  66080. +
  66081. + va_start(args, format);
  66082. + DWC_VPRINTF(format, args);
  66083. + va_end(args);
  66084. +}
  66085. +#endif
  66086. +
  66087. +
  66088. +/* dwc_mem.h */
  66089. +
  66090. +#if 0
  66091. +dwc_pool_t *DWC_DMA_POOL_CREATE(uint32_t size,
  66092. + uint32_t align,
  66093. + uint32_t alloc)
  66094. +{
  66095. + struct dma_pool *pool = dma_pool_create("Pool", NULL,
  66096. + size, align, alloc);
  66097. + return (dwc_pool_t *)pool;
  66098. +}
  66099. +
  66100. +void DWC_DMA_POOL_DESTROY(dwc_pool_t *pool)
  66101. +{
  66102. + dma_pool_destroy((struct dma_pool *)pool);
  66103. +}
  66104. +
  66105. +void *DWC_DMA_POOL_ALLOC(dwc_pool_t *pool, uint64_t *dma_addr)
  66106. +{
  66107. +// return dma_pool_alloc((struct dma_pool *)pool, GFP_KERNEL, dma_addr);
  66108. + return dma_pool_alloc((struct dma_pool *)pool, M_WAITOK, dma_addr);
  66109. +}
  66110. +
  66111. +void *DWC_DMA_POOL_ZALLOC(dwc_pool_t *pool, uint64_t *dma_addr)
  66112. +{
  66113. + void *vaddr = DWC_DMA_POOL_ALLOC(pool, dma_addr);
  66114. + memset(..);
  66115. +}
  66116. +
  66117. +void DWC_DMA_POOL_FREE(dwc_pool_t *pool, void *vaddr, void *daddr)
  66118. +{
  66119. + dma_pool_free(pool, vaddr, daddr);
  66120. +}
  66121. +#endif
  66122. +
  66123. +static void dmamap_cb(void *arg, bus_dma_segment_t *segs, int nseg, int error)
  66124. +{
  66125. + if (error)
  66126. + return;
  66127. + *(bus_addr_t *)arg = segs[0].ds_addr;
  66128. +}
  66129. +
  66130. +void *__DWC_DMA_ALLOC(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr)
  66131. +{
  66132. + dwc_dmactx_t *dma = (dwc_dmactx_t *)dma_ctx;
  66133. + int error;
  66134. +
  66135. + error = bus_dma_tag_create(
  66136. +#if __FreeBSD_version >= 700000
  66137. + bus_get_dma_tag(dma->dev), /* parent */
  66138. +#else
  66139. + NULL, /* parent */
  66140. +#endif
  66141. + 4, 0, /* alignment, bounds */
  66142. + BUS_SPACE_MAXADDR_32BIT, /* lowaddr */
  66143. + BUS_SPACE_MAXADDR, /* highaddr */
  66144. + NULL, NULL, /* filter, filterarg */
  66145. + size, /* maxsize */
  66146. + 1, /* nsegments */
  66147. + size, /* maxsegsize */
  66148. + 0, /* flags */
  66149. + NULL, /* lockfunc */
  66150. + NULL, /* lockarg */
  66151. + &dma->dma_tag);
  66152. + if (error) {
  66153. + device_printf(dma->dev, "%s: bus_dma_tag_create failed: %d\n",
  66154. + __func__, error);
  66155. + goto fail_0;
  66156. + }
  66157. +
  66158. + error = bus_dmamem_alloc(dma->dma_tag, &dma->dma_vaddr,
  66159. + BUS_DMA_NOWAIT | BUS_DMA_COHERENT, &dma->dma_map);
  66160. + if (error) {
  66161. + device_printf(dma->dev, "%s: bus_dmamem_alloc(%ju) failed: %d\n",
  66162. + __func__, (uintmax_t)size, error);
  66163. + goto fail_1;
  66164. + }
  66165. +
  66166. + dma->dma_paddr = 0;
  66167. + error = bus_dmamap_load(dma->dma_tag, dma->dma_map, dma->dma_vaddr, size,
  66168. + dmamap_cb, &dma->dma_paddr, BUS_DMA_NOWAIT);
  66169. + if (error || dma->dma_paddr == 0) {
  66170. + device_printf(dma->dev, "%s: bus_dmamap_load failed: %d\n",
  66171. + __func__, error);
  66172. + goto fail_2;
  66173. + }
  66174. +
  66175. + *dma_addr = dma->dma_paddr;
  66176. + return dma->dma_vaddr;
  66177. +
  66178. +fail_2:
  66179. + bus_dmamap_unload(dma->dma_tag, dma->dma_map);
  66180. +fail_1:
  66181. + bus_dmamem_free(dma->dma_tag, dma->dma_vaddr, dma->dma_map);
  66182. + bus_dma_tag_destroy(dma->dma_tag);
  66183. +fail_0:
  66184. + dma->dma_map = NULL;
  66185. + dma->dma_tag = NULL;
  66186. +
  66187. + return NULL;
  66188. +}
  66189. +
  66190. +void __DWC_DMA_FREE(void *dma_ctx, uint32_t size, void *virt_addr, dwc_dma_t dma_addr)
  66191. +{
  66192. + dwc_dmactx_t *dma = (dwc_dmactx_t *)dma_ctx;
  66193. +
  66194. + if (dma->dma_tag == NULL)
  66195. + return;
  66196. + if (dma->dma_map != NULL) {
  66197. + bus_dmamap_sync(dma->dma_tag, dma->dma_map,
  66198. + BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
  66199. + bus_dmamap_unload(dma->dma_tag, dma->dma_map);
  66200. + bus_dmamem_free(dma->dma_tag, dma->dma_vaddr, dma->dma_map);
  66201. + dma->dma_map = NULL;
  66202. + }
  66203. +
  66204. + bus_dma_tag_destroy(dma->dma_tag);
  66205. + dma->dma_tag = NULL;
  66206. +}
  66207. +
  66208. +void *__DWC_ALLOC(void *mem_ctx, uint32_t size)
  66209. +{
  66210. + return malloc(size, M_DEVBUF, M_WAITOK | M_ZERO);
  66211. +}
  66212. +
  66213. +void *__DWC_ALLOC_ATOMIC(void *mem_ctx, uint32_t size)
  66214. +{
  66215. + return malloc(size, M_DEVBUF, M_NOWAIT | M_ZERO);
  66216. +}
  66217. +
  66218. +void __DWC_FREE(void *mem_ctx, void *addr)
  66219. +{
  66220. + free(addr, M_DEVBUF);
  66221. +}
  66222. +
  66223. +
  66224. +#ifdef DWC_CRYPTOLIB
  66225. +/* dwc_crypto.h */
  66226. +
  66227. +void DWC_RANDOM_BYTES(uint8_t *buffer, uint32_t length)
  66228. +{
  66229. + get_random_bytes(buffer, length);
  66230. +}
  66231. +
  66232. +int DWC_AES_CBC(uint8_t *message, uint32_t messagelen, uint8_t *key, uint32_t keylen, uint8_t iv[16], uint8_t *out)
  66233. +{
  66234. + struct crypto_blkcipher *tfm;
  66235. + struct blkcipher_desc desc;
  66236. + struct scatterlist sgd;
  66237. + struct scatterlist sgs;
  66238. +
  66239. + tfm = crypto_alloc_blkcipher("cbc(aes)", 0, CRYPTO_ALG_ASYNC);
  66240. + if (tfm == NULL) {
  66241. + printk("failed to load transform for aes CBC\n");
  66242. + return -1;
  66243. + }
  66244. +
  66245. + crypto_blkcipher_setkey(tfm, key, keylen);
  66246. + crypto_blkcipher_set_iv(tfm, iv, 16);
  66247. +
  66248. + sg_init_one(&sgd, out, messagelen);
  66249. + sg_init_one(&sgs, message, messagelen);
  66250. +
  66251. + desc.tfm = tfm;
  66252. + desc.flags = 0;
  66253. +
  66254. + if (crypto_blkcipher_encrypt(&desc, &sgd, &sgs, messagelen)) {
  66255. + crypto_free_blkcipher(tfm);
  66256. + DWC_ERROR("AES CBC encryption failed");
  66257. + return -1;
  66258. + }
  66259. +
  66260. + crypto_free_blkcipher(tfm);
  66261. + return 0;
  66262. +}
  66263. +
  66264. +int DWC_SHA256(uint8_t *message, uint32_t len, uint8_t *out)
  66265. +{
  66266. + struct crypto_hash *tfm;
  66267. + struct hash_desc desc;
  66268. + struct scatterlist sg;
  66269. +
  66270. + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
  66271. + if (IS_ERR(tfm)) {
  66272. + DWC_ERROR("Failed to load transform for sha256: %ld", PTR_ERR(tfm));
  66273. + return 0;
  66274. + }
  66275. + desc.tfm = tfm;
  66276. + desc.flags = 0;
  66277. +
  66278. + sg_init_one(&sg, message, len);
  66279. + crypto_hash_digest(&desc, &sg, len, out);
  66280. + crypto_free_hash(tfm);
  66281. +
  66282. + return 1;
  66283. +}
  66284. +
  66285. +int DWC_HMAC_SHA256(uint8_t *message, uint32_t messagelen,
  66286. + uint8_t *key, uint32_t keylen, uint8_t *out)
  66287. +{
  66288. + struct crypto_hash *tfm;
  66289. + struct hash_desc desc;
  66290. + struct scatterlist sg;
  66291. +
  66292. + tfm = crypto_alloc_hash("hmac(sha256)", 0, CRYPTO_ALG_ASYNC);
  66293. + if (IS_ERR(tfm)) {
  66294. + DWC_ERROR("Failed to load transform for hmac(sha256): %ld", PTR_ERR(tfm));
  66295. + return 0;
  66296. + }
  66297. + desc.tfm = tfm;
  66298. + desc.flags = 0;
  66299. +
  66300. + sg_init_one(&sg, message, messagelen);
  66301. + crypto_hash_setkey(tfm, key, keylen);
  66302. + crypto_hash_digest(&desc, &sg, messagelen, out);
  66303. + crypto_free_hash(tfm);
  66304. +
  66305. + return 1;
  66306. +}
  66307. +
  66308. +#endif /* DWC_CRYPTOLIB */
  66309. +
  66310. +
  66311. +/* Byte Ordering Conversions */
  66312. +
  66313. +uint32_t DWC_CPU_TO_LE32(uint32_t *p)
  66314. +{
  66315. +#ifdef __LITTLE_ENDIAN
  66316. + return *p;
  66317. +#else
  66318. + uint8_t *u_p = (uint8_t *)p;
  66319. +
  66320. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  66321. +#endif
  66322. +}
  66323. +
  66324. +uint32_t DWC_CPU_TO_BE32(uint32_t *p)
  66325. +{
  66326. +#ifdef __BIG_ENDIAN
  66327. + return *p;
  66328. +#else
  66329. + uint8_t *u_p = (uint8_t *)p;
  66330. +
  66331. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  66332. +#endif
  66333. +}
  66334. +
  66335. +uint32_t DWC_LE32_TO_CPU(uint32_t *p)
  66336. +{
  66337. +#ifdef __LITTLE_ENDIAN
  66338. + return *p;
  66339. +#else
  66340. + uint8_t *u_p = (uint8_t *)p;
  66341. +
  66342. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  66343. +#endif
  66344. +}
  66345. +
  66346. +uint32_t DWC_BE32_TO_CPU(uint32_t *p)
  66347. +{
  66348. +#ifdef __BIG_ENDIAN
  66349. + return *p;
  66350. +#else
  66351. + uint8_t *u_p = (uint8_t *)p;
  66352. +
  66353. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  66354. +#endif
  66355. +}
  66356. +
  66357. +uint16_t DWC_CPU_TO_LE16(uint16_t *p)
  66358. +{
  66359. +#ifdef __LITTLE_ENDIAN
  66360. + return *p;
  66361. +#else
  66362. + uint8_t *u_p = (uint8_t *)p;
  66363. + return (u_p[1] | (u_p[0] << 8));
  66364. +#endif
  66365. +}
  66366. +
  66367. +uint16_t DWC_CPU_TO_BE16(uint16_t *p)
  66368. +{
  66369. +#ifdef __BIG_ENDIAN
  66370. + return *p;
  66371. +#else
  66372. + uint8_t *u_p = (uint8_t *)p;
  66373. + return (u_p[1] | (u_p[0] << 8));
  66374. +#endif
  66375. +}
  66376. +
  66377. +uint16_t DWC_LE16_TO_CPU(uint16_t *p)
  66378. +{
  66379. +#ifdef __LITTLE_ENDIAN
  66380. + return *p;
  66381. +#else
  66382. + uint8_t *u_p = (uint8_t *)p;
  66383. + return (u_p[1] | (u_p[0] << 8));
  66384. +#endif
  66385. +}
  66386. +
  66387. +uint16_t DWC_BE16_TO_CPU(uint16_t *p)
  66388. +{
  66389. +#ifdef __BIG_ENDIAN
  66390. + return *p;
  66391. +#else
  66392. + uint8_t *u_p = (uint8_t *)p;
  66393. + return (u_p[1] | (u_p[0] << 8));
  66394. +#endif
  66395. +}
  66396. +
  66397. +
  66398. +/* Registers */
  66399. +
  66400. +uint32_t DWC_READ_REG32(void *io_ctx, uint32_t volatile *reg)
  66401. +{
  66402. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  66403. + bus_size_t ior = (bus_size_t)reg;
  66404. +
  66405. + return bus_space_read_4(io->iot, io->ioh, ior);
  66406. +}
  66407. +
  66408. +#if 0
  66409. +uint64_t DWC_READ_REG64(void *io_ctx, uint64_t volatile *reg)
  66410. +{
  66411. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  66412. + bus_size_t ior = (bus_size_t)reg;
  66413. +
  66414. + return bus_space_read_8(io->iot, io->ioh, ior);
  66415. +}
  66416. +#endif
  66417. +
  66418. +void DWC_WRITE_REG32(void *io_ctx, uint32_t volatile *reg, uint32_t value)
  66419. +{
  66420. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  66421. + bus_size_t ior = (bus_size_t)reg;
  66422. +
  66423. + bus_space_write_4(io->iot, io->ioh, ior, value);
  66424. +}
  66425. +
  66426. +#if 0
  66427. +void DWC_WRITE_REG64(void *io_ctx, uint64_t volatile *reg, uint64_t value)
  66428. +{
  66429. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  66430. + bus_size_t ior = (bus_size_t)reg;
  66431. +
  66432. + bus_space_write_8(io->iot, io->ioh, ior, value);
  66433. +}
  66434. +#endif
  66435. +
  66436. +void DWC_MODIFY_REG32(void *io_ctx, uint32_t volatile *reg, uint32_t clear_mask,
  66437. + uint32_t set_mask)
  66438. +{
  66439. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  66440. + bus_size_t ior = (bus_size_t)reg;
  66441. +
  66442. + bus_space_write_4(io->iot, io->ioh, ior,
  66443. + (bus_space_read_4(io->iot, io->ioh, ior) &
  66444. + ~clear_mask) | set_mask);
  66445. +}
  66446. +
  66447. +#if 0
  66448. +void DWC_MODIFY_REG64(void *io_ctx, uint64_t volatile *reg, uint64_t clear_mask,
  66449. + uint64_t set_mask)
  66450. +{
  66451. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  66452. + bus_size_t ior = (bus_size_t)reg;
  66453. +
  66454. + bus_space_write_8(io->iot, io->ioh, ior,
  66455. + (bus_space_read_8(io->iot, io->ioh, ior) &
  66456. + ~clear_mask) | set_mask);
  66457. +}
  66458. +#endif
  66459. +
  66460. +
  66461. +/* Locking */
  66462. +
  66463. +dwc_spinlock_t *DWC_SPINLOCK_ALLOC(void)
  66464. +{
  66465. + struct mtx *sl = DWC_ALLOC(sizeof(*sl));
  66466. +
  66467. + if (!sl) {
  66468. + DWC_ERROR("Cannot allocate memory for spinlock");
  66469. + return NULL;
  66470. + }
  66471. +
  66472. + mtx_init(sl, "dw3spn", NULL, MTX_SPIN);
  66473. + return (dwc_spinlock_t *)sl;
  66474. +}
  66475. +
  66476. +void DWC_SPINLOCK_FREE(dwc_spinlock_t *lock)
  66477. +{
  66478. + struct mtx *sl = (struct mtx *)lock;
  66479. +
  66480. + mtx_destroy(sl);
  66481. + DWC_FREE(sl);
  66482. +}
  66483. +
  66484. +void DWC_SPINLOCK(dwc_spinlock_t *lock)
  66485. +{
  66486. + mtx_lock_spin((struct mtx *)lock); // ???
  66487. +}
  66488. +
  66489. +void DWC_SPINUNLOCK(dwc_spinlock_t *lock)
  66490. +{
  66491. + mtx_unlock_spin((struct mtx *)lock); // ???
  66492. +}
  66493. +
  66494. +void DWC_SPINLOCK_IRQSAVE(dwc_spinlock_t *lock, dwc_irqflags_t *flags)
  66495. +{
  66496. + mtx_lock_spin((struct mtx *)lock);
  66497. +}
  66498. +
  66499. +void DWC_SPINUNLOCK_IRQRESTORE(dwc_spinlock_t *lock, dwc_irqflags_t flags)
  66500. +{
  66501. + mtx_unlock_spin((struct mtx *)lock);
  66502. +}
  66503. +
  66504. +dwc_mutex_t *DWC_MUTEX_ALLOC(void)
  66505. +{
  66506. + struct mtx *m;
  66507. + dwc_mutex_t *mutex = (dwc_mutex_t *)DWC_ALLOC(sizeof(struct mtx));
  66508. +
  66509. + if (!mutex) {
  66510. + DWC_ERROR("Cannot allocate memory for mutex");
  66511. + return NULL;
  66512. + }
  66513. +
  66514. + m = (struct mtx *)mutex;
  66515. + mtx_init(m, "dw3mtx", NULL, MTX_DEF);
  66516. + return mutex;
  66517. +}
  66518. +
  66519. +#if (defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES))
  66520. +#else
  66521. +void DWC_MUTEX_FREE(dwc_mutex_t *mutex)
  66522. +{
  66523. + mtx_destroy((struct mtx *)mutex);
  66524. + DWC_FREE(mutex);
  66525. +}
  66526. +#endif
  66527. +
  66528. +void DWC_MUTEX_LOCK(dwc_mutex_t *mutex)
  66529. +{
  66530. + struct mtx *m = (struct mtx *)mutex;
  66531. +
  66532. + mtx_lock(m);
  66533. +}
  66534. +
  66535. +int DWC_MUTEX_TRYLOCK(dwc_mutex_t *mutex)
  66536. +{
  66537. + struct mtx *m = (struct mtx *)mutex;
  66538. +
  66539. + return mtx_trylock(m);
  66540. +}
  66541. +
  66542. +void DWC_MUTEX_UNLOCK(dwc_mutex_t *mutex)
  66543. +{
  66544. + struct mtx *m = (struct mtx *)mutex;
  66545. +
  66546. + mtx_unlock(m);
  66547. +}
  66548. +
  66549. +
  66550. +/* Timing */
  66551. +
  66552. +void DWC_UDELAY(uint32_t usecs)
  66553. +{
  66554. + DELAY(usecs);
  66555. +}
  66556. +
  66557. +void DWC_MDELAY(uint32_t msecs)
  66558. +{
  66559. + do {
  66560. + DELAY(1000);
  66561. + } while (--msecs);
  66562. +}
  66563. +
  66564. +void DWC_MSLEEP(uint32_t msecs)
  66565. +{
  66566. + struct timeval tv;
  66567. +
  66568. + tv.tv_sec = msecs / 1000;
  66569. + tv.tv_usec = (msecs - tv.tv_sec * 1000) * 1000;
  66570. + pause("dw3slp", tvtohz(&tv));
  66571. +}
  66572. +
  66573. +uint32_t DWC_TIME(void)
  66574. +{
  66575. + struct timeval tv;
  66576. +
  66577. + microuptime(&tv); // or getmicrouptime? (less precise, but faster)
  66578. + return tv.tv_sec * 1000 + tv.tv_usec / 1000;
  66579. +}
  66580. +
  66581. +
  66582. +/* Timers */
  66583. +
  66584. +struct dwc_timer {
  66585. + struct callout t;
  66586. + char *name;
  66587. + dwc_spinlock_t *lock;
  66588. + dwc_timer_callback_t cb;
  66589. + void *data;
  66590. +};
  66591. +
  66592. +dwc_timer_t *DWC_TIMER_ALLOC(char *name, dwc_timer_callback_t cb, void *data)
  66593. +{
  66594. + dwc_timer_t *t = DWC_ALLOC(sizeof(*t));
  66595. +
  66596. + if (!t) {
  66597. + DWC_ERROR("Cannot allocate memory for timer");
  66598. + return NULL;
  66599. + }
  66600. +
  66601. + callout_init(&t->t, 1);
  66602. +
  66603. + t->name = DWC_STRDUP(name);
  66604. + if (!t->name) {
  66605. + DWC_ERROR("Cannot allocate memory for timer->name");
  66606. + goto no_name;
  66607. + }
  66608. +
  66609. + t->lock = DWC_SPINLOCK_ALLOC();
  66610. + if (!t->lock) {
  66611. + DWC_ERROR("Cannot allocate memory for lock");
  66612. + goto no_lock;
  66613. + }
  66614. +
  66615. + t->cb = cb;
  66616. + t->data = data;
  66617. +
  66618. + return t;
  66619. +
  66620. + no_lock:
  66621. + DWC_FREE(t->name);
  66622. + no_name:
  66623. + DWC_FREE(t);
  66624. +
  66625. + return NULL;
  66626. +}
  66627. +
  66628. +void DWC_TIMER_FREE(dwc_timer_t *timer)
  66629. +{
  66630. + callout_stop(&timer->t);
  66631. + DWC_SPINLOCK_FREE(timer->lock);
  66632. + DWC_FREE(timer->name);
  66633. + DWC_FREE(timer);
  66634. +}
  66635. +
  66636. +void DWC_TIMER_SCHEDULE(dwc_timer_t *timer, uint32_t time)
  66637. +{
  66638. + struct timeval tv;
  66639. +
  66640. + tv.tv_sec = time / 1000;
  66641. + tv.tv_usec = (time - tv.tv_sec * 1000) * 1000;
  66642. + callout_reset(&timer->t, tvtohz(&tv), timer->cb, timer->data);
  66643. +}
  66644. +
  66645. +void DWC_TIMER_CANCEL(dwc_timer_t *timer)
  66646. +{
  66647. + callout_stop(&timer->t);
  66648. +}
  66649. +
  66650. +
  66651. +/* Wait Queues */
  66652. +
  66653. +struct dwc_waitq {
  66654. + struct mtx lock;
  66655. + int abort;
  66656. +};
  66657. +
  66658. +dwc_waitq_t *DWC_WAITQ_ALLOC(void)
  66659. +{
  66660. + dwc_waitq_t *wq = DWC_ALLOC(sizeof(*wq));
  66661. +
  66662. + if (!wq) {
  66663. + DWC_ERROR("Cannot allocate memory for waitqueue");
  66664. + return NULL;
  66665. + }
  66666. +
  66667. + mtx_init(&wq->lock, "dw3wtq", NULL, MTX_DEF);
  66668. + wq->abort = 0;
  66669. +
  66670. + return wq;
  66671. +}
  66672. +
  66673. +void DWC_WAITQ_FREE(dwc_waitq_t *wq)
  66674. +{
  66675. + mtx_destroy(&wq->lock);
  66676. + DWC_FREE(wq);
  66677. +}
  66678. +
  66679. +int32_t DWC_WAITQ_WAIT(dwc_waitq_t *wq, dwc_waitq_condition_t cond, void *data)
  66680. +{
  66681. +// intrmask_t ipl;
  66682. + int result = 0;
  66683. +
  66684. + mtx_lock(&wq->lock);
  66685. +// ipl = splbio();
  66686. +
  66687. + /* Skip the sleep if already aborted or triggered */
  66688. + if (!wq->abort && !cond(data)) {
  66689. +// splx(ipl);
  66690. + result = msleep(wq, &wq->lock, PCATCH, "dw3wat", 0); // infinite timeout
  66691. +// ipl = splbio();
  66692. + }
  66693. +
  66694. + if (result == ERESTART) { // signaled - restart
  66695. + result = -DWC_E_RESTART;
  66696. +
  66697. + } else if (result == EINTR) { // signaled - interrupt
  66698. + result = -DWC_E_ABORT;
  66699. +
  66700. + } else if (wq->abort) {
  66701. + result = -DWC_E_ABORT;
  66702. +
  66703. + } else {
  66704. + result = 0;
  66705. + }
  66706. +
  66707. + wq->abort = 0;
  66708. +// splx(ipl);
  66709. + mtx_unlock(&wq->lock);
  66710. + return result;
  66711. +}
  66712. +
  66713. +int32_t DWC_WAITQ_WAIT_TIMEOUT(dwc_waitq_t *wq, dwc_waitq_condition_t cond,
  66714. + void *data, int32_t msecs)
  66715. +{
  66716. + struct timeval tv, tv1, tv2;
  66717. +// intrmask_t ipl;
  66718. + int result = 0;
  66719. +
  66720. + tv.tv_sec = msecs / 1000;
  66721. + tv.tv_usec = (msecs - tv.tv_sec * 1000) * 1000;
  66722. +
  66723. + mtx_lock(&wq->lock);
  66724. +// ipl = splbio();
  66725. +
  66726. + /* Skip the sleep if already aborted or triggered */
  66727. + if (!wq->abort && !cond(data)) {
  66728. +// splx(ipl);
  66729. + getmicrouptime(&tv1);
  66730. + result = msleep(wq, &wq->lock, PCATCH, "dw3wto", tvtohz(&tv));
  66731. + getmicrouptime(&tv2);
  66732. +// ipl = splbio();
  66733. + }
  66734. +
  66735. + if (result == 0) { // awoken
  66736. + if (wq->abort) {
  66737. + result = -DWC_E_ABORT;
  66738. + } else {
  66739. + tv2.tv_usec -= tv1.tv_usec;
  66740. + if (tv2.tv_usec < 0) {
  66741. + tv2.tv_usec += 1000000;
  66742. + tv2.tv_sec--;
  66743. + }
  66744. +
  66745. + tv2.tv_sec -= tv1.tv_sec;
  66746. + result = tv2.tv_sec * 1000 + tv2.tv_usec / 1000;
  66747. + result = msecs - result;
  66748. + if (result <= 0)
  66749. + result = 1;
  66750. + }
  66751. + } else if (result == ERESTART) { // signaled - restart
  66752. + result = -DWC_E_RESTART;
  66753. +
  66754. + } else if (result == EINTR) { // signaled - interrupt
  66755. + result = -DWC_E_ABORT;
  66756. +
  66757. + } else { // timed out
  66758. + result = -DWC_E_TIMEOUT;
  66759. + }
  66760. +
  66761. + wq->abort = 0;
  66762. +// splx(ipl);
  66763. + mtx_unlock(&wq->lock);
  66764. + return result;
  66765. +}
  66766. +
  66767. +void DWC_WAITQ_TRIGGER(dwc_waitq_t *wq)
  66768. +{
  66769. + wakeup(wq);
  66770. +}
  66771. +
  66772. +void DWC_WAITQ_ABORT(dwc_waitq_t *wq)
  66773. +{
  66774. +// intrmask_t ipl;
  66775. +
  66776. + mtx_lock(&wq->lock);
  66777. +// ipl = splbio();
  66778. + wq->abort = 1;
  66779. + wakeup(wq);
  66780. +// splx(ipl);
  66781. + mtx_unlock(&wq->lock);
  66782. +}
  66783. +
  66784. +
  66785. +/* Threading */
  66786. +
  66787. +struct dwc_thread {
  66788. + struct proc *proc;
  66789. + int abort;
  66790. +};
  66791. +
  66792. +dwc_thread_t *DWC_THREAD_RUN(dwc_thread_function_t func, char *name, void *data)
  66793. +{
  66794. + int retval;
  66795. + dwc_thread_t *thread = DWC_ALLOC(sizeof(*thread));
  66796. +
  66797. + if (!thread) {
  66798. + return NULL;
  66799. + }
  66800. +
  66801. + thread->abort = 0;
  66802. + retval = kthread_create((void (*)(void *))func, data, &thread->proc,
  66803. + RFPROC | RFNOWAIT, 0, "%s", name);
  66804. + if (retval) {
  66805. + DWC_FREE(thread);
  66806. + return NULL;
  66807. + }
  66808. +
  66809. + return thread;
  66810. +}
  66811. +
  66812. +int DWC_THREAD_STOP(dwc_thread_t *thread)
  66813. +{
  66814. + int retval;
  66815. +
  66816. + thread->abort = 1;
  66817. + retval = tsleep(&thread->abort, 0, "dw3stp", 60 * hz);
  66818. +
  66819. + if (retval == 0) {
  66820. + /* DWC_THREAD_EXIT() will free the thread struct */
  66821. + return 0;
  66822. + }
  66823. +
  66824. + /* NOTE: We leak the thread struct if thread doesn't die */
  66825. +
  66826. + if (retval == EWOULDBLOCK) {
  66827. + return -DWC_E_TIMEOUT;
  66828. + }
  66829. +
  66830. + return -DWC_E_UNKNOWN;
  66831. +}
  66832. +
  66833. +dwc_bool_t DWC_THREAD_SHOULD_STOP(dwc_thread_t *thread)
  66834. +{
  66835. + return thread->abort;
  66836. +}
  66837. +
  66838. +void DWC_THREAD_EXIT(dwc_thread_t *thread)
  66839. +{
  66840. + wakeup(&thread->abort);
  66841. + DWC_FREE(thread);
  66842. + kthread_exit(0);
  66843. +}
  66844. +
  66845. +
  66846. +/* tasklets
  66847. + - Runs in interrupt context (cannot sleep)
  66848. + - Each tasklet runs on a single CPU [ How can we ensure this on FreeBSD? Does it matter? ]
  66849. + - Different tasklets can be running simultaneously on different CPUs [ shouldn't matter ]
  66850. + */
  66851. +struct dwc_tasklet {
  66852. + struct task t;
  66853. + dwc_tasklet_callback_t cb;
  66854. + void *data;
  66855. +};
  66856. +
  66857. +static void tasklet_callback(void *data, int pending) // what to do with pending ???
  66858. +{
  66859. + dwc_tasklet_t *task = (dwc_tasklet_t *)data;
  66860. +
  66861. + task->cb(task->data);
  66862. +}
  66863. +
  66864. +dwc_tasklet_t *DWC_TASK_ALLOC(char *name, dwc_tasklet_callback_t cb, void *data)
  66865. +{
  66866. + dwc_tasklet_t *task = DWC_ALLOC(sizeof(*task));
  66867. +
  66868. + if (task) {
  66869. + task->cb = cb;
  66870. + task->data = data;
  66871. + TASK_INIT(&task->t, 0, tasklet_callback, task);
  66872. + } else {
  66873. + DWC_ERROR("Cannot allocate memory for tasklet");
  66874. + }
  66875. +
  66876. + return task;
  66877. +}
  66878. +
  66879. +void DWC_TASK_FREE(dwc_tasklet_t *task)
  66880. +{
  66881. + taskqueue_drain(taskqueue_fast, &task->t); // ???
  66882. + DWC_FREE(task);
  66883. +}
  66884. +
  66885. +void DWC_TASK_SCHEDULE(dwc_tasklet_t *task)
  66886. +{
  66887. + /* Uses predefined system queue */
  66888. + taskqueue_enqueue_fast(taskqueue_fast, &task->t);
  66889. +}
  66890. +
  66891. +
  66892. +/* workqueues
  66893. + - Runs in process context (can sleep)
  66894. + */
  66895. +typedef struct work_container {
  66896. + dwc_work_callback_t cb;
  66897. + void *data;
  66898. + dwc_workq_t *wq;
  66899. + char *name;
  66900. + int hz;
  66901. +
  66902. +#ifdef DEBUG
  66903. + DWC_CIRCLEQ_ENTRY(work_container) entry;
  66904. +#endif
  66905. + struct task task;
  66906. +} work_container_t;
  66907. +
  66908. +#ifdef DEBUG
  66909. +DWC_CIRCLEQ_HEAD(work_container_queue, work_container);
  66910. +#endif
  66911. +
  66912. +struct dwc_workq {
  66913. + struct taskqueue *taskq;
  66914. + dwc_spinlock_t *lock;
  66915. + dwc_waitq_t *waitq;
  66916. + int pending;
  66917. +
  66918. +#ifdef DEBUG
  66919. + struct work_container_queue entries;
  66920. +#endif
  66921. +};
  66922. +
  66923. +static void do_work(void *data, int pending) // what to do with pending ???
  66924. +{
  66925. + work_container_t *container = (work_container_t *)data;
  66926. + dwc_workq_t *wq = container->wq;
  66927. + dwc_irqflags_t flags;
  66928. +
  66929. + if (container->hz) {
  66930. + pause("dw3wrk", container->hz);
  66931. + }
  66932. +
  66933. + container->cb(container->data);
  66934. + DWC_DEBUG("Work done: %s, container=%p", container->name, container);
  66935. +
  66936. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  66937. +
  66938. +#ifdef DEBUG
  66939. + DWC_CIRCLEQ_REMOVE(&wq->entries, container, entry);
  66940. +#endif
  66941. + if (container->name)
  66942. + DWC_FREE(container->name);
  66943. + DWC_FREE(container);
  66944. + wq->pending--;
  66945. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  66946. + DWC_WAITQ_TRIGGER(wq->waitq);
  66947. +}
  66948. +
  66949. +static int work_done(void *data)
  66950. +{
  66951. + dwc_workq_t *workq = (dwc_workq_t *)data;
  66952. +
  66953. + return workq->pending == 0;
  66954. +}
  66955. +
  66956. +int DWC_WORKQ_WAIT_WORK_DONE(dwc_workq_t *workq, int timeout)
  66957. +{
  66958. + return DWC_WAITQ_WAIT_TIMEOUT(workq->waitq, work_done, workq, timeout);
  66959. +}
  66960. +
  66961. +dwc_workq_t *DWC_WORKQ_ALLOC(char *name)
  66962. +{
  66963. + dwc_workq_t *wq = DWC_ALLOC(sizeof(*wq));
  66964. +
  66965. + if (!wq) {
  66966. + DWC_ERROR("Cannot allocate memory for workqueue");
  66967. + return NULL;
  66968. + }
  66969. +
  66970. + wq->taskq = taskqueue_create(name, M_NOWAIT, taskqueue_thread_enqueue, &wq->taskq);
  66971. + if (!wq->taskq) {
  66972. + DWC_ERROR("Cannot allocate memory for taskqueue");
  66973. + goto no_taskq;
  66974. + }
  66975. +
  66976. + wq->pending = 0;
  66977. +
  66978. + wq->lock = DWC_SPINLOCK_ALLOC();
  66979. + if (!wq->lock) {
  66980. + DWC_ERROR("Cannot allocate memory for spinlock");
  66981. + goto no_lock;
  66982. + }
  66983. +
  66984. + wq->waitq = DWC_WAITQ_ALLOC();
  66985. + if (!wq->waitq) {
  66986. + DWC_ERROR("Cannot allocate memory for waitqueue");
  66987. + goto no_waitq;
  66988. + }
  66989. +
  66990. + taskqueue_start_threads(&wq->taskq, 1, PWAIT, "%s taskq", "dw3tsk");
  66991. +
  66992. +#ifdef DEBUG
  66993. + DWC_CIRCLEQ_INIT(&wq->entries);
  66994. +#endif
  66995. + return wq;
  66996. +
  66997. + no_waitq:
  66998. + DWC_SPINLOCK_FREE(wq->lock);
  66999. + no_lock:
  67000. + taskqueue_free(wq->taskq);
  67001. + no_taskq:
  67002. + DWC_FREE(wq);
  67003. +
  67004. + return NULL;
  67005. +}
  67006. +
  67007. +void DWC_WORKQ_FREE(dwc_workq_t *wq)
  67008. +{
  67009. +#ifdef DEBUG
  67010. + dwc_irqflags_t flags;
  67011. +
  67012. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  67013. +
  67014. + if (wq->pending != 0) {
  67015. + struct work_container *container;
  67016. +
  67017. + DWC_ERROR("Destroying work queue with pending work");
  67018. +
  67019. + DWC_CIRCLEQ_FOREACH(container, &wq->entries, entry) {
  67020. + DWC_ERROR("Work %s still pending", container->name);
  67021. + }
  67022. + }
  67023. +
  67024. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  67025. +#endif
  67026. + DWC_WAITQ_FREE(wq->waitq);
  67027. + DWC_SPINLOCK_FREE(wq->lock);
  67028. + taskqueue_free(wq->taskq);
  67029. + DWC_FREE(wq);
  67030. +}
  67031. +
  67032. +void DWC_WORKQ_SCHEDULE(dwc_workq_t *wq, dwc_work_callback_t cb, void *data,
  67033. + char *format, ...)
  67034. +{
  67035. + dwc_irqflags_t flags;
  67036. + work_container_t *container;
  67037. + static char name[128];
  67038. + va_list args;
  67039. +
  67040. + va_start(args, format);
  67041. + DWC_VSNPRINTF(name, 128, format, args);
  67042. + va_end(args);
  67043. +
  67044. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  67045. + wq->pending++;
  67046. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  67047. + DWC_WAITQ_TRIGGER(wq->waitq);
  67048. +
  67049. + container = DWC_ALLOC_ATOMIC(sizeof(*container));
  67050. + if (!container) {
  67051. + DWC_ERROR("Cannot allocate memory for container");
  67052. + return;
  67053. + }
  67054. +
  67055. + container->name = DWC_STRDUP(name);
  67056. + if (!container->name) {
  67057. + DWC_ERROR("Cannot allocate memory for container->name");
  67058. + DWC_FREE(container);
  67059. + return;
  67060. + }
  67061. +
  67062. + container->cb = cb;
  67063. + container->data = data;
  67064. + container->wq = wq;
  67065. + container->hz = 0;
  67066. +
  67067. + DWC_DEBUG("Queueing work: %s, container=%p", container->name, container);
  67068. +
  67069. + TASK_INIT(&container->task, 0, do_work, container);
  67070. +
  67071. +#ifdef DEBUG
  67072. + DWC_CIRCLEQ_INSERT_TAIL(&wq->entries, container, entry);
  67073. +#endif
  67074. + taskqueue_enqueue_fast(wq->taskq, &container->task);
  67075. +}
  67076. +
  67077. +void DWC_WORKQ_SCHEDULE_DELAYED(dwc_workq_t *wq, dwc_work_callback_t cb,
  67078. + void *data, uint32_t time, char *format, ...)
  67079. +{
  67080. + dwc_irqflags_t flags;
  67081. + work_container_t *container;
  67082. + static char name[128];
  67083. + struct timeval tv;
  67084. + va_list args;
  67085. +
  67086. + va_start(args, format);
  67087. + DWC_VSNPRINTF(name, 128, format, args);
  67088. + va_end(args);
  67089. +
  67090. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  67091. + wq->pending++;
  67092. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  67093. + DWC_WAITQ_TRIGGER(wq->waitq);
  67094. +
  67095. + container = DWC_ALLOC_ATOMIC(sizeof(*container));
  67096. + if (!container) {
  67097. + DWC_ERROR("Cannot allocate memory for container");
  67098. + return;
  67099. + }
  67100. +
  67101. + container->name = DWC_STRDUP(name);
  67102. + if (!container->name) {
  67103. + DWC_ERROR("Cannot allocate memory for container->name");
  67104. + DWC_FREE(container);
  67105. + return;
  67106. + }
  67107. +
  67108. + container->cb = cb;
  67109. + container->data = data;
  67110. + container->wq = wq;
  67111. +
  67112. + tv.tv_sec = time / 1000;
  67113. + tv.tv_usec = (time - tv.tv_sec * 1000) * 1000;
  67114. + container->hz = tvtohz(&tv);
  67115. +
  67116. + DWC_DEBUG("Queueing work: %s, container=%p", container->name, container);
  67117. +
  67118. + TASK_INIT(&container->task, 0, do_work, container);
  67119. +
  67120. +#ifdef DEBUG
  67121. + DWC_CIRCLEQ_INSERT_TAIL(&wq->entries, container, entry);
  67122. +#endif
  67123. + taskqueue_enqueue_fast(wq->taskq, &container->task);
  67124. +}
  67125. +
  67126. +int DWC_WORKQ_PENDING(dwc_workq_t *wq)
  67127. +{
  67128. + return wq->pending;
  67129. +}
  67130. diff -Nur linux-3.18.8/drivers/usb/host/dwc_common_port/dwc_common_linux.c linux-rpi/drivers/usb/host/dwc_common_port/dwc_common_linux.c
  67131. --- linux-3.18.8/drivers/usb/host/dwc_common_port/dwc_common_linux.c 1970-01-01 01:00:00.000000000 +0100
  67132. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_common_linux.c 2015-03-05 14:40:16.553715806 +0100
  67133. @@ -0,0 +1,1434 @@
  67134. +#include <linux/kernel.h>
  67135. +#include <linux/init.h>
  67136. +#include <linux/module.h>
  67137. +#include <linux/kthread.h>
  67138. +
  67139. +#ifdef DWC_CCLIB
  67140. +# include "dwc_cc.h"
  67141. +#endif
  67142. +
  67143. +#ifdef DWC_CRYPTOLIB
  67144. +# include "dwc_modpow.h"
  67145. +# include "dwc_dh.h"
  67146. +# include "dwc_crypto.h"
  67147. +#endif
  67148. +
  67149. +#ifdef DWC_NOTIFYLIB
  67150. +# include "dwc_notifier.h"
  67151. +#endif
  67152. +
  67153. +/* OS-Level Implementations */
  67154. +
  67155. +/* This is the Linux kernel implementation of the DWC platform library. */
  67156. +#include <linux/moduleparam.h>
  67157. +#include <linux/ctype.h>
  67158. +#include <linux/crypto.h>
  67159. +#include <linux/delay.h>
  67160. +#include <linux/device.h>
  67161. +#include <linux/dma-mapping.h>
  67162. +#include <linux/cdev.h>
  67163. +#include <linux/errno.h>
  67164. +#include <linux/interrupt.h>
  67165. +#include <linux/jiffies.h>
  67166. +#include <linux/list.h>
  67167. +#include <linux/pci.h>
  67168. +#include <linux/random.h>
  67169. +#include <linux/scatterlist.h>
  67170. +#include <linux/slab.h>
  67171. +#include <linux/stat.h>
  67172. +#include <linux/string.h>
  67173. +#include <linux/timer.h>
  67174. +#include <linux/usb.h>
  67175. +
  67176. +#include <linux/version.h>
  67177. +
  67178. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
  67179. +# include <linux/usb/gadget.h>
  67180. +#else
  67181. +# include <linux/usb_gadget.h>
  67182. +#endif
  67183. +
  67184. +#include <asm/io.h>
  67185. +#include <asm/page.h>
  67186. +#include <asm/uaccess.h>
  67187. +#include <asm/unaligned.h>
  67188. +
  67189. +#include "dwc_os.h"
  67190. +#include "dwc_list.h"
  67191. +
  67192. +
  67193. +/* MISC */
  67194. +
  67195. +void *DWC_MEMSET(void *dest, uint8_t byte, uint32_t size)
  67196. +{
  67197. + return memset(dest, byte, size);
  67198. +}
  67199. +
  67200. +void *DWC_MEMCPY(void *dest, void const *src, uint32_t size)
  67201. +{
  67202. + return memcpy(dest, src, size);
  67203. +}
  67204. +
  67205. +void *DWC_MEMMOVE(void *dest, void *src, uint32_t size)
  67206. +{
  67207. + return memmove(dest, src, size);
  67208. +}
  67209. +
  67210. +int DWC_MEMCMP(void *m1, void *m2, uint32_t size)
  67211. +{
  67212. + return memcmp(m1, m2, size);
  67213. +}
  67214. +
  67215. +int DWC_STRNCMP(void *s1, void *s2, uint32_t size)
  67216. +{
  67217. + return strncmp(s1, s2, size);
  67218. +}
  67219. +
  67220. +int DWC_STRCMP(void *s1, void *s2)
  67221. +{
  67222. + return strcmp(s1, s2);
  67223. +}
  67224. +
  67225. +int DWC_STRLEN(char const *str)
  67226. +{
  67227. + return strlen(str);
  67228. +}
  67229. +
  67230. +char *DWC_STRCPY(char *to, char const *from)
  67231. +{
  67232. + return strcpy(to, from);
  67233. +}
  67234. +
  67235. +char *DWC_STRDUP(char const *str)
  67236. +{
  67237. + int len = DWC_STRLEN(str) + 1;
  67238. + char *new = DWC_ALLOC_ATOMIC(len);
  67239. +
  67240. + if (!new) {
  67241. + return NULL;
  67242. + }
  67243. +
  67244. + DWC_MEMCPY(new, str, len);
  67245. + return new;
  67246. +}
  67247. +
  67248. +int DWC_ATOI(const char *str, int32_t *value)
  67249. +{
  67250. + char *end = NULL;
  67251. +
  67252. + *value = simple_strtol(str, &end, 0);
  67253. + if (*end == '\0') {
  67254. + return 0;
  67255. + }
  67256. +
  67257. + return -1;
  67258. +}
  67259. +
  67260. +int DWC_ATOUI(const char *str, uint32_t *value)
  67261. +{
  67262. + char *end = NULL;
  67263. +
  67264. + *value = simple_strtoul(str, &end, 0);
  67265. + if (*end == '\0') {
  67266. + return 0;
  67267. + }
  67268. +
  67269. + return -1;
  67270. +}
  67271. +
  67272. +
  67273. +#ifdef DWC_UTFLIB
  67274. +/* From usbstring.c */
  67275. +
  67276. +int DWC_UTF8_TO_UTF16LE(uint8_t const *s, uint16_t *cp, unsigned len)
  67277. +{
  67278. + int count = 0;
  67279. + u8 c;
  67280. + u16 uchar;
  67281. +
  67282. + /* this insists on correct encodings, though not minimal ones.
  67283. + * BUT it currently rejects legit 4-byte UTF-8 code points,
  67284. + * which need surrogate pairs. (Unicode 3.1 can use them.)
  67285. + */
  67286. + while (len != 0 && (c = (u8) *s++) != 0) {
  67287. + if (unlikely(c & 0x80)) {
  67288. + // 2-byte sequence:
  67289. + // 00000yyyyyxxxxxx = 110yyyyy 10xxxxxx
  67290. + if ((c & 0xe0) == 0xc0) {
  67291. + uchar = (c & 0x1f) << 6;
  67292. +
  67293. + c = (u8) *s++;
  67294. + if ((c & 0xc0) != 0xc0)
  67295. + goto fail;
  67296. + c &= 0x3f;
  67297. + uchar |= c;
  67298. +
  67299. + // 3-byte sequence (most CJKV characters):
  67300. + // zzzzyyyyyyxxxxxx = 1110zzzz 10yyyyyy 10xxxxxx
  67301. + } else if ((c & 0xf0) == 0xe0) {
  67302. + uchar = (c & 0x0f) << 12;
  67303. +
  67304. + c = (u8) *s++;
  67305. + if ((c & 0xc0) != 0xc0)
  67306. + goto fail;
  67307. + c &= 0x3f;
  67308. + uchar |= c << 6;
  67309. +
  67310. + c = (u8) *s++;
  67311. + if ((c & 0xc0) != 0xc0)
  67312. + goto fail;
  67313. + c &= 0x3f;
  67314. + uchar |= c;
  67315. +
  67316. + /* no bogus surrogates */
  67317. + if (0xd800 <= uchar && uchar <= 0xdfff)
  67318. + goto fail;
  67319. +
  67320. + // 4-byte sequence (surrogate pairs, currently rare):
  67321. + // 11101110wwwwzzzzyy + 110111yyyyxxxxxx
  67322. + // = 11110uuu 10uuzzzz 10yyyyyy 10xxxxxx
  67323. + // (uuuuu = wwww + 1)
  67324. + // FIXME accept the surrogate code points (only)
  67325. + } else
  67326. + goto fail;
  67327. + } else
  67328. + uchar = c;
  67329. + put_unaligned (cpu_to_le16 (uchar), cp++);
  67330. + count++;
  67331. + len--;
  67332. + }
  67333. + return count;
  67334. +fail:
  67335. + return -1;
  67336. +}
  67337. +#endif /* DWC_UTFLIB */
  67338. +
  67339. +
  67340. +/* dwc_debug.h */
  67341. +
  67342. +dwc_bool_t DWC_IN_IRQ(void)
  67343. +{
  67344. + return in_irq();
  67345. +}
  67346. +
  67347. +dwc_bool_t DWC_IN_BH(void)
  67348. +{
  67349. + return in_softirq();
  67350. +}
  67351. +
  67352. +void DWC_VPRINTF(char *format, va_list args)
  67353. +{
  67354. + vprintk(format, args);
  67355. +}
  67356. +
  67357. +int DWC_VSNPRINTF(char *str, int size, char *format, va_list args)
  67358. +{
  67359. + return vsnprintf(str, size, format, args);
  67360. +}
  67361. +
  67362. +void DWC_PRINTF(char *format, ...)
  67363. +{
  67364. + va_list args;
  67365. +
  67366. + va_start(args, format);
  67367. + DWC_VPRINTF(format, args);
  67368. + va_end(args);
  67369. +}
  67370. +
  67371. +int DWC_SPRINTF(char *buffer, char *format, ...)
  67372. +{
  67373. + int retval;
  67374. + va_list args;
  67375. +
  67376. + va_start(args, format);
  67377. + retval = vsprintf(buffer, format, args);
  67378. + va_end(args);
  67379. + return retval;
  67380. +}
  67381. +
  67382. +int DWC_SNPRINTF(char *buffer, int size, char *format, ...)
  67383. +{
  67384. + int retval;
  67385. + va_list args;
  67386. +
  67387. + va_start(args, format);
  67388. + retval = vsnprintf(buffer, size, format, args);
  67389. + va_end(args);
  67390. + return retval;
  67391. +}
  67392. +
  67393. +void __DWC_WARN(char *format, ...)
  67394. +{
  67395. + va_list args;
  67396. +
  67397. + va_start(args, format);
  67398. + DWC_PRINTF(KERN_WARNING);
  67399. + DWC_VPRINTF(format, args);
  67400. + va_end(args);
  67401. +}
  67402. +
  67403. +void __DWC_ERROR(char *format, ...)
  67404. +{
  67405. + va_list args;
  67406. +
  67407. + va_start(args, format);
  67408. + DWC_PRINTF(KERN_ERR);
  67409. + DWC_VPRINTF(format, args);
  67410. + va_end(args);
  67411. +}
  67412. +
  67413. +void DWC_EXCEPTION(char *format, ...)
  67414. +{
  67415. + va_list args;
  67416. +
  67417. + va_start(args, format);
  67418. + DWC_PRINTF(KERN_ERR);
  67419. + DWC_VPRINTF(format, args);
  67420. + va_end(args);
  67421. + BUG_ON(1);
  67422. +}
  67423. +
  67424. +#ifdef DEBUG
  67425. +void __DWC_DEBUG(char *format, ...)
  67426. +{
  67427. + va_list args;
  67428. +
  67429. + va_start(args, format);
  67430. + DWC_PRINTF(KERN_DEBUG);
  67431. + DWC_VPRINTF(format, args);
  67432. + va_end(args);
  67433. +}
  67434. +#endif
  67435. +
  67436. +
  67437. +/* dwc_mem.h */
  67438. +
  67439. +#if 0
  67440. +dwc_pool_t *DWC_DMA_POOL_CREATE(uint32_t size,
  67441. + uint32_t align,
  67442. + uint32_t alloc)
  67443. +{
  67444. + struct dma_pool *pool = dma_pool_create("Pool", NULL,
  67445. + size, align, alloc);
  67446. + return (dwc_pool_t *)pool;
  67447. +}
  67448. +
  67449. +void DWC_DMA_POOL_DESTROY(dwc_pool_t *pool)
  67450. +{
  67451. + dma_pool_destroy((struct dma_pool *)pool);
  67452. +}
  67453. +
  67454. +void *DWC_DMA_POOL_ALLOC(dwc_pool_t *pool, uint64_t *dma_addr)
  67455. +{
  67456. + return dma_pool_alloc((struct dma_pool *)pool, GFP_KERNEL, dma_addr);
  67457. +}
  67458. +
  67459. +void *DWC_DMA_POOL_ZALLOC(dwc_pool_t *pool, uint64_t *dma_addr)
  67460. +{
  67461. + void *vaddr = DWC_DMA_POOL_ALLOC(pool, dma_addr);
  67462. + memset(..);
  67463. +}
  67464. +
  67465. +void DWC_DMA_POOL_FREE(dwc_pool_t *pool, void *vaddr, void *daddr)
  67466. +{
  67467. + dma_pool_free(pool, vaddr, daddr);
  67468. +}
  67469. +#endif
  67470. +
  67471. +void *__DWC_DMA_ALLOC(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr)
  67472. +{
  67473. +#ifdef xxCOSIM /* Only works for 32-bit cosim */
  67474. + void *buf = dma_alloc_coherent(dma_ctx, (size_t)size, dma_addr, GFP_KERNEL);
  67475. +#else
  67476. + void *buf = dma_alloc_coherent(dma_ctx, (size_t)size, dma_addr, GFP_KERNEL | GFP_DMA32);
  67477. +#endif
  67478. + if (!buf) {
  67479. + return NULL;
  67480. + }
  67481. +
  67482. + memset(buf, 0, (size_t)size);
  67483. + return buf;
  67484. +}
  67485. +
  67486. +void *__DWC_DMA_ALLOC_ATOMIC(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr)
  67487. +{
  67488. + void *buf = dma_alloc_coherent(NULL, (size_t)size, dma_addr, GFP_ATOMIC);
  67489. + if (!buf) {
  67490. + return NULL;
  67491. + }
  67492. + memset(buf, 0, (size_t)size);
  67493. + return buf;
  67494. +}
  67495. +
  67496. +void __DWC_DMA_FREE(void *dma_ctx, uint32_t size, void *virt_addr, dwc_dma_t dma_addr)
  67497. +{
  67498. + dma_free_coherent(dma_ctx, size, virt_addr, dma_addr);
  67499. +}
  67500. +
  67501. +void *__DWC_ALLOC(void *mem_ctx, uint32_t size)
  67502. +{
  67503. + return kzalloc(size, GFP_KERNEL);
  67504. +}
  67505. +
  67506. +void *__DWC_ALLOC_ATOMIC(void *mem_ctx, uint32_t size)
  67507. +{
  67508. + return kzalloc(size, GFP_ATOMIC);
  67509. +}
  67510. +
  67511. +void __DWC_FREE(void *mem_ctx, void *addr)
  67512. +{
  67513. + kfree(addr);
  67514. +}
  67515. +
  67516. +
  67517. +#ifdef DWC_CRYPTOLIB
  67518. +/* dwc_crypto.h */
  67519. +
  67520. +void DWC_RANDOM_BYTES(uint8_t *buffer, uint32_t length)
  67521. +{
  67522. + get_random_bytes(buffer, length);
  67523. +}
  67524. +
  67525. +int DWC_AES_CBC(uint8_t *message, uint32_t messagelen, uint8_t *key, uint32_t keylen, uint8_t iv[16], uint8_t *out)
  67526. +{
  67527. + struct crypto_blkcipher *tfm;
  67528. + struct blkcipher_desc desc;
  67529. + struct scatterlist sgd;
  67530. + struct scatterlist sgs;
  67531. +
  67532. + tfm = crypto_alloc_blkcipher("cbc(aes)", 0, CRYPTO_ALG_ASYNC);
  67533. + if (tfm == NULL) {
  67534. + printk("failed to load transform for aes CBC\n");
  67535. + return -1;
  67536. + }
  67537. +
  67538. + crypto_blkcipher_setkey(tfm, key, keylen);
  67539. + crypto_blkcipher_set_iv(tfm, iv, 16);
  67540. +
  67541. + sg_init_one(&sgd, out, messagelen);
  67542. + sg_init_one(&sgs, message, messagelen);
  67543. +
  67544. + desc.tfm = tfm;
  67545. + desc.flags = 0;
  67546. +
  67547. + if (crypto_blkcipher_encrypt(&desc, &sgd, &sgs, messagelen)) {
  67548. + crypto_free_blkcipher(tfm);
  67549. + DWC_ERROR("AES CBC encryption failed");
  67550. + return -1;
  67551. + }
  67552. +
  67553. + crypto_free_blkcipher(tfm);
  67554. + return 0;
  67555. +}
  67556. +
  67557. +int DWC_SHA256(uint8_t *message, uint32_t len, uint8_t *out)
  67558. +{
  67559. + struct crypto_hash *tfm;
  67560. + struct hash_desc desc;
  67561. + struct scatterlist sg;
  67562. +
  67563. + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
  67564. + if (IS_ERR(tfm)) {
  67565. + DWC_ERROR("Failed to load transform for sha256: %ld\n", PTR_ERR(tfm));
  67566. + return 0;
  67567. + }
  67568. + desc.tfm = tfm;
  67569. + desc.flags = 0;
  67570. +
  67571. + sg_init_one(&sg, message, len);
  67572. + crypto_hash_digest(&desc, &sg, len, out);
  67573. + crypto_free_hash(tfm);
  67574. +
  67575. + return 1;
  67576. +}
  67577. +
  67578. +int DWC_HMAC_SHA256(uint8_t *message, uint32_t messagelen,
  67579. + uint8_t *key, uint32_t keylen, uint8_t *out)
  67580. +{
  67581. + struct crypto_hash *tfm;
  67582. + struct hash_desc desc;
  67583. + struct scatterlist sg;
  67584. +
  67585. + tfm = crypto_alloc_hash("hmac(sha256)", 0, CRYPTO_ALG_ASYNC);
  67586. + if (IS_ERR(tfm)) {
  67587. + DWC_ERROR("Failed to load transform for hmac(sha256): %ld\n", PTR_ERR(tfm));
  67588. + return 0;
  67589. + }
  67590. + desc.tfm = tfm;
  67591. + desc.flags = 0;
  67592. +
  67593. + sg_init_one(&sg, message, messagelen);
  67594. + crypto_hash_setkey(tfm, key, keylen);
  67595. + crypto_hash_digest(&desc, &sg, messagelen, out);
  67596. + crypto_free_hash(tfm);
  67597. +
  67598. + return 1;
  67599. +}
  67600. +#endif /* DWC_CRYPTOLIB */
  67601. +
  67602. +
  67603. +/* Byte Ordering Conversions */
  67604. +
  67605. +uint32_t DWC_CPU_TO_LE32(uint32_t *p)
  67606. +{
  67607. +#ifdef __LITTLE_ENDIAN
  67608. + return *p;
  67609. +#else
  67610. + uint8_t *u_p = (uint8_t *)p;
  67611. +
  67612. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  67613. +#endif
  67614. +}
  67615. +
  67616. +uint32_t DWC_CPU_TO_BE32(uint32_t *p)
  67617. +{
  67618. +#ifdef __BIG_ENDIAN
  67619. + return *p;
  67620. +#else
  67621. + uint8_t *u_p = (uint8_t *)p;
  67622. +
  67623. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  67624. +#endif
  67625. +}
  67626. +
  67627. +uint32_t DWC_LE32_TO_CPU(uint32_t *p)
  67628. +{
  67629. +#ifdef __LITTLE_ENDIAN
  67630. + return *p;
  67631. +#else
  67632. + uint8_t *u_p = (uint8_t *)p;
  67633. +
  67634. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  67635. +#endif
  67636. +}
  67637. +
  67638. +uint32_t DWC_BE32_TO_CPU(uint32_t *p)
  67639. +{
  67640. +#ifdef __BIG_ENDIAN
  67641. + return *p;
  67642. +#else
  67643. + uint8_t *u_p = (uint8_t *)p;
  67644. +
  67645. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  67646. +#endif
  67647. +}
  67648. +
  67649. +uint16_t DWC_CPU_TO_LE16(uint16_t *p)
  67650. +{
  67651. +#ifdef __LITTLE_ENDIAN
  67652. + return *p;
  67653. +#else
  67654. + uint8_t *u_p = (uint8_t *)p;
  67655. + return (u_p[1] | (u_p[0] << 8));
  67656. +#endif
  67657. +}
  67658. +
  67659. +uint16_t DWC_CPU_TO_BE16(uint16_t *p)
  67660. +{
  67661. +#ifdef __BIG_ENDIAN
  67662. + return *p;
  67663. +#else
  67664. + uint8_t *u_p = (uint8_t *)p;
  67665. + return (u_p[1] | (u_p[0] << 8));
  67666. +#endif
  67667. +}
  67668. +
  67669. +uint16_t DWC_LE16_TO_CPU(uint16_t *p)
  67670. +{
  67671. +#ifdef __LITTLE_ENDIAN
  67672. + return *p;
  67673. +#else
  67674. + uint8_t *u_p = (uint8_t *)p;
  67675. + return (u_p[1] | (u_p[0] << 8));
  67676. +#endif
  67677. +}
  67678. +
  67679. +uint16_t DWC_BE16_TO_CPU(uint16_t *p)
  67680. +{
  67681. +#ifdef __BIG_ENDIAN
  67682. + return *p;
  67683. +#else
  67684. + uint8_t *u_p = (uint8_t *)p;
  67685. + return (u_p[1] | (u_p[0] << 8));
  67686. +#endif
  67687. +}
  67688. +
  67689. +
  67690. +/* Registers */
  67691. +
  67692. +uint32_t DWC_READ_REG32(uint32_t volatile *reg)
  67693. +{
  67694. + return readl(reg);
  67695. +}
  67696. +
  67697. +#if 0
  67698. +uint64_t DWC_READ_REG64(uint64_t volatile *reg)
  67699. +{
  67700. +}
  67701. +#endif
  67702. +
  67703. +void DWC_WRITE_REG32(uint32_t volatile *reg, uint32_t value)
  67704. +{
  67705. + writel(value, reg);
  67706. +}
  67707. +
  67708. +#if 0
  67709. +void DWC_WRITE_REG64(uint64_t volatile *reg, uint64_t value)
  67710. +{
  67711. +}
  67712. +#endif
  67713. +
  67714. +void DWC_MODIFY_REG32(uint32_t volatile *reg, uint32_t clear_mask, uint32_t set_mask)
  67715. +{
  67716. + writel((readl(reg) & ~clear_mask) | set_mask, reg);
  67717. +}
  67718. +
  67719. +#if 0
  67720. +void DWC_MODIFY_REG64(uint64_t volatile *reg, uint64_t clear_mask, uint64_t set_mask)
  67721. +{
  67722. +}
  67723. +#endif
  67724. +
  67725. +
  67726. +/* Locking */
  67727. +
  67728. +dwc_spinlock_t *DWC_SPINLOCK_ALLOC(void)
  67729. +{
  67730. + spinlock_t *sl = (spinlock_t *)1;
  67731. +
  67732. +#if defined(CONFIG_PREEMPT) || defined(CONFIG_SMP)
  67733. + sl = DWC_ALLOC(sizeof(*sl));
  67734. + if (!sl) {
  67735. + DWC_ERROR("Cannot allocate memory for spinlock\n");
  67736. + return NULL;
  67737. + }
  67738. +
  67739. + spin_lock_init(sl);
  67740. +#endif
  67741. + return (dwc_spinlock_t *)sl;
  67742. +}
  67743. +
  67744. +void DWC_SPINLOCK_FREE(dwc_spinlock_t *lock)
  67745. +{
  67746. +#if defined(CONFIG_PREEMPT) || defined(CONFIG_SMP)
  67747. + DWC_FREE(lock);
  67748. +#endif
  67749. +}
  67750. +
  67751. +void DWC_SPINLOCK(dwc_spinlock_t *lock)
  67752. +{
  67753. +#if defined(CONFIG_PREEMPT) || defined(CONFIG_SMP)
  67754. + spin_lock((spinlock_t *)lock);
  67755. +#endif
  67756. +}
  67757. +
  67758. +void DWC_SPINUNLOCK(dwc_spinlock_t *lock)
  67759. +{
  67760. +#if defined(CONFIG_PREEMPT) || defined(CONFIG_SMP)
  67761. + spin_unlock((spinlock_t *)lock);
  67762. +#endif
  67763. +}
  67764. +
  67765. +void DWC_SPINLOCK_IRQSAVE(dwc_spinlock_t *lock, dwc_irqflags_t *flags)
  67766. +{
  67767. + dwc_irqflags_t f;
  67768. +
  67769. +#if defined(CONFIG_PREEMPT) || defined(CONFIG_SMP)
  67770. + spin_lock_irqsave((spinlock_t *)lock, f);
  67771. +#else
  67772. + local_irq_save(f);
  67773. +#endif
  67774. + *flags = f;
  67775. +}
  67776. +
  67777. +void DWC_SPINUNLOCK_IRQRESTORE(dwc_spinlock_t *lock, dwc_irqflags_t flags)
  67778. +{
  67779. +#if defined(CONFIG_PREEMPT) || defined(CONFIG_SMP)
  67780. + spin_unlock_irqrestore((spinlock_t *)lock, flags);
  67781. +#else
  67782. + local_irq_restore(flags);
  67783. +#endif
  67784. +}
  67785. +
  67786. +dwc_mutex_t *DWC_MUTEX_ALLOC(void)
  67787. +{
  67788. + struct mutex *m;
  67789. + dwc_mutex_t *mutex = (dwc_mutex_t *)DWC_ALLOC(sizeof(struct mutex));
  67790. +
  67791. + if (!mutex) {
  67792. + DWC_ERROR("Cannot allocate memory for mutex\n");
  67793. + return NULL;
  67794. + }
  67795. +
  67796. + m = (struct mutex *)mutex;
  67797. + mutex_init(m);
  67798. + return mutex;
  67799. +}
  67800. +
  67801. +#if (defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES))
  67802. +#else
  67803. +void DWC_MUTEX_FREE(dwc_mutex_t *mutex)
  67804. +{
  67805. + mutex_destroy((struct mutex *)mutex);
  67806. + DWC_FREE(mutex);
  67807. +}
  67808. +#endif
  67809. +
  67810. +void DWC_MUTEX_LOCK(dwc_mutex_t *mutex)
  67811. +{
  67812. + struct mutex *m = (struct mutex *)mutex;
  67813. + mutex_lock(m);
  67814. +}
  67815. +
  67816. +int DWC_MUTEX_TRYLOCK(dwc_mutex_t *mutex)
  67817. +{
  67818. + struct mutex *m = (struct mutex *)mutex;
  67819. + return mutex_trylock(m);
  67820. +}
  67821. +
  67822. +void DWC_MUTEX_UNLOCK(dwc_mutex_t *mutex)
  67823. +{
  67824. + struct mutex *m = (struct mutex *)mutex;
  67825. + mutex_unlock(m);
  67826. +}
  67827. +
  67828. +
  67829. +/* Timing */
  67830. +
  67831. +void DWC_UDELAY(uint32_t usecs)
  67832. +{
  67833. + udelay(usecs);
  67834. +}
  67835. +
  67836. +void DWC_MDELAY(uint32_t msecs)
  67837. +{
  67838. + mdelay(msecs);
  67839. +}
  67840. +
  67841. +void DWC_MSLEEP(uint32_t msecs)
  67842. +{
  67843. + msleep(msecs);
  67844. +}
  67845. +
  67846. +uint32_t DWC_TIME(void)
  67847. +{
  67848. + return jiffies_to_msecs(jiffies);
  67849. +}
  67850. +
  67851. +
  67852. +/* Timers */
  67853. +
  67854. +struct dwc_timer {
  67855. + struct timer_list *t;
  67856. + char *name;
  67857. + dwc_timer_callback_t cb;
  67858. + void *data;
  67859. + uint8_t scheduled;
  67860. + dwc_spinlock_t *lock;
  67861. +};
  67862. +
  67863. +static void timer_callback(unsigned long data)
  67864. +{
  67865. + dwc_timer_t *timer = (dwc_timer_t *)data;
  67866. + dwc_irqflags_t flags;
  67867. +
  67868. + DWC_SPINLOCK_IRQSAVE(timer->lock, &flags);
  67869. + timer->scheduled = 0;
  67870. + DWC_SPINUNLOCK_IRQRESTORE(timer->lock, flags);
  67871. + DWC_DEBUGC("Timer %s callback", timer->name);
  67872. + timer->cb(timer->data);
  67873. +}
  67874. +
  67875. +dwc_timer_t *DWC_TIMER_ALLOC(char *name, dwc_timer_callback_t cb, void *data)
  67876. +{
  67877. + dwc_timer_t *t = DWC_ALLOC(sizeof(*t));
  67878. +
  67879. + if (!t) {
  67880. + DWC_ERROR("Cannot allocate memory for timer");
  67881. + return NULL;
  67882. + }
  67883. +
  67884. + t->t = DWC_ALLOC(sizeof(*t->t));
  67885. + if (!t->t) {
  67886. + DWC_ERROR("Cannot allocate memory for timer->t");
  67887. + goto no_timer;
  67888. + }
  67889. +
  67890. + t->name = DWC_STRDUP(name);
  67891. + if (!t->name) {
  67892. + DWC_ERROR("Cannot allocate memory for timer->name");
  67893. + goto no_name;
  67894. + }
  67895. +
  67896. +#if (defined(DWC_LINUX) && defined(CONFIG_DEBUG_SPINLOCK))
  67897. + DWC_SPINLOCK_ALLOC_LINUX_DEBUG(t->lock);
  67898. +#else
  67899. + t->lock = DWC_SPINLOCK_ALLOC();
  67900. +#endif
  67901. + if (!t->lock) {
  67902. + DWC_ERROR("Cannot allocate memory for lock");
  67903. + goto no_lock;
  67904. + }
  67905. +
  67906. + t->scheduled = 0;
  67907. + t->t->base = &boot_tvec_bases;
  67908. + t->t->expires = jiffies;
  67909. + setup_timer(t->t, timer_callback, (unsigned long)t);
  67910. +
  67911. + t->cb = cb;
  67912. + t->data = data;
  67913. +
  67914. + return t;
  67915. +
  67916. + no_lock:
  67917. + DWC_FREE(t->name);
  67918. + no_name:
  67919. + DWC_FREE(t->t);
  67920. + no_timer:
  67921. + DWC_FREE(t);
  67922. + return NULL;
  67923. +}
  67924. +
  67925. +void DWC_TIMER_FREE(dwc_timer_t *timer)
  67926. +{
  67927. + dwc_irqflags_t flags;
  67928. +
  67929. + DWC_SPINLOCK_IRQSAVE(timer->lock, &flags);
  67930. +
  67931. + if (timer->scheduled) {
  67932. + del_timer(timer->t);
  67933. + timer->scheduled = 0;
  67934. + }
  67935. +
  67936. + DWC_SPINUNLOCK_IRQRESTORE(timer->lock, flags);
  67937. + DWC_SPINLOCK_FREE(timer->lock);
  67938. + DWC_FREE(timer->t);
  67939. + DWC_FREE(timer->name);
  67940. + DWC_FREE(timer);
  67941. +}
  67942. +
  67943. +void DWC_TIMER_SCHEDULE(dwc_timer_t *timer, uint32_t time)
  67944. +{
  67945. + dwc_irqflags_t flags;
  67946. +
  67947. + DWC_SPINLOCK_IRQSAVE(timer->lock, &flags);
  67948. +
  67949. + if (!timer->scheduled) {
  67950. + timer->scheduled = 1;
  67951. + DWC_DEBUGC("Scheduling timer %s to expire in +%d msec", timer->name, time);
  67952. + timer->t->expires = jiffies + msecs_to_jiffies(time);
  67953. + add_timer(timer->t);
  67954. + } else {
  67955. + DWC_DEBUGC("Modifying timer %s to expire in +%d msec", timer->name, time);
  67956. + mod_timer(timer->t, jiffies + msecs_to_jiffies(time));
  67957. + }
  67958. +
  67959. + DWC_SPINUNLOCK_IRQRESTORE(timer->lock, flags);
  67960. +}
  67961. +
  67962. +void DWC_TIMER_CANCEL(dwc_timer_t *timer)
  67963. +{
  67964. + del_timer(timer->t);
  67965. +}
  67966. +
  67967. +
  67968. +/* Wait Queues */
  67969. +
  67970. +struct dwc_waitq {
  67971. + wait_queue_head_t queue;
  67972. + int abort;
  67973. +};
  67974. +
  67975. +dwc_waitq_t *DWC_WAITQ_ALLOC(void)
  67976. +{
  67977. + dwc_waitq_t *wq = DWC_ALLOC(sizeof(*wq));
  67978. +
  67979. + if (!wq) {
  67980. + DWC_ERROR("Cannot allocate memory for waitqueue\n");
  67981. + return NULL;
  67982. + }
  67983. +
  67984. + init_waitqueue_head(&wq->queue);
  67985. + wq->abort = 0;
  67986. + return wq;
  67987. +}
  67988. +
  67989. +void DWC_WAITQ_FREE(dwc_waitq_t *wq)
  67990. +{
  67991. + DWC_FREE(wq);
  67992. +}
  67993. +
  67994. +int32_t DWC_WAITQ_WAIT(dwc_waitq_t *wq, dwc_waitq_condition_t cond, void *data)
  67995. +{
  67996. + int result = wait_event_interruptible(wq->queue,
  67997. + cond(data) || wq->abort);
  67998. + if (result == -ERESTARTSYS) {
  67999. + wq->abort = 0;
  68000. + return -DWC_E_RESTART;
  68001. + }
  68002. +
  68003. + if (wq->abort == 1) {
  68004. + wq->abort = 0;
  68005. + return -DWC_E_ABORT;
  68006. + }
  68007. +
  68008. + wq->abort = 0;
  68009. +
  68010. + if (result == 0) {
  68011. + return 0;
  68012. + }
  68013. +
  68014. + return -DWC_E_UNKNOWN;
  68015. +}
  68016. +
  68017. +int32_t DWC_WAITQ_WAIT_TIMEOUT(dwc_waitq_t *wq, dwc_waitq_condition_t cond,
  68018. + void *data, int32_t msecs)
  68019. +{
  68020. + int32_t tmsecs;
  68021. + int result = wait_event_interruptible_timeout(wq->queue,
  68022. + cond(data) || wq->abort,
  68023. + msecs_to_jiffies(msecs));
  68024. + if (result == -ERESTARTSYS) {
  68025. + wq->abort = 0;
  68026. + return -DWC_E_RESTART;
  68027. + }
  68028. +
  68029. + if (wq->abort == 1) {
  68030. + wq->abort = 0;
  68031. + return -DWC_E_ABORT;
  68032. + }
  68033. +
  68034. + wq->abort = 0;
  68035. +
  68036. + if (result > 0) {
  68037. + tmsecs = jiffies_to_msecs(result);
  68038. + if (!tmsecs) {
  68039. + return 1;
  68040. + }
  68041. +
  68042. + return tmsecs;
  68043. + }
  68044. +
  68045. + if (result == 0) {
  68046. + return -DWC_E_TIMEOUT;
  68047. + }
  68048. +
  68049. + return -DWC_E_UNKNOWN;
  68050. +}
  68051. +
  68052. +void DWC_WAITQ_TRIGGER(dwc_waitq_t *wq)
  68053. +{
  68054. + wq->abort = 0;
  68055. + wake_up_interruptible(&wq->queue);
  68056. +}
  68057. +
  68058. +void DWC_WAITQ_ABORT(dwc_waitq_t *wq)
  68059. +{
  68060. + wq->abort = 1;
  68061. + wake_up_interruptible(&wq->queue);
  68062. +}
  68063. +
  68064. +
  68065. +/* Threading */
  68066. +
  68067. +dwc_thread_t *DWC_THREAD_RUN(dwc_thread_function_t func, char *name, void *data)
  68068. +{
  68069. + struct task_struct *thread = kthread_run(func, data, name);
  68070. +
  68071. + if (thread == ERR_PTR(-ENOMEM)) {
  68072. + return NULL;
  68073. + }
  68074. +
  68075. + return (dwc_thread_t *)thread;
  68076. +}
  68077. +
  68078. +int DWC_THREAD_STOP(dwc_thread_t *thread)
  68079. +{
  68080. + return kthread_stop((struct task_struct *)thread);
  68081. +}
  68082. +
  68083. +dwc_bool_t DWC_THREAD_SHOULD_STOP(void)
  68084. +{
  68085. + return kthread_should_stop();
  68086. +}
  68087. +
  68088. +
  68089. +/* tasklets
  68090. + - run in interrupt context (cannot sleep)
  68091. + - each tasklet runs on a single CPU
  68092. + - different tasklets can be running simultaneously on different CPUs
  68093. + */
  68094. +struct dwc_tasklet {
  68095. + struct tasklet_struct t;
  68096. + dwc_tasklet_callback_t cb;
  68097. + void *data;
  68098. +};
  68099. +
  68100. +static void tasklet_callback(unsigned long data)
  68101. +{
  68102. + dwc_tasklet_t *t = (dwc_tasklet_t *)data;
  68103. + t->cb(t->data);
  68104. +}
  68105. +
  68106. +dwc_tasklet_t *DWC_TASK_ALLOC(char *name, dwc_tasklet_callback_t cb, void *data)
  68107. +{
  68108. + dwc_tasklet_t *t = DWC_ALLOC(sizeof(*t));
  68109. +
  68110. + if (t) {
  68111. + t->cb = cb;
  68112. + t->data = data;
  68113. + tasklet_init(&t->t, tasklet_callback, (unsigned long)t);
  68114. + } else {
  68115. + DWC_ERROR("Cannot allocate memory for tasklet\n");
  68116. + }
  68117. +
  68118. + return t;
  68119. +}
  68120. +
  68121. +void DWC_TASK_FREE(dwc_tasklet_t *task)
  68122. +{
  68123. + DWC_FREE(task);
  68124. +}
  68125. +
  68126. +void DWC_TASK_SCHEDULE(dwc_tasklet_t *task)
  68127. +{
  68128. + tasklet_schedule(&task->t);
  68129. +}
  68130. +
  68131. +void DWC_TASK_HI_SCHEDULE(dwc_tasklet_t *task)
  68132. +{
  68133. + tasklet_hi_schedule(&task->t);
  68134. +}
  68135. +
  68136. +
  68137. +/* workqueues
  68138. + - run in process context (can sleep)
  68139. + */
  68140. +typedef struct work_container {
  68141. + dwc_work_callback_t cb;
  68142. + void *data;
  68143. + dwc_workq_t *wq;
  68144. + char *name;
  68145. +
  68146. +#ifdef DEBUG
  68147. + DWC_CIRCLEQ_ENTRY(work_container) entry;
  68148. +#endif
  68149. + struct delayed_work work;
  68150. +} work_container_t;
  68151. +
  68152. +#ifdef DEBUG
  68153. +DWC_CIRCLEQ_HEAD(work_container_queue, work_container);
  68154. +#endif
  68155. +
  68156. +struct dwc_workq {
  68157. + struct workqueue_struct *wq;
  68158. + dwc_spinlock_t *lock;
  68159. + dwc_waitq_t *waitq;
  68160. + int pending;
  68161. +
  68162. +#ifdef DEBUG
  68163. + struct work_container_queue entries;
  68164. +#endif
  68165. +};
  68166. +
  68167. +static void do_work(struct work_struct *work)
  68168. +{
  68169. + dwc_irqflags_t flags;
  68170. + struct delayed_work *dw = container_of(work, struct delayed_work, work);
  68171. + work_container_t *container = container_of(dw, struct work_container, work);
  68172. + dwc_workq_t *wq = container->wq;
  68173. +
  68174. + container->cb(container->data);
  68175. +
  68176. +#ifdef DEBUG
  68177. + DWC_CIRCLEQ_REMOVE(&wq->entries, container, entry);
  68178. +#endif
  68179. + DWC_DEBUGC("Work done: %s, container=%p", container->name, container);
  68180. + if (container->name) {
  68181. + DWC_FREE(container->name);
  68182. + }
  68183. + DWC_FREE(container);
  68184. +
  68185. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  68186. + wq->pending--;
  68187. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  68188. + DWC_WAITQ_TRIGGER(wq->waitq);
  68189. +}
  68190. +
  68191. +static int work_done(void *data)
  68192. +{
  68193. + dwc_workq_t *workq = (dwc_workq_t *)data;
  68194. + return workq->pending == 0;
  68195. +}
  68196. +
  68197. +int DWC_WORKQ_WAIT_WORK_DONE(dwc_workq_t *workq, int timeout)
  68198. +{
  68199. + return DWC_WAITQ_WAIT_TIMEOUT(workq->waitq, work_done, workq, timeout);
  68200. +}
  68201. +
  68202. +dwc_workq_t *DWC_WORKQ_ALLOC(char *name)
  68203. +{
  68204. + dwc_workq_t *wq = DWC_ALLOC(sizeof(*wq));
  68205. +
  68206. + if (!wq) {
  68207. + return NULL;
  68208. + }
  68209. +
  68210. + wq->wq = create_singlethread_workqueue(name);
  68211. + if (!wq->wq) {
  68212. + goto no_wq;
  68213. + }
  68214. +
  68215. + wq->pending = 0;
  68216. +
  68217. +#if (defined(DWC_LINUX) && defined(CONFIG_DEBUG_SPINLOCK))
  68218. + DWC_SPINLOCK_ALLOC_LINUX_DEBUG(wq->lock);
  68219. +#else
  68220. + wq->lock = DWC_SPINLOCK_ALLOC();
  68221. +#endif
  68222. + if (!wq->lock) {
  68223. + goto no_lock;
  68224. + }
  68225. +
  68226. + wq->waitq = DWC_WAITQ_ALLOC();
  68227. + if (!wq->waitq) {
  68228. + goto no_waitq;
  68229. + }
  68230. +
  68231. +#ifdef DEBUG
  68232. + DWC_CIRCLEQ_INIT(&wq->entries);
  68233. +#endif
  68234. + return wq;
  68235. +
  68236. + no_waitq:
  68237. + DWC_SPINLOCK_FREE(wq->lock);
  68238. + no_lock:
  68239. + destroy_workqueue(wq->wq);
  68240. + no_wq:
  68241. + DWC_FREE(wq);
  68242. +
  68243. + return NULL;
  68244. +}
  68245. +
  68246. +void DWC_WORKQ_FREE(dwc_workq_t *wq)
  68247. +{
  68248. +#ifdef DEBUG
  68249. + if (wq->pending != 0) {
  68250. + struct work_container *wc;
  68251. + DWC_ERROR("Destroying work queue with pending work");
  68252. + DWC_CIRCLEQ_FOREACH(wc, &wq->entries, entry) {
  68253. + DWC_ERROR("Work %s still pending", wc->name);
  68254. + }
  68255. + }
  68256. +#endif
  68257. + destroy_workqueue(wq->wq);
  68258. + DWC_SPINLOCK_FREE(wq->lock);
  68259. + DWC_WAITQ_FREE(wq->waitq);
  68260. + DWC_FREE(wq);
  68261. +}
  68262. +
  68263. +void DWC_WORKQ_SCHEDULE(dwc_workq_t *wq, dwc_work_callback_t cb, void *data,
  68264. + char *format, ...)
  68265. +{
  68266. + dwc_irqflags_t flags;
  68267. + work_container_t *container;
  68268. + static char name[128];
  68269. + va_list args;
  68270. +
  68271. + va_start(args, format);
  68272. + DWC_VSNPRINTF(name, 128, format, args);
  68273. + va_end(args);
  68274. +
  68275. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  68276. + wq->pending++;
  68277. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  68278. + DWC_WAITQ_TRIGGER(wq->waitq);
  68279. +
  68280. + container = DWC_ALLOC_ATOMIC(sizeof(*container));
  68281. + if (!container) {
  68282. + DWC_ERROR("Cannot allocate memory for container\n");
  68283. + return;
  68284. + }
  68285. +
  68286. + container->name = DWC_STRDUP(name);
  68287. + if (!container->name) {
  68288. + DWC_ERROR("Cannot allocate memory for container->name\n");
  68289. + DWC_FREE(container);
  68290. + return;
  68291. + }
  68292. +
  68293. + container->cb = cb;
  68294. + container->data = data;
  68295. + container->wq = wq;
  68296. + DWC_DEBUGC("Queueing work: %s, container=%p", container->name, container);
  68297. + INIT_WORK(&container->work.work, do_work);
  68298. +
  68299. +#ifdef DEBUG
  68300. + DWC_CIRCLEQ_INSERT_TAIL(&wq->entries, container, entry);
  68301. +#endif
  68302. + queue_work(wq->wq, &container->work.work);
  68303. +}
  68304. +
  68305. +void DWC_WORKQ_SCHEDULE_DELAYED(dwc_workq_t *wq, dwc_work_callback_t cb,
  68306. + void *data, uint32_t time, char *format, ...)
  68307. +{
  68308. + dwc_irqflags_t flags;
  68309. + work_container_t *container;
  68310. + static char name[128];
  68311. + va_list args;
  68312. +
  68313. + va_start(args, format);
  68314. + DWC_VSNPRINTF(name, 128, format, args);
  68315. + va_end(args);
  68316. +
  68317. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  68318. + wq->pending++;
  68319. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  68320. + DWC_WAITQ_TRIGGER(wq->waitq);
  68321. +
  68322. + container = DWC_ALLOC_ATOMIC(sizeof(*container));
  68323. + if (!container) {
  68324. + DWC_ERROR("Cannot allocate memory for container\n");
  68325. + return;
  68326. + }
  68327. +
  68328. + container->name = DWC_STRDUP(name);
  68329. + if (!container->name) {
  68330. + DWC_ERROR("Cannot allocate memory for container->name\n");
  68331. + DWC_FREE(container);
  68332. + return;
  68333. + }
  68334. +
  68335. + container->cb = cb;
  68336. + container->data = data;
  68337. + container->wq = wq;
  68338. + DWC_DEBUGC("Queueing work: %s, container=%p", container->name, container);
  68339. + INIT_DELAYED_WORK(&container->work, do_work);
  68340. +
  68341. +#ifdef DEBUG
  68342. + DWC_CIRCLEQ_INSERT_TAIL(&wq->entries, container, entry);
  68343. +#endif
  68344. + queue_delayed_work(wq->wq, &container->work, msecs_to_jiffies(time));
  68345. +}
  68346. +
  68347. +int DWC_WORKQ_PENDING(dwc_workq_t *wq)
  68348. +{
  68349. + return wq->pending;
  68350. +}
  68351. +
  68352. +
  68353. +#ifdef DWC_LIBMODULE
  68354. +
  68355. +#ifdef DWC_CCLIB
  68356. +/* CC */
  68357. +EXPORT_SYMBOL(dwc_cc_if_alloc);
  68358. +EXPORT_SYMBOL(dwc_cc_if_free);
  68359. +EXPORT_SYMBOL(dwc_cc_clear);
  68360. +EXPORT_SYMBOL(dwc_cc_add);
  68361. +EXPORT_SYMBOL(dwc_cc_remove);
  68362. +EXPORT_SYMBOL(dwc_cc_change);
  68363. +EXPORT_SYMBOL(dwc_cc_data_for_save);
  68364. +EXPORT_SYMBOL(dwc_cc_restore_from_data);
  68365. +EXPORT_SYMBOL(dwc_cc_match_chid);
  68366. +EXPORT_SYMBOL(dwc_cc_match_cdid);
  68367. +EXPORT_SYMBOL(dwc_cc_ck);
  68368. +EXPORT_SYMBOL(dwc_cc_chid);
  68369. +EXPORT_SYMBOL(dwc_cc_cdid);
  68370. +EXPORT_SYMBOL(dwc_cc_name);
  68371. +#endif /* DWC_CCLIB */
  68372. +
  68373. +#ifdef DWC_CRYPTOLIB
  68374. +# ifndef CONFIG_MACH_IPMATE
  68375. +/* Modpow */
  68376. +EXPORT_SYMBOL(dwc_modpow);
  68377. +
  68378. +/* DH */
  68379. +EXPORT_SYMBOL(dwc_dh_modpow);
  68380. +EXPORT_SYMBOL(dwc_dh_derive_keys);
  68381. +EXPORT_SYMBOL(dwc_dh_pk);
  68382. +# endif /* CONFIG_MACH_IPMATE */
  68383. +
  68384. +/* Crypto */
  68385. +EXPORT_SYMBOL(dwc_wusb_aes_encrypt);
  68386. +EXPORT_SYMBOL(dwc_wusb_cmf);
  68387. +EXPORT_SYMBOL(dwc_wusb_prf);
  68388. +EXPORT_SYMBOL(dwc_wusb_fill_ccm_nonce);
  68389. +EXPORT_SYMBOL(dwc_wusb_gen_nonce);
  68390. +EXPORT_SYMBOL(dwc_wusb_gen_key);
  68391. +EXPORT_SYMBOL(dwc_wusb_gen_mic);
  68392. +#endif /* DWC_CRYPTOLIB */
  68393. +
  68394. +/* Notification */
  68395. +#ifdef DWC_NOTIFYLIB
  68396. +EXPORT_SYMBOL(dwc_alloc_notification_manager);
  68397. +EXPORT_SYMBOL(dwc_free_notification_manager);
  68398. +EXPORT_SYMBOL(dwc_register_notifier);
  68399. +EXPORT_SYMBOL(dwc_unregister_notifier);
  68400. +EXPORT_SYMBOL(dwc_add_observer);
  68401. +EXPORT_SYMBOL(dwc_remove_observer);
  68402. +EXPORT_SYMBOL(dwc_notify);
  68403. +#endif
  68404. +
  68405. +/* Memory Debugging Routines */
  68406. +#ifdef DWC_DEBUG_MEMORY
  68407. +EXPORT_SYMBOL(dwc_alloc_debug);
  68408. +EXPORT_SYMBOL(dwc_alloc_atomic_debug);
  68409. +EXPORT_SYMBOL(dwc_free_debug);
  68410. +EXPORT_SYMBOL(dwc_dma_alloc_debug);
  68411. +EXPORT_SYMBOL(dwc_dma_free_debug);
  68412. +#endif
  68413. +
  68414. +EXPORT_SYMBOL(DWC_MEMSET);
  68415. +EXPORT_SYMBOL(DWC_MEMCPY);
  68416. +EXPORT_SYMBOL(DWC_MEMMOVE);
  68417. +EXPORT_SYMBOL(DWC_MEMCMP);
  68418. +EXPORT_SYMBOL(DWC_STRNCMP);
  68419. +EXPORT_SYMBOL(DWC_STRCMP);
  68420. +EXPORT_SYMBOL(DWC_STRLEN);
  68421. +EXPORT_SYMBOL(DWC_STRCPY);
  68422. +EXPORT_SYMBOL(DWC_STRDUP);
  68423. +EXPORT_SYMBOL(DWC_ATOI);
  68424. +EXPORT_SYMBOL(DWC_ATOUI);
  68425. +
  68426. +#ifdef DWC_UTFLIB
  68427. +EXPORT_SYMBOL(DWC_UTF8_TO_UTF16LE);
  68428. +#endif /* DWC_UTFLIB */
  68429. +
  68430. +EXPORT_SYMBOL(DWC_IN_IRQ);
  68431. +EXPORT_SYMBOL(DWC_IN_BH);
  68432. +EXPORT_SYMBOL(DWC_VPRINTF);
  68433. +EXPORT_SYMBOL(DWC_VSNPRINTF);
  68434. +EXPORT_SYMBOL(DWC_PRINTF);
  68435. +EXPORT_SYMBOL(DWC_SPRINTF);
  68436. +EXPORT_SYMBOL(DWC_SNPRINTF);
  68437. +EXPORT_SYMBOL(__DWC_WARN);
  68438. +EXPORT_SYMBOL(__DWC_ERROR);
  68439. +EXPORT_SYMBOL(DWC_EXCEPTION);
  68440. +
  68441. +#ifdef DEBUG
  68442. +EXPORT_SYMBOL(__DWC_DEBUG);
  68443. +#endif
  68444. +
  68445. +EXPORT_SYMBOL(__DWC_DMA_ALLOC);
  68446. +EXPORT_SYMBOL(__DWC_DMA_ALLOC_ATOMIC);
  68447. +EXPORT_SYMBOL(__DWC_DMA_FREE);
  68448. +EXPORT_SYMBOL(__DWC_ALLOC);
  68449. +EXPORT_SYMBOL(__DWC_ALLOC_ATOMIC);
  68450. +EXPORT_SYMBOL(__DWC_FREE);
  68451. +
  68452. +#ifdef DWC_CRYPTOLIB
  68453. +EXPORT_SYMBOL(DWC_RANDOM_BYTES);
  68454. +EXPORT_SYMBOL(DWC_AES_CBC);
  68455. +EXPORT_SYMBOL(DWC_SHA256);
  68456. +EXPORT_SYMBOL(DWC_HMAC_SHA256);
  68457. +#endif
  68458. +
  68459. +EXPORT_SYMBOL(DWC_CPU_TO_LE32);
  68460. +EXPORT_SYMBOL(DWC_CPU_TO_BE32);
  68461. +EXPORT_SYMBOL(DWC_LE32_TO_CPU);
  68462. +EXPORT_SYMBOL(DWC_BE32_TO_CPU);
  68463. +EXPORT_SYMBOL(DWC_CPU_TO_LE16);
  68464. +EXPORT_SYMBOL(DWC_CPU_TO_BE16);
  68465. +EXPORT_SYMBOL(DWC_LE16_TO_CPU);
  68466. +EXPORT_SYMBOL(DWC_BE16_TO_CPU);
  68467. +EXPORT_SYMBOL(DWC_READ_REG32);
  68468. +EXPORT_SYMBOL(DWC_WRITE_REG32);
  68469. +EXPORT_SYMBOL(DWC_MODIFY_REG32);
  68470. +
  68471. +#if 0
  68472. +EXPORT_SYMBOL(DWC_READ_REG64);
  68473. +EXPORT_SYMBOL(DWC_WRITE_REG64);
  68474. +EXPORT_SYMBOL(DWC_MODIFY_REG64);
  68475. +#endif
  68476. +
  68477. +EXPORT_SYMBOL(DWC_SPINLOCK_ALLOC);
  68478. +EXPORT_SYMBOL(DWC_SPINLOCK_FREE);
  68479. +EXPORT_SYMBOL(DWC_SPINLOCK);
  68480. +EXPORT_SYMBOL(DWC_SPINUNLOCK);
  68481. +EXPORT_SYMBOL(DWC_SPINLOCK_IRQSAVE);
  68482. +EXPORT_SYMBOL(DWC_SPINUNLOCK_IRQRESTORE);
  68483. +EXPORT_SYMBOL(DWC_MUTEX_ALLOC);
  68484. +
  68485. +#if (!defined(DWC_LINUX) || !defined(CONFIG_DEBUG_MUTEXES))
  68486. +EXPORT_SYMBOL(DWC_MUTEX_FREE);
  68487. +#endif
  68488. +
  68489. +EXPORT_SYMBOL(DWC_MUTEX_LOCK);
  68490. +EXPORT_SYMBOL(DWC_MUTEX_TRYLOCK);
  68491. +EXPORT_SYMBOL(DWC_MUTEX_UNLOCK);
  68492. +EXPORT_SYMBOL(DWC_UDELAY);
  68493. +EXPORT_SYMBOL(DWC_MDELAY);
  68494. +EXPORT_SYMBOL(DWC_MSLEEP);
  68495. +EXPORT_SYMBOL(DWC_TIME);
  68496. +EXPORT_SYMBOL(DWC_TIMER_ALLOC);
  68497. +EXPORT_SYMBOL(DWC_TIMER_FREE);
  68498. +EXPORT_SYMBOL(DWC_TIMER_SCHEDULE);
  68499. +EXPORT_SYMBOL(DWC_TIMER_CANCEL);
  68500. +EXPORT_SYMBOL(DWC_WAITQ_ALLOC);
  68501. +EXPORT_SYMBOL(DWC_WAITQ_FREE);
  68502. +EXPORT_SYMBOL(DWC_WAITQ_WAIT);
  68503. +EXPORT_SYMBOL(DWC_WAITQ_WAIT_TIMEOUT);
  68504. +EXPORT_SYMBOL(DWC_WAITQ_TRIGGER);
  68505. +EXPORT_SYMBOL(DWC_WAITQ_ABORT);
  68506. +EXPORT_SYMBOL(DWC_THREAD_RUN);
  68507. +EXPORT_SYMBOL(DWC_THREAD_STOP);
  68508. +EXPORT_SYMBOL(DWC_THREAD_SHOULD_STOP);
  68509. +EXPORT_SYMBOL(DWC_TASK_ALLOC);
  68510. +EXPORT_SYMBOL(DWC_TASK_FREE);
  68511. +EXPORT_SYMBOL(DWC_TASK_SCHEDULE);
  68512. +EXPORT_SYMBOL(DWC_WORKQ_WAIT_WORK_DONE);
  68513. +EXPORT_SYMBOL(DWC_WORKQ_ALLOC);
  68514. +EXPORT_SYMBOL(DWC_WORKQ_FREE);
  68515. +EXPORT_SYMBOL(DWC_WORKQ_SCHEDULE);
  68516. +EXPORT_SYMBOL(DWC_WORKQ_SCHEDULE_DELAYED);
  68517. +EXPORT_SYMBOL(DWC_WORKQ_PENDING);
  68518. +
  68519. +static int dwc_common_port_init_module(void)
  68520. +{
  68521. + int result = 0;
  68522. +
  68523. + printk(KERN_DEBUG "Module dwc_common_port init\n" );
  68524. +
  68525. +#ifdef DWC_DEBUG_MEMORY
  68526. + result = dwc_memory_debug_start(NULL);
  68527. + if (result) {
  68528. + printk(KERN_ERR
  68529. + "dwc_memory_debug_start() failed with error %d\n",
  68530. + result);
  68531. + return result;
  68532. + }
  68533. +#endif
  68534. +
  68535. +#ifdef DWC_NOTIFYLIB
  68536. + result = dwc_alloc_notification_manager(NULL, NULL);
  68537. + if (result) {
  68538. + printk(KERN_ERR
  68539. + "dwc_alloc_notification_manager() failed with error %d\n",
  68540. + result);
  68541. + return result;
  68542. + }
  68543. +#endif
  68544. + return result;
  68545. +}
  68546. +
  68547. +static void dwc_common_port_exit_module(void)
  68548. +{
  68549. + printk(KERN_DEBUG "Module dwc_common_port exit\n" );
  68550. +
  68551. +#ifdef DWC_NOTIFYLIB
  68552. + dwc_free_notification_manager();
  68553. +#endif
  68554. +
  68555. +#ifdef DWC_DEBUG_MEMORY
  68556. + dwc_memory_debug_stop();
  68557. +#endif
  68558. +}
  68559. +
  68560. +module_init(dwc_common_port_init_module);
  68561. +module_exit(dwc_common_port_exit_module);
  68562. +
  68563. +MODULE_DESCRIPTION("DWC Common Library - Portable version");
  68564. +MODULE_AUTHOR("Synopsys Inc.");
  68565. +MODULE_LICENSE ("GPL");
  68566. +
  68567. +#endif /* DWC_LIBMODULE */
  68568. diff -Nur linux-3.18.8/drivers/usb/host/dwc_common_port/dwc_common_nbsd.c linux-rpi/drivers/usb/host/dwc_common_port/dwc_common_nbsd.c
  68569. --- linux-3.18.8/drivers/usb/host/dwc_common_port/dwc_common_nbsd.c 1970-01-01 01:00:00.000000000 +0100
  68570. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_common_nbsd.c 2015-03-05 14:40:16.557715806 +0100
  68571. @@ -0,0 +1,1275 @@
  68572. +#include "dwc_os.h"
  68573. +#include "dwc_list.h"
  68574. +
  68575. +#ifdef DWC_CCLIB
  68576. +# include "dwc_cc.h"
  68577. +#endif
  68578. +
  68579. +#ifdef DWC_CRYPTOLIB
  68580. +# include "dwc_modpow.h"
  68581. +# include "dwc_dh.h"
  68582. +# include "dwc_crypto.h"
  68583. +#endif
  68584. +
  68585. +#ifdef DWC_NOTIFYLIB
  68586. +# include "dwc_notifier.h"
  68587. +#endif
  68588. +
  68589. +/* OS-Level Implementations */
  68590. +
  68591. +/* This is the NetBSD 4.0.1 kernel implementation of the DWC platform library. */
  68592. +
  68593. +
  68594. +/* MISC */
  68595. +
  68596. +void *DWC_MEMSET(void *dest, uint8_t byte, uint32_t size)
  68597. +{
  68598. + return memset(dest, byte, size);
  68599. +}
  68600. +
  68601. +void *DWC_MEMCPY(void *dest, void const *src, uint32_t size)
  68602. +{
  68603. + return memcpy(dest, src, size);
  68604. +}
  68605. +
  68606. +void *DWC_MEMMOVE(void *dest, void *src, uint32_t size)
  68607. +{
  68608. + bcopy(src, dest, size);
  68609. + return dest;
  68610. +}
  68611. +
  68612. +int DWC_MEMCMP(void *m1, void *m2, uint32_t size)
  68613. +{
  68614. + return memcmp(m1, m2, size);
  68615. +}
  68616. +
  68617. +int DWC_STRNCMP(void *s1, void *s2, uint32_t size)
  68618. +{
  68619. + return strncmp(s1, s2, size);
  68620. +}
  68621. +
  68622. +int DWC_STRCMP(void *s1, void *s2)
  68623. +{
  68624. + return strcmp(s1, s2);
  68625. +}
  68626. +
  68627. +int DWC_STRLEN(char const *str)
  68628. +{
  68629. + return strlen(str);
  68630. +}
  68631. +
  68632. +char *DWC_STRCPY(char *to, char const *from)
  68633. +{
  68634. + return strcpy(to, from);
  68635. +}
  68636. +
  68637. +char *DWC_STRDUP(char const *str)
  68638. +{
  68639. + int len = DWC_STRLEN(str) + 1;
  68640. + char *new = DWC_ALLOC_ATOMIC(len);
  68641. +
  68642. + if (!new) {
  68643. + return NULL;
  68644. + }
  68645. +
  68646. + DWC_MEMCPY(new, str, len);
  68647. + return new;
  68648. +}
  68649. +
  68650. +int DWC_ATOI(char *str, int32_t *value)
  68651. +{
  68652. + char *end = NULL;
  68653. +
  68654. + /* NetBSD doesn't have 'strtol' in the kernel, but 'strtoul'
  68655. + * should be equivalent on 2's complement machines
  68656. + */
  68657. + *value = strtoul(str, &end, 0);
  68658. + if (*end == '\0') {
  68659. + return 0;
  68660. + }
  68661. +
  68662. + return -1;
  68663. +}
  68664. +
  68665. +int DWC_ATOUI(char *str, uint32_t *value)
  68666. +{
  68667. + char *end = NULL;
  68668. +
  68669. + *value = strtoul(str, &end, 0);
  68670. + if (*end == '\0') {
  68671. + return 0;
  68672. + }
  68673. +
  68674. + return -1;
  68675. +}
  68676. +
  68677. +
  68678. +#ifdef DWC_UTFLIB
  68679. +/* From usbstring.c */
  68680. +
  68681. +int DWC_UTF8_TO_UTF16LE(uint8_t const *s, uint16_t *cp, unsigned len)
  68682. +{
  68683. + int count = 0;
  68684. + u8 c;
  68685. + u16 uchar;
  68686. +
  68687. + /* this insists on correct encodings, though not minimal ones.
  68688. + * BUT it currently rejects legit 4-byte UTF-8 code points,
  68689. + * which need surrogate pairs. (Unicode 3.1 can use them.)
  68690. + */
  68691. + while (len != 0 && (c = (u8) *s++) != 0) {
  68692. + if (unlikely(c & 0x80)) {
  68693. + // 2-byte sequence:
  68694. + // 00000yyyyyxxxxxx = 110yyyyy 10xxxxxx
  68695. + if ((c & 0xe0) == 0xc0) {
  68696. + uchar = (c & 0x1f) << 6;
  68697. +
  68698. + c = (u8) *s++;
  68699. + if ((c & 0xc0) != 0xc0)
  68700. + goto fail;
  68701. + c &= 0x3f;
  68702. + uchar |= c;
  68703. +
  68704. + // 3-byte sequence (most CJKV characters):
  68705. + // zzzzyyyyyyxxxxxx = 1110zzzz 10yyyyyy 10xxxxxx
  68706. + } else if ((c & 0xf0) == 0xe0) {
  68707. + uchar = (c & 0x0f) << 12;
  68708. +
  68709. + c = (u8) *s++;
  68710. + if ((c & 0xc0) != 0xc0)
  68711. + goto fail;
  68712. + c &= 0x3f;
  68713. + uchar |= c << 6;
  68714. +
  68715. + c = (u8) *s++;
  68716. + if ((c & 0xc0) != 0xc0)
  68717. + goto fail;
  68718. + c &= 0x3f;
  68719. + uchar |= c;
  68720. +
  68721. + /* no bogus surrogates */
  68722. + if (0xd800 <= uchar && uchar <= 0xdfff)
  68723. + goto fail;
  68724. +
  68725. + // 4-byte sequence (surrogate pairs, currently rare):
  68726. + // 11101110wwwwzzzzyy + 110111yyyyxxxxxx
  68727. + // = 11110uuu 10uuzzzz 10yyyyyy 10xxxxxx
  68728. + // (uuuuu = wwww + 1)
  68729. + // FIXME accept the surrogate code points (only)
  68730. + } else
  68731. + goto fail;
  68732. + } else
  68733. + uchar = c;
  68734. + put_unaligned (cpu_to_le16 (uchar), cp++);
  68735. + count++;
  68736. + len--;
  68737. + }
  68738. + return count;
  68739. +fail:
  68740. + return -1;
  68741. +}
  68742. +
  68743. +#endif /* DWC_UTFLIB */
  68744. +
  68745. +
  68746. +/* dwc_debug.h */
  68747. +
  68748. +dwc_bool_t DWC_IN_IRQ(void)
  68749. +{
  68750. +// return in_irq();
  68751. + return 0;
  68752. +}
  68753. +
  68754. +dwc_bool_t DWC_IN_BH(void)
  68755. +{
  68756. +// return in_softirq();
  68757. + return 0;
  68758. +}
  68759. +
  68760. +void DWC_VPRINTF(char *format, va_list args)
  68761. +{
  68762. + vprintf(format, args);
  68763. +}
  68764. +
  68765. +int DWC_VSNPRINTF(char *str, int size, char *format, va_list args)
  68766. +{
  68767. + return vsnprintf(str, size, format, args);
  68768. +}
  68769. +
  68770. +void DWC_PRINTF(char *format, ...)
  68771. +{
  68772. + va_list args;
  68773. +
  68774. + va_start(args, format);
  68775. + DWC_VPRINTF(format, args);
  68776. + va_end(args);
  68777. +}
  68778. +
  68779. +int DWC_SPRINTF(char *buffer, char *format, ...)
  68780. +{
  68781. + int retval;
  68782. + va_list args;
  68783. +
  68784. + va_start(args, format);
  68785. + retval = vsprintf(buffer, format, args);
  68786. + va_end(args);
  68787. + return retval;
  68788. +}
  68789. +
  68790. +int DWC_SNPRINTF(char *buffer, int size, char *format, ...)
  68791. +{
  68792. + int retval;
  68793. + va_list args;
  68794. +
  68795. + va_start(args, format);
  68796. + retval = vsnprintf(buffer, size, format, args);
  68797. + va_end(args);
  68798. + return retval;
  68799. +}
  68800. +
  68801. +void __DWC_WARN(char *format, ...)
  68802. +{
  68803. + va_list args;
  68804. +
  68805. + va_start(args, format);
  68806. + DWC_VPRINTF(format, args);
  68807. + va_end(args);
  68808. +}
  68809. +
  68810. +void __DWC_ERROR(char *format, ...)
  68811. +{
  68812. + va_list args;
  68813. +
  68814. + va_start(args, format);
  68815. + DWC_VPRINTF(format, args);
  68816. + va_end(args);
  68817. +}
  68818. +
  68819. +void DWC_EXCEPTION(char *format, ...)
  68820. +{
  68821. + va_list args;
  68822. +
  68823. + va_start(args, format);
  68824. + DWC_VPRINTF(format, args);
  68825. + va_end(args);
  68826. +// BUG_ON(1); ???
  68827. +}
  68828. +
  68829. +#ifdef DEBUG
  68830. +void __DWC_DEBUG(char *format, ...)
  68831. +{
  68832. + va_list args;
  68833. +
  68834. + va_start(args, format);
  68835. + DWC_VPRINTF(format, args);
  68836. + va_end(args);
  68837. +}
  68838. +#endif
  68839. +
  68840. +
  68841. +/* dwc_mem.h */
  68842. +
  68843. +#if 0
  68844. +dwc_pool_t *DWC_DMA_POOL_CREATE(uint32_t size,
  68845. + uint32_t align,
  68846. + uint32_t alloc)
  68847. +{
  68848. + struct dma_pool *pool = dma_pool_create("Pool", NULL,
  68849. + size, align, alloc);
  68850. + return (dwc_pool_t *)pool;
  68851. +}
  68852. +
  68853. +void DWC_DMA_POOL_DESTROY(dwc_pool_t *pool)
  68854. +{
  68855. + dma_pool_destroy((struct dma_pool *)pool);
  68856. +}
  68857. +
  68858. +void *DWC_DMA_POOL_ALLOC(dwc_pool_t *pool, uint64_t *dma_addr)
  68859. +{
  68860. +// return dma_pool_alloc((struct dma_pool *)pool, GFP_KERNEL, dma_addr);
  68861. + return dma_pool_alloc((struct dma_pool *)pool, M_WAITOK, dma_addr);
  68862. +}
  68863. +
  68864. +void *DWC_DMA_POOL_ZALLOC(dwc_pool_t *pool, uint64_t *dma_addr)
  68865. +{
  68866. + void *vaddr = DWC_DMA_POOL_ALLOC(pool, dma_addr);
  68867. + memset(..);
  68868. +}
  68869. +
  68870. +void DWC_DMA_POOL_FREE(dwc_pool_t *pool, void *vaddr, void *daddr)
  68871. +{
  68872. + dma_pool_free(pool, vaddr, daddr);
  68873. +}
  68874. +#endif
  68875. +
  68876. +void *__DWC_DMA_ALLOC(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr)
  68877. +{
  68878. + dwc_dmactx_t *dma = (dwc_dmactx_t *)dma_ctx;
  68879. + int error;
  68880. +
  68881. + error = bus_dmamem_alloc(dma->dma_tag, size, 1, size, dma->segs,
  68882. + sizeof(dma->segs) / sizeof(dma->segs[0]),
  68883. + &dma->nsegs, BUS_DMA_NOWAIT);
  68884. + if (error) {
  68885. + printf("%s: bus_dmamem_alloc(%ju) failed: %d\n", __func__,
  68886. + (uintmax_t)size, error);
  68887. + goto fail_0;
  68888. + }
  68889. +
  68890. + error = bus_dmamem_map(dma->dma_tag, dma->segs, dma->nsegs, size,
  68891. + (caddr_t *)&dma->dma_vaddr,
  68892. + BUS_DMA_NOWAIT | BUS_DMA_COHERENT);
  68893. + if (error) {
  68894. + printf("%s: bus_dmamem_map failed: %d\n", __func__, error);
  68895. + goto fail_1;
  68896. + }
  68897. +
  68898. + error = bus_dmamap_create(dma->dma_tag, size, 1, size, 0,
  68899. + BUS_DMA_NOWAIT, &dma->dma_map);
  68900. + if (error) {
  68901. + printf("%s: bus_dmamap_create failed: %d\n", __func__, error);
  68902. + goto fail_2;
  68903. + }
  68904. +
  68905. + error = bus_dmamap_load(dma->dma_tag, dma->dma_map, dma->dma_vaddr,
  68906. + size, NULL, BUS_DMA_NOWAIT);
  68907. + if (error) {
  68908. + printf("%s: bus_dmamap_load failed: %d\n", __func__, error);
  68909. + goto fail_3;
  68910. + }
  68911. +
  68912. + dma->dma_paddr = (bus_addr_t)dma->segs[0].ds_addr;
  68913. + *dma_addr = dma->dma_paddr;
  68914. + return dma->dma_vaddr;
  68915. +
  68916. +fail_3:
  68917. + bus_dmamap_destroy(dma->dma_tag, dma->dma_map);
  68918. +fail_2:
  68919. + bus_dmamem_unmap(dma->dma_tag, dma->dma_vaddr, size);
  68920. +fail_1:
  68921. + bus_dmamem_free(dma->dma_tag, dma->segs, dma->nsegs);
  68922. +fail_0:
  68923. + dma->dma_map = NULL;
  68924. + dma->dma_vaddr = NULL;
  68925. + dma->nsegs = 0;
  68926. +
  68927. + return NULL;
  68928. +}
  68929. +
  68930. +void __DWC_DMA_FREE(void *dma_ctx, uint32_t size, void *virt_addr, dwc_dma_t dma_addr)
  68931. +{
  68932. + dwc_dmactx_t *dma = (dwc_dmactx_t *)dma_ctx;
  68933. +
  68934. + if (dma->dma_map != NULL) {
  68935. + bus_dmamap_sync(dma->dma_tag, dma->dma_map, 0, size,
  68936. + BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
  68937. + bus_dmamap_unload(dma->dma_tag, dma->dma_map);
  68938. + bus_dmamap_destroy(dma->dma_tag, dma->dma_map);
  68939. + bus_dmamem_unmap(dma->dma_tag, dma->dma_vaddr, size);
  68940. + bus_dmamem_free(dma->dma_tag, dma->segs, dma->nsegs);
  68941. + dma->dma_paddr = 0;
  68942. + dma->dma_map = NULL;
  68943. + dma->dma_vaddr = NULL;
  68944. + dma->nsegs = 0;
  68945. + }
  68946. +}
  68947. +
  68948. +void *__DWC_ALLOC(void *mem_ctx, uint32_t size)
  68949. +{
  68950. + return malloc(size, M_DEVBUF, M_WAITOK | M_ZERO);
  68951. +}
  68952. +
  68953. +void *__DWC_ALLOC_ATOMIC(void *mem_ctx, uint32_t size)
  68954. +{
  68955. + return malloc(size, M_DEVBUF, M_NOWAIT | M_ZERO);
  68956. +}
  68957. +
  68958. +void __DWC_FREE(void *mem_ctx, void *addr)
  68959. +{
  68960. + free(addr, M_DEVBUF);
  68961. +}
  68962. +
  68963. +
  68964. +#ifdef DWC_CRYPTOLIB
  68965. +/* dwc_crypto.h */
  68966. +
  68967. +void DWC_RANDOM_BYTES(uint8_t *buffer, uint32_t length)
  68968. +{
  68969. + get_random_bytes(buffer, length);
  68970. +}
  68971. +
  68972. +int DWC_AES_CBC(uint8_t *message, uint32_t messagelen, uint8_t *key, uint32_t keylen, uint8_t iv[16], uint8_t *out)
  68973. +{
  68974. + struct crypto_blkcipher *tfm;
  68975. + struct blkcipher_desc desc;
  68976. + struct scatterlist sgd;
  68977. + struct scatterlist sgs;
  68978. +
  68979. + tfm = crypto_alloc_blkcipher("cbc(aes)", 0, CRYPTO_ALG_ASYNC);
  68980. + if (tfm == NULL) {
  68981. + printk("failed to load transform for aes CBC\n");
  68982. + return -1;
  68983. + }
  68984. +
  68985. + crypto_blkcipher_setkey(tfm, key, keylen);
  68986. + crypto_blkcipher_set_iv(tfm, iv, 16);
  68987. +
  68988. + sg_init_one(&sgd, out, messagelen);
  68989. + sg_init_one(&sgs, message, messagelen);
  68990. +
  68991. + desc.tfm = tfm;
  68992. + desc.flags = 0;
  68993. +
  68994. + if (crypto_blkcipher_encrypt(&desc, &sgd, &sgs, messagelen)) {
  68995. + crypto_free_blkcipher(tfm);
  68996. + DWC_ERROR("AES CBC encryption failed");
  68997. + return -1;
  68998. + }
  68999. +
  69000. + crypto_free_blkcipher(tfm);
  69001. + return 0;
  69002. +}
  69003. +
  69004. +int DWC_SHA256(uint8_t *message, uint32_t len, uint8_t *out)
  69005. +{
  69006. + struct crypto_hash *tfm;
  69007. + struct hash_desc desc;
  69008. + struct scatterlist sg;
  69009. +
  69010. + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
  69011. + if (IS_ERR(tfm)) {
  69012. + DWC_ERROR("Failed to load transform for sha256: %ld", PTR_ERR(tfm));
  69013. + return 0;
  69014. + }
  69015. + desc.tfm = tfm;
  69016. + desc.flags = 0;
  69017. +
  69018. + sg_init_one(&sg, message, len);
  69019. + crypto_hash_digest(&desc, &sg, len, out);
  69020. + crypto_free_hash(tfm);
  69021. +
  69022. + return 1;
  69023. +}
  69024. +
  69025. +int DWC_HMAC_SHA256(uint8_t *message, uint32_t messagelen,
  69026. + uint8_t *key, uint32_t keylen, uint8_t *out)
  69027. +{
  69028. + struct crypto_hash *tfm;
  69029. + struct hash_desc desc;
  69030. + struct scatterlist sg;
  69031. +
  69032. + tfm = crypto_alloc_hash("hmac(sha256)", 0, CRYPTO_ALG_ASYNC);
  69033. + if (IS_ERR(tfm)) {
  69034. + DWC_ERROR("Failed to load transform for hmac(sha256): %ld", PTR_ERR(tfm));
  69035. + return 0;
  69036. + }
  69037. + desc.tfm = tfm;
  69038. + desc.flags = 0;
  69039. +
  69040. + sg_init_one(&sg, message, messagelen);
  69041. + crypto_hash_setkey(tfm, key, keylen);
  69042. + crypto_hash_digest(&desc, &sg, messagelen, out);
  69043. + crypto_free_hash(tfm);
  69044. +
  69045. + return 1;
  69046. +}
  69047. +
  69048. +#endif /* DWC_CRYPTOLIB */
  69049. +
  69050. +
  69051. +/* Byte Ordering Conversions */
  69052. +
  69053. +uint32_t DWC_CPU_TO_LE32(uint32_t *p)
  69054. +{
  69055. +#ifdef __LITTLE_ENDIAN
  69056. + return *p;
  69057. +#else
  69058. + uint8_t *u_p = (uint8_t *)p;
  69059. +
  69060. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  69061. +#endif
  69062. +}
  69063. +
  69064. +uint32_t DWC_CPU_TO_BE32(uint32_t *p)
  69065. +{
  69066. +#ifdef __BIG_ENDIAN
  69067. + return *p;
  69068. +#else
  69069. + uint8_t *u_p = (uint8_t *)p;
  69070. +
  69071. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  69072. +#endif
  69073. +}
  69074. +
  69075. +uint32_t DWC_LE32_TO_CPU(uint32_t *p)
  69076. +{
  69077. +#ifdef __LITTLE_ENDIAN
  69078. + return *p;
  69079. +#else
  69080. + uint8_t *u_p = (uint8_t *)p;
  69081. +
  69082. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  69083. +#endif
  69084. +}
  69085. +
  69086. +uint32_t DWC_BE32_TO_CPU(uint32_t *p)
  69087. +{
  69088. +#ifdef __BIG_ENDIAN
  69089. + return *p;
  69090. +#else
  69091. + uint8_t *u_p = (uint8_t *)p;
  69092. +
  69093. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  69094. +#endif
  69095. +}
  69096. +
  69097. +uint16_t DWC_CPU_TO_LE16(uint16_t *p)
  69098. +{
  69099. +#ifdef __LITTLE_ENDIAN
  69100. + return *p;
  69101. +#else
  69102. + uint8_t *u_p = (uint8_t *)p;
  69103. + return (u_p[1] | (u_p[0] << 8));
  69104. +#endif
  69105. +}
  69106. +
  69107. +uint16_t DWC_CPU_TO_BE16(uint16_t *p)
  69108. +{
  69109. +#ifdef __BIG_ENDIAN
  69110. + return *p;
  69111. +#else
  69112. + uint8_t *u_p = (uint8_t *)p;
  69113. + return (u_p[1] | (u_p[0] << 8));
  69114. +#endif
  69115. +}
  69116. +
  69117. +uint16_t DWC_LE16_TO_CPU(uint16_t *p)
  69118. +{
  69119. +#ifdef __LITTLE_ENDIAN
  69120. + return *p;
  69121. +#else
  69122. + uint8_t *u_p = (uint8_t *)p;
  69123. + return (u_p[1] | (u_p[0] << 8));
  69124. +#endif
  69125. +}
  69126. +
  69127. +uint16_t DWC_BE16_TO_CPU(uint16_t *p)
  69128. +{
  69129. +#ifdef __BIG_ENDIAN
  69130. + return *p;
  69131. +#else
  69132. + uint8_t *u_p = (uint8_t *)p;
  69133. + return (u_p[1] | (u_p[0] << 8));
  69134. +#endif
  69135. +}
  69136. +
  69137. +
  69138. +/* Registers */
  69139. +
  69140. +uint32_t DWC_READ_REG32(void *io_ctx, uint32_t volatile *reg)
  69141. +{
  69142. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  69143. + bus_size_t ior = (bus_size_t)reg;
  69144. +
  69145. + return bus_space_read_4(io->iot, io->ioh, ior);
  69146. +}
  69147. +
  69148. +#if 0
  69149. +uint64_t DWC_READ_REG64(void *io_ctx, uint64_t volatile *reg)
  69150. +{
  69151. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  69152. + bus_size_t ior = (bus_size_t)reg;
  69153. +
  69154. + return bus_space_read_8(io->iot, io->ioh, ior);
  69155. +}
  69156. +#endif
  69157. +
  69158. +void DWC_WRITE_REG32(void *io_ctx, uint32_t volatile *reg, uint32_t value)
  69159. +{
  69160. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  69161. + bus_size_t ior = (bus_size_t)reg;
  69162. +
  69163. + bus_space_write_4(io->iot, io->ioh, ior, value);
  69164. +}
  69165. +
  69166. +#if 0
  69167. +void DWC_WRITE_REG64(void *io_ctx, uint64_t volatile *reg, uint64_t value)
  69168. +{
  69169. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  69170. + bus_size_t ior = (bus_size_t)reg;
  69171. +
  69172. + bus_space_write_8(io->iot, io->ioh, ior, value);
  69173. +}
  69174. +#endif
  69175. +
  69176. +void DWC_MODIFY_REG32(void *io_ctx, uint32_t volatile *reg, uint32_t clear_mask,
  69177. + uint32_t set_mask)
  69178. +{
  69179. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  69180. + bus_size_t ior = (bus_size_t)reg;
  69181. +
  69182. + bus_space_write_4(io->iot, io->ioh, ior,
  69183. + (bus_space_read_4(io->iot, io->ioh, ior) &
  69184. + ~clear_mask) | set_mask);
  69185. +}
  69186. +
  69187. +#if 0
  69188. +void DWC_MODIFY_REG64(void *io_ctx, uint64_t volatile *reg, uint64_t clear_mask,
  69189. + uint64_t set_mask)
  69190. +{
  69191. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  69192. + bus_size_t ior = (bus_size_t)reg;
  69193. +
  69194. + bus_space_write_8(io->iot, io->ioh, ior,
  69195. + (bus_space_read_8(io->iot, io->ioh, ior) &
  69196. + ~clear_mask) | set_mask);
  69197. +}
  69198. +#endif
  69199. +
  69200. +
  69201. +/* Locking */
  69202. +
  69203. +dwc_spinlock_t *DWC_SPINLOCK_ALLOC(void)
  69204. +{
  69205. + struct simplelock *sl = DWC_ALLOC(sizeof(*sl));
  69206. +
  69207. + if (!sl) {
  69208. + DWC_ERROR("Cannot allocate memory for spinlock");
  69209. + return NULL;
  69210. + }
  69211. +
  69212. + simple_lock_init(sl);
  69213. + return (dwc_spinlock_t *)sl;
  69214. +}
  69215. +
  69216. +void DWC_SPINLOCK_FREE(dwc_spinlock_t *lock)
  69217. +{
  69218. + struct simplelock *sl = (struct simplelock *)lock;
  69219. +
  69220. + DWC_FREE(sl);
  69221. +}
  69222. +
  69223. +void DWC_SPINLOCK(dwc_spinlock_t *lock)
  69224. +{
  69225. + simple_lock((struct simplelock *)lock);
  69226. +}
  69227. +
  69228. +void DWC_SPINUNLOCK(dwc_spinlock_t *lock)
  69229. +{
  69230. + simple_unlock((struct simplelock *)lock);
  69231. +}
  69232. +
  69233. +void DWC_SPINLOCK_IRQSAVE(dwc_spinlock_t *lock, dwc_irqflags_t *flags)
  69234. +{
  69235. + simple_lock((struct simplelock *)lock);
  69236. + *flags = splbio();
  69237. +}
  69238. +
  69239. +void DWC_SPINUNLOCK_IRQRESTORE(dwc_spinlock_t *lock, dwc_irqflags_t flags)
  69240. +{
  69241. + splx(flags);
  69242. + simple_unlock((struct simplelock *)lock);
  69243. +}
  69244. +
  69245. +dwc_mutex_t *DWC_MUTEX_ALLOC(void)
  69246. +{
  69247. + dwc_mutex_t *mutex = DWC_ALLOC(sizeof(struct lock));
  69248. +
  69249. + if (!mutex) {
  69250. + DWC_ERROR("Cannot allocate memory for mutex");
  69251. + return NULL;
  69252. + }
  69253. +
  69254. + lockinit((struct lock *)mutex, 0, "dw3mtx", 0, 0);
  69255. + return mutex;
  69256. +}
  69257. +
  69258. +#if (defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES))
  69259. +#else
  69260. +void DWC_MUTEX_FREE(dwc_mutex_t *mutex)
  69261. +{
  69262. + DWC_FREE(mutex);
  69263. +}
  69264. +#endif
  69265. +
  69266. +void DWC_MUTEX_LOCK(dwc_mutex_t *mutex)
  69267. +{
  69268. + lockmgr((struct lock *)mutex, LK_EXCLUSIVE, NULL);
  69269. +}
  69270. +
  69271. +int DWC_MUTEX_TRYLOCK(dwc_mutex_t *mutex)
  69272. +{
  69273. + int status;
  69274. +
  69275. + status = lockmgr((struct lock *)mutex, LK_EXCLUSIVE | LK_NOWAIT, NULL);
  69276. + return status == 0;
  69277. +}
  69278. +
  69279. +void DWC_MUTEX_UNLOCK(dwc_mutex_t *mutex)
  69280. +{
  69281. + lockmgr((struct lock *)mutex, LK_RELEASE, NULL);
  69282. +}
  69283. +
  69284. +
  69285. +/* Timing */
  69286. +
  69287. +void DWC_UDELAY(uint32_t usecs)
  69288. +{
  69289. + DELAY(usecs);
  69290. +}
  69291. +
  69292. +void DWC_MDELAY(uint32_t msecs)
  69293. +{
  69294. + do {
  69295. + DELAY(1000);
  69296. + } while (--msecs);
  69297. +}
  69298. +
  69299. +void DWC_MSLEEP(uint32_t msecs)
  69300. +{
  69301. + struct timeval tv;
  69302. +
  69303. + tv.tv_sec = msecs / 1000;
  69304. + tv.tv_usec = (msecs - tv.tv_sec * 1000) * 1000;
  69305. + tsleep(&tv, 0, "dw3slp", tvtohz(&tv));
  69306. +}
  69307. +
  69308. +uint32_t DWC_TIME(void)
  69309. +{
  69310. + struct timeval tv;
  69311. +
  69312. + microuptime(&tv); // or getmicrouptime? (less precise, but faster)
  69313. + return tv.tv_sec * 1000 + tv.tv_usec / 1000;
  69314. +}
  69315. +
  69316. +
  69317. +/* Timers */
  69318. +
  69319. +struct dwc_timer {
  69320. + struct callout t;
  69321. + char *name;
  69322. + dwc_spinlock_t *lock;
  69323. + dwc_timer_callback_t cb;
  69324. + void *data;
  69325. +};
  69326. +
  69327. +dwc_timer_t *DWC_TIMER_ALLOC(char *name, dwc_timer_callback_t cb, void *data)
  69328. +{
  69329. + dwc_timer_t *t = DWC_ALLOC(sizeof(*t));
  69330. +
  69331. + if (!t) {
  69332. + DWC_ERROR("Cannot allocate memory for timer");
  69333. + return NULL;
  69334. + }
  69335. +
  69336. + callout_init(&t->t);
  69337. +
  69338. + t->name = DWC_STRDUP(name);
  69339. + if (!t->name) {
  69340. + DWC_ERROR("Cannot allocate memory for timer->name");
  69341. + goto no_name;
  69342. + }
  69343. +
  69344. + t->lock = DWC_SPINLOCK_ALLOC();
  69345. + if (!t->lock) {
  69346. + DWC_ERROR("Cannot allocate memory for timer->lock");
  69347. + goto no_lock;
  69348. + }
  69349. +
  69350. + t->cb = cb;
  69351. + t->data = data;
  69352. +
  69353. + return t;
  69354. +
  69355. + no_lock:
  69356. + DWC_FREE(t->name);
  69357. + no_name:
  69358. + DWC_FREE(t);
  69359. +
  69360. + return NULL;
  69361. +}
  69362. +
  69363. +void DWC_TIMER_FREE(dwc_timer_t *timer)
  69364. +{
  69365. + callout_stop(&timer->t);
  69366. + DWC_SPINLOCK_FREE(timer->lock);
  69367. + DWC_FREE(timer->name);
  69368. + DWC_FREE(timer);
  69369. +}
  69370. +
  69371. +void DWC_TIMER_SCHEDULE(dwc_timer_t *timer, uint32_t time)
  69372. +{
  69373. + struct timeval tv;
  69374. +
  69375. + tv.tv_sec = time / 1000;
  69376. + tv.tv_usec = (time - tv.tv_sec * 1000) * 1000;
  69377. + callout_reset(&timer->t, tvtohz(&tv), timer->cb, timer->data);
  69378. +}
  69379. +
  69380. +void DWC_TIMER_CANCEL(dwc_timer_t *timer)
  69381. +{
  69382. + callout_stop(&timer->t);
  69383. +}
  69384. +
  69385. +
  69386. +/* Wait Queues */
  69387. +
  69388. +struct dwc_waitq {
  69389. + struct simplelock lock;
  69390. + int abort;
  69391. +};
  69392. +
  69393. +dwc_waitq_t *DWC_WAITQ_ALLOC(void)
  69394. +{
  69395. + dwc_waitq_t *wq = DWC_ALLOC(sizeof(*wq));
  69396. +
  69397. + if (!wq) {
  69398. + DWC_ERROR("Cannot allocate memory for waitqueue");
  69399. + return NULL;
  69400. + }
  69401. +
  69402. + simple_lock_init(&wq->lock);
  69403. + wq->abort = 0;
  69404. +
  69405. + return wq;
  69406. +}
  69407. +
  69408. +void DWC_WAITQ_FREE(dwc_waitq_t *wq)
  69409. +{
  69410. + DWC_FREE(wq);
  69411. +}
  69412. +
  69413. +int32_t DWC_WAITQ_WAIT(dwc_waitq_t *wq, dwc_waitq_condition_t cond, void *data)
  69414. +{
  69415. + int ipl;
  69416. + int result = 0;
  69417. +
  69418. + simple_lock(&wq->lock);
  69419. + ipl = splbio();
  69420. +
  69421. + /* Skip the sleep if already aborted or triggered */
  69422. + if (!wq->abort && !cond(data)) {
  69423. + splx(ipl);
  69424. + result = ltsleep(wq, PCATCH, "dw3wat", 0, &wq->lock); // infinite timeout
  69425. + ipl = splbio();
  69426. + }
  69427. +
  69428. + if (result == 0) { // awoken
  69429. + if (wq->abort) {
  69430. + wq->abort = 0;
  69431. + result = -DWC_E_ABORT;
  69432. + } else {
  69433. + result = 0;
  69434. + }
  69435. +
  69436. + splx(ipl);
  69437. + simple_unlock(&wq->lock);
  69438. + } else {
  69439. + wq->abort = 0;
  69440. + splx(ipl);
  69441. + simple_unlock(&wq->lock);
  69442. +
  69443. + if (result == ERESTART) { // signaled - restart
  69444. + result = -DWC_E_RESTART;
  69445. + } else { // signaled - must be EINTR
  69446. + result = -DWC_E_ABORT;
  69447. + }
  69448. + }
  69449. +
  69450. + return result;
  69451. +}
  69452. +
  69453. +int32_t DWC_WAITQ_WAIT_TIMEOUT(dwc_waitq_t *wq, dwc_waitq_condition_t cond,
  69454. + void *data, int32_t msecs)
  69455. +{
  69456. + struct timeval tv, tv1, tv2;
  69457. + int ipl;
  69458. + int result = 0;
  69459. +
  69460. + tv.tv_sec = msecs / 1000;
  69461. + tv.tv_usec = (msecs - tv.tv_sec * 1000) * 1000;
  69462. +
  69463. + simple_lock(&wq->lock);
  69464. + ipl = splbio();
  69465. +
  69466. + /* Skip the sleep if already aborted or triggered */
  69467. + if (!wq->abort && !cond(data)) {
  69468. + splx(ipl);
  69469. + getmicrouptime(&tv1);
  69470. + result = ltsleep(wq, PCATCH, "dw3wto", tvtohz(&tv), &wq->lock);
  69471. + getmicrouptime(&tv2);
  69472. + ipl = splbio();
  69473. + }
  69474. +
  69475. + if (result == 0) { // awoken
  69476. + if (wq->abort) {
  69477. + wq->abort = 0;
  69478. + splx(ipl);
  69479. + simple_unlock(&wq->lock);
  69480. + result = -DWC_E_ABORT;
  69481. + } else {
  69482. + splx(ipl);
  69483. + simple_unlock(&wq->lock);
  69484. +
  69485. + tv2.tv_usec -= tv1.tv_usec;
  69486. + if (tv2.tv_usec < 0) {
  69487. + tv2.tv_usec += 1000000;
  69488. + tv2.tv_sec--;
  69489. + }
  69490. +
  69491. + tv2.tv_sec -= tv1.tv_sec;
  69492. + result = tv2.tv_sec * 1000 + tv2.tv_usec / 1000;
  69493. + result = msecs - result;
  69494. + if (result <= 0)
  69495. + result = 1;
  69496. + }
  69497. + } else {
  69498. + wq->abort = 0;
  69499. + splx(ipl);
  69500. + simple_unlock(&wq->lock);
  69501. +
  69502. + if (result == ERESTART) { // signaled - restart
  69503. + result = -DWC_E_RESTART;
  69504. +
  69505. + } else if (result == EINTR) { // signaled - interrupt
  69506. + result = -DWC_E_ABORT;
  69507. +
  69508. + } else { // timed out
  69509. + result = -DWC_E_TIMEOUT;
  69510. + }
  69511. + }
  69512. +
  69513. + return result;
  69514. +}
  69515. +
  69516. +void DWC_WAITQ_TRIGGER(dwc_waitq_t *wq)
  69517. +{
  69518. + wakeup(wq);
  69519. +}
  69520. +
  69521. +void DWC_WAITQ_ABORT(dwc_waitq_t *wq)
  69522. +{
  69523. + int ipl;
  69524. +
  69525. + simple_lock(&wq->lock);
  69526. + ipl = splbio();
  69527. + wq->abort = 1;
  69528. + wakeup(wq);
  69529. + splx(ipl);
  69530. + simple_unlock(&wq->lock);
  69531. +}
  69532. +
  69533. +
  69534. +/* Threading */
  69535. +
  69536. +struct dwc_thread {
  69537. + struct proc *proc;
  69538. + int abort;
  69539. +};
  69540. +
  69541. +dwc_thread_t *DWC_THREAD_RUN(dwc_thread_function_t func, char *name, void *data)
  69542. +{
  69543. + int retval;
  69544. + dwc_thread_t *thread = DWC_ALLOC(sizeof(*thread));
  69545. +
  69546. + if (!thread) {
  69547. + return NULL;
  69548. + }
  69549. +
  69550. + thread->abort = 0;
  69551. + retval = kthread_create1((void (*)(void *))func, data, &thread->proc,
  69552. + "%s", name);
  69553. + if (retval) {
  69554. + DWC_FREE(thread);
  69555. + return NULL;
  69556. + }
  69557. +
  69558. + return thread;
  69559. +}
  69560. +
  69561. +int DWC_THREAD_STOP(dwc_thread_t *thread)
  69562. +{
  69563. + int retval;
  69564. +
  69565. + thread->abort = 1;
  69566. + retval = tsleep(&thread->abort, 0, "dw3stp", 60 * hz);
  69567. +
  69568. + if (retval == 0) {
  69569. + /* DWC_THREAD_EXIT() will free the thread struct */
  69570. + return 0;
  69571. + }
  69572. +
  69573. + /* NOTE: We leak the thread struct if thread doesn't die */
  69574. +
  69575. + if (retval == EWOULDBLOCK) {
  69576. + return -DWC_E_TIMEOUT;
  69577. + }
  69578. +
  69579. + return -DWC_E_UNKNOWN;
  69580. +}
  69581. +
  69582. +dwc_bool_t DWC_THREAD_SHOULD_STOP(dwc_thread_t *thread)
  69583. +{
  69584. + return thread->abort;
  69585. +}
  69586. +
  69587. +void DWC_THREAD_EXIT(dwc_thread_t *thread)
  69588. +{
  69589. + wakeup(&thread->abort);
  69590. + DWC_FREE(thread);
  69591. + kthread_exit(0);
  69592. +}
  69593. +
  69594. +/* tasklets
  69595. + - Runs in interrupt context (cannot sleep)
  69596. + - Each tasklet runs on a single CPU
  69597. + - Different tasklets can be running simultaneously on different CPUs
  69598. + [ On NetBSD there is no corresponding mechanism, drivers don't have bottom-
  69599. + halves. So we just call the callback directly from DWC_TASK_SCHEDULE() ]
  69600. + */
  69601. +struct dwc_tasklet {
  69602. + dwc_tasklet_callback_t cb;
  69603. + void *data;
  69604. +};
  69605. +
  69606. +static void tasklet_callback(void *data)
  69607. +{
  69608. + dwc_tasklet_t *task = (dwc_tasklet_t *)data;
  69609. +
  69610. + task->cb(task->data);
  69611. +}
  69612. +
  69613. +dwc_tasklet_t *DWC_TASK_ALLOC(char *name, dwc_tasklet_callback_t cb, void *data)
  69614. +{
  69615. + dwc_tasklet_t *task = DWC_ALLOC(sizeof(*task));
  69616. +
  69617. + if (task) {
  69618. + task->cb = cb;
  69619. + task->data = data;
  69620. + } else {
  69621. + DWC_ERROR("Cannot allocate memory for tasklet");
  69622. + }
  69623. +
  69624. + return task;
  69625. +}
  69626. +
  69627. +void DWC_TASK_FREE(dwc_tasklet_t *task)
  69628. +{
  69629. + DWC_FREE(task);
  69630. +}
  69631. +
  69632. +void DWC_TASK_SCHEDULE(dwc_tasklet_t *task)
  69633. +{
  69634. + tasklet_callback(task);
  69635. +}
  69636. +
  69637. +
  69638. +/* workqueues
  69639. + - Runs in process context (can sleep)
  69640. + */
  69641. +typedef struct work_container {
  69642. + dwc_work_callback_t cb;
  69643. + void *data;
  69644. + dwc_workq_t *wq;
  69645. + char *name;
  69646. + int hz;
  69647. + struct work task;
  69648. +} work_container_t;
  69649. +
  69650. +struct dwc_workq {
  69651. + struct workqueue *taskq;
  69652. + dwc_spinlock_t *lock;
  69653. + dwc_waitq_t *waitq;
  69654. + int pending;
  69655. + struct work_container *container;
  69656. +};
  69657. +
  69658. +static void do_work(struct work *task, void *data)
  69659. +{
  69660. + dwc_workq_t *wq = (dwc_workq_t *)data;
  69661. + work_container_t *container = wq->container;
  69662. + dwc_irqflags_t flags;
  69663. +
  69664. + if (container->hz) {
  69665. + tsleep(container, 0, "dw3wrk", container->hz);
  69666. + }
  69667. +
  69668. + container->cb(container->data);
  69669. + DWC_DEBUG("Work done: %s, container=%p", container->name, container);
  69670. +
  69671. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  69672. + if (container->name)
  69673. + DWC_FREE(container->name);
  69674. + DWC_FREE(container);
  69675. + wq->pending--;
  69676. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  69677. + DWC_WAITQ_TRIGGER(wq->waitq);
  69678. +}
  69679. +
  69680. +static int work_done(void *data)
  69681. +{
  69682. + dwc_workq_t *workq = (dwc_workq_t *)data;
  69683. +
  69684. + return workq->pending == 0;
  69685. +}
  69686. +
  69687. +int DWC_WORKQ_WAIT_WORK_DONE(dwc_workq_t *workq, int timeout)
  69688. +{
  69689. + return DWC_WAITQ_WAIT_TIMEOUT(workq->waitq, work_done, workq, timeout);
  69690. +}
  69691. +
  69692. +dwc_workq_t *DWC_WORKQ_ALLOC(char *name)
  69693. +{
  69694. + int result;
  69695. + dwc_workq_t *wq = DWC_ALLOC(sizeof(*wq));
  69696. +
  69697. + if (!wq) {
  69698. + DWC_ERROR("Cannot allocate memory for workqueue");
  69699. + return NULL;
  69700. + }
  69701. +
  69702. + result = workqueue_create(&wq->taskq, name, do_work, wq, 0 /*PWAIT*/,
  69703. + IPL_BIO, 0);
  69704. + if (result) {
  69705. + DWC_ERROR("Cannot create workqueue");
  69706. + goto no_taskq;
  69707. + }
  69708. +
  69709. + wq->pending = 0;
  69710. +
  69711. + wq->lock = DWC_SPINLOCK_ALLOC();
  69712. + if (!wq->lock) {
  69713. + DWC_ERROR("Cannot allocate memory for spinlock");
  69714. + goto no_lock;
  69715. + }
  69716. +
  69717. + wq->waitq = DWC_WAITQ_ALLOC();
  69718. + if (!wq->waitq) {
  69719. + DWC_ERROR("Cannot allocate memory for waitqueue");
  69720. + goto no_waitq;
  69721. + }
  69722. +
  69723. + return wq;
  69724. +
  69725. + no_waitq:
  69726. + DWC_SPINLOCK_FREE(wq->lock);
  69727. + no_lock:
  69728. + workqueue_destroy(wq->taskq);
  69729. + no_taskq:
  69730. + DWC_FREE(wq);
  69731. +
  69732. + return NULL;
  69733. +}
  69734. +
  69735. +void DWC_WORKQ_FREE(dwc_workq_t *wq)
  69736. +{
  69737. +#ifdef DEBUG
  69738. + dwc_irqflags_t flags;
  69739. +
  69740. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  69741. +
  69742. + if (wq->pending != 0) {
  69743. + struct work_container *container = wq->container;
  69744. +
  69745. + DWC_ERROR("Destroying work queue with pending work");
  69746. +
  69747. + if (container && container->name) {
  69748. + DWC_ERROR("Work %s still pending", container->name);
  69749. + }
  69750. + }
  69751. +
  69752. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  69753. +#endif
  69754. + DWC_WAITQ_FREE(wq->waitq);
  69755. + DWC_SPINLOCK_FREE(wq->lock);
  69756. + workqueue_destroy(wq->taskq);
  69757. + DWC_FREE(wq);
  69758. +}
  69759. +
  69760. +void DWC_WORKQ_SCHEDULE(dwc_workq_t *wq, dwc_work_callback_t cb, void *data,
  69761. + char *format, ...)
  69762. +{
  69763. + dwc_irqflags_t flags;
  69764. + work_container_t *container;
  69765. + static char name[128];
  69766. + va_list args;
  69767. +
  69768. + va_start(args, format);
  69769. + DWC_VSNPRINTF(name, 128, format, args);
  69770. + va_end(args);
  69771. +
  69772. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  69773. + wq->pending++;
  69774. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  69775. + DWC_WAITQ_TRIGGER(wq->waitq);
  69776. +
  69777. + container = DWC_ALLOC_ATOMIC(sizeof(*container));
  69778. + if (!container) {
  69779. + DWC_ERROR("Cannot allocate memory for container");
  69780. + return;
  69781. + }
  69782. +
  69783. + container->name = DWC_STRDUP(name);
  69784. + if (!container->name) {
  69785. + DWC_ERROR("Cannot allocate memory for container->name");
  69786. + DWC_FREE(container);
  69787. + return;
  69788. + }
  69789. +
  69790. + container->cb = cb;
  69791. + container->data = data;
  69792. + container->wq = wq;
  69793. + container->hz = 0;
  69794. + wq->container = container;
  69795. +
  69796. + DWC_DEBUG("Queueing work: %s, container=%p", container->name, container);
  69797. + workqueue_enqueue(wq->taskq, &container->task);
  69798. +}
  69799. +
  69800. +void DWC_WORKQ_SCHEDULE_DELAYED(dwc_workq_t *wq, dwc_work_callback_t cb,
  69801. + void *data, uint32_t time, char *format, ...)
  69802. +{
  69803. + dwc_irqflags_t flags;
  69804. + work_container_t *container;
  69805. + static char name[128];
  69806. + struct timeval tv;
  69807. + va_list args;
  69808. +
  69809. + va_start(args, format);
  69810. + DWC_VSNPRINTF(name, 128, format, args);
  69811. + va_end(args);
  69812. +
  69813. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  69814. + wq->pending++;
  69815. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  69816. + DWC_WAITQ_TRIGGER(wq->waitq);
  69817. +
  69818. + container = DWC_ALLOC_ATOMIC(sizeof(*container));
  69819. + if (!container) {
  69820. + DWC_ERROR("Cannot allocate memory for container");
  69821. + return;
  69822. + }
  69823. +
  69824. + container->name = DWC_STRDUP(name);
  69825. + if (!container->name) {
  69826. + DWC_ERROR("Cannot allocate memory for container->name");
  69827. + DWC_FREE(container);
  69828. + return;
  69829. + }
  69830. +
  69831. + container->cb = cb;
  69832. + container->data = data;
  69833. + container->wq = wq;
  69834. + tv.tv_sec = time / 1000;
  69835. + tv.tv_usec = (time - tv.tv_sec * 1000) * 1000;
  69836. + container->hz = tvtohz(&tv);
  69837. + wq->container = container;
  69838. +
  69839. + DWC_DEBUG("Queueing work: %s, container=%p", container->name, container);
  69840. + workqueue_enqueue(wq->taskq, &container->task);
  69841. +}
  69842. +
  69843. +int DWC_WORKQ_PENDING(dwc_workq_t *wq)
  69844. +{
  69845. + return wq->pending;
  69846. +}
  69847. diff -Nur linux-3.18.8/drivers/usb/host/dwc_common_port/dwc_crypto.c linux-rpi/drivers/usb/host/dwc_common_port/dwc_crypto.c
  69848. --- linux-3.18.8/drivers/usb/host/dwc_common_port/dwc_crypto.c 1970-01-01 01:00:00.000000000 +0100
  69849. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_crypto.c 2015-03-05 14:40:16.557715806 +0100
  69850. @@ -0,0 +1,308 @@
  69851. +/* =========================================================================
  69852. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_crypto.c $
  69853. + * $Revision: #5 $
  69854. + * $Date: 2010/09/28 $
  69855. + * $Change: 1596182 $
  69856. + *
  69857. + * Synopsys Portability Library Software and documentation
  69858. + * (hereinafter, "Software") is an Unsupported proprietary work of
  69859. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  69860. + * between Synopsys and you.
  69861. + *
  69862. + * The Software IS NOT an item of Licensed Software or Licensed Product
  69863. + * under any End User Software License Agreement or Agreement for
  69864. + * Licensed Product with Synopsys or any supplement thereto. You are
  69865. + * permitted to use and redistribute this Software in source and binary
  69866. + * forms, with or without modification, provided that redistributions
  69867. + * of source code must retain this notice. You may not view, use,
  69868. + * disclose, copy or distribute this file or any information contained
  69869. + * herein except pursuant to this license grant from Synopsys. If you
  69870. + * do not agree with this notice, including the disclaimer below, then
  69871. + * you are not authorized to use the Software.
  69872. + *
  69873. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  69874. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  69875. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  69876. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  69877. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  69878. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  69879. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  69880. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  69881. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  69882. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  69883. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  69884. + * DAMAGE.
  69885. + * ========================================================================= */
  69886. +
  69887. +/** @file
  69888. + * This file contains the WUSB cryptographic routines.
  69889. + */
  69890. +
  69891. +#ifdef DWC_CRYPTOLIB
  69892. +
  69893. +#include "dwc_crypto.h"
  69894. +#include "usb.h"
  69895. +
  69896. +#ifdef DEBUG
  69897. +static inline void dump_bytes(char *name, uint8_t *bytes, int len)
  69898. +{
  69899. + int i;
  69900. + DWC_PRINTF("%s: ", name);
  69901. + for (i=0; i<len; i++) {
  69902. + DWC_PRINTF("%02x ", bytes[i]);
  69903. + }
  69904. + DWC_PRINTF("\n");
  69905. +}
  69906. +#else
  69907. +#define dump_bytes(x...)
  69908. +#endif
  69909. +
  69910. +/* Display a block */
  69911. +void show_block(const u8 *blk, const char *prefix, const char *suffix, int a)
  69912. +{
  69913. +#ifdef DWC_DEBUG_CRYPTO
  69914. + int i, blksize = 16;
  69915. +
  69916. + DWC_DEBUG("%s", prefix);
  69917. +
  69918. + if (suffix == NULL) {
  69919. + suffix = "\n";
  69920. + blksize = a;
  69921. + }
  69922. +
  69923. + for (i = 0; i < blksize; i++)
  69924. + DWC_PRINT("%02x%s", *blk++, ((i & 3) == 3) ? " " : " ");
  69925. + DWC_PRINT(suffix);
  69926. +#endif
  69927. +}
  69928. +
  69929. +/**
  69930. + * Encrypts an array of bytes using the AES encryption engine.
  69931. + * If <code>dst</code> == <code>src</code>, then the bytes will be encrypted
  69932. + * in-place.
  69933. + *
  69934. + * @return 0 on success, negative error code on error.
  69935. + */
  69936. +int dwc_wusb_aes_encrypt(u8 *src, u8 *key, u8 *dst)
  69937. +{
  69938. + u8 block_t[16];
  69939. + DWC_MEMSET(block_t, 0, 16);
  69940. +
  69941. + return DWC_AES_CBC(src, 16, key, 16, block_t, dst);
  69942. +}
  69943. +
  69944. +/**
  69945. + * The CCM-MAC-FUNCTION described in section 6.5 of the WUSB spec.
  69946. + * This function takes a data string and returns the encrypted CBC
  69947. + * Counter-mode MIC.
  69948. + *
  69949. + * @param key The 128-bit symmetric key.
  69950. + * @param nonce The CCM nonce.
  69951. + * @param label The unique 14-byte ASCII text label.
  69952. + * @param bytes The byte array to be encrypted.
  69953. + * @param len Length of the byte array.
  69954. + * @param result Byte array to receive the 8-byte encrypted MIC.
  69955. + */
  69956. +void dwc_wusb_cmf(u8 *key, u8 *nonce,
  69957. + char *label, u8 *bytes, int len, u8 *result)
  69958. +{
  69959. + u8 block_m[16];
  69960. + u8 block_x[16];
  69961. + u8 block_t[8];
  69962. + int idx, blkNum;
  69963. + u16 la = (u16)(len + 14);
  69964. +
  69965. + /* Set the AES-128 key */
  69966. + //dwc_aes_setkey(tfm, key, 16);
  69967. +
  69968. + /* Fill block B0 from flags = 0x59, N, and l(m) = 0 */
  69969. + block_m[0] = 0x59;
  69970. + for (idx = 0; idx < 13; idx++)
  69971. + block_m[idx + 1] = nonce[idx];
  69972. + block_m[14] = 0;
  69973. + block_m[15] = 0;
  69974. +
  69975. + /* Produce the CBC IV */
  69976. + dwc_wusb_aes_encrypt(block_m, key, block_x);
  69977. + show_block(block_m, "CBC IV in: ", "\n", 0);
  69978. + show_block(block_x, "CBC IV out:", "\n", 0);
  69979. +
  69980. + /* Fill block B1 from l(a) = Blen + 14, and A */
  69981. + block_x[0] ^= (u8)(la >> 8);
  69982. + block_x[1] ^= (u8)la;
  69983. + for (idx = 0; idx < 14; idx++)
  69984. + block_x[idx + 2] ^= label[idx];
  69985. + show_block(block_x, "After xor: ", "b1\n", 16);
  69986. +
  69987. + dwc_wusb_aes_encrypt(block_x, key, block_x);
  69988. + show_block(block_x, "After AES: ", "b1\n", 16);
  69989. +
  69990. + idx = 0;
  69991. + blkNum = 0;
  69992. +
  69993. + /* Fill remaining blocks with B */
  69994. + while (len-- > 0) {
  69995. + block_x[idx] ^= *bytes++;
  69996. + if (++idx >= 16) {
  69997. + idx = 0;
  69998. + show_block(block_x, "After xor: ", "\n", blkNum);
  69999. + dwc_wusb_aes_encrypt(block_x, key, block_x);
  70000. + show_block(block_x, "After AES: ", "\n", blkNum);
  70001. + blkNum++;
  70002. + }
  70003. + }
  70004. +
  70005. + /* Handle partial last block */
  70006. + if (idx > 0) {
  70007. + show_block(block_x, "After xor: ", "\n", blkNum);
  70008. + dwc_wusb_aes_encrypt(block_x, key, block_x);
  70009. + show_block(block_x, "After AES: ", "\n", blkNum);
  70010. + }
  70011. +
  70012. + /* Save the MIC tag */
  70013. + DWC_MEMCPY(block_t, block_x, 8);
  70014. + show_block(block_t, "MIC tag : ", NULL, 8);
  70015. +
  70016. + /* Fill block A0 from flags = 0x01, N, and counter = 0 */
  70017. + block_m[0] = 0x01;
  70018. + block_m[14] = 0;
  70019. + block_m[15] = 0;
  70020. +
  70021. + /* Encrypt the counter */
  70022. + dwc_wusb_aes_encrypt(block_m, key, block_x);
  70023. + show_block(block_x, "CTR[MIC] : ", NULL, 8);
  70024. +
  70025. + /* XOR with MIC tag */
  70026. + for (idx = 0; idx < 8; idx++) {
  70027. + block_t[idx] ^= block_x[idx];
  70028. + }
  70029. +
  70030. + /* Return result to caller */
  70031. + DWC_MEMCPY(result, block_t, 8);
  70032. + show_block(result, "CCM-MIC : ", NULL, 8);
  70033. +
  70034. +}
  70035. +
  70036. +/**
  70037. + * The PRF function described in section 6.5 of the WUSB spec. This function
  70038. + * concatenates MIC values returned from dwc_cmf() to create a value of
  70039. + * the requested length.
  70040. + *
  70041. + * @param prf_len Length of the PRF function in bits (64, 128, or 256).
  70042. + * @param key, nonce, label, bytes, len Same as for dwc_cmf().
  70043. + * @param result Byte array to receive the result.
  70044. + */
  70045. +void dwc_wusb_prf(int prf_len, u8 *key,
  70046. + u8 *nonce, char *label, u8 *bytes, int len, u8 *result)
  70047. +{
  70048. + int i;
  70049. +
  70050. + nonce[0] = 0;
  70051. + for (i = 0; i < prf_len >> 6; i++, nonce[0]++) {
  70052. + dwc_wusb_cmf(key, nonce, label, bytes, len, result);
  70053. + result += 8;
  70054. + }
  70055. +}
  70056. +
  70057. +/**
  70058. + * Fills in CCM Nonce per the WUSB spec.
  70059. + *
  70060. + * @param[in] haddr Host address.
  70061. + * @param[in] daddr Device address.
  70062. + * @param[in] tkid Session Key(PTK) identifier.
  70063. + * @param[out] nonce Pointer to where the CCM Nonce output is to be written.
  70064. + */
  70065. +void dwc_wusb_fill_ccm_nonce(uint16_t haddr, uint16_t daddr, uint8_t *tkid,
  70066. + uint8_t *nonce)
  70067. +{
  70068. +
  70069. + DWC_DEBUG("%s %x %x\n", __func__, daddr, haddr);
  70070. +
  70071. + DWC_MEMSET(&nonce[0], 0, 16);
  70072. +
  70073. + DWC_MEMCPY(&nonce[6], tkid, 3);
  70074. + nonce[9] = daddr & 0xFF;
  70075. + nonce[10] = (daddr >> 8) & 0xFF;
  70076. + nonce[11] = haddr & 0xFF;
  70077. + nonce[12] = (haddr >> 8) & 0xFF;
  70078. +
  70079. + dump_bytes("CCM nonce", nonce, 16);
  70080. +}
  70081. +
  70082. +/**
  70083. + * Generates a 16-byte cryptographic-grade random number for the Host/Device
  70084. + * Nonce.
  70085. + */
  70086. +void dwc_wusb_gen_nonce(uint16_t addr, uint8_t *nonce)
  70087. +{
  70088. + uint8_t inonce[16];
  70089. + uint32_t temp[4];
  70090. +
  70091. + /* Fill in the Nonce */
  70092. + DWC_MEMSET(&inonce[0], 0, sizeof(inonce));
  70093. + inonce[9] = addr & 0xFF;
  70094. + inonce[10] = (addr >> 8) & 0xFF;
  70095. + inonce[11] = inonce[9];
  70096. + inonce[12] = inonce[10];
  70097. +
  70098. + /* Collect "randomness samples" */
  70099. + DWC_RANDOM_BYTES((uint8_t *)temp, 16);
  70100. +
  70101. + dwc_wusb_prf_128((uint8_t *)temp, nonce,
  70102. + "Random Numbers", (uint8_t *)temp, sizeof(temp),
  70103. + nonce);
  70104. +}
  70105. +
  70106. +/**
  70107. + * Generates the Session Key (PTK) and Key Confirmation Key (KCK) per the
  70108. + * WUSB spec.
  70109. + *
  70110. + * @param[in] ccm_nonce Pointer to CCM Nonce.
  70111. + * @param[in] mk Master Key to derive the session from
  70112. + * @param[in] hnonce Pointer to Host Nonce.
  70113. + * @param[in] dnonce Pointer to Device Nonce.
  70114. + * @param[out] kck Pointer to where the KCK output is to be written.
  70115. + * @param[out] ptk Pointer to where the PTK output is to be written.
  70116. + */
  70117. +void dwc_wusb_gen_key(uint8_t *ccm_nonce, uint8_t *mk, uint8_t *hnonce,
  70118. + uint8_t *dnonce, uint8_t *kck, uint8_t *ptk)
  70119. +{
  70120. + uint8_t idata[32];
  70121. + uint8_t odata[32];
  70122. +
  70123. + dump_bytes("ck", mk, 16);
  70124. + dump_bytes("hnonce", hnonce, 16);
  70125. + dump_bytes("dnonce", dnonce, 16);
  70126. +
  70127. + /* The data is the HNonce and DNonce concatenated */
  70128. + DWC_MEMCPY(&idata[0], hnonce, 16);
  70129. + DWC_MEMCPY(&idata[16], dnonce, 16);
  70130. +
  70131. + dwc_wusb_prf_256(mk, ccm_nonce, "Pair-wise keys", idata, 32, odata);
  70132. +
  70133. + /* Low 16 bytes of the result is the KCK, high 16 is the PTK */
  70134. + DWC_MEMCPY(kck, &odata[0], 16);
  70135. + DWC_MEMCPY(ptk, &odata[16], 16);
  70136. +
  70137. + dump_bytes("kck", kck, 16);
  70138. + dump_bytes("ptk", ptk, 16);
  70139. +}
  70140. +
  70141. +/**
  70142. + * Generates the Message Integrity Code over the Handshake data per the
  70143. + * WUSB spec.
  70144. + *
  70145. + * @param ccm_nonce Pointer to CCM Nonce.
  70146. + * @param kck Pointer to Key Confirmation Key.
  70147. + * @param data Pointer to Handshake data to be checked.
  70148. + * @param mic Pointer to where the MIC output is to be written.
  70149. + */
  70150. +void dwc_wusb_gen_mic(uint8_t *ccm_nonce, uint8_t *kck,
  70151. + uint8_t *data, uint8_t *mic)
  70152. +{
  70153. +
  70154. + dwc_wusb_prf_64(kck, ccm_nonce, "out-of-bandMIC",
  70155. + data, WUSB_HANDSHAKE_LEN_FOR_MIC, mic);
  70156. +}
  70157. +
  70158. +#endif /* DWC_CRYPTOLIB */
  70159. diff -Nur linux-3.18.8/drivers/usb/host/dwc_common_port/dwc_crypto.h linux-rpi/drivers/usb/host/dwc_common_port/dwc_crypto.h
  70160. --- linux-3.18.8/drivers/usb/host/dwc_common_port/dwc_crypto.h 1970-01-01 01:00:00.000000000 +0100
  70161. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_crypto.h 2015-03-05 14:40:16.557715806 +0100
  70162. @@ -0,0 +1,111 @@
  70163. +/* =========================================================================
  70164. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_crypto.h $
  70165. + * $Revision: #3 $
  70166. + * $Date: 2010/09/28 $
  70167. + * $Change: 1596182 $
  70168. + *
  70169. + * Synopsys Portability Library Software and documentation
  70170. + * (hereinafter, "Software") is an Unsupported proprietary work of
  70171. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  70172. + * between Synopsys and you.
  70173. + *
  70174. + * The Software IS NOT an item of Licensed Software or Licensed Product
  70175. + * under any End User Software License Agreement or Agreement for
  70176. + * Licensed Product with Synopsys or any supplement thereto. You are
  70177. + * permitted to use and redistribute this Software in source and binary
  70178. + * forms, with or without modification, provided that redistributions
  70179. + * of source code must retain this notice. You may not view, use,
  70180. + * disclose, copy or distribute this file or any information contained
  70181. + * herein except pursuant to this license grant from Synopsys. If you
  70182. + * do not agree with this notice, including the disclaimer below, then
  70183. + * you are not authorized to use the Software.
  70184. + *
  70185. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  70186. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  70187. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  70188. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  70189. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  70190. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  70191. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  70192. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  70193. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  70194. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  70195. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  70196. + * DAMAGE.
  70197. + * ========================================================================= */
  70198. +
  70199. +#ifndef _DWC_CRYPTO_H_
  70200. +#define _DWC_CRYPTO_H_
  70201. +
  70202. +#ifdef __cplusplus
  70203. +extern "C" {
  70204. +#endif
  70205. +
  70206. +/** @file
  70207. + *
  70208. + * This file contains declarations for the WUSB Cryptographic routines as
  70209. + * defined in the WUSB spec. They are only to be used internally by the DWC UWB
  70210. + * modules.
  70211. + */
  70212. +
  70213. +#include "dwc_os.h"
  70214. +
  70215. +int dwc_wusb_aes_encrypt(u8 *src, u8 *key, u8 *dst);
  70216. +
  70217. +void dwc_wusb_cmf(u8 *key, u8 *nonce,
  70218. + char *label, u8 *bytes, int len, u8 *result);
  70219. +void dwc_wusb_prf(int prf_len, u8 *key,
  70220. + u8 *nonce, char *label, u8 *bytes, int len, u8 *result);
  70221. +
  70222. +/**
  70223. + * The PRF-64 function described in section 6.5 of the WUSB spec.
  70224. + *
  70225. + * @param key, nonce, label, bytes, len, result Same as for dwc_prf().
  70226. + */
  70227. +static inline void dwc_wusb_prf_64(u8 *key, u8 *nonce,
  70228. + char *label, u8 *bytes, int len, u8 *result)
  70229. +{
  70230. + dwc_wusb_prf(64, key, nonce, label, bytes, len, result);
  70231. +}
  70232. +
  70233. +/**
  70234. + * The PRF-128 function described in section 6.5 of the WUSB spec.
  70235. + *
  70236. + * @param key, nonce, label, bytes, len, result Same as for dwc_prf().
  70237. + */
  70238. +static inline void dwc_wusb_prf_128(u8 *key, u8 *nonce,
  70239. + char *label, u8 *bytes, int len, u8 *result)
  70240. +{
  70241. + dwc_wusb_prf(128, key, nonce, label, bytes, len, result);
  70242. +}
  70243. +
  70244. +/**
  70245. + * The PRF-256 function described in section 6.5 of the WUSB spec.
  70246. + *
  70247. + * @param key, nonce, label, bytes, len, result Same as for dwc_prf().
  70248. + */
  70249. +static inline void dwc_wusb_prf_256(u8 *key, u8 *nonce,
  70250. + char *label, u8 *bytes, int len, u8 *result)
  70251. +{
  70252. + dwc_wusb_prf(256, key, nonce, label, bytes, len, result);
  70253. +}
  70254. +
  70255. +
  70256. +void dwc_wusb_fill_ccm_nonce(uint16_t haddr, uint16_t daddr, uint8_t *tkid,
  70257. + uint8_t *nonce);
  70258. +void dwc_wusb_gen_nonce(uint16_t addr,
  70259. + uint8_t *nonce);
  70260. +
  70261. +void dwc_wusb_gen_key(uint8_t *ccm_nonce, uint8_t *mk,
  70262. + uint8_t *hnonce, uint8_t *dnonce,
  70263. + uint8_t *kck, uint8_t *ptk);
  70264. +
  70265. +
  70266. +void dwc_wusb_gen_mic(uint8_t *ccm_nonce, uint8_t
  70267. + *kck, uint8_t *data, uint8_t *mic);
  70268. +
  70269. +#ifdef __cplusplus
  70270. +}
  70271. +#endif
  70272. +
  70273. +#endif /* _DWC_CRYPTO_H_ */
  70274. diff -Nur linux-3.18.8/drivers/usb/host/dwc_common_port/dwc_dh.c linux-rpi/drivers/usb/host/dwc_common_port/dwc_dh.c
  70275. --- linux-3.18.8/drivers/usb/host/dwc_common_port/dwc_dh.c 1970-01-01 01:00:00.000000000 +0100
  70276. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_dh.c 2015-03-05 14:40:16.557715806 +0100
  70277. @@ -0,0 +1,291 @@
  70278. +/* =========================================================================
  70279. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_dh.c $
  70280. + * $Revision: #3 $
  70281. + * $Date: 2010/09/28 $
  70282. + * $Change: 1596182 $
  70283. + *
  70284. + * Synopsys Portability Library Software and documentation
  70285. + * (hereinafter, "Software") is an Unsupported proprietary work of
  70286. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  70287. + * between Synopsys and you.
  70288. + *
  70289. + * The Software IS NOT an item of Licensed Software or Licensed Product
  70290. + * under any End User Software License Agreement or Agreement for
  70291. + * Licensed Product with Synopsys or any supplement thereto. You are
  70292. + * permitted to use and redistribute this Software in source and binary
  70293. + * forms, with or without modification, provided that redistributions
  70294. + * of source code must retain this notice. You may not view, use,
  70295. + * disclose, copy or distribute this file or any information contained
  70296. + * herein except pursuant to this license grant from Synopsys. If you
  70297. + * do not agree with this notice, including the disclaimer below, then
  70298. + * you are not authorized to use the Software.
  70299. + *
  70300. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  70301. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  70302. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  70303. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  70304. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  70305. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  70306. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  70307. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  70308. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  70309. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  70310. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  70311. + * DAMAGE.
  70312. + * ========================================================================= */
  70313. +#ifdef DWC_CRYPTOLIB
  70314. +
  70315. +#ifndef CONFIG_MACH_IPMATE
  70316. +
  70317. +#include "dwc_dh.h"
  70318. +#include "dwc_modpow.h"
  70319. +
  70320. +#ifdef DEBUG
  70321. +/* This function prints out a buffer in the format described in the Association
  70322. + * Model specification. */
  70323. +static void dh_dump(char *str, void *_num, int len)
  70324. +{
  70325. + uint8_t *num = _num;
  70326. + int i;
  70327. + DWC_PRINTF("%s\n", str);
  70328. + for (i = 0; i < len; i ++) {
  70329. + DWC_PRINTF("%02x", num[i]);
  70330. + if (((i + 1) % 2) == 0) DWC_PRINTF(" ");
  70331. + if (((i + 1) % 26) == 0) DWC_PRINTF("\n");
  70332. + }
  70333. +
  70334. + DWC_PRINTF("\n");
  70335. +}
  70336. +#else
  70337. +#define dh_dump(_x...) do {; } while(0)
  70338. +#endif
  70339. +
  70340. +/* Constant g value */
  70341. +static __u32 dh_g[] = {
  70342. + 0x02000000,
  70343. +};
  70344. +
  70345. +/* Constant p value */
  70346. +static __u32 dh_p[] = {
  70347. + 0xFFFFFFFF, 0xFFFFFFFF, 0xA2DA0FC9, 0x34C26821, 0x8B62C6C4, 0xD11CDC80, 0x084E0229, 0x74CC678A,
  70348. + 0xA6BE0B02, 0x229B133B, 0x79084A51, 0xDD04348E, 0xB31995EF, 0x1B433ACD, 0x6D0A2B30, 0x37145FF2,
  70349. + 0x6D35E14F, 0x45C2516D, 0x76B585E4, 0xC67E5E62, 0xE9424CF4, 0x6BED37A6, 0xB65CFF0B, 0xEDB706F4,
  70350. + 0xFB6B38EE, 0xA59F895A, 0x11249FAE, 0xE61F4B7C, 0x51662849, 0x3D5BE4EC, 0xB87C00C2, 0x05BF63A1,
  70351. + 0x3648DA98, 0x9AD3551C, 0xA83F1669, 0x5FCF24FD, 0x235D6583, 0x96ADA3DC, 0x56F3621C, 0xBB528520,
  70352. + 0x0729D59E, 0x6D969670, 0x4E350C67, 0x0498BC4A, 0x086C74F1, 0x7C2118CA, 0x465E9032, 0x3BCE362E,
  70353. + 0x2C779EE3, 0x03860E18, 0xA283279B, 0x8FA207EC, 0xF05DC5B5, 0xC9524C6F, 0xF6CB2BDE, 0x18175895,
  70354. + 0x7C499539, 0xE56A95EA, 0x1826D215, 0x1005FA98, 0x5A8E7215, 0x2DC4AA8A, 0x0D1733AD, 0x337A5004,
  70355. + 0xAB2155A8, 0x64BA1CDF, 0x0485FBEC, 0x0AEFDB58, 0x5771EA8A, 0x7D0C065D, 0x850F97B3, 0xC7E4E1A6,
  70356. + 0x8CAEF5AB, 0xD73309DB, 0xE0948C1E, 0x9D61254A, 0x26D2E3CE, 0x6BEED21A, 0x06FA2FF1, 0x64088AD9,
  70357. + 0x730276D8, 0x646AC83E, 0x182B1F52, 0x0C207B17, 0x5717E1BB, 0x6C5D617A, 0xC0880977, 0xE246D9BA,
  70358. + 0xA04FE208, 0x31ABE574, 0xFC5BDB43, 0x8E10FDE0, 0x20D1824B, 0xCAD23AA9, 0xFFFFFFFF, 0xFFFFFFFF,
  70359. +};
  70360. +
  70361. +static void dh_swap_bytes(void *_in, void *_out, uint32_t len)
  70362. +{
  70363. + uint8_t *in = _in;
  70364. + uint8_t *out = _out;
  70365. + int i;
  70366. + for (i=0; i<len; i++) {
  70367. + out[i] = in[len-1-i];
  70368. + }
  70369. +}
  70370. +
  70371. +/* Computes the modular exponentiation (num^exp % mod). num, exp, and mod are
  70372. + * big endian numbers of size len, in bytes. Each len value must be a multiple
  70373. + * of 4. */
  70374. +int dwc_dh_modpow(void *mem_ctx, void *num, uint32_t num_len,
  70375. + void *exp, uint32_t exp_len,
  70376. + void *mod, uint32_t mod_len,
  70377. + void *out)
  70378. +{
  70379. + /* modpow() takes little endian numbers. AM uses big-endian. This
  70380. + * function swaps bytes of numbers before passing onto modpow. */
  70381. +
  70382. + int retval = 0;
  70383. + uint32_t *result;
  70384. +
  70385. + uint32_t *bignum_num = dwc_alloc(mem_ctx, num_len + 4);
  70386. + uint32_t *bignum_exp = dwc_alloc(mem_ctx, exp_len + 4);
  70387. + uint32_t *bignum_mod = dwc_alloc(mem_ctx, mod_len + 4);
  70388. +
  70389. + dh_swap_bytes(num, &bignum_num[1], num_len);
  70390. + bignum_num[0] = num_len / 4;
  70391. +
  70392. + dh_swap_bytes(exp, &bignum_exp[1], exp_len);
  70393. + bignum_exp[0] = exp_len / 4;
  70394. +
  70395. + dh_swap_bytes(mod, &bignum_mod[1], mod_len);
  70396. + bignum_mod[0] = mod_len / 4;
  70397. +
  70398. + result = dwc_modpow(mem_ctx, bignum_num, bignum_exp, bignum_mod);
  70399. + if (!result) {
  70400. + retval = -1;
  70401. + goto dh_modpow_nomem;
  70402. + }
  70403. +
  70404. + dh_swap_bytes(&result[1], out, result[0] * 4);
  70405. + dwc_free(mem_ctx, result);
  70406. +
  70407. + dh_modpow_nomem:
  70408. + dwc_free(mem_ctx, bignum_num);
  70409. + dwc_free(mem_ctx, bignum_exp);
  70410. + dwc_free(mem_ctx, bignum_mod);
  70411. + return retval;
  70412. +}
  70413. +
  70414. +
  70415. +int dwc_dh_pk(void *mem_ctx, uint8_t nd, uint8_t *exp, uint8_t *pk, uint8_t *hash)
  70416. +{
  70417. + int retval;
  70418. + uint8_t m3[385];
  70419. +
  70420. +#ifndef DH_TEST_VECTORS
  70421. + DWC_RANDOM_BYTES(exp, 32);
  70422. +#endif
  70423. +
  70424. + /* Compute the pkd */
  70425. + if ((retval = dwc_dh_modpow(mem_ctx, dh_g, 4,
  70426. + exp, 32,
  70427. + dh_p, 384, pk))) {
  70428. + return retval;
  70429. + }
  70430. +
  70431. + m3[384] = nd;
  70432. + DWC_MEMCPY(&m3[0], pk, 384);
  70433. + DWC_SHA256(m3, 385, hash);
  70434. +
  70435. + dh_dump("PK", pk, 384);
  70436. + dh_dump("SHA-256(M3)", hash, 32);
  70437. + return 0;
  70438. +}
  70439. +
  70440. +int dwc_dh_derive_keys(void *mem_ctx, uint8_t nd, uint8_t *pkh, uint8_t *pkd,
  70441. + uint8_t *exp, int is_host,
  70442. + char *dd, uint8_t *ck, uint8_t *kdk)
  70443. +{
  70444. + int retval;
  70445. + uint8_t mv[784];
  70446. + uint8_t sha_result[32];
  70447. + uint8_t dhkey[384];
  70448. + uint8_t shared_secret[384];
  70449. + char *message;
  70450. + uint32_t vd;
  70451. +
  70452. + uint8_t *pk;
  70453. +
  70454. + if (is_host) {
  70455. + pk = pkd;
  70456. + }
  70457. + else {
  70458. + pk = pkh;
  70459. + }
  70460. +
  70461. + if ((retval = dwc_dh_modpow(mem_ctx, pk, 384,
  70462. + exp, 32,
  70463. + dh_p, 384, shared_secret))) {
  70464. + return retval;
  70465. + }
  70466. + dh_dump("Shared Secret", shared_secret, 384);
  70467. +
  70468. + DWC_SHA256(shared_secret, 384, dhkey);
  70469. + dh_dump("DHKEY", dhkey, 384);
  70470. +
  70471. + DWC_MEMCPY(&mv[0], pkd, 384);
  70472. + DWC_MEMCPY(&mv[384], pkh, 384);
  70473. + DWC_MEMCPY(&mv[768], "displayed digest", 16);
  70474. + dh_dump("MV", mv, 784);
  70475. +
  70476. + DWC_SHA256(mv, 784, sha_result);
  70477. + dh_dump("SHA-256(MV)", sha_result, 32);
  70478. + dh_dump("First 32-bits of SHA-256(MV)", sha_result, 4);
  70479. +
  70480. + dh_swap_bytes(sha_result, &vd, 4);
  70481. +#ifdef DEBUG
  70482. + DWC_PRINTF("Vd (decimal) = %d\n", vd);
  70483. +#endif
  70484. +
  70485. + switch (nd) {
  70486. + case 2:
  70487. + vd = vd % 100;
  70488. + DWC_SPRINTF(dd, "%02d", vd);
  70489. + break;
  70490. + case 3:
  70491. + vd = vd % 1000;
  70492. + DWC_SPRINTF(dd, "%03d", vd);
  70493. + break;
  70494. + case 4:
  70495. + vd = vd % 10000;
  70496. + DWC_SPRINTF(dd, "%04d", vd);
  70497. + break;
  70498. + }
  70499. +#ifdef DEBUG
  70500. + DWC_PRINTF("Display Digits: %s\n", dd);
  70501. +#endif
  70502. +
  70503. + message = "connection key";
  70504. + DWC_HMAC_SHA256(message, DWC_STRLEN(message), dhkey, 32, sha_result);
  70505. + dh_dump("HMAC(SHA-256, DHKey, connection key)", sha_result, 32);
  70506. + DWC_MEMCPY(ck, sha_result, 16);
  70507. +
  70508. + message = "key derivation key";
  70509. + DWC_HMAC_SHA256(message, DWC_STRLEN(message), dhkey, 32, sha_result);
  70510. + dh_dump("HMAC(SHA-256, DHKey, key derivation key)", sha_result, 32);
  70511. + DWC_MEMCPY(kdk, sha_result, 32);
  70512. +
  70513. + return 0;
  70514. +}
  70515. +
  70516. +
  70517. +#ifdef DH_TEST_VECTORS
  70518. +
  70519. +static __u8 dh_a[] = {
  70520. + 0x44, 0x00, 0x51, 0xd6,
  70521. + 0xf0, 0xb5, 0x5e, 0xa9,
  70522. + 0x67, 0xab, 0x31, 0xc6,
  70523. + 0x8a, 0x8b, 0x5e, 0x37,
  70524. + 0xd9, 0x10, 0xda, 0xe0,
  70525. + 0xe2, 0xd4, 0x59, 0xa4,
  70526. + 0x86, 0x45, 0x9c, 0xaa,
  70527. + 0xdf, 0x36, 0x75, 0x16,
  70528. +};
  70529. +
  70530. +static __u8 dh_b[] = {
  70531. + 0x5d, 0xae, 0xc7, 0x86,
  70532. + 0x79, 0x80, 0xa3, 0x24,
  70533. + 0x8c, 0xe3, 0x57, 0x8f,
  70534. + 0xc7, 0x5f, 0x1b, 0x0f,
  70535. + 0x2d, 0xf8, 0x9d, 0x30,
  70536. + 0x6f, 0xa4, 0x52, 0xcd,
  70537. + 0xe0, 0x7a, 0x04, 0x8a,
  70538. + 0xde, 0xd9, 0x26, 0x56,
  70539. +};
  70540. +
  70541. +void dwc_run_dh_test_vectors(void *mem_ctx)
  70542. +{
  70543. + uint8_t pkd[384];
  70544. + uint8_t pkh[384];
  70545. + uint8_t hashd[32];
  70546. + uint8_t hashh[32];
  70547. + uint8_t ck[16];
  70548. + uint8_t kdk[32];
  70549. + char dd[5];
  70550. +
  70551. + DWC_PRINTF("\n\n\nDH_TEST_VECTORS\n\n");
  70552. +
  70553. + /* compute the PKd and SHA-256(PKd || Nd) */
  70554. + DWC_PRINTF("Computing PKd\n");
  70555. + dwc_dh_pk(mem_ctx, 2, dh_a, pkd, hashd);
  70556. +
  70557. + /* compute the PKd and SHA-256(PKh || Nd) */
  70558. + DWC_PRINTF("Computing PKh\n");
  70559. + dwc_dh_pk(mem_ctx, 2, dh_b, pkh, hashh);
  70560. +
  70561. + /* compute the dhkey */
  70562. + dwc_dh_derive_keys(mem_ctx, 2, pkh, pkd, dh_a, 0, dd, ck, kdk);
  70563. +}
  70564. +#endif /* DH_TEST_VECTORS */
  70565. +
  70566. +#endif /* !CONFIG_MACH_IPMATE */
  70567. +
  70568. +#endif /* DWC_CRYPTOLIB */
  70569. diff -Nur linux-3.18.8/drivers/usb/host/dwc_common_port/dwc_dh.h linux-rpi/drivers/usb/host/dwc_common_port/dwc_dh.h
  70570. --- linux-3.18.8/drivers/usb/host/dwc_common_port/dwc_dh.h 1970-01-01 01:00:00.000000000 +0100
  70571. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_dh.h 2015-03-05 14:40:16.557715806 +0100
  70572. @@ -0,0 +1,106 @@
  70573. +/* =========================================================================
  70574. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_dh.h $
  70575. + * $Revision: #4 $
  70576. + * $Date: 2010/09/28 $
  70577. + * $Change: 1596182 $
  70578. + *
  70579. + * Synopsys Portability Library Software and documentation
  70580. + * (hereinafter, "Software") is an Unsupported proprietary work of
  70581. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  70582. + * between Synopsys and you.
  70583. + *
  70584. + * The Software IS NOT an item of Licensed Software or Licensed Product
  70585. + * under any End User Software License Agreement or Agreement for
  70586. + * Licensed Product with Synopsys or any supplement thereto. You are
  70587. + * permitted to use and redistribute this Software in source and binary
  70588. + * forms, with or without modification, provided that redistributions
  70589. + * of source code must retain this notice. You may not view, use,
  70590. + * disclose, copy or distribute this file or any information contained
  70591. + * herein except pursuant to this license grant from Synopsys. If you
  70592. + * do not agree with this notice, including the disclaimer below, then
  70593. + * you are not authorized to use the Software.
  70594. + *
  70595. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  70596. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  70597. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  70598. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  70599. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  70600. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  70601. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  70602. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  70603. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  70604. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  70605. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  70606. + * DAMAGE.
  70607. + * ========================================================================= */
  70608. +#ifndef _DWC_DH_H_
  70609. +#define _DWC_DH_H_
  70610. +
  70611. +#ifdef __cplusplus
  70612. +extern "C" {
  70613. +#endif
  70614. +
  70615. +#include "dwc_os.h"
  70616. +
  70617. +/** @file
  70618. + *
  70619. + * This file defines the common functions on device and host for performing
  70620. + * numeric association as defined in the WUSB spec. They are only to be
  70621. + * used internally by the DWC UWB modules. */
  70622. +
  70623. +extern int dwc_dh_sha256(uint8_t *message, uint32_t len, uint8_t *out);
  70624. +extern int dwc_dh_hmac_sha256(uint8_t *message, uint32_t messagelen,
  70625. + uint8_t *key, uint32_t keylen,
  70626. + uint8_t *out);
  70627. +extern int dwc_dh_modpow(void *mem_ctx, void *num, uint32_t num_len,
  70628. + void *exp, uint32_t exp_len,
  70629. + void *mod, uint32_t mod_len,
  70630. + void *out);
  70631. +
  70632. +/** Computes PKD or PKH, and SHA-256(PKd || Nd)
  70633. + *
  70634. + * PK = g^exp mod p.
  70635. + *
  70636. + * Input:
  70637. + * Nd = Number of digits on the device.
  70638. + *
  70639. + * Output:
  70640. + * exp = A 32-byte buffer to be filled with a randomly generated number.
  70641. + * used as either A or B.
  70642. + * pk = A 384-byte buffer to be filled with the PKH or PKD.
  70643. + * hash = A 32-byte buffer to be filled with SHA-256(PK || ND).
  70644. + */
  70645. +extern int dwc_dh_pk(void *mem_ctx, uint8_t nd, uint8_t *exp, uint8_t *pkd, uint8_t *hash);
  70646. +
  70647. +/** Computes the DHKEY, and VD.
  70648. + *
  70649. + * If called from host, then it will comput DHKEY=PKD^exp % p.
  70650. + * If called from device, then it will comput DHKEY=PKH^exp % p.
  70651. + *
  70652. + * Input:
  70653. + * pkd = The PKD value.
  70654. + * pkh = The PKH value.
  70655. + * exp = The A value (if device) or B value (if host) generated in dwc_wudev_dh_pk.
  70656. + * is_host = Set to non zero if a WUSB host is calling this function.
  70657. + *
  70658. + * Output:
  70659. +
  70660. + * dd = A pointer to an buffer to be set to the displayed digits string to be shown
  70661. + * to the user. This buffer should be at 5 bytes long to hold 4 digits plus a
  70662. + * null termination character. This buffer can be used directly for display.
  70663. + * ck = A 16-byte buffer to be filled with the CK.
  70664. + * kdk = A 32-byte buffer to be filled with the KDK.
  70665. + */
  70666. +extern int dwc_dh_derive_keys(void *mem_ctx, uint8_t nd, uint8_t *pkh, uint8_t *pkd,
  70667. + uint8_t *exp, int is_host,
  70668. + char *dd, uint8_t *ck, uint8_t *kdk);
  70669. +
  70670. +#ifdef DH_TEST_VECTORS
  70671. +extern void dwc_run_dh_test_vectors(void);
  70672. +#endif
  70673. +
  70674. +#ifdef __cplusplus
  70675. +}
  70676. +#endif
  70677. +
  70678. +#endif /* _DWC_DH_H_ */
  70679. diff -Nur linux-3.18.8/drivers/usb/host/dwc_common_port/dwc_list.h linux-rpi/drivers/usb/host/dwc_common_port/dwc_list.h
  70680. --- linux-3.18.8/drivers/usb/host/dwc_common_port/dwc_list.h 1970-01-01 01:00:00.000000000 +0100
  70681. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_list.h 2015-03-05 14:40:16.557715806 +0100
  70682. @@ -0,0 +1,594 @@
  70683. +/* $OpenBSD: queue.h,v 1.26 2004/05/04 16:59:32 grange Exp $ */
  70684. +/* $NetBSD: queue.h,v 1.11 1996/05/16 05:17:14 mycroft Exp $ */
  70685. +
  70686. +/*
  70687. + * Copyright (c) 1991, 1993
  70688. + * The Regents of the University of California. All rights reserved.
  70689. + *
  70690. + * Redistribution and use in source and binary forms, with or without
  70691. + * modification, are permitted provided that the following conditions
  70692. + * are met:
  70693. + * 1. Redistributions of source code must retain the above copyright
  70694. + * notice, this list of conditions and the following disclaimer.
  70695. + * 2. Redistributions in binary form must reproduce the above copyright
  70696. + * notice, this list of conditions and the following disclaimer in the
  70697. + * documentation and/or other materials provided with the distribution.
  70698. + * 3. Neither the name of the University nor the names of its contributors
  70699. + * may be used to endorse or promote products derived from this software
  70700. + * without specific prior written permission.
  70701. + *
  70702. + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  70703. + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  70704. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  70705. + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  70706. + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  70707. + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  70708. + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  70709. + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  70710. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  70711. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  70712. + * SUCH DAMAGE.
  70713. + *
  70714. + * @(#)queue.h 8.5 (Berkeley) 8/20/94
  70715. + */
  70716. +
  70717. +#ifndef _DWC_LIST_H_
  70718. +#define _DWC_LIST_H_
  70719. +
  70720. +#ifdef __cplusplus
  70721. +extern "C" {
  70722. +#endif
  70723. +
  70724. +/** @file
  70725. + *
  70726. + * This file defines linked list operations. It is derived from BSD with
  70727. + * only the MACRO names being prefixed with DWC_. This is because a few of
  70728. + * these names conflict with those on Linux. For documentation on use, see the
  70729. + * inline comments in the source code. The original license for this source
  70730. + * code applies and is preserved in the dwc_list.h source file.
  70731. + */
  70732. +
  70733. +/*
  70734. + * This file defines five types of data structures: singly-linked lists,
  70735. + * lists, simple queues, tail queues, and circular queues.
  70736. + *
  70737. + *
  70738. + * A singly-linked list is headed by a single forward pointer. The elements
  70739. + * are singly linked for minimum space and pointer manipulation overhead at
  70740. + * the expense of O(n) removal for arbitrary elements. New elements can be
  70741. + * added to the list after an existing element or at the head of the list.
  70742. + * Elements being removed from the head of the list should use the explicit
  70743. + * macro for this purpose for optimum efficiency. A singly-linked list may
  70744. + * only be traversed in the forward direction. Singly-linked lists are ideal
  70745. + * for applications with large datasets and few or no removals or for
  70746. + * implementing a LIFO queue.
  70747. + *
  70748. + * A list is headed by a single forward pointer (or an array of forward
  70749. + * pointers for a hash table header). The elements are doubly linked
  70750. + * so that an arbitrary element can be removed without a need to
  70751. + * traverse the list. New elements can be added to the list before
  70752. + * or after an existing element or at the head of the list. A list
  70753. + * may only be traversed in the forward direction.
  70754. + *
  70755. + * A simple queue is headed by a pair of pointers, one the head of the
  70756. + * list and the other to the tail of the list. The elements are singly
  70757. + * linked to save space, so elements can only be removed from the
  70758. + * head of the list. New elements can be added to the list before or after
  70759. + * an existing element, at the head of the list, or at the end of the
  70760. + * list. A simple queue may only be traversed in the forward direction.
  70761. + *
  70762. + * A tail queue is headed by a pair of pointers, one to the head of the
  70763. + * list and the other to the tail of the list. The elements are doubly
  70764. + * linked so that an arbitrary element can be removed without a need to
  70765. + * traverse the list. New elements can be added to the list before or
  70766. + * after an existing element, at the head of the list, or at the end of
  70767. + * the list. A tail queue may be traversed in either direction.
  70768. + *
  70769. + * A circle queue is headed by a pair of pointers, one to the head of the
  70770. + * list and the other to the tail of the list. The elements are doubly
  70771. + * linked so that an arbitrary element can be removed without a need to
  70772. + * traverse the list. New elements can be added to the list before or after
  70773. + * an existing element, at the head of the list, or at the end of the list.
  70774. + * A circle queue may be traversed in either direction, but has a more
  70775. + * complex end of list detection.
  70776. + *
  70777. + * For details on the use of these macros, see the queue(3) manual page.
  70778. + */
  70779. +
  70780. +/*
  70781. + * Double-linked List.
  70782. + */
  70783. +
  70784. +typedef struct dwc_list_link {
  70785. + struct dwc_list_link *next;
  70786. + struct dwc_list_link *prev;
  70787. +} dwc_list_link_t;
  70788. +
  70789. +#define DWC_LIST_INIT(link) do { \
  70790. + (link)->next = (link); \
  70791. + (link)->prev = (link); \
  70792. +} while (0)
  70793. +
  70794. +#define DWC_LIST_FIRST(link) ((link)->next)
  70795. +#define DWC_LIST_LAST(link) ((link)->prev)
  70796. +#define DWC_LIST_END(link) (link)
  70797. +#define DWC_LIST_NEXT(link) ((link)->next)
  70798. +#define DWC_LIST_PREV(link) ((link)->prev)
  70799. +#define DWC_LIST_EMPTY(link) \
  70800. + (DWC_LIST_FIRST(link) == DWC_LIST_END(link))
  70801. +#define DWC_LIST_ENTRY(link, type, field) \
  70802. + (type *)((uint8_t *)(link) - (size_t)(&((type *)0)->field))
  70803. +
  70804. +#if 0
  70805. +#define DWC_LIST_INSERT_HEAD(list, link) do { \
  70806. + (link)->next = (list)->next; \
  70807. + (link)->prev = (list); \
  70808. + (list)->next->prev = (link); \
  70809. + (list)->next = (link); \
  70810. +} while (0)
  70811. +
  70812. +#define DWC_LIST_INSERT_TAIL(list, link) do { \
  70813. + (link)->next = (list); \
  70814. + (link)->prev = (list)->prev; \
  70815. + (list)->prev->next = (link); \
  70816. + (list)->prev = (link); \
  70817. +} while (0)
  70818. +#else
  70819. +#define DWC_LIST_INSERT_HEAD(list, link) do { \
  70820. + dwc_list_link_t *__next__ = (list)->next; \
  70821. + __next__->prev = (link); \
  70822. + (link)->next = __next__; \
  70823. + (link)->prev = (list); \
  70824. + (list)->next = (link); \
  70825. +} while (0)
  70826. +
  70827. +#define DWC_LIST_INSERT_TAIL(list, link) do { \
  70828. + dwc_list_link_t *__prev__ = (list)->prev; \
  70829. + (list)->prev = (link); \
  70830. + (link)->next = (list); \
  70831. + (link)->prev = __prev__; \
  70832. + __prev__->next = (link); \
  70833. +} while (0)
  70834. +#endif
  70835. +
  70836. +#if 0
  70837. +static inline void __list_add(struct list_head *new,
  70838. + struct list_head *prev,
  70839. + struct list_head *next)
  70840. +{
  70841. + next->prev = new;
  70842. + new->next = next;
  70843. + new->prev = prev;
  70844. + prev->next = new;
  70845. +}
  70846. +
  70847. +static inline void list_add(struct list_head *new, struct list_head *head)
  70848. +{
  70849. + __list_add(new, head, head->next);
  70850. +}
  70851. +
  70852. +static inline void list_add_tail(struct list_head *new, struct list_head *head)
  70853. +{
  70854. + __list_add(new, head->prev, head);
  70855. +}
  70856. +
  70857. +static inline void __list_del(struct list_head * prev, struct list_head * next)
  70858. +{
  70859. + next->prev = prev;
  70860. + prev->next = next;
  70861. +}
  70862. +
  70863. +static inline void list_del(struct list_head *entry)
  70864. +{
  70865. + __list_del(entry->prev, entry->next);
  70866. + entry->next = LIST_POISON1;
  70867. + entry->prev = LIST_POISON2;
  70868. +}
  70869. +#endif
  70870. +
  70871. +#define DWC_LIST_REMOVE(link) do { \
  70872. + (link)->next->prev = (link)->prev; \
  70873. + (link)->prev->next = (link)->next; \
  70874. +} while (0)
  70875. +
  70876. +#define DWC_LIST_REMOVE_INIT(link) do { \
  70877. + DWC_LIST_REMOVE(link); \
  70878. + DWC_LIST_INIT(link); \
  70879. +} while (0)
  70880. +
  70881. +#define DWC_LIST_MOVE_HEAD(list, link) do { \
  70882. + DWC_LIST_REMOVE(link); \
  70883. + DWC_LIST_INSERT_HEAD(list, link); \
  70884. +} while (0)
  70885. +
  70886. +#define DWC_LIST_MOVE_TAIL(list, link) do { \
  70887. + DWC_LIST_REMOVE(link); \
  70888. + DWC_LIST_INSERT_TAIL(list, link); \
  70889. +} while (0)
  70890. +
  70891. +#define DWC_LIST_FOREACH(var, list) \
  70892. + for((var) = DWC_LIST_FIRST(list); \
  70893. + (var) != DWC_LIST_END(list); \
  70894. + (var) = DWC_LIST_NEXT(var))
  70895. +
  70896. +#define DWC_LIST_FOREACH_SAFE(var, var2, list) \
  70897. + for((var) = DWC_LIST_FIRST(list), (var2) = DWC_LIST_NEXT(var); \
  70898. + (var) != DWC_LIST_END(list); \
  70899. + (var) = (var2), (var2) = DWC_LIST_NEXT(var2))
  70900. +
  70901. +#define DWC_LIST_FOREACH_REVERSE(var, list) \
  70902. + for((var) = DWC_LIST_LAST(list); \
  70903. + (var) != DWC_LIST_END(list); \
  70904. + (var) = DWC_LIST_PREV(var))
  70905. +
  70906. +/*
  70907. + * Singly-linked List definitions.
  70908. + */
  70909. +#define DWC_SLIST_HEAD(name, type) \
  70910. +struct name { \
  70911. + struct type *slh_first; /* first element */ \
  70912. +}
  70913. +
  70914. +#define DWC_SLIST_HEAD_INITIALIZER(head) \
  70915. + { NULL }
  70916. +
  70917. +#define DWC_SLIST_ENTRY(type) \
  70918. +struct { \
  70919. + struct type *sle_next; /* next element */ \
  70920. +}
  70921. +
  70922. +/*
  70923. + * Singly-linked List access methods.
  70924. + */
  70925. +#define DWC_SLIST_FIRST(head) ((head)->slh_first)
  70926. +#define DWC_SLIST_END(head) NULL
  70927. +#define DWC_SLIST_EMPTY(head) (SLIST_FIRST(head) == SLIST_END(head))
  70928. +#define DWC_SLIST_NEXT(elm, field) ((elm)->field.sle_next)
  70929. +
  70930. +#define DWC_SLIST_FOREACH(var, head, field) \
  70931. + for((var) = SLIST_FIRST(head); \
  70932. + (var) != SLIST_END(head); \
  70933. + (var) = SLIST_NEXT(var, field))
  70934. +
  70935. +#define DWC_SLIST_FOREACH_PREVPTR(var, varp, head, field) \
  70936. + for((varp) = &SLIST_FIRST((head)); \
  70937. + ((var) = *(varp)) != SLIST_END(head); \
  70938. + (varp) = &SLIST_NEXT((var), field))
  70939. +
  70940. +/*
  70941. + * Singly-linked List functions.
  70942. + */
  70943. +#define DWC_SLIST_INIT(head) { \
  70944. + SLIST_FIRST(head) = SLIST_END(head); \
  70945. +}
  70946. +
  70947. +#define DWC_SLIST_INSERT_AFTER(slistelm, elm, field) do { \
  70948. + (elm)->field.sle_next = (slistelm)->field.sle_next; \
  70949. + (slistelm)->field.sle_next = (elm); \
  70950. +} while (0)
  70951. +
  70952. +#define DWC_SLIST_INSERT_HEAD(head, elm, field) do { \
  70953. + (elm)->field.sle_next = (head)->slh_first; \
  70954. + (head)->slh_first = (elm); \
  70955. +} while (0)
  70956. +
  70957. +#define DWC_SLIST_REMOVE_NEXT(head, elm, field) do { \
  70958. + (elm)->field.sle_next = (elm)->field.sle_next->field.sle_next; \
  70959. +} while (0)
  70960. +
  70961. +#define DWC_SLIST_REMOVE_HEAD(head, field) do { \
  70962. + (head)->slh_first = (head)->slh_first->field.sle_next; \
  70963. +} while (0)
  70964. +
  70965. +#define DWC_SLIST_REMOVE(head, elm, type, field) do { \
  70966. + if ((head)->slh_first == (elm)) { \
  70967. + SLIST_REMOVE_HEAD((head), field); \
  70968. + } \
  70969. + else { \
  70970. + struct type *curelm = (head)->slh_first; \
  70971. + while( curelm->field.sle_next != (elm) ) \
  70972. + curelm = curelm->field.sle_next; \
  70973. + curelm->field.sle_next = \
  70974. + curelm->field.sle_next->field.sle_next; \
  70975. + } \
  70976. +} while (0)
  70977. +
  70978. +/*
  70979. + * Simple queue definitions.
  70980. + */
  70981. +#define DWC_SIMPLEQ_HEAD(name, type) \
  70982. +struct name { \
  70983. + struct type *sqh_first; /* first element */ \
  70984. + struct type **sqh_last; /* addr of last next element */ \
  70985. +}
  70986. +
  70987. +#define DWC_SIMPLEQ_HEAD_INITIALIZER(head) \
  70988. + { NULL, &(head).sqh_first }
  70989. +
  70990. +#define DWC_SIMPLEQ_ENTRY(type) \
  70991. +struct { \
  70992. + struct type *sqe_next; /* next element */ \
  70993. +}
  70994. +
  70995. +/*
  70996. + * Simple queue access methods.
  70997. + */
  70998. +#define DWC_SIMPLEQ_FIRST(head) ((head)->sqh_first)
  70999. +#define DWC_SIMPLEQ_END(head) NULL
  71000. +#define DWC_SIMPLEQ_EMPTY(head) (SIMPLEQ_FIRST(head) == SIMPLEQ_END(head))
  71001. +#define DWC_SIMPLEQ_NEXT(elm, field) ((elm)->field.sqe_next)
  71002. +
  71003. +#define DWC_SIMPLEQ_FOREACH(var, head, field) \
  71004. + for((var) = SIMPLEQ_FIRST(head); \
  71005. + (var) != SIMPLEQ_END(head); \
  71006. + (var) = SIMPLEQ_NEXT(var, field))
  71007. +
  71008. +/*
  71009. + * Simple queue functions.
  71010. + */
  71011. +#define DWC_SIMPLEQ_INIT(head) do { \
  71012. + (head)->sqh_first = NULL; \
  71013. + (head)->sqh_last = &(head)->sqh_first; \
  71014. +} while (0)
  71015. +
  71016. +#define DWC_SIMPLEQ_INSERT_HEAD(head, elm, field) do { \
  71017. + if (((elm)->field.sqe_next = (head)->sqh_first) == NULL) \
  71018. + (head)->sqh_last = &(elm)->field.sqe_next; \
  71019. + (head)->sqh_first = (elm); \
  71020. +} while (0)
  71021. +
  71022. +#define DWC_SIMPLEQ_INSERT_TAIL(head, elm, field) do { \
  71023. + (elm)->field.sqe_next = NULL; \
  71024. + *(head)->sqh_last = (elm); \
  71025. + (head)->sqh_last = &(elm)->field.sqe_next; \
  71026. +} while (0)
  71027. +
  71028. +#define DWC_SIMPLEQ_INSERT_AFTER(head, listelm, elm, field) do { \
  71029. + if (((elm)->field.sqe_next = (listelm)->field.sqe_next) == NULL)\
  71030. + (head)->sqh_last = &(elm)->field.sqe_next; \
  71031. + (listelm)->field.sqe_next = (elm); \
  71032. +} while (0)
  71033. +
  71034. +#define DWC_SIMPLEQ_REMOVE_HEAD(head, field) do { \
  71035. + if (((head)->sqh_first = (head)->sqh_first->field.sqe_next) == NULL) \
  71036. + (head)->sqh_last = &(head)->sqh_first; \
  71037. +} while (0)
  71038. +
  71039. +/*
  71040. + * Tail queue definitions.
  71041. + */
  71042. +#define DWC_TAILQ_HEAD(name, type) \
  71043. +struct name { \
  71044. + struct type *tqh_first; /* first element */ \
  71045. + struct type **tqh_last; /* addr of last next element */ \
  71046. +}
  71047. +
  71048. +#define DWC_TAILQ_HEAD_INITIALIZER(head) \
  71049. + { NULL, &(head).tqh_first }
  71050. +
  71051. +#define DWC_TAILQ_ENTRY(type) \
  71052. +struct { \
  71053. + struct type *tqe_next; /* next element */ \
  71054. + struct type **tqe_prev; /* address of previous next element */ \
  71055. +}
  71056. +
  71057. +/*
  71058. + * tail queue access methods
  71059. + */
  71060. +#define DWC_TAILQ_FIRST(head) ((head)->tqh_first)
  71061. +#define DWC_TAILQ_END(head) NULL
  71062. +#define DWC_TAILQ_NEXT(elm, field) ((elm)->field.tqe_next)
  71063. +#define DWC_TAILQ_LAST(head, headname) \
  71064. + (*(((struct headname *)((head)->tqh_last))->tqh_last))
  71065. +/* XXX */
  71066. +#define DWC_TAILQ_PREV(elm, headname, field) \
  71067. + (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
  71068. +#define DWC_TAILQ_EMPTY(head) \
  71069. + (DWC_TAILQ_FIRST(head) == DWC_TAILQ_END(head))
  71070. +
  71071. +#define DWC_TAILQ_FOREACH(var, head, field) \
  71072. + for ((var) = DWC_TAILQ_FIRST(head); \
  71073. + (var) != DWC_TAILQ_END(head); \
  71074. + (var) = DWC_TAILQ_NEXT(var, field))
  71075. +
  71076. +#define DWC_TAILQ_FOREACH_REVERSE(var, head, headname, field) \
  71077. + for ((var) = DWC_TAILQ_LAST(head, headname); \
  71078. + (var) != DWC_TAILQ_END(head); \
  71079. + (var) = DWC_TAILQ_PREV(var, headname, field))
  71080. +
  71081. +/*
  71082. + * Tail queue functions.
  71083. + */
  71084. +#define DWC_TAILQ_INIT(head) do { \
  71085. + (head)->tqh_first = NULL; \
  71086. + (head)->tqh_last = &(head)->tqh_first; \
  71087. +} while (0)
  71088. +
  71089. +#define DWC_TAILQ_INSERT_HEAD(head, elm, field) do { \
  71090. + if (((elm)->field.tqe_next = (head)->tqh_first) != NULL) \
  71091. + (head)->tqh_first->field.tqe_prev = \
  71092. + &(elm)->field.tqe_next; \
  71093. + else \
  71094. + (head)->tqh_last = &(elm)->field.tqe_next; \
  71095. + (head)->tqh_first = (elm); \
  71096. + (elm)->field.tqe_prev = &(head)->tqh_first; \
  71097. +} while (0)
  71098. +
  71099. +#define DWC_TAILQ_INSERT_TAIL(head, elm, field) do { \
  71100. + (elm)->field.tqe_next = NULL; \
  71101. + (elm)->field.tqe_prev = (head)->tqh_last; \
  71102. + *(head)->tqh_last = (elm); \
  71103. + (head)->tqh_last = &(elm)->field.tqe_next; \
  71104. +} while (0)
  71105. +
  71106. +#define DWC_TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \
  71107. + if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)\
  71108. + (elm)->field.tqe_next->field.tqe_prev = \
  71109. + &(elm)->field.tqe_next; \
  71110. + else \
  71111. + (head)->tqh_last = &(elm)->field.tqe_next; \
  71112. + (listelm)->field.tqe_next = (elm); \
  71113. + (elm)->field.tqe_prev = &(listelm)->field.tqe_next; \
  71114. +} while (0)
  71115. +
  71116. +#define DWC_TAILQ_INSERT_BEFORE(listelm, elm, field) do { \
  71117. + (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \
  71118. + (elm)->field.tqe_next = (listelm); \
  71119. + *(listelm)->field.tqe_prev = (elm); \
  71120. + (listelm)->field.tqe_prev = &(elm)->field.tqe_next; \
  71121. +} while (0)
  71122. +
  71123. +#define DWC_TAILQ_REMOVE(head, elm, field) do { \
  71124. + if (((elm)->field.tqe_next) != NULL) \
  71125. + (elm)->field.tqe_next->field.tqe_prev = \
  71126. + (elm)->field.tqe_prev; \
  71127. + else \
  71128. + (head)->tqh_last = (elm)->field.tqe_prev; \
  71129. + *(elm)->field.tqe_prev = (elm)->field.tqe_next; \
  71130. +} while (0)
  71131. +
  71132. +#define DWC_TAILQ_REPLACE(head, elm, elm2, field) do { \
  71133. + if (((elm2)->field.tqe_next = (elm)->field.tqe_next) != NULL) \
  71134. + (elm2)->field.tqe_next->field.tqe_prev = \
  71135. + &(elm2)->field.tqe_next; \
  71136. + else \
  71137. + (head)->tqh_last = &(elm2)->field.tqe_next; \
  71138. + (elm2)->field.tqe_prev = (elm)->field.tqe_prev; \
  71139. + *(elm2)->field.tqe_prev = (elm2); \
  71140. +} while (0)
  71141. +
  71142. +/*
  71143. + * Circular queue definitions.
  71144. + */
  71145. +#define DWC_CIRCLEQ_HEAD(name, type) \
  71146. +struct name { \
  71147. + struct type *cqh_first; /* first element */ \
  71148. + struct type *cqh_last; /* last element */ \
  71149. +}
  71150. +
  71151. +#define DWC_CIRCLEQ_HEAD_INITIALIZER(head) \
  71152. + { DWC_CIRCLEQ_END(&head), DWC_CIRCLEQ_END(&head) }
  71153. +
  71154. +#define DWC_CIRCLEQ_ENTRY(type) \
  71155. +struct { \
  71156. + struct type *cqe_next; /* next element */ \
  71157. + struct type *cqe_prev; /* previous element */ \
  71158. +}
  71159. +
  71160. +/*
  71161. + * Circular queue access methods
  71162. + */
  71163. +#define DWC_CIRCLEQ_FIRST(head) ((head)->cqh_first)
  71164. +#define DWC_CIRCLEQ_LAST(head) ((head)->cqh_last)
  71165. +#define DWC_CIRCLEQ_END(head) ((void *)(head))
  71166. +#define DWC_CIRCLEQ_NEXT(elm, field) ((elm)->field.cqe_next)
  71167. +#define DWC_CIRCLEQ_PREV(elm, field) ((elm)->field.cqe_prev)
  71168. +#define DWC_CIRCLEQ_EMPTY(head) \
  71169. + (DWC_CIRCLEQ_FIRST(head) == DWC_CIRCLEQ_END(head))
  71170. +
  71171. +#define DWC_CIRCLEQ_EMPTY_ENTRY(elm, field) (((elm)->field.cqe_next == NULL) && ((elm)->field.cqe_prev == NULL))
  71172. +
  71173. +#define DWC_CIRCLEQ_FOREACH(var, head, field) \
  71174. + for((var) = DWC_CIRCLEQ_FIRST(head); \
  71175. + (var) != DWC_CIRCLEQ_END(head); \
  71176. + (var) = DWC_CIRCLEQ_NEXT(var, field))
  71177. +
  71178. +#define DWC_CIRCLEQ_FOREACH_SAFE(var, var2, head, field) \
  71179. + for((var) = DWC_CIRCLEQ_FIRST(head), var2 = DWC_CIRCLEQ_NEXT(var, field); \
  71180. + (var) != DWC_CIRCLEQ_END(head); \
  71181. + (var) = var2, var2 = DWC_CIRCLEQ_NEXT(var, field))
  71182. +
  71183. +#define DWC_CIRCLEQ_FOREACH_REVERSE(var, head, field) \
  71184. + for((var) = DWC_CIRCLEQ_LAST(head); \
  71185. + (var) != DWC_CIRCLEQ_END(head); \
  71186. + (var) = DWC_CIRCLEQ_PREV(var, field))
  71187. +
  71188. +/*
  71189. + * Circular queue functions.
  71190. + */
  71191. +#define DWC_CIRCLEQ_INIT(head) do { \
  71192. + (head)->cqh_first = DWC_CIRCLEQ_END(head); \
  71193. + (head)->cqh_last = DWC_CIRCLEQ_END(head); \
  71194. +} while (0)
  71195. +
  71196. +#define DWC_CIRCLEQ_INIT_ENTRY(elm, field) do { \
  71197. + (elm)->field.cqe_next = NULL; \
  71198. + (elm)->field.cqe_prev = NULL; \
  71199. +} while (0)
  71200. +
  71201. +#define DWC_CIRCLEQ_INSERT_AFTER(head, listelm, elm, field) do { \
  71202. + (elm)->field.cqe_next = (listelm)->field.cqe_next; \
  71203. + (elm)->field.cqe_prev = (listelm); \
  71204. + if ((listelm)->field.cqe_next == DWC_CIRCLEQ_END(head)) \
  71205. + (head)->cqh_last = (elm); \
  71206. + else \
  71207. + (listelm)->field.cqe_next->field.cqe_prev = (elm); \
  71208. + (listelm)->field.cqe_next = (elm); \
  71209. +} while (0)
  71210. +
  71211. +#define DWC_CIRCLEQ_INSERT_BEFORE(head, listelm, elm, field) do { \
  71212. + (elm)->field.cqe_next = (listelm); \
  71213. + (elm)->field.cqe_prev = (listelm)->field.cqe_prev; \
  71214. + if ((listelm)->field.cqe_prev == DWC_CIRCLEQ_END(head)) \
  71215. + (head)->cqh_first = (elm); \
  71216. + else \
  71217. + (listelm)->field.cqe_prev->field.cqe_next = (elm); \
  71218. + (listelm)->field.cqe_prev = (elm); \
  71219. +} while (0)
  71220. +
  71221. +#define DWC_CIRCLEQ_INSERT_HEAD(head, elm, field) do { \
  71222. + (elm)->field.cqe_next = (head)->cqh_first; \
  71223. + (elm)->field.cqe_prev = DWC_CIRCLEQ_END(head); \
  71224. + if ((head)->cqh_last == DWC_CIRCLEQ_END(head)) \
  71225. + (head)->cqh_last = (elm); \
  71226. + else \
  71227. + (head)->cqh_first->field.cqe_prev = (elm); \
  71228. + (head)->cqh_first = (elm); \
  71229. +} while (0)
  71230. +
  71231. +#define DWC_CIRCLEQ_INSERT_TAIL(head, elm, field) do { \
  71232. + (elm)->field.cqe_next = DWC_CIRCLEQ_END(head); \
  71233. + (elm)->field.cqe_prev = (head)->cqh_last; \
  71234. + if ((head)->cqh_first == DWC_CIRCLEQ_END(head)) \
  71235. + (head)->cqh_first = (elm); \
  71236. + else \
  71237. + (head)->cqh_last->field.cqe_next = (elm); \
  71238. + (head)->cqh_last = (elm); \
  71239. +} while (0)
  71240. +
  71241. +#define DWC_CIRCLEQ_REMOVE(head, elm, field) do { \
  71242. + if ((elm)->field.cqe_next == DWC_CIRCLEQ_END(head)) \
  71243. + (head)->cqh_last = (elm)->field.cqe_prev; \
  71244. + else \
  71245. + (elm)->field.cqe_next->field.cqe_prev = \
  71246. + (elm)->field.cqe_prev; \
  71247. + if ((elm)->field.cqe_prev == DWC_CIRCLEQ_END(head)) \
  71248. + (head)->cqh_first = (elm)->field.cqe_next; \
  71249. + else \
  71250. + (elm)->field.cqe_prev->field.cqe_next = \
  71251. + (elm)->field.cqe_next; \
  71252. +} while (0)
  71253. +
  71254. +#define DWC_CIRCLEQ_REMOVE_INIT(head, elm, field) do { \
  71255. + DWC_CIRCLEQ_REMOVE(head, elm, field); \
  71256. + DWC_CIRCLEQ_INIT_ENTRY(elm, field); \
  71257. +} while (0)
  71258. +
  71259. +#define DWC_CIRCLEQ_REPLACE(head, elm, elm2, field) do { \
  71260. + if (((elm2)->field.cqe_next = (elm)->field.cqe_next) == \
  71261. + DWC_CIRCLEQ_END(head)) \
  71262. + (head).cqh_last = (elm2); \
  71263. + else \
  71264. + (elm2)->field.cqe_next->field.cqe_prev = (elm2); \
  71265. + if (((elm2)->field.cqe_prev = (elm)->field.cqe_prev) == \
  71266. + DWC_CIRCLEQ_END(head)) \
  71267. + (head).cqh_first = (elm2); \
  71268. + else \
  71269. + (elm2)->field.cqe_prev->field.cqe_next = (elm2); \
  71270. +} while (0)
  71271. +
  71272. +#ifdef __cplusplus
  71273. +}
  71274. +#endif
  71275. +
  71276. +#endif /* _DWC_LIST_H_ */
  71277. diff -Nur linux-3.18.8/drivers/usb/host/dwc_common_port/dwc_mem.c linux-rpi/drivers/usb/host/dwc_common_port/dwc_mem.c
  71278. --- linux-3.18.8/drivers/usb/host/dwc_common_port/dwc_mem.c 1970-01-01 01:00:00.000000000 +0100
  71279. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_mem.c 2015-03-05 14:40:16.557715806 +0100
  71280. @@ -0,0 +1,245 @@
  71281. +/* Memory Debugging */
  71282. +#ifdef DWC_DEBUG_MEMORY
  71283. +
  71284. +#include "dwc_os.h"
  71285. +#include "dwc_list.h"
  71286. +
  71287. +struct allocation {
  71288. + void *addr;
  71289. + void *ctx;
  71290. + char *func;
  71291. + int line;
  71292. + uint32_t size;
  71293. + int dma;
  71294. + DWC_CIRCLEQ_ENTRY(allocation) entry;
  71295. +};
  71296. +
  71297. +DWC_CIRCLEQ_HEAD(allocation_queue, allocation);
  71298. +
  71299. +struct allocation_manager {
  71300. + void *mem_ctx;
  71301. + struct allocation_queue allocations;
  71302. +
  71303. + /* statistics */
  71304. + int num;
  71305. + int num_freed;
  71306. + int num_active;
  71307. + uint32_t total;
  71308. + uint32_t cur;
  71309. + uint32_t max;
  71310. +};
  71311. +
  71312. +static struct allocation_manager *manager = NULL;
  71313. +
  71314. +static int add_allocation(void *ctx, uint32_t size, char const *func, int line, void *addr,
  71315. + int dma)
  71316. +{
  71317. + struct allocation *a;
  71318. +
  71319. + DWC_ASSERT(manager != NULL, "manager not allocated");
  71320. +
  71321. + a = __DWC_ALLOC_ATOMIC(manager->mem_ctx, sizeof(*a));
  71322. + if (!a) {
  71323. + return -DWC_E_NO_MEMORY;
  71324. + }
  71325. +
  71326. + a->func = __DWC_ALLOC_ATOMIC(manager->mem_ctx, DWC_STRLEN(func) + 1);
  71327. + if (!a->func) {
  71328. + __DWC_FREE(manager->mem_ctx, a);
  71329. + return -DWC_E_NO_MEMORY;
  71330. + }
  71331. +
  71332. + DWC_MEMCPY(a->func, func, DWC_STRLEN(func) + 1);
  71333. + a->addr = addr;
  71334. + a->ctx = ctx;
  71335. + a->line = line;
  71336. + a->size = size;
  71337. + a->dma = dma;
  71338. + DWC_CIRCLEQ_INSERT_TAIL(&manager->allocations, a, entry);
  71339. +
  71340. + /* Update stats */
  71341. + manager->num++;
  71342. + manager->num_active++;
  71343. + manager->total += size;
  71344. + manager->cur += size;
  71345. +
  71346. + if (manager->max < manager->cur) {
  71347. + manager->max = manager->cur;
  71348. + }
  71349. +
  71350. + return 0;
  71351. +}
  71352. +
  71353. +static struct allocation *find_allocation(void *ctx, void *addr)
  71354. +{
  71355. + struct allocation *a;
  71356. +
  71357. + DWC_CIRCLEQ_FOREACH(a, &manager->allocations, entry) {
  71358. + if (a->ctx == ctx && a->addr == addr) {
  71359. + return a;
  71360. + }
  71361. + }
  71362. +
  71363. + return NULL;
  71364. +}
  71365. +
  71366. +static void free_allocation(void *ctx, void *addr, char const *func, int line)
  71367. +{
  71368. + struct allocation *a = find_allocation(ctx, addr);
  71369. +
  71370. + if (!a) {
  71371. + DWC_ASSERT(0,
  71372. + "Free of address %p that was never allocated or already freed %s:%d",
  71373. + addr, func, line);
  71374. + return;
  71375. + }
  71376. +
  71377. + DWC_CIRCLEQ_REMOVE(&manager->allocations, a, entry);
  71378. +
  71379. + manager->num_active--;
  71380. + manager->num_freed++;
  71381. + manager->cur -= a->size;
  71382. + __DWC_FREE(manager->mem_ctx, a->func);
  71383. + __DWC_FREE(manager->mem_ctx, a);
  71384. +}
  71385. +
  71386. +int dwc_memory_debug_start(void *mem_ctx)
  71387. +{
  71388. + DWC_ASSERT(manager == NULL, "Memory debugging has already started\n");
  71389. +
  71390. + if (manager) {
  71391. + return -DWC_E_BUSY;
  71392. + }
  71393. +
  71394. + manager = __DWC_ALLOC(mem_ctx, sizeof(*manager));
  71395. + if (!manager) {
  71396. + return -DWC_E_NO_MEMORY;
  71397. + }
  71398. +
  71399. + DWC_CIRCLEQ_INIT(&manager->allocations);
  71400. + manager->mem_ctx = mem_ctx;
  71401. + manager->num = 0;
  71402. + manager->num_freed = 0;
  71403. + manager->num_active = 0;
  71404. + manager->total = 0;
  71405. + manager->cur = 0;
  71406. + manager->max = 0;
  71407. +
  71408. + return 0;
  71409. +}
  71410. +
  71411. +void dwc_memory_debug_stop(void)
  71412. +{
  71413. + struct allocation *a;
  71414. +
  71415. + dwc_memory_debug_report();
  71416. +
  71417. + DWC_CIRCLEQ_FOREACH(a, &manager->allocations, entry) {
  71418. + DWC_ERROR("Memory leaked from %s:%d\n", a->func, a->line);
  71419. + free_allocation(a->ctx, a->addr, NULL, -1);
  71420. + }
  71421. +
  71422. + __DWC_FREE(manager->mem_ctx, manager);
  71423. +}
  71424. +
  71425. +void dwc_memory_debug_report(void)
  71426. +{
  71427. + struct allocation *a;
  71428. +
  71429. + DWC_PRINTF("\n\n\n----------------- Memory Debugging Report -----------------\n\n");
  71430. + DWC_PRINTF("Num Allocations = %d\n", manager->num);
  71431. + DWC_PRINTF("Freed = %d\n", manager->num_freed);
  71432. + DWC_PRINTF("Active = %d\n", manager->num_active);
  71433. + DWC_PRINTF("Current Memory Used = %d\n", manager->cur);
  71434. + DWC_PRINTF("Total Memory Used = %d\n", manager->total);
  71435. + DWC_PRINTF("Maximum Memory Used at Once = %d\n", manager->max);
  71436. + DWC_PRINTF("Unfreed allocations:\n");
  71437. +
  71438. + DWC_CIRCLEQ_FOREACH(a, &manager->allocations, entry) {
  71439. + DWC_PRINTF(" addr=%p, size=%d from %s:%d, DMA=%d\n",
  71440. + a->addr, a->size, a->func, a->line, a->dma);
  71441. + }
  71442. +}
  71443. +
  71444. +/* The replacement functions */
  71445. +void *dwc_alloc_debug(void *mem_ctx, uint32_t size, char const *func, int line)
  71446. +{
  71447. + void *addr = __DWC_ALLOC(mem_ctx, size);
  71448. +
  71449. + if (!addr) {
  71450. + return NULL;
  71451. + }
  71452. +
  71453. + if (add_allocation(mem_ctx, size, func, line, addr, 0)) {
  71454. + __DWC_FREE(mem_ctx, addr);
  71455. + return NULL;
  71456. + }
  71457. +
  71458. + return addr;
  71459. +}
  71460. +
  71461. +void *dwc_alloc_atomic_debug(void *mem_ctx, uint32_t size, char const *func,
  71462. + int line)
  71463. +{
  71464. + void *addr = __DWC_ALLOC_ATOMIC(mem_ctx, size);
  71465. +
  71466. + if (!addr) {
  71467. + return NULL;
  71468. + }
  71469. +
  71470. + if (add_allocation(mem_ctx, size, func, line, addr, 0)) {
  71471. + __DWC_FREE(mem_ctx, addr);
  71472. + return NULL;
  71473. + }
  71474. +
  71475. + return addr;
  71476. +}
  71477. +
  71478. +void dwc_free_debug(void *mem_ctx, void *addr, char const *func, int line)
  71479. +{
  71480. + free_allocation(mem_ctx, addr, func, line);
  71481. + __DWC_FREE(mem_ctx, addr);
  71482. +}
  71483. +
  71484. +void *dwc_dma_alloc_debug(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr,
  71485. + char const *func, int line)
  71486. +{
  71487. + void *addr = __DWC_DMA_ALLOC(dma_ctx, size, dma_addr);
  71488. +
  71489. + if (!addr) {
  71490. + return NULL;
  71491. + }
  71492. +
  71493. + if (add_allocation(dma_ctx, size, func, line, addr, 1)) {
  71494. + __DWC_DMA_FREE(dma_ctx, size, addr, *dma_addr);
  71495. + return NULL;
  71496. + }
  71497. +
  71498. + return addr;
  71499. +}
  71500. +
  71501. +void *dwc_dma_alloc_atomic_debug(void *dma_ctx, uint32_t size,
  71502. + dwc_dma_t *dma_addr, char const *func, int line)
  71503. +{
  71504. + void *addr = __DWC_DMA_ALLOC_ATOMIC(dma_ctx, size, dma_addr);
  71505. +
  71506. + if (!addr) {
  71507. + return NULL;
  71508. + }
  71509. +
  71510. + if (add_allocation(dma_ctx, size, func, line, addr, 1)) {
  71511. + __DWC_DMA_FREE(dma_ctx, size, addr, *dma_addr);
  71512. + return NULL;
  71513. + }
  71514. +
  71515. + return addr;
  71516. +}
  71517. +
  71518. +void dwc_dma_free_debug(void *dma_ctx, uint32_t size, void *virt_addr,
  71519. + dwc_dma_t dma_addr, char const *func, int line)
  71520. +{
  71521. + free_allocation(dma_ctx, virt_addr, func, line);
  71522. + __DWC_DMA_FREE(dma_ctx, size, virt_addr, dma_addr);
  71523. +}
  71524. +
  71525. +#endif /* DWC_DEBUG_MEMORY */
  71526. diff -Nur linux-3.18.8/drivers/usb/host/dwc_common_port/dwc_modpow.c linux-rpi/drivers/usb/host/dwc_common_port/dwc_modpow.c
  71527. --- linux-3.18.8/drivers/usb/host/dwc_common_port/dwc_modpow.c 1970-01-01 01:00:00.000000000 +0100
  71528. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_modpow.c 2015-03-05 14:40:16.557715806 +0100
  71529. @@ -0,0 +1,636 @@
  71530. +/* Bignum routines adapted from PUTTY sources. PuTTY copyright notice follows.
  71531. + *
  71532. + * PuTTY is copyright 1997-2007 Simon Tatham.
  71533. + *
  71534. + * Portions copyright Robert de Bath, Joris van Rantwijk, Delian
  71535. + * Delchev, Andreas Schultz, Jeroen Massar, Wez Furlong, Nicolas Barry,
  71536. + * Justin Bradford, Ben Harris, Malcolm Smith, Ahmad Khalifa, Markus
  71537. + * Kuhn, and CORE SDI S.A.
  71538. + *
  71539. + * Permission is hereby granted, free of charge, to any person
  71540. + * obtaining a copy of this software and associated documentation files
  71541. + * (the "Software"), to deal in the Software without restriction,
  71542. + * including without limitation the rights to use, copy, modify, merge,
  71543. + * publish, distribute, sublicense, and/or sell copies of the Software,
  71544. + * and to permit persons to whom the Software is furnished to do so,
  71545. + * subject to the following conditions:
  71546. + *
  71547. + * The above copyright notice and this permission notice shall be
  71548. + * included in all copies or substantial portions of the Software.
  71549. +
  71550. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  71551. + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  71552. + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  71553. + * NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE
  71554. + * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
  71555. + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  71556. + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  71557. + *
  71558. + */
  71559. +#ifdef DWC_CRYPTOLIB
  71560. +
  71561. +#ifndef CONFIG_MACH_IPMATE
  71562. +
  71563. +#include "dwc_modpow.h"
  71564. +
  71565. +#define BIGNUM_INT_MASK 0xFFFFFFFFUL
  71566. +#define BIGNUM_TOP_BIT 0x80000000UL
  71567. +#define BIGNUM_INT_BITS 32
  71568. +
  71569. +
  71570. +static void *snmalloc(void *mem_ctx, size_t n, size_t size)
  71571. +{
  71572. + void *p;
  71573. + size *= n;
  71574. + if (size == 0) size = 1;
  71575. + p = dwc_alloc(mem_ctx, size);
  71576. + return p;
  71577. +}
  71578. +
  71579. +#define snewn(ctx, n, type) ((type *)snmalloc((ctx), (n), sizeof(type)))
  71580. +#define sfree dwc_free
  71581. +
  71582. +/*
  71583. + * Usage notes:
  71584. + * * Do not call the DIVMOD_WORD macro with expressions such as array
  71585. + * subscripts, as some implementations object to this (see below).
  71586. + * * Note that none of the division methods below will cope if the
  71587. + * quotient won't fit into BIGNUM_INT_BITS. Callers should be careful
  71588. + * to avoid this case.
  71589. + * If this condition occurs, in the case of the x86 DIV instruction,
  71590. + * an overflow exception will occur, which (according to a correspondent)
  71591. + * will manifest on Windows as something like
  71592. + * 0xC0000095: Integer overflow
  71593. + * The C variant won't give the right answer, either.
  71594. + */
  71595. +
  71596. +#define MUL_WORD(w1, w2) ((BignumDblInt)w1 * w2)
  71597. +
  71598. +#if defined __GNUC__ && defined __i386__
  71599. +#define DIVMOD_WORD(q, r, hi, lo, w) \
  71600. + __asm__("div %2" : \
  71601. + "=d" (r), "=a" (q) : \
  71602. + "r" (w), "d" (hi), "a" (lo))
  71603. +#else
  71604. +#define DIVMOD_WORD(q, r, hi, lo, w) do { \
  71605. + BignumDblInt n = (((BignumDblInt)hi) << BIGNUM_INT_BITS) | lo; \
  71606. + q = n / w; \
  71607. + r = n % w; \
  71608. +} while (0)
  71609. +#endif
  71610. +
  71611. +// q = n / w;
  71612. +// r = n % w;
  71613. +
  71614. +#define BIGNUM_INT_BYTES (BIGNUM_INT_BITS / 8)
  71615. +
  71616. +#define BIGNUM_INTERNAL
  71617. +
  71618. +static Bignum newbn(void *mem_ctx, int length)
  71619. +{
  71620. + Bignum b = snewn(mem_ctx, length + 1, BignumInt);
  71621. + //if (!b)
  71622. + //abort(); /* FIXME */
  71623. + DWC_MEMSET(b, 0, (length + 1) * sizeof(*b));
  71624. + b[0] = length;
  71625. + return b;
  71626. +}
  71627. +
  71628. +void freebn(void *mem_ctx, Bignum b)
  71629. +{
  71630. + /*
  71631. + * Burn the evidence, just in case.
  71632. + */
  71633. + DWC_MEMSET(b, 0, sizeof(b[0]) * (b[0] + 1));
  71634. + sfree(mem_ctx, b);
  71635. +}
  71636. +
  71637. +/*
  71638. + * Compute c = a * b.
  71639. + * Input is in the first len words of a and b.
  71640. + * Result is returned in the first 2*len words of c.
  71641. + */
  71642. +static void internal_mul(BignumInt *a, BignumInt *b,
  71643. + BignumInt *c, int len)
  71644. +{
  71645. + int i, j;
  71646. + BignumDblInt t;
  71647. +
  71648. + for (j = 0; j < 2 * len; j++)
  71649. + c[j] = 0;
  71650. +
  71651. + for (i = len - 1; i >= 0; i--) {
  71652. + t = 0;
  71653. + for (j = len - 1; j >= 0; j--) {
  71654. + t += MUL_WORD(a[i], (BignumDblInt) b[j]);
  71655. + t += (BignumDblInt) c[i + j + 1];
  71656. + c[i + j + 1] = (BignumInt) t;
  71657. + t = t >> BIGNUM_INT_BITS;
  71658. + }
  71659. + c[i] = (BignumInt) t;
  71660. + }
  71661. +}
  71662. +
  71663. +static void internal_add_shifted(BignumInt *number,
  71664. + unsigned n, int shift)
  71665. +{
  71666. + int word = 1 + (shift / BIGNUM_INT_BITS);
  71667. + int bshift = shift % BIGNUM_INT_BITS;
  71668. + BignumDblInt addend;
  71669. +
  71670. + addend = (BignumDblInt)n << bshift;
  71671. +
  71672. + while (addend) {
  71673. + addend += number[word];
  71674. + number[word] = (BignumInt) addend & BIGNUM_INT_MASK;
  71675. + addend >>= BIGNUM_INT_BITS;
  71676. + word++;
  71677. + }
  71678. +}
  71679. +
  71680. +/*
  71681. + * Compute a = a % m.
  71682. + * Input in first alen words of a and first mlen words of m.
  71683. + * Output in first alen words of a
  71684. + * (of which first alen-mlen words will be zero).
  71685. + * The MSW of m MUST have its high bit set.
  71686. + * Quotient is accumulated in the `quotient' array, which is a Bignum
  71687. + * rather than the internal bigendian format. Quotient parts are shifted
  71688. + * left by `qshift' before adding into quot.
  71689. + */
  71690. +static void internal_mod(BignumInt *a, int alen,
  71691. + BignumInt *m, int mlen,
  71692. + BignumInt *quot, int qshift)
  71693. +{
  71694. + BignumInt m0, m1;
  71695. + unsigned int h;
  71696. + int i, k;
  71697. +
  71698. + m0 = m[0];
  71699. + if (mlen > 1)
  71700. + m1 = m[1];
  71701. + else
  71702. + m1 = 0;
  71703. +
  71704. + for (i = 0; i <= alen - mlen; i++) {
  71705. + BignumDblInt t;
  71706. + unsigned int q, r, c, ai1;
  71707. +
  71708. + if (i == 0) {
  71709. + h = 0;
  71710. + } else {
  71711. + h = a[i - 1];
  71712. + a[i - 1] = 0;
  71713. + }
  71714. +
  71715. + if (i == alen - 1)
  71716. + ai1 = 0;
  71717. + else
  71718. + ai1 = a[i + 1];
  71719. +
  71720. + /* Find q = h:a[i] / m0 */
  71721. + if (h >= m0) {
  71722. + /*
  71723. + * Special case.
  71724. + *
  71725. + * To illustrate it, suppose a BignumInt is 8 bits, and
  71726. + * we are dividing (say) A1:23:45:67 by A1:B2:C3. Then
  71727. + * our initial division will be 0xA123 / 0xA1, which
  71728. + * will give a quotient of 0x100 and a divide overflow.
  71729. + * However, the invariants in this division algorithm
  71730. + * are not violated, since the full number A1:23:... is
  71731. + * _less_ than the quotient prefix A1:B2:... and so the
  71732. + * following correction loop would have sorted it out.
  71733. + *
  71734. + * In this situation we set q to be the largest
  71735. + * quotient we _can_ stomach (0xFF, of course).
  71736. + */
  71737. + q = BIGNUM_INT_MASK;
  71738. + } else {
  71739. + /* Macro doesn't want an array subscript expression passed
  71740. + * into it (see definition), so use a temporary. */
  71741. + BignumInt tmplo = a[i];
  71742. + DIVMOD_WORD(q, r, h, tmplo, m0);
  71743. +
  71744. + /* Refine our estimate of q by looking at
  71745. + h:a[i]:a[i+1] / m0:m1 */
  71746. + t = MUL_WORD(m1, q);
  71747. + if (t > ((BignumDblInt) r << BIGNUM_INT_BITS) + ai1) {
  71748. + q--;
  71749. + t -= m1;
  71750. + r = (r + m0) & BIGNUM_INT_MASK; /* overflow? */
  71751. + if (r >= (BignumDblInt) m0 &&
  71752. + t > ((BignumDblInt) r << BIGNUM_INT_BITS) + ai1) q--;
  71753. + }
  71754. + }
  71755. +
  71756. + /* Subtract q * m from a[i...] */
  71757. + c = 0;
  71758. + for (k = mlen - 1; k >= 0; k--) {
  71759. + t = MUL_WORD(q, m[k]);
  71760. + t += c;
  71761. + c = (unsigned)(t >> BIGNUM_INT_BITS);
  71762. + if ((BignumInt) t > a[i + k])
  71763. + c++;
  71764. + a[i + k] -= (BignumInt) t;
  71765. + }
  71766. +
  71767. + /* Add back m in case of borrow */
  71768. + if (c != h) {
  71769. + t = 0;
  71770. + for (k = mlen - 1; k >= 0; k--) {
  71771. + t += m[k];
  71772. + t += a[i + k];
  71773. + a[i + k] = (BignumInt) t;
  71774. + t = t >> BIGNUM_INT_BITS;
  71775. + }
  71776. + q--;
  71777. + }
  71778. + if (quot)
  71779. + internal_add_shifted(quot, q, qshift + BIGNUM_INT_BITS * (alen - mlen - i));
  71780. + }
  71781. +}
  71782. +
  71783. +/*
  71784. + * Compute p % mod.
  71785. + * The most significant word of mod MUST be non-zero.
  71786. + * We assume that the result array is the same size as the mod array.
  71787. + * We optionally write out a quotient if `quotient' is non-NULL.
  71788. + * We can avoid writing out the result if `result' is NULL.
  71789. + */
  71790. +void bigdivmod(void *mem_ctx, Bignum p, Bignum mod, Bignum result, Bignum quotient)
  71791. +{
  71792. + BignumInt *n, *m;
  71793. + int mshift;
  71794. + int plen, mlen, i, j;
  71795. +
  71796. + /* Allocate m of size mlen, copy mod to m */
  71797. + /* We use big endian internally */
  71798. + mlen = mod[0];
  71799. + m = snewn(mem_ctx, mlen, BignumInt);
  71800. + //if (!m)
  71801. + //abort(); /* FIXME */
  71802. + for (j = 0; j < mlen; j++)
  71803. + m[j] = mod[mod[0] - j];
  71804. +
  71805. + /* Shift m left to make msb bit set */
  71806. + for (mshift = 0; mshift < BIGNUM_INT_BITS-1; mshift++)
  71807. + if ((m[0] << mshift) & BIGNUM_TOP_BIT)
  71808. + break;
  71809. + if (mshift) {
  71810. + for (i = 0; i < mlen - 1; i++)
  71811. + m[i] = (m[i] << mshift) | (m[i + 1] >> (BIGNUM_INT_BITS - mshift));
  71812. + m[mlen - 1] = m[mlen - 1] << mshift;
  71813. + }
  71814. +
  71815. + plen = p[0];
  71816. + /* Ensure plen > mlen */
  71817. + if (plen <= mlen)
  71818. + plen = mlen + 1;
  71819. +
  71820. + /* Allocate n of size plen, copy p to n */
  71821. + n = snewn(mem_ctx, plen, BignumInt);
  71822. + //if (!n)
  71823. + //abort(); /* FIXME */
  71824. + for (j = 0; j < plen; j++)
  71825. + n[j] = 0;
  71826. + for (j = 1; j <= (int)p[0]; j++)
  71827. + n[plen - j] = p[j];
  71828. +
  71829. + /* Main computation */
  71830. + internal_mod(n, plen, m, mlen, quotient, mshift);
  71831. +
  71832. + /* Fixup result in case the modulus was shifted */
  71833. + if (mshift) {
  71834. + for (i = plen - mlen - 1; i < plen - 1; i++)
  71835. + n[i] = (n[i] << mshift) | (n[i + 1] >> (BIGNUM_INT_BITS - mshift));
  71836. + n[plen - 1] = n[plen - 1] << mshift;
  71837. + internal_mod(n, plen, m, mlen, quotient, 0);
  71838. + for (i = plen - 1; i >= plen - mlen; i--)
  71839. + n[i] = (n[i] >> mshift) | (n[i - 1] << (BIGNUM_INT_BITS - mshift));
  71840. + }
  71841. +
  71842. + /* Copy result to buffer */
  71843. + if (result) {
  71844. + for (i = 1; i <= (int)result[0]; i++) {
  71845. + int j = plen - i;
  71846. + result[i] = j >= 0 ? n[j] : 0;
  71847. + }
  71848. + }
  71849. +
  71850. + /* Free temporary arrays */
  71851. + for (i = 0; i < mlen; i++)
  71852. + m[i] = 0;
  71853. + sfree(mem_ctx, m);
  71854. + for (i = 0; i < plen; i++)
  71855. + n[i] = 0;
  71856. + sfree(mem_ctx, n);
  71857. +}
  71858. +
  71859. +/*
  71860. + * Simple remainder.
  71861. + */
  71862. +Bignum bigmod(void *mem_ctx, Bignum a, Bignum b)
  71863. +{
  71864. + Bignum r = newbn(mem_ctx, b[0]);
  71865. + bigdivmod(mem_ctx, a, b, r, NULL);
  71866. + return r;
  71867. +}
  71868. +
  71869. +/*
  71870. + * Compute (base ^ exp) % mod.
  71871. + */
  71872. +Bignum dwc_modpow(void *mem_ctx, Bignum base_in, Bignum exp, Bignum mod)
  71873. +{
  71874. + BignumInt *a, *b, *n, *m;
  71875. + int mshift;
  71876. + int mlen, i, j;
  71877. + Bignum base, result;
  71878. +
  71879. + /*
  71880. + * The most significant word of mod needs to be non-zero. It
  71881. + * should already be, but let's make sure.
  71882. + */
  71883. + //assert(mod[mod[0]] != 0);
  71884. +
  71885. + /*
  71886. + * Make sure the base is smaller than the modulus, by reducing
  71887. + * it modulo the modulus if not.
  71888. + */
  71889. + base = bigmod(mem_ctx, base_in, mod);
  71890. +
  71891. + /* Allocate m of size mlen, copy mod to m */
  71892. + /* We use big endian internally */
  71893. + mlen = mod[0];
  71894. + m = snewn(mem_ctx, mlen, BignumInt);
  71895. + //if (!m)
  71896. + //abort(); /* FIXME */
  71897. + for (j = 0; j < mlen; j++)
  71898. + m[j] = mod[mod[0] - j];
  71899. +
  71900. + /* Shift m left to make msb bit set */
  71901. + for (mshift = 0; mshift < BIGNUM_INT_BITS - 1; mshift++)
  71902. + if ((m[0] << mshift) & BIGNUM_TOP_BIT)
  71903. + break;
  71904. + if (mshift) {
  71905. + for (i = 0; i < mlen - 1; i++)
  71906. + m[i] =
  71907. + (m[i] << mshift) | (m[i + 1] >>
  71908. + (BIGNUM_INT_BITS - mshift));
  71909. + m[mlen - 1] = m[mlen - 1] << mshift;
  71910. + }
  71911. +
  71912. + /* Allocate n of size mlen, copy base to n */
  71913. + n = snewn(mem_ctx, mlen, BignumInt);
  71914. + //if (!n)
  71915. + //abort(); /* FIXME */
  71916. + i = mlen - base[0];
  71917. + for (j = 0; j < i; j++)
  71918. + n[j] = 0;
  71919. + for (j = 0; j < base[0]; j++)
  71920. + n[i + j] = base[base[0] - j];
  71921. +
  71922. + /* Allocate a and b of size 2*mlen. Set a = 1 */
  71923. + a = snewn(mem_ctx, 2 * mlen, BignumInt);
  71924. + //if (!a)
  71925. + //abort(); /* FIXME */
  71926. + b = snewn(mem_ctx, 2 * mlen, BignumInt);
  71927. + //if (!b)
  71928. + //abort(); /* FIXME */
  71929. + for (i = 0; i < 2 * mlen; i++)
  71930. + a[i] = 0;
  71931. + a[2 * mlen - 1] = 1;
  71932. +
  71933. + /* Skip leading zero bits of exp. */
  71934. + i = 0;
  71935. + j = BIGNUM_INT_BITS - 1;
  71936. + while (i < exp[0] && (exp[exp[0] - i] & (1 << j)) == 0) {
  71937. + j--;
  71938. + if (j < 0) {
  71939. + i++;
  71940. + j = BIGNUM_INT_BITS - 1;
  71941. + }
  71942. + }
  71943. +
  71944. + /* Main computation */
  71945. + while (i < exp[0]) {
  71946. + while (j >= 0) {
  71947. + internal_mul(a + mlen, a + mlen, b, mlen);
  71948. + internal_mod(b, mlen * 2, m, mlen, NULL, 0);
  71949. + if ((exp[exp[0] - i] & (1 << j)) != 0) {
  71950. + internal_mul(b + mlen, n, a, mlen);
  71951. + internal_mod(a, mlen * 2, m, mlen, NULL, 0);
  71952. + } else {
  71953. + BignumInt *t;
  71954. + t = a;
  71955. + a = b;
  71956. + b = t;
  71957. + }
  71958. + j--;
  71959. + }
  71960. + i++;
  71961. + j = BIGNUM_INT_BITS - 1;
  71962. + }
  71963. +
  71964. + /* Fixup result in case the modulus was shifted */
  71965. + if (mshift) {
  71966. + for (i = mlen - 1; i < 2 * mlen - 1; i++)
  71967. + a[i] =
  71968. + (a[i] << mshift) | (a[i + 1] >>
  71969. + (BIGNUM_INT_BITS - mshift));
  71970. + a[2 * mlen - 1] = a[2 * mlen - 1] << mshift;
  71971. + internal_mod(a, mlen * 2, m, mlen, NULL, 0);
  71972. + for (i = 2 * mlen - 1; i >= mlen; i--)
  71973. + a[i] =
  71974. + (a[i] >> mshift) | (a[i - 1] <<
  71975. + (BIGNUM_INT_BITS - mshift));
  71976. + }
  71977. +
  71978. + /* Copy result to buffer */
  71979. + result = newbn(mem_ctx, mod[0]);
  71980. + for (i = 0; i < mlen; i++)
  71981. + result[result[0] - i] = a[i + mlen];
  71982. + while (result[0] > 1 && result[result[0]] == 0)
  71983. + result[0]--;
  71984. +
  71985. + /* Free temporary arrays */
  71986. + for (i = 0; i < 2 * mlen; i++)
  71987. + a[i] = 0;
  71988. + sfree(mem_ctx, a);
  71989. + for (i = 0; i < 2 * mlen; i++)
  71990. + b[i] = 0;
  71991. + sfree(mem_ctx, b);
  71992. + for (i = 0; i < mlen; i++)
  71993. + m[i] = 0;
  71994. + sfree(mem_ctx, m);
  71995. + for (i = 0; i < mlen; i++)
  71996. + n[i] = 0;
  71997. + sfree(mem_ctx, n);
  71998. +
  71999. + freebn(mem_ctx, base);
  72000. +
  72001. + return result;
  72002. +}
  72003. +
  72004. +
  72005. +#ifdef UNITTEST
  72006. +
  72007. +static __u32 dh_p[] = {
  72008. + 96,
  72009. + 0xFFFFFFFF,
  72010. + 0xFFFFFFFF,
  72011. + 0xA93AD2CA,
  72012. + 0x4B82D120,
  72013. + 0xE0FD108E,
  72014. + 0x43DB5BFC,
  72015. + 0x74E5AB31,
  72016. + 0x08E24FA0,
  72017. + 0xBAD946E2,
  72018. + 0x770988C0,
  72019. + 0x7A615D6C,
  72020. + 0xBBE11757,
  72021. + 0x177B200C,
  72022. + 0x521F2B18,
  72023. + 0x3EC86A64,
  72024. + 0xD8760273,
  72025. + 0xD98A0864,
  72026. + 0xF12FFA06,
  72027. + 0x1AD2EE6B,
  72028. + 0xCEE3D226,
  72029. + 0x4A25619D,
  72030. + 0x1E8C94E0,
  72031. + 0xDB0933D7,
  72032. + 0xABF5AE8C,
  72033. + 0xA6E1E4C7,
  72034. + 0xB3970F85,
  72035. + 0x5D060C7D,
  72036. + 0x8AEA7157,
  72037. + 0x58DBEF0A,
  72038. + 0xECFB8504,
  72039. + 0xDF1CBA64,
  72040. + 0xA85521AB,
  72041. + 0x04507A33,
  72042. + 0xAD33170D,
  72043. + 0x8AAAC42D,
  72044. + 0x15728E5A,
  72045. + 0x98FA0510,
  72046. + 0x15D22618,
  72047. + 0xEA956AE5,
  72048. + 0x3995497C,
  72049. + 0x95581718,
  72050. + 0xDE2BCBF6,
  72051. + 0x6F4C52C9,
  72052. + 0xB5C55DF0,
  72053. + 0xEC07A28F,
  72054. + 0x9B2783A2,
  72055. + 0x180E8603,
  72056. + 0xE39E772C,
  72057. + 0x2E36CE3B,
  72058. + 0x32905E46,
  72059. + 0xCA18217C,
  72060. + 0xF1746C08,
  72061. + 0x4ABC9804,
  72062. + 0x670C354E,
  72063. + 0x7096966D,
  72064. + 0x9ED52907,
  72065. + 0x208552BB,
  72066. + 0x1C62F356,
  72067. + 0xDCA3AD96,
  72068. + 0x83655D23,
  72069. + 0xFD24CF5F,
  72070. + 0x69163FA8,
  72071. + 0x1C55D39A,
  72072. + 0x98DA4836,
  72073. + 0xA163BF05,
  72074. + 0xC2007CB8,
  72075. + 0xECE45B3D,
  72076. + 0x49286651,
  72077. + 0x7C4B1FE6,
  72078. + 0xAE9F2411,
  72079. + 0x5A899FA5,
  72080. + 0xEE386BFB,
  72081. + 0xF406B7ED,
  72082. + 0x0BFF5CB6,
  72083. + 0xA637ED6B,
  72084. + 0xF44C42E9,
  72085. + 0x625E7EC6,
  72086. + 0xE485B576,
  72087. + 0x6D51C245,
  72088. + 0x4FE1356D,
  72089. + 0xF25F1437,
  72090. + 0x302B0A6D,
  72091. + 0xCD3A431B,
  72092. + 0xEF9519B3,
  72093. + 0x8E3404DD,
  72094. + 0x514A0879,
  72095. + 0x3B139B22,
  72096. + 0x020BBEA6,
  72097. + 0x8A67CC74,
  72098. + 0x29024E08,
  72099. + 0x80DC1CD1,
  72100. + 0xC4C6628B,
  72101. + 0x2168C234,
  72102. + 0xC90FDAA2,
  72103. + 0xFFFFFFFF,
  72104. + 0xFFFFFFFF,
  72105. +};
  72106. +
  72107. +static __u32 dh_a[] = {
  72108. + 8,
  72109. + 0xdf367516,
  72110. + 0x86459caa,
  72111. + 0xe2d459a4,
  72112. + 0xd910dae0,
  72113. + 0x8a8b5e37,
  72114. + 0x67ab31c6,
  72115. + 0xf0b55ea9,
  72116. + 0x440051d6,
  72117. +};
  72118. +
  72119. +static __u32 dh_b[] = {
  72120. + 8,
  72121. + 0xded92656,
  72122. + 0xe07a048a,
  72123. + 0x6fa452cd,
  72124. + 0x2df89d30,
  72125. + 0xc75f1b0f,
  72126. + 0x8ce3578f,
  72127. + 0x7980a324,
  72128. + 0x5daec786,
  72129. +};
  72130. +
  72131. +static __u32 dh_g[] = {
  72132. + 1,
  72133. + 2,
  72134. +};
  72135. +
  72136. +int main(void)
  72137. +{
  72138. + int i;
  72139. + __u32 *k;
  72140. + k = dwc_modpow(NULL, dh_g, dh_a, dh_p);
  72141. +
  72142. + printf("\n\n");
  72143. + for (i=0; i<k[0]; i++) {
  72144. + __u32 word32 = k[k[0] - i];
  72145. + __u16 l = word32 & 0xffff;
  72146. + __u16 m = (word32 & 0xffff0000) >> 16;
  72147. + printf("%04x %04x ", m, l);
  72148. + if (!((i + 1)%13)) printf("\n");
  72149. + }
  72150. + printf("\n\n");
  72151. +
  72152. + if ((k[0] == 0x60) && (k[1] == 0x28e490e5) && (k[0x60] == 0x5a0d3d4e)) {
  72153. + printf("PASS\n\n");
  72154. + }
  72155. + else {
  72156. + printf("FAIL\n\n");
  72157. + }
  72158. +
  72159. +}
  72160. +
  72161. +#endif /* UNITTEST */
  72162. +
  72163. +#endif /* CONFIG_MACH_IPMATE */
  72164. +
  72165. +#endif /*DWC_CRYPTOLIB */
  72166. diff -Nur linux-3.18.8/drivers/usb/host/dwc_common_port/dwc_modpow.h linux-rpi/drivers/usb/host/dwc_common_port/dwc_modpow.h
  72167. --- linux-3.18.8/drivers/usb/host/dwc_common_port/dwc_modpow.h 1970-01-01 01:00:00.000000000 +0100
  72168. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_modpow.h 2015-03-05 14:40:16.557715806 +0100
  72169. @@ -0,0 +1,34 @@
  72170. +/*
  72171. + * dwc_modpow.h
  72172. + * See dwc_modpow.c for license and changes
  72173. + */
  72174. +#ifndef _DWC_MODPOW_H
  72175. +#define _DWC_MODPOW_H
  72176. +
  72177. +#ifdef __cplusplus
  72178. +extern "C" {
  72179. +#endif
  72180. +
  72181. +#include "dwc_os.h"
  72182. +
  72183. +/** @file
  72184. + *
  72185. + * This file defines the module exponentiation function which is only used
  72186. + * internally by the DWC UWB modules for calculation of PKs during numeric
  72187. + * association. The routine is taken from the PUTTY, an open source terminal
  72188. + * emulator. The PUTTY License is preserved in the dwc_modpow.c file.
  72189. + *
  72190. + */
  72191. +
  72192. +typedef uint32_t BignumInt;
  72193. +typedef uint64_t BignumDblInt;
  72194. +typedef BignumInt *Bignum;
  72195. +
  72196. +/* Compute modular exponentiaion */
  72197. +extern Bignum dwc_modpow(void *mem_ctx, Bignum base_in, Bignum exp, Bignum mod);
  72198. +
  72199. +#ifdef __cplusplus
  72200. +}
  72201. +#endif
  72202. +
  72203. +#endif /* _LINUX_BIGNUM_H */
  72204. diff -Nur linux-3.18.8/drivers/usb/host/dwc_common_port/dwc_notifier.c linux-rpi/drivers/usb/host/dwc_common_port/dwc_notifier.c
  72205. --- linux-3.18.8/drivers/usb/host/dwc_common_port/dwc_notifier.c 1970-01-01 01:00:00.000000000 +0100
  72206. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_notifier.c 2015-03-05 14:40:16.557715806 +0100
  72207. @@ -0,0 +1,319 @@
  72208. +#ifdef DWC_NOTIFYLIB
  72209. +
  72210. +#include "dwc_notifier.h"
  72211. +#include "dwc_list.h"
  72212. +
  72213. +typedef struct dwc_observer {
  72214. + void *observer;
  72215. + dwc_notifier_callback_t callback;
  72216. + void *data;
  72217. + char *notification;
  72218. + DWC_CIRCLEQ_ENTRY(dwc_observer) list_entry;
  72219. +} observer_t;
  72220. +
  72221. +DWC_CIRCLEQ_HEAD(observer_queue, dwc_observer);
  72222. +
  72223. +typedef struct dwc_notifier {
  72224. + void *mem_ctx;
  72225. + void *object;
  72226. + struct observer_queue observers;
  72227. + DWC_CIRCLEQ_ENTRY(dwc_notifier) list_entry;
  72228. +} notifier_t;
  72229. +
  72230. +DWC_CIRCLEQ_HEAD(notifier_queue, dwc_notifier);
  72231. +
  72232. +typedef struct manager {
  72233. + void *mem_ctx;
  72234. + void *wkq_ctx;
  72235. + dwc_workq_t *wq;
  72236. +// dwc_mutex_t *mutex;
  72237. + struct notifier_queue notifiers;
  72238. +} manager_t;
  72239. +
  72240. +static manager_t *manager = NULL;
  72241. +
  72242. +static int create_manager(void *mem_ctx, void *wkq_ctx)
  72243. +{
  72244. + manager = dwc_alloc(mem_ctx, sizeof(manager_t));
  72245. + if (!manager) {
  72246. + return -DWC_E_NO_MEMORY;
  72247. + }
  72248. +
  72249. + DWC_CIRCLEQ_INIT(&manager->notifiers);
  72250. +
  72251. + manager->wq = dwc_workq_alloc(wkq_ctx, "DWC Notification WorkQ");
  72252. + if (!manager->wq) {
  72253. + return -DWC_E_NO_MEMORY;
  72254. + }
  72255. +
  72256. + return 0;
  72257. +}
  72258. +
  72259. +static void free_manager(void)
  72260. +{
  72261. + dwc_workq_free(manager->wq);
  72262. +
  72263. + /* All notifiers must have unregistered themselves before this module
  72264. + * can be removed. Hitting this assertion indicates a programmer
  72265. + * error. */
  72266. + DWC_ASSERT(DWC_CIRCLEQ_EMPTY(&manager->notifiers),
  72267. + "Notification manager being freed before all notifiers have been removed");
  72268. + dwc_free(manager->mem_ctx, manager);
  72269. +}
  72270. +
  72271. +#ifdef DEBUG
  72272. +static void dump_manager(void)
  72273. +{
  72274. + notifier_t *n;
  72275. + observer_t *o;
  72276. +
  72277. + DWC_ASSERT(manager, "Notification manager not found");
  72278. +
  72279. + DWC_DEBUG("List of all notifiers and observers:\n");
  72280. + DWC_CIRCLEQ_FOREACH(n, &manager->notifiers, list_entry) {
  72281. + DWC_DEBUG("Notifier %p has observers:\n", n->object);
  72282. + DWC_CIRCLEQ_FOREACH(o, &n->observers, list_entry) {
  72283. + DWC_DEBUG(" %p watching %s\n", o->observer, o->notification);
  72284. + }
  72285. + }
  72286. +}
  72287. +#else
  72288. +#define dump_manager(...)
  72289. +#endif
  72290. +
  72291. +static observer_t *alloc_observer(void *mem_ctx, void *observer, char *notification,
  72292. + dwc_notifier_callback_t callback, void *data)
  72293. +{
  72294. + observer_t *new_observer = dwc_alloc(mem_ctx, sizeof(observer_t));
  72295. +
  72296. + if (!new_observer) {
  72297. + return NULL;
  72298. + }
  72299. +
  72300. + DWC_CIRCLEQ_INIT_ENTRY(new_observer, list_entry);
  72301. + new_observer->observer = observer;
  72302. + new_observer->notification = notification;
  72303. + new_observer->callback = callback;
  72304. + new_observer->data = data;
  72305. + return new_observer;
  72306. +}
  72307. +
  72308. +static void free_observer(void *mem_ctx, observer_t *observer)
  72309. +{
  72310. + dwc_free(mem_ctx, observer);
  72311. +}
  72312. +
  72313. +static notifier_t *alloc_notifier(void *mem_ctx, void *object)
  72314. +{
  72315. + notifier_t *notifier;
  72316. +
  72317. + if (!object) {
  72318. + return NULL;
  72319. + }
  72320. +
  72321. + notifier = dwc_alloc(mem_ctx, sizeof(notifier_t));
  72322. + if (!notifier) {
  72323. + return NULL;
  72324. + }
  72325. +
  72326. + DWC_CIRCLEQ_INIT(&notifier->observers);
  72327. + DWC_CIRCLEQ_INIT_ENTRY(notifier, list_entry);
  72328. +
  72329. + notifier->mem_ctx = mem_ctx;
  72330. + notifier->object = object;
  72331. + return notifier;
  72332. +}
  72333. +
  72334. +static void free_notifier(notifier_t *notifier)
  72335. +{
  72336. + observer_t *observer;
  72337. +
  72338. + DWC_CIRCLEQ_FOREACH(observer, &notifier->observers, list_entry) {
  72339. + free_observer(notifier->mem_ctx, observer);
  72340. + }
  72341. +
  72342. + dwc_free(notifier->mem_ctx, notifier);
  72343. +}
  72344. +
  72345. +static notifier_t *find_notifier(void *object)
  72346. +{
  72347. + notifier_t *notifier;
  72348. +
  72349. + DWC_ASSERT(manager, "Notification manager not found");
  72350. +
  72351. + if (!object) {
  72352. + return NULL;
  72353. + }
  72354. +
  72355. + DWC_CIRCLEQ_FOREACH(notifier, &manager->notifiers, list_entry) {
  72356. + if (notifier->object == object) {
  72357. + return notifier;
  72358. + }
  72359. + }
  72360. +
  72361. + return NULL;
  72362. +}
  72363. +
  72364. +int dwc_alloc_notification_manager(void *mem_ctx, void *wkq_ctx)
  72365. +{
  72366. + return create_manager(mem_ctx, wkq_ctx);
  72367. +}
  72368. +
  72369. +void dwc_free_notification_manager(void)
  72370. +{
  72371. + free_manager();
  72372. +}
  72373. +
  72374. +dwc_notifier_t *dwc_register_notifier(void *mem_ctx, void *object)
  72375. +{
  72376. + notifier_t *notifier;
  72377. +
  72378. + DWC_ASSERT(manager, "Notification manager not found");
  72379. +
  72380. + notifier = find_notifier(object);
  72381. + if (notifier) {
  72382. + DWC_ERROR("Notifier %p is already registered\n", object);
  72383. + return NULL;
  72384. + }
  72385. +
  72386. + notifier = alloc_notifier(mem_ctx, object);
  72387. + if (!notifier) {
  72388. + return NULL;
  72389. + }
  72390. +
  72391. + DWC_CIRCLEQ_INSERT_TAIL(&manager->notifiers, notifier, list_entry);
  72392. +
  72393. + DWC_INFO("Notifier %p registered", object);
  72394. + dump_manager();
  72395. +
  72396. + return notifier;
  72397. +}
  72398. +
  72399. +void dwc_unregister_notifier(dwc_notifier_t *notifier)
  72400. +{
  72401. + DWC_ASSERT(manager, "Notification manager not found");
  72402. +
  72403. + if (!DWC_CIRCLEQ_EMPTY(&notifier->observers)) {
  72404. + observer_t *o;
  72405. +
  72406. + DWC_ERROR("Notifier %p has active observers when removing\n", notifier->object);
  72407. + DWC_CIRCLEQ_FOREACH(o, &notifier->observers, list_entry) {
  72408. + DWC_DEBUGC(" %p watching %s\n", o->observer, o->notification);
  72409. + }
  72410. +
  72411. + DWC_ASSERT(DWC_CIRCLEQ_EMPTY(&notifier->observers),
  72412. + "Notifier %p has active observers when removing", notifier);
  72413. + }
  72414. +
  72415. + DWC_CIRCLEQ_REMOVE_INIT(&manager->notifiers, notifier, list_entry);
  72416. + free_notifier(notifier);
  72417. +
  72418. + DWC_INFO("Notifier unregistered");
  72419. + dump_manager();
  72420. +}
  72421. +
  72422. +/* Add an observer to observe the notifier for a particular state, event, or notification. */
  72423. +int dwc_add_observer(void *observer, void *object, char *notification,
  72424. + dwc_notifier_callback_t callback, void *data)
  72425. +{
  72426. + notifier_t *notifier = find_notifier(object);
  72427. + observer_t *new_observer;
  72428. +
  72429. + if (!notifier) {
  72430. + DWC_ERROR("Notifier %p is not found when adding observer\n", object);
  72431. + return -DWC_E_INVALID;
  72432. + }
  72433. +
  72434. + new_observer = alloc_observer(notifier->mem_ctx, observer, notification, callback, data);
  72435. + if (!new_observer) {
  72436. + return -DWC_E_NO_MEMORY;
  72437. + }
  72438. +
  72439. + DWC_CIRCLEQ_INSERT_TAIL(&notifier->observers, new_observer, list_entry);
  72440. +
  72441. + DWC_INFO("Added observer %p to notifier %p observing notification %s, callback=%p, data=%p",
  72442. + observer, object, notification, callback, data);
  72443. +
  72444. + dump_manager();
  72445. + return 0;
  72446. +}
  72447. +
  72448. +int dwc_remove_observer(void *observer)
  72449. +{
  72450. + notifier_t *n;
  72451. +
  72452. + DWC_ASSERT(manager, "Notification manager not found");
  72453. +
  72454. + DWC_CIRCLEQ_FOREACH(n, &manager->notifiers, list_entry) {
  72455. + observer_t *o;
  72456. + observer_t *o2;
  72457. +
  72458. + DWC_CIRCLEQ_FOREACH_SAFE(o, o2, &n->observers, list_entry) {
  72459. + if (o->observer == observer) {
  72460. + DWC_CIRCLEQ_REMOVE_INIT(&n->observers, o, list_entry);
  72461. + DWC_INFO("Removing observer %p from notifier %p watching notification %s:",
  72462. + o->observer, n->object, o->notification);
  72463. + free_observer(n->mem_ctx, o);
  72464. + }
  72465. + }
  72466. + }
  72467. +
  72468. + dump_manager();
  72469. + return 0;
  72470. +}
  72471. +
  72472. +typedef struct callback_data {
  72473. + void *mem_ctx;
  72474. + dwc_notifier_callback_t cb;
  72475. + void *observer;
  72476. + void *data;
  72477. + void *object;
  72478. + char *notification;
  72479. + void *notification_data;
  72480. +} cb_data_t;
  72481. +
  72482. +static void cb_task(void *data)
  72483. +{
  72484. + cb_data_t *cb = (cb_data_t *)data;
  72485. +
  72486. + cb->cb(cb->object, cb->notification, cb->observer, cb->notification_data, cb->data);
  72487. + dwc_free(cb->mem_ctx, cb);
  72488. +}
  72489. +
  72490. +void dwc_notify(dwc_notifier_t *notifier, char *notification, void *notification_data)
  72491. +{
  72492. + observer_t *o;
  72493. +
  72494. + DWC_ASSERT(manager, "Notification manager not found");
  72495. +
  72496. + DWC_CIRCLEQ_FOREACH(o, &notifier->observers, list_entry) {
  72497. + int len = DWC_STRLEN(notification);
  72498. +
  72499. + if (DWC_STRLEN(o->notification) != len) {
  72500. + continue;
  72501. + }
  72502. +
  72503. + if (DWC_STRNCMP(o->notification, notification, len) == 0) {
  72504. + cb_data_t *cb_data = dwc_alloc(notifier->mem_ctx, sizeof(cb_data_t));
  72505. +
  72506. + if (!cb_data) {
  72507. + DWC_ERROR("Failed to allocate callback data\n");
  72508. + return;
  72509. + }
  72510. +
  72511. + cb_data->mem_ctx = notifier->mem_ctx;
  72512. + cb_data->cb = o->callback;
  72513. + cb_data->observer = o->observer;
  72514. + cb_data->data = o->data;
  72515. + cb_data->object = notifier->object;
  72516. + cb_data->notification = notification;
  72517. + cb_data->notification_data = notification_data;
  72518. + DWC_DEBUGC("Observer found %p for notification %s\n", o->observer, notification);
  72519. + DWC_WORKQ_SCHEDULE(manager->wq, cb_task, cb_data,
  72520. + "Notify callback from %p for Notification %s, to observer %p",
  72521. + cb_data->object, notification, cb_data->observer);
  72522. + }
  72523. + }
  72524. +}
  72525. +
  72526. +#endif /* DWC_NOTIFYLIB */
  72527. diff -Nur linux-3.18.8/drivers/usb/host/dwc_common_port/dwc_notifier.h linux-rpi/drivers/usb/host/dwc_common_port/dwc_notifier.h
  72528. --- linux-3.18.8/drivers/usb/host/dwc_common_port/dwc_notifier.h 1970-01-01 01:00:00.000000000 +0100
  72529. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_notifier.h 2015-03-05 14:40:16.557715806 +0100
  72530. @@ -0,0 +1,122 @@
  72531. +
  72532. +#ifndef __DWC_NOTIFIER_H__
  72533. +#define __DWC_NOTIFIER_H__
  72534. +
  72535. +#ifdef __cplusplus
  72536. +extern "C" {
  72537. +#endif
  72538. +
  72539. +#include "dwc_os.h"
  72540. +
  72541. +/** @file
  72542. + *
  72543. + * A simple implementation of the Observer pattern. Any "module" can
  72544. + * register as an observer or notifier. The notion of "module" is abstract and
  72545. + * can mean anything used to identify either an observer or notifier. Usually
  72546. + * it will be a pointer to a data structure which contains some state, ie an
  72547. + * object.
  72548. + *
  72549. + * Before any notifiers can be added, the global notification manager must be
  72550. + * brought up with dwc_alloc_notification_manager().
  72551. + * dwc_free_notification_manager() will bring it down and free all resources.
  72552. + * These would typically be called upon module load and unload. The
  72553. + * notification manager is a single global instance that handles all registered
  72554. + * observable modules and observers so this should be done only once.
  72555. + *
  72556. + * A module can be observable by using Notifications to publicize some general
  72557. + * information about it's state or operation. It does not care who listens, or
  72558. + * even if anyone listens, or what they do with the information. The observable
  72559. + * modules do not need to know any information about it's observers or their
  72560. + * interface, or their state or data.
  72561. + *
  72562. + * Any module can register to emit Notifications. It should publish a list of
  72563. + * notifications that it can emit and their behavior, such as when they will get
  72564. + * triggered, and what information will be provided to the observer. Then it
  72565. + * should register itself as an observable module. See dwc_register_notifier().
  72566. + *
  72567. + * Any module can observe any observable, registered module, provided it has a
  72568. + * handle to the other module and knows what notifications to observe. See
  72569. + * dwc_add_observer().
  72570. + *
  72571. + * A function of type dwc_notifier_callback_t is called whenever a notification
  72572. + * is triggered with one or more observers observing it. This function is
  72573. + * called in it's own process so it may sleep or block if needed. It is
  72574. + * guaranteed to be called sometime after the notification has occurred and will
  72575. + * be called once per each time the notification is triggered. It will NOT be
  72576. + * called in the same process context used to trigger the notification.
  72577. + *
  72578. + * @section Limitiations
  72579. + *
  72580. + * Keep in mind that Notifications that can be triggered in rapid sucession may
  72581. + * schedule too many processes too handle. Be aware of this limitation when
  72582. + * designing to use notifications, and only add notifications for appropriate
  72583. + * observable information.
  72584. + *
  72585. + * Also Notification callbacks are not synchronous. If you need to synchronize
  72586. + * the behavior between module/observer you must use other means. And perhaps
  72587. + * that will mean Notifications are not the proper solution.
  72588. + */
  72589. +
  72590. +struct dwc_notifier;
  72591. +typedef struct dwc_notifier dwc_notifier_t;
  72592. +
  72593. +/** The callback function must be of this type.
  72594. + *
  72595. + * @param object This is the object that is being observed.
  72596. + * @param notification This is the notification that was triggered.
  72597. + * @param observer This is the observer
  72598. + * @param notification_data This is notification-specific data that the notifier
  72599. + * has included in this notification. The value of this should be published in
  72600. + * the documentation of the observable module with the notifications.
  72601. + * @param user_data This is any custom data that the observer provided when
  72602. + * adding itself as an observer to the notification. */
  72603. +typedef void (*dwc_notifier_callback_t)(void *object, char *notification, void *observer,
  72604. + void *notification_data, void *user_data);
  72605. +
  72606. +/** Brings up the notification manager. */
  72607. +extern int dwc_alloc_notification_manager(void *mem_ctx, void *wkq_ctx);
  72608. +/** Brings down the notification manager. */
  72609. +extern void dwc_free_notification_manager(void);
  72610. +
  72611. +/** This function registers an observable module. A dwc_notifier_t object is
  72612. + * returned to the observable module. This is an opaque object that is used by
  72613. + * the observable module to trigger notifications. This object should only be
  72614. + * accessible to functions that are authorized to trigger notifications for this
  72615. + * module. Observers do not need this object. */
  72616. +extern dwc_notifier_t *dwc_register_notifier(void *mem_ctx, void *object);
  72617. +
  72618. +/** This function unregisters an observable module. All observers have to be
  72619. + * removed prior to unregistration. */
  72620. +extern void dwc_unregister_notifier(dwc_notifier_t *notifier);
  72621. +
  72622. +/** Add a module as an observer to the observable module. The observable module
  72623. + * needs to have previously registered with the notification manager.
  72624. + *
  72625. + * @param observer The observer module
  72626. + * @param object The module to observe
  72627. + * @param notification The notification to observe
  72628. + * @param callback The callback function to call
  72629. + * @param user_data Any additional user data to pass into the callback function */
  72630. +extern int dwc_add_observer(void *observer, void *object, char *notification,
  72631. + dwc_notifier_callback_t callback, void *user_data);
  72632. +
  72633. +/** Removes the specified observer from all notifications that it is currently
  72634. + * observing. */
  72635. +extern int dwc_remove_observer(void *observer);
  72636. +
  72637. +/** This function triggers a Notification. It should be called by the
  72638. + * observable module, or any module or library which the observable module
  72639. + * allows to trigger notification on it's behalf. Such as the dwc_cc_t.
  72640. + *
  72641. + * dwc_notify is a non-blocking function. Callbacks are scheduled called in
  72642. + * their own process context for each trigger. Callbacks can be blocking.
  72643. + * dwc_notify can be called from interrupt context if needed.
  72644. + *
  72645. + */
  72646. +void dwc_notify(dwc_notifier_t *notifier, char *notification, void *notification_data);
  72647. +
  72648. +#ifdef __cplusplus
  72649. +}
  72650. +#endif
  72651. +
  72652. +#endif /* __DWC_NOTIFIER_H__ */
  72653. diff -Nur linux-3.18.8/drivers/usb/host/dwc_common_port/dwc_os.h linux-rpi/drivers/usb/host/dwc_common_port/dwc_os.h
  72654. --- linux-3.18.8/drivers/usb/host/dwc_common_port/dwc_os.h 1970-01-01 01:00:00.000000000 +0100
  72655. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_os.h 2015-03-05 14:40:16.557715806 +0100
  72656. @@ -0,0 +1,1276 @@
  72657. +/* =========================================================================
  72658. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_os.h $
  72659. + * $Revision: #14 $
  72660. + * $Date: 2010/11/04 $
  72661. + * $Change: 1621695 $
  72662. + *
  72663. + * Synopsys Portability Library Software and documentation
  72664. + * (hereinafter, "Software") is an Unsupported proprietary work of
  72665. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  72666. + * between Synopsys and you.
  72667. + *
  72668. + * The Software IS NOT an item of Licensed Software or Licensed Product
  72669. + * under any End User Software License Agreement or Agreement for
  72670. + * Licensed Product with Synopsys or any supplement thereto. You are
  72671. + * permitted to use and redistribute this Software in source and binary
  72672. + * forms, with or without modification, provided that redistributions
  72673. + * of source code must retain this notice. You may not view, use,
  72674. + * disclose, copy or distribute this file or any information contained
  72675. + * herein except pursuant to this license grant from Synopsys. If you
  72676. + * do not agree with this notice, including the disclaimer below, then
  72677. + * you are not authorized to use the Software.
  72678. + *
  72679. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  72680. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  72681. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  72682. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  72683. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  72684. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  72685. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  72686. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  72687. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  72688. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  72689. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  72690. + * DAMAGE.
  72691. + * ========================================================================= */
  72692. +#ifndef _DWC_OS_H_
  72693. +#define _DWC_OS_H_
  72694. +
  72695. +#ifdef __cplusplus
  72696. +extern "C" {
  72697. +#endif
  72698. +
  72699. +/** @file
  72700. + *
  72701. + * DWC portability library, low level os-wrapper functions
  72702. + *
  72703. + */
  72704. +
  72705. +/* These basic types need to be defined by some OS header file or custom header
  72706. + * file for your specific target architecture.
  72707. + *
  72708. + * uint8_t, int8_t, uint16_t, int16_t, uint32_t, int32_t, uint64_t, int64_t
  72709. + *
  72710. + * Any custom or alternate header file must be added and enabled here.
  72711. + */
  72712. +
  72713. +#ifdef DWC_LINUX
  72714. +# include <linux/types.h>
  72715. +# ifdef CONFIG_DEBUG_MUTEXES
  72716. +# include <linux/mutex.h>
  72717. +# endif
  72718. +# include <linux/spinlock.h>
  72719. +# include <linux/errno.h>
  72720. +# include <stdarg.h>
  72721. +#endif
  72722. +
  72723. +#if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  72724. +# include <os_dep.h>
  72725. +#endif
  72726. +
  72727. +
  72728. +/** @name Primitive Types and Values */
  72729. +
  72730. +/** We define a boolean type for consistency. Can be either YES or NO */
  72731. +typedef uint8_t dwc_bool_t;
  72732. +#define YES 1
  72733. +#define NO 0
  72734. +
  72735. +#ifdef DWC_LINUX
  72736. +
  72737. +/** @name Error Codes */
  72738. +#define DWC_E_INVALID EINVAL
  72739. +#define DWC_E_NO_MEMORY ENOMEM
  72740. +#define DWC_E_NO_DEVICE ENODEV
  72741. +#define DWC_E_NOT_SUPPORTED EOPNOTSUPP
  72742. +#define DWC_E_TIMEOUT ETIMEDOUT
  72743. +#define DWC_E_BUSY EBUSY
  72744. +#define DWC_E_AGAIN EAGAIN
  72745. +#define DWC_E_RESTART ERESTART
  72746. +#define DWC_E_ABORT ECONNABORTED
  72747. +#define DWC_E_SHUTDOWN ESHUTDOWN
  72748. +#define DWC_E_NO_DATA ENODATA
  72749. +#define DWC_E_DISCONNECT ECONNRESET
  72750. +#define DWC_E_UNKNOWN EINVAL
  72751. +#define DWC_E_NO_STREAM_RES ENOSR
  72752. +#define DWC_E_COMMUNICATION ECOMM
  72753. +#define DWC_E_OVERFLOW EOVERFLOW
  72754. +#define DWC_E_PROTOCOL EPROTO
  72755. +#define DWC_E_IN_PROGRESS EINPROGRESS
  72756. +#define DWC_E_PIPE EPIPE
  72757. +#define DWC_E_IO EIO
  72758. +#define DWC_E_NO_SPACE ENOSPC
  72759. +
  72760. +#else
  72761. +
  72762. +/** @name Error Codes */
  72763. +#define DWC_E_INVALID 1001
  72764. +#define DWC_E_NO_MEMORY 1002
  72765. +#define DWC_E_NO_DEVICE 1003
  72766. +#define DWC_E_NOT_SUPPORTED 1004
  72767. +#define DWC_E_TIMEOUT 1005
  72768. +#define DWC_E_BUSY 1006
  72769. +#define DWC_E_AGAIN 1007
  72770. +#define DWC_E_RESTART 1008
  72771. +#define DWC_E_ABORT 1009
  72772. +#define DWC_E_SHUTDOWN 1010
  72773. +#define DWC_E_NO_DATA 1011
  72774. +#define DWC_E_DISCONNECT 2000
  72775. +#define DWC_E_UNKNOWN 3000
  72776. +#define DWC_E_NO_STREAM_RES 4001
  72777. +#define DWC_E_COMMUNICATION 4002
  72778. +#define DWC_E_OVERFLOW 4003
  72779. +#define DWC_E_PROTOCOL 4004
  72780. +#define DWC_E_IN_PROGRESS 4005
  72781. +#define DWC_E_PIPE 4006
  72782. +#define DWC_E_IO 4007
  72783. +#define DWC_E_NO_SPACE 4008
  72784. +
  72785. +#endif
  72786. +
  72787. +
  72788. +/** @name Tracing/Logging Functions
  72789. + *
  72790. + * These function provide the capability to add tracing, debugging, and error
  72791. + * messages, as well exceptions as assertions. The WUDEV uses these
  72792. + * extensively. These could be logged to the main console, the serial port, an
  72793. + * internal buffer, etc. These functions could also be no-op if they are too
  72794. + * expensive on your system. By default undefining the DEBUG macro already
  72795. + * no-ops some of these functions. */
  72796. +
  72797. +/** Returns non-zero if in interrupt context. */
  72798. +extern dwc_bool_t DWC_IN_IRQ(void);
  72799. +#define dwc_in_irq DWC_IN_IRQ
  72800. +
  72801. +/** Returns "IRQ" if DWC_IN_IRQ is true. */
  72802. +static inline char *dwc_irq(void) {
  72803. + return DWC_IN_IRQ() ? "IRQ" : "";
  72804. +}
  72805. +
  72806. +/** Returns non-zero if in bottom-half context. */
  72807. +extern dwc_bool_t DWC_IN_BH(void);
  72808. +#define dwc_in_bh DWC_IN_BH
  72809. +
  72810. +/** Returns "BH" if DWC_IN_BH is true. */
  72811. +static inline char *dwc_bh(void) {
  72812. + return DWC_IN_BH() ? "BH" : "";
  72813. +}
  72814. +
  72815. +/**
  72816. + * A vprintf() clone. Just call vprintf if you've got it.
  72817. + */
  72818. +extern void DWC_VPRINTF(char *format, va_list args);
  72819. +#define dwc_vprintf DWC_VPRINTF
  72820. +
  72821. +/**
  72822. + * A vsnprintf() clone. Just call vprintf if you've got it.
  72823. + */
  72824. +extern int DWC_VSNPRINTF(char *str, int size, char *format, va_list args);
  72825. +#define dwc_vsnprintf DWC_VSNPRINTF
  72826. +
  72827. +/**
  72828. + * printf() clone. Just call printf if you've go it.
  72829. + */
  72830. +extern void DWC_PRINTF(char *format, ...)
  72831. +/* This provides compiler level static checking of the parameters if you're
  72832. + * using GCC. */
  72833. +#ifdef __GNUC__
  72834. + __attribute__ ((format(printf, 1, 2)));
  72835. +#else
  72836. + ;
  72837. +#endif
  72838. +#define dwc_printf DWC_PRINTF
  72839. +
  72840. +/**
  72841. + * sprintf() clone. Just call sprintf if you've got it.
  72842. + */
  72843. +extern int DWC_SPRINTF(char *string, char *format, ...)
  72844. +#ifdef __GNUC__
  72845. + __attribute__ ((format(printf, 2, 3)));
  72846. +#else
  72847. + ;
  72848. +#endif
  72849. +#define dwc_sprintf DWC_SPRINTF
  72850. +
  72851. +/**
  72852. + * snprintf() clone. Just call snprintf if you've got it.
  72853. + */
  72854. +extern int DWC_SNPRINTF(char *string, int size, char *format, ...)
  72855. +#ifdef __GNUC__
  72856. + __attribute__ ((format(printf, 3, 4)));
  72857. +#else
  72858. + ;
  72859. +#endif
  72860. +#define dwc_snprintf DWC_SNPRINTF
  72861. +
  72862. +/**
  72863. + * Prints a WARNING message. On systems that don't differentiate between
  72864. + * warnings and regular log messages, just print it. Indicates that something
  72865. + * may be wrong with the driver. Works like printf().
  72866. + *
  72867. + * Use the DWC_WARN macro to call this function.
  72868. + */
  72869. +extern void __DWC_WARN(char *format, ...)
  72870. +#ifdef __GNUC__
  72871. + __attribute__ ((format(printf, 1, 2)));
  72872. +#else
  72873. + ;
  72874. +#endif
  72875. +
  72876. +/**
  72877. + * Prints an error message. On systems that don't differentiate between errors
  72878. + * and regular log messages, just print it. Indicates that something went wrong
  72879. + * with the driver. Works like printf().
  72880. + *
  72881. + * Use the DWC_ERROR macro to call this function.
  72882. + */
  72883. +extern void __DWC_ERROR(char *format, ...)
  72884. +#ifdef __GNUC__
  72885. + __attribute__ ((format(printf, 1, 2)));
  72886. +#else
  72887. + ;
  72888. +#endif
  72889. +
  72890. +/**
  72891. + * Prints an exception error message and takes some user-defined action such as
  72892. + * print out a backtrace or trigger a breakpoint. Indicates that something went
  72893. + * abnormally wrong with the driver such as programmer error, or other
  72894. + * exceptional condition. It should not be ignored so even on systems without
  72895. + * printing capability, some action should be taken to notify the developer of
  72896. + * it. Works like printf().
  72897. + */
  72898. +extern void DWC_EXCEPTION(char *format, ...)
  72899. +#ifdef __GNUC__
  72900. + __attribute__ ((format(printf, 1, 2)));
  72901. +#else
  72902. + ;
  72903. +#endif
  72904. +#define dwc_exception DWC_EXCEPTION
  72905. +
  72906. +#ifndef DWC_OTG_DEBUG_LEV
  72907. +#define DWC_OTG_DEBUG_LEV 0
  72908. +#endif
  72909. +
  72910. +#ifdef DEBUG
  72911. +/**
  72912. + * Prints out a debug message. Used for logging/trace messages.
  72913. + *
  72914. + * Use the DWC_DEBUG macro to call this function
  72915. + */
  72916. +extern void __DWC_DEBUG(char *format, ...)
  72917. +#ifdef __GNUC__
  72918. + __attribute__ ((format(printf, 1, 2)));
  72919. +#else
  72920. + ;
  72921. +#endif
  72922. +#else
  72923. +#define __DWC_DEBUG printk
  72924. +#endif
  72925. +
  72926. +/**
  72927. + * Prints out a Debug message.
  72928. + */
  72929. +#define DWC_DEBUG(_format, _args...) __DWC_DEBUG("DEBUG:%s:%s: " _format "\n", \
  72930. + __func__, dwc_irq(), ## _args)
  72931. +#define dwc_debug DWC_DEBUG
  72932. +/**
  72933. + * Prints out a Debug message if enabled at compile time.
  72934. + */
  72935. +#if DWC_OTG_DEBUG_LEV > 0
  72936. +#define DWC_DEBUGC(_format, _args...) DWC_DEBUG(_format, ##_args )
  72937. +#else
  72938. +#define DWC_DEBUGC(_format, _args...)
  72939. +#endif
  72940. +#define dwc_debugc DWC_DEBUGC
  72941. +/**
  72942. + * Prints out an informative message.
  72943. + */
  72944. +#define DWC_INFO(_format, _args...) DWC_PRINTF("INFO:%s: " _format "\n", \
  72945. + dwc_irq(), ## _args)
  72946. +#define dwc_info DWC_INFO
  72947. +/**
  72948. + * Prints out an informative message if enabled at compile time.
  72949. + */
  72950. +#if DWC_OTG_DEBUG_LEV > 1
  72951. +#define DWC_INFOC(_format, _args...) DWC_INFO(_format, ##_args )
  72952. +#else
  72953. +#define DWC_INFOC(_format, _args...)
  72954. +#endif
  72955. +#define dwc_infoc DWC_INFOC
  72956. +/**
  72957. + * Prints out a warning message.
  72958. + */
  72959. +#define DWC_WARN(_format, _args...) __DWC_WARN("WARN:%s:%s:%d: " _format "\n", \
  72960. + dwc_irq(), __func__, __LINE__, ## _args)
  72961. +#define dwc_warn DWC_WARN
  72962. +/**
  72963. + * Prints out an error message.
  72964. + */
  72965. +#define DWC_ERROR(_format, _args...) __DWC_ERROR("ERROR:%s:%s:%d: " _format "\n", \
  72966. + dwc_irq(), __func__, __LINE__, ## _args)
  72967. +#define dwc_error DWC_ERROR
  72968. +
  72969. +#define DWC_PROTO_ERROR(_format, _args...) __DWC_WARN("ERROR:%s:%s:%d: " _format "\n", \
  72970. + dwc_irq(), __func__, __LINE__, ## _args)
  72971. +#define dwc_proto_error DWC_PROTO_ERROR
  72972. +
  72973. +#ifdef DEBUG
  72974. +/** Prints out a exception error message if the _expr expression fails. Disabled
  72975. + * if DEBUG is not enabled. */
  72976. +#define DWC_ASSERT(_expr, _format, _args...) do { \
  72977. + if (!(_expr)) { DWC_EXCEPTION("%s:%s:%d: " _format "\n", dwc_irq(), \
  72978. + __FILE__, __LINE__, ## _args); } \
  72979. + } while (0)
  72980. +#else
  72981. +#define DWC_ASSERT(_x...)
  72982. +#endif
  72983. +#define dwc_assert DWC_ASSERT
  72984. +
  72985. +
  72986. +/** @name Byte Ordering
  72987. + * The following functions are for conversions between processor's byte ordering
  72988. + * and specific ordering you want.
  72989. + */
  72990. +
  72991. +/** Converts 32 bit data in CPU byte ordering to little endian. */
  72992. +extern uint32_t DWC_CPU_TO_LE32(uint32_t *p);
  72993. +#define dwc_cpu_to_le32 DWC_CPU_TO_LE32
  72994. +
  72995. +/** Converts 32 bit data in CPU byte orderint to big endian. */
  72996. +extern uint32_t DWC_CPU_TO_BE32(uint32_t *p);
  72997. +#define dwc_cpu_to_be32 DWC_CPU_TO_BE32
  72998. +
  72999. +/** Converts 32 bit little endian data to CPU byte ordering. */
  73000. +extern uint32_t DWC_LE32_TO_CPU(uint32_t *p);
  73001. +#define dwc_le32_to_cpu DWC_LE32_TO_CPU
  73002. +
  73003. +/** Converts 32 bit big endian data to CPU byte ordering. */
  73004. +extern uint32_t DWC_BE32_TO_CPU(uint32_t *p);
  73005. +#define dwc_be32_to_cpu DWC_BE32_TO_CPU
  73006. +
  73007. +/** Converts 16 bit data in CPU byte ordering to little endian. */
  73008. +extern uint16_t DWC_CPU_TO_LE16(uint16_t *p);
  73009. +#define dwc_cpu_to_le16 DWC_CPU_TO_LE16
  73010. +
  73011. +/** Converts 16 bit data in CPU byte orderint to big endian. */
  73012. +extern uint16_t DWC_CPU_TO_BE16(uint16_t *p);
  73013. +#define dwc_cpu_to_be16 DWC_CPU_TO_BE16
  73014. +
  73015. +/** Converts 16 bit little endian data to CPU byte ordering. */
  73016. +extern uint16_t DWC_LE16_TO_CPU(uint16_t *p);
  73017. +#define dwc_le16_to_cpu DWC_LE16_TO_CPU
  73018. +
  73019. +/** Converts 16 bit bi endian data to CPU byte ordering. */
  73020. +extern uint16_t DWC_BE16_TO_CPU(uint16_t *p);
  73021. +#define dwc_be16_to_cpu DWC_BE16_TO_CPU
  73022. +
  73023. +
  73024. +/** @name Register Read/Write
  73025. + *
  73026. + * The following six functions should be implemented to read/write registers of
  73027. + * 32-bit and 64-bit sizes. All modules use this to read/write register values.
  73028. + * The reg value is a pointer to the register calculated from the void *base
  73029. + * variable passed into the driver when it is started. */
  73030. +
  73031. +#ifdef DWC_LINUX
  73032. +/* Linux doesn't need any extra parameters for register read/write, so we
  73033. + * just throw away the IO context parameter.
  73034. + */
  73035. +/** Reads the content of a 32-bit register. */
  73036. +extern uint32_t DWC_READ_REG32(uint32_t volatile *reg);
  73037. +#define dwc_read_reg32(_ctx_,_reg_) DWC_READ_REG32(_reg_)
  73038. +
  73039. +/** Reads the content of a 64-bit register. */
  73040. +extern uint64_t DWC_READ_REG64(uint64_t volatile *reg);
  73041. +#define dwc_read_reg64(_ctx_,_reg_) DWC_READ_REG64(_reg_)
  73042. +
  73043. +/** Writes to a 32-bit register. */
  73044. +extern void DWC_WRITE_REG32(uint32_t volatile *reg, uint32_t value);
  73045. +#define dwc_write_reg32(_ctx_,_reg_,_val_) DWC_WRITE_REG32(_reg_, _val_)
  73046. +
  73047. +/** Writes to a 64-bit register. */
  73048. +extern void DWC_WRITE_REG64(uint64_t volatile *reg, uint64_t value);
  73049. +#define dwc_write_reg64(_ctx_,_reg_,_val_) DWC_WRITE_REG64(_reg_, _val_)
  73050. +
  73051. +/**
  73052. + * Modify bit values in a register. Using the
  73053. + * algorithm: (reg_contents & ~clear_mask) | set_mask.
  73054. + */
  73055. +extern void DWC_MODIFY_REG32(uint32_t volatile *reg, uint32_t clear_mask, uint32_t set_mask);
  73056. +#define dwc_modify_reg32(_ctx_,_reg_,_cmsk_,_smsk_) DWC_MODIFY_REG32(_reg_,_cmsk_,_smsk_)
  73057. +extern void DWC_MODIFY_REG64(uint64_t volatile *reg, uint64_t clear_mask, uint64_t set_mask);
  73058. +#define dwc_modify_reg64(_ctx_,_reg_,_cmsk_,_smsk_) DWC_MODIFY_REG64(_reg_,_cmsk_,_smsk_)
  73059. +
  73060. +#endif /* DWC_LINUX */
  73061. +
  73062. +#if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  73063. +typedef struct dwc_ioctx {
  73064. + struct device *dev;
  73065. + bus_space_tag_t iot;
  73066. + bus_space_handle_t ioh;
  73067. +} dwc_ioctx_t;
  73068. +
  73069. +/** BSD needs two extra parameters for register read/write, so we pass
  73070. + * them in using the IO context parameter.
  73071. + */
  73072. +/** Reads the content of a 32-bit register. */
  73073. +extern uint32_t DWC_READ_REG32(void *io_ctx, uint32_t volatile *reg);
  73074. +#define dwc_read_reg32 DWC_READ_REG32
  73075. +
  73076. +/** Reads the content of a 64-bit register. */
  73077. +extern uint64_t DWC_READ_REG64(void *io_ctx, uint64_t volatile *reg);
  73078. +#define dwc_read_reg64 DWC_READ_REG64
  73079. +
  73080. +/** Writes to a 32-bit register. */
  73081. +extern void DWC_WRITE_REG32(void *io_ctx, uint32_t volatile *reg, uint32_t value);
  73082. +#define dwc_write_reg32 DWC_WRITE_REG32
  73083. +
  73084. +/** Writes to a 64-bit register. */
  73085. +extern void DWC_WRITE_REG64(void *io_ctx, uint64_t volatile *reg, uint64_t value);
  73086. +#define dwc_write_reg64 DWC_WRITE_REG64
  73087. +
  73088. +/**
  73089. + * Modify bit values in a register. Using the
  73090. + * algorithm: (reg_contents & ~clear_mask) | set_mask.
  73091. + */
  73092. +extern void DWC_MODIFY_REG32(void *io_ctx, uint32_t volatile *reg, uint32_t clear_mask, uint32_t set_mask);
  73093. +#define dwc_modify_reg32 DWC_MODIFY_REG32
  73094. +extern void DWC_MODIFY_REG64(void *io_ctx, uint64_t volatile *reg, uint64_t clear_mask, uint64_t set_mask);
  73095. +#define dwc_modify_reg64 DWC_MODIFY_REG64
  73096. +
  73097. +#endif /* DWC_FREEBSD || DWC_NETBSD */
  73098. +
  73099. +/** @cond */
  73100. +
  73101. +/** @name Some convenience MACROS used internally. Define DWC_DEBUG_REGS to log the
  73102. + * register writes. */
  73103. +
  73104. +#ifdef DWC_LINUX
  73105. +
  73106. +# ifdef DWC_DEBUG_REGS
  73107. +
  73108. +#define dwc_define_read_write_reg_n(_reg,_container_type) \
  73109. +static inline uint32_t dwc_read_##_reg##_n(_container_type *container, int num) { \
  73110. + return DWC_READ_REG32(&container->regs->_reg[num]); \
  73111. +} \
  73112. +static inline void dwc_write_##_reg##_n(_container_type *container, int num, uint32_t data) { \
  73113. + DWC_DEBUG("WRITING %8s[%d]: %p: %08x", #_reg, num, \
  73114. + &(((uint32_t*)container->regs->_reg)[num]), data); \
  73115. + DWC_WRITE_REG32(&(((uint32_t*)container->regs->_reg)[num]), data); \
  73116. +}
  73117. +
  73118. +#define dwc_define_read_write_reg(_reg,_container_type) \
  73119. +static inline uint32_t dwc_read_##_reg(_container_type *container) { \
  73120. + return DWC_READ_REG32(&container->regs->_reg); \
  73121. +} \
  73122. +static inline void dwc_write_##_reg(_container_type *container, uint32_t data) { \
  73123. + DWC_DEBUG("WRITING %11s: %p: %08x", #_reg, &container->regs->_reg, data); \
  73124. + DWC_WRITE_REG32(&container->regs->_reg, data); \
  73125. +}
  73126. +
  73127. +# else /* DWC_DEBUG_REGS */
  73128. +
  73129. +#define dwc_define_read_write_reg_n(_reg,_container_type) \
  73130. +static inline uint32_t dwc_read_##_reg##_n(_container_type *container, int num) { \
  73131. + return DWC_READ_REG32(&container->regs->_reg[num]); \
  73132. +} \
  73133. +static inline void dwc_write_##_reg##_n(_container_type *container, int num, uint32_t data) { \
  73134. + DWC_WRITE_REG32(&(((uint32_t*)container->regs->_reg)[num]), data); \
  73135. +}
  73136. +
  73137. +#define dwc_define_read_write_reg(_reg,_container_type) \
  73138. +static inline uint32_t dwc_read_##_reg(_container_type *container) { \
  73139. + return DWC_READ_REG32(&container->regs->_reg); \
  73140. +} \
  73141. +static inline void dwc_write_##_reg(_container_type *container, uint32_t data) { \
  73142. + DWC_WRITE_REG32(&container->regs->_reg, data); \
  73143. +}
  73144. +
  73145. +# endif /* DWC_DEBUG_REGS */
  73146. +
  73147. +#endif /* DWC_LINUX */
  73148. +
  73149. +#if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  73150. +
  73151. +# ifdef DWC_DEBUG_REGS
  73152. +
  73153. +#define dwc_define_read_write_reg_n(_reg,_container_type) \
  73154. +static inline uint32_t dwc_read_##_reg##_n(void *io_ctx, _container_type *container, int num) { \
  73155. + return DWC_READ_REG32(io_ctx, &container->regs->_reg[num]); \
  73156. +} \
  73157. +static inline void dwc_write_##_reg##_n(void *io_ctx, _container_type *container, int num, uint32_t data) { \
  73158. + DWC_DEBUG("WRITING %8s[%d]: %p: %08x", #_reg, num, \
  73159. + &(((uint32_t*)container->regs->_reg)[num]), data); \
  73160. + DWC_WRITE_REG32(io_ctx, &(((uint32_t*)container->regs->_reg)[num]), data); \
  73161. +}
  73162. +
  73163. +#define dwc_define_read_write_reg(_reg,_container_type) \
  73164. +static inline uint32_t dwc_read_##_reg(void *io_ctx, _container_type *container) { \
  73165. + return DWC_READ_REG32(io_ctx, &container->regs->_reg); \
  73166. +} \
  73167. +static inline void dwc_write_##_reg(void *io_ctx, _container_type *container, uint32_t data) { \
  73168. + DWC_DEBUG("WRITING %11s: %p: %08x", #_reg, &container->regs->_reg, data); \
  73169. + DWC_WRITE_REG32(io_ctx, &container->regs->_reg, data); \
  73170. +}
  73171. +
  73172. +# else /* DWC_DEBUG_REGS */
  73173. +
  73174. +#define dwc_define_read_write_reg_n(_reg,_container_type) \
  73175. +static inline uint32_t dwc_read_##_reg##_n(void *io_ctx, _container_type *container, int num) { \
  73176. + return DWC_READ_REG32(io_ctx, &container->regs->_reg[num]); \
  73177. +} \
  73178. +static inline void dwc_write_##_reg##_n(void *io_ctx, _container_type *container, int num, uint32_t data) { \
  73179. + DWC_WRITE_REG32(io_ctx, &(((uint32_t*)container->regs->_reg)[num]), data); \
  73180. +}
  73181. +
  73182. +#define dwc_define_read_write_reg(_reg,_container_type) \
  73183. +static inline uint32_t dwc_read_##_reg(void *io_ctx, _container_type *container) { \
  73184. + return DWC_READ_REG32(io_ctx, &container->regs->_reg); \
  73185. +} \
  73186. +static inline void dwc_write_##_reg(void *io_ctx, _container_type *container, uint32_t data) { \
  73187. + DWC_WRITE_REG32(io_ctx, &container->regs->_reg, data); \
  73188. +}
  73189. +
  73190. +# endif /* DWC_DEBUG_REGS */
  73191. +
  73192. +#endif /* DWC_FREEBSD || DWC_NETBSD */
  73193. +
  73194. +/** @endcond */
  73195. +
  73196. +
  73197. +#ifdef DWC_CRYPTOLIB
  73198. +/** @name Crypto Functions
  73199. + *
  73200. + * These are the low-level cryptographic functions used by the driver. */
  73201. +
  73202. +/** Perform AES CBC */
  73203. +extern int DWC_AES_CBC(uint8_t *message, uint32_t messagelen, uint8_t *key, uint32_t keylen, uint8_t iv[16], uint8_t *out);
  73204. +#define dwc_aes_cbc DWC_AES_CBC
  73205. +
  73206. +/** Fill the provided buffer with random bytes. These should be cryptographic grade random numbers. */
  73207. +extern void DWC_RANDOM_BYTES(uint8_t *buffer, uint32_t length);
  73208. +#define dwc_random_bytes DWC_RANDOM_BYTES
  73209. +
  73210. +/** Perform the SHA-256 hash function */
  73211. +extern int DWC_SHA256(uint8_t *message, uint32_t len, uint8_t *out);
  73212. +#define dwc_sha256 DWC_SHA256
  73213. +
  73214. +/** Calculated the HMAC-SHA256 */
  73215. +extern int DWC_HMAC_SHA256(uint8_t *message, uint32_t messagelen, uint8_t *key, uint32_t keylen, uint8_t *out);
  73216. +#define dwc_hmac_sha256 DWC_HMAC_SHA256
  73217. +
  73218. +#endif /* DWC_CRYPTOLIB */
  73219. +
  73220. +
  73221. +/** @name Memory Allocation
  73222. + *
  73223. + * These function provide access to memory allocation. There are only 2 DMA
  73224. + * functions and 3 Regular memory functions that need to be implemented. None
  73225. + * of the memory debugging routines need to be implemented. The allocation
  73226. + * routines all ZERO the contents of the memory.
  73227. + *
  73228. + * Defining DWC_DEBUG_MEMORY turns on memory debugging and statistic gathering.
  73229. + * This checks for memory leaks, keeping track of alloc/free pairs. It also
  73230. + * keeps track of how much memory the driver is using at any given time. */
  73231. +
  73232. +#define DWC_PAGE_SIZE 4096
  73233. +#define DWC_PAGE_OFFSET(addr) (((uint32_t)addr) & 0xfff)
  73234. +#define DWC_PAGE_ALIGNED(addr) ((((uint32_t)addr) & 0xfff) == 0)
  73235. +
  73236. +#define DWC_INVALID_DMA_ADDR 0x0
  73237. +
  73238. +#ifdef DWC_LINUX
  73239. +/** Type for a DMA address */
  73240. +typedef dma_addr_t dwc_dma_t;
  73241. +#endif
  73242. +
  73243. +#if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  73244. +typedef bus_addr_t dwc_dma_t;
  73245. +#endif
  73246. +
  73247. +#ifdef DWC_FREEBSD
  73248. +typedef struct dwc_dmactx {
  73249. + struct device *dev;
  73250. + bus_dma_tag_t dma_tag;
  73251. + bus_dmamap_t dma_map;
  73252. + bus_addr_t dma_paddr;
  73253. + void *dma_vaddr;
  73254. +} dwc_dmactx_t;
  73255. +#endif
  73256. +
  73257. +#ifdef DWC_NETBSD
  73258. +typedef struct dwc_dmactx {
  73259. + struct device *dev;
  73260. + bus_dma_tag_t dma_tag;
  73261. + bus_dmamap_t dma_map;
  73262. + bus_dma_segment_t segs[1];
  73263. + int nsegs;
  73264. + bus_addr_t dma_paddr;
  73265. + void *dma_vaddr;
  73266. +} dwc_dmactx_t;
  73267. +#endif
  73268. +
  73269. +/* @todo these functions will be added in the future */
  73270. +#if 0
  73271. +/**
  73272. + * Creates a DMA pool from which you can allocate DMA buffers. Buffers
  73273. + * allocated from this pool will be guaranteed to meet the size, alignment, and
  73274. + * boundary requirements specified.
  73275. + *
  73276. + * @param[in] size Specifies the size of the buffers that will be allocated from
  73277. + * this pool.
  73278. + * @param[in] align Specifies the byte alignment requirements of the buffers
  73279. + * allocated from this pool. Must be a power of 2.
  73280. + * @param[in] boundary Specifies the N-byte boundary that buffers allocated from
  73281. + * this pool must not cross.
  73282. + *
  73283. + * @returns A pointer to an internal opaque structure which is not to be
  73284. + * accessed outside of these library functions. Use this handle to specify
  73285. + * which pools to allocate/free DMA buffers from and also to destroy the pool,
  73286. + * when you are done with it.
  73287. + */
  73288. +extern dwc_pool_t *DWC_DMA_POOL_CREATE(uint32_t size, uint32_t align, uint32_t boundary);
  73289. +
  73290. +/**
  73291. + * Destroy a DMA pool. All buffers allocated from that pool must be freed first.
  73292. + */
  73293. +extern void DWC_DMA_POOL_DESTROY(dwc_pool_t *pool);
  73294. +
  73295. +/**
  73296. + * Allocate a buffer from the specified DMA pool and zeros its contents.
  73297. + */
  73298. +extern void *DWC_DMA_POOL_ALLOC(dwc_pool_t *pool, uint64_t *dma_addr);
  73299. +
  73300. +/**
  73301. + * Free a previously allocated buffer from the DMA pool.
  73302. + */
  73303. +extern void DWC_DMA_POOL_FREE(dwc_pool_t *pool, void *vaddr, void *daddr);
  73304. +#endif
  73305. +
  73306. +/** Allocates a DMA capable buffer and zeroes its contents. */
  73307. +extern void *__DWC_DMA_ALLOC(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr);
  73308. +
  73309. +/** Allocates a DMA capable buffer and zeroes its contents in atomic contest */
  73310. +extern void *__DWC_DMA_ALLOC_ATOMIC(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr);
  73311. +
  73312. +/** Frees a previously allocated buffer. */
  73313. +extern void __DWC_DMA_FREE(void *dma_ctx, uint32_t size, void *virt_addr, dwc_dma_t dma_addr);
  73314. +
  73315. +/** Allocates a block of memory and zeroes its contents. */
  73316. +extern void *__DWC_ALLOC(void *mem_ctx, uint32_t size);
  73317. +
  73318. +/** Allocates a block of memory and zeroes its contents, in an atomic manner
  73319. + * which can be used inside interrupt context. The size should be sufficiently
  73320. + * small, a few KB at most, such that failures are not likely to occur. Can just call
  73321. + * __DWC_ALLOC if it is atomic. */
  73322. +extern void *__DWC_ALLOC_ATOMIC(void *mem_ctx, uint32_t size);
  73323. +
  73324. +/** Frees a previously allocated buffer. */
  73325. +extern void __DWC_FREE(void *mem_ctx, void *addr);
  73326. +
  73327. +#ifndef DWC_DEBUG_MEMORY
  73328. +
  73329. +#define DWC_ALLOC(_size_) __DWC_ALLOC(NULL, _size_)
  73330. +#define DWC_ALLOC_ATOMIC(_size_) __DWC_ALLOC_ATOMIC(NULL, _size_)
  73331. +#define DWC_FREE(_addr_) __DWC_FREE(NULL, _addr_)
  73332. +
  73333. +# ifdef DWC_LINUX
  73334. +#define DWC_DMA_ALLOC(_size_,_dma_) __DWC_DMA_ALLOC(NULL, _size_, _dma_)
  73335. +#define DWC_DMA_ALLOC_ATOMIC(_size_,_dma_) __DWC_DMA_ALLOC_ATOMIC(NULL, _size_,_dma_)
  73336. +#define DWC_DMA_FREE(_size_,_virt_,_dma_) __DWC_DMA_FREE(NULL, _size_, _virt_, _dma_)
  73337. +# endif
  73338. +
  73339. +# if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  73340. +#define DWC_DMA_ALLOC __DWC_DMA_ALLOC
  73341. +#define DWC_DMA_FREE __DWC_DMA_FREE
  73342. +# endif
  73343. +extern void *dwc_dma_alloc_atomic_debug(uint32_t size, dwc_dma_t *dma_addr, char const *func, int line);
  73344. +
  73345. +#else /* DWC_DEBUG_MEMORY */
  73346. +
  73347. +extern void *dwc_alloc_debug(void *mem_ctx, uint32_t size, char const *func, int line);
  73348. +extern void *dwc_alloc_atomic_debug(void *mem_ctx, uint32_t size, char const *func, int line);
  73349. +extern void dwc_free_debug(void *mem_ctx, void *addr, char const *func, int line);
  73350. +extern void *dwc_dma_alloc_debug(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr,
  73351. + char const *func, int line);
  73352. +extern void *dwc_dma_alloc_atomic_debug(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr,
  73353. + char const *func, int line);
  73354. +extern void dwc_dma_free_debug(void *dma_ctx, uint32_t size, void *virt_addr,
  73355. + dwc_dma_t dma_addr, char const *func, int line);
  73356. +
  73357. +extern int dwc_memory_debug_start(void *mem_ctx);
  73358. +extern void dwc_memory_debug_stop(void);
  73359. +extern void dwc_memory_debug_report(void);
  73360. +
  73361. +#define DWC_ALLOC(_size_) dwc_alloc_debug(NULL, _size_, __func__, __LINE__)
  73362. +#define DWC_ALLOC_ATOMIC(_size_) dwc_alloc_atomic_debug(NULL, _size_, \
  73363. + __func__, __LINE__)
  73364. +#define DWC_FREE(_addr_) dwc_free_debug(NULL, _addr_, __func__, __LINE__)
  73365. +
  73366. +# ifdef DWC_LINUX
  73367. +#define DWC_DMA_ALLOC(_size_,_dma_) dwc_dma_alloc_debug(NULL, _size_, \
  73368. + _dma_, __func__, __LINE__)
  73369. +#define DWC_DMA_ALLOC_ATOMIC(_size_,_dma_) dwc_dma_alloc_atomic_debug(NULL, _size_, \
  73370. + _dma_, __func__, __LINE__)
  73371. +#define DWC_DMA_FREE(_size_,_virt_,_dma_) dwc_dma_free_debug(NULL, _size_, \
  73372. + _virt_, _dma_, __func__, __LINE__)
  73373. +# endif
  73374. +
  73375. +# if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  73376. +#define DWC_DMA_ALLOC(_ctx_,_size_,_dma_) dwc_dma_alloc_debug(_ctx_, _size_, \
  73377. + _dma_, __func__, __LINE__)
  73378. +#define DWC_DMA_FREE(_ctx_,_size_,_virt_,_dma_) dwc_dma_free_debug(_ctx_, _size_, \
  73379. + _virt_, _dma_, __func__, __LINE__)
  73380. +# endif
  73381. +
  73382. +#endif /* DWC_DEBUG_MEMORY */
  73383. +
  73384. +#define dwc_alloc(_ctx_,_size_) DWC_ALLOC(_size_)
  73385. +#define dwc_alloc_atomic(_ctx_,_size_) DWC_ALLOC_ATOMIC(_size_)
  73386. +#define dwc_free(_ctx_,_addr_) DWC_FREE(_addr_)
  73387. +
  73388. +#ifdef DWC_LINUX
  73389. +/* Linux doesn't need any extra parameters for DMA buffer allocation, so we
  73390. + * just throw away the DMA context parameter.
  73391. + */
  73392. +#define dwc_dma_alloc(_ctx_,_size_,_dma_) DWC_DMA_ALLOC(_size_, _dma_)
  73393. +#define dwc_dma_alloc_atomic(_ctx_,_size_,_dma_) DWC_DMA_ALLOC_ATOMIC(_size_, _dma_)
  73394. +#define dwc_dma_free(_ctx_,_size_,_virt_,_dma_) DWC_DMA_FREE(_size_, _virt_, _dma_)
  73395. +#endif
  73396. +
  73397. +#if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  73398. +/** BSD needs several extra parameters for DMA buffer allocation, so we pass
  73399. + * them in using the DMA context parameter.
  73400. + */
  73401. +#define dwc_dma_alloc DWC_DMA_ALLOC
  73402. +#define dwc_dma_free DWC_DMA_FREE
  73403. +#endif
  73404. +
  73405. +
  73406. +/** @name Memory and String Processing */
  73407. +
  73408. +/** memset() clone */
  73409. +extern void *DWC_MEMSET(void *dest, uint8_t byte, uint32_t size);
  73410. +#define dwc_memset DWC_MEMSET
  73411. +
  73412. +/** memcpy() clone */
  73413. +extern void *DWC_MEMCPY(void *dest, void const *src, uint32_t size);
  73414. +#define dwc_memcpy DWC_MEMCPY
  73415. +
  73416. +/** memmove() clone */
  73417. +extern void *DWC_MEMMOVE(void *dest, void *src, uint32_t size);
  73418. +#define dwc_memmove DWC_MEMMOVE
  73419. +
  73420. +/** memcmp() clone */
  73421. +extern int DWC_MEMCMP(void *m1, void *m2, uint32_t size);
  73422. +#define dwc_memcmp DWC_MEMCMP
  73423. +
  73424. +/** strcmp() clone */
  73425. +extern int DWC_STRCMP(void *s1, void *s2);
  73426. +#define dwc_strcmp DWC_STRCMP
  73427. +
  73428. +/** strncmp() clone */
  73429. +extern int DWC_STRNCMP(void *s1, void *s2, uint32_t size);
  73430. +#define dwc_strncmp DWC_STRNCMP
  73431. +
  73432. +/** strlen() clone, for NULL terminated ASCII strings */
  73433. +extern int DWC_STRLEN(char const *str);
  73434. +#define dwc_strlen DWC_STRLEN
  73435. +
  73436. +/** strcpy() clone, for NULL terminated ASCII strings */
  73437. +extern char *DWC_STRCPY(char *to, const char *from);
  73438. +#define dwc_strcpy DWC_STRCPY
  73439. +
  73440. +/** strdup() clone. If you wish to use memory allocation debugging, this
  73441. + * implementation of strdup should use the DWC_* memory routines instead of
  73442. + * calling a predefined strdup. Otherwise the memory allocated by this routine
  73443. + * will not be seen by the debugging routines. */
  73444. +extern char *DWC_STRDUP(char const *str);
  73445. +#define dwc_strdup(_ctx_,_str_) DWC_STRDUP(_str_)
  73446. +
  73447. +/** NOT an atoi() clone. Read the description carefully. Returns an integer
  73448. + * converted from the string str in base 10 unless the string begins with a "0x"
  73449. + * in which case it is base 16. String must be a NULL terminated sequence of
  73450. + * ASCII characters and may optionally begin with whitespace, a + or -, and a
  73451. + * "0x" prefix if base 16. The remaining characters must be valid digits for
  73452. + * the number and end with a NULL character. If any invalid characters are
  73453. + * encountered or it returns with a negative error code and the results of the
  73454. + * conversion are undefined. On sucess it returns 0. Overflow conditions are
  73455. + * undefined. An example implementation using atoi() can be referenced from the
  73456. + * Linux implementation. */
  73457. +extern int DWC_ATOI(const char *str, int32_t *value);
  73458. +#define dwc_atoi DWC_ATOI
  73459. +
  73460. +/** Same as above but for unsigned. */
  73461. +extern int DWC_ATOUI(const char *str, uint32_t *value);
  73462. +#define dwc_atoui DWC_ATOUI
  73463. +
  73464. +#ifdef DWC_UTFLIB
  73465. +/** This routine returns a UTF16LE unicode encoded string from a UTF8 string. */
  73466. +extern int DWC_UTF8_TO_UTF16LE(uint8_t const *utf8string, uint16_t *utf16string, unsigned len);
  73467. +#define dwc_utf8_to_utf16le DWC_UTF8_TO_UTF16LE
  73468. +#endif
  73469. +
  73470. +
  73471. +/** @name Wait queues
  73472. + *
  73473. + * Wait queues provide a means of synchronizing between threads or processes. A
  73474. + * process can block on a waitq if some condition is not true, waiting for it to
  73475. + * become true. When the waitq is triggered all waiting process will get
  73476. + * unblocked and the condition will be check again. Waitqs should be triggered
  73477. + * every time a condition can potentially change.*/
  73478. +struct dwc_waitq;
  73479. +
  73480. +/** Type for a waitq */
  73481. +typedef struct dwc_waitq dwc_waitq_t;
  73482. +
  73483. +/** The type of waitq condition callback function. This is called every time
  73484. + * condition is evaluated. */
  73485. +typedef int (*dwc_waitq_condition_t)(void *data);
  73486. +
  73487. +/** Allocate a waitq */
  73488. +extern dwc_waitq_t *DWC_WAITQ_ALLOC(void);
  73489. +#define dwc_waitq_alloc(_ctx_) DWC_WAITQ_ALLOC()
  73490. +
  73491. +/** Free a waitq */
  73492. +extern void DWC_WAITQ_FREE(dwc_waitq_t *wq);
  73493. +#define dwc_waitq_free DWC_WAITQ_FREE
  73494. +
  73495. +/** Check the condition and if it is false, block on the waitq. When unblocked, check the
  73496. + * condition again. The function returns when the condition becomes true. The return value
  73497. + * is 0 on condition true, DWC_WAITQ_ABORTED on abort or killed, or DWC_WAITQ_UNKNOWN on error. */
  73498. +extern int32_t DWC_WAITQ_WAIT(dwc_waitq_t *wq, dwc_waitq_condition_t cond, void *data);
  73499. +#define dwc_waitq_wait DWC_WAITQ_WAIT
  73500. +
  73501. +/** Check the condition and if it is false, block on the waitq. When unblocked,
  73502. + * check the condition again. The function returns when the condition become
  73503. + * true or the timeout has passed. The return value is 0 on condition true or
  73504. + * DWC_TIMED_OUT on timeout, or DWC_WAITQ_ABORTED, or DWC_WAITQ_UNKNOWN on
  73505. + * error. */
  73506. +extern int32_t DWC_WAITQ_WAIT_TIMEOUT(dwc_waitq_t *wq, dwc_waitq_condition_t cond,
  73507. + void *data, int32_t msecs);
  73508. +#define dwc_waitq_wait_timeout DWC_WAITQ_WAIT_TIMEOUT
  73509. +
  73510. +/** Trigger a waitq, unblocking all processes. This should be called whenever a condition
  73511. + * has potentially changed. */
  73512. +extern void DWC_WAITQ_TRIGGER(dwc_waitq_t *wq);
  73513. +#define dwc_waitq_trigger DWC_WAITQ_TRIGGER
  73514. +
  73515. +/** Unblock all processes waiting on the waitq with an ABORTED result. */
  73516. +extern void DWC_WAITQ_ABORT(dwc_waitq_t *wq);
  73517. +#define dwc_waitq_abort DWC_WAITQ_ABORT
  73518. +
  73519. +
  73520. +/** @name Threads
  73521. + *
  73522. + * A thread must be explicitly stopped. It must check DWC_THREAD_SHOULD_STOP
  73523. + * whenever it is woken up, and then return. The DWC_THREAD_STOP function
  73524. + * returns the value from the thread.
  73525. + */
  73526. +
  73527. +struct dwc_thread;
  73528. +
  73529. +/** Type for a thread */
  73530. +typedef struct dwc_thread dwc_thread_t;
  73531. +
  73532. +/** The thread function */
  73533. +typedef int (*dwc_thread_function_t)(void *data);
  73534. +
  73535. +/** Create a thread and start it running the thread_function. Returns a handle
  73536. + * to the thread */
  73537. +extern dwc_thread_t *DWC_THREAD_RUN(dwc_thread_function_t func, char *name, void *data);
  73538. +#define dwc_thread_run(_ctx_,_func_,_name_,_data_) DWC_THREAD_RUN(_func_, _name_, _data_)
  73539. +
  73540. +/** Stops a thread. Return the value returned by the thread. Or will return
  73541. + * DWC_ABORT if the thread never started. */
  73542. +extern int DWC_THREAD_STOP(dwc_thread_t *thread);
  73543. +#define dwc_thread_stop DWC_THREAD_STOP
  73544. +
  73545. +/** Signifies to the thread that it must stop. */
  73546. +#ifdef DWC_LINUX
  73547. +/* Linux doesn't need any parameters for kthread_should_stop() */
  73548. +extern dwc_bool_t DWC_THREAD_SHOULD_STOP(void);
  73549. +#define dwc_thread_should_stop(_thrd_) DWC_THREAD_SHOULD_STOP()
  73550. +
  73551. +/* No thread_exit function in Linux */
  73552. +#define dwc_thread_exit(_thrd_)
  73553. +#endif
  73554. +
  73555. +#if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  73556. +/** BSD needs the thread pointer for kthread_suspend_check() */
  73557. +extern dwc_bool_t DWC_THREAD_SHOULD_STOP(dwc_thread_t *thread);
  73558. +#define dwc_thread_should_stop DWC_THREAD_SHOULD_STOP
  73559. +
  73560. +/** The thread must call this to exit. */
  73561. +extern void DWC_THREAD_EXIT(dwc_thread_t *thread);
  73562. +#define dwc_thread_exit DWC_THREAD_EXIT
  73563. +#endif
  73564. +
  73565. +
  73566. +/** @name Work queues
  73567. + *
  73568. + * Workqs are used to queue a callback function to be called at some later time,
  73569. + * in another thread. */
  73570. +struct dwc_workq;
  73571. +
  73572. +/** Type for a workq */
  73573. +typedef struct dwc_workq dwc_workq_t;
  73574. +
  73575. +/** The type of the callback function to be called. */
  73576. +typedef void (*dwc_work_callback_t)(void *data);
  73577. +
  73578. +/** Allocate a workq */
  73579. +extern dwc_workq_t *DWC_WORKQ_ALLOC(char *name);
  73580. +#define dwc_workq_alloc(_ctx_,_name_) DWC_WORKQ_ALLOC(_name_)
  73581. +
  73582. +/** Free a workq. All work must be completed before being freed. */
  73583. +extern void DWC_WORKQ_FREE(dwc_workq_t *workq);
  73584. +#define dwc_workq_free DWC_WORKQ_FREE
  73585. +
  73586. +/** Schedule a callback on the workq, passing in data. The function will be
  73587. + * scheduled at some later time. */
  73588. +extern void DWC_WORKQ_SCHEDULE(dwc_workq_t *workq, dwc_work_callback_t cb,
  73589. + void *data, char *format, ...)
  73590. +#ifdef __GNUC__
  73591. + __attribute__ ((format(printf, 4, 5)));
  73592. +#else
  73593. + ;
  73594. +#endif
  73595. +#define dwc_workq_schedule DWC_WORKQ_SCHEDULE
  73596. +
  73597. +/** Schedule a callback on the workq, that will be called until at least
  73598. + * given number miliseconds have passed. */
  73599. +extern void DWC_WORKQ_SCHEDULE_DELAYED(dwc_workq_t *workq, dwc_work_callback_t cb,
  73600. + void *data, uint32_t time, char *format, ...)
  73601. +#ifdef __GNUC__
  73602. + __attribute__ ((format(printf, 5, 6)));
  73603. +#else
  73604. + ;
  73605. +#endif
  73606. +#define dwc_workq_schedule_delayed DWC_WORKQ_SCHEDULE_DELAYED
  73607. +
  73608. +/** The number of processes in the workq */
  73609. +extern int DWC_WORKQ_PENDING(dwc_workq_t *workq);
  73610. +#define dwc_workq_pending DWC_WORKQ_PENDING
  73611. +
  73612. +/** Blocks until all the work in the workq is complete or timed out. Returns <
  73613. + * 0 on timeout. */
  73614. +extern int DWC_WORKQ_WAIT_WORK_DONE(dwc_workq_t *workq, int timeout);
  73615. +#define dwc_workq_wait_work_done DWC_WORKQ_WAIT_WORK_DONE
  73616. +
  73617. +
  73618. +/** @name Tasklets
  73619. + *
  73620. + */
  73621. +struct dwc_tasklet;
  73622. +
  73623. +/** Type for a tasklet */
  73624. +typedef struct dwc_tasklet dwc_tasklet_t;
  73625. +
  73626. +/** The type of the callback function to be called */
  73627. +typedef void (*dwc_tasklet_callback_t)(void *data);
  73628. +
  73629. +/** Allocates a tasklet */
  73630. +extern dwc_tasklet_t *DWC_TASK_ALLOC(char *name, dwc_tasklet_callback_t cb, void *data);
  73631. +#define dwc_task_alloc(_ctx_,_name_,_cb_,_data_) DWC_TASK_ALLOC(_name_, _cb_, _data_)
  73632. +
  73633. +/** Frees a tasklet */
  73634. +extern void DWC_TASK_FREE(dwc_tasklet_t *task);
  73635. +#define dwc_task_free DWC_TASK_FREE
  73636. +
  73637. +/** Schedules a tasklet to run */
  73638. +extern void DWC_TASK_SCHEDULE(dwc_tasklet_t *task);
  73639. +#define dwc_task_schedule DWC_TASK_SCHEDULE
  73640. +
  73641. +extern void DWC_TASK_HI_SCHEDULE(dwc_tasklet_t *task);
  73642. +#define dwc_task_hi_schedule DWC_TASK_HI_SCHEDULE
  73643. +
  73644. +/** @name Timer
  73645. + *
  73646. + * Callbacks must be small and atomic.
  73647. + */
  73648. +struct dwc_timer;
  73649. +
  73650. +/** Type for a timer */
  73651. +typedef struct dwc_timer dwc_timer_t;
  73652. +
  73653. +/** The type of the callback function to be called */
  73654. +typedef void (*dwc_timer_callback_t)(void *data);
  73655. +
  73656. +/** Allocates a timer */
  73657. +extern dwc_timer_t *DWC_TIMER_ALLOC(char *name, dwc_timer_callback_t cb, void *data);
  73658. +#define dwc_timer_alloc(_ctx_,_name_,_cb_,_data_) DWC_TIMER_ALLOC(_name_,_cb_,_data_)
  73659. +
  73660. +/** Frees a timer */
  73661. +extern void DWC_TIMER_FREE(dwc_timer_t *timer);
  73662. +#define dwc_timer_free DWC_TIMER_FREE
  73663. +
  73664. +/** Schedules the timer to run at time ms from now. And will repeat at every
  73665. + * repeat_interval msec therafter
  73666. + *
  73667. + * Modifies a timer that is still awaiting execution to a new expiration time.
  73668. + * The mod_time is added to the old time. */
  73669. +extern void DWC_TIMER_SCHEDULE(dwc_timer_t *timer, uint32_t time);
  73670. +#define dwc_timer_schedule DWC_TIMER_SCHEDULE
  73671. +
  73672. +/** Disables the timer from execution. */
  73673. +extern void DWC_TIMER_CANCEL(dwc_timer_t *timer);
  73674. +#define dwc_timer_cancel DWC_TIMER_CANCEL
  73675. +
  73676. +
  73677. +/** @name Spinlocks
  73678. + *
  73679. + * These locks are used when the work between the lock/unlock is atomic and
  73680. + * short. Interrupts are also disabled during the lock/unlock and thus they are
  73681. + * suitable to lock between interrupt/non-interrupt context. They also lock
  73682. + * between processes if you have multiple CPUs or Preemption. If you don't have
  73683. + * multiple CPUS or Preemption, then the you can simply implement the
  73684. + * DWC_SPINLOCK and DWC_SPINUNLOCK to disable and enable interrupts. Because
  73685. + * the work between the lock/unlock is atomic, the process context will never
  73686. + * change, and so you never have to lock between processes. */
  73687. +
  73688. +struct dwc_spinlock;
  73689. +
  73690. +/** Type for a spinlock */
  73691. +typedef struct dwc_spinlock dwc_spinlock_t;
  73692. +
  73693. +/** Type for the 'flags' argument to spinlock funtions */
  73694. +typedef unsigned long dwc_irqflags_t;
  73695. +
  73696. +/** Returns an initialized lock variable. This function should allocate and
  73697. + * initialize the OS-specific data structure used for locking. This data
  73698. + * structure is to be used for the DWC_LOCK and DWC_UNLOCK functions and should
  73699. + * be freed by the DWC_FREE_LOCK when it is no longer used.
  73700. + *
  73701. + * For Linux Spinlock Debugging make it macro because the debugging routines use
  73702. + * the symbol name to determine recursive locking. Using a wrapper function
  73703. + * makes it falsely think recursive locking occurs. */
  73704. +#if defined(DWC_LINUX) && defined(CONFIG_DEBUG_SPINLOCK)
  73705. +#define DWC_SPINLOCK_ALLOC_LINUX_DEBUG(lock) ({ \
  73706. + lock = DWC_ALLOC(sizeof(spinlock_t)); \
  73707. + if (lock) { \
  73708. + spin_lock_init((spinlock_t *)lock); \
  73709. + } \
  73710. +})
  73711. +#else
  73712. +extern dwc_spinlock_t *DWC_SPINLOCK_ALLOC(void);
  73713. +#define dwc_spinlock_alloc(_ctx_) DWC_SPINLOCK_ALLOC()
  73714. +#endif
  73715. +
  73716. +/** Frees an initialized lock variable. */
  73717. +extern void DWC_SPINLOCK_FREE(dwc_spinlock_t *lock);
  73718. +#define dwc_spinlock_free(_ctx_,_lock_) DWC_SPINLOCK_FREE(_lock_)
  73719. +
  73720. +/** Disables interrupts and blocks until it acquires the lock.
  73721. + *
  73722. + * @param lock Pointer to the spinlock.
  73723. + * @param flags Unsigned long for irq flags storage.
  73724. + */
  73725. +extern void DWC_SPINLOCK_IRQSAVE(dwc_spinlock_t *lock, dwc_irqflags_t *flags);
  73726. +#define dwc_spinlock_irqsave DWC_SPINLOCK_IRQSAVE
  73727. +
  73728. +/** Re-enables the interrupt and releases the lock.
  73729. + *
  73730. + * @param lock Pointer to the spinlock.
  73731. + * @param flags Unsigned long for irq flags storage. Must be the same as was
  73732. + * passed into DWC_LOCK.
  73733. + */
  73734. +extern void DWC_SPINUNLOCK_IRQRESTORE(dwc_spinlock_t *lock, dwc_irqflags_t flags);
  73735. +#define dwc_spinunlock_irqrestore DWC_SPINUNLOCK_IRQRESTORE
  73736. +
  73737. +/** Blocks until it acquires the lock.
  73738. + *
  73739. + * @param lock Pointer to the spinlock.
  73740. + */
  73741. +extern void DWC_SPINLOCK(dwc_spinlock_t *lock);
  73742. +#define dwc_spinlock DWC_SPINLOCK
  73743. +
  73744. +/** Releases the lock.
  73745. + *
  73746. + * @param lock Pointer to the spinlock.
  73747. + */
  73748. +extern void DWC_SPINUNLOCK(dwc_spinlock_t *lock);
  73749. +#define dwc_spinunlock DWC_SPINUNLOCK
  73750. +
  73751. +
  73752. +/** @name Mutexes
  73753. + *
  73754. + * Unlike spinlocks Mutexes lock only between processes and the work between the
  73755. + * lock/unlock CAN block, therefore it CANNOT be called from interrupt context.
  73756. + */
  73757. +
  73758. +struct dwc_mutex;
  73759. +
  73760. +/** Type for a mutex */
  73761. +typedef struct dwc_mutex dwc_mutex_t;
  73762. +
  73763. +/* For Linux Mutex Debugging make it inline because the debugging routines use
  73764. + * the symbol to determine recursive locking. This makes it falsely think
  73765. + * recursive locking occurs. */
  73766. +#if defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES)
  73767. +#define DWC_MUTEX_ALLOC_LINUX_DEBUG(__mutexp) ({ \
  73768. + __mutexp = (dwc_mutex_t *)DWC_ALLOC(sizeof(struct mutex)); \
  73769. + mutex_init((struct mutex *)__mutexp); \
  73770. +})
  73771. +#endif
  73772. +
  73773. +/** Allocate a mutex */
  73774. +extern dwc_mutex_t *DWC_MUTEX_ALLOC(void);
  73775. +#define dwc_mutex_alloc(_ctx_) DWC_MUTEX_ALLOC()
  73776. +
  73777. +/* For memory leak debugging when using Linux Mutex Debugging */
  73778. +#if defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES)
  73779. +#define DWC_MUTEX_FREE(__mutexp) do { \
  73780. + mutex_destroy((struct mutex *)__mutexp); \
  73781. + DWC_FREE(__mutexp); \
  73782. +} while(0)
  73783. +#else
  73784. +/** Free a mutex */
  73785. +extern void DWC_MUTEX_FREE(dwc_mutex_t *mutex);
  73786. +#define dwc_mutex_free(_ctx_,_mutex_) DWC_MUTEX_FREE(_mutex_)
  73787. +#endif
  73788. +
  73789. +/** Lock a mutex */
  73790. +extern void DWC_MUTEX_LOCK(dwc_mutex_t *mutex);
  73791. +#define dwc_mutex_lock DWC_MUTEX_LOCK
  73792. +
  73793. +/** Non-blocking lock returns 1 on successful lock. */
  73794. +extern int DWC_MUTEX_TRYLOCK(dwc_mutex_t *mutex);
  73795. +#define dwc_mutex_trylock DWC_MUTEX_TRYLOCK
  73796. +
  73797. +/** Unlock a mutex */
  73798. +extern void DWC_MUTEX_UNLOCK(dwc_mutex_t *mutex);
  73799. +#define dwc_mutex_unlock DWC_MUTEX_UNLOCK
  73800. +
  73801. +
  73802. +/** @name Time */
  73803. +
  73804. +/** Microsecond delay.
  73805. + *
  73806. + * @param usecs Microseconds to delay.
  73807. + */
  73808. +extern void DWC_UDELAY(uint32_t usecs);
  73809. +#define dwc_udelay DWC_UDELAY
  73810. +
  73811. +/** Millisecond delay.
  73812. + *
  73813. + * @param msecs Milliseconds to delay.
  73814. + */
  73815. +extern void DWC_MDELAY(uint32_t msecs);
  73816. +#define dwc_mdelay DWC_MDELAY
  73817. +
  73818. +/** Non-busy waiting.
  73819. + * Sleeps for specified number of milliseconds.
  73820. + *
  73821. + * @param msecs Milliseconds to sleep.
  73822. + */
  73823. +extern void DWC_MSLEEP(uint32_t msecs);
  73824. +#define dwc_msleep DWC_MSLEEP
  73825. +
  73826. +/**
  73827. + * Returns number of milliseconds since boot.
  73828. + */
  73829. +extern uint32_t DWC_TIME(void);
  73830. +#define dwc_time DWC_TIME
  73831. +
  73832. +
  73833. +
  73834. +
  73835. +/* @mainpage DWC Portability and Common Library
  73836. + *
  73837. + * This is the documentation for the DWC Portability and Common Library.
  73838. + *
  73839. + * @section intro Introduction
  73840. + *
  73841. + * The DWC Portability library consists of wrapper calls and data structures to
  73842. + * all low-level functions which are typically provided by the OS. The WUDEV
  73843. + * driver uses only these functions. In order to port the WUDEV driver, only
  73844. + * the functions in this library need to be re-implemented, with the same
  73845. + * behavior as documented here.
  73846. + *
  73847. + * The Common library consists of higher level functions, which rely only on
  73848. + * calling the functions from the DWC Portability library. These common
  73849. + * routines are shared across modules. Some of the common libraries need to be
  73850. + * used directly by the driver programmer when porting WUDEV. Such as the
  73851. + * parameter and notification libraries.
  73852. + *
  73853. + * @section low Portability Library OS Wrapper Functions
  73854. + *
  73855. + * Any function starting with DWC and in all CAPS is a low-level OS-wrapper that
  73856. + * needs to be implemented when porting, for example DWC_MUTEX_ALLOC(). All of
  73857. + * these functions are included in the dwc_os.h file.
  73858. + *
  73859. + * There are many functions here covering a wide array of OS services. Please
  73860. + * see dwc_os.h for details, and implementation notes for each function.
  73861. + *
  73862. + * @section common Common Library Functions
  73863. + *
  73864. + * Any function starting with dwc and in all lowercase is a common library
  73865. + * routine. These functions have a portable implementation and do not need to
  73866. + * be reimplemented when porting. The common routines can be used by any
  73867. + * driver, and some must be used by the end user to control the drivers. For
  73868. + * example, you must use the Parameter common library in order to set the
  73869. + * parameters in the WUDEV module.
  73870. + *
  73871. + * The common libraries consist of the following:
  73872. + *
  73873. + * - Connection Contexts - Used internally and can be used by end-user. See dwc_cc.h
  73874. + * - Parameters - Used internally and can be used by end-user. See dwc_params.h
  73875. + * - Notifications - Used internally and can be used by end-user. See dwc_notifier.h
  73876. + * - Lists - Used internally and can be used by end-user. See dwc_list.h
  73877. + * - Memory Debugging - Used internally and can be used by end-user. See dwc_os.h
  73878. + * - Modpow - Used internally only. See dwc_modpow.h
  73879. + * - DH - Used internally only. See dwc_dh.h
  73880. + * - Crypto - Used internally only. See dwc_crypto.h
  73881. + *
  73882. + *
  73883. + * @section prereq Prerequistes For dwc_os.h
  73884. + * @subsection types Data Types
  73885. + *
  73886. + * The dwc_os.h file assumes that several low-level data types are pre defined for the
  73887. + * compilation environment. These data types are:
  73888. + *
  73889. + * - uint8_t - unsigned 8-bit data type
  73890. + * - int8_t - signed 8-bit data type
  73891. + * - uint16_t - unsigned 16-bit data type
  73892. + * - int16_t - signed 16-bit data type
  73893. + * - uint32_t - unsigned 32-bit data type
  73894. + * - int32_t - signed 32-bit data type
  73895. + * - uint64_t - unsigned 64-bit data type
  73896. + * - int64_t - signed 64-bit data type
  73897. + *
  73898. + * Ensure that these are defined before using dwc_os.h. The easiest way to do
  73899. + * that is to modify the top of the file to include the appropriate header.
  73900. + * This is already done for the Linux environment. If the DWC_LINUX macro is
  73901. + * defined, the correct header will be added. A standard header <stdint.h> is
  73902. + * also used for environments where standard C headers are available.
  73903. + *
  73904. + * @subsection stdarg Variable Arguments
  73905. + *
  73906. + * Variable arguments are provided by a standard C header <stdarg.h>. it is
  73907. + * available in Both the Linux and ANSI C enviornment. An equivalent must be
  73908. + * provided in your enviornment in order to use dwc_os.h with the debug and
  73909. + * tracing message functionality.
  73910. + *
  73911. + * @subsection thread Threading
  73912. + *
  73913. + * WUDEV Core must be run on an operating system that provides for multiple
  73914. + * threads/processes. Threading can be implemented in many ways, even in
  73915. + * embedded systems without an operating system. At the bare minimum, the
  73916. + * system should be able to start any number of processes at any time to handle
  73917. + * special work. It need not be a pre-emptive system. Process context can
  73918. + * change upon a call to a blocking function. The hardware interrupt context
  73919. + * that calls the module's ISR() function must be differentiable from process
  73920. + * context, even if your processes are impemented via a hardware interrupt.
  73921. + * Further locking mechanism between process must exist (or be implemented), and
  73922. + * process context must have a way to disable interrupts for a period of time to
  73923. + * lock them out. If all of this exists, the functions in dwc_os.h related to
  73924. + * threading should be able to be implemented with the defined behavior.
  73925. + *
  73926. + */
  73927. +
  73928. +#ifdef __cplusplus
  73929. +}
  73930. +#endif
  73931. +
  73932. +#endif /* _DWC_OS_H_ */
  73933. diff -Nur linux-3.18.8/drivers/usb/host/dwc_common_port/Makefile linux-rpi/drivers/usb/host/dwc_common_port/Makefile
  73934. --- linux-3.18.8/drivers/usb/host/dwc_common_port/Makefile 1970-01-01 01:00:00.000000000 +0100
  73935. +++ linux-rpi/drivers/usb/host/dwc_common_port/Makefile 2015-03-05 14:40:16.553715806 +0100
  73936. @@ -0,0 +1,58 @@
  73937. +#
  73938. +# Makefile for DWC_common library
  73939. +#
  73940. +
  73941. +ifneq ($(KERNELRELEASE),)
  73942. +
  73943. +ccflags-y += -DDWC_LINUX
  73944. +#ccflags-y += -DDEBUG
  73945. +#ccflags-y += -DDWC_DEBUG_REGS
  73946. +#ccflags-y += -DDWC_DEBUG_MEMORY
  73947. +
  73948. +ccflags-y += -DDWC_LIBMODULE
  73949. +ccflags-y += -DDWC_CCLIB
  73950. +#ccflags-y += -DDWC_CRYPTOLIB
  73951. +ccflags-y += -DDWC_NOTIFYLIB
  73952. +ccflags-y += -DDWC_UTFLIB
  73953. +
  73954. +obj-$(CONFIG_USB_DWCOTG) += dwc_common_port_lib.o
  73955. +dwc_common_port_lib-objs := dwc_cc.o dwc_modpow.o dwc_dh.o \
  73956. + dwc_crypto.o dwc_notifier.o \
  73957. + dwc_common_linux.o dwc_mem.o
  73958. +
  73959. +kernrelwd := $(subst ., ,$(KERNELRELEASE))
  73960. +kernrel3 := $(word 1,$(kernrelwd)).$(word 2,$(kernrelwd)).$(word 3,$(kernrelwd))
  73961. +
  73962. +ifneq ($(kernrel3),2.6.20)
  73963. +# grayg - I only know that we use ccflags-y in 2.6.31 actually
  73964. +ccflags-y += $(CPPFLAGS)
  73965. +endif
  73966. +
  73967. +else
  73968. +
  73969. +#ifeq ($(KDIR),)
  73970. +#$(error Must give "KDIR=/path/to/kernel/source" on command line or in environment)
  73971. +#endif
  73972. +
  73973. +ifeq ($(ARCH),)
  73974. +$(error Must give "ARCH=<arch>" on command line or in environment. Also, if \
  73975. + cross-compiling, must give "CROSS_COMPILE=/path/to/compiler/plus/tool-prefix-")
  73976. +endif
  73977. +
  73978. +ifeq ($(DOXYGEN),)
  73979. +DOXYGEN := doxygen
  73980. +endif
  73981. +
  73982. +default:
  73983. + $(MAKE) -C$(KDIR) M=$(PWD) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) modules
  73984. +
  73985. +docs: $(wildcard *.[hc]) doc/doxygen.cfg
  73986. + $(DOXYGEN) doc/doxygen.cfg
  73987. +
  73988. +tags: $(wildcard *.[hc])
  73989. + $(CTAGS) -e $(wildcard *.[hc]) $(wildcard linux/*.[hc]) $(wildcard $(KDIR)/include/linux/usb*.h)
  73990. +
  73991. +endif
  73992. +
  73993. +clean:
  73994. + rm -rf *.o *.ko .*.cmd *.mod.c .*.o.d .*.o.tmp modules.order Module.markers Module.symvers .tmp_versions/
  73995. diff -Nur linux-3.18.8/drivers/usb/host/dwc_common_port/Makefile.fbsd linux-rpi/drivers/usb/host/dwc_common_port/Makefile.fbsd
  73996. --- linux-3.18.8/drivers/usb/host/dwc_common_port/Makefile.fbsd 1970-01-01 01:00:00.000000000 +0100
  73997. +++ linux-rpi/drivers/usb/host/dwc_common_port/Makefile.fbsd 2015-03-05 14:40:16.553715806 +0100
  73998. @@ -0,0 +1,17 @@
  73999. +CFLAGS += -I/sys/i386/compile/GENERIC -I/sys/i386/include -I/usr/include
  74000. +CFLAGS += -DDWC_FREEBSD
  74001. +CFLAGS += -DDEBUG
  74002. +#CFLAGS += -DDWC_DEBUG_REGS
  74003. +#CFLAGS += -DDWC_DEBUG_MEMORY
  74004. +
  74005. +#CFLAGS += -DDWC_LIBMODULE
  74006. +#CFLAGS += -DDWC_CCLIB
  74007. +#CFLAGS += -DDWC_CRYPTOLIB
  74008. +#CFLAGS += -DDWC_NOTIFYLIB
  74009. +#CFLAGS += -DDWC_UTFLIB
  74010. +
  74011. +KMOD = dwc_common_port_lib
  74012. +SRCS = dwc_cc.c dwc_modpow.c dwc_dh.c dwc_crypto.c dwc_notifier.c \
  74013. + dwc_common_fbsd.c dwc_mem.c
  74014. +
  74015. +.include <bsd.kmod.mk>
  74016. diff -Nur linux-3.18.8/drivers/usb/host/dwc_common_port/Makefile.linux linux-rpi/drivers/usb/host/dwc_common_port/Makefile.linux
  74017. --- linux-3.18.8/drivers/usb/host/dwc_common_port/Makefile.linux 1970-01-01 01:00:00.000000000 +0100
  74018. +++ linux-rpi/drivers/usb/host/dwc_common_port/Makefile.linux 2015-03-05 14:40:16.553715806 +0100
  74019. @@ -0,0 +1,49 @@
  74020. +#
  74021. +# Makefile for DWC_common library
  74022. +#
  74023. +ifneq ($(KERNELRELEASE),)
  74024. +
  74025. +ccflags-y += -DDWC_LINUX
  74026. +#ccflags-y += -DDEBUG
  74027. +#ccflags-y += -DDWC_DEBUG_REGS
  74028. +#ccflags-y += -DDWC_DEBUG_MEMORY
  74029. +
  74030. +ccflags-y += -DDWC_LIBMODULE
  74031. +ccflags-y += -DDWC_CCLIB
  74032. +ccflags-y += -DDWC_CRYPTOLIB
  74033. +ccflags-y += -DDWC_NOTIFYLIB
  74034. +ccflags-y += -DDWC_UTFLIB
  74035. +
  74036. +obj-m := dwc_common_port_lib.o
  74037. +dwc_common_port_lib-objs := dwc_cc.o dwc_modpow.o dwc_dh.o \
  74038. + dwc_crypto.o dwc_notifier.o \
  74039. + dwc_common_linux.o dwc_mem.o
  74040. +
  74041. +else
  74042. +
  74043. +ifeq ($(KDIR),)
  74044. +$(error Must give "KDIR=/path/to/kernel/source" on command line or in environment)
  74045. +endif
  74046. +
  74047. +ifeq ($(ARCH),)
  74048. +$(error Must give "ARCH=<arch>" on command line or in environment. Also, if \
  74049. + cross-compiling, must give "CROSS_COMPILE=/path/to/compiler/plus/tool-prefix-")
  74050. +endif
  74051. +
  74052. +ifeq ($(DOXYGEN),)
  74053. +DOXYGEN := doxygen
  74054. +endif
  74055. +
  74056. +default:
  74057. + $(MAKE) -C$(KDIR) M=$(PWD) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) modules
  74058. +
  74059. +docs: $(wildcard *.[hc]) doc/doxygen.cfg
  74060. + $(DOXYGEN) doc/doxygen.cfg
  74061. +
  74062. +tags: $(wildcard *.[hc])
  74063. + $(CTAGS) -e $(wildcard *.[hc]) $(wildcard linux/*.[hc]) $(wildcard $(KDIR)/include/linux/usb*.h)
  74064. +
  74065. +endif
  74066. +
  74067. +clean:
  74068. + rm -rf *.o *.ko .*.cmd *.mod.c .*.o.d .*.o.tmp modules.order Module.markers Module.symvers .tmp_versions/
  74069. diff -Nur linux-3.18.8/drivers/usb/host/dwc_common_port/usb.h linux-rpi/drivers/usb/host/dwc_common_port/usb.h
  74070. --- linux-3.18.8/drivers/usb/host/dwc_common_port/usb.h 1970-01-01 01:00:00.000000000 +0100
  74071. +++ linux-rpi/drivers/usb/host/dwc_common_port/usb.h 2015-03-05 14:40:16.557715806 +0100
  74072. @@ -0,0 +1,946 @@
  74073. +/*
  74074. + * Copyright (c) 1998 The NetBSD Foundation, Inc.
  74075. + * All rights reserved.
  74076. + *
  74077. + * This code is derived from software contributed to The NetBSD Foundation
  74078. + * by Lennart Augustsson (lennart@augustsson.net) at
  74079. + * Carlstedt Research & Technology.
  74080. + *
  74081. + * Redistribution and use in source and binary forms, with or without
  74082. + * modification, are permitted provided that the following conditions
  74083. + * are met:
  74084. + * 1. Redistributions of source code must retain the above copyright
  74085. + * notice, this list of conditions and the following disclaimer.
  74086. + * 2. Redistributions in binary form must reproduce the above copyright
  74087. + * notice, this list of conditions and the following disclaimer in the
  74088. + * documentation and/or other materials provided with the distribution.
  74089. + * 3. All advertising materials mentioning features or use of this software
  74090. + * must display the following acknowledgement:
  74091. + * This product includes software developed by the NetBSD
  74092. + * Foundation, Inc. and its contributors.
  74093. + * 4. Neither the name of The NetBSD Foundation nor the names of its
  74094. + * contributors may be used to endorse or promote products derived
  74095. + * from this software without specific prior written permission.
  74096. + *
  74097. + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
  74098. + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  74099. + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  74100. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
  74101. + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  74102. + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  74103. + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  74104. + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  74105. + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  74106. + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  74107. + * POSSIBILITY OF SUCH DAMAGE.
  74108. + */
  74109. +
  74110. +/* Modified by Synopsys, Inc, 12/12/2007 */
  74111. +
  74112. +
  74113. +#ifndef _USB_H_
  74114. +#define _USB_H_
  74115. +
  74116. +#ifdef __cplusplus
  74117. +extern "C" {
  74118. +#endif
  74119. +
  74120. +/*
  74121. + * The USB records contain some unaligned little-endian word
  74122. + * components. The U[SG]ETW macros take care of both the alignment
  74123. + * and endian problem and should always be used to access non-byte
  74124. + * values.
  74125. + */
  74126. +typedef u_int8_t uByte;
  74127. +typedef u_int8_t uWord[2];
  74128. +typedef u_int8_t uDWord[4];
  74129. +
  74130. +#define USETW2(w,h,l) ((w)[0] = (u_int8_t)(l), (w)[1] = (u_int8_t)(h))
  74131. +#define UCONSTW(x) { (x) & 0xff, ((x) >> 8) & 0xff }
  74132. +#define UCONSTDW(x) { (x) & 0xff, ((x) >> 8) & 0xff, \
  74133. + ((x) >> 16) & 0xff, ((x) >> 24) & 0xff }
  74134. +
  74135. +#if 1
  74136. +#define UGETW(w) ((w)[0] | ((w)[1] << 8))
  74137. +#define USETW(w,v) ((w)[0] = (u_int8_t)(v), (w)[1] = (u_int8_t)((v) >> 8))
  74138. +#define UGETDW(w) ((w)[0] | ((w)[1] << 8) | ((w)[2] << 16) | ((w)[3] << 24))
  74139. +#define USETDW(w,v) ((w)[0] = (u_int8_t)(v), \
  74140. + (w)[1] = (u_int8_t)((v) >> 8), \
  74141. + (w)[2] = (u_int8_t)((v) >> 16), \
  74142. + (w)[3] = (u_int8_t)((v) >> 24))
  74143. +#else
  74144. +/*
  74145. + * On little-endian machines that can handle unanliged accesses
  74146. + * (e.g. i386) these macros can be replaced by the following.
  74147. + */
  74148. +#define UGETW(w) (*(u_int16_t *)(w))
  74149. +#define USETW(w,v) (*(u_int16_t *)(w) = (v))
  74150. +#define UGETDW(w) (*(u_int32_t *)(w))
  74151. +#define USETDW(w,v) (*(u_int32_t *)(w) = (v))
  74152. +#endif
  74153. +
  74154. +/*
  74155. + * Macros for accessing UAS IU fields, which are big-endian
  74156. + */
  74157. +#define IUSETW2(w,h,l) ((w)[0] = (u_int8_t)(h), (w)[1] = (u_int8_t)(l))
  74158. +#define IUCONSTW(x) { ((x) >> 8) & 0xff, (x) & 0xff }
  74159. +#define IUCONSTDW(x) { ((x) >> 24) & 0xff, ((x) >> 16) & 0xff, \
  74160. + ((x) >> 8) & 0xff, (x) & 0xff }
  74161. +#define IUGETW(w) (((w)[0] << 8) | (w)[1])
  74162. +#define IUSETW(w,v) ((w)[0] = (u_int8_t)((v) >> 8), (w)[1] = (u_int8_t)(v))
  74163. +#define IUGETDW(w) (((w)[0] << 24) | ((w)[1] << 16) | ((w)[2] << 8) | (w)[3])
  74164. +#define IUSETDW(w,v) ((w)[0] = (u_int8_t)((v) >> 24), \
  74165. + (w)[1] = (u_int8_t)((v) >> 16), \
  74166. + (w)[2] = (u_int8_t)((v) >> 8), \
  74167. + (w)[3] = (u_int8_t)(v))
  74168. +
  74169. +#define UPACKED __attribute__((__packed__))
  74170. +
  74171. +typedef struct {
  74172. + uByte bmRequestType;
  74173. + uByte bRequest;
  74174. + uWord wValue;
  74175. + uWord wIndex;
  74176. + uWord wLength;
  74177. +} UPACKED usb_device_request_t;
  74178. +
  74179. +#define UT_GET_DIR(a) ((a) & 0x80)
  74180. +#define UT_WRITE 0x00
  74181. +#define UT_READ 0x80
  74182. +
  74183. +#define UT_GET_TYPE(a) ((a) & 0x60)
  74184. +#define UT_STANDARD 0x00
  74185. +#define UT_CLASS 0x20
  74186. +#define UT_VENDOR 0x40
  74187. +
  74188. +#define UT_GET_RECIPIENT(a) ((a) & 0x1f)
  74189. +#define UT_DEVICE 0x00
  74190. +#define UT_INTERFACE 0x01
  74191. +#define UT_ENDPOINT 0x02
  74192. +#define UT_OTHER 0x03
  74193. +
  74194. +#define UT_READ_DEVICE (UT_READ | UT_STANDARD | UT_DEVICE)
  74195. +#define UT_READ_INTERFACE (UT_READ | UT_STANDARD | UT_INTERFACE)
  74196. +#define UT_READ_ENDPOINT (UT_READ | UT_STANDARD | UT_ENDPOINT)
  74197. +#define UT_WRITE_DEVICE (UT_WRITE | UT_STANDARD | UT_DEVICE)
  74198. +#define UT_WRITE_INTERFACE (UT_WRITE | UT_STANDARD | UT_INTERFACE)
  74199. +#define UT_WRITE_ENDPOINT (UT_WRITE | UT_STANDARD | UT_ENDPOINT)
  74200. +#define UT_READ_CLASS_DEVICE (UT_READ | UT_CLASS | UT_DEVICE)
  74201. +#define UT_READ_CLASS_INTERFACE (UT_READ | UT_CLASS | UT_INTERFACE)
  74202. +#define UT_READ_CLASS_OTHER (UT_READ | UT_CLASS | UT_OTHER)
  74203. +#define UT_READ_CLASS_ENDPOINT (UT_READ | UT_CLASS | UT_ENDPOINT)
  74204. +#define UT_WRITE_CLASS_DEVICE (UT_WRITE | UT_CLASS | UT_DEVICE)
  74205. +#define UT_WRITE_CLASS_INTERFACE (UT_WRITE | UT_CLASS | UT_INTERFACE)
  74206. +#define UT_WRITE_CLASS_OTHER (UT_WRITE | UT_CLASS | UT_OTHER)
  74207. +#define UT_WRITE_CLASS_ENDPOINT (UT_WRITE | UT_CLASS | UT_ENDPOINT)
  74208. +#define UT_READ_VENDOR_DEVICE (UT_READ | UT_VENDOR | UT_DEVICE)
  74209. +#define UT_READ_VENDOR_INTERFACE (UT_READ | UT_VENDOR | UT_INTERFACE)
  74210. +#define UT_READ_VENDOR_OTHER (UT_READ | UT_VENDOR | UT_OTHER)
  74211. +#define UT_READ_VENDOR_ENDPOINT (UT_READ | UT_VENDOR | UT_ENDPOINT)
  74212. +#define UT_WRITE_VENDOR_DEVICE (UT_WRITE | UT_VENDOR | UT_DEVICE)
  74213. +#define UT_WRITE_VENDOR_INTERFACE (UT_WRITE | UT_VENDOR | UT_INTERFACE)
  74214. +#define UT_WRITE_VENDOR_OTHER (UT_WRITE | UT_VENDOR | UT_OTHER)
  74215. +#define UT_WRITE_VENDOR_ENDPOINT (UT_WRITE | UT_VENDOR | UT_ENDPOINT)
  74216. +
  74217. +/* Requests */
  74218. +#define UR_GET_STATUS 0x00
  74219. +#define USTAT_STANDARD_STATUS 0x00
  74220. +#define WUSTAT_WUSB_FEATURE 0x01
  74221. +#define WUSTAT_CHANNEL_INFO 0x02
  74222. +#define WUSTAT_RECEIVED_DATA 0x03
  74223. +#define WUSTAT_MAS_AVAILABILITY 0x04
  74224. +#define WUSTAT_CURRENT_TRANSMIT_POWER 0x05
  74225. +#define UR_CLEAR_FEATURE 0x01
  74226. +#define UR_SET_FEATURE 0x03
  74227. +#define UR_SET_AND_TEST_FEATURE 0x0c
  74228. +#define UR_SET_ADDRESS 0x05
  74229. +#define UR_GET_DESCRIPTOR 0x06
  74230. +#define UDESC_DEVICE 0x01
  74231. +#define UDESC_CONFIG 0x02
  74232. +#define UDESC_STRING 0x03
  74233. +#define UDESC_INTERFACE 0x04
  74234. +#define UDESC_ENDPOINT 0x05
  74235. +#define UDESC_SS_USB_COMPANION 0x30
  74236. +#define UDESC_DEVICE_QUALIFIER 0x06
  74237. +#define UDESC_OTHER_SPEED_CONFIGURATION 0x07
  74238. +#define UDESC_INTERFACE_POWER 0x08
  74239. +#define UDESC_OTG 0x09
  74240. +#define WUDESC_SECURITY 0x0c
  74241. +#define WUDESC_KEY 0x0d
  74242. +#define WUD_GET_KEY_INDEX(_wValue_) ((_wValue_) & 0xf)
  74243. +#define WUD_GET_KEY_TYPE(_wValue_) (((_wValue_) & 0x30) >> 4)
  74244. +#define WUD_KEY_TYPE_ASSOC 0x01
  74245. +#define WUD_KEY_TYPE_GTK 0x02
  74246. +#define WUD_GET_KEY_ORIGIN(_wValue_) (((_wValue_) & 0x40) >> 6)
  74247. +#define WUD_KEY_ORIGIN_HOST 0x00
  74248. +#define WUD_KEY_ORIGIN_DEVICE 0x01
  74249. +#define WUDESC_ENCRYPTION_TYPE 0x0e
  74250. +#define WUDESC_BOS 0x0f
  74251. +#define WUDESC_DEVICE_CAPABILITY 0x10
  74252. +#define WUDESC_WIRELESS_ENDPOINT_COMPANION 0x11
  74253. +#define UDESC_BOS 0x0f
  74254. +#define UDESC_DEVICE_CAPABILITY 0x10
  74255. +#define UDESC_CS_DEVICE 0x21 /* class specific */
  74256. +#define UDESC_CS_CONFIG 0x22
  74257. +#define UDESC_CS_STRING 0x23
  74258. +#define UDESC_CS_INTERFACE 0x24
  74259. +#define UDESC_CS_ENDPOINT 0x25
  74260. +#define UDESC_HUB 0x29
  74261. +#define UR_SET_DESCRIPTOR 0x07
  74262. +#define UR_GET_CONFIG 0x08
  74263. +#define UR_SET_CONFIG 0x09
  74264. +#define UR_GET_INTERFACE 0x0a
  74265. +#define UR_SET_INTERFACE 0x0b
  74266. +#define UR_SYNCH_FRAME 0x0c
  74267. +#define WUR_SET_ENCRYPTION 0x0d
  74268. +#define WUR_GET_ENCRYPTION 0x0e
  74269. +#define WUR_SET_HANDSHAKE 0x0f
  74270. +#define WUR_GET_HANDSHAKE 0x10
  74271. +#define WUR_SET_CONNECTION 0x11
  74272. +#define WUR_SET_SECURITY_DATA 0x12
  74273. +#define WUR_GET_SECURITY_DATA 0x13
  74274. +#define WUR_SET_WUSB_DATA 0x14
  74275. +#define WUDATA_DRPIE_INFO 0x01
  74276. +#define WUDATA_TRANSMIT_DATA 0x02
  74277. +#define WUDATA_TRANSMIT_PARAMS 0x03
  74278. +#define WUDATA_RECEIVE_PARAMS 0x04
  74279. +#define WUDATA_TRANSMIT_POWER 0x05
  74280. +#define WUR_LOOPBACK_DATA_WRITE 0x15
  74281. +#define WUR_LOOPBACK_DATA_READ 0x16
  74282. +#define WUR_SET_INTERFACE_DS 0x17
  74283. +
  74284. +/* Feature numbers */
  74285. +#define UF_ENDPOINT_HALT 0
  74286. +#define UF_DEVICE_REMOTE_WAKEUP 1
  74287. +#define UF_TEST_MODE 2
  74288. +#define UF_DEVICE_B_HNP_ENABLE 3
  74289. +#define UF_DEVICE_A_HNP_SUPPORT 4
  74290. +#define UF_DEVICE_A_ALT_HNP_SUPPORT 5
  74291. +#define WUF_WUSB 3
  74292. +#define WUF_TX_DRPIE 0x0
  74293. +#define WUF_DEV_XMIT_PACKET 0x1
  74294. +#define WUF_COUNT_PACKETS 0x2
  74295. +#define WUF_CAPTURE_PACKETS 0x3
  74296. +#define UF_FUNCTION_SUSPEND 0
  74297. +#define UF_U1_ENABLE 48
  74298. +#define UF_U2_ENABLE 49
  74299. +#define UF_LTM_ENABLE 50
  74300. +
  74301. +/* Class requests from the USB 2.0 hub spec, table 11-15 */
  74302. +#define UCR_CLEAR_HUB_FEATURE (0x2000 | UR_CLEAR_FEATURE)
  74303. +#define UCR_CLEAR_PORT_FEATURE (0x2300 | UR_CLEAR_FEATURE)
  74304. +#define UCR_GET_HUB_DESCRIPTOR (0xa000 | UR_GET_DESCRIPTOR)
  74305. +#define UCR_GET_HUB_STATUS (0xa000 | UR_GET_STATUS)
  74306. +#define UCR_GET_PORT_STATUS (0xa300 | UR_GET_STATUS)
  74307. +#define UCR_SET_HUB_FEATURE (0x2000 | UR_SET_FEATURE)
  74308. +#define UCR_SET_PORT_FEATURE (0x2300 | UR_SET_FEATURE)
  74309. +#define UCR_SET_AND_TEST_PORT_FEATURE (0xa300 | UR_SET_AND_TEST_FEATURE)
  74310. +
  74311. +#ifdef _MSC_VER
  74312. +#include <pshpack1.h>
  74313. +#endif
  74314. +
  74315. +typedef struct {
  74316. + uByte bLength;
  74317. + uByte bDescriptorType;
  74318. + uByte bDescriptorSubtype;
  74319. +} UPACKED usb_descriptor_t;
  74320. +
  74321. +typedef struct {
  74322. + uByte bLength;
  74323. + uByte bDescriptorType;
  74324. +} UPACKED usb_descriptor_header_t;
  74325. +
  74326. +typedef struct {
  74327. + uByte bLength;
  74328. + uByte bDescriptorType;
  74329. + uWord bcdUSB;
  74330. +#define UD_USB_2_0 0x0200
  74331. +#define UD_IS_USB2(d) (UGETW((d)->bcdUSB) >= UD_USB_2_0)
  74332. + uByte bDeviceClass;
  74333. + uByte bDeviceSubClass;
  74334. + uByte bDeviceProtocol;
  74335. + uByte bMaxPacketSize;
  74336. + /* The fields below are not part of the initial descriptor. */
  74337. + uWord idVendor;
  74338. + uWord idProduct;
  74339. + uWord bcdDevice;
  74340. + uByte iManufacturer;
  74341. + uByte iProduct;
  74342. + uByte iSerialNumber;
  74343. + uByte bNumConfigurations;
  74344. +} UPACKED usb_device_descriptor_t;
  74345. +#define USB_DEVICE_DESCRIPTOR_SIZE 18
  74346. +
  74347. +typedef struct {
  74348. + uByte bLength;
  74349. + uByte bDescriptorType;
  74350. + uWord wTotalLength;
  74351. + uByte bNumInterface;
  74352. + uByte bConfigurationValue;
  74353. + uByte iConfiguration;
  74354. +#define UC_ATT_ONE (1 << 7) /* must be set */
  74355. +#define UC_ATT_SELFPOWER (1 << 6) /* self powered */
  74356. +#define UC_ATT_WAKEUP (1 << 5) /* can wakeup */
  74357. +#define UC_ATT_BATTERY (1 << 4) /* battery powered */
  74358. + uByte bmAttributes;
  74359. +#define UC_BUS_POWERED 0x80
  74360. +#define UC_SELF_POWERED 0x40
  74361. +#define UC_REMOTE_WAKEUP 0x20
  74362. + uByte bMaxPower; /* max current in 2 mA units */
  74363. +#define UC_POWER_FACTOR 2
  74364. +} UPACKED usb_config_descriptor_t;
  74365. +#define USB_CONFIG_DESCRIPTOR_SIZE 9
  74366. +
  74367. +typedef struct {
  74368. + uByte bLength;
  74369. + uByte bDescriptorType;
  74370. + uByte bInterfaceNumber;
  74371. + uByte bAlternateSetting;
  74372. + uByte bNumEndpoints;
  74373. + uByte bInterfaceClass;
  74374. + uByte bInterfaceSubClass;
  74375. + uByte bInterfaceProtocol;
  74376. + uByte iInterface;
  74377. +} UPACKED usb_interface_descriptor_t;
  74378. +#define USB_INTERFACE_DESCRIPTOR_SIZE 9
  74379. +
  74380. +typedef struct {
  74381. + uByte bLength;
  74382. + uByte bDescriptorType;
  74383. + uByte bEndpointAddress;
  74384. +#define UE_GET_DIR(a) ((a) & 0x80)
  74385. +#define UE_SET_DIR(a,d) ((a) | (((d)&1) << 7))
  74386. +#define UE_DIR_IN 0x80
  74387. +#define UE_DIR_OUT 0x00
  74388. +#define UE_ADDR 0x0f
  74389. +#define UE_GET_ADDR(a) ((a) & UE_ADDR)
  74390. + uByte bmAttributes;
  74391. +#define UE_XFERTYPE 0x03
  74392. +#define UE_CONTROL 0x00
  74393. +#define UE_ISOCHRONOUS 0x01
  74394. +#define UE_BULK 0x02
  74395. +#define UE_INTERRUPT 0x03
  74396. +#define UE_GET_XFERTYPE(a) ((a) & UE_XFERTYPE)
  74397. +#define UE_ISO_TYPE 0x0c
  74398. +#define UE_ISO_ASYNC 0x04
  74399. +#define UE_ISO_ADAPT 0x08
  74400. +#define UE_ISO_SYNC 0x0c
  74401. +#define UE_GET_ISO_TYPE(a) ((a) & UE_ISO_TYPE)
  74402. + uWord wMaxPacketSize;
  74403. + uByte bInterval;
  74404. +} UPACKED usb_endpoint_descriptor_t;
  74405. +#define USB_ENDPOINT_DESCRIPTOR_SIZE 7
  74406. +
  74407. +typedef struct ss_endpoint_companion_descriptor {
  74408. + uByte bLength;
  74409. + uByte bDescriptorType;
  74410. + uByte bMaxBurst;
  74411. +#define USSE_GET_MAX_STREAMS(a) ((a) & 0x1f)
  74412. +#define USSE_SET_MAX_STREAMS(a, b) ((a) | ((b) & 0x1f))
  74413. +#define USSE_GET_MAX_PACKET_NUM(a) ((a) & 0x03)
  74414. +#define USSE_SET_MAX_PACKET_NUM(a, b) ((a) | ((b) & 0x03))
  74415. + uByte bmAttributes;
  74416. + uWord wBytesPerInterval;
  74417. +} UPACKED ss_endpoint_companion_descriptor_t;
  74418. +#define USB_SS_ENDPOINT_COMPANION_DESCRIPTOR_SIZE 6
  74419. +
  74420. +typedef struct {
  74421. + uByte bLength;
  74422. + uByte bDescriptorType;
  74423. + uWord bString[127];
  74424. +} UPACKED usb_string_descriptor_t;
  74425. +#define USB_MAX_STRING_LEN 128
  74426. +#define USB_LANGUAGE_TABLE 0 /* # of the string language id table */
  74427. +
  74428. +/* Hub specific request */
  74429. +#define UR_GET_BUS_STATE 0x02
  74430. +#define UR_CLEAR_TT_BUFFER 0x08
  74431. +#define UR_RESET_TT 0x09
  74432. +#define UR_GET_TT_STATE 0x0a
  74433. +#define UR_STOP_TT 0x0b
  74434. +
  74435. +/* Hub features */
  74436. +#define UHF_C_HUB_LOCAL_POWER 0
  74437. +#define UHF_C_HUB_OVER_CURRENT 1
  74438. +#define UHF_PORT_CONNECTION 0
  74439. +#define UHF_PORT_ENABLE 1
  74440. +#define UHF_PORT_SUSPEND 2
  74441. +#define UHF_PORT_OVER_CURRENT 3
  74442. +#define UHF_PORT_RESET 4
  74443. +#define UHF_PORT_L1 5
  74444. +#define UHF_PORT_POWER 8
  74445. +#define UHF_PORT_LOW_SPEED 9
  74446. +#define UHF_PORT_HIGH_SPEED 10
  74447. +#define UHF_C_PORT_CONNECTION 16
  74448. +#define UHF_C_PORT_ENABLE 17
  74449. +#define UHF_C_PORT_SUSPEND 18
  74450. +#define UHF_C_PORT_OVER_CURRENT 19
  74451. +#define UHF_C_PORT_RESET 20
  74452. +#define UHF_C_PORT_L1 23
  74453. +#define UHF_PORT_TEST 21
  74454. +#define UHF_PORT_INDICATOR 22
  74455. +
  74456. +typedef struct {
  74457. + uByte bDescLength;
  74458. + uByte bDescriptorType;
  74459. + uByte bNbrPorts;
  74460. + uWord wHubCharacteristics;
  74461. +#define UHD_PWR 0x0003
  74462. +#define UHD_PWR_GANGED 0x0000
  74463. +#define UHD_PWR_INDIVIDUAL 0x0001
  74464. +#define UHD_PWR_NO_SWITCH 0x0002
  74465. +#define UHD_COMPOUND 0x0004
  74466. +#define UHD_OC 0x0018
  74467. +#define UHD_OC_GLOBAL 0x0000
  74468. +#define UHD_OC_INDIVIDUAL 0x0008
  74469. +#define UHD_OC_NONE 0x0010
  74470. +#define UHD_TT_THINK 0x0060
  74471. +#define UHD_TT_THINK_8 0x0000
  74472. +#define UHD_TT_THINK_16 0x0020
  74473. +#define UHD_TT_THINK_24 0x0040
  74474. +#define UHD_TT_THINK_32 0x0060
  74475. +#define UHD_PORT_IND 0x0080
  74476. + uByte bPwrOn2PwrGood; /* delay in 2 ms units */
  74477. +#define UHD_PWRON_FACTOR 2
  74478. + uByte bHubContrCurrent;
  74479. + uByte DeviceRemovable[32]; /* max 255 ports */
  74480. +#define UHD_NOT_REMOV(desc, i) \
  74481. + (((desc)->DeviceRemovable[(i)/8] >> ((i) % 8)) & 1)
  74482. + /* deprecated */ uByte PortPowerCtrlMask[1];
  74483. +} UPACKED usb_hub_descriptor_t;
  74484. +#define USB_HUB_DESCRIPTOR_SIZE 9 /* includes deprecated PortPowerCtrlMask */
  74485. +
  74486. +typedef struct {
  74487. + uByte bLength;
  74488. + uByte bDescriptorType;
  74489. + uWord bcdUSB;
  74490. + uByte bDeviceClass;
  74491. + uByte bDeviceSubClass;
  74492. + uByte bDeviceProtocol;
  74493. + uByte bMaxPacketSize0;
  74494. + uByte bNumConfigurations;
  74495. + uByte bReserved;
  74496. +} UPACKED usb_device_qualifier_t;
  74497. +#define USB_DEVICE_QUALIFIER_SIZE 10
  74498. +
  74499. +typedef struct {
  74500. + uByte bLength;
  74501. + uByte bDescriptorType;
  74502. + uByte bmAttributes;
  74503. +#define UOTG_SRP 0x01
  74504. +#define UOTG_HNP 0x02
  74505. +} UPACKED usb_otg_descriptor_t;
  74506. +
  74507. +/* OTG feature selectors */
  74508. +#define UOTG_B_HNP_ENABLE 3
  74509. +#define UOTG_A_HNP_SUPPORT 4
  74510. +#define UOTG_A_ALT_HNP_SUPPORT 5
  74511. +
  74512. +typedef struct {
  74513. + uWord wStatus;
  74514. +/* Device status flags */
  74515. +#define UDS_SELF_POWERED 0x0001
  74516. +#define UDS_REMOTE_WAKEUP 0x0002
  74517. +/* Endpoint status flags */
  74518. +#define UES_HALT 0x0001
  74519. +} UPACKED usb_status_t;
  74520. +
  74521. +typedef struct {
  74522. + uWord wHubStatus;
  74523. +#define UHS_LOCAL_POWER 0x0001
  74524. +#define UHS_OVER_CURRENT 0x0002
  74525. + uWord wHubChange;
  74526. +} UPACKED usb_hub_status_t;
  74527. +
  74528. +typedef struct {
  74529. + uWord wPortStatus;
  74530. +#define UPS_CURRENT_CONNECT_STATUS 0x0001
  74531. +#define UPS_PORT_ENABLED 0x0002
  74532. +#define UPS_SUSPEND 0x0004
  74533. +#define UPS_OVERCURRENT_INDICATOR 0x0008
  74534. +#define UPS_RESET 0x0010
  74535. +#define UPS_PORT_POWER 0x0100
  74536. +#define UPS_LOW_SPEED 0x0200
  74537. +#define UPS_HIGH_SPEED 0x0400
  74538. +#define UPS_PORT_TEST 0x0800
  74539. +#define UPS_PORT_INDICATOR 0x1000
  74540. + uWord wPortChange;
  74541. +#define UPS_C_CONNECT_STATUS 0x0001
  74542. +#define UPS_C_PORT_ENABLED 0x0002
  74543. +#define UPS_C_SUSPEND 0x0004
  74544. +#define UPS_C_OVERCURRENT_INDICATOR 0x0008
  74545. +#define UPS_C_PORT_RESET 0x0010
  74546. +} UPACKED usb_port_status_t;
  74547. +
  74548. +#ifdef _MSC_VER
  74549. +#include <poppack.h>
  74550. +#endif
  74551. +
  74552. +/* Device class codes */
  74553. +#define UDCLASS_IN_INTERFACE 0x00
  74554. +#define UDCLASS_COMM 0x02
  74555. +#define UDCLASS_HUB 0x09
  74556. +#define UDSUBCLASS_HUB 0x00
  74557. +#define UDPROTO_FSHUB 0x00
  74558. +#define UDPROTO_HSHUBSTT 0x01
  74559. +#define UDPROTO_HSHUBMTT 0x02
  74560. +#define UDCLASS_DIAGNOSTIC 0xdc
  74561. +#define UDCLASS_WIRELESS 0xe0
  74562. +#define UDSUBCLASS_RF 0x01
  74563. +#define UDPROTO_BLUETOOTH 0x01
  74564. +#define UDCLASS_VENDOR 0xff
  74565. +
  74566. +/* Interface class codes */
  74567. +#define UICLASS_UNSPEC 0x00
  74568. +
  74569. +#define UICLASS_AUDIO 0x01
  74570. +#define UISUBCLASS_AUDIOCONTROL 1
  74571. +#define UISUBCLASS_AUDIOSTREAM 2
  74572. +#define UISUBCLASS_MIDISTREAM 3
  74573. +
  74574. +#define UICLASS_CDC 0x02 /* communication */
  74575. +#define UISUBCLASS_DIRECT_LINE_CONTROL_MODEL 1
  74576. +#define UISUBCLASS_ABSTRACT_CONTROL_MODEL 2
  74577. +#define UISUBCLASS_TELEPHONE_CONTROL_MODEL 3
  74578. +#define UISUBCLASS_MULTICHANNEL_CONTROL_MODEL 4
  74579. +#define UISUBCLASS_CAPI_CONTROLMODEL 5
  74580. +#define UISUBCLASS_ETHERNET_NETWORKING_CONTROL_MODEL 6
  74581. +#define UISUBCLASS_ATM_NETWORKING_CONTROL_MODEL 7
  74582. +#define UIPROTO_CDC_AT 1
  74583. +
  74584. +#define UICLASS_HID 0x03
  74585. +#define UISUBCLASS_BOOT 1
  74586. +#define UIPROTO_BOOT_KEYBOARD 1
  74587. +
  74588. +#define UICLASS_PHYSICAL 0x05
  74589. +
  74590. +#define UICLASS_IMAGE 0x06
  74591. +
  74592. +#define UICLASS_PRINTER 0x07
  74593. +#define UISUBCLASS_PRINTER 1
  74594. +#define UIPROTO_PRINTER_UNI 1
  74595. +#define UIPROTO_PRINTER_BI 2
  74596. +#define UIPROTO_PRINTER_1284 3
  74597. +
  74598. +#define UICLASS_MASS 0x08
  74599. +#define UISUBCLASS_RBC 1
  74600. +#define UISUBCLASS_SFF8020I 2
  74601. +#define UISUBCLASS_QIC157 3
  74602. +#define UISUBCLASS_UFI 4
  74603. +#define UISUBCLASS_SFF8070I 5
  74604. +#define UISUBCLASS_SCSI 6
  74605. +#define UIPROTO_MASS_CBI_I 0
  74606. +#define UIPROTO_MASS_CBI 1
  74607. +#define UIPROTO_MASS_BBB_OLD 2 /* Not in the spec anymore */
  74608. +#define UIPROTO_MASS_BBB 80 /* 'P' for the Iomega Zip drive */
  74609. +
  74610. +#define UICLASS_HUB 0x09
  74611. +#define UISUBCLASS_HUB 0
  74612. +#define UIPROTO_FSHUB 0
  74613. +#define UIPROTO_HSHUBSTT 0 /* Yes, same as previous */
  74614. +#define UIPROTO_HSHUBMTT 1
  74615. +
  74616. +#define UICLASS_CDC_DATA 0x0a
  74617. +#define UISUBCLASS_DATA 0
  74618. +#define UIPROTO_DATA_ISDNBRI 0x30 /* Physical iface */
  74619. +#define UIPROTO_DATA_HDLC 0x31 /* HDLC */
  74620. +#define UIPROTO_DATA_TRANSPARENT 0x32 /* Transparent */
  74621. +#define UIPROTO_DATA_Q921M 0x50 /* Management for Q921 */
  74622. +#define UIPROTO_DATA_Q921 0x51 /* Data for Q921 */
  74623. +#define UIPROTO_DATA_Q921TM 0x52 /* TEI multiplexer for Q921 */
  74624. +#define UIPROTO_DATA_V42BIS 0x90 /* Data compression */
  74625. +#define UIPROTO_DATA_Q931 0x91 /* Euro-ISDN */
  74626. +#define UIPROTO_DATA_V120 0x92 /* V.24 rate adaption */
  74627. +#define UIPROTO_DATA_CAPI 0x93 /* CAPI 2.0 commands */
  74628. +#define UIPROTO_DATA_HOST_BASED 0xfd /* Host based driver */
  74629. +#define UIPROTO_DATA_PUF 0xfe /* see Prot. Unit Func. Desc.*/
  74630. +#define UIPROTO_DATA_VENDOR 0xff /* Vendor specific */
  74631. +
  74632. +#define UICLASS_SMARTCARD 0x0b
  74633. +
  74634. +/*#define UICLASS_FIRM_UPD 0x0c*/
  74635. +
  74636. +#define UICLASS_SECURITY 0x0d
  74637. +
  74638. +#define UICLASS_DIAGNOSTIC 0xdc
  74639. +
  74640. +#define UICLASS_WIRELESS 0xe0
  74641. +#define UISUBCLASS_RF 0x01
  74642. +#define UIPROTO_BLUETOOTH 0x01
  74643. +
  74644. +#define UICLASS_APPL_SPEC 0xfe
  74645. +#define UISUBCLASS_FIRMWARE_DOWNLOAD 1
  74646. +#define UISUBCLASS_IRDA 2
  74647. +#define UIPROTO_IRDA 0
  74648. +
  74649. +#define UICLASS_VENDOR 0xff
  74650. +
  74651. +#define USB_HUB_MAX_DEPTH 5
  74652. +
  74653. +/*
  74654. + * Minimum time a device needs to be powered down to go through
  74655. + * a power cycle. XXX Are these time in the spec?
  74656. + */
  74657. +#define USB_POWER_DOWN_TIME 200 /* ms */
  74658. +#define USB_PORT_POWER_DOWN_TIME 100 /* ms */
  74659. +
  74660. +#if 0
  74661. +/* These are the values from the spec. */
  74662. +#define USB_PORT_RESET_DELAY 10 /* ms */
  74663. +#define USB_PORT_ROOT_RESET_DELAY 50 /* ms */
  74664. +#define USB_PORT_RESET_RECOVERY 10 /* ms */
  74665. +#define USB_PORT_POWERUP_DELAY 100 /* ms */
  74666. +#define USB_SET_ADDRESS_SETTLE 2 /* ms */
  74667. +#define USB_RESUME_DELAY (20*5) /* ms */
  74668. +#define USB_RESUME_WAIT 10 /* ms */
  74669. +#define USB_RESUME_RECOVERY 10 /* ms */
  74670. +#define USB_EXTRA_POWER_UP_TIME 0 /* ms */
  74671. +#else
  74672. +/* Allow for marginal (i.e. non-conforming) devices. */
  74673. +#define USB_PORT_RESET_DELAY 50 /* ms */
  74674. +#define USB_PORT_ROOT_RESET_DELAY 250 /* ms */
  74675. +#define USB_PORT_RESET_RECOVERY 250 /* ms */
  74676. +#define USB_PORT_POWERUP_DELAY 300 /* ms */
  74677. +#define USB_SET_ADDRESS_SETTLE 10 /* ms */
  74678. +#define USB_RESUME_DELAY (50*5) /* ms */
  74679. +#define USB_RESUME_WAIT 50 /* ms */
  74680. +#define USB_RESUME_RECOVERY 50 /* ms */
  74681. +#define USB_EXTRA_POWER_UP_TIME 20 /* ms */
  74682. +#endif
  74683. +
  74684. +#define USB_MIN_POWER 100 /* mA */
  74685. +#define USB_MAX_POWER 500 /* mA */
  74686. +
  74687. +#define USB_BUS_RESET_DELAY 100 /* ms XXX?*/
  74688. +
  74689. +#define USB_UNCONFIG_NO 0
  74690. +#define USB_UNCONFIG_INDEX (-1)
  74691. +
  74692. +/*** ioctl() related stuff ***/
  74693. +
  74694. +struct usb_ctl_request {
  74695. + int ucr_addr;
  74696. + usb_device_request_t ucr_request;
  74697. + void *ucr_data;
  74698. + int ucr_flags;
  74699. +#define USBD_SHORT_XFER_OK 0x04 /* allow short reads */
  74700. + int ucr_actlen; /* actual length transferred */
  74701. +};
  74702. +
  74703. +struct usb_alt_interface {
  74704. + int uai_config_index;
  74705. + int uai_interface_index;
  74706. + int uai_alt_no;
  74707. +};
  74708. +
  74709. +#define USB_CURRENT_CONFIG_INDEX (-1)
  74710. +#define USB_CURRENT_ALT_INDEX (-1)
  74711. +
  74712. +struct usb_config_desc {
  74713. + int ucd_config_index;
  74714. + usb_config_descriptor_t ucd_desc;
  74715. +};
  74716. +
  74717. +struct usb_interface_desc {
  74718. + int uid_config_index;
  74719. + int uid_interface_index;
  74720. + int uid_alt_index;
  74721. + usb_interface_descriptor_t uid_desc;
  74722. +};
  74723. +
  74724. +struct usb_endpoint_desc {
  74725. + int ued_config_index;
  74726. + int ued_interface_index;
  74727. + int ued_alt_index;
  74728. + int ued_endpoint_index;
  74729. + usb_endpoint_descriptor_t ued_desc;
  74730. +};
  74731. +
  74732. +struct usb_full_desc {
  74733. + int ufd_config_index;
  74734. + u_int ufd_size;
  74735. + u_char *ufd_data;
  74736. +};
  74737. +
  74738. +struct usb_string_desc {
  74739. + int usd_string_index;
  74740. + int usd_language_id;
  74741. + usb_string_descriptor_t usd_desc;
  74742. +};
  74743. +
  74744. +struct usb_ctl_report_desc {
  74745. + int ucrd_size;
  74746. + u_char ucrd_data[1024]; /* filled data size will vary */
  74747. +};
  74748. +
  74749. +typedef struct { u_int32_t cookie; } usb_event_cookie_t;
  74750. +
  74751. +#define USB_MAX_DEVNAMES 4
  74752. +#define USB_MAX_DEVNAMELEN 16
  74753. +struct usb_device_info {
  74754. + u_int8_t udi_bus;
  74755. + u_int8_t udi_addr; /* device address */
  74756. + usb_event_cookie_t udi_cookie;
  74757. + char udi_product[USB_MAX_STRING_LEN];
  74758. + char udi_vendor[USB_MAX_STRING_LEN];
  74759. + char udi_release[8];
  74760. + u_int16_t udi_productNo;
  74761. + u_int16_t udi_vendorNo;
  74762. + u_int16_t udi_releaseNo;
  74763. + u_int8_t udi_class;
  74764. + u_int8_t udi_subclass;
  74765. + u_int8_t udi_protocol;
  74766. + u_int8_t udi_config;
  74767. + u_int8_t udi_speed;
  74768. +#define USB_SPEED_UNKNOWN 0
  74769. +#define USB_SPEED_LOW 1
  74770. +#define USB_SPEED_FULL 2
  74771. +#define USB_SPEED_HIGH 3
  74772. +#define USB_SPEED_VARIABLE 4
  74773. +#define USB_SPEED_SUPER 5
  74774. + int udi_power; /* power consumption in mA, 0 if selfpowered */
  74775. + int udi_nports;
  74776. + char udi_devnames[USB_MAX_DEVNAMES][USB_MAX_DEVNAMELEN];
  74777. + u_int8_t udi_ports[16];/* hub only: addresses of devices on ports */
  74778. +#define USB_PORT_ENABLED 0xff
  74779. +#define USB_PORT_SUSPENDED 0xfe
  74780. +#define USB_PORT_POWERED 0xfd
  74781. +#define USB_PORT_DISABLED 0xfc
  74782. +};
  74783. +
  74784. +struct usb_ctl_report {
  74785. + int ucr_report;
  74786. + u_char ucr_data[1024]; /* filled data size will vary */
  74787. +};
  74788. +
  74789. +struct usb_device_stats {
  74790. + u_long uds_requests[4]; /* indexed by transfer type UE_* */
  74791. +};
  74792. +
  74793. +#define WUSB_MIN_IE 0x80
  74794. +#define WUSB_WCTA_IE 0x80
  74795. +#define WUSB_WCONNECTACK_IE 0x81
  74796. +#define WUSB_WHOSTINFO_IE 0x82
  74797. +#define WUHI_GET_CA(_bmAttributes_) ((_bmAttributes_) & 0x3)
  74798. +#define WUHI_CA_RECONN 0x00
  74799. +#define WUHI_CA_LIMITED 0x01
  74800. +#define WUHI_CA_ALL 0x03
  74801. +#define WUHI_GET_MLSI(_bmAttributes_) (((_bmAttributes_) & 0x38) >> 3)
  74802. +#define WUSB_WCHCHANGEANNOUNCE_IE 0x83
  74803. +#define WUSB_WDEV_DISCONNECT_IE 0x84
  74804. +#define WUSB_WHOST_DISCONNECT_IE 0x85
  74805. +#define WUSB_WRELEASE_CHANNEL_IE 0x86
  74806. +#define WUSB_WWORK_IE 0x87
  74807. +#define WUSB_WCHANNEL_STOP_IE 0x88
  74808. +#define WUSB_WDEV_KEEPALIVE_IE 0x89
  74809. +#define WUSB_WISOCH_DISCARD_IE 0x8A
  74810. +#define WUSB_WRESETDEVICE_IE 0x8B
  74811. +#define WUSB_WXMIT_PACKET_ADJUST_IE 0x8C
  74812. +#define WUSB_MAX_IE 0x8C
  74813. +
  74814. +/* Device Notification Types */
  74815. +
  74816. +#define WUSB_DN_MIN 0x01
  74817. +#define WUSB_DN_CONNECT 0x01
  74818. +# define WUSB_DA_OLDCONN 0x00
  74819. +# define WUSB_DA_NEWCONN 0x01
  74820. +# define WUSB_DA_SELF_BEACON 0x02
  74821. +# define WUSB_DA_DIR_BEACON 0x04
  74822. +# define WUSB_DA_NO_BEACON 0x06
  74823. +#define WUSB_DN_DISCONNECT 0x02
  74824. +#define WUSB_DN_EPRDY 0x03
  74825. +#define WUSB_DN_MASAVAILCHANGED 0x04
  74826. +#define WUSB_DN_REMOTEWAKEUP 0x05
  74827. +#define WUSB_DN_SLEEP 0x06
  74828. +#define WUSB_DN_ALIVE 0x07
  74829. +#define WUSB_DN_MAX 0x07
  74830. +
  74831. +#ifdef _MSC_VER
  74832. +#include <pshpack1.h>
  74833. +#endif
  74834. +
  74835. +/* WUSB Handshake Data. Used during the SET/GET HANDSHAKE requests */
  74836. +typedef struct wusb_hndshk_data {
  74837. + uByte bMessageNumber;
  74838. + uByte bStatus;
  74839. + uByte tTKID[3];
  74840. + uByte bReserved;
  74841. + uByte CDID[16];
  74842. + uByte Nonce[16];
  74843. + uByte MIC[8];
  74844. +} UPACKED wusb_hndshk_data_t;
  74845. +#define WUSB_HANDSHAKE_LEN_FOR_MIC 38
  74846. +
  74847. +/* WUSB Connection Context */
  74848. +typedef struct wusb_conn_context {
  74849. + uByte CHID [16];
  74850. + uByte CDID [16];
  74851. + uByte CK [16];
  74852. +} UPACKED wusb_conn_context_t;
  74853. +
  74854. +/* WUSB Security Descriptor */
  74855. +typedef struct wusb_security_desc {
  74856. + uByte bLength;
  74857. + uByte bDescriptorType;
  74858. + uWord wTotalLength;
  74859. + uByte bNumEncryptionTypes;
  74860. +} UPACKED wusb_security_desc_t;
  74861. +
  74862. +/* WUSB Encryption Type Descriptor */
  74863. +typedef struct wusb_encrypt_type_desc {
  74864. + uByte bLength;
  74865. + uByte bDescriptorType;
  74866. +
  74867. + uByte bEncryptionType;
  74868. +#define WUETD_UNSECURE 0
  74869. +#define WUETD_WIRED 1
  74870. +#define WUETD_CCM_1 2
  74871. +#define WUETD_RSA_1 3
  74872. +
  74873. + uByte bEncryptionValue;
  74874. + uByte bAuthKeyIndex;
  74875. +} UPACKED wusb_encrypt_type_desc_t;
  74876. +
  74877. +/* WUSB Key Descriptor */
  74878. +typedef struct wusb_key_desc {
  74879. + uByte bLength;
  74880. + uByte bDescriptorType;
  74881. + uByte tTKID[3];
  74882. + uByte bReserved;
  74883. + uByte KeyData[1]; /* variable length */
  74884. +} UPACKED wusb_key_desc_t;
  74885. +
  74886. +/* WUSB BOS Descriptor (Binary device Object Store) */
  74887. +typedef struct wusb_bos_desc {
  74888. + uByte bLength;
  74889. + uByte bDescriptorType;
  74890. + uWord wTotalLength;
  74891. + uByte bNumDeviceCaps;
  74892. +} UPACKED wusb_bos_desc_t;
  74893. +
  74894. +#define USB_DEVICE_CAPABILITY_20_EXTENSION 0x02
  74895. +typedef struct usb_dev_cap_20_ext_desc {
  74896. + uByte bLength;
  74897. + uByte bDescriptorType;
  74898. + uByte bDevCapabilityType;
  74899. +#define USB_20_EXT_LPM 0x02
  74900. + uDWord bmAttributes;
  74901. +} UPACKED usb_dev_cap_20_ext_desc_t;
  74902. +
  74903. +#define USB_DEVICE_CAPABILITY_SS_USB 0x03
  74904. +typedef struct usb_dev_cap_ss_usb {
  74905. + uByte bLength;
  74906. + uByte bDescriptorType;
  74907. + uByte bDevCapabilityType;
  74908. +#define USB_DC_SS_USB_LTM_CAPABLE 0x02
  74909. + uByte bmAttributes;
  74910. +#define USB_DC_SS_USB_SPEED_SUPPORT_LOW 0x01
  74911. +#define USB_DC_SS_USB_SPEED_SUPPORT_FULL 0x02
  74912. +#define USB_DC_SS_USB_SPEED_SUPPORT_HIGH 0x04
  74913. +#define USB_DC_SS_USB_SPEED_SUPPORT_SS 0x08
  74914. + uWord wSpeedsSupported;
  74915. + uByte bFunctionalitySupport;
  74916. + uByte bU1DevExitLat;
  74917. + uWord wU2DevExitLat;
  74918. +} UPACKED usb_dev_cap_ss_usb_t;
  74919. +
  74920. +#define USB_DEVICE_CAPABILITY_CONTAINER_ID 0x04
  74921. +typedef struct usb_dev_cap_container_id {
  74922. + uByte bLength;
  74923. + uByte bDescriptorType;
  74924. + uByte bDevCapabilityType;
  74925. + uByte bReserved;
  74926. + uByte containerID[16];
  74927. +} UPACKED usb_dev_cap_container_id_t;
  74928. +
  74929. +/* Device Capability Type Codes */
  74930. +#define WUSB_DEVICE_CAPABILITY_WIRELESS_USB 0x01
  74931. +
  74932. +/* Device Capability Descriptor */
  74933. +typedef struct wusb_dev_cap_desc {
  74934. + uByte bLength;
  74935. + uByte bDescriptorType;
  74936. + uByte bDevCapabilityType;
  74937. + uByte caps[1]; /* Variable length */
  74938. +} UPACKED wusb_dev_cap_desc_t;
  74939. +
  74940. +/* Device Capability Descriptor */
  74941. +typedef struct wusb_dev_cap_uwb_desc {
  74942. + uByte bLength;
  74943. + uByte bDescriptorType;
  74944. + uByte bDevCapabilityType;
  74945. + uByte bmAttributes;
  74946. + uWord wPHYRates; /* Bitmap */
  74947. + uByte bmTFITXPowerInfo;
  74948. + uByte bmFFITXPowerInfo;
  74949. + uWord bmBandGroup;
  74950. + uByte bReserved;
  74951. +} UPACKED wusb_dev_cap_uwb_desc_t;
  74952. +
  74953. +/* Wireless USB Endpoint Companion Descriptor */
  74954. +typedef struct wusb_endpoint_companion_desc {
  74955. + uByte bLength;
  74956. + uByte bDescriptorType;
  74957. + uByte bMaxBurst;
  74958. + uByte bMaxSequence;
  74959. + uWord wMaxStreamDelay;
  74960. + uWord wOverTheAirPacketSize;
  74961. + uByte bOverTheAirInterval;
  74962. + uByte bmCompAttributes;
  74963. +} UPACKED wusb_endpoint_companion_desc_t;
  74964. +
  74965. +/* Wireless USB Numeric Association M1 Data Structure */
  74966. +typedef struct wusb_m1_data {
  74967. + uByte version;
  74968. + uWord langId;
  74969. + uByte deviceFriendlyNameLength;
  74970. + uByte sha_256_m3[32];
  74971. + uByte deviceFriendlyName[256];
  74972. +} UPACKED wusb_m1_data_t;
  74973. +
  74974. +typedef struct wusb_m2_data {
  74975. + uByte version;
  74976. + uWord langId;
  74977. + uByte hostFriendlyNameLength;
  74978. + uByte pkh[384];
  74979. + uByte hostFriendlyName[256];
  74980. +} UPACKED wusb_m2_data_t;
  74981. +
  74982. +typedef struct wusb_m3_data {
  74983. + uByte pkd[384];
  74984. + uByte nd;
  74985. +} UPACKED wusb_m3_data_t;
  74986. +
  74987. +typedef struct wusb_m4_data {
  74988. + uDWord _attributeTypeIdAndLength_1;
  74989. + uWord associationTypeId;
  74990. +
  74991. + uDWord _attributeTypeIdAndLength_2;
  74992. + uWord associationSubTypeId;
  74993. +
  74994. + uDWord _attributeTypeIdAndLength_3;
  74995. + uDWord length;
  74996. +
  74997. + uDWord _attributeTypeIdAndLength_4;
  74998. + uDWord associationStatus;
  74999. +
  75000. + uDWord _attributeTypeIdAndLength_5;
  75001. + uByte chid[16];
  75002. +
  75003. + uDWord _attributeTypeIdAndLength_6;
  75004. + uByte cdid[16];
  75005. +
  75006. + uDWord _attributeTypeIdAndLength_7;
  75007. + uByte bandGroups[2];
  75008. +} UPACKED wusb_m4_data_t;
  75009. +
  75010. +#ifdef _MSC_VER
  75011. +#include <poppack.h>
  75012. +#endif
  75013. +
  75014. +#ifdef __cplusplus
  75015. +}
  75016. +#endif
  75017. +
  75018. +#endif /* _USB_H_ */
  75019. diff -Nur linux-3.18.8/drivers/usb/host/dwc_otg/doc/doxygen.cfg linux-rpi/drivers/usb/host/dwc_otg/doc/doxygen.cfg
  75020. --- linux-3.18.8/drivers/usb/host/dwc_otg/doc/doxygen.cfg 1970-01-01 01:00:00.000000000 +0100
  75021. +++ linux-rpi/drivers/usb/host/dwc_otg/doc/doxygen.cfg 2015-03-05 14:40:16.557715806 +0100
  75022. @@ -0,0 +1,224 @@
  75023. +# Doxyfile 1.3.9.1
  75024. +
  75025. +#---------------------------------------------------------------------------
  75026. +# Project related configuration options
  75027. +#---------------------------------------------------------------------------
  75028. +PROJECT_NAME = "DesignWare USB 2.0 OTG Controller (DWC_otg) Device Driver"
  75029. +PROJECT_NUMBER = v3.00a
  75030. +OUTPUT_DIRECTORY = ./doc/
  75031. +CREATE_SUBDIRS = NO
  75032. +OUTPUT_LANGUAGE = English
  75033. +BRIEF_MEMBER_DESC = YES
  75034. +REPEAT_BRIEF = YES
  75035. +ABBREVIATE_BRIEF = "The $name class" \
  75036. + "The $name widget" \
  75037. + "The $name file" \
  75038. + is \
  75039. + provides \
  75040. + specifies \
  75041. + contains \
  75042. + represents \
  75043. + a \
  75044. + an \
  75045. + the
  75046. +ALWAYS_DETAILED_SEC = NO
  75047. +INLINE_INHERITED_MEMB = NO
  75048. +FULL_PATH_NAMES = NO
  75049. +STRIP_FROM_PATH =
  75050. +STRIP_FROM_INC_PATH =
  75051. +SHORT_NAMES = NO
  75052. +JAVADOC_AUTOBRIEF = YES
  75053. +MULTILINE_CPP_IS_BRIEF = NO
  75054. +INHERIT_DOCS = YES
  75055. +DISTRIBUTE_GROUP_DOC = NO
  75056. +TAB_SIZE = 8
  75057. +ALIASES =
  75058. +OPTIMIZE_OUTPUT_FOR_C = YES
  75059. +OPTIMIZE_OUTPUT_JAVA = NO
  75060. +SUBGROUPING = YES
  75061. +#---------------------------------------------------------------------------
  75062. +# Build related configuration options
  75063. +#---------------------------------------------------------------------------
  75064. +EXTRACT_ALL = NO
  75065. +EXTRACT_PRIVATE = YES
  75066. +EXTRACT_STATIC = YES
  75067. +EXTRACT_LOCAL_CLASSES = YES
  75068. +EXTRACT_LOCAL_METHODS = NO
  75069. +HIDE_UNDOC_MEMBERS = NO
  75070. +HIDE_UNDOC_CLASSES = NO
  75071. +HIDE_FRIEND_COMPOUNDS = NO
  75072. +HIDE_IN_BODY_DOCS = NO
  75073. +INTERNAL_DOCS = NO
  75074. +CASE_SENSE_NAMES = NO
  75075. +HIDE_SCOPE_NAMES = NO
  75076. +SHOW_INCLUDE_FILES = YES
  75077. +INLINE_INFO = YES
  75078. +SORT_MEMBER_DOCS = NO
  75079. +SORT_BRIEF_DOCS = NO
  75080. +SORT_BY_SCOPE_NAME = NO
  75081. +GENERATE_TODOLIST = YES
  75082. +GENERATE_TESTLIST = YES
  75083. +GENERATE_BUGLIST = YES
  75084. +GENERATE_DEPRECATEDLIST= YES
  75085. +ENABLED_SECTIONS =
  75086. +MAX_INITIALIZER_LINES = 30
  75087. +SHOW_USED_FILES = YES
  75088. +SHOW_DIRECTORIES = YES
  75089. +#---------------------------------------------------------------------------
  75090. +# configuration options related to warning and progress messages
  75091. +#---------------------------------------------------------------------------
  75092. +QUIET = YES
  75093. +WARNINGS = YES
  75094. +WARN_IF_UNDOCUMENTED = NO
  75095. +WARN_IF_DOC_ERROR = YES
  75096. +WARN_FORMAT = "$file:$line: $text"
  75097. +WARN_LOGFILE =
  75098. +#---------------------------------------------------------------------------
  75099. +# configuration options related to the input files
  75100. +#---------------------------------------------------------------------------
  75101. +INPUT = .
  75102. +FILE_PATTERNS = *.c \
  75103. + *.h \
  75104. + ./linux/*.c \
  75105. + ./linux/*.h
  75106. +RECURSIVE = NO
  75107. +EXCLUDE = ./test/ \
  75108. + ./dwc_otg/.AppleDouble/
  75109. +EXCLUDE_SYMLINKS = YES
  75110. +EXCLUDE_PATTERNS = *.mod.*
  75111. +EXAMPLE_PATH =
  75112. +EXAMPLE_PATTERNS = *
  75113. +EXAMPLE_RECURSIVE = NO
  75114. +IMAGE_PATH =
  75115. +INPUT_FILTER =
  75116. +FILTER_PATTERNS =
  75117. +FILTER_SOURCE_FILES = NO
  75118. +#---------------------------------------------------------------------------
  75119. +# configuration options related to source browsing
  75120. +#---------------------------------------------------------------------------
  75121. +SOURCE_BROWSER = YES
  75122. +INLINE_SOURCES = NO
  75123. +STRIP_CODE_COMMENTS = YES
  75124. +REFERENCED_BY_RELATION = NO
  75125. +REFERENCES_RELATION = NO
  75126. +VERBATIM_HEADERS = NO
  75127. +#---------------------------------------------------------------------------
  75128. +# configuration options related to the alphabetical class index
  75129. +#---------------------------------------------------------------------------
  75130. +ALPHABETICAL_INDEX = NO
  75131. +COLS_IN_ALPHA_INDEX = 5
  75132. +IGNORE_PREFIX =
  75133. +#---------------------------------------------------------------------------
  75134. +# configuration options related to the HTML output
  75135. +#---------------------------------------------------------------------------
  75136. +GENERATE_HTML = YES
  75137. +HTML_OUTPUT = html
  75138. +HTML_FILE_EXTENSION = .html
  75139. +HTML_HEADER =
  75140. +HTML_FOOTER =
  75141. +HTML_STYLESHEET =
  75142. +HTML_ALIGN_MEMBERS = YES
  75143. +GENERATE_HTMLHELP = NO
  75144. +CHM_FILE =
  75145. +HHC_LOCATION =
  75146. +GENERATE_CHI = NO
  75147. +BINARY_TOC = NO
  75148. +TOC_EXPAND = NO
  75149. +DISABLE_INDEX = NO
  75150. +ENUM_VALUES_PER_LINE = 4
  75151. +GENERATE_TREEVIEW = YES
  75152. +TREEVIEW_WIDTH = 250
  75153. +#---------------------------------------------------------------------------
  75154. +# configuration options related to the LaTeX output
  75155. +#---------------------------------------------------------------------------
  75156. +GENERATE_LATEX = NO
  75157. +LATEX_OUTPUT = latex
  75158. +LATEX_CMD_NAME = latex
  75159. +MAKEINDEX_CMD_NAME = makeindex
  75160. +COMPACT_LATEX = NO
  75161. +PAPER_TYPE = a4wide
  75162. +EXTRA_PACKAGES =
  75163. +LATEX_HEADER =
  75164. +PDF_HYPERLINKS = NO
  75165. +USE_PDFLATEX = NO
  75166. +LATEX_BATCHMODE = NO
  75167. +LATEX_HIDE_INDICES = NO
  75168. +#---------------------------------------------------------------------------
  75169. +# configuration options related to the RTF output
  75170. +#---------------------------------------------------------------------------
  75171. +GENERATE_RTF = NO
  75172. +RTF_OUTPUT = rtf
  75173. +COMPACT_RTF = NO
  75174. +RTF_HYPERLINKS = NO
  75175. +RTF_STYLESHEET_FILE =
  75176. +RTF_EXTENSIONS_FILE =
  75177. +#---------------------------------------------------------------------------
  75178. +# configuration options related to the man page output
  75179. +#---------------------------------------------------------------------------
  75180. +GENERATE_MAN = NO
  75181. +MAN_OUTPUT = man
  75182. +MAN_EXTENSION = .3
  75183. +MAN_LINKS = NO
  75184. +#---------------------------------------------------------------------------
  75185. +# configuration options related to the XML output
  75186. +#---------------------------------------------------------------------------
  75187. +GENERATE_XML = NO
  75188. +XML_OUTPUT = xml
  75189. +XML_SCHEMA =
  75190. +XML_DTD =
  75191. +XML_PROGRAMLISTING = YES
  75192. +#---------------------------------------------------------------------------
  75193. +# configuration options for the AutoGen Definitions output
  75194. +#---------------------------------------------------------------------------
  75195. +GENERATE_AUTOGEN_DEF = NO
  75196. +#---------------------------------------------------------------------------
  75197. +# configuration options related to the Perl module output
  75198. +#---------------------------------------------------------------------------
  75199. +GENERATE_PERLMOD = NO
  75200. +PERLMOD_LATEX = NO
  75201. +PERLMOD_PRETTY = YES
  75202. +PERLMOD_MAKEVAR_PREFIX =
  75203. +#---------------------------------------------------------------------------
  75204. +# Configuration options related to the preprocessor
  75205. +#---------------------------------------------------------------------------
  75206. +ENABLE_PREPROCESSING = YES
  75207. +MACRO_EXPANSION = YES
  75208. +EXPAND_ONLY_PREDEF = YES
  75209. +SEARCH_INCLUDES = YES
  75210. +INCLUDE_PATH =
  75211. +INCLUDE_FILE_PATTERNS =
  75212. +PREDEFINED = DEVICE_ATTR DWC_EN_ISOC
  75213. +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
  75214. +SKIP_FUNCTION_MACROS = NO
  75215. +#---------------------------------------------------------------------------
  75216. +# Configuration::additions related to external references
  75217. +#---------------------------------------------------------------------------
  75218. +TAGFILES =
  75219. +GENERATE_TAGFILE =
  75220. +ALLEXTERNALS = NO
  75221. +EXTERNAL_GROUPS = YES
  75222. +PERL_PATH = /usr/bin/perl
  75223. +#---------------------------------------------------------------------------
  75224. +# Configuration options related to the dot tool
  75225. +#---------------------------------------------------------------------------
  75226. +CLASS_DIAGRAMS = YES
  75227. +HIDE_UNDOC_RELATIONS = YES
  75228. +HAVE_DOT = NO
  75229. +CLASS_GRAPH = YES
  75230. +COLLABORATION_GRAPH = YES
  75231. +UML_LOOK = NO
  75232. +TEMPLATE_RELATIONS = NO
  75233. +INCLUDE_GRAPH = YES
  75234. +INCLUDED_BY_GRAPH = YES
  75235. +CALL_GRAPH = NO
  75236. +GRAPHICAL_HIERARCHY = YES
  75237. +DOT_IMAGE_FORMAT = png
  75238. +DOT_PATH =
  75239. +DOTFILE_DIRS =
  75240. +MAX_DOT_GRAPH_DEPTH = 1000
  75241. +GENERATE_LEGEND = YES
  75242. +DOT_CLEANUP = YES
  75243. +#---------------------------------------------------------------------------
  75244. +# Configuration::additions related to the search engine
  75245. +#---------------------------------------------------------------------------
  75246. +SEARCHENGINE = NO
  75247. diff -Nur linux-3.18.8/drivers/usb/host/dwc_otg/dummy_audio.c linux-rpi/drivers/usb/host/dwc_otg/dummy_audio.c
  75248. --- linux-3.18.8/drivers/usb/host/dwc_otg/dummy_audio.c 1970-01-01 01:00:00.000000000 +0100
  75249. +++ linux-rpi/drivers/usb/host/dwc_otg/dummy_audio.c 2015-03-05 14:40:16.557715806 +0100
  75250. @@ -0,0 +1,1575 @@
  75251. +/*
  75252. + * zero.c -- Gadget Zero, for USB development
  75253. + *
  75254. + * Copyright (C) 2003-2004 David Brownell
  75255. + * All rights reserved.
  75256. + *
  75257. + * Redistribution and use in source and binary forms, with or without
  75258. + * modification, are permitted provided that the following conditions
  75259. + * are met:
  75260. + * 1. Redistributions of source code must retain the above copyright
  75261. + * notice, this list of conditions, and the following disclaimer,
  75262. + * without modification.
  75263. + * 2. Redistributions in binary form must reproduce the above copyright
  75264. + * notice, this list of conditions and the following disclaimer in the
  75265. + * documentation and/or other materials provided with the distribution.
  75266. + * 3. The names of the above-listed copyright holders may not be used
  75267. + * to endorse or promote products derived from this software without
  75268. + * specific prior written permission.
  75269. + *
  75270. + * ALTERNATIVELY, this software may be distributed under the terms of the
  75271. + * GNU General Public License ("GPL") as published by the Free Software
  75272. + * Foundation, either version 2 of that License or (at your option) any
  75273. + * later version.
  75274. + *
  75275. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  75276. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  75277. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  75278. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  75279. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  75280. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  75281. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  75282. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  75283. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  75284. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  75285. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  75286. + */
  75287. +
  75288. +
  75289. +/*
  75290. + * Gadget Zero only needs two bulk endpoints, and is an example of how you
  75291. + * can write a hardware-agnostic gadget driver running inside a USB device.
  75292. + *
  75293. + * Hardware details are visible (see CONFIG_USB_ZERO_* below) but don't
  75294. + * affect most of the driver.
  75295. + *
  75296. + * Use it with the Linux host/master side "usbtest" driver to get a basic
  75297. + * functional test of your device-side usb stack, or with "usb-skeleton".
  75298. + *
  75299. + * It supports two similar configurations. One sinks whatever the usb host
  75300. + * writes, and in return sources zeroes. The other loops whatever the host
  75301. + * writes back, so the host can read it. Module options include:
  75302. + *
  75303. + * buflen=N default N=4096, buffer size used
  75304. + * qlen=N default N=32, how many buffers in the loopback queue
  75305. + * loopdefault default false, list loopback config first
  75306. + *
  75307. + * Many drivers will only have one configuration, letting them be much
  75308. + * simpler if they also don't support high speed operation (like this
  75309. + * driver does).
  75310. + */
  75311. +
  75312. +#include <linux/config.h>
  75313. +#include <linux/module.h>
  75314. +#include <linux/kernel.h>
  75315. +#include <linux/delay.h>
  75316. +#include <linux/ioport.h>
  75317. +#include <linux/sched.h>
  75318. +#include <linux/slab.h>
  75319. +#include <linux/smp_lock.h>
  75320. +#include <linux/errno.h>
  75321. +#include <linux/init.h>
  75322. +#include <linux/timer.h>
  75323. +#include <linux/list.h>
  75324. +#include <linux/interrupt.h>
  75325. +#include <linux/uts.h>
  75326. +#include <linux/version.h>
  75327. +#include <linux/device.h>
  75328. +#include <linux/moduleparam.h>
  75329. +#include <linux/proc_fs.h>
  75330. +
  75331. +#include <asm/byteorder.h>
  75332. +#include <asm/io.h>
  75333. +#include <asm/irq.h>
  75334. +#include <asm/system.h>
  75335. +#include <asm/unaligned.h>
  75336. +
  75337. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21)
  75338. +# include <linux/usb/ch9.h>
  75339. +#else
  75340. +# include <linux/usb_ch9.h>
  75341. +#endif
  75342. +
  75343. +#include <linux/usb_gadget.h>
  75344. +
  75345. +
  75346. +/*-------------------------------------------------------------------------*/
  75347. +/*-------------------------------------------------------------------------*/
  75348. +
  75349. +
  75350. +static int utf8_to_utf16le(const char *s, u16 *cp, unsigned len)
  75351. +{
  75352. + int count = 0;
  75353. + u8 c;
  75354. + u16 uchar;
  75355. +
  75356. + /* this insists on correct encodings, though not minimal ones.
  75357. + * BUT it currently rejects legit 4-byte UTF-8 code points,
  75358. + * which need surrogate pairs. (Unicode 3.1 can use them.)
  75359. + */
  75360. + while (len != 0 && (c = (u8) *s++) != 0) {
  75361. + if (unlikely(c & 0x80)) {
  75362. + // 2-byte sequence:
  75363. + // 00000yyyyyxxxxxx = 110yyyyy 10xxxxxx
  75364. + if ((c & 0xe0) == 0xc0) {
  75365. + uchar = (c & 0x1f) << 6;
  75366. +
  75367. + c = (u8) *s++;
  75368. + if ((c & 0xc0) != 0xc0)
  75369. + goto fail;
  75370. + c &= 0x3f;
  75371. + uchar |= c;
  75372. +
  75373. + // 3-byte sequence (most CJKV characters):
  75374. + // zzzzyyyyyyxxxxxx = 1110zzzz 10yyyyyy 10xxxxxx
  75375. + } else if ((c & 0xf0) == 0xe0) {
  75376. + uchar = (c & 0x0f) << 12;
  75377. +
  75378. + c = (u8) *s++;
  75379. + if ((c & 0xc0) != 0xc0)
  75380. + goto fail;
  75381. + c &= 0x3f;
  75382. + uchar |= c << 6;
  75383. +
  75384. + c = (u8) *s++;
  75385. + if ((c & 0xc0) != 0xc0)
  75386. + goto fail;
  75387. + c &= 0x3f;
  75388. + uchar |= c;
  75389. +
  75390. + /* no bogus surrogates */
  75391. + if (0xd800 <= uchar && uchar <= 0xdfff)
  75392. + goto fail;
  75393. +
  75394. + // 4-byte sequence (surrogate pairs, currently rare):
  75395. + // 11101110wwwwzzzzyy + 110111yyyyxxxxxx
  75396. + // = 11110uuu 10uuzzzz 10yyyyyy 10xxxxxx
  75397. + // (uuuuu = wwww + 1)
  75398. + // FIXME accept the surrogate code points (only)
  75399. +
  75400. + } else
  75401. + goto fail;
  75402. + } else
  75403. + uchar = c;
  75404. + put_unaligned (cpu_to_le16 (uchar), cp++);
  75405. + count++;
  75406. + len--;
  75407. + }
  75408. + return count;
  75409. +fail:
  75410. + return -1;
  75411. +}
  75412. +
  75413. +
  75414. +/**
  75415. + * usb_gadget_get_string - fill out a string descriptor
  75416. + * @table: of c strings encoded using UTF-8
  75417. + * @id: string id, from low byte of wValue in get string descriptor
  75418. + * @buf: at least 256 bytes
  75419. + *
  75420. + * Finds the UTF-8 string matching the ID, and converts it into a
  75421. + * string descriptor in utf16-le.
  75422. + * Returns length of descriptor (always even) or negative errno
  75423. + *
  75424. + * If your driver needs stings in multiple languages, you'll probably
  75425. + * "switch (wIndex) { ... }" in your ep0 string descriptor logic,
  75426. + * using this routine after choosing which set of UTF-8 strings to use.
  75427. + * Note that US-ASCII is a strict subset of UTF-8; any string bytes with
  75428. + * the eighth bit set will be multibyte UTF-8 characters, not ISO-8859/1
  75429. + * characters (which are also widely used in C strings).
  75430. + */
  75431. +int
  75432. +usb_gadget_get_string (struct usb_gadget_strings *table, int id, u8 *buf)
  75433. +{
  75434. + struct usb_string *s;
  75435. + int len;
  75436. +
  75437. + /* descriptor 0 has the language id */
  75438. + if (id == 0) {
  75439. + buf [0] = 4;
  75440. + buf [1] = USB_DT_STRING;
  75441. + buf [2] = (u8) table->language;
  75442. + buf [3] = (u8) (table->language >> 8);
  75443. + return 4;
  75444. + }
  75445. + for (s = table->strings; s && s->s; s++)
  75446. + if (s->id == id)
  75447. + break;
  75448. +
  75449. + /* unrecognized: stall. */
  75450. + if (!s || !s->s)
  75451. + return -EINVAL;
  75452. +
  75453. + /* string descriptors have length, tag, then UTF16-LE text */
  75454. + len = min ((size_t) 126, strlen (s->s));
  75455. + memset (buf + 2, 0, 2 * len); /* zero all the bytes */
  75456. + len = utf8_to_utf16le(s->s, (u16 *)&buf[2], len);
  75457. + if (len < 0)
  75458. + return -EINVAL;
  75459. + buf [0] = (len + 1) * 2;
  75460. + buf [1] = USB_DT_STRING;
  75461. + return buf [0];
  75462. +}
  75463. +
  75464. +
  75465. +/*-------------------------------------------------------------------------*/
  75466. +/*-------------------------------------------------------------------------*/
  75467. +
  75468. +
  75469. +/**
  75470. + * usb_descriptor_fillbuf - fill buffer with descriptors
  75471. + * @buf: Buffer to be filled
  75472. + * @buflen: Size of buf
  75473. + * @src: Array of descriptor pointers, terminated by null pointer.
  75474. + *
  75475. + * Copies descriptors into the buffer, returning the length or a
  75476. + * negative error code if they can't all be copied. Useful when
  75477. + * assembling descriptors for an associated set of interfaces used
  75478. + * as part of configuring a composite device; or in other cases where
  75479. + * sets of descriptors need to be marshaled.
  75480. + */
  75481. +int
  75482. +usb_descriptor_fillbuf(void *buf, unsigned buflen,
  75483. + const struct usb_descriptor_header **src)
  75484. +{
  75485. + u8 *dest = buf;
  75486. +
  75487. + if (!src)
  75488. + return -EINVAL;
  75489. +
  75490. + /* fill buffer from src[] until null descriptor ptr */
  75491. + for (; 0 != *src; src++) {
  75492. + unsigned len = (*src)->bLength;
  75493. +
  75494. + if (len > buflen)
  75495. + return -EINVAL;
  75496. + memcpy(dest, *src, len);
  75497. + buflen -= len;
  75498. + dest += len;
  75499. + }
  75500. + return dest - (u8 *)buf;
  75501. +}
  75502. +
  75503. +
  75504. +/**
  75505. + * usb_gadget_config_buf - builts a complete configuration descriptor
  75506. + * @config: Header for the descriptor, including characteristics such
  75507. + * as power requirements and number of interfaces.
  75508. + * @desc: Null-terminated vector of pointers to the descriptors (interface,
  75509. + * endpoint, etc) defining all functions in this device configuration.
  75510. + * @buf: Buffer for the resulting configuration descriptor.
  75511. + * @length: Length of buffer. If this is not big enough to hold the
  75512. + * entire configuration descriptor, an error code will be returned.
  75513. + *
  75514. + * This copies descriptors into the response buffer, building a descriptor
  75515. + * for that configuration. It returns the buffer length or a negative
  75516. + * status code. The config.wTotalLength field is set to match the length
  75517. + * of the result, but other descriptor fields (including power usage and
  75518. + * interface count) must be set by the caller.
  75519. + *
  75520. + * Gadget drivers could use this when constructing a config descriptor
  75521. + * in response to USB_REQ_GET_DESCRIPTOR. They will need to patch the
  75522. + * resulting bDescriptorType value if USB_DT_OTHER_SPEED_CONFIG is needed.
  75523. + */
  75524. +int usb_gadget_config_buf(
  75525. + const struct usb_config_descriptor *config,
  75526. + void *buf,
  75527. + unsigned length,
  75528. + const struct usb_descriptor_header **desc
  75529. +)
  75530. +{
  75531. + struct usb_config_descriptor *cp = buf;
  75532. + int len;
  75533. +
  75534. + /* config descriptor first */
  75535. + if (length < USB_DT_CONFIG_SIZE || !desc)
  75536. + return -EINVAL;
  75537. + *cp = *config;
  75538. +
  75539. + /* then interface/endpoint/class/vendor/... */
  75540. + len = usb_descriptor_fillbuf(USB_DT_CONFIG_SIZE + (u8*)buf,
  75541. + length - USB_DT_CONFIG_SIZE, desc);
  75542. + if (len < 0)
  75543. + return len;
  75544. + len += USB_DT_CONFIG_SIZE;
  75545. + if (len > 0xffff)
  75546. + return -EINVAL;
  75547. +
  75548. + /* patch up the config descriptor */
  75549. + cp->bLength = USB_DT_CONFIG_SIZE;
  75550. + cp->bDescriptorType = USB_DT_CONFIG;
  75551. + cp->wTotalLength = cpu_to_le16(len);
  75552. + cp->bmAttributes |= USB_CONFIG_ATT_ONE;
  75553. + return len;
  75554. +}
  75555. +
  75556. +/*-------------------------------------------------------------------------*/
  75557. +/*-------------------------------------------------------------------------*/
  75558. +
  75559. +
  75560. +#define RBUF_LEN (1024*1024)
  75561. +static int rbuf_start;
  75562. +static int rbuf_len;
  75563. +static __u8 rbuf[RBUF_LEN];
  75564. +
  75565. +/*-------------------------------------------------------------------------*/
  75566. +
  75567. +#define DRIVER_VERSION "St Patrick's Day 2004"
  75568. +
  75569. +static const char shortname [] = "zero";
  75570. +static const char longname [] = "YAMAHA YST-MS35D USB Speaker ";
  75571. +
  75572. +static const char source_sink [] = "source and sink data";
  75573. +static const char loopback [] = "loop input to output";
  75574. +
  75575. +/*-------------------------------------------------------------------------*/
  75576. +
  75577. +/*
  75578. + * driver assumes self-powered hardware, and
  75579. + * has no way for users to trigger remote wakeup.
  75580. + *
  75581. + * this version autoconfigures as much as possible,
  75582. + * which is reasonable for most "bulk-only" drivers.
  75583. + */
  75584. +static const char *EP_IN_NAME; /* source */
  75585. +static const char *EP_OUT_NAME; /* sink */
  75586. +
  75587. +/*-------------------------------------------------------------------------*/
  75588. +
  75589. +/* big enough to hold our biggest descriptor */
  75590. +#define USB_BUFSIZ 512
  75591. +
  75592. +struct zero_dev {
  75593. + spinlock_t lock;
  75594. + struct usb_gadget *gadget;
  75595. + struct usb_request *req; /* for control responses */
  75596. +
  75597. + /* when configured, we have one of two configs:
  75598. + * - source data (in to host) and sink it (out from host)
  75599. + * - or loop it back (out from host back in to host)
  75600. + */
  75601. + u8 config;
  75602. + struct usb_ep *in_ep, *out_ep;
  75603. +
  75604. + /* autoresume timer */
  75605. + struct timer_list resume;
  75606. +};
  75607. +
  75608. +#define xprintk(d,level,fmt,args...) \
  75609. + dev_printk(level , &(d)->gadget->dev , fmt , ## args)
  75610. +
  75611. +#ifdef DEBUG
  75612. +#define DBG(dev,fmt,args...) \
  75613. + xprintk(dev , KERN_DEBUG , fmt , ## args)
  75614. +#else
  75615. +#define DBG(dev,fmt,args...) \
  75616. + do { } while (0)
  75617. +#endif /* DEBUG */
  75618. +
  75619. +#ifdef VERBOSE
  75620. +#define VDBG DBG
  75621. +#else
  75622. +#define VDBG(dev,fmt,args...) \
  75623. + do { } while (0)
  75624. +#endif /* VERBOSE */
  75625. +
  75626. +#define ERROR(dev,fmt,args...) \
  75627. + xprintk(dev , KERN_ERR , fmt , ## args)
  75628. +#define WARN(dev,fmt,args...) \
  75629. + xprintk(dev , KERN_WARNING , fmt , ## args)
  75630. +#define INFO(dev,fmt,args...) \
  75631. + xprintk(dev , KERN_INFO , fmt , ## args)
  75632. +
  75633. +/*-------------------------------------------------------------------------*/
  75634. +
  75635. +static unsigned buflen = 4096;
  75636. +static unsigned qlen = 32;
  75637. +static unsigned pattern = 0;
  75638. +
  75639. +module_param (buflen, uint, S_IRUGO|S_IWUSR);
  75640. +module_param (qlen, uint, S_IRUGO|S_IWUSR);
  75641. +module_param (pattern, uint, S_IRUGO|S_IWUSR);
  75642. +
  75643. +/*
  75644. + * if it's nonzero, autoresume says how many seconds to wait
  75645. + * before trying to wake up the host after suspend.
  75646. + */
  75647. +static unsigned autoresume = 0;
  75648. +module_param (autoresume, uint, 0);
  75649. +
  75650. +/*
  75651. + * Normally the "loopback" configuration is second (index 1) so
  75652. + * it's not the default. Here's where to change that order, to
  75653. + * work better with hosts where config changes are problematic.
  75654. + * Or controllers (like superh) that only support one config.
  75655. + */
  75656. +static int loopdefault = 0;
  75657. +
  75658. +module_param (loopdefault, bool, S_IRUGO|S_IWUSR);
  75659. +
  75660. +/*-------------------------------------------------------------------------*/
  75661. +
  75662. +/* Thanks to NetChip Technologies for donating this product ID.
  75663. + *
  75664. + * DO NOT REUSE THESE IDs with a protocol-incompatible driver!! Ever!!
  75665. + * Instead: allocate your own, using normal USB-IF procedures.
  75666. + */
  75667. +#ifndef CONFIG_USB_ZERO_HNPTEST
  75668. +#define DRIVER_VENDOR_NUM 0x0525 /* NetChip */
  75669. +#define DRIVER_PRODUCT_NUM 0xa4a0 /* Linux-USB "Gadget Zero" */
  75670. +#else
  75671. +#define DRIVER_VENDOR_NUM 0x1a0a /* OTG test device IDs */
  75672. +#define DRIVER_PRODUCT_NUM 0xbadd
  75673. +#endif
  75674. +
  75675. +/*-------------------------------------------------------------------------*/
  75676. +
  75677. +/*
  75678. + * DESCRIPTORS ... most are static, but strings and (full)
  75679. + * configuration descriptors are built on demand.
  75680. + */
  75681. +
  75682. +/*
  75683. +#define STRING_MANUFACTURER 25
  75684. +#define STRING_PRODUCT 42
  75685. +#define STRING_SERIAL 101
  75686. +*/
  75687. +#define STRING_MANUFACTURER 1
  75688. +#define STRING_PRODUCT 2
  75689. +#define STRING_SERIAL 3
  75690. +
  75691. +#define STRING_SOURCE_SINK 250
  75692. +#define STRING_LOOPBACK 251
  75693. +
  75694. +/*
  75695. + * This device advertises two configurations; these numbers work
  75696. + * on a pxa250 as well as more flexible hardware.
  75697. + */
  75698. +#define CONFIG_SOURCE_SINK 3
  75699. +#define CONFIG_LOOPBACK 2
  75700. +
  75701. +/*
  75702. +static struct usb_device_descriptor
  75703. +device_desc = {
  75704. + .bLength = sizeof device_desc,
  75705. + .bDescriptorType = USB_DT_DEVICE,
  75706. +
  75707. + .bcdUSB = __constant_cpu_to_le16 (0x0200),
  75708. + .bDeviceClass = USB_CLASS_VENDOR_SPEC,
  75709. +
  75710. + .idVendor = __constant_cpu_to_le16 (DRIVER_VENDOR_NUM),
  75711. + .idProduct = __constant_cpu_to_le16 (DRIVER_PRODUCT_NUM),
  75712. + .iManufacturer = STRING_MANUFACTURER,
  75713. + .iProduct = STRING_PRODUCT,
  75714. + .iSerialNumber = STRING_SERIAL,
  75715. + .bNumConfigurations = 2,
  75716. +};
  75717. +*/
  75718. +static struct usb_device_descriptor
  75719. +device_desc = {
  75720. + .bLength = sizeof device_desc,
  75721. + .bDescriptorType = USB_DT_DEVICE,
  75722. + .bcdUSB = __constant_cpu_to_le16 (0x0100),
  75723. + .bDeviceClass = USB_CLASS_PER_INTERFACE,
  75724. + .bDeviceSubClass = 0,
  75725. + .bDeviceProtocol = 0,
  75726. + .bMaxPacketSize0 = 64,
  75727. + .bcdDevice = __constant_cpu_to_le16 (0x0100),
  75728. + .idVendor = __constant_cpu_to_le16 (0x0499),
  75729. + .idProduct = __constant_cpu_to_le16 (0x3002),
  75730. + .iManufacturer = STRING_MANUFACTURER,
  75731. + .iProduct = STRING_PRODUCT,
  75732. + .iSerialNumber = STRING_SERIAL,
  75733. + .bNumConfigurations = 1,
  75734. +};
  75735. +
  75736. +static struct usb_config_descriptor
  75737. +z_config = {
  75738. + .bLength = sizeof z_config,
  75739. + .bDescriptorType = USB_DT_CONFIG,
  75740. +
  75741. + /* compute wTotalLength on the fly */
  75742. + .bNumInterfaces = 2,
  75743. + .bConfigurationValue = 1,
  75744. + .iConfiguration = 0,
  75745. + .bmAttributes = 0x40,
  75746. + .bMaxPower = 0, /* self-powered */
  75747. +};
  75748. +
  75749. +
  75750. +static struct usb_otg_descriptor
  75751. +otg_descriptor = {
  75752. + .bLength = sizeof otg_descriptor,
  75753. + .bDescriptorType = USB_DT_OTG,
  75754. +
  75755. + .bmAttributes = USB_OTG_SRP,
  75756. +};
  75757. +
  75758. +/* one interface in each configuration */
  75759. +#ifdef CONFIG_USB_GADGET_DUALSPEED
  75760. +
  75761. +/*
  75762. + * usb 2.0 devices need to expose both high speed and full speed
  75763. + * descriptors, unless they only run at full speed.
  75764. + *
  75765. + * that means alternate endpoint descriptors (bigger packets)
  75766. + * and a "device qualifier" ... plus more construction options
  75767. + * for the config descriptor.
  75768. + */
  75769. +
  75770. +static struct usb_qualifier_descriptor
  75771. +dev_qualifier = {
  75772. + .bLength = sizeof dev_qualifier,
  75773. + .bDescriptorType = USB_DT_DEVICE_QUALIFIER,
  75774. +
  75775. + .bcdUSB = __constant_cpu_to_le16 (0x0200),
  75776. + .bDeviceClass = USB_CLASS_VENDOR_SPEC,
  75777. +
  75778. + .bNumConfigurations = 2,
  75779. +};
  75780. +
  75781. +
  75782. +struct usb_cs_as_general_descriptor {
  75783. + __u8 bLength;
  75784. + __u8 bDescriptorType;
  75785. +
  75786. + __u8 bDescriptorSubType;
  75787. + __u8 bTerminalLink;
  75788. + __u8 bDelay;
  75789. + __u16 wFormatTag;
  75790. +} __attribute__ ((packed));
  75791. +
  75792. +struct usb_cs_as_format_descriptor {
  75793. + __u8 bLength;
  75794. + __u8 bDescriptorType;
  75795. +
  75796. + __u8 bDescriptorSubType;
  75797. + __u8 bFormatType;
  75798. + __u8 bNrChannels;
  75799. + __u8 bSubframeSize;
  75800. + __u8 bBitResolution;
  75801. + __u8 bSamfreqType;
  75802. + __u8 tLowerSamFreq[3];
  75803. + __u8 tUpperSamFreq[3];
  75804. +} __attribute__ ((packed));
  75805. +
  75806. +static const struct usb_interface_descriptor
  75807. +z_audio_control_if_desc = {
  75808. + .bLength = sizeof z_audio_control_if_desc,
  75809. + .bDescriptorType = USB_DT_INTERFACE,
  75810. + .bInterfaceNumber = 0,
  75811. + .bAlternateSetting = 0,
  75812. + .bNumEndpoints = 0,
  75813. + .bInterfaceClass = USB_CLASS_AUDIO,
  75814. + .bInterfaceSubClass = 0x1,
  75815. + .bInterfaceProtocol = 0,
  75816. + .iInterface = 0,
  75817. +};
  75818. +
  75819. +static const struct usb_interface_descriptor
  75820. +z_audio_if_desc = {
  75821. + .bLength = sizeof z_audio_if_desc,
  75822. + .bDescriptorType = USB_DT_INTERFACE,
  75823. + .bInterfaceNumber = 1,
  75824. + .bAlternateSetting = 0,
  75825. + .bNumEndpoints = 0,
  75826. + .bInterfaceClass = USB_CLASS_AUDIO,
  75827. + .bInterfaceSubClass = 0x2,
  75828. + .bInterfaceProtocol = 0,
  75829. + .iInterface = 0,
  75830. +};
  75831. +
  75832. +static const struct usb_interface_descriptor
  75833. +z_audio_if_desc2 = {
  75834. + .bLength = sizeof z_audio_if_desc,
  75835. + .bDescriptorType = USB_DT_INTERFACE,
  75836. + .bInterfaceNumber = 1,
  75837. + .bAlternateSetting = 1,
  75838. + .bNumEndpoints = 1,
  75839. + .bInterfaceClass = USB_CLASS_AUDIO,
  75840. + .bInterfaceSubClass = 0x2,
  75841. + .bInterfaceProtocol = 0,
  75842. + .iInterface = 0,
  75843. +};
  75844. +
  75845. +static const struct usb_cs_as_general_descriptor
  75846. +z_audio_cs_as_if_desc = {
  75847. + .bLength = 7,
  75848. + .bDescriptorType = 0x24,
  75849. +
  75850. + .bDescriptorSubType = 0x01,
  75851. + .bTerminalLink = 0x01,
  75852. + .bDelay = 0x0,
  75853. + .wFormatTag = __constant_cpu_to_le16 (0x0001)
  75854. +};
  75855. +
  75856. +
  75857. +static const struct usb_cs_as_format_descriptor
  75858. +z_audio_cs_as_format_desc = {
  75859. + .bLength = 0xe,
  75860. + .bDescriptorType = 0x24,
  75861. +
  75862. + .bDescriptorSubType = 2,
  75863. + .bFormatType = 1,
  75864. + .bNrChannels = 1,
  75865. + .bSubframeSize = 1,
  75866. + .bBitResolution = 8,
  75867. + .bSamfreqType = 0,
  75868. + .tLowerSamFreq = {0x7e, 0x13, 0x00},
  75869. + .tUpperSamFreq = {0xe2, 0xd6, 0x00},
  75870. +};
  75871. +
  75872. +static const struct usb_endpoint_descriptor
  75873. +z_iso_ep = {
  75874. + .bLength = 0x09,
  75875. + .bDescriptorType = 0x05,
  75876. + .bEndpointAddress = 0x04,
  75877. + .bmAttributes = 0x09,
  75878. + .wMaxPacketSize = 0x0038,
  75879. + .bInterval = 0x01,
  75880. + .bRefresh = 0x00,
  75881. + .bSynchAddress = 0x00,
  75882. +};
  75883. +
  75884. +static char z_iso_ep2[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
  75885. +
  75886. +// 9 bytes
  75887. +static char z_ac_interface_header_desc[] =
  75888. +{ 0x09, 0x24, 0x01, 0x00, 0x01, 0x2b, 0x00, 0x01, 0x01 };
  75889. +
  75890. +// 12 bytes
  75891. +static char z_0[] = {0x0c, 0x24, 0x02, 0x01, 0x01, 0x01, 0x00, 0x02,
  75892. + 0x03, 0x00, 0x00, 0x00};
  75893. +// 13 bytes
  75894. +static char z_1[] = {0x0d, 0x24, 0x06, 0x02, 0x01, 0x02, 0x15, 0x00,
  75895. + 0x02, 0x00, 0x02, 0x00, 0x00};
  75896. +// 9 bytes
  75897. +static char z_2[] = {0x09, 0x24, 0x03, 0x03, 0x01, 0x03, 0x00, 0x02,
  75898. + 0x00};
  75899. +
  75900. +static char za_0[] = {0x09, 0x04, 0x01, 0x02, 0x01, 0x01, 0x02, 0x00,
  75901. + 0x00};
  75902. +
  75903. +static char za_1[] = {0x07, 0x24, 0x01, 0x01, 0x00, 0x01, 0x00};
  75904. +
  75905. +static char za_2[] = {0x0e, 0x24, 0x02, 0x01, 0x02, 0x01, 0x08, 0x00,
  75906. + 0x7e, 0x13, 0x00, 0xe2, 0xd6, 0x00};
  75907. +
  75908. +static char za_3[] = {0x09, 0x05, 0x04, 0x09, 0x70, 0x00, 0x01, 0x00,
  75909. + 0x00};
  75910. +
  75911. +static char za_4[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
  75912. +
  75913. +static char za_5[] = {0x09, 0x04, 0x01, 0x03, 0x01, 0x01, 0x02, 0x00,
  75914. + 0x00};
  75915. +
  75916. +static char za_6[] = {0x07, 0x24, 0x01, 0x01, 0x00, 0x01, 0x00};
  75917. +
  75918. +static char za_7[] = {0x0e, 0x24, 0x02, 0x01, 0x01, 0x02, 0x10, 0x00,
  75919. + 0x7e, 0x13, 0x00, 0xe2, 0xd6, 0x00};
  75920. +
  75921. +static char za_8[] = {0x09, 0x05, 0x04, 0x09, 0x70, 0x00, 0x01, 0x00,
  75922. + 0x00};
  75923. +
  75924. +static char za_9[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
  75925. +
  75926. +static char za_10[] = {0x09, 0x04, 0x01, 0x04, 0x01, 0x01, 0x02, 0x00,
  75927. + 0x00};
  75928. +
  75929. +static char za_11[] = {0x07, 0x24, 0x01, 0x01, 0x00, 0x01, 0x00};
  75930. +
  75931. +static char za_12[] = {0x0e, 0x24, 0x02, 0x01, 0x02, 0x02, 0x10, 0x00,
  75932. + 0x73, 0x13, 0x00, 0xe2, 0xd6, 0x00};
  75933. +
  75934. +static char za_13[] = {0x09, 0x05, 0x04, 0x09, 0xe0, 0x00, 0x01, 0x00,
  75935. + 0x00};
  75936. +
  75937. +static char za_14[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
  75938. +
  75939. +static char za_15[] = {0x09, 0x04, 0x01, 0x05, 0x01, 0x01, 0x02, 0x00,
  75940. + 0x00};
  75941. +
  75942. +static char za_16[] = {0x07, 0x24, 0x01, 0x01, 0x00, 0x01, 0x00};
  75943. +
  75944. +static char za_17[] = {0x0e, 0x24, 0x02, 0x01, 0x01, 0x03, 0x14, 0x00,
  75945. + 0x7e, 0x13, 0x00, 0xe2, 0xd6, 0x00};
  75946. +
  75947. +static char za_18[] = {0x09, 0x05, 0x04, 0x09, 0xa8, 0x00, 0x01, 0x00,
  75948. + 0x00};
  75949. +
  75950. +static char za_19[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
  75951. +
  75952. +static char za_20[] = {0x09, 0x04, 0x01, 0x06, 0x01, 0x01, 0x02, 0x00,
  75953. + 0x00};
  75954. +
  75955. +static char za_21[] = {0x07, 0x24, 0x01, 0x01, 0x00, 0x01, 0x00};
  75956. +
  75957. +static char za_22[] = {0x0e, 0x24, 0x02, 0x01, 0x02, 0x03, 0x14, 0x00,
  75958. + 0x7e, 0x13, 0x00, 0xe2, 0xd6, 0x00};
  75959. +
  75960. +static char za_23[] = {0x09, 0x05, 0x04, 0x09, 0x50, 0x01, 0x01, 0x00,
  75961. + 0x00};
  75962. +
  75963. +static char za_24[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
  75964. +
  75965. +
  75966. +
  75967. +static const struct usb_descriptor_header *z_function [] = {
  75968. + (struct usb_descriptor_header *) &z_audio_control_if_desc,
  75969. + (struct usb_descriptor_header *) &z_ac_interface_header_desc,
  75970. + (struct usb_descriptor_header *) &z_0,
  75971. + (struct usb_descriptor_header *) &z_1,
  75972. + (struct usb_descriptor_header *) &z_2,
  75973. + (struct usb_descriptor_header *) &z_audio_if_desc,
  75974. + (struct usb_descriptor_header *) &z_audio_if_desc2,
  75975. + (struct usb_descriptor_header *) &z_audio_cs_as_if_desc,
  75976. + (struct usb_descriptor_header *) &z_audio_cs_as_format_desc,
  75977. + (struct usb_descriptor_header *) &z_iso_ep,
  75978. + (struct usb_descriptor_header *) &z_iso_ep2,
  75979. + (struct usb_descriptor_header *) &za_0,
  75980. + (struct usb_descriptor_header *) &za_1,
  75981. + (struct usb_descriptor_header *) &za_2,
  75982. + (struct usb_descriptor_header *) &za_3,
  75983. + (struct usb_descriptor_header *) &za_4,
  75984. + (struct usb_descriptor_header *) &za_5,
  75985. + (struct usb_descriptor_header *) &za_6,
  75986. + (struct usb_descriptor_header *) &za_7,
  75987. + (struct usb_descriptor_header *) &za_8,
  75988. + (struct usb_descriptor_header *) &za_9,
  75989. + (struct usb_descriptor_header *) &za_10,
  75990. + (struct usb_descriptor_header *) &za_11,
  75991. + (struct usb_descriptor_header *) &za_12,
  75992. + (struct usb_descriptor_header *) &za_13,
  75993. + (struct usb_descriptor_header *) &za_14,
  75994. + (struct usb_descriptor_header *) &za_15,
  75995. + (struct usb_descriptor_header *) &za_16,
  75996. + (struct usb_descriptor_header *) &za_17,
  75997. + (struct usb_descriptor_header *) &za_18,
  75998. + (struct usb_descriptor_header *) &za_19,
  75999. + (struct usb_descriptor_header *) &za_20,
  76000. + (struct usb_descriptor_header *) &za_21,
  76001. + (struct usb_descriptor_header *) &za_22,
  76002. + (struct usb_descriptor_header *) &za_23,
  76003. + (struct usb_descriptor_header *) &za_24,
  76004. + NULL,
  76005. +};
  76006. +
  76007. +/* maxpacket and other transfer characteristics vary by speed. */
  76008. +#define ep_desc(g,hs,fs) (((g)->speed==USB_SPEED_HIGH)?(hs):(fs))
  76009. +
  76010. +#else
  76011. +
  76012. +/* if there's no high speed support, maxpacket doesn't change. */
  76013. +#define ep_desc(g,hs,fs) fs
  76014. +
  76015. +#endif /* !CONFIG_USB_GADGET_DUALSPEED */
  76016. +
  76017. +static char manufacturer [40];
  76018. +//static char serial [40];
  76019. +static char serial [] = "Ser 00 em";
  76020. +
  76021. +/* static strings, in UTF-8 */
  76022. +static struct usb_string strings [] = {
  76023. + { STRING_MANUFACTURER, manufacturer, },
  76024. + { STRING_PRODUCT, longname, },
  76025. + { STRING_SERIAL, serial, },
  76026. + { STRING_LOOPBACK, loopback, },
  76027. + { STRING_SOURCE_SINK, source_sink, },
  76028. + { } /* end of list */
  76029. +};
  76030. +
  76031. +static struct usb_gadget_strings stringtab = {
  76032. + .language = 0x0409, /* en-us */
  76033. + .strings = strings,
  76034. +};
  76035. +
  76036. +/*
  76037. + * config descriptors are also handcrafted. these must agree with code
  76038. + * that sets configurations, and with code managing interfaces and their
  76039. + * altsettings. other complexity may come from:
  76040. + *
  76041. + * - high speed support, including "other speed config" rules
  76042. + * - multiple configurations
  76043. + * - interfaces with alternate settings
  76044. + * - embedded class or vendor-specific descriptors
  76045. + *
  76046. + * this handles high speed, and has a second config that could as easily
  76047. + * have been an alternate interface setting (on most hardware).
  76048. + *
  76049. + * NOTE: to demonstrate (and test) more USB capabilities, this driver
  76050. + * should include an altsetting to test interrupt transfers, including
  76051. + * high bandwidth modes at high speed. (Maybe work like Intel's test
  76052. + * device?)
  76053. + */
  76054. +static int
  76055. +config_buf (struct usb_gadget *gadget, u8 *buf, u8 type, unsigned index)
  76056. +{
  76057. + int len;
  76058. + const struct usb_descriptor_header **function;
  76059. +
  76060. + function = z_function;
  76061. + len = usb_gadget_config_buf (&z_config, buf, USB_BUFSIZ, function);
  76062. + if (len < 0)
  76063. + return len;
  76064. + ((struct usb_config_descriptor *) buf)->bDescriptorType = type;
  76065. + return len;
  76066. +}
  76067. +
  76068. +/*-------------------------------------------------------------------------*/
  76069. +
  76070. +static struct usb_request *
  76071. +alloc_ep_req (struct usb_ep *ep, unsigned length)
  76072. +{
  76073. + struct usb_request *req;
  76074. +
  76075. + req = usb_ep_alloc_request (ep, GFP_ATOMIC);
  76076. + if (req) {
  76077. + req->length = length;
  76078. + req->buf = usb_ep_alloc_buffer (ep, length,
  76079. + &req->dma, GFP_ATOMIC);
  76080. + if (!req->buf) {
  76081. + usb_ep_free_request (ep, req);
  76082. + req = NULL;
  76083. + }
  76084. + }
  76085. + return req;
  76086. +}
  76087. +
  76088. +static void free_ep_req (struct usb_ep *ep, struct usb_request *req)
  76089. +{
  76090. + if (req->buf)
  76091. + usb_ep_free_buffer (ep, req->buf, req->dma, req->length);
  76092. + usb_ep_free_request (ep, req);
  76093. +}
  76094. +
  76095. +/*-------------------------------------------------------------------------*/
  76096. +
  76097. +/* optionally require specific source/sink data patterns */
  76098. +
  76099. +static int
  76100. +check_read_data (
  76101. + struct zero_dev *dev,
  76102. + struct usb_ep *ep,
  76103. + struct usb_request *req
  76104. +)
  76105. +{
  76106. + unsigned i;
  76107. + u8 *buf = req->buf;
  76108. +
  76109. + for (i = 0; i < req->actual; i++, buf++) {
  76110. + switch (pattern) {
  76111. + /* all-zeroes has no synchronization issues */
  76112. + case 0:
  76113. + if (*buf == 0)
  76114. + continue;
  76115. + break;
  76116. + /* mod63 stays in sync with short-terminated transfers,
  76117. + * or otherwise when host and gadget agree on how large
  76118. + * each usb transfer request should be. resync is done
  76119. + * with set_interface or set_config.
  76120. + */
  76121. + case 1:
  76122. + if (*buf == (u8)(i % 63))
  76123. + continue;
  76124. + break;
  76125. + }
  76126. + ERROR (dev, "bad OUT byte, buf [%d] = %d\n", i, *buf);
  76127. + usb_ep_set_halt (ep);
  76128. + return -EINVAL;
  76129. + }
  76130. + return 0;
  76131. +}
  76132. +
  76133. +/*-------------------------------------------------------------------------*/
  76134. +
  76135. +static void zero_reset_config (struct zero_dev *dev)
  76136. +{
  76137. + if (dev->config == 0)
  76138. + return;
  76139. +
  76140. + DBG (dev, "reset config\n");
  76141. +
  76142. + /* just disable endpoints, forcing completion of pending i/o.
  76143. + * all our completion handlers free their requests in this case.
  76144. + */
  76145. + if (dev->in_ep) {
  76146. + usb_ep_disable (dev->in_ep);
  76147. + dev->in_ep = NULL;
  76148. + }
  76149. + if (dev->out_ep) {
  76150. + usb_ep_disable (dev->out_ep);
  76151. + dev->out_ep = NULL;
  76152. + }
  76153. + dev->config = 0;
  76154. + del_timer (&dev->resume);
  76155. +}
  76156. +
  76157. +#define _write(f, buf, sz) (f->f_op->write(f, buf, sz, &f->f_pos))
  76158. +
  76159. +static void
  76160. +zero_isoc_complete (struct usb_ep *ep, struct usb_request *req)
  76161. +{
  76162. + struct zero_dev *dev = ep->driver_data;
  76163. + int status = req->status;
  76164. + int i, j;
  76165. +
  76166. + switch (status) {
  76167. +
  76168. + case 0: /* normal completion? */
  76169. + //printk ("\nzero ---------------> isoc normal completion %d bytes\n", req->actual);
  76170. + for (i=0, j=rbuf_start; i<req->actual; i++) {
  76171. + //printk ("%02x ", ((__u8*)req->buf)[i]);
  76172. + rbuf[j] = ((__u8*)req->buf)[i];
  76173. + j++;
  76174. + if (j >= RBUF_LEN) j=0;
  76175. + }
  76176. + rbuf_start = j;
  76177. + //printk ("\n\n");
  76178. +
  76179. + if (rbuf_len < RBUF_LEN) {
  76180. + rbuf_len += req->actual;
  76181. + if (rbuf_len > RBUF_LEN) {
  76182. + rbuf_len = RBUF_LEN;
  76183. + }
  76184. + }
  76185. +
  76186. + break;
  76187. +
  76188. + /* this endpoint is normally active while we're configured */
  76189. + case -ECONNABORTED: /* hardware forced ep reset */
  76190. + case -ECONNRESET: /* request dequeued */
  76191. + case -ESHUTDOWN: /* disconnect from host */
  76192. + VDBG (dev, "%s gone (%d), %d/%d\n", ep->name, status,
  76193. + req->actual, req->length);
  76194. + if (ep == dev->out_ep)
  76195. + check_read_data (dev, ep, req);
  76196. + free_ep_req (ep, req);
  76197. + return;
  76198. +
  76199. + case -EOVERFLOW: /* buffer overrun on read means that
  76200. + * we didn't provide a big enough
  76201. + * buffer.
  76202. + */
  76203. + default:
  76204. +#if 1
  76205. + DBG (dev, "%s complete --> %d, %d/%d\n", ep->name,
  76206. + status, req->actual, req->length);
  76207. +#endif
  76208. + case -EREMOTEIO: /* short read */
  76209. + break;
  76210. + }
  76211. +
  76212. + status = usb_ep_queue (ep, req, GFP_ATOMIC);
  76213. + if (status) {
  76214. + ERROR (dev, "kill %s: resubmit %d bytes --> %d\n",
  76215. + ep->name, req->length, status);
  76216. + usb_ep_set_halt (ep);
  76217. + /* FIXME recover later ... somehow */
  76218. + }
  76219. +}
  76220. +
  76221. +static struct usb_request *
  76222. +zero_start_isoc_ep (struct usb_ep *ep, int gfp_flags)
  76223. +{
  76224. + struct usb_request *req;
  76225. + int status;
  76226. +
  76227. + req = alloc_ep_req (ep, 512);
  76228. + if (!req)
  76229. + return NULL;
  76230. +
  76231. + req->complete = zero_isoc_complete;
  76232. +
  76233. + status = usb_ep_queue (ep, req, gfp_flags);
  76234. + if (status) {
  76235. + struct zero_dev *dev = ep->driver_data;
  76236. +
  76237. + ERROR (dev, "start %s --> %d\n", ep->name, status);
  76238. + free_ep_req (ep, req);
  76239. + req = NULL;
  76240. + }
  76241. +
  76242. + return req;
  76243. +}
  76244. +
  76245. +/* change our operational config. this code must agree with the code
  76246. + * that returns config descriptors, and altsetting code.
  76247. + *
  76248. + * it's also responsible for power management interactions. some
  76249. + * configurations might not work with our current power sources.
  76250. + *
  76251. + * note that some device controller hardware will constrain what this
  76252. + * code can do, perhaps by disallowing more than one configuration or
  76253. + * by limiting configuration choices (like the pxa2xx).
  76254. + */
  76255. +static int
  76256. +zero_set_config (struct zero_dev *dev, unsigned number, int gfp_flags)
  76257. +{
  76258. + int result = 0;
  76259. + struct usb_gadget *gadget = dev->gadget;
  76260. + const struct usb_endpoint_descriptor *d;
  76261. + struct usb_ep *ep;
  76262. +
  76263. + if (number == dev->config)
  76264. + return 0;
  76265. +
  76266. + zero_reset_config (dev);
  76267. +
  76268. + gadget_for_each_ep (ep, gadget) {
  76269. +
  76270. + if (strcmp (ep->name, "ep4") == 0) {
  76271. +
  76272. + d = (struct usb_endpoint_descripter *)&za_23; // isoc ep desc for audio i/f alt setting 6
  76273. + result = usb_ep_enable (ep, d);
  76274. +
  76275. + if (result == 0) {
  76276. + ep->driver_data = dev;
  76277. + dev->in_ep = ep;
  76278. +
  76279. + if (zero_start_isoc_ep (ep, gfp_flags) != 0) {
  76280. +
  76281. + dev->in_ep = ep;
  76282. + continue;
  76283. + }
  76284. +
  76285. + usb_ep_disable (ep);
  76286. + result = -EIO;
  76287. + }
  76288. + }
  76289. +
  76290. + }
  76291. +
  76292. + dev->config = number;
  76293. + return result;
  76294. +}
  76295. +
  76296. +/*-------------------------------------------------------------------------*/
  76297. +
  76298. +static void zero_setup_complete (struct usb_ep *ep, struct usb_request *req)
  76299. +{
  76300. + if (req->status || req->actual != req->length)
  76301. + DBG ((struct zero_dev *) ep->driver_data,
  76302. + "setup complete --> %d, %d/%d\n",
  76303. + req->status, req->actual, req->length);
  76304. +}
  76305. +
  76306. +/*
  76307. + * The setup() callback implements all the ep0 functionality that's
  76308. + * not handled lower down, in hardware or the hardware driver (like
  76309. + * device and endpoint feature flags, and their status). It's all
  76310. + * housekeeping for the gadget function we're implementing. Most of
  76311. + * the work is in config-specific setup.
  76312. + */
  76313. +static int
  76314. +zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
  76315. +{
  76316. + struct zero_dev *dev = get_gadget_data (gadget);
  76317. + struct usb_request *req = dev->req;
  76318. + int value = -EOPNOTSUPP;
  76319. +
  76320. + /* usually this stores reply data in the pre-allocated ep0 buffer,
  76321. + * but config change events will reconfigure hardware.
  76322. + */
  76323. + req->zero = 0;
  76324. + switch (ctrl->bRequest) {
  76325. +
  76326. + case USB_REQ_GET_DESCRIPTOR:
  76327. +
  76328. + switch (ctrl->wValue >> 8) {
  76329. +
  76330. + case USB_DT_DEVICE:
  76331. + value = min (ctrl->wLength, (u16) sizeof device_desc);
  76332. + memcpy (req->buf, &device_desc, value);
  76333. + break;
  76334. +#ifdef CONFIG_USB_GADGET_DUALSPEED
  76335. + case USB_DT_DEVICE_QUALIFIER:
  76336. + if (!gadget->is_dualspeed)
  76337. + break;
  76338. + value = min (ctrl->wLength, (u16) sizeof dev_qualifier);
  76339. + memcpy (req->buf, &dev_qualifier, value);
  76340. + break;
  76341. +
  76342. + case USB_DT_OTHER_SPEED_CONFIG:
  76343. + if (!gadget->is_dualspeed)
  76344. + break;
  76345. + // FALLTHROUGH
  76346. +#endif /* CONFIG_USB_GADGET_DUALSPEED */
  76347. + case USB_DT_CONFIG:
  76348. + value = config_buf (gadget, req->buf,
  76349. + ctrl->wValue >> 8,
  76350. + ctrl->wValue & 0xff);
  76351. + if (value >= 0)
  76352. + value = min (ctrl->wLength, (u16) value);
  76353. + break;
  76354. +
  76355. + case USB_DT_STRING:
  76356. + /* wIndex == language code.
  76357. + * this driver only handles one language, you can
  76358. + * add string tables for other languages, using
  76359. + * any UTF-8 characters
  76360. + */
  76361. + value = usb_gadget_get_string (&stringtab,
  76362. + ctrl->wValue & 0xff, req->buf);
  76363. + if (value >= 0) {
  76364. + value = min (ctrl->wLength, (u16) value);
  76365. + }
  76366. + break;
  76367. + }
  76368. + break;
  76369. +
  76370. + /* currently two configs, two speeds */
  76371. + case USB_REQ_SET_CONFIGURATION:
  76372. + if (ctrl->bRequestType != 0)
  76373. + goto unknown;
  76374. +
  76375. + spin_lock (&dev->lock);
  76376. + value = zero_set_config (dev, ctrl->wValue, GFP_ATOMIC);
  76377. + spin_unlock (&dev->lock);
  76378. + break;
  76379. + case USB_REQ_GET_CONFIGURATION:
  76380. + if (ctrl->bRequestType != USB_DIR_IN)
  76381. + goto unknown;
  76382. + *(u8 *)req->buf = dev->config;
  76383. + value = min (ctrl->wLength, (u16) 1);
  76384. + break;
  76385. +
  76386. + /* until we add altsetting support, or other interfaces,
  76387. + * only 0/0 are possible. pxa2xx only supports 0/0 (poorly)
  76388. + * and already killed pending endpoint I/O.
  76389. + */
  76390. + case USB_REQ_SET_INTERFACE:
  76391. +
  76392. + if (ctrl->bRequestType != USB_RECIP_INTERFACE)
  76393. + goto unknown;
  76394. + spin_lock (&dev->lock);
  76395. + if (dev->config) {
  76396. + u8 config = dev->config;
  76397. +
  76398. + /* resets interface configuration, forgets about
  76399. + * previous transaction state (queued bufs, etc)
  76400. + * and re-inits endpoint state (toggle etc)
  76401. + * no response queued, just zero status == success.
  76402. + * if we had more than one interface we couldn't
  76403. + * use this "reset the config" shortcut.
  76404. + */
  76405. + zero_reset_config (dev);
  76406. + zero_set_config (dev, config, GFP_ATOMIC);
  76407. + value = 0;
  76408. + }
  76409. + spin_unlock (&dev->lock);
  76410. + break;
  76411. + case USB_REQ_GET_INTERFACE:
  76412. + if ((ctrl->bRequestType == 0x21) && (ctrl->wIndex == 0x02)) {
  76413. + value = ctrl->wLength;
  76414. + break;
  76415. + }
  76416. + else {
  76417. + if (ctrl->bRequestType != (USB_DIR_IN|USB_RECIP_INTERFACE))
  76418. + goto unknown;
  76419. + if (!dev->config)
  76420. + break;
  76421. + if (ctrl->wIndex != 0) {
  76422. + value = -EDOM;
  76423. + break;
  76424. + }
  76425. + *(u8 *)req->buf = 0;
  76426. + value = min (ctrl->wLength, (u16) 1);
  76427. + }
  76428. + break;
  76429. +
  76430. + /*
  76431. + * These are the same vendor-specific requests supported by
  76432. + * Intel's USB 2.0 compliance test devices. We exceed that
  76433. + * device spec by allowing multiple-packet requests.
  76434. + */
  76435. + case 0x5b: /* control WRITE test -- fill the buffer */
  76436. + if (ctrl->bRequestType != (USB_DIR_OUT|USB_TYPE_VENDOR))
  76437. + goto unknown;
  76438. + if (ctrl->wValue || ctrl->wIndex)
  76439. + break;
  76440. + /* just read that many bytes into the buffer */
  76441. + if (ctrl->wLength > USB_BUFSIZ)
  76442. + break;
  76443. + value = ctrl->wLength;
  76444. + break;
  76445. + case 0x5c: /* control READ test -- return the buffer */
  76446. + if (ctrl->bRequestType != (USB_DIR_IN|USB_TYPE_VENDOR))
  76447. + goto unknown;
  76448. + if (ctrl->wValue || ctrl->wIndex)
  76449. + break;
  76450. + /* expect those bytes are still in the buffer; send back */
  76451. + if (ctrl->wLength > USB_BUFSIZ
  76452. + || ctrl->wLength != req->length)
  76453. + break;
  76454. + value = ctrl->wLength;
  76455. + break;
  76456. +
  76457. + case 0x01: // SET_CUR
  76458. + case 0x02:
  76459. + case 0x03:
  76460. + case 0x04:
  76461. + case 0x05:
  76462. + value = ctrl->wLength;
  76463. + break;
  76464. + case 0x81:
  76465. + switch (ctrl->wValue) {
  76466. + case 0x0201:
  76467. + case 0x0202:
  76468. + ((u8*)req->buf)[0] = 0x00;
  76469. + ((u8*)req->buf)[1] = 0xe3;
  76470. + break;
  76471. + case 0x0300:
  76472. + case 0x0500:
  76473. + ((u8*)req->buf)[0] = 0x00;
  76474. + break;
  76475. + }
  76476. + //((u8*)req->buf)[0] = 0x81;
  76477. + //((u8*)req->buf)[1] = 0x81;
  76478. + value = ctrl->wLength;
  76479. + break;
  76480. + case 0x82:
  76481. + switch (ctrl->wValue) {
  76482. + case 0x0201:
  76483. + case 0x0202:
  76484. + ((u8*)req->buf)[0] = 0x00;
  76485. + ((u8*)req->buf)[1] = 0xc3;
  76486. + break;
  76487. + case 0x0300:
  76488. + case 0x0500:
  76489. + ((u8*)req->buf)[0] = 0x00;
  76490. + break;
  76491. + }
  76492. + //((u8*)req->buf)[0] = 0x82;
  76493. + //((u8*)req->buf)[1] = 0x82;
  76494. + value = ctrl->wLength;
  76495. + break;
  76496. + case 0x83:
  76497. + switch (ctrl->wValue) {
  76498. + case 0x0201:
  76499. + case 0x0202:
  76500. + ((u8*)req->buf)[0] = 0x00;
  76501. + ((u8*)req->buf)[1] = 0x00;
  76502. + break;
  76503. + case 0x0300:
  76504. + ((u8*)req->buf)[0] = 0x60;
  76505. + break;
  76506. + case 0x0500:
  76507. + ((u8*)req->buf)[0] = 0x18;
  76508. + break;
  76509. + }
  76510. + //((u8*)req->buf)[0] = 0x83;
  76511. + //((u8*)req->buf)[1] = 0x83;
  76512. + value = ctrl->wLength;
  76513. + break;
  76514. + case 0x84:
  76515. + switch (ctrl->wValue) {
  76516. + case 0x0201:
  76517. + case 0x0202:
  76518. + ((u8*)req->buf)[0] = 0x00;
  76519. + ((u8*)req->buf)[1] = 0x01;
  76520. + break;
  76521. + case 0x0300:
  76522. + case 0x0500:
  76523. + ((u8*)req->buf)[0] = 0x08;
  76524. + break;
  76525. + }
  76526. + //((u8*)req->buf)[0] = 0x84;
  76527. + //((u8*)req->buf)[1] = 0x84;
  76528. + value = ctrl->wLength;
  76529. + break;
  76530. + case 0x85:
  76531. + ((u8*)req->buf)[0] = 0x85;
  76532. + ((u8*)req->buf)[1] = 0x85;
  76533. + value = ctrl->wLength;
  76534. + break;
  76535. +
  76536. +
  76537. + default:
  76538. +unknown:
  76539. + printk("unknown control req%02x.%02x v%04x i%04x l%d\n",
  76540. + ctrl->bRequestType, ctrl->bRequest,
  76541. + ctrl->wValue, ctrl->wIndex, ctrl->wLength);
  76542. + }
  76543. +
  76544. + /* respond with data transfer before status phase? */
  76545. + if (value >= 0) {
  76546. + req->length = value;
  76547. + req->zero = value < ctrl->wLength
  76548. + && (value % gadget->ep0->maxpacket) == 0;
  76549. + value = usb_ep_queue (gadget->ep0, req, GFP_ATOMIC);
  76550. + if (value < 0) {
  76551. + DBG (dev, "ep_queue < 0 --> %d\n", value);
  76552. + req->status = 0;
  76553. + zero_setup_complete (gadget->ep0, req);
  76554. + }
  76555. + }
  76556. +
  76557. + /* device either stalls (value < 0) or reports success */
  76558. + return value;
  76559. +}
  76560. +
  76561. +static void
  76562. +zero_disconnect (struct usb_gadget *gadget)
  76563. +{
  76564. + struct zero_dev *dev = get_gadget_data (gadget);
  76565. + unsigned long flags;
  76566. +
  76567. + spin_lock_irqsave (&dev->lock, flags);
  76568. + zero_reset_config (dev);
  76569. +
  76570. + /* a more significant application might have some non-usb
  76571. + * activities to quiesce here, saving resources like power
  76572. + * or pushing the notification up a network stack.
  76573. + */
  76574. + spin_unlock_irqrestore (&dev->lock, flags);
  76575. +
  76576. + /* next we may get setup() calls to enumerate new connections;
  76577. + * or an unbind() during shutdown (including removing module).
  76578. + */
  76579. +}
  76580. +
  76581. +static void
  76582. +zero_autoresume (unsigned long _dev)
  76583. +{
  76584. + struct zero_dev *dev = (struct zero_dev *) _dev;
  76585. + int status;
  76586. +
  76587. + /* normally the host would be woken up for something
  76588. + * more significant than just a timer firing...
  76589. + */
  76590. + if (dev->gadget->speed != USB_SPEED_UNKNOWN) {
  76591. + status = usb_gadget_wakeup (dev->gadget);
  76592. + DBG (dev, "wakeup --> %d\n", status);
  76593. + }
  76594. +}
  76595. +
  76596. +/*-------------------------------------------------------------------------*/
  76597. +
  76598. +static void
  76599. +zero_unbind (struct usb_gadget *gadget)
  76600. +{
  76601. + struct zero_dev *dev = get_gadget_data (gadget);
  76602. +
  76603. + DBG (dev, "unbind\n");
  76604. +
  76605. + /* we've already been disconnected ... no i/o is active */
  76606. + if (dev->req)
  76607. + free_ep_req (gadget->ep0, dev->req);
  76608. + del_timer_sync (&dev->resume);
  76609. + kfree (dev);
  76610. + set_gadget_data (gadget, NULL);
  76611. +}
  76612. +
  76613. +static int
  76614. +zero_bind (struct usb_gadget *gadget)
  76615. +{
  76616. + struct zero_dev *dev;
  76617. + //struct usb_ep *ep;
  76618. +
  76619. + printk("binding\n");
  76620. + /*
  76621. + * DRIVER POLICY CHOICE: you may want to do this differently.
  76622. + * One thing to avoid is reusing a bcdDevice revision code
  76623. + * with different host-visible configurations or behavior
  76624. + * restrictions -- using ep1in/ep2out vs ep1out/ep3in, etc
  76625. + */
  76626. + //device_desc.bcdDevice = __constant_cpu_to_le16 (0x0201);
  76627. +
  76628. +
  76629. + /* ok, we made sense of the hardware ... */
  76630. + dev = kmalloc (sizeof *dev, SLAB_KERNEL);
  76631. + if (!dev)
  76632. + return -ENOMEM;
  76633. + memset (dev, 0, sizeof *dev);
  76634. + spin_lock_init (&dev->lock);
  76635. + dev->gadget = gadget;
  76636. + set_gadget_data (gadget, dev);
  76637. +
  76638. + /* preallocate control response and buffer */
  76639. + dev->req = usb_ep_alloc_request (gadget->ep0, GFP_KERNEL);
  76640. + if (!dev->req)
  76641. + goto enomem;
  76642. + dev->req->buf = usb_ep_alloc_buffer (gadget->ep0, USB_BUFSIZ,
  76643. + &dev->req->dma, GFP_KERNEL);
  76644. + if (!dev->req->buf)
  76645. + goto enomem;
  76646. +
  76647. + dev->req->complete = zero_setup_complete;
  76648. +
  76649. + device_desc.bMaxPacketSize0 = gadget->ep0->maxpacket;
  76650. +
  76651. +#ifdef CONFIG_USB_GADGET_DUALSPEED
  76652. + /* assume ep0 uses the same value for both speeds ... */
  76653. + dev_qualifier.bMaxPacketSize0 = device_desc.bMaxPacketSize0;
  76654. +
  76655. + /* and that all endpoints are dual-speed */
  76656. + //hs_source_desc.bEndpointAddress = fs_source_desc.bEndpointAddress;
  76657. + //hs_sink_desc.bEndpointAddress = fs_sink_desc.bEndpointAddress;
  76658. +#endif
  76659. +
  76660. + usb_gadget_set_selfpowered (gadget);
  76661. +
  76662. + init_timer (&dev->resume);
  76663. + dev->resume.function = zero_autoresume;
  76664. + dev->resume.data = (unsigned long) dev;
  76665. +
  76666. + gadget->ep0->driver_data = dev;
  76667. +
  76668. + INFO (dev, "%s, version: " DRIVER_VERSION "\n", longname);
  76669. + INFO (dev, "using %s, OUT %s IN %s\n", gadget->name,
  76670. + EP_OUT_NAME, EP_IN_NAME);
  76671. +
  76672. + snprintf (manufacturer, sizeof manufacturer,
  76673. + UTS_SYSNAME " " UTS_RELEASE " with %s",
  76674. + gadget->name);
  76675. +
  76676. + return 0;
  76677. +
  76678. +enomem:
  76679. + zero_unbind (gadget);
  76680. + return -ENOMEM;
  76681. +}
  76682. +
  76683. +/*-------------------------------------------------------------------------*/
  76684. +
  76685. +static void
  76686. +zero_suspend (struct usb_gadget *gadget)
  76687. +{
  76688. + struct zero_dev *dev = get_gadget_data (gadget);
  76689. +
  76690. + if (gadget->speed == USB_SPEED_UNKNOWN)
  76691. + return;
  76692. +
  76693. + if (autoresume) {
  76694. + mod_timer (&dev->resume, jiffies + (HZ * autoresume));
  76695. + DBG (dev, "suspend, wakeup in %d seconds\n", autoresume);
  76696. + } else
  76697. + DBG (dev, "suspend\n");
  76698. +}
  76699. +
  76700. +static void
  76701. +zero_resume (struct usb_gadget *gadget)
  76702. +{
  76703. + struct zero_dev *dev = get_gadget_data (gadget);
  76704. +
  76705. + DBG (dev, "resume\n");
  76706. + del_timer (&dev->resume);
  76707. +}
  76708. +
  76709. +
  76710. +/*-------------------------------------------------------------------------*/
  76711. +
  76712. +static struct usb_gadget_driver zero_driver = {
  76713. +#ifdef CONFIG_USB_GADGET_DUALSPEED
  76714. + .speed = USB_SPEED_HIGH,
  76715. +#else
  76716. + .speed = USB_SPEED_FULL,
  76717. +#endif
  76718. + .function = (char *) longname,
  76719. + .bind = zero_bind,
  76720. + .unbind = zero_unbind,
  76721. +
  76722. + .setup = zero_setup,
  76723. + .disconnect = zero_disconnect,
  76724. +
  76725. + .suspend = zero_suspend,
  76726. + .resume = zero_resume,
  76727. +
  76728. + .driver = {
  76729. + .name = (char *) shortname,
  76730. + // .shutdown = ...
  76731. + // .suspend = ...
  76732. + // .resume = ...
  76733. + },
  76734. +};
  76735. +
  76736. +MODULE_AUTHOR ("David Brownell");
  76737. +MODULE_LICENSE ("Dual BSD/GPL");
  76738. +
  76739. +static struct proc_dir_entry *pdir, *pfile;
  76740. +
  76741. +static int isoc_read_data (char *page, char **start,
  76742. + off_t off, int count,
  76743. + int *eof, void *data)
  76744. +{
  76745. + int i;
  76746. + static int c = 0;
  76747. + static int done = 0;
  76748. + static int s = 0;
  76749. +
  76750. +/*
  76751. + printk ("\ncount: %d\n", count);
  76752. + printk ("rbuf_start: %d\n", rbuf_start);
  76753. + printk ("rbuf_len: %d\n", rbuf_len);
  76754. + printk ("off: %d\n", off);
  76755. + printk ("start: %p\n\n", *start);
  76756. +*/
  76757. + if (done) {
  76758. + c = 0;
  76759. + done = 0;
  76760. + *eof = 1;
  76761. + return 0;
  76762. + }
  76763. +
  76764. + if (c == 0) {
  76765. + if (rbuf_len == RBUF_LEN)
  76766. + s = rbuf_start;
  76767. + else s = 0;
  76768. + }
  76769. +
  76770. + for (i=0; i<count && c<rbuf_len; i++, c++) {
  76771. + page[i] = rbuf[(c+s) % RBUF_LEN];
  76772. + }
  76773. + *start = page;
  76774. +
  76775. + if (c >= rbuf_len) {
  76776. + *eof = 1;
  76777. + done = 1;
  76778. + }
  76779. +
  76780. +
  76781. + return i;
  76782. +}
  76783. +
  76784. +static int __init init (void)
  76785. +{
  76786. +
  76787. + int retval = 0;
  76788. +
  76789. + pdir = proc_mkdir("isoc_test", NULL);
  76790. + if(pdir == NULL) {
  76791. + retval = -ENOMEM;
  76792. + printk("Error creating dir\n");
  76793. + goto done;
  76794. + }
  76795. + pdir->owner = THIS_MODULE;
  76796. +
  76797. + pfile = create_proc_read_entry("isoc_data",
  76798. + 0444, pdir,
  76799. + isoc_read_data,
  76800. + NULL);
  76801. + if (pfile == NULL) {
  76802. + retval = -ENOMEM;
  76803. + printk("Error creating file\n");
  76804. + goto no_file;
  76805. + }
  76806. + pfile->owner = THIS_MODULE;
  76807. +
  76808. + return usb_gadget_register_driver (&zero_driver);
  76809. +
  76810. + no_file:
  76811. + remove_proc_entry("isoc_data", NULL);
  76812. + done:
  76813. + return retval;
  76814. +}
  76815. +module_init (init);
  76816. +
  76817. +static void __exit cleanup (void)
  76818. +{
  76819. +
  76820. + usb_gadget_unregister_driver (&zero_driver);
  76821. +
  76822. + remove_proc_entry("isoc_data", pdir);
  76823. + remove_proc_entry("isoc_test", NULL);
  76824. +}
  76825. +module_exit (cleanup);
  76826. diff -Nur linux-3.18.8/drivers/usb/host/dwc_otg/dwc_cfi_common.h linux-rpi/drivers/usb/host/dwc_otg/dwc_cfi_common.h
  76827. --- linux-3.18.8/drivers/usb/host/dwc_otg/dwc_cfi_common.h 1970-01-01 01:00:00.000000000 +0100
  76828. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_cfi_common.h 2015-03-05 14:40:16.557715806 +0100
  76829. @@ -0,0 +1,142 @@
  76830. +/* ==========================================================================
  76831. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  76832. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  76833. + * otherwise expressly agreed to in writing between Synopsys and you.
  76834. + *
  76835. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  76836. + * any End User Software License Agreement or Agreement for Licensed Product
  76837. + * with Synopsys or any supplement thereto. You are permitted to use and
  76838. + * redistribute this Software in source and binary forms, with or without
  76839. + * modification, provided that redistributions of source code must retain this
  76840. + * notice. You may not view, use, disclose, copy or distribute this file or
  76841. + * any information contained herein except pursuant to this license grant from
  76842. + * Synopsys. If you do not agree with this notice, including the disclaimer
  76843. + * below, then you are not authorized to use the Software.
  76844. + *
  76845. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  76846. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  76847. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  76848. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  76849. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  76850. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  76851. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  76852. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  76853. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  76854. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  76855. + * DAMAGE.
  76856. + * ========================================================================== */
  76857. +
  76858. +#if !defined(__DWC_CFI_COMMON_H__)
  76859. +#define __DWC_CFI_COMMON_H__
  76860. +
  76861. +//#include <linux/types.h>
  76862. +
  76863. +/**
  76864. + * @file
  76865. + *
  76866. + * This file contains the CFI specific common constants, interfaces
  76867. + * (functions and macros) and structures for Linux. No PCD specific
  76868. + * data structure or definition is to be included in this file.
  76869. + *
  76870. + */
  76871. +
  76872. +/** This is a request for all Core Features */
  76873. +#define VEN_CORE_GET_FEATURES 0xB1
  76874. +
  76875. +/** This is a request to get the value of a specific Core Feature */
  76876. +#define VEN_CORE_GET_FEATURE 0xB2
  76877. +
  76878. +/** This command allows the host to set the value of a specific Core Feature */
  76879. +#define VEN_CORE_SET_FEATURE 0xB3
  76880. +
  76881. +/** This command allows the host to set the default values of
  76882. + * either all or any specific Core Feature
  76883. + */
  76884. +#define VEN_CORE_RESET_FEATURES 0xB4
  76885. +
  76886. +/** This command forces the PCD to write the deferred values of a Core Features */
  76887. +#define VEN_CORE_ACTIVATE_FEATURES 0xB5
  76888. +
  76889. +/** This request reads a DWORD value from a register at the specified offset */
  76890. +#define VEN_CORE_READ_REGISTER 0xB6
  76891. +
  76892. +/** This request writes a DWORD value into a register at the specified offset */
  76893. +#define VEN_CORE_WRITE_REGISTER 0xB7
  76894. +
  76895. +/** This structure is the header of the Core Features dataset returned to
  76896. + * the Host
  76897. + */
  76898. +struct cfi_all_features_header {
  76899. +/** The features header structure length is */
  76900. +#define CFI_ALL_FEATURES_HDR_LEN 8
  76901. + /**
  76902. + * The total length of the features dataset returned to the Host
  76903. + */
  76904. + uint16_t wTotalLen;
  76905. +
  76906. + /**
  76907. + * CFI version number inBinary-Coded Decimal (i.e., 1.00 is 100H).
  76908. + * This field identifies the version of the CFI Specification with which
  76909. + * the device is compliant.
  76910. + */
  76911. + uint16_t wVersion;
  76912. +
  76913. + /** The ID of the Core */
  76914. + uint16_t wCoreID;
  76915. +#define CFI_CORE_ID_UDC 1
  76916. +#define CFI_CORE_ID_OTG 2
  76917. +#define CFI_CORE_ID_WUDEV 3
  76918. +
  76919. + /** Number of features returned by VEN_CORE_GET_FEATURES request */
  76920. + uint16_t wNumFeatures;
  76921. +} UPACKED;
  76922. +
  76923. +typedef struct cfi_all_features_header cfi_all_features_header_t;
  76924. +
  76925. +/** This structure is a header of the Core Feature descriptor dataset returned to
  76926. + * the Host after the VEN_CORE_GET_FEATURES request
  76927. + */
  76928. +struct cfi_feature_desc_header {
  76929. +#define CFI_FEATURE_DESC_HDR_LEN 8
  76930. +
  76931. + /** The feature ID */
  76932. + uint16_t wFeatureID;
  76933. +
  76934. + /** Length of this feature descriptor in bytes - including the
  76935. + * length of the feature name string
  76936. + */
  76937. + uint16_t wLength;
  76938. +
  76939. + /** The data length of this feature in bytes */
  76940. + uint16_t wDataLength;
  76941. +
  76942. + /**
  76943. + * Attributes of this features
  76944. + * D0: Access rights
  76945. + * 0 - Read/Write
  76946. + * 1 - Read only
  76947. + */
  76948. + uint8_t bmAttributes;
  76949. +#define CFI_FEATURE_ATTR_RO 1
  76950. +#define CFI_FEATURE_ATTR_RW 0
  76951. +
  76952. + /** Length of the feature name in bytes */
  76953. + uint8_t bNameLen;
  76954. +
  76955. + /** The feature name buffer */
  76956. + //uint8_t *name;
  76957. +} UPACKED;
  76958. +
  76959. +typedef struct cfi_feature_desc_header cfi_feature_desc_header_t;
  76960. +
  76961. +/**
  76962. + * This structure describes a NULL terminated string referenced by its id field.
  76963. + * It is very similar to usb_string structure but has the id field type set to 16-bit.
  76964. + */
  76965. +struct cfi_string {
  76966. + uint16_t id;
  76967. + const uint8_t *s;
  76968. +};
  76969. +typedef struct cfi_string cfi_string_t;
  76970. +
  76971. +#endif
  76972. diff -Nur linux-3.18.8/drivers/usb/host/dwc_otg/dwc_otg_adp.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_adp.c
  76973. --- linux-3.18.8/drivers/usb/host/dwc_otg/dwc_otg_adp.c 1970-01-01 01:00:00.000000000 +0100
  76974. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_adp.c 2015-03-05 14:40:16.557715806 +0100
  76975. @@ -0,0 +1,854 @@
  76976. +/* ==========================================================================
  76977. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_adp.c $
  76978. + * $Revision: #12 $
  76979. + * $Date: 2011/10/26 $
  76980. + * $Change: 1873028 $
  76981. + *
  76982. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  76983. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  76984. + * otherwise expressly agreed to in writing between Synopsys and you.
  76985. + *
  76986. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  76987. + * any End User Software License Agreement or Agreement for Licensed Product
  76988. + * with Synopsys or any supplement thereto. You are permitted to use and
  76989. + * redistribute this Software in source and binary forms, with or without
  76990. + * modification, provided that redistributions of source code must retain this
  76991. + * notice. You may not view, use, disclose, copy or distribute this file or
  76992. + * any information contained herein except pursuant to this license grant from
  76993. + * Synopsys. If you do not agree with this notice, including the disclaimer
  76994. + * below, then you are not authorized to use the Software.
  76995. + *
  76996. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  76997. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  76998. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  76999. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  77000. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  77001. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  77002. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  77003. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  77004. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  77005. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  77006. + * DAMAGE.
  77007. + * ========================================================================== */
  77008. +
  77009. +#include "dwc_os.h"
  77010. +#include "dwc_otg_regs.h"
  77011. +#include "dwc_otg_cil.h"
  77012. +#include "dwc_otg_adp.h"
  77013. +
  77014. +/** @file
  77015. + *
  77016. + * This file contains the most of the Attach Detect Protocol implementation for
  77017. + * the driver to support OTG Rev2.0.
  77018. + *
  77019. + */
  77020. +
  77021. +void dwc_otg_adp_write_reg(dwc_otg_core_if_t * core_if, uint32_t value)
  77022. +{
  77023. + adpctl_data_t adpctl;
  77024. +
  77025. + adpctl.d32 = value;
  77026. + adpctl.b.ar = 0x2;
  77027. +
  77028. + DWC_WRITE_REG32(&core_if->core_global_regs->adpctl, adpctl.d32);
  77029. +
  77030. + while (adpctl.b.ar) {
  77031. + adpctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->adpctl);
  77032. + }
  77033. +
  77034. +}
  77035. +
  77036. +/**
  77037. + * Function is called to read ADP registers
  77038. + */
  77039. +uint32_t dwc_otg_adp_read_reg(dwc_otg_core_if_t * core_if)
  77040. +{
  77041. + adpctl_data_t adpctl;
  77042. +
  77043. + adpctl.d32 = 0;
  77044. + adpctl.b.ar = 0x1;
  77045. +
  77046. + DWC_WRITE_REG32(&core_if->core_global_regs->adpctl, adpctl.d32);
  77047. +
  77048. + while (adpctl.b.ar) {
  77049. + adpctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->adpctl);
  77050. + }
  77051. +
  77052. + return adpctl.d32;
  77053. +}
  77054. +
  77055. +/**
  77056. + * Function is called to read ADPCTL register and filter Write-clear bits
  77057. + */
  77058. +uint32_t dwc_otg_adp_read_reg_filter(dwc_otg_core_if_t * core_if)
  77059. +{
  77060. + adpctl_data_t adpctl;
  77061. +
  77062. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  77063. + adpctl.b.adp_tmout_int = 0;
  77064. + adpctl.b.adp_prb_int = 0;
  77065. + adpctl.b.adp_tmout_int = 0;
  77066. +
  77067. + return adpctl.d32;
  77068. +}
  77069. +
  77070. +/**
  77071. + * Function is called to write ADP registers
  77072. + */
  77073. +void dwc_otg_adp_modify_reg(dwc_otg_core_if_t * core_if, uint32_t clr,
  77074. + uint32_t set)
  77075. +{
  77076. + dwc_otg_adp_write_reg(core_if,
  77077. + (dwc_otg_adp_read_reg(core_if) & (~clr)) | set);
  77078. +}
  77079. +
  77080. +static void adp_sense_timeout(void *ptr)
  77081. +{
  77082. + dwc_otg_core_if_t *core_if = (dwc_otg_core_if_t *) ptr;
  77083. + core_if->adp.sense_timer_started = 0;
  77084. + DWC_PRINTF("ADP SENSE TIMEOUT\n");
  77085. + if (core_if->adp_enable) {
  77086. + dwc_otg_adp_sense_stop(core_if);
  77087. + dwc_otg_adp_probe_start(core_if);
  77088. + }
  77089. +}
  77090. +
  77091. +/**
  77092. + * This function is called when the ADP vbus timer expires. Timeout is 1.1s.
  77093. + */
  77094. +static void adp_vbuson_timeout(void *ptr)
  77095. +{
  77096. + gpwrdn_data_t gpwrdn;
  77097. + dwc_otg_core_if_t *core_if = (dwc_otg_core_if_t *) ptr;
  77098. + hprt0_data_t hprt0 = {.d32 = 0 };
  77099. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  77100. + DWC_PRINTF("%s: 1.1 seconds expire after turning on VBUS\n",__FUNCTION__);
  77101. + if (core_if) {
  77102. + core_if->adp.vbuson_timer_started = 0;
  77103. + /* Turn off vbus */
  77104. + hprt0.b.prtpwr = 1;
  77105. + DWC_MODIFY_REG32(core_if->host_if->hprt0, hprt0.d32, 0);
  77106. + gpwrdn.d32 = 0;
  77107. +
  77108. + /* Power off the core */
  77109. + if (core_if->power_down == 2) {
  77110. + /* Enable Wakeup Logic */
  77111. +// gpwrdn.b.wkupactiv = 1;
  77112. + gpwrdn.b.pmuactv = 0;
  77113. + gpwrdn.b.pwrdnrstn = 1;
  77114. + gpwrdn.b.pwrdnclmp = 1;
  77115. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0,
  77116. + gpwrdn.d32);
  77117. +
  77118. + /* Suspend the Phy Clock */
  77119. + pcgcctl.b.stoppclk = 1;
  77120. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, pcgcctl.d32);
  77121. +
  77122. + /* Switch on VDD */
  77123. +// gpwrdn.b.wkupactiv = 1;
  77124. + gpwrdn.b.pmuactv = 1;
  77125. + gpwrdn.b.pwrdnrstn = 1;
  77126. + gpwrdn.b.pwrdnclmp = 1;
  77127. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0,
  77128. + gpwrdn.d32);
  77129. + } else {
  77130. + /* Enable Power Down Logic */
  77131. + gpwrdn.b.pmuintsel = 1;
  77132. + gpwrdn.b.pmuactv = 1;
  77133. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  77134. + }
  77135. +
  77136. + /* Power off the core */
  77137. + if (core_if->power_down == 2) {
  77138. + gpwrdn.d32 = 0;
  77139. + gpwrdn.b.pwrdnswtch = 1;
  77140. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn,
  77141. + gpwrdn.d32, 0);
  77142. + }
  77143. +
  77144. + /* Unmask SRP detected interrupt from Power Down Logic */
  77145. + gpwrdn.d32 = 0;
  77146. + gpwrdn.b.srp_det_msk = 1;
  77147. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  77148. +
  77149. + dwc_otg_adp_probe_start(core_if);
  77150. + dwc_otg_dump_global_registers(core_if);
  77151. + dwc_otg_dump_host_registers(core_if);
  77152. + }
  77153. +
  77154. +}
  77155. +
  77156. +/**
  77157. + * Start the ADP Initial Probe timer to detect if Port Connected interrupt is
  77158. + * not asserted within 1.1 seconds.
  77159. + *
  77160. + * @param core_if the pointer to core_if strucure.
  77161. + */
  77162. +void dwc_otg_adp_vbuson_timer_start(dwc_otg_core_if_t * core_if)
  77163. +{
  77164. + core_if->adp.vbuson_timer_started = 1;
  77165. + if (core_if->adp.vbuson_timer)
  77166. + {
  77167. + DWC_PRINTF("SCHEDULING VBUSON TIMER\n");
  77168. + /* 1.1 secs + 60ms necessary for cil_hcd_start*/
  77169. + DWC_TIMER_SCHEDULE(core_if->adp.vbuson_timer, 1160);
  77170. + } else {
  77171. + DWC_WARN("VBUSON_TIMER = %p\n",core_if->adp.vbuson_timer);
  77172. + }
  77173. +}
  77174. +
  77175. +#if 0
  77176. +/**
  77177. + * Masks all DWC OTG core interrupts
  77178. + *
  77179. + */
  77180. +static void mask_all_interrupts(dwc_otg_core_if_t * core_if)
  77181. +{
  77182. + int i;
  77183. + gahbcfg_data_t ahbcfg = {.d32 = 0 };
  77184. +
  77185. + /* Mask Host Interrupts */
  77186. +
  77187. + /* Clear and disable HCINTs */
  77188. + for (i = 0; i < core_if->core_params->host_channels; i++) {
  77189. + DWC_WRITE_REG32(&core_if->host_if->hc_regs[i]->hcintmsk, 0);
  77190. + DWC_WRITE_REG32(&core_if->host_if->hc_regs[i]->hcint, 0xFFFFFFFF);
  77191. +
  77192. + }
  77193. +
  77194. + /* Clear and disable HAINT */
  77195. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->haintmsk, 0x0000);
  77196. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->haint, 0xFFFFFFFF);
  77197. +
  77198. + /* Mask Device Interrupts */
  77199. + if (!core_if->multiproc_int_enable) {
  77200. + /* Clear and disable IN Endpoint interrupts */
  77201. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->diepmsk, 0);
  77202. + for (i = 0; i <= core_if->dev_if->num_in_eps; i++) {
  77203. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[i]->
  77204. + diepint, 0xFFFFFFFF);
  77205. + }
  77206. +
  77207. + /* Clear and disable OUT Endpoint interrupts */
  77208. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->doepmsk, 0);
  77209. + for (i = 0; i <= core_if->dev_if->num_out_eps; i++) {
  77210. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[i]->
  77211. + doepint, 0xFFFFFFFF);
  77212. + }
  77213. +
  77214. + /* Clear and disable DAINT */
  77215. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->daint,
  77216. + 0xFFFFFFFF);
  77217. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->daintmsk, 0);
  77218. + } else {
  77219. + for (i = 0; i < core_if->dev_if->num_in_eps; ++i) {
  77220. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->
  77221. + diepeachintmsk[i], 0);
  77222. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[i]->
  77223. + diepint, 0xFFFFFFFF);
  77224. + }
  77225. +
  77226. + for (i = 0; i < core_if->dev_if->num_out_eps; ++i) {
  77227. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->
  77228. + doepeachintmsk[i], 0);
  77229. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[i]->
  77230. + doepint, 0xFFFFFFFF);
  77231. + }
  77232. +
  77233. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->deachintmsk,
  77234. + 0);
  77235. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->deachint,
  77236. + 0xFFFFFFFF);
  77237. +
  77238. + }
  77239. +
  77240. + /* Disable interrupts */
  77241. + ahbcfg.b.glblintrmsk = 1;
  77242. + DWC_MODIFY_REG32(&core_if->core_global_regs->gahbcfg, ahbcfg.d32, 0);
  77243. +
  77244. + /* Disable all interrupts. */
  77245. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, 0);
  77246. +
  77247. + /* Clear any pending interrupts */
  77248. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  77249. +
  77250. + /* Clear any pending OTG Interrupts */
  77251. + DWC_WRITE_REG32(&core_if->core_global_regs->gotgint, 0xFFFFFFFF);
  77252. +}
  77253. +
  77254. +/**
  77255. + * Unmask Port Connection Detected interrupt
  77256. + *
  77257. + */
  77258. +static void unmask_conn_det_intr(dwc_otg_core_if_t * core_if)
  77259. +{
  77260. + gintmsk_data_t gintmsk = {.d32 = 0,.b.portintr = 1 };
  77261. +
  77262. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, gintmsk.d32);
  77263. +}
  77264. +#endif
  77265. +
  77266. +/**
  77267. + * Starts the ADP Probing
  77268. + *
  77269. + * @param core_if the pointer to core_if structure.
  77270. + */
  77271. +uint32_t dwc_otg_adp_probe_start(dwc_otg_core_if_t * core_if)
  77272. +{
  77273. +
  77274. + adpctl_data_t adpctl = {.d32 = 0};
  77275. + gpwrdn_data_t gpwrdn;
  77276. +#if 0
  77277. + adpctl_data_t adpctl_int = {.d32 = 0, .b.adp_prb_int = 1,
  77278. + .b.adp_sns_int = 1, b.adp_tmout_int};
  77279. +#endif
  77280. + dwc_otg_disable_global_interrupts(core_if);
  77281. + DWC_PRINTF("ADP Probe Start\n");
  77282. + core_if->adp.probe_enabled = 1;
  77283. +
  77284. + adpctl.b.adpres = 1;
  77285. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  77286. +
  77287. + while (adpctl.b.adpres) {
  77288. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  77289. + }
  77290. +
  77291. + adpctl.d32 = 0;
  77292. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  77293. +
  77294. + /* In Host mode unmask SRP detected interrupt */
  77295. + gpwrdn.d32 = 0;
  77296. + gpwrdn.b.sts_chngint_msk = 1;
  77297. + if (!gpwrdn.b.idsts) {
  77298. + gpwrdn.b.srp_det_msk = 1;
  77299. + }
  77300. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  77301. +
  77302. + adpctl.b.adp_tmout_int_msk = 1;
  77303. + adpctl.b.adp_prb_int_msk = 1;
  77304. + adpctl.b.prb_dschg = 1;
  77305. + adpctl.b.prb_delta = 1;
  77306. + adpctl.b.prb_per = 1;
  77307. + adpctl.b.adpen = 1;
  77308. + adpctl.b.enaprb = 1;
  77309. +
  77310. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  77311. + DWC_PRINTF("ADP Probe Finish\n");
  77312. + return 0;
  77313. +}
  77314. +
  77315. +/**
  77316. + * Starts the ADP Sense timer to detect if ADP Sense interrupt is not asserted
  77317. + * within 3 seconds.
  77318. + *
  77319. + * @param core_if the pointer to core_if strucure.
  77320. + */
  77321. +void dwc_otg_adp_sense_timer_start(dwc_otg_core_if_t * core_if)
  77322. +{
  77323. + core_if->adp.sense_timer_started = 1;
  77324. + DWC_TIMER_SCHEDULE(core_if->adp.sense_timer, 3000 /* 3 secs */ );
  77325. +}
  77326. +
  77327. +/**
  77328. + * Starts the ADP Sense
  77329. + *
  77330. + * @param core_if the pointer to core_if strucure.
  77331. + */
  77332. +uint32_t dwc_otg_adp_sense_start(dwc_otg_core_if_t * core_if)
  77333. +{
  77334. + adpctl_data_t adpctl;
  77335. +
  77336. + DWC_PRINTF("ADP Sense Start\n");
  77337. +
  77338. + /* Unmask ADP sense interrupt and mask all other from the core */
  77339. + adpctl.d32 = dwc_otg_adp_read_reg_filter(core_if);
  77340. + adpctl.b.adp_sns_int_msk = 1;
  77341. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  77342. + dwc_otg_disable_global_interrupts(core_if); // vahrama
  77343. +
  77344. + /* Set ADP reset bit*/
  77345. + adpctl.d32 = dwc_otg_adp_read_reg_filter(core_if);
  77346. + adpctl.b.adpres = 1;
  77347. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  77348. +
  77349. + while (adpctl.b.adpres) {
  77350. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  77351. + }
  77352. +
  77353. + adpctl.b.adpres = 0;
  77354. + adpctl.b.adpen = 1;
  77355. + adpctl.b.enasns = 1;
  77356. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  77357. +
  77358. + dwc_otg_adp_sense_timer_start(core_if);
  77359. +
  77360. + return 0;
  77361. +}
  77362. +
  77363. +/**
  77364. + * Stops the ADP Probing
  77365. + *
  77366. + * @param core_if the pointer to core_if strucure.
  77367. + */
  77368. +uint32_t dwc_otg_adp_probe_stop(dwc_otg_core_if_t * core_if)
  77369. +{
  77370. +
  77371. + adpctl_data_t adpctl;
  77372. + DWC_PRINTF("Stop ADP probe\n");
  77373. + core_if->adp.probe_enabled = 0;
  77374. + core_if->adp.probe_counter = 0;
  77375. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  77376. +
  77377. + adpctl.b.adpen = 0;
  77378. + adpctl.b.adp_prb_int = 1;
  77379. + adpctl.b.adp_tmout_int = 1;
  77380. + adpctl.b.adp_sns_int = 1;
  77381. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  77382. +
  77383. + return 0;
  77384. +}
  77385. +
  77386. +/**
  77387. + * Stops the ADP Sensing
  77388. + *
  77389. + * @param core_if the pointer to core_if strucure.
  77390. + */
  77391. +uint32_t dwc_otg_adp_sense_stop(dwc_otg_core_if_t * core_if)
  77392. +{
  77393. + adpctl_data_t adpctl;
  77394. +
  77395. + core_if->adp.sense_enabled = 0;
  77396. +
  77397. + adpctl.d32 = dwc_otg_adp_read_reg_filter(core_if);
  77398. + adpctl.b.enasns = 0;
  77399. + adpctl.b.adp_sns_int = 1;
  77400. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  77401. +
  77402. + return 0;
  77403. +}
  77404. +
  77405. +/**
  77406. + * Called to turn on the VBUS after initial ADP probe in host mode.
  77407. + * If port power was already enabled in cil_hcd_start function then
  77408. + * only schedule a timer.
  77409. + *
  77410. + * @param core_if the pointer to core_if structure.
  77411. + */
  77412. +void dwc_otg_adp_turnon_vbus(dwc_otg_core_if_t * core_if)
  77413. +{
  77414. + hprt0_data_t hprt0 = {.d32 = 0 };
  77415. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  77416. + DWC_PRINTF("Turn on VBUS for 1.1s, port power is %d\n", hprt0.b.prtpwr);
  77417. +
  77418. + if (hprt0.b.prtpwr == 0) {
  77419. + hprt0.b.prtpwr = 1;
  77420. + //DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  77421. + }
  77422. +
  77423. + dwc_otg_adp_vbuson_timer_start(core_if);
  77424. +}
  77425. +
  77426. +/**
  77427. + * Called right after driver is loaded
  77428. + * to perform initial actions for ADP
  77429. + *
  77430. + * @param core_if the pointer to core_if structure.
  77431. + * @param is_host - flag for current mode of operation either from GINTSTS or GPWRDN
  77432. + */
  77433. +void dwc_otg_adp_start(dwc_otg_core_if_t * core_if, uint8_t is_host)
  77434. +{
  77435. + gpwrdn_data_t gpwrdn;
  77436. +
  77437. + DWC_PRINTF("ADP Initial Start\n");
  77438. + core_if->adp.adp_started = 1;
  77439. +
  77440. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  77441. + dwc_otg_disable_global_interrupts(core_if);
  77442. + if (is_host) {
  77443. + DWC_PRINTF("HOST MODE\n");
  77444. + /* Enable Power Down Logic Interrupt*/
  77445. + gpwrdn.d32 = 0;
  77446. + gpwrdn.b.pmuintsel = 1;
  77447. + gpwrdn.b.pmuactv = 1;
  77448. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  77449. + /* Initialize first ADP probe to obtain Ramp Time value */
  77450. + core_if->adp.initial_probe = 1;
  77451. + dwc_otg_adp_probe_start(core_if);
  77452. + } else {
  77453. + gotgctl_data_t gotgctl;
  77454. + gotgctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  77455. + DWC_PRINTF("DEVICE MODE\n");
  77456. + if (gotgctl.b.bsesvld == 0) {
  77457. + /* Enable Power Down Logic Interrupt*/
  77458. + gpwrdn.d32 = 0;
  77459. + DWC_PRINTF("VBUS is not valid - start ADP probe\n");
  77460. + gpwrdn.b.pmuintsel = 1;
  77461. + gpwrdn.b.pmuactv = 1;
  77462. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  77463. + core_if->adp.initial_probe = 1;
  77464. + dwc_otg_adp_probe_start(core_if);
  77465. + } else {
  77466. + DWC_PRINTF("VBUS is valid - initialize core as a Device\n");
  77467. + core_if->op_state = B_PERIPHERAL;
  77468. + dwc_otg_core_init(core_if);
  77469. + dwc_otg_enable_global_interrupts(core_if);
  77470. + cil_pcd_start(core_if);
  77471. + dwc_otg_dump_global_registers(core_if);
  77472. + dwc_otg_dump_dev_registers(core_if);
  77473. + }
  77474. + }
  77475. +}
  77476. +
  77477. +void dwc_otg_adp_init(dwc_otg_core_if_t * core_if)
  77478. +{
  77479. + core_if->adp.adp_started = 0;
  77480. + core_if->adp.initial_probe = 0;
  77481. + core_if->adp.probe_timer_values[0] = -1;
  77482. + core_if->adp.probe_timer_values[1] = -1;
  77483. + core_if->adp.probe_enabled = 0;
  77484. + core_if->adp.sense_enabled = 0;
  77485. + core_if->adp.sense_timer_started = 0;
  77486. + core_if->adp.vbuson_timer_started = 0;
  77487. + core_if->adp.probe_counter = 0;
  77488. + core_if->adp.gpwrdn = 0;
  77489. + core_if->adp.attached = DWC_OTG_ADP_UNKOWN;
  77490. + /* Initialize timers */
  77491. + core_if->adp.sense_timer =
  77492. + DWC_TIMER_ALLOC("ADP SENSE TIMER", adp_sense_timeout, core_if);
  77493. + core_if->adp.vbuson_timer =
  77494. + DWC_TIMER_ALLOC("ADP VBUS ON TIMER", adp_vbuson_timeout, core_if);
  77495. + if (!core_if->adp.sense_timer || !core_if->adp.vbuson_timer)
  77496. + {
  77497. + DWC_ERROR("Could not allocate memory for ADP timers\n");
  77498. + }
  77499. +}
  77500. +
  77501. +void dwc_otg_adp_remove(dwc_otg_core_if_t * core_if)
  77502. +{
  77503. + gpwrdn_data_t gpwrdn = { .d32 = 0 };
  77504. + gpwrdn.b.pmuintsel = 1;
  77505. + gpwrdn.b.pmuactv = 1;
  77506. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  77507. +
  77508. + if (core_if->adp.probe_enabled)
  77509. + dwc_otg_adp_probe_stop(core_if);
  77510. + if (core_if->adp.sense_enabled)
  77511. + dwc_otg_adp_sense_stop(core_if);
  77512. + if (core_if->adp.sense_timer_started)
  77513. + DWC_TIMER_CANCEL(core_if->adp.sense_timer);
  77514. + if (core_if->adp.vbuson_timer_started)
  77515. + DWC_TIMER_CANCEL(core_if->adp.vbuson_timer);
  77516. + DWC_TIMER_FREE(core_if->adp.sense_timer);
  77517. + DWC_TIMER_FREE(core_if->adp.vbuson_timer);
  77518. +}
  77519. +
  77520. +/////////////////////////////////////////////////////////////////////
  77521. +////////////// ADP Interrupt Handlers ///////////////////////////////
  77522. +/////////////////////////////////////////////////////////////////////
  77523. +/**
  77524. + * This function sets Ramp Timer values
  77525. + */
  77526. +static uint32_t set_timer_value(dwc_otg_core_if_t * core_if, uint32_t val)
  77527. +{
  77528. + if (core_if->adp.probe_timer_values[0] == -1) {
  77529. + core_if->adp.probe_timer_values[0] = val;
  77530. + core_if->adp.probe_timer_values[1] = -1;
  77531. + return 1;
  77532. + } else {
  77533. + core_if->adp.probe_timer_values[1] =
  77534. + core_if->adp.probe_timer_values[0];
  77535. + core_if->adp.probe_timer_values[0] = val;
  77536. + return 0;
  77537. + }
  77538. +}
  77539. +
  77540. +/**
  77541. + * This function compares Ramp Timer values
  77542. + */
  77543. +static uint32_t compare_timer_values(dwc_otg_core_if_t * core_if)
  77544. +{
  77545. + uint32_t diff;
  77546. + if (core_if->adp.probe_timer_values[0]>=core_if->adp.probe_timer_values[1])
  77547. + diff = core_if->adp.probe_timer_values[0]-core_if->adp.probe_timer_values[1];
  77548. + else
  77549. + diff = core_if->adp.probe_timer_values[1]-core_if->adp.probe_timer_values[0];
  77550. + if(diff < 2) {
  77551. + return 0;
  77552. + } else {
  77553. + return 1;
  77554. + }
  77555. +}
  77556. +
  77557. +/**
  77558. + * This function handles ADP Probe Interrupts
  77559. + */
  77560. +static int32_t dwc_otg_adp_handle_prb_intr(dwc_otg_core_if_t * core_if,
  77561. + uint32_t val)
  77562. +{
  77563. + adpctl_data_t adpctl = {.d32 = 0 };
  77564. + gpwrdn_data_t gpwrdn, temp;
  77565. + adpctl.d32 = val;
  77566. +
  77567. + temp.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  77568. + core_if->adp.probe_counter++;
  77569. + core_if->adp.gpwrdn = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  77570. + if (adpctl.b.rtim == 0 && !temp.b.idsts){
  77571. + DWC_PRINTF("RTIM value is 0\n");
  77572. + goto exit;
  77573. + }
  77574. + if (set_timer_value(core_if, adpctl.b.rtim) &&
  77575. + core_if->adp.initial_probe) {
  77576. + core_if->adp.initial_probe = 0;
  77577. + dwc_otg_adp_probe_stop(core_if);
  77578. + gpwrdn.d32 = 0;
  77579. + gpwrdn.b.pmuactv = 1;
  77580. + gpwrdn.b.pmuintsel = 1;
  77581. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  77582. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  77583. +
  77584. + /* check which value is for device mode and which for Host mode */
  77585. + if (!temp.b.idsts) { /* considered host mode value is 0 */
  77586. + /*
  77587. + * Turn on VBUS after initial ADP probe.
  77588. + */
  77589. + core_if->op_state = A_HOST;
  77590. + dwc_otg_enable_global_interrupts(core_if);
  77591. + DWC_SPINUNLOCK(core_if->lock);
  77592. + cil_hcd_start(core_if);
  77593. + dwc_otg_adp_turnon_vbus(core_if);
  77594. + DWC_SPINLOCK(core_if->lock);
  77595. + } else {
  77596. + /*
  77597. + * Initiate SRP after initial ADP probe.
  77598. + */
  77599. + dwc_otg_enable_global_interrupts(core_if);
  77600. + dwc_otg_initiate_srp(core_if);
  77601. + }
  77602. + } else if (core_if->adp.probe_counter > 2){
  77603. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  77604. + if (compare_timer_values(core_if)) {
  77605. + DWC_PRINTF("Difference in timer values !!! \n");
  77606. +// core_if->adp.attached = DWC_OTG_ADP_ATTACHED;
  77607. + dwc_otg_adp_probe_stop(core_if);
  77608. +
  77609. + /* Power on the core */
  77610. + if (core_if->power_down == 2) {
  77611. + gpwrdn.b.pwrdnswtch = 1;
  77612. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  77613. + gpwrdn, 0, gpwrdn.d32);
  77614. + }
  77615. +
  77616. + /* check which value is for device mode and which for Host mode */
  77617. + if (!temp.b.idsts) { /* considered host mode value is 0 */
  77618. + /* Disable Interrupt from Power Down Logic */
  77619. + gpwrdn.d32 = 0;
  77620. + gpwrdn.b.pmuintsel = 1;
  77621. + gpwrdn.b.pmuactv = 1;
  77622. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  77623. + gpwrdn, gpwrdn.d32, 0);
  77624. +
  77625. + /*
  77626. + * Initialize the Core for Host mode.
  77627. + */
  77628. + core_if->op_state = A_HOST;
  77629. + dwc_otg_core_init(core_if);
  77630. + dwc_otg_enable_global_interrupts(core_if);
  77631. + cil_hcd_start(core_if);
  77632. + } else {
  77633. + gotgctl_data_t gotgctl;
  77634. + /* Mask SRP detected interrupt from Power Down Logic */
  77635. + gpwrdn.d32 = 0;
  77636. + gpwrdn.b.srp_det_msk = 1;
  77637. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  77638. + gpwrdn, gpwrdn.d32, 0);
  77639. +
  77640. + /* Disable Power Down Logic */
  77641. + gpwrdn.d32 = 0;
  77642. + gpwrdn.b.pmuintsel = 1;
  77643. + gpwrdn.b.pmuactv = 1;
  77644. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  77645. + gpwrdn, gpwrdn.d32, 0);
  77646. +
  77647. + /*
  77648. + * Initialize the Core for Device mode.
  77649. + */
  77650. + core_if->op_state = B_PERIPHERAL;
  77651. + dwc_otg_core_init(core_if);
  77652. + dwc_otg_enable_global_interrupts(core_if);
  77653. + cil_pcd_start(core_if);
  77654. +
  77655. + gotgctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  77656. + if (!gotgctl.b.bsesvld) {
  77657. + dwc_otg_initiate_srp(core_if);
  77658. + }
  77659. + }
  77660. + }
  77661. + if (core_if->power_down == 2) {
  77662. + if (gpwrdn.b.bsessvld) {
  77663. + /* Mask SRP detected interrupt from Power Down Logic */
  77664. + gpwrdn.d32 = 0;
  77665. + gpwrdn.b.srp_det_msk = 1;
  77666. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  77667. +
  77668. + /* Disable Power Down Logic */
  77669. + gpwrdn.d32 = 0;
  77670. + gpwrdn.b.pmuactv = 1;
  77671. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  77672. +
  77673. + /*
  77674. + * Initialize the Core for Device mode.
  77675. + */
  77676. + core_if->op_state = B_PERIPHERAL;
  77677. + dwc_otg_core_init(core_if);
  77678. + dwc_otg_enable_global_interrupts(core_if);
  77679. + cil_pcd_start(core_if);
  77680. + }
  77681. + }
  77682. + }
  77683. +exit:
  77684. + /* Clear interrupt */
  77685. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  77686. + adpctl.b.adp_prb_int = 1;
  77687. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  77688. +
  77689. + return 0;
  77690. +}
  77691. +
  77692. +/**
  77693. + * This function hadles ADP Sense Interrupt
  77694. + */
  77695. +static int32_t dwc_otg_adp_handle_sns_intr(dwc_otg_core_if_t * core_if)
  77696. +{
  77697. + adpctl_data_t adpctl;
  77698. + /* Stop ADP Sense timer */
  77699. + DWC_TIMER_CANCEL(core_if->adp.sense_timer);
  77700. +
  77701. + /* Restart ADP Sense timer */
  77702. + dwc_otg_adp_sense_timer_start(core_if);
  77703. +
  77704. + /* Clear interrupt */
  77705. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  77706. + adpctl.b.adp_sns_int = 1;
  77707. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  77708. +
  77709. + return 0;
  77710. +}
  77711. +
  77712. +/**
  77713. + * This function handles ADP Probe Interrupts
  77714. + */
  77715. +static int32_t dwc_otg_adp_handle_prb_tmout_intr(dwc_otg_core_if_t * core_if,
  77716. + uint32_t val)
  77717. +{
  77718. + adpctl_data_t adpctl = {.d32 = 0 };
  77719. + adpctl.d32 = val;
  77720. + set_timer_value(core_if, adpctl.b.rtim);
  77721. +
  77722. + /* Clear interrupt */
  77723. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  77724. + adpctl.b.adp_tmout_int = 1;
  77725. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  77726. +
  77727. + return 0;
  77728. +}
  77729. +
  77730. +/**
  77731. + * ADP Interrupt handler.
  77732. + *
  77733. + */
  77734. +int32_t dwc_otg_adp_handle_intr(dwc_otg_core_if_t * core_if)
  77735. +{
  77736. + int retval = 0;
  77737. + adpctl_data_t adpctl = {.d32 = 0};
  77738. +
  77739. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  77740. + DWC_PRINTF("ADPCTL = %08x\n",adpctl.d32);
  77741. +
  77742. + if (adpctl.b.adp_sns_int & adpctl.b.adp_sns_int_msk) {
  77743. + DWC_PRINTF("ADP Sense interrupt\n");
  77744. + retval |= dwc_otg_adp_handle_sns_intr(core_if);
  77745. + }
  77746. + if (adpctl.b.adp_tmout_int & adpctl.b.adp_tmout_int_msk) {
  77747. + DWC_PRINTF("ADP timeout interrupt\n");
  77748. + retval |= dwc_otg_adp_handle_prb_tmout_intr(core_if, adpctl.d32);
  77749. + }
  77750. + if (adpctl.b.adp_prb_int & adpctl.b.adp_prb_int_msk) {
  77751. + DWC_PRINTF("ADP Probe interrupt\n");
  77752. + adpctl.b.adp_prb_int = 1;
  77753. + retval |= dwc_otg_adp_handle_prb_intr(core_if, adpctl.d32);
  77754. + }
  77755. +
  77756. +// dwc_otg_adp_modify_reg(core_if, adpctl.d32, 0);
  77757. + //dwc_otg_adp_write_reg(core_if, adpctl.d32);
  77758. + DWC_PRINTF("RETURN FROM ADP ISR\n");
  77759. +
  77760. + return retval;
  77761. +}
  77762. +
  77763. +/**
  77764. + *
  77765. + * @param core_if Programming view of DWC_otg controller.
  77766. + */
  77767. +int32_t dwc_otg_adp_handle_srp_intr(dwc_otg_core_if_t * core_if)
  77768. +{
  77769. +
  77770. +#ifndef DWC_HOST_ONLY
  77771. + hprt0_data_t hprt0;
  77772. + gpwrdn_data_t gpwrdn;
  77773. + DWC_DEBUGPL(DBG_ANY, "++ Power Down Logic Session Request Interrupt++\n");
  77774. +
  77775. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  77776. + /* check which value is for device mode and which for Host mode */
  77777. + if (!gpwrdn.b.idsts) { /* considered host mode value is 0 */
  77778. + DWC_PRINTF("SRP: Host mode\n");
  77779. +
  77780. + if (core_if->adp_enable) {
  77781. + dwc_otg_adp_probe_stop(core_if);
  77782. +
  77783. + /* Power on the core */
  77784. + if (core_if->power_down == 2) {
  77785. + gpwrdn.b.pwrdnswtch = 1;
  77786. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  77787. + gpwrdn, 0, gpwrdn.d32);
  77788. + }
  77789. +
  77790. + core_if->op_state = A_HOST;
  77791. + dwc_otg_core_init(core_if);
  77792. + dwc_otg_enable_global_interrupts(core_if);
  77793. + cil_hcd_start(core_if);
  77794. + }
  77795. +
  77796. + /* Turn on the port power bit. */
  77797. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  77798. + hprt0.b.prtpwr = 1;
  77799. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  77800. +
  77801. + /* Start the Connection timer. So a message can be displayed
  77802. + * if connect does not occur within 10 seconds. */
  77803. + cil_hcd_session_start(core_if);
  77804. + } else {
  77805. + DWC_PRINTF("SRP: Device mode %s\n", __FUNCTION__);
  77806. + if (core_if->adp_enable) {
  77807. + dwc_otg_adp_probe_stop(core_if);
  77808. +
  77809. + /* Power on the core */
  77810. + if (core_if->power_down == 2) {
  77811. + gpwrdn.b.pwrdnswtch = 1;
  77812. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  77813. + gpwrdn, 0, gpwrdn.d32);
  77814. + }
  77815. +
  77816. + gpwrdn.d32 = 0;
  77817. + gpwrdn.b.pmuactv = 0;
  77818. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0,
  77819. + gpwrdn.d32);
  77820. +
  77821. + core_if->op_state = B_PERIPHERAL;
  77822. + dwc_otg_core_init(core_if);
  77823. + dwc_otg_enable_global_interrupts(core_if);
  77824. + cil_pcd_start(core_if);
  77825. + }
  77826. + }
  77827. +#endif
  77828. + return 1;
  77829. +}
  77830. diff -Nur linux-3.18.8/drivers/usb/host/dwc_otg/dwc_otg_adp.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_adp.h
  77831. --- linux-3.18.8/drivers/usb/host/dwc_otg/dwc_otg_adp.h 1970-01-01 01:00:00.000000000 +0100
  77832. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_adp.h 2015-03-05 14:40:16.557715806 +0100
  77833. @@ -0,0 +1,80 @@
  77834. +/* ==========================================================================
  77835. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_adp.h $
  77836. + * $Revision: #7 $
  77837. + * $Date: 2011/10/24 $
  77838. + * $Change: 1871159 $
  77839. + *
  77840. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  77841. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  77842. + * otherwise expressly agreed to in writing between Synopsys and you.
  77843. + *
  77844. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  77845. + * any End User Software License Agreement or Agreement for Licensed Product
  77846. + * with Synopsys or any supplement thereto. You are permitted to use and
  77847. + * redistribute this Software in source and binary forms, with or without
  77848. + * modification, provided that redistributions of source code must retain this
  77849. + * notice. You may not view, use, disclose, copy or distribute this file or
  77850. + * any information contained herein except pursuant to this license grant from
  77851. + * Synopsys. If you do not agree with this notice, including the disclaimer
  77852. + * below, then you are not authorized to use the Software.
  77853. + *
  77854. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  77855. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  77856. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  77857. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  77858. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  77859. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  77860. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  77861. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  77862. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  77863. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  77864. + * DAMAGE.
  77865. + * ========================================================================== */
  77866. +
  77867. +#ifndef __DWC_OTG_ADP_H__
  77868. +#define __DWC_OTG_ADP_H__
  77869. +
  77870. +/**
  77871. + * @file
  77872. + *
  77873. + * This file contains the Attach Detect Protocol interfaces and defines
  77874. + * (functions) and structures for Linux.
  77875. + *
  77876. + */
  77877. +
  77878. +#define DWC_OTG_ADP_UNATTACHED 0
  77879. +#define DWC_OTG_ADP_ATTACHED 1
  77880. +#define DWC_OTG_ADP_UNKOWN 2
  77881. +
  77882. +typedef struct dwc_otg_adp {
  77883. + uint32_t adp_started;
  77884. + uint32_t initial_probe;
  77885. + int32_t probe_timer_values[2];
  77886. + uint32_t probe_enabled;
  77887. + uint32_t sense_enabled;
  77888. + dwc_timer_t *sense_timer;
  77889. + uint32_t sense_timer_started;
  77890. + dwc_timer_t *vbuson_timer;
  77891. + uint32_t vbuson_timer_started;
  77892. + uint32_t attached;
  77893. + uint32_t probe_counter;
  77894. + uint32_t gpwrdn;
  77895. +} dwc_otg_adp_t;
  77896. +
  77897. +/**
  77898. + * Attach Detect Protocol functions
  77899. + */
  77900. +
  77901. +extern void dwc_otg_adp_write_reg(dwc_otg_core_if_t * core_if, uint32_t value);
  77902. +extern uint32_t dwc_otg_adp_read_reg(dwc_otg_core_if_t * core_if);
  77903. +extern uint32_t dwc_otg_adp_probe_start(dwc_otg_core_if_t * core_if);
  77904. +extern uint32_t dwc_otg_adp_sense_start(dwc_otg_core_if_t * core_if);
  77905. +extern uint32_t dwc_otg_adp_probe_stop(dwc_otg_core_if_t * core_if);
  77906. +extern uint32_t dwc_otg_adp_sense_stop(dwc_otg_core_if_t * core_if);
  77907. +extern void dwc_otg_adp_start(dwc_otg_core_if_t * core_if, uint8_t is_host);
  77908. +extern void dwc_otg_adp_init(dwc_otg_core_if_t * core_if);
  77909. +extern void dwc_otg_adp_remove(dwc_otg_core_if_t * core_if);
  77910. +extern int32_t dwc_otg_adp_handle_intr(dwc_otg_core_if_t * core_if);
  77911. +extern int32_t dwc_otg_adp_handle_srp_intr(dwc_otg_core_if_t * core_if);
  77912. +
  77913. +#endif //__DWC_OTG_ADP_H__
  77914. diff -Nur linux-3.18.8/drivers/usb/host/dwc_otg/dwc_otg_attr.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_attr.c
  77915. --- linux-3.18.8/drivers/usb/host/dwc_otg/dwc_otg_attr.c 1970-01-01 01:00:00.000000000 +0100
  77916. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_attr.c 2015-03-05 14:40:16.557715806 +0100
  77917. @@ -0,0 +1,1210 @@
  77918. +/* ==========================================================================
  77919. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_attr.c $
  77920. + * $Revision: #44 $
  77921. + * $Date: 2010/11/29 $
  77922. + * $Change: 1636033 $
  77923. + *
  77924. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  77925. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  77926. + * otherwise expressly agreed to in writing between Synopsys and you.
  77927. + *
  77928. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  77929. + * any End User Software License Agreement or Agreement for Licensed Product
  77930. + * with Synopsys or any supplement thereto. You are permitted to use and
  77931. + * redistribute this Software in source and binary forms, with or without
  77932. + * modification, provided that redistributions of source code must retain this
  77933. + * notice. You may not view, use, disclose, copy or distribute this file or
  77934. + * any information contained herein except pursuant to this license grant from
  77935. + * Synopsys. If you do not agree with this notice, including the disclaimer
  77936. + * below, then you are not authorized to use the Software.
  77937. + *
  77938. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  77939. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  77940. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  77941. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  77942. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  77943. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  77944. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  77945. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  77946. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  77947. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  77948. + * DAMAGE.
  77949. + * ========================================================================== */
  77950. +
  77951. +/** @file
  77952. + *
  77953. + * The diagnostic interface will provide access to the controller for
  77954. + * bringing up the hardware and testing. The Linux driver attributes
  77955. + * feature will be used to provide the Linux Diagnostic
  77956. + * Interface. These attributes are accessed through sysfs.
  77957. + */
  77958. +
  77959. +/** @page "Linux Module Attributes"
  77960. + *
  77961. + * The Linux module attributes feature is used to provide the Linux
  77962. + * Diagnostic Interface. These attributes are accessed through sysfs.
  77963. + * The diagnostic interface will provide access to the controller for
  77964. + * bringing up the hardware and testing.
  77965. +
  77966. + The following table shows the attributes.
  77967. + <table>
  77968. + <tr>
  77969. + <td><b> Name</b></td>
  77970. + <td><b> Description</b></td>
  77971. + <td><b> Access</b></td>
  77972. + </tr>
  77973. +
  77974. + <tr>
  77975. + <td> mode </td>
  77976. + <td> Returns the current mode: 0 for device mode, 1 for host mode</td>
  77977. + <td> Read</td>
  77978. + </tr>
  77979. +
  77980. + <tr>
  77981. + <td> hnpcapable </td>
  77982. + <td> Gets or sets the "HNP-capable" bit in the Core USB Configuraton Register.
  77983. + Read returns the current value.</td>
  77984. + <td> Read/Write</td>
  77985. + </tr>
  77986. +
  77987. + <tr>
  77988. + <td> srpcapable </td>
  77989. + <td> Gets or sets the "SRP-capable" bit in the Core USB Configuraton Register.
  77990. + Read returns the current value.</td>
  77991. + <td> Read/Write</td>
  77992. + </tr>
  77993. +
  77994. + <tr>
  77995. + <td> hsic_connect </td>
  77996. + <td> Gets or sets the "HSIC-Connect" bit in the GLPMCFG Register.
  77997. + Read returns the current value.</td>
  77998. + <td> Read/Write</td>
  77999. + </tr>
  78000. +
  78001. + <tr>
  78002. + <td> inv_sel_hsic </td>
  78003. + <td> Gets or sets the "Invert Select HSIC" bit in the GLPMFG Register.
  78004. + Read returns the current value.</td>
  78005. + <td> Read/Write</td>
  78006. + </tr>
  78007. +
  78008. + <tr>
  78009. + <td> hnp </td>
  78010. + <td> Initiates the Host Negotiation Protocol. Read returns the status.</td>
  78011. + <td> Read/Write</td>
  78012. + </tr>
  78013. +
  78014. + <tr>
  78015. + <td> srp </td>
  78016. + <td> Initiates the Session Request Protocol. Read returns the status.</td>
  78017. + <td> Read/Write</td>
  78018. + </tr>
  78019. +
  78020. + <tr>
  78021. + <td> buspower </td>
  78022. + <td> Gets or sets the Power State of the bus (0 - Off or 1 - On)</td>
  78023. + <td> Read/Write</td>
  78024. + </tr>
  78025. +
  78026. + <tr>
  78027. + <td> bussuspend </td>
  78028. + <td> Suspends the USB bus.</td>
  78029. + <td> Read/Write</td>
  78030. + </tr>
  78031. +
  78032. + <tr>
  78033. + <td> busconnected </td>
  78034. + <td> Gets the connection status of the bus</td>
  78035. + <td> Read</td>
  78036. + </tr>
  78037. +
  78038. + <tr>
  78039. + <td> gotgctl </td>
  78040. + <td> Gets or sets the Core Control Status Register.</td>
  78041. + <td> Read/Write</td>
  78042. + </tr>
  78043. +
  78044. + <tr>
  78045. + <td> gusbcfg </td>
  78046. + <td> Gets or sets the Core USB Configuration Register</td>
  78047. + <td> Read/Write</td>
  78048. + </tr>
  78049. +
  78050. + <tr>
  78051. + <td> grxfsiz </td>
  78052. + <td> Gets or sets the Receive FIFO Size Register</td>
  78053. + <td> Read/Write</td>
  78054. + </tr>
  78055. +
  78056. + <tr>
  78057. + <td> gnptxfsiz </td>
  78058. + <td> Gets or sets the non-periodic Transmit Size Register</td>
  78059. + <td> Read/Write</td>
  78060. + </tr>
  78061. +
  78062. + <tr>
  78063. + <td> gpvndctl </td>
  78064. + <td> Gets or sets the PHY Vendor Control Register</td>
  78065. + <td> Read/Write</td>
  78066. + </tr>
  78067. +
  78068. + <tr>
  78069. + <td> ggpio </td>
  78070. + <td> Gets the value in the lower 16-bits of the General Purpose IO Register
  78071. + or sets the upper 16 bits.</td>
  78072. + <td> Read/Write</td>
  78073. + </tr>
  78074. +
  78075. + <tr>
  78076. + <td> guid </td>
  78077. + <td> Gets or sets the value of the User ID Register</td>
  78078. + <td> Read/Write</td>
  78079. + </tr>
  78080. +
  78081. + <tr>
  78082. + <td> gsnpsid </td>
  78083. + <td> Gets the value of the Synopsys ID Regester</td>
  78084. + <td> Read</td>
  78085. + </tr>
  78086. +
  78087. + <tr>
  78088. + <td> devspeed </td>
  78089. + <td> Gets or sets the device speed setting in the DCFG register</td>
  78090. + <td> Read/Write</td>
  78091. + </tr>
  78092. +
  78093. + <tr>
  78094. + <td> enumspeed </td>
  78095. + <td> Gets the device enumeration Speed.</td>
  78096. + <td> Read</td>
  78097. + </tr>
  78098. +
  78099. + <tr>
  78100. + <td> hptxfsiz </td>
  78101. + <td> Gets the value of the Host Periodic Transmit FIFO</td>
  78102. + <td> Read</td>
  78103. + </tr>
  78104. +
  78105. + <tr>
  78106. + <td> hprt0 </td>
  78107. + <td> Gets or sets the value in the Host Port Control and Status Register</td>
  78108. + <td> Read/Write</td>
  78109. + </tr>
  78110. +
  78111. + <tr>
  78112. + <td> regoffset </td>
  78113. + <td> Sets the register offset for the next Register Access</td>
  78114. + <td> Read/Write</td>
  78115. + </tr>
  78116. +
  78117. + <tr>
  78118. + <td> regvalue </td>
  78119. + <td> Gets or sets the value of the register at the offset in the regoffset attribute.</td>
  78120. + <td> Read/Write</td>
  78121. + </tr>
  78122. +
  78123. + <tr>
  78124. + <td> remote_wakeup </td>
  78125. + <td> On read, shows the status of Remote Wakeup. On write, initiates a remote
  78126. + wakeup of the host. When bit 0 is 1 and Remote Wakeup is enabled, the Remote
  78127. + Wakeup signalling bit in the Device Control Register is set for 1
  78128. + milli-second.</td>
  78129. + <td> Read/Write</td>
  78130. + </tr>
  78131. +
  78132. + <tr>
  78133. + <td> rem_wakeup_pwrdn </td>
  78134. + <td> On read, shows the status core - hibernated or not. On write, initiates
  78135. + a remote wakeup of the device from Hibernation. </td>
  78136. + <td> Read/Write</td>
  78137. + </tr>
  78138. +
  78139. + <tr>
  78140. + <td> mode_ch_tim_en </td>
  78141. + <td> This bit is used to enable or disable the host core to wait for 200 PHY
  78142. + clock cycles at the end of Resume to change the opmode signal to the PHY to 00
  78143. + after Suspend or LPM. </td>
  78144. + <td> Read/Write</td>
  78145. + </tr>
  78146. +
  78147. + <tr>
  78148. + <td> fr_interval </td>
  78149. + <td> On read, shows the value of HFIR Frame Interval. On write, dynamically
  78150. + reload HFIR register during runtime. The application can write a value to this
  78151. + register only after the Port Enable bit of the Host Port Control and Status
  78152. + register (HPRT.PrtEnaPort) has been set </td>
  78153. + <td> Read/Write</td>
  78154. + </tr>
  78155. +
  78156. + <tr>
  78157. + <td> disconnect_us </td>
  78158. + <td> On read, shows the status of disconnect_device_us. On write, sets disconnect_us
  78159. + which causes soft disconnect for 100us. Applicable only for device mode of operation.</td>
  78160. + <td> Read/Write</td>
  78161. + </tr>
  78162. +
  78163. + <tr>
  78164. + <td> regdump </td>
  78165. + <td> Dumps the contents of core registers.</td>
  78166. + <td> Read</td>
  78167. + </tr>
  78168. +
  78169. + <tr>
  78170. + <td> spramdump </td>
  78171. + <td> Dumps the contents of core registers.</td>
  78172. + <td> Read</td>
  78173. + </tr>
  78174. +
  78175. + <tr>
  78176. + <td> hcddump </td>
  78177. + <td> Dumps the current HCD state.</td>
  78178. + <td> Read</td>
  78179. + </tr>
  78180. +
  78181. + <tr>
  78182. + <td> hcd_frrem </td>
  78183. + <td> Shows the average value of the Frame Remaining
  78184. + field in the Host Frame Number/Frame Remaining register when an SOF interrupt
  78185. + occurs. This can be used to determine the average interrupt latency. Also
  78186. + shows the average Frame Remaining value for start_transfer and the "a" and
  78187. + "b" sample points. The "a" and "b" sample points may be used during debugging
  78188. + bto determine how long it takes to execute a section of the HCD code.</td>
  78189. + <td> Read</td>
  78190. + </tr>
  78191. +
  78192. + <tr>
  78193. + <td> rd_reg_test </td>
  78194. + <td> Displays the time required to read the GNPTXFSIZ register many times
  78195. + (the output shows the number of times the register is read).
  78196. + <td> Read</td>
  78197. + </tr>
  78198. +
  78199. + <tr>
  78200. + <td> wr_reg_test </td>
  78201. + <td> Displays the time required to write the GNPTXFSIZ register many times
  78202. + (the output shows the number of times the register is written).
  78203. + <td> Read</td>
  78204. + </tr>
  78205. +
  78206. + <tr>
  78207. + <td> lpm_response </td>
  78208. + <td> Gets or sets lpm_response mode. Applicable only in device mode.
  78209. + <td> Write</td>
  78210. + </tr>
  78211. +
  78212. + <tr>
  78213. + <td> sleep_status </td>
  78214. + <td> Shows sleep status of device.
  78215. + <td> Read</td>
  78216. + </tr>
  78217. +
  78218. + </table>
  78219. +
  78220. + Example usage:
  78221. + To get the current mode:
  78222. + cat /sys/devices/lm0/mode
  78223. +
  78224. + To power down the USB:
  78225. + echo 0 > /sys/devices/lm0/buspower
  78226. + */
  78227. +
  78228. +#include "dwc_otg_os_dep.h"
  78229. +#include "dwc_os.h"
  78230. +#include "dwc_otg_driver.h"
  78231. +#include "dwc_otg_attr.h"
  78232. +#include "dwc_otg_core_if.h"
  78233. +#include "dwc_otg_pcd_if.h"
  78234. +#include "dwc_otg_hcd_if.h"
  78235. +
  78236. +/*
  78237. + * MACROs for defining sysfs attribute
  78238. + */
  78239. +#ifdef LM_INTERFACE
  78240. +
  78241. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_string_) \
  78242. +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
  78243. +{ \
  78244. + struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev); \
  78245. + dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev); \
  78246. + uint32_t val; \
  78247. + val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
  78248. + return sprintf (buf, "%s = 0x%x\n", _string_, val); \
  78249. +}
  78250. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_STORE(_otg_attr_name_,_string_) \
  78251. +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
  78252. + const char *buf, size_t count) \
  78253. +{ \
  78254. + struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev); \
  78255. + dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev); \
  78256. + uint32_t set = simple_strtoul(buf, NULL, 16); \
  78257. + dwc_otg_set_##_otg_attr_name_(otg_dev->core_if, set);\
  78258. + return count; \
  78259. +}
  78260. +
  78261. +#elif defined(PCI_INTERFACE)
  78262. +
  78263. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_string_) \
  78264. +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
  78265. +{ \
  78266. + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev); \
  78267. + uint32_t val; \
  78268. + val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
  78269. + return sprintf (buf, "%s = 0x%x\n", _string_, val); \
  78270. +}
  78271. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_STORE(_otg_attr_name_,_string_) \
  78272. +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
  78273. + const char *buf, size_t count) \
  78274. +{ \
  78275. + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev); \
  78276. + uint32_t set = simple_strtoul(buf, NULL, 16); \
  78277. + dwc_otg_set_##_otg_attr_name_(otg_dev->core_if, set);\
  78278. + return count; \
  78279. +}
  78280. +
  78281. +#elif defined(PLATFORM_INTERFACE)
  78282. +
  78283. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_string_) \
  78284. +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
  78285. +{ \
  78286. + struct platform_device *platform_dev = \
  78287. + container_of(_dev, struct platform_device, dev); \
  78288. + dwc_otg_device_t *otg_dev = platform_get_drvdata(platform_dev); \
  78289. + uint32_t val; \
  78290. + DWC_PRINTF("%s(%p) -> platform_dev %p, otg_dev %p\n", \
  78291. + __func__, _dev, platform_dev, otg_dev); \
  78292. + val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
  78293. + return sprintf (buf, "%s = 0x%x\n", _string_, val); \
  78294. +}
  78295. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_STORE(_otg_attr_name_,_string_) \
  78296. +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
  78297. + const char *buf, size_t count) \
  78298. +{ \
  78299. + struct platform_device *platform_dev = container_of(_dev, struct platform_device, dev); \
  78300. + dwc_otg_device_t *otg_dev = platform_get_drvdata(platform_dev); \
  78301. + uint32_t set = simple_strtoul(buf, NULL, 16); \
  78302. + dwc_otg_set_##_otg_attr_name_(otg_dev->core_if, set);\
  78303. + return count; \
  78304. +}
  78305. +#endif
  78306. +
  78307. +/*
  78308. + * MACROs for defining sysfs attribute for 32-bit registers
  78309. + */
  78310. +#ifdef LM_INTERFACE
  78311. +#define DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_string_) \
  78312. +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
  78313. +{ \
  78314. + struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev); \
  78315. + dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev); \
  78316. + uint32_t val; \
  78317. + val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
  78318. + return sprintf (buf, "%s = 0x%08x\n", _string_, val); \
  78319. +}
  78320. +#define DWC_OTG_DEVICE_ATTR_REG_STORE(_otg_attr_name_,_string_) \
  78321. +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
  78322. + const char *buf, size_t count) \
  78323. +{ \
  78324. + struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev); \
  78325. + dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev); \
  78326. + uint32_t val = simple_strtoul(buf, NULL, 16); \
  78327. + dwc_otg_set_##_otg_attr_name_ (otg_dev->core_if, val); \
  78328. + return count; \
  78329. +}
  78330. +#elif defined(PCI_INTERFACE)
  78331. +#define DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_string_) \
  78332. +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
  78333. +{ \
  78334. + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev); \
  78335. + uint32_t val; \
  78336. + val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
  78337. + return sprintf (buf, "%s = 0x%08x\n", _string_, val); \
  78338. +}
  78339. +#define DWC_OTG_DEVICE_ATTR_REG_STORE(_otg_attr_name_,_string_) \
  78340. +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
  78341. + const char *buf, size_t count) \
  78342. +{ \
  78343. + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev); \
  78344. + uint32_t val = simple_strtoul(buf, NULL, 16); \
  78345. + dwc_otg_set_##_otg_attr_name_ (otg_dev->core_if, val); \
  78346. + return count; \
  78347. +}
  78348. +
  78349. +#elif defined(PLATFORM_INTERFACE)
  78350. +#include "dwc_otg_dbg.h"
  78351. +#define DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_string_) \
  78352. +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
  78353. +{ \
  78354. + struct platform_device *platform_dev = container_of(_dev, struct platform_device, dev); \
  78355. + dwc_otg_device_t *otg_dev = platform_get_drvdata(platform_dev); \
  78356. + uint32_t val; \
  78357. + DWC_PRINTF("%s(%p) -> platform_dev %p, otg_dev %p\n", \
  78358. + __func__, _dev, platform_dev, otg_dev); \
  78359. + val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
  78360. + return sprintf (buf, "%s = 0x%08x\n", _string_, val); \
  78361. +}
  78362. +#define DWC_OTG_DEVICE_ATTR_REG_STORE(_otg_attr_name_,_string_) \
  78363. +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
  78364. + const char *buf, size_t count) \
  78365. +{ \
  78366. + struct platform_device *platform_dev = container_of(_dev, struct platform_device, dev); \
  78367. + dwc_otg_device_t *otg_dev = platform_get_drvdata(platform_dev); \
  78368. + uint32_t val = simple_strtoul(buf, NULL, 16); \
  78369. + dwc_otg_set_##_otg_attr_name_ (otg_dev->core_if, val); \
  78370. + return count; \
  78371. +}
  78372. +
  78373. +#endif
  78374. +
  78375. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_RW(_otg_attr_name_,_string_) \
  78376. +DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_string_) \
  78377. +DWC_OTG_DEVICE_ATTR_BITFIELD_STORE(_otg_attr_name_,_string_) \
  78378. +DEVICE_ATTR(_otg_attr_name_,0644,_otg_attr_name_##_show,_otg_attr_name_##_store);
  78379. +
  78380. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_RO(_otg_attr_name_,_string_) \
  78381. +DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_string_) \
  78382. +DEVICE_ATTR(_otg_attr_name_,0444,_otg_attr_name_##_show,NULL);
  78383. +
  78384. +#define DWC_OTG_DEVICE_ATTR_REG32_RW(_otg_attr_name_,_addr_,_string_) \
  78385. +DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_string_) \
  78386. +DWC_OTG_DEVICE_ATTR_REG_STORE(_otg_attr_name_,_string_) \
  78387. +DEVICE_ATTR(_otg_attr_name_,0644,_otg_attr_name_##_show,_otg_attr_name_##_store);
  78388. +
  78389. +#define DWC_OTG_DEVICE_ATTR_REG32_RO(_otg_attr_name_,_addr_,_string_) \
  78390. +DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_string_) \
  78391. +DEVICE_ATTR(_otg_attr_name_,0444,_otg_attr_name_##_show,NULL);
  78392. +
  78393. +/** @name Functions for Show/Store of Attributes */
  78394. +/**@{*/
  78395. +
  78396. +/**
  78397. + * Helper function returning the otg_device structure of the given device
  78398. + */
  78399. +static dwc_otg_device_t *dwc_otg_drvdev(struct device *_dev)
  78400. +{
  78401. + dwc_otg_device_t *otg_dev;
  78402. + DWC_OTG_GETDRVDEV(otg_dev, _dev);
  78403. + return otg_dev;
  78404. +}
  78405. +
  78406. +/**
  78407. + * Show the register offset of the Register Access.
  78408. + */
  78409. +static ssize_t regoffset_show(struct device *_dev,
  78410. + struct device_attribute *attr, char *buf)
  78411. +{
  78412. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  78413. + return snprintf(buf, sizeof("0xFFFFFFFF\n") + 1, "0x%08x\n",
  78414. + otg_dev->os_dep.reg_offset);
  78415. +}
  78416. +
  78417. +/**
  78418. + * Set the register offset for the next Register Access Read/Write
  78419. + */
  78420. +static ssize_t regoffset_store(struct device *_dev,
  78421. + struct device_attribute *attr,
  78422. + const char *buf, size_t count)
  78423. +{
  78424. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  78425. + uint32_t offset = simple_strtoul(buf, NULL, 16);
  78426. +#if defined(LM_INTERFACE) || defined(PLATFORM_INTERFACE)
  78427. + if (offset < SZ_256K) {
  78428. +#elif defined(PCI_INTERFACE)
  78429. + if (offset < 0x00040000) {
  78430. +#endif
  78431. + otg_dev->os_dep.reg_offset = offset;
  78432. + } else {
  78433. + dev_err(_dev, "invalid offset\n");
  78434. + }
  78435. +
  78436. + return count;
  78437. +}
  78438. +
  78439. +DEVICE_ATTR(regoffset, S_IRUGO | S_IWUSR, regoffset_show, regoffset_store);
  78440. +
  78441. +/**
  78442. + * Show the value of the register at the offset in the reg_offset
  78443. + * attribute.
  78444. + */
  78445. +static ssize_t regvalue_show(struct device *_dev,
  78446. + struct device_attribute *attr, char *buf)
  78447. +{
  78448. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  78449. + uint32_t val;
  78450. + volatile uint32_t *addr;
  78451. +
  78452. + if (otg_dev->os_dep.reg_offset != 0xFFFFFFFF && 0 != otg_dev->os_dep.base) {
  78453. + /* Calculate the address */
  78454. + addr = (uint32_t *) (otg_dev->os_dep.reg_offset +
  78455. + (uint8_t *) otg_dev->os_dep.base);
  78456. + val = DWC_READ_REG32(addr);
  78457. + return snprintf(buf,
  78458. + sizeof("Reg@0xFFFFFFFF = 0xFFFFFFFF\n") + 1,
  78459. + "Reg@0x%06x = 0x%08x\n", otg_dev->os_dep.reg_offset,
  78460. + val);
  78461. + } else {
  78462. + dev_err(_dev, "Invalid offset (0x%0x)\n", otg_dev->os_dep.reg_offset);
  78463. + return sprintf(buf, "invalid offset\n");
  78464. + }
  78465. +}
  78466. +
  78467. +/**
  78468. + * Store the value in the register at the offset in the reg_offset
  78469. + * attribute.
  78470. + *
  78471. + */
  78472. +static ssize_t regvalue_store(struct device *_dev,
  78473. + struct device_attribute *attr,
  78474. + const char *buf, size_t count)
  78475. +{
  78476. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  78477. + volatile uint32_t *addr;
  78478. + uint32_t val = simple_strtoul(buf, NULL, 16);
  78479. + //dev_dbg(_dev, "Offset=0x%08x Val=0x%08x\n", otg_dev->reg_offset, val);
  78480. + if (otg_dev->os_dep.reg_offset != 0xFFFFFFFF && 0 != otg_dev->os_dep.base) {
  78481. + /* Calculate the address */
  78482. + addr = (uint32_t *) (otg_dev->os_dep.reg_offset +
  78483. + (uint8_t *) otg_dev->os_dep.base);
  78484. + DWC_WRITE_REG32(addr, val);
  78485. + } else {
  78486. + dev_err(_dev, "Invalid Register Offset (0x%08x)\n",
  78487. + otg_dev->os_dep.reg_offset);
  78488. + }
  78489. + return count;
  78490. +}
  78491. +
  78492. +DEVICE_ATTR(regvalue, S_IRUGO | S_IWUSR, regvalue_show, regvalue_store);
  78493. +
  78494. +/*
  78495. + * Attributes
  78496. + */
  78497. +DWC_OTG_DEVICE_ATTR_BITFIELD_RO(mode, "Mode");
  78498. +DWC_OTG_DEVICE_ATTR_BITFIELD_RW(hnpcapable, "HNPCapable");
  78499. +DWC_OTG_DEVICE_ATTR_BITFIELD_RW(srpcapable, "SRPCapable");
  78500. +DWC_OTG_DEVICE_ATTR_BITFIELD_RW(hsic_connect, "HSIC Connect");
  78501. +DWC_OTG_DEVICE_ATTR_BITFIELD_RW(inv_sel_hsic, "Invert Select HSIC");
  78502. +
  78503. +//DWC_OTG_DEVICE_ATTR_BITFIELD_RW(buspower,&(otg_dev->core_if->core_global_regs->gotgctl),(1<<8),8,"Mode");
  78504. +//DWC_OTG_DEVICE_ATTR_BITFIELD_RW(bussuspend,&(otg_dev->core_if->core_global_regs->gotgctl),(1<<8),8,"Mode");
  78505. +DWC_OTG_DEVICE_ATTR_BITFIELD_RO(busconnected, "Bus Connected");
  78506. +
  78507. +DWC_OTG_DEVICE_ATTR_REG32_RW(gotgctl, 0, "GOTGCTL");
  78508. +DWC_OTG_DEVICE_ATTR_REG32_RW(gusbcfg,
  78509. + &(otg_dev->core_if->core_global_regs->gusbcfg),
  78510. + "GUSBCFG");
  78511. +DWC_OTG_DEVICE_ATTR_REG32_RW(grxfsiz,
  78512. + &(otg_dev->core_if->core_global_regs->grxfsiz),
  78513. + "GRXFSIZ");
  78514. +DWC_OTG_DEVICE_ATTR_REG32_RW(gnptxfsiz,
  78515. + &(otg_dev->core_if->core_global_regs->gnptxfsiz),
  78516. + "GNPTXFSIZ");
  78517. +DWC_OTG_DEVICE_ATTR_REG32_RW(gpvndctl,
  78518. + &(otg_dev->core_if->core_global_regs->gpvndctl),
  78519. + "GPVNDCTL");
  78520. +DWC_OTG_DEVICE_ATTR_REG32_RW(ggpio,
  78521. + &(otg_dev->core_if->core_global_regs->ggpio),
  78522. + "GGPIO");
  78523. +DWC_OTG_DEVICE_ATTR_REG32_RW(guid, &(otg_dev->core_if->core_global_regs->guid),
  78524. + "GUID");
  78525. +DWC_OTG_DEVICE_ATTR_REG32_RO(gsnpsid,
  78526. + &(otg_dev->core_if->core_global_regs->gsnpsid),
  78527. + "GSNPSID");
  78528. +DWC_OTG_DEVICE_ATTR_BITFIELD_RW(devspeed, "Device Speed");
  78529. +DWC_OTG_DEVICE_ATTR_BITFIELD_RO(enumspeed, "Device Enumeration Speed");
  78530. +
  78531. +DWC_OTG_DEVICE_ATTR_REG32_RO(hptxfsiz,
  78532. + &(otg_dev->core_if->core_global_regs->hptxfsiz),
  78533. + "HPTXFSIZ");
  78534. +DWC_OTG_DEVICE_ATTR_REG32_RW(hprt0, otg_dev->core_if->host_if->hprt0, "HPRT0");
  78535. +
  78536. +/**
  78537. + * @todo Add code to initiate the HNP.
  78538. + */
  78539. +/**
  78540. + * Show the HNP status bit
  78541. + */
  78542. +static ssize_t hnp_show(struct device *_dev,
  78543. + struct device_attribute *attr, char *buf)
  78544. +{
  78545. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  78546. + return sprintf(buf, "HstNegScs = 0x%x\n",
  78547. + dwc_otg_get_hnpstatus(otg_dev->core_if));
  78548. +}
  78549. +
  78550. +/**
  78551. + * Set the HNP Request bit
  78552. + */
  78553. +static ssize_t hnp_store(struct device *_dev,
  78554. + struct device_attribute *attr,
  78555. + const char *buf, size_t count)
  78556. +{
  78557. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  78558. + uint32_t in = simple_strtoul(buf, NULL, 16);
  78559. + dwc_otg_set_hnpreq(otg_dev->core_if, in);
  78560. + return count;
  78561. +}
  78562. +
  78563. +DEVICE_ATTR(hnp, 0644, hnp_show, hnp_store);
  78564. +
  78565. +/**
  78566. + * @todo Add code to initiate the SRP.
  78567. + */
  78568. +/**
  78569. + * Show the SRP status bit
  78570. + */
  78571. +static ssize_t srp_show(struct device *_dev,
  78572. + struct device_attribute *attr, char *buf)
  78573. +{
  78574. +#ifndef DWC_HOST_ONLY
  78575. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  78576. + return sprintf(buf, "SesReqScs = 0x%x\n",
  78577. + dwc_otg_get_srpstatus(otg_dev->core_if));
  78578. +#else
  78579. + return sprintf(buf, "Host Only Mode!\n");
  78580. +#endif
  78581. +}
  78582. +
  78583. +/**
  78584. + * Set the SRP Request bit
  78585. + */
  78586. +static ssize_t srp_store(struct device *_dev,
  78587. + struct device_attribute *attr,
  78588. + const char *buf, size_t count)
  78589. +{
  78590. +#ifndef DWC_HOST_ONLY
  78591. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  78592. + dwc_otg_pcd_initiate_srp(otg_dev->pcd);
  78593. +#endif
  78594. + return count;
  78595. +}
  78596. +
  78597. +DEVICE_ATTR(srp, 0644, srp_show, srp_store);
  78598. +
  78599. +/**
  78600. + * @todo Need to do more for power on/off?
  78601. + */
  78602. +/**
  78603. + * Show the Bus Power status
  78604. + */
  78605. +static ssize_t buspower_show(struct device *_dev,
  78606. + struct device_attribute *attr, char *buf)
  78607. +{
  78608. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  78609. + return sprintf(buf, "Bus Power = 0x%x\n",
  78610. + dwc_otg_get_prtpower(otg_dev->core_if));
  78611. +}
  78612. +
  78613. +/**
  78614. + * Set the Bus Power status
  78615. + */
  78616. +static ssize_t buspower_store(struct device *_dev,
  78617. + struct device_attribute *attr,
  78618. + const char *buf, size_t count)
  78619. +{
  78620. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  78621. + uint32_t on = simple_strtoul(buf, NULL, 16);
  78622. + dwc_otg_set_prtpower(otg_dev->core_if, on);
  78623. + return count;
  78624. +}
  78625. +
  78626. +DEVICE_ATTR(buspower, 0644, buspower_show, buspower_store);
  78627. +
  78628. +/**
  78629. + * @todo Need to do more for suspend?
  78630. + */
  78631. +/**
  78632. + * Show the Bus Suspend status
  78633. + */
  78634. +static ssize_t bussuspend_show(struct device *_dev,
  78635. + struct device_attribute *attr, char *buf)
  78636. +{
  78637. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  78638. + return sprintf(buf, "Bus Suspend = 0x%x\n",
  78639. + dwc_otg_get_prtsuspend(otg_dev->core_if));
  78640. +}
  78641. +
  78642. +/**
  78643. + * Set the Bus Suspend status
  78644. + */
  78645. +static ssize_t bussuspend_store(struct device *_dev,
  78646. + struct device_attribute *attr,
  78647. + const char *buf, size_t count)
  78648. +{
  78649. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  78650. + uint32_t in = simple_strtoul(buf, NULL, 16);
  78651. + dwc_otg_set_prtsuspend(otg_dev->core_if, in);
  78652. + return count;
  78653. +}
  78654. +
  78655. +DEVICE_ATTR(bussuspend, 0644, bussuspend_show, bussuspend_store);
  78656. +
  78657. +/**
  78658. + * Show the Mode Change Ready Timer status
  78659. + */
  78660. +static ssize_t mode_ch_tim_en_show(struct device *_dev,
  78661. + struct device_attribute *attr, char *buf)
  78662. +{
  78663. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  78664. + return sprintf(buf, "Mode Change Ready Timer Enable = 0x%x\n",
  78665. + dwc_otg_get_mode_ch_tim(otg_dev->core_if));
  78666. +}
  78667. +
  78668. +/**
  78669. + * Set the Mode Change Ready Timer status
  78670. + */
  78671. +static ssize_t mode_ch_tim_en_store(struct device *_dev,
  78672. + struct device_attribute *attr,
  78673. + const char *buf, size_t count)
  78674. +{
  78675. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  78676. + uint32_t in = simple_strtoul(buf, NULL, 16);
  78677. + dwc_otg_set_mode_ch_tim(otg_dev->core_if, in);
  78678. + return count;
  78679. +}
  78680. +
  78681. +DEVICE_ATTR(mode_ch_tim_en, 0644, mode_ch_tim_en_show, mode_ch_tim_en_store);
  78682. +
  78683. +/**
  78684. + * Show the value of HFIR Frame Interval bitfield
  78685. + */
  78686. +static ssize_t fr_interval_show(struct device *_dev,
  78687. + struct device_attribute *attr, char *buf)
  78688. +{
  78689. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  78690. + return sprintf(buf, "Frame Interval = 0x%x\n",
  78691. + dwc_otg_get_fr_interval(otg_dev->core_if));
  78692. +}
  78693. +
  78694. +/**
  78695. + * Set the HFIR Frame Interval value
  78696. + */
  78697. +static ssize_t fr_interval_store(struct device *_dev,
  78698. + struct device_attribute *attr,
  78699. + const char *buf, size_t count)
  78700. +{
  78701. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  78702. + uint32_t in = simple_strtoul(buf, NULL, 10);
  78703. + dwc_otg_set_fr_interval(otg_dev->core_if, in);
  78704. + return count;
  78705. +}
  78706. +
  78707. +DEVICE_ATTR(fr_interval, 0644, fr_interval_show, fr_interval_store);
  78708. +
  78709. +/**
  78710. + * Show the status of Remote Wakeup.
  78711. + */
  78712. +static ssize_t remote_wakeup_show(struct device *_dev,
  78713. + struct device_attribute *attr, char *buf)
  78714. +{
  78715. +#ifndef DWC_HOST_ONLY
  78716. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  78717. +
  78718. + return sprintf(buf,
  78719. + "Remote Wakeup Sig = %d Enabled = %d LPM Remote Wakeup = %d\n",
  78720. + dwc_otg_get_remotewakesig(otg_dev->core_if),
  78721. + dwc_otg_pcd_get_rmwkup_enable(otg_dev->pcd),
  78722. + dwc_otg_get_lpm_remotewakeenabled(otg_dev->core_if));
  78723. +#else
  78724. + return sprintf(buf, "Host Only Mode!\n");
  78725. +#endif /* DWC_HOST_ONLY */
  78726. +}
  78727. +
  78728. +/**
  78729. + * Initiate a remote wakeup of the host. The Device control register
  78730. + * Remote Wakeup Signal bit is written if the PCD Remote wakeup enable
  78731. + * flag is set.
  78732. + *
  78733. + */
  78734. +static ssize_t remote_wakeup_store(struct device *_dev,
  78735. + struct device_attribute *attr,
  78736. + const char *buf, size_t count)
  78737. +{
  78738. +#ifndef DWC_HOST_ONLY
  78739. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  78740. + uint32_t val = simple_strtoul(buf, NULL, 16);
  78741. +
  78742. + if (val & 1) {
  78743. + dwc_otg_pcd_remote_wakeup(otg_dev->pcd, 1);
  78744. + } else {
  78745. + dwc_otg_pcd_remote_wakeup(otg_dev->pcd, 0);
  78746. + }
  78747. +#endif /* DWC_HOST_ONLY */
  78748. + return count;
  78749. +}
  78750. +
  78751. +DEVICE_ATTR(remote_wakeup, S_IRUGO | S_IWUSR, remote_wakeup_show,
  78752. + remote_wakeup_store);
  78753. +
  78754. +/**
  78755. + * Show the whether core is hibernated or not.
  78756. + */
  78757. +static ssize_t rem_wakeup_pwrdn_show(struct device *_dev,
  78758. + struct device_attribute *attr, char *buf)
  78759. +{
  78760. +#ifndef DWC_HOST_ONLY
  78761. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  78762. +
  78763. + if (dwc_otg_get_core_state(otg_dev->core_if)) {
  78764. + DWC_PRINTF("Core is in hibernation\n");
  78765. + } else {
  78766. + DWC_PRINTF("Core is not in hibernation\n");
  78767. + }
  78768. +#endif /* DWC_HOST_ONLY */
  78769. + return 0;
  78770. +}
  78771. +
  78772. +extern int dwc_otg_device_hibernation_restore(dwc_otg_core_if_t * core_if,
  78773. + int rem_wakeup, int reset);
  78774. +
  78775. +/**
  78776. + * Initiate a remote wakeup of the device to exit from hibernation.
  78777. + */
  78778. +static ssize_t rem_wakeup_pwrdn_store(struct device *_dev,
  78779. + struct device_attribute *attr,
  78780. + const char *buf, size_t count)
  78781. +{
  78782. +#ifndef DWC_HOST_ONLY
  78783. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  78784. + dwc_otg_device_hibernation_restore(otg_dev->core_if, 1, 0);
  78785. +#endif
  78786. + return count;
  78787. +}
  78788. +
  78789. +DEVICE_ATTR(rem_wakeup_pwrdn, S_IRUGO | S_IWUSR, rem_wakeup_pwrdn_show,
  78790. + rem_wakeup_pwrdn_store);
  78791. +
  78792. +static ssize_t disconnect_us(struct device *_dev,
  78793. + struct device_attribute *attr,
  78794. + const char *buf, size_t count)
  78795. +{
  78796. +
  78797. +#ifndef DWC_HOST_ONLY
  78798. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  78799. + uint32_t val = simple_strtoul(buf, NULL, 16);
  78800. + DWC_PRINTF("The Passed value is %04x\n", val);
  78801. +
  78802. + dwc_otg_pcd_disconnect_us(otg_dev->pcd, 50);
  78803. +
  78804. +#endif /* DWC_HOST_ONLY */
  78805. + return count;
  78806. +}
  78807. +
  78808. +DEVICE_ATTR(disconnect_us, S_IWUSR, 0, disconnect_us);
  78809. +
  78810. +/**
  78811. + * Dump global registers and either host or device registers (depending on the
  78812. + * current mode of the core).
  78813. + */
  78814. +static ssize_t regdump_show(struct device *_dev,
  78815. + struct device_attribute *attr, char *buf)
  78816. +{
  78817. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  78818. +
  78819. + dwc_otg_dump_global_registers(otg_dev->core_if);
  78820. + if (dwc_otg_is_host_mode(otg_dev->core_if)) {
  78821. + dwc_otg_dump_host_registers(otg_dev->core_if);
  78822. + } else {
  78823. + dwc_otg_dump_dev_registers(otg_dev->core_if);
  78824. +
  78825. + }
  78826. + return sprintf(buf, "Register Dump\n");
  78827. +}
  78828. +
  78829. +DEVICE_ATTR(regdump, S_IRUGO, regdump_show, 0);
  78830. +
  78831. +/**
  78832. + * Dump global registers and either host or device registers (depending on the
  78833. + * current mode of the core).
  78834. + */
  78835. +static ssize_t spramdump_show(struct device *_dev,
  78836. + struct device_attribute *attr, char *buf)
  78837. +{
  78838. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  78839. +
  78840. + //dwc_otg_dump_spram(otg_dev->core_if);
  78841. +
  78842. + return sprintf(buf, "SPRAM Dump\n");
  78843. +}
  78844. +
  78845. +DEVICE_ATTR(spramdump, S_IRUGO, spramdump_show, 0);
  78846. +
  78847. +/**
  78848. + * Dump the current hcd state.
  78849. + */
  78850. +static ssize_t hcddump_show(struct device *_dev,
  78851. + struct device_attribute *attr, char *buf)
  78852. +{
  78853. +#ifndef DWC_DEVICE_ONLY
  78854. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  78855. + dwc_otg_hcd_dump_state(otg_dev->hcd);
  78856. +#endif /* DWC_DEVICE_ONLY */
  78857. + return sprintf(buf, "HCD Dump\n");
  78858. +}
  78859. +
  78860. +DEVICE_ATTR(hcddump, S_IRUGO, hcddump_show, 0);
  78861. +
  78862. +/**
  78863. + * Dump the average frame remaining at SOF. This can be used to
  78864. + * determine average interrupt latency. Frame remaining is also shown for
  78865. + * start transfer and two additional sample points.
  78866. + */
  78867. +static ssize_t hcd_frrem_show(struct device *_dev,
  78868. + struct device_attribute *attr, char *buf)
  78869. +{
  78870. +#ifndef DWC_DEVICE_ONLY
  78871. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  78872. +
  78873. + dwc_otg_hcd_dump_frrem(otg_dev->hcd);
  78874. +#endif /* DWC_DEVICE_ONLY */
  78875. + return sprintf(buf, "HCD Dump Frame Remaining\n");
  78876. +}
  78877. +
  78878. +DEVICE_ATTR(hcd_frrem, S_IRUGO, hcd_frrem_show, 0);
  78879. +
  78880. +/**
  78881. + * Displays the time required to read the GNPTXFSIZ register many times (the
  78882. + * output shows the number of times the register is read).
  78883. + */
  78884. +#define RW_REG_COUNT 10000000
  78885. +#define MSEC_PER_JIFFIE 1000/HZ
  78886. +static ssize_t rd_reg_test_show(struct device *_dev,
  78887. + struct device_attribute *attr, char *buf)
  78888. +{
  78889. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  78890. + int i;
  78891. + int time;
  78892. + int start_jiffies;
  78893. +
  78894. + printk("HZ %d, MSEC_PER_JIFFIE %d, loops_per_jiffy %lu\n",
  78895. + HZ, MSEC_PER_JIFFIE, loops_per_jiffy);
  78896. + start_jiffies = jiffies;
  78897. + for (i = 0; i < RW_REG_COUNT; i++) {
  78898. + dwc_otg_get_gnptxfsiz(otg_dev->core_if);
  78899. + }
  78900. + time = jiffies - start_jiffies;
  78901. + return sprintf(buf,
  78902. + "Time to read GNPTXFSIZ reg %d times: %d msecs (%d jiffies)\n",
  78903. + RW_REG_COUNT, time * MSEC_PER_JIFFIE, time);
  78904. +}
  78905. +
  78906. +DEVICE_ATTR(rd_reg_test, S_IRUGO, rd_reg_test_show, 0);
  78907. +
  78908. +/**
  78909. + * Displays the time required to write the GNPTXFSIZ register many times (the
  78910. + * output shows the number of times the register is written).
  78911. + */
  78912. +static ssize_t wr_reg_test_show(struct device *_dev,
  78913. + struct device_attribute *attr, char *buf)
  78914. +{
  78915. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  78916. + uint32_t reg_val;
  78917. + int i;
  78918. + int time;
  78919. + int start_jiffies;
  78920. +
  78921. + printk("HZ %d, MSEC_PER_JIFFIE %d, loops_per_jiffy %lu\n",
  78922. + HZ, MSEC_PER_JIFFIE, loops_per_jiffy);
  78923. + reg_val = dwc_otg_get_gnptxfsiz(otg_dev->core_if);
  78924. + start_jiffies = jiffies;
  78925. + for (i = 0; i < RW_REG_COUNT; i++) {
  78926. + dwc_otg_set_gnptxfsiz(otg_dev->core_if, reg_val);
  78927. + }
  78928. + time = jiffies - start_jiffies;
  78929. + return sprintf(buf,
  78930. + "Time to write GNPTXFSIZ reg %d times: %d msecs (%d jiffies)\n",
  78931. + RW_REG_COUNT, time * MSEC_PER_JIFFIE, time);
  78932. +}
  78933. +
  78934. +DEVICE_ATTR(wr_reg_test, S_IRUGO, wr_reg_test_show, 0);
  78935. +
  78936. +#ifdef CONFIG_USB_DWC_OTG_LPM
  78937. +
  78938. +/**
  78939. +* Show the lpm_response attribute.
  78940. +*/
  78941. +static ssize_t lpmresp_show(struct device *_dev,
  78942. + struct device_attribute *attr, char *buf)
  78943. +{
  78944. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  78945. +
  78946. + if (!dwc_otg_get_param_lpm_enable(otg_dev->core_if))
  78947. + return sprintf(buf, "** LPM is DISABLED **\n");
  78948. +
  78949. + if (!dwc_otg_is_device_mode(otg_dev->core_if)) {
  78950. + return sprintf(buf, "** Current mode is not device mode\n");
  78951. + }
  78952. + return sprintf(buf, "lpm_response = %d\n",
  78953. + dwc_otg_get_lpmresponse(otg_dev->core_if));
  78954. +}
  78955. +
  78956. +/**
  78957. +* Store the lpm_response attribute.
  78958. +*/
  78959. +static ssize_t lpmresp_store(struct device *_dev,
  78960. + struct device_attribute *attr,
  78961. + const char *buf, size_t count)
  78962. +{
  78963. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  78964. + uint32_t val = simple_strtoul(buf, NULL, 16);
  78965. +
  78966. + if (!dwc_otg_get_param_lpm_enable(otg_dev->core_if)) {
  78967. + return 0;
  78968. + }
  78969. +
  78970. + if (!dwc_otg_is_device_mode(otg_dev->core_if)) {
  78971. + return 0;
  78972. + }
  78973. +
  78974. + dwc_otg_set_lpmresponse(otg_dev->core_if, val);
  78975. + return count;
  78976. +}
  78977. +
  78978. +DEVICE_ATTR(lpm_response, S_IRUGO | S_IWUSR, lpmresp_show, lpmresp_store);
  78979. +
  78980. +/**
  78981. +* Show the sleep_status attribute.
  78982. +*/
  78983. +static ssize_t sleepstatus_show(struct device *_dev,
  78984. + struct device_attribute *attr, char *buf)
  78985. +{
  78986. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  78987. + return sprintf(buf, "Sleep Status = %d\n",
  78988. + dwc_otg_get_lpm_portsleepstatus(otg_dev->core_if));
  78989. +}
  78990. +
  78991. +/**
  78992. + * Store the sleep_status attribure.
  78993. + */
  78994. +static ssize_t sleepstatus_store(struct device *_dev,
  78995. + struct device_attribute *attr,
  78996. + const char *buf, size_t count)
  78997. +{
  78998. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  78999. + dwc_otg_core_if_t *core_if = otg_dev->core_if;
  79000. +
  79001. + if (dwc_otg_get_lpm_portsleepstatus(otg_dev->core_if)) {
  79002. + if (dwc_otg_is_host_mode(core_if)) {
  79003. +
  79004. + DWC_PRINTF("Host initiated resume\n");
  79005. + dwc_otg_set_prtresume(otg_dev->core_if, 1);
  79006. + }
  79007. + }
  79008. +
  79009. + return count;
  79010. +}
  79011. +
  79012. +DEVICE_ATTR(sleep_status, S_IRUGO | S_IWUSR, sleepstatus_show,
  79013. + sleepstatus_store);
  79014. +
  79015. +#endif /* CONFIG_USB_DWC_OTG_LPM_ENABLE */
  79016. +
  79017. +/**@}*/
  79018. +
  79019. +/**
  79020. + * Create the device files
  79021. + */
  79022. +void dwc_otg_attr_create(
  79023. +#ifdef LM_INTERFACE
  79024. + struct lm_device *dev
  79025. +#elif defined(PCI_INTERFACE)
  79026. + struct pci_dev *dev
  79027. +#elif defined(PLATFORM_INTERFACE)
  79028. + struct platform_device *dev
  79029. +#endif
  79030. + )
  79031. +{
  79032. + int error;
  79033. +
  79034. + error = device_create_file(&dev->dev, &dev_attr_regoffset);
  79035. + error = device_create_file(&dev->dev, &dev_attr_regvalue);
  79036. + error = device_create_file(&dev->dev, &dev_attr_mode);
  79037. + error = device_create_file(&dev->dev, &dev_attr_hnpcapable);
  79038. + error = device_create_file(&dev->dev, &dev_attr_srpcapable);
  79039. + error = device_create_file(&dev->dev, &dev_attr_hsic_connect);
  79040. + error = device_create_file(&dev->dev, &dev_attr_inv_sel_hsic);
  79041. + error = device_create_file(&dev->dev, &dev_attr_hnp);
  79042. + error = device_create_file(&dev->dev, &dev_attr_srp);
  79043. + error = device_create_file(&dev->dev, &dev_attr_buspower);
  79044. + error = device_create_file(&dev->dev, &dev_attr_bussuspend);
  79045. + error = device_create_file(&dev->dev, &dev_attr_mode_ch_tim_en);
  79046. + error = device_create_file(&dev->dev, &dev_attr_fr_interval);
  79047. + error = device_create_file(&dev->dev, &dev_attr_busconnected);
  79048. + error = device_create_file(&dev->dev, &dev_attr_gotgctl);
  79049. + error = device_create_file(&dev->dev, &dev_attr_gusbcfg);
  79050. + error = device_create_file(&dev->dev, &dev_attr_grxfsiz);
  79051. + error = device_create_file(&dev->dev, &dev_attr_gnptxfsiz);
  79052. + error = device_create_file(&dev->dev, &dev_attr_gpvndctl);
  79053. + error = device_create_file(&dev->dev, &dev_attr_ggpio);
  79054. + error = device_create_file(&dev->dev, &dev_attr_guid);
  79055. + error = device_create_file(&dev->dev, &dev_attr_gsnpsid);
  79056. + error = device_create_file(&dev->dev, &dev_attr_devspeed);
  79057. + error = device_create_file(&dev->dev, &dev_attr_enumspeed);
  79058. + error = device_create_file(&dev->dev, &dev_attr_hptxfsiz);
  79059. + error = device_create_file(&dev->dev, &dev_attr_hprt0);
  79060. + error = device_create_file(&dev->dev, &dev_attr_remote_wakeup);
  79061. + error = device_create_file(&dev->dev, &dev_attr_rem_wakeup_pwrdn);
  79062. + error = device_create_file(&dev->dev, &dev_attr_disconnect_us);
  79063. + error = device_create_file(&dev->dev, &dev_attr_regdump);
  79064. + error = device_create_file(&dev->dev, &dev_attr_spramdump);
  79065. + error = device_create_file(&dev->dev, &dev_attr_hcddump);
  79066. + error = device_create_file(&dev->dev, &dev_attr_hcd_frrem);
  79067. + error = device_create_file(&dev->dev, &dev_attr_rd_reg_test);
  79068. + error = device_create_file(&dev->dev, &dev_attr_wr_reg_test);
  79069. +#ifdef CONFIG_USB_DWC_OTG_LPM
  79070. + error = device_create_file(&dev->dev, &dev_attr_lpm_response);
  79071. + error = device_create_file(&dev->dev, &dev_attr_sleep_status);
  79072. +#endif
  79073. +}
  79074. +
  79075. +/**
  79076. + * Remove the device files
  79077. + */
  79078. +void dwc_otg_attr_remove(
  79079. +#ifdef LM_INTERFACE
  79080. + struct lm_device *dev
  79081. +#elif defined(PCI_INTERFACE)
  79082. + struct pci_dev *dev
  79083. +#elif defined(PLATFORM_INTERFACE)
  79084. + struct platform_device *dev
  79085. +#endif
  79086. + )
  79087. +{
  79088. + device_remove_file(&dev->dev, &dev_attr_regoffset);
  79089. + device_remove_file(&dev->dev, &dev_attr_regvalue);
  79090. + device_remove_file(&dev->dev, &dev_attr_mode);
  79091. + device_remove_file(&dev->dev, &dev_attr_hnpcapable);
  79092. + device_remove_file(&dev->dev, &dev_attr_srpcapable);
  79093. + device_remove_file(&dev->dev, &dev_attr_hsic_connect);
  79094. + device_remove_file(&dev->dev, &dev_attr_inv_sel_hsic);
  79095. + device_remove_file(&dev->dev, &dev_attr_hnp);
  79096. + device_remove_file(&dev->dev, &dev_attr_srp);
  79097. + device_remove_file(&dev->dev, &dev_attr_buspower);
  79098. + device_remove_file(&dev->dev, &dev_attr_bussuspend);
  79099. + device_remove_file(&dev->dev, &dev_attr_mode_ch_tim_en);
  79100. + device_remove_file(&dev->dev, &dev_attr_fr_interval);
  79101. + device_remove_file(&dev->dev, &dev_attr_busconnected);
  79102. + device_remove_file(&dev->dev, &dev_attr_gotgctl);
  79103. + device_remove_file(&dev->dev, &dev_attr_gusbcfg);
  79104. + device_remove_file(&dev->dev, &dev_attr_grxfsiz);
  79105. + device_remove_file(&dev->dev, &dev_attr_gnptxfsiz);
  79106. + device_remove_file(&dev->dev, &dev_attr_gpvndctl);
  79107. + device_remove_file(&dev->dev, &dev_attr_ggpio);
  79108. + device_remove_file(&dev->dev, &dev_attr_guid);
  79109. + device_remove_file(&dev->dev, &dev_attr_gsnpsid);
  79110. + device_remove_file(&dev->dev, &dev_attr_devspeed);
  79111. + device_remove_file(&dev->dev, &dev_attr_enumspeed);
  79112. + device_remove_file(&dev->dev, &dev_attr_hptxfsiz);
  79113. + device_remove_file(&dev->dev, &dev_attr_hprt0);
  79114. + device_remove_file(&dev->dev, &dev_attr_remote_wakeup);
  79115. + device_remove_file(&dev->dev, &dev_attr_rem_wakeup_pwrdn);
  79116. + device_remove_file(&dev->dev, &dev_attr_disconnect_us);
  79117. + device_remove_file(&dev->dev, &dev_attr_regdump);
  79118. + device_remove_file(&dev->dev, &dev_attr_spramdump);
  79119. + device_remove_file(&dev->dev, &dev_attr_hcddump);
  79120. + device_remove_file(&dev->dev, &dev_attr_hcd_frrem);
  79121. + device_remove_file(&dev->dev, &dev_attr_rd_reg_test);
  79122. + device_remove_file(&dev->dev, &dev_attr_wr_reg_test);
  79123. +#ifdef CONFIG_USB_DWC_OTG_LPM
  79124. + device_remove_file(&dev->dev, &dev_attr_lpm_response);
  79125. + device_remove_file(&dev->dev, &dev_attr_sleep_status);
  79126. +#endif
  79127. +}
  79128. diff -Nur linux-3.18.8/drivers/usb/host/dwc_otg/dwc_otg_attr.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_attr.h
  79129. --- linux-3.18.8/drivers/usb/host/dwc_otg/dwc_otg_attr.h 1970-01-01 01:00:00.000000000 +0100
  79130. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_attr.h 2015-03-05 14:40:16.557715806 +0100
  79131. @@ -0,0 +1,89 @@
  79132. +/* ==========================================================================
  79133. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_attr.h $
  79134. + * $Revision: #13 $
  79135. + * $Date: 2010/06/21 $
  79136. + * $Change: 1532021 $
  79137. + *
  79138. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  79139. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  79140. + * otherwise expressly agreed to in writing between Synopsys and you.
  79141. + *
  79142. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  79143. + * any End User Software License Agreement or Agreement for Licensed Product
  79144. + * with Synopsys or any supplement thereto. You are permitted to use and
  79145. + * redistribute this Software in source and binary forms, with or without
  79146. + * modification, provided that redistributions of source code must retain this
  79147. + * notice. You may not view, use, disclose, copy or distribute this file or
  79148. + * any information contained herein except pursuant to this license grant from
  79149. + * Synopsys. If you do not agree with this notice, including the disclaimer
  79150. + * below, then you are not authorized to use the Software.
  79151. + *
  79152. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  79153. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  79154. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  79155. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  79156. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  79157. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  79158. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  79159. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  79160. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  79161. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  79162. + * DAMAGE.
  79163. + * ========================================================================== */
  79164. +
  79165. +#if !defined(__DWC_OTG_ATTR_H__)
  79166. +#define __DWC_OTG_ATTR_H__
  79167. +
  79168. +/** @file
  79169. + * This file contains the interface to the Linux device attributes.
  79170. + */
  79171. +extern struct device_attribute dev_attr_regoffset;
  79172. +extern struct device_attribute dev_attr_regvalue;
  79173. +
  79174. +extern struct device_attribute dev_attr_mode;
  79175. +extern struct device_attribute dev_attr_hnpcapable;
  79176. +extern struct device_attribute dev_attr_srpcapable;
  79177. +extern struct device_attribute dev_attr_hnp;
  79178. +extern struct device_attribute dev_attr_srp;
  79179. +extern struct device_attribute dev_attr_buspower;
  79180. +extern struct device_attribute dev_attr_bussuspend;
  79181. +extern struct device_attribute dev_attr_mode_ch_tim_en;
  79182. +extern struct device_attribute dev_attr_fr_interval;
  79183. +extern struct device_attribute dev_attr_busconnected;
  79184. +extern struct device_attribute dev_attr_gotgctl;
  79185. +extern struct device_attribute dev_attr_gusbcfg;
  79186. +extern struct device_attribute dev_attr_grxfsiz;
  79187. +extern struct device_attribute dev_attr_gnptxfsiz;
  79188. +extern struct device_attribute dev_attr_gpvndctl;
  79189. +extern struct device_attribute dev_attr_ggpio;
  79190. +extern struct device_attribute dev_attr_guid;
  79191. +extern struct device_attribute dev_attr_gsnpsid;
  79192. +extern struct device_attribute dev_attr_devspeed;
  79193. +extern struct device_attribute dev_attr_enumspeed;
  79194. +extern struct device_attribute dev_attr_hptxfsiz;
  79195. +extern struct device_attribute dev_attr_hprt0;
  79196. +#ifdef CONFIG_USB_DWC_OTG_LPM
  79197. +extern struct device_attribute dev_attr_lpm_response;
  79198. +extern struct device_attribute devi_attr_sleep_status;
  79199. +#endif
  79200. +
  79201. +void dwc_otg_attr_create(
  79202. +#ifdef LM_INTERFACE
  79203. + struct lm_device *dev
  79204. +#elif defined(PCI_INTERFACE)
  79205. + struct pci_dev *dev
  79206. +#elif defined(PLATFORM_INTERFACE)
  79207. + struct platform_device *dev
  79208. +#endif
  79209. + );
  79210. +
  79211. +void dwc_otg_attr_remove(
  79212. +#ifdef LM_INTERFACE
  79213. + struct lm_device *dev
  79214. +#elif defined(PCI_INTERFACE)
  79215. + struct pci_dev *dev
  79216. +#elif defined(PLATFORM_INTERFACE)
  79217. + struct platform_device *dev
  79218. +#endif
  79219. + );
  79220. +#endif
  79221. diff -Nur linux-3.18.8/drivers/usb/host/dwc_otg/dwc_otg_cfi.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_cfi.c
  79222. --- linux-3.18.8/drivers/usb/host/dwc_otg/dwc_otg_cfi.c 1970-01-01 01:00:00.000000000 +0100
  79223. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_cfi.c 2015-03-05 14:40:16.557715806 +0100
  79224. @@ -0,0 +1,1876 @@
  79225. +/* ==========================================================================
  79226. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  79227. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  79228. + * otherwise expressly agreed to in writing between Synopsys and you.
  79229. + *
  79230. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  79231. + * any End User Software License Agreement or Agreement for Licensed Product
  79232. + * with Synopsys or any supplement thereto. You are permitted to use and
  79233. + * redistribute this Software in source and binary forms, with or without
  79234. + * modification, provided that redistributions of source code must retain this
  79235. + * notice. You may not view, use, disclose, copy or distribute this file or
  79236. + * any information contained herein except pursuant to this license grant from
  79237. + * Synopsys. If you do not agree with this notice, including the disclaimer
  79238. + * below, then you are not authorized to use the Software.
  79239. + *
  79240. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  79241. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  79242. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  79243. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  79244. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  79245. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  79246. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  79247. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  79248. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  79249. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  79250. + * DAMAGE.
  79251. + * ========================================================================== */
  79252. +
  79253. +/** @file
  79254. + *
  79255. + * This file contains the most of the CFI(Core Feature Interface)
  79256. + * implementation for the OTG.
  79257. + */
  79258. +
  79259. +#ifdef DWC_UTE_CFI
  79260. +
  79261. +#include "dwc_otg_pcd.h"
  79262. +#include "dwc_otg_cfi.h"
  79263. +
  79264. +/** This definition should actually migrate to the Portability Library */
  79265. +#define DWC_CONSTANT_CPU_TO_LE16(x) (x)
  79266. +
  79267. +extern dwc_otg_pcd_ep_t *get_ep_by_addr(dwc_otg_pcd_t * pcd, u16 wIndex);
  79268. +
  79269. +static int cfi_core_features_buf(uint8_t * buf, uint16_t buflen);
  79270. +static int cfi_get_feature_value(uint8_t * buf, uint16_t buflen,
  79271. + struct dwc_otg_pcd *pcd,
  79272. + struct cfi_usb_ctrlrequest *ctrl_req);
  79273. +static int cfi_set_feature_value(struct dwc_otg_pcd *pcd);
  79274. +static int cfi_ep_get_sg_val(uint8_t * buf, struct dwc_otg_pcd *pcd,
  79275. + struct cfi_usb_ctrlrequest *req);
  79276. +static int cfi_ep_get_concat_val(uint8_t * buf, struct dwc_otg_pcd *pcd,
  79277. + struct cfi_usb_ctrlrequest *req);
  79278. +static int cfi_ep_get_align_val(uint8_t * buf, struct dwc_otg_pcd *pcd,
  79279. + struct cfi_usb_ctrlrequest *req);
  79280. +static int cfi_preproc_reset(struct dwc_otg_pcd *pcd,
  79281. + struct cfi_usb_ctrlrequest *req);
  79282. +static void cfi_free_ep_bs_dyn_data(cfi_ep_t * cfiep);
  79283. +
  79284. +static uint16_t get_dfifo_size(dwc_otg_core_if_t * core_if);
  79285. +static int32_t get_rxfifo_size(dwc_otg_core_if_t * core_if, uint16_t wValue);
  79286. +static int32_t get_txfifo_size(struct dwc_otg_pcd *pcd, uint16_t wValue);
  79287. +
  79288. +static uint8_t resize_fifos(dwc_otg_core_if_t * core_if);
  79289. +
  79290. +/** This is the header of the all features descriptor */
  79291. +static cfi_all_features_header_t all_props_desc_header = {
  79292. + .wVersion = DWC_CONSTANT_CPU_TO_LE16(0x100),
  79293. + .wCoreID = DWC_CONSTANT_CPU_TO_LE16(CFI_CORE_ID_OTG),
  79294. + .wNumFeatures = DWC_CONSTANT_CPU_TO_LE16(9),
  79295. +};
  79296. +
  79297. +/** This is an array of statically allocated feature descriptors */
  79298. +static cfi_feature_desc_header_t prop_descs[] = {
  79299. +
  79300. + /* FT_ID_DMA_MODE */
  79301. + {
  79302. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_DMA_MODE),
  79303. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  79304. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(1),
  79305. + },
  79306. +
  79307. + /* FT_ID_DMA_BUFFER_SETUP */
  79308. + {
  79309. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_DMA_BUFFER_SETUP),
  79310. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  79311. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(6),
  79312. + },
  79313. +
  79314. + /* FT_ID_DMA_BUFF_ALIGN */
  79315. + {
  79316. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_DMA_BUFF_ALIGN),
  79317. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  79318. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(2),
  79319. + },
  79320. +
  79321. + /* FT_ID_DMA_CONCAT_SETUP */
  79322. + {
  79323. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_DMA_CONCAT_SETUP),
  79324. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  79325. + //.wDataLength = DWC_CONSTANT_CPU_TO_LE16(6),
  79326. + },
  79327. +
  79328. + /* FT_ID_DMA_CIRCULAR */
  79329. + {
  79330. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_DMA_CIRCULAR),
  79331. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  79332. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(6),
  79333. + },
  79334. +
  79335. + /* FT_ID_THRESHOLD_SETUP */
  79336. + {
  79337. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_THRESHOLD_SETUP),
  79338. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  79339. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(6),
  79340. + },
  79341. +
  79342. + /* FT_ID_DFIFO_DEPTH */
  79343. + {
  79344. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_DFIFO_DEPTH),
  79345. + .bmAttributes = CFI_FEATURE_ATTR_RO,
  79346. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(2),
  79347. + },
  79348. +
  79349. + /* FT_ID_TX_FIFO_DEPTH */
  79350. + {
  79351. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_TX_FIFO_DEPTH),
  79352. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  79353. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(2),
  79354. + },
  79355. +
  79356. + /* FT_ID_RX_FIFO_DEPTH */
  79357. + {
  79358. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_RX_FIFO_DEPTH),
  79359. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  79360. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(2),
  79361. + }
  79362. +};
  79363. +
  79364. +/** The table of feature names */
  79365. +cfi_string_t prop_name_table[] = {
  79366. + {FT_ID_DMA_MODE, "dma_mode"},
  79367. + {FT_ID_DMA_BUFFER_SETUP, "buffer_setup"},
  79368. + {FT_ID_DMA_BUFF_ALIGN, "buffer_align"},
  79369. + {FT_ID_DMA_CONCAT_SETUP, "concat_setup"},
  79370. + {FT_ID_DMA_CIRCULAR, "buffer_circular"},
  79371. + {FT_ID_THRESHOLD_SETUP, "threshold_setup"},
  79372. + {FT_ID_DFIFO_DEPTH, "dfifo_depth"},
  79373. + {FT_ID_TX_FIFO_DEPTH, "txfifo_depth"},
  79374. + {FT_ID_RX_FIFO_DEPTH, "rxfifo_depth"},
  79375. + {}
  79376. +};
  79377. +
  79378. +/************************************************************************/
  79379. +
  79380. +/**
  79381. + * Returns the name of the feature by its ID
  79382. + * or NULL if no featute ID matches.
  79383. + *
  79384. + */
  79385. +const uint8_t *get_prop_name(uint16_t prop_id, int *len)
  79386. +{
  79387. + cfi_string_t *pstr;
  79388. + *len = 0;
  79389. +
  79390. + for (pstr = prop_name_table; pstr && pstr->s; pstr++) {
  79391. + if (pstr->id == prop_id) {
  79392. + *len = DWC_STRLEN(pstr->s);
  79393. + return pstr->s;
  79394. + }
  79395. + }
  79396. + return NULL;
  79397. +}
  79398. +
  79399. +/**
  79400. + * This function handles all CFI specific control requests.
  79401. + *
  79402. + * Return a negative value to stall the DCE.
  79403. + */
  79404. +int cfi_setup(struct dwc_otg_pcd *pcd, struct cfi_usb_ctrlrequest *ctrl)
  79405. +{
  79406. + int retval = 0;
  79407. + dwc_otg_pcd_ep_t *ep = NULL;
  79408. + cfiobject_t *cfi = pcd->cfi;
  79409. + struct dwc_otg_core_if *coreif = GET_CORE_IF(pcd);
  79410. + uint16_t wLen = DWC_LE16_TO_CPU(&ctrl->wLength);
  79411. + uint16_t wValue = DWC_LE16_TO_CPU(&ctrl->wValue);
  79412. + uint16_t wIndex = DWC_LE16_TO_CPU(&ctrl->wIndex);
  79413. + uint32_t regaddr = 0;
  79414. + uint32_t regval = 0;
  79415. +
  79416. + /* Save this Control Request in the CFI object.
  79417. + * The data field will be assigned in the data stage completion CB function.
  79418. + */
  79419. + cfi->ctrl_req = *ctrl;
  79420. + cfi->ctrl_req.data = NULL;
  79421. +
  79422. + cfi->need_gadget_att = 0;
  79423. + cfi->need_status_in_complete = 0;
  79424. +
  79425. + switch (ctrl->bRequest) {
  79426. + case VEN_CORE_GET_FEATURES:
  79427. + retval = cfi_core_features_buf(cfi->buf_in.buf, CFI_IN_BUF_LEN);
  79428. + if (retval >= 0) {
  79429. + //dump_msg(cfi->buf_in.buf, retval);
  79430. + ep = &pcd->ep0;
  79431. +
  79432. + retval = min((uint16_t) retval, wLen);
  79433. + /* Transfer this buffer to the host through the EP0-IN EP */
  79434. + ep->dwc_ep.dma_addr = cfi->buf_in.addr;
  79435. + ep->dwc_ep.start_xfer_buff = cfi->buf_in.buf;
  79436. + ep->dwc_ep.xfer_buff = cfi->buf_in.buf;
  79437. + ep->dwc_ep.xfer_len = retval;
  79438. + ep->dwc_ep.xfer_count = 0;
  79439. + ep->dwc_ep.sent_zlp = 0;
  79440. + ep->dwc_ep.total_len = ep->dwc_ep.xfer_len;
  79441. +
  79442. + pcd->ep0_pending = 1;
  79443. + dwc_otg_ep0_start_transfer(coreif, &ep->dwc_ep);
  79444. + }
  79445. + retval = 0;
  79446. + break;
  79447. +
  79448. + case VEN_CORE_GET_FEATURE:
  79449. + CFI_INFO("VEN_CORE_GET_FEATURE\n");
  79450. + retval = cfi_get_feature_value(cfi->buf_in.buf, CFI_IN_BUF_LEN,
  79451. + pcd, ctrl);
  79452. + if (retval >= 0) {
  79453. + ep = &pcd->ep0;
  79454. +
  79455. + retval = min((uint16_t) retval, wLen);
  79456. + /* Transfer this buffer to the host through the EP0-IN EP */
  79457. + ep->dwc_ep.dma_addr = cfi->buf_in.addr;
  79458. + ep->dwc_ep.start_xfer_buff = cfi->buf_in.buf;
  79459. + ep->dwc_ep.xfer_buff = cfi->buf_in.buf;
  79460. + ep->dwc_ep.xfer_len = retval;
  79461. + ep->dwc_ep.xfer_count = 0;
  79462. + ep->dwc_ep.sent_zlp = 0;
  79463. + ep->dwc_ep.total_len = ep->dwc_ep.xfer_len;
  79464. +
  79465. + pcd->ep0_pending = 1;
  79466. + dwc_otg_ep0_start_transfer(coreif, &ep->dwc_ep);
  79467. + }
  79468. + CFI_INFO("VEN_CORE_GET_FEATURE=%d\n", retval);
  79469. + dump_msg(cfi->buf_in.buf, retval);
  79470. + break;
  79471. +
  79472. + case VEN_CORE_SET_FEATURE:
  79473. + CFI_INFO("VEN_CORE_SET_FEATURE\n");
  79474. + /* Set up an XFER to get the data stage of the control request,
  79475. + * which is the new value of the feature to be modified.
  79476. + */
  79477. + ep = &pcd->ep0;
  79478. + ep->dwc_ep.is_in = 0;
  79479. + ep->dwc_ep.dma_addr = cfi->buf_out.addr;
  79480. + ep->dwc_ep.start_xfer_buff = cfi->buf_out.buf;
  79481. + ep->dwc_ep.xfer_buff = cfi->buf_out.buf;
  79482. + ep->dwc_ep.xfer_len = wLen;
  79483. + ep->dwc_ep.xfer_count = 0;
  79484. + ep->dwc_ep.sent_zlp = 0;
  79485. + ep->dwc_ep.total_len = ep->dwc_ep.xfer_len;
  79486. +
  79487. + pcd->ep0_pending = 1;
  79488. + /* Read the control write's data stage */
  79489. + dwc_otg_ep0_start_transfer(coreif, &ep->dwc_ep);
  79490. + retval = 0;
  79491. + break;
  79492. +
  79493. + case VEN_CORE_RESET_FEATURES:
  79494. + CFI_INFO("VEN_CORE_RESET_FEATURES\n");
  79495. + cfi->need_gadget_att = 1;
  79496. + cfi->need_status_in_complete = 1;
  79497. + retval = cfi_preproc_reset(pcd, ctrl);
  79498. + CFI_INFO("VEN_CORE_RESET_FEATURES = (%d)\n", retval);
  79499. + break;
  79500. +
  79501. + case VEN_CORE_ACTIVATE_FEATURES:
  79502. + CFI_INFO("VEN_CORE_ACTIVATE_FEATURES\n");
  79503. + break;
  79504. +
  79505. + case VEN_CORE_READ_REGISTER:
  79506. + CFI_INFO("VEN_CORE_READ_REGISTER\n");
  79507. + /* wValue optionally contains the HI WORD of the register offset and
  79508. + * wIndex contains the LOW WORD of the register offset
  79509. + */
  79510. + if (wValue == 0) {
  79511. + /* @TODO - MAS - fix the access to the base field */
  79512. + regaddr = 0;
  79513. + //regaddr = (uint32_t) pcd->otg_dev->os_dep.base;
  79514. + //GET_CORE_IF(pcd)->co
  79515. + regaddr |= wIndex;
  79516. + } else {
  79517. + regaddr = (wValue << 16) | wIndex;
  79518. + }
  79519. +
  79520. + /* Read a 32-bit value of the memory at the regaddr */
  79521. + regval = DWC_READ_REG32((uint32_t *) regaddr);
  79522. +
  79523. + ep = &pcd->ep0;
  79524. + dwc_memcpy(cfi->buf_in.buf, &regval, sizeof(uint32_t));
  79525. + ep->dwc_ep.is_in = 1;
  79526. + ep->dwc_ep.dma_addr = cfi->buf_in.addr;
  79527. + ep->dwc_ep.start_xfer_buff = cfi->buf_in.buf;
  79528. + ep->dwc_ep.xfer_buff = cfi->buf_in.buf;
  79529. + ep->dwc_ep.xfer_len = wLen;
  79530. + ep->dwc_ep.xfer_count = 0;
  79531. + ep->dwc_ep.sent_zlp = 0;
  79532. + ep->dwc_ep.total_len = ep->dwc_ep.xfer_len;
  79533. +
  79534. + pcd->ep0_pending = 1;
  79535. + dwc_otg_ep0_start_transfer(coreif, &ep->dwc_ep);
  79536. + cfi->need_gadget_att = 0;
  79537. + retval = 0;
  79538. + break;
  79539. +
  79540. + case VEN_CORE_WRITE_REGISTER:
  79541. + CFI_INFO("VEN_CORE_WRITE_REGISTER\n");
  79542. + /* Set up an XFER to get the data stage of the control request,
  79543. + * which is the new value of the register to be modified.
  79544. + */
  79545. + ep = &pcd->ep0;
  79546. + ep->dwc_ep.is_in = 0;
  79547. + ep->dwc_ep.dma_addr = cfi->buf_out.addr;
  79548. + ep->dwc_ep.start_xfer_buff = cfi->buf_out.buf;
  79549. + ep->dwc_ep.xfer_buff = cfi->buf_out.buf;
  79550. + ep->dwc_ep.xfer_len = wLen;
  79551. + ep->dwc_ep.xfer_count = 0;
  79552. + ep->dwc_ep.sent_zlp = 0;
  79553. + ep->dwc_ep.total_len = ep->dwc_ep.xfer_len;
  79554. +
  79555. + pcd->ep0_pending = 1;
  79556. + /* Read the control write's data stage */
  79557. + dwc_otg_ep0_start_transfer(coreif, &ep->dwc_ep);
  79558. + retval = 0;
  79559. + break;
  79560. +
  79561. + default:
  79562. + retval = -DWC_E_NOT_SUPPORTED;
  79563. + break;
  79564. + }
  79565. +
  79566. + return retval;
  79567. +}
  79568. +
  79569. +/**
  79570. + * This function prepares the core features descriptors and copies its
  79571. + * raw representation into the buffer <buf>.
  79572. + *
  79573. + * The buffer structure is as follows:
  79574. + * all_features_header (8 bytes)
  79575. + * features_#1 (8 bytes + feature name string length)
  79576. + * features_#2 (8 bytes + feature name string length)
  79577. + * .....
  79578. + * features_#n - where n=the total count of feature descriptors
  79579. + */
  79580. +static int cfi_core_features_buf(uint8_t * buf, uint16_t buflen)
  79581. +{
  79582. + cfi_feature_desc_header_t *prop_hdr = prop_descs;
  79583. + cfi_feature_desc_header_t *prop;
  79584. + cfi_all_features_header_t *all_props_hdr = &all_props_desc_header;
  79585. + cfi_all_features_header_t *tmp;
  79586. + uint8_t *tmpbuf = buf;
  79587. + const uint8_t *pname = NULL;
  79588. + int i, j, namelen = 0, totlen;
  79589. +
  79590. + /* Prepare and copy the core features into the buffer */
  79591. + CFI_INFO("%s:\n", __func__);
  79592. +
  79593. + tmp = (cfi_all_features_header_t *) tmpbuf;
  79594. + *tmp = *all_props_hdr;
  79595. + tmpbuf += CFI_ALL_FEATURES_HDR_LEN;
  79596. +
  79597. + j = sizeof(prop_descs) / sizeof(cfi_all_features_header_t);
  79598. + for (i = 0; i < j; i++, prop_hdr++) {
  79599. + pname = get_prop_name(prop_hdr->wFeatureID, &namelen);
  79600. + prop = (cfi_feature_desc_header_t *) tmpbuf;
  79601. + *prop = *prop_hdr;
  79602. +
  79603. + prop->bNameLen = namelen;
  79604. + prop->wLength =
  79605. + DWC_CONSTANT_CPU_TO_LE16(CFI_FEATURE_DESC_HDR_LEN +
  79606. + namelen);
  79607. +
  79608. + tmpbuf += CFI_FEATURE_DESC_HDR_LEN;
  79609. + dwc_memcpy(tmpbuf, pname, namelen);
  79610. + tmpbuf += namelen;
  79611. + }
  79612. +
  79613. + totlen = tmpbuf - buf;
  79614. +
  79615. + if (totlen > 0) {
  79616. + tmp = (cfi_all_features_header_t *) buf;
  79617. + tmp->wTotalLen = DWC_CONSTANT_CPU_TO_LE16(totlen);
  79618. + }
  79619. +
  79620. + return totlen;
  79621. +}
  79622. +
  79623. +/**
  79624. + * This function releases all the dynamic memory in the CFI object.
  79625. + */
  79626. +static void cfi_release(cfiobject_t * cfiobj)
  79627. +{
  79628. + cfi_ep_t *cfiep;
  79629. + dwc_list_link_t *tmp;
  79630. +
  79631. + CFI_INFO("%s\n", __func__);
  79632. +
  79633. + if (cfiobj->buf_in.buf) {
  79634. + DWC_DMA_FREE(CFI_IN_BUF_LEN, cfiobj->buf_in.buf,
  79635. + cfiobj->buf_in.addr);
  79636. + cfiobj->buf_in.buf = NULL;
  79637. + }
  79638. +
  79639. + if (cfiobj->buf_out.buf) {
  79640. + DWC_DMA_FREE(CFI_OUT_BUF_LEN, cfiobj->buf_out.buf,
  79641. + cfiobj->buf_out.addr);
  79642. + cfiobj->buf_out.buf = NULL;
  79643. + }
  79644. +
  79645. + /* Free the Buffer Setup values for each EP */
  79646. + //list_for_each_entry(cfiep, &cfiobj->active_eps, lh) {
  79647. + DWC_LIST_FOREACH(tmp, &cfiobj->active_eps) {
  79648. + cfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  79649. + cfi_free_ep_bs_dyn_data(cfiep);
  79650. + }
  79651. +}
  79652. +
  79653. +/**
  79654. + * This function frees the dynamically allocated EP buffer setup data.
  79655. + */
  79656. +static void cfi_free_ep_bs_dyn_data(cfi_ep_t * cfiep)
  79657. +{
  79658. + if (cfiep->bm_sg) {
  79659. + DWC_FREE(cfiep->bm_sg);
  79660. + cfiep->bm_sg = NULL;
  79661. + }
  79662. +
  79663. + if (cfiep->bm_align) {
  79664. + DWC_FREE(cfiep->bm_align);
  79665. + cfiep->bm_align = NULL;
  79666. + }
  79667. +
  79668. + if (cfiep->bm_concat) {
  79669. + if (NULL != cfiep->bm_concat->wTxBytes) {
  79670. + DWC_FREE(cfiep->bm_concat->wTxBytes);
  79671. + cfiep->bm_concat->wTxBytes = NULL;
  79672. + }
  79673. + DWC_FREE(cfiep->bm_concat);
  79674. + cfiep->bm_concat = NULL;
  79675. + }
  79676. +}
  79677. +
  79678. +/**
  79679. + * This function initializes the default values of the features
  79680. + * for a specific endpoint and should be called only once when
  79681. + * the EP is enabled first time.
  79682. + */
  79683. +static int cfi_ep_init_defaults(struct dwc_otg_pcd *pcd, cfi_ep_t * cfiep)
  79684. +{
  79685. + int retval = 0;
  79686. +
  79687. + cfiep->bm_sg = DWC_ALLOC(sizeof(ddma_sg_buffer_setup_t));
  79688. + if (NULL == cfiep->bm_sg) {
  79689. + CFI_INFO("Failed to allocate memory for SG feature value\n");
  79690. + return -DWC_E_NO_MEMORY;
  79691. + }
  79692. + dwc_memset(cfiep->bm_sg, 0, sizeof(ddma_sg_buffer_setup_t));
  79693. +
  79694. + /* For the Concatenation feature's default value we do not allocate
  79695. + * memory for the wTxBytes field - it will be done in the set_feature_value
  79696. + * request handler.
  79697. + */
  79698. + cfiep->bm_concat = DWC_ALLOC(sizeof(ddma_concat_buffer_setup_t));
  79699. + if (NULL == cfiep->bm_concat) {
  79700. + CFI_INFO
  79701. + ("Failed to allocate memory for CONCATENATION feature value\n");
  79702. + DWC_FREE(cfiep->bm_sg);
  79703. + return -DWC_E_NO_MEMORY;
  79704. + }
  79705. + dwc_memset(cfiep->bm_concat, 0, sizeof(ddma_concat_buffer_setup_t));
  79706. +
  79707. + cfiep->bm_align = DWC_ALLOC(sizeof(ddma_align_buffer_setup_t));
  79708. + if (NULL == cfiep->bm_align) {
  79709. + CFI_INFO
  79710. + ("Failed to allocate memory for Alignment feature value\n");
  79711. + DWC_FREE(cfiep->bm_sg);
  79712. + DWC_FREE(cfiep->bm_concat);
  79713. + return -DWC_E_NO_MEMORY;
  79714. + }
  79715. + dwc_memset(cfiep->bm_align, 0, sizeof(ddma_align_buffer_setup_t));
  79716. +
  79717. + return retval;
  79718. +}
  79719. +
  79720. +/**
  79721. + * The callback function that notifies the CFI on the activation of
  79722. + * an endpoint in the PCD. The following steps are done in this function:
  79723. + *
  79724. + * Create a dynamically allocated cfi_ep_t object (a CFI wrapper to the PCD's
  79725. + * active endpoint)
  79726. + * Create MAX_DMA_DESCS_PER_EP count DMA Descriptors for the EP
  79727. + * Set the Buffer Mode to standard
  79728. + * Initialize the default values for all EP modes (SG, Circular, Concat, Align)
  79729. + * Add the cfi_ep_t object to the list of active endpoints in the CFI object
  79730. + */
  79731. +static int cfi_ep_enable(struct cfiobject *cfi, struct dwc_otg_pcd *pcd,
  79732. + struct dwc_otg_pcd_ep *ep)
  79733. +{
  79734. + cfi_ep_t *cfiep;
  79735. + int retval = -DWC_E_NOT_SUPPORTED;
  79736. +
  79737. + CFI_INFO("%s: epname=%s; epnum=0x%02x\n", __func__,
  79738. + "EP_" /*ep->ep.name */ , ep->desc->bEndpointAddress);
  79739. + /* MAS - Check whether this endpoint already is in the list */
  79740. + cfiep = get_cfi_ep_by_pcd_ep(cfi, ep);
  79741. +
  79742. + if (NULL == cfiep) {
  79743. + /* Allocate a cfi_ep_t object */
  79744. + cfiep = DWC_ALLOC(sizeof(cfi_ep_t));
  79745. + if (NULL == cfiep) {
  79746. + CFI_INFO
  79747. + ("Unable to allocate memory for <cfiep> in function %s\n",
  79748. + __func__);
  79749. + return -DWC_E_NO_MEMORY;
  79750. + }
  79751. + dwc_memset(cfiep, 0, sizeof(cfi_ep_t));
  79752. +
  79753. + /* Save the dwc_otg_pcd_ep pointer in the cfiep object */
  79754. + cfiep->ep = ep;
  79755. +
  79756. + /* Allocate the DMA Descriptors chain of MAX_DMA_DESCS_PER_EP count */
  79757. + ep->dwc_ep.descs =
  79758. + DWC_DMA_ALLOC(MAX_DMA_DESCS_PER_EP *
  79759. + sizeof(dwc_otg_dma_desc_t),
  79760. + &ep->dwc_ep.descs_dma_addr);
  79761. +
  79762. + if (NULL == ep->dwc_ep.descs) {
  79763. + DWC_FREE(cfiep);
  79764. + return -DWC_E_NO_MEMORY;
  79765. + }
  79766. +
  79767. + DWC_LIST_INIT(&cfiep->lh);
  79768. +
  79769. + /* Set the buffer mode to BM_STANDARD. It will be modified
  79770. + * when building descriptors for a specific buffer mode */
  79771. + ep->dwc_ep.buff_mode = BM_STANDARD;
  79772. +
  79773. + /* Create and initialize the default values for this EP's Buffer modes */
  79774. + if ((retval = cfi_ep_init_defaults(pcd, cfiep)) < 0)
  79775. + return retval;
  79776. +
  79777. + /* Add the cfi_ep_t object to the CFI object's list of active endpoints */
  79778. + DWC_LIST_INSERT_TAIL(&cfi->active_eps, &cfiep->lh);
  79779. + retval = 0;
  79780. + } else { /* The sought EP already is in the list */
  79781. + CFI_INFO("%s: The sought EP already is in the list\n",
  79782. + __func__);
  79783. + }
  79784. +
  79785. + return retval;
  79786. +}
  79787. +
  79788. +/**
  79789. + * This function is called when the data stage of a 3-stage Control Write request
  79790. + * is complete.
  79791. + *
  79792. + */
  79793. +static int cfi_ctrl_write_complete(struct cfiobject *cfi,
  79794. + struct dwc_otg_pcd *pcd)
  79795. +{
  79796. + uint32_t addr, reg_value;
  79797. + uint16_t wIndex, wValue;
  79798. + uint8_t bRequest;
  79799. + uint8_t *buf = cfi->buf_out.buf;
  79800. + //struct usb_ctrlrequest *ctrl_req = &cfi->ctrl_req_saved;
  79801. + struct cfi_usb_ctrlrequest *ctrl_req = &cfi->ctrl_req;
  79802. + int retval = -DWC_E_NOT_SUPPORTED;
  79803. +
  79804. + CFI_INFO("%s\n", __func__);
  79805. +
  79806. + bRequest = ctrl_req->bRequest;
  79807. + wIndex = DWC_CONSTANT_CPU_TO_LE16(ctrl_req->wIndex);
  79808. + wValue = DWC_CONSTANT_CPU_TO_LE16(ctrl_req->wValue);
  79809. +
  79810. + /*
  79811. + * Save the pointer to the data stage in the ctrl_req's <data> field.
  79812. + * The request should be already saved in the command stage by now.
  79813. + */
  79814. + ctrl_req->data = cfi->buf_out.buf;
  79815. + cfi->need_status_in_complete = 0;
  79816. + cfi->need_gadget_att = 0;
  79817. +
  79818. + switch (bRequest) {
  79819. + case VEN_CORE_WRITE_REGISTER:
  79820. + /* The buffer contains raw data of the new value for the register */
  79821. + reg_value = *((uint32_t *) buf);
  79822. + if (wValue == 0) {
  79823. + addr = 0;
  79824. + //addr = (uint32_t) pcd->otg_dev->os_dep.base;
  79825. + addr += wIndex;
  79826. + } else {
  79827. + addr = (wValue << 16) | wIndex;
  79828. + }
  79829. +
  79830. + //writel(reg_value, addr);
  79831. +
  79832. + retval = 0;
  79833. + cfi->need_status_in_complete = 1;
  79834. + break;
  79835. +
  79836. + case VEN_CORE_SET_FEATURE:
  79837. + /* The buffer contains raw data of the new value of the feature */
  79838. + retval = cfi_set_feature_value(pcd);
  79839. + if (retval < 0)
  79840. + return retval;
  79841. +
  79842. + cfi->need_status_in_complete = 1;
  79843. + break;
  79844. +
  79845. + default:
  79846. + break;
  79847. + }
  79848. +
  79849. + return retval;
  79850. +}
  79851. +
  79852. +/**
  79853. + * This function builds the DMA descriptors for the SG buffer mode.
  79854. + */
  79855. +static void cfi_build_sg_descs(struct cfiobject *cfi, cfi_ep_t * cfiep,
  79856. + dwc_otg_pcd_request_t * req)
  79857. +{
  79858. + struct dwc_otg_pcd_ep *ep = cfiep->ep;
  79859. + ddma_sg_buffer_setup_t *sgval = cfiep->bm_sg;
  79860. + struct dwc_otg_dma_desc *desc = cfiep->ep->dwc_ep.descs;
  79861. + struct dwc_otg_dma_desc *desc_last = cfiep->ep->dwc_ep.descs;
  79862. + dma_addr_t buff_addr = req->dma;
  79863. + int i;
  79864. + uint32_t txsize, off;
  79865. +
  79866. + txsize = sgval->wSize;
  79867. + off = sgval->bOffset;
  79868. +
  79869. +// CFI_INFO("%s: %s TXSIZE=0x%08x; OFFSET=0x%08x\n",
  79870. +// __func__, cfiep->ep->ep.name, txsize, off);
  79871. +
  79872. + for (i = 0; i < sgval->bCount; i++) {
  79873. + desc->status.b.bs = BS_HOST_BUSY;
  79874. + desc->buf = buff_addr;
  79875. + desc->status.b.l = 0;
  79876. + desc->status.b.ioc = 0;
  79877. + desc->status.b.sp = 0;
  79878. + desc->status.b.bytes = txsize;
  79879. + desc->status.b.bs = BS_HOST_READY;
  79880. +
  79881. + /* Set the next address of the buffer */
  79882. + buff_addr += txsize + off;
  79883. + desc_last = desc;
  79884. + desc++;
  79885. + }
  79886. +
  79887. + /* Set the last, ioc and sp bits on the Last DMA Descriptor */
  79888. + desc_last->status.b.l = 1;
  79889. + desc_last->status.b.ioc = 1;
  79890. + desc_last->status.b.sp = ep->dwc_ep.sent_zlp;
  79891. + /* Save the last DMA descriptor pointer */
  79892. + cfiep->dma_desc_last = desc_last;
  79893. + cfiep->desc_count = sgval->bCount;
  79894. +}
  79895. +
  79896. +/**
  79897. + * This function builds the DMA descriptors for the Concatenation buffer mode.
  79898. + */
  79899. +static void cfi_build_concat_descs(struct cfiobject *cfi, cfi_ep_t * cfiep,
  79900. + dwc_otg_pcd_request_t * req)
  79901. +{
  79902. + struct dwc_otg_pcd_ep *ep = cfiep->ep;
  79903. + ddma_concat_buffer_setup_t *concatval = cfiep->bm_concat;
  79904. + struct dwc_otg_dma_desc *desc = cfiep->ep->dwc_ep.descs;
  79905. + struct dwc_otg_dma_desc *desc_last = cfiep->ep->dwc_ep.descs;
  79906. + dma_addr_t buff_addr = req->dma;
  79907. + int i;
  79908. + uint16_t *txsize;
  79909. +
  79910. + txsize = concatval->wTxBytes;
  79911. +
  79912. + for (i = 0; i < concatval->hdr.bDescCount; i++) {
  79913. + desc->buf = buff_addr;
  79914. + desc->status.b.bs = BS_HOST_BUSY;
  79915. + desc->status.b.l = 0;
  79916. + desc->status.b.ioc = 0;
  79917. + desc->status.b.sp = 0;
  79918. + desc->status.b.bytes = *txsize;
  79919. + desc->status.b.bs = BS_HOST_READY;
  79920. +
  79921. + txsize++;
  79922. + /* Set the next address of the buffer */
  79923. + buff_addr += UGETW(ep->desc->wMaxPacketSize);
  79924. + desc_last = desc;
  79925. + desc++;
  79926. + }
  79927. +
  79928. + /* Set the last, ioc and sp bits on the Last DMA Descriptor */
  79929. + desc_last->status.b.l = 1;
  79930. + desc_last->status.b.ioc = 1;
  79931. + desc_last->status.b.sp = ep->dwc_ep.sent_zlp;
  79932. + cfiep->dma_desc_last = desc_last;
  79933. + cfiep->desc_count = concatval->hdr.bDescCount;
  79934. +}
  79935. +
  79936. +/**
  79937. + * This function builds the DMA descriptors for the Circular buffer mode
  79938. + */
  79939. +static void cfi_build_circ_descs(struct cfiobject *cfi, cfi_ep_t * cfiep,
  79940. + dwc_otg_pcd_request_t * req)
  79941. +{
  79942. + /* @todo: MAS - add implementation when this feature needs to be tested */
  79943. +}
  79944. +
  79945. +/**
  79946. + * This function builds the DMA descriptors for the Alignment buffer mode
  79947. + */
  79948. +static void cfi_build_align_descs(struct cfiobject *cfi, cfi_ep_t * cfiep,
  79949. + dwc_otg_pcd_request_t * req)
  79950. +{
  79951. + struct dwc_otg_pcd_ep *ep = cfiep->ep;
  79952. + ddma_align_buffer_setup_t *alignval = cfiep->bm_align;
  79953. + struct dwc_otg_dma_desc *desc = cfiep->ep->dwc_ep.descs;
  79954. + dma_addr_t buff_addr = req->dma;
  79955. +
  79956. + desc->status.b.bs = BS_HOST_BUSY;
  79957. + desc->status.b.l = 1;
  79958. + desc->status.b.ioc = 1;
  79959. + desc->status.b.sp = ep->dwc_ep.sent_zlp;
  79960. + desc->status.b.bytes = req->length;
  79961. + /* Adjust the buffer alignment */
  79962. + desc->buf = (buff_addr + alignval->bAlign);
  79963. + desc->status.b.bs = BS_HOST_READY;
  79964. + cfiep->dma_desc_last = desc;
  79965. + cfiep->desc_count = 1;
  79966. +}
  79967. +
  79968. +/**
  79969. + * This function builds the DMA descriptors chain for different modes of the
  79970. + * buffer setup of an endpoint.
  79971. + */
  79972. +static void cfi_build_descriptors(struct cfiobject *cfi,
  79973. + struct dwc_otg_pcd *pcd,
  79974. + struct dwc_otg_pcd_ep *ep,
  79975. + dwc_otg_pcd_request_t * req)
  79976. +{
  79977. + cfi_ep_t *cfiep;
  79978. +
  79979. + /* Get the cfiep by the dwc_otg_pcd_ep */
  79980. + cfiep = get_cfi_ep_by_pcd_ep(cfi, ep);
  79981. + if (NULL == cfiep) {
  79982. + CFI_INFO("%s: Unable to find a matching active endpoint\n",
  79983. + __func__);
  79984. + return;
  79985. + }
  79986. +
  79987. + cfiep->xfer_len = req->length;
  79988. +
  79989. + /* Iterate through all the DMA descriptors */
  79990. + switch (cfiep->ep->dwc_ep.buff_mode) {
  79991. + case BM_SG:
  79992. + cfi_build_sg_descs(cfi, cfiep, req);
  79993. + break;
  79994. +
  79995. + case BM_CONCAT:
  79996. + cfi_build_concat_descs(cfi, cfiep, req);
  79997. + break;
  79998. +
  79999. + case BM_CIRCULAR:
  80000. + cfi_build_circ_descs(cfi, cfiep, req);
  80001. + break;
  80002. +
  80003. + case BM_ALIGN:
  80004. + cfi_build_align_descs(cfi, cfiep, req);
  80005. + break;
  80006. +
  80007. + default:
  80008. + break;
  80009. + }
  80010. +}
  80011. +
  80012. +/**
  80013. + * Allocate DMA buffer for different Buffer modes.
  80014. + */
  80015. +static void *cfi_ep_alloc_buf(struct cfiobject *cfi, struct dwc_otg_pcd *pcd,
  80016. + struct dwc_otg_pcd_ep *ep, dma_addr_t * dma,
  80017. + unsigned size, gfp_t flags)
  80018. +{
  80019. + return DWC_DMA_ALLOC(size, dma);
  80020. +}
  80021. +
  80022. +/**
  80023. + * This function initializes the CFI object.
  80024. + */
  80025. +int init_cfi(cfiobject_t * cfiobj)
  80026. +{
  80027. + CFI_INFO("%s\n", __func__);
  80028. +
  80029. + /* Allocate a buffer for IN XFERs */
  80030. + cfiobj->buf_in.buf =
  80031. + DWC_DMA_ALLOC(CFI_IN_BUF_LEN, &cfiobj->buf_in.addr);
  80032. + if (NULL == cfiobj->buf_in.buf) {
  80033. + CFI_INFO("Unable to allocate buffer for INs\n");
  80034. + return -DWC_E_NO_MEMORY;
  80035. + }
  80036. +
  80037. + /* Allocate a buffer for OUT XFERs */
  80038. + cfiobj->buf_out.buf =
  80039. + DWC_DMA_ALLOC(CFI_OUT_BUF_LEN, &cfiobj->buf_out.addr);
  80040. + if (NULL == cfiobj->buf_out.buf) {
  80041. + CFI_INFO("Unable to allocate buffer for OUT\n");
  80042. + return -DWC_E_NO_MEMORY;
  80043. + }
  80044. +
  80045. + /* Initialize the callback function pointers */
  80046. + cfiobj->ops.release = cfi_release;
  80047. + cfiobj->ops.ep_enable = cfi_ep_enable;
  80048. + cfiobj->ops.ctrl_write_complete = cfi_ctrl_write_complete;
  80049. + cfiobj->ops.build_descriptors = cfi_build_descriptors;
  80050. + cfiobj->ops.ep_alloc_buf = cfi_ep_alloc_buf;
  80051. +
  80052. + /* Initialize the list of active endpoints in the CFI object */
  80053. + DWC_LIST_INIT(&cfiobj->active_eps);
  80054. +
  80055. + return 0;
  80056. +}
  80057. +
  80058. +/**
  80059. + * This function reads the required feature's current value into the buffer
  80060. + *
  80061. + * @retval: Returns negative as error, or the data length of the feature
  80062. + */
  80063. +static int cfi_get_feature_value(uint8_t * buf, uint16_t buflen,
  80064. + struct dwc_otg_pcd *pcd,
  80065. + struct cfi_usb_ctrlrequest *ctrl_req)
  80066. +{
  80067. + int retval = -DWC_E_NOT_SUPPORTED;
  80068. + struct dwc_otg_core_if *coreif = GET_CORE_IF(pcd);
  80069. + uint16_t dfifo, rxfifo, txfifo;
  80070. +
  80071. + switch (ctrl_req->wIndex) {
  80072. + /* Whether the DDMA is enabled or not */
  80073. + case FT_ID_DMA_MODE:
  80074. + *buf = (coreif->dma_enable && coreif->dma_desc_enable) ? 1 : 0;
  80075. + retval = 1;
  80076. + break;
  80077. +
  80078. + case FT_ID_DMA_BUFFER_SETUP:
  80079. + retval = cfi_ep_get_sg_val(buf, pcd, ctrl_req);
  80080. + break;
  80081. +
  80082. + case FT_ID_DMA_BUFF_ALIGN:
  80083. + retval = cfi_ep_get_align_val(buf, pcd, ctrl_req);
  80084. + break;
  80085. +
  80086. + case FT_ID_DMA_CONCAT_SETUP:
  80087. + retval = cfi_ep_get_concat_val(buf, pcd, ctrl_req);
  80088. + break;
  80089. +
  80090. + case FT_ID_DMA_CIRCULAR:
  80091. + CFI_INFO("GetFeature value (FT_ID_DMA_CIRCULAR)\n");
  80092. + break;
  80093. +
  80094. + case FT_ID_THRESHOLD_SETUP:
  80095. + CFI_INFO("GetFeature value (FT_ID_THRESHOLD_SETUP)\n");
  80096. + break;
  80097. +
  80098. + case FT_ID_DFIFO_DEPTH:
  80099. + dfifo = get_dfifo_size(coreif);
  80100. + *((uint16_t *) buf) = dfifo;
  80101. + retval = sizeof(uint16_t);
  80102. + break;
  80103. +
  80104. + case FT_ID_TX_FIFO_DEPTH:
  80105. + retval = get_txfifo_size(pcd, ctrl_req->wValue);
  80106. + if (retval >= 0) {
  80107. + txfifo = retval;
  80108. + *((uint16_t *) buf) = txfifo;
  80109. + retval = sizeof(uint16_t);
  80110. + }
  80111. + break;
  80112. +
  80113. + case FT_ID_RX_FIFO_DEPTH:
  80114. + retval = get_rxfifo_size(coreif, ctrl_req->wValue);
  80115. + if (retval >= 0) {
  80116. + rxfifo = retval;
  80117. + *((uint16_t *) buf) = rxfifo;
  80118. + retval = sizeof(uint16_t);
  80119. + }
  80120. + break;
  80121. + }
  80122. +
  80123. + return retval;
  80124. +}
  80125. +
  80126. +/**
  80127. + * This function resets the SG for the specified EP to its default value
  80128. + */
  80129. +static int cfi_reset_sg_val(cfi_ep_t * cfiep)
  80130. +{
  80131. + dwc_memset(cfiep->bm_sg, 0, sizeof(ddma_sg_buffer_setup_t));
  80132. + return 0;
  80133. +}
  80134. +
  80135. +/**
  80136. + * This function resets the Alignment for the specified EP to its default value
  80137. + */
  80138. +static int cfi_reset_align_val(cfi_ep_t * cfiep)
  80139. +{
  80140. + dwc_memset(cfiep->bm_sg, 0, sizeof(ddma_sg_buffer_setup_t));
  80141. + return 0;
  80142. +}
  80143. +
  80144. +/**
  80145. + * This function resets the Concatenation for the specified EP to its default value
  80146. + * This function will also set the value of the wTxBytes field to NULL after
  80147. + * freeing the memory previously allocated for this field.
  80148. + */
  80149. +static int cfi_reset_concat_val(cfi_ep_t * cfiep)
  80150. +{
  80151. + /* First we need to free the wTxBytes field */
  80152. + if (cfiep->bm_concat->wTxBytes) {
  80153. + DWC_FREE(cfiep->bm_concat->wTxBytes);
  80154. + cfiep->bm_concat->wTxBytes = NULL;
  80155. + }
  80156. +
  80157. + dwc_memset(cfiep->bm_concat, 0, sizeof(ddma_concat_buffer_setup_t));
  80158. + return 0;
  80159. +}
  80160. +
  80161. +/**
  80162. + * This function resets all the buffer setups of the specified endpoint
  80163. + */
  80164. +static int cfi_ep_reset_all_setup_vals(cfi_ep_t * cfiep)
  80165. +{
  80166. + cfi_reset_sg_val(cfiep);
  80167. + cfi_reset_align_val(cfiep);
  80168. + cfi_reset_concat_val(cfiep);
  80169. + return 0;
  80170. +}
  80171. +
  80172. +static int cfi_handle_reset_fifo_val(struct dwc_otg_pcd *pcd, uint8_t ep_addr,
  80173. + uint8_t rx_rst, uint8_t tx_rst)
  80174. +{
  80175. + int retval = -DWC_E_INVALID;
  80176. + uint16_t tx_siz[15];
  80177. + uint16_t rx_siz = 0;
  80178. + dwc_otg_pcd_ep_t *ep = NULL;
  80179. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  80180. + dwc_otg_core_params_t *params = GET_CORE_IF(pcd)->core_params;
  80181. +
  80182. + if (rx_rst) {
  80183. + rx_siz = params->dev_rx_fifo_size;
  80184. + params->dev_rx_fifo_size = GET_CORE_IF(pcd)->init_rxfsiz;
  80185. + }
  80186. +
  80187. + if (tx_rst) {
  80188. + if (ep_addr == 0) {
  80189. + int i;
  80190. +
  80191. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  80192. + tx_siz[i] =
  80193. + core_if->core_params->dev_tx_fifo_size[i];
  80194. + core_if->core_params->dev_tx_fifo_size[i] =
  80195. + core_if->init_txfsiz[i];
  80196. + }
  80197. + } else {
  80198. +
  80199. + ep = get_ep_by_addr(pcd, ep_addr);
  80200. +
  80201. + if (NULL == ep) {
  80202. + CFI_INFO
  80203. + ("%s: Unable to get the endpoint addr=0x%02x\n",
  80204. + __func__, ep_addr);
  80205. + return -DWC_E_INVALID;
  80206. + }
  80207. +
  80208. + tx_siz[0] =
  80209. + params->dev_tx_fifo_size[ep->dwc_ep.tx_fifo_num -
  80210. + 1];
  80211. + params->dev_tx_fifo_size[ep->dwc_ep.tx_fifo_num - 1] =
  80212. + GET_CORE_IF(pcd)->init_txfsiz[ep->
  80213. + dwc_ep.tx_fifo_num -
  80214. + 1];
  80215. + }
  80216. + }
  80217. +
  80218. + if (resize_fifos(GET_CORE_IF(pcd))) {
  80219. + retval = 0;
  80220. + } else {
  80221. + CFI_INFO
  80222. + ("%s: Error resetting the feature Reset All(FIFO size)\n",
  80223. + __func__);
  80224. + if (rx_rst) {
  80225. + params->dev_rx_fifo_size = rx_siz;
  80226. + }
  80227. +
  80228. + if (tx_rst) {
  80229. + if (ep_addr == 0) {
  80230. + int i;
  80231. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps;
  80232. + i++) {
  80233. + core_if->
  80234. + core_params->dev_tx_fifo_size[i] =
  80235. + tx_siz[i];
  80236. + }
  80237. + } else {
  80238. + params->dev_tx_fifo_size[ep->
  80239. + dwc_ep.tx_fifo_num -
  80240. + 1] = tx_siz[0];
  80241. + }
  80242. + }
  80243. + retval = -DWC_E_INVALID;
  80244. + }
  80245. + return retval;
  80246. +}
  80247. +
  80248. +static int cfi_handle_reset_all(struct dwc_otg_pcd *pcd, uint8_t addr)
  80249. +{
  80250. + int retval = 0;
  80251. + cfi_ep_t *cfiep;
  80252. + cfiobject_t *cfi = pcd->cfi;
  80253. + dwc_list_link_t *tmp;
  80254. +
  80255. + retval = cfi_handle_reset_fifo_val(pcd, addr, 1, 1);
  80256. + if (retval < 0) {
  80257. + return retval;
  80258. + }
  80259. +
  80260. + /* If the EP address is known then reset the features for only that EP */
  80261. + if (addr) {
  80262. + cfiep = get_cfi_ep_by_addr(pcd->cfi, addr);
  80263. + if (NULL == cfiep) {
  80264. + CFI_INFO("%s: Error getting the EP address 0x%02x\n",
  80265. + __func__, addr);
  80266. + return -DWC_E_INVALID;
  80267. + }
  80268. + retval = cfi_ep_reset_all_setup_vals(cfiep);
  80269. + cfiep->ep->dwc_ep.buff_mode = BM_STANDARD;
  80270. + }
  80271. + /* Otherwise (wValue == 0), reset all features of all EP's */
  80272. + else {
  80273. + /* Traverse all the active EP's and reset the feature(s) value(s) */
  80274. + //list_for_each_entry(cfiep, &cfi->active_eps, lh) {
  80275. + DWC_LIST_FOREACH(tmp, &cfi->active_eps) {
  80276. + cfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  80277. + retval = cfi_ep_reset_all_setup_vals(cfiep);
  80278. + cfiep->ep->dwc_ep.buff_mode = BM_STANDARD;
  80279. + if (retval < 0) {
  80280. + CFI_INFO
  80281. + ("%s: Error resetting the feature Reset All\n",
  80282. + __func__);
  80283. + return retval;
  80284. + }
  80285. + }
  80286. + }
  80287. + return retval;
  80288. +}
  80289. +
  80290. +static int cfi_handle_reset_dma_buff_setup(struct dwc_otg_pcd *pcd,
  80291. + uint8_t addr)
  80292. +{
  80293. + int retval = 0;
  80294. + cfi_ep_t *cfiep;
  80295. + cfiobject_t *cfi = pcd->cfi;
  80296. + dwc_list_link_t *tmp;
  80297. +
  80298. + /* If the EP address is known then reset the features for only that EP */
  80299. + if (addr) {
  80300. + cfiep = get_cfi_ep_by_addr(pcd->cfi, addr);
  80301. + if (NULL == cfiep) {
  80302. + CFI_INFO("%s: Error getting the EP address 0x%02x\n",
  80303. + __func__, addr);
  80304. + return -DWC_E_INVALID;
  80305. + }
  80306. + retval = cfi_reset_sg_val(cfiep);
  80307. + }
  80308. + /* Otherwise (wValue == 0), reset all features of all EP's */
  80309. + else {
  80310. + /* Traverse all the active EP's and reset the feature(s) value(s) */
  80311. + //list_for_each_entry(cfiep, &cfi->active_eps, lh) {
  80312. + DWC_LIST_FOREACH(tmp, &cfi->active_eps) {
  80313. + cfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  80314. + retval = cfi_reset_sg_val(cfiep);
  80315. + if (retval < 0) {
  80316. + CFI_INFO
  80317. + ("%s: Error resetting the feature Buffer Setup\n",
  80318. + __func__);
  80319. + return retval;
  80320. + }
  80321. + }
  80322. + }
  80323. + return retval;
  80324. +}
  80325. +
  80326. +static int cfi_handle_reset_concat_val(struct dwc_otg_pcd *pcd, uint8_t addr)
  80327. +{
  80328. + int retval = 0;
  80329. + cfi_ep_t *cfiep;
  80330. + cfiobject_t *cfi = pcd->cfi;
  80331. + dwc_list_link_t *tmp;
  80332. +
  80333. + /* If the EP address is known then reset the features for only that EP */
  80334. + if (addr) {
  80335. + cfiep = get_cfi_ep_by_addr(pcd->cfi, addr);
  80336. + if (NULL == cfiep) {
  80337. + CFI_INFO("%s: Error getting the EP address 0x%02x\n",
  80338. + __func__, addr);
  80339. + return -DWC_E_INVALID;
  80340. + }
  80341. + retval = cfi_reset_concat_val(cfiep);
  80342. + }
  80343. + /* Otherwise (wValue == 0), reset all features of all EP's */
  80344. + else {
  80345. + /* Traverse all the active EP's and reset the feature(s) value(s) */
  80346. + //list_for_each_entry(cfiep, &cfi->active_eps, lh) {
  80347. + DWC_LIST_FOREACH(tmp, &cfi->active_eps) {
  80348. + cfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  80349. + retval = cfi_reset_concat_val(cfiep);
  80350. + if (retval < 0) {
  80351. + CFI_INFO
  80352. + ("%s: Error resetting the feature Concatenation Value\n",
  80353. + __func__);
  80354. + return retval;
  80355. + }
  80356. + }
  80357. + }
  80358. + return retval;
  80359. +}
  80360. +
  80361. +static int cfi_handle_reset_align_val(struct dwc_otg_pcd *pcd, uint8_t addr)
  80362. +{
  80363. + int retval = 0;
  80364. + cfi_ep_t *cfiep;
  80365. + cfiobject_t *cfi = pcd->cfi;
  80366. + dwc_list_link_t *tmp;
  80367. +
  80368. + /* If the EP address is known then reset the features for only that EP */
  80369. + if (addr) {
  80370. + cfiep = get_cfi_ep_by_addr(pcd->cfi, addr);
  80371. + if (NULL == cfiep) {
  80372. + CFI_INFO("%s: Error getting the EP address 0x%02x\n",
  80373. + __func__, addr);
  80374. + return -DWC_E_INVALID;
  80375. + }
  80376. + retval = cfi_reset_align_val(cfiep);
  80377. + }
  80378. + /* Otherwise (wValue == 0), reset all features of all EP's */
  80379. + else {
  80380. + /* Traverse all the active EP's and reset the feature(s) value(s) */
  80381. + //list_for_each_entry(cfiep, &cfi->active_eps, lh) {
  80382. + DWC_LIST_FOREACH(tmp, &cfi->active_eps) {
  80383. + cfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  80384. + retval = cfi_reset_align_val(cfiep);
  80385. + if (retval < 0) {
  80386. + CFI_INFO
  80387. + ("%s: Error resetting the feature Aliignment Value\n",
  80388. + __func__);
  80389. + return retval;
  80390. + }
  80391. + }
  80392. + }
  80393. + return retval;
  80394. +
  80395. +}
  80396. +
  80397. +static int cfi_preproc_reset(struct dwc_otg_pcd *pcd,
  80398. + struct cfi_usb_ctrlrequest *req)
  80399. +{
  80400. + int retval = 0;
  80401. +
  80402. + switch (req->wIndex) {
  80403. + case 0:
  80404. + /* Reset all features */
  80405. + retval = cfi_handle_reset_all(pcd, req->wValue & 0xff);
  80406. + break;
  80407. +
  80408. + case FT_ID_DMA_BUFFER_SETUP:
  80409. + /* Reset the SG buffer setup */
  80410. + retval =
  80411. + cfi_handle_reset_dma_buff_setup(pcd, req->wValue & 0xff);
  80412. + break;
  80413. +
  80414. + case FT_ID_DMA_CONCAT_SETUP:
  80415. + /* Reset the Concatenation buffer setup */
  80416. + retval = cfi_handle_reset_concat_val(pcd, req->wValue & 0xff);
  80417. + break;
  80418. +
  80419. + case FT_ID_DMA_BUFF_ALIGN:
  80420. + /* Reset the Alignment buffer setup */
  80421. + retval = cfi_handle_reset_align_val(pcd, req->wValue & 0xff);
  80422. + break;
  80423. +
  80424. + case FT_ID_TX_FIFO_DEPTH:
  80425. + retval =
  80426. + cfi_handle_reset_fifo_val(pcd, req->wValue & 0xff, 0, 1);
  80427. + pcd->cfi->need_gadget_att = 0;
  80428. + break;
  80429. +
  80430. + case FT_ID_RX_FIFO_DEPTH:
  80431. + retval = cfi_handle_reset_fifo_val(pcd, 0, 1, 0);
  80432. + pcd->cfi->need_gadget_att = 0;
  80433. + break;
  80434. + default:
  80435. + break;
  80436. + }
  80437. + return retval;
  80438. +}
  80439. +
  80440. +/**
  80441. + * This function sets a new value for the SG buffer setup.
  80442. + */
  80443. +static int cfi_ep_set_sg_val(uint8_t * buf, struct dwc_otg_pcd *pcd)
  80444. +{
  80445. + uint8_t inaddr, outaddr;
  80446. + cfi_ep_t *epin, *epout;
  80447. + ddma_sg_buffer_setup_t *psgval;
  80448. + uint32_t desccount, size;
  80449. +
  80450. + CFI_INFO("%s\n", __func__);
  80451. +
  80452. + psgval = (ddma_sg_buffer_setup_t *) buf;
  80453. + desccount = (uint32_t) psgval->bCount;
  80454. + size = (uint32_t) psgval->wSize;
  80455. +
  80456. + /* Check the DMA descriptor count */
  80457. + if ((desccount > MAX_DMA_DESCS_PER_EP) || (desccount == 0)) {
  80458. + CFI_INFO
  80459. + ("%s: The count of DMA Descriptors should be between 1 and %d\n",
  80460. + __func__, MAX_DMA_DESCS_PER_EP);
  80461. + return -DWC_E_INVALID;
  80462. + }
  80463. +
  80464. + /* Check the DMA descriptor count */
  80465. +
  80466. + if (size == 0) {
  80467. +
  80468. + CFI_INFO("%s: The transfer size should be at least 1 byte\n",
  80469. + __func__);
  80470. +
  80471. + return -DWC_E_INVALID;
  80472. +
  80473. + }
  80474. +
  80475. + inaddr = psgval->bInEndpointAddress;
  80476. + outaddr = psgval->bOutEndpointAddress;
  80477. +
  80478. + epin = get_cfi_ep_by_addr(pcd->cfi, inaddr);
  80479. + epout = get_cfi_ep_by_addr(pcd->cfi, outaddr);
  80480. +
  80481. + if (NULL == epin || NULL == epout) {
  80482. + CFI_INFO
  80483. + ("%s: Unable to get the endpoints inaddr=0x%02x outaddr=0x%02x\n",
  80484. + __func__, inaddr, outaddr);
  80485. + return -DWC_E_INVALID;
  80486. + }
  80487. +
  80488. + epin->ep->dwc_ep.buff_mode = BM_SG;
  80489. + dwc_memcpy(epin->bm_sg, psgval, sizeof(ddma_sg_buffer_setup_t));
  80490. +
  80491. + epout->ep->dwc_ep.buff_mode = BM_SG;
  80492. + dwc_memcpy(epout->bm_sg, psgval, sizeof(ddma_sg_buffer_setup_t));
  80493. +
  80494. + return 0;
  80495. +}
  80496. +
  80497. +/**
  80498. + * This function sets a new value for the buffer Alignment setup.
  80499. + */
  80500. +static int cfi_ep_set_alignment_val(uint8_t * buf, struct dwc_otg_pcd *pcd)
  80501. +{
  80502. + cfi_ep_t *ep;
  80503. + uint8_t addr;
  80504. + ddma_align_buffer_setup_t *palignval;
  80505. +
  80506. + palignval = (ddma_align_buffer_setup_t *) buf;
  80507. + addr = palignval->bEndpointAddress;
  80508. +
  80509. + ep = get_cfi_ep_by_addr(pcd->cfi, addr);
  80510. +
  80511. + if (NULL == ep) {
  80512. + CFI_INFO("%s: Unable to get the endpoint addr=0x%02x\n",
  80513. + __func__, addr);
  80514. + return -DWC_E_INVALID;
  80515. + }
  80516. +
  80517. + ep->ep->dwc_ep.buff_mode = BM_ALIGN;
  80518. + dwc_memcpy(ep->bm_align, palignval, sizeof(ddma_align_buffer_setup_t));
  80519. +
  80520. + return 0;
  80521. +}
  80522. +
  80523. +/**
  80524. + * This function sets a new value for the Concatenation buffer setup.
  80525. + */
  80526. +static int cfi_ep_set_concat_val(uint8_t * buf, struct dwc_otg_pcd *pcd)
  80527. +{
  80528. + uint8_t addr;
  80529. + cfi_ep_t *ep;
  80530. + struct _ddma_concat_buffer_setup_hdr *pConcatValHdr;
  80531. + uint16_t *pVals;
  80532. + uint32_t desccount;
  80533. + int i;
  80534. + uint16_t mps;
  80535. +
  80536. + pConcatValHdr = (struct _ddma_concat_buffer_setup_hdr *)buf;
  80537. + desccount = (uint32_t) pConcatValHdr->bDescCount;
  80538. + pVals = (uint16_t *) (buf + BS_CONCAT_VAL_HDR_LEN);
  80539. +
  80540. + /* Check the DMA descriptor count */
  80541. + if (desccount > MAX_DMA_DESCS_PER_EP) {
  80542. + CFI_INFO("%s: Maximum DMA Descriptor count should be %d\n",
  80543. + __func__, MAX_DMA_DESCS_PER_EP);
  80544. + return -DWC_E_INVALID;
  80545. + }
  80546. +
  80547. + addr = pConcatValHdr->bEndpointAddress;
  80548. + ep = get_cfi_ep_by_addr(pcd->cfi, addr);
  80549. + if (NULL == ep) {
  80550. + CFI_INFO("%s: Unable to get the endpoint addr=0x%02x\n",
  80551. + __func__, addr);
  80552. + return -DWC_E_INVALID;
  80553. + }
  80554. +
  80555. + mps = UGETW(ep->ep->desc->wMaxPacketSize);
  80556. +
  80557. +#if 0
  80558. + for (i = 0; i < desccount; i++) {
  80559. + CFI_INFO("%s: wTxSize[%d]=0x%04x\n", __func__, i, pVals[i]);
  80560. + }
  80561. + CFI_INFO("%s: epname=%s; mps=%d\n", __func__, ep->ep->ep.name, mps);
  80562. +#endif
  80563. +
  80564. + /* Check the wTxSizes to be less than or equal to the mps */
  80565. + for (i = 0; i < desccount; i++) {
  80566. + if (pVals[i] > mps) {
  80567. + CFI_INFO
  80568. + ("%s: ERROR - the wTxSize[%d] should be <= MPS (wTxSize=%d)\n",
  80569. + __func__, i, pVals[i]);
  80570. + return -DWC_E_INVALID;
  80571. + }
  80572. + }
  80573. +
  80574. + ep->ep->dwc_ep.buff_mode = BM_CONCAT;
  80575. + dwc_memcpy(ep->bm_concat, pConcatValHdr, BS_CONCAT_VAL_HDR_LEN);
  80576. +
  80577. + /* Free the previously allocated storage for the wTxBytes */
  80578. + if (ep->bm_concat->wTxBytes) {
  80579. + DWC_FREE(ep->bm_concat->wTxBytes);
  80580. + }
  80581. +
  80582. + /* Allocate a new storage for the wTxBytes field */
  80583. + ep->bm_concat->wTxBytes =
  80584. + DWC_ALLOC(sizeof(uint16_t) * pConcatValHdr->bDescCount);
  80585. + if (NULL == ep->bm_concat->wTxBytes) {
  80586. + CFI_INFO("%s: Unable to allocate memory\n", __func__);
  80587. + return -DWC_E_NO_MEMORY;
  80588. + }
  80589. +
  80590. + /* Copy the new values into the wTxBytes filed */
  80591. + dwc_memcpy(ep->bm_concat->wTxBytes, buf + BS_CONCAT_VAL_HDR_LEN,
  80592. + sizeof(uint16_t) * pConcatValHdr->bDescCount);
  80593. +
  80594. + return 0;
  80595. +}
  80596. +
  80597. +/**
  80598. + * This function calculates the total of all FIFO sizes
  80599. + *
  80600. + * @param core_if Programming view of DWC_otg controller
  80601. + *
  80602. + * @return The total of data FIFO sizes.
  80603. + *
  80604. + */
  80605. +static uint16_t get_dfifo_size(dwc_otg_core_if_t * core_if)
  80606. +{
  80607. + dwc_otg_core_params_t *params = core_if->core_params;
  80608. + uint16_t dfifo_total = 0;
  80609. + int i;
  80610. +
  80611. + /* The shared RxFIFO size */
  80612. + dfifo_total =
  80613. + params->dev_rx_fifo_size + params->dev_nperio_tx_fifo_size;
  80614. +
  80615. + /* Add up each TxFIFO size to the total */
  80616. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  80617. + dfifo_total += params->dev_tx_fifo_size[i];
  80618. + }
  80619. +
  80620. + return dfifo_total;
  80621. +}
  80622. +
  80623. +/**
  80624. + * This function returns Rx FIFO size
  80625. + *
  80626. + * @param core_if Programming view of DWC_otg controller
  80627. + *
  80628. + * @return The total of data FIFO sizes.
  80629. + *
  80630. + */
  80631. +static int32_t get_rxfifo_size(dwc_otg_core_if_t * core_if, uint16_t wValue)
  80632. +{
  80633. + switch (wValue >> 8) {
  80634. + case 0:
  80635. + return (core_if->pwron_rxfsiz <
  80636. + 32768) ? core_if->pwron_rxfsiz : 32768;
  80637. + break;
  80638. + case 1:
  80639. + return core_if->core_params->dev_rx_fifo_size;
  80640. + break;
  80641. + default:
  80642. + return -DWC_E_INVALID;
  80643. + break;
  80644. + }
  80645. +}
  80646. +
  80647. +/**
  80648. + * This function returns Tx FIFO size for IN EP
  80649. + *
  80650. + * @param core_if Programming view of DWC_otg controller
  80651. + *
  80652. + * @return The total of data FIFO sizes.
  80653. + *
  80654. + */
  80655. +static int32_t get_txfifo_size(struct dwc_otg_pcd *pcd, uint16_t wValue)
  80656. +{
  80657. + dwc_otg_pcd_ep_t *ep;
  80658. +
  80659. + ep = get_ep_by_addr(pcd, wValue & 0xff);
  80660. +
  80661. + if (NULL == ep) {
  80662. + CFI_INFO("%s: Unable to get the endpoint addr=0x%02x\n",
  80663. + __func__, wValue & 0xff);
  80664. + return -DWC_E_INVALID;
  80665. + }
  80666. +
  80667. + if (!ep->dwc_ep.is_in) {
  80668. + CFI_INFO
  80669. + ("%s: No Tx FIFO assingned to the Out endpoint addr=0x%02x\n",
  80670. + __func__, wValue & 0xff);
  80671. + return -DWC_E_INVALID;
  80672. + }
  80673. +
  80674. + switch (wValue >> 8) {
  80675. + case 0:
  80676. + return (GET_CORE_IF(pcd)->pwron_txfsiz
  80677. + [ep->dwc_ep.tx_fifo_num - 1] <
  80678. + 768) ? GET_CORE_IF(pcd)->pwron_txfsiz[ep->
  80679. + dwc_ep.tx_fifo_num
  80680. + - 1] : 32768;
  80681. + break;
  80682. + case 1:
  80683. + return GET_CORE_IF(pcd)->core_params->
  80684. + dev_tx_fifo_size[ep->dwc_ep.num - 1];
  80685. + break;
  80686. + default:
  80687. + return -DWC_E_INVALID;
  80688. + break;
  80689. + }
  80690. +}
  80691. +
  80692. +/**
  80693. + * This function checks if the submitted combination of
  80694. + * device mode FIFO sizes is possible or not.
  80695. + *
  80696. + * @param core_if Programming view of DWC_otg controller
  80697. + *
  80698. + * @return 1 if possible, 0 otherwise.
  80699. + *
  80700. + */
  80701. +static uint8_t check_fifo_sizes(dwc_otg_core_if_t * core_if)
  80702. +{
  80703. + uint16_t dfifo_actual = 0;
  80704. + dwc_otg_core_params_t *params = core_if->core_params;
  80705. + uint16_t start_addr = 0;
  80706. + int i;
  80707. +
  80708. + dfifo_actual =
  80709. + params->dev_rx_fifo_size + params->dev_nperio_tx_fifo_size;
  80710. +
  80711. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  80712. + dfifo_actual += params->dev_tx_fifo_size[i];
  80713. + }
  80714. +
  80715. + if (dfifo_actual > core_if->total_fifo_size) {
  80716. + return 0;
  80717. + }
  80718. +
  80719. + if (params->dev_rx_fifo_size > 32768 || params->dev_rx_fifo_size < 16)
  80720. + return 0;
  80721. +
  80722. + if (params->dev_nperio_tx_fifo_size > 32768
  80723. + || params->dev_nperio_tx_fifo_size < 16)
  80724. + return 0;
  80725. +
  80726. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  80727. +
  80728. + if (params->dev_tx_fifo_size[i] > 768
  80729. + || params->dev_tx_fifo_size[i] < 4)
  80730. + return 0;
  80731. + }
  80732. +
  80733. + if (params->dev_rx_fifo_size > core_if->pwron_rxfsiz)
  80734. + return 0;
  80735. + start_addr = params->dev_rx_fifo_size;
  80736. +
  80737. + if (params->dev_nperio_tx_fifo_size > core_if->pwron_gnptxfsiz)
  80738. + return 0;
  80739. + start_addr += params->dev_nperio_tx_fifo_size;
  80740. +
  80741. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  80742. +
  80743. + if (params->dev_tx_fifo_size[i] > core_if->pwron_txfsiz[i])
  80744. + return 0;
  80745. + start_addr += params->dev_tx_fifo_size[i];
  80746. + }
  80747. +
  80748. + return 1;
  80749. +}
  80750. +
  80751. +/**
  80752. + * This function resizes Device mode FIFOs
  80753. + *
  80754. + * @param core_if Programming view of DWC_otg controller
  80755. + *
  80756. + * @return 1 if successful, 0 otherwise
  80757. + *
  80758. + */
  80759. +static uint8_t resize_fifos(dwc_otg_core_if_t * core_if)
  80760. +{
  80761. + int i = 0;
  80762. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  80763. + dwc_otg_core_params_t *params = core_if->core_params;
  80764. + uint32_t rx_fifo_size;
  80765. + fifosize_data_t nptxfifosize;
  80766. + fifosize_data_t txfifosize[15];
  80767. +
  80768. + uint32_t rx_fsz_bak;
  80769. + uint32_t nptxfsz_bak;
  80770. + uint32_t txfsz_bak[15];
  80771. +
  80772. + uint16_t start_address;
  80773. + uint8_t retval = 1;
  80774. +
  80775. + if (!check_fifo_sizes(core_if)) {
  80776. + return 0;
  80777. + }
  80778. +
  80779. + /* Configure data FIFO sizes */
  80780. + if (core_if->hwcfg2.b.dynamic_fifo && params->enable_dynamic_fifo) {
  80781. + rx_fsz_bak = DWC_READ_REG32(&global_regs->grxfsiz);
  80782. + rx_fifo_size = params->dev_rx_fifo_size;
  80783. + DWC_WRITE_REG32(&global_regs->grxfsiz, rx_fifo_size);
  80784. +
  80785. + /*
  80786. + * Tx FIFOs These FIFOs are numbered from 1 to 15.
  80787. + * Indexes of the FIFO size module parameters in the
  80788. + * dev_tx_fifo_size array and the FIFO size registers in
  80789. + * the dtxfsiz array run from 0 to 14.
  80790. + */
  80791. +
  80792. + /* Non-periodic Tx FIFO */
  80793. + nptxfsz_bak = DWC_READ_REG32(&global_regs->gnptxfsiz);
  80794. + nptxfifosize.b.depth = params->dev_nperio_tx_fifo_size;
  80795. + start_address = params->dev_rx_fifo_size;
  80796. + nptxfifosize.b.startaddr = start_address;
  80797. +
  80798. + DWC_WRITE_REG32(&global_regs->gnptxfsiz, nptxfifosize.d32);
  80799. +
  80800. + start_address += nptxfifosize.b.depth;
  80801. +
  80802. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  80803. + txfsz_bak[i] = DWC_READ_REG32(&global_regs->dtxfsiz[i]);
  80804. +
  80805. + txfifosize[i].b.depth = params->dev_tx_fifo_size[i];
  80806. + txfifosize[i].b.startaddr = start_address;
  80807. + DWC_WRITE_REG32(&global_regs->dtxfsiz[i],
  80808. + txfifosize[i].d32);
  80809. +
  80810. + start_address += txfifosize[i].b.depth;
  80811. + }
  80812. +
  80813. + /** Check if register values are set correctly */
  80814. + if (rx_fifo_size != DWC_READ_REG32(&global_regs->grxfsiz)) {
  80815. + retval = 0;
  80816. + }
  80817. +
  80818. + if (nptxfifosize.d32 != DWC_READ_REG32(&global_regs->gnptxfsiz)) {
  80819. + retval = 0;
  80820. + }
  80821. +
  80822. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  80823. + if (txfifosize[i].d32 !=
  80824. + DWC_READ_REG32(&global_regs->dtxfsiz[i])) {
  80825. + retval = 0;
  80826. + }
  80827. + }
  80828. +
  80829. + /** If register values are not set correctly, reset old values */
  80830. + if (retval == 0) {
  80831. + DWC_WRITE_REG32(&global_regs->grxfsiz, rx_fsz_bak);
  80832. +
  80833. + /* Non-periodic Tx FIFO */
  80834. + DWC_WRITE_REG32(&global_regs->gnptxfsiz, nptxfsz_bak);
  80835. +
  80836. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  80837. + DWC_WRITE_REG32(&global_regs->dtxfsiz[i],
  80838. + txfsz_bak[i]);
  80839. + }
  80840. + }
  80841. + } else {
  80842. + return 0;
  80843. + }
  80844. +
  80845. + /* Flush the FIFOs */
  80846. + dwc_otg_flush_tx_fifo(core_if, 0x10); /* all Tx FIFOs */
  80847. + dwc_otg_flush_rx_fifo(core_if);
  80848. +
  80849. + return retval;
  80850. +}
  80851. +
  80852. +/**
  80853. + * This function sets a new value for the buffer Alignment setup.
  80854. + */
  80855. +static int cfi_ep_set_tx_fifo_val(uint8_t * buf, dwc_otg_pcd_t * pcd)
  80856. +{
  80857. + int retval;
  80858. + uint32_t fsiz;
  80859. + uint16_t size;
  80860. + uint16_t ep_addr;
  80861. + dwc_otg_pcd_ep_t *ep;
  80862. + dwc_otg_core_params_t *params = GET_CORE_IF(pcd)->core_params;
  80863. + tx_fifo_size_setup_t *ptxfifoval;
  80864. +
  80865. + ptxfifoval = (tx_fifo_size_setup_t *) buf;
  80866. + ep_addr = ptxfifoval->bEndpointAddress;
  80867. + size = ptxfifoval->wDepth;
  80868. +
  80869. + ep = get_ep_by_addr(pcd, ep_addr);
  80870. +
  80871. + CFI_INFO
  80872. + ("%s: Set Tx FIFO size: endpoint addr=0x%02x, depth=%d, FIFO Num=%d\n",
  80873. + __func__, ep_addr, size, ep->dwc_ep.tx_fifo_num);
  80874. +
  80875. + if (NULL == ep) {
  80876. + CFI_INFO("%s: Unable to get the endpoint addr=0x%02x\n",
  80877. + __func__, ep_addr);
  80878. + return -DWC_E_INVALID;
  80879. + }
  80880. +
  80881. + fsiz = params->dev_tx_fifo_size[ep->dwc_ep.tx_fifo_num - 1];
  80882. + params->dev_tx_fifo_size[ep->dwc_ep.tx_fifo_num - 1] = size;
  80883. +
  80884. + if (resize_fifos(GET_CORE_IF(pcd))) {
  80885. + retval = 0;
  80886. + } else {
  80887. + CFI_INFO
  80888. + ("%s: Error setting the feature Tx FIFO Size for EP%d\n",
  80889. + __func__, ep_addr);
  80890. + params->dev_tx_fifo_size[ep->dwc_ep.tx_fifo_num - 1] = fsiz;
  80891. + retval = -DWC_E_INVALID;
  80892. + }
  80893. +
  80894. + return retval;
  80895. +}
  80896. +
  80897. +/**
  80898. + * This function sets a new value for the buffer Alignment setup.
  80899. + */
  80900. +static int cfi_set_rx_fifo_val(uint8_t * buf, dwc_otg_pcd_t * pcd)
  80901. +{
  80902. + int retval;
  80903. + uint32_t fsiz;
  80904. + uint16_t size;
  80905. + dwc_otg_core_params_t *params = GET_CORE_IF(pcd)->core_params;
  80906. + rx_fifo_size_setup_t *prxfifoval;
  80907. +
  80908. + prxfifoval = (rx_fifo_size_setup_t *) buf;
  80909. + size = prxfifoval->wDepth;
  80910. +
  80911. + fsiz = params->dev_rx_fifo_size;
  80912. + params->dev_rx_fifo_size = size;
  80913. +
  80914. + if (resize_fifos(GET_CORE_IF(pcd))) {
  80915. + retval = 0;
  80916. + } else {
  80917. + CFI_INFO("%s: Error setting the feature Rx FIFO Size\n",
  80918. + __func__);
  80919. + params->dev_rx_fifo_size = fsiz;
  80920. + retval = -DWC_E_INVALID;
  80921. + }
  80922. +
  80923. + return retval;
  80924. +}
  80925. +
  80926. +/**
  80927. + * This function reads the SG of an EP's buffer setup into the buffer buf
  80928. + */
  80929. +static int cfi_ep_get_sg_val(uint8_t * buf, struct dwc_otg_pcd *pcd,
  80930. + struct cfi_usb_ctrlrequest *req)
  80931. +{
  80932. + int retval = -DWC_E_INVALID;
  80933. + uint8_t addr;
  80934. + cfi_ep_t *ep;
  80935. +
  80936. + /* The Low Byte of the wValue contains a non-zero address of the endpoint */
  80937. + addr = req->wValue & 0xFF;
  80938. + if (addr == 0) /* The address should be non-zero */
  80939. + return retval;
  80940. +
  80941. + ep = get_cfi_ep_by_addr(pcd->cfi, addr);
  80942. + if (NULL == ep) {
  80943. + CFI_INFO("%s: Unable to get the endpoint address(0x%02x)\n",
  80944. + __func__, addr);
  80945. + return retval;
  80946. + }
  80947. +
  80948. + dwc_memcpy(buf, ep->bm_sg, BS_SG_VAL_DESC_LEN);
  80949. + retval = BS_SG_VAL_DESC_LEN;
  80950. + return retval;
  80951. +}
  80952. +
  80953. +/**
  80954. + * This function reads the Concatenation value of an EP's buffer mode into
  80955. + * the buffer buf
  80956. + */
  80957. +static int cfi_ep_get_concat_val(uint8_t * buf, struct dwc_otg_pcd *pcd,
  80958. + struct cfi_usb_ctrlrequest *req)
  80959. +{
  80960. + int retval = -DWC_E_INVALID;
  80961. + uint8_t addr;
  80962. + cfi_ep_t *ep;
  80963. + uint8_t desc_count;
  80964. +
  80965. + /* The Low Byte of the wValue contains a non-zero address of the endpoint */
  80966. + addr = req->wValue & 0xFF;
  80967. + if (addr == 0) /* The address should be non-zero */
  80968. + return retval;
  80969. +
  80970. + ep = get_cfi_ep_by_addr(pcd->cfi, addr);
  80971. + if (NULL == ep) {
  80972. + CFI_INFO("%s: Unable to get the endpoint address(0x%02x)\n",
  80973. + __func__, addr);
  80974. + return retval;
  80975. + }
  80976. +
  80977. + /* Copy the header to the buffer */
  80978. + dwc_memcpy(buf, ep->bm_concat, BS_CONCAT_VAL_HDR_LEN);
  80979. + /* Advance the buffer pointer by the header size */
  80980. + buf += BS_CONCAT_VAL_HDR_LEN;
  80981. +
  80982. + desc_count = ep->bm_concat->hdr.bDescCount;
  80983. + /* Copy alll the wTxBytes to the buffer */
  80984. + dwc_memcpy(buf, ep->bm_concat->wTxBytes, sizeof(uid16_t) * desc_count);
  80985. +
  80986. + retval = BS_CONCAT_VAL_HDR_LEN + sizeof(uid16_t) * desc_count;
  80987. + return retval;
  80988. +}
  80989. +
  80990. +/**
  80991. + * This function reads the buffer Alignment value of an EP's buffer mode into
  80992. + * the buffer buf
  80993. + *
  80994. + * @return The total number of bytes copied to the buffer or negative error code.
  80995. + */
  80996. +static int cfi_ep_get_align_val(uint8_t * buf, struct dwc_otg_pcd *pcd,
  80997. + struct cfi_usb_ctrlrequest *req)
  80998. +{
  80999. + int retval = -DWC_E_INVALID;
  81000. + uint8_t addr;
  81001. + cfi_ep_t *ep;
  81002. +
  81003. + /* The Low Byte of the wValue contains a non-zero address of the endpoint */
  81004. + addr = req->wValue & 0xFF;
  81005. + if (addr == 0) /* The address should be non-zero */
  81006. + return retval;
  81007. +
  81008. + ep = get_cfi_ep_by_addr(pcd->cfi, addr);
  81009. + if (NULL == ep) {
  81010. + CFI_INFO("%s: Unable to get the endpoint address(0x%02x)\n",
  81011. + __func__, addr);
  81012. + return retval;
  81013. + }
  81014. +
  81015. + dwc_memcpy(buf, ep->bm_align, BS_ALIGN_VAL_HDR_LEN);
  81016. + retval = BS_ALIGN_VAL_HDR_LEN;
  81017. +
  81018. + return retval;
  81019. +}
  81020. +
  81021. +/**
  81022. + * This function sets a new value for the specified feature
  81023. + *
  81024. + * @param pcd A pointer to the PCD object
  81025. + *
  81026. + * @return 0 if successful, negative error code otherwise to stall the DCE.
  81027. + */
  81028. +static int cfi_set_feature_value(struct dwc_otg_pcd *pcd)
  81029. +{
  81030. + int retval = -DWC_E_NOT_SUPPORTED;
  81031. + uint16_t wIndex, wValue;
  81032. + uint8_t bRequest;
  81033. + struct dwc_otg_core_if *coreif;
  81034. + cfiobject_t *cfi = pcd->cfi;
  81035. + struct cfi_usb_ctrlrequest *ctrl_req;
  81036. + uint8_t *buf;
  81037. + ctrl_req = &cfi->ctrl_req;
  81038. +
  81039. + buf = pcd->cfi->ctrl_req.data;
  81040. +
  81041. + coreif = GET_CORE_IF(pcd);
  81042. + bRequest = ctrl_req->bRequest;
  81043. + wIndex = DWC_CONSTANT_CPU_TO_LE16(ctrl_req->wIndex);
  81044. + wValue = DWC_CONSTANT_CPU_TO_LE16(ctrl_req->wValue);
  81045. +
  81046. + /* See which feature is to be modified */
  81047. + switch (wIndex) {
  81048. + case FT_ID_DMA_BUFFER_SETUP:
  81049. + /* Modify the feature */
  81050. + if ((retval = cfi_ep_set_sg_val(buf, pcd)) < 0)
  81051. + return retval;
  81052. +
  81053. + /* And send this request to the gadget */
  81054. + cfi->need_gadget_att = 1;
  81055. + break;
  81056. +
  81057. + case FT_ID_DMA_BUFF_ALIGN:
  81058. + if ((retval = cfi_ep_set_alignment_val(buf, pcd)) < 0)
  81059. + return retval;
  81060. + cfi->need_gadget_att = 1;
  81061. + break;
  81062. +
  81063. + case FT_ID_DMA_CONCAT_SETUP:
  81064. + /* Modify the feature */
  81065. + if ((retval = cfi_ep_set_concat_val(buf, pcd)) < 0)
  81066. + return retval;
  81067. + cfi->need_gadget_att = 1;
  81068. + break;
  81069. +
  81070. + case FT_ID_DMA_CIRCULAR:
  81071. + CFI_INFO("FT_ID_DMA_CIRCULAR\n");
  81072. + break;
  81073. +
  81074. + case FT_ID_THRESHOLD_SETUP:
  81075. + CFI_INFO("FT_ID_THRESHOLD_SETUP\n");
  81076. + break;
  81077. +
  81078. + case FT_ID_DFIFO_DEPTH:
  81079. + CFI_INFO("FT_ID_DFIFO_DEPTH\n");
  81080. + break;
  81081. +
  81082. + case FT_ID_TX_FIFO_DEPTH:
  81083. + CFI_INFO("FT_ID_TX_FIFO_DEPTH\n");
  81084. + if ((retval = cfi_ep_set_tx_fifo_val(buf, pcd)) < 0)
  81085. + return retval;
  81086. + cfi->need_gadget_att = 0;
  81087. + break;
  81088. +
  81089. + case FT_ID_RX_FIFO_DEPTH:
  81090. + CFI_INFO("FT_ID_RX_FIFO_DEPTH\n");
  81091. + if ((retval = cfi_set_rx_fifo_val(buf, pcd)) < 0)
  81092. + return retval;
  81093. + cfi->need_gadget_att = 0;
  81094. + break;
  81095. + }
  81096. +
  81097. + return retval;
  81098. +}
  81099. +
  81100. +#endif //DWC_UTE_CFI
  81101. diff -Nur linux-3.18.8/drivers/usb/host/dwc_otg/dwc_otg_cfi.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_cfi.h
  81102. --- linux-3.18.8/drivers/usb/host/dwc_otg/dwc_otg_cfi.h 1970-01-01 01:00:00.000000000 +0100
  81103. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_cfi.h 2015-03-05 14:40:16.557715806 +0100
  81104. @@ -0,0 +1,320 @@
  81105. +/* ==========================================================================
  81106. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  81107. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  81108. + * otherwise expressly agreed to in writing between Synopsys and you.
  81109. + *
  81110. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  81111. + * any End User Software License Agreement or Agreement for Licensed Product
  81112. + * with Synopsys or any supplement thereto. You are permitted to use and
  81113. + * redistribute this Software in source and binary forms, with or without
  81114. + * modification, provided that redistributions of source code must retain this
  81115. + * notice. You may not view, use, disclose, copy or distribute this file or
  81116. + * any information contained herein except pursuant to this license grant from
  81117. + * Synopsys. If you do not agree with this notice, including the disclaimer
  81118. + * below, then you are not authorized to use the Software.
  81119. + *
  81120. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  81121. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  81122. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  81123. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  81124. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  81125. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  81126. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  81127. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  81128. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  81129. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  81130. + * DAMAGE.
  81131. + * ========================================================================== */
  81132. +
  81133. +#if !defined(__DWC_OTG_CFI_H__)
  81134. +#define __DWC_OTG_CFI_H__
  81135. +
  81136. +#include "dwc_otg_pcd.h"
  81137. +#include "dwc_cfi_common.h"
  81138. +
  81139. +/**
  81140. + * @file
  81141. + * This file contains the CFI related OTG PCD specific common constants,
  81142. + * interfaces(functions and macros) and data structures.The CFI Protocol is an
  81143. + * optional interface for internal testing purposes that a DUT may implement to
  81144. + * support testing of configurable features.
  81145. + *
  81146. + */
  81147. +
  81148. +struct dwc_otg_pcd;
  81149. +struct dwc_otg_pcd_ep;
  81150. +
  81151. +/** OTG CFI Features (properties) ID constants */
  81152. +/** This is a request for all Core Features */
  81153. +#define FT_ID_DMA_MODE 0x0001
  81154. +#define FT_ID_DMA_BUFFER_SETUP 0x0002
  81155. +#define FT_ID_DMA_BUFF_ALIGN 0x0003
  81156. +#define FT_ID_DMA_CONCAT_SETUP 0x0004
  81157. +#define FT_ID_DMA_CIRCULAR 0x0005
  81158. +#define FT_ID_THRESHOLD_SETUP 0x0006
  81159. +#define FT_ID_DFIFO_DEPTH 0x0007
  81160. +#define FT_ID_TX_FIFO_DEPTH 0x0008
  81161. +#define FT_ID_RX_FIFO_DEPTH 0x0009
  81162. +
  81163. +/**********************************************************/
  81164. +#define CFI_INFO_DEF
  81165. +
  81166. +#ifdef CFI_INFO_DEF
  81167. +#define CFI_INFO(fmt...) DWC_PRINTF("CFI: " fmt);
  81168. +#else
  81169. +#define CFI_INFO(fmt...)
  81170. +#endif
  81171. +
  81172. +#define min(x,y) ({ \
  81173. + x < y ? x : y; })
  81174. +
  81175. +#define max(x,y) ({ \
  81176. + x > y ? x : y; })
  81177. +
  81178. +/**
  81179. + * Descriptor DMA SG Buffer setup structure (SG buffer). This structure is
  81180. + * also used for setting up a buffer for Circular DDMA.
  81181. + */
  81182. +struct _ddma_sg_buffer_setup {
  81183. +#define BS_SG_VAL_DESC_LEN 6
  81184. + /* The OUT EP address */
  81185. + uint8_t bOutEndpointAddress;
  81186. + /* The IN EP address */
  81187. + uint8_t bInEndpointAddress;
  81188. + /* Number of bytes to put between transfer segments (must be DWORD boundaries) */
  81189. + uint8_t bOffset;
  81190. + /* The number of transfer segments (a DMA descriptors per each segment) */
  81191. + uint8_t bCount;
  81192. + /* Size (in byte) of each transfer segment */
  81193. + uint16_t wSize;
  81194. +} __attribute__ ((packed));
  81195. +typedef struct _ddma_sg_buffer_setup ddma_sg_buffer_setup_t;
  81196. +
  81197. +/** Descriptor DMA Concatenation Buffer setup structure */
  81198. +struct _ddma_concat_buffer_setup_hdr {
  81199. +#define BS_CONCAT_VAL_HDR_LEN 4
  81200. + /* The endpoint for which the buffer is to be set up */
  81201. + uint8_t bEndpointAddress;
  81202. + /* The count of descriptors to be used */
  81203. + uint8_t bDescCount;
  81204. + /* The total size of the transfer */
  81205. + uint16_t wSize;
  81206. +} __attribute__ ((packed));
  81207. +typedef struct _ddma_concat_buffer_setup_hdr ddma_concat_buffer_setup_hdr_t;
  81208. +
  81209. +/** Descriptor DMA Concatenation Buffer setup structure */
  81210. +struct _ddma_concat_buffer_setup {
  81211. + /* The SG header */
  81212. + ddma_concat_buffer_setup_hdr_t hdr;
  81213. +
  81214. + /* The XFER sizes pointer (allocated dynamically) */
  81215. + uint16_t *wTxBytes;
  81216. +} __attribute__ ((packed));
  81217. +typedef struct _ddma_concat_buffer_setup ddma_concat_buffer_setup_t;
  81218. +
  81219. +/** Descriptor DMA Alignment Buffer setup structure */
  81220. +struct _ddma_align_buffer_setup {
  81221. +#define BS_ALIGN_VAL_HDR_LEN 2
  81222. + uint8_t bEndpointAddress;
  81223. + uint8_t bAlign;
  81224. +} __attribute__ ((packed));
  81225. +typedef struct _ddma_align_buffer_setup ddma_align_buffer_setup_t;
  81226. +
  81227. +/** Transmit FIFO Size setup structure */
  81228. +struct _tx_fifo_size_setup {
  81229. + uint8_t bEndpointAddress;
  81230. + uint16_t wDepth;
  81231. +} __attribute__ ((packed));
  81232. +typedef struct _tx_fifo_size_setup tx_fifo_size_setup_t;
  81233. +
  81234. +/** Transmit FIFO Size setup structure */
  81235. +struct _rx_fifo_size_setup {
  81236. + uint16_t wDepth;
  81237. +} __attribute__ ((packed));
  81238. +typedef struct _rx_fifo_size_setup rx_fifo_size_setup_t;
  81239. +
  81240. +/**
  81241. + * struct cfi_usb_ctrlrequest - the CFI implementation of the struct usb_ctrlrequest
  81242. + * This structure encapsulates the standard usb_ctrlrequest and adds a pointer
  81243. + * to the data returned in the data stage of a 3-stage Control Write requests.
  81244. + */
  81245. +struct cfi_usb_ctrlrequest {
  81246. + uint8_t bRequestType;
  81247. + uint8_t bRequest;
  81248. + uint16_t wValue;
  81249. + uint16_t wIndex;
  81250. + uint16_t wLength;
  81251. + uint8_t *data;
  81252. +} UPACKED;
  81253. +
  81254. +/*---------------------------------------------------------------------------*/
  81255. +
  81256. +/**
  81257. + * The CFI wrapper of the enabled and activated dwc_otg_pcd_ep structures.
  81258. + * This structure is used to store the buffer setup data for any
  81259. + * enabled endpoint in the PCD.
  81260. + */
  81261. +struct cfi_ep {
  81262. + /* Entry for the list container */
  81263. + dwc_list_link_t lh;
  81264. + /* Pointer to the active PCD endpoint structure */
  81265. + struct dwc_otg_pcd_ep *ep;
  81266. + /* The last descriptor in the chain of DMA descriptors of the endpoint */
  81267. + struct dwc_otg_dma_desc *dma_desc_last;
  81268. + /* The SG feature value */
  81269. + ddma_sg_buffer_setup_t *bm_sg;
  81270. + /* The Circular feature value */
  81271. + ddma_sg_buffer_setup_t *bm_circ;
  81272. + /* The Concatenation feature value */
  81273. + ddma_concat_buffer_setup_t *bm_concat;
  81274. + /* The Alignment feature value */
  81275. + ddma_align_buffer_setup_t *bm_align;
  81276. + /* XFER length */
  81277. + uint32_t xfer_len;
  81278. + /*
  81279. + * Count of DMA descriptors currently used.
  81280. + * The total should not exceed the MAX_DMA_DESCS_PER_EP value
  81281. + * defined in the dwc_otg_cil.h
  81282. + */
  81283. + uint32_t desc_count;
  81284. +};
  81285. +typedef struct cfi_ep cfi_ep_t;
  81286. +
  81287. +typedef struct cfi_dma_buff {
  81288. +#define CFI_IN_BUF_LEN 1024
  81289. +#define CFI_OUT_BUF_LEN 1024
  81290. + dma_addr_t addr;
  81291. + uint8_t *buf;
  81292. +} cfi_dma_buff_t;
  81293. +
  81294. +struct cfiobject;
  81295. +
  81296. +/**
  81297. + * This is the interface for the CFI operations.
  81298. + *
  81299. + * @param ep_enable Called when any endpoint is enabled and activated.
  81300. + * @param release Called when the CFI object is released and it needs to correctly
  81301. + * deallocate the dynamic memory
  81302. + * @param ctrl_write_complete Called when the data stage of the request is complete
  81303. + */
  81304. +typedef struct cfi_ops {
  81305. + int (*ep_enable) (struct cfiobject * cfi, struct dwc_otg_pcd * pcd,
  81306. + struct dwc_otg_pcd_ep * ep);
  81307. + void *(*ep_alloc_buf) (struct cfiobject * cfi, struct dwc_otg_pcd * pcd,
  81308. + struct dwc_otg_pcd_ep * ep, dma_addr_t * dma,
  81309. + unsigned size, gfp_t flags);
  81310. + void (*release) (struct cfiobject * cfi);
  81311. + int (*ctrl_write_complete) (struct cfiobject * cfi,
  81312. + struct dwc_otg_pcd * pcd);
  81313. + void (*build_descriptors) (struct cfiobject * cfi,
  81314. + struct dwc_otg_pcd * pcd,
  81315. + struct dwc_otg_pcd_ep * ep,
  81316. + dwc_otg_pcd_request_t * req);
  81317. +} cfi_ops_t;
  81318. +
  81319. +struct cfiobject {
  81320. + cfi_ops_t ops;
  81321. + struct dwc_otg_pcd *pcd;
  81322. + struct usb_gadget *gadget;
  81323. +
  81324. + /* Buffers used to send/receive CFI-related request data */
  81325. + cfi_dma_buff_t buf_in;
  81326. + cfi_dma_buff_t buf_out;
  81327. +
  81328. + /* CFI specific Control request wrapper */
  81329. + struct cfi_usb_ctrlrequest ctrl_req;
  81330. +
  81331. + /* The list of active EP's in the PCD of type cfi_ep_t */
  81332. + dwc_list_link_t active_eps;
  81333. +
  81334. + /* This flag shall control the propagation of a specific request
  81335. + * to the gadget's processing routines.
  81336. + * 0 - no gadget handling
  81337. + * 1 - the gadget needs to know about this request (w/o completing a status
  81338. + * phase - just return a 0 to the _setup callback)
  81339. + */
  81340. + uint8_t need_gadget_att;
  81341. +
  81342. + /* Flag indicating whether the status IN phase needs to be
  81343. + * completed by the PCD
  81344. + */
  81345. + uint8_t need_status_in_complete;
  81346. +};
  81347. +typedef struct cfiobject cfiobject_t;
  81348. +
  81349. +#define DUMP_MSG
  81350. +
  81351. +#if defined(DUMP_MSG)
  81352. +static inline void dump_msg(const u8 * buf, unsigned int length)
  81353. +{
  81354. + unsigned int start, num, i;
  81355. + char line[52], *p;
  81356. +
  81357. + if (length >= 512)
  81358. + return;
  81359. +
  81360. + start = 0;
  81361. + while (length > 0) {
  81362. + num = min(length, 16u);
  81363. + p = line;
  81364. + for (i = 0; i < num; ++i) {
  81365. + if (i == 8)
  81366. + *p++ = ' ';
  81367. + DWC_SPRINTF(p, " %02x", buf[i]);
  81368. + p += 3;
  81369. + }
  81370. + *p = 0;
  81371. + DWC_DEBUG("%6x: %s\n", start, line);
  81372. + buf += num;
  81373. + start += num;
  81374. + length -= num;
  81375. + }
  81376. +}
  81377. +#else
  81378. +static inline void dump_msg(const u8 * buf, unsigned int length)
  81379. +{
  81380. +}
  81381. +#endif
  81382. +
  81383. +/**
  81384. + * This function returns a pointer to cfi_ep_t object with the addr address.
  81385. + */
  81386. +static inline struct cfi_ep *get_cfi_ep_by_addr(struct cfiobject *cfi,
  81387. + uint8_t addr)
  81388. +{
  81389. + struct cfi_ep *pcfiep;
  81390. + dwc_list_link_t *tmp;
  81391. +
  81392. + DWC_LIST_FOREACH(tmp, &cfi->active_eps) {
  81393. + pcfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  81394. +
  81395. + if (pcfiep->ep->desc->bEndpointAddress == addr) {
  81396. + return pcfiep;
  81397. + }
  81398. + }
  81399. +
  81400. + return NULL;
  81401. +}
  81402. +
  81403. +/**
  81404. + * This function returns a pointer to cfi_ep_t object that matches
  81405. + * the dwc_otg_pcd_ep object.
  81406. + */
  81407. +static inline struct cfi_ep *get_cfi_ep_by_pcd_ep(struct cfiobject *cfi,
  81408. + struct dwc_otg_pcd_ep *ep)
  81409. +{
  81410. + struct cfi_ep *pcfiep = NULL;
  81411. + dwc_list_link_t *tmp;
  81412. +
  81413. + DWC_LIST_FOREACH(tmp, &cfi->active_eps) {
  81414. + pcfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  81415. + if (pcfiep->ep == ep) {
  81416. + return pcfiep;
  81417. + }
  81418. + }
  81419. + return NULL;
  81420. +}
  81421. +
  81422. +int cfi_setup(struct dwc_otg_pcd *pcd, struct cfi_usb_ctrlrequest *ctrl);
  81423. +
  81424. +#endif /* (__DWC_OTG_CFI_H__) */
  81425. diff -Nur linux-3.18.8/drivers/usb/host/dwc_otg/dwc_otg_cil.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_cil.c
  81426. --- linux-3.18.8/drivers/usb/host/dwc_otg/dwc_otg_cil.c 1970-01-01 01:00:00.000000000 +0100
  81427. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_cil.c 2015-03-05 14:40:16.557715806 +0100
  81428. @@ -0,0 +1,7141 @@
  81429. +/* ==========================================================================
  81430. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_cil.c $
  81431. + * $Revision: #191 $
  81432. + * $Date: 2012/08/10 $
  81433. + * $Change: 2047372 $
  81434. + *
  81435. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  81436. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  81437. + * otherwise expressly agreed to in writing between Synopsys and you.
  81438. + *
  81439. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  81440. + * any End User Software License Agreement or Agreement for Licensed Product
  81441. + * with Synopsys or any supplement thereto. You are permitted to use and
  81442. + * redistribute this Software in source and binary forms, with or without
  81443. + * modification, provided that redistributions of source code must retain this
  81444. + * notice. You may not view, use, disclose, copy or distribute this file or
  81445. + * any information contained herein except pursuant to this license grant from
  81446. + * Synopsys. If you do not agree with this notice, including the disclaimer
  81447. + * below, then you are not authorized to use the Software.
  81448. + *
  81449. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  81450. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  81451. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  81452. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  81453. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  81454. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  81455. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  81456. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  81457. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  81458. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  81459. + * DAMAGE.
  81460. + * ========================================================================== */
  81461. +
  81462. +/** @file
  81463. + *
  81464. + * The Core Interface Layer provides basic services for accessing and
  81465. + * managing the DWC_otg hardware. These services are used by both the
  81466. + * Host Controller Driver and the Peripheral Controller Driver.
  81467. + *
  81468. + * The CIL manages the memory map for the core so that the HCD and PCD
  81469. + * don't have to do this separately. It also handles basic tasks like
  81470. + * reading/writing the registers and data FIFOs in the controller.
  81471. + * Some of the data access functions provide encapsulation of several
  81472. + * operations required to perform a task, such as writing multiple
  81473. + * registers to start a transfer. Finally, the CIL performs basic
  81474. + * services that are not specific to either the host or device modes
  81475. + * of operation. These services include management of the OTG Host
  81476. + * Negotiation Protocol (HNP) and Session Request Protocol (SRP). A
  81477. + * Diagnostic API is also provided to allow testing of the controller
  81478. + * hardware.
  81479. + *
  81480. + * The Core Interface Layer has the following requirements:
  81481. + * - Provides basic controller operations.
  81482. + * - Minimal use of OS services.
  81483. + * - The OS services used will be abstracted by using inline functions
  81484. + * or macros.
  81485. + *
  81486. + */
  81487. +
  81488. +#include "dwc_os.h"
  81489. +#include "dwc_otg_regs.h"
  81490. +#include "dwc_otg_cil.h"
  81491. +
  81492. +static int dwc_otg_setup_params(dwc_otg_core_if_t * core_if);
  81493. +
  81494. +/**
  81495. + * This function is called to initialize the DWC_otg CSR data
  81496. + * structures. The register addresses in the device and host
  81497. + * structures are initialized from the base address supplied by the
  81498. + * caller. The calling function must make the OS calls to get the
  81499. + * base address of the DWC_otg controller registers. The core_params
  81500. + * argument holds the parameters that specify how the core should be
  81501. + * configured.
  81502. + *
  81503. + * @param reg_base_addr Base address of DWC_otg core registers
  81504. + *
  81505. + */
  81506. +dwc_otg_core_if_t *dwc_otg_cil_init(const uint32_t * reg_base_addr)
  81507. +{
  81508. + dwc_otg_core_if_t *core_if = 0;
  81509. + dwc_otg_dev_if_t *dev_if = 0;
  81510. + dwc_otg_host_if_t *host_if = 0;
  81511. + uint8_t *reg_base = (uint8_t *) reg_base_addr;
  81512. + int i = 0;
  81513. +
  81514. + DWC_DEBUGPL(DBG_CILV, "%s(%p)\n", __func__, reg_base_addr);
  81515. +
  81516. + core_if = DWC_ALLOC(sizeof(dwc_otg_core_if_t));
  81517. +
  81518. + if (core_if == NULL) {
  81519. + DWC_DEBUGPL(DBG_CIL,
  81520. + "Allocation of dwc_otg_core_if_t failed\n");
  81521. + return 0;
  81522. + }
  81523. + core_if->core_global_regs = (dwc_otg_core_global_regs_t *) reg_base;
  81524. +
  81525. + /*
  81526. + * Allocate the Device Mode structures.
  81527. + */
  81528. + dev_if = DWC_ALLOC(sizeof(dwc_otg_dev_if_t));
  81529. +
  81530. + if (dev_if == NULL) {
  81531. + DWC_DEBUGPL(DBG_CIL, "Allocation of dwc_otg_dev_if_t failed\n");
  81532. + DWC_FREE(core_if);
  81533. + return 0;
  81534. + }
  81535. +
  81536. + dev_if->dev_global_regs =
  81537. + (dwc_otg_device_global_regs_t *) (reg_base +
  81538. + DWC_DEV_GLOBAL_REG_OFFSET);
  81539. +
  81540. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  81541. + dev_if->in_ep_regs[i] = (dwc_otg_dev_in_ep_regs_t *)
  81542. + (reg_base + DWC_DEV_IN_EP_REG_OFFSET +
  81543. + (i * DWC_EP_REG_OFFSET));
  81544. +
  81545. + dev_if->out_ep_regs[i] = (dwc_otg_dev_out_ep_regs_t *)
  81546. + (reg_base + DWC_DEV_OUT_EP_REG_OFFSET +
  81547. + (i * DWC_EP_REG_OFFSET));
  81548. + DWC_DEBUGPL(DBG_CILV, "in_ep_regs[%d]->diepctl=%p\n",
  81549. + i, &dev_if->in_ep_regs[i]->diepctl);
  81550. + DWC_DEBUGPL(DBG_CILV, "out_ep_regs[%d]->doepctl=%p\n",
  81551. + i, &dev_if->out_ep_regs[i]->doepctl);
  81552. + }
  81553. +
  81554. + dev_if->speed = 0; // unknown
  81555. +
  81556. + core_if->dev_if = dev_if;
  81557. +
  81558. + /*
  81559. + * Allocate the Host Mode structures.
  81560. + */
  81561. + host_if = DWC_ALLOC(sizeof(dwc_otg_host_if_t));
  81562. +
  81563. + if (host_if == NULL) {
  81564. + DWC_DEBUGPL(DBG_CIL,
  81565. + "Allocation of dwc_otg_host_if_t failed\n");
  81566. + DWC_FREE(dev_if);
  81567. + DWC_FREE(core_if);
  81568. + return 0;
  81569. + }
  81570. +
  81571. + host_if->host_global_regs = (dwc_otg_host_global_regs_t *)
  81572. + (reg_base + DWC_OTG_HOST_GLOBAL_REG_OFFSET);
  81573. +
  81574. + host_if->hprt0 =
  81575. + (uint32_t *) (reg_base + DWC_OTG_HOST_PORT_REGS_OFFSET);
  81576. +
  81577. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  81578. + host_if->hc_regs[i] = (dwc_otg_hc_regs_t *)
  81579. + (reg_base + DWC_OTG_HOST_CHAN_REGS_OFFSET +
  81580. + (i * DWC_OTG_CHAN_REGS_OFFSET));
  81581. + DWC_DEBUGPL(DBG_CILV, "hc_reg[%d]->hcchar=%p\n",
  81582. + i, &host_if->hc_regs[i]->hcchar);
  81583. + }
  81584. +
  81585. + host_if->num_host_channels = MAX_EPS_CHANNELS;
  81586. + core_if->host_if = host_if;
  81587. +
  81588. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  81589. + core_if->data_fifo[i] =
  81590. + (uint32_t *) (reg_base + DWC_OTG_DATA_FIFO_OFFSET +
  81591. + (i * DWC_OTG_DATA_FIFO_SIZE));
  81592. + DWC_DEBUGPL(DBG_CILV, "data_fifo[%d]=0x%08lx\n",
  81593. + i, (unsigned long)core_if->data_fifo[i]);
  81594. + }
  81595. +
  81596. + core_if->pcgcctl = (uint32_t *) (reg_base + DWC_OTG_PCGCCTL_OFFSET);
  81597. +
  81598. + /* Initiate lx_state to L3 disconnected state */
  81599. + core_if->lx_state = DWC_OTG_L3;
  81600. + /*
  81601. + * Store the contents of the hardware configuration registers here for
  81602. + * easy access later.
  81603. + */
  81604. + core_if->hwcfg1.d32 =
  81605. + DWC_READ_REG32(&core_if->core_global_regs->ghwcfg1);
  81606. + core_if->hwcfg2.d32 =
  81607. + DWC_READ_REG32(&core_if->core_global_regs->ghwcfg2);
  81608. + core_if->hwcfg3.d32 =
  81609. + DWC_READ_REG32(&core_if->core_global_regs->ghwcfg3);
  81610. + core_if->hwcfg4.d32 =
  81611. + DWC_READ_REG32(&core_if->core_global_regs->ghwcfg4);
  81612. +
  81613. + /* Force host mode to get HPTXFSIZ exact power on value */
  81614. + {
  81615. + gusbcfg_data_t gusbcfg = {.d32 = 0 };
  81616. + gusbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  81617. + gusbcfg.b.force_host_mode = 1;
  81618. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, gusbcfg.d32);
  81619. + dwc_mdelay(100);
  81620. + core_if->hptxfsiz.d32 =
  81621. + DWC_READ_REG32(&core_if->core_global_regs->hptxfsiz);
  81622. + gusbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  81623. + gusbcfg.b.force_host_mode = 0;
  81624. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, gusbcfg.d32);
  81625. + dwc_mdelay(100);
  81626. + }
  81627. +
  81628. + DWC_DEBUGPL(DBG_CILV, "hwcfg1=%08x\n", core_if->hwcfg1.d32);
  81629. + DWC_DEBUGPL(DBG_CILV, "hwcfg2=%08x\n", core_if->hwcfg2.d32);
  81630. + DWC_DEBUGPL(DBG_CILV, "hwcfg3=%08x\n", core_if->hwcfg3.d32);
  81631. + DWC_DEBUGPL(DBG_CILV, "hwcfg4=%08x\n", core_if->hwcfg4.d32);
  81632. +
  81633. + core_if->hcfg.d32 =
  81634. + DWC_READ_REG32(&core_if->host_if->host_global_regs->hcfg);
  81635. + core_if->dcfg.d32 =
  81636. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  81637. +
  81638. + DWC_DEBUGPL(DBG_CILV, "hcfg=%08x\n", core_if->hcfg.d32);
  81639. + DWC_DEBUGPL(DBG_CILV, "dcfg=%08x\n", core_if->dcfg.d32);
  81640. +
  81641. + DWC_DEBUGPL(DBG_CILV, "op_mode=%0x\n", core_if->hwcfg2.b.op_mode);
  81642. + DWC_DEBUGPL(DBG_CILV, "arch=%0x\n", core_if->hwcfg2.b.architecture);
  81643. + DWC_DEBUGPL(DBG_CILV, "num_dev_ep=%d\n", core_if->hwcfg2.b.num_dev_ep);
  81644. + DWC_DEBUGPL(DBG_CILV, "num_host_chan=%d\n",
  81645. + core_if->hwcfg2.b.num_host_chan);
  81646. + DWC_DEBUGPL(DBG_CILV, "nonperio_tx_q_depth=0x%0x\n",
  81647. + core_if->hwcfg2.b.nonperio_tx_q_depth);
  81648. + DWC_DEBUGPL(DBG_CILV, "host_perio_tx_q_depth=0x%0x\n",
  81649. + core_if->hwcfg2.b.host_perio_tx_q_depth);
  81650. + DWC_DEBUGPL(DBG_CILV, "dev_token_q_depth=0x%0x\n",
  81651. + core_if->hwcfg2.b.dev_token_q_depth);
  81652. +
  81653. + DWC_DEBUGPL(DBG_CILV, "Total FIFO SZ=%d\n",
  81654. + core_if->hwcfg3.b.dfifo_depth);
  81655. + DWC_DEBUGPL(DBG_CILV, "xfer_size_cntr_width=%0x\n",
  81656. + core_if->hwcfg3.b.xfer_size_cntr_width);
  81657. +
  81658. + /*
  81659. + * Set the SRP sucess bit for FS-I2c
  81660. + */
  81661. + core_if->srp_success = 0;
  81662. + core_if->srp_timer_started = 0;
  81663. +
  81664. + /*
  81665. + * Create new workqueue and init works
  81666. + */
  81667. + core_if->wq_otg = DWC_WORKQ_ALLOC("dwc_otg");
  81668. + if (core_if->wq_otg == 0) {
  81669. + DWC_WARN("DWC_WORKQ_ALLOC failed\n");
  81670. + DWC_FREE(host_if);
  81671. + DWC_FREE(dev_if);
  81672. + DWC_FREE(core_if);
  81673. + return 0;
  81674. + }
  81675. +
  81676. + core_if->snpsid = DWC_READ_REG32(&core_if->core_global_regs->gsnpsid);
  81677. +
  81678. + DWC_PRINTF("Core Release: %x.%x%x%x\n",
  81679. + (core_if->snpsid >> 12 & 0xF),
  81680. + (core_if->snpsid >> 8 & 0xF),
  81681. + (core_if->snpsid >> 4 & 0xF), (core_if->snpsid & 0xF));
  81682. +
  81683. + core_if->wkp_timer = DWC_TIMER_ALLOC("Wake Up Timer",
  81684. + w_wakeup_detected, core_if);
  81685. + if (core_if->wkp_timer == 0) {
  81686. + DWC_WARN("DWC_TIMER_ALLOC failed\n");
  81687. + DWC_FREE(host_if);
  81688. + DWC_FREE(dev_if);
  81689. + DWC_WORKQ_FREE(core_if->wq_otg);
  81690. + DWC_FREE(core_if);
  81691. + return 0;
  81692. + }
  81693. +
  81694. + if (dwc_otg_setup_params(core_if)) {
  81695. + DWC_WARN("Error while setting core params\n");
  81696. + }
  81697. +
  81698. + core_if->hibernation_suspend = 0;
  81699. +
  81700. + /** ADP initialization */
  81701. + dwc_otg_adp_init(core_if);
  81702. +
  81703. + return core_if;
  81704. +}
  81705. +
  81706. +/**
  81707. + * This function frees the structures allocated by dwc_otg_cil_init().
  81708. + *
  81709. + * @param core_if The core interface pointer returned from
  81710. + * dwc_otg_cil_init().
  81711. + *
  81712. + */
  81713. +void dwc_otg_cil_remove(dwc_otg_core_if_t * core_if)
  81714. +{
  81715. + dctl_data_t dctl = {.d32 = 0 };
  81716. + DWC_DEBUGPL(DBG_CILV, "%s(%p)\n", __func__, core_if);
  81717. +
  81718. + /* Disable all interrupts */
  81719. + DWC_MODIFY_REG32(&core_if->core_global_regs->gahbcfg, 1, 0);
  81720. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, 0);
  81721. +
  81722. + dctl.b.sftdiscon = 1;
  81723. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  81724. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0,
  81725. + dctl.d32);
  81726. + }
  81727. +
  81728. + if (core_if->wq_otg) {
  81729. + DWC_WORKQ_WAIT_WORK_DONE(core_if->wq_otg, 500);
  81730. + DWC_WORKQ_FREE(core_if->wq_otg);
  81731. + }
  81732. + if (core_if->dev_if) {
  81733. + DWC_FREE(core_if->dev_if);
  81734. + }
  81735. + if (core_if->host_if) {
  81736. + DWC_FREE(core_if->host_if);
  81737. + }
  81738. +
  81739. + /** Remove ADP Stuff */
  81740. + dwc_otg_adp_remove(core_if);
  81741. + if (core_if->core_params) {
  81742. + DWC_FREE(core_if->core_params);
  81743. + }
  81744. + if (core_if->wkp_timer) {
  81745. + DWC_TIMER_FREE(core_if->wkp_timer);
  81746. + }
  81747. + if (core_if->srp_timer) {
  81748. + DWC_TIMER_FREE(core_if->srp_timer);
  81749. + }
  81750. + DWC_FREE(core_if);
  81751. +}
  81752. +
  81753. +/**
  81754. + * This function enables the controller's Global Interrupt in the AHB Config
  81755. + * register.
  81756. + *
  81757. + * @param core_if Programming view of DWC_otg controller.
  81758. + */
  81759. +void dwc_otg_enable_global_interrupts(dwc_otg_core_if_t * core_if)
  81760. +{
  81761. + gahbcfg_data_t ahbcfg = {.d32 = 0 };
  81762. + ahbcfg.b.glblintrmsk = 1; /* Enable interrupts */
  81763. + DWC_MODIFY_REG32(&core_if->core_global_regs->gahbcfg, 0, ahbcfg.d32);
  81764. +}
  81765. +
  81766. +/**
  81767. + * This function disables the controller's Global Interrupt in the AHB Config
  81768. + * register.
  81769. + *
  81770. + * @param core_if Programming view of DWC_otg controller.
  81771. + */
  81772. +void dwc_otg_disable_global_interrupts(dwc_otg_core_if_t * core_if)
  81773. +{
  81774. + gahbcfg_data_t ahbcfg = {.d32 = 0 };
  81775. + ahbcfg.b.glblintrmsk = 1; /* Disable interrupts */
  81776. + DWC_MODIFY_REG32(&core_if->core_global_regs->gahbcfg, ahbcfg.d32, 0);
  81777. +}
  81778. +
  81779. +/**
  81780. + * This function initializes the commmon interrupts, used in both
  81781. + * device and host modes.
  81782. + *
  81783. + * @param core_if Programming view of the DWC_otg controller
  81784. + *
  81785. + */
  81786. +static void dwc_otg_enable_common_interrupts(dwc_otg_core_if_t * core_if)
  81787. +{
  81788. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  81789. + gintmsk_data_t intr_mask = {.d32 = 0 };
  81790. +
  81791. + /* Clear any pending OTG Interrupts */
  81792. + DWC_WRITE_REG32(&global_regs->gotgint, 0xFFFFFFFF);
  81793. +
  81794. + /* Clear any pending interrupts */
  81795. + DWC_WRITE_REG32(&global_regs->gintsts, 0xFFFFFFFF);
  81796. +
  81797. + /*
  81798. + * Enable the interrupts in the GINTMSK.
  81799. + */
  81800. + intr_mask.b.modemismatch = 1;
  81801. + intr_mask.b.otgintr = 1;
  81802. +
  81803. + if (!core_if->dma_enable) {
  81804. + intr_mask.b.rxstsqlvl = 1;
  81805. + }
  81806. +
  81807. + intr_mask.b.conidstschng = 1;
  81808. + intr_mask.b.wkupintr = 1;
  81809. + intr_mask.b.disconnect = 0;
  81810. + intr_mask.b.usbsuspend = 1;
  81811. + intr_mask.b.sessreqintr = 1;
  81812. +#ifdef CONFIG_USB_DWC_OTG_LPM
  81813. + if (core_if->core_params->lpm_enable) {
  81814. + intr_mask.b.lpmtranrcvd = 1;
  81815. + }
  81816. +#endif
  81817. + DWC_WRITE_REG32(&global_regs->gintmsk, intr_mask.d32);
  81818. +}
  81819. +
  81820. +/*
  81821. + * The restore operation is modified to support Synopsys Emulated Powerdown and
  81822. + * Hibernation. This function is for exiting from Device mode hibernation by
  81823. + * Host Initiated Resume/Reset and Device Initiated Remote-Wakeup.
  81824. + * @param core_if Programming view of DWC_otg controller.
  81825. + * @param rem_wakeup - indicates whether resume is initiated by Device or Host.
  81826. + * @param reset - indicates whether resume is initiated by Reset.
  81827. + */
  81828. +int dwc_otg_device_hibernation_restore(dwc_otg_core_if_t * core_if,
  81829. + int rem_wakeup, int reset)
  81830. +{
  81831. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  81832. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  81833. + dctl_data_t dctl = {.d32 = 0 };
  81834. +
  81835. + int timeout = 2000;
  81836. +
  81837. + if (!core_if->hibernation_suspend) {
  81838. + DWC_PRINTF("Already exited from Hibernation\n");
  81839. + return 1;
  81840. + }
  81841. +
  81842. + DWC_DEBUGPL(DBG_PCD, "%s called\n", __FUNCTION__);
  81843. + /* Switch-on voltage to the core */
  81844. + gpwrdn.b.pwrdnswtch = 1;
  81845. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  81846. + dwc_udelay(10);
  81847. +
  81848. + /* Reset core */
  81849. + gpwrdn.d32 = 0;
  81850. + gpwrdn.b.pwrdnrstn = 1;
  81851. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  81852. + dwc_udelay(10);
  81853. +
  81854. + /* Assert Restore signal */
  81855. + gpwrdn.d32 = 0;
  81856. + gpwrdn.b.restore = 1;
  81857. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  81858. + dwc_udelay(10);
  81859. +
  81860. + /* Disable power clamps */
  81861. + gpwrdn.d32 = 0;
  81862. + gpwrdn.b.pwrdnclmp = 1;
  81863. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  81864. +
  81865. + if (rem_wakeup) {
  81866. + dwc_udelay(70);
  81867. + }
  81868. +
  81869. + /* Deassert Reset core */
  81870. + gpwrdn.d32 = 0;
  81871. + gpwrdn.b.pwrdnrstn = 1;
  81872. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  81873. + dwc_udelay(10);
  81874. +
  81875. + /* Disable PMU interrupt */
  81876. + gpwrdn.d32 = 0;
  81877. + gpwrdn.b.pmuintsel = 1;
  81878. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  81879. +
  81880. + /* Mask interrupts from gpwrdn */
  81881. + gpwrdn.d32 = 0;
  81882. + gpwrdn.b.connect_det_msk = 1;
  81883. + gpwrdn.b.srp_det_msk = 1;
  81884. + gpwrdn.b.disconn_det_msk = 1;
  81885. + gpwrdn.b.rst_det_msk = 1;
  81886. + gpwrdn.b.lnstchng_msk = 1;
  81887. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  81888. +
  81889. + /* Indicates that we are going out from hibernation */
  81890. + core_if->hibernation_suspend = 0;
  81891. +
  81892. + /*
  81893. + * Set Restore Essential Regs bit in PCGCCTL register, restore_mode = 1
  81894. + * indicates restore from remote_wakeup
  81895. + */
  81896. + restore_essential_regs(core_if, rem_wakeup, 0);
  81897. +
  81898. + /*
  81899. + * Wait a little for seeing new value of variable hibernation_suspend if
  81900. + * Restore done interrupt received before polling
  81901. + */
  81902. + dwc_udelay(10);
  81903. +
  81904. + if (core_if->hibernation_suspend == 0) {
  81905. + /*
  81906. + * Wait For Restore_done Interrupt. This mechanism of polling the
  81907. + * interrupt is introduced to avoid any possible race conditions
  81908. + */
  81909. + do {
  81910. + gintsts_data_t gintsts;
  81911. + gintsts.d32 =
  81912. + DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  81913. + if (gintsts.b.restoredone) {
  81914. + gintsts.d32 = 0;
  81915. + gintsts.b.restoredone = 1;
  81916. + DWC_WRITE_REG32(&core_if->core_global_regs->
  81917. + gintsts, gintsts.d32);
  81918. + DWC_PRINTF("Restore Done Interrupt seen\n");
  81919. + break;
  81920. + }
  81921. + dwc_udelay(10);
  81922. + } while (--timeout);
  81923. + if (!timeout) {
  81924. + DWC_PRINTF("Restore Done interrupt wasn't generated here\n");
  81925. + }
  81926. + }
  81927. + /* Clear all pending interupts */
  81928. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  81929. +
  81930. + /* De-assert Restore */
  81931. + gpwrdn.d32 = 0;
  81932. + gpwrdn.b.restore = 1;
  81933. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  81934. + dwc_udelay(10);
  81935. +
  81936. + if (!rem_wakeup) {
  81937. + pcgcctl.d32 = 0;
  81938. + pcgcctl.b.rstpdwnmodule = 1;
  81939. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  81940. + }
  81941. +
  81942. + /* Restore GUSBCFG and DCFG */
  81943. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg,
  81944. + core_if->gr_backup->gusbcfg_local);
  81945. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg,
  81946. + core_if->dr_backup->dcfg);
  81947. +
  81948. + /* De-assert Wakeup Logic */
  81949. + gpwrdn.d32 = 0;
  81950. + gpwrdn.b.pmuactv = 1;
  81951. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  81952. + dwc_udelay(10);
  81953. +
  81954. + if (!rem_wakeup) {
  81955. + /* Set Device programming done bit */
  81956. + dctl.b.pwronprgdone = 1;
  81957. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0, dctl.d32);
  81958. + } else {
  81959. + /* Start Remote Wakeup Signaling */
  81960. + dctl.d32 = core_if->dr_backup->dctl;
  81961. + dctl.b.rmtwkupsig = 1;
  81962. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32);
  81963. + }
  81964. +
  81965. + dwc_mdelay(2);
  81966. + /* Clear all pending interupts */
  81967. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  81968. +
  81969. + /* Restore global registers */
  81970. + dwc_otg_restore_global_regs(core_if);
  81971. + /* Restore device global registers */
  81972. + dwc_otg_restore_dev_regs(core_if, rem_wakeup);
  81973. +
  81974. + if (rem_wakeup) {
  81975. + dwc_mdelay(7);
  81976. + dctl.d32 = 0;
  81977. + dctl.b.rmtwkupsig = 1;
  81978. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32, 0);
  81979. + }
  81980. +
  81981. + core_if->hibernation_suspend = 0;
  81982. + /* The core will be in ON STATE */
  81983. + core_if->lx_state = DWC_OTG_L0;
  81984. + DWC_PRINTF("Hibernation recovery completes here\n");
  81985. +
  81986. + return 1;
  81987. +}
  81988. +
  81989. +/*
  81990. + * The restore operation is modified to support Synopsys Emulated Powerdown and
  81991. + * Hibernation. This function is for exiting from Host mode hibernation by
  81992. + * Host Initiated Resume/Reset and Device Initiated Remote-Wakeup.
  81993. + * @param core_if Programming view of DWC_otg controller.
  81994. + * @param rem_wakeup - indicates whether resume is initiated by Device or Host.
  81995. + * @param reset - indicates whether resume is initiated by Reset.
  81996. + */
  81997. +int dwc_otg_host_hibernation_restore(dwc_otg_core_if_t * core_if,
  81998. + int rem_wakeup, int reset)
  81999. +{
  82000. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  82001. + hprt0_data_t hprt0 = {.d32 = 0 };
  82002. +
  82003. + int timeout = 2000;
  82004. +
  82005. + DWC_DEBUGPL(DBG_HCD, "%s called\n", __FUNCTION__);
  82006. + /* Switch-on voltage to the core */
  82007. + gpwrdn.b.pwrdnswtch = 1;
  82008. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  82009. + dwc_udelay(10);
  82010. +
  82011. + /* Reset core */
  82012. + gpwrdn.d32 = 0;
  82013. + gpwrdn.b.pwrdnrstn = 1;
  82014. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  82015. + dwc_udelay(10);
  82016. +
  82017. + /* Assert Restore signal */
  82018. + gpwrdn.d32 = 0;
  82019. + gpwrdn.b.restore = 1;
  82020. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  82021. + dwc_udelay(10);
  82022. +
  82023. + /* Disable power clamps */
  82024. + gpwrdn.d32 = 0;
  82025. + gpwrdn.b.pwrdnclmp = 1;
  82026. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  82027. +
  82028. + if (!rem_wakeup) {
  82029. + dwc_udelay(50);
  82030. + }
  82031. +
  82032. + /* Deassert Reset core */
  82033. + gpwrdn.d32 = 0;
  82034. + gpwrdn.b.pwrdnrstn = 1;
  82035. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  82036. + dwc_udelay(10);
  82037. +
  82038. + /* Disable PMU interrupt */
  82039. + gpwrdn.d32 = 0;
  82040. + gpwrdn.b.pmuintsel = 1;
  82041. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  82042. +
  82043. + gpwrdn.d32 = 0;
  82044. + gpwrdn.b.connect_det_msk = 1;
  82045. + gpwrdn.b.srp_det_msk = 1;
  82046. + gpwrdn.b.disconn_det_msk = 1;
  82047. + gpwrdn.b.rst_det_msk = 1;
  82048. + gpwrdn.b.lnstchng_msk = 1;
  82049. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  82050. +
  82051. + /* Indicates that we are going out from hibernation */
  82052. + core_if->hibernation_suspend = 0;
  82053. +
  82054. + /* Set Restore Essential Regs bit in PCGCCTL register */
  82055. + restore_essential_regs(core_if, rem_wakeup, 1);
  82056. +
  82057. + /* Wait a little for seeing new value of variable hibernation_suspend if
  82058. + * Restore done interrupt received before polling */
  82059. + dwc_udelay(10);
  82060. +
  82061. + if (core_if->hibernation_suspend == 0) {
  82062. + /* Wait For Restore_done Interrupt. This mechanism of polling the
  82063. + * interrupt is introduced to avoid any possible race conditions
  82064. + */
  82065. + do {
  82066. + gintsts_data_t gintsts;
  82067. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  82068. + if (gintsts.b.restoredone) {
  82069. + gintsts.d32 = 0;
  82070. + gintsts.b.restoredone = 1;
  82071. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  82072. + DWC_DEBUGPL(DBG_HCD,"Restore Done Interrupt seen\n");
  82073. + break;
  82074. + }
  82075. + dwc_udelay(10);
  82076. + } while (--timeout);
  82077. + if (!timeout) {
  82078. + DWC_WARN("Restore Done interrupt wasn't generated\n");
  82079. + }
  82080. + }
  82081. +
  82082. + /* Set the flag's value to 0 again after receiving restore done interrupt */
  82083. + core_if->hibernation_suspend = 0;
  82084. +
  82085. + /* This step is not described in functional spec but if not wait for this
  82086. + * delay, mismatch interrupts occurred because just after restore core is
  82087. + * in Device mode(gintsts.curmode == 0) */
  82088. + dwc_mdelay(100);
  82089. +
  82090. + /* Clear all pending interrupts */
  82091. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  82092. +
  82093. + /* De-assert Restore */
  82094. + gpwrdn.d32 = 0;
  82095. + gpwrdn.b.restore = 1;
  82096. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  82097. + dwc_udelay(10);
  82098. +
  82099. + /* Restore GUSBCFG and HCFG */
  82100. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg,
  82101. + core_if->gr_backup->gusbcfg_local);
  82102. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hcfg,
  82103. + core_if->hr_backup->hcfg_local);
  82104. +
  82105. + /* De-assert Wakeup Logic */
  82106. + gpwrdn.d32 = 0;
  82107. + gpwrdn.b.pmuactv = 1;
  82108. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  82109. + dwc_udelay(10);
  82110. +
  82111. + /* Start the Resume operation by programming HPRT0 */
  82112. + hprt0.d32 = core_if->hr_backup->hprt0_local;
  82113. + hprt0.b.prtpwr = 1;
  82114. + hprt0.b.prtena = 0;
  82115. + hprt0.b.prtsusp = 0;
  82116. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  82117. +
  82118. + DWC_PRINTF("Resume Starts Now\n");
  82119. + if (!reset) { // Indicates it is Resume Operation
  82120. + hprt0.d32 = core_if->hr_backup->hprt0_local;
  82121. + hprt0.b.prtres = 1;
  82122. + hprt0.b.prtpwr = 1;
  82123. + hprt0.b.prtena = 0;
  82124. + hprt0.b.prtsusp = 0;
  82125. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  82126. +
  82127. + if (!rem_wakeup)
  82128. + hprt0.b.prtres = 0;
  82129. + /* Wait for Resume time and then program HPRT again */
  82130. + dwc_mdelay(100);
  82131. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  82132. +
  82133. + } else { // Indicates it is Reset Operation
  82134. + hprt0.d32 = core_if->hr_backup->hprt0_local;
  82135. + hprt0.b.prtrst = 1;
  82136. + hprt0.b.prtpwr = 1;
  82137. + hprt0.b.prtena = 0;
  82138. + hprt0.b.prtsusp = 0;
  82139. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  82140. + /* Wait for Reset time and then program HPRT again */
  82141. + dwc_mdelay(60);
  82142. + hprt0.b.prtrst = 0;
  82143. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  82144. + }
  82145. + /* Clear all interrupt status */
  82146. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  82147. + hprt0.b.prtconndet = 1;
  82148. + hprt0.b.prtenchng = 1;
  82149. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  82150. +
  82151. + /* Clear all pending interupts */
  82152. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  82153. +
  82154. + /* Restore global registers */
  82155. + dwc_otg_restore_global_regs(core_if);
  82156. + /* Restore host global registers */
  82157. + dwc_otg_restore_host_regs(core_if, reset);
  82158. +
  82159. + /* The core will be in ON STATE */
  82160. + core_if->lx_state = DWC_OTG_L0;
  82161. + DWC_PRINTF("Hibernation recovery is complete here\n");
  82162. + return 0;
  82163. +}
  82164. +
  82165. +/** Saves some register values into system memory. */
  82166. +int dwc_otg_save_global_regs(dwc_otg_core_if_t * core_if)
  82167. +{
  82168. + struct dwc_otg_global_regs_backup *gr;
  82169. + int i;
  82170. +
  82171. + gr = core_if->gr_backup;
  82172. + if (!gr) {
  82173. + gr = DWC_ALLOC(sizeof(*gr));
  82174. + if (!gr) {
  82175. + return -DWC_E_NO_MEMORY;
  82176. + }
  82177. + core_if->gr_backup = gr;
  82178. + }
  82179. +
  82180. + gr->gotgctl_local = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  82181. + gr->gintmsk_local = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
  82182. + gr->gahbcfg_local = DWC_READ_REG32(&core_if->core_global_regs->gahbcfg);
  82183. + gr->gusbcfg_local = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  82184. + gr->grxfsiz_local = DWC_READ_REG32(&core_if->core_global_regs->grxfsiz);
  82185. + gr->gnptxfsiz_local = DWC_READ_REG32(&core_if->core_global_regs->gnptxfsiz);
  82186. + gr->hptxfsiz_local = DWC_READ_REG32(&core_if->core_global_regs->hptxfsiz);
  82187. +#ifdef CONFIG_USB_DWC_OTG_LPM
  82188. + gr->glpmcfg_local = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  82189. +#endif
  82190. + gr->gi2cctl_local = DWC_READ_REG32(&core_if->core_global_regs->gi2cctl);
  82191. + gr->pcgcctl_local = DWC_READ_REG32(core_if->pcgcctl);
  82192. + gr->gdfifocfg_local =
  82193. + DWC_READ_REG32(&core_if->core_global_regs->gdfifocfg);
  82194. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  82195. + gr->dtxfsiz_local[i] =
  82196. + DWC_READ_REG32(&(core_if->core_global_regs->dtxfsiz[i]));
  82197. + }
  82198. +
  82199. + DWC_DEBUGPL(DBG_ANY, "===========Backing Global registers==========\n");
  82200. + DWC_DEBUGPL(DBG_ANY, "Backed up gotgctl = %08x\n", gr->gotgctl_local);
  82201. + DWC_DEBUGPL(DBG_ANY, "Backed up gintmsk = %08x\n", gr->gintmsk_local);
  82202. + DWC_DEBUGPL(DBG_ANY, "Backed up gahbcfg = %08x\n", gr->gahbcfg_local);
  82203. + DWC_DEBUGPL(DBG_ANY, "Backed up gusbcfg = %08x\n", gr->gusbcfg_local);
  82204. + DWC_DEBUGPL(DBG_ANY, "Backed up grxfsiz = %08x\n", gr->grxfsiz_local);
  82205. + DWC_DEBUGPL(DBG_ANY, "Backed up gnptxfsiz = %08x\n",
  82206. + gr->gnptxfsiz_local);
  82207. + DWC_DEBUGPL(DBG_ANY, "Backed up hptxfsiz = %08x\n",
  82208. + gr->hptxfsiz_local);
  82209. +#ifdef CONFIG_USB_DWC_OTG_LPM
  82210. + DWC_DEBUGPL(DBG_ANY, "Backed up glpmcfg = %08x\n", gr->glpmcfg_local);
  82211. +#endif
  82212. + DWC_DEBUGPL(DBG_ANY, "Backed up gi2cctl = %08x\n", gr->gi2cctl_local);
  82213. + DWC_DEBUGPL(DBG_ANY, "Backed up pcgcctl = %08x\n", gr->pcgcctl_local);
  82214. + DWC_DEBUGPL(DBG_ANY,"Backed up gdfifocfg = %08x\n",gr->gdfifocfg_local);
  82215. +
  82216. + return 0;
  82217. +}
  82218. +
  82219. +/** Saves GINTMSK register before setting the msk bits. */
  82220. +int dwc_otg_save_gintmsk_reg(dwc_otg_core_if_t * core_if)
  82221. +{
  82222. + struct dwc_otg_global_regs_backup *gr;
  82223. +
  82224. + gr = core_if->gr_backup;
  82225. + if (!gr) {
  82226. + gr = DWC_ALLOC(sizeof(*gr));
  82227. + if (!gr) {
  82228. + return -DWC_E_NO_MEMORY;
  82229. + }
  82230. + core_if->gr_backup = gr;
  82231. + }
  82232. +
  82233. + gr->gintmsk_local = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
  82234. +
  82235. + DWC_DEBUGPL(DBG_ANY,"=============Backing GINTMSK registers============\n");
  82236. + DWC_DEBUGPL(DBG_ANY, "Backed up gintmsk = %08x\n", gr->gintmsk_local);
  82237. +
  82238. + return 0;
  82239. +}
  82240. +
  82241. +int dwc_otg_save_dev_regs(dwc_otg_core_if_t * core_if)
  82242. +{
  82243. + struct dwc_otg_dev_regs_backup *dr;
  82244. + int i;
  82245. +
  82246. + dr = core_if->dr_backup;
  82247. + if (!dr) {
  82248. + dr = DWC_ALLOC(sizeof(*dr));
  82249. + if (!dr) {
  82250. + return -DWC_E_NO_MEMORY;
  82251. + }
  82252. + core_if->dr_backup = dr;
  82253. + }
  82254. +
  82255. + dr->dcfg = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  82256. + dr->dctl = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dctl);
  82257. + dr->daintmsk =
  82258. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->daintmsk);
  82259. + dr->diepmsk =
  82260. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->diepmsk);
  82261. + dr->doepmsk =
  82262. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->doepmsk);
  82263. +
  82264. + for (i = 0; i < core_if->dev_if->num_in_eps; ++i) {
  82265. + dr->diepctl[i] =
  82266. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[i]->diepctl);
  82267. + dr->dieptsiz[i] =
  82268. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[i]->dieptsiz);
  82269. + dr->diepdma[i] =
  82270. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[i]->diepdma);
  82271. + }
  82272. +
  82273. + DWC_DEBUGPL(DBG_ANY,
  82274. + "=============Backing Host registers==============\n");
  82275. + DWC_DEBUGPL(DBG_ANY, "Backed up dcfg = %08x\n", dr->dcfg);
  82276. + DWC_DEBUGPL(DBG_ANY, "Backed up dctl = %08x\n", dr->dctl);
  82277. + DWC_DEBUGPL(DBG_ANY, "Backed up daintmsk = %08x\n",
  82278. + dr->daintmsk);
  82279. + DWC_DEBUGPL(DBG_ANY, "Backed up diepmsk = %08x\n", dr->diepmsk);
  82280. + DWC_DEBUGPL(DBG_ANY, "Backed up doepmsk = %08x\n", dr->doepmsk);
  82281. + for (i = 0; i < core_if->dev_if->num_in_eps; ++i) {
  82282. + DWC_DEBUGPL(DBG_ANY, "Backed up diepctl[%d] = %08x\n", i,
  82283. + dr->diepctl[i]);
  82284. + DWC_DEBUGPL(DBG_ANY, "Backed up dieptsiz[%d] = %08x\n",
  82285. + i, dr->dieptsiz[i]);
  82286. + DWC_DEBUGPL(DBG_ANY, "Backed up diepdma[%d] = %08x\n", i,
  82287. + dr->diepdma[i]);
  82288. + }
  82289. +
  82290. + return 0;
  82291. +}
  82292. +
  82293. +int dwc_otg_save_host_regs(dwc_otg_core_if_t * core_if)
  82294. +{
  82295. + struct dwc_otg_host_regs_backup *hr;
  82296. + int i;
  82297. +
  82298. + hr = core_if->hr_backup;
  82299. + if (!hr) {
  82300. + hr = DWC_ALLOC(sizeof(*hr));
  82301. + if (!hr) {
  82302. + return -DWC_E_NO_MEMORY;
  82303. + }
  82304. + core_if->hr_backup = hr;
  82305. + }
  82306. +
  82307. + hr->hcfg_local =
  82308. + DWC_READ_REG32(&core_if->host_if->host_global_regs->hcfg);
  82309. + hr->haintmsk_local =
  82310. + DWC_READ_REG32(&core_if->host_if->host_global_regs->haintmsk);
  82311. + for (i = 0; i < dwc_otg_get_param_host_channels(core_if); ++i) {
  82312. + hr->hcintmsk_local[i] =
  82313. + DWC_READ_REG32(&core_if->host_if->hc_regs[i]->hcintmsk);
  82314. + }
  82315. + hr->hprt0_local = DWC_READ_REG32(core_if->host_if->hprt0);
  82316. + hr->hfir_local =
  82317. + DWC_READ_REG32(&core_if->host_if->host_global_regs->hfir);
  82318. +
  82319. + DWC_DEBUGPL(DBG_ANY,
  82320. + "=============Backing Host registers===============\n");
  82321. + DWC_DEBUGPL(DBG_ANY, "Backed up hcfg = %08x\n",
  82322. + hr->hcfg_local);
  82323. + DWC_DEBUGPL(DBG_ANY, "Backed up haintmsk = %08x\n", hr->haintmsk_local);
  82324. + for (i = 0; i < dwc_otg_get_param_host_channels(core_if); ++i) {
  82325. + DWC_DEBUGPL(DBG_ANY, "Backed up hcintmsk[%02d]=%08x\n", i,
  82326. + hr->hcintmsk_local[i]);
  82327. + }
  82328. + DWC_DEBUGPL(DBG_ANY, "Backed up hprt0 = %08x\n",
  82329. + hr->hprt0_local);
  82330. + DWC_DEBUGPL(DBG_ANY, "Backed up hfir = %08x\n",
  82331. + hr->hfir_local);
  82332. +
  82333. + return 0;
  82334. +}
  82335. +
  82336. +int dwc_otg_restore_global_regs(dwc_otg_core_if_t *core_if)
  82337. +{
  82338. + struct dwc_otg_global_regs_backup *gr;
  82339. + int i;
  82340. +
  82341. + gr = core_if->gr_backup;
  82342. + if (!gr) {
  82343. + return -DWC_E_INVALID;
  82344. + }
  82345. +
  82346. + DWC_WRITE_REG32(&core_if->core_global_regs->gotgctl, gr->gotgctl_local);
  82347. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, gr->gintmsk_local);
  82348. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, gr->gusbcfg_local);
  82349. + DWC_WRITE_REG32(&core_if->core_global_regs->gahbcfg, gr->gahbcfg_local);
  82350. + DWC_WRITE_REG32(&core_if->core_global_regs->grxfsiz, gr->grxfsiz_local);
  82351. + DWC_WRITE_REG32(&core_if->core_global_regs->gnptxfsiz,
  82352. + gr->gnptxfsiz_local);
  82353. + DWC_WRITE_REG32(&core_if->core_global_regs->hptxfsiz,
  82354. + gr->hptxfsiz_local);
  82355. + DWC_WRITE_REG32(&core_if->core_global_regs->gdfifocfg,
  82356. + gr->gdfifocfg_local);
  82357. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  82358. + DWC_WRITE_REG32(&core_if->core_global_regs->dtxfsiz[i],
  82359. + gr->dtxfsiz_local[i]);
  82360. + }
  82361. +
  82362. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  82363. + DWC_WRITE_REG32(core_if->host_if->hprt0, 0x0000100A);
  82364. + DWC_WRITE_REG32(&core_if->core_global_regs->gahbcfg,
  82365. + (gr->gahbcfg_local));
  82366. + return 0;
  82367. +}
  82368. +
  82369. +int dwc_otg_restore_dev_regs(dwc_otg_core_if_t * core_if, int rem_wakeup)
  82370. +{
  82371. + struct dwc_otg_dev_regs_backup *dr;
  82372. + int i;
  82373. +
  82374. + dr = core_if->dr_backup;
  82375. +
  82376. + if (!dr) {
  82377. + return -DWC_E_INVALID;
  82378. + }
  82379. +
  82380. + if (!rem_wakeup) {
  82381. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl,
  82382. + dr->dctl);
  82383. + }
  82384. +
  82385. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->daintmsk, dr->daintmsk);
  82386. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->diepmsk, dr->diepmsk);
  82387. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->doepmsk, dr->doepmsk);
  82388. +
  82389. + for (i = 0; i < core_if->dev_if->num_in_eps; ++i) {
  82390. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[i]->dieptsiz, dr->dieptsiz[i]);
  82391. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[i]->diepdma, dr->diepdma[i]);
  82392. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[i]->diepctl, dr->diepctl[i]);
  82393. + }
  82394. +
  82395. + return 0;
  82396. +}
  82397. +
  82398. +int dwc_otg_restore_host_regs(dwc_otg_core_if_t * core_if, int reset)
  82399. +{
  82400. + struct dwc_otg_host_regs_backup *hr;
  82401. + int i;
  82402. + hr = core_if->hr_backup;
  82403. +
  82404. + if (!hr) {
  82405. + return -DWC_E_INVALID;
  82406. + }
  82407. +
  82408. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hcfg, hr->hcfg_local);
  82409. + //if (!reset)
  82410. + //{
  82411. + // DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hfir, hr->hfir_local);
  82412. + //}
  82413. +
  82414. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->haintmsk,
  82415. + hr->haintmsk_local);
  82416. + for (i = 0; i < dwc_otg_get_param_host_channels(core_if); ++i) {
  82417. + DWC_WRITE_REG32(&core_if->host_if->hc_regs[i]->hcintmsk,
  82418. + hr->hcintmsk_local[i]);
  82419. + }
  82420. +
  82421. + return 0;
  82422. +}
  82423. +
  82424. +int restore_lpm_i2c_regs(dwc_otg_core_if_t * core_if)
  82425. +{
  82426. + struct dwc_otg_global_regs_backup *gr;
  82427. +
  82428. + gr = core_if->gr_backup;
  82429. +
  82430. + /* Restore values for LPM and I2C */
  82431. +#ifdef CONFIG_USB_DWC_OTG_LPM
  82432. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg, gr->glpmcfg_local);
  82433. +#endif
  82434. + DWC_WRITE_REG32(&core_if->core_global_regs->gi2cctl, gr->gi2cctl_local);
  82435. +
  82436. + return 0;
  82437. +}
  82438. +
  82439. +int restore_essential_regs(dwc_otg_core_if_t * core_if, int rmode, int is_host)
  82440. +{
  82441. + struct dwc_otg_global_regs_backup *gr;
  82442. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  82443. + gahbcfg_data_t gahbcfg = {.d32 = 0 };
  82444. + gusbcfg_data_t gusbcfg = {.d32 = 0 };
  82445. + gintmsk_data_t gintmsk = {.d32 = 0 };
  82446. +
  82447. + /* Restore LPM and I2C registers */
  82448. + restore_lpm_i2c_regs(core_if);
  82449. +
  82450. + /* Set PCGCCTL to 0 */
  82451. + DWC_WRITE_REG32(core_if->pcgcctl, 0x00000000);
  82452. +
  82453. + gr = core_if->gr_backup;
  82454. + /* Load restore values for [31:14] bits */
  82455. + DWC_WRITE_REG32(core_if->pcgcctl,
  82456. + ((gr->pcgcctl_local & 0xffffc000) | 0x00020000));
  82457. +
  82458. + /* Umnask global Interrupt in GAHBCFG and restore it */
  82459. + gahbcfg.d32 = gr->gahbcfg_local;
  82460. + gahbcfg.b.glblintrmsk = 1;
  82461. + DWC_WRITE_REG32(&core_if->core_global_regs->gahbcfg, gahbcfg.d32);
  82462. +
  82463. + /* Clear all pending interupts */
  82464. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  82465. +
  82466. + /* Unmask restore done interrupt */
  82467. + gintmsk.b.restoredone = 1;
  82468. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, gintmsk.d32);
  82469. +
  82470. + /* Restore GUSBCFG and HCFG/DCFG */
  82471. + gusbcfg.d32 = core_if->gr_backup->gusbcfg_local;
  82472. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, gusbcfg.d32);
  82473. +
  82474. + if (is_host) {
  82475. + hcfg_data_t hcfg = {.d32 = 0 };
  82476. + hcfg.d32 = core_if->hr_backup->hcfg_local;
  82477. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hcfg,
  82478. + hcfg.d32);
  82479. +
  82480. + /* Load restore values for [31:14] bits */
  82481. + pcgcctl.d32 = gr->pcgcctl_local & 0xffffc000;
  82482. + pcgcctl.d32 = gr->pcgcctl_local | 0x00020000;
  82483. +
  82484. + if (rmode)
  82485. + pcgcctl.b.restoremode = 1;
  82486. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  82487. + dwc_udelay(10);
  82488. +
  82489. + /* Load restore values for [31:14] bits and set EssRegRestored bit */
  82490. + pcgcctl.d32 = gr->pcgcctl_local | 0xffffc000;
  82491. + pcgcctl.d32 = gr->pcgcctl_local & 0xffffc000;
  82492. + pcgcctl.b.ess_reg_restored = 1;
  82493. + if (rmode)
  82494. + pcgcctl.b.restoremode = 1;
  82495. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  82496. + } else {
  82497. + dcfg_data_t dcfg = {.d32 = 0 };
  82498. + dcfg.d32 = core_if->dr_backup->dcfg;
  82499. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg, dcfg.d32);
  82500. +
  82501. + /* Load restore values for [31:14] bits */
  82502. + pcgcctl.d32 = gr->pcgcctl_local & 0xffffc000;
  82503. + pcgcctl.d32 = gr->pcgcctl_local | 0x00020000;
  82504. + if (!rmode) {
  82505. + pcgcctl.d32 |= 0x208;
  82506. + }
  82507. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  82508. + dwc_udelay(10);
  82509. +
  82510. + /* Load restore values for [31:14] bits */
  82511. + pcgcctl.d32 = gr->pcgcctl_local & 0xffffc000;
  82512. + pcgcctl.d32 = gr->pcgcctl_local | 0x00020000;
  82513. + pcgcctl.b.ess_reg_restored = 1;
  82514. + if (!rmode)
  82515. + pcgcctl.d32 |= 0x208;
  82516. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  82517. + }
  82518. +
  82519. + return 0;
  82520. +}
  82521. +
  82522. +/**
  82523. + * Initializes the FSLSPClkSel field of the HCFG register depending on the PHY
  82524. + * type.
  82525. + */
  82526. +static void init_fslspclksel(dwc_otg_core_if_t * core_if)
  82527. +{
  82528. + uint32_t val;
  82529. + hcfg_data_t hcfg;
  82530. +
  82531. + if (((core_if->hwcfg2.b.hs_phy_type == 2) &&
  82532. + (core_if->hwcfg2.b.fs_phy_type == 1) &&
  82533. + (core_if->core_params->ulpi_fs_ls)) ||
  82534. + (core_if->core_params->phy_type == DWC_PHY_TYPE_PARAM_FS)) {
  82535. + /* Full speed PHY */
  82536. + val = DWC_HCFG_48_MHZ;
  82537. + } else {
  82538. + /* High speed PHY running at full speed or high speed */
  82539. + val = DWC_HCFG_30_60_MHZ;
  82540. + }
  82541. +
  82542. + DWC_DEBUGPL(DBG_CIL, "Initializing HCFG.FSLSPClkSel to 0x%1x\n", val);
  82543. + hcfg.d32 = DWC_READ_REG32(&core_if->host_if->host_global_regs->hcfg);
  82544. + hcfg.b.fslspclksel = val;
  82545. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hcfg, hcfg.d32);
  82546. +}
  82547. +
  82548. +/**
  82549. + * Initializes the DevSpd field of the DCFG register depending on the PHY type
  82550. + * and the enumeration speed of the device.
  82551. + */
  82552. +static void init_devspd(dwc_otg_core_if_t * core_if)
  82553. +{
  82554. + uint32_t val;
  82555. + dcfg_data_t dcfg;
  82556. +
  82557. + if (((core_if->hwcfg2.b.hs_phy_type == 2) &&
  82558. + (core_if->hwcfg2.b.fs_phy_type == 1) &&
  82559. + (core_if->core_params->ulpi_fs_ls)) ||
  82560. + (core_if->core_params->phy_type == DWC_PHY_TYPE_PARAM_FS)) {
  82561. + /* Full speed PHY */
  82562. + val = 0x3;
  82563. + } else if (core_if->core_params->speed == DWC_SPEED_PARAM_FULL) {
  82564. + /* High speed PHY running at full speed */
  82565. + val = 0x1;
  82566. + } else {
  82567. + /* High speed PHY running at high speed */
  82568. + val = 0x0;
  82569. + }
  82570. +
  82571. + DWC_DEBUGPL(DBG_CIL, "Initializing DCFG.DevSpd to 0x%1x\n", val);
  82572. +
  82573. + dcfg.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  82574. + dcfg.b.devspd = val;
  82575. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg, dcfg.d32);
  82576. +}
  82577. +
  82578. +/**
  82579. + * This function calculates the number of IN EPS
  82580. + * using GHWCFG1 and GHWCFG2 registers values
  82581. + *
  82582. + * @param core_if Programming view of the DWC_otg controller
  82583. + */
  82584. +static uint32_t calc_num_in_eps(dwc_otg_core_if_t * core_if)
  82585. +{
  82586. + uint32_t num_in_eps = 0;
  82587. + uint32_t num_eps = core_if->hwcfg2.b.num_dev_ep;
  82588. + uint32_t hwcfg1 = core_if->hwcfg1.d32 >> 3;
  82589. + uint32_t num_tx_fifos = core_if->hwcfg4.b.num_in_eps;
  82590. + int i;
  82591. +
  82592. + for (i = 0; i < num_eps; ++i) {
  82593. + if (!(hwcfg1 & 0x1))
  82594. + num_in_eps++;
  82595. +
  82596. + hwcfg1 >>= 2;
  82597. + }
  82598. +
  82599. + if (core_if->hwcfg4.b.ded_fifo_en) {
  82600. + num_in_eps =
  82601. + (num_in_eps > num_tx_fifos) ? num_tx_fifos : num_in_eps;
  82602. + }
  82603. +
  82604. + return num_in_eps;
  82605. +}
  82606. +
  82607. +/**
  82608. + * This function calculates the number of OUT EPS
  82609. + * using GHWCFG1 and GHWCFG2 registers values
  82610. + *
  82611. + * @param core_if Programming view of the DWC_otg controller
  82612. + */
  82613. +static uint32_t calc_num_out_eps(dwc_otg_core_if_t * core_if)
  82614. +{
  82615. + uint32_t num_out_eps = 0;
  82616. + uint32_t num_eps = core_if->hwcfg2.b.num_dev_ep;
  82617. + uint32_t hwcfg1 = core_if->hwcfg1.d32 >> 2;
  82618. + int i;
  82619. +
  82620. + for (i = 0; i < num_eps; ++i) {
  82621. + if (!(hwcfg1 & 0x1))
  82622. + num_out_eps++;
  82623. +
  82624. + hwcfg1 >>= 2;
  82625. + }
  82626. + return num_out_eps;
  82627. +}
  82628. +
  82629. +/**
  82630. + * This function initializes the DWC_otg controller registers and
  82631. + * prepares the core for device mode or host mode operation.
  82632. + *
  82633. + * @param core_if Programming view of the DWC_otg controller
  82634. + *
  82635. + */
  82636. +void dwc_otg_core_init(dwc_otg_core_if_t * core_if)
  82637. +{
  82638. + int i = 0;
  82639. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  82640. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  82641. + gahbcfg_data_t ahbcfg = {.d32 = 0 };
  82642. + gusbcfg_data_t usbcfg = {.d32 = 0 };
  82643. + gi2cctl_data_t i2cctl = {.d32 = 0 };
  82644. +
  82645. + DWC_DEBUGPL(DBG_CILV, "dwc_otg_core_init(%p) regs at %p\n",
  82646. + core_if, global_regs);
  82647. +
  82648. + /* Common Initialization */
  82649. + usbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  82650. +
  82651. + /* Program the ULPI External VBUS bit if needed */
  82652. + usbcfg.b.ulpi_ext_vbus_drv =
  82653. + (core_if->core_params->phy_ulpi_ext_vbus ==
  82654. + DWC_PHY_ULPI_EXTERNAL_VBUS) ? 1 : 0;
  82655. +
  82656. + /* Set external TS Dline pulsing */
  82657. + usbcfg.b.term_sel_dl_pulse =
  82658. + (core_if->core_params->ts_dline == 1) ? 1 : 0;
  82659. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  82660. +
  82661. + /* Reset the Controller */
  82662. + dwc_otg_core_reset(core_if);
  82663. +
  82664. + core_if->adp_enable = core_if->core_params->adp_supp_enable;
  82665. + core_if->power_down = core_if->core_params->power_down;
  82666. + core_if->otg_sts = 0;
  82667. +
  82668. + /* Initialize parameters from Hardware configuration registers. */
  82669. + dev_if->num_in_eps = calc_num_in_eps(core_if);
  82670. + dev_if->num_out_eps = calc_num_out_eps(core_if);
  82671. +
  82672. + DWC_DEBUGPL(DBG_CIL, "num_dev_perio_in_ep=%d\n",
  82673. + core_if->hwcfg4.b.num_dev_perio_in_ep);
  82674. +
  82675. + for (i = 0; i < core_if->hwcfg4.b.num_dev_perio_in_ep; i++) {
  82676. + dev_if->perio_tx_fifo_size[i] =
  82677. + DWC_READ_REG32(&global_regs->dtxfsiz[i]) >> 16;
  82678. + DWC_DEBUGPL(DBG_CIL, "Periodic Tx FIFO SZ #%d=0x%0x\n",
  82679. + i, dev_if->perio_tx_fifo_size[i]);
  82680. + }
  82681. +
  82682. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  82683. + dev_if->tx_fifo_size[i] =
  82684. + DWC_READ_REG32(&global_regs->dtxfsiz[i]) >> 16;
  82685. + DWC_DEBUGPL(DBG_CIL, "Tx FIFO SZ #%d=0x%0x\n",
  82686. + i, dev_if->tx_fifo_size[i]);
  82687. + }
  82688. +
  82689. + core_if->total_fifo_size = core_if->hwcfg3.b.dfifo_depth;
  82690. + core_if->rx_fifo_size = DWC_READ_REG32(&global_regs->grxfsiz);
  82691. + core_if->nperio_tx_fifo_size =
  82692. + DWC_READ_REG32(&global_regs->gnptxfsiz) >> 16;
  82693. +
  82694. + DWC_DEBUGPL(DBG_CIL, "Total FIFO SZ=%d\n", core_if->total_fifo_size);
  82695. + DWC_DEBUGPL(DBG_CIL, "Rx FIFO SZ=%d\n", core_if->rx_fifo_size);
  82696. + DWC_DEBUGPL(DBG_CIL, "NP Tx FIFO SZ=%d\n",
  82697. + core_if->nperio_tx_fifo_size);
  82698. +
  82699. + /* This programming sequence needs to happen in FS mode before any other
  82700. + * programming occurs */
  82701. + if ((core_if->core_params->speed == DWC_SPEED_PARAM_FULL) &&
  82702. + (core_if->core_params->phy_type == DWC_PHY_TYPE_PARAM_FS)) {
  82703. + /* If FS mode with FS PHY */
  82704. +
  82705. + /* core_init() is now called on every switch so only call the
  82706. + * following for the first time through. */
  82707. + if (!core_if->phy_init_done) {
  82708. + core_if->phy_init_done = 1;
  82709. + DWC_DEBUGPL(DBG_CIL, "FS_PHY detected\n");
  82710. + usbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  82711. + usbcfg.b.physel = 1;
  82712. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  82713. +
  82714. + /* Reset after a PHY select */
  82715. + dwc_otg_core_reset(core_if);
  82716. + }
  82717. +
  82718. + /* Program DCFG.DevSpd or HCFG.FSLSPclkSel to 48Mhz in FS. Also
  82719. + * do this on HNP Dev/Host mode switches (done in dev_init and
  82720. + * host_init). */
  82721. + if (dwc_otg_is_host_mode(core_if)) {
  82722. + init_fslspclksel(core_if);
  82723. + } else {
  82724. + init_devspd(core_if);
  82725. + }
  82726. +
  82727. + if (core_if->core_params->i2c_enable) {
  82728. + DWC_DEBUGPL(DBG_CIL, "FS_PHY Enabling I2c\n");
  82729. + /* Program GUSBCFG.OtgUtmifsSel to I2C */
  82730. + usbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  82731. + usbcfg.b.otgutmifssel = 1;
  82732. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  82733. +
  82734. + /* Program GI2CCTL.I2CEn */
  82735. + i2cctl.d32 = DWC_READ_REG32(&global_regs->gi2cctl);
  82736. + i2cctl.b.i2cdevaddr = 1;
  82737. + i2cctl.b.i2cen = 0;
  82738. + DWC_WRITE_REG32(&global_regs->gi2cctl, i2cctl.d32);
  82739. + i2cctl.b.i2cen = 1;
  82740. + DWC_WRITE_REG32(&global_regs->gi2cctl, i2cctl.d32);
  82741. + }
  82742. +
  82743. + } /* endif speed == DWC_SPEED_PARAM_FULL */
  82744. + else {
  82745. + /* High speed PHY. */
  82746. + if (!core_if->phy_init_done) {
  82747. + core_if->phy_init_done = 1;
  82748. + /* HS PHY parameters. These parameters are preserved
  82749. + * during soft reset so only program the first time. Do
  82750. + * a soft reset immediately after setting phyif. */
  82751. +
  82752. + if (core_if->core_params->phy_type == 2) {
  82753. + /* ULPI interface */
  82754. + usbcfg.b.ulpi_utmi_sel = 1;
  82755. + usbcfg.b.phyif = 0;
  82756. + usbcfg.b.ddrsel =
  82757. + core_if->core_params->phy_ulpi_ddr;
  82758. + } else if (core_if->core_params->phy_type == 1) {
  82759. + /* UTMI+ interface */
  82760. + usbcfg.b.ulpi_utmi_sel = 0;
  82761. + if (core_if->core_params->phy_utmi_width == 16) {
  82762. + usbcfg.b.phyif = 1;
  82763. +
  82764. + } else {
  82765. + usbcfg.b.phyif = 0;
  82766. + }
  82767. + } else {
  82768. + DWC_ERROR("FS PHY TYPE\n");
  82769. + }
  82770. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  82771. + /* Reset after setting the PHY parameters */
  82772. + dwc_otg_core_reset(core_if);
  82773. + }
  82774. + }
  82775. +
  82776. + if ((core_if->hwcfg2.b.hs_phy_type == 2) &&
  82777. + (core_if->hwcfg2.b.fs_phy_type == 1) &&
  82778. + (core_if->core_params->ulpi_fs_ls)) {
  82779. + DWC_DEBUGPL(DBG_CIL, "Setting ULPI FSLS\n");
  82780. + usbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  82781. + usbcfg.b.ulpi_fsls = 1;
  82782. + usbcfg.b.ulpi_clk_sus_m = 1;
  82783. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  82784. + } else {
  82785. + usbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  82786. + usbcfg.b.ulpi_fsls = 0;
  82787. + usbcfg.b.ulpi_clk_sus_m = 0;
  82788. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  82789. + }
  82790. +
  82791. + /* Program the GAHBCFG Register. */
  82792. + switch (core_if->hwcfg2.b.architecture) {
  82793. +
  82794. + case DWC_SLAVE_ONLY_ARCH:
  82795. + DWC_DEBUGPL(DBG_CIL, "Slave Only Mode\n");
  82796. + ahbcfg.b.nptxfemplvl_txfemplvl =
  82797. + DWC_GAHBCFG_TXFEMPTYLVL_HALFEMPTY;
  82798. + ahbcfg.b.ptxfemplvl = DWC_GAHBCFG_TXFEMPTYLVL_HALFEMPTY;
  82799. + core_if->dma_enable = 0;
  82800. + core_if->dma_desc_enable = 0;
  82801. + break;
  82802. +
  82803. + case DWC_EXT_DMA_ARCH:
  82804. + DWC_DEBUGPL(DBG_CIL, "External DMA Mode\n");
  82805. + {
  82806. + uint8_t brst_sz = core_if->core_params->dma_burst_size;
  82807. + ahbcfg.b.hburstlen = 0;
  82808. + while (brst_sz > 1) {
  82809. + ahbcfg.b.hburstlen++;
  82810. + brst_sz >>= 1;
  82811. + }
  82812. + }
  82813. + core_if->dma_enable = (core_if->core_params->dma_enable != 0);
  82814. + core_if->dma_desc_enable =
  82815. + (core_if->core_params->dma_desc_enable != 0);
  82816. + break;
  82817. +
  82818. + case DWC_INT_DMA_ARCH:
  82819. + DWC_DEBUGPL(DBG_CIL, "Internal DMA Mode\n");
  82820. + /* Old value was DWC_GAHBCFG_INT_DMA_BURST_INCR - done for
  82821. + Host mode ISOC in issue fix - vahrama */
  82822. + /* Broadcom had altered to (1<<3)|(0<<0) - WRESP=1, max 4 beats */
  82823. + ahbcfg.b.hburstlen = (1<<3)|(0<<0);//DWC_GAHBCFG_INT_DMA_BURST_INCR4;
  82824. + core_if->dma_enable = (core_if->core_params->dma_enable != 0);
  82825. + core_if->dma_desc_enable =
  82826. + (core_if->core_params->dma_desc_enable != 0);
  82827. + break;
  82828. +
  82829. + }
  82830. + if (core_if->dma_enable) {
  82831. + if (core_if->dma_desc_enable) {
  82832. + DWC_PRINTF("Using Descriptor DMA mode\n");
  82833. + } else {
  82834. + DWC_PRINTF("Using Buffer DMA mode\n");
  82835. +
  82836. + }
  82837. + } else {
  82838. + DWC_PRINTF("Using Slave mode\n");
  82839. + core_if->dma_desc_enable = 0;
  82840. + }
  82841. +
  82842. + if (core_if->core_params->ahb_single) {
  82843. + ahbcfg.b.ahbsingle = 1;
  82844. + }
  82845. +
  82846. + ahbcfg.b.dmaenable = core_if->dma_enable;
  82847. + DWC_WRITE_REG32(&global_regs->gahbcfg, ahbcfg.d32);
  82848. +
  82849. + core_if->en_multiple_tx_fifo = core_if->hwcfg4.b.ded_fifo_en;
  82850. +
  82851. + core_if->pti_enh_enable = core_if->core_params->pti_enable != 0;
  82852. + core_if->multiproc_int_enable = core_if->core_params->mpi_enable;
  82853. + DWC_PRINTF("Periodic Transfer Interrupt Enhancement - %s\n",
  82854. + ((core_if->pti_enh_enable) ? "enabled" : "disabled"));
  82855. + DWC_PRINTF("Multiprocessor Interrupt Enhancement - %s\n",
  82856. + ((core_if->multiproc_int_enable) ? "enabled" : "disabled"));
  82857. +
  82858. + /*
  82859. + * Program the GUSBCFG register.
  82860. + */
  82861. + usbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  82862. +
  82863. + switch (core_if->hwcfg2.b.op_mode) {
  82864. + case DWC_MODE_HNP_SRP_CAPABLE:
  82865. + usbcfg.b.hnpcap = (core_if->core_params->otg_cap ==
  82866. + DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE);
  82867. + usbcfg.b.srpcap = (core_if->core_params->otg_cap !=
  82868. + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
  82869. + break;
  82870. +
  82871. + case DWC_MODE_SRP_ONLY_CAPABLE:
  82872. + usbcfg.b.hnpcap = 0;
  82873. + usbcfg.b.srpcap = (core_if->core_params->otg_cap !=
  82874. + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
  82875. + break;
  82876. +
  82877. + case DWC_MODE_NO_HNP_SRP_CAPABLE:
  82878. + usbcfg.b.hnpcap = 0;
  82879. + usbcfg.b.srpcap = 0;
  82880. + break;
  82881. +
  82882. + case DWC_MODE_SRP_CAPABLE_DEVICE:
  82883. + usbcfg.b.hnpcap = 0;
  82884. + usbcfg.b.srpcap = (core_if->core_params->otg_cap !=
  82885. + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
  82886. + break;
  82887. +
  82888. + case DWC_MODE_NO_SRP_CAPABLE_DEVICE:
  82889. + usbcfg.b.hnpcap = 0;
  82890. + usbcfg.b.srpcap = 0;
  82891. + break;
  82892. +
  82893. + case DWC_MODE_SRP_CAPABLE_HOST:
  82894. + usbcfg.b.hnpcap = 0;
  82895. + usbcfg.b.srpcap = (core_if->core_params->otg_cap !=
  82896. + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
  82897. + break;
  82898. +
  82899. + case DWC_MODE_NO_SRP_CAPABLE_HOST:
  82900. + usbcfg.b.hnpcap = 0;
  82901. + usbcfg.b.srpcap = 0;
  82902. + break;
  82903. + }
  82904. +
  82905. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  82906. +
  82907. +#ifdef CONFIG_USB_DWC_OTG_LPM
  82908. + if (core_if->core_params->lpm_enable) {
  82909. + glpmcfg_data_t lpmcfg = {.d32 = 0 };
  82910. +
  82911. + /* To enable LPM support set lpm_cap_en bit */
  82912. + lpmcfg.b.lpm_cap_en = 1;
  82913. +
  82914. + /* Make AppL1Res ACK */
  82915. + lpmcfg.b.appl_resp = 1;
  82916. +
  82917. + /* Retry 3 times */
  82918. + lpmcfg.b.retry_count = 3;
  82919. +
  82920. + DWC_MODIFY_REG32(&core_if->core_global_regs->glpmcfg,
  82921. + 0, lpmcfg.d32);
  82922. +
  82923. + }
  82924. +#endif
  82925. + if (core_if->core_params->ic_usb_cap) {
  82926. + gusbcfg_data_t gusbcfg = {.d32 = 0 };
  82927. + gusbcfg.b.ic_usb_cap = 1;
  82928. + DWC_MODIFY_REG32(&core_if->core_global_regs->gusbcfg,
  82929. + 0, gusbcfg.d32);
  82930. + }
  82931. + {
  82932. + gotgctl_data_t gotgctl = {.d32 = 0 };
  82933. + gotgctl.b.otgver = core_if->core_params->otg_ver;
  82934. + DWC_MODIFY_REG32(&core_if->core_global_regs->gotgctl, 0,
  82935. + gotgctl.d32);
  82936. + /* Set OTG version supported */
  82937. + core_if->otg_ver = core_if->core_params->otg_ver;
  82938. + DWC_PRINTF("OTG VER PARAM: %d, OTG VER FLAG: %d\n",
  82939. + core_if->core_params->otg_ver, core_if->otg_ver);
  82940. + }
  82941. +
  82942. +
  82943. + /* Enable common interrupts */
  82944. + dwc_otg_enable_common_interrupts(core_if);
  82945. +
  82946. + /* Do device or host intialization based on mode during PCD
  82947. + * and HCD initialization */
  82948. + if (dwc_otg_is_host_mode(core_if)) {
  82949. + DWC_DEBUGPL(DBG_ANY, "Host Mode\n");
  82950. + core_if->op_state = A_HOST;
  82951. + } else {
  82952. + DWC_DEBUGPL(DBG_ANY, "Device Mode\n");
  82953. + core_if->op_state = B_PERIPHERAL;
  82954. +#ifdef DWC_DEVICE_ONLY
  82955. + dwc_otg_core_dev_init(core_if);
  82956. +#endif
  82957. + }
  82958. +}
  82959. +
  82960. +/**
  82961. + * This function enables the Device mode interrupts.
  82962. + *
  82963. + * @param core_if Programming view of DWC_otg controller
  82964. + */
  82965. +void dwc_otg_enable_device_interrupts(dwc_otg_core_if_t * core_if)
  82966. +{
  82967. + gintmsk_data_t intr_mask = {.d32 = 0 };
  82968. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  82969. +
  82970. + DWC_DEBUGPL(DBG_CIL, "%s()\n", __func__);
  82971. +
  82972. + /* Disable all interrupts. */
  82973. + DWC_WRITE_REG32(&global_regs->gintmsk, 0);
  82974. +
  82975. + /* Clear any pending interrupts */
  82976. + DWC_WRITE_REG32(&global_regs->gintsts, 0xFFFFFFFF);
  82977. +
  82978. + /* Enable the common interrupts */
  82979. + dwc_otg_enable_common_interrupts(core_if);
  82980. +
  82981. + /* Enable interrupts */
  82982. + intr_mask.b.usbreset = 1;
  82983. + intr_mask.b.enumdone = 1;
  82984. + /* Disable Disconnect interrupt in Device mode */
  82985. + intr_mask.b.disconnect = 0;
  82986. +
  82987. + if (!core_if->multiproc_int_enable) {
  82988. + intr_mask.b.inepintr = 1;
  82989. + intr_mask.b.outepintr = 1;
  82990. + }
  82991. +
  82992. + intr_mask.b.erlysuspend = 1;
  82993. +
  82994. + if (core_if->en_multiple_tx_fifo == 0) {
  82995. + intr_mask.b.epmismatch = 1;
  82996. + }
  82997. +
  82998. + //intr_mask.b.incomplisoout = 1;
  82999. + intr_mask.b.incomplisoin = 1;
  83000. +
  83001. +/* Enable the ignore frame number for ISOC xfers - MAS */
  83002. +/* Disable to support high bandwith ISOC transfers - manukz */
  83003. +#if 0
  83004. +#ifdef DWC_UTE_PER_IO
  83005. + if (core_if->dma_enable) {
  83006. + if (core_if->dma_desc_enable) {
  83007. + dctl_data_t dctl1 = {.d32 = 0 };
  83008. + dctl1.b.ifrmnum = 1;
  83009. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  83010. + dctl, 0, dctl1.d32);
  83011. + DWC_DEBUG("----Enabled Ignore frame number (0x%08x)",
  83012. + DWC_READ_REG32(&core_if->dev_if->
  83013. + dev_global_regs->dctl));
  83014. + }
  83015. + }
  83016. +#endif
  83017. +#endif
  83018. +#ifdef DWC_EN_ISOC
  83019. + if (core_if->dma_enable) {
  83020. + if (core_if->dma_desc_enable == 0) {
  83021. + if (core_if->pti_enh_enable) {
  83022. + dctl_data_t dctl = {.d32 = 0 };
  83023. + dctl.b.ifrmnum = 1;
  83024. + DWC_MODIFY_REG32(&core_if->
  83025. + dev_if->dev_global_regs->dctl,
  83026. + 0, dctl.d32);
  83027. + } else {
  83028. + intr_mask.b.incomplisoin = 1;
  83029. + intr_mask.b.incomplisoout = 1;
  83030. + }
  83031. + }
  83032. + } else {
  83033. + intr_mask.b.incomplisoin = 1;
  83034. + intr_mask.b.incomplisoout = 1;
  83035. + }
  83036. +#endif /* DWC_EN_ISOC */
  83037. +
  83038. + /** @todo NGS: Should this be a module parameter? */
  83039. +#ifdef USE_PERIODIC_EP
  83040. + intr_mask.b.isooutdrop = 1;
  83041. + intr_mask.b.eopframe = 1;
  83042. + intr_mask.b.incomplisoin = 1;
  83043. + intr_mask.b.incomplisoout = 1;
  83044. +#endif
  83045. +
  83046. + DWC_MODIFY_REG32(&global_regs->gintmsk, intr_mask.d32, intr_mask.d32);
  83047. +
  83048. + DWC_DEBUGPL(DBG_CIL, "%s() gintmsk=%0x\n", __func__,
  83049. + DWC_READ_REG32(&global_regs->gintmsk));
  83050. +}
  83051. +
  83052. +/**
  83053. + * This function initializes the DWC_otg controller registers for
  83054. + * device mode.
  83055. + *
  83056. + * @param core_if Programming view of DWC_otg controller
  83057. + *
  83058. + */
  83059. +void dwc_otg_core_dev_init(dwc_otg_core_if_t * core_if)
  83060. +{
  83061. + int i;
  83062. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  83063. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  83064. + dwc_otg_core_params_t *params = core_if->core_params;
  83065. + dcfg_data_t dcfg = {.d32 = 0 };
  83066. + depctl_data_t diepctl = {.d32 = 0 };
  83067. + grstctl_t resetctl = {.d32 = 0 };
  83068. + uint32_t rx_fifo_size;
  83069. + fifosize_data_t nptxfifosize;
  83070. + fifosize_data_t txfifosize;
  83071. + dthrctl_data_t dthrctl;
  83072. + fifosize_data_t ptxfifosize;
  83073. + uint16_t rxfsiz, nptxfsiz;
  83074. + gdfifocfg_data_t gdfifocfg = {.d32 = 0 };
  83075. + hwcfg3_data_t hwcfg3 = {.d32 = 0 };
  83076. +
  83077. + /* Restart the Phy Clock */
  83078. + DWC_WRITE_REG32(core_if->pcgcctl, 0);
  83079. +
  83080. + /* Device configuration register */
  83081. + init_devspd(core_if);
  83082. + dcfg.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dcfg);
  83083. + dcfg.b.descdma = (core_if->dma_desc_enable) ? 1 : 0;
  83084. + dcfg.b.perfrint = DWC_DCFG_FRAME_INTERVAL_80;
  83085. + /* Enable Device OUT NAK in case of DDMA mode*/
  83086. + if (core_if->core_params->dev_out_nak) {
  83087. + dcfg.b.endevoutnak = 1;
  83088. + }
  83089. +
  83090. + if (core_if->core_params->cont_on_bna) {
  83091. + dctl_data_t dctl = {.d32 = 0 };
  83092. + dctl.b.encontonbna = 1;
  83093. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dctl, 0, dctl.d32);
  83094. + }
  83095. +
  83096. +
  83097. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dcfg, dcfg.d32);
  83098. +
  83099. + /* Configure data FIFO sizes */
  83100. + if (core_if->hwcfg2.b.dynamic_fifo && params->enable_dynamic_fifo) {
  83101. + DWC_DEBUGPL(DBG_CIL, "Total FIFO Size=%d\n",
  83102. + core_if->total_fifo_size);
  83103. + DWC_DEBUGPL(DBG_CIL, "Rx FIFO Size=%d\n",
  83104. + params->dev_rx_fifo_size);
  83105. + DWC_DEBUGPL(DBG_CIL, "NP Tx FIFO Size=%d\n",
  83106. + params->dev_nperio_tx_fifo_size);
  83107. +
  83108. + /* Rx FIFO */
  83109. + DWC_DEBUGPL(DBG_CIL, "initial grxfsiz=%08x\n",
  83110. + DWC_READ_REG32(&global_regs->grxfsiz));
  83111. +
  83112. +#ifdef DWC_UTE_CFI
  83113. + core_if->pwron_rxfsiz = DWC_READ_REG32(&global_regs->grxfsiz);
  83114. + core_if->init_rxfsiz = params->dev_rx_fifo_size;
  83115. +#endif
  83116. + rx_fifo_size = params->dev_rx_fifo_size;
  83117. + DWC_WRITE_REG32(&global_regs->grxfsiz, rx_fifo_size);
  83118. +
  83119. + DWC_DEBUGPL(DBG_CIL, "new grxfsiz=%08x\n",
  83120. + DWC_READ_REG32(&global_regs->grxfsiz));
  83121. +
  83122. + /** Set Periodic Tx FIFO Mask all bits 0 */
  83123. + core_if->p_tx_msk = 0;
  83124. +
  83125. + /** Set Tx FIFO Mask all bits 0 */
  83126. + core_if->tx_msk = 0;
  83127. +
  83128. + if (core_if->en_multiple_tx_fifo == 0) {
  83129. + /* Non-periodic Tx FIFO */
  83130. + DWC_DEBUGPL(DBG_CIL, "initial gnptxfsiz=%08x\n",
  83131. + DWC_READ_REG32(&global_regs->gnptxfsiz));
  83132. +
  83133. + nptxfifosize.b.depth = params->dev_nperio_tx_fifo_size;
  83134. + nptxfifosize.b.startaddr = params->dev_rx_fifo_size;
  83135. +
  83136. + DWC_WRITE_REG32(&global_regs->gnptxfsiz,
  83137. + nptxfifosize.d32);
  83138. +
  83139. + DWC_DEBUGPL(DBG_CIL, "new gnptxfsiz=%08x\n",
  83140. + DWC_READ_REG32(&global_regs->gnptxfsiz));
  83141. +
  83142. + /**@todo NGS: Fix Periodic FIFO Sizing! */
  83143. + /*
  83144. + * Periodic Tx FIFOs These FIFOs are numbered from 1 to 15.
  83145. + * Indexes of the FIFO size module parameters in the
  83146. + * dev_perio_tx_fifo_size array and the FIFO size registers in
  83147. + * the dptxfsiz array run from 0 to 14.
  83148. + */
  83149. + /** @todo Finish debug of this */
  83150. + ptxfifosize.b.startaddr =
  83151. + nptxfifosize.b.startaddr + nptxfifosize.b.depth;
  83152. + for (i = 0; i < core_if->hwcfg4.b.num_dev_perio_in_ep; i++) {
  83153. + ptxfifosize.b.depth =
  83154. + params->dev_perio_tx_fifo_size[i];
  83155. + DWC_DEBUGPL(DBG_CIL,
  83156. + "initial dtxfsiz[%d]=%08x\n", i,
  83157. + DWC_READ_REG32(&global_regs->dtxfsiz
  83158. + [i]));
  83159. + DWC_WRITE_REG32(&global_regs->dtxfsiz[i],
  83160. + ptxfifosize.d32);
  83161. + DWC_DEBUGPL(DBG_CIL, "new dtxfsiz[%d]=%08x\n",
  83162. + i,
  83163. + DWC_READ_REG32(&global_regs->dtxfsiz
  83164. + [i]));
  83165. + ptxfifosize.b.startaddr += ptxfifosize.b.depth;
  83166. + }
  83167. + } else {
  83168. + /*
  83169. + * Tx FIFOs These FIFOs are numbered from 1 to 15.
  83170. + * Indexes of the FIFO size module parameters in the
  83171. + * dev_tx_fifo_size array and the FIFO size registers in
  83172. + * the dtxfsiz array run from 0 to 14.
  83173. + */
  83174. +
  83175. + /* Non-periodic Tx FIFO */
  83176. + DWC_DEBUGPL(DBG_CIL, "initial gnptxfsiz=%08x\n",
  83177. + DWC_READ_REG32(&global_regs->gnptxfsiz));
  83178. +
  83179. +#ifdef DWC_UTE_CFI
  83180. + core_if->pwron_gnptxfsiz =
  83181. + (DWC_READ_REG32(&global_regs->gnptxfsiz) >> 16);
  83182. + core_if->init_gnptxfsiz =
  83183. + params->dev_nperio_tx_fifo_size;
  83184. +#endif
  83185. + nptxfifosize.b.depth = params->dev_nperio_tx_fifo_size;
  83186. + nptxfifosize.b.startaddr = params->dev_rx_fifo_size;
  83187. +
  83188. + DWC_WRITE_REG32(&global_regs->gnptxfsiz,
  83189. + nptxfifosize.d32);
  83190. +
  83191. + DWC_DEBUGPL(DBG_CIL, "new gnptxfsiz=%08x\n",
  83192. + DWC_READ_REG32(&global_regs->gnptxfsiz));
  83193. +
  83194. + txfifosize.b.startaddr =
  83195. + nptxfifosize.b.startaddr + nptxfifosize.b.depth;
  83196. +
  83197. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  83198. +
  83199. + txfifosize.b.depth =
  83200. + params->dev_tx_fifo_size[i];
  83201. +
  83202. + DWC_DEBUGPL(DBG_CIL,
  83203. + "initial dtxfsiz[%d]=%08x\n",
  83204. + i,
  83205. + DWC_READ_REG32(&global_regs->dtxfsiz
  83206. + [i]));
  83207. +
  83208. +#ifdef DWC_UTE_CFI
  83209. + core_if->pwron_txfsiz[i] =
  83210. + (DWC_READ_REG32
  83211. + (&global_regs->dtxfsiz[i]) >> 16);
  83212. + core_if->init_txfsiz[i] =
  83213. + params->dev_tx_fifo_size[i];
  83214. +#endif
  83215. + DWC_WRITE_REG32(&global_regs->dtxfsiz[i],
  83216. + txfifosize.d32);
  83217. +
  83218. + DWC_DEBUGPL(DBG_CIL,
  83219. + "new dtxfsiz[%d]=%08x\n",
  83220. + i,
  83221. + DWC_READ_REG32(&global_regs->dtxfsiz
  83222. + [i]));
  83223. +
  83224. + txfifosize.b.startaddr += txfifosize.b.depth;
  83225. + }
  83226. + if (core_if->snpsid <= OTG_CORE_REV_2_94a) {
  83227. + /* Calculating DFIFOCFG for Device mode to include RxFIFO and NPTXFIFO */
  83228. + gdfifocfg.d32 = DWC_READ_REG32(&global_regs->gdfifocfg);
  83229. + hwcfg3.d32 = DWC_READ_REG32(&global_regs->ghwcfg3);
  83230. + gdfifocfg.b.gdfifocfg = (DWC_READ_REG32(&global_regs->ghwcfg3) >> 16);
  83231. + DWC_WRITE_REG32(&global_regs->gdfifocfg, gdfifocfg.d32);
  83232. + rxfsiz = (DWC_READ_REG32(&global_regs->grxfsiz) & 0x0000ffff);
  83233. + nptxfsiz = (DWC_READ_REG32(&global_regs->gnptxfsiz) >> 16);
  83234. + gdfifocfg.b.epinfobase = rxfsiz + nptxfsiz;
  83235. + DWC_WRITE_REG32(&global_regs->gdfifocfg, gdfifocfg.d32);
  83236. + }
  83237. + }
  83238. +
  83239. + /* Flush the FIFOs */
  83240. + dwc_otg_flush_tx_fifo(core_if, 0x10); /* all Tx FIFOs */
  83241. + dwc_otg_flush_rx_fifo(core_if);
  83242. +
  83243. + /* Flush the Learning Queue. */
  83244. + resetctl.b.intknqflsh = 1;
  83245. + DWC_WRITE_REG32(&core_if->core_global_regs->grstctl, resetctl.d32);
  83246. +
  83247. + if (!core_if->core_params->en_multiple_tx_fifo && core_if->dma_enable) {
  83248. + core_if->start_predict = 0;
  83249. + for (i = 0; i<= core_if->dev_if->num_in_eps; ++i) {
  83250. + core_if->nextep_seq[i] = 0xff; // 0xff - EP not active
  83251. + }
  83252. + core_if->nextep_seq[0] = 0;
  83253. + core_if->first_in_nextep_seq = 0;
  83254. + diepctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[0]->diepctl);
  83255. + diepctl.b.nextep = 0;
  83256. + DWC_WRITE_REG32(&dev_if->in_ep_regs[0]->diepctl, diepctl.d32);
  83257. +
  83258. + /* Update IN Endpoint Mismatch Count by active IN NP EP count + 1 */
  83259. + dcfg.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dcfg);
  83260. + dcfg.b.epmscnt = 2;
  83261. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dcfg, dcfg.d32);
  83262. +
  83263. + DWC_DEBUGPL(DBG_CILV,"%s first_in_nextep_seq= %2d; nextep_seq[]:\n",
  83264. + __func__, core_if->first_in_nextep_seq);
  83265. + for (i=0; i <= core_if->dev_if->num_in_eps; i++) {
  83266. + DWC_DEBUGPL(DBG_CILV, "%2d ", core_if->nextep_seq[i]);
  83267. + }
  83268. + DWC_DEBUGPL(DBG_CILV,"\n");
  83269. + }
  83270. +
  83271. + /* Clear all pending Device Interrupts */
  83272. + /** @todo - if the condition needed to be checked
  83273. + * or in any case all pending interrutps should be cleared?
  83274. + */
  83275. + if (core_if->multiproc_int_enable) {
  83276. + for (i = 0; i < core_if->dev_if->num_in_eps; ++i) {
  83277. + DWC_WRITE_REG32(&dev_if->
  83278. + dev_global_regs->diepeachintmsk[i], 0);
  83279. + }
  83280. + }
  83281. +
  83282. + for (i = 0; i < core_if->dev_if->num_out_eps; ++i) {
  83283. + DWC_WRITE_REG32(&dev_if->
  83284. + dev_global_regs->doepeachintmsk[i], 0);
  83285. + }
  83286. +
  83287. + DWC_WRITE_REG32(&dev_if->dev_global_regs->deachint, 0xFFFFFFFF);
  83288. + DWC_WRITE_REG32(&dev_if->dev_global_regs->deachintmsk, 0);
  83289. + } else {
  83290. + DWC_WRITE_REG32(&dev_if->dev_global_regs->diepmsk, 0);
  83291. + DWC_WRITE_REG32(&dev_if->dev_global_regs->doepmsk, 0);
  83292. + DWC_WRITE_REG32(&dev_if->dev_global_regs->daint, 0xFFFFFFFF);
  83293. + DWC_WRITE_REG32(&dev_if->dev_global_regs->daintmsk, 0);
  83294. + }
  83295. +
  83296. + for (i = 0; i <= dev_if->num_in_eps; i++) {
  83297. + depctl_data_t depctl;
  83298. + depctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  83299. + if (depctl.b.epena) {
  83300. + depctl.d32 = 0;
  83301. + depctl.b.epdis = 1;
  83302. + depctl.b.snak = 1;
  83303. + } else {
  83304. + depctl.d32 = 0;
  83305. + }
  83306. +
  83307. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepctl, depctl.d32);
  83308. +
  83309. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->dieptsiz, 0);
  83310. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepdma, 0);
  83311. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepint, 0xFF);
  83312. + }
  83313. +
  83314. + for (i = 0; i <= dev_if->num_out_eps; i++) {
  83315. + depctl_data_t depctl;
  83316. + depctl.d32 = DWC_READ_REG32(&dev_if->out_ep_regs[i]->doepctl);
  83317. + if (depctl.b.epena) {
  83318. + dctl_data_t dctl = {.d32 = 0 };
  83319. + gintmsk_data_t gintsts = {.d32 = 0 };
  83320. + doepint_data_t doepint = {.d32 = 0 };
  83321. + dctl.b.sgoutnak = 1;
  83322. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0, dctl.d32);
  83323. + do {
  83324. + dwc_udelay(10);
  83325. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  83326. + } while (!gintsts.b.goutnakeff);
  83327. + gintsts.d32 = 0;
  83328. + gintsts.b.goutnakeff = 1;
  83329. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  83330. +
  83331. + depctl.d32 = 0;
  83332. + depctl.b.epdis = 1;
  83333. + depctl.b.snak = 1;
  83334. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[i]->doepctl, depctl.d32);
  83335. + do {
  83336. + dwc_udelay(10);
  83337. + doepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  83338. + out_ep_regs[i]->doepint);
  83339. + } while (!doepint.b.epdisabled);
  83340. +
  83341. + doepint.b.epdisabled = 1;
  83342. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[i]->doepint, doepint.d32);
  83343. +
  83344. + dctl.d32 = 0;
  83345. + dctl.b.cgoutnak = 1;
  83346. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0, dctl.d32);
  83347. + } else {
  83348. + depctl.d32 = 0;
  83349. + }
  83350. +
  83351. + DWC_WRITE_REG32(&dev_if->out_ep_regs[i]->doepctl, depctl.d32);
  83352. +
  83353. + DWC_WRITE_REG32(&dev_if->out_ep_regs[i]->doeptsiz, 0);
  83354. + DWC_WRITE_REG32(&dev_if->out_ep_regs[i]->doepdma, 0);
  83355. + DWC_WRITE_REG32(&dev_if->out_ep_regs[i]->doepint, 0xFF);
  83356. + }
  83357. +
  83358. + if (core_if->en_multiple_tx_fifo && core_if->dma_enable) {
  83359. + dev_if->non_iso_tx_thr_en = params->thr_ctl & 0x1;
  83360. + dev_if->iso_tx_thr_en = (params->thr_ctl >> 1) & 0x1;
  83361. + dev_if->rx_thr_en = (params->thr_ctl >> 2) & 0x1;
  83362. +
  83363. + dev_if->rx_thr_length = params->rx_thr_length;
  83364. + dev_if->tx_thr_length = params->tx_thr_length;
  83365. +
  83366. + dev_if->setup_desc_index = 0;
  83367. +
  83368. + dthrctl.d32 = 0;
  83369. + dthrctl.b.non_iso_thr_en = dev_if->non_iso_tx_thr_en;
  83370. + dthrctl.b.iso_thr_en = dev_if->iso_tx_thr_en;
  83371. + dthrctl.b.tx_thr_len = dev_if->tx_thr_length;
  83372. + dthrctl.b.rx_thr_en = dev_if->rx_thr_en;
  83373. + dthrctl.b.rx_thr_len = dev_if->rx_thr_length;
  83374. + dthrctl.b.ahb_thr_ratio = params->ahb_thr_ratio;
  83375. +
  83376. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dtknqr3_dthrctl,
  83377. + dthrctl.d32);
  83378. +
  83379. + DWC_DEBUGPL(DBG_CIL,
  83380. + "Non ISO Tx Thr - %d\nISO Tx Thr - %d\nRx Thr - %d\nTx Thr Len - %d\nRx Thr Len - %d\n",
  83381. + dthrctl.b.non_iso_thr_en, dthrctl.b.iso_thr_en,
  83382. + dthrctl.b.rx_thr_en, dthrctl.b.tx_thr_len,
  83383. + dthrctl.b.rx_thr_len);
  83384. +
  83385. + }
  83386. +
  83387. + dwc_otg_enable_device_interrupts(core_if);
  83388. +
  83389. + {
  83390. + diepmsk_data_t msk = {.d32 = 0 };
  83391. + msk.b.txfifoundrn = 1;
  83392. + if (core_if->multiproc_int_enable) {
  83393. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->
  83394. + diepeachintmsk[0], msk.d32, msk.d32);
  83395. + } else {
  83396. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->diepmsk,
  83397. + msk.d32, msk.d32);
  83398. + }
  83399. + }
  83400. +
  83401. + if (core_if->multiproc_int_enable) {
  83402. + /* Set NAK on Babble */
  83403. + dctl_data_t dctl = {.d32 = 0 };
  83404. + dctl.b.nakonbble = 1;
  83405. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dctl, 0, dctl.d32);
  83406. + }
  83407. +
  83408. + if (core_if->snpsid >= OTG_CORE_REV_2_94a) {
  83409. + dctl_data_t dctl = {.d32 = 0 };
  83410. + dctl.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dctl);
  83411. + dctl.b.sftdiscon = 0;
  83412. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dctl, dctl.d32);
  83413. + }
  83414. +}
  83415. +
  83416. +/**
  83417. + * This function enables the Host mode interrupts.
  83418. + *
  83419. + * @param core_if Programming view of DWC_otg controller
  83420. + */
  83421. +void dwc_otg_enable_host_interrupts(dwc_otg_core_if_t * core_if)
  83422. +{
  83423. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  83424. + gintmsk_data_t intr_mask = {.d32 = 0 };
  83425. +
  83426. + DWC_DEBUGPL(DBG_CIL, "%s(%p)\n", __func__, core_if);
  83427. +
  83428. + /* Disable all interrupts. */
  83429. + DWC_WRITE_REG32(&global_regs->gintmsk, 0);
  83430. +
  83431. + /* Clear any pending interrupts. */
  83432. + DWC_WRITE_REG32(&global_regs->gintsts, 0xFFFFFFFF);
  83433. +
  83434. + /* Enable the common interrupts */
  83435. + dwc_otg_enable_common_interrupts(core_if);
  83436. +
  83437. + /*
  83438. + * Enable host mode interrupts without disturbing common
  83439. + * interrupts.
  83440. + */
  83441. +
  83442. + intr_mask.b.disconnect = 1;
  83443. + intr_mask.b.portintr = 1;
  83444. + intr_mask.b.hcintr = 1;
  83445. +
  83446. + DWC_MODIFY_REG32(&global_regs->gintmsk, intr_mask.d32, intr_mask.d32);
  83447. +}
  83448. +
  83449. +/**
  83450. + * This function disables the Host Mode interrupts.
  83451. + *
  83452. + * @param core_if Programming view of DWC_otg controller
  83453. + */
  83454. +void dwc_otg_disable_host_interrupts(dwc_otg_core_if_t * core_if)
  83455. +{
  83456. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  83457. + gintmsk_data_t intr_mask = {.d32 = 0 };
  83458. +
  83459. + DWC_DEBUGPL(DBG_CILV, "%s()\n", __func__);
  83460. +
  83461. + /*
  83462. + * Disable host mode interrupts without disturbing common
  83463. + * interrupts.
  83464. + */
  83465. + intr_mask.b.sofintr = 1;
  83466. + intr_mask.b.portintr = 1;
  83467. + intr_mask.b.hcintr = 1;
  83468. + intr_mask.b.ptxfempty = 1;
  83469. + intr_mask.b.nptxfempty = 1;
  83470. +
  83471. + DWC_MODIFY_REG32(&global_regs->gintmsk, intr_mask.d32, 0);
  83472. +}
  83473. +
  83474. +/**
  83475. + * This function initializes the DWC_otg controller registers for
  83476. + * host mode.
  83477. + *
  83478. + * This function flushes the Tx and Rx FIFOs and it flushes any entries in the
  83479. + * request queues. Host channels are reset to ensure that they are ready for
  83480. + * performing transfers.
  83481. + *
  83482. + * @param core_if Programming view of DWC_otg controller
  83483. + *
  83484. + */
  83485. +void dwc_otg_core_host_init(dwc_otg_core_if_t * core_if)
  83486. +{
  83487. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  83488. + dwc_otg_host_if_t *host_if = core_if->host_if;
  83489. + dwc_otg_core_params_t *params = core_if->core_params;
  83490. + hprt0_data_t hprt0 = {.d32 = 0 };
  83491. + fifosize_data_t nptxfifosize;
  83492. + fifosize_data_t ptxfifosize;
  83493. + uint16_t rxfsiz, nptxfsiz, hptxfsiz;
  83494. + gdfifocfg_data_t gdfifocfg = {.d32 = 0 };
  83495. + int i;
  83496. + hcchar_data_t hcchar;
  83497. + hcfg_data_t hcfg;
  83498. + hfir_data_t hfir;
  83499. + dwc_otg_hc_regs_t *hc_regs;
  83500. + int num_channels;
  83501. + gotgctl_data_t gotgctl = {.d32 = 0 };
  83502. +
  83503. + DWC_DEBUGPL(DBG_CILV, "%s(%p)\n", __func__, core_if);
  83504. +
  83505. + /* Restart the Phy Clock */
  83506. + DWC_WRITE_REG32(core_if->pcgcctl, 0);
  83507. +
  83508. + /* Initialize Host Configuration Register */
  83509. + init_fslspclksel(core_if);
  83510. + if (core_if->core_params->speed == DWC_SPEED_PARAM_FULL) {
  83511. + hcfg.d32 = DWC_READ_REG32(&host_if->host_global_regs->hcfg);
  83512. + hcfg.b.fslssupp = 1;
  83513. + DWC_WRITE_REG32(&host_if->host_global_regs->hcfg, hcfg.d32);
  83514. +
  83515. + }
  83516. +
  83517. + /* This bit allows dynamic reloading of the HFIR register
  83518. + * during runtime. This bit needs to be programmed during
  83519. + * initial configuration and its value must not be changed
  83520. + * during runtime.*/
  83521. + if (core_if->core_params->reload_ctl == 1) {
  83522. + hfir.d32 = DWC_READ_REG32(&host_if->host_global_regs->hfir);
  83523. + hfir.b.hfirrldctrl = 1;
  83524. + DWC_WRITE_REG32(&host_if->host_global_regs->hfir, hfir.d32);
  83525. + }
  83526. +
  83527. + if (core_if->core_params->dma_desc_enable) {
  83528. + uint8_t op_mode = core_if->hwcfg2.b.op_mode;
  83529. + if (!
  83530. + (core_if->hwcfg4.b.desc_dma
  83531. + && (core_if->snpsid >= OTG_CORE_REV_2_90a)
  83532. + && ((op_mode == DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG)
  83533. + || (op_mode == DWC_HWCFG2_OP_MODE_SRP_ONLY_CAPABLE_OTG)
  83534. + || (op_mode ==
  83535. + DWC_HWCFG2_OP_MODE_NO_HNP_SRP_CAPABLE_OTG)
  83536. + || (op_mode == DWC_HWCFG2_OP_MODE_SRP_CAPABLE_HOST)
  83537. + || (op_mode ==
  83538. + DWC_HWCFG2_OP_MODE_NO_SRP_CAPABLE_HOST)))) {
  83539. +
  83540. + DWC_ERROR("Host can't operate in Descriptor DMA mode.\n"
  83541. + "Either core version is below 2.90a or "
  83542. + "GHWCFG2, GHWCFG4 registers' values do not allow Descriptor DMA in host mode.\n"
  83543. + "To run the driver in Buffer DMA host mode set dma_desc_enable "
  83544. + "module parameter to 0.\n");
  83545. + return;
  83546. + }
  83547. + hcfg.d32 = DWC_READ_REG32(&host_if->host_global_regs->hcfg);
  83548. + hcfg.b.descdma = 1;
  83549. + DWC_WRITE_REG32(&host_if->host_global_regs->hcfg, hcfg.d32);
  83550. + }
  83551. +
  83552. + /* Configure data FIFO sizes */
  83553. + if (core_if->hwcfg2.b.dynamic_fifo && params->enable_dynamic_fifo) {
  83554. + DWC_DEBUGPL(DBG_CIL, "Total FIFO Size=%d\n",
  83555. + core_if->total_fifo_size);
  83556. + DWC_DEBUGPL(DBG_CIL, "Rx FIFO Size=%d\n",
  83557. + params->host_rx_fifo_size);
  83558. + DWC_DEBUGPL(DBG_CIL, "NP Tx FIFO Size=%d\n",
  83559. + params->host_nperio_tx_fifo_size);
  83560. + DWC_DEBUGPL(DBG_CIL, "P Tx FIFO Size=%d\n",
  83561. + params->host_perio_tx_fifo_size);
  83562. +
  83563. + /* Rx FIFO */
  83564. + DWC_DEBUGPL(DBG_CIL, "initial grxfsiz=%08x\n",
  83565. + DWC_READ_REG32(&global_regs->grxfsiz));
  83566. + DWC_WRITE_REG32(&global_regs->grxfsiz,
  83567. + params->host_rx_fifo_size);
  83568. + DWC_DEBUGPL(DBG_CIL, "new grxfsiz=%08x\n",
  83569. + DWC_READ_REG32(&global_regs->grxfsiz));
  83570. +
  83571. + /* Non-periodic Tx FIFO */
  83572. + DWC_DEBUGPL(DBG_CIL, "initial gnptxfsiz=%08x\n",
  83573. + DWC_READ_REG32(&global_regs->gnptxfsiz));
  83574. + nptxfifosize.b.depth = params->host_nperio_tx_fifo_size;
  83575. + nptxfifosize.b.startaddr = params->host_rx_fifo_size;
  83576. + DWC_WRITE_REG32(&global_regs->gnptxfsiz, nptxfifosize.d32);
  83577. + DWC_DEBUGPL(DBG_CIL, "new gnptxfsiz=%08x\n",
  83578. + DWC_READ_REG32(&global_regs->gnptxfsiz));
  83579. +
  83580. + /* Periodic Tx FIFO */
  83581. + DWC_DEBUGPL(DBG_CIL, "initial hptxfsiz=%08x\n",
  83582. + DWC_READ_REG32(&global_regs->hptxfsiz));
  83583. + ptxfifosize.b.depth = params->host_perio_tx_fifo_size;
  83584. + ptxfifosize.b.startaddr =
  83585. + nptxfifosize.b.startaddr + nptxfifosize.b.depth;
  83586. + DWC_WRITE_REG32(&global_regs->hptxfsiz, ptxfifosize.d32);
  83587. + DWC_DEBUGPL(DBG_CIL, "new hptxfsiz=%08x\n",
  83588. + DWC_READ_REG32(&global_regs->hptxfsiz));
  83589. +
  83590. + if (core_if->en_multiple_tx_fifo
  83591. + && core_if->snpsid <= OTG_CORE_REV_2_94a) {
  83592. + /* Global DFIFOCFG calculation for Host mode - include RxFIFO, NPTXFIFO and HPTXFIFO */
  83593. + gdfifocfg.d32 = DWC_READ_REG32(&global_regs->gdfifocfg);
  83594. + rxfsiz = (DWC_READ_REG32(&global_regs->grxfsiz) & 0x0000ffff);
  83595. + nptxfsiz = (DWC_READ_REG32(&global_regs->gnptxfsiz) >> 16);
  83596. + hptxfsiz = (DWC_READ_REG32(&global_regs->hptxfsiz) >> 16);
  83597. + gdfifocfg.b.epinfobase = rxfsiz + nptxfsiz + hptxfsiz;
  83598. + DWC_WRITE_REG32(&global_regs->gdfifocfg, gdfifocfg.d32);
  83599. + }
  83600. + }
  83601. +
  83602. + /* TODO - check this */
  83603. + /* Clear Host Set HNP Enable in the OTG Control Register */
  83604. + gotgctl.b.hstsethnpen = 1;
  83605. + DWC_MODIFY_REG32(&global_regs->gotgctl, gotgctl.d32, 0);
  83606. + /* Make sure the FIFOs are flushed. */
  83607. + dwc_otg_flush_tx_fifo(core_if, 0x10 /* all TX FIFOs */ );
  83608. + dwc_otg_flush_rx_fifo(core_if);
  83609. +
  83610. + /* Clear Host Set HNP Enable in the OTG Control Register */
  83611. + gotgctl.b.hstsethnpen = 1;
  83612. + DWC_MODIFY_REG32(&global_regs->gotgctl, gotgctl.d32, 0);
  83613. +
  83614. + if (!core_if->core_params->dma_desc_enable) {
  83615. + /* Flush out any leftover queued requests. */
  83616. + num_channels = core_if->core_params->host_channels;
  83617. +
  83618. + for (i = 0; i < num_channels; i++) {
  83619. + hc_regs = core_if->host_if->hc_regs[i];
  83620. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  83621. + hcchar.b.chen = 0;
  83622. + hcchar.b.chdis = 1;
  83623. + hcchar.b.epdir = 0;
  83624. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  83625. + }
  83626. +
  83627. + /* Halt all channels to put them into a known state. */
  83628. + for (i = 0; i < num_channels; i++) {
  83629. + int count = 0;
  83630. + hc_regs = core_if->host_if->hc_regs[i];
  83631. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  83632. + hcchar.b.chen = 1;
  83633. + hcchar.b.chdis = 1;
  83634. + hcchar.b.epdir = 0;
  83635. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  83636. + DWC_DEBUGPL(DBG_HCDV, "%s: Halt channel %d regs %p\n", __func__, i, hc_regs);
  83637. + do {
  83638. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  83639. + if (++count > 1000) {
  83640. + DWC_ERROR
  83641. + ("%s: Unable to clear halt on channel %d (timeout HCCHAR 0x%X @%p)\n",
  83642. + __func__, i, hcchar.d32, &hc_regs->hcchar);
  83643. + break;
  83644. + }
  83645. + dwc_udelay(1);
  83646. + } while (hcchar.b.chen);
  83647. + }
  83648. + }
  83649. +
  83650. + /* Turn on the vbus power. */
  83651. + DWC_PRINTF("Init: Port Power? op_state=%d\n", core_if->op_state);
  83652. + if (core_if->op_state == A_HOST) {
  83653. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  83654. + DWC_PRINTF("Init: Power Port (%d)\n", hprt0.b.prtpwr);
  83655. + if (hprt0.b.prtpwr == 0) {
  83656. + hprt0.b.prtpwr = 1;
  83657. + DWC_WRITE_REG32(host_if->hprt0, hprt0.d32);
  83658. + }
  83659. + }
  83660. +
  83661. + dwc_otg_enable_host_interrupts(core_if);
  83662. +}
  83663. +
  83664. +/**
  83665. + * Prepares a host channel for transferring packets to/from a specific
  83666. + * endpoint. The HCCHARn register is set up with the characteristics specified
  83667. + * in _hc. Host channel interrupts that may need to be serviced while this
  83668. + * transfer is in progress are enabled.
  83669. + *
  83670. + * @param core_if Programming view of DWC_otg controller
  83671. + * @param hc Information needed to initialize the host channel
  83672. + */
  83673. +void dwc_otg_hc_init(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  83674. +{
  83675. + hcintmsk_data_t hc_intr_mask;
  83676. + hcchar_data_t hcchar;
  83677. + hcsplt_data_t hcsplt;
  83678. +
  83679. + uint8_t hc_num = hc->hc_num;
  83680. + dwc_otg_host_if_t *host_if = core_if->host_if;
  83681. + dwc_otg_hc_regs_t *hc_regs = host_if->hc_regs[hc_num];
  83682. +
  83683. + /* Clear old interrupt conditions for this host channel. */
  83684. + hc_intr_mask.d32 = 0xFFFFFFFF;
  83685. + hc_intr_mask.b.reserved14_31 = 0;
  83686. + DWC_WRITE_REG32(&hc_regs->hcint, hc_intr_mask.d32);
  83687. +
  83688. + /* Enable channel interrupts required for this transfer. */
  83689. + hc_intr_mask.d32 = 0;
  83690. + hc_intr_mask.b.chhltd = 1;
  83691. + if (core_if->dma_enable) {
  83692. + /* For Descriptor DMA mode core halts the channel on AHB error. Interrupt is not required */
  83693. + if (!core_if->dma_desc_enable)
  83694. + hc_intr_mask.b.ahberr = 1;
  83695. + else {
  83696. + if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC)
  83697. + hc_intr_mask.b.xfercompl = 1;
  83698. + }
  83699. +
  83700. + if (hc->error_state && !hc->do_split &&
  83701. + hc->ep_type != DWC_OTG_EP_TYPE_ISOC) {
  83702. + hc_intr_mask.b.ack = 1;
  83703. + if (hc->ep_is_in) {
  83704. + hc_intr_mask.b.datatglerr = 1;
  83705. + if (hc->ep_type != DWC_OTG_EP_TYPE_INTR) {
  83706. + hc_intr_mask.b.nak = 1;
  83707. + }
  83708. + }
  83709. + }
  83710. + } else {
  83711. + switch (hc->ep_type) {
  83712. + case DWC_OTG_EP_TYPE_CONTROL:
  83713. + case DWC_OTG_EP_TYPE_BULK:
  83714. + hc_intr_mask.b.xfercompl = 1;
  83715. + hc_intr_mask.b.stall = 1;
  83716. + hc_intr_mask.b.xacterr = 1;
  83717. + hc_intr_mask.b.datatglerr = 1;
  83718. + if (hc->ep_is_in) {
  83719. + hc_intr_mask.b.bblerr = 1;
  83720. + } else {
  83721. + hc_intr_mask.b.nak = 1;
  83722. + hc_intr_mask.b.nyet = 1;
  83723. + if (hc->do_ping) {
  83724. + hc_intr_mask.b.ack = 1;
  83725. + }
  83726. + }
  83727. +
  83728. + if (hc->do_split) {
  83729. + hc_intr_mask.b.nak = 1;
  83730. + if (hc->complete_split) {
  83731. + hc_intr_mask.b.nyet = 1;
  83732. + } else {
  83733. + hc_intr_mask.b.ack = 1;
  83734. + }
  83735. + }
  83736. +
  83737. + if (hc->error_state) {
  83738. + hc_intr_mask.b.ack = 1;
  83739. + }
  83740. + break;
  83741. + case DWC_OTG_EP_TYPE_INTR:
  83742. + hc_intr_mask.b.xfercompl = 1;
  83743. + hc_intr_mask.b.nak = 1;
  83744. + hc_intr_mask.b.stall = 1;
  83745. + hc_intr_mask.b.xacterr = 1;
  83746. + hc_intr_mask.b.datatglerr = 1;
  83747. + hc_intr_mask.b.frmovrun = 1;
  83748. +
  83749. + if (hc->ep_is_in) {
  83750. + hc_intr_mask.b.bblerr = 1;
  83751. + }
  83752. + if (hc->error_state) {
  83753. + hc_intr_mask.b.ack = 1;
  83754. + }
  83755. + if (hc->do_split) {
  83756. + if (hc->complete_split) {
  83757. + hc_intr_mask.b.nyet = 1;
  83758. + } else {
  83759. + hc_intr_mask.b.ack = 1;
  83760. + }
  83761. + }
  83762. + break;
  83763. + case DWC_OTG_EP_TYPE_ISOC:
  83764. + hc_intr_mask.b.xfercompl = 1;
  83765. + hc_intr_mask.b.frmovrun = 1;
  83766. + hc_intr_mask.b.ack = 1;
  83767. +
  83768. + if (hc->ep_is_in) {
  83769. + hc_intr_mask.b.xacterr = 1;
  83770. + hc_intr_mask.b.bblerr = 1;
  83771. + }
  83772. + break;
  83773. + }
  83774. + }
  83775. + DWC_WRITE_REG32(&hc_regs->hcintmsk, hc_intr_mask.d32);
  83776. +
  83777. + /*
  83778. + * Program the HCCHARn register with the endpoint characteristics for
  83779. + * the current transfer.
  83780. + */
  83781. + hcchar.d32 = 0;
  83782. + hcchar.b.devaddr = hc->dev_addr;
  83783. + hcchar.b.epnum = hc->ep_num;
  83784. + hcchar.b.epdir = hc->ep_is_in;
  83785. + hcchar.b.lspddev = (hc->speed == DWC_OTG_EP_SPEED_LOW);
  83786. + hcchar.b.eptype = hc->ep_type;
  83787. + hcchar.b.mps = hc->max_packet;
  83788. +
  83789. + DWC_WRITE_REG32(&host_if->hc_regs[hc_num]->hcchar, hcchar.d32);
  83790. +
  83791. + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d, Dev Addr %d, EP #%d\n",
  83792. + __func__, hc->hc_num, hcchar.b.devaddr, hcchar.b.epnum);
  83793. + DWC_DEBUGPL(DBG_HCDV, " Is In %d, Is Low Speed %d, EP Type %d, "
  83794. + "Max Pkt %d, Multi Cnt %d\n",
  83795. + hcchar.b.epdir, hcchar.b.lspddev, hcchar.b.eptype,
  83796. + hcchar.b.mps, hcchar.b.multicnt);
  83797. +
  83798. + /*
  83799. + * Program the HCSPLIT register for SPLITs
  83800. + */
  83801. + hcsplt.d32 = 0;
  83802. + if (hc->do_split) {
  83803. + DWC_DEBUGPL(DBG_HCDV, "Programming HC %d with split --> %s\n",
  83804. + hc->hc_num,
  83805. + hc->complete_split ? "CSPLIT" : "SSPLIT");
  83806. + hcsplt.b.compsplt = hc->complete_split;
  83807. + hcsplt.b.xactpos = hc->xact_pos;
  83808. + hcsplt.b.hubaddr = hc->hub_addr;
  83809. + hcsplt.b.prtaddr = hc->port_addr;
  83810. + DWC_DEBUGPL(DBG_HCDV, "\t comp split %d\n", hc->complete_split);
  83811. + DWC_DEBUGPL(DBG_HCDV, "\t xact pos %d\n", hc->xact_pos);
  83812. + DWC_DEBUGPL(DBG_HCDV, "\t hub addr %d\n", hc->hub_addr);
  83813. + DWC_DEBUGPL(DBG_HCDV, "\t port addr %d\n", hc->port_addr);
  83814. + DWC_DEBUGPL(DBG_HCDV, "\t is_in %d\n", hc->ep_is_in);
  83815. + DWC_DEBUGPL(DBG_HCDV, "\t Max Pkt: %d\n", hcchar.b.mps);
  83816. + DWC_DEBUGPL(DBG_HCDV, "\t xferlen: %d\n", hc->xfer_len);
  83817. + }
  83818. + DWC_WRITE_REG32(&host_if->hc_regs[hc_num]->hcsplt, hcsplt.d32);
  83819. +
  83820. +}
  83821. +
  83822. +/**
  83823. + * Attempts to halt a host channel. This function should only be called in
  83824. + * Slave mode or to abort a transfer in either Slave mode or DMA mode. Under
  83825. + * normal circumstances in DMA mode, the controller halts the channel when the
  83826. + * transfer is complete or a condition occurs that requires application
  83827. + * intervention.
  83828. + *
  83829. + * In slave mode, checks for a free request queue entry, then sets the Channel
  83830. + * Enable and Channel Disable bits of the Host Channel Characteristics
  83831. + * register of the specified channel to intiate the halt. If there is no free
  83832. + * request queue entry, sets only the Channel Disable bit of the HCCHARn
  83833. + * register to flush requests for this channel. In the latter case, sets a
  83834. + * flag to indicate that the host channel needs to be halted when a request
  83835. + * queue slot is open.
  83836. + *
  83837. + * In DMA mode, always sets the Channel Enable and Channel Disable bits of the
  83838. + * HCCHARn register. The controller ensures there is space in the request
  83839. + * queue before submitting the halt request.
  83840. + *
  83841. + * Some time may elapse before the core flushes any posted requests for this
  83842. + * host channel and halts. The Channel Halted interrupt handler completes the
  83843. + * deactivation of the host channel.
  83844. + *
  83845. + * @param core_if Controller register interface.
  83846. + * @param hc Host channel to halt.
  83847. + * @param halt_status Reason for halting the channel.
  83848. + */
  83849. +void dwc_otg_hc_halt(dwc_otg_core_if_t * core_if,
  83850. + dwc_hc_t * hc, dwc_otg_halt_status_e halt_status)
  83851. +{
  83852. + gnptxsts_data_t nptxsts;
  83853. + hptxsts_data_t hptxsts;
  83854. + hcchar_data_t hcchar;
  83855. + dwc_otg_hc_regs_t *hc_regs;
  83856. + dwc_otg_core_global_regs_t *global_regs;
  83857. + dwc_otg_host_global_regs_t *host_global_regs;
  83858. +
  83859. + hc_regs = core_if->host_if->hc_regs[hc->hc_num];
  83860. + global_regs = core_if->core_global_regs;
  83861. + host_global_regs = core_if->host_if->host_global_regs;
  83862. +
  83863. + DWC_ASSERT(!(halt_status == DWC_OTG_HC_XFER_NO_HALT_STATUS),
  83864. + "halt_status = %d\n", halt_status);
  83865. +
  83866. + if (halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE ||
  83867. + halt_status == DWC_OTG_HC_XFER_AHB_ERR) {
  83868. + /*
  83869. + * Disable all channel interrupts except Ch Halted. The QTD
  83870. + * and QH state associated with this transfer has been cleared
  83871. + * (in the case of URB_DEQUEUE), so the channel needs to be
  83872. + * shut down carefully to prevent crashes.
  83873. + */
  83874. + hcintmsk_data_t hcintmsk;
  83875. + hcintmsk.d32 = 0;
  83876. + hcintmsk.b.chhltd = 1;
  83877. + DWC_WRITE_REG32(&hc_regs->hcintmsk, hcintmsk.d32);
  83878. +
  83879. + /*
  83880. + * Make sure no other interrupts besides halt are currently
  83881. + * pending. Handling another interrupt could cause a crash due
  83882. + * to the QTD and QH state.
  83883. + */
  83884. + DWC_WRITE_REG32(&hc_regs->hcint, ~hcintmsk.d32);
  83885. +
  83886. + /*
  83887. + * Make sure the halt status is set to URB_DEQUEUE or AHB_ERR
  83888. + * even if the channel was already halted for some other
  83889. + * reason.
  83890. + */
  83891. + hc->halt_status = halt_status;
  83892. +
  83893. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  83894. + if (hcchar.b.chen == 0) {
  83895. + /*
  83896. + * The channel is either already halted or it hasn't
  83897. + * started yet. In DMA mode, the transfer may halt if
  83898. + * it finishes normally or a condition occurs that
  83899. + * requires driver intervention. Don't want to halt
  83900. + * the channel again. In either Slave or DMA mode,
  83901. + * it's possible that the transfer has been assigned
  83902. + * to a channel, but not started yet when an URB is
  83903. + * dequeued. Don't want to halt a channel that hasn't
  83904. + * started yet.
  83905. + */
  83906. + return;
  83907. + }
  83908. + }
  83909. + if (hc->halt_pending) {
  83910. + /*
  83911. + * A halt has already been issued for this channel. This might
  83912. + * happen when a transfer is aborted by a higher level in
  83913. + * the stack.
  83914. + */
  83915. +#ifdef DEBUG
  83916. + DWC_PRINTF
  83917. + ("*** %s: Channel %d, _hc->halt_pending already set ***\n",
  83918. + __func__, hc->hc_num);
  83919. +
  83920. +#endif
  83921. + return;
  83922. + }
  83923. +
  83924. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  83925. +
  83926. + /* No need to set the bit in DDMA for disabling the channel */
  83927. + //TODO check it everywhere channel is disabled
  83928. + if (!core_if->core_params->dma_desc_enable)
  83929. + hcchar.b.chen = 1;
  83930. + hcchar.b.chdis = 1;
  83931. +
  83932. + if (!core_if->dma_enable) {
  83933. + /* Check for space in the request queue to issue the halt. */
  83934. + if (hc->ep_type == DWC_OTG_EP_TYPE_CONTROL ||
  83935. + hc->ep_type == DWC_OTG_EP_TYPE_BULK) {
  83936. + nptxsts.d32 = DWC_READ_REG32(&global_regs->gnptxsts);
  83937. + if (nptxsts.b.nptxqspcavail == 0) {
  83938. + hcchar.b.chen = 0;
  83939. + }
  83940. + } else {
  83941. + hptxsts.d32 =
  83942. + DWC_READ_REG32(&host_global_regs->hptxsts);
  83943. + if ((hptxsts.b.ptxqspcavail == 0)
  83944. + || (core_if->queuing_high_bandwidth)) {
  83945. + hcchar.b.chen = 0;
  83946. + }
  83947. + }
  83948. + }
  83949. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  83950. +
  83951. + hc->halt_status = halt_status;
  83952. +
  83953. + if (hcchar.b.chen) {
  83954. + hc->halt_pending = 1;
  83955. + hc->halt_on_queue = 0;
  83956. + } else {
  83957. + hc->halt_on_queue = 1;
  83958. + }
  83959. +
  83960. + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, hc->hc_num);
  83961. + DWC_DEBUGPL(DBG_HCDV, " hcchar: 0x%08x\n", hcchar.d32);
  83962. + DWC_DEBUGPL(DBG_HCDV, " halt_pending: %d\n", hc->halt_pending);
  83963. + DWC_DEBUGPL(DBG_HCDV, " halt_on_queue: %d\n", hc->halt_on_queue);
  83964. + DWC_DEBUGPL(DBG_HCDV, " halt_status: %d\n", hc->halt_status);
  83965. +
  83966. + return;
  83967. +}
  83968. +
  83969. +/**
  83970. + * Clears the transfer state for a host channel. This function is normally
  83971. + * called after a transfer is done and the host channel is being released.
  83972. + *
  83973. + * @param core_if Programming view of DWC_otg controller.
  83974. + * @param hc Identifies the host channel to clean up.
  83975. + */
  83976. +void dwc_otg_hc_cleanup(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  83977. +{
  83978. + dwc_otg_hc_regs_t *hc_regs;
  83979. +
  83980. + hc->xfer_started = 0;
  83981. +
  83982. + /*
  83983. + * Clear channel interrupt enables and any unhandled channel interrupt
  83984. + * conditions.
  83985. + */
  83986. + hc_regs = core_if->host_if->hc_regs[hc->hc_num];
  83987. + DWC_WRITE_REG32(&hc_regs->hcintmsk, 0);
  83988. + DWC_WRITE_REG32(&hc_regs->hcint, 0xFFFFFFFF);
  83989. +#ifdef DEBUG
  83990. + DWC_TIMER_CANCEL(core_if->hc_xfer_timer[hc->hc_num]);
  83991. +#endif
  83992. +}
  83993. +
  83994. +/**
  83995. + * Sets the channel property that indicates in which frame a periodic transfer
  83996. + * should occur. This is always set to the _next_ frame. This function has no
  83997. + * effect on non-periodic transfers.
  83998. + *
  83999. + * @param core_if Programming view of DWC_otg controller.
  84000. + * @param hc Identifies the host channel to set up and its properties.
  84001. + * @param hcchar Current value of the HCCHAR register for the specified host
  84002. + * channel.
  84003. + */
  84004. +static inline void hc_set_even_odd_frame(dwc_otg_core_if_t * core_if,
  84005. + dwc_hc_t * hc, hcchar_data_t * hcchar)
  84006. +{
  84007. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  84008. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  84009. + hfnum_data_t hfnum;
  84010. + hfnum.d32 =
  84011. + DWC_READ_REG32(&core_if->host_if->host_global_regs->hfnum);
  84012. +
  84013. + /* 1 if _next_ frame is odd, 0 if it's even */
  84014. + hcchar->b.oddfrm = (hfnum.b.frnum & 0x1) ? 0 : 1;
  84015. +#ifdef DEBUG
  84016. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR && hc->do_split
  84017. + && !hc->complete_split) {
  84018. + switch (hfnum.b.frnum & 0x7) {
  84019. + case 7:
  84020. + core_if->hfnum_7_samples++;
  84021. + core_if->hfnum_7_frrem_accum += hfnum.b.frrem;
  84022. + break;
  84023. + case 0:
  84024. + core_if->hfnum_0_samples++;
  84025. + core_if->hfnum_0_frrem_accum += hfnum.b.frrem;
  84026. + break;
  84027. + default:
  84028. + core_if->hfnum_other_samples++;
  84029. + core_if->hfnum_other_frrem_accum +=
  84030. + hfnum.b.frrem;
  84031. + break;
  84032. + }
  84033. + }
  84034. +#endif
  84035. + }
  84036. +}
  84037. +
  84038. +#ifdef DEBUG
  84039. +void hc_xfer_timeout(void *ptr)
  84040. +{
  84041. + hc_xfer_info_t *xfer_info = NULL;
  84042. + int hc_num = 0;
  84043. +
  84044. + if (ptr)
  84045. + xfer_info = (hc_xfer_info_t *) ptr;
  84046. +
  84047. + if (!xfer_info->hc) {
  84048. + DWC_ERROR("xfer_info->hc = %p\n", xfer_info->hc);
  84049. + return;
  84050. + }
  84051. +
  84052. + hc_num = xfer_info->hc->hc_num;
  84053. + DWC_WARN("%s: timeout on channel %d\n", __func__, hc_num);
  84054. + DWC_WARN(" start_hcchar_val 0x%08x\n",
  84055. + xfer_info->core_if->start_hcchar_val[hc_num]);
  84056. +}
  84057. +#endif
  84058. +
  84059. +void ep_xfer_timeout(void *ptr)
  84060. +{
  84061. + ep_xfer_info_t *xfer_info = NULL;
  84062. + int ep_num = 0;
  84063. + dctl_data_t dctl = {.d32 = 0 };
  84064. + gintsts_data_t gintsts = {.d32 = 0 };
  84065. + gintmsk_data_t gintmsk = {.d32 = 0 };
  84066. +
  84067. + if (ptr)
  84068. + xfer_info = (ep_xfer_info_t *) ptr;
  84069. +
  84070. + if (!xfer_info->ep) {
  84071. + DWC_ERROR("xfer_info->ep = %p\n", xfer_info->ep);
  84072. + return;
  84073. + }
  84074. +
  84075. + ep_num = xfer_info->ep->num;
  84076. + DWC_WARN("%s: timeout on endpoit %d\n", __func__, ep_num);
  84077. + /* Put the sate to 2 as it was time outed */
  84078. + xfer_info->state = 2;
  84079. +
  84080. + dctl.d32 =
  84081. + DWC_READ_REG32(&xfer_info->core_if->dev_if->dev_global_regs->dctl);
  84082. + gintsts.d32 =
  84083. + DWC_READ_REG32(&xfer_info->core_if->core_global_regs->gintsts);
  84084. + gintmsk.d32 =
  84085. + DWC_READ_REG32(&xfer_info->core_if->core_global_regs->gintmsk);
  84086. +
  84087. + if (!gintmsk.b.goutnakeff) {
  84088. + /* Unmask it */
  84089. + gintmsk.b.goutnakeff = 1;
  84090. + DWC_WRITE_REG32(&xfer_info->core_if->core_global_regs->gintmsk,
  84091. + gintmsk.d32);
  84092. +
  84093. + }
  84094. +
  84095. + if (!gintsts.b.goutnakeff) {
  84096. + dctl.b.sgoutnak = 1;
  84097. + }
  84098. + DWC_WRITE_REG32(&xfer_info->core_if->dev_if->dev_global_regs->dctl,
  84099. + dctl.d32);
  84100. +
  84101. +}
  84102. +
  84103. +void set_pid_isoc(dwc_hc_t * hc)
  84104. +{
  84105. + /* Set up the initial PID for the transfer. */
  84106. + if (hc->speed == DWC_OTG_EP_SPEED_HIGH) {
  84107. + if (hc->ep_is_in) {
  84108. + if (hc->multi_count == 1) {
  84109. + hc->data_pid_start = DWC_OTG_HC_PID_DATA0;
  84110. + } else if (hc->multi_count == 2) {
  84111. + hc->data_pid_start = DWC_OTG_HC_PID_DATA1;
  84112. + } else {
  84113. + hc->data_pid_start = DWC_OTG_HC_PID_DATA2;
  84114. + }
  84115. + } else {
  84116. + if (hc->multi_count == 1) {
  84117. + hc->data_pid_start = DWC_OTG_HC_PID_DATA0;
  84118. + } else {
  84119. + hc->data_pid_start = DWC_OTG_HC_PID_MDATA;
  84120. + }
  84121. + }
  84122. + } else {
  84123. + hc->data_pid_start = DWC_OTG_HC_PID_DATA0;
  84124. + }
  84125. +}
  84126. +
  84127. +/**
  84128. + * This function does the setup for a data transfer for a host channel and
  84129. + * starts the transfer. May be called in either Slave mode or DMA mode. In
  84130. + * Slave mode, the caller must ensure that there is sufficient space in the
  84131. + * request queue and Tx Data FIFO.
  84132. + *
  84133. + * For an OUT transfer in Slave mode, it loads a data packet into the
  84134. + * appropriate FIFO. If necessary, additional data packets will be loaded in
  84135. + * the Host ISR.
  84136. + *
  84137. + * For an IN transfer in Slave mode, a data packet is requested. The data
  84138. + * packets are unloaded from the Rx FIFO in the Host ISR. If necessary,
  84139. + * additional data packets are requested in the Host ISR.
  84140. + *
  84141. + * For a PING transfer in Slave mode, the Do Ping bit is set in the HCTSIZ
  84142. + * register along with a packet count of 1 and the channel is enabled. This
  84143. + * causes a single PING transaction to occur. Other fields in HCTSIZ are
  84144. + * simply set to 0 since no data transfer occurs in this case.
  84145. + *
  84146. + * For a PING transfer in DMA mode, the HCTSIZ register is initialized with
  84147. + * all the information required to perform the subsequent data transfer. In
  84148. + * addition, the Do Ping bit is set in the HCTSIZ register. In this case, the
  84149. + * controller performs the entire PING protocol, then starts the data
  84150. + * transfer.
  84151. + *
  84152. + * @param core_if Programming view of DWC_otg controller.
  84153. + * @param hc Information needed to initialize the host channel. The xfer_len
  84154. + * value may be reduced to accommodate the max widths of the XferSize and
  84155. + * PktCnt fields in the HCTSIZn register. The multi_count value may be changed
  84156. + * to reflect the final xfer_len value.
  84157. + */
  84158. +void dwc_otg_hc_start_transfer(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  84159. +{
  84160. + hcchar_data_t hcchar;
  84161. + hctsiz_data_t hctsiz;
  84162. + uint16_t num_packets;
  84163. + uint32_t max_hc_xfer_size = core_if->core_params->max_transfer_size;
  84164. + uint16_t max_hc_pkt_count = core_if->core_params->max_packet_count;
  84165. + dwc_otg_hc_regs_t *hc_regs = core_if->host_if->hc_regs[hc->hc_num];
  84166. +
  84167. + hctsiz.d32 = 0;
  84168. +
  84169. + if (hc->do_ping) {
  84170. + if (!core_if->dma_enable) {
  84171. + dwc_otg_hc_do_ping(core_if, hc);
  84172. + hc->xfer_started = 1;
  84173. + return;
  84174. + } else {
  84175. + hctsiz.b.dopng = 1;
  84176. + }
  84177. + }
  84178. +
  84179. + if (hc->do_split) {
  84180. + num_packets = 1;
  84181. +
  84182. + if (hc->complete_split && !hc->ep_is_in) {
  84183. + /* For CSPLIT OUT Transfer, set the size to 0 so the
  84184. + * core doesn't expect any data written to the FIFO */
  84185. + hc->xfer_len = 0;
  84186. + } else if (hc->ep_is_in || (hc->xfer_len > hc->max_packet)) {
  84187. + hc->xfer_len = hc->max_packet;
  84188. + } else if (!hc->ep_is_in && (hc->xfer_len > 188)) {
  84189. + hc->xfer_len = 188;
  84190. + }
  84191. +
  84192. + hctsiz.b.xfersize = hc->xfer_len;
  84193. + } else {
  84194. + /*
  84195. + * Ensure that the transfer length and packet count will fit
  84196. + * in the widths allocated for them in the HCTSIZn register.
  84197. + */
  84198. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  84199. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  84200. + /*
  84201. + * Make sure the transfer size is no larger than one
  84202. + * (micro)frame's worth of data. (A check was done
  84203. + * when the periodic transfer was accepted to ensure
  84204. + * that a (micro)frame's worth of data can be
  84205. + * programmed into a channel.)
  84206. + */
  84207. + uint32_t max_periodic_len =
  84208. + hc->multi_count * hc->max_packet;
  84209. + if (hc->xfer_len > max_periodic_len) {
  84210. + hc->xfer_len = max_periodic_len;
  84211. + } else {
  84212. + }
  84213. + } else if (hc->xfer_len > max_hc_xfer_size) {
  84214. + /* Make sure that xfer_len is a multiple of max packet size. */
  84215. + hc->xfer_len = max_hc_xfer_size - hc->max_packet + 1;
  84216. + }
  84217. +
  84218. + if (hc->xfer_len > 0) {
  84219. + num_packets =
  84220. + (hc->xfer_len + hc->max_packet -
  84221. + 1) / hc->max_packet;
  84222. + if (num_packets > max_hc_pkt_count) {
  84223. + num_packets = max_hc_pkt_count;
  84224. + hc->xfer_len = num_packets * hc->max_packet;
  84225. + }
  84226. + } else {
  84227. + /* Need 1 packet for transfer length of 0. */
  84228. + num_packets = 1;
  84229. + }
  84230. +
  84231. + if (hc->ep_is_in) {
  84232. + /* Always program an integral # of max packets for IN transfers. */
  84233. + hc->xfer_len = num_packets * hc->max_packet;
  84234. + }
  84235. +
  84236. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  84237. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  84238. + /*
  84239. + * Make sure that the multi_count field matches the
  84240. + * actual transfer length.
  84241. + */
  84242. + hc->multi_count = num_packets;
  84243. + }
  84244. +
  84245. + if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC)
  84246. + set_pid_isoc(hc);
  84247. +
  84248. + hctsiz.b.xfersize = hc->xfer_len;
  84249. + }
  84250. +
  84251. + hc->start_pkt_count = num_packets;
  84252. + hctsiz.b.pktcnt = num_packets;
  84253. + hctsiz.b.pid = hc->data_pid_start;
  84254. + DWC_WRITE_REG32(&hc_regs->hctsiz, hctsiz.d32);
  84255. +
  84256. + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, hc->hc_num);
  84257. + DWC_DEBUGPL(DBG_HCDV, " Xfer Size: %d\n", hctsiz.b.xfersize);
  84258. + DWC_DEBUGPL(DBG_HCDV, " Num Pkts: %d\n", hctsiz.b.pktcnt);
  84259. + DWC_DEBUGPL(DBG_HCDV, " Start PID: %d\n", hctsiz.b.pid);
  84260. +
  84261. + if (core_if->dma_enable) {
  84262. + dwc_dma_t dma_addr;
  84263. + if (hc->align_buff) {
  84264. + dma_addr = hc->align_buff;
  84265. + } else {
  84266. + dma_addr = ((unsigned long)hc->xfer_buff & 0xffffffff);
  84267. + }
  84268. + DWC_WRITE_REG32(&hc_regs->hcdma, dma_addr);
  84269. + }
  84270. +
  84271. + /* Start the split */
  84272. + if (hc->do_split) {
  84273. + hcsplt_data_t hcsplt;
  84274. + hcsplt.d32 = DWC_READ_REG32(&hc_regs->hcsplt);
  84275. + hcsplt.b.spltena = 1;
  84276. + DWC_WRITE_REG32(&hc_regs->hcsplt, hcsplt.d32);
  84277. + }
  84278. +
  84279. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  84280. + hcchar.b.multicnt = hc->multi_count;
  84281. + hc_set_even_odd_frame(core_if, hc, &hcchar);
  84282. +#ifdef DEBUG
  84283. + core_if->start_hcchar_val[hc->hc_num] = hcchar.d32;
  84284. + if (hcchar.b.chdis) {
  84285. + DWC_WARN("%s: chdis set, channel %d, hcchar 0x%08x\n",
  84286. + __func__, hc->hc_num, hcchar.d32);
  84287. + }
  84288. +#endif
  84289. +
  84290. + /* Set host channel enable after all other setup is complete. */
  84291. + hcchar.b.chen = 1;
  84292. + hcchar.b.chdis = 0;
  84293. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  84294. +
  84295. + hc->xfer_started = 1;
  84296. + hc->requests++;
  84297. +
  84298. + if (!core_if->dma_enable && !hc->ep_is_in && hc->xfer_len > 0) {
  84299. + /* Load OUT packet into the appropriate Tx FIFO. */
  84300. + dwc_otg_hc_write_packet(core_if, hc);
  84301. + }
  84302. +#ifdef DEBUG
  84303. + if (hc->ep_type != DWC_OTG_EP_TYPE_INTR) {
  84304. + DWC_DEBUGPL(DBG_HCDV, "transfer %d from core_if %p\n",
  84305. + hc->hc_num, core_if);//GRAYG
  84306. + core_if->hc_xfer_info[hc->hc_num].core_if = core_if;
  84307. + core_if->hc_xfer_info[hc->hc_num].hc = hc;
  84308. +
  84309. + /* Start a timer for this transfer. */
  84310. + DWC_TIMER_SCHEDULE(core_if->hc_xfer_timer[hc->hc_num], 10000);
  84311. + }
  84312. +#endif
  84313. +}
  84314. +
  84315. +/**
  84316. + * This function does the setup for a data transfer for a host channel
  84317. + * and starts the transfer in Descriptor DMA mode.
  84318. + *
  84319. + * Initializes HCTSIZ register. For a PING transfer the Do Ping bit is set.
  84320. + * Sets PID and NTD values. For periodic transfers
  84321. + * initializes SCHED_INFO field with micro-frame bitmap.
  84322. + *
  84323. + * Initializes HCDMA register with descriptor list address and CTD value
  84324. + * then starts the transfer via enabling the channel.
  84325. + *
  84326. + * @param core_if Programming view of DWC_otg controller.
  84327. + * @param hc Information needed to initialize the host channel.
  84328. + */
  84329. +void dwc_otg_hc_start_transfer_ddma(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  84330. +{
  84331. + dwc_otg_hc_regs_t *hc_regs = core_if->host_if->hc_regs[hc->hc_num];
  84332. + hcchar_data_t hcchar;
  84333. + hctsiz_data_t hctsiz;
  84334. + hcdma_data_t hcdma;
  84335. +
  84336. + hctsiz.d32 = 0;
  84337. +
  84338. + if (hc->do_ping)
  84339. + hctsiz.b_ddma.dopng = 1;
  84340. +
  84341. + if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC)
  84342. + set_pid_isoc(hc);
  84343. +
  84344. + /* Packet Count and Xfer Size are not used in Descriptor DMA mode */
  84345. + hctsiz.b_ddma.pid = hc->data_pid_start;
  84346. + hctsiz.b_ddma.ntd = hc->ntd - 1; /* 0 - 1 descriptor, 1 - 2 descriptors, etc. */
  84347. + hctsiz.b_ddma.schinfo = hc->schinfo; /* Non-zero only for high-speed interrupt endpoints */
  84348. +
  84349. + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, hc->hc_num);
  84350. + DWC_DEBUGPL(DBG_HCDV, " Start PID: %d\n", hctsiz.b.pid);
  84351. + DWC_DEBUGPL(DBG_HCDV, " NTD: %d\n", hctsiz.b_ddma.ntd);
  84352. +
  84353. + DWC_WRITE_REG32(&hc_regs->hctsiz, hctsiz.d32);
  84354. +
  84355. + hcdma.d32 = 0;
  84356. + hcdma.b.dma_addr = ((uint32_t) hc->desc_list_addr) >> 11;
  84357. +
  84358. + /* Always start from first descriptor. */
  84359. + hcdma.b.ctd = 0;
  84360. + DWC_WRITE_REG32(&hc_regs->hcdma, hcdma.d32);
  84361. +
  84362. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  84363. + hcchar.b.multicnt = hc->multi_count;
  84364. +
  84365. +#ifdef DEBUG
  84366. + core_if->start_hcchar_val[hc->hc_num] = hcchar.d32;
  84367. + if (hcchar.b.chdis) {
  84368. + DWC_WARN("%s: chdis set, channel %d, hcchar 0x%08x\n",
  84369. + __func__, hc->hc_num, hcchar.d32);
  84370. + }
  84371. +#endif
  84372. +
  84373. + /* Set host channel enable after all other setup is complete. */
  84374. + hcchar.b.chen = 1;
  84375. + hcchar.b.chdis = 0;
  84376. +
  84377. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  84378. +
  84379. + hc->xfer_started = 1;
  84380. + hc->requests++;
  84381. +
  84382. +#ifdef DEBUG
  84383. + if ((hc->ep_type != DWC_OTG_EP_TYPE_INTR)
  84384. + && (hc->ep_type != DWC_OTG_EP_TYPE_ISOC)) {
  84385. + DWC_DEBUGPL(DBG_HCDV, "DMA transfer %d from core_if %p\n",
  84386. + hc->hc_num, core_if);//GRAYG
  84387. + core_if->hc_xfer_info[hc->hc_num].core_if = core_if;
  84388. + core_if->hc_xfer_info[hc->hc_num].hc = hc;
  84389. + /* Start a timer for this transfer. */
  84390. + DWC_TIMER_SCHEDULE(core_if->hc_xfer_timer[hc->hc_num], 10000);
  84391. + }
  84392. +#endif
  84393. +
  84394. +}
  84395. +
  84396. +/**
  84397. + * This function continues a data transfer that was started by previous call
  84398. + * to <code>dwc_otg_hc_start_transfer</code>. The caller must ensure there is
  84399. + * sufficient space in the request queue and Tx Data FIFO. This function
  84400. + * should only be called in Slave mode. In DMA mode, the controller acts
  84401. + * autonomously to complete transfers programmed to a host channel.
  84402. + *
  84403. + * For an OUT transfer, a new data packet is loaded into the appropriate FIFO
  84404. + * if there is any data remaining to be queued. For an IN transfer, another
  84405. + * data packet is always requested. For the SETUP phase of a control transfer,
  84406. + * this function does nothing.
  84407. + *
  84408. + * @return 1 if a new request is queued, 0 if no more requests are required
  84409. + * for this transfer.
  84410. + */
  84411. +int dwc_otg_hc_continue_transfer(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  84412. +{
  84413. + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, hc->hc_num);
  84414. +
  84415. + if (hc->do_split) {
  84416. + /* SPLITs always queue just once per channel */
  84417. + return 0;
  84418. + } else if (hc->data_pid_start == DWC_OTG_HC_PID_SETUP) {
  84419. + /* SETUPs are queued only once since they can't be NAKed. */
  84420. + return 0;
  84421. + } else if (hc->ep_is_in) {
  84422. + /*
  84423. + * Always queue another request for other IN transfers. If
  84424. + * back-to-back INs are issued and NAKs are received for both,
  84425. + * the driver may still be processing the first NAK when the
  84426. + * second NAK is received. When the interrupt handler clears
  84427. + * the NAK interrupt for the first NAK, the second NAK will
  84428. + * not be seen. So we can't depend on the NAK interrupt
  84429. + * handler to requeue a NAKed request. Instead, IN requests
  84430. + * are issued each time this function is called. When the
  84431. + * transfer completes, the extra requests for the channel will
  84432. + * be flushed.
  84433. + */
  84434. + hcchar_data_t hcchar;
  84435. + dwc_otg_hc_regs_t *hc_regs =
  84436. + core_if->host_if->hc_regs[hc->hc_num];
  84437. +
  84438. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  84439. + hc_set_even_odd_frame(core_if, hc, &hcchar);
  84440. + hcchar.b.chen = 1;
  84441. + hcchar.b.chdis = 0;
  84442. + DWC_DEBUGPL(DBG_HCDV, " IN xfer: hcchar = 0x%08x\n",
  84443. + hcchar.d32);
  84444. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  84445. + hc->requests++;
  84446. + return 1;
  84447. + } else {
  84448. + /* OUT transfers. */
  84449. + if (hc->xfer_count < hc->xfer_len) {
  84450. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  84451. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  84452. + hcchar_data_t hcchar;
  84453. + dwc_otg_hc_regs_t *hc_regs;
  84454. + hc_regs = core_if->host_if->hc_regs[hc->hc_num];
  84455. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  84456. + hc_set_even_odd_frame(core_if, hc, &hcchar);
  84457. + }
  84458. +
  84459. + /* Load OUT packet into the appropriate Tx FIFO. */
  84460. + dwc_otg_hc_write_packet(core_if, hc);
  84461. + hc->requests++;
  84462. + return 1;
  84463. + } else {
  84464. + return 0;
  84465. + }
  84466. + }
  84467. +}
  84468. +
  84469. +/**
  84470. + * Starts a PING transfer. This function should only be called in Slave mode.
  84471. + * The Do Ping bit is set in the HCTSIZ register, then the channel is enabled.
  84472. + */
  84473. +void dwc_otg_hc_do_ping(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  84474. +{
  84475. + hcchar_data_t hcchar;
  84476. + hctsiz_data_t hctsiz;
  84477. + dwc_otg_hc_regs_t *hc_regs = core_if->host_if->hc_regs[hc->hc_num];
  84478. +
  84479. + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, hc->hc_num);
  84480. +
  84481. + hctsiz.d32 = 0;
  84482. + hctsiz.b.dopng = 1;
  84483. + hctsiz.b.pktcnt = 1;
  84484. + DWC_WRITE_REG32(&hc_regs->hctsiz, hctsiz.d32);
  84485. +
  84486. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  84487. + hcchar.b.chen = 1;
  84488. + hcchar.b.chdis = 0;
  84489. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  84490. +}
  84491. +
  84492. +/*
  84493. + * This function writes a packet into the Tx FIFO associated with the Host
  84494. + * Channel. For a channel associated with a non-periodic EP, the non-periodic
  84495. + * Tx FIFO is written. For a channel associated with a periodic EP, the
  84496. + * periodic Tx FIFO is written. This function should only be called in Slave
  84497. + * mode.
  84498. + *
  84499. + * Upon return the xfer_buff and xfer_count fields in _hc are incremented by
  84500. + * then number of bytes written to the Tx FIFO.
  84501. + */
  84502. +void dwc_otg_hc_write_packet(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  84503. +{
  84504. + uint32_t i;
  84505. + uint32_t remaining_count;
  84506. + uint32_t byte_count;
  84507. + uint32_t dword_count;
  84508. +
  84509. + uint32_t *data_buff = (uint32_t *) (hc->xfer_buff);
  84510. + uint32_t *data_fifo = core_if->data_fifo[hc->hc_num];
  84511. +
  84512. + remaining_count = hc->xfer_len - hc->xfer_count;
  84513. + if (remaining_count > hc->max_packet) {
  84514. + byte_count = hc->max_packet;
  84515. + } else {
  84516. + byte_count = remaining_count;
  84517. + }
  84518. +
  84519. + dword_count = (byte_count + 3) / 4;
  84520. +
  84521. + if ((((unsigned long)data_buff) & 0x3) == 0) {
  84522. + /* xfer_buff is DWORD aligned. */
  84523. + for (i = 0; i < dword_count; i++, data_buff++) {
  84524. + DWC_WRITE_REG32(data_fifo, *data_buff);
  84525. + }
  84526. + } else {
  84527. + /* xfer_buff is not DWORD aligned. */
  84528. + for (i = 0; i < dword_count; i++, data_buff++) {
  84529. + uint32_t data;
  84530. + data =
  84531. + (data_buff[0] | data_buff[1] << 8 | data_buff[2] <<
  84532. + 16 | data_buff[3] << 24);
  84533. + DWC_WRITE_REG32(data_fifo, data);
  84534. + }
  84535. + }
  84536. +
  84537. + hc->xfer_count += byte_count;
  84538. + hc->xfer_buff += byte_count;
  84539. +}
  84540. +
  84541. +/**
  84542. + * Gets the current USB frame number. This is the frame number from the last
  84543. + * SOF packet.
  84544. + */
  84545. +uint32_t dwc_otg_get_frame_number(dwc_otg_core_if_t * core_if)
  84546. +{
  84547. + dsts_data_t dsts;
  84548. + dsts.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  84549. +
  84550. + /* read current frame/microframe number from DSTS register */
  84551. + return dsts.b.soffn;
  84552. +}
  84553. +
  84554. +/**
  84555. + * Calculates and gets the frame Interval value of HFIR register according PHY
  84556. + * type and speed.The application can modify a value of HFIR register only after
  84557. + * the Port Enable bit of the Host Port Control and Status register
  84558. + * (HPRT.PrtEnaPort) has been set.
  84559. +*/
  84560. +
  84561. +uint32_t calc_frame_interval(dwc_otg_core_if_t * core_if)
  84562. +{
  84563. + gusbcfg_data_t usbcfg;
  84564. + hwcfg2_data_t hwcfg2;
  84565. + hprt0_data_t hprt0;
  84566. + int clock = 60; // default value
  84567. + usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  84568. + hwcfg2.d32 = DWC_READ_REG32(&core_if->core_global_regs->ghwcfg2);
  84569. + hprt0.d32 = DWC_READ_REG32(core_if->host_if->hprt0);
  84570. + if (!usbcfg.b.physel && usbcfg.b.ulpi_utmi_sel && !usbcfg.b.phyif)
  84571. + clock = 60;
  84572. + if (usbcfg.b.physel && hwcfg2.b.fs_phy_type == 3)
  84573. + clock = 48;
  84574. + if (!usbcfg.b.phylpwrclksel && !usbcfg.b.physel &&
  84575. + !usbcfg.b.ulpi_utmi_sel && usbcfg.b.phyif)
  84576. + clock = 30;
  84577. + if (!usbcfg.b.phylpwrclksel && !usbcfg.b.physel &&
  84578. + !usbcfg.b.ulpi_utmi_sel && !usbcfg.b.phyif)
  84579. + clock = 60;
  84580. + if (usbcfg.b.phylpwrclksel && !usbcfg.b.physel &&
  84581. + !usbcfg.b.ulpi_utmi_sel && usbcfg.b.phyif)
  84582. + clock = 48;
  84583. + if (usbcfg.b.physel && !usbcfg.b.phyif && hwcfg2.b.fs_phy_type == 2)
  84584. + clock = 48;
  84585. + if (usbcfg.b.physel && hwcfg2.b.fs_phy_type == 1)
  84586. + clock = 48;
  84587. + if (hprt0.b.prtspd == 0)
  84588. + /* High speed case */
  84589. + return 125 * clock;
  84590. + else
  84591. + /* FS/LS case */
  84592. + return 1000 * clock;
  84593. +}
  84594. +
  84595. +/**
  84596. + * This function reads a setup packet from the Rx FIFO into the destination
  84597. + * buffer. This function is called from the Rx Status Queue Level (RxStsQLvl)
  84598. + * Interrupt routine when a SETUP packet has been received in Slave mode.
  84599. + *
  84600. + * @param core_if Programming view of DWC_otg controller.
  84601. + * @param dest Destination buffer for packet data.
  84602. + */
  84603. +void dwc_otg_read_setup_packet(dwc_otg_core_if_t * core_if, uint32_t * dest)
  84604. +{
  84605. + device_grxsts_data_t status;
  84606. + /* Get the 8 bytes of a setup transaction data */
  84607. +
  84608. + /* Pop 2 DWORDS off the receive data FIFO into memory */
  84609. + dest[0] = DWC_READ_REG32(core_if->data_fifo[0]);
  84610. + dest[1] = DWC_READ_REG32(core_if->data_fifo[0]);
  84611. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  84612. + status.d32 =
  84613. + DWC_READ_REG32(&core_if->core_global_regs->grxstsp);
  84614. + DWC_DEBUGPL(DBG_ANY,
  84615. + "EP:%d BCnt:%d " "pktsts:%x Frame:%d(0x%0x)\n",
  84616. + status.b.epnum, status.b.bcnt, status.b.pktsts,
  84617. + status.b.fn, status.b.fn);
  84618. + }
  84619. +}
  84620. +
  84621. +/**
  84622. + * This function enables EP0 OUT to receive SETUP packets and configures EP0
  84623. + * IN for transmitting packets. It is normally called when the
  84624. + * "Enumeration Done" interrupt occurs.
  84625. + *
  84626. + * @param core_if Programming view of DWC_otg controller.
  84627. + * @param ep The EP0 data.
  84628. + */
  84629. +void dwc_otg_ep0_activate(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  84630. +{
  84631. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  84632. + dsts_data_t dsts;
  84633. + depctl_data_t diepctl;
  84634. + depctl_data_t doepctl;
  84635. + dctl_data_t dctl = {.d32 = 0 };
  84636. +
  84637. + ep->stp_rollover = 0;
  84638. + /* Read the Device Status and Endpoint 0 Control registers */
  84639. + dsts.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dsts);
  84640. + diepctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[0]->diepctl);
  84641. + doepctl.d32 = DWC_READ_REG32(&dev_if->out_ep_regs[0]->doepctl);
  84642. +
  84643. + /* Set the MPS of the IN EP based on the enumeration speed */
  84644. + switch (dsts.b.enumspd) {
  84645. + case DWC_DSTS_ENUMSPD_HS_PHY_30MHZ_OR_60MHZ:
  84646. + case DWC_DSTS_ENUMSPD_FS_PHY_30MHZ_OR_60MHZ:
  84647. + case DWC_DSTS_ENUMSPD_FS_PHY_48MHZ:
  84648. + diepctl.b.mps = DWC_DEP0CTL_MPS_64;
  84649. + break;
  84650. + case DWC_DSTS_ENUMSPD_LS_PHY_6MHZ:
  84651. + diepctl.b.mps = DWC_DEP0CTL_MPS_8;
  84652. + break;
  84653. + }
  84654. +
  84655. + DWC_WRITE_REG32(&dev_if->in_ep_regs[0]->diepctl, diepctl.d32);
  84656. +
  84657. + /* Enable OUT EP for receive */
  84658. + if (core_if->snpsid <= OTG_CORE_REV_2_94a) {
  84659. + doepctl.b.epena = 1;
  84660. + DWC_WRITE_REG32(&dev_if->out_ep_regs[0]->doepctl, doepctl.d32);
  84661. + }
  84662. +#ifdef VERBOSE
  84663. + DWC_DEBUGPL(DBG_PCDV, "doepctl0=%0x\n",
  84664. + DWC_READ_REG32(&dev_if->out_ep_regs[0]->doepctl));
  84665. + DWC_DEBUGPL(DBG_PCDV, "diepctl0=%0x\n",
  84666. + DWC_READ_REG32(&dev_if->in_ep_regs[0]->diepctl));
  84667. +#endif
  84668. + dctl.b.cgnpinnak = 1;
  84669. +
  84670. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dctl, dctl.d32, dctl.d32);
  84671. + DWC_DEBUGPL(DBG_PCDV, "dctl=%0x\n",
  84672. + DWC_READ_REG32(&dev_if->dev_global_regs->dctl));
  84673. +
  84674. +}
  84675. +
  84676. +/**
  84677. + * This function activates an EP. The Device EP control register for
  84678. + * the EP is configured as defined in the ep structure. Note: This
  84679. + * function is not used for EP0.
  84680. + *
  84681. + * @param core_if Programming view of DWC_otg controller.
  84682. + * @param ep The EP to activate.
  84683. + */
  84684. +void dwc_otg_ep_activate(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  84685. +{
  84686. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  84687. + depctl_data_t depctl;
  84688. + volatile uint32_t *addr;
  84689. + daint_data_t daintmsk = {.d32 = 0 };
  84690. + dcfg_data_t dcfg;
  84691. + uint8_t i;
  84692. +
  84693. + DWC_DEBUGPL(DBG_PCDV, "%s() EP%d-%s\n", __func__, ep->num,
  84694. + (ep->is_in ? "IN" : "OUT"));
  84695. +
  84696. +#ifdef DWC_UTE_PER_IO
  84697. + ep->xiso_frame_num = 0xFFFFFFFF;
  84698. + ep->xiso_active_xfers = 0;
  84699. + ep->xiso_queued_xfers = 0;
  84700. +#endif
  84701. + /* Read DEPCTLn register */
  84702. + if (ep->is_in == 1) {
  84703. + addr = &dev_if->in_ep_regs[ep->num]->diepctl;
  84704. + daintmsk.ep.in = 1 << ep->num;
  84705. + } else {
  84706. + addr = &dev_if->out_ep_regs[ep->num]->doepctl;
  84707. + daintmsk.ep.out = 1 << ep->num;
  84708. + }
  84709. +
  84710. + /* If the EP is already active don't change the EP Control
  84711. + * register. */
  84712. + depctl.d32 = DWC_READ_REG32(addr);
  84713. + if (!depctl.b.usbactep) {
  84714. + depctl.b.mps = ep->maxpacket;
  84715. + depctl.b.eptype = ep->type;
  84716. + depctl.b.txfnum = ep->tx_fifo_num;
  84717. +
  84718. + if (ep->type == DWC_OTG_EP_TYPE_ISOC) {
  84719. + depctl.b.setd0pid = 1; // ???
  84720. + } else {
  84721. + depctl.b.setd0pid = 1;
  84722. + }
  84723. + depctl.b.usbactep = 1;
  84724. +
  84725. + /* Update nextep_seq array and EPMSCNT in DCFG*/
  84726. + if (!(depctl.b.eptype & 1) && (ep->is_in == 1)) { // NP IN EP
  84727. + for (i = 0; i <= core_if->dev_if->num_in_eps; i++) {
  84728. + if (core_if->nextep_seq[i] == core_if->first_in_nextep_seq)
  84729. + break;
  84730. + }
  84731. + core_if->nextep_seq[i] = ep->num;
  84732. + core_if->nextep_seq[ep->num] = core_if->first_in_nextep_seq;
  84733. + depctl.b.nextep = core_if->nextep_seq[ep->num];
  84734. + dcfg.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dcfg);
  84735. + dcfg.b.epmscnt++;
  84736. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dcfg, dcfg.d32);
  84737. +
  84738. + DWC_DEBUGPL(DBG_PCDV,
  84739. + "%s first_in_nextep_seq= %2d; nextep_seq[]:\n",
  84740. + __func__, core_if->first_in_nextep_seq);
  84741. + for (i=0; i <= core_if->dev_if->num_in_eps; i++) {
  84742. + DWC_DEBUGPL(DBG_PCDV, "%2d\n",
  84743. + core_if->nextep_seq[i]);
  84744. + }
  84745. +
  84746. + }
  84747. +
  84748. +
  84749. + DWC_WRITE_REG32(addr, depctl.d32);
  84750. + DWC_DEBUGPL(DBG_PCDV, "DEPCTL=%08x\n", DWC_READ_REG32(addr));
  84751. + }
  84752. +
  84753. + /* Enable the Interrupt for this EP */
  84754. + if (core_if->multiproc_int_enable) {
  84755. + if (ep->is_in == 1) {
  84756. + diepmsk_data_t diepmsk = {.d32 = 0 };
  84757. + diepmsk.b.xfercompl = 1;
  84758. + diepmsk.b.timeout = 1;
  84759. + diepmsk.b.epdisabled = 1;
  84760. + diepmsk.b.ahberr = 1;
  84761. + diepmsk.b.intknepmis = 1;
  84762. + if (!core_if->en_multiple_tx_fifo && core_if->dma_enable)
  84763. + diepmsk.b.intknepmis = 0;
  84764. + diepmsk.b.txfifoundrn = 1; //?????
  84765. + if (ep->type == DWC_OTG_EP_TYPE_ISOC) {
  84766. + diepmsk.b.nak = 1;
  84767. + }
  84768. +
  84769. +
  84770. +
  84771. +/*
  84772. + if (core_if->dma_desc_enable) {
  84773. + diepmsk.b.bna = 1;
  84774. + }
  84775. +*/
  84776. +/*
  84777. + if (core_if->dma_enable) {
  84778. + doepmsk.b.nak = 1;
  84779. + }
  84780. +*/
  84781. + DWC_WRITE_REG32(&dev_if->dev_global_regs->
  84782. + diepeachintmsk[ep->num], diepmsk.d32);
  84783. +
  84784. + } else {
  84785. + doepmsk_data_t doepmsk = {.d32 = 0 };
  84786. + doepmsk.b.xfercompl = 1;
  84787. + doepmsk.b.ahberr = 1;
  84788. + doepmsk.b.epdisabled = 1;
  84789. + if (ep->type == DWC_OTG_EP_TYPE_ISOC)
  84790. + doepmsk.b.outtknepdis = 1;
  84791. +
  84792. +/*
  84793. +
  84794. + if (core_if->dma_desc_enable) {
  84795. + doepmsk.b.bna = 1;
  84796. + }
  84797. +*/
  84798. +/*
  84799. + doepmsk.b.babble = 1;
  84800. + doepmsk.b.nyet = 1;
  84801. + doepmsk.b.nak = 1;
  84802. +*/
  84803. + DWC_WRITE_REG32(&dev_if->dev_global_regs->
  84804. + doepeachintmsk[ep->num], doepmsk.d32);
  84805. + }
  84806. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->deachintmsk,
  84807. + 0, daintmsk.d32);
  84808. + } else {
  84809. + if (ep->type == DWC_OTG_EP_TYPE_ISOC) {
  84810. + if (ep->is_in) {
  84811. + diepmsk_data_t diepmsk = {.d32 = 0 };
  84812. + diepmsk.b.nak = 1;
  84813. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->diepmsk, 0, diepmsk.d32);
  84814. + } else {
  84815. + doepmsk_data_t doepmsk = {.d32 = 0 };
  84816. + doepmsk.b.outtknepdis = 1;
  84817. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->doepmsk, 0, doepmsk.d32);
  84818. + }
  84819. + }
  84820. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->daintmsk,
  84821. + 0, daintmsk.d32);
  84822. + }
  84823. +
  84824. + DWC_DEBUGPL(DBG_PCDV, "DAINTMSK=%0x\n",
  84825. + DWC_READ_REG32(&dev_if->dev_global_regs->daintmsk));
  84826. +
  84827. + ep->stall_clear_flag = 0;
  84828. +
  84829. + return;
  84830. +}
  84831. +
  84832. +/**
  84833. + * This function deactivates an EP. This is done by clearing the USB Active
  84834. + * EP bit in the Device EP control register. Note: This function is not used
  84835. + * for EP0. EP0 cannot be deactivated.
  84836. + *
  84837. + * @param core_if Programming view of DWC_otg controller.
  84838. + * @param ep The EP to deactivate.
  84839. + */
  84840. +void dwc_otg_ep_deactivate(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  84841. +{
  84842. + depctl_data_t depctl = {.d32 = 0 };
  84843. + volatile uint32_t *addr;
  84844. + daint_data_t daintmsk = {.d32 = 0 };
  84845. + dcfg_data_t dcfg;
  84846. + uint8_t i = 0;
  84847. +
  84848. +#ifdef DWC_UTE_PER_IO
  84849. + ep->xiso_frame_num = 0xFFFFFFFF;
  84850. + ep->xiso_active_xfers = 0;
  84851. + ep->xiso_queued_xfers = 0;
  84852. +#endif
  84853. +
  84854. + /* Read DEPCTLn register */
  84855. + if (ep->is_in == 1) {
  84856. + addr = &core_if->dev_if->in_ep_regs[ep->num]->diepctl;
  84857. + daintmsk.ep.in = 1 << ep->num;
  84858. + } else {
  84859. + addr = &core_if->dev_if->out_ep_regs[ep->num]->doepctl;
  84860. + daintmsk.ep.out = 1 << ep->num;
  84861. + }
  84862. +
  84863. + depctl.d32 = DWC_READ_REG32(addr);
  84864. +
  84865. + depctl.b.usbactep = 0;
  84866. +
  84867. + /* Update nextep_seq array and EPMSCNT in DCFG*/
  84868. + if (!(depctl.b.eptype & 1) && ep->is_in == 1) { // NP EP IN
  84869. + for (i = 0; i <= core_if->dev_if->num_in_eps; i++) {
  84870. + if (core_if->nextep_seq[i] == ep->num)
  84871. + break;
  84872. + }
  84873. + core_if->nextep_seq[i] = core_if->nextep_seq[ep->num];
  84874. + if (core_if->first_in_nextep_seq == ep->num)
  84875. + core_if->first_in_nextep_seq = i;
  84876. + core_if->nextep_seq[ep->num] = 0xff;
  84877. + depctl.b.nextep = 0;
  84878. + dcfg.d32 =
  84879. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  84880. + dcfg.b.epmscnt--;
  84881. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg,
  84882. + dcfg.d32);
  84883. +
  84884. + DWC_DEBUGPL(DBG_PCDV,
  84885. + "%s first_in_nextep_seq= %2d; nextep_seq[]:\n",
  84886. + __func__, core_if->first_in_nextep_seq);
  84887. + for (i=0; i <= core_if->dev_if->num_in_eps; i++) {
  84888. + DWC_DEBUGPL(DBG_PCDV, "%2d\n", core_if->nextep_seq[i]);
  84889. + }
  84890. + }
  84891. +
  84892. + if (ep->is_in == 1)
  84893. + depctl.b.txfnum = 0;
  84894. +
  84895. + if (core_if->dma_desc_enable)
  84896. + depctl.b.epdis = 1;
  84897. +
  84898. + DWC_WRITE_REG32(addr, depctl.d32);
  84899. + depctl.d32 = DWC_READ_REG32(addr);
  84900. + if (core_if->dma_enable && ep->type == DWC_OTG_EP_TYPE_ISOC
  84901. + && depctl.b.epena) {
  84902. + depctl_data_t depctl = {.d32 = 0};
  84903. + if (ep->is_in) {
  84904. + diepint_data_t diepint = {.d32 = 0};
  84905. +
  84906. + depctl.b.snak = 1;
  84907. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  84908. + diepctl, depctl.d32);
  84909. + do {
  84910. + dwc_udelay(10);
  84911. + diepint.d32 =
  84912. + DWC_READ_REG32(&core_if->
  84913. + dev_if->in_ep_regs[ep->num]->
  84914. + diepint);
  84915. + } while (!diepint.b.inepnakeff);
  84916. + diepint.b.inepnakeff = 1;
  84917. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  84918. + diepint, diepint.d32);
  84919. + depctl.d32 = 0;
  84920. + depctl.b.epdis = 1;
  84921. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  84922. + diepctl, depctl.d32);
  84923. + do {
  84924. + dwc_udelay(10);
  84925. + diepint.d32 =
  84926. + DWC_READ_REG32(&core_if->
  84927. + dev_if->in_ep_regs[ep->num]->
  84928. + diepint);
  84929. + } while (!diepint.b.epdisabled);
  84930. + diepint.b.epdisabled = 1;
  84931. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  84932. + diepint, diepint.d32);
  84933. + } else {
  84934. + dctl_data_t dctl = {.d32 = 0};
  84935. + gintmsk_data_t gintsts = {.d32 = 0};
  84936. + doepint_data_t doepint = {.d32 = 0};
  84937. + dctl.b.sgoutnak = 1;
  84938. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  84939. + dctl, 0, dctl.d32);
  84940. + do {
  84941. + dwc_udelay(10);
  84942. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  84943. + } while (!gintsts.b.goutnakeff);
  84944. + gintsts.d32 = 0;
  84945. + gintsts.b.goutnakeff = 1;
  84946. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  84947. +
  84948. + depctl.d32 = 0;
  84949. + depctl.b.epdis = 1;
  84950. + depctl.b.snak = 1;
  84951. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[ep->num]->doepctl, depctl.d32);
  84952. + do
  84953. + {
  84954. + dwc_udelay(10);
  84955. + doepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  84956. + out_ep_regs[ep->num]->doepint);
  84957. + } while (!doepint.b.epdisabled);
  84958. +
  84959. + doepint.b.epdisabled = 1;
  84960. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[ep->num]->doepint, doepint.d32);
  84961. +
  84962. + dctl.d32 = 0;
  84963. + dctl.b.cgoutnak = 1;
  84964. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0, dctl.d32);
  84965. + }
  84966. + }
  84967. +
  84968. + /* Disable the Interrupt for this EP */
  84969. + if (core_if->multiproc_int_enable) {
  84970. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->deachintmsk,
  84971. + daintmsk.d32, 0);
  84972. +
  84973. + if (ep->is_in == 1) {
  84974. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->
  84975. + diepeachintmsk[ep->num], 0);
  84976. + } else {
  84977. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->
  84978. + doepeachintmsk[ep->num], 0);
  84979. + }
  84980. + } else {
  84981. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->daintmsk,
  84982. + daintmsk.d32, 0);
  84983. + }
  84984. +
  84985. +}
  84986. +
  84987. +/**
  84988. + * This function initializes dma descriptor chain.
  84989. + *
  84990. + * @param core_if Programming view of DWC_otg controller.
  84991. + * @param ep The EP to start the transfer on.
  84992. + */
  84993. +static void init_dma_desc_chain(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  84994. +{
  84995. + dwc_otg_dev_dma_desc_t *dma_desc;
  84996. + uint32_t offset;
  84997. + uint32_t xfer_est;
  84998. + int i;
  84999. + unsigned maxxfer_local, total_len;
  85000. +
  85001. + if (!ep->is_in && ep->type == DWC_OTG_EP_TYPE_INTR &&
  85002. + (ep->maxpacket%4)) {
  85003. + maxxfer_local = ep->maxpacket;
  85004. + total_len = ep->xfer_len;
  85005. + } else {
  85006. + maxxfer_local = ep->maxxfer;
  85007. + total_len = ep->total_len;
  85008. + }
  85009. +
  85010. + ep->desc_cnt = (total_len / maxxfer_local) +
  85011. + ((total_len % maxxfer_local) ? 1 : 0);
  85012. +
  85013. + if (!ep->desc_cnt)
  85014. + ep->desc_cnt = 1;
  85015. +
  85016. + if (ep->desc_cnt > MAX_DMA_DESC_CNT)
  85017. + ep->desc_cnt = MAX_DMA_DESC_CNT;
  85018. +
  85019. + dma_desc = ep->desc_addr;
  85020. + if (maxxfer_local == ep->maxpacket) {
  85021. + if ((total_len % maxxfer_local) &&
  85022. + (total_len/maxxfer_local < MAX_DMA_DESC_CNT)) {
  85023. + xfer_est = (ep->desc_cnt - 1) * maxxfer_local +
  85024. + (total_len % maxxfer_local);
  85025. + } else
  85026. + xfer_est = ep->desc_cnt * maxxfer_local;
  85027. + } else
  85028. + xfer_est = total_len;
  85029. + offset = 0;
  85030. + for (i = 0; i < ep->desc_cnt; ++i) {
  85031. + /** DMA Descriptor Setup */
  85032. + if (xfer_est > maxxfer_local) {
  85033. + dma_desc->status.b.bs = BS_HOST_BUSY;
  85034. + dma_desc->status.b.l = 0;
  85035. + dma_desc->status.b.ioc = 0;
  85036. + dma_desc->status.b.sp = 0;
  85037. + dma_desc->status.b.bytes = maxxfer_local;
  85038. + dma_desc->buf = ep->dma_addr + offset;
  85039. + dma_desc->status.b.sts = 0;
  85040. + dma_desc->status.b.bs = BS_HOST_READY;
  85041. +
  85042. + xfer_est -= maxxfer_local;
  85043. + offset += maxxfer_local;
  85044. + } else {
  85045. + dma_desc->status.b.bs = BS_HOST_BUSY;
  85046. + dma_desc->status.b.l = 1;
  85047. + dma_desc->status.b.ioc = 1;
  85048. + if (ep->is_in) {
  85049. + dma_desc->status.b.sp =
  85050. + (xfer_est %
  85051. + ep->maxpacket) ? 1 : ((ep->
  85052. + sent_zlp) ? 1 : 0);
  85053. + dma_desc->status.b.bytes = xfer_est;
  85054. + } else {
  85055. + if (maxxfer_local == ep->maxpacket)
  85056. + dma_desc->status.b.bytes = xfer_est;
  85057. + else
  85058. + dma_desc->status.b.bytes =
  85059. + xfer_est + ((4 - (xfer_est & 0x3)) & 0x3);
  85060. + }
  85061. +
  85062. + dma_desc->buf = ep->dma_addr + offset;
  85063. + dma_desc->status.b.sts = 0;
  85064. + dma_desc->status.b.bs = BS_HOST_READY;
  85065. + }
  85066. + dma_desc++;
  85067. + }
  85068. +}
  85069. +/**
  85070. + * This function is called when to write ISOC data into appropriate dedicated
  85071. + * periodic FIFO.
  85072. + */
  85073. +static int32_t write_isoc_tx_fifo(dwc_otg_core_if_t * core_if, dwc_ep_t * dwc_ep)
  85074. +{
  85075. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  85076. + dwc_otg_dev_in_ep_regs_t *ep_regs;
  85077. + dtxfsts_data_t txstatus = {.d32 = 0 };
  85078. + uint32_t len = 0;
  85079. + int epnum = dwc_ep->num;
  85080. + int dwords;
  85081. +
  85082. + DWC_DEBUGPL(DBG_PCD, "Dedicated TxFifo Empty: %d \n", epnum);
  85083. +
  85084. + ep_regs = core_if->dev_if->in_ep_regs[epnum];
  85085. +
  85086. + len = dwc_ep->xfer_len - dwc_ep->xfer_count;
  85087. +
  85088. + if (len > dwc_ep->maxpacket) {
  85089. + len = dwc_ep->maxpacket;
  85090. + }
  85091. +
  85092. + dwords = (len + 3) / 4;
  85093. +
  85094. + /* While there is space in the queue and space in the FIFO and
  85095. + * More data to tranfer, Write packets to the Tx FIFO */
  85096. + txstatus.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dtxfsts);
  85097. + DWC_DEBUGPL(DBG_PCDV, "b4 dtxfsts[%d]=0x%08x\n", epnum, txstatus.d32);
  85098. +
  85099. + while (txstatus.b.txfspcavail > dwords &&
  85100. + dwc_ep->xfer_count < dwc_ep->xfer_len && dwc_ep->xfer_len != 0) {
  85101. + /* Write the FIFO */
  85102. + dwc_otg_ep_write_packet(core_if, dwc_ep, 0);
  85103. +
  85104. + len = dwc_ep->xfer_len - dwc_ep->xfer_count;
  85105. + if (len > dwc_ep->maxpacket) {
  85106. + len = dwc_ep->maxpacket;
  85107. + }
  85108. +
  85109. + dwords = (len + 3) / 4;
  85110. + txstatus.d32 =
  85111. + DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dtxfsts);
  85112. + DWC_DEBUGPL(DBG_PCDV, "dtxfsts[%d]=0x%08x\n", epnum,
  85113. + txstatus.d32);
  85114. + }
  85115. +
  85116. + DWC_DEBUGPL(DBG_PCDV, "b4 dtxfsts[%d]=0x%08x\n", epnum,
  85117. + DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dtxfsts));
  85118. +
  85119. + return 1;
  85120. +}
  85121. +/**
  85122. + * This function does the setup for a data transfer for an EP and
  85123. + * starts the transfer. For an IN transfer, the packets will be
  85124. + * loaded into the appropriate Tx FIFO in the ISR. For OUT transfers,
  85125. + * the packets are unloaded from the Rx FIFO in the ISR. the ISR.
  85126. + *
  85127. + * @param core_if Programming view of DWC_otg controller.
  85128. + * @param ep The EP to start the transfer on.
  85129. + */
  85130. +
  85131. +void dwc_otg_ep_start_transfer(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  85132. +{
  85133. + depctl_data_t depctl;
  85134. + deptsiz_data_t deptsiz;
  85135. + gintmsk_data_t intr_mask = {.d32 = 0 };
  85136. +
  85137. + DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "%s()\n", __func__);
  85138. + DWC_DEBUGPL(DBG_PCD, "ep%d-%s xfer_len=%d xfer_cnt=%d "
  85139. + "xfer_buff=%p start_xfer_buff=%p, total_len = %d\n",
  85140. + ep->num, (ep->is_in ? "IN" : "OUT"), ep->xfer_len,
  85141. + ep->xfer_count, ep->xfer_buff, ep->start_xfer_buff,
  85142. + ep->total_len);
  85143. + /* IN endpoint */
  85144. + if (ep->is_in == 1) {
  85145. + dwc_otg_dev_in_ep_regs_t *in_regs =
  85146. + core_if->dev_if->in_ep_regs[ep->num];
  85147. +
  85148. + gnptxsts_data_t gtxstatus;
  85149. +
  85150. + gtxstatus.d32 =
  85151. + DWC_READ_REG32(&core_if->core_global_regs->gnptxsts);
  85152. +
  85153. + if (core_if->en_multiple_tx_fifo == 0
  85154. + && gtxstatus.b.nptxqspcavail == 0 && !core_if->dma_enable) {
  85155. +#ifdef DEBUG
  85156. + DWC_PRINTF("TX Queue Full (0x%0x)\n", gtxstatus.d32);
  85157. +#endif
  85158. + return;
  85159. + }
  85160. +
  85161. + depctl.d32 = DWC_READ_REG32(&(in_regs->diepctl));
  85162. + deptsiz.d32 = DWC_READ_REG32(&(in_regs->dieptsiz));
  85163. +
  85164. + if (ep->maxpacket > ep->maxxfer / MAX_PKT_CNT)
  85165. + ep->xfer_len += (ep->maxxfer < (ep->total_len - ep->xfer_len)) ?
  85166. + ep->maxxfer : (ep->total_len - ep->xfer_len);
  85167. + else
  85168. + ep->xfer_len += (MAX_PKT_CNT * ep->maxpacket < (ep->total_len - ep->xfer_len)) ?
  85169. + MAX_PKT_CNT * ep->maxpacket : (ep->total_len - ep->xfer_len);
  85170. +
  85171. +
  85172. + /* Zero Length Packet? */
  85173. + if ((ep->xfer_len - ep->xfer_count) == 0) {
  85174. + deptsiz.b.xfersize = 0;
  85175. + deptsiz.b.pktcnt = 1;
  85176. + } else {
  85177. + /* Program the transfer size and packet count
  85178. + * as follows: xfersize = N * maxpacket +
  85179. + * short_packet pktcnt = N + (short_packet
  85180. + * exist ? 1 : 0)
  85181. + */
  85182. + deptsiz.b.xfersize = ep->xfer_len - ep->xfer_count;
  85183. + deptsiz.b.pktcnt =
  85184. + (ep->xfer_len - ep->xfer_count - 1 +
  85185. + ep->maxpacket) / ep->maxpacket;
  85186. + if (deptsiz.b.pktcnt > MAX_PKT_CNT) {
  85187. + deptsiz.b.pktcnt = MAX_PKT_CNT;
  85188. + deptsiz.b.xfersize = deptsiz.b.pktcnt * ep->maxpacket;
  85189. + }
  85190. + if (ep->type == DWC_OTG_EP_TYPE_ISOC)
  85191. + deptsiz.b.mc = deptsiz.b.pktcnt;
  85192. + }
  85193. +
  85194. + /* Write the DMA register */
  85195. + if (core_if->dma_enable) {
  85196. + if (core_if->dma_desc_enable == 0) {
  85197. + if (ep->type != DWC_OTG_EP_TYPE_ISOC)
  85198. + deptsiz.b.mc = 1;
  85199. + DWC_WRITE_REG32(&in_regs->dieptsiz,
  85200. + deptsiz.d32);
  85201. + DWC_WRITE_REG32(&(in_regs->diepdma),
  85202. + (uint32_t) ep->dma_addr);
  85203. + } else {
  85204. +#ifdef DWC_UTE_CFI
  85205. + /* The descriptor chain should be already initialized by now */
  85206. + if (ep->buff_mode != BM_STANDARD) {
  85207. + DWC_WRITE_REG32(&in_regs->diepdma,
  85208. + ep->descs_dma_addr);
  85209. + } else {
  85210. +#endif
  85211. + init_dma_desc_chain(core_if, ep);
  85212. + /** DIEPDMAn Register write */
  85213. + DWC_WRITE_REG32(&in_regs->diepdma,
  85214. + ep->dma_desc_addr);
  85215. +#ifdef DWC_UTE_CFI
  85216. + }
  85217. +#endif
  85218. + }
  85219. + } else {
  85220. + DWC_WRITE_REG32(&in_regs->dieptsiz, deptsiz.d32);
  85221. + if (ep->type != DWC_OTG_EP_TYPE_ISOC) {
  85222. + /**
  85223. + * Enable the Non-Periodic Tx FIFO empty interrupt,
  85224. + * or the Tx FIFO epmty interrupt in dedicated Tx FIFO mode,
  85225. + * the data will be written into the fifo by the ISR.
  85226. + */
  85227. + if (core_if->en_multiple_tx_fifo == 0) {
  85228. + intr_mask.b.nptxfempty = 1;
  85229. + DWC_MODIFY_REG32
  85230. + (&core_if->core_global_regs->gintmsk,
  85231. + intr_mask.d32, intr_mask.d32);
  85232. + } else {
  85233. + /* Enable the Tx FIFO Empty Interrupt for this EP */
  85234. + if (ep->xfer_len > 0) {
  85235. + uint32_t fifoemptymsk = 0;
  85236. + fifoemptymsk = 1 << ep->num;
  85237. + DWC_MODIFY_REG32
  85238. + (&core_if->dev_if->dev_global_regs->dtknqr4_fifoemptymsk,
  85239. + 0, fifoemptymsk);
  85240. +
  85241. + }
  85242. + }
  85243. + } else {
  85244. + write_isoc_tx_fifo(core_if, ep);
  85245. + }
  85246. + }
  85247. + if (!core_if->core_params->en_multiple_tx_fifo && core_if->dma_enable)
  85248. + depctl.b.nextep = core_if->nextep_seq[ep->num];
  85249. +
  85250. + if (ep->type == DWC_OTG_EP_TYPE_ISOC) {
  85251. + dsts_data_t dsts = {.d32 = 0};
  85252. + if (ep->bInterval == 1) {
  85253. + dsts.d32 =
  85254. + DWC_READ_REG32(&core_if->dev_if->
  85255. + dev_global_regs->dsts);
  85256. + ep->frame_num = dsts.b.soffn + ep->bInterval;
  85257. + if (ep->frame_num > 0x3FFF) {
  85258. + ep->frm_overrun = 1;
  85259. + ep->frame_num &= 0x3FFF;
  85260. + } else
  85261. + ep->frm_overrun = 0;
  85262. + if (ep->frame_num & 0x1) {
  85263. + depctl.b.setd1pid = 1;
  85264. + } else {
  85265. + depctl.b.setd0pid = 1;
  85266. + }
  85267. + }
  85268. + }
  85269. + /* EP enable, IN data in FIFO */
  85270. + depctl.b.cnak = 1;
  85271. + depctl.b.epena = 1;
  85272. + DWC_WRITE_REG32(&in_regs->diepctl, depctl.d32);
  85273. +
  85274. + } else {
  85275. + /* OUT endpoint */
  85276. + dwc_otg_dev_out_ep_regs_t *out_regs =
  85277. + core_if->dev_if->out_ep_regs[ep->num];
  85278. +
  85279. + depctl.d32 = DWC_READ_REG32(&(out_regs->doepctl));
  85280. + deptsiz.d32 = DWC_READ_REG32(&(out_regs->doeptsiz));
  85281. +
  85282. + if (!core_if->dma_desc_enable) {
  85283. + if (ep->maxpacket > ep->maxxfer / MAX_PKT_CNT)
  85284. + ep->xfer_len += (ep->maxxfer < (ep->total_len - ep->xfer_len)) ?
  85285. + ep->maxxfer : (ep->total_len - ep->xfer_len);
  85286. + else
  85287. + ep->xfer_len += (MAX_PKT_CNT * ep->maxpacket < (ep->total_len
  85288. + - ep->xfer_len)) ? MAX_PKT_CNT * ep->maxpacket : (ep->total_len - ep->xfer_len);
  85289. + }
  85290. +
  85291. + /* Program the transfer size and packet count as follows:
  85292. + *
  85293. + * pktcnt = N
  85294. + * xfersize = N * maxpacket
  85295. + */
  85296. + if ((ep->xfer_len - ep->xfer_count) == 0) {
  85297. + /* Zero Length Packet */
  85298. + deptsiz.b.xfersize = ep->maxpacket;
  85299. + deptsiz.b.pktcnt = 1;
  85300. + } else {
  85301. + deptsiz.b.pktcnt =
  85302. + (ep->xfer_len - ep->xfer_count +
  85303. + (ep->maxpacket - 1)) / ep->maxpacket;
  85304. + if (deptsiz.b.pktcnt > MAX_PKT_CNT) {
  85305. + deptsiz.b.pktcnt = MAX_PKT_CNT;
  85306. + }
  85307. + if (!core_if->dma_desc_enable) {
  85308. + ep->xfer_len =
  85309. + deptsiz.b.pktcnt * ep->maxpacket + ep->xfer_count;
  85310. + }
  85311. + deptsiz.b.xfersize = ep->xfer_len - ep->xfer_count;
  85312. + }
  85313. +
  85314. + DWC_DEBUGPL(DBG_PCDV, "ep%d xfersize=%d pktcnt=%d\n",
  85315. + ep->num, deptsiz.b.xfersize, deptsiz.b.pktcnt);
  85316. +
  85317. + if (core_if->dma_enable) {
  85318. + if (!core_if->dma_desc_enable) {
  85319. + DWC_WRITE_REG32(&out_regs->doeptsiz,
  85320. + deptsiz.d32);
  85321. +
  85322. + DWC_WRITE_REG32(&(out_regs->doepdma),
  85323. + (uint32_t) ep->dma_addr);
  85324. + } else {
  85325. +#ifdef DWC_UTE_CFI
  85326. + /* The descriptor chain should be already initialized by now */
  85327. + if (ep->buff_mode != BM_STANDARD) {
  85328. + DWC_WRITE_REG32(&out_regs->doepdma,
  85329. + ep->descs_dma_addr);
  85330. + } else {
  85331. +#endif
  85332. + /** This is used for interrupt out transfers*/
  85333. + if (!ep->xfer_len)
  85334. + ep->xfer_len = ep->total_len;
  85335. + init_dma_desc_chain(core_if, ep);
  85336. +
  85337. + if (core_if->core_params->dev_out_nak) {
  85338. + if (ep->type == DWC_OTG_EP_TYPE_BULK) {
  85339. + deptsiz.b.pktcnt = (ep->total_len +
  85340. + (ep->maxpacket - 1)) / ep->maxpacket;
  85341. + deptsiz.b.xfersize = ep->total_len;
  85342. + /* Remember initial value of doeptsiz */
  85343. + core_if->start_doeptsiz_val[ep->num] = deptsiz.d32;
  85344. + DWC_WRITE_REG32(&out_regs->doeptsiz,
  85345. + deptsiz.d32);
  85346. + }
  85347. + }
  85348. + /** DOEPDMAn Register write */
  85349. + DWC_WRITE_REG32(&out_regs->doepdma,
  85350. + ep->dma_desc_addr);
  85351. +#ifdef DWC_UTE_CFI
  85352. + }
  85353. +#endif
  85354. + }
  85355. + } else {
  85356. + DWC_WRITE_REG32(&out_regs->doeptsiz, deptsiz.d32);
  85357. + }
  85358. +
  85359. + if (ep->type == DWC_OTG_EP_TYPE_ISOC) {
  85360. + dsts_data_t dsts = {.d32 = 0};
  85361. + if (ep->bInterval == 1) {
  85362. + dsts.d32 =
  85363. + DWC_READ_REG32(&core_if->dev_if->
  85364. + dev_global_regs->dsts);
  85365. + ep->frame_num = dsts.b.soffn + ep->bInterval;
  85366. + if (ep->frame_num > 0x3FFF) {
  85367. + ep->frm_overrun = 1;
  85368. + ep->frame_num &= 0x3FFF;
  85369. + } else
  85370. + ep->frm_overrun = 0;
  85371. +
  85372. + if (ep->frame_num & 0x1) {
  85373. + depctl.b.setd1pid = 1;
  85374. + } else {
  85375. + depctl.b.setd0pid = 1;
  85376. + }
  85377. + }
  85378. + }
  85379. +
  85380. + /* EP enable */
  85381. + depctl.b.cnak = 1;
  85382. + depctl.b.epena = 1;
  85383. +
  85384. + DWC_WRITE_REG32(&out_regs->doepctl, depctl.d32);
  85385. +
  85386. + DWC_DEBUGPL(DBG_PCD, "DOEPCTL=%08x DOEPTSIZ=%08x\n",
  85387. + DWC_READ_REG32(&out_regs->doepctl),
  85388. + DWC_READ_REG32(&out_regs->doeptsiz));
  85389. + DWC_DEBUGPL(DBG_PCD, "DAINTMSK=%08x GINTMSK=%08x\n",
  85390. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->
  85391. + daintmsk),
  85392. + DWC_READ_REG32(&core_if->core_global_regs->
  85393. + gintmsk));
  85394. +
  85395. + /* Timer is scheduling only for out bulk transfers for
  85396. + * "Device DDMA OUT NAK Enhancement" feature to inform user
  85397. + * about received data payload in case of timeout
  85398. + */
  85399. + if (core_if->core_params->dev_out_nak) {
  85400. + if (ep->type == DWC_OTG_EP_TYPE_BULK) {
  85401. + core_if->ep_xfer_info[ep->num].core_if = core_if;
  85402. + core_if->ep_xfer_info[ep->num].ep = ep;
  85403. + core_if->ep_xfer_info[ep->num].state = 1;
  85404. +
  85405. + /* Start a timer for this transfer. */
  85406. + DWC_TIMER_SCHEDULE(core_if->ep_xfer_timer[ep->num], 10000);
  85407. + }
  85408. + }
  85409. + }
  85410. +}
  85411. +
  85412. +/**
  85413. + * This function setup a zero length transfer in Buffer DMA and
  85414. + * Slave modes for usb requests with zero field set
  85415. + *
  85416. + * @param core_if Programming view of DWC_otg controller.
  85417. + * @param ep The EP to start the transfer on.
  85418. + *
  85419. + */
  85420. +void dwc_otg_ep_start_zl_transfer(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  85421. +{
  85422. +
  85423. + depctl_data_t depctl;
  85424. + deptsiz_data_t deptsiz;
  85425. + gintmsk_data_t intr_mask = {.d32 = 0 };
  85426. +
  85427. + DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "%s()\n", __func__);
  85428. + DWC_PRINTF("zero length transfer is called\n");
  85429. +
  85430. + /* IN endpoint */
  85431. + if (ep->is_in == 1) {
  85432. + dwc_otg_dev_in_ep_regs_t *in_regs =
  85433. + core_if->dev_if->in_ep_regs[ep->num];
  85434. +
  85435. + depctl.d32 = DWC_READ_REG32(&(in_regs->diepctl));
  85436. + deptsiz.d32 = DWC_READ_REG32(&(in_regs->dieptsiz));
  85437. +
  85438. + deptsiz.b.xfersize = 0;
  85439. + deptsiz.b.pktcnt = 1;
  85440. +
  85441. + /* Write the DMA register */
  85442. + if (core_if->dma_enable) {
  85443. + if (core_if->dma_desc_enable == 0) {
  85444. + deptsiz.b.mc = 1;
  85445. + DWC_WRITE_REG32(&in_regs->dieptsiz,
  85446. + deptsiz.d32);
  85447. + DWC_WRITE_REG32(&(in_regs->diepdma),
  85448. + (uint32_t) ep->dma_addr);
  85449. + }
  85450. + } else {
  85451. + DWC_WRITE_REG32(&in_regs->dieptsiz, deptsiz.d32);
  85452. + /**
  85453. + * Enable the Non-Periodic Tx FIFO empty interrupt,
  85454. + * or the Tx FIFO epmty interrupt in dedicated Tx FIFO mode,
  85455. + * the data will be written into the fifo by the ISR.
  85456. + */
  85457. + if (core_if->en_multiple_tx_fifo == 0) {
  85458. + intr_mask.b.nptxfempty = 1;
  85459. + DWC_MODIFY_REG32(&core_if->
  85460. + core_global_regs->gintmsk,
  85461. + intr_mask.d32, intr_mask.d32);
  85462. + } else {
  85463. + /* Enable the Tx FIFO Empty Interrupt for this EP */
  85464. + if (ep->xfer_len > 0) {
  85465. + uint32_t fifoemptymsk = 0;
  85466. + fifoemptymsk = 1 << ep->num;
  85467. + DWC_MODIFY_REG32(&core_if->
  85468. + dev_if->dev_global_regs->dtknqr4_fifoemptymsk,
  85469. + 0, fifoemptymsk);
  85470. + }
  85471. + }
  85472. + }
  85473. +
  85474. + if (!core_if->core_params->en_multiple_tx_fifo && core_if->dma_enable)
  85475. + depctl.b.nextep = core_if->nextep_seq[ep->num];
  85476. + /* EP enable, IN data in FIFO */
  85477. + depctl.b.cnak = 1;
  85478. + depctl.b.epena = 1;
  85479. + DWC_WRITE_REG32(&in_regs->diepctl, depctl.d32);
  85480. +
  85481. + } else {
  85482. + /* OUT endpoint */
  85483. + dwc_otg_dev_out_ep_regs_t *out_regs =
  85484. + core_if->dev_if->out_ep_regs[ep->num];
  85485. +
  85486. + depctl.d32 = DWC_READ_REG32(&(out_regs->doepctl));
  85487. + deptsiz.d32 = DWC_READ_REG32(&(out_regs->doeptsiz));
  85488. +
  85489. + /* Zero Length Packet */
  85490. + deptsiz.b.xfersize = ep->maxpacket;
  85491. + deptsiz.b.pktcnt = 1;
  85492. +
  85493. + if (core_if->dma_enable) {
  85494. + if (!core_if->dma_desc_enable) {
  85495. + DWC_WRITE_REG32(&out_regs->doeptsiz,
  85496. + deptsiz.d32);
  85497. +
  85498. + DWC_WRITE_REG32(&(out_regs->doepdma),
  85499. + (uint32_t) ep->dma_addr);
  85500. + }
  85501. + } else {
  85502. + DWC_WRITE_REG32(&out_regs->doeptsiz, deptsiz.d32);
  85503. + }
  85504. +
  85505. + /* EP enable */
  85506. + depctl.b.cnak = 1;
  85507. + depctl.b.epena = 1;
  85508. +
  85509. + DWC_WRITE_REG32(&out_regs->doepctl, depctl.d32);
  85510. +
  85511. + }
  85512. +}
  85513. +
  85514. +/**
  85515. + * This function does the setup for a data transfer for EP0 and starts
  85516. + * the transfer. For an IN transfer, the packets will be loaded into
  85517. + * the appropriate Tx FIFO in the ISR. For OUT transfers, the packets are
  85518. + * unloaded from the Rx FIFO in the ISR.
  85519. + *
  85520. + * @param core_if Programming view of DWC_otg controller.
  85521. + * @param ep The EP0 data.
  85522. + */
  85523. +void dwc_otg_ep0_start_transfer(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  85524. +{
  85525. + depctl_data_t depctl;
  85526. + deptsiz0_data_t deptsiz;
  85527. + gintmsk_data_t intr_mask = {.d32 = 0 };
  85528. + dwc_otg_dev_dma_desc_t *dma_desc;
  85529. +
  85530. + DWC_DEBUGPL(DBG_PCD, "ep%d-%s xfer_len=%d xfer_cnt=%d "
  85531. + "xfer_buff=%p start_xfer_buff=%p \n",
  85532. + ep->num, (ep->is_in ? "IN" : "OUT"), ep->xfer_len,
  85533. + ep->xfer_count, ep->xfer_buff, ep->start_xfer_buff);
  85534. +
  85535. + ep->total_len = ep->xfer_len;
  85536. +
  85537. + /* IN endpoint */
  85538. + if (ep->is_in == 1) {
  85539. + dwc_otg_dev_in_ep_regs_t *in_regs =
  85540. + core_if->dev_if->in_ep_regs[0];
  85541. +
  85542. + gnptxsts_data_t gtxstatus;
  85543. +
  85544. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  85545. + depctl.d32 = DWC_READ_REG32(&in_regs->diepctl);
  85546. + if (depctl.b.epena)
  85547. + return;
  85548. + }
  85549. +
  85550. + gtxstatus.d32 =
  85551. + DWC_READ_REG32(&core_if->core_global_regs->gnptxsts);
  85552. +
  85553. + /* If dedicated FIFO every time flush fifo before enable ep*/
  85554. + if (core_if->en_multiple_tx_fifo && core_if->snpsid >= OTG_CORE_REV_3_00a)
  85555. + dwc_otg_flush_tx_fifo(core_if, ep->tx_fifo_num);
  85556. +
  85557. + if (core_if->en_multiple_tx_fifo == 0
  85558. + && gtxstatus.b.nptxqspcavail == 0
  85559. + && !core_if->dma_enable) {
  85560. +#ifdef DEBUG
  85561. + deptsiz.d32 = DWC_READ_REG32(&in_regs->dieptsiz);
  85562. + DWC_DEBUGPL(DBG_PCD, "DIEPCTL0=%0x\n",
  85563. + DWC_READ_REG32(&in_regs->diepctl));
  85564. + DWC_DEBUGPL(DBG_PCD, "DIEPTSIZ0=%0x (sz=%d, pcnt=%d)\n",
  85565. + deptsiz.d32,
  85566. + deptsiz.b.xfersize, deptsiz.b.pktcnt);
  85567. + DWC_PRINTF("TX Queue or FIFO Full (0x%0x)\n",
  85568. + gtxstatus.d32);
  85569. +#endif
  85570. + return;
  85571. + }
  85572. +
  85573. + depctl.d32 = DWC_READ_REG32(&in_regs->diepctl);
  85574. + deptsiz.d32 = DWC_READ_REG32(&in_regs->dieptsiz);
  85575. +
  85576. + /* Zero Length Packet? */
  85577. + if (ep->xfer_len == 0) {
  85578. + deptsiz.b.xfersize = 0;
  85579. + deptsiz.b.pktcnt = 1;
  85580. + } else {
  85581. + /* Program the transfer size and packet count
  85582. + * as follows: xfersize = N * maxpacket +
  85583. + * short_packet pktcnt = N + (short_packet
  85584. + * exist ? 1 : 0)
  85585. + */
  85586. + if (ep->xfer_len > ep->maxpacket) {
  85587. + ep->xfer_len = ep->maxpacket;
  85588. + deptsiz.b.xfersize = ep->maxpacket;
  85589. + } else {
  85590. + deptsiz.b.xfersize = ep->xfer_len;
  85591. + }
  85592. + deptsiz.b.pktcnt = 1;
  85593. +
  85594. + }
  85595. + DWC_DEBUGPL(DBG_PCDV,
  85596. + "IN len=%d xfersize=%d pktcnt=%d [%08x]\n",
  85597. + ep->xfer_len, deptsiz.b.xfersize, deptsiz.b.pktcnt,
  85598. + deptsiz.d32);
  85599. +
  85600. + /* Write the DMA register */
  85601. + if (core_if->dma_enable) {
  85602. + if (core_if->dma_desc_enable == 0) {
  85603. + DWC_WRITE_REG32(&in_regs->dieptsiz,
  85604. + deptsiz.d32);
  85605. +
  85606. + DWC_WRITE_REG32(&(in_regs->diepdma),
  85607. + (uint32_t) ep->dma_addr);
  85608. + } else {
  85609. + dma_desc = core_if->dev_if->in_desc_addr;
  85610. +
  85611. + /** DMA Descriptor Setup */
  85612. + dma_desc->status.b.bs = BS_HOST_BUSY;
  85613. + dma_desc->status.b.l = 1;
  85614. + dma_desc->status.b.ioc = 1;
  85615. + dma_desc->status.b.sp =
  85616. + (ep->xfer_len == ep->maxpacket) ? 0 : 1;
  85617. + dma_desc->status.b.bytes = ep->xfer_len;
  85618. + dma_desc->buf = ep->dma_addr;
  85619. + dma_desc->status.b.sts = 0;
  85620. + dma_desc->status.b.bs = BS_HOST_READY;
  85621. +
  85622. + /** DIEPDMA0 Register write */
  85623. + DWC_WRITE_REG32(&in_regs->diepdma,
  85624. + core_if->
  85625. + dev_if->dma_in_desc_addr);
  85626. + }
  85627. + } else {
  85628. + DWC_WRITE_REG32(&in_regs->dieptsiz, deptsiz.d32);
  85629. + }
  85630. +
  85631. + if (!core_if->core_params->en_multiple_tx_fifo && core_if->dma_enable)
  85632. + depctl.b.nextep = core_if->nextep_seq[ep->num];
  85633. + /* EP enable, IN data in FIFO */
  85634. + depctl.b.cnak = 1;
  85635. + depctl.b.epena = 1;
  85636. + DWC_WRITE_REG32(&in_regs->diepctl, depctl.d32);
  85637. +
  85638. + /**
  85639. + * Enable the Non-Periodic Tx FIFO empty interrupt, the
  85640. + * data will be written into the fifo by the ISR.
  85641. + */
  85642. + if (!core_if->dma_enable) {
  85643. + if (core_if->en_multiple_tx_fifo == 0) {
  85644. + intr_mask.b.nptxfempty = 1;
  85645. + DWC_MODIFY_REG32(&core_if->
  85646. + core_global_regs->gintmsk,
  85647. + intr_mask.d32, intr_mask.d32);
  85648. + } else {
  85649. + /* Enable the Tx FIFO Empty Interrupt for this EP */
  85650. + if (ep->xfer_len > 0) {
  85651. + uint32_t fifoemptymsk = 0;
  85652. + fifoemptymsk |= 1 << ep->num;
  85653. + DWC_MODIFY_REG32(&core_if->
  85654. + dev_if->dev_global_regs->dtknqr4_fifoemptymsk,
  85655. + 0, fifoemptymsk);
  85656. + }
  85657. + }
  85658. + }
  85659. + } else {
  85660. + /* OUT endpoint */
  85661. + dwc_otg_dev_out_ep_regs_t *out_regs =
  85662. + core_if->dev_if->out_ep_regs[0];
  85663. +
  85664. + depctl.d32 = DWC_READ_REG32(&out_regs->doepctl);
  85665. + deptsiz.d32 = DWC_READ_REG32(&out_regs->doeptsiz);
  85666. +
  85667. + /* Program the transfer size and packet count as follows:
  85668. + * xfersize = N * (maxpacket + 4 - (maxpacket % 4))
  85669. + * pktcnt = N */
  85670. + /* Zero Length Packet */
  85671. + deptsiz.b.xfersize = ep->maxpacket;
  85672. + deptsiz.b.pktcnt = 1;
  85673. + if (core_if->snpsid >= OTG_CORE_REV_3_00a)
  85674. + deptsiz.b.supcnt = 3;
  85675. +
  85676. + DWC_DEBUGPL(DBG_PCDV, "len=%d xfersize=%d pktcnt=%d\n",
  85677. + ep->xfer_len, deptsiz.b.xfersize, deptsiz.b.pktcnt);
  85678. +
  85679. + if (core_if->dma_enable) {
  85680. + if (!core_if->dma_desc_enable) {
  85681. + DWC_WRITE_REG32(&out_regs->doeptsiz,
  85682. + deptsiz.d32);
  85683. +
  85684. + DWC_WRITE_REG32(&(out_regs->doepdma),
  85685. + (uint32_t) ep->dma_addr);
  85686. + } else {
  85687. + dma_desc = core_if->dev_if->out_desc_addr;
  85688. +
  85689. + /** DMA Descriptor Setup */
  85690. + dma_desc->status.b.bs = BS_HOST_BUSY;
  85691. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  85692. + dma_desc->status.b.mtrf = 0;
  85693. + dma_desc->status.b.sr = 0;
  85694. + }
  85695. + dma_desc->status.b.l = 1;
  85696. + dma_desc->status.b.ioc = 1;
  85697. + dma_desc->status.b.bytes = ep->maxpacket;
  85698. + dma_desc->buf = ep->dma_addr;
  85699. + dma_desc->status.b.sts = 0;
  85700. + dma_desc->status.b.bs = BS_HOST_READY;
  85701. +
  85702. + /** DOEPDMA0 Register write */
  85703. + DWC_WRITE_REG32(&out_regs->doepdma,
  85704. + core_if->dev_if->
  85705. + dma_out_desc_addr);
  85706. + }
  85707. + } else {
  85708. + DWC_WRITE_REG32(&out_regs->doeptsiz, deptsiz.d32);
  85709. + }
  85710. +
  85711. + /* EP enable */
  85712. + depctl.b.cnak = 1;
  85713. + depctl.b.epena = 1;
  85714. + DWC_WRITE_REG32(&(out_regs->doepctl), depctl.d32);
  85715. + }
  85716. +}
  85717. +
  85718. +/**
  85719. + * This function continues control IN transfers started by
  85720. + * dwc_otg_ep0_start_transfer, when the transfer does not fit in a
  85721. + * single packet. NOTE: The DIEPCTL0/DOEPCTL0 registers only have one
  85722. + * bit for the packet count.
  85723. + *
  85724. + * @param core_if Programming view of DWC_otg controller.
  85725. + * @param ep The EP0 data.
  85726. + */
  85727. +void dwc_otg_ep0_continue_transfer(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  85728. +{
  85729. + depctl_data_t depctl;
  85730. + deptsiz0_data_t deptsiz;
  85731. + gintmsk_data_t intr_mask = {.d32 = 0 };
  85732. + dwc_otg_dev_dma_desc_t *dma_desc;
  85733. +
  85734. + if (ep->is_in == 1) {
  85735. + dwc_otg_dev_in_ep_regs_t *in_regs =
  85736. + core_if->dev_if->in_ep_regs[0];
  85737. + gnptxsts_data_t tx_status = {.d32 = 0 };
  85738. +
  85739. + tx_status.d32 =
  85740. + DWC_READ_REG32(&core_if->core_global_regs->gnptxsts);
  85741. + /** @todo Should there be check for room in the Tx
  85742. + * Status Queue. If not remove the code above this comment. */
  85743. +
  85744. + depctl.d32 = DWC_READ_REG32(&in_regs->diepctl);
  85745. + deptsiz.d32 = DWC_READ_REG32(&in_regs->dieptsiz);
  85746. +
  85747. + /* Program the transfer size and packet count
  85748. + * as follows: xfersize = N * maxpacket +
  85749. + * short_packet pktcnt = N + (short_packet
  85750. + * exist ? 1 : 0)
  85751. + */
  85752. +
  85753. + if (core_if->dma_desc_enable == 0) {
  85754. + deptsiz.b.xfersize =
  85755. + (ep->total_len - ep->xfer_count) >
  85756. + ep->maxpacket ? ep->maxpacket : (ep->total_len -
  85757. + ep->xfer_count);
  85758. + deptsiz.b.pktcnt = 1;
  85759. + if (core_if->dma_enable == 0) {
  85760. + ep->xfer_len += deptsiz.b.xfersize;
  85761. + } else {
  85762. + ep->xfer_len = deptsiz.b.xfersize;
  85763. + }
  85764. + DWC_WRITE_REG32(&in_regs->dieptsiz, deptsiz.d32);
  85765. + } else {
  85766. + ep->xfer_len =
  85767. + (ep->total_len - ep->xfer_count) >
  85768. + ep->maxpacket ? ep->maxpacket : (ep->total_len -
  85769. + ep->xfer_count);
  85770. +
  85771. + dma_desc = core_if->dev_if->in_desc_addr;
  85772. +
  85773. + /** DMA Descriptor Setup */
  85774. + dma_desc->status.b.bs = BS_HOST_BUSY;
  85775. + dma_desc->status.b.l = 1;
  85776. + dma_desc->status.b.ioc = 1;
  85777. + dma_desc->status.b.sp =
  85778. + (ep->xfer_len == ep->maxpacket) ? 0 : 1;
  85779. + dma_desc->status.b.bytes = ep->xfer_len;
  85780. + dma_desc->buf = ep->dma_addr;
  85781. + dma_desc->status.b.sts = 0;
  85782. + dma_desc->status.b.bs = BS_HOST_READY;
  85783. +
  85784. + /** DIEPDMA0 Register write */
  85785. + DWC_WRITE_REG32(&in_regs->diepdma,
  85786. + core_if->dev_if->dma_in_desc_addr);
  85787. + }
  85788. +
  85789. + DWC_DEBUGPL(DBG_PCDV,
  85790. + "IN len=%d xfersize=%d pktcnt=%d [%08x]\n",
  85791. + ep->xfer_len, deptsiz.b.xfersize, deptsiz.b.pktcnt,
  85792. + deptsiz.d32);
  85793. +
  85794. + /* Write the DMA register */
  85795. + if (core_if->hwcfg2.b.architecture == DWC_INT_DMA_ARCH) {
  85796. + if (core_if->dma_desc_enable == 0)
  85797. + DWC_WRITE_REG32(&(in_regs->diepdma),
  85798. + (uint32_t) ep->dma_addr);
  85799. + }
  85800. + if (!core_if->core_params->en_multiple_tx_fifo && core_if->dma_enable)
  85801. + depctl.b.nextep = core_if->nextep_seq[ep->num];
  85802. + /* EP enable, IN data in FIFO */
  85803. + depctl.b.cnak = 1;
  85804. + depctl.b.epena = 1;
  85805. + DWC_WRITE_REG32(&in_regs->diepctl, depctl.d32);
  85806. +
  85807. + /**
  85808. + * Enable the Non-Periodic Tx FIFO empty interrupt, the
  85809. + * data will be written into the fifo by the ISR.
  85810. + */
  85811. + if (!core_if->dma_enable) {
  85812. + if (core_if->en_multiple_tx_fifo == 0) {
  85813. + /* First clear it from GINTSTS */
  85814. + intr_mask.b.nptxfempty = 1;
  85815. + DWC_MODIFY_REG32(&core_if->
  85816. + core_global_regs->gintmsk,
  85817. + intr_mask.d32, intr_mask.d32);
  85818. +
  85819. + } else {
  85820. + /* Enable the Tx FIFO Empty Interrupt for this EP */
  85821. + if (ep->xfer_len > 0) {
  85822. + uint32_t fifoemptymsk = 0;
  85823. + fifoemptymsk |= 1 << ep->num;
  85824. + DWC_MODIFY_REG32(&core_if->
  85825. + dev_if->dev_global_regs->dtknqr4_fifoemptymsk,
  85826. + 0, fifoemptymsk);
  85827. + }
  85828. + }
  85829. + }
  85830. + } else {
  85831. + dwc_otg_dev_out_ep_regs_t *out_regs =
  85832. + core_if->dev_if->out_ep_regs[0];
  85833. +
  85834. + depctl.d32 = DWC_READ_REG32(&out_regs->doepctl);
  85835. + deptsiz.d32 = DWC_READ_REG32(&out_regs->doeptsiz);
  85836. +
  85837. + /* Program the transfer size and packet count
  85838. + * as follows: xfersize = N * maxpacket +
  85839. + * short_packet pktcnt = N + (short_packet
  85840. + * exist ? 1 : 0)
  85841. + */
  85842. + deptsiz.b.xfersize = ep->maxpacket;
  85843. + deptsiz.b.pktcnt = 1;
  85844. +
  85845. + if (core_if->dma_desc_enable == 0) {
  85846. + DWC_WRITE_REG32(&out_regs->doeptsiz, deptsiz.d32);
  85847. + } else {
  85848. + dma_desc = core_if->dev_if->out_desc_addr;
  85849. +
  85850. + /** DMA Descriptor Setup */
  85851. + dma_desc->status.b.bs = BS_HOST_BUSY;
  85852. + dma_desc->status.b.l = 1;
  85853. + dma_desc->status.b.ioc = 1;
  85854. + dma_desc->status.b.bytes = ep->maxpacket;
  85855. + dma_desc->buf = ep->dma_addr;
  85856. + dma_desc->status.b.sts = 0;
  85857. + dma_desc->status.b.bs = BS_HOST_READY;
  85858. +
  85859. + /** DOEPDMA0 Register write */
  85860. + DWC_WRITE_REG32(&out_regs->doepdma,
  85861. + core_if->dev_if->dma_out_desc_addr);
  85862. + }
  85863. +
  85864. + DWC_DEBUGPL(DBG_PCDV,
  85865. + "IN len=%d xfersize=%d pktcnt=%d [%08x]\n",
  85866. + ep->xfer_len, deptsiz.b.xfersize, deptsiz.b.pktcnt,
  85867. + deptsiz.d32);
  85868. +
  85869. + /* Write the DMA register */
  85870. + if (core_if->hwcfg2.b.architecture == DWC_INT_DMA_ARCH) {
  85871. + if (core_if->dma_desc_enable == 0)
  85872. + DWC_WRITE_REG32(&(out_regs->doepdma),
  85873. + (uint32_t) ep->dma_addr);
  85874. +
  85875. + }
  85876. +
  85877. + /* EP enable, IN data in FIFO */
  85878. + depctl.b.cnak = 1;
  85879. + depctl.b.epena = 1;
  85880. + DWC_WRITE_REG32(&out_regs->doepctl, depctl.d32);
  85881. +
  85882. + }
  85883. +}
  85884. +
  85885. +#ifdef DEBUG
  85886. +void dump_msg(const u8 * buf, unsigned int length)
  85887. +{
  85888. + unsigned int start, num, i;
  85889. + char line[52], *p;
  85890. +
  85891. + if (length >= 512)
  85892. + return;
  85893. + start = 0;
  85894. + while (length > 0) {
  85895. + num = length < 16u ? length : 16u;
  85896. + p = line;
  85897. + for (i = 0; i < num; ++i) {
  85898. + if (i == 8)
  85899. + *p++ = ' ';
  85900. + DWC_SPRINTF(p, " %02x", buf[i]);
  85901. + p += 3;
  85902. + }
  85903. + *p = 0;
  85904. + DWC_PRINTF("%6x: %s\n", start, line);
  85905. + buf += num;
  85906. + start += num;
  85907. + length -= num;
  85908. + }
  85909. +}
  85910. +#else
  85911. +static inline void dump_msg(const u8 * buf, unsigned int length)
  85912. +{
  85913. +}
  85914. +#endif
  85915. +
  85916. +/**
  85917. + * This function writes a packet into the Tx FIFO associated with the
  85918. + * EP. For non-periodic EPs the non-periodic Tx FIFO is written. For
  85919. + * periodic EPs the periodic Tx FIFO associated with the EP is written
  85920. + * with all packets for the next micro-frame.
  85921. + *
  85922. + * @param core_if Programming view of DWC_otg controller.
  85923. + * @param ep The EP to write packet for.
  85924. + * @param dma Indicates if DMA is being used.
  85925. + */
  85926. +void dwc_otg_ep_write_packet(dwc_otg_core_if_t * core_if, dwc_ep_t * ep,
  85927. + int dma)
  85928. +{
  85929. + /**
  85930. + * The buffer is padded to DWORD on a per packet basis in
  85931. + * slave/dma mode if the MPS is not DWORD aligned. The last
  85932. + * packet, if short, is also padded to a multiple of DWORD.
  85933. + *
  85934. + * ep->xfer_buff always starts DWORD aligned in memory and is a
  85935. + * multiple of DWORD in length
  85936. + *
  85937. + * ep->xfer_len can be any number of bytes
  85938. + *
  85939. + * ep->xfer_count is a multiple of ep->maxpacket until the last
  85940. + * packet
  85941. + *
  85942. + * FIFO access is DWORD */
  85943. +
  85944. + uint32_t i;
  85945. + uint32_t byte_count;
  85946. + uint32_t dword_count;
  85947. + uint32_t *fifo;
  85948. + uint32_t *data_buff = (uint32_t *) ep->xfer_buff;
  85949. +
  85950. + DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "%s(%p,%p)\n", __func__, core_if,
  85951. + ep);
  85952. + if (ep->xfer_count >= ep->xfer_len) {
  85953. + DWC_WARN("%s() No data for EP%d!!!\n", __func__, ep->num);
  85954. + return;
  85955. + }
  85956. +
  85957. + /* Find the byte length of the packet either short packet or MPS */
  85958. + if ((ep->xfer_len - ep->xfer_count) < ep->maxpacket) {
  85959. + byte_count = ep->xfer_len - ep->xfer_count;
  85960. + } else {
  85961. + byte_count = ep->maxpacket;
  85962. + }
  85963. +
  85964. + /* Find the DWORD length, padded by extra bytes as neccessary if MPS
  85965. + * is not a multiple of DWORD */
  85966. + dword_count = (byte_count + 3) / 4;
  85967. +
  85968. +#ifdef VERBOSE
  85969. + dump_msg(ep->xfer_buff, byte_count);
  85970. +#endif
  85971. +
  85972. + /**@todo NGS Where are the Periodic Tx FIFO addresses
  85973. + * intialized? What should this be? */
  85974. +
  85975. + fifo = core_if->data_fifo[ep->num];
  85976. +
  85977. + DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "fifo=%p buff=%p *p=%08x bc=%d\n",
  85978. + fifo, data_buff, *data_buff, byte_count);
  85979. +
  85980. + if (!dma) {
  85981. + for (i = 0; i < dword_count; i++, data_buff++) {
  85982. + DWC_WRITE_REG32(fifo, *data_buff);
  85983. + }
  85984. + }
  85985. +
  85986. + ep->xfer_count += byte_count;
  85987. + ep->xfer_buff += byte_count;
  85988. + ep->dma_addr += byte_count;
  85989. +}
  85990. +
  85991. +/**
  85992. + * Set the EP STALL.
  85993. + *
  85994. + * @param core_if Programming view of DWC_otg controller.
  85995. + * @param ep The EP to set the stall on.
  85996. + */
  85997. +void dwc_otg_ep_set_stall(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  85998. +{
  85999. + depctl_data_t depctl;
  86000. + volatile uint32_t *depctl_addr;
  86001. +
  86002. + DWC_DEBUGPL(DBG_PCD, "%s ep%d-%s\n", __func__, ep->num,
  86003. + (ep->is_in ? "IN" : "OUT"));
  86004. +
  86005. + if (ep->is_in == 1) {
  86006. + depctl_addr = &(core_if->dev_if->in_ep_regs[ep->num]->diepctl);
  86007. + depctl.d32 = DWC_READ_REG32(depctl_addr);
  86008. +
  86009. + /* set the disable and stall bits */
  86010. + if (depctl.b.epena) {
  86011. + depctl.b.epdis = 1;
  86012. + }
  86013. + depctl.b.stall = 1;
  86014. + DWC_WRITE_REG32(depctl_addr, depctl.d32);
  86015. + } else {
  86016. + depctl_addr = &(core_if->dev_if->out_ep_regs[ep->num]->doepctl);
  86017. + depctl.d32 = DWC_READ_REG32(depctl_addr);
  86018. +
  86019. + /* set the stall bit */
  86020. + depctl.b.stall = 1;
  86021. + DWC_WRITE_REG32(depctl_addr, depctl.d32);
  86022. + }
  86023. +
  86024. + DWC_DEBUGPL(DBG_PCD, "DEPCTL=%0x\n", DWC_READ_REG32(depctl_addr));
  86025. +
  86026. + return;
  86027. +}
  86028. +
  86029. +/**
  86030. + * Clear the EP STALL.
  86031. + *
  86032. + * @param core_if Programming view of DWC_otg controller.
  86033. + * @param ep The EP to clear stall from.
  86034. + */
  86035. +void dwc_otg_ep_clear_stall(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  86036. +{
  86037. + depctl_data_t depctl;
  86038. + volatile uint32_t *depctl_addr;
  86039. +
  86040. + DWC_DEBUGPL(DBG_PCD, "%s ep%d-%s\n", __func__, ep->num,
  86041. + (ep->is_in ? "IN" : "OUT"));
  86042. +
  86043. + if (ep->is_in == 1) {
  86044. + depctl_addr = &(core_if->dev_if->in_ep_regs[ep->num]->diepctl);
  86045. + } else {
  86046. + depctl_addr = &(core_if->dev_if->out_ep_regs[ep->num]->doepctl);
  86047. + }
  86048. +
  86049. + depctl.d32 = DWC_READ_REG32(depctl_addr);
  86050. +
  86051. + /* clear the stall bits */
  86052. + depctl.b.stall = 0;
  86053. +
  86054. + /*
  86055. + * USB Spec 9.4.5: For endpoints using data toggle, regardless
  86056. + * of whether an endpoint has the Halt feature set, a
  86057. + * ClearFeature(ENDPOINT_HALT) request always results in the
  86058. + * data toggle being reinitialized to DATA0.
  86059. + */
  86060. + if (ep->type == DWC_OTG_EP_TYPE_INTR ||
  86061. + ep->type == DWC_OTG_EP_TYPE_BULK) {
  86062. + depctl.b.setd0pid = 1; /* DATA0 */
  86063. + }
  86064. +
  86065. + DWC_WRITE_REG32(depctl_addr, depctl.d32);
  86066. + DWC_DEBUGPL(DBG_PCD, "DEPCTL=%0x\n", DWC_READ_REG32(depctl_addr));
  86067. + return;
  86068. +}
  86069. +
  86070. +/**
  86071. + * This function reads a packet from the Rx FIFO into the destination
  86072. + * buffer. To read SETUP data use dwc_otg_read_setup_packet.
  86073. + *
  86074. + * @param core_if Programming view of DWC_otg controller.
  86075. + * @param dest Destination buffer for the packet.
  86076. + * @param bytes Number of bytes to copy to the destination.
  86077. + */
  86078. +void dwc_otg_read_packet(dwc_otg_core_if_t * core_if,
  86079. + uint8_t * dest, uint16_t bytes)
  86080. +{
  86081. + int i;
  86082. + int word_count = (bytes + 3) / 4;
  86083. +
  86084. + volatile uint32_t *fifo = core_if->data_fifo[0];
  86085. + uint32_t *data_buff = (uint32_t *) dest;
  86086. +
  86087. + /**
  86088. + * @todo Account for the case where _dest is not dword aligned. This
  86089. + * requires reading data from the FIFO into a uint32_t temp buffer,
  86090. + * then moving it into the data buffer.
  86091. + */
  86092. +
  86093. + DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "%s(%p,%p,%d)\n", __func__,
  86094. + core_if, dest, bytes);
  86095. +
  86096. + for (i = 0; i < word_count; i++, data_buff++) {
  86097. + *data_buff = DWC_READ_REG32(fifo);
  86098. + }
  86099. +
  86100. + return;
  86101. +}
  86102. +
  86103. +/**
  86104. + * This functions reads the device registers and prints them
  86105. + *
  86106. + * @param core_if Programming view of DWC_otg controller.
  86107. + */
  86108. +void dwc_otg_dump_dev_registers(dwc_otg_core_if_t * core_if)
  86109. +{
  86110. + int i;
  86111. + volatile uint32_t *addr;
  86112. +
  86113. + DWC_PRINTF("Device Global Registers\n");
  86114. + addr = &core_if->dev_if->dev_global_regs->dcfg;
  86115. + DWC_PRINTF("DCFG @0x%08lX : 0x%08X\n",
  86116. + (unsigned long)addr, DWC_READ_REG32(addr));
  86117. + addr = &core_if->dev_if->dev_global_regs->dctl;
  86118. + DWC_PRINTF("DCTL @0x%08lX : 0x%08X\n",
  86119. + (unsigned long)addr, DWC_READ_REG32(addr));
  86120. + addr = &core_if->dev_if->dev_global_regs->dsts;
  86121. + DWC_PRINTF("DSTS @0x%08lX : 0x%08X\n",
  86122. + (unsigned long)addr, DWC_READ_REG32(addr));
  86123. + addr = &core_if->dev_if->dev_global_regs->diepmsk;
  86124. + DWC_PRINTF("DIEPMSK @0x%08lX : 0x%08X\n", (unsigned long)addr,
  86125. + DWC_READ_REG32(addr));
  86126. + addr = &core_if->dev_if->dev_global_regs->doepmsk;
  86127. + DWC_PRINTF("DOEPMSK @0x%08lX : 0x%08X\n", (unsigned long)addr,
  86128. + DWC_READ_REG32(addr));
  86129. + addr = &core_if->dev_if->dev_global_regs->daint;
  86130. + DWC_PRINTF("DAINT @0x%08lX : 0x%08X\n", (unsigned long)addr,
  86131. + DWC_READ_REG32(addr));
  86132. + addr = &core_if->dev_if->dev_global_regs->daintmsk;
  86133. + DWC_PRINTF("DAINTMSK @0x%08lX : 0x%08X\n", (unsigned long)addr,
  86134. + DWC_READ_REG32(addr));
  86135. + addr = &core_if->dev_if->dev_global_regs->dtknqr1;
  86136. + DWC_PRINTF("DTKNQR1 @0x%08lX : 0x%08X\n", (unsigned long)addr,
  86137. + DWC_READ_REG32(addr));
  86138. + if (core_if->hwcfg2.b.dev_token_q_depth > 6) {
  86139. + addr = &core_if->dev_if->dev_global_regs->dtknqr2;
  86140. + DWC_PRINTF("DTKNQR2 @0x%08lX : 0x%08X\n",
  86141. + (unsigned long)addr, DWC_READ_REG32(addr));
  86142. + }
  86143. +
  86144. + addr = &core_if->dev_if->dev_global_regs->dvbusdis;
  86145. + DWC_PRINTF("DVBUSID @0x%08lX : 0x%08X\n", (unsigned long)addr,
  86146. + DWC_READ_REG32(addr));
  86147. +
  86148. + addr = &core_if->dev_if->dev_global_regs->dvbuspulse;
  86149. + DWC_PRINTF("DVBUSPULSE @0x%08lX : 0x%08X\n",
  86150. + (unsigned long)addr, DWC_READ_REG32(addr));
  86151. +
  86152. + addr = &core_if->dev_if->dev_global_regs->dtknqr3_dthrctl;
  86153. + DWC_PRINTF("DTKNQR3_DTHRCTL @0x%08lX : 0x%08X\n",
  86154. + (unsigned long)addr, DWC_READ_REG32(addr));
  86155. +
  86156. + if (core_if->hwcfg2.b.dev_token_q_depth > 22) {
  86157. + addr = &core_if->dev_if->dev_global_regs->dtknqr4_fifoemptymsk;
  86158. + DWC_PRINTF("DTKNQR4 @0x%08lX : 0x%08X\n",
  86159. + (unsigned long)addr, DWC_READ_REG32(addr));
  86160. + }
  86161. +
  86162. + addr = &core_if->dev_if->dev_global_regs->dtknqr4_fifoemptymsk;
  86163. + DWC_PRINTF("FIFOEMPMSK @0x%08lX : 0x%08X\n", (unsigned long)addr,
  86164. + DWC_READ_REG32(addr));
  86165. +
  86166. + if (core_if->hwcfg2.b.multi_proc_int) {
  86167. +
  86168. + addr = &core_if->dev_if->dev_global_regs->deachint;
  86169. + DWC_PRINTF("DEACHINT @0x%08lX : 0x%08X\n",
  86170. + (unsigned long)addr, DWC_READ_REG32(addr));
  86171. + addr = &core_if->dev_if->dev_global_regs->deachintmsk;
  86172. + DWC_PRINTF("DEACHINTMSK @0x%08lX : 0x%08X\n",
  86173. + (unsigned long)addr, DWC_READ_REG32(addr));
  86174. +
  86175. + for (i = 0; i <= core_if->dev_if->num_in_eps; i++) {
  86176. + addr =
  86177. + &core_if->dev_if->
  86178. + dev_global_regs->diepeachintmsk[i];
  86179. + DWC_PRINTF("DIEPEACHINTMSK[%d] @0x%08lX : 0x%08X\n",
  86180. + i, (unsigned long)addr,
  86181. + DWC_READ_REG32(addr));
  86182. + }
  86183. +
  86184. + for (i = 0; i <= core_if->dev_if->num_out_eps; i++) {
  86185. + addr =
  86186. + &core_if->dev_if->
  86187. + dev_global_regs->doepeachintmsk[i];
  86188. + DWC_PRINTF("DOEPEACHINTMSK[%d] @0x%08lX : 0x%08X\n",
  86189. + i, (unsigned long)addr,
  86190. + DWC_READ_REG32(addr));
  86191. + }
  86192. + }
  86193. +
  86194. + for (i = 0; i <= core_if->dev_if->num_in_eps; i++) {
  86195. + DWC_PRINTF("Device IN EP %d Registers\n", i);
  86196. + addr = &core_if->dev_if->in_ep_regs[i]->diepctl;
  86197. + DWC_PRINTF("DIEPCTL @0x%08lX : 0x%08X\n",
  86198. + (unsigned long)addr, DWC_READ_REG32(addr));
  86199. + addr = &core_if->dev_if->in_ep_regs[i]->diepint;
  86200. + DWC_PRINTF("DIEPINT @0x%08lX : 0x%08X\n",
  86201. + (unsigned long)addr, DWC_READ_REG32(addr));
  86202. + addr = &core_if->dev_if->in_ep_regs[i]->dieptsiz;
  86203. + DWC_PRINTF("DIETSIZ @0x%08lX : 0x%08X\n",
  86204. + (unsigned long)addr, DWC_READ_REG32(addr));
  86205. + addr = &core_if->dev_if->in_ep_regs[i]->diepdma;
  86206. + DWC_PRINTF("DIEPDMA @0x%08lX : 0x%08X\n",
  86207. + (unsigned long)addr, DWC_READ_REG32(addr));
  86208. + addr = &core_if->dev_if->in_ep_regs[i]->dtxfsts;
  86209. + DWC_PRINTF("DTXFSTS @0x%08lX : 0x%08X\n",
  86210. + (unsigned long)addr, DWC_READ_REG32(addr));
  86211. + addr = &core_if->dev_if->in_ep_regs[i]->diepdmab;
  86212. + DWC_PRINTF("DIEPDMAB @0x%08lX : 0x%08X\n",
  86213. + (unsigned long)addr, 0 /*DWC_READ_REG32(addr) */ );
  86214. + }
  86215. +
  86216. + for (i = 0; i <= core_if->dev_if->num_out_eps; i++) {
  86217. + DWC_PRINTF("Device OUT EP %d Registers\n", i);
  86218. + addr = &core_if->dev_if->out_ep_regs[i]->doepctl;
  86219. + DWC_PRINTF("DOEPCTL @0x%08lX : 0x%08X\n",
  86220. + (unsigned long)addr, DWC_READ_REG32(addr));
  86221. + addr = &core_if->dev_if->out_ep_regs[i]->doepint;
  86222. + DWC_PRINTF("DOEPINT @0x%08lX : 0x%08X\n",
  86223. + (unsigned long)addr, DWC_READ_REG32(addr));
  86224. + addr = &core_if->dev_if->out_ep_regs[i]->doeptsiz;
  86225. + DWC_PRINTF("DOETSIZ @0x%08lX : 0x%08X\n",
  86226. + (unsigned long)addr, DWC_READ_REG32(addr));
  86227. + addr = &core_if->dev_if->out_ep_regs[i]->doepdma;
  86228. + DWC_PRINTF("DOEPDMA @0x%08lX : 0x%08X\n",
  86229. + (unsigned long)addr, DWC_READ_REG32(addr));
  86230. + if (core_if->dma_enable) { /* Don't access this register in SLAVE mode */
  86231. + addr = &core_if->dev_if->out_ep_regs[i]->doepdmab;
  86232. + DWC_PRINTF("DOEPDMAB @0x%08lX : 0x%08X\n",
  86233. + (unsigned long)addr, DWC_READ_REG32(addr));
  86234. + }
  86235. +
  86236. + }
  86237. +}
  86238. +
  86239. +/**
  86240. + * This functions reads the SPRAM and prints its content
  86241. + *
  86242. + * @param core_if Programming view of DWC_otg controller.
  86243. + */
  86244. +void dwc_otg_dump_spram(dwc_otg_core_if_t * core_if)
  86245. +{
  86246. + volatile uint8_t *addr, *start_addr, *end_addr;
  86247. +
  86248. + DWC_PRINTF("SPRAM Data:\n");
  86249. + start_addr = (void *)core_if->core_global_regs;
  86250. + DWC_PRINTF("Base Address: 0x%8lX\n", (unsigned long)start_addr);
  86251. + start_addr += 0x00028000;
  86252. + end_addr = (void *)core_if->core_global_regs;
  86253. + end_addr += 0x000280e0;
  86254. +
  86255. + for (addr = start_addr; addr < end_addr; addr += 16) {
  86256. + DWC_PRINTF
  86257. + ("0x%8lX:\t%2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X\n",
  86258. + (unsigned long)addr, addr[0], addr[1], addr[2], addr[3],
  86259. + addr[4], addr[5], addr[6], addr[7], addr[8], addr[9],
  86260. + addr[10], addr[11], addr[12], addr[13], addr[14], addr[15]
  86261. + );
  86262. + }
  86263. +
  86264. + return;
  86265. +}
  86266. +
  86267. +/**
  86268. + * This function reads the host registers and prints them
  86269. + *
  86270. + * @param core_if Programming view of DWC_otg controller.
  86271. + */
  86272. +void dwc_otg_dump_host_registers(dwc_otg_core_if_t * core_if)
  86273. +{
  86274. + int i;
  86275. + volatile uint32_t *addr;
  86276. +
  86277. + DWC_PRINTF("Host Global Registers\n");
  86278. + addr = &core_if->host_if->host_global_regs->hcfg;
  86279. + DWC_PRINTF("HCFG @0x%08lX : 0x%08X\n",
  86280. + (unsigned long)addr, DWC_READ_REG32(addr));
  86281. + addr = &core_if->host_if->host_global_regs->hfir;
  86282. + DWC_PRINTF("HFIR @0x%08lX : 0x%08X\n",
  86283. + (unsigned long)addr, DWC_READ_REG32(addr));
  86284. + addr = &core_if->host_if->host_global_regs->hfnum;
  86285. + DWC_PRINTF("HFNUM @0x%08lX : 0x%08X\n", (unsigned long)addr,
  86286. + DWC_READ_REG32(addr));
  86287. + addr = &core_if->host_if->host_global_regs->hptxsts;
  86288. + DWC_PRINTF("HPTXSTS @0x%08lX : 0x%08X\n", (unsigned long)addr,
  86289. + DWC_READ_REG32(addr));
  86290. + addr = &core_if->host_if->host_global_regs->haint;
  86291. + DWC_PRINTF("HAINT @0x%08lX : 0x%08X\n", (unsigned long)addr,
  86292. + DWC_READ_REG32(addr));
  86293. + addr = &core_if->host_if->host_global_regs->haintmsk;
  86294. + DWC_PRINTF("HAINTMSK @0x%08lX : 0x%08X\n", (unsigned long)addr,
  86295. + DWC_READ_REG32(addr));
  86296. + if (core_if->dma_desc_enable) {
  86297. + addr = &core_if->host_if->host_global_regs->hflbaddr;
  86298. + DWC_PRINTF("HFLBADDR @0x%08lX : 0x%08X\n",
  86299. + (unsigned long)addr, DWC_READ_REG32(addr));
  86300. + }
  86301. +
  86302. + addr = core_if->host_if->hprt0;
  86303. + DWC_PRINTF("HPRT0 @0x%08lX : 0x%08X\n", (unsigned long)addr,
  86304. + DWC_READ_REG32(addr));
  86305. +
  86306. + for (i = 0; i < core_if->core_params->host_channels; i++) {
  86307. + DWC_PRINTF("Host Channel %d Specific Registers\n", i);
  86308. + addr = &core_if->host_if->hc_regs[i]->hcchar;
  86309. + DWC_PRINTF("HCCHAR @0x%08lX : 0x%08X\n",
  86310. + (unsigned long)addr, DWC_READ_REG32(addr));
  86311. + addr = &core_if->host_if->hc_regs[i]->hcsplt;
  86312. + DWC_PRINTF("HCSPLT @0x%08lX : 0x%08X\n",
  86313. + (unsigned long)addr, DWC_READ_REG32(addr));
  86314. + addr = &core_if->host_if->hc_regs[i]->hcint;
  86315. + DWC_PRINTF("HCINT @0x%08lX : 0x%08X\n",
  86316. + (unsigned long)addr, DWC_READ_REG32(addr));
  86317. + addr = &core_if->host_if->hc_regs[i]->hcintmsk;
  86318. + DWC_PRINTF("HCINTMSK @0x%08lX : 0x%08X\n",
  86319. + (unsigned long)addr, DWC_READ_REG32(addr));
  86320. + addr = &core_if->host_if->hc_regs[i]->hctsiz;
  86321. + DWC_PRINTF("HCTSIZ @0x%08lX : 0x%08X\n",
  86322. + (unsigned long)addr, DWC_READ_REG32(addr));
  86323. + addr = &core_if->host_if->hc_regs[i]->hcdma;
  86324. + DWC_PRINTF("HCDMA @0x%08lX : 0x%08X\n",
  86325. + (unsigned long)addr, DWC_READ_REG32(addr));
  86326. + if (core_if->dma_desc_enable) {
  86327. + addr = &core_if->host_if->hc_regs[i]->hcdmab;
  86328. + DWC_PRINTF("HCDMAB @0x%08lX : 0x%08X\n",
  86329. + (unsigned long)addr, DWC_READ_REG32(addr));
  86330. + }
  86331. +
  86332. + }
  86333. + return;
  86334. +}
  86335. +
  86336. +/**
  86337. + * This function reads the core global registers and prints them
  86338. + *
  86339. + * @param core_if Programming view of DWC_otg controller.
  86340. + */
  86341. +void dwc_otg_dump_global_registers(dwc_otg_core_if_t * core_if)
  86342. +{
  86343. + int i, ep_num;
  86344. + volatile uint32_t *addr;
  86345. + char *txfsiz;
  86346. +
  86347. + DWC_PRINTF("Core Global Registers\n");
  86348. + addr = &core_if->core_global_regs->gotgctl;
  86349. + DWC_PRINTF("GOTGCTL @0x%08lX : 0x%08X\n", (unsigned long)addr,
  86350. + DWC_READ_REG32(addr));
  86351. + addr = &core_if->core_global_regs->gotgint;
  86352. + DWC_PRINTF("GOTGINT @0x%08lX : 0x%08X\n", (unsigned long)addr,
  86353. + DWC_READ_REG32(addr));
  86354. + addr = &core_if->core_global_regs->gahbcfg;
  86355. + DWC_PRINTF("GAHBCFG @0x%08lX : 0x%08X\n", (unsigned long)addr,
  86356. + DWC_READ_REG32(addr));
  86357. + addr = &core_if->core_global_regs->gusbcfg;
  86358. + DWC_PRINTF("GUSBCFG @0x%08lX : 0x%08X\n", (unsigned long)addr,
  86359. + DWC_READ_REG32(addr));
  86360. + addr = &core_if->core_global_regs->grstctl;
  86361. + DWC_PRINTF("GRSTCTL @0x%08lX : 0x%08X\n", (unsigned long)addr,
  86362. + DWC_READ_REG32(addr));
  86363. + addr = &core_if->core_global_regs->gintsts;
  86364. + DWC_PRINTF("GINTSTS @0x%08lX : 0x%08X\n", (unsigned long)addr,
  86365. + DWC_READ_REG32(addr));
  86366. + addr = &core_if->core_global_regs->gintmsk;
  86367. + DWC_PRINTF("GINTMSK @0x%08lX : 0x%08X\n", (unsigned long)addr,
  86368. + DWC_READ_REG32(addr));
  86369. + addr = &core_if->core_global_regs->grxstsr;
  86370. + DWC_PRINTF("GRXSTSR @0x%08lX : 0x%08X\n", (unsigned long)addr,
  86371. + DWC_READ_REG32(addr));
  86372. + addr = &core_if->core_global_regs->grxfsiz;
  86373. + DWC_PRINTF("GRXFSIZ @0x%08lX : 0x%08X\n", (unsigned long)addr,
  86374. + DWC_READ_REG32(addr));
  86375. + addr = &core_if->core_global_regs->gnptxfsiz;
  86376. + DWC_PRINTF("GNPTXFSIZ @0x%08lX : 0x%08X\n", (unsigned long)addr,
  86377. + DWC_READ_REG32(addr));
  86378. + addr = &core_if->core_global_regs->gnptxsts;
  86379. + DWC_PRINTF("GNPTXSTS @0x%08lX : 0x%08X\n", (unsigned long)addr,
  86380. + DWC_READ_REG32(addr));
  86381. + addr = &core_if->core_global_regs->gi2cctl;
  86382. + DWC_PRINTF("GI2CCTL @0x%08lX : 0x%08X\n", (unsigned long)addr,
  86383. + DWC_READ_REG32(addr));
  86384. + addr = &core_if->core_global_regs->gpvndctl;
  86385. + DWC_PRINTF("GPVNDCTL @0x%08lX : 0x%08X\n", (unsigned long)addr,
  86386. + DWC_READ_REG32(addr));
  86387. + addr = &core_if->core_global_regs->ggpio;
  86388. + DWC_PRINTF("GGPIO @0x%08lX : 0x%08X\n", (unsigned long)addr,
  86389. + DWC_READ_REG32(addr));
  86390. + addr = &core_if->core_global_regs->guid;
  86391. + DWC_PRINTF("GUID @0x%08lX : 0x%08X\n",
  86392. + (unsigned long)addr, DWC_READ_REG32(addr));
  86393. + addr = &core_if->core_global_regs->gsnpsid;
  86394. + DWC_PRINTF("GSNPSID @0x%08lX : 0x%08X\n", (unsigned long)addr,
  86395. + DWC_READ_REG32(addr));
  86396. + addr = &core_if->core_global_regs->ghwcfg1;
  86397. + DWC_PRINTF("GHWCFG1 @0x%08lX : 0x%08X\n", (unsigned long)addr,
  86398. + DWC_READ_REG32(addr));
  86399. + addr = &core_if->core_global_regs->ghwcfg2;
  86400. + DWC_PRINTF("GHWCFG2 @0x%08lX : 0x%08X\n", (unsigned long)addr,
  86401. + DWC_READ_REG32(addr));
  86402. + addr = &core_if->core_global_regs->ghwcfg3;
  86403. + DWC_PRINTF("GHWCFG3 @0x%08lX : 0x%08X\n", (unsigned long)addr,
  86404. + DWC_READ_REG32(addr));
  86405. + addr = &core_if->core_global_regs->ghwcfg4;
  86406. + DWC_PRINTF("GHWCFG4 @0x%08lX : 0x%08X\n", (unsigned long)addr,
  86407. + DWC_READ_REG32(addr));
  86408. + addr = &core_if->core_global_regs->glpmcfg;
  86409. + DWC_PRINTF("GLPMCFG @0x%08lX : 0x%08X\n", (unsigned long)addr,
  86410. + DWC_READ_REG32(addr));
  86411. + addr = &core_if->core_global_regs->gpwrdn;
  86412. + DWC_PRINTF("GPWRDN @0x%08lX : 0x%08X\n", (unsigned long)addr,
  86413. + DWC_READ_REG32(addr));
  86414. + addr = &core_if->core_global_regs->gdfifocfg;
  86415. + DWC_PRINTF("GDFIFOCFG @0x%08lX : 0x%08X\n", (unsigned long)addr,
  86416. + DWC_READ_REG32(addr));
  86417. + addr = &core_if->core_global_regs->adpctl;
  86418. + DWC_PRINTF("ADPCTL @0x%08lX : 0x%08X\n", (unsigned long)addr,
  86419. + dwc_otg_adp_read_reg(core_if));
  86420. + addr = &core_if->core_global_regs->hptxfsiz;
  86421. + DWC_PRINTF("HPTXFSIZ @0x%08lX : 0x%08X\n", (unsigned long)addr,
  86422. + DWC_READ_REG32(addr));
  86423. +
  86424. + if (core_if->en_multiple_tx_fifo == 0) {
  86425. + ep_num = core_if->hwcfg4.b.num_dev_perio_in_ep;
  86426. + txfsiz = "DPTXFSIZ";
  86427. + } else {
  86428. + ep_num = core_if->hwcfg4.b.num_in_eps;
  86429. + txfsiz = "DIENPTXF";
  86430. + }
  86431. + for (i = 0; i < ep_num; i++) {
  86432. + addr = &core_if->core_global_regs->dtxfsiz[i];
  86433. + DWC_PRINTF("%s[%d] @0x%08lX : 0x%08X\n", txfsiz, i + 1,
  86434. + (unsigned long)addr, DWC_READ_REG32(addr));
  86435. + }
  86436. + addr = core_if->pcgcctl;
  86437. + DWC_PRINTF("PCGCCTL @0x%08lX : 0x%08X\n", (unsigned long)addr,
  86438. + DWC_READ_REG32(addr));
  86439. +}
  86440. +
  86441. +/**
  86442. + * Flush a Tx FIFO.
  86443. + *
  86444. + * @param core_if Programming view of DWC_otg controller.
  86445. + * @param num Tx FIFO to flush.
  86446. + */
  86447. +void dwc_otg_flush_tx_fifo(dwc_otg_core_if_t * core_if, const int num)
  86448. +{
  86449. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  86450. + volatile grstctl_t greset = {.d32 = 0 };
  86451. + int count = 0;
  86452. +
  86453. + DWC_DEBUGPL((DBG_CIL | DBG_PCDV), "Flush Tx FIFO %d\n", num);
  86454. +
  86455. + greset.b.txfflsh = 1;
  86456. + greset.b.txfnum = num;
  86457. + DWC_WRITE_REG32(&global_regs->grstctl, greset.d32);
  86458. +
  86459. + do {
  86460. + greset.d32 = DWC_READ_REG32(&global_regs->grstctl);
  86461. + if (++count > 10000) {
  86462. + DWC_WARN("%s() HANG! GRSTCTL=%0x GNPTXSTS=0x%08x\n",
  86463. + __func__, greset.d32,
  86464. + DWC_READ_REG32(&global_regs->gnptxsts));
  86465. + break;
  86466. + }
  86467. + dwc_udelay(1);
  86468. + } while (greset.b.txfflsh == 1);
  86469. +
  86470. + /* Wait for 3 PHY Clocks */
  86471. + dwc_udelay(1);
  86472. +}
  86473. +
  86474. +/**
  86475. + * Flush Rx FIFO.
  86476. + *
  86477. + * @param core_if Programming view of DWC_otg controller.
  86478. + */
  86479. +void dwc_otg_flush_rx_fifo(dwc_otg_core_if_t * core_if)
  86480. +{
  86481. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  86482. + volatile grstctl_t greset = {.d32 = 0 };
  86483. + int count = 0;
  86484. +
  86485. + DWC_DEBUGPL((DBG_CIL | DBG_PCDV), "%s\n", __func__);
  86486. + /*
  86487. + *
  86488. + */
  86489. + greset.b.rxfflsh = 1;
  86490. + DWC_WRITE_REG32(&global_regs->grstctl, greset.d32);
  86491. +
  86492. + do {
  86493. + greset.d32 = DWC_READ_REG32(&global_regs->grstctl);
  86494. + if (++count > 10000) {
  86495. + DWC_WARN("%s() HANG! GRSTCTL=%0x\n", __func__,
  86496. + greset.d32);
  86497. + break;
  86498. + }
  86499. + dwc_udelay(1);
  86500. + } while (greset.b.rxfflsh == 1);
  86501. +
  86502. + /* Wait for 3 PHY Clocks */
  86503. + dwc_udelay(1);
  86504. +}
  86505. +
  86506. +/**
  86507. + * Do core a soft reset of the core. Be careful with this because it
  86508. + * resets all the internal state machines of the core.
  86509. + */
  86510. +void dwc_otg_core_reset(dwc_otg_core_if_t * core_if)
  86511. +{
  86512. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  86513. + volatile grstctl_t greset = {.d32 = 0 };
  86514. + int count = 0;
  86515. +
  86516. + DWC_DEBUGPL(DBG_CILV, "%s\n", __func__);
  86517. + /* Wait for AHB master IDLE state. */
  86518. + do {
  86519. + dwc_udelay(10);
  86520. + greset.d32 = DWC_READ_REG32(&global_regs->grstctl);
  86521. + if (++count > 100000) {
  86522. + DWC_WARN("%s() HANG! AHB Idle GRSTCTL=%0x\n", __func__,
  86523. + greset.d32);
  86524. + return;
  86525. + }
  86526. + }
  86527. + while (greset.b.ahbidle == 0);
  86528. +
  86529. + /* Core Soft Reset */
  86530. + count = 0;
  86531. + greset.b.csftrst = 1;
  86532. + DWC_WRITE_REG32(&global_regs->grstctl, greset.d32);
  86533. + do {
  86534. + greset.d32 = DWC_READ_REG32(&global_regs->grstctl);
  86535. + if (++count > 10000) {
  86536. + DWC_WARN("%s() HANG! Soft Reset GRSTCTL=%0x\n",
  86537. + __func__, greset.d32);
  86538. + break;
  86539. + }
  86540. + dwc_udelay(1);
  86541. + }
  86542. + while (greset.b.csftrst == 1);
  86543. +
  86544. + /* Wait for 3 PHY Clocks */
  86545. + dwc_mdelay(100);
  86546. +}
  86547. +
  86548. +uint8_t dwc_otg_is_device_mode(dwc_otg_core_if_t * _core_if)
  86549. +{
  86550. + return (dwc_otg_mode(_core_if) != DWC_HOST_MODE);
  86551. +}
  86552. +
  86553. +uint8_t dwc_otg_is_host_mode(dwc_otg_core_if_t * _core_if)
  86554. +{
  86555. + return (dwc_otg_mode(_core_if) == DWC_HOST_MODE);
  86556. +}
  86557. +
  86558. +/**
  86559. + * Register HCD callbacks. The callbacks are used to start and stop
  86560. + * the HCD for interrupt processing.
  86561. + *
  86562. + * @param core_if Programming view of DWC_otg controller.
  86563. + * @param cb the HCD callback structure.
  86564. + * @param p pointer to be passed to callback function (usb_hcd*).
  86565. + */
  86566. +void dwc_otg_cil_register_hcd_callbacks(dwc_otg_core_if_t * core_if,
  86567. + dwc_otg_cil_callbacks_t * cb, void *p)
  86568. +{
  86569. + core_if->hcd_cb = cb;
  86570. + cb->p = p;
  86571. +}
  86572. +
  86573. +/**
  86574. + * Register PCD callbacks. The callbacks are used to start and stop
  86575. + * the PCD for interrupt processing.
  86576. + *
  86577. + * @param core_if Programming view of DWC_otg controller.
  86578. + * @param cb the PCD callback structure.
  86579. + * @param p pointer to be passed to callback function (pcd*).
  86580. + */
  86581. +void dwc_otg_cil_register_pcd_callbacks(dwc_otg_core_if_t * core_if,
  86582. + dwc_otg_cil_callbacks_t * cb, void *p)
  86583. +{
  86584. + core_if->pcd_cb = cb;
  86585. + cb->p = p;
  86586. +}
  86587. +
  86588. +#ifdef DWC_EN_ISOC
  86589. +
  86590. +/**
  86591. + * This function writes isoc data per 1 (micro)frame into tx fifo
  86592. + *
  86593. + * @param core_if Programming view of DWC_otg controller.
  86594. + * @param ep The EP to start the transfer on.
  86595. + *
  86596. + */
  86597. +void write_isoc_frame_data(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  86598. +{
  86599. + dwc_otg_dev_in_ep_regs_t *ep_regs;
  86600. + dtxfsts_data_t txstatus = {.d32 = 0 };
  86601. + uint32_t len = 0;
  86602. + uint32_t dwords;
  86603. +
  86604. + ep->xfer_len = ep->data_per_frame;
  86605. + ep->xfer_count = 0;
  86606. +
  86607. + ep_regs = core_if->dev_if->in_ep_regs[ep->num];
  86608. +
  86609. + len = ep->xfer_len - ep->xfer_count;
  86610. +
  86611. + if (len > ep->maxpacket) {
  86612. + len = ep->maxpacket;
  86613. + }
  86614. +
  86615. + dwords = (len + 3) / 4;
  86616. +
  86617. + /* While there is space in the queue and space in the FIFO and
  86618. + * More data to tranfer, Write packets to the Tx FIFO */
  86619. + txstatus.d32 =
  86620. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[ep->num]->dtxfsts);
  86621. + DWC_DEBUGPL(DBG_PCDV, "b4 dtxfsts[%d]=0x%08x\n", ep->num, txstatus.d32);
  86622. +
  86623. + while (txstatus.b.txfspcavail > dwords &&
  86624. + ep->xfer_count < ep->xfer_len && ep->xfer_len != 0) {
  86625. + /* Write the FIFO */
  86626. + dwc_otg_ep_write_packet(core_if, ep, 0);
  86627. +
  86628. + len = ep->xfer_len - ep->xfer_count;
  86629. + if (len > ep->maxpacket) {
  86630. + len = ep->maxpacket;
  86631. + }
  86632. +
  86633. + dwords = (len + 3) / 4;
  86634. + txstatus.d32 =
  86635. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  86636. + dtxfsts);
  86637. + DWC_DEBUGPL(DBG_PCDV, "dtxfsts[%d]=0x%08x\n", ep->num,
  86638. + txstatus.d32);
  86639. + }
  86640. +}
  86641. +
  86642. +/**
  86643. + * This function initializes a descriptor chain for Isochronous transfer
  86644. + *
  86645. + * @param core_if Programming view of DWC_otg controller.
  86646. + * @param ep The EP to start the transfer on.
  86647. + *
  86648. + */
  86649. +void dwc_otg_iso_ep_start_frm_transfer(dwc_otg_core_if_t * core_if,
  86650. + dwc_ep_t * ep)
  86651. +{
  86652. + deptsiz_data_t deptsiz = {.d32 = 0 };
  86653. + depctl_data_t depctl = {.d32 = 0 };
  86654. + dsts_data_t dsts = {.d32 = 0 };
  86655. + volatile uint32_t *addr;
  86656. +
  86657. + if (ep->is_in) {
  86658. + addr = &core_if->dev_if->in_ep_regs[ep->num]->diepctl;
  86659. + } else {
  86660. + addr = &core_if->dev_if->out_ep_regs[ep->num]->doepctl;
  86661. + }
  86662. +
  86663. + ep->xfer_len = ep->data_per_frame;
  86664. + ep->xfer_count = 0;
  86665. + ep->xfer_buff = ep->cur_pkt_addr;
  86666. + ep->dma_addr = ep->cur_pkt_dma_addr;
  86667. +
  86668. + if (ep->is_in) {
  86669. + /* Program the transfer size and packet count
  86670. + * as follows: xfersize = N * maxpacket +
  86671. + * short_packet pktcnt = N + (short_packet
  86672. + * exist ? 1 : 0)
  86673. + */
  86674. + deptsiz.b.xfersize = ep->xfer_len;
  86675. + deptsiz.b.pktcnt =
  86676. + (ep->xfer_len - 1 + ep->maxpacket) / ep->maxpacket;
  86677. + deptsiz.b.mc = deptsiz.b.pktcnt;
  86678. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[ep->num]->dieptsiz,
  86679. + deptsiz.d32);
  86680. +
  86681. + /* Write the DMA register */
  86682. + if (core_if->dma_enable) {
  86683. + DWC_WRITE_REG32(&
  86684. + (core_if->dev_if->in_ep_regs[ep->num]->
  86685. + diepdma), (uint32_t) ep->dma_addr);
  86686. + }
  86687. + } else {
  86688. + deptsiz.b.pktcnt =
  86689. + (ep->xfer_len + (ep->maxpacket - 1)) / ep->maxpacket;
  86690. + deptsiz.b.xfersize = deptsiz.b.pktcnt * ep->maxpacket;
  86691. +
  86692. + DWC_WRITE_REG32(&core_if->dev_if->
  86693. + out_ep_regs[ep->num]->doeptsiz, deptsiz.d32);
  86694. +
  86695. + if (core_if->dma_enable) {
  86696. + DWC_WRITE_REG32(&
  86697. + (core_if->dev_if->
  86698. + out_ep_regs[ep->num]->doepdma),
  86699. + (uint32_t) ep->dma_addr);
  86700. + }
  86701. + }
  86702. +
  86703. + /** Enable endpoint, clear nak */
  86704. +
  86705. + depctl.d32 = 0;
  86706. + if (ep->bInterval == 1) {
  86707. + dsts.d32 =
  86708. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  86709. + ep->next_frame = dsts.b.soffn + ep->bInterval;
  86710. +
  86711. + if (ep->next_frame & 0x1) {
  86712. + depctl.b.setd1pid = 1;
  86713. + } else {
  86714. + depctl.b.setd0pid = 1;
  86715. + }
  86716. + } else {
  86717. + ep->next_frame += ep->bInterval;
  86718. +
  86719. + if (ep->next_frame & 0x1) {
  86720. + depctl.b.setd1pid = 1;
  86721. + } else {
  86722. + depctl.b.setd0pid = 1;
  86723. + }
  86724. + }
  86725. + depctl.b.epena = 1;
  86726. + depctl.b.cnak = 1;
  86727. +
  86728. + DWC_MODIFY_REG32(addr, 0, depctl.d32);
  86729. + depctl.d32 = DWC_READ_REG32(addr);
  86730. +
  86731. + if (ep->is_in && core_if->dma_enable == 0) {
  86732. + write_isoc_frame_data(core_if, ep);
  86733. + }
  86734. +
  86735. +}
  86736. +#endif /* DWC_EN_ISOC */
  86737. +
  86738. +static void dwc_otg_set_uninitialized(int32_t * p, int size)
  86739. +{
  86740. + int i;
  86741. + for (i = 0; i < size; i++) {
  86742. + p[i] = -1;
  86743. + }
  86744. +}
  86745. +
  86746. +static int dwc_otg_param_initialized(int32_t val)
  86747. +{
  86748. + return val != -1;
  86749. +}
  86750. +
  86751. +static int dwc_otg_setup_params(dwc_otg_core_if_t * core_if)
  86752. +{
  86753. + int i;
  86754. + core_if->core_params = DWC_ALLOC(sizeof(*core_if->core_params));
  86755. + if (!core_if->core_params) {
  86756. + return -DWC_E_NO_MEMORY;
  86757. + }
  86758. + dwc_otg_set_uninitialized((int32_t *) core_if->core_params,
  86759. + sizeof(*core_if->core_params) /
  86760. + sizeof(int32_t));
  86761. + DWC_PRINTF("Setting default values for core params\n");
  86762. + dwc_otg_set_param_otg_cap(core_if, dwc_param_otg_cap_default);
  86763. + dwc_otg_set_param_dma_enable(core_if, dwc_param_dma_enable_default);
  86764. + dwc_otg_set_param_dma_desc_enable(core_if,
  86765. + dwc_param_dma_desc_enable_default);
  86766. + dwc_otg_set_param_opt(core_if, dwc_param_opt_default);
  86767. + dwc_otg_set_param_dma_burst_size(core_if,
  86768. + dwc_param_dma_burst_size_default);
  86769. + dwc_otg_set_param_host_support_fs_ls_low_power(core_if,
  86770. + dwc_param_host_support_fs_ls_low_power_default);
  86771. + dwc_otg_set_param_enable_dynamic_fifo(core_if,
  86772. + dwc_param_enable_dynamic_fifo_default);
  86773. + dwc_otg_set_param_data_fifo_size(core_if,
  86774. + dwc_param_data_fifo_size_default);
  86775. + dwc_otg_set_param_dev_rx_fifo_size(core_if,
  86776. + dwc_param_dev_rx_fifo_size_default);
  86777. + dwc_otg_set_param_dev_nperio_tx_fifo_size(core_if,
  86778. + dwc_param_dev_nperio_tx_fifo_size_default);
  86779. + dwc_otg_set_param_host_rx_fifo_size(core_if,
  86780. + dwc_param_host_rx_fifo_size_default);
  86781. + dwc_otg_set_param_host_nperio_tx_fifo_size(core_if,
  86782. + dwc_param_host_nperio_tx_fifo_size_default);
  86783. + dwc_otg_set_param_host_perio_tx_fifo_size(core_if,
  86784. + dwc_param_host_perio_tx_fifo_size_default);
  86785. + dwc_otg_set_param_max_transfer_size(core_if,
  86786. + dwc_param_max_transfer_size_default);
  86787. + dwc_otg_set_param_max_packet_count(core_if,
  86788. + dwc_param_max_packet_count_default);
  86789. + dwc_otg_set_param_host_channels(core_if,
  86790. + dwc_param_host_channels_default);
  86791. + dwc_otg_set_param_dev_endpoints(core_if,
  86792. + dwc_param_dev_endpoints_default);
  86793. + dwc_otg_set_param_phy_type(core_if, dwc_param_phy_type_default);
  86794. + dwc_otg_set_param_speed(core_if, dwc_param_speed_default);
  86795. + dwc_otg_set_param_host_ls_low_power_phy_clk(core_if,
  86796. + dwc_param_host_ls_low_power_phy_clk_default);
  86797. + dwc_otg_set_param_phy_ulpi_ddr(core_if, dwc_param_phy_ulpi_ddr_default);
  86798. + dwc_otg_set_param_phy_ulpi_ext_vbus(core_if,
  86799. + dwc_param_phy_ulpi_ext_vbus_default);
  86800. + dwc_otg_set_param_phy_utmi_width(core_if,
  86801. + dwc_param_phy_utmi_width_default);
  86802. + dwc_otg_set_param_ts_dline(core_if, dwc_param_ts_dline_default);
  86803. + dwc_otg_set_param_i2c_enable(core_if, dwc_param_i2c_enable_default);
  86804. + dwc_otg_set_param_ulpi_fs_ls(core_if, dwc_param_ulpi_fs_ls_default);
  86805. + dwc_otg_set_param_en_multiple_tx_fifo(core_if,
  86806. + dwc_param_en_multiple_tx_fifo_default);
  86807. + for (i = 0; i < 15; i++) {
  86808. + dwc_otg_set_param_dev_perio_tx_fifo_size(core_if,
  86809. + dwc_param_dev_perio_tx_fifo_size_default,
  86810. + i);
  86811. + }
  86812. +
  86813. + for (i = 0; i < 15; i++) {
  86814. + dwc_otg_set_param_dev_tx_fifo_size(core_if,
  86815. + dwc_param_dev_tx_fifo_size_default,
  86816. + i);
  86817. + }
  86818. + dwc_otg_set_param_thr_ctl(core_if, dwc_param_thr_ctl_default);
  86819. + dwc_otg_set_param_mpi_enable(core_if, dwc_param_mpi_enable_default);
  86820. + dwc_otg_set_param_pti_enable(core_if, dwc_param_pti_enable_default);
  86821. + dwc_otg_set_param_lpm_enable(core_if, dwc_param_lpm_enable_default);
  86822. + dwc_otg_set_param_ic_usb_cap(core_if, dwc_param_ic_usb_cap_default);
  86823. + dwc_otg_set_param_tx_thr_length(core_if,
  86824. + dwc_param_tx_thr_length_default);
  86825. + dwc_otg_set_param_rx_thr_length(core_if,
  86826. + dwc_param_rx_thr_length_default);
  86827. + dwc_otg_set_param_ahb_thr_ratio(core_if,
  86828. + dwc_param_ahb_thr_ratio_default);
  86829. + dwc_otg_set_param_power_down(core_if, dwc_param_power_down_default);
  86830. + dwc_otg_set_param_reload_ctl(core_if, dwc_param_reload_ctl_default);
  86831. + dwc_otg_set_param_dev_out_nak(core_if, dwc_param_dev_out_nak_default);
  86832. + dwc_otg_set_param_cont_on_bna(core_if, dwc_param_cont_on_bna_default);
  86833. + dwc_otg_set_param_ahb_single(core_if, dwc_param_ahb_single_default);
  86834. + dwc_otg_set_param_otg_ver(core_if, dwc_param_otg_ver_default);
  86835. + dwc_otg_set_param_adp_enable(core_if, dwc_param_adp_enable_default);
  86836. + DWC_PRINTF("Finished setting default values for core params\n");
  86837. +
  86838. + return 0;
  86839. +}
  86840. +
  86841. +uint8_t dwc_otg_is_dma_enable(dwc_otg_core_if_t * core_if)
  86842. +{
  86843. + return core_if->dma_enable;
  86844. +}
  86845. +
  86846. +/* Checks if the parameter is outside of its valid range of values */
  86847. +#define DWC_OTG_PARAM_TEST(_param_, _low_, _high_) \
  86848. + (((_param_) < (_low_)) || \
  86849. + ((_param_) > (_high_)))
  86850. +
  86851. +/* Parameter access functions */
  86852. +int dwc_otg_set_param_otg_cap(dwc_otg_core_if_t * core_if, int32_t val)
  86853. +{
  86854. + int valid;
  86855. + int retval = 0;
  86856. + if (DWC_OTG_PARAM_TEST(val, 0, 2)) {
  86857. + DWC_WARN("Wrong value for otg_cap parameter\n");
  86858. + DWC_WARN("otg_cap parameter must be 0,1 or 2\n");
  86859. + retval = -DWC_E_INVALID;
  86860. + goto out;
  86861. + }
  86862. +
  86863. + valid = 1;
  86864. + switch (val) {
  86865. + case DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE:
  86866. + if (core_if->hwcfg2.b.op_mode !=
  86867. + DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG)
  86868. + valid = 0;
  86869. + break;
  86870. + case DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE:
  86871. + if ((core_if->hwcfg2.b.op_mode !=
  86872. + DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG)
  86873. + && (core_if->hwcfg2.b.op_mode !=
  86874. + DWC_HWCFG2_OP_MODE_SRP_ONLY_CAPABLE_OTG)
  86875. + && (core_if->hwcfg2.b.op_mode !=
  86876. + DWC_HWCFG2_OP_MODE_SRP_CAPABLE_DEVICE)
  86877. + && (core_if->hwcfg2.b.op_mode !=
  86878. + DWC_HWCFG2_OP_MODE_SRP_CAPABLE_HOST)) {
  86879. + valid = 0;
  86880. + }
  86881. + break;
  86882. + case DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE:
  86883. + /* always valid */
  86884. + break;
  86885. + }
  86886. + if (!valid) {
  86887. + if (dwc_otg_param_initialized(core_if->core_params->otg_cap)) {
  86888. + DWC_ERROR
  86889. + ("%d invalid for otg_cap paremter. Check HW configuration.\n",
  86890. + val);
  86891. + }
  86892. + val =
  86893. + (((core_if->hwcfg2.b.op_mode ==
  86894. + DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG)
  86895. + || (core_if->hwcfg2.b.op_mode ==
  86896. + DWC_HWCFG2_OP_MODE_SRP_ONLY_CAPABLE_OTG)
  86897. + || (core_if->hwcfg2.b.op_mode ==
  86898. + DWC_HWCFG2_OP_MODE_SRP_CAPABLE_DEVICE)
  86899. + || (core_if->hwcfg2.b.op_mode ==
  86900. + DWC_HWCFG2_OP_MODE_SRP_CAPABLE_HOST)) ?
  86901. + DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE :
  86902. + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
  86903. + retval = -DWC_E_INVALID;
  86904. + }
  86905. +
  86906. + core_if->core_params->otg_cap = val;
  86907. +out:
  86908. + return retval;
  86909. +}
  86910. +
  86911. +int32_t dwc_otg_get_param_otg_cap(dwc_otg_core_if_t * core_if)
  86912. +{
  86913. + return core_if->core_params->otg_cap;
  86914. +}
  86915. +
  86916. +int dwc_otg_set_param_opt(dwc_otg_core_if_t * core_if, int32_t val)
  86917. +{
  86918. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  86919. + DWC_WARN("Wrong value for opt parameter\n");
  86920. + return -DWC_E_INVALID;
  86921. + }
  86922. + core_if->core_params->opt = val;
  86923. + return 0;
  86924. +}
  86925. +
  86926. +int32_t dwc_otg_get_param_opt(dwc_otg_core_if_t * core_if)
  86927. +{
  86928. + return core_if->core_params->opt;
  86929. +}
  86930. +
  86931. +int dwc_otg_set_param_dma_enable(dwc_otg_core_if_t * core_if, int32_t val)
  86932. +{
  86933. + int retval = 0;
  86934. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  86935. + DWC_WARN("Wrong value for dma enable\n");
  86936. + return -DWC_E_INVALID;
  86937. + }
  86938. +
  86939. + if ((val == 1) && (core_if->hwcfg2.b.architecture == 0)) {
  86940. + if (dwc_otg_param_initialized(core_if->core_params->dma_enable)) {
  86941. + DWC_ERROR
  86942. + ("%d invalid for dma_enable paremter. Check HW configuration.\n",
  86943. + val);
  86944. + }
  86945. + val = 0;
  86946. + retval = -DWC_E_INVALID;
  86947. + }
  86948. +
  86949. + core_if->core_params->dma_enable = val;
  86950. + if (val == 0) {
  86951. + dwc_otg_set_param_dma_desc_enable(core_if, 0);
  86952. + }
  86953. + return retval;
  86954. +}
  86955. +
  86956. +int32_t dwc_otg_get_param_dma_enable(dwc_otg_core_if_t * core_if)
  86957. +{
  86958. + return core_if->core_params->dma_enable;
  86959. +}
  86960. +
  86961. +int dwc_otg_set_param_dma_desc_enable(dwc_otg_core_if_t * core_if, int32_t val)
  86962. +{
  86963. + int retval = 0;
  86964. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  86965. + DWC_WARN("Wrong value for dma_enable\n");
  86966. + DWC_WARN("dma_desc_enable must be 0 or 1\n");
  86967. + return -DWC_E_INVALID;
  86968. + }
  86969. +
  86970. + if ((val == 1)
  86971. + && ((dwc_otg_get_param_dma_enable(core_if) == 0)
  86972. + || (core_if->hwcfg4.b.desc_dma == 0))) {
  86973. + if (dwc_otg_param_initialized
  86974. + (core_if->core_params->dma_desc_enable)) {
  86975. + DWC_ERROR
  86976. + ("%d invalid for dma_desc_enable paremter. Check HW configuration.\n",
  86977. + val);
  86978. + }
  86979. + val = 0;
  86980. + retval = -DWC_E_INVALID;
  86981. + }
  86982. + core_if->core_params->dma_desc_enable = val;
  86983. + return retval;
  86984. +}
  86985. +
  86986. +int32_t dwc_otg_get_param_dma_desc_enable(dwc_otg_core_if_t * core_if)
  86987. +{
  86988. + return core_if->core_params->dma_desc_enable;
  86989. +}
  86990. +
  86991. +int dwc_otg_set_param_host_support_fs_ls_low_power(dwc_otg_core_if_t * core_if,
  86992. + int32_t val)
  86993. +{
  86994. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  86995. + DWC_WARN("Wrong value for host_support_fs_low_power\n");
  86996. + DWC_WARN("host_support_fs_low_power must be 0 or 1\n");
  86997. + return -DWC_E_INVALID;
  86998. + }
  86999. + core_if->core_params->host_support_fs_ls_low_power = val;
  87000. + return 0;
  87001. +}
  87002. +
  87003. +int32_t dwc_otg_get_param_host_support_fs_ls_low_power(dwc_otg_core_if_t *
  87004. + core_if)
  87005. +{
  87006. + return core_if->core_params->host_support_fs_ls_low_power;
  87007. +}
  87008. +
  87009. +int dwc_otg_set_param_enable_dynamic_fifo(dwc_otg_core_if_t * core_if,
  87010. + int32_t val)
  87011. +{
  87012. + int retval = 0;
  87013. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  87014. + DWC_WARN("Wrong value for enable_dynamic_fifo\n");
  87015. + DWC_WARN("enable_dynamic_fifo must be 0 or 1\n");
  87016. + return -DWC_E_INVALID;
  87017. + }
  87018. +
  87019. + if ((val == 1) && (core_if->hwcfg2.b.dynamic_fifo == 0)) {
  87020. + if (dwc_otg_param_initialized
  87021. + (core_if->core_params->enable_dynamic_fifo)) {
  87022. + DWC_ERROR
  87023. + ("%d invalid for enable_dynamic_fifo paremter. Check HW configuration.\n",
  87024. + val);
  87025. + }
  87026. + val = 0;
  87027. + retval = -DWC_E_INVALID;
  87028. + }
  87029. + core_if->core_params->enable_dynamic_fifo = val;
  87030. + return retval;
  87031. +}
  87032. +
  87033. +int32_t dwc_otg_get_param_enable_dynamic_fifo(dwc_otg_core_if_t * core_if)
  87034. +{
  87035. + return core_if->core_params->enable_dynamic_fifo;
  87036. +}
  87037. +
  87038. +int dwc_otg_set_param_data_fifo_size(dwc_otg_core_if_t * core_if, int32_t val)
  87039. +{
  87040. + int retval = 0;
  87041. + if (DWC_OTG_PARAM_TEST(val, 32, 32768)) {
  87042. + DWC_WARN("Wrong value for data_fifo_size\n");
  87043. + DWC_WARN("data_fifo_size must be 32-32768\n");
  87044. + return -DWC_E_INVALID;
  87045. + }
  87046. +
  87047. + if (val > core_if->hwcfg3.b.dfifo_depth) {
  87048. + if (dwc_otg_param_initialized
  87049. + (core_if->core_params->data_fifo_size)) {
  87050. + DWC_ERROR
  87051. + ("%d invalid for data_fifo_size parameter. Check HW configuration.\n",
  87052. + val);
  87053. + }
  87054. + val = core_if->hwcfg3.b.dfifo_depth;
  87055. + retval = -DWC_E_INVALID;
  87056. + }
  87057. +
  87058. + core_if->core_params->data_fifo_size = val;
  87059. + return retval;
  87060. +}
  87061. +
  87062. +int32_t dwc_otg_get_param_data_fifo_size(dwc_otg_core_if_t * core_if)
  87063. +{
  87064. + return core_if->core_params->data_fifo_size;
  87065. +}
  87066. +
  87067. +int dwc_otg_set_param_dev_rx_fifo_size(dwc_otg_core_if_t * core_if, int32_t val)
  87068. +{
  87069. + int retval = 0;
  87070. + if (DWC_OTG_PARAM_TEST(val, 16, 32768)) {
  87071. + DWC_WARN("Wrong value for dev_rx_fifo_size\n");
  87072. + DWC_WARN("dev_rx_fifo_size must be 16-32768\n");
  87073. + return -DWC_E_INVALID;
  87074. + }
  87075. +
  87076. + if (val > DWC_READ_REG32(&core_if->core_global_regs->grxfsiz)) {
  87077. + if (dwc_otg_param_initialized(core_if->core_params->dev_rx_fifo_size)) {
  87078. + DWC_WARN("%d invalid for dev_rx_fifo_size parameter\n", val);
  87079. + }
  87080. + val = DWC_READ_REG32(&core_if->core_global_regs->grxfsiz);
  87081. + retval = -DWC_E_INVALID;
  87082. + }
  87083. +
  87084. + core_if->core_params->dev_rx_fifo_size = val;
  87085. + return retval;
  87086. +}
  87087. +
  87088. +int32_t dwc_otg_get_param_dev_rx_fifo_size(dwc_otg_core_if_t * core_if)
  87089. +{
  87090. + return core_if->core_params->dev_rx_fifo_size;
  87091. +}
  87092. +
  87093. +int dwc_otg_set_param_dev_nperio_tx_fifo_size(dwc_otg_core_if_t * core_if,
  87094. + int32_t val)
  87095. +{
  87096. + int retval = 0;
  87097. +
  87098. + if (DWC_OTG_PARAM_TEST(val, 16, 32768)) {
  87099. + DWC_WARN("Wrong value for dev_nperio_tx_fifo\n");
  87100. + DWC_WARN("dev_nperio_tx_fifo must be 16-32768\n");
  87101. + return -DWC_E_INVALID;
  87102. + }
  87103. +
  87104. + if (val > (DWC_READ_REG32(&core_if->core_global_regs->gnptxfsiz) >> 16)) {
  87105. + if (dwc_otg_param_initialized
  87106. + (core_if->core_params->dev_nperio_tx_fifo_size)) {
  87107. + DWC_ERROR
  87108. + ("%d invalid for dev_nperio_tx_fifo_size. Check HW configuration.\n",
  87109. + val);
  87110. + }
  87111. + val =
  87112. + (DWC_READ_REG32(&core_if->core_global_regs->gnptxfsiz) >>
  87113. + 16);
  87114. + retval = -DWC_E_INVALID;
  87115. + }
  87116. +
  87117. + core_if->core_params->dev_nperio_tx_fifo_size = val;
  87118. + return retval;
  87119. +}
  87120. +
  87121. +int32_t dwc_otg_get_param_dev_nperio_tx_fifo_size(dwc_otg_core_if_t * core_if)
  87122. +{
  87123. + return core_if->core_params->dev_nperio_tx_fifo_size;
  87124. +}
  87125. +
  87126. +int dwc_otg_set_param_host_rx_fifo_size(dwc_otg_core_if_t * core_if,
  87127. + int32_t val)
  87128. +{
  87129. + int retval = 0;
  87130. +
  87131. + if (DWC_OTG_PARAM_TEST(val, 16, 32768)) {
  87132. + DWC_WARN("Wrong value for host_rx_fifo_size\n");
  87133. + DWC_WARN("host_rx_fifo_size must be 16-32768\n");
  87134. + return -DWC_E_INVALID;
  87135. + }
  87136. +
  87137. + if (val > DWC_READ_REG32(&core_if->core_global_regs->grxfsiz)) {
  87138. + if (dwc_otg_param_initialized
  87139. + (core_if->core_params->host_rx_fifo_size)) {
  87140. + DWC_ERROR
  87141. + ("%d invalid for host_rx_fifo_size. Check HW configuration.\n",
  87142. + val);
  87143. + }
  87144. + val = DWC_READ_REG32(&core_if->core_global_regs->grxfsiz);
  87145. + retval = -DWC_E_INVALID;
  87146. + }
  87147. +
  87148. + core_if->core_params->host_rx_fifo_size = val;
  87149. + return retval;
  87150. +
  87151. +}
  87152. +
  87153. +int32_t dwc_otg_get_param_host_rx_fifo_size(dwc_otg_core_if_t * core_if)
  87154. +{
  87155. + return core_if->core_params->host_rx_fifo_size;
  87156. +}
  87157. +
  87158. +int dwc_otg_set_param_host_nperio_tx_fifo_size(dwc_otg_core_if_t * core_if,
  87159. + int32_t val)
  87160. +{
  87161. + int retval = 0;
  87162. +
  87163. + if (DWC_OTG_PARAM_TEST(val, 16, 32768)) {
  87164. + DWC_WARN("Wrong value for host_nperio_tx_fifo_size\n");
  87165. + DWC_WARN("host_nperio_tx_fifo_size must be 16-32768\n");
  87166. + return -DWC_E_INVALID;
  87167. + }
  87168. +
  87169. + if (val > (DWC_READ_REG32(&core_if->core_global_regs->gnptxfsiz) >> 16)) {
  87170. + if (dwc_otg_param_initialized
  87171. + (core_if->core_params->host_nperio_tx_fifo_size)) {
  87172. + DWC_ERROR
  87173. + ("%d invalid for host_nperio_tx_fifo_size. Check HW configuration.\n",
  87174. + val);
  87175. + }
  87176. + val =
  87177. + (DWC_READ_REG32(&core_if->core_global_regs->gnptxfsiz) >>
  87178. + 16);
  87179. + retval = -DWC_E_INVALID;
  87180. + }
  87181. +
  87182. + core_if->core_params->host_nperio_tx_fifo_size = val;
  87183. + return retval;
  87184. +}
  87185. +
  87186. +int32_t dwc_otg_get_param_host_nperio_tx_fifo_size(dwc_otg_core_if_t * core_if)
  87187. +{
  87188. + return core_if->core_params->host_nperio_tx_fifo_size;
  87189. +}
  87190. +
  87191. +int dwc_otg_set_param_host_perio_tx_fifo_size(dwc_otg_core_if_t * core_if,
  87192. + int32_t val)
  87193. +{
  87194. + int retval = 0;
  87195. + if (DWC_OTG_PARAM_TEST(val, 16, 32768)) {
  87196. + DWC_WARN("Wrong value for host_perio_tx_fifo_size\n");
  87197. + DWC_WARN("host_perio_tx_fifo_size must be 16-32768\n");
  87198. + return -DWC_E_INVALID;
  87199. + }
  87200. +
  87201. + if (val > ((core_if->hptxfsiz.d32) >> 16)) {
  87202. + if (dwc_otg_param_initialized
  87203. + (core_if->core_params->host_perio_tx_fifo_size)) {
  87204. + DWC_ERROR
  87205. + ("%d invalid for host_perio_tx_fifo_size. Check HW configuration.\n",
  87206. + val);
  87207. + }
  87208. + val = (core_if->hptxfsiz.d32) >> 16;
  87209. + retval = -DWC_E_INVALID;
  87210. + }
  87211. +
  87212. + core_if->core_params->host_perio_tx_fifo_size = val;
  87213. + return retval;
  87214. +}
  87215. +
  87216. +int32_t dwc_otg_get_param_host_perio_tx_fifo_size(dwc_otg_core_if_t * core_if)
  87217. +{
  87218. + return core_if->core_params->host_perio_tx_fifo_size;
  87219. +}
  87220. +
  87221. +int dwc_otg_set_param_max_transfer_size(dwc_otg_core_if_t * core_if,
  87222. + int32_t val)
  87223. +{
  87224. + int retval = 0;
  87225. +
  87226. + if (DWC_OTG_PARAM_TEST(val, 2047, 524288)) {
  87227. + DWC_WARN("Wrong value for max_transfer_size\n");
  87228. + DWC_WARN("max_transfer_size must be 2047-524288\n");
  87229. + return -DWC_E_INVALID;
  87230. + }
  87231. +
  87232. + if (val >= (1 << (core_if->hwcfg3.b.xfer_size_cntr_width + 11))) {
  87233. + if (dwc_otg_param_initialized
  87234. + (core_if->core_params->max_transfer_size)) {
  87235. + DWC_ERROR
  87236. + ("%d invalid for max_transfer_size. Check HW configuration.\n",
  87237. + val);
  87238. + }
  87239. + val =
  87240. + ((1 << (core_if->hwcfg3.b.packet_size_cntr_width + 11)) -
  87241. + 1);
  87242. + retval = -DWC_E_INVALID;
  87243. + }
  87244. +
  87245. + core_if->core_params->max_transfer_size = val;
  87246. + return retval;
  87247. +}
  87248. +
  87249. +int32_t dwc_otg_get_param_max_transfer_size(dwc_otg_core_if_t * core_if)
  87250. +{
  87251. + return core_if->core_params->max_transfer_size;
  87252. +}
  87253. +
  87254. +int dwc_otg_set_param_max_packet_count(dwc_otg_core_if_t * core_if, int32_t val)
  87255. +{
  87256. + int retval = 0;
  87257. +
  87258. + if (DWC_OTG_PARAM_TEST(val, 15, 511)) {
  87259. + DWC_WARN("Wrong value for max_packet_count\n");
  87260. + DWC_WARN("max_packet_count must be 15-511\n");
  87261. + return -DWC_E_INVALID;
  87262. + }
  87263. +
  87264. + if (val > (1 << (core_if->hwcfg3.b.packet_size_cntr_width + 4))) {
  87265. + if (dwc_otg_param_initialized
  87266. + (core_if->core_params->max_packet_count)) {
  87267. + DWC_ERROR
  87268. + ("%d invalid for max_packet_count. Check HW configuration.\n",
  87269. + val);
  87270. + }
  87271. + val =
  87272. + ((1 << (core_if->hwcfg3.b.packet_size_cntr_width + 4)) - 1);
  87273. + retval = -DWC_E_INVALID;
  87274. + }
  87275. +
  87276. + core_if->core_params->max_packet_count = val;
  87277. + return retval;
  87278. +}
  87279. +
  87280. +int32_t dwc_otg_get_param_max_packet_count(dwc_otg_core_if_t * core_if)
  87281. +{
  87282. + return core_if->core_params->max_packet_count;
  87283. +}
  87284. +
  87285. +int dwc_otg_set_param_host_channels(dwc_otg_core_if_t * core_if, int32_t val)
  87286. +{
  87287. + int retval = 0;
  87288. +
  87289. + if (DWC_OTG_PARAM_TEST(val, 1, 16)) {
  87290. + DWC_WARN("Wrong value for host_channels\n");
  87291. + DWC_WARN("host_channels must be 1-16\n");
  87292. + return -DWC_E_INVALID;
  87293. + }
  87294. +
  87295. + if (val > (core_if->hwcfg2.b.num_host_chan + 1)) {
  87296. + if (dwc_otg_param_initialized
  87297. + (core_if->core_params->host_channels)) {
  87298. + DWC_ERROR
  87299. + ("%d invalid for host_channels. Check HW configurations.\n",
  87300. + val);
  87301. + }
  87302. + val = (core_if->hwcfg2.b.num_host_chan + 1);
  87303. + retval = -DWC_E_INVALID;
  87304. + }
  87305. +
  87306. + core_if->core_params->host_channels = val;
  87307. + return retval;
  87308. +}
  87309. +
  87310. +int32_t dwc_otg_get_param_host_channels(dwc_otg_core_if_t * core_if)
  87311. +{
  87312. + return core_if->core_params->host_channels;
  87313. +}
  87314. +
  87315. +int dwc_otg_set_param_dev_endpoints(dwc_otg_core_if_t * core_if, int32_t val)
  87316. +{
  87317. + int retval = 0;
  87318. +
  87319. + if (DWC_OTG_PARAM_TEST(val, 1, 15)) {
  87320. + DWC_WARN("Wrong value for dev_endpoints\n");
  87321. + DWC_WARN("dev_endpoints must be 1-15\n");
  87322. + return -DWC_E_INVALID;
  87323. + }
  87324. +
  87325. + if (val > (core_if->hwcfg2.b.num_dev_ep)) {
  87326. + if (dwc_otg_param_initialized
  87327. + (core_if->core_params->dev_endpoints)) {
  87328. + DWC_ERROR
  87329. + ("%d invalid for dev_endpoints. Check HW configurations.\n",
  87330. + val);
  87331. + }
  87332. + val = core_if->hwcfg2.b.num_dev_ep;
  87333. + retval = -DWC_E_INVALID;
  87334. + }
  87335. +
  87336. + core_if->core_params->dev_endpoints = val;
  87337. + return retval;
  87338. +}
  87339. +
  87340. +int32_t dwc_otg_get_param_dev_endpoints(dwc_otg_core_if_t * core_if)
  87341. +{
  87342. + return core_if->core_params->dev_endpoints;
  87343. +}
  87344. +
  87345. +int dwc_otg_set_param_phy_type(dwc_otg_core_if_t * core_if, int32_t val)
  87346. +{
  87347. + int retval = 0;
  87348. + int valid = 0;
  87349. +
  87350. + if (DWC_OTG_PARAM_TEST(val, 0, 2)) {
  87351. + DWC_WARN("Wrong value for phy_type\n");
  87352. + DWC_WARN("phy_type must be 0,1 or 2\n");
  87353. + return -DWC_E_INVALID;
  87354. + }
  87355. +#ifndef NO_FS_PHY_HW_CHECKS
  87356. + if ((val == DWC_PHY_TYPE_PARAM_UTMI) &&
  87357. + ((core_if->hwcfg2.b.hs_phy_type == 1) ||
  87358. + (core_if->hwcfg2.b.hs_phy_type == 3))) {
  87359. + valid = 1;
  87360. + } else if ((val == DWC_PHY_TYPE_PARAM_ULPI) &&
  87361. + ((core_if->hwcfg2.b.hs_phy_type == 2) ||
  87362. + (core_if->hwcfg2.b.hs_phy_type == 3))) {
  87363. + valid = 1;
  87364. + } else if ((val == DWC_PHY_TYPE_PARAM_FS) &&
  87365. + (core_if->hwcfg2.b.fs_phy_type == 1)) {
  87366. + valid = 1;
  87367. + }
  87368. + if (!valid) {
  87369. + if (dwc_otg_param_initialized(core_if->core_params->phy_type)) {
  87370. + DWC_ERROR
  87371. + ("%d invalid for phy_type. Check HW configurations.\n",
  87372. + val);
  87373. + }
  87374. + if (core_if->hwcfg2.b.hs_phy_type) {
  87375. + if ((core_if->hwcfg2.b.hs_phy_type == 3) ||
  87376. + (core_if->hwcfg2.b.hs_phy_type == 1)) {
  87377. + val = DWC_PHY_TYPE_PARAM_UTMI;
  87378. + } else {
  87379. + val = DWC_PHY_TYPE_PARAM_ULPI;
  87380. + }
  87381. + }
  87382. + retval = -DWC_E_INVALID;
  87383. + }
  87384. +#endif
  87385. + core_if->core_params->phy_type = val;
  87386. + return retval;
  87387. +}
  87388. +
  87389. +int32_t dwc_otg_get_param_phy_type(dwc_otg_core_if_t * core_if)
  87390. +{
  87391. + return core_if->core_params->phy_type;
  87392. +}
  87393. +
  87394. +int dwc_otg_set_param_speed(dwc_otg_core_if_t * core_if, int32_t val)
  87395. +{
  87396. + int retval = 0;
  87397. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  87398. + DWC_WARN("Wrong value for speed parameter\n");
  87399. + DWC_WARN("max_speed parameter must be 0 or 1\n");
  87400. + return -DWC_E_INVALID;
  87401. + }
  87402. + if ((val == 0)
  87403. + && dwc_otg_get_param_phy_type(core_if) == DWC_PHY_TYPE_PARAM_FS) {
  87404. + if (dwc_otg_param_initialized(core_if->core_params->speed)) {
  87405. + DWC_ERROR
  87406. + ("%d invalid for speed paremter. Check HW configuration.\n",
  87407. + val);
  87408. + }
  87409. + val =
  87410. + (dwc_otg_get_param_phy_type(core_if) ==
  87411. + DWC_PHY_TYPE_PARAM_FS ? 1 : 0);
  87412. + retval = -DWC_E_INVALID;
  87413. + }
  87414. + core_if->core_params->speed = val;
  87415. + return retval;
  87416. +}
  87417. +
  87418. +int32_t dwc_otg_get_param_speed(dwc_otg_core_if_t * core_if)
  87419. +{
  87420. + return core_if->core_params->speed;
  87421. +}
  87422. +
  87423. +int dwc_otg_set_param_host_ls_low_power_phy_clk(dwc_otg_core_if_t * core_if,
  87424. + int32_t val)
  87425. +{
  87426. + int retval = 0;
  87427. +
  87428. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  87429. + DWC_WARN
  87430. + ("Wrong value for host_ls_low_power_phy_clk parameter\n");
  87431. + DWC_WARN("host_ls_low_power_phy_clk must be 0 or 1\n");
  87432. + return -DWC_E_INVALID;
  87433. + }
  87434. +
  87435. + if ((val == DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ)
  87436. + && (dwc_otg_get_param_phy_type(core_if) == DWC_PHY_TYPE_PARAM_FS)) {
  87437. + if (dwc_otg_param_initialized
  87438. + (core_if->core_params->host_ls_low_power_phy_clk)) {
  87439. + DWC_ERROR
  87440. + ("%d invalid for host_ls_low_power_phy_clk. Check HW configuration.\n",
  87441. + val);
  87442. + }
  87443. + val =
  87444. + (dwc_otg_get_param_phy_type(core_if) ==
  87445. + DWC_PHY_TYPE_PARAM_FS) ?
  87446. + DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ :
  87447. + DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ;
  87448. + retval = -DWC_E_INVALID;
  87449. + }
  87450. +
  87451. + core_if->core_params->host_ls_low_power_phy_clk = val;
  87452. + return retval;
  87453. +}
  87454. +
  87455. +int32_t dwc_otg_get_param_host_ls_low_power_phy_clk(dwc_otg_core_if_t * core_if)
  87456. +{
  87457. + return core_if->core_params->host_ls_low_power_phy_clk;
  87458. +}
  87459. +
  87460. +int dwc_otg_set_param_phy_ulpi_ddr(dwc_otg_core_if_t * core_if, int32_t val)
  87461. +{
  87462. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  87463. + DWC_WARN("Wrong value for phy_ulpi_ddr\n");
  87464. + DWC_WARN("phy_upli_ddr must be 0 or 1\n");
  87465. + return -DWC_E_INVALID;
  87466. + }
  87467. +
  87468. + core_if->core_params->phy_ulpi_ddr = val;
  87469. + return 0;
  87470. +}
  87471. +
  87472. +int32_t dwc_otg_get_param_phy_ulpi_ddr(dwc_otg_core_if_t * core_if)
  87473. +{
  87474. + return core_if->core_params->phy_ulpi_ddr;
  87475. +}
  87476. +
  87477. +int dwc_otg_set_param_phy_ulpi_ext_vbus(dwc_otg_core_if_t * core_if,
  87478. + int32_t val)
  87479. +{
  87480. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  87481. + DWC_WARN("Wrong valaue for phy_ulpi_ext_vbus\n");
  87482. + DWC_WARN("phy_ulpi_ext_vbus must be 0 or 1\n");
  87483. + return -DWC_E_INVALID;
  87484. + }
  87485. +
  87486. + core_if->core_params->phy_ulpi_ext_vbus = val;
  87487. + return 0;
  87488. +}
  87489. +
  87490. +int32_t dwc_otg_get_param_phy_ulpi_ext_vbus(dwc_otg_core_if_t * core_if)
  87491. +{
  87492. + return core_if->core_params->phy_ulpi_ext_vbus;
  87493. +}
  87494. +
  87495. +int dwc_otg_set_param_phy_utmi_width(dwc_otg_core_if_t * core_if, int32_t val)
  87496. +{
  87497. + if (DWC_OTG_PARAM_TEST(val, 8, 8) && DWC_OTG_PARAM_TEST(val, 16, 16)) {
  87498. + DWC_WARN("Wrong valaue for phy_utmi_width\n");
  87499. + DWC_WARN("phy_utmi_width must be 8 or 16\n");
  87500. + return -DWC_E_INVALID;
  87501. + }
  87502. +
  87503. + core_if->core_params->phy_utmi_width = val;
  87504. + return 0;
  87505. +}
  87506. +
  87507. +int32_t dwc_otg_get_param_phy_utmi_width(dwc_otg_core_if_t * core_if)
  87508. +{
  87509. + return core_if->core_params->phy_utmi_width;
  87510. +}
  87511. +
  87512. +int dwc_otg_set_param_ulpi_fs_ls(dwc_otg_core_if_t * core_if, int32_t val)
  87513. +{
  87514. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  87515. + DWC_WARN("Wrong valaue for ulpi_fs_ls\n");
  87516. + DWC_WARN("ulpi_fs_ls must be 0 or 1\n");
  87517. + return -DWC_E_INVALID;
  87518. + }
  87519. +
  87520. + core_if->core_params->ulpi_fs_ls = val;
  87521. + return 0;
  87522. +}
  87523. +
  87524. +int32_t dwc_otg_get_param_ulpi_fs_ls(dwc_otg_core_if_t * core_if)
  87525. +{
  87526. + return core_if->core_params->ulpi_fs_ls;
  87527. +}
  87528. +
  87529. +int dwc_otg_set_param_ts_dline(dwc_otg_core_if_t * core_if, int32_t val)
  87530. +{
  87531. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  87532. + DWC_WARN("Wrong valaue for ts_dline\n");
  87533. + DWC_WARN("ts_dline must be 0 or 1\n");
  87534. + return -DWC_E_INVALID;
  87535. + }
  87536. +
  87537. + core_if->core_params->ts_dline = val;
  87538. + return 0;
  87539. +}
  87540. +
  87541. +int32_t dwc_otg_get_param_ts_dline(dwc_otg_core_if_t * core_if)
  87542. +{
  87543. + return core_if->core_params->ts_dline;
  87544. +}
  87545. +
  87546. +int dwc_otg_set_param_i2c_enable(dwc_otg_core_if_t * core_if, int32_t val)
  87547. +{
  87548. + int retval = 0;
  87549. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  87550. + DWC_WARN("Wrong valaue for i2c_enable\n");
  87551. + DWC_WARN("i2c_enable must be 0 or 1\n");
  87552. + return -DWC_E_INVALID;
  87553. + }
  87554. +#ifndef NO_FS_PHY_HW_CHECK
  87555. + if (val == 1 && core_if->hwcfg3.b.i2c == 0) {
  87556. + if (dwc_otg_param_initialized(core_if->core_params->i2c_enable)) {
  87557. + DWC_ERROR
  87558. + ("%d invalid for i2c_enable. Check HW configuration.\n",
  87559. + val);
  87560. + }
  87561. + val = 0;
  87562. + retval = -DWC_E_INVALID;
  87563. + }
  87564. +#endif
  87565. +
  87566. + core_if->core_params->i2c_enable = val;
  87567. + return retval;
  87568. +}
  87569. +
  87570. +int32_t dwc_otg_get_param_i2c_enable(dwc_otg_core_if_t * core_if)
  87571. +{
  87572. + return core_if->core_params->i2c_enable;
  87573. +}
  87574. +
  87575. +int dwc_otg_set_param_dev_perio_tx_fifo_size(dwc_otg_core_if_t * core_if,
  87576. + int32_t val, int fifo_num)
  87577. +{
  87578. + int retval = 0;
  87579. +
  87580. + if (DWC_OTG_PARAM_TEST(val, 4, 768)) {
  87581. + DWC_WARN("Wrong value for dev_perio_tx_fifo_size\n");
  87582. + DWC_WARN("dev_perio_tx_fifo_size must be 4-768\n");
  87583. + return -DWC_E_INVALID;
  87584. + }
  87585. +
  87586. + if (val >
  87587. + (DWC_READ_REG32(&core_if->core_global_regs->dtxfsiz[fifo_num]))) {
  87588. + if (dwc_otg_param_initialized
  87589. + (core_if->core_params->dev_perio_tx_fifo_size[fifo_num])) {
  87590. + DWC_ERROR
  87591. + ("`%d' invalid for parameter `dev_perio_fifo_size_%d'. Check HW configuration.\n",
  87592. + val, fifo_num);
  87593. + }
  87594. + val = (DWC_READ_REG32(&core_if->core_global_regs->dtxfsiz[fifo_num]));
  87595. + retval = -DWC_E_INVALID;
  87596. + }
  87597. +
  87598. + core_if->core_params->dev_perio_tx_fifo_size[fifo_num] = val;
  87599. + return retval;
  87600. +}
  87601. +
  87602. +int32_t dwc_otg_get_param_dev_perio_tx_fifo_size(dwc_otg_core_if_t * core_if,
  87603. + int fifo_num)
  87604. +{
  87605. + return core_if->core_params->dev_perio_tx_fifo_size[fifo_num];
  87606. +}
  87607. +
  87608. +int dwc_otg_set_param_en_multiple_tx_fifo(dwc_otg_core_if_t * core_if,
  87609. + int32_t val)
  87610. +{
  87611. + int retval = 0;
  87612. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  87613. + DWC_WARN("Wrong valaue for en_multiple_tx_fifo,\n");
  87614. + DWC_WARN("en_multiple_tx_fifo must be 0 or 1\n");
  87615. + return -DWC_E_INVALID;
  87616. + }
  87617. +
  87618. + if (val == 1 && core_if->hwcfg4.b.ded_fifo_en == 0) {
  87619. + if (dwc_otg_param_initialized
  87620. + (core_if->core_params->en_multiple_tx_fifo)) {
  87621. + DWC_ERROR
  87622. + ("%d invalid for parameter en_multiple_tx_fifo. Check HW configuration.\n",
  87623. + val);
  87624. + }
  87625. + val = 0;
  87626. + retval = -DWC_E_INVALID;
  87627. + }
  87628. +
  87629. + core_if->core_params->en_multiple_tx_fifo = val;
  87630. + return retval;
  87631. +}
  87632. +
  87633. +int32_t dwc_otg_get_param_en_multiple_tx_fifo(dwc_otg_core_if_t * core_if)
  87634. +{
  87635. + return core_if->core_params->en_multiple_tx_fifo;
  87636. +}
  87637. +
  87638. +int dwc_otg_set_param_dev_tx_fifo_size(dwc_otg_core_if_t * core_if, int32_t val,
  87639. + int fifo_num)
  87640. +{
  87641. + int retval = 0;
  87642. +
  87643. + if (DWC_OTG_PARAM_TEST(val, 4, 768)) {
  87644. + DWC_WARN("Wrong value for dev_tx_fifo_size\n");
  87645. + DWC_WARN("dev_tx_fifo_size must be 4-768\n");
  87646. + return -DWC_E_INVALID;
  87647. + }
  87648. +
  87649. + if (val >
  87650. + (DWC_READ_REG32(&core_if->core_global_regs->dtxfsiz[fifo_num]))) {
  87651. + if (dwc_otg_param_initialized
  87652. + (core_if->core_params->dev_tx_fifo_size[fifo_num])) {
  87653. + DWC_ERROR
  87654. + ("`%d' invalid for parameter `dev_tx_fifo_size_%d'. Check HW configuration.\n",
  87655. + val, fifo_num);
  87656. + }
  87657. + val = (DWC_READ_REG32(&core_if->core_global_regs->dtxfsiz[fifo_num]));
  87658. + retval = -DWC_E_INVALID;
  87659. + }
  87660. +
  87661. + core_if->core_params->dev_tx_fifo_size[fifo_num] = val;
  87662. + return retval;
  87663. +}
  87664. +
  87665. +int32_t dwc_otg_get_param_dev_tx_fifo_size(dwc_otg_core_if_t * core_if,
  87666. + int fifo_num)
  87667. +{
  87668. + return core_if->core_params->dev_tx_fifo_size[fifo_num];
  87669. +}
  87670. +
  87671. +int dwc_otg_set_param_thr_ctl(dwc_otg_core_if_t * core_if, int32_t val)
  87672. +{
  87673. + int retval = 0;
  87674. +
  87675. + if (DWC_OTG_PARAM_TEST(val, 0, 7)) {
  87676. + DWC_WARN("Wrong value for thr_ctl\n");
  87677. + DWC_WARN("thr_ctl must be 0-7\n");
  87678. + return -DWC_E_INVALID;
  87679. + }
  87680. +
  87681. + if ((val != 0) &&
  87682. + (!dwc_otg_get_param_dma_enable(core_if) ||
  87683. + !core_if->hwcfg4.b.ded_fifo_en)) {
  87684. + if (dwc_otg_param_initialized(core_if->core_params->thr_ctl)) {
  87685. + DWC_ERROR
  87686. + ("%d invalid for parameter thr_ctl. Check HW configuration.\n",
  87687. + val);
  87688. + }
  87689. + val = 0;
  87690. + retval = -DWC_E_INVALID;
  87691. + }
  87692. +
  87693. + core_if->core_params->thr_ctl = val;
  87694. + return retval;
  87695. +}
  87696. +
  87697. +int32_t dwc_otg_get_param_thr_ctl(dwc_otg_core_if_t * core_if)
  87698. +{
  87699. + return core_if->core_params->thr_ctl;
  87700. +}
  87701. +
  87702. +int dwc_otg_set_param_lpm_enable(dwc_otg_core_if_t * core_if, int32_t val)
  87703. +{
  87704. + int retval = 0;
  87705. +
  87706. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  87707. + DWC_WARN("Wrong value for lpm_enable\n");
  87708. + DWC_WARN("lpm_enable must be 0 or 1\n");
  87709. + return -DWC_E_INVALID;
  87710. + }
  87711. +
  87712. + if (val && !core_if->hwcfg3.b.otg_lpm_en) {
  87713. + if (dwc_otg_param_initialized(core_if->core_params->lpm_enable)) {
  87714. + DWC_ERROR
  87715. + ("%d invalid for parameter lpm_enable. Check HW configuration.\n",
  87716. + val);
  87717. + }
  87718. + val = 0;
  87719. + retval = -DWC_E_INVALID;
  87720. + }
  87721. +
  87722. + core_if->core_params->lpm_enable = val;
  87723. + return retval;
  87724. +}
  87725. +
  87726. +int32_t dwc_otg_get_param_lpm_enable(dwc_otg_core_if_t * core_if)
  87727. +{
  87728. + return core_if->core_params->lpm_enable;
  87729. +}
  87730. +
  87731. +int dwc_otg_set_param_tx_thr_length(dwc_otg_core_if_t * core_if, int32_t val)
  87732. +{
  87733. + if (DWC_OTG_PARAM_TEST(val, 8, 128)) {
  87734. + DWC_WARN("Wrong valaue for tx_thr_length\n");
  87735. + DWC_WARN("tx_thr_length must be 8 - 128\n");
  87736. + return -DWC_E_INVALID;
  87737. + }
  87738. +
  87739. + core_if->core_params->tx_thr_length = val;
  87740. + return 0;
  87741. +}
  87742. +
  87743. +int32_t dwc_otg_get_param_tx_thr_length(dwc_otg_core_if_t * core_if)
  87744. +{
  87745. + return core_if->core_params->tx_thr_length;
  87746. +}
  87747. +
  87748. +int dwc_otg_set_param_rx_thr_length(dwc_otg_core_if_t * core_if, int32_t val)
  87749. +{
  87750. + if (DWC_OTG_PARAM_TEST(val, 8, 128)) {
  87751. + DWC_WARN("Wrong valaue for rx_thr_length\n");
  87752. + DWC_WARN("rx_thr_length must be 8 - 128\n");
  87753. + return -DWC_E_INVALID;
  87754. + }
  87755. +
  87756. + core_if->core_params->rx_thr_length = val;
  87757. + return 0;
  87758. +}
  87759. +
  87760. +int32_t dwc_otg_get_param_rx_thr_length(dwc_otg_core_if_t * core_if)
  87761. +{
  87762. + return core_if->core_params->rx_thr_length;
  87763. +}
  87764. +
  87765. +int dwc_otg_set_param_dma_burst_size(dwc_otg_core_if_t * core_if, int32_t val)
  87766. +{
  87767. + if (DWC_OTG_PARAM_TEST(val, 1, 1) &&
  87768. + DWC_OTG_PARAM_TEST(val, 4, 4) &&
  87769. + DWC_OTG_PARAM_TEST(val, 8, 8) &&
  87770. + DWC_OTG_PARAM_TEST(val, 16, 16) &&
  87771. + DWC_OTG_PARAM_TEST(val, 32, 32) &&
  87772. + DWC_OTG_PARAM_TEST(val, 64, 64) &&
  87773. + DWC_OTG_PARAM_TEST(val, 128, 128) &&
  87774. + DWC_OTG_PARAM_TEST(val, 256, 256)) {
  87775. + DWC_WARN("`%d' invalid for parameter `dma_burst_size'\n", val);
  87776. + return -DWC_E_INVALID;
  87777. + }
  87778. + core_if->core_params->dma_burst_size = val;
  87779. + return 0;
  87780. +}
  87781. +
  87782. +int32_t dwc_otg_get_param_dma_burst_size(dwc_otg_core_if_t * core_if)
  87783. +{
  87784. + return core_if->core_params->dma_burst_size;
  87785. +}
  87786. +
  87787. +int dwc_otg_set_param_pti_enable(dwc_otg_core_if_t * core_if, int32_t val)
  87788. +{
  87789. + int retval = 0;
  87790. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  87791. + DWC_WARN("`%d' invalid for parameter `pti_enable'\n", val);
  87792. + return -DWC_E_INVALID;
  87793. + }
  87794. + if (val && (core_if->snpsid < OTG_CORE_REV_2_72a)) {
  87795. + if (dwc_otg_param_initialized(core_if->core_params->pti_enable)) {
  87796. + DWC_ERROR
  87797. + ("%d invalid for parameter pti_enable. Check HW configuration.\n",
  87798. + val);
  87799. + }
  87800. + retval = -DWC_E_INVALID;
  87801. + val = 0;
  87802. + }
  87803. + core_if->core_params->pti_enable = val;
  87804. + return retval;
  87805. +}
  87806. +
  87807. +int32_t dwc_otg_get_param_pti_enable(dwc_otg_core_if_t * core_if)
  87808. +{
  87809. + return core_if->core_params->pti_enable;
  87810. +}
  87811. +
  87812. +int dwc_otg_set_param_mpi_enable(dwc_otg_core_if_t * core_if, int32_t val)
  87813. +{
  87814. + int retval = 0;
  87815. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  87816. + DWC_WARN("`%d' invalid for parameter `mpi_enable'\n", val);
  87817. + return -DWC_E_INVALID;
  87818. + }
  87819. + if (val && (core_if->hwcfg2.b.multi_proc_int == 0)) {
  87820. + if (dwc_otg_param_initialized(core_if->core_params->mpi_enable)) {
  87821. + DWC_ERROR
  87822. + ("%d invalid for parameter mpi_enable. Check HW configuration.\n",
  87823. + val);
  87824. + }
  87825. + retval = -DWC_E_INVALID;
  87826. + val = 0;
  87827. + }
  87828. + core_if->core_params->mpi_enable = val;
  87829. + return retval;
  87830. +}
  87831. +
  87832. +int32_t dwc_otg_get_param_mpi_enable(dwc_otg_core_if_t * core_if)
  87833. +{
  87834. + return core_if->core_params->mpi_enable;
  87835. +}
  87836. +
  87837. +int dwc_otg_set_param_adp_enable(dwc_otg_core_if_t * core_if, int32_t val)
  87838. +{
  87839. + int retval = 0;
  87840. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  87841. + DWC_WARN("`%d' invalid for parameter `adp_enable'\n", val);
  87842. + return -DWC_E_INVALID;
  87843. + }
  87844. + if (val && (core_if->hwcfg3.b.adp_supp == 0)) {
  87845. + if (dwc_otg_param_initialized
  87846. + (core_if->core_params->adp_supp_enable)) {
  87847. + DWC_ERROR
  87848. + ("%d invalid for parameter adp_enable. Check HW configuration.\n",
  87849. + val);
  87850. + }
  87851. + retval = -DWC_E_INVALID;
  87852. + val = 0;
  87853. + }
  87854. + core_if->core_params->adp_supp_enable = val;
  87855. + /*Set OTG version 2.0 in case of enabling ADP*/
  87856. + if (val)
  87857. + dwc_otg_set_param_otg_ver(core_if, 1);
  87858. +
  87859. + return retval;
  87860. +}
  87861. +
  87862. +int32_t dwc_otg_get_param_adp_enable(dwc_otg_core_if_t * core_if)
  87863. +{
  87864. + return core_if->core_params->adp_supp_enable;
  87865. +}
  87866. +
  87867. +int dwc_otg_set_param_ic_usb_cap(dwc_otg_core_if_t * core_if, int32_t val)
  87868. +{
  87869. + int retval = 0;
  87870. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  87871. + DWC_WARN("`%d' invalid for parameter `ic_usb_cap'\n", val);
  87872. + DWC_WARN("ic_usb_cap must be 0 or 1\n");
  87873. + return -DWC_E_INVALID;
  87874. + }
  87875. +
  87876. + if (val && (core_if->hwcfg2.b.otg_enable_ic_usb == 0)) {
  87877. + if (dwc_otg_param_initialized(core_if->core_params->ic_usb_cap)) {
  87878. + DWC_ERROR
  87879. + ("%d invalid for parameter ic_usb_cap. Check HW configuration.\n",
  87880. + val);
  87881. + }
  87882. + retval = -DWC_E_INVALID;
  87883. + val = 0;
  87884. + }
  87885. + core_if->core_params->ic_usb_cap = val;
  87886. + return retval;
  87887. +}
  87888. +
  87889. +int32_t dwc_otg_get_param_ic_usb_cap(dwc_otg_core_if_t * core_if)
  87890. +{
  87891. + return core_if->core_params->ic_usb_cap;
  87892. +}
  87893. +
  87894. +int dwc_otg_set_param_ahb_thr_ratio(dwc_otg_core_if_t * core_if, int32_t val)
  87895. +{
  87896. + int retval = 0;
  87897. + int valid = 1;
  87898. +
  87899. + if (DWC_OTG_PARAM_TEST(val, 0, 3)) {
  87900. + DWC_WARN("`%d' invalid for parameter `ahb_thr_ratio'\n", val);
  87901. + DWC_WARN("ahb_thr_ratio must be 0 - 3\n");
  87902. + return -DWC_E_INVALID;
  87903. + }
  87904. +
  87905. + if (val
  87906. + && (core_if->snpsid < OTG_CORE_REV_2_81a
  87907. + || !dwc_otg_get_param_thr_ctl(core_if))) {
  87908. + valid = 0;
  87909. + } else if (val
  87910. + && ((dwc_otg_get_param_tx_thr_length(core_if) / (1 << val)) <
  87911. + 4)) {
  87912. + valid = 0;
  87913. + }
  87914. + if (valid == 0) {
  87915. + if (dwc_otg_param_initialized
  87916. + (core_if->core_params->ahb_thr_ratio)) {
  87917. + DWC_ERROR
  87918. + ("%d invalid for parameter ahb_thr_ratio. Check HW configuration.\n",
  87919. + val);
  87920. + }
  87921. + retval = -DWC_E_INVALID;
  87922. + val = 0;
  87923. + }
  87924. +
  87925. + core_if->core_params->ahb_thr_ratio = val;
  87926. + return retval;
  87927. +}
  87928. +
  87929. +int32_t dwc_otg_get_param_ahb_thr_ratio(dwc_otg_core_if_t * core_if)
  87930. +{
  87931. + return core_if->core_params->ahb_thr_ratio;
  87932. +}
  87933. +
  87934. +int dwc_otg_set_param_power_down(dwc_otg_core_if_t * core_if, int32_t val)
  87935. +{
  87936. + int retval = 0;
  87937. + int valid = 1;
  87938. + hwcfg4_data_t hwcfg4 = {.d32 = 0 };
  87939. + hwcfg4.d32 = DWC_READ_REG32(&core_if->core_global_regs->ghwcfg4);
  87940. +
  87941. + if (DWC_OTG_PARAM_TEST(val, 0, 3)) {
  87942. + DWC_WARN("`%d' invalid for parameter `power_down'\n", val);
  87943. + DWC_WARN("power_down must be 0 - 2\n");
  87944. + return -DWC_E_INVALID;
  87945. + }
  87946. +
  87947. + if ((val == 2) && (core_if->snpsid < OTG_CORE_REV_2_91a)) {
  87948. + valid = 0;
  87949. + }
  87950. + if ((val == 3)
  87951. + && ((core_if->snpsid < OTG_CORE_REV_3_00a)
  87952. + || (hwcfg4.b.xhiber == 0))) {
  87953. + valid = 0;
  87954. + }
  87955. + if (valid == 0) {
  87956. + if (dwc_otg_param_initialized(core_if->core_params->power_down)) {
  87957. + DWC_ERROR
  87958. + ("%d invalid for parameter power_down. Check HW configuration.\n",
  87959. + val);
  87960. + }
  87961. + retval = -DWC_E_INVALID;
  87962. + val = 0;
  87963. + }
  87964. + core_if->core_params->power_down = val;
  87965. + return retval;
  87966. +}
  87967. +
  87968. +int32_t dwc_otg_get_param_power_down(dwc_otg_core_if_t * core_if)
  87969. +{
  87970. + return core_if->core_params->power_down;
  87971. +}
  87972. +
  87973. +int dwc_otg_set_param_reload_ctl(dwc_otg_core_if_t * core_if, int32_t val)
  87974. +{
  87975. + int retval = 0;
  87976. + int valid = 1;
  87977. +
  87978. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  87979. + DWC_WARN("`%d' invalid for parameter `reload_ctl'\n", val);
  87980. + DWC_WARN("reload_ctl must be 0 or 1\n");
  87981. + return -DWC_E_INVALID;
  87982. + }
  87983. +
  87984. + if ((val == 1) && (core_if->snpsid < OTG_CORE_REV_2_92a)) {
  87985. + valid = 0;
  87986. + }
  87987. + if (valid == 0) {
  87988. + if (dwc_otg_param_initialized(core_if->core_params->reload_ctl)) {
  87989. + DWC_ERROR("%d invalid for parameter reload_ctl."
  87990. + "Check HW configuration.\n", val);
  87991. + }
  87992. + retval = -DWC_E_INVALID;
  87993. + val = 0;
  87994. + }
  87995. + core_if->core_params->reload_ctl = val;
  87996. + return retval;
  87997. +}
  87998. +
  87999. +int32_t dwc_otg_get_param_reload_ctl(dwc_otg_core_if_t * core_if)
  88000. +{
  88001. + return core_if->core_params->reload_ctl;
  88002. +}
  88003. +
  88004. +int dwc_otg_set_param_dev_out_nak(dwc_otg_core_if_t * core_if, int32_t val)
  88005. +{
  88006. + int retval = 0;
  88007. + int valid = 1;
  88008. +
  88009. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  88010. + DWC_WARN("`%d' invalid for parameter `dev_out_nak'\n", val);
  88011. + DWC_WARN("dev_out_nak must be 0 or 1\n");
  88012. + return -DWC_E_INVALID;
  88013. + }
  88014. +
  88015. + if ((val == 1) && ((core_if->snpsid < OTG_CORE_REV_2_93a) ||
  88016. + !(core_if->core_params->dma_desc_enable))) {
  88017. + valid = 0;
  88018. + }
  88019. + if (valid == 0) {
  88020. + if (dwc_otg_param_initialized(core_if->core_params->dev_out_nak)) {
  88021. + DWC_ERROR("%d invalid for parameter dev_out_nak."
  88022. + "Check HW configuration.\n", val);
  88023. + }
  88024. + retval = -DWC_E_INVALID;
  88025. + val = 0;
  88026. + }
  88027. + core_if->core_params->dev_out_nak = val;
  88028. + return retval;
  88029. +}
  88030. +
  88031. +int32_t dwc_otg_get_param_dev_out_nak(dwc_otg_core_if_t * core_if)
  88032. +{
  88033. + return core_if->core_params->dev_out_nak;
  88034. +}
  88035. +
  88036. +int dwc_otg_set_param_cont_on_bna(dwc_otg_core_if_t * core_if, int32_t val)
  88037. +{
  88038. + int retval = 0;
  88039. + int valid = 1;
  88040. +
  88041. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  88042. + DWC_WARN("`%d' invalid for parameter `cont_on_bna'\n", val);
  88043. + DWC_WARN("cont_on_bna must be 0 or 1\n");
  88044. + return -DWC_E_INVALID;
  88045. + }
  88046. +
  88047. + if ((val == 1) && ((core_if->snpsid < OTG_CORE_REV_2_94a) ||
  88048. + !(core_if->core_params->dma_desc_enable))) {
  88049. + valid = 0;
  88050. + }
  88051. + if (valid == 0) {
  88052. + if (dwc_otg_param_initialized(core_if->core_params->cont_on_bna)) {
  88053. + DWC_ERROR("%d invalid for parameter cont_on_bna."
  88054. + "Check HW configuration.\n", val);
  88055. + }
  88056. + retval = -DWC_E_INVALID;
  88057. + val = 0;
  88058. + }
  88059. + core_if->core_params->cont_on_bna = val;
  88060. + return retval;
  88061. +}
  88062. +
  88063. +int32_t dwc_otg_get_param_cont_on_bna(dwc_otg_core_if_t * core_if)
  88064. +{
  88065. + return core_if->core_params->cont_on_bna;
  88066. +}
  88067. +
  88068. +int dwc_otg_set_param_ahb_single(dwc_otg_core_if_t * core_if, int32_t val)
  88069. +{
  88070. + int retval = 0;
  88071. + int valid = 1;
  88072. +
  88073. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  88074. + DWC_WARN("`%d' invalid for parameter `ahb_single'\n", val);
  88075. + DWC_WARN("ahb_single must be 0 or 1\n");
  88076. + return -DWC_E_INVALID;
  88077. + }
  88078. +
  88079. + if ((val == 1) && (core_if->snpsid < OTG_CORE_REV_2_94a)) {
  88080. + valid = 0;
  88081. + }
  88082. + if (valid == 0) {
  88083. + if (dwc_otg_param_initialized(core_if->core_params->ahb_single)) {
  88084. + DWC_ERROR("%d invalid for parameter ahb_single."
  88085. + "Check HW configuration.\n", val);
  88086. + }
  88087. + retval = -DWC_E_INVALID;
  88088. + val = 0;
  88089. + }
  88090. + core_if->core_params->ahb_single = val;
  88091. + return retval;
  88092. +}
  88093. +
  88094. +int32_t dwc_otg_get_param_ahb_single(dwc_otg_core_if_t * core_if)
  88095. +{
  88096. + return core_if->core_params->ahb_single;
  88097. +}
  88098. +
  88099. +int dwc_otg_set_param_otg_ver(dwc_otg_core_if_t * core_if, int32_t val)
  88100. +{
  88101. + int retval = 0;
  88102. +
  88103. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  88104. + DWC_WARN("`%d' invalid for parameter `otg_ver'\n", val);
  88105. + DWC_WARN
  88106. + ("otg_ver must be 0(for OTG 1.3 support) or 1(for OTG 2.0 support)\n");
  88107. + return -DWC_E_INVALID;
  88108. + }
  88109. +
  88110. + core_if->core_params->otg_ver = val;
  88111. + return retval;
  88112. +}
  88113. +
  88114. +int32_t dwc_otg_get_param_otg_ver(dwc_otg_core_if_t * core_if)
  88115. +{
  88116. + return core_if->core_params->otg_ver;
  88117. +}
  88118. +
  88119. +uint32_t dwc_otg_get_hnpstatus(dwc_otg_core_if_t * core_if)
  88120. +{
  88121. + gotgctl_data_t otgctl;
  88122. + otgctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  88123. + return otgctl.b.hstnegscs;
  88124. +}
  88125. +
  88126. +uint32_t dwc_otg_get_srpstatus(dwc_otg_core_if_t * core_if)
  88127. +{
  88128. + gotgctl_data_t otgctl;
  88129. + otgctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  88130. + return otgctl.b.sesreqscs;
  88131. +}
  88132. +
  88133. +void dwc_otg_set_hnpreq(dwc_otg_core_if_t * core_if, uint32_t val)
  88134. +{
  88135. + if(core_if->otg_ver == 0) {
  88136. + gotgctl_data_t otgctl;
  88137. + otgctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  88138. + otgctl.b.hnpreq = val;
  88139. + DWC_WRITE_REG32(&core_if->core_global_regs->gotgctl, otgctl.d32);
  88140. + } else {
  88141. + core_if->otg_sts = val;
  88142. + }
  88143. +}
  88144. +
  88145. +uint32_t dwc_otg_get_gsnpsid(dwc_otg_core_if_t * core_if)
  88146. +{
  88147. + return core_if->snpsid;
  88148. +}
  88149. +
  88150. +uint32_t dwc_otg_get_mode(dwc_otg_core_if_t * core_if)
  88151. +{
  88152. + gintsts_data_t gintsts;
  88153. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  88154. + return gintsts.b.curmode;
  88155. +}
  88156. +
  88157. +uint32_t dwc_otg_get_hnpcapable(dwc_otg_core_if_t * core_if)
  88158. +{
  88159. + gusbcfg_data_t usbcfg;
  88160. + usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  88161. + return usbcfg.b.hnpcap;
  88162. +}
  88163. +
  88164. +void dwc_otg_set_hnpcapable(dwc_otg_core_if_t * core_if, uint32_t val)
  88165. +{
  88166. + gusbcfg_data_t usbcfg;
  88167. + usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  88168. + usbcfg.b.hnpcap = val;
  88169. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, usbcfg.d32);
  88170. +}
  88171. +
  88172. +uint32_t dwc_otg_get_srpcapable(dwc_otg_core_if_t * core_if)
  88173. +{
  88174. + gusbcfg_data_t usbcfg;
  88175. + usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  88176. + return usbcfg.b.srpcap;
  88177. +}
  88178. +
  88179. +void dwc_otg_set_srpcapable(dwc_otg_core_if_t * core_if, uint32_t val)
  88180. +{
  88181. + gusbcfg_data_t usbcfg;
  88182. + usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  88183. + usbcfg.b.srpcap = val;
  88184. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, usbcfg.d32);
  88185. +}
  88186. +
  88187. +uint32_t dwc_otg_get_devspeed(dwc_otg_core_if_t * core_if)
  88188. +{
  88189. + dcfg_data_t dcfg;
  88190. + /* originally: dcfg.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg); */
  88191. +
  88192. + dcfg.d32 = -1; //GRAYG
  88193. + DWC_DEBUGPL(DBG_CILV, "%s - core_if(%p)\n", __func__, core_if);
  88194. + if (NULL == core_if)
  88195. + DWC_ERROR("reg request with NULL core_if\n");
  88196. + DWC_DEBUGPL(DBG_CILV, "%s - core_if(%p)->dev_if(%p)\n", __func__,
  88197. + core_if, core_if->dev_if);
  88198. + if (NULL == core_if->dev_if)
  88199. + DWC_ERROR("reg request with NULL dev_if\n");
  88200. + DWC_DEBUGPL(DBG_CILV, "%s - core_if(%p)->dev_if(%p)->"
  88201. + "dev_global_regs(%p)\n", __func__,
  88202. + core_if, core_if->dev_if,
  88203. + core_if->dev_if->dev_global_regs);
  88204. + if (NULL == core_if->dev_if->dev_global_regs)
  88205. + DWC_ERROR("reg request with NULL dev_global_regs\n");
  88206. + else {
  88207. + DWC_DEBUGPL(DBG_CILV, "%s - &core_if(%p)->dev_if(%p)->"
  88208. + "dev_global_regs(%p)->dcfg = %p\n", __func__,
  88209. + core_if, core_if->dev_if,
  88210. + core_if->dev_if->dev_global_regs,
  88211. + &core_if->dev_if->dev_global_regs->dcfg);
  88212. + dcfg.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  88213. + }
  88214. + return dcfg.b.devspd;
  88215. +}
  88216. +
  88217. +void dwc_otg_set_devspeed(dwc_otg_core_if_t * core_if, uint32_t val)
  88218. +{
  88219. + dcfg_data_t dcfg;
  88220. + dcfg.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  88221. + dcfg.b.devspd = val;
  88222. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg, dcfg.d32);
  88223. +}
  88224. +
  88225. +uint32_t dwc_otg_get_busconnected(dwc_otg_core_if_t * core_if)
  88226. +{
  88227. + hprt0_data_t hprt0;
  88228. + hprt0.d32 = DWC_READ_REG32(core_if->host_if->hprt0);
  88229. + return hprt0.b.prtconnsts;
  88230. +}
  88231. +
  88232. +uint32_t dwc_otg_get_enumspeed(dwc_otg_core_if_t * core_if)
  88233. +{
  88234. + dsts_data_t dsts;
  88235. + dsts.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  88236. + return dsts.b.enumspd;
  88237. +}
  88238. +
  88239. +uint32_t dwc_otg_get_prtpower(dwc_otg_core_if_t * core_if)
  88240. +{
  88241. + hprt0_data_t hprt0;
  88242. + hprt0.d32 = DWC_READ_REG32(core_if->host_if->hprt0);
  88243. + return hprt0.b.prtpwr;
  88244. +
  88245. +}
  88246. +
  88247. +uint32_t dwc_otg_get_core_state(dwc_otg_core_if_t * core_if)
  88248. +{
  88249. + return core_if->hibernation_suspend;
  88250. +}
  88251. +
  88252. +void dwc_otg_set_prtpower(dwc_otg_core_if_t * core_if, uint32_t val)
  88253. +{
  88254. + hprt0_data_t hprt0;
  88255. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  88256. + hprt0.b.prtpwr = val;
  88257. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  88258. +}
  88259. +
  88260. +uint32_t dwc_otg_get_prtsuspend(dwc_otg_core_if_t * core_if)
  88261. +{
  88262. + hprt0_data_t hprt0;
  88263. + hprt0.d32 = DWC_READ_REG32(core_if->host_if->hprt0);
  88264. + return hprt0.b.prtsusp;
  88265. +
  88266. +}
  88267. +
  88268. +void dwc_otg_set_prtsuspend(dwc_otg_core_if_t * core_if, uint32_t val)
  88269. +{
  88270. + hprt0_data_t hprt0;
  88271. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  88272. + hprt0.b.prtsusp = val;
  88273. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  88274. +}
  88275. +
  88276. +uint32_t dwc_otg_get_fr_interval(dwc_otg_core_if_t * core_if)
  88277. +{
  88278. + hfir_data_t hfir;
  88279. + hfir.d32 = DWC_READ_REG32(&core_if->host_if->host_global_regs->hfir);
  88280. + return hfir.b.frint;
  88281. +
  88282. +}
  88283. +
  88284. +void dwc_otg_set_fr_interval(dwc_otg_core_if_t * core_if, uint32_t val)
  88285. +{
  88286. + hfir_data_t hfir;
  88287. + uint32_t fram_int;
  88288. + fram_int = calc_frame_interval(core_if);
  88289. + hfir.d32 = DWC_READ_REG32(&core_if->host_if->host_global_regs->hfir);
  88290. + if (!core_if->core_params->reload_ctl) {
  88291. + DWC_WARN("\nCannot reload HFIR register.HFIR.HFIRRldCtrl bit is"
  88292. + "not set to 1.\nShould load driver with reload_ctl=1"
  88293. + " module parameter\n");
  88294. + return;
  88295. + }
  88296. + switch (fram_int) {
  88297. + case 3750:
  88298. + if ((val < 3350) || (val > 4150)) {
  88299. + DWC_WARN("HFIR interval for HS core and 30 MHz"
  88300. + "clock freq should be from 3350 to 4150\n");
  88301. + return;
  88302. + }
  88303. + break;
  88304. + case 30000:
  88305. + if ((val < 26820) || (val > 33180)) {
  88306. + DWC_WARN("HFIR interval for FS/LS core and 30 MHz"
  88307. + "clock freq should be from 26820 to 33180\n");
  88308. + return;
  88309. + }
  88310. + break;
  88311. + case 6000:
  88312. + if ((val < 5360) || (val > 6640)) {
  88313. + DWC_WARN("HFIR interval for HS core and 48 MHz"
  88314. + "clock freq should be from 5360 to 6640\n");
  88315. + return;
  88316. + }
  88317. + break;
  88318. + case 48000:
  88319. + if ((val < 42912) || (val > 53088)) {
  88320. + DWC_WARN("HFIR interval for FS/LS core and 48 MHz"
  88321. + "clock freq should be from 42912 to 53088\n");
  88322. + return;
  88323. + }
  88324. + break;
  88325. + case 7500:
  88326. + if ((val < 6700) || (val > 8300)) {
  88327. + DWC_WARN("HFIR interval for HS core and 60 MHz"
  88328. + "clock freq should be from 6700 to 8300\n");
  88329. + return;
  88330. + }
  88331. + break;
  88332. + case 60000:
  88333. + if ((val < 53640) || (val > 65536)) {
  88334. + DWC_WARN("HFIR interval for FS/LS core and 60 MHz"
  88335. + "clock freq should be from 53640 to 65536\n");
  88336. + return;
  88337. + }
  88338. + break;
  88339. + default:
  88340. + DWC_WARN("Unknown frame interval\n");
  88341. + return;
  88342. + break;
  88343. +
  88344. + }
  88345. + hfir.b.frint = val;
  88346. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hfir, hfir.d32);
  88347. +}
  88348. +
  88349. +uint32_t dwc_otg_get_mode_ch_tim(dwc_otg_core_if_t * core_if)
  88350. +{
  88351. + hcfg_data_t hcfg;
  88352. + hcfg.d32 = DWC_READ_REG32(&core_if->host_if->host_global_regs->hcfg);
  88353. + return hcfg.b.modechtimen;
  88354. +
  88355. +}
  88356. +
  88357. +void dwc_otg_set_mode_ch_tim(dwc_otg_core_if_t * core_if, uint32_t val)
  88358. +{
  88359. + hcfg_data_t hcfg;
  88360. + hcfg.d32 = DWC_READ_REG32(&core_if->host_if->host_global_regs->hcfg);
  88361. + hcfg.b.modechtimen = val;
  88362. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hcfg, hcfg.d32);
  88363. +}
  88364. +
  88365. +void dwc_otg_set_prtresume(dwc_otg_core_if_t * core_if, uint32_t val)
  88366. +{
  88367. + hprt0_data_t hprt0;
  88368. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  88369. + hprt0.b.prtres = val;
  88370. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  88371. +}
  88372. +
  88373. +uint32_t dwc_otg_get_remotewakesig(dwc_otg_core_if_t * core_if)
  88374. +{
  88375. + dctl_data_t dctl;
  88376. + dctl.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dctl);
  88377. + return dctl.b.rmtwkupsig;
  88378. +}
  88379. +
  88380. +uint32_t dwc_otg_get_lpm_portsleepstatus(dwc_otg_core_if_t * core_if)
  88381. +{
  88382. + glpmcfg_data_t lpmcfg;
  88383. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  88384. +
  88385. + DWC_ASSERT(!
  88386. + ((core_if->lx_state == DWC_OTG_L1) ^ lpmcfg.b.prt_sleep_sts),
  88387. + "lx_state = %d, lmpcfg.prt_sleep_sts = %d\n",
  88388. + core_if->lx_state, lpmcfg.b.prt_sleep_sts);
  88389. +
  88390. + return lpmcfg.b.prt_sleep_sts;
  88391. +}
  88392. +
  88393. +uint32_t dwc_otg_get_lpm_remotewakeenabled(dwc_otg_core_if_t * core_if)
  88394. +{
  88395. + glpmcfg_data_t lpmcfg;
  88396. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  88397. + return lpmcfg.b.rem_wkup_en;
  88398. +}
  88399. +
  88400. +uint32_t dwc_otg_get_lpmresponse(dwc_otg_core_if_t * core_if)
  88401. +{
  88402. + glpmcfg_data_t lpmcfg;
  88403. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  88404. + return lpmcfg.b.appl_resp;
  88405. +}
  88406. +
  88407. +void dwc_otg_set_lpmresponse(dwc_otg_core_if_t * core_if, uint32_t val)
  88408. +{
  88409. + glpmcfg_data_t lpmcfg;
  88410. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  88411. + lpmcfg.b.appl_resp = val;
  88412. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg, lpmcfg.d32);
  88413. +}
  88414. +
  88415. +uint32_t dwc_otg_get_hsic_connect(dwc_otg_core_if_t * core_if)
  88416. +{
  88417. + glpmcfg_data_t lpmcfg;
  88418. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  88419. + return lpmcfg.b.hsic_connect;
  88420. +}
  88421. +
  88422. +void dwc_otg_set_hsic_connect(dwc_otg_core_if_t * core_if, uint32_t val)
  88423. +{
  88424. + glpmcfg_data_t lpmcfg;
  88425. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  88426. + lpmcfg.b.hsic_connect = val;
  88427. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg, lpmcfg.d32);
  88428. +}
  88429. +
  88430. +uint32_t dwc_otg_get_inv_sel_hsic(dwc_otg_core_if_t * core_if)
  88431. +{
  88432. + glpmcfg_data_t lpmcfg;
  88433. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  88434. + return lpmcfg.b.inv_sel_hsic;
  88435. +
  88436. +}
  88437. +
  88438. +void dwc_otg_set_inv_sel_hsic(dwc_otg_core_if_t * core_if, uint32_t val)
  88439. +{
  88440. + glpmcfg_data_t lpmcfg;
  88441. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  88442. + lpmcfg.b.inv_sel_hsic = val;
  88443. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg, lpmcfg.d32);
  88444. +}
  88445. +
  88446. +uint32_t dwc_otg_get_gotgctl(dwc_otg_core_if_t * core_if)
  88447. +{
  88448. + return DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  88449. +}
  88450. +
  88451. +void dwc_otg_set_gotgctl(dwc_otg_core_if_t * core_if, uint32_t val)
  88452. +{
  88453. + DWC_WRITE_REG32(&core_if->core_global_regs->gotgctl, val);
  88454. +}
  88455. +
  88456. +uint32_t dwc_otg_get_gusbcfg(dwc_otg_core_if_t * core_if)
  88457. +{
  88458. + return DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  88459. +}
  88460. +
  88461. +void dwc_otg_set_gusbcfg(dwc_otg_core_if_t * core_if, uint32_t val)
  88462. +{
  88463. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, val);
  88464. +}
  88465. +
  88466. +uint32_t dwc_otg_get_grxfsiz(dwc_otg_core_if_t * core_if)
  88467. +{
  88468. + return DWC_READ_REG32(&core_if->core_global_regs->grxfsiz);
  88469. +}
  88470. +
  88471. +void dwc_otg_set_grxfsiz(dwc_otg_core_if_t * core_if, uint32_t val)
  88472. +{
  88473. + DWC_WRITE_REG32(&core_if->core_global_regs->grxfsiz, val);
  88474. +}
  88475. +
  88476. +uint32_t dwc_otg_get_gnptxfsiz(dwc_otg_core_if_t * core_if)
  88477. +{
  88478. + return DWC_READ_REG32(&core_if->core_global_regs->gnptxfsiz);
  88479. +}
  88480. +
  88481. +void dwc_otg_set_gnptxfsiz(dwc_otg_core_if_t * core_if, uint32_t val)
  88482. +{
  88483. + DWC_WRITE_REG32(&core_if->core_global_regs->gnptxfsiz, val);
  88484. +}
  88485. +
  88486. +uint32_t dwc_otg_get_gpvndctl(dwc_otg_core_if_t * core_if)
  88487. +{
  88488. + return DWC_READ_REG32(&core_if->core_global_regs->gpvndctl);
  88489. +}
  88490. +
  88491. +void dwc_otg_set_gpvndctl(dwc_otg_core_if_t * core_if, uint32_t val)
  88492. +{
  88493. + DWC_WRITE_REG32(&core_if->core_global_regs->gpvndctl, val);
  88494. +}
  88495. +
  88496. +uint32_t dwc_otg_get_ggpio(dwc_otg_core_if_t * core_if)
  88497. +{
  88498. + return DWC_READ_REG32(&core_if->core_global_regs->ggpio);
  88499. +}
  88500. +
  88501. +void dwc_otg_set_ggpio(dwc_otg_core_if_t * core_if, uint32_t val)
  88502. +{
  88503. + DWC_WRITE_REG32(&core_if->core_global_regs->ggpio, val);
  88504. +}
  88505. +
  88506. +uint32_t dwc_otg_get_hprt0(dwc_otg_core_if_t * core_if)
  88507. +{
  88508. + return DWC_READ_REG32(core_if->host_if->hprt0);
  88509. +
  88510. +}
  88511. +
  88512. +void dwc_otg_set_hprt0(dwc_otg_core_if_t * core_if, uint32_t val)
  88513. +{
  88514. + DWC_WRITE_REG32(core_if->host_if->hprt0, val);
  88515. +}
  88516. +
  88517. +uint32_t dwc_otg_get_guid(dwc_otg_core_if_t * core_if)
  88518. +{
  88519. + return DWC_READ_REG32(&core_if->core_global_regs->guid);
  88520. +}
  88521. +
  88522. +void dwc_otg_set_guid(dwc_otg_core_if_t * core_if, uint32_t val)
  88523. +{
  88524. + DWC_WRITE_REG32(&core_if->core_global_regs->guid, val);
  88525. +}
  88526. +
  88527. +uint32_t dwc_otg_get_hptxfsiz(dwc_otg_core_if_t * core_if)
  88528. +{
  88529. + return DWC_READ_REG32(&core_if->core_global_regs->hptxfsiz);
  88530. +}
  88531. +
  88532. +uint16_t dwc_otg_get_otg_version(dwc_otg_core_if_t * core_if)
  88533. +{
  88534. + return ((core_if->otg_ver == 1) ? (uint16_t)0x0200 : (uint16_t)0x0103);
  88535. +}
  88536. +
  88537. +/**
  88538. + * Start the SRP timer to detect when the SRP does not complete within
  88539. + * 6 seconds.
  88540. + *
  88541. + * @param core_if the pointer to core_if strucure.
  88542. + */
  88543. +void dwc_otg_pcd_start_srp_timer(dwc_otg_core_if_t * core_if)
  88544. +{
  88545. + core_if->srp_timer_started = 1;
  88546. + DWC_TIMER_SCHEDULE(core_if->srp_timer, 6000 /* 6 secs */ );
  88547. +}
  88548. +
  88549. +void dwc_otg_initiate_srp(dwc_otg_core_if_t * core_if)
  88550. +{
  88551. + uint32_t *addr = (uint32_t *) & (core_if->core_global_regs->gotgctl);
  88552. + gotgctl_data_t mem;
  88553. + gotgctl_data_t val;
  88554. +
  88555. + val.d32 = DWC_READ_REG32(addr);
  88556. + if (val.b.sesreq) {
  88557. + DWC_ERROR("Session Request Already active!\n");
  88558. + return;
  88559. + }
  88560. +
  88561. + DWC_INFO("Session Request Initated\n"); //NOTICE
  88562. + mem.d32 = DWC_READ_REG32(addr);
  88563. + mem.b.sesreq = 1;
  88564. + DWC_WRITE_REG32(addr, mem.d32);
  88565. +
  88566. + /* Start the SRP timer */
  88567. + dwc_otg_pcd_start_srp_timer(core_if);
  88568. + return;
  88569. +}
  88570. diff -Nur linux-3.18.8/drivers/usb/host/dwc_otg/dwc_otg_cil.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_cil.h
  88571. --- linux-3.18.8/drivers/usb/host/dwc_otg/dwc_otg_cil.h 1970-01-01 01:00:00.000000000 +0100
  88572. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_cil.h 2015-03-05 14:40:16.557715806 +0100
  88573. @@ -0,0 +1,1464 @@
  88574. +/* ==========================================================================
  88575. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_cil.h $
  88576. + * $Revision: #123 $
  88577. + * $Date: 2012/08/10 $
  88578. + * $Change: 2047372 $
  88579. + *
  88580. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  88581. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  88582. + * otherwise expressly agreed to in writing between Synopsys and you.
  88583. + *
  88584. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  88585. + * any End User Software License Agreement or Agreement for Licensed Product
  88586. + * with Synopsys or any supplement thereto. You are permitted to use and
  88587. + * redistribute this Software in source and binary forms, with or without
  88588. + * modification, provided that redistributions of source code must retain this
  88589. + * notice. You may not view, use, disclose, copy or distribute this file or
  88590. + * any information contained herein except pursuant to this license grant from
  88591. + * Synopsys. If you do not agree with this notice, including the disclaimer
  88592. + * below, then you are not authorized to use the Software.
  88593. + *
  88594. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  88595. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  88596. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  88597. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  88598. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  88599. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  88600. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  88601. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  88602. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  88603. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  88604. + * DAMAGE.
  88605. + * ========================================================================== */
  88606. +
  88607. +#if !defined(__DWC_CIL_H__)
  88608. +#define __DWC_CIL_H__
  88609. +
  88610. +#include "dwc_list.h"
  88611. +#include "dwc_otg_dbg.h"
  88612. +#include "dwc_otg_regs.h"
  88613. +
  88614. +#include "dwc_otg_core_if.h"
  88615. +#include "dwc_otg_adp.h"
  88616. +
  88617. +/**
  88618. + * @file
  88619. + * This file contains the interface to the Core Interface Layer.
  88620. + */
  88621. +
  88622. +#ifdef DWC_UTE_CFI
  88623. +
  88624. +#define MAX_DMA_DESCS_PER_EP 256
  88625. +
  88626. +/**
  88627. + * Enumeration for the data buffer mode
  88628. + */
  88629. +typedef enum _data_buffer_mode {
  88630. + BM_STANDARD = 0, /* data buffer is in normal mode */
  88631. + BM_SG = 1, /* data buffer uses the scatter/gather mode */
  88632. + BM_CONCAT = 2, /* data buffer uses the concatenation mode */
  88633. + BM_CIRCULAR = 3, /* data buffer uses the circular DMA mode */
  88634. + BM_ALIGN = 4 /* data buffer is in buffer alignment mode */
  88635. +} data_buffer_mode_e;
  88636. +#endif //DWC_UTE_CFI
  88637. +
  88638. +/** Macros defined for DWC OTG HW Release version */
  88639. +
  88640. +#define OTG_CORE_REV_2_60a 0x4F54260A
  88641. +#define OTG_CORE_REV_2_71a 0x4F54271A
  88642. +#define OTG_CORE_REV_2_72a 0x4F54272A
  88643. +#define OTG_CORE_REV_2_80a 0x4F54280A
  88644. +#define OTG_CORE_REV_2_81a 0x4F54281A
  88645. +#define OTG_CORE_REV_2_90a 0x4F54290A
  88646. +#define OTG_CORE_REV_2_91a 0x4F54291A
  88647. +#define OTG_CORE_REV_2_92a 0x4F54292A
  88648. +#define OTG_CORE_REV_2_93a 0x4F54293A
  88649. +#define OTG_CORE_REV_2_94a 0x4F54294A
  88650. +#define OTG_CORE_REV_3_00a 0x4F54300A
  88651. +
  88652. +/**
  88653. + * Information for each ISOC packet.
  88654. + */
  88655. +typedef struct iso_pkt_info {
  88656. + uint32_t offset;
  88657. + uint32_t length;
  88658. + int32_t status;
  88659. +} iso_pkt_info_t;
  88660. +
  88661. +/**
  88662. + * The <code>dwc_ep</code> structure represents the state of a single
  88663. + * endpoint when acting in device mode. It contains the data items
  88664. + * needed for an endpoint to be activated and transfer packets.
  88665. + */
  88666. +typedef struct dwc_ep {
  88667. + /** EP number used for register address lookup */
  88668. + uint8_t num;
  88669. + /** EP direction 0 = OUT */
  88670. + unsigned is_in:1;
  88671. + /** EP active. */
  88672. + unsigned active:1;
  88673. +
  88674. + /**
  88675. + * Periodic Tx FIFO # for IN EPs For INTR EP set to 0 to use non-periodic
  88676. + * Tx FIFO. If dedicated Tx FIFOs are enabled Tx FIFO # FOR IN EPs*/
  88677. + unsigned tx_fifo_num:4;
  88678. + /** EP type: 0 - Control, 1 - ISOC, 2 - BULK, 3 - INTR */
  88679. + unsigned type:2;
  88680. +#define DWC_OTG_EP_TYPE_CONTROL 0
  88681. +#define DWC_OTG_EP_TYPE_ISOC 1
  88682. +#define DWC_OTG_EP_TYPE_BULK 2
  88683. +#define DWC_OTG_EP_TYPE_INTR 3
  88684. +
  88685. + /** DATA start PID for INTR and BULK EP */
  88686. + unsigned data_pid_start:1;
  88687. + /** Frame (even/odd) for ISOC EP */
  88688. + unsigned even_odd_frame:1;
  88689. + /** Max Packet bytes */
  88690. + unsigned maxpacket:11;
  88691. +
  88692. + /** Max Transfer size */
  88693. + uint32_t maxxfer;
  88694. +
  88695. + /** @name Transfer state */
  88696. + /** @{ */
  88697. +
  88698. + /**
  88699. + * Pointer to the beginning of the transfer buffer -- do not modify
  88700. + * during transfer.
  88701. + */
  88702. +
  88703. + dwc_dma_t dma_addr;
  88704. +
  88705. + dwc_dma_t dma_desc_addr;
  88706. + dwc_otg_dev_dma_desc_t *desc_addr;
  88707. +
  88708. + uint8_t *start_xfer_buff;
  88709. + /** pointer to the transfer buffer */
  88710. + uint8_t *xfer_buff;
  88711. + /** Number of bytes to transfer */
  88712. + unsigned xfer_len:19;
  88713. + /** Number of bytes transferred. */
  88714. + unsigned xfer_count:19;
  88715. + /** Sent ZLP */
  88716. + unsigned sent_zlp:1;
  88717. + /** Total len for control transfer */
  88718. + unsigned total_len:19;
  88719. +
  88720. + /** stall clear flag */
  88721. + unsigned stall_clear_flag:1;
  88722. +
  88723. + /** SETUP pkt cnt rollover flag for EP0 out*/
  88724. + unsigned stp_rollover;
  88725. +
  88726. +#ifdef DWC_UTE_CFI
  88727. + /* The buffer mode */
  88728. + data_buffer_mode_e buff_mode;
  88729. +
  88730. + /* The chain of DMA descriptors.
  88731. + * MAX_DMA_DESCS_PER_EP will be allocated for each active EP.
  88732. + */
  88733. + dwc_otg_dma_desc_t *descs;
  88734. +
  88735. + /* The DMA address of the descriptors chain start */
  88736. + dma_addr_t descs_dma_addr;
  88737. + /** This variable stores the length of the last enqueued request */
  88738. + uint32_t cfi_req_len;
  88739. +#endif //DWC_UTE_CFI
  88740. +
  88741. +/** Max DMA Descriptor count for any EP */
  88742. +#define MAX_DMA_DESC_CNT 256
  88743. + /** Allocated DMA Desc count */
  88744. + uint32_t desc_cnt;
  88745. +
  88746. + /** bInterval */
  88747. + uint32_t bInterval;
  88748. + /** Next frame num to setup next ISOC transfer */
  88749. + uint32_t frame_num;
  88750. + /** Indicates SOF number overrun in DSTS */
  88751. + uint8_t frm_overrun;
  88752. +
  88753. +#ifdef DWC_UTE_PER_IO
  88754. + /** Next frame num for which will be setup DMA Desc */
  88755. + uint32_t xiso_frame_num;
  88756. + /** bInterval */
  88757. + uint32_t xiso_bInterval;
  88758. + /** Count of currently active transfers - shall be either 0 or 1 */
  88759. + int xiso_active_xfers;
  88760. + int xiso_queued_xfers;
  88761. +#endif
  88762. +#ifdef DWC_EN_ISOC
  88763. + /**
  88764. + * Variables specific for ISOC EPs
  88765. + *
  88766. + */
  88767. + /** DMA addresses of ISOC buffers */
  88768. + dwc_dma_t dma_addr0;
  88769. + dwc_dma_t dma_addr1;
  88770. +
  88771. + dwc_dma_t iso_dma_desc_addr;
  88772. + dwc_otg_dev_dma_desc_t *iso_desc_addr;
  88773. +
  88774. + /** pointer to the transfer buffers */
  88775. + uint8_t *xfer_buff0;
  88776. + uint8_t *xfer_buff1;
  88777. +
  88778. + /** number of ISOC Buffer is processing */
  88779. + uint32_t proc_buf_num;
  88780. + /** Interval of ISOC Buffer processing */
  88781. + uint32_t buf_proc_intrvl;
  88782. + /** Data size for regular frame */
  88783. + uint32_t data_per_frame;
  88784. +
  88785. + /* todo - pattern data support is to be implemented in the future */
  88786. + /** Data size for pattern frame */
  88787. + uint32_t data_pattern_frame;
  88788. + /** Frame number of pattern data */
  88789. + uint32_t sync_frame;
  88790. +
  88791. + /** bInterval */
  88792. + uint32_t bInterval;
  88793. + /** ISO Packet number per frame */
  88794. + uint32_t pkt_per_frm;
  88795. + /** Next frame num for which will be setup DMA Desc */
  88796. + uint32_t next_frame;
  88797. + /** Number of packets per buffer processing */
  88798. + uint32_t pkt_cnt;
  88799. + /** Info for all isoc packets */
  88800. + iso_pkt_info_t *pkt_info;
  88801. + /** current pkt number */
  88802. + uint32_t cur_pkt;
  88803. + /** current pkt number */
  88804. + uint8_t *cur_pkt_addr;
  88805. + /** current pkt number */
  88806. + uint32_t cur_pkt_dma_addr;
  88807. +#endif /* DWC_EN_ISOC */
  88808. +
  88809. +/** @} */
  88810. +} dwc_ep_t;
  88811. +
  88812. +/*
  88813. + * Reasons for halting a host channel.
  88814. + */
  88815. +typedef enum dwc_otg_halt_status {
  88816. + DWC_OTG_HC_XFER_NO_HALT_STATUS,
  88817. + DWC_OTG_HC_XFER_COMPLETE,
  88818. + DWC_OTG_HC_XFER_URB_COMPLETE,
  88819. + DWC_OTG_HC_XFER_ACK,
  88820. + DWC_OTG_HC_XFER_NAK,
  88821. + DWC_OTG_HC_XFER_NYET,
  88822. + DWC_OTG_HC_XFER_STALL,
  88823. + DWC_OTG_HC_XFER_XACT_ERR,
  88824. + DWC_OTG_HC_XFER_FRAME_OVERRUN,
  88825. + DWC_OTG_HC_XFER_BABBLE_ERR,
  88826. + DWC_OTG_HC_XFER_DATA_TOGGLE_ERR,
  88827. + DWC_OTG_HC_XFER_AHB_ERR,
  88828. + DWC_OTG_HC_XFER_PERIODIC_INCOMPLETE,
  88829. + DWC_OTG_HC_XFER_URB_DEQUEUE
  88830. +} dwc_otg_halt_status_e;
  88831. +
  88832. +/**
  88833. + * Host channel descriptor. This structure represents the state of a single
  88834. + * host channel when acting in host mode. It contains the data items needed to
  88835. + * transfer packets to an endpoint via a host channel.
  88836. + */
  88837. +typedef struct dwc_hc {
  88838. + /** Host channel number used for register address lookup */
  88839. + uint8_t hc_num;
  88840. +
  88841. + /** Device to access */
  88842. + unsigned dev_addr:7;
  88843. +
  88844. + /** EP to access */
  88845. + unsigned ep_num:4;
  88846. +
  88847. + /** EP direction. 0: OUT, 1: IN */
  88848. + unsigned ep_is_in:1;
  88849. +
  88850. + /**
  88851. + * EP speed.
  88852. + * One of the following values:
  88853. + * - DWC_OTG_EP_SPEED_LOW
  88854. + * - DWC_OTG_EP_SPEED_FULL
  88855. + * - DWC_OTG_EP_SPEED_HIGH
  88856. + */
  88857. + unsigned speed:2;
  88858. +#define DWC_OTG_EP_SPEED_LOW 0
  88859. +#define DWC_OTG_EP_SPEED_FULL 1
  88860. +#define DWC_OTG_EP_SPEED_HIGH 2
  88861. +
  88862. + /**
  88863. + * Endpoint type.
  88864. + * One of the following values:
  88865. + * - DWC_OTG_EP_TYPE_CONTROL: 0
  88866. + * - DWC_OTG_EP_TYPE_ISOC: 1
  88867. + * - DWC_OTG_EP_TYPE_BULK: 2
  88868. + * - DWC_OTG_EP_TYPE_INTR: 3
  88869. + */
  88870. + unsigned ep_type:2;
  88871. +
  88872. + /** Max packet size in bytes */
  88873. + unsigned max_packet:11;
  88874. +
  88875. + /**
  88876. + * PID for initial transaction.
  88877. + * 0: DATA0,<br>
  88878. + * 1: DATA2,<br>
  88879. + * 2: DATA1,<br>
  88880. + * 3: MDATA (non-Control EP),
  88881. + * SETUP (Control EP)
  88882. + */
  88883. + unsigned data_pid_start:2;
  88884. +#define DWC_OTG_HC_PID_DATA0 0
  88885. +#define DWC_OTG_HC_PID_DATA2 1
  88886. +#define DWC_OTG_HC_PID_DATA1 2
  88887. +#define DWC_OTG_HC_PID_MDATA 3
  88888. +#define DWC_OTG_HC_PID_SETUP 3
  88889. +
  88890. + /** Number of periodic transactions per (micro)frame */
  88891. + unsigned multi_count:2;
  88892. +
  88893. + /** @name Transfer State */
  88894. + /** @{ */
  88895. +
  88896. + /** Pointer to the current transfer buffer position. */
  88897. + uint8_t *xfer_buff;
  88898. + /**
  88899. + * In Buffer DMA mode this buffer will be used
  88900. + * if xfer_buff is not DWORD aligned.
  88901. + */
  88902. + dwc_dma_t align_buff;
  88903. + /** Total number of bytes to transfer. */
  88904. + uint32_t xfer_len;
  88905. + /** Number of bytes transferred so far. */
  88906. + uint32_t xfer_count;
  88907. + /** Packet count at start of transfer.*/
  88908. + uint16_t start_pkt_count;
  88909. +
  88910. + /**
  88911. + * Flag to indicate whether the transfer has been started. Set to 1 if
  88912. + * it has been started, 0 otherwise.
  88913. + */
  88914. + uint8_t xfer_started;
  88915. +
  88916. + /**
  88917. + * Set to 1 to indicate that a PING request should be issued on this
  88918. + * channel. If 0, process normally.
  88919. + */
  88920. + uint8_t do_ping;
  88921. +
  88922. + /**
  88923. + * Set to 1 to indicate that the error count for this transaction is
  88924. + * non-zero. Set to 0 if the error count is 0.
  88925. + */
  88926. + uint8_t error_state;
  88927. +
  88928. + /**
  88929. + * Set to 1 to indicate that this channel should be halted the next
  88930. + * time a request is queued for the channel. This is necessary in
  88931. + * slave mode if no request queue space is available when an attempt
  88932. + * is made to halt the channel.
  88933. + */
  88934. + uint8_t halt_on_queue;
  88935. +
  88936. + /**
  88937. + * Set to 1 if the host channel has been halted, but the core is not
  88938. + * finished flushing queued requests. Otherwise 0.
  88939. + */
  88940. + uint8_t halt_pending;
  88941. +
  88942. + /**
  88943. + * Reason for halting the host channel.
  88944. + */
  88945. + dwc_otg_halt_status_e halt_status;
  88946. +
  88947. + /*
  88948. + * Split settings for the host channel
  88949. + */
  88950. + uint8_t do_split; /**< Enable split for the channel */
  88951. + uint8_t complete_split; /**< Enable complete split */
  88952. + uint8_t hub_addr; /**< Address of high speed hub */
  88953. +
  88954. + uint8_t port_addr; /**< Port of the low/full speed device */
  88955. + /** Split transaction position
  88956. + * One of the following values:
  88957. + * - DWC_HCSPLIT_XACTPOS_MID
  88958. + * - DWC_HCSPLIT_XACTPOS_BEGIN
  88959. + * - DWC_HCSPLIT_XACTPOS_END
  88960. + * - DWC_HCSPLIT_XACTPOS_ALL */
  88961. + uint8_t xact_pos;
  88962. +
  88963. + /** Set when the host channel does a short read. */
  88964. + uint8_t short_read;
  88965. +
  88966. + /**
  88967. + * Number of requests issued for this channel since it was assigned to
  88968. + * the current transfer (not counting PINGs).
  88969. + */
  88970. + uint8_t requests;
  88971. +
  88972. + /**
  88973. + * Queue Head for the transfer being processed by this channel.
  88974. + */
  88975. + struct dwc_otg_qh *qh;
  88976. +
  88977. + /** @} */
  88978. +
  88979. + /** Entry in list of host channels. */
  88980. + DWC_CIRCLEQ_ENTRY(dwc_hc) hc_list_entry;
  88981. +
  88982. + /** @name Descriptor DMA support */
  88983. + /** @{ */
  88984. +
  88985. + /** Number of Transfer Descriptors */
  88986. + uint16_t ntd;
  88987. +
  88988. + /** Descriptor List DMA address */
  88989. + dwc_dma_t desc_list_addr;
  88990. +
  88991. + /** Scheduling micro-frame bitmap. */
  88992. + uint8_t schinfo;
  88993. +
  88994. + /** @} */
  88995. +} dwc_hc_t;
  88996. +
  88997. +/**
  88998. + * The following parameters may be specified when starting the module. These
  88999. + * parameters define how the DWC_otg controller should be configured.
  89000. + */
  89001. +typedef struct dwc_otg_core_params {
  89002. + int32_t opt;
  89003. +
  89004. + /**
  89005. + * Specifies the OTG capabilities. The driver will automatically
  89006. + * detect the value for this parameter if none is specified.
  89007. + * 0 - HNP and SRP capable (default)
  89008. + * 1 - SRP Only capable
  89009. + * 2 - No HNP/SRP capable
  89010. + */
  89011. + int32_t otg_cap;
  89012. +
  89013. + /**
  89014. + * Specifies whether to use slave or DMA mode for accessing the data
  89015. + * FIFOs. The driver will automatically detect the value for this
  89016. + * parameter if none is specified.
  89017. + * 0 - Slave
  89018. + * 1 - DMA (default, if available)
  89019. + */
  89020. + int32_t dma_enable;
  89021. +
  89022. + /**
  89023. + * When DMA mode is enabled specifies whether to use address DMA or DMA
  89024. + * Descriptor mode for accessing the data FIFOs in device mode. The driver
  89025. + * will automatically detect the value for this if none is specified.
  89026. + * 0 - address DMA
  89027. + * 1 - DMA Descriptor(default, if available)
  89028. + */
  89029. + int32_t dma_desc_enable;
  89030. + /** The DMA Burst size (applicable only for External DMA
  89031. + * Mode). 1, 4, 8 16, 32, 64, 128, 256 (default 32)
  89032. + */
  89033. + int32_t dma_burst_size; /* Translate this to GAHBCFG values */
  89034. +
  89035. + /**
  89036. + * Specifies the maximum speed of operation in host and device mode.
  89037. + * The actual speed depends on the speed of the attached device and
  89038. + * the value of phy_type. The actual speed depends on the speed of the
  89039. + * attached device.
  89040. + * 0 - High Speed (default)
  89041. + * 1 - Full Speed
  89042. + */
  89043. + int32_t speed;
  89044. + /** Specifies whether low power mode is supported when attached
  89045. + * to a Full Speed or Low Speed device in host mode.
  89046. + * 0 - Don't support low power mode (default)
  89047. + * 1 - Support low power mode
  89048. + */
  89049. + int32_t host_support_fs_ls_low_power;
  89050. +
  89051. + /** Specifies the PHY clock rate in low power mode when connected to a
  89052. + * Low Speed device in host mode. This parameter is applicable only if
  89053. + * HOST_SUPPORT_FS_LS_LOW_POWER is enabled. If PHY_TYPE is set to FS
  89054. + * then defaults to 6 MHZ otherwise 48 MHZ.
  89055. + *
  89056. + * 0 - 48 MHz
  89057. + * 1 - 6 MHz
  89058. + */
  89059. + int32_t host_ls_low_power_phy_clk;
  89060. +
  89061. + /**
  89062. + * 0 - Use cC FIFO size parameters
  89063. + * 1 - Allow dynamic FIFO sizing (default)
  89064. + */
  89065. + int32_t enable_dynamic_fifo;
  89066. +
  89067. + /** Total number of 4-byte words in the data FIFO memory. This
  89068. + * memory includes the Rx FIFO, non-periodic Tx FIFO, and periodic
  89069. + * Tx FIFOs.
  89070. + * 32 to 32768 (default 8192)
  89071. + * Note: The total FIFO memory depth in the FPGA configuration is 8192.
  89072. + */
  89073. + int32_t data_fifo_size;
  89074. +
  89075. + /** Number of 4-byte words in the Rx FIFO in device mode when dynamic
  89076. + * FIFO sizing is enabled.
  89077. + * 16 to 32768 (default 1064)
  89078. + */
  89079. + int32_t dev_rx_fifo_size;
  89080. +
  89081. + /** Number of 4-byte words in the non-periodic Tx FIFO in device mode
  89082. + * when dynamic FIFO sizing is enabled.
  89083. + * 16 to 32768 (default 1024)
  89084. + */
  89085. + int32_t dev_nperio_tx_fifo_size;
  89086. +
  89087. + /** Number of 4-byte words in each of the periodic Tx FIFOs in device
  89088. + * mode when dynamic FIFO sizing is enabled.
  89089. + * 4 to 768 (default 256)
  89090. + */
  89091. + uint32_t dev_perio_tx_fifo_size[MAX_PERIO_FIFOS];
  89092. +
  89093. + /** Number of 4-byte words in the Rx FIFO in host mode when dynamic
  89094. + * FIFO sizing is enabled.
  89095. + * 16 to 32768 (default 1024)
  89096. + */
  89097. + int32_t host_rx_fifo_size;
  89098. +
  89099. + /** Number of 4-byte words in the non-periodic Tx FIFO in host mode
  89100. + * when Dynamic FIFO sizing is enabled in the core.
  89101. + * 16 to 32768 (default 1024)
  89102. + */
  89103. + int32_t host_nperio_tx_fifo_size;
  89104. +
  89105. + /** Number of 4-byte words in the host periodic Tx FIFO when dynamic
  89106. + * FIFO sizing is enabled.
  89107. + * 16 to 32768 (default 1024)
  89108. + */
  89109. + int32_t host_perio_tx_fifo_size;
  89110. +
  89111. + /** The maximum transfer size supported in bytes.
  89112. + * 2047 to 65,535 (default 65,535)
  89113. + */
  89114. + int32_t max_transfer_size;
  89115. +
  89116. + /** The maximum number of packets in a transfer.
  89117. + * 15 to 511 (default 511)
  89118. + */
  89119. + int32_t max_packet_count;
  89120. +
  89121. + /** The number of host channel registers to use.
  89122. + * 1 to 16 (default 12)
  89123. + * Note: The FPGA configuration supports a maximum of 12 host channels.
  89124. + */
  89125. + int32_t host_channels;
  89126. +
  89127. + /** The number of endpoints in addition to EP0 available for device
  89128. + * mode operations.
  89129. + * 1 to 15 (default 6 IN and OUT)
  89130. + * Note: The FPGA configuration supports a maximum of 6 IN and OUT
  89131. + * endpoints in addition to EP0.
  89132. + */
  89133. + int32_t dev_endpoints;
  89134. +
  89135. + /**
  89136. + * Specifies the type of PHY interface to use. By default, the driver
  89137. + * will automatically detect the phy_type.
  89138. + *
  89139. + * 0 - Full Speed PHY
  89140. + * 1 - UTMI+ (default)
  89141. + * 2 - ULPI
  89142. + */
  89143. + int32_t phy_type;
  89144. +
  89145. + /**
  89146. + * Specifies the UTMI+ Data Width. This parameter is
  89147. + * applicable for a PHY_TYPE of UTMI+ or ULPI. (For a ULPI
  89148. + * PHY_TYPE, this parameter indicates the data width between
  89149. + * the MAC and the ULPI Wrapper.) Also, this parameter is
  89150. + * applicable only if the OTG_HSPHY_WIDTH cC parameter was set
  89151. + * to "8 and 16 bits", meaning that the core has been
  89152. + * configured to work at either data path width.
  89153. + *
  89154. + * 8 or 16 bits (default 16)
  89155. + */
  89156. + int32_t phy_utmi_width;
  89157. +
  89158. + /**
  89159. + * Specifies whether the ULPI operates at double or single
  89160. + * data rate. This parameter is only applicable if PHY_TYPE is
  89161. + * ULPI.
  89162. + *
  89163. + * 0 - single data rate ULPI interface with 8 bit wide data
  89164. + * bus (default)
  89165. + * 1 - double data rate ULPI interface with 4 bit wide data
  89166. + * bus
  89167. + */
  89168. + int32_t phy_ulpi_ddr;
  89169. +
  89170. + /**
  89171. + * Specifies whether to use the internal or external supply to
  89172. + * drive the vbus with a ULPI phy.
  89173. + */
  89174. + int32_t phy_ulpi_ext_vbus;
  89175. +
  89176. + /**
  89177. + * Specifies whether to use the I2Cinterface for full speed PHY. This
  89178. + * parameter is only applicable if PHY_TYPE is FS.
  89179. + * 0 - No (default)
  89180. + * 1 - Yes
  89181. + */
  89182. + int32_t i2c_enable;
  89183. +
  89184. + int32_t ulpi_fs_ls;
  89185. +
  89186. + int32_t ts_dline;
  89187. +
  89188. + /**
  89189. + * Specifies whether dedicated transmit FIFOs are
  89190. + * enabled for non periodic IN endpoints in device mode
  89191. + * 0 - No
  89192. + * 1 - Yes
  89193. + */
  89194. + int32_t en_multiple_tx_fifo;
  89195. +
  89196. + /** Number of 4-byte words in each of the Tx FIFOs in device
  89197. + * mode when dynamic FIFO sizing is enabled.
  89198. + * 4 to 768 (default 256)
  89199. + */
  89200. + uint32_t dev_tx_fifo_size[MAX_TX_FIFOS];
  89201. +
  89202. + /** Thresholding enable flag-
  89203. + * bit 0 - enable non-ISO Tx thresholding
  89204. + * bit 1 - enable ISO Tx thresholding
  89205. + * bit 2 - enable Rx thresholding
  89206. + */
  89207. + uint32_t thr_ctl;
  89208. +
  89209. + /** Thresholding length for Tx
  89210. + * FIFOs in 32 bit DWORDs
  89211. + */
  89212. + uint32_t tx_thr_length;
  89213. +
  89214. + /** Thresholding length for Rx
  89215. + * FIFOs in 32 bit DWORDs
  89216. + */
  89217. + uint32_t rx_thr_length;
  89218. +
  89219. + /**
  89220. + * Specifies whether LPM (Link Power Management) support is enabled
  89221. + */
  89222. + int32_t lpm_enable;
  89223. +
  89224. + /** Per Transfer Interrupt
  89225. + * mode enable flag
  89226. + * 1 - Enabled
  89227. + * 0 - Disabled
  89228. + */
  89229. + int32_t pti_enable;
  89230. +
  89231. + /** Multi Processor Interrupt
  89232. + * mode enable flag
  89233. + * 1 - Enabled
  89234. + * 0 - Disabled
  89235. + */
  89236. + int32_t mpi_enable;
  89237. +
  89238. + /** IS_USB Capability
  89239. + * 1 - Enabled
  89240. + * 0 - Disabled
  89241. + */
  89242. + int32_t ic_usb_cap;
  89243. +
  89244. + /** AHB Threshold Ratio
  89245. + * 2'b00 AHB Threshold = MAC Threshold
  89246. + * 2'b01 AHB Threshold = 1/2 MAC Threshold
  89247. + * 2'b10 AHB Threshold = 1/4 MAC Threshold
  89248. + * 2'b11 AHB Threshold = 1/8 MAC Threshold
  89249. + */
  89250. + int32_t ahb_thr_ratio;
  89251. +
  89252. + /** ADP Support
  89253. + * 1 - Enabled
  89254. + * 0 - Disabled
  89255. + */
  89256. + int32_t adp_supp_enable;
  89257. +
  89258. + /** HFIR Reload Control
  89259. + * 0 - The HFIR cannot be reloaded dynamically.
  89260. + * 1 - Allow dynamic reloading of the HFIR register during runtime.
  89261. + */
  89262. + int32_t reload_ctl;
  89263. +
  89264. + /** DCFG: Enable device Out NAK
  89265. + * 0 - The core does not set NAK after Bulk Out transfer complete.
  89266. + * 1 - The core sets NAK after Bulk OUT transfer complete.
  89267. + */
  89268. + int32_t dev_out_nak;
  89269. +
  89270. + /** DCFG: Enable Continue on BNA
  89271. + * After receiving BNA interrupt the core disables the endpoint,when the
  89272. + * endpoint is re-enabled by the application the core starts processing
  89273. + * 0 - from the DOEPDMA descriptor
  89274. + * 1 - from the descriptor which received the BNA.
  89275. + */
  89276. + int32_t cont_on_bna;
  89277. +
  89278. + /** GAHBCFG: AHB Single Support
  89279. + * This bit when programmed supports SINGLE transfers for remainder
  89280. + * data in a transfer for DMA mode of operation.
  89281. + * 0 - in this case the remainder data will be sent using INCR burst size.
  89282. + * 1 - in this case the remainder data will be sent using SINGLE burst size.
  89283. + */
  89284. + int32_t ahb_single;
  89285. +
  89286. + /** Core Power down mode
  89287. + * 0 - No Power Down is enabled
  89288. + * 1 - Reserved
  89289. + * 2 - Complete Power Down (Hibernation)
  89290. + */
  89291. + int32_t power_down;
  89292. +
  89293. + /** OTG revision supported
  89294. + * 0 - OTG 1.3 revision
  89295. + * 1 - OTG 2.0 revision
  89296. + */
  89297. + int32_t otg_ver;
  89298. +
  89299. +} dwc_otg_core_params_t;
  89300. +
  89301. +#ifdef DEBUG
  89302. +struct dwc_otg_core_if;
  89303. +typedef struct hc_xfer_info {
  89304. + struct dwc_otg_core_if *core_if;
  89305. + dwc_hc_t *hc;
  89306. +} hc_xfer_info_t;
  89307. +#endif
  89308. +
  89309. +typedef struct ep_xfer_info {
  89310. + struct dwc_otg_core_if *core_if;
  89311. + dwc_ep_t *ep;
  89312. + uint8_t state;
  89313. +} ep_xfer_info_t;
  89314. +/*
  89315. + * Device States
  89316. + */
  89317. +typedef enum dwc_otg_lx_state {
  89318. + /** On state */
  89319. + DWC_OTG_L0,
  89320. + /** LPM sleep state*/
  89321. + DWC_OTG_L1,
  89322. + /** USB suspend state*/
  89323. + DWC_OTG_L2,
  89324. + /** Off state*/
  89325. + DWC_OTG_L3
  89326. +} dwc_otg_lx_state_e;
  89327. +
  89328. +struct dwc_otg_global_regs_backup {
  89329. + uint32_t gotgctl_local;
  89330. + uint32_t gintmsk_local;
  89331. + uint32_t gahbcfg_local;
  89332. + uint32_t gusbcfg_local;
  89333. + uint32_t grxfsiz_local;
  89334. + uint32_t gnptxfsiz_local;
  89335. +#ifdef CONFIG_USB_DWC_OTG_LPM
  89336. + uint32_t glpmcfg_local;
  89337. +#endif
  89338. + uint32_t gi2cctl_local;
  89339. + uint32_t hptxfsiz_local;
  89340. + uint32_t pcgcctl_local;
  89341. + uint32_t gdfifocfg_local;
  89342. + uint32_t dtxfsiz_local[MAX_EPS_CHANNELS];
  89343. + uint32_t gpwrdn_local;
  89344. + uint32_t xhib_pcgcctl;
  89345. + uint32_t xhib_gpwrdn;
  89346. +};
  89347. +
  89348. +struct dwc_otg_host_regs_backup {
  89349. + uint32_t hcfg_local;
  89350. + uint32_t haintmsk_local;
  89351. + uint32_t hcintmsk_local[MAX_EPS_CHANNELS];
  89352. + uint32_t hprt0_local;
  89353. + uint32_t hfir_local;
  89354. +};
  89355. +
  89356. +struct dwc_otg_dev_regs_backup {
  89357. + uint32_t dcfg;
  89358. + uint32_t dctl;
  89359. + uint32_t daintmsk;
  89360. + uint32_t diepmsk;
  89361. + uint32_t doepmsk;
  89362. + uint32_t diepctl[MAX_EPS_CHANNELS];
  89363. + uint32_t dieptsiz[MAX_EPS_CHANNELS];
  89364. + uint32_t diepdma[MAX_EPS_CHANNELS];
  89365. +};
  89366. +/**
  89367. + * The <code>dwc_otg_core_if</code> structure contains information needed to manage
  89368. + * the DWC_otg controller acting in either host or device mode. It
  89369. + * represents the programming view of the controller as a whole.
  89370. + */
  89371. +struct dwc_otg_core_if {
  89372. + /** Parameters that define how the core should be configured.*/
  89373. + dwc_otg_core_params_t *core_params;
  89374. +
  89375. + /** Core Global registers starting at offset 000h. */
  89376. + dwc_otg_core_global_regs_t *core_global_regs;
  89377. +
  89378. + /** Device-specific information */
  89379. + dwc_otg_dev_if_t *dev_if;
  89380. + /** Host-specific information */
  89381. + dwc_otg_host_if_t *host_if;
  89382. +
  89383. + /** Value from SNPSID register */
  89384. + uint32_t snpsid;
  89385. +
  89386. + /*
  89387. + * Set to 1 if the core PHY interface bits in USBCFG have been
  89388. + * initialized.
  89389. + */
  89390. + uint8_t phy_init_done;
  89391. +
  89392. + /*
  89393. + * SRP Success flag, set by srp success interrupt in FS I2C mode
  89394. + */
  89395. + uint8_t srp_success;
  89396. + uint8_t srp_timer_started;
  89397. + /** Timer for SRP. If it expires before SRP is successful
  89398. + * clear the SRP. */
  89399. + dwc_timer_t *srp_timer;
  89400. +
  89401. +#ifdef DWC_DEV_SRPCAP
  89402. + /* This timer is needed to power on the hibernated host core if SRP is not
  89403. + * initiated on connected SRP capable device for limited period of time
  89404. + */
  89405. + uint8_t pwron_timer_started;
  89406. + dwc_timer_t *pwron_timer;
  89407. +#endif
  89408. + /* Common configuration information */
  89409. + /** Power and Clock Gating Control Register */
  89410. + volatile uint32_t *pcgcctl;
  89411. +#define DWC_OTG_PCGCCTL_OFFSET 0xE00
  89412. +
  89413. + /** Push/pop addresses for endpoints or host channels.*/
  89414. + uint32_t *data_fifo[MAX_EPS_CHANNELS];
  89415. +#define DWC_OTG_DATA_FIFO_OFFSET 0x1000
  89416. +#define DWC_OTG_DATA_FIFO_SIZE 0x1000
  89417. +
  89418. + /** Total RAM for FIFOs (Bytes) */
  89419. + uint16_t total_fifo_size;
  89420. + /** Size of Rx FIFO (Bytes) */
  89421. + uint16_t rx_fifo_size;
  89422. + /** Size of Non-periodic Tx FIFO (Bytes) */
  89423. + uint16_t nperio_tx_fifo_size;
  89424. +
  89425. + /** 1 if DMA is enabled, 0 otherwise. */
  89426. + uint8_t dma_enable;
  89427. +
  89428. + /** 1 if DMA descriptor is enabled, 0 otherwise. */
  89429. + uint8_t dma_desc_enable;
  89430. +
  89431. + /** 1 if PTI Enhancement mode is enabled, 0 otherwise. */
  89432. + uint8_t pti_enh_enable;
  89433. +
  89434. + /** 1 if MPI Enhancement mode is enabled, 0 otherwise. */
  89435. + uint8_t multiproc_int_enable;
  89436. +
  89437. + /** 1 if dedicated Tx FIFOs are enabled, 0 otherwise. */
  89438. + uint8_t en_multiple_tx_fifo;
  89439. +
  89440. + /** Set to 1 if multiple packets of a high-bandwidth transfer is in
  89441. + * process of being queued */
  89442. + uint8_t queuing_high_bandwidth;
  89443. +
  89444. + /** Hardware Configuration -- stored here for convenience.*/
  89445. + hwcfg1_data_t hwcfg1;
  89446. + hwcfg2_data_t hwcfg2;
  89447. + hwcfg3_data_t hwcfg3;
  89448. + hwcfg4_data_t hwcfg4;
  89449. + fifosize_data_t hptxfsiz;
  89450. +
  89451. + /** Host and Device Configuration -- stored here for convenience.*/
  89452. + hcfg_data_t hcfg;
  89453. + dcfg_data_t dcfg;
  89454. +
  89455. + /** The operational State, during transations
  89456. + * (a_host>>a_peripherial and b_device=>b_host) this may not
  89457. + * match the core but allows the software to determine
  89458. + * transitions.
  89459. + */
  89460. + uint8_t op_state;
  89461. +
  89462. + /**
  89463. + * Set to 1 if the HCD needs to be restarted on a session request
  89464. + * interrupt. This is required if no connector ID status change has
  89465. + * occurred since the HCD was last disconnected.
  89466. + */
  89467. + uint8_t restart_hcd_on_session_req;
  89468. +
  89469. + /** HCD callbacks */
  89470. + /** A-Device is a_host */
  89471. +#define A_HOST (1)
  89472. + /** A-Device is a_suspend */
  89473. +#define A_SUSPEND (2)
  89474. + /** A-Device is a_peripherial */
  89475. +#define A_PERIPHERAL (3)
  89476. + /** B-Device is operating as a Peripheral. */
  89477. +#define B_PERIPHERAL (4)
  89478. + /** B-Device is operating as a Host. */
  89479. +#define B_HOST (5)
  89480. +
  89481. + /** HCD callbacks */
  89482. + struct dwc_otg_cil_callbacks *hcd_cb;
  89483. + /** PCD callbacks */
  89484. + struct dwc_otg_cil_callbacks *pcd_cb;
  89485. +
  89486. + /** Device mode Periodic Tx FIFO Mask */
  89487. + uint32_t p_tx_msk;
  89488. + /** Device mode Periodic Tx FIFO Mask */
  89489. + uint32_t tx_msk;
  89490. +
  89491. + /** Workqueue object used for handling several interrupts */
  89492. + dwc_workq_t *wq_otg;
  89493. +
  89494. + /** Timer object used for handling "Wakeup Detected" Interrupt */
  89495. + dwc_timer_t *wkp_timer;
  89496. + /** This arrays used for debug purposes for DEV OUT NAK enhancement */
  89497. + uint32_t start_doeptsiz_val[MAX_EPS_CHANNELS];
  89498. + ep_xfer_info_t ep_xfer_info[MAX_EPS_CHANNELS];
  89499. + dwc_timer_t *ep_xfer_timer[MAX_EPS_CHANNELS];
  89500. +#ifdef DEBUG
  89501. + uint32_t start_hcchar_val[MAX_EPS_CHANNELS];
  89502. +
  89503. + hc_xfer_info_t hc_xfer_info[MAX_EPS_CHANNELS];
  89504. + dwc_timer_t *hc_xfer_timer[MAX_EPS_CHANNELS];
  89505. +
  89506. + uint32_t hfnum_7_samples;
  89507. + uint64_t hfnum_7_frrem_accum;
  89508. + uint32_t hfnum_0_samples;
  89509. + uint64_t hfnum_0_frrem_accum;
  89510. + uint32_t hfnum_other_samples;
  89511. + uint64_t hfnum_other_frrem_accum;
  89512. +#endif
  89513. +
  89514. +#ifdef DWC_UTE_CFI
  89515. + uint16_t pwron_rxfsiz;
  89516. + uint16_t pwron_gnptxfsiz;
  89517. + uint16_t pwron_txfsiz[15];
  89518. +
  89519. + uint16_t init_rxfsiz;
  89520. + uint16_t init_gnptxfsiz;
  89521. + uint16_t init_txfsiz[15];
  89522. +#endif
  89523. +
  89524. + /** Lx state of device */
  89525. + dwc_otg_lx_state_e lx_state;
  89526. +
  89527. + /** Saved Core Global registers */
  89528. + struct dwc_otg_global_regs_backup *gr_backup;
  89529. + /** Saved Host registers */
  89530. + struct dwc_otg_host_regs_backup *hr_backup;
  89531. + /** Saved Device registers */
  89532. + struct dwc_otg_dev_regs_backup *dr_backup;
  89533. +
  89534. + /** Power Down Enable */
  89535. + uint32_t power_down;
  89536. +
  89537. + /** ADP support Enable */
  89538. + uint32_t adp_enable;
  89539. +
  89540. + /** ADP structure object */
  89541. + dwc_otg_adp_t adp;
  89542. +
  89543. + /** hibernation/suspend flag */
  89544. + int hibernation_suspend;
  89545. +
  89546. + /** Device mode extended hibernation flag */
  89547. + int xhib;
  89548. +
  89549. + /** OTG revision supported */
  89550. + uint32_t otg_ver;
  89551. +
  89552. + /** OTG status flag used for HNP polling */
  89553. + uint8_t otg_sts;
  89554. +
  89555. + /** Pointer to either hcd->lock or pcd->lock */
  89556. + dwc_spinlock_t *lock;
  89557. +
  89558. + /** Start predict NextEP based on Learning Queue if equal 1,
  89559. + * also used as counter of disabled NP IN EP's */
  89560. + uint8_t start_predict;
  89561. +
  89562. + /** NextEp sequence, including EP0: nextep_seq[] = EP if non-periodic and
  89563. + * active, 0xff otherwise */
  89564. + uint8_t nextep_seq[MAX_EPS_CHANNELS];
  89565. +
  89566. + /** Index of fisrt EP in nextep_seq array which should be re-enabled **/
  89567. + uint8_t first_in_nextep_seq;
  89568. +
  89569. + /** Frame number while entering to ISR - needed for ISOCs **/
  89570. + uint32_t frame_num;
  89571. +
  89572. +};
  89573. +
  89574. +#ifdef DEBUG
  89575. +/*
  89576. + * This function is called when transfer is timed out.
  89577. + */
  89578. +extern void hc_xfer_timeout(void *ptr);
  89579. +#endif
  89580. +
  89581. +/*
  89582. + * This function is called when transfer is timed out on endpoint.
  89583. + */
  89584. +extern void ep_xfer_timeout(void *ptr);
  89585. +
  89586. +/*
  89587. + * The following functions are functions for works
  89588. + * using during handling some interrupts
  89589. + */
  89590. +extern void w_conn_id_status_change(void *p);
  89591. +
  89592. +extern void w_wakeup_detected(void *p);
  89593. +
  89594. +/** Saves global register values into system memory. */
  89595. +extern int dwc_otg_save_global_regs(dwc_otg_core_if_t * core_if);
  89596. +/** Saves device register values into system memory. */
  89597. +extern int dwc_otg_save_dev_regs(dwc_otg_core_if_t * core_if);
  89598. +/** Saves host register values into system memory. */
  89599. +extern int dwc_otg_save_host_regs(dwc_otg_core_if_t * core_if);
  89600. +/** Restore global register values. */
  89601. +extern int dwc_otg_restore_global_regs(dwc_otg_core_if_t * core_if);
  89602. +/** Restore host register values. */
  89603. +extern int dwc_otg_restore_host_regs(dwc_otg_core_if_t * core_if, int reset);
  89604. +/** Restore device register values. */
  89605. +extern int dwc_otg_restore_dev_regs(dwc_otg_core_if_t * core_if,
  89606. + int rem_wakeup);
  89607. +extern int restore_lpm_i2c_regs(dwc_otg_core_if_t * core_if);
  89608. +extern int restore_essential_regs(dwc_otg_core_if_t * core_if, int rmode,
  89609. + int is_host);
  89610. +
  89611. +extern int dwc_otg_host_hibernation_restore(dwc_otg_core_if_t * core_if,
  89612. + int restore_mode, int reset);
  89613. +extern int dwc_otg_device_hibernation_restore(dwc_otg_core_if_t * core_if,
  89614. + int rem_wakeup, int reset);
  89615. +
  89616. +/*
  89617. + * The following functions support initialization of the CIL driver component
  89618. + * and the DWC_otg controller.
  89619. + */
  89620. +extern void dwc_otg_core_host_init(dwc_otg_core_if_t * _core_if);
  89621. +extern void dwc_otg_core_dev_init(dwc_otg_core_if_t * _core_if);
  89622. +
  89623. +/** @name Device CIL Functions
  89624. + * The following functions support managing the DWC_otg controller in device
  89625. + * mode.
  89626. + */
  89627. +/**@{*/
  89628. +extern void dwc_otg_wakeup(dwc_otg_core_if_t * _core_if);
  89629. +extern void dwc_otg_read_setup_packet(dwc_otg_core_if_t * _core_if,
  89630. + uint32_t * _dest);
  89631. +extern uint32_t dwc_otg_get_frame_number(dwc_otg_core_if_t * _core_if);
  89632. +extern void dwc_otg_ep0_activate(dwc_otg_core_if_t * _core_if, dwc_ep_t * _ep);
  89633. +extern void dwc_otg_ep_activate(dwc_otg_core_if_t * _core_if, dwc_ep_t * _ep);
  89634. +extern void dwc_otg_ep_deactivate(dwc_otg_core_if_t * _core_if, dwc_ep_t * _ep);
  89635. +extern void dwc_otg_ep_start_transfer(dwc_otg_core_if_t * _core_if,
  89636. + dwc_ep_t * _ep);
  89637. +extern void dwc_otg_ep_start_zl_transfer(dwc_otg_core_if_t * _core_if,
  89638. + dwc_ep_t * _ep);
  89639. +extern void dwc_otg_ep0_start_transfer(dwc_otg_core_if_t * _core_if,
  89640. + dwc_ep_t * _ep);
  89641. +extern void dwc_otg_ep0_continue_transfer(dwc_otg_core_if_t * _core_if,
  89642. + dwc_ep_t * _ep);
  89643. +extern void dwc_otg_ep_write_packet(dwc_otg_core_if_t * _core_if,
  89644. + dwc_ep_t * _ep, int _dma);
  89645. +extern void dwc_otg_ep_set_stall(dwc_otg_core_if_t * _core_if, dwc_ep_t * _ep);
  89646. +extern void dwc_otg_ep_clear_stall(dwc_otg_core_if_t * _core_if,
  89647. + dwc_ep_t * _ep);
  89648. +extern void dwc_otg_enable_device_interrupts(dwc_otg_core_if_t * _core_if);
  89649. +
  89650. +#ifdef DWC_EN_ISOC
  89651. +extern void dwc_otg_iso_ep_start_frm_transfer(dwc_otg_core_if_t * core_if,
  89652. + dwc_ep_t * ep);
  89653. +extern void dwc_otg_iso_ep_start_buf_transfer(dwc_otg_core_if_t * core_if,
  89654. + dwc_ep_t * ep);
  89655. +#endif /* DWC_EN_ISOC */
  89656. +/**@}*/
  89657. +
  89658. +/** @name Host CIL Functions
  89659. + * The following functions support managing the DWC_otg controller in host
  89660. + * mode.
  89661. + */
  89662. +/**@{*/
  89663. +extern void dwc_otg_hc_init(dwc_otg_core_if_t * _core_if, dwc_hc_t * _hc);
  89664. +extern void dwc_otg_hc_halt(dwc_otg_core_if_t * _core_if,
  89665. + dwc_hc_t * _hc, dwc_otg_halt_status_e _halt_status);
  89666. +extern void dwc_otg_hc_cleanup(dwc_otg_core_if_t * _core_if, dwc_hc_t * _hc);
  89667. +extern void dwc_otg_hc_start_transfer(dwc_otg_core_if_t * _core_if,
  89668. + dwc_hc_t * _hc);
  89669. +extern int dwc_otg_hc_continue_transfer(dwc_otg_core_if_t * _core_if,
  89670. + dwc_hc_t * _hc);
  89671. +extern void dwc_otg_hc_do_ping(dwc_otg_core_if_t * _core_if, dwc_hc_t * _hc);
  89672. +extern void dwc_otg_hc_write_packet(dwc_otg_core_if_t * _core_if,
  89673. + dwc_hc_t * _hc);
  89674. +extern void dwc_otg_enable_host_interrupts(dwc_otg_core_if_t * _core_if);
  89675. +extern void dwc_otg_disable_host_interrupts(dwc_otg_core_if_t * _core_if);
  89676. +
  89677. +extern void dwc_otg_hc_start_transfer_ddma(dwc_otg_core_if_t * core_if,
  89678. + dwc_hc_t * hc);
  89679. +
  89680. +extern uint32_t calc_frame_interval(dwc_otg_core_if_t * core_if);
  89681. +
  89682. +/* Macro used to clear one channel interrupt */
  89683. +#define clear_hc_int(_hc_regs_, _intr_) \
  89684. +do { \
  89685. + hcint_data_t hcint_clear = {.d32 = 0}; \
  89686. + hcint_clear.b._intr_ = 1; \
  89687. + DWC_WRITE_REG32(&(_hc_regs_)->hcint, hcint_clear.d32); \
  89688. +} while (0)
  89689. +
  89690. +/*
  89691. + * Macro used to disable one channel interrupt. Channel interrupts are
  89692. + * disabled when the channel is halted or released by the interrupt handler.
  89693. + * There is no need to handle further interrupts of that type until the
  89694. + * channel is re-assigned. In fact, subsequent handling may cause crashes
  89695. + * because the channel structures are cleaned up when the channel is released.
  89696. + */
  89697. +#define disable_hc_int(_hc_regs_, _intr_) \
  89698. +do { \
  89699. + hcintmsk_data_t hcintmsk = {.d32 = 0}; \
  89700. + hcintmsk.b._intr_ = 1; \
  89701. + DWC_MODIFY_REG32(&(_hc_regs_)->hcintmsk, hcintmsk.d32, 0); \
  89702. +} while (0)
  89703. +
  89704. +/**
  89705. + * This function Reads HPRT0 in preparation to modify. It keeps the
  89706. + * WC bits 0 so that if they are read as 1, they won't clear when you
  89707. + * write it back
  89708. + */
  89709. +static inline uint32_t dwc_otg_read_hprt0(dwc_otg_core_if_t * _core_if)
  89710. +{
  89711. + hprt0_data_t hprt0;
  89712. + hprt0.d32 = DWC_READ_REG32(_core_if->host_if->hprt0);
  89713. + hprt0.b.prtena = 0;
  89714. + hprt0.b.prtconndet = 0;
  89715. + hprt0.b.prtenchng = 0;
  89716. + hprt0.b.prtovrcurrchng = 0;
  89717. + return hprt0.d32;
  89718. +}
  89719. +
  89720. +/**@}*/
  89721. +
  89722. +/** @name Common CIL Functions
  89723. + * The following functions support managing the DWC_otg controller in either
  89724. + * device or host mode.
  89725. + */
  89726. +/**@{*/
  89727. +
  89728. +extern void dwc_otg_read_packet(dwc_otg_core_if_t * core_if,
  89729. + uint8_t * dest, uint16_t bytes);
  89730. +
  89731. +extern void dwc_otg_flush_tx_fifo(dwc_otg_core_if_t * _core_if, const int _num);
  89732. +extern void dwc_otg_flush_rx_fifo(dwc_otg_core_if_t * _core_if);
  89733. +extern void dwc_otg_core_reset(dwc_otg_core_if_t * _core_if);
  89734. +
  89735. +/**
  89736. + * This function returns the Core Interrupt register.
  89737. + */
  89738. +static inline uint32_t dwc_otg_read_core_intr(dwc_otg_core_if_t * core_if)
  89739. +{
  89740. + return (DWC_READ_REG32(&core_if->core_global_regs->gintsts) &
  89741. + DWC_READ_REG32(&core_if->core_global_regs->gintmsk));
  89742. +}
  89743. +
  89744. +/**
  89745. + * This function returns the OTG Interrupt register.
  89746. + */
  89747. +static inline uint32_t dwc_otg_read_otg_intr(dwc_otg_core_if_t * core_if)
  89748. +{
  89749. + return (DWC_READ_REG32(&core_if->core_global_regs->gotgint));
  89750. +}
  89751. +
  89752. +/**
  89753. + * This function reads the Device All Endpoints Interrupt register and
  89754. + * returns the IN endpoint interrupt bits.
  89755. + */
  89756. +static inline uint32_t dwc_otg_read_dev_all_in_ep_intr(dwc_otg_core_if_t *
  89757. + core_if)
  89758. +{
  89759. +
  89760. + uint32_t v;
  89761. +
  89762. + if (core_if->multiproc_int_enable) {
  89763. + v = DWC_READ_REG32(&core_if->dev_if->
  89764. + dev_global_regs->deachint) &
  89765. + DWC_READ_REG32(&core_if->
  89766. + dev_if->dev_global_regs->deachintmsk);
  89767. + } else {
  89768. + v = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->daint) &
  89769. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->daintmsk);
  89770. + }
  89771. + return (v & 0xffff);
  89772. +}
  89773. +
  89774. +/**
  89775. + * This function reads the Device All Endpoints Interrupt register and
  89776. + * returns the OUT endpoint interrupt bits.
  89777. + */
  89778. +static inline uint32_t dwc_otg_read_dev_all_out_ep_intr(dwc_otg_core_if_t *
  89779. + core_if)
  89780. +{
  89781. + uint32_t v;
  89782. +
  89783. + if (core_if->multiproc_int_enable) {
  89784. + v = DWC_READ_REG32(&core_if->dev_if->
  89785. + dev_global_regs->deachint) &
  89786. + DWC_READ_REG32(&core_if->
  89787. + dev_if->dev_global_regs->deachintmsk);
  89788. + } else {
  89789. + v = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->daint) &
  89790. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->daintmsk);
  89791. + }
  89792. +
  89793. + return ((v & 0xffff0000) >> 16);
  89794. +}
  89795. +
  89796. +/**
  89797. + * This function returns the Device IN EP Interrupt register
  89798. + */
  89799. +static inline uint32_t dwc_otg_read_dev_in_ep_intr(dwc_otg_core_if_t * core_if,
  89800. + dwc_ep_t * ep)
  89801. +{
  89802. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  89803. + uint32_t v, msk, emp;
  89804. +
  89805. + if (core_if->multiproc_int_enable) {
  89806. + msk =
  89807. + DWC_READ_REG32(&dev_if->
  89808. + dev_global_regs->diepeachintmsk[ep->num]);
  89809. + emp =
  89810. + DWC_READ_REG32(&dev_if->
  89811. + dev_global_regs->dtknqr4_fifoemptymsk);
  89812. + msk |= ((emp >> ep->num) & 0x1) << 7;
  89813. + v = DWC_READ_REG32(&dev_if->in_ep_regs[ep->num]->diepint) & msk;
  89814. + } else {
  89815. + msk = DWC_READ_REG32(&dev_if->dev_global_regs->diepmsk);
  89816. + emp =
  89817. + DWC_READ_REG32(&dev_if->
  89818. + dev_global_regs->dtknqr4_fifoemptymsk);
  89819. + msk |= ((emp >> ep->num) & 0x1) << 7;
  89820. + v = DWC_READ_REG32(&dev_if->in_ep_regs[ep->num]->diepint) & msk;
  89821. + }
  89822. +
  89823. + return v;
  89824. +}
  89825. +
  89826. +/**
  89827. + * This function returns the Device OUT EP Interrupt register
  89828. + */
  89829. +static inline uint32_t dwc_otg_read_dev_out_ep_intr(dwc_otg_core_if_t *
  89830. + _core_if, dwc_ep_t * _ep)
  89831. +{
  89832. + dwc_otg_dev_if_t *dev_if = _core_if->dev_if;
  89833. + uint32_t v;
  89834. + doepmsk_data_t msk = {.d32 = 0 };
  89835. +
  89836. + if (_core_if->multiproc_int_enable) {
  89837. + msk.d32 =
  89838. + DWC_READ_REG32(&dev_if->
  89839. + dev_global_regs->doepeachintmsk[_ep->num]);
  89840. + if (_core_if->pti_enh_enable) {
  89841. + msk.b.pktdrpsts = 1;
  89842. + }
  89843. + v = DWC_READ_REG32(&dev_if->
  89844. + out_ep_regs[_ep->num]->doepint) & msk.d32;
  89845. + } else {
  89846. + msk.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->doepmsk);
  89847. + if (_core_if->pti_enh_enable) {
  89848. + msk.b.pktdrpsts = 1;
  89849. + }
  89850. + v = DWC_READ_REG32(&dev_if->
  89851. + out_ep_regs[_ep->num]->doepint) & msk.d32;
  89852. + }
  89853. + return v;
  89854. +}
  89855. +
  89856. +/**
  89857. + * This function returns the Host All Channel Interrupt register
  89858. + */
  89859. +static inline uint32_t dwc_otg_read_host_all_channels_intr(dwc_otg_core_if_t *
  89860. + _core_if)
  89861. +{
  89862. + return (DWC_READ_REG32(&_core_if->host_if->host_global_regs->haint));
  89863. +}
  89864. +
  89865. +static inline uint32_t dwc_otg_read_host_channel_intr(dwc_otg_core_if_t *
  89866. + _core_if, dwc_hc_t * _hc)
  89867. +{
  89868. + return (DWC_READ_REG32
  89869. + (&_core_if->host_if->hc_regs[_hc->hc_num]->hcint));
  89870. +}
  89871. +
  89872. +/**
  89873. + * This function returns the mode of the operation, host or device.
  89874. + *
  89875. + * @return 0 - Device Mode, 1 - Host Mode
  89876. + */
  89877. +static inline uint32_t dwc_otg_mode(dwc_otg_core_if_t * _core_if)
  89878. +{
  89879. + return (DWC_READ_REG32(&_core_if->core_global_regs->gintsts) & 0x1);
  89880. +}
  89881. +
  89882. +/**@}*/
  89883. +
  89884. +/**
  89885. + * DWC_otg CIL callback structure. This structure allows the HCD and
  89886. + * PCD to register functions used for starting and stopping the PCD
  89887. + * and HCD for role change on for a DRD.
  89888. + */
  89889. +typedef struct dwc_otg_cil_callbacks {
  89890. + /** Start function for role change */
  89891. + int (*start) (void *_p);
  89892. + /** Stop Function for role change */
  89893. + int (*stop) (void *_p);
  89894. + /** Disconnect Function for role change */
  89895. + int (*disconnect) (void *_p);
  89896. + /** Resume/Remote wakeup Function */
  89897. + int (*resume_wakeup) (void *_p);
  89898. + /** Suspend function */
  89899. + int (*suspend) (void *_p);
  89900. + /** Session Start (SRP) */
  89901. + int (*session_start) (void *_p);
  89902. +#ifdef CONFIG_USB_DWC_OTG_LPM
  89903. + /** Sleep (switch to L0 state) */
  89904. + int (*sleep) (void *_p);
  89905. +#endif
  89906. + /** Pointer passed to start() and stop() */
  89907. + void *p;
  89908. +} dwc_otg_cil_callbacks_t;
  89909. +
  89910. +extern void dwc_otg_cil_register_pcd_callbacks(dwc_otg_core_if_t * _core_if,
  89911. + dwc_otg_cil_callbacks_t * _cb,
  89912. + void *_p);
  89913. +extern void dwc_otg_cil_register_hcd_callbacks(dwc_otg_core_if_t * _core_if,
  89914. + dwc_otg_cil_callbacks_t * _cb,
  89915. + void *_p);
  89916. +
  89917. +void dwc_otg_initiate_srp(dwc_otg_core_if_t * core_if);
  89918. +
  89919. +//////////////////////////////////////////////////////////////////////
  89920. +/** Start the HCD. Helper function for using the HCD callbacks.
  89921. + *
  89922. + * @param core_if Programming view of DWC_otg controller.
  89923. + */
  89924. +static inline void cil_hcd_start(dwc_otg_core_if_t * core_if)
  89925. +{
  89926. + if (core_if->hcd_cb && core_if->hcd_cb->start) {
  89927. + core_if->hcd_cb->start(core_if->hcd_cb->p);
  89928. + }
  89929. +}
  89930. +
  89931. +/** Stop the HCD. Helper function for using the HCD callbacks.
  89932. + *
  89933. + * @param core_if Programming view of DWC_otg controller.
  89934. + */
  89935. +static inline void cil_hcd_stop(dwc_otg_core_if_t * core_if)
  89936. +{
  89937. + if (core_if->hcd_cb && core_if->hcd_cb->stop) {
  89938. + core_if->hcd_cb->stop(core_if->hcd_cb->p);
  89939. + }
  89940. +}
  89941. +
  89942. +/** Disconnect the HCD. Helper function for using the HCD callbacks.
  89943. + *
  89944. + * @param core_if Programming view of DWC_otg controller.
  89945. + */
  89946. +static inline void cil_hcd_disconnect(dwc_otg_core_if_t * core_if)
  89947. +{
  89948. + if (core_if->hcd_cb && core_if->hcd_cb->disconnect) {
  89949. + core_if->hcd_cb->disconnect(core_if->hcd_cb->p);
  89950. + }
  89951. +}
  89952. +
  89953. +/** Inform the HCD the a New Session has begun. Helper function for
  89954. + * using the HCD callbacks.
  89955. + *
  89956. + * @param core_if Programming view of DWC_otg controller.
  89957. + */
  89958. +static inline void cil_hcd_session_start(dwc_otg_core_if_t * core_if)
  89959. +{
  89960. + if (core_if->hcd_cb && core_if->hcd_cb->session_start) {
  89961. + core_if->hcd_cb->session_start(core_if->hcd_cb->p);
  89962. + }
  89963. +}
  89964. +
  89965. +#ifdef CONFIG_USB_DWC_OTG_LPM
  89966. +/**
  89967. + * Inform the HCD about LPM sleep.
  89968. + * Helper function for using the HCD callbacks.
  89969. + *
  89970. + * @param core_if Programming view of DWC_otg controller.
  89971. + */
  89972. +static inline void cil_hcd_sleep(dwc_otg_core_if_t * core_if)
  89973. +{
  89974. + if (core_if->hcd_cb && core_if->hcd_cb->sleep) {
  89975. + core_if->hcd_cb->sleep(core_if->hcd_cb->p);
  89976. + }
  89977. +}
  89978. +#endif
  89979. +
  89980. +/** Resume the HCD. Helper function for using the HCD callbacks.
  89981. + *
  89982. + * @param core_if Programming view of DWC_otg controller.
  89983. + */
  89984. +static inline void cil_hcd_resume(dwc_otg_core_if_t * core_if)
  89985. +{
  89986. + if (core_if->hcd_cb && core_if->hcd_cb->resume_wakeup) {
  89987. + core_if->hcd_cb->resume_wakeup(core_if->hcd_cb->p);
  89988. + }
  89989. +}
  89990. +
  89991. +/** Start the PCD. Helper function for using the PCD callbacks.
  89992. + *
  89993. + * @param core_if Programming view of DWC_otg controller.
  89994. + */
  89995. +static inline void cil_pcd_start(dwc_otg_core_if_t * core_if)
  89996. +{
  89997. + if (core_if->pcd_cb && core_if->pcd_cb->start) {
  89998. + core_if->pcd_cb->start(core_if->pcd_cb->p);
  89999. + }
  90000. +}
  90001. +
  90002. +/** Stop the PCD. Helper function for using the PCD callbacks.
  90003. + *
  90004. + * @param core_if Programming view of DWC_otg controller.
  90005. + */
  90006. +static inline void cil_pcd_stop(dwc_otg_core_if_t * core_if)
  90007. +{
  90008. + if (core_if->pcd_cb && core_if->pcd_cb->stop) {
  90009. + core_if->pcd_cb->stop(core_if->pcd_cb->p);
  90010. + }
  90011. +}
  90012. +
  90013. +/** Suspend the PCD. Helper function for using the PCD callbacks.
  90014. + *
  90015. + * @param core_if Programming view of DWC_otg controller.
  90016. + */
  90017. +static inline void cil_pcd_suspend(dwc_otg_core_if_t * core_if)
  90018. +{
  90019. + if (core_if->pcd_cb && core_if->pcd_cb->suspend) {
  90020. + core_if->pcd_cb->suspend(core_if->pcd_cb->p);
  90021. + }
  90022. +}
  90023. +
  90024. +/** Resume the PCD. Helper function for using the PCD callbacks.
  90025. + *
  90026. + * @param core_if Programming view of DWC_otg controller.
  90027. + */
  90028. +static inline void cil_pcd_resume(dwc_otg_core_if_t * core_if)
  90029. +{
  90030. + if (core_if->pcd_cb && core_if->pcd_cb->resume_wakeup) {
  90031. + core_if->pcd_cb->resume_wakeup(core_if->pcd_cb->p);
  90032. + }
  90033. +}
  90034. +
  90035. +//////////////////////////////////////////////////////////////////////
  90036. +
  90037. +#endif
  90038. diff -Nur linux-3.18.8/drivers/usb/host/dwc_otg/dwc_otg_cil_intr.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_cil_intr.c
  90039. --- linux-3.18.8/drivers/usb/host/dwc_otg/dwc_otg_cil_intr.c 1970-01-01 01:00:00.000000000 +0100
  90040. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_cil_intr.c 2015-03-05 14:40:16.557715806 +0100
  90041. @@ -0,0 +1,1594 @@
  90042. +/* ==========================================================================
  90043. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_cil_intr.c $
  90044. + * $Revision: #32 $
  90045. + * $Date: 2012/08/10 $
  90046. + * $Change: 2047372 $
  90047. + *
  90048. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  90049. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  90050. + * otherwise expressly agreed to in writing between Synopsys and you.
  90051. + *
  90052. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  90053. + * any End User Software License Agreement or Agreement for Licensed Product
  90054. + * with Synopsys or any supplement thereto. You are permitted to use and
  90055. + * redistribute this Software in source and binary forms, with or without
  90056. + * modification, provided that redistributions of source code must retain this
  90057. + * notice. You may not view, use, disclose, copy or distribute this file or
  90058. + * any information contained herein except pursuant to this license grant from
  90059. + * Synopsys. If you do not agree with this notice, including the disclaimer
  90060. + * below, then you are not authorized to use the Software.
  90061. + *
  90062. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  90063. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  90064. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  90065. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  90066. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  90067. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  90068. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  90069. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  90070. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  90071. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  90072. + * DAMAGE.
  90073. + * ========================================================================== */
  90074. +
  90075. +/** @file
  90076. + *
  90077. + * The Core Interface Layer provides basic services for accessing and
  90078. + * managing the DWC_otg hardware. These services are used by both the
  90079. + * Host Controller Driver and the Peripheral Controller Driver.
  90080. + *
  90081. + * This file contains the Common Interrupt handlers.
  90082. + */
  90083. +#include "dwc_os.h"
  90084. +#include "dwc_otg_regs.h"
  90085. +#include "dwc_otg_cil.h"
  90086. +#include "dwc_otg_driver.h"
  90087. +#include "dwc_otg_pcd.h"
  90088. +#include "dwc_otg_hcd.h"
  90089. +
  90090. +#ifdef DEBUG
  90091. +inline const char *op_state_str(dwc_otg_core_if_t * core_if)
  90092. +{
  90093. + return (core_if->op_state == A_HOST ? "a_host" :
  90094. + (core_if->op_state == A_SUSPEND ? "a_suspend" :
  90095. + (core_if->op_state == A_PERIPHERAL ? "a_peripheral" :
  90096. + (core_if->op_state == B_PERIPHERAL ? "b_peripheral" :
  90097. + (core_if->op_state == B_HOST ? "b_host" : "unknown")))));
  90098. +}
  90099. +#endif
  90100. +
  90101. +/** This function will log a debug message
  90102. + *
  90103. + * @param core_if Programming view of DWC_otg controller.
  90104. + */
  90105. +int32_t dwc_otg_handle_mode_mismatch_intr(dwc_otg_core_if_t * core_if)
  90106. +{
  90107. + gintsts_data_t gintsts;
  90108. + DWC_WARN("Mode Mismatch Interrupt: currently in %s mode\n",
  90109. + dwc_otg_mode(core_if) ? "Host" : "Device");
  90110. +
  90111. + /* Clear interrupt */
  90112. + gintsts.d32 = 0;
  90113. + gintsts.b.modemismatch = 1;
  90114. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  90115. + return 1;
  90116. +}
  90117. +
  90118. +/**
  90119. + * This function handles the OTG Interrupts. It reads the OTG
  90120. + * Interrupt Register (GOTGINT) to determine what interrupt has
  90121. + * occurred.
  90122. + *
  90123. + * @param core_if Programming view of DWC_otg controller.
  90124. + */
  90125. +int32_t dwc_otg_handle_otg_intr(dwc_otg_core_if_t * core_if)
  90126. +{
  90127. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  90128. + gotgint_data_t gotgint;
  90129. + gotgctl_data_t gotgctl;
  90130. + gintmsk_data_t gintmsk;
  90131. + gpwrdn_data_t gpwrdn;
  90132. +
  90133. + gotgint.d32 = DWC_READ_REG32(&global_regs->gotgint);
  90134. + gotgctl.d32 = DWC_READ_REG32(&global_regs->gotgctl);
  90135. + DWC_DEBUGPL(DBG_CIL, "++OTG Interrupt gotgint=%0x [%s]\n", gotgint.d32,
  90136. + op_state_str(core_if));
  90137. +
  90138. + if (gotgint.b.sesenddet) {
  90139. + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: "
  90140. + "Session End Detected++ (%s)\n",
  90141. + op_state_str(core_if));
  90142. + gotgctl.d32 = DWC_READ_REG32(&global_regs->gotgctl);
  90143. +
  90144. + if (core_if->op_state == B_HOST) {
  90145. + cil_pcd_start(core_if);
  90146. + core_if->op_state = B_PERIPHERAL;
  90147. + } else {
  90148. + /* If not B_HOST and Device HNP still set. HNP
  90149. + * Did not succeed!*/
  90150. + if (gotgctl.b.devhnpen) {
  90151. + DWC_DEBUGPL(DBG_ANY, "Session End Detected\n");
  90152. + __DWC_ERROR("Device Not Connected/Responding!\n");
  90153. + }
  90154. +
  90155. + /* If Session End Detected the B-Cable has
  90156. + * been disconnected. */
  90157. + /* Reset PCD and Gadget driver to a
  90158. + * clean state. */
  90159. + core_if->lx_state = DWC_OTG_L0;
  90160. + DWC_SPINUNLOCK(core_if->lock);
  90161. + cil_pcd_stop(core_if);
  90162. + DWC_SPINLOCK(core_if->lock);
  90163. +
  90164. + if (core_if->adp_enable) {
  90165. + if (core_if->power_down == 2) {
  90166. + gpwrdn.d32 = 0;
  90167. + gpwrdn.b.pwrdnswtch = 1;
  90168. + DWC_MODIFY_REG32(&core_if->
  90169. + core_global_regs->
  90170. + gpwrdn, gpwrdn.d32, 0);
  90171. + }
  90172. +
  90173. + gpwrdn.d32 = 0;
  90174. + gpwrdn.b.pmuintsel = 1;
  90175. + gpwrdn.b.pmuactv = 1;
  90176. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  90177. + gpwrdn, 0, gpwrdn.d32);
  90178. +
  90179. + dwc_otg_adp_sense_start(core_if);
  90180. + }
  90181. + }
  90182. +
  90183. + gotgctl.d32 = 0;
  90184. + gotgctl.b.devhnpen = 1;
  90185. + DWC_MODIFY_REG32(&global_regs->gotgctl, gotgctl.d32, 0);
  90186. + }
  90187. + if (gotgint.b.sesreqsucstschng) {
  90188. + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: "
  90189. + "Session Reqeust Success Status Change++\n");
  90190. + gotgctl.d32 = DWC_READ_REG32(&global_regs->gotgctl);
  90191. + if (gotgctl.b.sesreqscs) {
  90192. +
  90193. + if ((core_if->core_params->phy_type ==
  90194. + DWC_PHY_TYPE_PARAM_FS) && (core_if->core_params->i2c_enable)) {
  90195. + core_if->srp_success = 1;
  90196. + } else {
  90197. + DWC_SPINUNLOCK(core_if->lock);
  90198. + cil_pcd_resume(core_if);
  90199. + DWC_SPINLOCK(core_if->lock);
  90200. + /* Clear Session Request */
  90201. + gotgctl.d32 = 0;
  90202. + gotgctl.b.sesreq = 1;
  90203. + DWC_MODIFY_REG32(&global_regs->gotgctl,
  90204. + gotgctl.d32, 0);
  90205. + }
  90206. + }
  90207. + }
  90208. + if (gotgint.b.hstnegsucstschng) {
  90209. + /* Print statements during the HNP interrupt handling
  90210. + * can cause it to fail.*/
  90211. + gotgctl.d32 = DWC_READ_REG32(&global_regs->gotgctl);
  90212. + /* WA for 3.00a- HW is not setting cur_mode, even sometimes
  90213. + * this does not help*/
  90214. + if (core_if->snpsid >= OTG_CORE_REV_3_00a)
  90215. + dwc_udelay(100);
  90216. + if (gotgctl.b.hstnegscs) {
  90217. + if (dwc_otg_is_host_mode(core_if)) {
  90218. + core_if->op_state = B_HOST;
  90219. + /*
  90220. + * Need to disable SOF interrupt immediately.
  90221. + * When switching from device to host, the PCD
  90222. + * interrupt handler won't handle the
  90223. + * interrupt if host mode is already set. The
  90224. + * HCD interrupt handler won't get called if
  90225. + * the HCD state is HALT. This means that the
  90226. + * interrupt does not get handled and Linux
  90227. + * complains loudly.
  90228. + */
  90229. + gintmsk.d32 = 0;
  90230. + gintmsk.b.sofintr = 1;
  90231. + DWC_MODIFY_REG32(&global_regs->gintmsk,
  90232. + gintmsk.d32, 0);
  90233. + /* Call callback function with spin lock released */
  90234. + DWC_SPINUNLOCK(core_if->lock);
  90235. + cil_pcd_stop(core_if);
  90236. + /*
  90237. + * Initialize the Core for Host mode.
  90238. + */
  90239. + cil_hcd_start(core_if);
  90240. + DWC_SPINLOCK(core_if->lock);
  90241. + core_if->op_state = B_HOST;
  90242. + }
  90243. + } else {
  90244. + gotgctl.d32 = 0;
  90245. + gotgctl.b.hnpreq = 1;
  90246. + gotgctl.b.devhnpen = 1;
  90247. + DWC_MODIFY_REG32(&global_regs->gotgctl, gotgctl.d32, 0);
  90248. + DWC_DEBUGPL(DBG_ANY, "HNP Failed\n");
  90249. + __DWC_ERROR("Device Not Connected/Responding\n");
  90250. + }
  90251. + }
  90252. + if (gotgint.b.hstnegdet) {
  90253. + /* The disconnect interrupt is set at the same time as
  90254. + * Host Negotiation Detected. During the mode
  90255. + * switch all interrupts are cleared so the disconnect
  90256. + * interrupt handler will not get executed.
  90257. + */
  90258. + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: "
  90259. + "Host Negotiation Detected++ (%s)\n",
  90260. + (dwc_otg_is_host_mode(core_if) ? "Host" :
  90261. + "Device"));
  90262. + if (dwc_otg_is_device_mode(core_if)) {
  90263. + DWC_DEBUGPL(DBG_ANY, "a_suspend->a_peripheral (%d)\n",
  90264. + core_if->op_state);
  90265. + DWC_SPINUNLOCK(core_if->lock);
  90266. + cil_hcd_disconnect(core_if);
  90267. + cil_pcd_start(core_if);
  90268. + DWC_SPINLOCK(core_if->lock);
  90269. + core_if->op_state = A_PERIPHERAL;
  90270. + } else {
  90271. + /*
  90272. + * Need to disable SOF interrupt immediately. When
  90273. + * switching from device to host, the PCD interrupt
  90274. + * handler won't handle the interrupt if host mode is
  90275. + * already set. The HCD interrupt handler won't get
  90276. + * called if the HCD state is HALT. This means that
  90277. + * the interrupt does not get handled and Linux
  90278. + * complains loudly.
  90279. + */
  90280. + gintmsk.d32 = 0;
  90281. + gintmsk.b.sofintr = 1;
  90282. + DWC_MODIFY_REG32(&global_regs->gintmsk, gintmsk.d32, 0);
  90283. + DWC_SPINUNLOCK(core_if->lock);
  90284. + cil_pcd_stop(core_if);
  90285. + cil_hcd_start(core_if);
  90286. + DWC_SPINLOCK(core_if->lock);
  90287. + core_if->op_state = A_HOST;
  90288. + }
  90289. + }
  90290. + if (gotgint.b.adevtoutchng) {
  90291. + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: "
  90292. + "A-Device Timeout Change++\n");
  90293. + }
  90294. + if (gotgint.b.debdone) {
  90295. + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: " "Debounce Done++\n");
  90296. + }
  90297. +
  90298. + /* Clear GOTGINT */
  90299. + DWC_WRITE_REG32(&core_if->core_global_regs->gotgint, gotgint.d32);
  90300. +
  90301. + return 1;
  90302. +}
  90303. +
  90304. +void w_conn_id_status_change(void *p)
  90305. +{
  90306. + dwc_otg_core_if_t *core_if = p;
  90307. + uint32_t count = 0;
  90308. + gotgctl_data_t gotgctl = {.d32 = 0 };
  90309. +
  90310. + gotgctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  90311. + DWC_DEBUGPL(DBG_CIL, "gotgctl=%0x\n", gotgctl.d32);
  90312. + DWC_DEBUGPL(DBG_CIL, "gotgctl.b.conidsts=%d\n", gotgctl.b.conidsts);
  90313. +
  90314. + /* B-Device connector (Device Mode) */
  90315. + if (gotgctl.b.conidsts) {
  90316. + /* Wait for switch to device mode. */
  90317. + while (!dwc_otg_is_device_mode(core_if)) {
  90318. + DWC_PRINTF("Waiting for Peripheral Mode, Mode=%s\n",
  90319. + (dwc_otg_is_host_mode(core_if) ? "Host" :
  90320. + "Peripheral"));
  90321. + dwc_mdelay(100);
  90322. + if (++count > 10000)
  90323. + break;
  90324. + }
  90325. + DWC_ASSERT(++count < 10000,
  90326. + "Connection id status change timed out");
  90327. + core_if->op_state = B_PERIPHERAL;
  90328. + dwc_otg_core_init(core_if);
  90329. + dwc_otg_enable_global_interrupts(core_if);
  90330. + cil_pcd_start(core_if);
  90331. + } else {
  90332. + /* A-Device connector (Host Mode) */
  90333. + while (!dwc_otg_is_host_mode(core_if)) {
  90334. + DWC_PRINTF("Waiting for Host Mode, Mode=%s\n",
  90335. + (dwc_otg_is_host_mode(core_if) ? "Host" :
  90336. + "Peripheral"));
  90337. + dwc_mdelay(100);
  90338. + if (++count > 10000)
  90339. + break;
  90340. + }
  90341. + DWC_ASSERT(++count < 10000,
  90342. + "Connection id status change timed out");
  90343. + core_if->op_state = A_HOST;
  90344. + /*
  90345. + * Initialize the Core for Host mode.
  90346. + */
  90347. + dwc_otg_core_init(core_if);
  90348. + dwc_otg_enable_global_interrupts(core_if);
  90349. + cil_hcd_start(core_if);
  90350. + }
  90351. +}
  90352. +
  90353. +/**
  90354. + * This function handles the Connector ID Status Change Interrupt. It
  90355. + * reads the OTG Interrupt Register (GOTCTL) to determine whether this
  90356. + * is a Device to Host Mode transition or a Host Mode to Device
  90357. + * Transition.
  90358. + *
  90359. + * This only occurs when the cable is connected/removed from the PHY
  90360. + * connector.
  90361. + *
  90362. + * @param core_if Programming view of DWC_otg controller.
  90363. + */
  90364. +int32_t dwc_otg_handle_conn_id_status_change_intr(dwc_otg_core_if_t * core_if)
  90365. +{
  90366. +
  90367. + /*
  90368. + * Need to disable SOF interrupt immediately. If switching from device
  90369. + * to host, the PCD interrupt handler won't handle the interrupt if
  90370. + * host mode is already set. The HCD interrupt handler won't get
  90371. + * called if the HCD state is HALT. This means that the interrupt does
  90372. + * not get handled and Linux complains loudly.
  90373. + */
  90374. + gintmsk_data_t gintmsk = {.d32 = 0 };
  90375. + gintsts_data_t gintsts = {.d32 = 0 };
  90376. +
  90377. + gintmsk.b.sofintr = 1;
  90378. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, gintmsk.d32, 0);
  90379. +
  90380. + DWC_DEBUGPL(DBG_CIL,
  90381. + " ++Connector ID Status Change Interrupt++ (%s)\n",
  90382. + (dwc_otg_is_host_mode(core_if) ? "Host" : "Device"));
  90383. +
  90384. + DWC_SPINUNLOCK(core_if->lock);
  90385. +
  90386. + /*
  90387. + * Need to schedule a work, as there are possible DELAY function calls
  90388. + * Release lock before scheduling workq as it holds spinlock during scheduling
  90389. + */
  90390. +
  90391. + DWC_WORKQ_SCHEDULE(core_if->wq_otg, w_conn_id_status_change,
  90392. + core_if, "connection id status change");
  90393. + DWC_SPINLOCK(core_if->lock);
  90394. +
  90395. + /* Set flag and clear interrupt */
  90396. + gintsts.b.conidstschng = 1;
  90397. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  90398. +
  90399. + return 1;
  90400. +}
  90401. +
  90402. +/**
  90403. + * This interrupt indicates that a device is initiating the Session
  90404. + * Request Protocol to request the host to turn on bus power so a new
  90405. + * session can begin. The handler responds by turning on bus power. If
  90406. + * the DWC_otg controller is in low power mode, the handler brings the
  90407. + * controller out of low power mode before turning on bus power.
  90408. + *
  90409. + * @param core_if Programming view of DWC_otg controller.
  90410. + */
  90411. +int32_t dwc_otg_handle_session_req_intr(dwc_otg_core_if_t * core_if)
  90412. +{
  90413. + gintsts_data_t gintsts;
  90414. +
  90415. +#ifndef DWC_HOST_ONLY
  90416. + DWC_DEBUGPL(DBG_ANY, "++Session Request Interrupt++\n");
  90417. +
  90418. + if (dwc_otg_is_device_mode(core_if)) {
  90419. + DWC_PRINTF("SRP: Device mode\n");
  90420. + } else {
  90421. + hprt0_data_t hprt0;
  90422. + DWC_PRINTF("SRP: Host mode\n");
  90423. +
  90424. + /* Turn on the port power bit. */
  90425. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  90426. + hprt0.b.prtpwr = 1;
  90427. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  90428. +
  90429. + /* Start the Connection timer. So a message can be displayed
  90430. + * if connect does not occur within 10 seconds. */
  90431. + cil_hcd_session_start(core_if);
  90432. + }
  90433. +#endif
  90434. +
  90435. + /* Clear interrupt */
  90436. + gintsts.d32 = 0;
  90437. + gintsts.b.sessreqintr = 1;
  90438. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  90439. +
  90440. + return 1;
  90441. +}
  90442. +
  90443. +void w_wakeup_detected(void *p)
  90444. +{
  90445. + dwc_otg_core_if_t *core_if = (dwc_otg_core_if_t *) p;
  90446. + /*
  90447. + * Clear the Resume after 70ms. (Need 20 ms minimum. Use 70 ms
  90448. + * so that OPT tests pass with all PHYs).
  90449. + */
  90450. + hprt0_data_t hprt0 = {.d32 = 0 };
  90451. +#if 0
  90452. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  90453. + /* Restart the Phy Clock */
  90454. + pcgcctl.b.stoppclk = 1;
  90455. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  90456. + dwc_udelay(10);
  90457. +#endif //0
  90458. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  90459. + DWC_DEBUGPL(DBG_ANY, "Resume: HPRT0=%0x\n", hprt0.d32);
  90460. +// dwc_mdelay(70);
  90461. + hprt0.b.prtres = 0; /* Resume */
  90462. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  90463. + DWC_DEBUGPL(DBG_ANY, "Clear Resume: HPRT0=%0x\n",
  90464. + DWC_READ_REG32(core_if->host_if->hprt0));
  90465. +
  90466. + cil_hcd_resume(core_if);
  90467. +
  90468. + /** Change to L0 state*/
  90469. + core_if->lx_state = DWC_OTG_L0;
  90470. +}
  90471. +
  90472. +/**
  90473. + * This interrupt indicates that the DWC_otg controller has detected a
  90474. + * resume or remote wakeup sequence. If the DWC_otg controller is in
  90475. + * low power mode, the handler must brings the controller out of low
  90476. + * power mode. The controller automatically begins resume
  90477. + * signaling. The handler schedules a time to stop resume signaling.
  90478. + */
  90479. +int32_t dwc_otg_handle_wakeup_detected_intr(dwc_otg_core_if_t * core_if)
  90480. +{
  90481. + gintsts_data_t gintsts;
  90482. +
  90483. + DWC_DEBUGPL(DBG_ANY,
  90484. + "++Resume and Remote Wakeup Detected Interrupt++\n");
  90485. +
  90486. + DWC_PRINTF("%s lxstate = %d\n", __func__, core_if->lx_state);
  90487. +
  90488. + if (dwc_otg_is_device_mode(core_if)) {
  90489. + dctl_data_t dctl = {.d32 = 0 };
  90490. + DWC_DEBUGPL(DBG_PCD, "DSTS=0x%0x\n",
  90491. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->
  90492. + dsts));
  90493. + if (core_if->lx_state == DWC_OTG_L2) {
  90494. +#ifdef PARTIAL_POWER_DOWN
  90495. + if (core_if->hwcfg4.b.power_optimiz) {
  90496. + pcgcctl_data_t power = {.d32 = 0 };
  90497. +
  90498. + power.d32 = DWC_READ_REG32(core_if->pcgcctl);
  90499. + DWC_DEBUGPL(DBG_CIL, "PCGCCTL=%0x\n",
  90500. + power.d32);
  90501. +
  90502. + power.b.stoppclk = 0;
  90503. + DWC_WRITE_REG32(core_if->pcgcctl, power.d32);
  90504. +
  90505. + power.b.pwrclmp = 0;
  90506. + DWC_WRITE_REG32(core_if->pcgcctl, power.d32);
  90507. +
  90508. + power.b.rstpdwnmodule = 0;
  90509. + DWC_WRITE_REG32(core_if->pcgcctl, power.d32);
  90510. + }
  90511. +#endif
  90512. + /* Clear the Remote Wakeup Signaling */
  90513. + dctl.b.rmtwkupsig = 1;
  90514. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  90515. + dctl, dctl.d32, 0);
  90516. +
  90517. + DWC_SPINUNLOCK(core_if->lock);
  90518. + if (core_if->pcd_cb && core_if->pcd_cb->resume_wakeup) {
  90519. + core_if->pcd_cb->resume_wakeup(core_if->pcd_cb->p);
  90520. + }
  90521. + DWC_SPINLOCK(core_if->lock);
  90522. + } else {
  90523. + glpmcfg_data_t lpmcfg;
  90524. + lpmcfg.d32 =
  90525. + DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  90526. + lpmcfg.b.hird_thres &= (~(1 << 4));
  90527. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg,
  90528. + lpmcfg.d32);
  90529. + }
  90530. + /** Change to L0 state*/
  90531. + core_if->lx_state = DWC_OTG_L0;
  90532. + } else {
  90533. + if (core_if->lx_state != DWC_OTG_L1) {
  90534. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  90535. +
  90536. + /* Restart the Phy Clock */
  90537. + pcgcctl.b.stoppclk = 1;
  90538. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  90539. + DWC_TIMER_SCHEDULE(core_if->wkp_timer, 71);
  90540. + } else {
  90541. + /** Change to L0 state*/
  90542. + core_if->lx_state = DWC_OTG_L0;
  90543. + }
  90544. + }
  90545. +
  90546. + /* Clear interrupt */
  90547. + gintsts.d32 = 0;
  90548. + gintsts.b.wkupintr = 1;
  90549. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  90550. +
  90551. + return 1;
  90552. +}
  90553. +
  90554. +/**
  90555. + * This interrupt indicates that the Wakeup Logic has detected a
  90556. + * Device disconnect.
  90557. + */
  90558. +static int32_t dwc_otg_handle_pwrdn_disconnect_intr(dwc_otg_core_if_t *core_if)
  90559. +{
  90560. + gpwrdn_data_t gpwrdn = { .d32 = 0 };
  90561. + gpwrdn_data_t gpwrdn_temp = { .d32 = 0 };
  90562. + gpwrdn_temp.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  90563. +
  90564. + DWC_PRINTF("%s called\n", __FUNCTION__);
  90565. +
  90566. + if (!core_if->hibernation_suspend) {
  90567. + DWC_PRINTF("Already exited from Hibernation\n");
  90568. + return 1;
  90569. + }
  90570. +
  90571. + /* Switch on the voltage to the core */
  90572. + gpwrdn.b.pwrdnswtch = 1;
  90573. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  90574. + dwc_udelay(10);
  90575. +
  90576. + /* Reset the core */
  90577. + gpwrdn.d32 = 0;
  90578. + gpwrdn.b.pwrdnrstn = 1;
  90579. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  90580. + dwc_udelay(10);
  90581. +
  90582. + /* Disable power clamps*/
  90583. + gpwrdn.d32 = 0;
  90584. + gpwrdn.b.pwrdnclmp = 1;
  90585. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  90586. +
  90587. + /* Remove reset the core signal */
  90588. + gpwrdn.d32 = 0;
  90589. + gpwrdn.b.pwrdnrstn = 1;
  90590. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  90591. + dwc_udelay(10);
  90592. +
  90593. + /* Disable PMU interrupt */
  90594. + gpwrdn.d32 = 0;
  90595. + gpwrdn.b.pmuintsel = 1;
  90596. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  90597. +
  90598. + core_if->hibernation_suspend = 0;
  90599. +
  90600. + /* Disable PMU */
  90601. + gpwrdn.d32 = 0;
  90602. + gpwrdn.b.pmuactv = 1;
  90603. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  90604. + dwc_udelay(10);
  90605. +
  90606. + if (gpwrdn_temp.b.idsts) {
  90607. + core_if->op_state = B_PERIPHERAL;
  90608. + dwc_otg_core_init(core_if);
  90609. + dwc_otg_enable_global_interrupts(core_if);
  90610. + cil_pcd_start(core_if);
  90611. + } else {
  90612. + core_if->op_state = A_HOST;
  90613. + dwc_otg_core_init(core_if);
  90614. + dwc_otg_enable_global_interrupts(core_if);
  90615. + cil_hcd_start(core_if);
  90616. + }
  90617. +
  90618. + return 1;
  90619. +}
  90620. +
  90621. +/**
  90622. + * This interrupt indicates that the Wakeup Logic has detected a
  90623. + * remote wakeup sequence.
  90624. + */
  90625. +static int32_t dwc_otg_handle_pwrdn_wakeup_detected_intr(dwc_otg_core_if_t * core_if)
  90626. +{
  90627. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  90628. + DWC_DEBUGPL(DBG_ANY,
  90629. + "++Powerdown Remote Wakeup Detected Interrupt++\n");
  90630. +
  90631. + if (!core_if->hibernation_suspend) {
  90632. + DWC_PRINTF("Already exited from Hibernation\n");
  90633. + return 1;
  90634. + }
  90635. +
  90636. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  90637. + if (gpwrdn.b.idsts) { // Device Mode
  90638. + if ((core_if->power_down == 2)
  90639. + && (core_if->hibernation_suspend == 1)) {
  90640. + dwc_otg_device_hibernation_restore(core_if, 0, 0);
  90641. + }
  90642. + } else {
  90643. + if ((core_if->power_down == 2)
  90644. + && (core_if->hibernation_suspend == 1)) {
  90645. + dwc_otg_host_hibernation_restore(core_if, 1, 0);
  90646. + }
  90647. + }
  90648. + return 1;
  90649. +}
  90650. +
  90651. +static int32_t dwc_otg_handle_pwrdn_idsts_change(dwc_otg_device_t *otg_dev)
  90652. +{
  90653. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  90654. + gpwrdn_data_t gpwrdn_temp = {.d32 = 0 };
  90655. + dwc_otg_core_if_t *core_if = otg_dev->core_if;
  90656. +
  90657. + DWC_DEBUGPL(DBG_ANY, "%s called\n", __FUNCTION__);
  90658. + gpwrdn_temp.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  90659. + if (core_if->power_down == 2) {
  90660. + if (!core_if->hibernation_suspend) {
  90661. + DWC_PRINTF("Already exited from Hibernation\n");
  90662. + return 1;
  90663. + }
  90664. + DWC_DEBUGPL(DBG_ANY, "Exit from hibernation on ID sts change\n");
  90665. + /* Switch on the voltage to the core */
  90666. + gpwrdn.b.pwrdnswtch = 1;
  90667. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  90668. + dwc_udelay(10);
  90669. +
  90670. + /* Reset the core */
  90671. + gpwrdn.d32 = 0;
  90672. + gpwrdn.b.pwrdnrstn = 1;
  90673. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  90674. + dwc_udelay(10);
  90675. +
  90676. + /* Disable power clamps */
  90677. + gpwrdn.d32 = 0;
  90678. + gpwrdn.b.pwrdnclmp = 1;
  90679. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  90680. +
  90681. + /* Remove reset the core signal */
  90682. + gpwrdn.d32 = 0;
  90683. + gpwrdn.b.pwrdnrstn = 1;
  90684. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  90685. + dwc_udelay(10);
  90686. +
  90687. + /* Disable PMU interrupt */
  90688. + gpwrdn.d32 = 0;
  90689. + gpwrdn.b.pmuintsel = 1;
  90690. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  90691. +
  90692. + /*Indicates that we are exiting from hibernation */
  90693. + core_if->hibernation_suspend = 0;
  90694. +
  90695. + /* Disable PMU */
  90696. + gpwrdn.d32 = 0;
  90697. + gpwrdn.b.pmuactv = 1;
  90698. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  90699. + dwc_udelay(10);
  90700. +
  90701. + gpwrdn.d32 = core_if->gr_backup->gpwrdn_local;
  90702. + if (gpwrdn.b.dis_vbus == 1) {
  90703. + gpwrdn.d32 = 0;
  90704. + gpwrdn.b.dis_vbus = 1;
  90705. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  90706. + }
  90707. +
  90708. + if (gpwrdn_temp.b.idsts) {
  90709. + core_if->op_state = B_PERIPHERAL;
  90710. + dwc_otg_core_init(core_if);
  90711. + dwc_otg_enable_global_interrupts(core_if);
  90712. + cil_pcd_start(core_if);
  90713. + } else {
  90714. + core_if->op_state = A_HOST;
  90715. + dwc_otg_core_init(core_if);
  90716. + dwc_otg_enable_global_interrupts(core_if);
  90717. + cil_hcd_start(core_if);
  90718. + }
  90719. + }
  90720. +
  90721. + if (core_if->adp_enable) {
  90722. + uint8_t is_host = 0;
  90723. + DWC_SPINUNLOCK(core_if->lock);
  90724. + /* Change the core_if's lock to hcd/pcd lock depend on mode? */
  90725. +#ifndef DWC_HOST_ONLY
  90726. + if (gpwrdn_temp.b.idsts)
  90727. + core_if->lock = otg_dev->pcd->lock;
  90728. +#endif
  90729. +#ifndef DWC_DEVICE_ONLY
  90730. + if (!gpwrdn_temp.b.idsts) {
  90731. + core_if->lock = otg_dev->hcd->lock;
  90732. + is_host = 1;
  90733. + }
  90734. +#endif
  90735. + DWC_PRINTF("RESTART ADP\n");
  90736. + if (core_if->adp.probe_enabled)
  90737. + dwc_otg_adp_probe_stop(core_if);
  90738. + if (core_if->adp.sense_enabled)
  90739. + dwc_otg_adp_sense_stop(core_if);
  90740. + if (core_if->adp.sense_timer_started)
  90741. + DWC_TIMER_CANCEL(core_if->adp.sense_timer);
  90742. + if (core_if->adp.vbuson_timer_started)
  90743. + DWC_TIMER_CANCEL(core_if->adp.vbuson_timer);
  90744. + core_if->adp.probe_timer_values[0] = -1;
  90745. + core_if->adp.probe_timer_values[1] = -1;
  90746. + core_if->adp.sense_timer_started = 0;
  90747. + core_if->adp.vbuson_timer_started = 0;
  90748. + core_if->adp.probe_counter = 0;
  90749. + core_if->adp.gpwrdn = 0;
  90750. +
  90751. + /* Disable PMU and restart ADP */
  90752. + gpwrdn_temp.d32 = 0;
  90753. + gpwrdn_temp.b.pmuactv = 1;
  90754. + gpwrdn_temp.b.pmuintsel = 1;
  90755. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  90756. + DWC_PRINTF("Check point 1\n");
  90757. + dwc_mdelay(110);
  90758. + dwc_otg_adp_start(core_if, is_host);
  90759. + DWC_SPINLOCK(core_if->lock);
  90760. + }
  90761. +
  90762. +
  90763. + return 1;
  90764. +}
  90765. +
  90766. +static int32_t dwc_otg_handle_pwrdn_session_change(dwc_otg_core_if_t * core_if)
  90767. +{
  90768. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  90769. + int32_t otg_cap_param = core_if->core_params->otg_cap;
  90770. + DWC_DEBUGPL(DBG_ANY, "%s called\n", __FUNCTION__);
  90771. +
  90772. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  90773. + if (core_if->power_down == 2) {
  90774. + if (!core_if->hibernation_suspend) {
  90775. + DWC_PRINTF("Already exited from Hibernation\n");
  90776. + return 1;
  90777. + }
  90778. +
  90779. + if ((otg_cap_param != DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE ||
  90780. + otg_cap_param != DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE) &&
  90781. + gpwrdn.b.bsessvld == 0) {
  90782. + /* Save gpwrdn register for further usage if stschng interrupt */
  90783. + core_if->gr_backup->gpwrdn_local =
  90784. + DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  90785. + /*Exit from ISR and wait for stschng interrupt with bsessvld = 1 */
  90786. + return 1;
  90787. + }
  90788. +
  90789. + /* Switch on the voltage to the core */
  90790. + gpwrdn.d32 = 0;
  90791. + gpwrdn.b.pwrdnswtch = 1;
  90792. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  90793. + dwc_udelay(10);
  90794. +
  90795. + /* Reset the core */
  90796. + gpwrdn.d32 = 0;
  90797. + gpwrdn.b.pwrdnrstn = 1;
  90798. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  90799. + dwc_udelay(10);
  90800. +
  90801. + /* Disable power clamps */
  90802. + gpwrdn.d32 = 0;
  90803. + gpwrdn.b.pwrdnclmp = 1;
  90804. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  90805. +
  90806. + /* Remove reset the core signal */
  90807. + gpwrdn.d32 = 0;
  90808. + gpwrdn.b.pwrdnrstn = 1;
  90809. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  90810. + dwc_udelay(10);
  90811. +
  90812. + /* Disable PMU interrupt */
  90813. + gpwrdn.d32 = 0;
  90814. + gpwrdn.b.pmuintsel = 1;
  90815. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  90816. + dwc_udelay(10);
  90817. +
  90818. + /*Indicates that we are exiting from hibernation */
  90819. + core_if->hibernation_suspend = 0;
  90820. +
  90821. + /* Disable PMU */
  90822. + gpwrdn.d32 = 0;
  90823. + gpwrdn.b.pmuactv = 1;
  90824. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  90825. + dwc_udelay(10);
  90826. +
  90827. + core_if->op_state = B_PERIPHERAL;
  90828. + dwc_otg_core_init(core_if);
  90829. + dwc_otg_enable_global_interrupts(core_if);
  90830. + cil_pcd_start(core_if);
  90831. +
  90832. + if (otg_cap_param == DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE ||
  90833. + otg_cap_param == DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE) {
  90834. + /*
  90835. + * Initiate SRP after initial ADP probe.
  90836. + */
  90837. + dwc_otg_initiate_srp(core_if);
  90838. + }
  90839. + }
  90840. +
  90841. + return 1;
  90842. +}
  90843. +/**
  90844. + * This interrupt indicates that the Wakeup Logic has detected a
  90845. + * status change either on IDDIG or BSessVld.
  90846. + */
  90847. +static uint32_t dwc_otg_handle_pwrdn_stschng_intr(dwc_otg_device_t *otg_dev)
  90848. +{
  90849. + int retval;
  90850. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  90851. + gpwrdn_data_t gpwrdn_temp = {.d32 = 0 };
  90852. + dwc_otg_core_if_t *core_if = otg_dev->core_if;
  90853. +
  90854. + DWC_PRINTF("%s called\n", __FUNCTION__);
  90855. +
  90856. + if (core_if->power_down == 2) {
  90857. + if (core_if->hibernation_suspend <= 0) {
  90858. + DWC_PRINTF("Already exited from Hibernation\n");
  90859. + return 1;
  90860. + } else
  90861. + gpwrdn_temp.d32 = core_if->gr_backup->gpwrdn_local;
  90862. +
  90863. + } else {
  90864. + gpwrdn_temp.d32 = core_if->adp.gpwrdn;
  90865. + }
  90866. +
  90867. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  90868. +
  90869. + if (gpwrdn.b.idsts ^ gpwrdn_temp.b.idsts) {
  90870. + retval = dwc_otg_handle_pwrdn_idsts_change(otg_dev);
  90871. + } else if (gpwrdn.b.bsessvld ^ gpwrdn_temp.b.bsessvld) {
  90872. + retval = dwc_otg_handle_pwrdn_session_change(core_if);
  90873. + }
  90874. +
  90875. + return retval;
  90876. +}
  90877. +
  90878. +/**
  90879. + * This interrupt indicates that the Wakeup Logic has detected a
  90880. + * SRP.
  90881. + */
  90882. +static int32_t dwc_otg_handle_pwrdn_srp_intr(dwc_otg_core_if_t * core_if)
  90883. +{
  90884. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  90885. +
  90886. + DWC_PRINTF("%s called\n", __FUNCTION__);
  90887. +
  90888. + if (!core_if->hibernation_suspend) {
  90889. + DWC_PRINTF("Already exited from Hibernation\n");
  90890. + return 1;
  90891. + }
  90892. +#ifdef DWC_DEV_SRPCAP
  90893. + if (core_if->pwron_timer_started) {
  90894. + core_if->pwron_timer_started = 0;
  90895. + DWC_TIMER_CANCEL(core_if->pwron_timer);
  90896. + }
  90897. +#endif
  90898. +
  90899. + /* Switch on the voltage to the core */
  90900. + gpwrdn.b.pwrdnswtch = 1;
  90901. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  90902. + dwc_udelay(10);
  90903. +
  90904. + /* Reset the core */
  90905. + gpwrdn.d32 = 0;
  90906. + gpwrdn.b.pwrdnrstn = 1;
  90907. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  90908. + dwc_udelay(10);
  90909. +
  90910. + /* Disable power clamps */
  90911. + gpwrdn.d32 = 0;
  90912. + gpwrdn.b.pwrdnclmp = 1;
  90913. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  90914. +
  90915. + /* Remove reset the core signal */
  90916. + gpwrdn.d32 = 0;
  90917. + gpwrdn.b.pwrdnrstn = 1;
  90918. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  90919. + dwc_udelay(10);
  90920. +
  90921. + /* Disable PMU interrupt */
  90922. + gpwrdn.d32 = 0;
  90923. + gpwrdn.b.pmuintsel = 1;
  90924. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  90925. +
  90926. + /* Indicates that we are exiting from hibernation */
  90927. + core_if->hibernation_suspend = 0;
  90928. +
  90929. + /* Disable PMU */
  90930. + gpwrdn.d32 = 0;
  90931. + gpwrdn.b.pmuactv = 1;
  90932. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  90933. + dwc_udelay(10);
  90934. +
  90935. + /* Programm Disable VBUS to 0 */
  90936. + gpwrdn.d32 = 0;
  90937. + gpwrdn.b.dis_vbus = 1;
  90938. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  90939. +
  90940. + /*Initialize the core as Host */
  90941. + core_if->op_state = A_HOST;
  90942. + dwc_otg_core_init(core_if);
  90943. + dwc_otg_enable_global_interrupts(core_if);
  90944. + cil_hcd_start(core_if);
  90945. +
  90946. + return 1;
  90947. +}
  90948. +
  90949. +/** This interrupt indicates that restore command after Hibernation
  90950. + * was completed by the core. */
  90951. +int32_t dwc_otg_handle_restore_done_intr(dwc_otg_core_if_t * core_if)
  90952. +{
  90953. + pcgcctl_data_t pcgcctl;
  90954. + DWC_DEBUGPL(DBG_ANY, "++Restore Done Interrupt++\n");
  90955. +
  90956. + //TODO De-assert restore signal. 8.a
  90957. + pcgcctl.d32 = DWC_READ_REG32(core_if->pcgcctl);
  90958. + if (pcgcctl.b.restoremode == 1) {
  90959. + gintmsk_data_t gintmsk = {.d32 = 0 };
  90960. + /*
  90961. + * If restore mode is Remote Wakeup,
  90962. + * unmask Remote Wakeup interrupt.
  90963. + */
  90964. + gintmsk.b.wkupintr = 1;
  90965. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk,
  90966. + 0, gintmsk.d32);
  90967. + }
  90968. +
  90969. + return 1;
  90970. +}
  90971. +
  90972. +/**
  90973. + * This interrupt indicates that a device has been disconnected from
  90974. + * the root port.
  90975. + */
  90976. +int32_t dwc_otg_handle_disconnect_intr(dwc_otg_core_if_t * core_if)
  90977. +{
  90978. + gintsts_data_t gintsts;
  90979. +
  90980. + DWC_DEBUGPL(DBG_ANY, "++Disconnect Detected Interrupt++ (%s) %s\n",
  90981. + (dwc_otg_is_host_mode(core_if) ? "Host" : "Device"),
  90982. + op_state_str(core_if));
  90983. +
  90984. +/** @todo Consolidate this if statement. */
  90985. +#ifndef DWC_HOST_ONLY
  90986. + if (core_if->op_state == B_HOST) {
  90987. + /* If in device mode Disconnect and stop the HCD, then
  90988. + * start the PCD. */
  90989. + DWC_SPINUNLOCK(core_if->lock);
  90990. + cil_hcd_disconnect(core_if);
  90991. + cil_pcd_start(core_if);
  90992. + DWC_SPINLOCK(core_if->lock);
  90993. + core_if->op_state = B_PERIPHERAL;
  90994. + } else if (dwc_otg_is_device_mode(core_if)) {
  90995. + gotgctl_data_t gotgctl = {.d32 = 0 };
  90996. + gotgctl.d32 =
  90997. + DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  90998. + if (gotgctl.b.hstsethnpen == 1) {
  90999. + /* Do nothing, if HNP in process the OTG
  91000. + * interrupt "Host Negotiation Detected"
  91001. + * interrupt will do the mode switch.
  91002. + */
  91003. + } else if (gotgctl.b.devhnpen == 0) {
  91004. + /* If in device mode Disconnect and stop the HCD, then
  91005. + * start the PCD. */
  91006. + DWC_SPINUNLOCK(core_if->lock);
  91007. + cil_hcd_disconnect(core_if);
  91008. + cil_pcd_start(core_if);
  91009. + DWC_SPINLOCK(core_if->lock);
  91010. + core_if->op_state = B_PERIPHERAL;
  91011. + } else {
  91012. + DWC_DEBUGPL(DBG_ANY, "!a_peripheral && !devhnpen\n");
  91013. + }
  91014. + } else {
  91015. + if (core_if->op_state == A_HOST) {
  91016. + /* A-Cable still connected but device disconnected. */
  91017. + cil_hcd_disconnect(core_if);
  91018. + if (core_if->adp_enable) {
  91019. + gpwrdn_data_t gpwrdn = { .d32 = 0 };
  91020. + cil_hcd_stop(core_if);
  91021. + /* Enable Power Down Logic */
  91022. + gpwrdn.b.pmuintsel = 1;
  91023. + gpwrdn.b.pmuactv = 1;
  91024. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  91025. + gpwrdn, 0, gpwrdn.d32);
  91026. + dwc_otg_adp_probe_start(core_if);
  91027. +
  91028. + /* Power off the core */
  91029. + if (core_if->power_down == 2) {
  91030. + gpwrdn.d32 = 0;
  91031. + gpwrdn.b.pwrdnswtch = 1;
  91032. + DWC_MODIFY_REG32
  91033. + (&core_if->core_global_regs->gpwrdn,
  91034. + gpwrdn.d32, 0);
  91035. + }
  91036. + }
  91037. + }
  91038. + }
  91039. +#endif
  91040. + /* Change to L3(OFF) state */
  91041. + core_if->lx_state = DWC_OTG_L3;
  91042. +
  91043. + gintsts.d32 = 0;
  91044. + gintsts.b.disconnect = 1;
  91045. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  91046. + return 1;
  91047. +}
  91048. +
  91049. +/**
  91050. + * This interrupt indicates that SUSPEND state has been detected on
  91051. + * the USB.
  91052. + *
  91053. + * For HNP the USB Suspend interrupt signals the change from
  91054. + * "a_peripheral" to "a_host".
  91055. + *
  91056. + * When power management is enabled the core will be put in low power
  91057. + * mode.
  91058. + */
  91059. +int32_t dwc_otg_handle_usb_suspend_intr(dwc_otg_core_if_t * core_if)
  91060. +{
  91061. + dsts_data_t dsts;
  91062. + gintsts_data_t gintsts;
  91063. + dcfg_data_t dcfg;
  91064. +
  91065. + DWC_DEBUGPL(DBG_ANY, "USB SUSPEND\n");
  91066. +
  91067. + if (dwc_otg_is_device_mode(core_if)) {
  91068. + /* Check the Device status register to determine if the Suspend
  91069. + * state is active. */
  91070. + dsts.d32 =
  91071. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  91072. + DWC_DEBUGPL(DBG_PCD, "DSTS=0x%0x\n", dsts.d32);
  91073. + DWC_DEBUGPL(DBG_PCD, "DSTS.Suspend Status=%d "
  91074. + "HWCFG4.power Optimize=%d\n",
  91075. + dsts.b.suspsts, core_if->hwcfg4.b.power_optimiz);
  91076. +
  91077. +#ifdef PARTIAL_POWER_DOWN
  91078. +/** @todo Add a module parameter for power management. */
  91079. +
  91080. + if (dsts.b.suspsts && core_if->hwcfg4.b.power_optimiz) {
  91081. + pcgcctl_data_t power = {.d32 = 0 };
  91082. + DWC_DEBUGPL(DBG_CIL, "suspend\n");
  91083. +
  91084. + power.b.pwrclmp = 1;
  91085. + DWC_WRITE_REG32(core_if->pcgcctl, power.d32);
  91086. +
  91087. + power.b.rstpdwnmodule = 1;
  91088. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, power.d32);
  91089. +
  91090. + power.b.stoppclk = 1;
  91091. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, power.d32);
  91092. +
  91093. + } else {
  91094. + DWC_DEBUGPL(DBG_ANY, "disconnect?\n");
  91095. + }
  91096. +#endif
  91097. + /* PCD callback for suspend. Release the lock inside of callback function */
  91098. + cil_pcd_suspend(core_if);
  91099. + if (core_if->power_down == 2)
  91100. + {
  91101. + dcfg.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  91102. + DWC_DEBUGPL(DBG_ANY,"lx_state = %08x\n",core_if->lx_state);
  91103. + DWC_DEBUGPL(DBG_ANY," device address = %08d\n",dcfg.b.devaddr);
  91104. +
  91105. + if (core_if->lx_state != DWC_OTG_L3 && dcfg.b.devaddr) {
  91106. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  91107. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  91108. + gusbcfg_data_t gusbcfg = {.d32 = 0 };
  91109. +
  91110. + /* Change to L2(suspend) state */
  91111. + core_if->lx_state = DWC_OTG_L2;
  91112. +
  91113. + /* Clear interrupt in gintsts */
  91114. + gintsts.d32 = 0;
  91115. + gintsts.b.usbsuspend = 1;
  91116. + DWC_WRITE_REG32(&core_if->core_global_regs->
  91117. + gintsts, gintsts.d32);
  91118. + DWC_PRINTF("Start of hibernation completed\n");
  91119. + dwc_otg_save_global_regs(core_if);
  91120. + dwc_otg_save_dev_regs(core_if);
  91121. +
  91122. + gusbcfg.d32 =
  91123. + DWC_READ_REG32(&core_if->core_global_regs->
  91124. + gusbcfg);
  91125. + if (gusbcfg.b.ulpi_utmi_sel == 1) {
  91126. + /* ULPI interface */
  91127. + /* Suspend the Phy Clock */
  91128. + pcgcctl.d32 = 0;
  91129. + pcgcctl.b.stoppclk = 1;
  91130. + DWC_MODIFY_REG32(core_if->pcgcctl, 0,
  91131. + pcgcctl.d32);
  91132. + dwc_udelay(10);
  91133. + gpwrdn.b.pmuactv = 1;
  91134. + DWC_MODIFY_REG32(&core_if->
  91135. + core_global_regs->
  91136. + gpwrdn, 0, gpwrdn.d32);
  91137. + } else {
  91138. + /* UTMI+ Interface */
  91139. + gpwrdn.b.pmuactv = 1;
  91140. + DWC_MODIFY_REG32(&core_if->
  91141. + core_global_regs->
  91142. + gpwrdn, 0, gpwrdn.d32);
  91143. + dwc_udelay(10);
  91144. + pcgcctl.b.stoppclk = 1;
  91145. + DWC_MODIFY_REG32(core_if->pcgcctl, 0,
  91146. + pcgcctl.d32);
  91147. + dwc_udelay(10);
  91148. + }
  91149. +
  91150. + /* Set flag to indicate that we are in hibernation */
  91151. + core_if->hibernation_suspend = 1;
  91152. + /* Enable interrupts from wake up logic */
  91153. + gpwrdn.d32 = 0;
  91154. + gpwrdn.b.pmuintsel = 1;
  91155. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  91156. + gpwrdn, 0, gpwrdn.d32);
  91157. + dwc_udelay(10);
  91158. +
  91159. + /* Unmask device mode interrupts in GPWRDN */
  91160. + gpwrdn.d32 = 0;
  91161. + gpwrdn.b.rst_det_msk = 1;
  91162. + gpwrdn.b.lnstchng_msk = 1;
  91163. + gpwrdn.b.sts_chngint_msk = 1;
  91164. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  91165. + gpwrdn, 0, gpwrdn.d32);
  91166. + dwc_udelay(10);
  91167. +
  91168. + /* Enable Power Down Clamp */
  91169. + gpwrdn.d32 = 0;
  91170. + gpwrdn.b.pwrdnclmp = 1;
  91171. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  91172. + gpwrdn, 0, gpwrdn.d32);
  91173. + dwc_udelay(10);
  91174. +
  91175. + /* Switch off VDD */
  91176. + gpwrdn.d32 = 0;
  91177. + gpwrdn.b.pwrdnswtch = 1;
  91178. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  91179. + gpwrdn, 0, gpwrdn.d32);
  91180. +
  91181. + /* Save gpwrdn register for further usage if stschng interrupt */
  91182. + core_if->gr_backup->gpwrdn_local =
  91183. + DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  91184. + DWC_PRINTF("Hibernation completed\n");
  91185. +
  91186. + return 1;
  91187. + }
  91188. + } else if (core_if->power_down == 3) {
  91189. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  91190. + dcfg.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  91191. + DWC_DEBUGPL(DBG_ANY, "lx_state = %08x\n",core_if->lx_state);
  91192. + DWC_DEBUGPL(DBG_ANY, " device address = %08d\n",dcfg.b.devaddr);
  91193. +
  91194. + if (core_if->lx_state != DWC_OTG_L3 && dcfg.b.devaddr) {
  91195. + DWC_DEBUGPL(DBG_ANY, "Start entering to extended hibernation\n");
  91196. + core_if->xhib = 1;
  91197. +
  91198. + /* Clear interrupt in gintsts */
  91199. + gintsts.d32 = 0;
  91200. + gintsts.b.usbsuspend = 1;
  91201. + DWC_WRITE_REG32(&core_if->core_global_regs->
  91202. + gintsts, gintsts.d32);
  91203. +
  91204. + dwc_otg_save_global_regs(core_if);
  91205. + dwc_otg_save_dev_regs(core_if);
  91206. +
  91207. + /* Wait for 10 PHY clocks */
  91208. + dwc_udelay(10);
  91209. +
  91210. + /* Program GPIO register while entering to xHib */
  91211. + DWC_WRITE_REG32(&core_if->core_global_regs->ggpio, 0x1);
  91212. +
  91213. + pcgcctl.b.enbl_extnd_hiber = 1;
  91214. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, pcgcctl.d32);
  91215. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, pcgcctl.d32);
  91216. +
  91217. + pcgcctl.d32 = 0;
  91218. + pcgcctl.b.extnd_hiber_pwrclmp = 1;
  91219. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, pcgcctl.d32);
  91220. +
  91221. + pcgcctl.d32 = 0;
  91222. + pcgcctl.b.extnd_hiber_switch = 1;
  91223. + core_if->gr_backup->xhib_gpwrdn = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  91224. + core_if->gr_backup->xhib_pcgcctl = DWC_READ_REG32(core_if->pcgcctl) | pcgcctl.d32;
  91225. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, pcgcctl.d32);
  91226. +
  91227. + DWC_DEBUGPL(DBG_ANY, "Finished entering to extended hibernation\n");
  91228. +
  91229. + return 1;
  91230. + }
  91231. + }
  91232. + } else {
  91233. + if (core_if->op_state == A_PERIPHERAL) {
  91234. + DWC_DEBUGPL(DBG_ANY, "a_peripheral->a_host\n");
  91235. + /* Clear the a_peripheral flag, back to a_host. */
  91236. + DWC_SPINUNLOCK(core_if->lock);
  91237. + cil_pcd_stop(core_if);
  91238. + cil_hcd_start(core_if);
  91239. + DWC_SPINLOCK(core_if->lock);
  91240. + core_if->op_state = A_HOST;
  91241. + }
  91242. + }
  91243. +
  91244. + /* Change to L2(suspend) state */
  91245. + core_if->lx_state = DWC_OTG_L2;
  91246. +
  91247. + /* Clear interrupt */
  91248. + gintsts.d32 = 0;
  91249. + gintsts.b.usbsuspend = 1;
  91250. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  91251. +
  91252. + return 1;
  91253. +}
  91254. +
  91255. +static int32_t dwc_otg_handle_xhib_exit_intr(dwc_otg_core_if_t * core_if)
  91256. +{
  91257. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  91258. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  91259. + gahbcfg_data_t gahbcfg = {.d32 = 0 };
  91260. +
  91261. + dwc_udelay(10);
  91262. +
  91263. + /* Program GPIO register while entering to xHib */
  91264. + DWC_WRITE_REG32(&core_if->core_global_regs->ggpio, 0x0);
  91265. +
  91266. + pcgcctl.d32 = core_if->gr_backup->xhib_pcgcctl;
  91267. + pcgcctl.b.extnd_hiber_pwrclmp = 0;
  91268. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  91269. + dwc_udelay(10);
  91270. +
  91271. + gpwrdn.d32 = core_if->gr_backup->xhib_gpwrdn;
  91272. + gpwrdn.b.restore = 1;
  91273. + DWC_WRITE_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32);
  91274. + dwc_udelay(10);
  91275. +
  91276. + restore_lpm_i2c_regs(core_if);
  91277. +
  91278. + pcgcctl.d32 = core_if->gr_backup->pcgcctl_local & (0x3FFFF << 14);
  91279. + pcgcctl.b.max_xcvrselect = 1;
  91280. + pcgcctl.b.ess_reg_restored = 0;
  91281. + pcgcctl.b.extnd_hiber_switch = 0;
  91282. + pcgcctl.b.extnd_hiber_pwrclmp = 0;
  91283. + pcgcctl.b.enbl_extnd_hiber = 1;
  91284. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  91285. +
  91286. + gahbcfg.d32 = core_if->gr_backup->gahbcfg_local;
  91287. + gahbcfg.b.glblintrmsk = 1;
  91288. + DWC_WRITE_REG32(&core_if->core_global_regs->gahbcfg, gahbcfg.d32);
  91289. +
  91290. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  91291. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, 0x1 << 16);
  91292. +
  91293. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg,
  91294. + core_if->gr_backup->gusbcfg_local);
  91295. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg,
  91296. + core_if->dr_backup->dcfg);
  91297. +
  91298. + pcgcctl.d32 = 0;
  91299. + pcgcctl.d32 = core_if->gr_backup->pcgcctl_local & (0x3FFFF << 14);
  91300. + pcgcctl.b.max_xcvrselect = 1;
  91301. + pcgcctl.d32 |= 0x608;
  91302. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  91303. + dwc_udelay(10);
  91304. +
  91305. + pcgcctl.d32 = 0;
  91306. + pcgcctl.d32 = core_if->gr_backup->pcgcctl_local & (0x3FFFF << 14);
  91307. + pcgcctl.b.max_xcvrselect = 1;
  91308. + pcgcctl.b.ess_reg_restored = 1;
  91309. + pcgcctl.b.enbl_extnd_hiber = 1;
  91310. + pcgcctl.b.rstpdwnmodule = 1;
  91311. + pcgcctl.b.restoremode = 1;
  91312. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  91313. +
  91314. + DWC_DEBUGPL(DBG_ANY, "%s called\n", __FUNCTION__);
  91315. +
  91316. + return 1;
  91317. +}
  91318. +
  91319. +#ifdef CONFIG_USB_DWC_OTG_LPM
  91320. +/**
  91321. + * This function hadles LPM transaction received interrupt.
  91322. + */
  91323. +static int32_t dwc_otg_handle_lpm_intr(dwc_otg_core_if_t * core_if)
  91324. +{
  91325. + glpmcfg_data_t lpmcfg;
  91326. + gintsts_data_t gintsts;
  91327. +
  91328. + if (!core_if->core_params->lpm_enable) {
  91329. + DWC_PRINTF("Unexpected LPM interrupt\n");
  91330. + }
  91331. +
  91332. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  91333. + DWC_PRINTF("LPM config register = 0x%08x\n", lpmcfg.d32);
  91334. +
  91335. + if (dwc_otg_is_host_mode(core_if)) {
  91336. + cil_hcd_sleep(core_if);
  91337. + } else {
  91338. + lpmcfg.b.hird_thres |= (1 << 4);
  91339. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg,
  91340. + lpmcfg.d32);
  91341. + }
  91342. +
  91343. + /* Examine prt_sleep_sts after TL1TokenTetry period max (10 us) */
  91344. + dwc_udelay(10);
  91345. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  91346. + if (lpmcfg.b.prt_sleep_sts) {
  91347. + /* Save the current state */
  91348. + core_if->lx_state = DWC_OTG_L1;
  91349. + }
  91350. +
  91351. + /* Clear interrupt */
  91352. + gintsts.d32 = 0;
  91353. + gintsts.b.lpmtranrcvd = 1;
  91354. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  91355. + return 1;
  91356. +}
  91357. +#endif /* CONFIG_USB_DWC_OTG_LPM */
  91358. +
  91359. +/**
  91360. + * This function returns the Core Interrupt register.
  91361. + */
  91362. +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)
  91363. +{
  91364. + gahbcfg_data_t gahbcfg = {.d32 = 0 };
  91365. + gintsts_data_t gintsts;
  91366. + gintmsk_data_t gintmsk;
  91367. + gintmsk_data_t gintmsk_common = {.d32 = 0 };
  91368. + gintmsk_common.b.wkupintr = 1;
  91369. + gintmsk_common.b.sessreqintr = 1;
  91370. + gintmsk_common.b.conidstschng = 1;
  91371. + gintmsk_common.b.otgintr = 1;
  91372. + gintmsk_common.b.modemismatch = 1;
  91373. + gintmsk_common.b.disconnect = 1;
  91374. + gintmsk_common.b.usbsuspend = 1;
  91375. +#ifdef CONFIG_USB_DWC_OTG_LPM
  91376. + gintmsk_common.b.lpmtranrcvd = 1;
  91377. +#endif
  91378. + gintmsk_common.b.restoredone = 1;
  91379. + if(dwc_otg_is_device_mode(core_if))
  91380. + {
  91381. + /** @todo: The port interrupt occurs while in device
  91382. + * mode. Added code to CIL to clear the interrupt for now!
  91383. + */
  91384. + gintmsk_common.b.portintr = 1;
  91385. + }
  91386. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  91387. + gintmsk.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
  91388. + if(fiq_enable) {
  91389. + local_fiq_disable();
  91390. + /* Pull in the interrupts that the FIQ has masked */
  91391. + gintmsk.d32 |= ~(hcd->fiq_state->gintmsk_saved.d32);
  91392. + gintmsk.d32 |= gintmsk_common.d32;
  91393. + /* for the upstairs function to reenable - have to read it here in case FIQ triggers again */
  91394. + reenable_gintmsk->d32 = gintmsk.d32;
  91395. + local_fiq_enable();
  91396. + }
  91397. +
  91398. + gahbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gahbcfg);
  91399. +
  91400. +#ifdef DEBUG
  91401. + /* if any common interrupts set */
  91402. + if (gintsts.d32 & gintmsk_common.d32) {
  91403. + DWC_DEBUGPL(DBG_ANY, "common_intr: gintsts=%08x gintmsk=%08x\n",
  91404. + gintsts.d32, gintmsk.d32);
  91405. + }
  91406. +#endif
  91407. + if (!fiq_enable){
  91408. + if (gahbcfg.b.glblintrmsk)
  91409. + return ((gintsts.d32 & gintmsk.d32) & gintmsk_common.d32);
  91410. + else
  91411. + return 0;
  91412. + } else {
  91413. + /* Our IRQ kicker is no longer the USB hardware, it's the MPHI interface.
  91414. + * Can't trust the global interrupt mask bit in this case.
  91415. + */
  91416. + return ((gintsts.d32 & gintmsk.d32) & gintmsk_common.d32);
  91417. + }
  91418. +
  91419. +}
  91420. +
  91421. +/* MACRO for clearing interupt bits in GPWRDN register */
  91422. +#define CLEAR_GPWRDN_INTR(__core_if,__intr) \
  91423. +do { \
  91424. + gpwrdn_data_t gpwrdn = {.d32=0}; \
  91425. + gpwrdn.b.__intr = 1; \
  91426. + DWC_MODIFY_REG32(&__core_if->core_global_regs->gpwrdn, \
  91427. + 0, gpwrdn.d32); \
  91428. +} while (0)
  91429. +
  91430. +/**
  91431. + * Common interrupt handler.
  91432. + *
  91433. + * The common interrupts are those that occur in both Host and Device mode.
  91434. + * This handler handles the following interrupts:
  91435. + * - Mode Mismatch Interrupt
  91436. + * - Disconnect Interrupt
  91437. + * - OTG Interrupt
  91438. + * - Connector ID Status Change Interrupt
  91439. + * - Session Request Interrupt.
  91440. + * - Resume / Remote Wakeup Detected Interrupt.
  91441. + * - LPM Transaction Received Interrupt
  91442. + * - ADP Transaction Received Interrupt
  91443. + *
  91444. + */
  91445. +int32_t dwc_otg_handle_common_intr(void *dev)
  91446. +{
  91447. + int retval = 0;
  91448. + gintsts_data_t gintsts;
  91449. + gintmsk_data_t gintmsk_reenable = { .d32 = 0 };
  91450. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  91451. + dwc_otg_device_t *otg_dev = dev;
  91452. + dwc_otg_core_if_t *core_if = otg_dev->core_if;
  91453. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  91454. + if (dwc_otg_is_device_mode(core_if))
  91455. + core_if->frame_num = dwc_otg_get_frame_number(core_if);
  91456. +
  91457. + if (core_if->lock)
  91458. + DWC_SPINLOCK(core_if->lock);
  91459. +
  91460. + if (core_if->power_down == 3 && core_if->xhib == 1) {
  91461. + DWC_DEBUGPL(DBG_ANY, "Exiting from xHIB state\n");
  91462. + retval |= dwc_otg_handle_xhib_exit_intr(core_if);
  91463. + core_if->xhib = 2;
  91464. + if (core_if->lock)
  91465. + DWC_SPINUNLOCK(core_if->lock);
  91466. +
  91467. + return retval;
  91468. + }
  91469. +
  91470. + if (core_if->hibernation_suspend <= 0) {
  91471. + /* read_common will have to poke the FIQ's saved mask. We must then clear this mask at the end
  91472. + * of this handler - god only knows why it's done like this
  91473. + */
  91474. + gintsts.d32 = dwc_otg_read_common_intr(core_if, &gintmsk_reenable, otg_dev->hcd);
  91475. +
  91476. + if (gintsts.b.modemismatch) {
  91477. + retval |= dwc_otg_handle_mode_mismatch_intr(core_if);
  91478. + }
  91479. + if (gintsts.b.otgintr) {
  91480. + retval |= dwc_otg_handle_otg_intr(core_if);
  91481. + }
  91482. + if (gintsts.b.conidstschng) {
  91483. + retval |=
  91484. + dwc_otg_handle_conn_id_status_change_intr(core_if);
  91485. + }
  91486. + if (gintsts.b.disconnect) {
  91487. + retval |= dwc_otg_handle_disconnect_intr(core_if);
  91488. + }
  91489. + if (gintsts.b.sessreqintr) {
  91490. + retval |= dwc_otg_handle_session_req_intr(core_if);
  91491. + }
  91492. + if (gintsts.b.wkupintr) {
  91493. + retval |= dwc_otg_handle_wakeup_detected_intr(core_if);
  91494. + }
  91495. + if (gintsts.b.usbsuspend) {
  91496. + retval |= dwc_otg_handle_usb_suspend_intr(core_if);
  91497. + }
  91498. +#ifdef CONFIG_USB_DWC_OTG_LPM
  91499. + if (gintsts.b.lpmtranrcvd) {
  91500. + retval |= dwc_otg_handle_lpm_intr(core_if);
  91501. + }
  91502. +#endif
  91503. + if (gintsts.b.restoredone) {
  91504. + gintsts.d32 = 0;
  91505. + if (core_if->power_down == 2)
  91506. + core_if->hibernation_suspend = -1;
  91507. + else if (core_if->power_down == 3 && core_if->xhib == 2) {
  91508. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  91509. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  91510. + dctl_data_t dctl = {.d32 = 0 };
  91511. +
  91512. + DWC_WRITE_REG32(&core_if->core_global_regs->
  91513. + gintsts, 0xFFFFFFFF);
  91514. +
  91515. + DWC_DEBUGPL(DBG_ANY,
  91516. + "RESTORE DONE generated\n");
  91517. +
  91518. + gpwrdn.b.restore = 1;
  91519. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  91520. + dwc_udelay(10);
  91521. +
  91522. + pcgcctl.b.rstpdwnmodule = 1;
  91523. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  91524. +
  91525. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, core_if->gr_backup->gusbcfg_local);
  91526. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg, core_if->dr_backup->dcfg);
  91527. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl, core_if->dr_backup->dctl);
  91528. + dwc_udelay(50);
  91529. +
  91530. + dctl.b.pwronprgdone = 1;
  91531. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0, dctl.d32);
  91532. + dwc_udelay(10);
  91533. +
  91534. + dwc_otg_restore_global_regs(core_if);
  91535. + dwc_otg_restore_dev_regs(core_if, 0);
  91536. +
  91537. + dctl.d32 = 0;
  91538. + dctl.b.pwronprgdone = 1;
  91539. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32, 0);
  91540. + dwc_udelay(10);
  91541. +
  91542. + pcgcctl.d32 = 0;
  91543. + pcgcctl.b.enbl_extnd_hiber = 1;
  91544. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  91545. +
  91546. + /* The core will be in ON STATE */
  91547. + core_if->lx_state = DWC_OTG_L0;
  91548. + core_if->xhib = 0;
  91549. +
  91550. + DWC_SPINUNLOCK(core_if->lock);
  91551. + if (core_if->pcd_cb && core_if->pcd_cb->resume_wakeup) {
  91552. + core_if->pcd_cb->resume_wakeup(core_if->pcd_cb->p);
  91553. + }
  91554. + DWC_SPINLOCK(core_if->lock);
  91555. +
  91556. + }
  91557. +
  91558. + gintsts.b.restoredone = 1;
  91559. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts,gintsts.d32);
  91560. + DWC_PRINTF(" --Restore done interrupt received-- \n");
  91561. + retval |= 1;
  91562. + }
  91563. + if (gintsts.b.portintr && dwc_otg_is_device_mode(core_if)) {
  91564. + /* The port interrupt occurs while in device mode with HPRT0
  91565. + * Port Enable/Disable.
  91566. + */
  91567. + gintsts.d32 = 0;
  91568. + gintsts.b.portintr = 1;
  91569. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts,gintsts.d32);
  91570. + retval |= 1;
  91571. + gintmsk_reenable.b.portintr = 1;
  91572. +
  91573. + }
  91574. + /* Did we actually handle anything? if so, unmask the interrupt */
  91575. +// fiq_print(FIQDBG_INT, otg_dev->hcd->fiq_state, "CILOUT %1d", retval);
  91576. +// fiq_print(FIQDBG_INT, otg_dev->hcd->fiq_state, "%08x", gintsts.d32);
  91577. +// fiq_print(FIQDBG_INT, otg_dev->hcd->fiq_state, "%08x", gintmsk_reenable.d32);
  91578. + if (retval && fiq_enable) {
  91579. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, gintmsk_reenable.d32);
  91580. + }
  91581. +
  91582. + } else {
  91583. + DWC_DEBUGPL(DBG_ANY, "gpwrdn=%08x\n", gpwrdn.d32);
  91584. +
  91585. + if (gpwrdn.b.disconn_det && gpwrdn.b.disconn_det_msk) {
  91586. + CLEAR_GPWRDN_INTR(core_if, disconn_det);
  91587. + if (gpwrdn.b.linestate == 0) {
  91588. + dwc_otg_handle_pwrdn_disconnect_intr(core_if);
  91589. + } else {
  91590. + DWC_PRINTF("Disconnect detected while linestate is not 0\n");
  91591. + }
  91592. +
  91593. + retval |= 1;
  91594. + }
  91595. + if (gpwrdn.b.lnstschng && gpwrdn.b.lnstchng_msk) {
  91596. + CLEAR_GPWRDN_INTR(core_if, lnstschng);
  91597. + /* remote wakeup from hibernation */
  91598. + if (gpwrdn.b.linestate == 2 || gpwrdn.b.linestate == 1) {
  91599. + dwc_otg_handle_pwrdn_wakeup_detected_intr(core_if);
  91600. + } else {
  91601. + DWC_PRINTF("gpwrdn.linestate = %d\n", gpwrdn.b.linestate);
  91602. + }
  91603. + retval |= 1;
  91604. + }
  91605. + if (gpwrdn.b.rst_det && gpwrdn.b.rst_det_msk) {
  91606. + CLEAR_GPWRDN_INTR(core_if, rst_det);
  91607. + if (gpwrdn.b.linestate == 0) {
  91608. + DWC_PRINTF("Reset detected\n");
  91609. + retval |= dwc_otg_device_hibernation_restore(core_if, 0, 1);
  91610. + }
  91611. + }
  91612. + if (gpwrdn.b.srp_det && gpwrdn.b.srp_det_msk) {
  91613. + CLEAR_GPWRDN_INTR(core_if, srp_det);
  91614. + dwc_otg_handle_pwrdn_srp_intr(core_if);
  91615. + retval |= 1;
  91616. + }
  91617. + }
  91618. + /* Handle ADP interrupt here */
  91619. + if (gpwrdn.b.adp_int) {
  91620. + DWC_PRINTF("ADP interrupt\n");
  91621. + CLEAR_GPWRDN_INTR(core_if, adp_int);
  91622. + dwc_otg_adp_handle_intr(core_if);
  91623. + retval |= 1;
  91624. + }
  91625. + if (gpwrdn.b.sts_chngint && gpwrdn.b.sts_chngint_msk) {
  91626. + DWC_PRINTF("STS CHNG interrupt asserted\n");
  91627. + CLEAR_GPWRDN_INTR(core_if, sts_chngint);
  91628. + dwc_otg_handle_pwrdn_stschng_intr(otg_dev);
  91629. +
  91630. + retval |= 1;
  91631. + }
  91632. + if (core_if->lock)
  91633. + DWC_SPINUNLOCK(core_if->lock);
  91634. + return retval;
  91635. +}
  91636. diff -Nur linux-3.18.8/drivers/usb/host/dwc_otg/dwc_otg_core_if.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_core_if.h
  91637. --- linux-3.18.8/drivers/usb/host/dwc_otg/dwc_otg_core_if.h 1970-01-01 01:00:00.000000000 +0100
  91638. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_core_if.h 2015-03-05 14:40:16.557715806 +0100
  91639. @@ -0,0 +1,705 @@
  91640. +/* ==========================================================================
  91641. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_core_if.h $
  91642. + * $Revision: #13 $
  91643. + * $Date: 2012/08/10 $
  91644. + * $Change: 2047372 $
  91645. + *
  91646. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  91647. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  91648. + * otherwise expressly agreed to in writing between Synopsys and you.
  91649. + *
  91650. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  91651. + * any End User Software License Agreement or Agreement for Licensed Product
  91652. + * with Synopsys or any supplement thereto. You are permitted to use and
  91653. + * redistribute this Software in source and binary forms, with or without
  91654. + * modification, provided that redistributions of source code must retain this
  91655. + * notice. You may not view, use, disclose, copy or distribute this file or
  91656. + * any information contained herein except pursuant to this license grant from
  91657. + * Synopsys. If you do not agree with this notice, including the disclaimer
  91658. + * below, then you are not authorized to use the Software.
  91659. + *
  91660. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  91661. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  91662. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  91663. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  91664. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  91665. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  91666. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  91667. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  91668. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  91669. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  91670. + * DAMAGE.
  91671. + * ========================================================================== */
  91672. +#if !defined(__DWC_CORE_IF_H__)
  91673. +#define __DWC_CORE_IF_H__
  91674. +
  91675. +#include "dwc_os.h"
  91676. +
  91677. +/** @file
  91678. + * This file defines DWC_OTG Core API
  91679. + */
  91680. +
  91681. +struct dwc_otg_core_if;
  91682. +typedef struct dwc_otg_core_if dwc_otg_core_if_t;
  91683. +
  91684. +/** Maximum number of Periodic FIFOs */
  91685. +#define MAX_PERIO_FIFOS 15
  91686. +/** Maximum number of Periodic FIFOs */
  91687. +#define MAX_TX_FIFOS 15
  91688. +
  91689. +/** Maximum number of Endpoints/HostChannels */
  91690. +#define MAX_EPS_CHANNELS 16
  91691. +
  91692. +extern dwc_otg_core_if_t *dwc_otg_cil_init(const uint32_t * _reg_base_addr);
  91693. +extern void dwc_otg_core_init(dwc_otg_core_if_t * _core_if);
  91694. +extern void dwc_otg_cil_remove(dwc_otg_core_if_t * _core_if);
  91695. +
  91696. +extern void dwc_otg_enable_global_interrupts(dwc_otg_core_if_t * _core_if);
  91697. +extern void dwc_otg_disable_global_interrupts(dwc_otg_core_if_t * _core_if);
  91698. +
  91699. +extern uint8_t dwc_otg_is_device_mode(dwc_otg_core_if_t * _core_if);
  91700. +extern uint8_t dwc_otg_is_host_mode(dwc_otg_core_if_t * _core_if);
  91701. +
  91702. +extern uint8_t dwc_otg_is_dma_enable(dwc_otg_core_if_t * core_if);
  91703. +
  91704. +/** This function should be called on every hardware interrupt. */
  91705. +extern int32_t dwc_otg_handle_common_intr(void *otg_dev);
  91706. +
  91707. +/** @name OTG Core Parameters */
  91708. +/** @{ */
  91709. +
  91710. +/**
  91711. + * Specifies the OTG capabilities. The driver will automatically
  91712. + * detect the value for this parameter if none is specified.
  91713. + * 0 - HNP and SRP capable (default)
  91714. + * 1 - SRP Only capable
  91715. + * 2 - No HNP/SRP capable
  91716. + */
  91717. +extern int dwc_otg_set_param_otg_cap(dwc_otg_core_if_t * core_if, int32_t val);
  91718. +extern int32_t dwc_otg_get_param_otg_cap(dwc_otg_core_if_t * core_if);
  91719. +#define DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE 0
  91720. +#define DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE 1
  91721. +#define DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE 2
  91722. +#define dwc_param_otg_cap_default DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE
  91723. +
  91724. +extern int dwc_otg_set_param_opt(dwc_otg_core_if_t * core_if, int32_t val);
  91725. +extern int32_t dwc_otg_get_param_opt(dwc_otg_core_if_t * core_if);
  91726. +#define dwc_param_opt_default 1
  91727. +
  91728. +/**
  91729. + * Specifies whether to use slave or DMA mode for accessing the data
  91730. + * FIFOs. The driver will automatically detect the value for this
  91731. + * parameter if none is specified.
  91732. + * 0 - Slave
  91733. + * 1 - DMA (default, if available)
  91734. + */
  91735. +extern int dwc_otg_set_param_dma_enable(dwc_otg_core_if_t * core_if,
  91736. + int32_t val);
  91737. +extern int32_t dwc_otg_get_param_dma_enable(dwc_otg_core_if_t * core_if);
  91738. +#define dwc_param_dma_enable_default 1
  91739. +
  91740. +/**
  91741. + * When DMA mode is enabled specifies whether to use
  91742. + * address DMA or DMA Descritor mode for accessing the data
  91743. + * FIFOs in device mode. The driver will automatically detect
  91744. + * the value for this parameter if none is specified.
  91745. + * 0 - address DMA
  91746. + * 1 - DMA Descriptor(default, if available)
  91747. + */
  91748. +extern int dwc_otg_set_param_dma_desc_enable(dwc_otg_core_if_t * core_if,
  91749. + int32_t val);
  91750. +extern int32_t dwc_otg_get_param_dma_desc_enable(dwc_otg_core_if_t * core_if);
  91751. +//#define dwc_param_dma_desc_enable_default 1
  91752. +#define dwc_param_dma_desc_enable_default 0 // Broadcom BCM2708
  91753. +
  91754. +/** The DMA Burst size (applicable only for External DMA
  91755. + * Mode). 1, 4, 8 16, 32, 64, 128, 256 (default 32)
  91756. + */
  91757. +extern int dwc_otg_set_param_dma_burst_size(dwc_otg_core_if_t * core_if,
  91758. + int32_t val);
  91759. +extern int32_t dwc_otg_get_param_dma_burst_size(dwc_otg_core_if_t * core_if);
  91760. +#define dwc_param_dma_burst_size_default 32
  91761. +
  91762. +/**
  91763. + * Specifies the maximum speed of operation in host and device mode.
  91764. + * The actual speed depends on the speed of the attached device and
  91765. + * the value of phy_type. The actual speed depends on the speed of the
  91766. + * attached device.
  91767. + * 0 - High Speed (default)
  91768. + * 1 - Full Speed
  91769. + */
  91770. +extern int dwc_otg_set_param_speed(dwc_otg_core_if_t * core_if, int32_t val);
  91771. +extern int32_t dwc_otg_get_param_speed(dwc_otg_core_if_t * core_if);
  91772. +#define dwc_param_speed_default 0
  91773. +#define DWC_SPEED_PARAM_HIGH 0
  91774. +#define DWC_SPEED_PARAM_FULL 1
  91775. +
  91776. +/** Specifies whether low power mode is supported when attached
  91777. + * to a Full Speed or Low Speed device in host mode.
  91778. + * 0 - Don't support low power mode (default)
  91779. + * 1 - Support low power mode
  91780. + */
  91781. +extern int dwc_otg_set_param_host_support_fs_ls_low_power(dwc_otg_core_if_t *
  91782. + core_if, int32_t val);
  91783. +extern int32_t dwc_otg_get_param_host_support_fs_ls_low_power(dwc_otg_core_if_t
  91784. + * core_if);
  91785. +#define dwc_param_host_support_fs_ls_low_power_default 0
  91786. +
  91787. +/** Specifies the PHY clock rate in low power mode when connected to a
  91788. + * Low Speed device in host mode. This parameter is applicable only if
  91789. + * HOST_SUPPORT_FS_LS_LOW_POWER is enabled. If PHY_TYPE is set to FS
  91790. + * then defaults to 6 MHZ otherwise 48 MHZ.
  91791. + *
  91792. + * 0 - 48 MHz
  91793. + * 1 - 6 MHz
  91794. + */
  91795. +extern int dwc_otg_set_param_host_ls_low_power_phy_clk(dwc_otg_core_if_t *
  91796. + core_if, int32_t val);
  91797. +extern int32_t dwc_otg_get_param_host_ls_low_power_phy_clk(dwc_otg_core_if_t *
  91798. + core_if);
  91799. +#define dwc_param_host_ls_low_power_phy_clk_default 0
  91800. +#define DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ 0
  91801. +#define DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ 1
  91802. +
  91803. +/**
  91804. + * 0 - Use cC FIFO size parameters
  91805. + * 1 - Allow dynamic FIFO sizing (default)
  91806. + */
  91807. +extern int dwc_otg_set_param_enable_dynamic_fifo(dwc_otg_core_if_t * core_if,
  91808. + int32_t val);
  91809. +extern int32_t dwc_otg_get_param_enable_dynamic_fifo(dwc_otg_core_if_t *
  91810. + core_if);
  91811. +#define dwc_param_enable_dynamic_fifo_default 1
  91812. +
  91813. +/** Total number of 4-byte words in the data FIFO memory. This
  91814. + * memory includes the Rx FIFO, non-periodic Tx FIFO, and periodic
  91815. + * Tx FIFOs.
  91816. + * 32 to 32768 (default 8192)
  91817. + * Note: The total FIFO memory depth in the FPGA configuration is 8192.
  91818. + */
  91819. +extern int dwc_otg_set_param_data_fifo_size(dwc_otg_core_if_t * core_if,
  91820. + int32_t val);
  91821. +extern int32_t dwc_otg_get_param_data_fifo_size(dwc_otg_core_if_t * core_if);
  91822. +//#define dwc_param_data_fifo_size_default 8192
  91823. +#define dwc_param_data_fifo_size_default 0xFF0 // Broadcom BCM2708
  91824. +
  91825. +/** Number of 4-byte words in the Rx FIFO in device mode when dynamic
  91826. + * FIFO sizing is enabled.
  91827. + * 16 to 32768 (default 1064)
  91828. + */
  91829. +extern int dwc_otg_set_param_dev_rx_fifo_size(dwc_otg_core_if_t * core_if,
  91830. + int32_t val);
  91831. +extern int32_t dwc_otg_get_param_dev_rx_fifo_size(dwc_otg_core_if_t * core_if);
  91832. +#define dwc_param_dev_rx_fifo_size_default 1064
  91833. +
  91834. +/** Number of 4-byte words in the non-periodic Tx FIFO in device mode
  91835. + * when dynamic FIFO sizing is enabled.
  91836. + * 16 to 32768 (default 1024)
  91837. + */
  91838. +extern int dwc_otg_set_param_dev_nperio_tx_fifo_size(dwc_otg_core_if_t *
  91839. + core_if, int32_t val);
  91840. +extern int32_t dwc_otg_get_param_dev_nperio_tx_fifo_size(dwc_otg_core_if_t *
  91841. + core_if);
  91842. +#define dwc_param_dev_nperio_tx_fifo_size_default 1024
  91843. +
  91844. +/** Number of 4-byte words in each of the periodic Tx FIFOs in device
  91845. + * mode when dynamic FIFO sizing is enabled.
  91846. + * 4 to 768 (default 256)
  91847. + */
  91848. +extern int dwc_otg_set_param_dev_perio_tx_fifo_size(dwc_otg_core_if_t * core_if,
  91849. + int32_t val, int fifo_num);
  91850. +extern int32_t dwc_otg_get_param_dev_perio_tx_fifo_size(dwc_otg_core_if_t *
  91851. + core_if, int fifo_num);
  91852. +#define dwc_param_dev_perio_tx_fifo_size_default 256
  91853. +
  91854. +/** Number of 4-byte words in the Rx FIFO in host mode when dynamic
  91855. + * FIFO sizing is enabled.
  91856. + * 16 to 32768 (default 1024)
  91857. + */
  91858. +extern int dwc_otg_set_param_host_rx_fifo_size(dwc_otg_core_if_t * core_if,
  91859. + int32_t val);
  91860. +extern int32_t dwc_otg_get_param_host_rx_fifo_size(dwc_otg_core_if_t * core_if);
  91861. +//#define dwc_param_host_rx_fifo_size_default 1024
  91862. +#define dwc_param_host_rx_fifo_size_default 774 // Broadcom BCM2708
  91863. +
  91864. +/** Number of 4-byte words in the non-periodic Tx FIFO in host mode
  91865. + * when Dynamic FIFO sizing is enabled in the core.
  91866. + * 16 to 32768 (default 1024)
  91867. + */
  91868. +extern int dwc_otg_set_param_host_nperio_tx_fifo_size(dwc_otg_core_if_t *
  91869. + core_if, int32_t val);
  91870. +extern int32_t dwc_otg_get_param_host_nperio_tx_fifo_size(dwc_otg_core_if_t *
  91871. + core_if);
  91872. +//#define dwc_param_host_nperio_tx_fifo_size_default 1024
  91873. +#define dwc_param_host_nperio_tx_fifo_size_default 0x100 // Broadcom BCM2708
  91874. +
  91875. +/** Number of 4-byte words in the host periodic Tx FIFO when dynamic
  91876. + * FIFO sizing is enabled.
  91877. + * 16 to 32768 (default 1024)
  91878. + */
  91879. +extern int dwc_otg_set_param_host_perio_tx_fifo_size(dwc_otg_core_if_t *
  91880. + core_if, int32_t val);
  91881. +extern int32_t dwc_otg_get_param_host_perio_tx_fifo_size(dwc_otg_core_if_t *
  91882. + core_if);
  91883. +//#define dwc_param_host_perio_tx_fifo_size_default 1024
  91884. +#define dwc_param_host_perio_tx_fifo_size_default 0x200 // Broadcom BCM2708
  91885. +
  91886. +/** The maximum transfer size supported in bytes.
  91887. + * 2047 to 65,535 (default 65,535)
  91888. + */
  91889. +extern int dwc_otg_set_param_max_transfer_size(dwc_otg_core_if_t * core_if,
  91890. + int32_t val);
  91891. +extern int32_t dwc_otg_get_param_max_transfer_size(dwc_otg_core_if_t * core_if);
  91892. +#define dwc_param_max_transfer_size_default 65535
  91893. +
  91894. +/** The maximum number of packets in a transfer.
  91895. + * 15 to 511 (default 511)
  91896. + */
  91897. +extern int dwc_otg_set_param_max_packet_count(dwc_otg_core_if_t * core_if,
  91898. + int32_t val);
  91899. +extern int32_t dwc_otg_get_param_max_packet_count(dwc_otg_core_if_t * core_if);
  91900. +#define dwc_param_max_packet_count_default 511
  91901. +
  91902. +/** The number of host channel registers to use.
  91903. + * 1 to 16 (default 12)
  91904. + * Note: The FPGA configuration supports a maximum of 12 host channels.
  91905. + */
  91906. +extern int dwc_otg_set_param_host_channels(dwc_otg_core_if_t * core_if,
  91907. + int32_t val);
  91908. +extern int32_t dwc_otg_get_param_host_channels(dwc_otg_core_if_t * core_if);
  91909. +//#define dwc_param_host_channels_default 12
  91910. +#define dwc_param_host_channels_default 8 // Broadcom BCM2708
  91911. +
  91912. +/** The number of endpoints in addition to EP0 available for device
  91913. + * mode operations.
  91914. + * 1 to 15 (default 6 IN and OUT)
  91915. + * Note: The FPGA configuration supports a maximum of 6 IN and OUT
  91916. + * endpoints in addition to EP0.
  91917. + */
  91918. +extern int dwc_otg_set_param_dev_endpoints(dwc_otg_core_if_t * core_if,
  91919. + int32_t val);
  91920. +extern int32_t dwc_otg_get_param_dev_endpoints(dwc_otg_core_if_t * core_if);
  91921. +#define dwc_param_dev_endpoints_default 6
  91922. +
  91923. +/**
  91924. + * Specifies the type of PHY interface to use. By default, the driver
  91925. + * will automatically detect the phy_type.
  91926. + *
  91927. + * 0 - Full Speed PHY
  91928. + * 1 - UTMI+ (default)
  91929. + * 2 - ULPI
  91930. + */
  91931. +extern int dwc_otg_set_param_phy_type(dwc_otg_core_if_t * core_if, int32_t val);
  91932. +extern int32_t dwc_otg_get_param_phy_type(dwc_otg_core_if_t * core_if);
  91933. +#define DWC_PHY_TYPE_PARAM_FS 0
  91934. +#define DWC_PHY_TYPE_PARAM_UTMI 1
  91935. +#define DWC_PHY_TYPE_PARAM_ULPI 2
  91936. +#define dwc_param_phy_type_default DWC_PHY_TYPE_PARAM_UTMI
  91937. +
  91938. +/**
  91939. + * Specifies the UTMI+ Data Width. This parameter is
  91940. + * applicable for a PHY_TYPE of UTMI+ or ULPI. (For a ULPI
  91941. + * PHY_TYPE, this parameter indicates the data width between
  91942. + * the MAC and the ULPI Wrapper.) Also, this parameter is
  91943. + * applicable only if the OTG_HSPHY_WIDTH cC parameter was set
  91944. + * to "8 and 16 bits", meaning that the core has been
  91945. + * configured to work at either data path width.
  91946. + *
  91947. + * 8 or 16 bits (default 16)
  91948. + */
  91949. +extern int dwc_otg_set_param_phy_utmi_width(dwc_otg_core_if_t * core_if,
  91950. + int32_t val);
  91951. +extern int32_t dwc_otg_get_param_phy_utmi_width(dwc_otg_core_if_t * core_if);
  91952. +//#define dwc_param_phy_utmi_width_default 16
  91953. +#define dwc_param_phy_utmi_width_default 8 // Broadcom BCM2708
  91954. +
  91955. +/**
  91956. + * Specifies whether the ULPI operates at double or single
  91957. + * data rate. This parameter is only applicable if PHY_TYPE is
  91958. + * ULPI.
  91959. + *
  91960. + * 0 - single data rate ULPI interface with 8 bit wide data
  91961. + * bus (default)
  91962. + * 1 - double data rate ULPI interface with 4 bit wide data
  91963. + * bus
  91964. + */
  91965. +extern int dwc_otg_set_param_phy_ulpi_ddr(dwc_otg_core_if_t * core_if,
  91966. + int32_t val);
  91967. +extern int32_t dwc_otg_get_param_phy_ulpi_ddr(dwc_otg_core_if_t * core_if);
  91968. +#define dwc_param_phy_ulpi_ddr_default 0
  91969. +
  91970. +/**
  91971. + * Specifies whether to use the internal or external supply to
  91972. + * drive the vbus with a ULPI phy.
  91973. + */
  91974. +extern int dwc_otg_set_param_phy_ulpi_ext_vbus(dwc_otg_core_if_t * core_if,
  91975. + int32_t val);
  91976. +extern int32_t dwc_otg_get_param_phy_ulpi_ext_vbus(dwc_otg_core_if_t * core_if);
  91977. +#define DWC_PHY_ULPI_INTERNAL_VBUS 0
  91978. +#define DWC_PHY_ULPI_EXTERNAL_VBUS 1
  91979. +#define dwc_param_phy_ulpi_ext_vbus_default DWC_PHY_ULPI_INTERNAL_VBUS
  91980. +
  91981. +/**
  91982. + * Specifies whether to use the I2Cinterface for full speed PHY. This
  91983. + * parameter is only applicable if PHY_TYPE is FS.
  91984. + * 0 - No (default)
  91985. + * 1 - Yes
  91986. + */
  91987. +extern int dwc_otg_set_param_i2c_enable(dwc_otg_core_if_t * core_if,
  91988. + int32_t val);
  91989. +extern int32_t dwc_otg_get_param_i2c_enable(dwc_otg_core_if_t * core_if);
  91990. +#define dwc_param_i2c_enable_default 0
  91991. +
  91992. +extern int dwc_otg_set_param_ulpi_fs_ls(dwc_otg_core_if_t * core_if,
  91993. + int32_t val);
  91994. +extern int32_t dwc_otg_get_param_ulpi_fs_ls(dwc_otg_core_if_t * core_if);
  91995. +#define dwc_param_ulpi_fs_ls_default 0
  91996. +
  91997. +extern int dwc_otg_set_param_ts_dline(dwc_otg_core_if_t * core_if, int32_t val);
  91998. +extern int32_t dwc_otg_get_param_ts_dline(dwc_otg_core_if_t * core_if);
  91999. +#define dwc_param_ts_dline_default 0
  92000. +
  92001. +/**
  92002. + * Specifies whether dedicated transmit FIFOs are
  92003. + * enabled for non periodic IN endpoints in device mode
  92004. + * 0 - No
  92005. + * 1 - Yes
  92006. + */
  92007. +extern int dwc_otg_set_param_en_multiple_tx_fifo(dwc_otg_core_if_t * core_if,
  92008. + int32_t val);
  92009. +extern int32_t dwc_otg_get_param_en_multiple_tx_fifo(dwc_otg_core_if_t *
  92010. + core_if);
  92011. +#define dwc_param_en_multiple_tx_fifo_default 1
  92012. +
  92013. +/** Number of 4-byte words in each of the Tx FIFOs in device
  92014. + * mode when dynamic FIFO sizing is enabled.
  92015. + * 4 to 768 (default 256)
  92016. + */
  92017. +extern int dwc_otg_set_param_dev_tx_fifo_size(dwc_otg_core_if_t * core_if,
  92018. + int fifo_num, int32_t val);
  92019. +extern int32_t dwc_otg_get_param_dev_tx_fifo_size(dwc_otg_core_if_t * core_if,
  92020. + int fifo_num);
  92021. +#define dwc_param_dev_tx_fifo_size_default 768
  92022. +
  92023. +/** Thresholding enable flag-
  92024. + * bit 0 - enable non-ISO Tx thresholding
  92025. + * bit 1 - enable ISO Tx thresholding
  92026. + * bit 2 - enable Rx thresholding
  92027. + */
  92028. +extern int dwc_otg_set_param_thr_ctl(dwc_otg_core_if_t * core_if, int32_t val);
  92029. +extern int32_t dwc_otg_get_thr_ctl(dwc_otg_core_if_t * core_if, int fifo_num);
  92030. +#define dwc_param_thr_ctl_default 0
  92031. +
  92032. +/** Thresholding length for Tx
  92033. + * FIFOs in 32 bit DWORDs
  92034. + */
  92035. +extern int dwc_otg_set_param_tx_thr_length(dwc_otg_core_if_t * core_if,
  92036. + int32_t val);
  92037. +extern int32_t dwc_otg_get_tx_thr_length(dwc_otg_core_if_t * core_if);
  92038. +#define dwc_param_tx_thr_length_default 64
  92039. +
  92040. +/** Thresholding length for Rx
  92041. + * FIFOs in 32 bit DWORDs
  92042. + */
  92043. +extern int dwc_otg_set_param_rx_thr_length(dwc_otg_core_if_t * core_if,
  92044. + int32_t val);
  92045. +extern int32_t dwc_otg_get_rx_thr_length(dwc_otg_core_if_t * core_if);
  92046. +#define dwc_param_rx_thr_length_default 64
  92047. +
  92048. +/**
  92049. + * Specifies whether LPM (Link Power Management) support is enabled
  92050. + */
  92051. +extern int dwc_otg_set_param_lpm_enable(dwc_otg_core_if_t * core_if,
  92052. + int32_t val);
  92053. +extern int32_t dwc_otg_get_param_lpm_enable(dwc_otg_core_if_t * core_if);
  92054. +#define dwc_param_lpm_enable_default 1
  92055. +
  92056. +/**
  92057. + * Specifies whether PTI enhancement is enabled
  92058. + */
  92059. +extern int dwc_otg_set_param_pti_enable(dwc_otg_core_if_t * core_if,
  92060. + int32_t val);
  92061. +extern int32_t dwc_otg_get_param_pti_enable(dwc_otg_core_if_t * core_if);
  92062. +#define dwc_param_pti_enable_default 0
  92063. +
  92064. +/**
  92065. + * Specifies whether MPI enhancement is enabled
  92066. + */
  92067. +extern int dwc_otg_set_param_mpi_enable(dwc_otg_core_if_t * core_if,
  92068. + int32_t val);
  92069. +extern int32_t dwc_otg_get_param_mpi_enable(dwc_otg_core_if_t * core_if);
  92070. +#define dwc_param_mpi_enable_default 0
  92071. +
  92072. +/**
  92073. + * Specifies whether ADP capability is enabled
  92074. + */
  92075. +extern int dwc_otg_set_param_adp_enable(dwc_otg_core_if_t * core_if,
  92076. + int32_t val);
  92077. +extern int32_t dwc_otg_get_param_adp_enable(dwc_otg_core_if_t * core_if);
  92078. +#define dwc_param_adp_enable_default 0
  92079. +
  92080. +/**
  92081. + * Specifies whether IC_USB capability is enabled
  92082. + */
  92083. +
  92084. +extern int dwc_otg_set_param_ic_usb_cap(dwc_otg_core_if_t * core_if,
  92085. + int32_t val);
  92086. +extern int32_t dwc_otg_get_param_ic_usb_cap(dwc_otg_core_if_t * core_if);
  92087. +#define dwc_param_ic_usb_cap_default 0
  92088. +
  92089. +extern int dwc_otg_set_param_ahb_thr_ratio(dwc_otg_core_if_t * core_if,
  92090. + int32_t val);
  92091. +extern int32_t dwc_otg_get_param_ahb_thr_ratio(dwc_otg_core_if_t * core_if);
  92092. +#define dwc_param_ahb_thr_ratio_default 0
  92093. +
  92094. +extern int dwc_otg_set_param_power_down(dwc_otg_core_if_t * core_if,
  92095. + int32_t val);
  92096. +extern int32_t dwc_otg_get_param_power_down(dwc_otg_core_if_t * core_if);
  92097. +#define dwc_param_power_down_default 0
  92098. +
  92099. +extern int dwc_otg_set_param_reload_ctl(dwc_otg_core_if_t * core_if,
  92100. + int32_t val);
  92101. +extern int32_t dwc_otg_get_param_reload_ctl(dwc_otg_core_if_t * core_if);
  92102. +#define dwc_param_reload_ctl_default 0
  92103. +
  92104. +extern int dwc_otg_set_param_dev_out_nak(dwc_otg_core_if_t * core_if,
  92105. + int32_t val);
  92106. +extern int32_t dwc_otg_get_param_dev_out_nak(dwc_otg_core_if_t * core_if);
  92107. +#define dwc_param_dev_out_nak_default 0
  92108. +
  92109. +extern int dwc_otg_set_param_cont_on_bna(dwc_otg_core_if_t * core_if,
  92110. + int32_t val);
  92111. +extern int32_t dwc_otg_get_param_cont_on_bna(dwc_otg_core_if_t * core_if);
  92112. +#define dwc_param_cont_on_bna_default 0
  92113. +
  92114. +extern int dwc_otg_set_param_ahb_single(dwc_otg_core_if_t * core_if,
  92115. + int32_t val);
  92116. +extern int32_t dwc_otg_get_param_ahb_single(dwc_otg_core_if_t * core_if);
  92117. +#define dwc_param_ahb_single_default 0
  92118. +
  92119. +extern int dwc_otg_set_param_otg_ver(dwc_otg_core_if_t * core_if, int32_t val);
  92120. +extern int32_t dwc_otg_get_param_otg_ver(dwc_otg_core_if_t * core_if);
  92121. +#define dwc_param_otg_ver_default 0
  92122. +
  92123. +/** @} */
  92124. +
  92125. +/** @name Access to registers and bit-fields */
  92126. +
  92127. +/**
  92128. + * Dump core registers and SPRAM
  92129. + */
  92130. +extern void dwc_otg_dump_dev_registers(dwc_otg_core_if_t * _core_if);
  92131. +extern void dwc_otg_dump_spram(dwc_otg_core_if_t * _core_if);
  92132. +extern void dwc_otg_dump_host_registers(dwc_otg_core_if_t * _core_if);
  92133. +extern void dwc_otg_dump_global_registers(dwc_otg_core_if_t * _core_if);
  92134. +
  92135. +/**
  92136. + * Get host negotiation status.
  92137. + */
  92138. +extern uint32_t dwc_otg_get_hnpstatus(dwc_otg_core_if_t * core_if);
  92139. +
  92140. +/**
  92141. + * Get srp status
  92142. + */
  92143. +extern uint32_t dwc_otg_get_srpstatus(dwc_otg_core_if_t * core_if);
  92144. +
  92145. +/**
  92146. + * Set hnpreq bit in the GOTGCTL register.
  92147. + */
  92148. +extern void dwc_otg_set_hnpreq(dwc_otg_core_if_t * core_if, uint32_t val);
  92149. +
  92150. +/**
  92151. + * Get Content of SNPSID register.
  92152. + */
  92153. +extern uint32_t dwc_otg_get_gsnpsid(dwc_otg_core_if_t * core_if);
  92154. +
  92155. +/**
  92156. + * Get current mode.
  92157. + * Returns 0 if in device mode, and 1 if in host mode.
  92158. + */
  92159. +extern uint32_t dwc_otg_get_mode(dwc_otg_core_if_t * core_if);
  92160. +
  92161. +/**
  92162. + * Get value of hnpcapable field in the GUSBCFG register
  92163. + */
  92164. +extern uint32_t dwc_otg_get_hnpcapable(dwc_otg_core_if_t * core_if);
  92165. +/**
  92166. + * Set value of hnpcapable field in the GUSBCFG register
  92167. + */
  92168. +extern void dwc_otg_set_hnpcapable(dwc_otg_core_if_t * core_if, uint32_t val);
  92169. +
  92170. +/**
  92171. + * Get value of srpcapable field in the GUSBCFG register
  92172. + */
  92173. +extern uint32_t dwc_otg_get_srpcapable(dwc_otg_core_if_t * core_if);
  92174. +/**
  92175. + * Set value of srpcapable field in the GUSBCFG register
  92176. + */
  92177. +extern void dwc_otg_set_srpcapable(dwc_otg_core_if_t * core_if, uint32_t val);
  92178. +
  92179. +/**
  92180. + * Get value of devspeed field in the DCFG register
  92181. + */
  92182. +extern uint32_t dwc_otg_get_devspeed(dwc_otg_core_if_t * core_if);
  92183. +/**
  92184. + * Set value of devspeed field in the DCFG register
  92185. + */
  92186. +extern void dwc_otg_set_devspeed(dwc_otg_core_if_t * core_if, uint32_t val);
  92187. +
  92188. +/**
  92189. + * Get the value of busconnected field from the HPRT0 register
  92190. + */
  92191. +extern uint32_t dwc_otg_get_busconnected(dwc_otg_core_if_t * core_if);
  92192. +
  92193. +/**
  92194. + * Gets the device enumeration Speed.
  92195. + */
  92196. +extern uint32_t dwc_otg_get_enumspeed(dwc_otg_core_if_t * core_if);
  92197. +
  92198. +/**
  92199. + * Get value of prtpwr field from the HPRT0 register
  92200. + */
  92201. +extern uint32_t dwc_otg_get_prtpower(dwc_otg_core_if_t * core_if);
  92202. +
  92203. +/**
  92204. + * Get value of flag indicating core state - hibernated or not
  92205. + */
  92206. +extern uint32_t dwc_otg_get_core_state(dwc_otg_core_if_t * core_if);
  92207. +
  92208. +/**
  92209. + * Set value of prtpwr field from the HPRT0 register
  92210. + */
  92211. +extern void dwc_otg_set_prtpower(dwc_otg_core_if_t * core_if, uint32_t val);
  92212. +
  92213. +/**
  92214. + * Get value of prtsusp field from the HPRT0 regsiter
  92215. + */
  92216. +extern uint32_t dwc_otg_get_prtsuspend(dwc_otg_core_if_t * core_if);
  92217. +/**
  92218. + * Set value of prtpwr field from the HPRT0 register
  92219. + */
  92220. +extern void dwc_otg_set_prtsuspend(dwc_otg_core_if_t * core_if, uint32_t val);
  92221. +
  92222. +/**
  92223. + * Get value of ModeChTimEn field from the HCFG regsiter
  92224. + */
  92225. +extern uint32_t dwc_otg_get_mode_ch_tim(dwc_otg_core_if_t * core_if);
  92226. +/**
  92227. + * Set value of ModeChTimEn field from the HCFG regsiter
  92228. + */
  92229. +extern void dwc_otg_set_mode_ch_tim(dwc_otg_core_if_t * core_if, uint32_t val);
  92230. +
  92231. +/**
  92232. + * Get value of Fram Interval field from the HFIR regsiter
  92233. + */
  92234. +extern uint32_t dwc_otg_get_fr_interval(dwc_otg_core_if_t * core_if);
  92235. +/**
  92236. + * Set value of Frame Interval field from the HFIR regsiter
  92237. + */
  92238. +extern void dwc_otg_set_fr_interval(dwc_otg_core_if_t * core_if, uint32_t val);
  92239. +
  92240. +/**
  92241. + * Set value of prtres field from the HPRT0 register
  92242. + *FIXME Remove?
  92243. + */
  92244. +extern void dwc_otg_set_prtresume(dwc_otg_core_if_t * core_if, uint32_t val);
  92245. +
  92246. +/**
  92247. + * Get value of rmtwkupsig bit in DCTL register
  92248. + */
  92249. +extern uint32_t dwc_otg_get_remotewakesig(dwc_otg_core_if_t * core_if);
  92250. +
  92251. +/**
  92252. + * Get value of prt_sleep_sts field from the GLPMCFG register
  92253. + */
  92254. +extern uint32_t dwc_otg_get_lpm_portsleepstatus(dwc_otg_core_if_t * core_if);
  92255. +
  92256. +/**
  92257. + * Get value of rem_wkup_en field from the GLPMCFG register
  92258. + */
  92259. +extern uint32_t dwc_otg_get_lpm_remotewakeenabled(dwc_otg_core_if_t * core_if);
  92260. +
  92261. +/**
  92262. + * Get value of appl_resp field from the GLPMCFG register
  92263. + */
  92264. +extern uint32_t dwc_otg_get_lpmresponse(dwc_otg_core_if_t * core_if);
  92265. +/**
  92266. + * Set value of appl_resp field from the GLPMCFG register
  92267. + */
  92268. +extern void dwc_otg_set_lpmresponse(dwc_otg_core_if_t * core_if, uint32_t val);
  92269. +
  92270. +/**
  92271. + * Get value of hsic_connect field from the GLPMCFG register
  92272. + */
  92273. +extern uint32_t dwc_otg_get_hsic_connect(dwc_otg_core_if_t * core_if);
  92274. +/**
  92275. + * Set value of hsic_connect field from the GLPMCFG register
  92276. + */
  92277. +extern void dwc_otg_set_hsic_connect(dwc_otg_core_if_t * core_if, uint32_t val);
  92278. +
  92279. +/**
  92280. + * Get value of inv_sel_hsic field from the GLPMCFG register.
  92281. + */
  92282. +extern uint32_t dwc_otg_get_inv_sel_hsic(dwc_otg_core_if_t * core_if);
  92283. +/**
  92284. + * Set value of inv_sel_hsic field from the GLPMFG register.
  92285. + */
  92286. +extern void dwc_otg_set_inv_sel_hsic(dwc_otg_core_if_t * core_if, uint32_t val);
  92287. +
  92288. +/*
  92289. + * Some functions for accessing registers
  92290. + */
  92291. +
  92292. +/**
  92293. + * GOTGCTL register
  92294. + */
  92295. +extern uint32_t dwc_otg_get_gotgctl(dwc_otg_core_if_t * core_if);
  92296. +extern void dwc_otg_set_gotgctl(dwc_otg_core_if_t * core_if, uint32_t val);
  92297. +
  92298. +/**
  92299. + * GUSBCFG register
  92300. + */
  92301. +extern uint32_t dwc_otg_get_gusbcfg(dwc_otg_core_if_t * core_if);
  92302. +extern void dwc_otg_set_gusbcfg(dwc_otg_core_if_t * core_if, uint32_t val);
  92303. +
  92304. +/**
  92305. + * GRXFSIZ register
  92306. + */
  92307. +extern uint32_t dwc_otg_get_grxfsiz(dwc_otg_core_if_t * core_if);
  92308. +extern void dwc_otg_set_grxfsiz(dwc_otg_core_if_t * core_if, uint32_t val);
  92309. +
  92310. +/**
  92311. + * GNPTXFSIZ register
  92312. + */
  92313. +extern uint32_t dwc_otg_get_gnptxfsiz(dwc_otg_core_if_t * core_if);
  92314. +extern void dwc_otg_set_gnptxfsiz(dwc_otg_core_if_t * core_if, uint32_t val);
  92315. +
  92316. +extern uint32_t dwc_otg_get_gpvndctl(dwc_otg_core_if_t * core_if);
  92317. +extern void dwc_otg_set_gpvndctl(dwc_otg_core_if_t * core_if, uint32_t val);
  92318. +
  92319. +/**
  92320. + * GGPIO register
  92321. + */
  92322. +extern uint32_t dwc_otg_get_ggpio(dwc_otg_core_if_t * core_if);
  92323. +extern void dwc_otg_set_ggpio(dwc_otg_core_if_t * core_if, uint32_t val);
  92324. +
  92325. +/**
  92326. + * GUID register
  92327. + */
  92328. +extern uint32_t dwc_otg_get_guid(dwc_otg_core_if_t * core_if);
  92329. +extern void dwc_otg_set_guid(dwc_otg_core_if_t * core_if, uint32_t val);
  92330. +
  92331. +/**
  92332. + * HPRT0 register
  92333. + */
  92334. +extern uint32_t dwc_otg_get_hprt0(dwc_otg_core_if_t * core_if);
  92335. +extern void dwc_otg_set_hprt0(dwc_otg_core_if_t * core_if, uint32_t val);
  92336. +
  92337. +/**
  92338. + * GHPTXFSIZE
  92339. + */
  92340. +extern uint32_t dwc_otg_get_hptxfsiz(dwc_otg_core_if_t * core_if);
  92341. +
  92342. +/** @} */
  92343. +
  92344. +#endif /* __DWC_CORE_IF_H__ */
  92345. diff -Nur linux-3.18.8/drivers/usb/host/dwc_otg/dwc_otg_dbg.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_dbg.h
  92346. --- linux-3.18.8/drivers/usb/host/dwc_otg/dwc_otg_dbg.h 1970-01-01 01:00:00.000000000 +0100
  92347. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_dbg.h 2015-03-05 14:40:16.557715806 +0100
  92348. @@ -0,0 +1,117 @@
  92349. +/* ==========================================================================
  92350. + *
  92351. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  92352. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  92353. + * otherwise expressly agreed to in writing between Synopsys and you.
  92354. + *
  92355. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  92356. + * any End User Software License Agreement or Agreement for Licensed Product
  92357. + * with Synopsys or any supplement thereto. You are permitted to use and
  92358. + * redistribute this Software in source and binary forms, with or without
  92359. + * modification, provided that redistributions of source code must retain this
  92360. + * notice. You may not view, use, disclose, copy or distribute this file or
  92361. + * any information contained herein except pursuant to this license grant from
  92362. + * Synopsys. If you do not agree with this notice, including the disclaimer
  92363. + * below, then you are not authorized to use the Software.
  92364. + *
  92365. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  92366. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  92367. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  92368. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  92369. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  92370. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  92371. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  92372. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  92373. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  92374. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  92375. + * DAMAGE.
  92376. + * ========================================================================== */
  92377. +
  92378. +#ifndef __DWC_OTG_DBG_H__
  92379. +#define __DWC_OTG_DBG_H__
  92380. +
  92381. +/** @file
  92382. + * This file defines debug levels.
  92383. + * Debugging support vanishes in non-debug builds.
  92384. + */
  92385. +
  92386. +/**
  92387. + * The Debug Level bit-mask variable.
  92388. + */
  92389. +extern uint32_t g_dbg_lvl;
  92390. +/**
  92391. + * Set the Debug Level variable.
  92392. + */
  92393. +static inline uint32_t SET_DEBUG_LEVEL(const uint32_t new)
  92394. +{
  92395. + uint32_t old = g_dbg_lvl;
  92396. + g_dbg_lvl = new;
  92397. + return old;
  92398. +}
  92399. +
  92400. +#define DBG_USER (0x1)
  92401. +/** When debug level has the DBG_CIL bit set, display CIL Debug messages. */
  92402. +#define DBG_CIL (0x2)
  92403. +/** When debug level has the DBG_CILV bit set, display CIL Verbose debug
  92404. + * messages */
  92405. +#define DBG_CILV (0x20)
  92406. +/** When debug level has the DBG_PCD bit set, display PCD (Device) debug
  92407. + * messages */
  92408. +#define DBG_PCD (0x4)
  92409. +/** When debug level has the DBG_PCDV set, display PCD (Device) Verbose debug
  92410. + * messages */
  92411. +#define DBG_PCDV (0x40)
  92412. +/** When debug level has the DBG_HCD bit set, display Host debug messages */
  92413. +#define DBG_HCD (0x8)
  92414. +/** When debug level has the DBG_HCDV bit set, display Verbose Host debug
  92415. + * messages */
  92416. +#define DBG_HCDV (0x80)
  92417. +/** When debug level has the DBG_HCD_URB bit set, display enqueued URBs in host
  92418. + * mode. */
  92419. +#define DBG_HCD_URB (0x800)
  92420. +/** When debug level has the DBG_HCDI bit set, display host interrupt
  92421. + * messages. */
  92422. +#define DBG_HCDI (0x1000)
  92423. +
  92424. +/** When debug level has any bit set, display debug messages */
  92425. +#define DBG_ANY (0xFF)
  92426. +
  92427. +/** All debug messages off */
  92428. +#define DBG_OFF 0
  92429. +
  92430. +/** Prefix string for DWC_DEBUG print macros. */
  92431. +#define USB_DWC "DWC_otg: "
  92432. +
  92433. +/**
  92434. + * Print a debug message when the Global debug level variable contains
  92435. + * the bit defined in <code>lvl</code>.
  92436. + *
  92437. + * @param[in] lvl - Debug level, use one of the DBG_ constants above.
  92438. + * @param[in] x - like printf
  92439. + *
  92440. + * Example:<p>
  92441. + * <code>
  92442. + * DWC_DEBUGPL( DBG_ANY, "%s(%p)\n", __func__, _reg_base_addr);
  92443. + * </code>
  92444. + * <br>
  92445. + * results in:<br>
  92446. + * <code>
  92447. + * usb-DWC_otg: dwc_otg_cil_init(ca867000)
  92448. + * </code>
  92449. + */
  92450. +#ifdef DEBUG
  92451. +
  92452. +# define DWC_DEBUGPL(lvl, x...) do{ if ((lvl)&g_dbg_lvl)__DWC_DEBUG(USB_DWC x ); }while(0)
  92453. +# define DWC_DEBUGP(x...) DWC_DEBUGPL(DBG_ANY, x )
  92454. +
  92455. +# define CHK_DEBUG_LEVEL(level) ((level) & g_dbg_lvl)
  92456. +
  92457. +#else
  92458. +
  92459. +# define DWC_DEBUGPL(lvl, x...) do{}while(0)
  92460. +# define DWC_DEBUGP(x...)
  92461. +
  92462. +# define CHK_DEBUG_LEVEL(level) (0)
  92463. +
  92464. +#endif /*DEBUG*/
  92465. +#endif
  92466. diff -Nur linux-3.18.8/drivers/usb/host/dwc_otg/dwc_otg_driver.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_driver.c
  92467. --- linux-3.18.8/drivers/usb/host/dwc_otg/dwc_otg_driver.c 1970-01-01 01:00:00.000000000 +0100
  92468. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_driver.c 2015-03-05 14:40:16.557715806 +0100
  92469. @@ -0,0 +1,1749 @@
  92470. +/* ==========================================================================
  92471. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_driver.c $
  92472. + * $Revision: #92 $
  92473. + * $Date: 2012/08/10 $
  92474. + * $Change: 2047372 $
  92475. + *
  92476. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  92477. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  92478. + * otherwise expressly agreed to in writing between Synopsys and you.
  92479. + *
  92480. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  92481. + * any End User Software License Agreement or Agreement for Licensed Product
  92482. + * with Synopsys or any supplement thereto. You are permitted to use and
  92483. + * redistribute this Software in source and binary forms, with or without
  92484. + * modification, provided that redistributions of source code must retain this
  92485. + * notice. You may not view, use, disclose, copy or distribute this file or
  92486. + * any information contained herein except pursuant to this license grant from
  92487. + * Synopsys. If you do not agree with this notice, including the disclaimer
  92488. + * below, then you are not authorized to use the Software.
  92489. + *
  92490. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  92491. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  92492. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  92493. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  92494. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  92495. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  92496. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  92497. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  92498. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  92499. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  92500. + * DAMAGE.
  92501. + * ========================================================================== */
  92502. +
  92503. +/** @file
  92504. + * The dwc_otg_driver module provides the initialization and cleanup entry
  92505. + * points for the DWC_otg driver. This module will be dynamically installed
  92506. + * after Linux is booted using the insmod command. When the module is
  92507. + * installed, the dwc_otg_driver_init function is called. When the module is
  92508. + * removed (using rmmod), the dwc_otg_driver_cleanup function is called.
  92509. + *
  92510. + * This module also defines a data structure for the dwc_otg_driver, which is
  92511. + * used in conjunction with the standard ARM lm_device structure. These
  92512. + * structures allow the OTG driver to comply with the standard Linux driver
  92513. + * model in which devices and drivers are registered with a bus driver. This
  92514. + * has the benefit that Linux can expose attributes of the driver and device
  92515. + * in its special sysfs file system. Users can then read or write files in
  92516. + * this file system to perform diagnostics on the driver components or the
  92517. + * device.
  92518. + */
  92519. +
  92520. +#include "dwc_otg_os_dep.h"
  92521. +#include "dwc_os.h"
  92522. +#include "dwc_otg_dbg.h"
  92523. +#include "dwc_otg_driver.h"
  92524. +#include "dwc_otg_attr.h"
  92525. +#include "dwc_otg_core_if.h"
  92526. +#include "dwc_otg_pcd_if.h"
  92527. +#include "dwc_otg_hcd_if.h"
  92528. +#include "dwc_otg_fiq_fsm.h"
  92529. +
  92530. +#define DWC_DRIVER_VERSION "3.00a 10-AUG-2012"
  92531. +#define DWC_DRIVER_DESC "HS OTG USB Controller driver"
  92532. +
  92533. +bool microframe_schedule=true;
  92534. +
  92535. +static const char dwc_driver_name[] = "dwc_otg";
  92536. +
  92537. +
  92538. +extern int pcd_init(
  92539. +#ifdef LM_INTERFACE
  92540. + struct lm_device *_dev
  92541. +#elif defined(PCI_INTERFACE)
  92542. + struct pci_dev *_dev
  92543. +#elif defined(PLATFORM_INTERFACE)
  92544. + struct platform_device *dev
  92545. +#endif
  92546. + );
  92547. +extern int hcd_init(
  92548. +#ifdef LM_INTERFACE
  92549. + struct lm_device *_dev
  92550. +#elif defined(PCI_INTERFACE)
  92551. + struct pci_dev *_dev
  92552. +#elif defined(PLATFORM_INTERFACE)
  92553. + struct platform_device *dev
  92554. +#endif
  92555. + );
  92556. +
  92557. +extern int pcd_remove(
  92558. +#ifdef LM_INTERFACE
  92559. + struct lm_device *_dev
  92560. +#elif defined(PCI_INTERFACE)
  92561. + struct pci_dev *_dev
  92562. +#elif defined(PLATFORM_INTERFACE)
  92563. + struct platform_device *_dev
  92564. +#endif
  92565. + );
  92566. +
  92567. +extern void hcd_remove(
  92568. +#ifdef LM_INTERFACE
  92569. + struct lm_device *_dev
  92570. +#elif defined(PCI_INTERFACE)
  92571. + struct pci_dev *_dev
  92572. +#elif defined(PLATFORM_INTERFACE)
  92573. + struct platform_device *_dev
  92574. +#endif
  92575. + );
  92576. +
  92577. +extern void dwc_otg_adp_start(dwc_otg_core_if_t * core_if, uint8_t is_host);
  92578. +
  92579. +/*-------------------------------------------------------------------------*/
  92580. +/* Encapsulate the module parameter settings */
  92581. +
  92582. +struct dwc_otg_driver_module_params {
  92583. + int32_t opt;
  92584. + int32_t otg_cap;
  92585. + int32_t dma_enable;
  92586. + int32_t dma_desc_enable;
  92587. + int32_t dma_burst_size;
  92588. + int32_t speed;
  92589. + int32_t host_support_fs_ls_low_power;
  92590. + int32_t host_ls_low_power_phy_clk;
  92591. + int32_t enable_dynamic_fifo;
  92592. + int32_t data_fifo_size;
  92593. + int32_t dev_rx_fifo_size;
  92594. + int32_t dev_nperio_tx_fifo_size;
  92595. + uint32_t dev_perio_tx_fifo_size[MAX_PERIO_FIFOS];
  92596. + int32_t host_rx_fifo_size;
  92597. + int32_t host_nperio_tx_fifo_size;
  92598. + int32_t host_perio_tx_fifo_size;
  92599. + int32_t max_transfer_size;
  92600. + int32_t max_packet_count;
  92601. + int32_t host_channels;
  92602. + int32_t dev_endpoints;
  92603. + int32_t phy_type;
  92604. + int32_t phy_utmi_width;
  92605. + int32_t phy_ulpi_ddr;
  92606. + int32_t phy_ulpi_ext_vbus;
  92607. + int32_t i2c_enable;
  92608. + int32_t ulpi_fs_ls;
  92609. + int32_t ts_dline;
  92610. + int32_t en_multiple_tx_fifo;
  92611. + uint32_t dev_tx_fifo_size[MAX_TX_FIFOS];
  92612. + uint32_t thr_ctl;
  92613. + uint32_t tx_thr_length;
  92614. + uint32_t rx_thr_length;
  92615. + int32_t pti_enable;
  92616. + int32_t mpi_enable;
  92617. + int32_t lpm_enable;
  92618. + int32_t ic_usb_cap;
  92619. + int32_t ahb_thr_ratio;
  92620. + int32_t power_down;
  92621. + int32_t reload_ctl;
  92622. + int32_t dev_out_nak;
  92623. + int32_t cont_on_bna;
  92624. + int32_t ahb_single;
  92625. + int32_t otg_ver;
  92626. + int32_t adp_enable;
  92627. +};
  92628. +
  92629. +static struct dwc_otg_driver_module_params dwc_otg_module_params = {
  92630. + .opt = -1,
  92631. + .otg_cap = -1,
  92632. + .dma_enable = -1,
  92633. + .dma_desc_enable = -1,
  92634. + .dma_burst_size = -1,
  92635. + .speed = -1,
  92636. + .host_support_fs_ls_low_power = -1,
  92637. + .host_ls_low_power_phy_clk = -1,
  92638. + .enable_dynamic_fifo = -1,
  92639. + .data_fifo_size = -1,
  92640. + .dev_rx_fifo_size = -1,
  92641. + .dev_nperio_tx_fifo_size = -1,
  92642. + .dev_perio_tx_fifo_size = {
  92643. + /* dev_perio_tx_fifo_size_1 */
  92644. + -1,
  92645. + -1,
  92646. + -1,
  92647. + -1,
  92648. + -1,
  92649. + -1,
  92650. + -1,
  92651. + -1,
  92652. + -1,
  92653. + -1,
  92654. + -1,
  92655. + -1,
  92656. + -1,
  92657. + -1,
  92658. + -1
  92659. + /* 15 */
  92660. + },
  92661. + .host_rx_fifo_size = -1,
  92662. + .host_nperio_tx_fifo_size = -1,
  92663. + .host_perio_tx_fifo_size = -1,
  92664. + .max_transfer_size = -1,
  92665. + .max_packet_count = -1,
  92666. + .host_channels = -1,
  92667. + .dev_endpoints = -1,
  92668. + .phy_type = -1,
  92669. + .phy_utmi_width = -1,
  92670. + .phy_ulpi_ddr = -1,
  92671. + .phy_ulpi_ext_vbus = -1,
  92672. + .i2c_enable = -1,
  92673. + .ulpi_fs_ls = -1,
  92674. + .ts_dline = -1,
  92675. + .en_multiple_tx_fifo = -1,
  92676. + .dev_tx_fifo_size = {
  92677. + /* dev_tx_fifo_size */
  92678. + -1,
  92679. + -1,
  92680. + -1,
  92681. + -1,
  92682. + -1,
  92683. + -1,
  92684. + -1,
  92685. + -1,
  92686. + -1,
  92687. + -1,
  92688. + -1,
  92689. + -1,
  92690. + -1,
  92691. + -1,
  92692. + -1
  92693. + /* 15 */
  92694. + },
  92695. + .thr_ctl = -1,
  92696. + .tx_thr_length = -1,
  92697. + .rx_thr_length = -1,
  92698. + .pti_enable = -1,
  92699. + .mpi_enable = -1,
  92700. + .lpm_enable = 0,
  92701. + .ic_usb_cap = -1,
  92702. + .ahb_thr_ratio = -1,
  92703. + .power_down = -1,
  92704. + .reload_ctl = -1,
  92705. + .dev_out_nak = -1,
  92706. + .cont_on_bna = -1,
  92707. + .ahb_single = -1,
  92708. + .otg_ver = -1,
  92709. + .adp_enable = -1,
  92710. +};
  92711. +
  92712. +//Global variable to switch the fiq fix on or off
  92713. +bool fiq_enable = 1;
  92714. +// Global variable to enable the split transaction fix
  92715. +bool fiq_fsm_enable = true;
  92716. +//Bulk split-transaction NAK holdoff in microframes
  92717. +uint16_t nak_holdoff = 8;
  92718. +
  92719. +unsigned short fiq_fsm_mask = 0x07;
  92720. +
  92721. +/**
  92722. + * This function shows the Driver Version.
  92723. + */
  92724. +static ssize_t version_show(struct device_driver *dev, char *buf)
  92725. +{
  92726. + return snprintf(buf, sizeof(DWC_DRIVER_VERSION) + 2, "%s\n",
  92727. + DWC_DRIVER_VERSION);
  92728. +}
  92729. +
  92730. +static DRIVER_ATTR(version, S_IRUGO, version_show, NULL);
  92731. +
  92732. +/**
  92733. + * Global Debug Level Mask.
  92734. + */
  92735. +uint32_t g_dbg_lvl = 0; /* OFF */
  92736. +
  92737. +/**
  92738. + * This function shows the driver Debug Level.
  92739. + */
  92740. +static ssize_t dbg_level_show(struct device_driver *drv, char *buf)
  92741. +{
  92742. + return sprintf(buf, "0x%0x\n", g_dbg_lvl);
  92743. +}
  92744. +
  92745. +/**
  92746. + * This function stores the driver Debug Level.
  92747. + */
  92748. +static ssize_t dbg_level_store(struct device_driver *drv, const char *buf,
  92749. + size_t count)
  92750. +{
  92751. + g_dbg_lvl = simple_strtoul(buf, NULL, 16);
  92752. + return count;
  92753. +}
  92754. +
  92755. +static DRIVER_ATTR(debuglevel, S_IRUGO | S_IWUSR, dbg_level_show,
  92756. + dbg_level_store);
  92757. +
  92758. +/**
  92759. + * This function is called during module intialization
  92760. + * to pass module parameters to the DWC_OTG CORE.
  92761. + */
  92762. +static int set_parameters(dwc_otg_core_if_t * core_if)
  92763. +{
  92764. + int retval = 0;
  92765. + int i;
  92766. +
  92767. + if (dwc_otg_module_params.otg_cap != -1) {
  92768. + retval +=
  92769. + dwc_otg_set_param_otg_cap(core_if,
  92770. + dwc_otg_module_params.otg_cap);
  92771. + }
  92772. + if (dwc_otg_module_params.dma_enable != -1) {
  92773. + retval +=
  92774. + dwc_otg_set_param_dma_enable(core_if,
  92775. + dwc_otg_module_params.
  92776. + dma_enable);
  92777. + }
  92778. + if (dwc_otg_module_params.dma_desc_enable != -1) {
  92779. + retval +=
  92780. + dwc_otg_set_param_dma_desc_enable(core_if,
  92781. + dwc_otg_module_params.
  92782. + dma_desc_enable);
  92783. + }
  92784. + if (dwc_otg_module_params.opt != -1) {
  92785. + retval +=
  92786. + dwc_otg_set_param_opt(core_if, dwc_otg_module_params.opt);
  92787. + }
  92788. + if (dwc_otg_module_params.dma_burst_size != -1) {
  92789. + retval +=
  92790. + dwc_otg_set_param_dma_burst_size(core_if,
  92791. + dwc_otg_module_params.
  92792. + dma_burst_size);
  92793. + }
  92794. + if (dwc_otg_module_params.host_support_fs_ls_low_power != -1) {
  92795. + retval +=
  92796. + dwc_otg_set_param_host_support_fs_ls_low_power(core_if,
  92797. + dwc_otg_module_params.
  92798. + host_support_fs_ls_low_power);
  92799. + }
  92800. + if (dwc_otg_module_params.enable_dynamic_fifo != -1) {
  92801. + retval +=
  92802. + dwc_otg_set_param_enable_dynamic_fifo(core_if,
  92803. + dwc_otg_module_params.
  92804. + enable_dynamic_fifo);
  92805. + }
  92806. + if (dwc_otg_module_params.data_fifo_size != -1) {
  92807. + retval +=
  92808. + dwc_otg_set_param_data_fifo_size(core_if,
  92809. + dwc_otg_module_params.
  92810. + data_fifo_size);
  92811. + }
  92812. + if (dwc_otg_module_params.dev_rx_fifo_size != -1) {
  92813. + retval +=
  92814. + dwc_otg_set_param_dev_rx_fifo_size(core_if,
  92815. + dwc_otg_module_params.
  92816. + dev_rx_fifo_size);
  92817. + }
  92818. + if (dwc_otg_module_params.dev_nperio_tx_fifo_size != -1) {
  92819. + retval +=
  92820. + dwc_otg_set_param_dev_nperio_tx_fifo_size(core_if,
  92821. + dwc_otg_module_params.
  92822. + dev_nperio_tx_fifo_size);
  92823. + }
  92824. + if (dwc_otg_module_params.host_rx_fifo_size != -1) {
  92825. + retval +=
  92826. + dwc_otg_set_param_host_rx_fifo_size(core_if,
  92827. + dwc_otg_module_params.host_rx_fifo_size);
  92828. + }
  92829. + if (dwc_otg_module_params.host_nperio_tx_fifo_size != -1) {
  92830. + retval +=
  92831. + dwc_otg_set_param_host_nperio_tx_fifo_size(core_if,
  92832. + dwc_otg_module_params.
  92833. + host_nperio_tx_fifo_size);
  92834. + }
  92835. + if (dwc_otg_module_params.host_perio_tx_fifo_size != -1) {
  92836. + retval +=
  92837. + dwc_otg_set_param_host_perio_tx_fifo_size(core_if,
  92838. + dwc_otg_module_params.
  92839. + host_perio_tx_fifo_size);
  92840. + }
  92841. + if (dwc_otg_module_params.max_transfer_size != -1) {
  92842. + retval +=
  92843. + dwc_otg_set_param_max_transfer_size(core_if,
  92844. + dwc_otg_module_params.
  92845. + max_transfer_size);
  92846. + }
  92847. + if (dwc_otg_module_params.max_packet_count != -1) {
  92848. + retval +=
  92849. + dwc_otg_set_param_max_packet_count(core_if,
  92850. + dwc_otg_module_params.
  92851. + max_packet_count);
  92852. + }
  92853. + if (dwc_otg_module_params.host_channels != -1) {
  92854. + retval +=
  92855. + dwc_otg_set_param_host_channels(core_if,
  92856. + dwc_otg_module_params.
  92857. + host_channels);
  92858. + }
  92859. + if (dwc_otg_module_params.dev_endpoints != -1) {
  92860. + retval +=
  92861. + dwc_otg_set_param_dev_endpoints(core_if,
  92862. + dwc_otg_module_params.
  92863. + dev_endpoints);
  92864. + }
  92865. + if (dwc_otg_module_params.phy_type != -1) {
  92866. + retval +=
  92867. + dwc_otg_set_param_phy_type(core_if,
  92868. + dwc_otg_module_params.phy_type);
  92869. + }
  92870. + if (dwc_otg_module_params.speed != -1) {
  92871. + retval +=
  92872. + dwc_otg_set_param_speed(core_if,
  92873. + dwc_otg_module_params.speed);
  92874. + }
  92875. + if (dwc_otg_module_params.host_ls_low_power_phy_clk != -1) {
  92876. + retval +=
  92877. + dwc_otg_set_param_host_ls_low_power_phy_clk(core_if,
  92878. + dwc_otg_module_params.
  92879. + host_ls_low_power_phy_clk);
  92880. + }
  92881. + if (dwc_otg_module_params.phy_ulpi_ddr != -1) {
  92882. + retval +=
  92883. + dwc_otg_set_param_phy_ulpi_ddr(core_if,
  92884. + dwc_otg_module_params.
  92885. + phy_ulpi_ddr);
  92886. + }
  92887. + if (dwc_otg_module_params.phy_ulpi_ext_vbus != -1) {
  92888. + retval +=
  92889. + dwc_otg_set_param_phy_ulpi_ext_vbus(core_if,
  92890. + dwc_otg_module_params.
  92891. + phy_ulpi_ext_vbus);
  92892. + }
  92893. + if (dwc_otg_module_params.phy_utmi_width != -1) {
  92894. + retval +=
  92895. + dwc_otg_set_param_phy_utmi_width(core_if,
  92896. + dwc_otg_module_params.
  92897. + phy_utmi_width);
  92898. + }
  92899. + if (dwc_otg_module_params.ulpi_fs_ls != -1) {
  92900. + retval +=
  92901. + dwc_otg_set_param_ulpi_fs_ls(core_if,
  92902. + dwc_otg_module_params.ulpi_fs_ls);
  92903. + }
  92904. + if (dwc_otg_module_params.ts_dline != -1) {
  92905. + retval +=
  92906. + dwc_otg_set_param_ts_dline(core_if,
  92907. + dwc_otg_module_params.ts_dline);
  92908. + }
  92909. + if (dwc_otg_module_params.i2c_enable != -1) {
  92910. + retval +=
  92911. + dwc_otg_set_param_i2c_enable(core_if,
  92912. + dwc_otg_module_params.
  92913. + i2c_enable);
  92914. + }
  92915. + if (dwc_otg_module_params.en_multiple_tx_fifo != -1) {
  92916. + retval +=
  92917. + dwc_otg_set_param_en_multiple_tx_fifo(core_if,
  92918. + dwc_otg_module_params.
  92919. + en_multiple_tx_fifo);
  92920. + }
  92921. + for (i = 0; i < 15; i++) {
  92922. + if (dwc_otg_module_params.dev_perio_tx_fifo_size[i] != -1) {
  92923. + retval +=
  92924. + dwc_otg_set_param_dev_perio_tx_fifo_size(core_if,
  92925. + dwc_otg_module_params.
  92926. + dev_perio_tx_fifo_size
  92927. + [i], i);
  92928. + }
  92929. + }
  92930. +
  92931. + for (i = 0; i < 15; i++) {
  92932. + if (dwc_otg_module_params.dev_tx_fifo_size[i] != -1) {
  92933. + retval += dwc_otg_set_param_dev_tx_fifo_size(core_if,
  92934. + dwc_otg_module_params.
  92935. + dev_tx_fifo_size
  92936. + [i], i);
  92937. + }
  92938. + }
  92939. + if (dwc_otg_module_params.thr_ctl != -1) {
  92940. + retval +=
  92941. + dwc_otg_set_param_thr_ctl(core_if,
  92942. + dwc_otg_module_params.thr_ctl);
  92943. + }
  92944. + if (dwc_otg_module_params.mpi_enable != -1) {
  92945. + retval +=
  92946. + dwc_otg_set_param_mpi_enable(core_if,
  92947. + dwc_otg_module_params.
  92948. + mpi_enable);
  92949. + }
  92950. + if (dwc_otg_module_params.pti_enable != -1) {
  92951. + retval +=
  92952. + dwc_otg_set_param_pti_enable(core_if,
  92953. + dwc_otg_module_params.
  92954. + pti_enable);
  92955. + }
  92956. + if (dwc_otg_module_params.lpm_enable != -1) {
  92957. + retval +=
  92958. + dwc_otg_set_param_lpm_enable(core_if,
  92959. + dwc_otg_module_params.
  92960. + lpm_enable);
  92961. + }
  92962. + if (dwc_otg_module_params.ic_usb_cap != -1) {
  92963. + retval +=
  92964. + dwc_otg_set_param_ic_usb_cap(core_if,
  92965. + dwc_otg_module_params.
  92966. + ic_usb_cap);
  92967. + }
  92968. + if (dwc_otg_module_params.tx_thr_length != -1) {
  92969. + retval +=
  92970. + dwc_otg_set_param_tx_thr_length(core_if,
  92971. + dwc_otg_module_params.tx_thr_length);
  92972. + }
  92973. + if (dwc_otg_module_params.rx_thr_length != -1) {
  92974. + retval +=
  92975. + dwc_otg_set_param_rx_thr_length(core_if,
  92976. + dwc_otg_module_params.
  92977. + rx_thr_length);
  92978. + }
  92979. + if (dwc_otg_module_params.ahb_thr_ratio != -1) {
  92980. + retval +=
  92981. + dwc_otg_set_param_ahb_thr_ratio(core_if,
  92982. + dwc_otg_module_params.ahb_thr_ratio);
  92983. + }
  92984. + if (dwc_otg_module_params.power_down != -1) {
  92985. + retval +=
  92986. + dwc_otg_set_param_power_down(core_if,
  92987. + dwc_otg_module_params.power_down);
  92988. + }
  92989. + if (dwc_otg_module_params.reload_ctl != -1) {
  92990. + retval +=
  92991. + dwc_otg_set_param_reload_ctl(core_if,
  92992. + dwc_otg_module_params.reload_ctl);
  92993. + }
  92994. +
  92995. + if (dwc_otg_module_params.dev_out_nak != -1) {
  92996. + retval +=
  92997. + dwc_otg_set_param_dev_out_nak(core_if,
  92998. + dwc_otg_module_params.dev_out_nak);
  92999. + }
  93000. +
  93001. + if (dwc_otg_module_params.cont_on_bna != -1) {
  93002. + retval +=
  93003. + dwc_otg_set_param_cont_on_bna(core_if,
  93004. + dwc_otg_module_params.cont_on_bna);
  93005. + }
  93006. +
  93007. + if (dwc_otg_module_params.ahb_single != -1) {
  93008. + retval +=
  93009. + dwc_otg_set_param_ahb_single(core_if,
  93010. + dwc_otg_module_params.ahb_single);
  93011. + }
  93012. +
  93013. + if (dwc_otg_module_params.otg_ver != -1) {
  93014. + retval +=
  93015. + dwc_otg_set_param_otg_ver(core_if,
  93016. + dwc_otg_module_params.otg_ver);
  93017. + }
  93018. + if (dwc_otg_module_params.adp_enable != -1) {
  93019. + retval +=
  93020. + dwc_otg_set_param_adp_enable(core_if,
  93021. + dwc_otg_module_params.
  93022. + adp_enable);
  93023. + }
  93024. + return retval;
  93025. +}
  93026. +
  93027. +/**
  93028. + * This function is the top level interrupt handler for the Common
  93029. + * (Device and host modes) interrupts.
  93030. + */
  93031. +static irqreturn_t dwc_otg_common_irq(int irq, void *dev)
  93032. +{
  93033. + int32_t retval = IRQ_NONE;
  93034. +
  93035. + retval = dwc_otg_handle_common_intr(dev);
  93036. + if (retval != 0) {
  93037. + S3C2410X_CLEAR_EINTPEND();
  93038. + }
  93039. + return IRQ_RETVAL(retval);
  93040. +}
  93041. +
  93042. +/**
  93043. + * This function is called when a lm_device is unregistered with the
  93044. + * dwc_otg_driver. This happens, for example, when the rmmod command is
  93045. + * executed. The device may or may not be electrically present. If it is
  93046. + * present, the driver stops device processing. Any resources used on behalf
  93047. + * of this device are freed.
  93048. + *
  93049. + * @param _dev
  93050. + */
  93051. +#ifdef LM_INTERFACE
  93052. +#define REM_RETVAL(n)
  93053. +static void dwc_otg_driver_remove( struct lm_device *_dev )
  93054. +{ dwc_otg_device_t *otg_dev = lm_get_drvdata(_dev);
  93055. +#elif defined(PCI_INTERFACE)
  93056. +#define REM_RETVAL(n)
  93057. +static void dwc_otg_driver_remove( struct pci_dev *_dev )
  93058. +{ dwc_otg_device_t *otg_dev = pci_get_drvdata(_dev);
  93059. +#elif defined(PLATFORM_INTERFACE)
  93060. +#define REM_RETVAL(n) n
  93061. +static int dwc_otg_driver_remove( struct platform_device *_dev )
  93062. +{ dwc_otg_device_t *otg_dev = platform_get_drvdata(_dev);
  93063. +#endif
  93064. +
  93065. + DWC_DEBUGPL(DBG_ANY, "%s(%p) otg_dev %p\n", __func__, _dev, otg_dev);
  93066. +
  93067. + if (!otg_dev) {
  93068. + /* Memory allocation for the dwc_otg_device failed. */
  93069. + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev NULL!\n", __func__);
  93070. + return REM_RETVAL(-ENOMEM);
  93071. + }
  93072. +#ifndef DWC_DEVICE_ONLY
  93073. + if (otg_dev->hcd) {
  93074. + hcd_remove(_dev);
  93075. + } else {
  93076. + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev->hcd NULL!\n", __func__);
  93077. + return REM_RETVAL(-EINVAL);
  93078. + }
  93079. +#endif
  93080. +
  93081. +#ifndef DWC_HOST_ONLY
  93082. + if (otg_dev->pcd) {
  93083. + pcd_remove(_dev);
  93084. + } else {
  93085. + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev->pcd NULL!\n", __func__);
  93086. + return REM_RETVAL(-EINVAL);
  93087. + }
  93088. +#endif
  93089. + /*
  93090. + * Free the IRQ
  93091. + */
  93092. + if (otg_dev->common_irq_installed) {
  93093. +#ifdef PLATFORM_INTERFACE
  93094. + free_irq(platform_get_irq(_dev, 0), otg_dev);
  93095. +#else
  93096. + free_irq(_dev->irq, otg_dev);
  93097. +#endif
  93098. + } else {
  93099. + DWC_DEBUGPL(DBG_ANY, "%s: There is no installed irq!\n", __func__);
  93100. + return REM_RETVAL(-ENXIO);
  93101. + }
  93102. +
  93103. + if (otg_dev->core_if) {
  93104. + dwc_otg_cil_remove(otg_dev->core_if);
  93105. + } else {
  93106. + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev->core_if NULL!\n", __func__);
  93107. + return REM_RETVAL(-ENXIO);
  93108. + }
  93109. +
  93110. + /*
  93111. + * Remove the device attributes
  93112. + */
  93113. + dwc_otg_attr_remove(_dev);
  93114. +
  93115. + /*
  93116. + * Return the memory.
  93117. + */
  93118. + if (otg_dev->os_dep.base) {
  93119. + iounmap(otg_dev->os_dep.base);
  93120. + }
  93121. + DWC_FREE(otg_dev);
  93122. +
  93123. + /*
  93124. + * Clear the drvdata pointer.
  93125. + */
  93126. +#ifdef LM_INTERFACE
  93127. + lm_set_drvdata(_dev, 0);
  93128. +#elif defined(PCI_INTERFACE)
  93129. + release_mem_region(otg_dev->os_dep.rsrc_start,
  93130. + otg_dev->os_dep.rsrc_len);
  93131. + pci_set_drvdata(_dev, 0);
  93132. +#elif defined(PLATFORM_INTERFACE)
  93133. + platform_set_drvdata(_dev, 0);
  93134. +#endif
  93135. + return REM_RETVAL(0);
  93136. +}
  93137. +
  93138. +/**
  93139. + * This function is called when an lm_device is bound to a
  93140. + * dwc_otg_driver. It creates the driver components required to
  93141. + * control the device (CIL, HCD, and PCD) and it initializes the
  93142. + * device. The driver components are stored in a dwc_otg_device
  93143. + * structure. A reference to the dwc_otg_device is saved in the
  93144. + * lm_device. This allows the driver to access the dwc_otg_device
  93145. + * structure on subsequent calls to driver methods for this device.
  93146. + *
  93147. + * @param _dev Bus device
  93148. + */
  93149. +static int dwc_otg_driver_probe(
  93150. +#ifdef LM_INTERFACE
  93151. + struct lm_device *_dev
  93152. +#elif defined(PCI_INTERFACE)
  93153. + struct pci_dev *_dev,
  93154. + const struct pci_device_id *id
  93155. +#elif defined(PLATFORM_INTERFACE)
  93156. + struct platform_device *_dev
  93157. +#endif
  93158. + )
  93159. +{
  93160. + int retval = 0;
  93161. + dwc_otg_device_t *dwc_otg_device;
  93162. + int devirq;
  93163. +
  93164. + dev_dbg(&_dev->dev, "dwc_otg_driver_probe(%p)\n", _dev);
  93165. +#ifdef LM_INTERFACE
  93166. + dev_dbg(&_dev->dev, "start=0x%08x\n", (unsigned)_dev->resource.start);
  93167. +#elif defined(PCI_INTERFACE)
  93168. + if (!id) {
  93169. + DWC_ERROR("Invalid pci_device_id %p", id);
  93170. + return -EINVAL;
  93171. + }
  93172. +
  93173. + if (!_dev || (pci_enable_device(_dev) < 0)) {
  93174. + DWC_ERROR("Invalid pci_device %p", _dev);
  93175. + return -ENODEV;
  93176. + }
  93177. + dev_dbg(&_dev->dev, "start=0x%08x\n", (unsigned)pci_resource_start(_dev,0));
  93178. + /* other stuff needed as well? */
  93179. +
  93180. +#elif defined(PLATFORM_INTERFACE)
  93181. + dev_dbg(&_dev->dev, "start=0x%08x (len 0x%x)\n",
  93182. + (unsigned)_dev->resource->start,
  93183. + (unsigned)(_dev->resource->end - _dev->resource->start));
  93184. +#endif
  93185. +
  93186. + dwc_otg_device = DWC_ALLOC(sizeof(dwc_otg_device_t));
  93187. +
  93188. + if (!dwc_otg_device) {
  93189. + dev_err(&_dev->dev, "kmalloc of dwc_otg_device failed\n");
  93190. + return -ENOMEM;
  93191. + }
  93192. +
  93193. + memset(dwc_otg_device, 0, sizeof(*dwc_otg_device));
  93194. + dwc_otg_device->os_dep.reg_offset = 0xFFFFFFFF;
  93195. +
  93196. + /*
  93197. + * Map the DWC_otg Core memory into virtual address space.
  93198. + */
  93199. +#ifdef LM_INTERFACE
  93200. + dwc_otg_device->os_dep.base = ioremap(_dev->resource.start, SZ_256K);
  93201. +
  93202. + if (!dwc_otg_device->os_dep.base) {
  93203. + dev_err(&_dev->dev, "ioremap() failed\n");
  93204. + DWC_FREE(dwc_otg_device);
  93205. + return -ENOMEM;
  93206. + }
  93207. + dev_dbg(&_dev->dev, "base=0x%08x\n",
  93208. + (unsigned)dwc_otg_device->os_dep.base);
  93209. +#elif defined(PCI_INTERFACE)
  93210. + _dev->current_state = PCI_D0;
  93211. + _dev->dev.power.power_state = PMSG_ON;
  93212. +
  93213. + if (!_dev->irq) {
  93214. + DWC_ERROR("Found HC with no IRQ. Check BIOS/PCI %s setup!",
  93215. + pci_name(_dev));
  93216. + iounmap(dwc_otg_device->os_dep.base);
  93217. + DWC_FREE(dwc_otg_device);
  93218. + return -ENODEV;
  93219. + }
  93220. +
  93221. + dwc_otg_device->os_dep.rsrc_start = pci_resource_start(_dev, 0);
  93222. + dwc_otg_device->os_dep.rsrc_len = pci_resource_len(_dev, 0);
  93223. + DWC_DEBUGPL(DBG_ANY, "PCI resource: start=%08x, len=%08x\n",
  93224. + (unsigned)dwc_otg_device->os_dep.rsrc_start,
  93225. + (unsigned)dwc_otg_device->os_dep.rsrc_len);
  93226. + if (!request_mem_region
  93227. + (dwc_otg_device->os_dep.rsrc_start, dwc_otg_device->os_dep.rsrc_len,
  93228. + "dwc_otg")) {
  93229. + dev_dbg(&_dev->dev, "error requesting memory\n");
  93230. + iounmap(dwc_otg_device->os_dep.base);
  93231. + DWC_FREE(dwc_otg_device);
  93232. + return -EFAULT;
  93233. + }
  93234. +
  93235. + dwc_otg_device->os_dep.base =
  93236. + ioremap_nocache(dwc_otg_device->os_dep.rsrc_start,
  93237. + dwc_otg_device->os_dep.rsrc_len);
  93238. + if (dwc_otg_device->os_dep.base == NULL) {
  93239. + dev_dbg(&_dev->dev, "error mapping memory\n");
  93240. + release_mem_region(dwc_otg_device->os_dep.rsrc_start,
  93241. + dwc_otg_device->os_dep.rsrc_len);
  93242. + iounmap(dwc_otg_device->os_dep.base);
  93243. + DWC_FREE(dwc_otg_device);
  93244. + return -EFAULT;
  93245. + }
  93246. + dev_dbg(&_dev->dev, "base=0x%p (before adjust) \n",
  93247. + dwc_otg_device->os_dep.base);
  93248. + dwc_otg_device->os_dep.base = (char *)dwc_otg_device->os_dep.base;
  93249. + dev_dbg(&_dev->dev, "base=0x%p (after adjust) \n",
  93250. + dwc_otg_device->os_dep.base);
  93251. + dev_dbg(&_dev->dev, "%s: mapped PA 0x%x to VA 0x%p\n", __func__,
  93252. + (unsigned)dwc_otg_device->os_dep.rsrc_start,
  93253. + dwc_otg_device->os_dep.base);
  93254. +
  93255. + pci_set_master(_dev);
  93256. + pci_set_drvdata(_dev, dwc_otg_device);
  93257. +#elif defined(PLATFORM_INTERFACE)
  93258. + DWC_DEBUGPL(DBG_ANY,"Platform resource: start=%08x, len=%08x\n",
  93259. + _dev->resource->start,
  93260. + _dev->resource->end - _dev->resource->start + 1);
  93261. +#if 1
  93262. + if (!request_mem_region(_dev->resource[0].start,
  93263. + _dev->resource[0].end - _dev->resource[0].start + 1,
  93264. + "dwc_otg")) {
  93265. + dev_dbg(&_dev->dev, "error reserving mapped memory\n");
  93266. + retval = -EFAULT;
  93267. + goto fail;
  93268. + }
  93269. +
  93270. + dwc_otg_device->os_dep.base = ioremap_nocache(_dev->resource[0].start,
  93271. + _dev->resource[0].end -
  93272. + _dev->resource[0].start+1);
  93273. + if (fiq_enable)
  93274. + {
  93275. + if (!request_mem_region(_dev->resource[1].start,
  93276. + _dev->resource[1].end - _dev->resource[1].start + 1,
  93277. + "dwc_otg")) {
  93278. + dev_dbg(&_dev->dev, "error reserving mapped memory\n");
  93279. + retval = -EFAULT;
  93280. + goto fail;
  93281. + }
  93282. +
  93283. + dwc_otg_device->os_dep.mphi_base = ioremap_nocache(_dev->resource[1].start,
  93284. + _dev->resource[1].end -
  93285. + _dev->resource[1].start + 1);
  93286. + }
  93287. +
  93288. +#else
  93289. + {
  93290. + struct map_desc desc = {
  93291. + .virtual = IO_ADDRESS((unsigned)_dev->resource->start),
  93292. + .pfn = __phys_to_pfn((unsigned)_dev->resource->start),
  93293. + .length = SZ_128K,
  93294. + .type = MT_DEVICE
  93295. + };
  93296. + iotable_init(&desc, 1);
  93297. + dwc_otg_device->os_dep.base = (void *)desc.virtual;
  93298. + }
  93299. +#endif
  93300. + if (!dwc_otg_device->os_dep.base) {
  93301. + dev_err(&_dev->dev, "ioremap() failed\n");
  93302. + retval = -ENOMEM;
  93303. + goto fail;
  93304. + }
  93305. + dev_dbg(&_dev->dev, "base=0x%08x\n",
  93306. + (unsigned)dwc_otg_device->os_dep.base);
  93307. +#endif
  93308. +
  93309. + /*
  93310. + * Initialize driver data to point to the global DWC_otg
  93311. + * Device structure.
  93312. + */
  93313. +#ifdef LM_INTERFACE
  93314. + lm_set_drvdata(_dev, dwc_otg_device);
  93315. +#elif defined(PLATFORM_INTERFACE)
  93316. + platform_set_drvdata(_dev, dwc_otg_device);
  93317. +#endif
  93318. + dev_dbg(&_dev->dev, "dwc_otg_device=0x%p\n", dwc_otg_device);
  93319. +
  93320. + dwc_otg_device->core_if = dwc_otg_cil_init(dwc_otg_device->os_dep.base);
  93321. + DWC_DEBUGPL(DBG_HCDV, "probe of device %p given core_if %p\n",
  93322. + dwc_otg_device, dwc_otg_device->core_if);//GRAYG
  93323. +
  93324. + if (!dwc_otg_device->core_if) {
  93325. + dev_err(&_dev->dev, "CIL initialization failed!\n");
  93326. + retval = -ENOMEM;
  93327. + goto fail;
  93328. + }
  93329. +
  93330. + dev_dbg(&_dev->dev, "Calling get_gsnpsid\n");
  93331. + /*
  93332. + * Attempt to ensure this device is really a DWC_otg Controller.
  93333. + * Read and verify the SNPSID register contents. The value should be
  93334. + * 0x45F42XXX or 0x45F42XXX, which corresponds to either "OT2" or "OTG3",
  93335. + * as in "OTG version 2.XX" or "OTG version 3.XX".
  93336. + */
  93337. +
  93338. + if (((dwc_otg_get_gsnpsid(dwc_otg_device->core_if) & 0xFFFFF000) != 0x4F542000) &&
  93339. + ((dwc_otg_get_gsnpsid(dwc_otg_device->core_if) & 0xFFFFF000) != 0x4F543000)) {
  93340. + dev_err(&_dev->dev, "Bad value for SNPSID: 0x%08x\n",
  93341. + dwc_otg_get_gsnpsid(dwc_otg_device->core_if));
  93342. + retval = -EINVAL;
  93343. + goto fail;
  93344. + }
  93345. +
  93346. + /*
  93347. + * Validate parameter values.
  93348. + */
  93349. + dev_dbg(&_dev->dev, "Calling set_parameters\n");
  93350. + if (set_parameters(dwc_otg_device->core_if)) {
  93351. + retval = -EINVAL;
  93352. + goto fail;
  93353. + }
  93354. +
  93355. + /*
  93356. + * Create Device Attributes in sysfs
  93357. + */
  93358. + dev_dbg(&_dev->dev, "Calling attr_create\n");
  93359. + dwc_otg_attr_create(_dev);
  93360. +
  93361. + /*
  93362. + * Disable the global interrupt until all the interrupt
  93363. + * handlers are installed.
  93364. + */
  93365. + dev_dbg(&_dev->dev, "Calling disable_global_interrupts\n");
  93366. + dwc_otg_disable_global_interrupts(dwc_otg_device->core_if);
  93367. +
  93368. + /*
  93369. + * Install the interrupt handler for the common interrupts before
  93370. + * enabling common interrupts in core_init below.
  93371. + */
  93372. +
  93373. +#if defined(PLATFORM_INTERFACE)
  93374. + devirq = platform_get_irq(_dev, fiq_enable ? 0 : 1);
  93375. +#else
  93376. + devirq = _dev->irq;
  93377. +#endif
  93378. + DWC_DEBUGPL(DBG_CIL, "registering (common) handler for irq%d\n",
  93379. + devirq);
  93380. + dev_dbg(&_dev->dev, "Calling request_irq(%d)\n", devirq);
  93381. + retval = request_irq(devirq, dwc_otg_common_irq,
  93382. + IRQF_SHARED,
  93383. + "dwc_otg", dwc_otg_device);
  93384. + if (retval) {
  93385. + DWC_ERROR("request of irq%d failed\n", devirq);
  93386. + retval = -EBUSY;
  93387. + goto fail;
  93388. + } else {
  93389. + dwc_otg_device->common_irq_installed = 1;
  93390. + }
  93391. +
  93392. +#ifndef IRQF_TRIGGER_LOW
  93393. +#if defined(LM_INTERFACE) || defined(PLATFORM_INTERFACE)
  93394. + dev_dbg(&_dev->dev, "Calling set_irq_type\n");
  93395. + set_irq_type(devirq,
  93396. +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30))
  93397. + IRQT_LOW
  93398. +#else
  93399. + IRQ_TYPE_LEVEL_LOW
  93400. +#endif
  93401. + );
  93402. +#endif
  93403. +#endif /*IRQF_TRIGGER_LOW*/
  93404. +
  93405. + /*
  93406. + * Initialize the DWC_otg core.
  93407. + */
  93408. + dev_dbg(&_dev->dev, "Calling dwc_otg_core_init\n");
  93409. + dwc_otg_core_init(dwc_otg_device->core_if);
  93410. +
  93411. +#ifndef DWC_HOST_ONLY
  93412. + /*
  93413. + * Initialize the PCD
  93414. + */
  93415. + dev_dbg(&_dev->dev, "Calling pcd_init\n");
  93416. + retval = pcd_init(_dev);
  93417. + if (retval != 0) {
  93418. + DWC_ERROR("pcd_init failed\n");
  93419. + dwc_otg_device->pcd = NULL;
  93420. + goto fail;
  93421. + }
  93422. +#endif
  93423. +#ifndef DWC_DEVICE_ONLY
  93424. + /*
  93425. + * Initialize the HCD
  93426. + */
  93427. + dev_dbg(&_dev->dev, "Calling hcd_init\n");
  93428. + retval = hcd_init(_dev);
  93429. + if (retval != 0) {
  93430. + DWC_ERROR("hcd_init failed\n");
  93431. + dwc_otg_device->hcd = NULL;
  93432. + goto fail;
  93433. + }
  93434. +#endif
  93435. + /* Recover from drvdata having been overwritten by hcd_init() */
  93436. +#ifdef LM_INTERFACE
  93437. + lm_set_drvdata(_dev, dwc_otg_device);
  93438. +#elif defined(PLATFORM_INTERFACE)
  93439. + platform_set_drvdata(_dev, dwc_otg_device);
  93440. +#elif defined(PCI_INTERFACE)
  93441. + pci_set_drvdata(_dev, dwc_otg_device);
  93442. + dwc_otg_device->os_dep.pcidev = _dev;
  93443. +#endif
  93444. +
  93445. + /*
  93446. + * Enable the global interrupt after all the interrupt
  93447. + * handlers are installed if there is no ADP support else
  93448. + * perform initial actions required for Internal ADP logic.
  93449. + */
  93450. + if (!dwc_otg_get_param_adp_enable(dwc_otg_device->core_if)) {
  93451. + dev_dbg(&_dev->dev, "Calling enable_global_interrupts\n");
  93452. + dwc_otg_enable_global_interrupts(dwc_otg_device->core_if);
  93453. + dev_dbg(&_dev->dev, "Done\n");
  93454. + } else
  93455. + dwc_otg_adp_start(dwc_otg_device->core_if,
  93456. + dwc_otg_is_host_mode(dwc_otg_device->core_if));
  93457. +
  93458. + return 0;
  93459. +
  93460. +fail:
  93461. + dwc_otg_driver_remove(_dev);
  93462. + return retval;
  93463. +}
  93464. +
  93465. +/**
  93466. + * This structure defines the methods to be called by a bus driver
  93467. + * during the lifecycle of a device on that bus. Both drivers and
  93468. + * devices are registered with a bus driver. The bus driver matches
  93469. + * devices to drivers based on information in the device and driver
  93470. + * structures.
  93471. + *
  93472. + * The probe function is called when the bus driver matches a device
  93473. + * to this driver. The remove function is called when a device is
  93474. + * unregistered with the bus driver.
  93475. + */
  93476. +#ifdef LM_INTERFACE
  93477. +static struct lm_driver dwc_otg_driver = {
  93478. + .drv = {.name = (char *)dwc_driver_name,},
  93479. + .probe = dwc_otg_driver_probe,
  93480. + .remove = dwc_otg_driver_remove,
  93481. + // 'suspend' and 'resume' absent
  93482. +};
  93483. +#elif defined(PCI_INTERFACE)
  93484. +static const struct pci_device_id pci_ids[] = { {
  93485. + PCI_DEVICE(0x16c3, 0xabcd),
  93486. + .driver_data =
  93487. + (unsigned long)0xdeadbeef,
  93488. + }, { /* end: all zeroes */ }
  93489. +};
  93490. +
  93491. +MODULE_DEVICE_TABLE(pci, pci_ids);
  93492. +
  93493. +/* pci driver glue; this is a "new style" PCI driver module */
  93494. +static struct pci_driver dwc_otg_driver = {
  93495. + .name = "dwc_otg",
  93496. + .id_table = pci_ids,
  93497. +
  93498. + .probe = dwc_otg_driver_probe,
  93499. + .remove = dwc_otg_driver_remove,
  93500. +
  93501. + .driver = {
  93502. + .name = (char *)dwc_driver_name,
  93503. + },
  93504. +};
  93505. +#elif defined(PLATFORM_INTERFACE)
  93506. +static struct platform_device_id platform_ids[] = {
  93507. + {
  93508. + .name = "bcm2708_usb",
  93509. + .driver_data = (kernel_ulong_t) 0xdeadbeef,
  93510. + },
  93511. + { /* end: all zeroes */ }
  93512. +};
  93513. +MODULE_DEVICE_TABLE(platform, platform_ids);
  93514. +
  93515. +static struct platform_driver dwc_otg_driver = {
  93516. + .driver = {
  93517. + .name = (char *)dwc_driver_name,
  93518. + },
  93519. + .id_table = platform_ids,
  93520. +
  93521. + .probe = dwc_otg_driver_probe,
  93522. + .remove = dwc_otg_driver_remove,
  93523. + // no 'shutdown', 'suspend', 'resume', 'suspend_late' or 'resume_early'
  93524. +};
  93525. +#endif
  93526. +
  93527. +/**
  93528. + * This function is called when the dwc_otg_driver is installed with the
  93529. + * insmod command. It registers the dwc_otg_driver structure with the
  93530. + * appropriate bus driver. This will cause the dwc_otg_driver_probe function
  93531. + * to be called. In addition, the bus driver will automatically expose
  93532. + * attributes defined for the device and driver in the special sysfs file
  93533. + * system.
  93534. + *
  93535. + * @return
  93536. + */
  93537. +static int __init dwc_otg_driver_init(void)
  93538. +{
  93539. + int retval = 0;
  93540. + int error;
  93541. + struct device_driver *drv;
  93542. +
  93543. + if(fiq_fsm_enable && !fiq_enable) {
  93544. + printk(KERN_WARNING "dwc_otg: fiq_fsm_enable was set without fiq_enable! Correcting.\n");
  93545. + fiq_enable = 1;
  93546. + }
  93547. +
  93548. + printk(KERN_INFO "%s: version %s (%s bus)\n", dwc_driver_name,
  93549. + DWC_DRIVER_VERSION,
  93550. +#ifdef LM_INTERFACE
  93551. + "logicmodule");
  93552. + retval = lm_driver_register(&dwc_otg_driver);
  93553. + drv = &dwc_otg_driver.drv;
  93554. +#elif defined(PCI_INTERFACE)
  93555. + "pci");
  93556. + retval = pci_register_driver(&dwc_otg_driver);
  93557. + drv = &dwc_otg_driver.driver;
  93558. +#elif defined(PLATFORM_INTERFACE)
  93559. + "platform");
  93560. + retval = platform_driver_register(&dwc_otg_driver);
  93561. + drv = &dwc_otg_driver.driver;
  93562. +#endif
  93563. + if (retval < 0) {
  93564. + printk(KERN_ERR "%s retval=%d\n", __func__, retval);
  93565. + return retval;
  93566. + }
  93567. + printk(KERN_DEBUG "dwc_otg: FIQ %s\n", fiq_enable ? "enabled":"disabled");
  93568. + printk(KERN_DEBUG "dwc_otg: NAK holdoff %s\n", nak_holdoff ? "enabled":"disabled");
  93569. + printk(KERN_DEBUG "dwc_otg: FIQ split-transaction FSM %s\n", fiq_fsm_enable ? "enabled":"disabled");
  93570. +
  93571. + error = driver_create_file(drv, &driver_attr_version);
  93572. +#ifdef DEBUG
  93573. + error = driver_create_file(drv, &driver_attr_debuglevel);
  93574. +#endif
  93575. + return retval;
  93576. +}
  93577. +
  93578. +module_init(dwc_otg_driver_init);
  93579. +
  93580. +/**
  93581. + * This function is called when the driver is removed from the kernel
  93582. + * with the rmmod command. The driver unregisters itself with its bus
  93583. + * driver.
  93584. + *
  93585. + */
  93586. +static void __exit dwc_otg_driver_cleanup(void)
  93587. +{
  93588. + printk(KERN_DEBUG "dwc_otg_driver_cleanup()\n");
  93589. +
  93590. +#ifdef LM_INTERFACE
  93591. + driver_remove_file(&dwc_otg_driver.drv, &driver_attr_debuglevel);
  93592. + driver_remove_file(&dwc_otg_driver.drv, &driver_attr_version);
  93593. + lm_driver_unregister(&dwc_otg_driver);
  93594. +#elif defined(PCI_INTERFACE)
  93595. + driver_remove_file(&dwc_otg_driver.driver, &driver_attr_debuglevel);
  93596. + driver_remove_file(&dwc_otg_driver.driver, &driver_attr_version);
  93597. + pci_unregister_driver(&dwc_otg_driver);
  93598. +#elif defined(PLATFORM_INTERFACE)
  93599. + driver_remove_file(&dwc_otg_driver.driver, &driver_attr_debuglevel);
  93600. + driver_remove_file(&dwc_otg_driver.driver, &driver_attr_version);
  93601. + platform_driver_unregister(&dwc_otg_driver);
  93602. +#endif
  93603. +
  93604. + printk(KERN_INFO "%s module removed\n", dwc_driver_name);
  93605. +}
  93606. +
  93607. +module_exit(dwc_otg_driver_cleanup);
  93608. +
  93609. +MODULE_DESCRIPTION(DWC_DRIVER_DESC);
  93610. +MODULE_AUTHOR("Synopsys Inc.");
  93611. +MODULE_LICENSE("GPL");
  93612. +
  93613. +module_param_named(otg_cap, dwc_otg_module_params.otg_cap, int, 0444);
  93614. +MODULE_PARM_DESC(otg_cap, "OTG Capabilities 0=HNP&SRP 1=SRP Only 2=None");
  93615. +module_param_named(opt, dwc_otg_module_params.opt, int, 0444);
  93616. +MODULE_PARM_DESC(opt, "OPT Mode");
  93617. +module_param_named(dma_enable, dwc_otg_module_params.dma_enable, int, 0444);
  93618. +MODULE_PARM_DESC(dma_enable, "DMA Mode 0=Slave 1=DMA enabled");
  93619. +
  93620. +module_param_named(dma_desc_enable, dwc_otg_module_params.dma_desc_enable, int,
  93621. + 0444);
  93622. +MODULE_PARM_DESC(dma_desc_enable,
  93623. + "DMA Desc Mode 0=Address DMA 1=DMA Descriptor enabled");
  93624. +
  93625. +module_param_named(dma_burst_size, dwc_otg_module_params.dma_burst_size, int,
  93626. + 0444);
  93627. +MODULE_PARM_DESC(dma_burst_size,
  93628. + "DMA Burst Size 1, 4, 8, 16, 32, 64, 128, 256");
  93629. +module_param_named(speed, dwc_otg_module_params.speed, int, 0444);
  93630. +MODULE_PARM_DESC(speed, "Speed 0=High Speed 1=Full Speed");
  93631. +module_param_named(host_support_fs_ls_low_power,
  93632. + dwc_otg_module_params.host_support_fs_ls_low_power, int,
  93633. + 0444);
  93634. +MODULE_PARM_DESC(host_support_fs_ls_low_power,
  93635. + "Support Low Power w/FS or LS 0=Support 1=Don't Support");
  93636. +module_param_named(host_ls_low_power_phy_clk,
  93637. + dwc_otg_module_params.host_ls_low_power_phy_clk, int, 0444);
  93638. +MODULE_PARM_DESC(host_ls_low_power_phy_clk,
  93639. + "Low Speed Low Power Clock 0=48Mhz 1=6Mhz");
  93640. +module_param_named(enable_dynamic_fifo,
  93641. + dwc_otg_module_params.enable_dynamic_fifo, int, 0444);
  93642. +MODULE_PARM_DESC(enable_dynamic_fifo, "0=cC Setting 1=Allow Dynamic Sizing");
  93643. +module_param_named(data_fifo_size, dwc_otg_module_params.data_fifo_size, int,
  93644. + 0444);
  93645. +MODULE_PARM_DESC(data_fifo_size,
  93646. + "Total number of words in the data FIFO memory 32-32768");
  93647. +module_param_named(dev_rx_fifo_size, dwc_otg_module_params.dev_rx_fifo_size,
  93648. + int, 0444);
  93649. +MODULE_PARM_DESC(dev_rx_fifo_size, "Number of words in the Rx FIFO 16-32768");
  93650. +module_param_named(dev_nperio_tx_fifo_size,
  93651. + dwc_otg_module_params.dev_nperio_tx_fifo_size, int, 0444);
  93652. +MODULE_PARM_DESC(dev_nperio_tx_fifo_size,
  93653. + "Number of words in the non-periodic Tx FIFO 16-32768");
  93654. +module_param_named(dev_perio_tx_fifo_size_1,
  93655. + dwc_otg_module_params.dev_perio_tx_fifo_size[0], int, 0444);
  93656. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_1,
  93657. + "Number of words in the periodic Tx FIFO 4-768");
  93658. +module_param_named(dev_perio_tx_fifo_size_2,
  93659. + dwc_otg_module_params.dev_perio_tx_fifo_size[1], int, 0444);
  93660. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_2,
  93661. + "Number of words in the periodic Tx FIFO 4-768");
  93662. +module_param_named(dev_perio_tx_fifo_size_3,
  93663. + dwc_otg_module_params.dev_perio_tx_fifo_size[2], int, 0444);
  93664. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_3,
  93665. + "Number of words in the periodic Tx FIFO 4-768");
  93666. +module_param_named(dev_perio_tx_fifo_size_4,
  93667. + dwc_otg_module_params.dev_perio_tx_fifo_size[3], int, 0444);
  93668. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_4,
  93669. + "Number of words in the periodic Tx FIFO 4-768");
  93670. +module_param_named(dev_perio_tx_fifo_size_5,
  93671. + dwc_otg_module_params.dev_perio_tx_fifo_size[4], int, 0444);
  93672. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_5,
  93673. + "Number of words in the periodic Tx FIFO 4-768");
  93674. +module_param_named(dev_perio_tx_fifo_size_6,
  93675. + dwc_otg_module_params.dev_perio_tx_fifo_size[5], int, 0444);
  93676. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_6,
  93677. + "Number of words in the periodic Tx FIFO 4-768");
  93678. +module_param_named(dev_perio_tx_fifo_size_7,
  93679. + dwc_otg_module_params.dev_perio_tx_fifo_size[6], int, 0444);
  93680. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_7,
  93681. + "Number of words in the periodic Tx FIFO 4-768");
  93682. +module_param_named(dev_perio_tx_fifo_size_8,
  93683. + dwc_otg_module_params.dev_perio_tx_fifo_size[7], int, 0444);
  93684. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_8,
  93685. + "Number of words in the periodic Tx FIFO 4-768");
  93686. +module_param_named(dev_perio_tx_fifo_size_9,
  93687. + dwc_otg_module_params.dev_perio_tx_fifo_size[8], int, 0444);
  93688. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_9,
  93689. + "Number of words in the periodic Tx FIFO 4-768");
  93690. +module_param_named(dev_perio_tx_fifo_size_10,
  93691. + dwc_otg_module_params.dev_perio_tx_fifo_size[9], int, 0444);
  93692. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_10,
  93693. + "Number of words in the periodic Tx FIFO 4-768");
  93694. +module_param_named(dev_perio_tx_fifo_size_11,
  93695. + dwc_otg_module_params.dev_perio_tx_fifo_size[10], int, 0444);
  93696. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_11,
  93697. + "Number of words in the periodic Tx FIFO 4-768");
  93698. +module_param_named(dev_perio_tx_fifo_size_12,
  93699. + dwc_otg_module_params.dev_perio_tx_fifo_size[11], int, 0444);
  93700. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_12,
  93701. + "Number of words in the periodic Tx FIFO 4-768");
  93702. +module_param_named(dev_perio_tx_fifo_size_13,
  93703. + dwc_otg_module_params.dev_perio_tx_fifo_size[12], int, 0444);
  93704. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_13,
  93705. + "Number of words in the periodic Tx FIFO 4-768");
  93706. +module_param_named(dev_perio_tx_fifo_size_14,
  93707. + dwc_otg_module_params.dev_perio_tx_fifo_size[13], int, 0444);
  93708. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_14,
  93709. + "Number of words in the periodic Tx FIFO 4-768");
  93710. +module_param_named(dev_perio_tx_fifo_size_15,
  93711. + dwc_otg_module_params.dev_perio_tx_fifo_size[14], int, 0444);
  93712. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_15,
  93713. + "Number of words in the periodic Tx FIFO 4-768");
  93714. +module_param_named(host_rx_fifo_size, dwc_otg_module_params.host_rx_fifo_size,
  93715. + int, 0444);
  93716. +MODULE_PARM_DESC(host_rx_fifo_size, "Number of words in the Rx FIFO 16-32768");
  93717. +module_param_named(host_nperio_tx_fifo_size,
  93718. + dwc_otg_module_params.host_nperio_tx_fifo_size, int, 0444);
  93719. +MODULE_PARM_DESC(host_nperio_tx_fifo_size,
  93720. + "Number of words in the non-periodic Tx FIFO 16-32768");
  93721. +module_param_named(host_perio_tx_fifo_size,
  93722. + dwc_otg_module_params.host_perio_tx_fifo_size, int, 0444);
  93723. +MODULE_PARM_DESC(host_perio_tx_fifo_size,
  93724. + "Number of words in the host periodic Tx FIFO 16-32768");
  93725. +module_param_named(max_transfer_size, dwc_otg_module_params.max_transfer_size,
  93726. + int, 0444);
  93727. +/** @todo Set the max to 512K, modify checks */
  93728. +MODULE_PARM_DESC(max_transfer_size,
  93729. + "The maximum transfer size supported in bytes 2047-65535");
  93730. +module_param_named(max_packet_count, dwc_otg_module_params.max_packet_count,
  93731. + int, 0444);
  93732. +MODULE_PARM_DESC(max_packet_count,
  93733. + "The maximum number of packets in a transfer 15-511");
  93734. +module_param_named(host_channels, dwc_otg_module_params.host_channels, int,
  93735. + 0444);
  93736. +MODULE_PARM_DESC(host_channels,
  93737. + "The number of host channel registers to use 1-16");
  93738. +module_param_named(dev_endpoints, dwc_otg_module_params.dev_endpoints, int,
  93739. + 0444);
  93740. +MODULE_PARM_DESC(dev_endpoints,
  93741. + "The number of endpoints in addition to EP0 available for device mode 1-15");
  93742. +module_param_named(phy_type, dwc_otg_module_params.phy_type, int, 0444);
  93743. +MODULE_PARM_DESC(phy_type, "0=Reserved 1=UTMI+ 2=ULPI");
  93744. +module_param_named(phy_utmi_width, dwc_otg_module_params.phy_utmi_width, int,
  93745. + 0444);
  93746. +MODULE_PARM_DESC(phy_utmi_width, "Specifies the UTMI+ Data Width 8 or 16 bits");
  93747. +module_param_named(phy_ulpi_ddr, dwc_otg_module_params.phy_ulpi_ddr, int, 0444);
  93748. +MODULE_PARM_DESC(phy_ulpi_ddr,
  93749. + "ULPI at double or single data rate 0=Single 1=Double");
  93750. +module_param_named(phy_ulpi_ext_vbus, dwc_otg_module_params.phy_ulpi_ext_vbus,
  93751. + int, 0444);
  93752. +MODULE_PARM_DESC(phy_ulpi_ext_vbus,
  93753. + "ULPI PHY using internal or external vbus 0=Internal");
  93754. +module_param_named(i2c_enable, dwc_otg_module_params.i2c_enable, int, 0444);
  93755. +MODULE_PARM_DESC(i2c_enable, "FS PHY Interface");
  93756. +module_param_named(ulpi_fs_ls, dwc_otg_module_params.ulpi_fs_ls, int, 0444);
  93757. +MODULE_PARM_DESC(ulpi_fs_ls, "ULPI PHY FS/LS mode only");
  93758. +module_param_named(ts_dline, dwc_otg_module_params.ts_dline, int, 0444);
  93759. +MODULE_PARM_DESC(ts_dline, "Term select Dline pulsing for all PHYs");
  93760. +module_param_named(debug, g_dbg_lvl, int, 0444);
  93761. +MODULE_PARM_DESC(debug, "");
  93762. +
  93763. +module_param_named(en_multiple_tx_fifo,
  93764. + dwc_otg_module_params.en_multiple_tx_fifo, int, 0444);
  93765. +MODULE_PARM_DESC(en_multiple_tx_fifo,
  93766. + "Dedicated Non Periodic Tx FIFOs 0=disabled 1=enabled");
  93767. +module_param_named(dev_tx_fifo_size_1,
  93768. + dwc_otg_module_params.dev_tx_fifo_size[0], int, 0444);
  93769. +MODULE_PARM_DESC(dev_tx_fifo_size_1, "Number of words in the Tx FIFO 4-768");
  93770. +module_param_named(dev_tx_fifo_size_2,
  93771. + dwc_otg_module_params.dev_tx_fifo_size[1], int, 0444);
  93772. +MODULE_PARM_DESC(dev_tx_fifo_size_2, "Number of words in the Tx FIFO 4-768");
  93773. +module_param_named(dev_tx_fifo_size_3,
  93774. + dwc_otg_module_params.dev_tx_fifo_size[2], int, 0444);
  93775. +MODULE_PARM_DESC(dev_tx_fifo_size_3, "Number of words in the Tx FIFO 4-768");
  93776. +module_param_named(dev_tx_fifo_size_4,
  93777. + dwc_otg_module_params.dev_tx_fifo_size[3], int, 0444);
  93778. +MODULE_PARM_DESC(dev_tx_fifo_size_4, "Number of words in the Tx FIFO 4-768");
  93779. +module_param_named(dev_tx_fifo_size_5,
  93780. + dwc_otg_module_params.dev_tx_fifo_size[4], int, 0444);
  93781. +MODULE_PARM_DESC(dev_tx_fifo_size_5, "Number of words in the Tx FIFO 4-768");
  93782. +module_param_named(dev_tx_fifo_size_6,
  93783. + dwc_otg_module_params.dev_tx_fifo_size[5], int, 0444);
  93784. +MODULE_PARM_DESC(dev_tx_fifo_size_6, "Number of words in the Tx FIFO 4-768");
  93785. +module_param_named(dev_tx_fifo_size_7,
  93786. + dwc_otg_module_params.dev_tx_fifo_size[6], int, 0444);
  93787. +MODULE_PARM_DESC(dev_tx_fifo_size_7, "Number of words in the Tx FIFO 4-768");
  93788. +module_param_named(dev_tx_fifo_size_8,
  93789. + dwc_otg_module_params.dev_tx_fifo_size[7], int, 0444);
  93790. +MODULE_PARM_DESC(dev_tx_fifo_size_8, "Number of words in the Tx FIFO 4-768");
  93791. +module_param_named(dev_tx_fifo_size_9,
  93792. + dwc_otg_module_params.dev_tx_fifo_size[8], int, 0444);
  93793. +MODULE_PARM_DESC(dev_tx_fifo_size_9, "Number of words in the Tx FIFO 4-768");
  93794. +module_param_named(dev_tx_fifo_size_10,
  93795. + dwc_otg_module_params.dev_tx_fifo_size[9], int, 0444);
  93796. +MODULE_PARM_DESC(dev_tx_fifo_size_10, "Number of words in the Tx FIFO 4-768");
  93797. +module_param_named(dev_tx_fifo_size_11,
  93798. + dwc_otg_module_params.dev_tx_fifo_size[10], int, 0444);
  93799. +MODULE_PARM_DESC(dev_tx_fifo_size_11, "Number of words in the Tx FIFO 4-768");
  93800. +module_param_named(dev_tx_fifo_size_12,
  93801. + dwc_otg_module_params.dev_tx_fifo_size[11], int, 0444);
  93802. +MODULE_PARM_DESC(dev_tx_fifo_size_12, "Number of words in the Tx FIFO 4-768");
  93803. +module_param_named(dev_tx_fifo_size_13,
  93804. + dwc_otg_module_params.dev_tx_fifo_size[12], int, 0444);
  93805. +MODULE_PARM_DESC(dev_tx_fifo_size_13, "Number of words in the Tx FIFO 4-768");
  93806. +module_param_named(dev_tx_fifo_size_14,
  93807. + dwc_otg_module_params.dev_tx_fifo_size[13], int, 0444);
  93808. +MODULE_PARM_DESC(dev_tx_fifo_size_14, "Number of words in the Tx FIFO 4-768");
  93809. +module_param_named(dev_tx_fifo_size_15,
  93810. + dwc_otg_module_params.dev_tx_fifo_size[14], int, 0444);
  93811. +MODULE_PARM_DESC(dev_tx_fifo_size_15, "Number of words in the Tx FIFO 4-768");
  93812. +
  93813. +module_param_named(thr_ctl, dwc_otg_module_params.thr_ctl, int, 0444);
  93814. +MODULE_PARM_DESC(thr_ctl,
  93815. + "Thresholding enable flag bit 0 - non ISO Tx thr., 1 - ISO Tx thr., 2 - Rx thr.- bit 0=disabled 1=enabled");
  93816. +module_param_named(tx_thr_length, dwc_otg_module_params.tx_thr_length, int,
  93817. + 0444);
  93818. +MODULE_PARM_DESC(tx_thr_length, "Tx Threshold length in 32 bit DWORDs");
  93819. +module_param_named(rx_thr_length, dwc_otg_module_params.rx_thr_length, int,
  93820. + 0444);
  93821. +MODULE_PARM_DESC(rx_thr_length, "Rx Threshold length in 32 bit DWORDs");
  93822. +
  93823. +module_param_named(pti_enable, dwc_otg_module_params.pti_enable, int, 0444);
  93824. +module_param_named(mpi_enable, dwc_otg_module_params.mpi_enable, int, 0444);
  93825. +module_param_named(lpm_enable, dwc_otg_module_params.lpm_enable, int, 0444);
  93826. +MODULE_PARM_DESC(lpm_enable, "LPM Enable 0=LPM Disabled 1=LPM Enabled");
  93827. +module_param_named(ic_usb_cap, dwc_otg_module_params.ic_usb_cap, int, 0444);
  93828. +MODULE_PARM_DESC(ic_usb_cap,
  93829. + "IC_USB Capability 0=IC_USB Disabled 1=IC_USB Enabled");
  93830. +module_param_named(ahb_thr_ratio, dwc_otg_module_params.ahb_thr_ratio, int,
  93831. + 0444);
  93832. +MODULE_PARM_DESC(ahb_thr_ratio, "AHB Threshold Ratio");
  93833. +module_param_named(power_down, dwc_otg_module_params.power_down, int, 0444);
  93834. +MODULE_PARM_DESC(power_down, "Power Down Mode");
  93835. +module_param_named(reload_ctl, dwc_otg_module_params.reload_ctl, int, 0444);
  93836. +MODULE_PARM_DESC(reload_ctl, "HFIR Reload Control");
  93837. +module_param_named(dev_out_nak, dwc_otg_module_params.dev_out_nak, int, 0444);
  93838. +MODULE_PARM_DESC(dev_out_nak, "Enable Device OUT NAK");
  93839. +module_param_named(cont_on_bna, dwc_otg_module_params.cont_on_bna, int, 0444);
  93840. +MODULE_PARM_DESC(cont_on_bna, "Enable Enable Continue on BNA");
  93841. +module_param_named(ahb_single, dwc_otg_module_params.ahb_single, int, 0444);
  93842. +MODULE_PARM_DESC(ahb_single, "Enable AHB Single Support");
  93843. +module_param_named(adp_enable, dwc_otg_module_params.adp_enable, int, 0444);
  93844. +MODULE_PARM_DESC(adp_enable, "ADP Enable 0=ADP Disabled 1=ADP Enabled");
  93845. +module_param_named(otg_ver, dwc_otg_module_params.otg_ver, int, 0444);
  93846. +MODULE_PARM_DESC(otg_ver, "OTG revision supported 0=OTG 1.3 1=OTG 2.0");
  93847. +module_param(microframe_schedule, bool, 0444);
  93848. +MODULE_PARM_DESC(microframe_schedule, "Enable the microframe scheduler");
  93849. +
  93850. +module_param(fiq_enable, bool, 0444);
  93851. +MODULE_PARM_DESC(fiq_enable, "Enable the FIQ");
  93852. +module_param(nak_holdoff, ushort, 0644);
  93853. +MODULE_PARM_DESC(nak_holdoff, "Throttle duration for bulk split-transaction endpoints on a NAK. Default 8");
  93854. +module_param(fiq_fsm_enable, bool, 0444);
  93855. +MODULE_PARM_DESC(fiq_fsm_enable, "Enable the FIQ to perform split transactions as defined by fiq_fsm_mask");
  93856. +module_param(fiq_fsm_mask, ushort, 0444);
  93857. +MODULE_PARM_DESC(fiq_fsm_mask, "Bitmask of transactions to perform in the FIQ.\n"
  93858. + "Bit 0 : Non-periodic split transactions\n"
  93859. + "Bit 1 : Periodic split transactions\n"
  93860. + "Bit 2 : High-speed multi-transfer isochronous\n"
  93861. + "All other bits should be set 0.");
  93862. +
  93863. +
  93864. +/** @page "Module Parameters"
  93865. + *
  93866. + * The following parameters may be specified when starting the module.
  93867. + * These parameters define how the DWC_otg controller should be
  93868. + * configured. Parameter values are passed to the CIL initialization
  93869. + * function dwc_otg_cil_init
  93870. + *
  93871. + * Example: <code>modprobe dwc_otg speed=1 otg_cap=1</code>
  93872. + *
  93873. +
  93874. + <table>
  93875. + <tr><td>Parameter Name</td><td>Meaning</td></tr>
  93876. +
  93877. + <tr>
  93878. + <td>otg_cap</td>
  93879. + <td>Specifies the OTG capabilities. The driver will automatically detect the
  93880. + value for this parameter if none is specified.
  93881. + - 0: HNP and SRP capable (default, if available)
  93882. + - 1: SRP Only capable
  93883. + - 2: No HNP/SRP capable
  93884. + </td></tr>
  93885. +
  93886. + <tr>
  93887. + <td>dma_enable</td>
  93888. + <td>Specifies whether to use slave or DMA mode for accessing the data FIFOs.
  93889. + The driver will automatically detect the value for this parameter if none is
  93890. + specified.
  93891. + - 0: Slave
  93892. + - 1: DMA (default, if available)
  93893. + </td></tr>
  93894. +
  93895. + <tr>
  93896. + <td>dma_burst_size</td>
  93897. + <td>The DMA Burst size (applicable only for External DMA Mode).
  93898. + - Values: 1, 4, 8 16, 32, 64, 128, 256 (default 32)
  93899. + </td></tr>
  93900. +
  93901. + <tr>
  93902. + <td>speed</td>
  93903. + <td>Specifies the maximum speed of operation in host and device mode. The
  93904. + actual speed depends on the speed of the attached device and the value of
  93905. + phy_type.
  93906. + - 0: High Speed (default)
  93907. + - 1: Full Speed
  93908. + </td></tr>
  93909. +
  93910. + <tr>
  93911. + <td>host_support_fs_ls_low_power</td>
  93912. + <td>Specifies whether low power mode is supported when attached to a Full
  93913. + Speed or Low Speed device in host mode.
  93914. + - 0: Don't support low power mode (default)
  93915. + - 1: Support low power mode
  93916. + </td></tr>
  93917. +
  93918. + <tr>
  93919. + <td>host_ls_low_power_phy_clk</td>
  93920. + <td>Specifies the PHY clock rate in low power mode when connected to a Low
  93921. + Speed device in host mode. This parameter is applicable only if
  93922. + HOST_SUPPORT_FS_LS_LOW_POWER is enabled.
  93923. + - 0: 48 MHz (default)
  93924. + - 1: 6 MHz
  93925. + </td></tr>
  93926. +
  93927. + <tr>
  93928. + <td>enable_dynamic_fifo</td>
  93929. + <td> Specifies whether FIFOs may be resized by the driver software.
  93930. + - 0: Use cC FIFO size parameters
  93931. + - 1: Allow dynamic FIFO sizing (default)
  93932. + </td></tr>
  93933. +
  93934. + <tr>
  93935. + <td>data_fifo_size</td>
  93936. + <td>Total number of 4-byte words in the data FIFO memory. This memory
  93937. + includes the Rx FIFO, non-periodic Tx FIFO, and periodic Tx FIFOs.
  93938. + - Values: 32 to 32768 (default 8192)
  93939. +
  93940. + Note: The total FIFO memory depth in the FPGA configuration is 8192.
  93941. + </td></tr>
  93942. +
  93943. + <tr>
  93944. + <td>dev_rx_fifo_size</td>
  93945. + <td>Number of 4-byte words in the Rx FIFO in device mode when dynamic
  93946. + FIFO sizing is enabled.
  93947. + - Values: 16 to 32768 (default 1064)
  93948. + </td></tr>
  93949. +
  93950. + <tr>
  93951. + <td>dev_nperio_tx_fifo_size</td>
  93952. + <td>Number of 4-byte words in the non-periodic Tx FIFO in device mode when
  93953. + dynamic FIFO sizing is enabled.
  93954. + - Values: 16 to 32768 (default 1024)
  93955. + </td></tr>
  93956. +
  93957. + <tr>
  93958. + <td>dev_perio_tx_fifo_size_n (n = 1 to 15)</td>
  93959. + <td>Number of 4-byte words in each of the periodic Tx FIFOs in device mode
  93960. + when dynamic FIFO sizing is enabled.
  93961. + - Values: 4 to 768 (default 256)
  93962. + </td></tr>
  93963. +
  93964. + <tr>
  93965. + <td>host_rx_fifo_size</td>
  93966. + <td>Number of 4-byte words in the Rx FIFO in host mode when dynamic FIFO
  93967. + sizing is enabled.
  93968. + - Values: 16 to 32768 (default 1024)
  93969. + </td></tr>
  93970. +
  93971. + <tr>
  93972. + <td>host_nperio_tx_fifo_size</td>
  93973. + <td>Number of 4-byte words in the non-periodic Tx FIFO in host mode when
  93974. + dynamic FIFO sizing is enabled in the core.
  93975. + - Values: 16 to 32768 (default 1024)
  93976. + </td></tr>
  93977. +
  93978. + <tr>
  93979. + <td>host_perio_tx_fifo_size</td>
  93980. + <td>Number of 4-byte words in the host periodic Tx FIFO when dynamic FIFO
  93981. + sizing is enabled.
  93982. + - Values: 16 to 32768 (default 1024)
  93983. + </td></tr>
  93984. +
  93985. + <tr>
  93986. + <td>max_transfer_size</td>
  93987. + <td>The maximum transfer size supported in bytes.
  93988. + - Values: 2047 to 65,535 (default 65,535)
  93989. + </td></tr>
  93990. +
  93991. + <tr>
  93992. + <td>max_packet_count</td>
  93993. + <td>The maximum number of packets in a transfer.
  93994. + - Values: 15 to 511 (default 511)
  93995. + </td></tr>
  93996. +
  93997. + <tr>
  93998. + <td>host_channels</td>
  93999. + <td>The number of host channel registers to use.
  94000. + - Values: 1 to 16 (default 12)
  94001. +
  94002. + Note: The FPGA configuration supports a maximum of 12 host channels.
  94003. + </td></tr>
  94004. +
  94005. + <tr>
  94006. + <td>dev_endpoints</td>
  94007. + <td>The number of endpoints in addition to EP0 available for device mode
  94008. + operations.
  94009. + - Values: 1 to 15 (default 6 IN and OUT)
  94010. +
  94011. + Note: The FPGA configuration supports a maximum of 6 IN and OUT endpoints in
  94012. + addition to EP0.
  94013. + </td></tr>
  94014. +
  94015. + <tr>
  94016. + <td>phy_type</td>
  94017. + <td>Specifies the type of PHY interface to use. By default, the driver will
  94018. + automatically detect the phy_type.
  94019. + - 0: Full Speed
  94020. + - 1: UTMI+ (default, if available)
  94021. + - 2: ULPI
  94022. + </td></tr>
  94023. +
  94024. + <tr>
  94025. + <td>phy_utmi_width</td>
  94026. + <td>Specifies the UTMI+ Data Width. This parameter is applicable for a
  94027. + phy_type of UTMI+. Also, this parameter is applicable only if the
  94028. + OTG_HSPHY_WIDTH cC parameter was set to "8 and 16 bits", meaning that the
  94029. + core has been configured to work at either data path width.
  94030. + - Values: 8 or 16 bits (default 16)
  94031. + </td></tr>
  94032. +
  94033. + <tr>
  94034. + <td>phy_ulpi_ddr</td>
  94035. + <td>Specifies whether the ULPI operates at double or single data rate. This
  94036. + parameter is only applicable if phy_type is ULPI.
  94037. + - 0: single data rate ULPI interface with 8 bit wide data bus (default)
  94038. + - 1: double data rate ULPI interface with 4 bit wide data bus
  94039. + </td></tr>
  94040. +
  94041. + <tr>
  94042. + <td>i2c_enable</td>
  94043. + <td>Specifies whether to use the I2C interface for full speed PHY. This
  94044. + parameter is only applicable if PHY_TYPE is FS.
  94045. + - 0: Disabled (default)
  94046. + - 1: Enabled
  94047. + </td></tr>
  94048. +
  94049. + <tr>
  94050. + <td>ulpi_fs_ls</td>
  94051. + <td>Specifies whether to use ULPI FS/LS mode only.
  94052. + - 0: Disabled (default)
  94053. + - 1: Enabled
  94054. + </td></tr>
  94055. +
  94056. + <tr>
  94057. + <td>ts_dline</td>
  94058. + <td>Specifies whether term select D-Line pulsing for all PHYs is enabled.
  94059. + - 0: Disabled (default)
  94060. + - 1: Enabled
  94061. + </td></tr>
  94062. +
  94063. + <tr>
  94064. + <td>en_multiple_tx_fifo</td>
  94065. + <td>Specifies whether dedicatedto tx fifos are enabled for non periodic IN EPs.
  94066. + The driver will automatically detect the value for this parameter if none is
  94067. + specified.
  94068. + - 0: Disabled
  94069. + - 1: Enabled (default, if available)
  94070. + </td></tr>
  94071. +
  94072. + <tr>
  94073. + <td>dev_tx_fifo_size_n (n = 1 to 15)</td>
  94074. + <td>Number of 4-byte words in each of the Tx FIFOs in device mode
  94075. + when dynamic FIFO sizing is enabled.
  94076. + - Values: 4 to 768 (default 256)
  94077. + </td></tr>
  94078. +
  94079. + <tr>
  94080. + <td>tx_thr_length</td>
  94081. + <td>Transmit Threshold length in 32 bit double words
  94082. + - Values: 8 to 128 (default 64)
  94083. + </td></tr>
  94084. +
  94085. + <tr>
  94086. + <td>rx_thr_length</td>
  94087. + <td>Receive Threshold length in 32 bit double words
  94088. + - Values: 8 to 128 (default 64)
  94089. + </td></tr>
  94090. +
  94091. +<tr>
  94092. + <td>thr_ctl</td>
  94093. + <td>Specifies whether to enable Thresholding for Device mode. Bits 0, 1, 2 of
  94094. + this parmater specifies if thresholding is enabled for non-Iso Tx, Iso Tx and
  94095. + Rx transfers accordingly.
  94096. + The driver will automatically detect the value for this parameter if none is
  94097. + specified.
  94098. + - Values: 0 to 7 (default 0)
  94099. + Bit values indicate:
  94100. + - 0: Thresholding disabled
  94101. + - 1: Thresholding enabled
  94102. + </td></tr>
  94103. +
  94104. +<tr>
  94105. + <td>dma_desc_enable</td>
  94106. + <td>Specifies whether to enable Descriptor DMA mode.
  94107. + The driver will automatically detect the value for this parameter if none is
  94108. + specified.
  94109. + - 0: Descriptor DMA disabled
  94110. + - 1: Descriptor DMA (default, if available)
  94111. + </td></tr>
  94112. +
  94113. +<tr>
  94114. + <td>mpi_enable</td>
  94115. + <td>Specifies whether to enable MPI enhancement mode.
  94116. + The driver will automatically detect the value for this parameter if none is
  94117. + specified.
  94118. + - 0: MPI disabled (default)
  94119. + - 1: MPI enable
  94120. + </td></tr>
  94121. +
  94122. +<tr>
  94123. + <td>pti_enable</td>
  94124. + <td>Specifies whether to enable PTI enhancement support.
  94125. + The driver will automatically detect the value for this parameter if none is
  94126. + specified.
  94127. + - 0: PTI disabled (default)
  94128. + - 1: PTI enable
  94129. + </td></tr>
  94130. +
  94131. +<tr>
  94132. + <td>lpm_enable</td>
  94133. + <td>Specifies whether to enable LPM support.
  94134. + The driver will automatically detect the value for this parameter if none is
  94135. + specified.
  94136. + - 0: LPM disabled
  94137. + - 1: LPM enable (default, if available)
  94138. + </td></tr>
  94139. +
  94140. +<tr>
  94141. + <td>ic_usb_cap</td>
  94142. + <td>Specifies whether to enable IC_USB capability.
  94143. + The driver will automatically detect the value for this parameter if none is
  94144. + specified.
  94145. + - 0: IC_USB disabled (default, if available)
  94146. + - 1: IC_USB enable
  94147. + </td></tr>
  94148. +
  94149. +<tr>
  94150. + <td>ahb_thr_ratio</td>
  94151. + <td>Specifies AHB Threshold ratio.
  94152. + - Values: 0 to 3 (default 0)
  94153. + </td></tr>
  94154. +
  94155. +<tr>
  94156. + <td>power_down</td>
  94157. + <td>Specifies Power Down(Hibernation) Mode.
  94158. + The driver will automatically detect the value for this parameter if none is
  94159. + specified.
  94160. + - 0: Power Down disabled (default)
  94161. + - 2: Power Down enabled
  94162. + </td></tr>
  94163. +
  94164. + <tr>
  94165. + <td>reload_ctl</td>
  94166. + <td>Specifies whether dynamic reloading of the HFIR register is allowed during
  94167. + run time. The driver will automatically detect the value for this parameter if
  94168. + none is specified. In case the HFIR value is reloaded when HFIR.RldCtrl == 1'b0
  94169. + the core might misbehave.
  94170. + - 0: Reload Control disabled (default)
  94171. + - 1: Reload Control enabled
  94172. + </td></tr>
  94173. +
  94174. + <tr>
  94175. + <td>dev_out_nak</td>
  94176. + <td>Specifies whether Device OUT NAK enhancement enabled or no.
  94177. + The driver will automatically detect the value for this parameter if
  94178. + none is specified. This parameter is valid only when OTG_EN_DESC_DMA == 1b1.
  94179. + - 0: The core does not set NAK after Bulk OUT transfer complete (default)
  94180. + - 1: The core sets NAK after Bulk OUT transfer complete
  94181. + </td></tr>
  94182. +
  94183. + <tr>
  94184. + <td>cont_on_bna</td>
  94185. + <td>Specifies whether Enable Continue on BNA enabled or no.
  94186. + After receiving BNA interrupt the core disables the endpoint,when the
  94187. + endpoint is re-enabled by the application the
  94188. + - 0: Core starts processing from the DOEPDMA descriptor (default)
  94189. + - 1: Core starts processing from the descriptor which received the BNA.
  94190. + This parameter is valid only when OTG_EN_DESC_DMA == 1b1.
  94191. + </td></tr>
  94192. +
  94193. + <tr>
  94194. + <td>ahb_single</td>
  94195. + <td>This bit when programmed supports SINGLE transfers for remainder data
  94196. + in a transfer for DMA mode of operation.
  94197. + - 0: The remainder data will be sent using INCR burst size (default)
  94198. + - 1: The remainder data will be sent using SINGLE burst size.
  94199. + </td></tr>
  94200. +
  94201. +<tr>
  94202. + <td>adp_enable</td>
  94203. + <td>Specifies whether ADP feature is enabled.
  94204. + The driver will automatically detect the value for this parameter if none is
  94205. + specified.
  94206. + - 0: ADP feature disabled (default)
  94207. + - 1: ADP feature enabled
  94208. + </td></tr>
  94209. +
  94210. + <tr>
  94211. + <td>otg_ver</td>
  94212. + <td>Specifies whether OTG is performing as USB OTG Revision 2.0 or Revision 1.3
  94213. + USB OTG device.
  94214. + - 0: OTG 2.0 support disabled (default)
  94215. + - 1: OTG 2.0 support enabled
  94216. + </td></tr>
  94217. +
  94218. +*/
  94219. diff -Nur linux-3.18.8/drivers/usb/host/dwc_otg/dwc_otg_driver.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_driver.h
  94220. --- linux-3.18.8/drivers/usb/host/dwc_otg/dwc_otg_driver.h 1970-01-01 01:00:00.000000000 +0100
  94221. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_driver.h 2015-03-05 14:40:16.557715806 +0100
  94222. @@ -0,0 +1,86 @@
  94223. +/* ==========================================================================
  94224. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_driver.h $
  94225. + * $Revision: #19 $
  94226. + * $Date: 2010/11/15 $
  94227. + * $Change: 1627671 $
  94228. + *
  94229. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  94230. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  94231. + * otherwise expressly agreed to in writing between Synopsys and you.
  94232. + *
  94233. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  94234. + * any End User Software License Agreement or Agreement for Licensed Product
  94235. + * with Synopsys or any supplement thereto. You are permitted to use and
  94236. + * redistribute this Software in source and binary forms, with or without
  94237. + * modification, provided that redistributions of source code must retain this
  94238. + * notice. You may not view, use, disclose, copy or distribute this file or
  94239. + * any information contained herein except pursuant to this license grant from
  94240. + * Synopsys. If you do not agree with this notice, including the disclaimer
  94241. + * below, then you are not authorized to use the Software.
  94242. + *
  94243. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  94244. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  94245. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  94246. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  94247. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  94248. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  94249. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  94250. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  94251. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  94252. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  94253. + * DAMAGE.
  94254. + * ========================================================================== */
  94255. +
  94256. +#ifndef __DWC_OTG_DRIVER_H__
  94257. +#define __DWC_OTG_DRIVER_H__
  94258. +
  94259. +/** @file
  94260. + * This file contains the interface to the Linux driver.
  94261. + */
  94262. +#include "dwc_otg_os_dep.h"
  94263. +#include "dwc_otg_core_if.h"
  94264. +
  94265. +/* Type declarations */
  94266. +struct dwc_otg_pcd;
  94267. +struct dwc_otg_hcd;
  94268. +
  94269. +/**
  94270. + * This structure is a wrapper that encapsulates the driver components used to
  94271. + * manage a single DWC_otg controller.
  94272. + */
  94273. +typedef struct dwc_otg_device {
  94274. + /** Structure containing OS-dependent stuff. KEEP THIS STRUCT AT THE
  94275. + * VERY BEGINNING OF THE DEVICE STRUCT. OSes such as FreeBSD and NetBSD
  94276. + * require this. */
  94277. + struct os_dependent os_dep;
  94278. +
  94279. + /** Pointer to the core interface structure. */
  94280. + dwc_otg_core_if_t *core_if;
  94281. +
  94282. + /** Pointer to the PCD structure. */
  94283. + struct dwc_otg_pcd *pcd;
  94284. +
  94285. + /** Pointer to the HCD structure. */
  94286. + struct dwc_otg_hcd *hcd;
  94287. +
  94288. + /** Flag to indicate whether the common IRQ handler is installed. */
  94289. + uint8_t common_irq_installed;
  94290. +
  94291. +} dwc_otg_device_t;
  94292. +
  94293. +/*We must clear S3C24XX_EINTPEND external interrupt register
  94294. + * because after clearing in this register trigerred IRQ from
  94295. + * H/W core in kernel interrupt can be occured again before OTG
  94296. + * handlers clear all IRQ sources of Core registers because of
  94297. + * timing latencies and Low Level IRQ Type.
  94298. + */
  94299. +#ifdef CONFIG_MACH_IPMATE
  94300. +#define S3C2410X_CLEAR_EINTPEND() \
  94301. +do { \
  94302. + __raw_writel(1UL << 11,S3C24XX_EINTPEND); \
  94303. +} while (0)
  94304. +#else
  94305. +#define S3C2410X_CLEAR_EINTPEND() do { } while (0)
  94306. +#endif
  94307. +
  94308. +#endif
  94309. diff -Nur linux-3.18.8/drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.c
  94310. --- linux-3.18.8/drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.c 1970-01-01 01:00:00.000000000 +0100
  94311. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.c 2015-03-05 14:40:16.557715806 +0100
  94312. @@ -0,0 +1,1346 @@
  94313. +/*
  94314. + * dwc_otg_fiq_fsm.c - The finite state machine FIQ
  94315. + *
  94316. + * Copyright (c) 2013 Raspberry Pi Foundation
  94317. + *
  94318. + * Author: Jonathan Bell <jonathan@raspberrypi.org>
  94319. + * All rights reserved.
  94320. + *
  94321. + * Redistribution and use in source and binary forms, with or without
  94322. + * modification, are permitted provided that the following conditions are met:
  94323. + * * Redistributions of source code must retain the above copyright
  94324. + * notice, this list of conditions and the following disclaimer.
  94325. + * * Redistributions in binary form must reproduce the above copyright
  94326. + * notice, this list of conditions and the following disclaimer in the
  94327. + * documentation and/or other materials provided with the distribution.
  94328. + * * Neither the name of Raspberry Pi nor the
  94329. + * names of its contributors may be used to endorse or promote products
  94330. + * derived from this software without specific prior written permission.
  94331. + *
  94332. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  94333. + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  94334. + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  94335. + * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  94336. + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  94337. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  94338. + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  94339. + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  94340. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  94341. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  94342. + *
  94343. + * This FIQ implements functionality that performs split transactions on
  94344. + * the dwc_otg hardware without any outside intervention. A split transaction
  94345. + * is "queued" by nominating a specific host channel to perform the entirety
  94346. + * of a split transaction. This FIQ will then perform the microframe-precise
  94347. + * scheduling required in each phase of the transaction until completion.
  94348. + *
  94349. + * The FIQ functionality is glued into the Synopsys driver via the entry point
  94350. + * in the FSM enqueue function, and at the exit point in handling a HC interrupt
  94351. + * for a FSM-enabled channel.
  94352. + *
  94353. + * NB: Large parts of this implementation have architecture-specific code.
  94354. + * For porting this functionality to other ARM machines, the minimum is required:
  94355. + * - An interrupt controller allowing the top-level dwc USB interrupt to be routed
  94356. + * to the FIQ
  94357. + * - A method of forcing a software generated interrupt from FIQ mode that then
  94358. + * triggers an IRQ entry (with the dwc USB handler called by this IRQ number)
  94359. + * - Guaranteed interrupt routing such that both the FIQ and SGI occur on the same
  94360. + * processor core - there is no locking between the FIQ and IRQ (aside from
  94361. + * local_fiq_disable)
  94362. + *
  94363. + */
  94364. +
  94365. +#include "dwc_otg_fiq_fsm.h"
  94366. +
  94367. +
  94368. +char buffer[1000*16];
  94369. +int wptr;
  94370. +void notrace _fiq_print(enum fiq_debug_level dbg_lvl, volatile struct fiq_state *state, char *fmt, ...)
  94371. +{
  94372. + enum fiq_debug_level dbg_lvl_req = FIQDBG_ERR;
  94373. + va_list args;
  94374. + char text[17];
  94375. + hfnum_data_t hfnum = { .d32 = FIQ_READ(state->dwc_regs_base + 0x408) };
  94376. +
  94377. + if((dbg_lvl & dbg_lvl_req) || dbg_lvl == FIQDBG_ERR)
  94378. + {
  94379. + snprintf(text, 9, " %4d:%1u ", hfnum.b.frnum/8, hfnum.b.frnum & 7);
  94380. + va_start(args, fmt);
  94381. + vsnprintf(text+8, 9, fmt, args);
  94382. + va_end(args);
  94383. +
  94384. + memcpy(buffer + wptr, text, 16);
  94385. + wptr = (wptr + 16) % sizeof(buffer);
  94386. + }
  94387. +}
  94388. +
  94389. +/**
  94390. + * fiq_fsm_spin_lock() - ARMv6+ bare bones spinlock
  94391. + * Must be called with local interrupts and FIQ disabled.
  94392. + */
  94393. +#ifdef CONFIG_ARCH_BCM2709
  94394. +inline void fiq_fsm_spin_lock(fiq_lock_t *lock)
  94395. +{
  94396. + unsigned long tmp;
  94397. + uint32_t newval;
  94398. + fiq_lock_t lockval;
  94399. + smp_mb__before_spinlock();
  94400. + /* Nested locking, yay. If we are on the same CPU as the fiq, then the disable
  94401. + * will be sufficient. If we are on a different CPU, then the lock protects us. */
  94402. + prefetchw(&lock->slock);
  94403. + asm volatile (
  94404. + "1: ldrex %0, [%3]\n"
  94405. + " add %1, %0, %4\n"
  94406. + " strex %2, %1, [%3]\n"
  94407. + " teq %2, #0\n"
  94408. + " bne 1b"
  94409. + : "=&r" (lockval), "=&r" (newval), "=&r" (tmp)
  94410. + : "r" (&lock->slock), "I" (1 << 16)
  94411. + : "cc");
  94412. +
  94413. + while (lockval.tickets.next != lockval.tickets.owner) {
  94414. + wfe();
  94415. + lockval.tickets.owner = ACCESS_ONCE(lock->tickets.owner);
  94416. + }
  94417. + smp_mb();
  94418. +}
  94419. +#else
  94420. +inline void fiq_fsm_spin_lock(fiq_lock_t *lock) { }
  94421. +#endif
  94422. +
  94423. +/**
  94424. + * fiq_fsm_spin_unlock() - ARMv6+ bare bones spinunlock
  94425. + */
  94426. +#ifdef CONFIG_ARCH_BCM2709
  94427. +inline void fiq_fsm_spin_unlock(fiq_lock_t *lock)
  94428. +{
  94429. + smp_mb();
  94430. + lock->tickets.owner++;
  94431. + dsb_sev();
  94432. +}
  94433. +#else
  94434. +inline void fiq_fsm_spin_unlock(fiq_lock_t *lock) { }
  94435. +#endif
  94436. +
  94437. +/**
  94438. + * fiq_fsm_restart_channel() - Poke channel enable bit for a split transaction
  94439. + * @channel: channel to re-enable
  94440. + */
  94441. +static void fiq_fsm_restart_channel(struct fiq_state *st, int n, int force)
  94442. +{
  94443. + hcchar_data_t hcchar = { .d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR) };
  94444. +
  94445. + hcchar.b.chen = 0;
  94446. + if (st->channel[n].hcchar_copy.b.eptype & 0x1) {
  94447. + hfnum_data_t hfnum = { .d32 = FIQ_READ(st->dwc_regs_base + HFNUM) };
  94448. + /* Hardware bug workaround: update the ssplit index */
  94449. + if (st->channel[n].hcsplt_copy.b.spltena)
  94450. + st->channel[n].expected_uframe = (hfnum.b.frnum + 1) & 0x3FFF;
  94451. +
  94452. + hcchar.b.oddfrm = (hfnum.b.frnum & 0x1) ? 0 : 1;
  94453. + }
  94454. +
  94455. + FIQ_WRITE(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR, hcchar.d32);
  94456. + hcchar.d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR);
  94457. + hcchar.b.chen = 1;
  94458. +
  94459. + FIQ_WRITE(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR, hcchar.d32);
  94460. + fiq_print(FIQDBG_INT, st, "HCGO %01d %01d", n, force);
  94461. +}
  94462. +
  94463. +/**
  94464. + * fiq_fsm_setup_csplit() - Prepare a host channel for a CSplit transaction stage
  94465. + * @st: Pointer to the channel's state
  94466. + * @n : channel number
  94467. + *
  94468. + * Change host channel registers to perform a complete-split transaction. Being mindful of the
  94469. + * endpoint direction, set control regs up correctly.
  94470. + */
  94471. +static void notrace fiq_fsm_setup_csplit(struct fiq_state *st, int n)
  94472. +{
  94473. + hcsplt_data_t hcsplt = { .d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCSPLT) };
  94474. + hctsiz_data_t hctsiz = { .d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ) };
  94475. +
  94476. + hcsplt.b.compsplt = 1;
  94477. + if (st->channel[n].hcchar_copy.b.epdir == 1) {
  94478. + // If IN, the CSPLIT result contains the data or a hub handshake. hctsiz = maxpacket.
  94479. + hctsiz.b.xfersize = st->channel[n].hctsiz_copy.b.xfersize;
  94480. + } else {
  94481. + // If OUT, the CSPLIT result contains handshake only.
  94482. + hctsiz.b.xfersize = 0;
  94483. + }
  94484. + FIQ_WRITE(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCSPLT, hcsplt.d32);
  94485. + FIQ_WRITE(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ, hctsiz.d32);
  94486. + mb();
  94487. +}
  94488. +
  94489. +static inline int notrace fiq_get_xfer_len(struct fiq_state *st, int n)
  94490. +{
  94491. + /* The xfersize register is a bit wonky. For IN transfers, it decrements by the packet size. */
  94492. + hctsiz_data_t hctsiz = { .d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ) };
  94493. +
  94494. + if (st->channel[n].hcchar_copy.b.epdir == 0) {
  94495. + return st->channel[n].hctsiz_copy.b.xfersize;
  94496. + } else {
  94497. + return st->channel[n].hctsiz_copy.b.xfersize - hctsiz.b.xfersize;
  94498. + }
  94499. +
  94500. +}
  94501. +
  94502. +
  94503. +/**
  94504. + * fiq_increment_dma_buf() - update DMA address for bounce buffers after a CSPLIT
  94505. + *
  94506. + * Of use only for IN periodic transfers.
  94507. + */
  94508. +static int notrace fiq_increment_dma_buf(struct fiq_state *st, int num_channels, int n)
  94509. +{
  94510. + hcdma_data_t hcdma;
  94511. + int i = st->channel[n].dma_info.index;
  94512. + int len;
  94513. + struct fiq_dma_blob *blob = (struct fiq_dma_blob *) st->dma_base;
  94514. +
  94515. + len = fiq_get_xfer_len(st, n);
  94516. + fiq_print(FIQDBG_INT, st, "LEN: %03d", len);
  94517. + st->channel[n].dma_info.slot_len[i] = len;
  94518. + i++;
  94519. + if (i > 6)
  94520. + BUG();
  94521. +
  94522. + hcdma.d32 = (dma_addr_t) &blob->channel[n].index[i].buf[0];
  94523. + FIQ_WRITE(st->dwc_regs_base + HC_DMA + (HC_OFFSET * n), hcdma.d32);
  94524. + st->channel[n].dma_info.index = i;
  94525. + return 0;
  94526. +}
  94527. +
  94528. +/**
  94529. + * fiq_reload_hctsiz() - for IN transactions, reset HCTSIZ
  94530. + */
  94531. +static void notrace fiq_fsm_reload_hctsiz(struct fiq_state *st, int n)
  94532. +{
  94533. + hctsiz_data_t hctsiz = { .d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ) };
  94534. + hctsiz.b.xfersize = st->channel[n].hctsiz_copy.b.xfersize;
  94535. + hctsiz.b.pktcnt = 1;
  94536. + FIQ_WRITE(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ, hctsiz.d32);
  94537. +}
  94538. +
  94539. +/**
  94540. + * fiq_iso_out_advance() - update DMA address and split position bits
  94541. + * for isochronous OUT transactions.
  94542. + *
  94543. + * Returns 1 if this is the last packet queued, 0 otherwise. Split-ALL and
  94544. + * Split-BEGIN states are not handled - this is done when the transaction was queued.
  94545. + *
  94546. + * This function must only be called from the FIQ_ISO_OUT_ACTIVE state.
  94547. + */
  94548. +static int notrace fiq_iso_out_advance(struct fiq_state *st, int num_channels, int n)
  94549. +{
  94550. + hcsplt_data_t hcsplt;
  94551. + hctsiz_data_t hctsiz;
  94552. + hcdma_data_t hcdma;
  94553. + struct fiq_dma_blob *blob = (struct fiq_dma_blob *) st->dma_base;
  94554. + int last = 0;
  94555. + int i = st->channel[n].dma_info.index;
  94556. +
  94557. + fiq_print(FIQDBG_INT, st, "ADV %01d %01d ", n, i);
  94558. + i++;
  94559. + if (i == 4)
  94560. + last = 1;
  94561. + if (st->channel[n].dma_info.slot_len[i+1] == 255)
  94562. + last = 1;
  94563. +
  94564. + /* New DMA address - address of bounce buffer referred to in index */
  94565. + hcdma.d32 = (uint32_t) &blob->channel[n].index[i].buf[0];
  94566. + //hcdma.d32 = FIQ_READ(st->dwc_regs_base + HC_DMA + (HC_OFFSET * n));
  94567. + //hcdma.d32 += st->channel[n].dma_info.slot_len[i];
  94568. + fiq_print(FIQDBG_INT, st, "LAST: %01d ", last);
  94569. + fiq_print(FIQDBG_INT, st, "LEN: %03d", st->channel[n].dma_info.slot_len[i]);
  94570. + hcsplt.d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCSPLT);
  94571. + hctsiz.d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ);
  94572. + hcsplt.b.xactpos = (last) ? ISOC_XACTPOS_END : ISOC_XACTPOS_MID;
  94573. + /* Set up new packet length */
  94574. + hctsiz.b.pktcnt = 1;
  94575. + hctsiz.b.xfersize = st->channel[n].dma_info.slot_len[i];
  94576. + fiq_print(FIQDBG_INT, st, "%08x", hctsiz.d32);
  94577. +
  94578. + st->channel[n].dma_info.index++;
  94579. + FIQ_WRITE(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCSPLT, hcsplt.d32);
  94580. + FIQ_WRITE(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ, hctsiz.d32);
  94581. + FIQ_WRITE(st->dwc_regs_base + HC_DMA + (HC_OFFSET * n), hcdma.d32);
  94582. + return last;
  94583. +}
  94584. +
  94585. +/**
  94586. + * fiq_fsm_tt_next_isoc() - queue next pending isochronous out start-split on a TT
  94587. + *
  94588. + * Despite the limitations of the DWC core, we can force a microframe pipeline of
  94589. + * isochronous OUT start-split transactions while waiting for a corresponding other-type
  94590. + * of endpoint to finish its CSPLITs. TTs have big periodic buffers therefore it
  94591. + * is very unlikely that filling the start-split FIFO will cause data loss.
  94592. + * This allows much better interleaving of transactions in an order-independent way-
  94593. + * there is no requirement to prioritise isochronous, just a state-space search has
  94594. + * to be performed on each periodic start-split complete interrupt.
  94595. + */
  94596. +static int notrace fiq_fsm_tt_next_isoc(struct fiq_state *st, int num_channels, int n)
  94597. +{
  94598. + int hub_addr = st->channel[n].hub_addr;
  94599. + int port_addr = st->channel[n].port_addr;
  94600. + int i, poked = 0;
  94601. + for (i = 0; i < num_channels; i++) {
  94602. + if (i == n || st->channel[i].fsm == FIQ_PASSTHROUGH)
  94603. + continue;
  94604. + if (st->channel[i].hub_addr == hub_addr &&
  94605. + st->channel[i].port_addr == port_addr) {
  94606. + switch (st->channel[i].fsm) {
  94607. + case FIQ_PER_ISO_OUT_PENDING:
  94608. + if (st->channel[i].nrpackets == 1) {
  94609. + st->channel[i].fsm = FIQ_PER_ISO_OUT_LAST;
  94610. + } else {
  94611. + st->channel[i].fsm = FIQ_PER_ISO_OUT_ACTIVE;
  94612. + }
  94613. + fiq_fsm_restart_channel(st, i, 0);
  94614. + poked = 1;
  94615. + break;
  94616. +
  94617. + default:
  94618. + break;
  94619. + }
  94620. + }
  94621. + if (poked)
  94622. + break;
  94623. + }
  94624. + return poked;
  94625. +}
  94626. +
  94627. +/**
  94628. + * fiq_fsm_tt_in_use() - search for host channels using this TT
  94629. + * @n: Channel to use as reference
  94630. + *
  94631. + */
  94632. +int notrace noinline fiq_fsm_tt_in_use(struct fiq_state *st, int num_channels, int n)
  94633. +{
  94634. + int hub_addr = st->channel[n].hub_addr;
  94635. + int port_addr = st->channel[n].port_addr;
  94636. + int i, in_use = 0;
  94637. + for (i = 0; i < num_channels; i++) {
  94638. + if (i == n || st->channel[i].fsm == FIQ_PASSTHROUGH)
  94639. + continue;
  94640. + switch (st->channel[i].fsm) {
  94641. + /* TT is reserved for channels that are in the middle of a periodic
  94642. + * split transaction.
  94643. + */
  94644. + case FIQ_PER_SSPLIT_STARTED:
  94645. + case FIQ_PER_CSPLIT_WAIT:
  94646. + case FIQ_PER_CSPLIT_NYET1:
  94647. + //case FIQ_PER_CSPLIT_POLL:
  94648. + case FIQ_PER_ISO_OUT_ACTIVE:
  94649. + case FIQ_PER_ISO_OUT_LAST:
  94650. + if (st->channel[i].hub_addr == hub_addr &&
  94651. + st->channel[i].port_addr == port_addr) {
  94652. + in_use = 1;
  94653. + }
  94654. + break;
  94655. + default:
  94656. + break;
  94657. + }
  94658. + if (in_use)
  94659. + break;
  94660. + }
  94661. + return in_use;
  94662. +}
  94663. +
  94664. +/**
  94665. + * fiq_fsm_more_csplits() - determine whether additional CSPLITs need
  94666. + * to be issued for this IN transaction.
  94667. + *
  94668. + * We cannot tell the inbound PID of a data packet due to hardware limitations.
  94669. + * we need to make an educated guess as to whether we need to queue another CSPLIT
  94670. + * or not. A no-brainer is when we have received enough data to fill the endpoint
  94671. + * size, but for endpoints that give variable-length data then we have to resort
  94672. + * to heuristics.
  94673. + *
  94674. + * We also return whether this is the last CSPLIT to be queued, again based on
  94675. + * heuristics. This is to allow a 1-uframe overlap of periodic split transactions.
  94676. + * Note: requires at least 1 CSPLIT to have been performed prior to being called.
  94677. + */
  94678. +
  94679. +/*
  94680. + * We need some way of guaranteeing if a returned periodic packet of size X
  94681. + * has a DATA0 PID.
  94682. + * The heuristic value of 144 bytes assumes that the received data has maximal
  94683. + * bit-stuffing and the clock frequency of the transmitting device is at the lowest
  94684. + * permissible limit. If the transfer length results in a final packet size
  94685. + * 144 < p <= 188, then an erroneous CSPLIT will be issued.
  94686. + * Also used to ensure that an endpoint will nominally only return a single
  94687. + * complete-split worth of data.
  94688. + */
  94689. +#define DATA0_PID_HEURISTIC 144
  94690. +
  94691. +static int notrace noinline fiq_fsm_more_csplits(struct fiq_state *state, int n, int *probably_last)
  94692. +{
  94693. +
  94694. + int i;
  94695. + int total_len = 0;
  94696. + int more_needed = 1;
  94697. + struct fiq_channel_state *st = &state->channel[n];
  94698. +
  94699. + for (i = 0; i < st->dma_info.index; i++) {
  94700. + total_len += st->dma_info.slot_len[i];
  94701. + }
  94702. +
  94703. + *probably_last = 0;
  94704. +
  94705. + if (st->hcchar_copy.b.eptype == 0x3) {
  94706. + /*
  94707. + * An interrupt endpoint will take max 2 CSPLITs. if we are receiving data
  94708. + * then this is definitely the last CSPLIT.
  94709. + */
  94710. + *probably_last = 1;
  94711. + } else {
  94712. + /* Isoc IN. This is a bit risky if we are the first transaction:
  94713. + * we may have been held off slightly. */
  94714. + if (i > 1 && st->dma_info.slot_len[st->dma_info.index-1] <= DATA0_PID_HEURISTIC) {
  94715. + more_needed = 0;
  94716. + }
  94717. + /* If in the next uframe we will receive enough data to fill the endpoint,
  94718. + * then only issue 1 more csplit.
  94719. + */
  94720. + if (st->hctsiz_copy.b.xfersize - total_len <= DATA0_PID_HEURISTIC)
  94721. + *probably_last = 1;
  94722. + }
  94723. +
  94724. + if (total_len >= st->hctsiz_copy.b.xfersize ||
  94725. + i == 6 || total_len == 0)
  94726. + /* Note: due to bit stuffing it is possible to have > 6 CSPLITs for
  94727. + * a single endpoint. Accepting more would completely break our scheduling mechanism though
  94728. + * - in these extreme cases we will pass through a truncated packet.
  94729. + */
  94730. + more_needed = 0;
  94731. +
  94732. + return more_needed;
  94733. +}
  94734. +
  94735. +/**
  94736. + * fiq_fsm_too_late() - Test transaction for lateness
  94737. + *
  94738. + * If a SSPLIT for a large IN transaction is issued too late in a frame,
  94739. + * the hub will disable the port to the device and respond with ERR handshakes.
  94740. + * The hub status endpoint will not reflect this change.
  94741. + * Returns 1 if we will issue a SSPLIT that will result in a device babble.
  94742. + */
  94743. +int notrace fiq_fsm_too_late(struct fiq_state *st, int n)
  94744. +{
  94745. + int uframe;
  94746. + hfnum_data_t hfnum = { .d32 = FIQ_READ(st->dwc_regs_base + HFNUM) };
  94747. + uframe = hfnum.b.frnum & 0x7;
  94748. + if ((uframe < 6) && (st->channel[n].nrpackets + 1 + uframe > 7)) {
  94749. + return 1;
  94750. + } else {
  94751. + return 0;
  94752. + }
  94753. +}
  94754. +
  94755. +
  94756. +/**
  94757. + * fiq_fsm_start_next_periodic() - A half-arsed attempt at a microframe pipeline
  94758. + *
  94759. + * Search pending transactions in the start-split pending state and queue them.
  94760. + * Don't queue packets in uframe .5 (comes out in .6) (USB2.0 11.18.4).
  94761. + * Note: we specifically don't do isochronous OUT transactions first because better
  94762. + * use of the TT's start-split fifo can be achieved by pipelining an IN before an OUT.
  94763. + */
  94764. +static void notrace noinline fiq_fsm_start_next_periodic(struct fiq_state *st, int num_channels)
  94765. +{
  94766. + int n;
  94767. + hfnum_data_t hfnum = { .d32 = FIQ_READ(st->dwc_regs_base + HFNUM) };
  94768. + if ((hfnum.b.frnum & 0x7) == 5)
  94769. + return;
  94770. + for (n = 0; n < num_channels; n++) {
  94771. + if (st->channel[n].fsm == FIQ_PER_SSPLIT_QUEUED) {
  94772. + /* Check to see if any other transactions are using this TT */
  94773. + if(!fiq_fsm_tt_in_use(st, num_channels, n)) {
  94774. + if (!fiq_fsm_too_late(st, n)) {
  94775. + st->channel[n].fsm = FIQ_PER_SSPLIT_STARTED;
  94776. + fiq_print(FIQDBG_INT, st, "NEXTPER ");
  94777. + fiq_fsm_restart_channel(st, n, 0);
  94778. + } else {
  94779. + st->channel[n].fsm = FIQ_PER_SPLIT_TIMEOUT;
  94780. + }
  94781. + break;
  94782. + }
  94783. + }
  94784. + }
  94785. + for (n = 0; n < num_channels; n++) {
  94786. + if (st->channel[n].fsm == FIQ_PER_ISO_OUT_PENDING) {
  94787. + if (!fiq_fsm_tt_in_use(st, num_channels, n)) {
  94788. + fiq_print(FIQDBG_INT, st, "NEXTISO ");
  94789. + st->channel[n].fsm = FIQ_PER_ISO_OUT_ACTIVE;
  94790. + fiq_fsm_restart_channel(st, n, 0);
  94791. + break;
  94792. + }
  94793. + }
  94794. + }
  94795. +}
  94796. +
  94797. +/**
  94798. + * fiq_fsm_update_hs_isoc() - update isochronous frame and transfer data
  94799. + * @state: Pointer to fiq_state
  94800. + * @n: Channel transaction is active on
  94801. + * @hcint: Copy of host channel interrupt register
  94802. + *
  94803. + * Returns 0 if there are no more transactions for this HC to do, 1
  94804. + * otherwise.
  94805. + */
  94806. +static int notrace noinline fiq_fsm_update_hs_isoc(struct fiq_state *state, int n, hcint_data_t hcint)
  94807. +{
  94808. + struct fiq_channel_state *st = &state->channel[n];
  94809. + int xfer_len = 0, nrpackets = 0;
  94810. + hcdma_data_t hcdma;
  94811. + fiq_print(FIQDBG_INT, state, "HSISO %02d", n);
  94812. +
  94813. + xfer_len = fiq_get_xfer_len(state, n);
  94814. + st->hs_isoc_info.iso_desc[st->hs_isoc_info.index].actual_length = xfer_len;
  94815. +
  94816. + st->hs_isoc_info.iso_desc[st->hs_isoc_info.index].status = hcint.d32;
  94817. +
  94818. + st->hs_isoc_info.index++;
  94819. + if (st->hs_isoc_info.index == st->hs_isoc_info.nrframes) {
  94820. + return 0;
  94821. + }
  94822. +
  94823. + /* grab the next DMA address offset from the array */
  94824. + hcdma.d32 = st->hcdma_copy.d32 + st->hs_isoc_info.iso_desc[st->hs_isoc_info.index].offset;
  94825. + FIQ_WRITE(state->dwc_regs_base + HC_DMA + (HC_OFFSET * n), hcdma.d32);
  94826. +
  94827. + /* We need to set multi_count. This is a bit tricky - has to be set per-transaction as
  94828. + * the core needs to be told to send the correct number. Caution: for IN transfers,
  94829. + * this is always set to the maximum size of the endpoint. */
  94830. + xfer_len = st->hs_isoc_info.iso_desc[st->hs_isoc_info.index].length;
  94831. + /* Integer divide in a FIQ: fun. FIXME: make this not suck */
  94832. + nrpackets = (xfer_len + st->hcchar_copy.b.mps - 1) / st->hcchar_copy.b.mps;
  94833. + if (nrpackets == 0)
  94834. + nrpackets = 1;
  94835. + st->hcchar_copy.b.multicnt = nrpackets;
  94836. + st->hctsiz_copy.b.pktcnt = nrpackets;
  94837. +
  94838. + /* Initial PID also needs to be set */
  94839. + if (st->hcchar_copy.b.epdir == 0) {
  94840. + st->hctsiz_copy.b.xfersize = xfer_len;
  94841. + switch (st->hcchar_copy.b.multicnt) {
  94842. + case 1:
  94843. + st->hctsiz_copy.b.pid = DWC_PID_DATA0;
  94844. + break;
  94845. + case 2:
  94846. + case 3:
  94847. + st->hctsiz_copy.b.pid = DWC_PID_MDATA;
  94848. + break;
  94849. + }
  94850. +
  94851. + } else {
  94852. + switch (st->hcchar_copy.b.multicnt) {
  94853. + st->hctsiz_copy.b.xfersize = nrpackets * st->hcchar_copy.b.mps;
  94854. + case 1:
  94855. + st->hctsiz_copy.b.pid = DWC_PID_DATA0;
  94856. + break;
  94857. + case 2:
  94858. + st->hctsiz_copy.b.pid = DWC_PID_DATA1;
  94859. + break;
  94860. + case 3:
  94861. + st->hctsiz_copy.b.pid = DWC_PID_DATA2;
  94862. + break;
  94863. + }
  94864. + }
  94865. + FIQ_WRITE(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ, st->hctsiz_copy.d32);
  94866. + FIQ_WRITE(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR, st->hcchar_copy.d32);
  94867. + /* Channel is enabled on hcint handler exit */
  94868. + fiq_print(FIQDBG_INT, state, "HSISOOUT");
  94869. + return 1;
  94870. +}
  94871. +
  94872. +
  94873. +/**
  94874. + * fiq_fsm_do_sof() - FSM start-of-frame interrupt handler
  94875. + * @state: Pointer to the state struct passed from banked FIQ mode registers.
  94876. + * @num_channels: set according to the DWC hardware configuration
  94877. + *
  94878. + * The SOF handler in FSM mode has two functions
  94879. + * 1. Hold off SOF from causing schedule advancement in IRQ context if there's
  94880. + * nothing to do
  94881. + * 2. Advance certain FSM states that require either a microframe delay, or a microframe
  94882. + * of holdoff.
  94883. + *
  94884. + * The second part is architecture-specific to mach-bcm2835 -
  94885. + * a sane interrupt controller would have a mask register for ARM interrupt sources
  94886. + * to be promoted to the nFIQ line, but it doesn't. Instead a single interrupt
  94887. + * number (USB) can be enabled. This means that certain parts of the USB specification
  94888. + * that require "wait a little while, then issue another packet" cannot be fulfilled with
  94889. + * the timing granularity required to achieve optimal throughout. The workaround is to use
  94890. + * the SOF "timer" (125uS) to perform this task.
  94891. + */
  94892. +static int notrace noinline fiq_fsm_do_sof(struct fiq_state *state, int num_channels)
  94893. +{
  94894. + hfnum_data_t hfnum = { .d32 = FIQ_READ(state->dwc_regs_base + HFNUM) };
  94895. + int n;
  94896. + int kick_irq = 0;
  94897. +
  94898. + if ((hfnum.b.frnum & 0x7) == 1) {
  94899. + /* We cannot issue csplits for transactions in the last frame past (n+1).1
  94900. + * Check to see if there are any transactions that are stale.
  94901. + * Boot them out.
  94902. + */
  94903. + for (n = 0; n < num_channels; n++) {
  94904. + switch (state->channel[n].fsm) {
  94905. + case FIQ_PER_CSPLIT_WAIT:
  94906. + case FIQ_PER_CSPLIT_NYET1:
  94907. + case FIQ_PER_CSPLIT_POLL:
  94908. + case FIQ_PER_CSPLIT_LAST:
  94909. + /* Check if we are no longer in the same full-speed frame. */
  94910. + if (((state->channel[n].expected_uframe & 0x3FFF) & ~0x7) <
  94911. + (hfnum.b.frnum & ~0x7))
  94912. + state->channel[n].fsm = FIQ_PER_SPLIT_TIMEOUT;
  94913. + break;
  94914. + default:
  94915. + break;
  94916. + }
  94917. + }
  94918. + }
  94919. +
  94920. + for (n = 0; n < num_channels; n++) {
  94921. + switch (state->channel[n].fsm) {
  94922. +
  94923. + case FIQ_NP_SSPLIT_RETRY:
  94924. + case FIQ_NP_IN_CSPLIT_RETRY:
  94925. + case FIQ_NP_OUT_CSPLIT_RETRY:
  94926. + fiq_fsm_restart_channel(state, n, 0);
  94927. + break;
  94928. +
  94929. + case FIQ_HS_ISOC_SLEEPING:
  94930. + state->channel[n].fsm = FIQ_HS_ISOC_TURBO;
  94931. + fiq_fsm_restart_channel(state, n, 0);
  94932. + break;
  94933. +
  94934. + case FIQ_PER_SSPLIT_QUEUED:
  94935. + if ((hfnum.b.frnum & 0x7) == 5)
  94936. + break;
  94937. + if(!fiq_fsm_tt_in_use(state, num_channels, n)) {
  94938. + if (!fiq_fsm_too_late(state, n)) {
  94939. + fiq_print(FIQDBG_INT, st, "SOF GO %01d", n);
  94940. + fiq_fsm_restart_channel(state, n, 0);
  94941. + state->channel[n].fsm = FIQ_PER_SSPLIT_STARTED;
  94942. + } else {
  94943. + /* Transaction cannot be started without risking a device babble error */
  94944. + state->channel[n].fsm = FIQ_PER_SPLIT_TIMEOUT;
  94945. + state->haintmsk_saved.b2.chint &= ~(1 << n);
  94946. + FIQ_WRITE(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCINTMSK, 0);
  94947. + kick_irq |= 1;
  94948. + }
  94949. + }
  94950. + break;
  94951. +
  94952. + case FIQ_PER_ISO_OUT_PENDING:
  94953. + /* Ordinarily, this should be poked after the SSPLIT
  94954. + * complete interrupt for a competing transfer on the same
  94955. + * TT. Doesn't happen for aborted transactions though.
  94956. + */
  94957. + if ((hfnum.b.frnum & 0x7) >= 5)
  94958. + break;
  94959. + if (!fiq_fsm_tt_in_use(state, num_channels, n)) {
  94960. + /* Hardware bug. SOF can sometimes occur after the channel halt interrupt
  94961. + * that caused this.
  94962. + */
  94963. + fiq_fsm_restart_channel(state, n, 0);
  94964. + fiq_print(FIQDBG_INT, state, "SOF ISOC");
  94965. + if (state->channel[n].nrpackets == 1) {
  94966. + state->channel[n].fsm = FIQ_PER_ISO_OUT_LAST;
  94967. + } else {
  94968. + state->channel[n].fsm = FIQ_PER_ISO_OUT_ACTIVE;
  94969. + }
  94970. + }
  94971. + break;
  94972. +
  94973. + case FIQ_PER_CSPLIT_WAIT:
  94974. + /* we are guaranteed to be in this state if and only if the SSPLIT interrupt
  94975. + * occurred when the bus transaction occurred. The SOF interrupt reversal bug
  94976. + * will utterly bugger this up though.
  94977. + */
  94978. + if (hfnum.b.frnum != state->channel[n].expected_uframe) {
  94979. + fiq_print(FIQDBG_INT, state, "SOFCS %d ", n);
  94980. + state->channel[n].fsm = FIQ_PER_CSPLIT_POLL;
  94981. + fiq_fsm_restart_channel(state, n, 0);
  94982. + fiq_fsm_start_next_periodic(state, num_channels);
  94983. +
  94984. + }
  94985. + break;
  94986. +
  94987. + case FIQ_PER_SPLIT_TIMEOUT:
  94988. + case FIQ_DEQUEUE_ISSUED:
  94989. + /* Ugly: we have to force a HCD interrupt.
  94990. + * Poke the mask for the channel in question.
  94991. + * We will take a fake SOF because of this, but
  94992. + * that's OK.
  94993. + */
  94994. + state->haintmsk_saved.b2.chint &= ~(1 << n);
  94995. + FIQ_WRITE(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCINTMSK, 0);
  94996. + kick_irq |= 1;
  94997. + break;
  94998. +
  94999. + default:
  95000. + break;
  95001. + }
  95002. + }
  95003. +
  95004. + if (state->kick_np_queues ||
  95005. + dwc_frame_num_le(state->next_sched_frame, hfnum.b.frnum))
  95006. + kick_irq |= 1;
  95007. +
  95008. + return !kick_irq;
  95009. +}
  95010. +
  95011. +
  95012. +/**
  95013. + * fiq_fsm_do_hcintr() - FSM host channel interrupt handler
  95014. + * @state: Pointer to the FIQ state struct
  95015. + * @num_channels: Number of channels as per hardware config
  95016. + * @n: channel for which HAINT(i) was raised
  95017. + *
  95018. + * An important property is that only the CHHLT interrupt is unmasked. Unfortunately, AHBerr is as well.
  95019. + */
  95020. +static int notrace noinline fiq_fsm_do_hcintr(struct fiq_state *state, int num_channels, int n)
  95021. +{
  95022. + hcint_data_t hcint;
  95023. + hcintmsk_data_t hcintmsk;
  95024. + hcint_data_t hcint_probe;
  95025. + hcchar_data_t hcchar;
  95026. + int handled = 0;
  95027. + int restart = 0;
  95028. + int last_csplit = 0;
  95029. + int start_next_periodic = 0;
  95030. + struct fiq_channel_state *st = &state->channel[n];
  95031. + hfnum_data_t hfnum;
  95032. +
  95033. + hcint.d32 = FIQ_READ(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCINT);
  95034. + hcintmsk.d32 = FIQ_READ(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCINTMSK);
  95035. + hcint_probe.d32 = hcint.d32 & hcintmsk.d32;
  95036. +
  95037. + if (st->fsm != FIQ_PASSTHROUGH) {
  95038. + fiq_print(FIQDBG_INT, state, "HC%01d ST%02d", n, st->fsm);
  95039. + fiq_print(FIQDBG_INT, state, "%08x", hcint.d32);
  95040. + }
  95041. +
  95042. + switch (st->fsm) {
  95043. +
  95044. + case FIQ_PASSTHROUGH:
  95045. + case FIQ_DEQUEUE_ISSUED:
  95046. + /* doesn't belong to us, kick it upstairs */
  95047. + break;
  95048. +
  95049. + case FIQ_PASSTHROUGH_ERRORSTATE:
  95050. + /* We are here to emulate the error recovery mechanism of the dwc HCD.
  95051. + * Several interrupts are unmasked if a previous transaction failed - it's
  95052. + * death for the FIQ to attempt to handle them as the channel isn't halted.
  95053. + * Emulate what the HCD does in this situation: mask and continue.
  95054. + * The FSM has no other state setup so this has to be handled out-of-band.
  95055. + */
  95056. + fiq_print(FIQDBG_ERR, state, "ERRST %02d", n);
  95057. + if (hcint_probe.b.nak || hcint_probe.b.ack || hcint_probe.b.datatglerr) {
  95058. + fiq_print(FIQDBG_ERR, state, "RESET %02d", n);
  95059. + /* In some random cases we can get a NAK interrupt coincident with a Xacterr
  95060. + * interrupt, after the device has disappeared.
  95061. + */
  95062. + if (!hcint.b.xacterr)
  95063. + st->nr_errors = 0;
  95064. + hcintmsk.b.nak = 0;
  95065. + hcintmsk.b.ack = 0;
  95066. + hcintmsk.b.datatglerr = 0;
  95067. + FIQ_WRITE(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCINTMSK, hcintmsk.d32);
  95068. + return 1;
  95069. + }
  95070. + if (hcint_probe.b.chhltd) {
  95071. + fiq_print(FIQDBG_ERR, state, "CHHLT %02d", n);
  95072. + fiq_print(FIQDBG_ERR, state, "%08x", hcint.d32);
  95073. + return 0;
  95074. + }
  95075. + break;
  95076. +
  95077. + /* Non-periodic state groups */
  95078. + case FIQ_NP_SSPLIT_STARTED:
  95079. + case FIQ_NP_SSPLIT_RETRY:
  95080. + /* Got a HCINT for a NP SSPLIT. Expected ACK / NAK / fail */
  95081. + if (hcint.b.ack) {
  95082. + /* SSPLIT complete. For OUT, the data has been sent. For IN, the LS transaction
  95083. + * will start shortly. SOF needs to kick the transaction to prevent a NYET flood.
  95084. + */
  95085. + if(st->hcchar_copy.b.epdir == 1)
  95086. + st->fsm = FIQ_NP_IN_CSPLIT_RETRY;
  95087. + else
  95088. + st->fsm = FIQ_NP_OUT_CSPLIT_RETRY;
  95089. + st->nr_errors = 0;
  95090. + handled = 1;
  95091. + fiq_fsm_setup_csplit(state, n);
  95092. + } else if (hcint.b.nak) {
  95093. + // No buffer space in TT. Retry on a uframe boundary.
  95094. + st->fsm = FIQ_NP_SSPLIT_RETRY;
  95095. + handled = 1;
  95096. + } else if (hcint.b.xacterr) {
  95097. + // The only other one we care about is xacterr. This implies HS bus error - retry.
  95098. + st->nr_errors++;
  95099. + st->fsm = FIQ_NP_SSPLIT_RETRY;
  95100. + if (st->nr_errors >= 3) {
  95101. + st->fsm = FIQ_NP_SPLIT_HS_ABORTED;
  95102. + } else {
  95103. + handled = 1;
  95104. + restart = 1;
  95105. + }
  95106. + } else {
  95107. + st->fsm = FIQ_NP_SPLIT_LS_ABORTED;
  95108. + handled = 0;
  95109. + restart = 0;
  95110. + }
  95111. + break;
  95112. +
  95113. + case FIQ_NP_IN_CSPLIT_RETRY:
  95114. + /* Received a CSPLIT done interrupt.
  95115. + * Expected Data/NAK/STALL/NYET for IN.
  95116. + */
  95117. + if (hcint.b.xfercomp) {
  95118. + /* For IN, data is present. */
  95119. + st->fsm = FIQ_NP_SPLIT_DONE;
  95120. + } else if (hcint.b.nak) {
  95121. + /* no endpoint data. Punt it upstairs */
  95122. + st->fsm = FIQ_NP_SPLIT_DONE;
  95123. + } else if (hcint.b.nyet) {
  95124. + /* CSPLIT NYET - retry on a uframe boundary. */
  95125. + handled = 1;
  95126. + st->nr_errors = 0;
  95127. + } else if (hcint.b.datatglerr) {
  95128. + /* data toggle errors do not set the xfercomp bit. */
  95129. + st->fsm = FIQ_NP_SPLIT_LS_ABORTED;
  95130. + } else if (hcint.b.xacterr) {
  95131. + /* HS error. Retry immediate */
  95132. + st->fsm = FIQ_NP_IN_CSPLIT_RETRY;
  95133. + st->nr_errors++;
  95134. + if (st->nr_errors >= 3) {
  95135. + st->fsm = FIQ_NP_SPLIT_HS_ABORTED;
  95136. + } else {
  95137. + handled = 1;
  95138. + restart = 1;
  95139. + }
  95140. + } else if (hcint.b.stall || hcint.b.bblerr) {
  95141. + /* A STALL implies either a LS bus error or a genuine STALL. */
  95142. + st->fsm = FIQ_NP_SPLIT_LS_ABORTED;
  95143. + } else {
  95144. + /* Hardware bug. It's possible in some cases to
  95145. + * get a channel halt with nothing else set when
  95146. + * the response was a NYET. Treat as local 3-strikes retry.
  95147. + */
  95148. + hcint_data_t hcint_test = hcint;
  95149. + hcint_test.b.chhltd = 0;
  95150. + if (!hcint_test.d32) {
  95151. + st->nr_errors++;
  95152. + if (st->nr_errors >= 3) {
  95153. + st->fsm = FIQ_NP_SPLIT_HS_ABORTED;
  95154. + } else {
  95155. + handled = 1;
  95156. + }
  95157. + } else {
  95158. + /* Bail out if something unexpected happened */
  95159. + st->fsm = FIQ_NP_SPLIT_HS_ABORTED;
  95160. + }
  95161. + }
  95162. + break;
  95163. +
  95164. + case FIQ_NP_OUT_CSPLIT_RETRY:
  95165. + /* Received a CSPLIT done interrupt.
  95166. + * Expected ACK/NAK/STALL/NYET/XFERCOMP for OUT.*/
  95167. + if (hcint.b.xfercomp) {
  95168. + st->fsm = FIQ_NP_SPLIT_DONE;
  95169. + } else if (hcint.b.nak) {
  95170. + // The HCD will implement the holdoff on frame boundaries.
  95171. + st->fsm = FIQ_NP_SPLIT_DONE;
  95172. + } else if (hcint.b.nyet) {
  95173. + // Hub still processing.
  95174. + st->fsm = FIQ_NP_OUT_CSPLIT_RETRY;
  95175. + handled = 1;
  95176. + st->nr_errors = 0;
  95177. + //restart = 1;
  95178. + } else if (hcint.b.xacterr) {
  95179. + /* HS error. retry immediate */
  95180. + st->fsm = FIQ_NP_OUT_CSPLIT_RETRY;
  95181. + st->nr_errors++;
  95182. + if (st->nr_errors >= 3) {
  95183. + st->fsm = FIQ_NP_SPLIT_HS_ABORTED;
  95184. + } else {
  95185. + handled = 1;
  95186. + restart = 1;
  95187. + }
  95188. + } else if (hcint.b.stall) {
  95189. + /* LS bus error or genuine stall */
  95190. + st->fsm = FIQ_NP_SPLIT_LS_ABORTED;
  95191. + } else {
  95192. + /*
  95193. + * Hardware bug. It's possible in some cases to get a
  95194. + * channel halt with nothing else set when the response was a NYET.
  95195. + * Treat as local 3-strikes retry.
  95196. + */
  95197. + hcint_data_t hcint_test = hcint;
  95198. + hcint_test.b.chhltd = 0;
  95199. + if (!hcint_test.d32) {
  95200. + st->nr_errors++;
  95201. + if (st->nr_errors >= 3) {
  95202. + st->fsm = FIQ_NP_SPLIT_HS_ABORTED;
  95203. + } else {
  95204. + handled = 1;
  95205. + }
  95206. + } else {
  95207. + // Something unexpected happened. AHBerror or babble perhaps. Let the IRQ deal with it.
  95208. + st->fsm = FIQ_NP_SPLIT_HS_ABORTED;
  95209. + }
  95210. + }
  95211. + break;
  95212. +
  95213. + /* Periodic split states (except isoc out) */
  95214. + case FIQ_PER_SSPLIT_STARTED:
  95215. + /* Expect an ACK or failure for SSPLIT */
  95216. + if (hcint.b.ack) {
  95217. + /*
  95218. + * SSPLIT transfer complete interrupt - the generation of this interrupt is fraught with bugs.
  95219. + * For a packet queued in microframe n-3 to appear in n-2, if the channel is enabled near the EOF1
  95220. + * point for microframe n-3, the packet will not appear on the bus until microframe n.
  95221. + * Additionally, the generation of the actual interrupt is dodgy. For a packet appearing on the bus
  95222. + * in microframe n, sometimes the interrupt is generated immediately. Sometimes, it appears in n+1
  95223. + * coincident with SOF for n+1.
  95224. + * SOF is also buggy. It can sometimes be raised AFTER the first bus transaction has taken place.
  95225. + * These appear to be caused by timing/clock crossing bugs within the core itself.
  95226. + * State machine workaround.
  95227. + */
  95228. + hfnum.d32 = FIQ_READ(state->dwc_regs_base + HFNUM);
  95229. + hcchar.d32 = FIQ_READ(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR);
  95230. + fiq_fsm_setup_csplit(state, n);
  95231. + /* Poke the oddfrm bit. If we are equivalent, we received the interrupt at the correct
  95232. + * time. If not, then we're in the next SOF.
  95233. + */
  95234. + if ((hfnum.b.frnum & 0x1) == hcchar.b.oddfrm) {
  95235. + fiq_print(FIQDBG_INT, state, "CSWAIT %01d", n);
  95236. + st->expected_uframe = hfnum.b.frnum;
  95237. + st->fsm = FIQ_PER_CSPLIT_WAIT;
  95238. + } else {
  95239. + fiq_print(FIQDBG_INT, state, "CSPOL %01d", n);
  95240. + /* For isochronous IN endpoints,
  95241. + * we need to hold off if we are expecting a lot of data */
  95242. + if (st->hcchar_copy.b.mps < DATA0_PID_HEURISTIC) {
  95243. + start_next_periodic = 1;
  95244. + }
  95245. + /* Danger will robinson: we are in a broken state. If our first interrupt after
  95246. + * this is a NYET, it will be delayed by 1 uframe and result in an unrecoverable
  95247. + * lag. Unmask the NYET interrupt.
  95248. + */
  95249. + st->expected_uframe = (hfnum.b.frnum + 1) & 0x3FFF;
  95250. + st->fsm = FIQ_PER_CSPLIT_BROKEN_NYET1;
  95251. + restart = 1;
  95252. + }
  95253. + handled = 1;
  95254. + } else if (hcint.b.xacterr) {
  95255. + /* 3-strikes retry is enabled, we have hit our max nr_errors */
  95256. + st->fsm = FIQ_PER_SPLIT_HS_ABORTED;
  95257. + start_next_periodic = 1;
  95258. + } else {
  95259. + st->fsm = FIQ_PER_SPLIT_HS_ABORTED;
  95260. + start_next_periodic = 1;
  95261. + }
  95262. + /* We can now queue the next isochronous OUT transaction, if one is pending. */
  95263. + if(fiq_fsm_tt_next_isoc(state, num_channels, n)) {
  95264. + fiq_print(FIQDBG_INT, state, "NEXTISO ");
  95265. + }
  95266. + break;
  95267. +
  95268. + case FIQ_PER_CSPLIT_NYET1:
  95269. + /* First CSPLIT attempt was a NYET. If we get a subsequent NYET,
  95270. + * we are too late and the TT has dropped its CSPLIT fifo.
  95271. + */
  95272. + hfnum.d32 = FIQ_READ(state->dwc_regs_base + HFNUM);
  95273. + hcchar.d32 = FIQ_READ(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR);
  95274. + start_next_periodic = 1;
  95275. + if (hcint.b.nak) {
  95276. + st->fsm = FIQ_PER_SPLIT_DONE;
  95277. + } else if (hcint.b.xfercomp) {
  95278. + fiq_increment_dma_buf(state, num_channels, n);
  95279. + st->fsm = FIQ_PER_CSPLIT_POLL;
  95280. + st->nr_errors = 0;
  95281. + if (fiq_fsm_more_csplits(state, n, &last_csplit)) {
  95282. + handled = 1;
  95283. + restart = 1;
  95284. + if (!last_csplit)
  95285. + start_next_periodic = 0;
  95286. + } else {
  95287. + st->fsm = FIQ_PER_SPLIT_DONE;
  95288. + }
  95289. + } else if (hcint.b.nyet) {
  95290. + /* Doh. Data lost. */
  95291. + st->fsm = FIQ_PER_SPLIT_NYET_ABORTED;
  95292. + } else if (hcint.b.xacterr || hcint.b.stall || hcint.b.bblerr) {
  95293. + st->fsm = FIQ_PER_SPLIT_LS_ABORTED;
  95294. + } else {
  95295. + st->fsm = FIQ_PER_SPLIT_HS_ABORTED;
  95296. + }
  95297. + break;
  95298. +
  95299. + case FIQ_PER_CSPLIT_BROKEN_NYET1:
  95300. + /*
  95301. + * we got here because our host channel is in the delayed-interrupt
  95302. + * state and we cannot take a NYET interrupt any later than when it
  95303. + * occurred. Disable then re-enable the channel if this happens to force
  95304. + * CSPLITs to occur at the right time.
  95305. + */
  95306. + hfnum.d32 = FIQ_READ(state->dwc_regs_base + HFNUM);
  95307. + hcchar.d32 = FIQ_READ(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR);
  95308. + fiq_print(FIQDBG_INT, state, "BROK: %01d ", n);
  95309. + if (hcint.b.nak) {
  95310. + st->fsm = FIQ_PER_SPLIT_DONE;
  95311. + start_next_periodic = 1;
  95312. + } else if (hcint.b.xfercomp) {
  95313. + fiq_increment_dma_buf(state, num_channels, n);
  95314. + if (fiq_fsm_more_csplits(state, n, &last_csplit)) {
  95315. + st->fsm = FIQ_PER_CSPLIT_POLL;
  95316. + handled = 1;
  95317. + restart = 1;
  95318. + start_next_periodic = 1;
  95319. + /* Reload HCTSIZ for the next transfer */
  95320. + fiq_fsm_reload_hctsiz(state, n);
  95321. + if (!last_csplit)
  95322. + start_next_periodic = 0;
  95323. + } else {
  95324. + st->fsm = FIQ_PER_SPLIT_DONE;
  95325. + }
  95326. + } else if (hcint.b.nyet) {
  95327. + st->fsm = FIQ_PER_SPLIT_NYET_ABORTED;
  95328. + start_next_periodic = 1;
  95329. + } else if (hcint.b.xacterr || hcint.b.stall || hcint.b.bblerr) {
  95330. + /* Local 3-strikes retry is handled by the core. This is a ERR response.*/
  95331. + st->fsm = FIQ_PER_SPLIT_LS_ABORTED;
  95332. + } else {
  95333. + st->fsm = FIQ_PER_SPLIT_HS_ABORTED;
  95334. + }
  95335. + break;
  95336. +
  95337. + case FIQ_PER_CSPLIT_POLL:
  95338. + hfnum.d32 = FIQ_READ(state->dwc_regs_base + HFNUM);
  95339. + hcchar.d32 = FIQ_READ(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR);
  95340. + start_next_periodic = 1;
  95341. + if (hcint.b.nak) {
  95342. + st->fsm = FIQ_PER_SPLIT_DONE;
  95343. + } else if (hcint.b.xfercomp) {
  95344. + fiq_increment_dma_buf(state, num_channels, n);
  95345. + if (fiq_fsm_more_csplits(state, n, &last_csplit)) {
  95346. + handled = 1;
  95347. + restart = 1;
  95348. + /* Reload HCTSIZ for the next transfer */
  95349. + fiq_fsm_reload_hctsiz(state, n);
  95350. + if (!last_csplit)
  95351. + start_next_periodic = 0;
  95352. + } else {
  95353. + st->fsm = FIQ_PER_SPLIT_DONE;
  95354. + }
  95355. + } else if (hcint.b.nyet) {
  95356. + /* Are we a NYET after the first data packet? */
  95357. + if (st->nrpackets == 0) {
  95358. + st->fsm = FIQ_PER_CSPLIT_NYET1;
  95359. + handled = 1;
  95360. + restart = 1;
  95361. + } else {
  95362. + /* We got a NYET when polling CSPLITs. Can happen
  95363. + * if our heuristic fails, or if someone disables us
  95364. + * for any significant length of time.
  95365. + */
  95366. + if (st->nr_errors >= 3) {
  95367. + st->fsm = FIQ_PER_SPLIT_NYET_ABORTED;
  95368. + } else {
  95369. + st->fsm = FIQ_PER_SPLIT_DONE;
  95370. + }
  95371. + }
  95372. + } else if (hcint.b.xacterr || hcint.b.stall || hcint.b.bblerr) {
  95373. + /* For xacterr, Local 3-strikes retry is handled by the core. This is a ERR response.*/
  95374. + st->fsm = FIQ_PER_SPLIT_LS_ABORTED;
  95375. + } else {
  95376. + st->fsm = FIQ_PER_SPLIT_HS_ABORTED;
  95377. + }
  95378. + break;
  95379. +
  95380. + case FIQ_HS_ISOC_TURBO:
  95381. + if (fiq_fsm_update_hs_isoc(state, n, hcint)) {
  95382. + /* more transactions to come */
  95383. + handled = 1;
  95384. + restart = 1;
  95385. + fiq_print(FIQDBG_INT, state, "HSISO M ");
  95386. + } else {
  95387. + st->fsm = FIQ_HS_ISOC_DONE;
  95388. + fiq_print(FIQDBG_INT, state, "HSISO F ");
  95389. + }
  95390. + break;
  95391. +
  95392. + case FIQ_HS_ISOC_ABORTED:
  95393. + /* This abort is called by the driver rewriting the state mid-transaction
  95394. + * which allows the dequeue mechanism to work more effectively.
  95395. + */
  95396. + break;
  95397. +
  95398. + case FIQ_PER_ISO_OUT_ACTIVE:
  95399. + if (hcint.b.ack) {
  95400. + if(fiq_iso_out_advance(state, num_channels, n)) {
  95401. + /* last OUT transfer */
  95402. + st->fsm = FIQ_PER_ISO_OUT_LAST;
  95403. + /*
  95404. + * Assuming the periodic FIFO in the dwc core
  95405. + * actually does its job properly, we can queue
  95406. + * the next ssplit now and in theory, the wire
  95407. + * transactions will be in-order.
  95408. + */
  95409. + // No it doesn't. It appears to process requests in host channel order.
  95410. + //start_next_periodic = 1;
  95411. + }
  95412. + handled = 1;
  95413. + restart = 1;
  95414. + } else {
  95415. + /*
  95416. + * Isochronous transactions carry on regardless. Log the error
  95417. + * and continue.
  95418. + */
  95419. + //explode += 1;
  95420. + st->nr_errors++;
  95421. + if(fiq_iso_out_advance(state, num_channels, n)) {
  95422. + st->fsm = FIQ_PER_ISO_OUT_LAST;
  95423. + //start_next_periodic = 1;
  95424. + }
  95425. + handled = 1;
  95426. + restart = 1;
  95427. + }
  95428. + break;
  95429. +
  95430. + case FIQ_PER_ISO_OUT_LAST:
  95431. + if (hcint.b.ack) {
  95432. + /* All done here */
  95433. + st->fsm = FIQ_PER_ISO_OUT_DONE;
  95434. + } else {
  95435. + st->fsm = FIQ_PER_ISO_OUT_DONE;
  95436. + st->nr_errors++;
  95437. + }
  95438. + start_next_periodic = 1;
  95439. + break;
  95440. +
  95441. + case FIQ_PER_SPLIT_TIMEOUT:
  95442. + /* SOF kicked us because we overran. */
  95443. + start_next_periodic = 1;
  95444. + break;
  95445. +
  95446. + default:
  95447. + break;
  95448. + }
  95449. +
  95450. + if (handled) {
  95451. + FIQ_WRITE(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCINT, hcint.d32);
  95452. + } else {
  95453. + /* Copy the regs into the state so the IRQ knows what to do */
  95454. + st->hcint_copy.d32 = hcint.d32;
  95455. + }
  95456. +
  95457. + if (restart) {
  95458. + /* Restart always implies handled. */
  95459. + if (restart == 2) {
  95460. + /* For complete-split INs, the show must go on.
  95461. + * Force a channel restart */
  95462. + fiq_fsm_restart_channel(state, n, 1);
  95463. + } else {
  95464. + fiq_fsm_restart_channel(state, n, 0);
  95465. + }
  95466. + }
  95467. + if (start_next_periodic) {
  95468. + fiq_fsm_start_next_periodic(state, num_channels);
  95469. + }
  95470. + if (st->fsm != FIQ_PASSTHROUGH)
  95471. + fiq_print(FIQDBG_INT, state, "FSMOUT%02d", st->fsm);
  95472. +
  95473. + return handled;
  95474. +}
  95475. +
  95476. +
  95477. +/**
  95478. + * dwc_otg_fiq_fsm() - Flying State Machine (monster) FIQ
  95479. + * @state: pointer to state struct passed from the banked FIQ mode registers.
  95480. + * @num_channels: set according to the DWC hardware configuration
  95481. + * @dma: pointer to DMA bounce buffers for split transaction slots
  95482. + *
  95483. + * The FSM FIQ performs the low-level tasks that normally would be performed by the microcode
  95484. + * inside an EHCI or similar host controller regarding split transactions. The DWC core
  95485. + * interrupts each and every time a split transaction packet is received or sent successfully.
  95486. + * This results in either an interrupt storm when everything is working "properly", or
  95487. + * the interrupt latency of the system in general breaks time-sensitive periodic split
  95488. + * transactions. Pushing the low-level, but relatively easy state machine work into the FIQ
  95489. + * solves these problems.
  95490. + *
  95491. + * Return: void
  95492. + */
  95493. +void notrace dwc_otg_fiq_fsm(struct fiq_state *state, int num_channels)
  95494. +{
  95495. + gintsts_data_t gintsts, gintsts_handled;
  95496. + gintmsk_data_t gintmsk;
  95497. + //hfnum_data_t hfnum;
  95498. + haint_data_t haint, haint_handled;
  95499. + haintmsk_data_t haintmsk;
  95500. + int kick_irq = 0;
  95501. +
  95502. + gintsts_handled.d32 = 0;
  95503. + haint_handled.d32 = 0;
  95504. +
  95505. + fiq_fsm_spin_lock(&state->lock);
  95506. + gintsts.d32 = FIQ_READ(state->dwc_regs_base + GINTSTS);
  95507. + gintmsk.d32 = FIQ_READ(state->dwc_regs_base + GINTMSK);
  95508. + gintsts.d32 &= gintmsk.d32;
  95509. +
  95510. + if (gintsts.b.sofintr) {
  95511. + /* For FSM mode, SOF is required to keep the state machine advance for
  95512. + * certain stages of the periodic pipeline. It's death to mask this
  95513. + * interrupt in that case.
  95514. + */
  95515. +
  95516. + if (!fiq_fsm_do_sof(state, num_channels)) {
  95517. + /* Kick IRQ once. Queue advancement means that all pending transactions
  95518. + * will get serviced when the IRQ finally executes.
  95519. + */
  95520. + if (state->gintmsk_saved.b.sofintr == 1)
  95521. + kick_irq |= 1;
  95522. + state->gintmsk_saved.b.sofintr = 0;
  95523. + }
  95524. + gintsts_handled.b.sofintr = 1;
  95525. + }
  95526. +
  95527. + if (gintsts.b.hcintr) {
  95528. + int i;
  95529. + haint.d32 = FIQ_READ(state->dwc_regs_base + HAINT);
  95530. + haintmsk.d32 = FIQ_READ(state->dwc_regs_base + HAINTMSK);
  95531. + haint.d32 &= haintmsk.d32;
  95532. + haint_handled.d32 = 0;
  95533. + for (i=0; i<num_channels; i++) {
  95534. + if (haint.b2.chint & (1 << i)) {
  95535. + if(!fiq_fsm_do_hcintr(state, num_channels, i)) {
  95536. + /* HCINT was not handled in FIQ
  95537. + * HAINT is level-sensitive, leading to level-sensitive ginststs.b.hcint bit.
  95538. + * Mask HAINT(i) but keep top-level hcint unmasked.
  95539. + */
  95540. + state->haintmsk_saved.b2.chint &= ~(1 << i);
  95541. + } else {
  95542. + /* do_hcintr cleaned up after itself, but clear haint */
  95543. + haint_handled.b2.chint |= (1 << i);
  95544. + }
  95545. + }
  95546. + }
  95547. +
  95548. + if (haint_handled.b2.chint) {
  95549. + FIQ_WRITE(state->dwc_regs_base + HAINT, haint_handled.d32);
  95550. + }
  95551. +
  95552. + if (haintmsk.d32 != (haintmsk.d32 & state->haintmsk_saved.d32)) {
  95553. + /*
  95554. + * This is necessary to avoid multiple retriggers of the MPHI in the case
  95555. + * where interrupts are held off and HCINTs start to pile up.
  95556. + * Only wake up the IRQ if a new interrupt came in, was not handled and was
  95557. + * masked.
  95558. + */
  95559. + haintmsk.d32 &= state->haintmsk_saved.d32;
  95560. + FIQ_WRITE(state->dwc_regs_base + HAINTMSK, haintmsk.d32);
  95561. + kick_irq |= 1;
  95562. + }
  95563. + /* Top-Level interrupt - always handled because it's level-sensitive */
  95564. + gintsts_handled.b.hcintr = 1;
  95565. + }
  95566. +
  95567. +
  95568. + /* Clear the bits in the saved register that were not handled but were triggered. */
  95569. + state->gintmsk_saved.d32 &= ~(gintsts.d32 & ~gintsts_handled.d32);
  95570. +
  95571. + /* FIQ didn't handle something - mask has changed - write new mask */
  95572. + if (gintmsk.d32 != (gintmsk.d32 & state->gintmsk_saved.d32)) {
  95573. + gintmsk.d32 &= state->gintmsk_saved.d32;
  95574. + gintmsk.b.sofintr = 1;
  95575. + FIQ_WRITE(state->dwc_regs_base + GINTMSK, gintmsk.d32);
  95576. +// fiq_print(FIQDBG_INT, state, "KICKGINT");
  95577. +// fiq_print(FIQDBG_INT, state, "%08x", gintmsk.d32);
  95578. +// fiq_print(FIQDBG_INT, state, "%08x", state->gintmsk_saved.d32);
  95579. + kick_irq |= 1;
  95580. + }
  95581. +
  95582. + if (gintsts_handled.d32) {
  95583. + /* Only applies to edge-sensitive bits in GINTSTS */
  95584. + FIQ_WRITE(state->dwc_regs_base + GINTSTS, gintsts_handled.d32);
  95585. + }
  95586. +
  95587. + /* We got an interrupt, didn't handle it. */
  95588. + if (kick_irq) {
  95589. + state->mphi_int_count++;
  95590. + FIQ_WRITE(state->mphi_regs.outdda, (int) state->dummy_send);
  95591. + FIQ_WRITE(state->mphi_regs.outddb, (1<<29));
  95592. +
  95593. + }
  95594. + state->fiq_done++;
  95595. + mb();
  95596. + fiq_fsm_spin_unlock(&state->lock);
  95597. +}
  95598. +
  95599. +
  95600. +/**
  95601. + * dwc_otg_fiq_nop() - FIQ "lite"
  95602. + * @state: pointer to state struct passed from the banked FIQ mode registers.
  95603. + *
  95604. + * The "nop" handler does not intervene on any interrupts other than SOF.
  95605. + * It is limited in scope to deciding at each SOF if the IRQ SOF handler (which deals
  95606. + * with non-periodic/periodic queues) needs to be kicked.
  95607. + *
  95608. + * This is done to hold off the SOF interrupt, which occurs at a rate of 8000 per second.
  95609. + *
  95610. + * Return: void
  95611. + */
  95612. +void notrace dwc_otg_fiq_nop(struct fiq_state *state)
  95613. +{
  95614. + gintsts_data_t gintsts, gintsts_handled;
  95615. + gintmsk_data_t gintmsk;
  95616. + hfnum_data_t hfnum;
  95617. +
  95618. + fiq_fsm_spin_lock(&state->lock);
  95619. + hfnum.d32 = FIQ_READ(state->dwc_regs_base + HFNUM);
  95620. + gintsts.d32 = FIQ_READ(state->dwc_regs_base + GINTSTS);
  95621. + gintmsk.d32 = FIQ_READ(state->dwc_regs_base + GINTMSK);
  95622. + gintsts.d32 &= gintmsk.d32;
  95623. + gintsts_handled.d32 = 0;
  95624. +
  95625. + if (gintsts.b.sofintr) {
  95626. + if (!state->kick_np_queues &&
  95627. + dwc_frame_num_gt(state->next_sched_frame, hfnum.b.frnum)) {
  95628. + /* SOF handled, no work to do, just ACK interrupt */
  95629. + gintsts_handled.b.sofintr = 1;
  95630. + } else {
  95631. + /* Kick IRQ */
  95632. + state->gintmsk_saved.b.sofintr = 0;
  95633. + }
  95634. + }
  95635. +
  95636. + /* Reset handled interrupts */
  95637. + if(gintsts_handled.d32) {
  95638. + FIQ_WRITE(state->dwc_regs_base + GINTSTS, gintsts_handled.d32);
  95639. + }
  95640. +
  95641. + /* Clear the bits in the saved register that were not handled but were triggered. */
  95642. + state->gintmsk_saved.d32 &= ~(gintsts.d32 & ~gintsts_handled.d32);
  95643. +
  95644. + /* We got an interrupt, didn't handle it and want to mask it */
  95645. + if (~(state->gintmsk_saved.d32)) {
  95646. + state->mphi_int_count++;
  95647. + gintmsk.d32 &= state->gintmsk_saved.d32;
  95648. + FIQ_WRITE(state->dwc_regs_base + GINTMSK, gintmsk.d32);
  95649. + /* Force a clear before another dummy send */
  95650. + FIQ_WRITE(state->mphi_regs.intstat, (1<<29));
  95651. + FIQ_WRITE(state->mphi_regs.outdda, (int) state->dummy_send);
  95652. + FIQ_WRITE(state->mphi_regs.outddb, (1<<29));
  95653. +
  95654. + }
  95655. + state->fiq_done++;
  95656. + mb();
  95657. + fiq_fsm_spin_unlock(&state->lock);
  95658. +}
  95659. diff -Nur linux-3.18.8/drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.h
  95660. --- linux-3.18.8/drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.h 1970-01-01 01:00:00.000000000 +0100
  95661. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.h 2015-03-05 14:40:16.557715806 +0100
  95662. @@ -0,0 +1,367 @@
  95663. +/*
  95664. + * dwc_otg_fiq_fsm.h - Finite state machine FIQ header definitions
  95665. + *
  95666. + * Copyright (c) 2013 Raspberry Pi Foundation
  95667. + *
  95668. + * Author: Jonathan Bell <jonathan@raspberrypi.org>
  95669. + * All rights reserved.
  95670. + *
  95671. + * Redistribution and use in source and binary forms, with or without
  95672. + * modification, are permitted provided that the following conditions are met:
  95673. + * * Redistributions of source code must retain the above copyright
  95674. + * notice, this list of conditions and the following disclaimer.
  95675. + * * Redistributions in binary form must reproduce the above copyright
  95676. + * notice, this list of conditions and the following disclaimer in the
  95677. + * documentation and/or other materials provided with the distribution.
  95678. + * * Neither the name of Raspberry Pi nor the
  95679. + * names of its contributors may be used to endorse or promote products
  95680. + * derived from this software without specific prior written permission.
  95681. + *
  95682. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  95683. + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  95684. + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  95685. + * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  95686. + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  95687. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  95688. + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  95689. + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  95690. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  95691. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  95692. + *
  95693. + * This FIQ implements functionality that performs split transactions on
  95694. + * the dwc_otg hardware without any outside intervention. A split transaction
  95695. + * is "queued" by nominating a specific host channel to perform the entirety
  95696. + * of a split transaction. This FIQ will then perform the microframe-precise
  95697. + * scheduling required in each phase of the transaction until completion.
  95698. + *
  95699. + * The FIQ functionality has been surgically implanted into the Synopsys
  95700. + * vendor-provided driver.
  95701. + *
  95702. + */
  95703. +
  95704. +#ifndef DWC_OTG_FIQ_FSM_H_
  95705. +#define DWC_OTG_FIQ_FSM_H_
  95706. +
  95707. +#include "dwc_otg_regs.h"
  95708. +#include "dwc_otg_cil.h"
  95709. +#include "dwc_otg_hcd.h"
  95710. +#include <linux/kernel.h>
  95711. +#include <linux/irqflags.h>
  95712. +#include <linux/string.h>
  95713. +#include <asm/barrier.h>
  95714. +
  95715. +#if 0
  95716. +#define FLAME_ON(x) \
  95717. +do { \
  95718. + int gpioreg; \
  95719. + \
  95720. + gpioreg = readl(__io_address(0x20200000+0x8)); \
  95721. + gpioreg &= ~(7 << (x-20)*3); \
  95722. + gpioreg |= 0x1 << (x-20)*3; \
  95723. + writel(gpioreg, __io_address(0x20200000+0x8)); \
  95724. + \
  95725. + writel(1<<x, __io_address(0x20200000+(0x1C))); \
  95726. +} while (0)
  95727. +
  95728. +#define FLAME_OFF(x) \
  95729. +do { \
  95730. + writel(1<<x, __io_address(0x20200000+(0x28))); \
  95731. +} while (0)
  95732. +#else
  95733. +#define FLAME_ON(x) do { } while (0)
  95734. +#define FLAME_OFF(X) do { } while (0)
  95735. +#endif
  95736. +
  95737. +/* This is a quick-and-dirty arch-specific register read/write. We know that
  95738. + * writes to a peripheral on BCM2835 will always arrive in-order, also that
  95739. + * reads and writes are executed in-order therefore the need for memory barriers
  95740. + * is obviated if we're only talking to USB.
  95741. + */
  95742. +#define FIQ_WRITE(_addr_,_data_) (*(volatile unsigned int *) (_addr_) = (_data_))
  95743. +#define FIQ_READ(_addr_) (*(volatile unsigned int *) (_addr_))
  95744. +
  95745. +/* FIQ-ified register definitions. Offsets are from dwc_regs_base. */
  95746. +#define GINTSTS 0x014
  95747. +#define GINTMSK 0x018
  95748. +/* Debug register. Poll the top of the received packets FIFO. */
  95749. +#define GRXSTSR 0x01C
  95750. +#define HFNUM 0x408
  95751. +#define HAINT 0x414
  95752. +#define HAINTMSK 0x418
  95753. +#define HPRT0 0x440
  95754. +
  95755. +/* HC_regs start from an offset of 0x500 */
  95756. +#define HC_START 0x500
  95757. +#define HC_OFFSET 0x020
  95758. +
  95759. +#define HC_DMA 0x514
  95760. +
  95761. +#define HCCHAR 0x00
  95762. +#define HCSPLT 0x04
  95763. +#define HCINT 0x08
  95764. +#define HCINTMSK 0x0C
  95765. +#define HCTSIZ 0x10
  95766. +
  95767. +#define ISOC_XACTPOS_ALL 0b11
  95768. +#define ISOC_XACTPOS_BEGIN 0b10
  95769. +#define ISOC_XACTPOS_MID 0b00
  95770. +#define ISOC_XACTPOS_END 0b01
  95771. +
  95772. +#define DWC_PID_DATA2 0b01
  95773. +#define DWC_PID_MDATA 0b11
  95774. +#define DWC_PID_DATA1 0b10
  95775. +#define DWC_PID_DATA0 0b00
  95776. +
  95777. +typedef struct {
  95778. + volatile void* base;
  95779. + volatile void* ctrl;
  95780. + volatile void* outdda;
  95781. + volatile void* outddb;
  95782. + volatile void* intstat;
  95783. +} mphi_regs_t;
  95784. +
  95785. +enum fiq_debug_level {
  95786. + FIQDBG_SCHED = (1 << 0),
  95787. + FIQDBG_INT = (1 << 1),
  95788. + FIQDBG_ERR = (1 << 2),
  95789. + FIQDBG_PORTHUB = (1 << 3),
  95790. +};
  95791. +
  95792. +typedef struct {
  95793. + union {
  95794. + uint32_t slock;
  95795. + struct _tickets {
  95796. + uint16_t owner;
  95797. + uint16_t next;
  95798. + } tickets;
  95799. + };
  95800. +} fiq_lock_t;
  95801. +
  95802. +struct fiq_state;
  95803. +
  95804. +extern void _fiq_print (enum fiq_debug_level dbg_lvl, volatile struct fiq_state *state, char *fmt, ...);
  95805. +#if 0
  95806. +#define fiq_print _fiq_print
  95807. +#else
  95808. +#define fiq_print(x, y, ...)
  95809. +#endif
  95810. +
  95811. +extern bool fiq_enable, fiq_fsm_enable;
  95812. +extern ushort nak_holdoff;
  95813. +
  95814. +/**
  95815. + * enum fiq_fsm_state - The FIQ FSM states.
  95816. + *
  95817. + * This is the "core" of the FIQ FSM. Broadly, the FSM states follow the
  95818. + * USB2.0 specification for host responses to various transaction states.
  95819. + * There are modifications to this host state machine because of a variety of
  95820. + * quirks and limitations in the dwc_otg hardware.
  95821. + *
  95822. + * The fsm state is also used to communicate back to the driver on completion of
  95823. + * a split transaction. The end states are used in conjunction with the interrupts
  95824. + * raised by the final transaction.
  95825. + */
  95826. +enum fiq_fsm_state {
  95827. + /* FIQ isn't enabled for this host channel */
  95828. + FIQ_PASSTHROUGH = 0,
  95829. + /* For the first interrupt received for this channel,
  95830. + * the FIQ has to ack any interrupts indicating success. */
  95831. + FIQ_PASSTHROUGH_ERRORSTATE = 31,
  95832. + /* Nonperiodic state groups */
  95833. + FIQ_NP_SSPLIT_STARTED = 1,
  95834. + FIQ_NP_SSPLIT_RETRY = 2,
  95835. + FIQ_NP_OUT_CSPLIT_RETRY = 3,
  95836. + FIQ_NP_IN_CSPLIT_RETRY = 4,
  95837. + FIQ_NP_SPLIT_DONE = 5,
  95838. + FIQ_NP_SPLIT_LS_ABORTED = 6,
  95839. + /* This differentiates a HS transaction error from a LS one
  95840. + * (handling the hub state is different) */
  95841. + FIQ_NP_SPLIT_HS_ABORTED = 7,
  95842. +
  95843. + /* Periodic state groups */
  95844. + /* Periodic transactions are either started directly by the IRQ handler
  95845. + * or deferred if the TT is already in use.
  95846. + */
  95847. + FIQ_PER_SSPLIT_QUEUED = 8,
  95848. + FIQ_PER_SSPLIT_STARTED = 9,
  95849. + FIQ_PER_SSPLIT_LAST = 10,
  95850. +
  95851. +
  95852. + FIQ_PER_ISO_OUT_PENDING = 11,
  95853. + FIQ_PER_ISO_OUT_ACTIVE = 12,
  95854. + FIQ_PER_ISO_OUT_LAST = 13,
  95855. + FIQ_PER_ISO_OUT_DONE = 27,
  95856. +
  95857. + FIQ_PER_CSPLIT_WAIT = 14,
  95858. + FIQ_PER_CSPLIT_NYET1 = 15,
  95859. + FIQ_PER_CSPLIT_BROKEN_NYET1 = 28,
  95860. + FIQ_PER_CSPLIT_NYET_FAFF = 29,
  95861. + /* For multiple CSPLITs (large isoc IN, or delayed interrupt) */
  95862. + FIQ_PER_CSPLIT_POLL = 16,
  95863. + /* The last CSPLIT for a transaction has been issued, differentiates
  95864. + * for the state machine to queue the next packet.
  95865. + */
  95866. + FIQ_PER_CSPLIT_LAST = 17,
  95867. +
  95868. + FIQ_PER_SPLIT_DONE = 18,
  95869. + FIQ_PER_SPLIT_LS_ABORTED = 19,
  95870. + FIQ_PER_SPLIT_HS_ABORTED = 20,
  95871. + FIQ_PER_SPLIT_NYET_ABORTED = 21,
  95872. + /* Frame rollover has occurred without the transaction finishing. */
  95873. + FIQ_PER_SPLIT_TIMEOUT = 22,
  95874. +
  95875. + /* FIQ-accelerated HS Isochronous state groups */
  95876. + FIQ_HS_ISOC_TURBO = 23,
  95877. + /* For interval > 1, SOF wakes up the isochronous FSM */
  95878. + FIQ_HS_ISOC_SLEEPING = 24,
  95879. + FIQ_HS_ISOC_DONE = 25,
  95880. + FIQ_HS_ISOC_ABORTED = 26,
  95881. + FIQ_DEQUEUE_ISSUED = 30,
  95882. + FIQ_TEST = 32,
  95883. +};
  95884. +
  95885. +struct fiq_stack {
  95886. + int magic1;
  95887. + uint8_t stack[2048];
  95888. + int magic2;
  95889. +};
  95890. +
  95891. +
  95892. +/**
  95893. + * struct fiq_dma_info - DMA bounce buffer utilisation information (per-channel)
  95894. + * @index: Number of slots reported used for IN transactions / number of slots
  95895. + * transmitted for an OUT transaction
  95896. + * @slot_len[6]: Number of actual transfer bytes in each slot (255 if unused)
  95897. + *
  95898. + * Split transaction transfers can have variable length depending on other bus
  95899. + * traffic. The OTG core DMA engine requires 4-byte aligned addresses therefore
  95900. + * each transaction needs a guaranteed aligned address. A maximum of 6 split transfers
  95901. + * can happen per-frame.
  95902. + */
  95903. +struct fiq_dma_info {
  95904. + u8 index;
  95905. + u8 slot_len[6];
  95906. +};
  95907. +
  95908. +struct __attribute__((packed)) fiq_split_dma_slot {
  95909. + u8 buf[188];
  95910. +};
  95911. +
  95912. +struct fiq_dma_channel {
  95913. + struct __attribute__((packed)) fiq_split_dma_slot index[6];
  95914. +};
  95915. +
  95916. +struct fiq_dma_blob {
  95917. + struct __attribute__((packed)) fiq_dma_channel channel[0];
  95918. +};
  95919. +
  95920. +/**
  95921. + * struct fiq_hs_isoc_info - USB2.0 isochronous data
  95922. + * @iso_frame: Pointer to the array of OTG URB iso_frame_descs.
  95923. + * @nrframes: Total length of iso_frame_desc array
  95924. + * @index: Current index (FIQ-maintained)
  95925. + *
  95926. + */
  95927. +struct fiq_hs_isoc_info {
  95928. + struct dwc_otg_hcd_iso_packet_desc *iso_desc;
  95929. + unsigned int nrframes;
  95930. + unsigned int index;
  95931. +};
  95932. +
  95933. +/**
  95934. + * struct fiq_channel_state - FIQ state machine storage
  95935. + * @fsm: Current state of the channel as understood by the FIQ
  95936. + * @nr_errors: Number of transaction errors on this split-transaction
  95937. + * @hub_addr: SSPLIT/CSPLIT destination hub
  95938. + * @port_addr: SSPLIT/CSPLIT destination port - always 1 if single TT hub
  95939. + * @nrpackets: For isoc OUT, the number of split-OUT packets to transmit. For
  95940. + * split-IN, number of CSPLIT data packets that were received.
  95941. + * @hcchar_copy:
  95942. + * @hcsplt_copy:
  95943. + * @hcintmsk_copy:
  95944. + * @hctsiz_copy: Copies of the host channel registers.
  95945. + * For use as scratch, or for returning state.
  95946. + *
  95947. + * The fiq_channel_state is state storage between interrupts for a host channel. The
  95948. + * FSM state is stored here. Members of this structure must only be set up by the
  95949. + * driver prior to enabling the FIQ for this host channel, and not touched until the FIQ
  95950. + * has updated the state to either a COMPLETE state group or ABORT state group.
  95951. + */
  95952. +
  95953. +struct fiq_channel_state {
  95954. + enum fiq_fsm_state fsm;
  95955. + unsigned int nr_errors;
  95956. + unsigned int hub_addr;
  95957. + unsigned int port_addr;
  95958. + /* Hardware bug workaround: sometimes channel halt interrupts are
  95959. + * delayed until the next SOF. Keep track of when we expected to get interrupted. */
  95960. + unsigned int expected_uframe;
  95961. + /* in/out for communicating number of dma buffers used, or number of ISOC to do */
  95962. + unsigned int nrpackets;
  95963. + struct fiq_dma_info dma_info;
  95964. + struct fiq_hs_isoc_info hs_isoc_info;
  95965. + /* Copies of HC registers - in/out communication from/to IRQ handler
  95966. + * and for ease of channel setup. A bit of mungeing is performed - for
  95967. + * example the hctsiz.b.maxp is _always_ the max packet size of the endpoint.
  95968. + */
  95969. + hcchar_data_t hcchar_copy;
  95970. + hcsplt_data_t hcsplt_copy;
  95971. + hcint_data_t hcint_copy;
  95972. + hcintmsk_data_t hcintmsk_copy;
  95973. + hctsiz_data_t hctsiz_copy;
  95974. + hcdma_data_t hcdma_copy;
  95975. +};
  95976. +
  95977. +/**
  95978. + * struct fiq_state - top-level FIQ state machine storage
  95979. + * @mphi_regs: virtual address of the MPHI peripheral register file
  95980. + * @dwc_regs_base: virtual address of the base of the DWC core register file
  95981. + * @dma_base: physical address for the base of the DMA bounce buffers
  95982. + * @dummy_send: Scratch area for sending a fake message to the MPHI peripheral
  95983. + * @gintmsk_saved: Top-level mask of interrupts that the FIQ has not handled.
  95984. + * Used for determining which interrupts fired to set off the IRQ handler.
  95985. + * @haintmsk_saved: Mask of interrupts from host channels that the FIQ did not handle internally.
  95986. + * @np_count: Non-periodic transactions in the active queue
  95987. + * @np_sent: Count of non-periodic transactions that have completed
  95988. + * @next_sched_frame: For periodic transactions handled by the driver's SOF-driven queuing mechanism,
  95989. + * this is the next frame on which a SOF interrupt is required. Used to hold off
  95990. + * passing SOF through to the driver until necessary.
  95991. + * @channel[n]: Per-channel FIQ state. Allocated during init depending on the number of host
  95992. + * channels configured into the core logic.
  95993. + *
  95994. + * This is passed as the first argument to the dwc_otg_fiq_fsm top-level FIQ handler from the asm stub.
  95995. + * It contains top-level state information.
  95996. + */
  95997. +struct fiq_state {
  95998. + fiq_lock_t lock;
  95999. + mphi_regs_t mphi_regs;
  96000. + void *dwc_regs_base;
  96001. + dma_addr_t dma_base;
  96002. + struct fiq_dma_blob *fiq_dmab;
  96003. + void *dummy_send;
  96004. + gintmsk_data_t gintmsk_saved;
  96005. + haintmsk_data_t haintmsk_saved;
  96006. + int mphi_int_count;
  96007. + unsigned int fiq_done;
  96008. + unsigned int kick_np_queues;
  96009. + unsigned int next_sched_frame;
  96010. +#ifdef FIQ_DEBUG
  96011. + char * buffer;
  96012. + unsigned int bufsiz;
  96013. +#endif
  96014. + struct fiq_channel_state channel[0];
  96015. +};
  96016. +
  96017. +extern void fiq_fsm_spin_lock(fiq_lock_t *lock);
  96018. +
  96019. +extern void fiq_fsm_spin_unlock(fiq_lock_t *lock);
  96020. +
  96021. +extern int fiq_fsm_too_late(struct fiq_state *st, int n);
  96022. +
  96023. +extern int fiq_fsm_tt_in_use(struct fiq_state *st, int num_channels, int n);
  96024. +
  96025. +extern void dwc_otg_fiq_fsm(struct fiq_state *state, int num_channels);
  96026. +
  96027. +extern void dwc_otg_fiq_nop(struct fiq_state *state);
  96028. +
  96029. +#endif /* DWC_OTG_FIQ_FSM_H_ */
  96030. diff -Nur linux-3.18.8/drivers/usb/host/dwc_otg/dwc_otg_fiq_stub.S linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_fiq_stub.S
  96031. --- linux-3.18.8/drivers/usb/host/dwc_otg/dwc_otg_fiq_stub.S 1970-01-01 01:00:00.000000000 +0100
  96032. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_fiq_stub.S 2015-03-05 14:40:16.557715806 +0100
  96033. @@ -0,0 +1,81 @@
  96034. +/*
  96035. + * dwc_otg_fiq_fsm.S - assembly stub for the FSM FIQ
  96036. + *
  96037. + * Copyright (c) 2013 Raspberry Pi Foundation
  96038. + *
  96039. + * Author: Jonathan Bell <jonathan@raspberrypi.org>
  96040. + * All rights reserved.
  96041. + *
  96042. + * Redistribution and use in source and binary forms, with or without
  96043. + * modification, are permitted provided that the following conditions are met:
  96044. + * * Redistributions of source code must retain the above copyright
  96045. + * notice, this list of conditions and the following disclaimer.
  96046. + * * Redistributions in binary form must reproduce the above copyright
  96047. + * notice, this list of conditions and the following disclaimer in the
  96048. + * documentation and/or other materials provided with the distribution.
  96049. + * * Neither the name of Raspberry Pi nor the
  96050. + * names of its contributors may be used to endorse or promote products
  96051. + * derived from this software without specific prior written permission.
  96052. + *
  96053. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  96054. + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  96055. + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  96056. + * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  96057. + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  96058. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  96059. + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  96060. + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  96061. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  96062. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  96063. + */
  96064. +
  96065. +
  96066. +#include <asm/assembler.h>
  96067. +#include <linux/linkage.h>
  96068. +
  96069. +
  96070. +.text
  96071. +
  96072. +.global _dwc_otg_fiq_stub_end;
  96073. +
  96074. +/**
  96075. + * _dwc_otg_fiq_stub() - entry copied to the FIQ vector page to allow
  96076. + * a C-style function call with arguments from the FIQ banked registers.
  96077. + * r0 = &hcd->fiq_state
  96078. + * r1 = &hcd->num_channels
  96079. + * r2 = &hcd->dma_buffers
  96080. + * Tramples: r0, r1, r2, r4, fp, ip
  96081. + */
  96082. +
  96083. +ENTRY(_dwc_otg_fiq_stub)
  96084. + /* Stash unbanked regs - SP will have been set up for us */
  96085. + mov ip, sp;
  96086. + stmdb sp!, {r0-r12, lr};
  96087. +#ifdef FIQ_DEBUG
  96088. + // Cycle profiling - read cycle counter at start
  96089. + mrc p15, 0, r5, c15, c12, 1;
  96090. +#endif
  96091. + /* r11 = fp, don't trample it */
  96092. + mov r4, fp;
  96093. + /* set EABI frame size */
  96094. + sub fp, ip, #512;
  96095. +
  96096. + /* for fiq NOP mode - just need state */
  96097. + mov r0, r8;
  96098. + /* r9 = num_channels */
  96099. + mov r1, r9;
  96100. + /* r10 = struct *dma_bufs */
  96101. +// mov r2, r10;
  96102. +
  96103. + /* r4 = &fiq_c_function */
  96104. + blx r4;
  96105. +#ifdef FIQ_DEBUG
  96106. + mrc p15, 0, r4, c15, c12, 1;
  96107. + subs r5, r5, r4;
  96108. + // r5 is now the cycle count time for executing the FIQ. Store it somewhere?
  96109. +#endif
  96110. + ldmia sp!, {r0-r12, lr};
  96111. + subs pc, lr, #4;
  96112. +_dwc_otg_fiq_stub_end:
  96113. +END(_dwc_otg_fiq_stub)
  96114. +
  96115. diff -Nur linux-3.18.8/drivers/usb/host/dwc_otg/dwc_otg_hcd.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd.c
  96116. --- linux-3.18.8/drivers/usb/host/dwc_otg/dwc_otg_hcd.c 1970-01-01 01:00:00.000000000 +0100
  96117. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd.c 2015-03-05 14:40:16.557715806 +0100
  96118. @@ -0,0 +1,4244 @@
  96119. +
  96120. +/* ==========================================================================
  96121. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd.c $
  96122. + * $Revision: #104 $
  96123. + * $Date: 2011/10/24 $
  96124. + * $Change: 1871159 $
  96125. + *
  96126. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  96127. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  96128. + * otherwise expressly agreed to in writing between Synopsys and you.
  96129. + *
  96130. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  96131. + * any End User Software License Agreement or Agreement for Licensed Product
  96132. + * with Synopsys or any supplement thereto. You are permitted to use and
  96133. + * redistribute this Software in source and binary forms, with or without
  96134. + * modification, provided that redistributions of source code must retain this
  96135. + * notice. You may not view, use, disclose, copy or distribute this file or
  96136. + * any information contained herein except pursuant to this license grant from
  96137. + * Synopsys. If you do not agree with this notice, including the disclaimer
  96138. + * below, then you are not authorized to use the Software.
  96139. + *
  96140. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  96141. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  96142. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  96143. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  96144. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  96145. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  96146. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  96147. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  96148. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  96149. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  96150. + * DAMAGE.
  96151. + * ========================================================================== */
  96152. +#ifndef DWC_DEVICE_ONLY
  96153. +
  96154. +/** @file
  96155. + * This file implements HCD Core. All code in this file is portable and doesn't
  96156. + * use any OS specific functions.
  96157. + * Interface provided by HCD Core is defined in <code><hcd_if.h></code>
  96158. + * header file.
  96159. + */
  96160. +
  96161. +#include <linux/usb.h>
  96162. +#include <linux/usb/hcd.h>
  96163. +
  96164. +#include "dwc_otg_hcd.h"
  96165. +#include "dwc_otg_regs.h"
  96166. +#include "dwc_otg_fiq_fsm.h"
  96167. +
  96168. +extern bool microframe_schedule;
  96169. +extern uint16_t fiq_fsm_mask, nak_holdoff;
  96170. +
  96171. +//#define DEBUG_HOST_CHANNELS
  96172. +#ifdef DEBUG_HOST_CHANNELS
  96173. +static int last_sel_trans_num_per_scheduled = 0;
  96174. +static int last_sel_trans_num_nonper_scheduled = 0;
  96175. +static int last_sel_trans_num_avail_hc_at_start = 0;
  96176. +static int last_sel_trans_num_avail_hc_at_end = 0;
  96177. +#endif /* DEBUG_HOST_CHANNELS */
  96178. +
  96179. +
  96180. +dwc_otg_hcd_t *dwc_otg_hcd_alloc_hcd(void)
  96181. +{
  96182. + return DWC_ALLOC(sizeof(dwc_otg_hcd_t));
  96183. +}
  96184. +
  96185. +/**
  96186. + * Connection timeout function. An OTG host is required to display a
  96187. + * message if the device does not connect within 10 seconds.
  96188. + */
  96189. +void dwc_otg_hcd_connect_timeout(void *ptr)
  96190. +{
  96191. + DWC_DEBUGPL(DBG_HCDV, "%s(%p)\n", __func__, ptr);
  96192. + DWC_PRINTF("Connect Timeout\n");
  96193. + __DWC_ERROR("Device Not Connected/Responding\n");
  96194. +}
  96195. +
  96196. +#if defined(DEBUG)
  96197. +static void dump_channel_info(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  96198. +{
  96199. + if (qh->channel != NULL) {
  96200. + dwc_hc_t *hc = qh->channel;
  96201. + dwc_list_link_t *item;
  96202. + dwc_otg_qh_t *qh_item;
  96203. + int num_channels = hcd->core_if->core_params->host_channels;
  96204. + int i;
  96205. +
  96206. + dwc_otg_hc_regs_t *hc_regs;
  96207. + hcchar_data_t hcchar;
  96208. + hcsplt_data_t hcsplt;
  96209. + hctsiz_data_t hctsiz;
  96210. + uint32_t hcdma;
  96211. +
  96212. + hc_regs = hcd->core_if->host_if->hc_regs[hc->hc_num];
  96213. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  96214. + hcsplt.d32 = DWC_READ_REG32(&hc_regs->hcsplt);
  96215. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  96216. + hcdma = DWC_READ_REG32(&hc_regs->hcdma);
  96217. +
  96218. + DWC_PRINTF(" Assigned to channel %p:\n", hc);
  96219. + DWC_PRINTF(" hcchar 0x%08x, hcsplt 0x%08x\n", hcchar.d32,
  96220. + hcsplt.d32);
  96221. + DWC_PRINTF(" hctsiz 0x%08x, hcdma 0x%08x\n", hctsiz.d32,
  96222. + hcdma);
  96223. + DWC_PRINTF(" dev_addr: %d, ep_num: %d, ep_is_in: %d\n",
  96224. + hc->dev_addr, hc->ep_num, hc->ep_is_in);
  96225. + DWC_PRINTF(" ep_type: %d\n", hc->ep_type);
  96226. + DWC_PRINTF(" max_packet: %d\n", hc->max_packet);
  96227. + DWC_PRINTF(" data_pid_start: %d\n", hc->data_pid_start);
  96228. + DWC_PRINTF(" xfer_started: %d\n", hc->xfer_started);
  96229. + DWC_PRINTF(" halt_status: %d\n", hc->halt_status);
  96230. + DWC_PRINTF(" xfer_buff: %p\n", hc->xfer_buff);
  96231. + DWC_PRINTF(" xfer_len: %d\n", hc->xfer_len);
  96232. + DWC_PRINTF(" qh: %p\n", hc->qh);
  96233. + DWC_PRINTF(" NP inactive sched:\n");
  96234. + DWC_LIST_FOREACH(item, &hcd->non_periodic_sched_inactive) {
  96235. + qh_item =
  96236. + DWC_LIST_ENTRY(item, dwc_otg_qh_t, qh_list_entry);
  96237. + DWC_PRINTF(" %p\n", qh_item);
  96238. + }
  96239. + DWC_PRINTF(" NP active sched:\n");
  96240. + DWC_LIST_FOREACH(item, &hcd->non_periodic_sched_active) {
  96241. + qh_item =
  96242. + DWC_LIST_ENTRY(item, dwc_otg_qh_t, qh_list_entry);
  96243. + DWC_PRINTF(" %p\n", qh_item);
  96244. + }
  96245. + DWC_PRINTF(" Channels: \n");
  96246. + for (i = 0; i < num_channels; i++) {
  96247. + dwc_hc_t *hc = hcd->hc_ptr_array[i];
  96248. + DWC_PRINTF(" %2d: %p\n", i, hc);
  96249. + }
  96250. + }
  96251. +}
  96252. +#else
  96253. +#define dump_channel_info(hcd, qh)
  96254. +#endif /* DEBUG */
  96255. +
  96256. +/**
  96257. + * Work queue function for starting the HCD when A-Cable is connected.
  96258. + * The hcd_start() must be called in a process context.
  96259. + */
  96260. +static void hcd_start_func(void *_vp)
  96261. +{
  96262. + dwc_otg_hcd_t *hcd = (dwc_otg_hcd_t *) _vp;
  96263. +
  96264. + DWC_DEBUGPL(DBG_HCDV, "%s() %p\n", __func__, hcd);
  96265. + if (hcd) {
  96266. + hcd->fops->start(hcd);
  96267. + }
  96268. +}
  96269. +
  96270. +static void del_xfer_timers(dwc_otg_hcd_t * hcd)
  96271. +{
  96272. +#ifdef DEBUG
  96273. + int i;
  96274. + int num_channels = hcd->core_if->core_params->host_channels;
  96275. + for (i = 0; i < num_channels; i++) {
  96276. + DWC_TIMER_CANCEL(hcd->core_if->hc_xfer_timer[i]);
  96277. + }
  96278. +#endif
  96279. +}
  96280. +
  96281. +static void del_timers(dwc_otg_hcd_t * hcd)
  96282. +{
  96283. + del_xfer_timers(hcd);
  96284. + DWC_TIMER_CANCEL(hcd->conn_timer);
  96285. +}
  96286. +
  96287. +/**
  96288. + * Processes all the URBs in a single list of QHs. Completes them with
  96289. + * -ESHUTDOWN and frees the QTD.
  96290. + */
  96291. +static void kill_urbs_in_qh_list(dwc_otg_hcd_t * hcd, dwc_list_link_t * qh_list)
  96292. +{
  96293. + dwc_list_link_t *qh_item, *qh_tmp;
  96294. + dwc_otg_qh_t *qh;
  96295. + dwc_otg_qtd_t *qtd, *qtd_tmp;
  96296. +
  96297. + DWC_LIST_FOREACH_SAFE(qh_item, qh_tmp, qh_list) {
  96298. + qh = DWC_LIST_ENTRY(qh_item, dwc_otg_qh_t, qh_list_entry);
  96299. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp,
  96300. + &qh->qtd_list, qtd_list_entry) {
  96301. + qtd = DWC_CIRCLEQ_FIRST(&qh->qtd_list);
  96302. + if (qtd->urb != NULL) {
  96303. + hcd->fops->complete(hcd, qtd->urb->priv,
  96304. + qtd->urb, -DWC_E_SHUTDOWN);
  96305. + dwc_otg_hcd_qtd_remove_and_free(hcd, qtd, qh);
  96306. + }
  96307. +
  96308. + }
  96309. + if(qh->channel) {
  96310. + /* Using hcchar.chen == 1 is not a reliable test.
  96311. + * It is possible that the channel has already halted
  96312. + * but not yet been through the IRQ handler.
  96313. + */
  96314. + dwc_otg_hc_halt(hcd->core_if, qh->channel,
  96315. + DWC_OTG_HC_XFER_URB_DEQUEUE);
  96316. + if(microframe_schedule)
  96317. + hcd->available_host_channels++;
  96318. + qh->channel = NULL;
  96319. + }
  96320. + dwc_otg_hcd_qh_remove(hcd, qh);
  96321. + }
  96322. +}
  96323. +
  96324. +/**
  96325. + * Responds with an error status of ESHUTDOWN to all URBs in the non-periodic
  96326. + * and periodic schedules. The QTD associated with each URB is removed from
  96327. + * the schedule and freed. This function may be called when a disconnect is
  96328. + * detected or when the HCD is being stopped.
  96329. + */
  96330. +static void kill_all_urbs(dwc_otg_hcd_t * hcd)
  96331. +{
  96332. + kill_urbs_in_qh_list(hcd, &hcd->non_periodic_sched_inactive);
  96333. + kill_urbs_in_qh_list(hcd, &hcd->non_periodic_sched_active);
  96334. + kill_urbs_in_qh_list(hcd, &hcd->periodic_sched_inactive);
  96335. + kill_urbs_in_qh_list(hcd, &hcd->periodic_sched_ready);
  96336. + kill_urbs_in_qh_list(hcd, &hcd->periodic_sched_assigned);
  96337. + kill_urbs_in_qh_list(hcd, &hcd->periodic_sched_queued);
  96338. +}
  96339. +
  96340. +/**
  96341. + * Start the connection timer. An OTG host is required to display a
  96342. + * message if the device does not connect within 10 seconds. The
  96343. + * timer is deleted if a port connect interrupt occurs before the
  96344. + * timer expires.
  96345. + */
  96346. +static void dwc_otg_hcd_start_connect_timer(dwc_otg_hcd_t * hcd)
  96347. +{
  96348. + DWC_TIMER_SCHEDULE(hcd->conn_timer, 10000 /* 10 secs */ );
  96349. +}
  96350. +
  96351. +/**
  96352. + * HCD Callback function for disconnect of the HCD.
  96353. + *
  96354. + * @param p void pointer to the <code>struct usb_hcd</code>
  96355. + */
  96356. +static int32_t dwc_otg_hcd_session_start_cb(void *p)
  96357. +{
  96358. + dwc_otg_hcd_t *dwc_otg_hcd;
  96359. + DWC_DEBUGPL(DBG_HCDV, "%s(%p)\n", __func__, p);
  96360. + dwc_otg_hcd = p;
  96361. + dwc_otg_hcd_start_connect_timer(dwc_otg_hcd);
  96362. + return 1;
  96363. +}
  96364. +
  96365. +/**
  96366. + * HCD Callback function for starting the HCD when A-Cable is
  96367. + * connected.
  96368. + *
  96369. + * @param p void pointer to the <code>struct usb_hcd</code>
  96370. + */
  96371. +static int32_t dwc_otg_hcd_start_cb(void *p)
  96372. +{
  96373. + dwc_otg_hcd_t *dwc_otg_hcd = p;
  96374. + dwc_otg_core_if_t *core_if;
  96375. + hprt0_data_t hprt0;
  96376. +
  96377. + core_if = dwc_otg_hcd->core_if;
  96378. +
  96379. + if (core_if->op_state == B_HOST) {
  96380. + /*
  96381. + * Reset the port. During a HNP mode switch the reset
  96382. + * needs to occur within 1ms and have a duration of at
  96383. + * least 50ms.
  96384. + */
  96385. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  96386. + hprt0.b.prtrst = 1;
  96387. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  96388. + }
  96389. + DWC_WORKQ_SCHEDULE_DELAYED(core_if->wq_otg,
  96390. + hcd_start_func, dwc_otg_hcd, 50,
  96391. + "start hcd");
  96392. +
  96393. + return 1;
  96394. +}
  96395. +
  96396. +/**
  96397. + * HCD Callback function for disconnect of the HCD.
  96398. + *
  96399. + * @param p void pointer to the <code>struct usb_hcd</code>
  96400. + */
  96401. +static int32_t dwc_otg_hcd_disconnect_cb(void *p)
  96402. +{
  96403. + gintsts_data_t intr;
  96404. + dwc_otg_hcd_t *dwc_otg_hcd = p;
  96405. +
  96406. + /*
  96407. + * Set status flags for the hub driver.
  96408. + */
  96409. + dwc_otg_hcd->flags.b.port_connect_status_change = 1;
  96410. + dwc_otg_hcd->flags.b.port_connect_status = 0;
  96411. + if(fiq_enable)
  96412. + local_fiq_disable();
  96413. + /*
  96414. + * Shutdown any transfers in process by clearing the Tx FIFO Empty
  96415. + * interrupt mask and status bits and disabling subsequent host
  96416. + * channel interrupts.
  96417. + */
  96418. + intr.d32 = 0;
  96419. + intr.b.nptxfempty = 1;
  96420. + intr.b.ptxfempty = 1;
  96421. + intr.b.hcintr = 1;
  96422. + DWC_MODIFY_REG32(&dwc_otg_hcd->core_if->core_global_regs->gintmsk,
  96423. + intr.d32, 0);
  96424. + DWC_MODIFY_REG32(&dwc_otg_hcd->core_if->core_global_regs->gintsts,
  96425. + intr.d32, 0);
  96426. +
  96427. + del_timers(dwc_otg_hcd);
  96428. +
  96429. + /*
  96430. + * Turn off the vbus power only if the core has transitioned to device
  96431. + * mode. If still in host mode, need to keep power on to detect a
  96432. + * reconnection.
  96433. + */
  96434. + if (dwc_otg_is_device_mode(dwc_otg_hcd->core_if)) {
  96435. + if (dwc_otg_hcd->core_if->op_state != A_SUSPEND) {
  96436. + hprt0_data_t hprt0 = {.d32 = 0 };
  96437. + DWC_PRINTF("Disconnect: PortPower off\n");
  96438. + hprt0.b.prtpwr = 0;
  96439. + DWC_WRITE_REG32(dwc_otg_hcd->core_if->host_if->hprt0,
  96440. + hprt0.d32);
  96441. + }
  96442. +
  96443. + dwc_otg_disable_host_interrupts(dwc_otg_hcd->core_if);
  96444. + }
  96445. +
  96446. + /* Respond with an error status to all URBs in the schedule. */
  96447. + kill_all_urbs(dwc_otg_hcd);
  96448. +
  96449. + if (dwc_otg_is_host_mode(dwc_otg_hcd->core_if)) {
  96450. + /* Clean up any host channels that were in use. */
  96451. + int num_channels;
  96452. + int i;
  96453. + dwc_hc_t *channel;
  96454. + dwc_otg_hc_regs_t *hc_regs;
  96455. + hcchar_data_t hcchar;
  96456. +
  96457. + num_channels = dwc_otg_hcd->core_if->core_params->host_channels;
  96458. +
  96459. + if (!dwc_otg_hcd->core_if->dma_enable) {
  96460. + /* Flush out any channel requests in slave mode. */
  96461. + for (i = 0; i < num_channels; i++) {
  96462. + channel = dwc_otg_hcd->hc_ptr_array[i];
  96463. + if (DWC_CIRCLEQ_EMPTY_ENTRY
  96464. + (channel, hc_list_entry)) {
  96465. + hc_regs =
  96466. + dwc_otg_hcd->core_if->
  96467. + host_if->hc_regs[i];
  96468. + hcchar.d32 =
  96469. + DWC_READ_REG32(&hc_regs->hcchar);
  96470. + if (hcchar.b.chen) {
  96471. + hcchar.b.chen = 0;
  96472. + hcchar.b.chdis = 1;
  96473. + hcchar.b.epdir = 0;
  96474. + DWC_WRITE_REG32
  96475. + (&hc_regs->hcchar,
  96476. + hcchar.d32);
  96477. + }
  96478. + }
  96479. + }
  96480. + }
  96481. +
  96482. + for (i = 0; i < num_channels; i++) {
  96483. + channel = dwc_otg_hcd->hc_ptr_array[i];
  96484. + if (DWC_CIRCLEQ_EMPTY_ENTRY(channel, hc_list_entry)) {
  96485. + hc_regs =
  96486. + dwc_otg_hcd->core_if->host_if->hc_regs[i];
  96487. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  96488. + if (hcchar.b.chen) {
  96489. + /* Halt the channel. */
  96490. + hcchar.b.chdis = 1;
  96491. + DWC_WRITE_REG32(&hc_regs->hcchar,
  96492. + hcchar.d32);
  96493. + }
  96494. +
  96495. + dwc_otg_hc_cleanup(dwc_otg_hcd->core_if,
  96496. + channel);
  96497. + DWC_CIRCLEQ_INSERT_TAIL
  96498. + (&dwc_otg_hcd->free_hc_list, channel,
  96499. + hc_list_entry);
  96500. + /*
  96501. + * Added for Descriptor DMA to prevent channel double cleanup
  96502. + * in release_channel_ddma(). Which called from ep_disable
  96503. + * when device disconnect.
  96504. + */
  96505. + channel->qh = NULL;
  96506. + }
  96507. + }
  96508. + if(fiq_fsm_enable) {
  96509. + for(i=0; i < 128; i++) {
  96510. + dwc_otg_hcd->hub_port[i] = 0;
  96511. + }
  96512. + }
  96513. +
  96514. + }
  96515. +
  96516. + if(fiq_enable)
  96517. + local_fiq_enable();
  96518. +
  96519. + if (dwc_otg_hcd->fops->disconnect) {
  96520. + dwc_otg_hcd->fops->disconnect(dwc_otg_hcd);
  96521. + }
  96522. +
  96523. + return 1;
  96524. +}
  96525. +
  96526. +/**
  96527. + * HCD Callback function for stopping the HCD.
  96528. + *
  96529. + * @param p void pointer to the <code>struct usb_hcd</code>
  96530. + */
  96531. +static int32_t dwc_otg_hcd_stop_cb(void *p)
  96532. +{
  96533. + dwc_otg_hcd_t *dwc_otg_hcd = p;
  96534. +
  96535. + DWC_DEBUGPL(DBG_HCDV, "%s(%p)\n", __func__, p);
  96536. + dwc_otg_hcd_stop(dwc_otg_hcd);
  96537. + return 1;
  96538. +}
  96539. +
  96540. +#ifdef CONFIG_USB_DWC_OTG_LPM
  96541. +/**
  96542. + * HCD Callback function for sleep of HCD.
  96543. + *
  96544. + * @param p void pointer to the <code>struct usb_hcd</code>
  96545. + */
  96546. +static int dwc_otg_hcd_sleep_cb(void *p)
  96547. +{
  96548. + dwc_otg_hcd_t *hcd = p;
  96549. +
  96550. + dwc_otg_hcd_free_hc_from_lpm(hcd);
  96551. +
  96552. + return 0;
  96553. +}
  96554. +#endif
  96555. +
  96556. +
  96557. +/**
  96558. + * HCD Callback function for Remote Wakeup.
  96559. + *
  96560. + * @param p void pointer to the <code>struct usb_hcd</code>
  96561. + */
  96562. +static int dwc_otg_hcd_rem_wakeup_cb(void *p)
  96563. +{
  96564. + dwc_otg_hcd_t *hcd = p;
  96565. +
  96566. + if (hcd->core_if->lx_state == DWC_OTG_L2) {
  96567. + hcd->flags.b.port_suspend_change = 1;
  96568. + }
  96569. +#ifdef CONFIG_USB_DWC_OTG_LPM
  96570. + else {
  96571. + hcd->flags.b.port_l1_change = 1;
  96572. + }
  96573. +#endif
  96574. + return 0;
  96575. +}
  96576. +
  96577. +/**
  96578. + * Halts the DWC_otg host mode operations in a clean manner. USB transfers are
  96579. + * stopped.
  96580. + */
  96581. +void dwc_otg_hcd_stop(dwc_otg_hcd_t * hcd)
  96582. +{
  96583. + hprt0_data_t hprt0 = {.d32 = 0 };
  96584. +
  96585. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD STOP\n");
  96586. +
  96587. + /*
  96588. + * The root hub should be disconnected before this function is called.
  96589. + * The disconnect will clear the QTD lists (via ..._hcd_urb_dequeue)
  96590. + * and the QH lists (via ..._hcd_endpoint_disable).
  96591. + */
  96592. +
  96593. + /* Turn off all host-specific interrupts. */
  96594. + dwc_otg_disable_host_interrupts(hcd->core_if);
  96595. +
  96596. + /* Turn off the vbus power */
  96597. + DWC_PRINTF("PortPower off\n");
  96598. + hprt0.b.prtpwr = 0;
  96599. + DWC_WRITE_REG32(hcd->core_if->host_if->hprt0, hprt0.d32);
  96600. + dwc_mdelay(1);
  96601. +}
  96602. +
  96603. +int dwc_otg_hcd_urb_enqueue(dwc_otg_hcd_t * hcd,
  96604. + dwc_otg_hcd_urb_t * dwc_otg_urb, void **ep_handle,
  96605. + int atomic_alloc)
  96606. +{
  96607. + int retval = 0;
  96608. + uint8_t needs_scheduling = 0;
  96609. + dwc_otg_transaction_type_e tr_type;
  96610. + dwc_otg_qtd_t *qtd;
  96611. + gintmsk_data_t intr_mask = {.d32 = 0 };
  96612. + hprt0_data_t hprt0 = { .d32 = 0 };
  96613. +
  96614. +#ifdef DEBUG /* integrity checks (Broadcom) */
  96615. + if (NULL == hcd->core_if) {
  96616. + DWC_ERROR("**** DWC OTG HCD URB Enqueue - HCD has NULL core_if\n");
  96617. + /* No longer connected. */
  96618. + return -DWC_E_INVALID;
  96619. + }
  96620. +#endif
  96621. + if (!hcd->flags.b.port_connect_status) {
  96622. + /* No longer connected. */
  96623. + DWC_ERROR("Not connected\n");
  96624. + return -DWC_E_NO_DEVICE;
  96625. + }
  96626. +
  96627. + /* Some core configurations cannot support LS traffic on a FS root port */
  96628. + if ((hcd->fops->speed(hcd, dwc_otg_urb->priv) == USB_SPEED_LOW) &&
  96629. + (hcd->core_if->hwcfg2.b.fs_phy_type == 1) &&
  96630. + (hcd->core_if->hwcfg2.b.hs_phy_type == 1)) {
  96631. + hprt0.d32 = DWC_READ_REG32(hcd->core_if->host_if->hprt0);
  96632. + if (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_FULL_SPEED) {
  96633. + return -DWC_E_NO_DEVICE;
  96634. + }
  96635. + }
  96636. +
  96637. + qtd = dwc_otg_hcd_qtd_create(dwc_otg_urb, atomic_alloc);
  96638. + if (qtd == NULL) {
  96639. + DWC_ERROR("DWC OTG HCD URB Enqueue failed creating QTD\n");
  96640. + return -DWC_E_NO_MEMORY;
  96641. + }
  96642. +#ifdef DEBUG /* integrity checks (Broadcom) */
  96643. + if (qtd->urb == NULL) {
  96644. + DWC_ERROR("**** DWC OTG HCD URB Enqueue created QTD with no URBs\n");
  96645. + return -DWC_E_NO_MEMORY;
  96646. + }
  96647. + if (qtd->urb->priv == NULL) {
  96648. + DWC_ERROR("**** DWC OTG HCD URB Enqueue created QTD URB with no URB handle\n");
  96649. + return -DWC_E_NO_MEMORY;
  96650. + }
  96651. +#endif
  96652. + intr_mask.d32 = DWC_READ_REG32(&hcd->core_if->core_global_regs->gintmsk);
  96653. + if(!intr_mask.b.sofintr || fiq_enable) needs_scheduling = 1;
  96654. + if((((dwc_otg_qh_t *)ep_handle)->ep_type == UE_BULK) && !(qtd->urb->flags & URB_GIVEBACK_ASAP))
  96655. + /* Do not schedule SG transactions until qtd has URB_GIVEBACK_ASAP set */
  96656. + needs_scheduling = 0;
  96657. +
  96658. + retval = dwc_otg_hcd_qtd_add(qtd, hcd, (dwc_otg_qh_t **) ep_handle, atomic_alloc);
  96659. + // creates a new queue in ep_handle if it doesn't exist already
  96660. + if (retval < 0) {
  96661. + DWC_ERROR("DWC OTG HCD URB Enqueue failed adding QTD. "
  96662. + "Error status %d\n", retval);
  96663. + dwc_otg_hcd_qtd_free(qtd);
  96664. + return retval;
  96665. + }
  96666. +
  96667. + if(needs_scheduling) {
  96668. + tr_type = dwc_otg_hcd_select_transactions(hcd);
  96669. + if (tr_type != DWC_OTG_TRANSACTION_NONE) {
  96670. + dwc_otg_hcd_queue_transactions(hcd, tr_type);
  96671. + }
  96672. + }
  96673. + return retval;
  96674. +}
  96675. +
  96676. +int dwc_otg_hcd_urb_dequeue(dwc_otg_hcd_t * hcd,
  96677. + dwc_otg_hcd_urb_t * dwc_otg_urb)
  96678. +{
  96679. + dwc_otg_qh_t *qh;
  96680. + dwc_otg_qtd_t *urb_qtd;
  96681. + BUG_ON(!hcd);
  96682. + BUG_ON(!dwc_otg_urb);
  96683. +
  96684. +#ifdef DEBUG /* integrity checks (Broadcom) */
  96685. +
  96686. + if (hcd == NULL) {
  96687. + DWC_ERROR("**** DWC OTG HCD URB Dequeue has NULL HCD\n");
  96688. + return -DWC_E_INVALID;
  96689. + }
  96690. + if (dwc_otg_urb == NULL) {
  96691. + DWC_ERROR("**** DWC OTG HCD URB Dequeue has NULL URB\n");
  96692. + return -DWC_E_INVALID;
  96693. + }
  96694. + if (dwc_otg_urb->qtd == NULL) {
  96695. + DWC_ERROR("**** DWC OTG HCD URB Dequeue with NULL QTD\n");
  96696. + return -DWC_E_INVALID;
  96697. + }
  96698. + urb_qtd = dwc_otg_urb->qtd;
  96699. + BUG_ON(!urb_qtd);
  96700. + if (urb_qtd->qh == NULL) {
  96701. + DWC_ERROR("**** DWC OTG HCD URB Dequeue with QTD with NULL Q handler\n");
  96702. + return -DWC_E_INVALID;
  96703. + }
  96704. +#else
  96705. + urb_qtd = dwc_otg_urb->qtd;
  96706. + BUG_ON(!urb_qtd);
  96707. +#endif
  96708. + qh = urb_qtd->qh;
  96709. + BUG_ON(!qh);
  96710. + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
  96711. + if (urb_qtd->in_process) {
  96712. + dump_channel_info(hcd, qh);
  96713. + }
  96714. + }
  96715. +#ifdef DEBUG /* integrity checks (Broadcom) */
  96716. + if (hcd->core_if == NULL) {
  96717. + DWC_ERROR("**** DWC OTG HCD URB Dequeue HCD has NULL core_if\n");
  96718. + return -DWC_E_INVALID;
  96719. + }
  96720. +#endif
  96721. + if (urb_qtd->in_process && qh->channel) {
  96722. + /* The QTD is in process (it has been assigned to a channel). */
  96723. + if (hcd->flags.b.port_connect_status) {
  96724. + int n = qh->channel->hc_num;
  96725. + /*
  96726. + * If still connected (i.e. in host mode), halt the
  96727. + * channel so it can be used for other transfers. If
  96728. + * no longer connected, the host registers can't be
  96729. + * written to halt the channel since the core is in
  96730. + * device mode.
  96731. + */
  96732. + /* In FIQ FSM mode, we need to shut down carefully.
  96733. + * The FIQ may attempt to restart a disabled channel */
  96734. + if (fiq_fsm_enable && (hcd->fiq_state->channel[n].fsm != FIQ_PASSTHROUGH)) {
  96735. + qh->channel->halt_status = DWC_OTG_HC_XFER_URB_DEQUEUE;
  96736. + qh->channel->halt_pending = 1;
  96737. + hcd->fiq_state->channel[n].fsm = FIQ_DEQUEUE_ISSUED;
  96738. + } else {
  96739. + dwc_otg_hc_halt(hcd->core_if, qh->channel,
  96740. + DWC_OTG_HC_XFER_URB_DEQUEUE);
  96741. + }
  96742. + }
  96743. + }
  96744. +
  96745. + /*
  96746. + * Free the QTD and clean up the associated QH. Leave the QH in the
  96747. + * schedule if it has any remaining QTDs.
  96748. + */
  96749. +
  96750. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD URB Dequeue - "
  96751. + "delete %sQueue handler\n",
  96752. + hcd->core_if->dma_desc_enable?"DMA ":"");
  96753. + if (!hcd->core_if->dma_desc_enable) {
  96754. + uint8_t b = urb_qtd->in_process;
  96755. + dwc_otg_hcd_qtd_remove_and_free(hcd, urb_qtd, qh);
  96756. + if (b) {
  96757. + dwc_otg_hcd_qh_deactivate(hcd, qh, 0);
  96758. + qh->channel = NULL;
  96759. + } else if (DWC_CIRCLEQ_EMPTY(&qh->qtd_list)) {
  96760. + dwc_otg_hcd_qh_remove(hcd, qh);
  96761. + }
  96762. + } else {
  96763. + dwc_otg_hcd_qtd_remove_and_free(hcd, urb_qtd, qh);
  96764. + }
  96765. + return 0;
  96766. +}
  96767. +
  96768. +int dwc_otg_hcd_endpoint_disable(dwc_otg_hcd_t * hcd, void *ep_handle,
  96769. + int retry)
  96770. +{
  96771. + dwc_otg_qh_t *qh = (dwc_otg_qh_t *) ep_handle;
  96772. + int retval = 0;
  96773. + dwc_irqflags_t flags;
  96774. +
  96775. + if (retry < 0) {
  96776. + retval = -DWC_E_INVALID;
  96777. + goto done;
  96778. + }
  96779. +
  96780. + if (!qh) {
  96781. + retval = -DWC_E_INVALID;
  96782. + goto done;
  96783. + }
  96784. +
  96785. + DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
  96786. +
  96787. + while (!DWC_CIRCLEQ_EMPTY(&qh->qtd_list) && retry) {
  96788. + DWC_SPINUNLOCK_IRQRESTORE(hcd->lock, flags);
  96789. + retry--;
  96790. + dwc_msleep(5);
  96791. + DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
  96792. + }
  96793. +
  96794. + dwc_otg_hcd_qh_remove(hcd, qh);
  96795. +
  96796. + DWC_SPINUNLOCK_IRQRESTORE(hcd->lock, flags);
  96797. + /*
  96798. + * Split dwc_otg_hcd_qh_remove_and_free() into qh_remove
  96799. + * and qh_free to prevent stack dump on DWC_DMA_FREE() with
  96800. + * irq_disabled (spinlock_irqsave) in dwc_otg_hcd_desc_list_free()
  96801. + * and dwc_otg_hcd_frame_list_alloc().
  96802. + */
  96803. + dwc_otg_hcd_qh_free(hcd, qh);
  96804. +
  96805. +done:
  96806. + return retval;
  96807. +}
  96808. +
  96809. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30)
  96810. +int dwc_otg_hcd_endpoint_reset(dwc_otg_hcd_t * hcd, void *ep_handle)
  96811. +{
  96812. + int retval = 0;
  96813. + dwc_otg_qh_t *qh = (dwc_otg_qh_t *) ep_handle;
  96814. + if (!qh)
  96815. + return -DWC_E_INVALID;
  96816. +
  96817. + qh->data_toggle = DWC_OTG_HC_PID_DATA0;
  96818. + return retval;
  96819. +}
  96820. +#endif
  96821. +
  96822. +/**
  96823. + * HCD Callback structure for handling mode switching.
  96824. + */
  96825. +static dwc_otg_cil_callbacks_t hcd_cil_callbacks = {
  96826. + .start = dwc_otg_hcd_start_cb,
  96827. + .stop = dwc_otg_hcd_stop_cb,
  96828. + .disconnect = dwc_otg_hcd_disconnect_cb,
  96829. + .session_start = dwc_otg_hcd_session_start_cb,
  96830. + .resume_wakeup = dwc_otg_hcd_rem_wakeup_cb,
  96831. +#ifdef CONFIG_USB_DWC_OTG_LPM
  96832. + .sleep = dwc_otg_hcd_sleep_cb,
  96833. +#endif
  96834. + .p = 0,
  96835. +};
  96836. +
  96837. +/**
  96838. + * Reset tasklet function
  96839. + */
  96840. +static void reset_tasklet_func(void *data)
  96841. +{
  96842. + dwc_otg_hcd_t *dwc_otg_hcd = (dwc_otg_hcd_t *) data;
  96843. + dwc_otg_core_if_t *core_if = dwc_otg_hcd->core_if;
  96844. + hprt0_data_t hprt0;
  96845. +
  96846. + DWC_DEBUGPL(DBG_HCDV, "USB RESET tasklet called\n");
  96847. +
  96848. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  96849. + hprt0.b.prtrst = 1;
  96850. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  96851. + dwc_mdelay(60);
  96852. +
  96853. + hprt0.b.prtrst = 0;
  96854. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  96855. + dwc_otg_hcd->flags.b.port_reset_change = 1;
  96856. +}
  96857. +
  96858. +static void completion_tasklet_func(void *ptr)
  96859. +{
  96860. + dwc_otg_hcd_t *hcd = (dwc_otg_hcd_t *) ptr;
  96861. + struct urb *urb;
  96862. + urb_tq_entry_t *item;
  96863. + dwc_irqflags_t flags;
  96864. +
  96865. + /* This could just be spin_lock_irq */
  96866. + DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
  96867. + while (!DWC_TAILQ_EMPTY(&hcd->completed_urb_list)) {
  96868. + item = DWC_TAILQ_FIRST(&hcd->completed_urb_list);
  96869. + urb = item->urb;
  96870. + DWC_TAILQ_REMOVE(&hcd->completed_urb_list, item,
  96871. + urb_tq_entries);
  96872. + DWC_SPINUNLOCK_IRQRESTORE(hcd->lock, flags);
  96873. + DWC_FREE(item);
  96874. +
  96875. + usb_hcd_giveback_urb(hcd->priv, urb, urb->status);
  96876. +
  96877. +
  96878. + DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
  96879. + }
  96880. + DWC_SPINUNLOCK_IRQRESTORE(hcd->lock, flags);
  96881. + return;
  96882. +}
  96883. +
  96884. +static void qh_list_free(dwc_otg_hcd_t * hcd, dwc_list_link_t * qh_list)
  96885. +{
  96886. + dwc_list_link_t *item;
  96887. + dwc_otg_qh_t *qh;
  96888. + dwc_irqflags_t flags;
  96889. +
  96890. + if (!qh_list->next) {
  96891. + /* The list hasn't been initialized yet. */
  96892. + return;
  96893. + }
  96894. + /*
  96895. + * Hold spinlock here. Not needed in that case if bellow
  96896. + * function is being called from ISR
  96897. + */
  96898. + DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
  96899. + /* Ensure there are no QTDs or URBs left. */
  96900. + kill_urbs_in_qh_list(hcd, qh_list);
  96901. + DWC_SPINUNLOCK_IRQRESTORE(hcd->lock, flags);
  96902. +
  96903. + DWC_LIST_FOREACH(item, qh_list) {
  96904. + qh = DWC_LIST_ENTRY(item, dwc_otg_qh_t, qh_list_entry);
  96905. + dwc_otg_hcd_qh_remove_and_free(hcd, qh);
  96906. + }
  96907. +}
  96908. +
  96909. +/**
  96910. + * Exit from Hibernation if Host did not detect SRP from connected SRP capable
  96911. + * Device during SRP time by host power up.
  96912. + */
  96913. +void dwc_otg_hcd_power_up(void *ptr)
  96914. +{
  96915. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  96916. + dwc_otg_core_if_t *core_if = (dwc_otg_core_if_t *) ptr;
  96917. +
  96918. + DWC_PRINTF("%s called\n", __FUNCTION__);
  96919. +
  96920. + if (!core_if->hibernation_suspend) {
  96921. + DWC_PRINTF("Already exited from Hibernation\n");
  96922. + return;
  96923. + }
  96924. +
  96925. + /* Switch on the voltage to the core */
  96926. + gpwrdn.b.pwrdnswtch = 1;
  96927. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  96928. + dwc_udelay(10);
  96929. +
  96930. + /* Reset the core */
  96931. + gpwrdn.d32 = 0;
  96932. + gpwrdn.b.pwrdnrstn = 1;
  96933. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  96934. + dwc_udelay(10);
  96935. +
  96936. + /* Disable power clamps */
  96937. + gpwrdn.d32 = 0;
  96938. + gpwrdn.b.pwrdnclmp = 1;
  96939. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  96940. +
  96941. + /* Remove reset the core signal */
  96942. + gpwrdn.d32 = 0;
  96943. + gpwrdn.b.pwrdnrstn = 1;
  96944. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  96945. + dwc_udelay(10);
  96946. +
  96947. + /* Disable PMU interrupt */
  96948. + gpwrdn.d32 = 0;
  96949. + gpwrdn.b.pmuintsel = 1;
  96950. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  96951. +
  96952. + core_if->hibernation_suspend = 0;
  96953. +
  96954. + /* Disable PMU */
  96955. + gpwrdn.d32 = 0;
  96956. + gpwrdn.b.pmuactv = 1;
  96957. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  96958. + dwc_udelay(10);
  96959. +
  96960. + /* Enable VBUS */
  96961. + gpwrdn.d32 = 0;
  96962. + gpwrdn.b.dis_vbus = 1;
  96963. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  96964. +
  96965. + core_if->op_state = A_HOST;
  96966. + dwc_otg_core_init(core_if);
  96967. + dwc_otg_enable_global_interrupts(core_if);
  96968. + cil_hcd_start(core_if);
  96969. +}
  96970. +
  96971. +void dwc_otg_cleanup_fiq_channel(dwc_otg_hcd_t *hcd, uint32_t num)
  96972. +{
  96973. + struct fiq_channel_state *st = &hcd->fiq_state->channel[num];
  96974. + struct fiq_dma_blob *blob = hcd->fiq_dmab;
  96975. + int i;
  96976. +
  96977. + st->fsm = FIQ_PASSTHROUGH;
  96978. + st->hcchar_copy.d32 = 0;
  96979. + st->hcsplt_copy.d32 = 0;
  96980. + st->hcint_copy.d32 = 0;
  96981. + st->hcintmsk_copy.d32 = 0;
  96982. + st->hctsiz_copy.d32 = 0;
  96983. + st->hcdma_copy.d32 = 0;
  96984. + st->nr_errors = 0;
  96985. + st->hub_addr = 0;
  96986. + st->port_addr = 0;
  96987. + st->expected_uframe = 0;
  96988. + st->nrpackets = 0;
  96989. + st->dma_info.index = 0;
  96990. + for (i = 0; i < 6; i++)
  96991. + st->dma_info.slot_len[i] = 255;
  96992. + st->hs_isoc_info.index = 0;
  96993. + st->hs_isoc_info.iso_desc = NULL;
  96994. + st->hs_isoc_info.nrframes = 0;
  96995. +
  96996. + DWC_MEMSET(&blob->channel[num].index[0], 0x6b, 1128);
  96997. +}
  96998. +
  96999. +/**
  97000. + * Frees secondary storage associated with the dwc_otg_hcd structure contained
  97001. + * in the struct usb_hcd field.
  97002. + */
  97003. +static void dwc_otg_hcd_free(dwc_otg_hcd_t * dwc_otg_hcd)
  97004. +{
  97005. + int i;
  97006. +
  97007. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD FREE\n");
  97008. +
  97009. + del_timers(dwc_otg_hcd);
  97010. +
  97011. + /* Free memory for QH/QTD lists */
  97012. + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->non_periodic_sched_inactive);
  97013. + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->non_periodic_sched_active);
  97014. + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->periodic_sched_inactive);
  97015. + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->periodic_sched_ready);
  97016. + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->periodic_sched_assigned);
  97017. + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->periodic_sched_queued);
  97018. +
  97019. + /* Free memory for the host channels. */
  97020. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  97021. + dwc_hc_t *hc = dwc_otg_hcd->hc_ptr_array[i];
  97022. +
  97023. +#ifdef DEBUG
  97024. + if (dwc_otg_hcd->core_if->hc_xfer_timer[i]) {
  97025. + DWC_TIMER_FREE(dwc_otg_hcd->core_if->hc_xfer_timer[i]);
  97026. + }
  97027. +#endif
  97028. + if (hc != NULL) {
  97029. + DWC_DEBUGPL(DBG_HCDV, "HCD Free channel #%i, hc=%p\n",
  97030. + i, hc);
  97031. + DWC_FREE(hc);
  97032. + }
  97033. + }
  97034. +
  97035. + if (dwc_otg_hcd->core_if->dma_enable) {
  97036. + if (dwc_otg_hcd->status_buf_dma) {
  97037. + DWC_DMA_FREE(DWC_OTG_HCD_STATUS_BUF_SIZE,
  97038. + dwc_otg_hcd->status_buf,
  97039. + dwc_otg_hcd->status_buf_dma);
  97040. + }
  97041. + } else if (dwc_otg_hcd->status_buf != NULL) {
  97042. + DWC_FREE(dwc_otg_hcd->status_buf);
  97043. + }
  97044. + DWC_SPINLOCK_FREE(dwc_otg_hcd->channel_lock);
  97045. + DWC_SPINLOCK_FREE(dwc_otg_hcd->lock);
  97046. + /* Set core_if's lock pointer to NULL */
  97047. + dwc_otg_hcd->core_if->lock = NULL;
  97048. +
  97049. + DWC_TIMER_FREE(dwc_otg_hcd->conn_timer);
  97050. + DWC_TASK_FREE(dwc_otg_hcd->reset_tasklet);
  97051. + DWC_TASK_FREE(dwc_otg_hcd->completion_tasklet);
  97052. + DWC_FREE(dwc_otg_hcd->fiq_state);
  97053. +
  97054. +#ifdef DWC_DEV_SRPCAP
  97055. + if (dwc_otg_hcd->core_if->power_down == 2 &&
  97056. + dwc_otg_hcd->core_if->pwron_timer) {
  97057. + DWC_TIMER_FREE(dwc_otg_hcd->core_if->pwron_timer);
  97058. + }
  97059. +#endif
  97060. + DWC_FREE(dwc_otg_hcd);
  97061. +}
  97062. +
  97063. +int init_hcd_usecs(dwc_otg_hcd_t *_hcd);
  97064. +
  97065. +int dwc_otg_hcd_init(dwc_otg_hcd_t * hcd, dwc_otg_core_if_t * core_if)
  97066. +{
  97067. + int retval = 0;
  97068. + int num_channels;
  97069. + int i;
  97070. + dwc_hc_t *channel;
  97071. +
  97072. +#if (defined(DWC_LINUX) && defined(CONFIG_DEBUG_SPINLOCK))
  97073. + DWC_SPINLOCK_ALLOC_LINUX_DEBUG(hcd->lock);
  97074. + DWC_SPINLOCK_ALLOC_LINUX_DEBUG(hcd->channel_lock);
  97075. +#else
  97076. + hcd->lock = DWC_SPINLOCK_ALLOC();
  97077. + hcd->channel_lock = DWC_SPINLOCK_ALLOC();
  97078. +#endif
  97079. + DWC_DEBUGPL(DBG_HCDV, "init of HCD %p given core_if %p\n",
  97080. + hcd, core_if);
  97081. + if (!hcd->lock) {
  97082. + DWC_ERROR("Could not allocate lock for pcd");
  97083. + DWC_FREE(hcd);
  97084. + retval = -DWC_E_NO_MEMORY;
  97085. + goto out;
  97086. + }
  97087. + hcd->core_if = core_if;
  97088. +
  97089. + /* Register the HCD CIL Callbacks */
  97090. + dwc_otg_cil_register_hcd_callbacks(hcd->core_if,
  97091. + &hcd_cil_callbacks, hcd);
  97092. +
  97093. + /* Initialize the non-periodic schedule. */
  97094. + DWC_LIST_INIT(&hcd->non_periodic_sched_inactive);
  97095. + DWC_LIST_INIT(&hcd->non_periodic_sched_active);
  97096. +
  97097. + /* Initialize the periodic schedule. */
  97098. + DWC_LIST_INIT(&hcd->periodic_sched_inactive);
  97099. + DWC_LIST_INIT(&hcd->periodic_sched_ready);
  97100. + DWC_LIST_INIT(&hcd->periodic_sched_assigned);
  97101. + DWC_LIST_INIT(&hcd->periodic_sched_queued);
  97102. + DWC_TAILQ_INIT(&hcd->completed_urb_list);
  97103. + /*
  97104. + * Create a host channel descriptor for each host channel implemented
  97105. + * in the controller. Initialize the channel descriptor array.
  97106. + */
  97107. + DWC_CIRCLEQ_INIT(&hcd->free_hc_list);
  97108. + num_channels = hcd->core_if->core_params->host_channels;
  97109. + DWC_MEMSET(hcd->hc_ptr_array, 0, sizeof(hcd->hc_ptr_array));
  97110. + for (i = 0; i < num_channels; i++) {
  97111. + channel = DWC_ALLOC(sizeof(dwc_hc_t));
  97112. + if (channel == NULL) {
  97113. + retval = -DWC_E_NO_MEMORY;
  97114. + DWC_ERROR("%s: host channel allocation failed\n",
  97115. + __func__);
  97116. + dwc_otg_hcd_free(hcd);
  97117. + goto out;
  97118. + }
  97119. + channel->hc_num = i;
  97120. + hcd->hc_ptr_array[i] = channel;
  97121. +#ifdef DEBUG
  97122. + hcd->core_if->hc_xfer_timer[i] =
  97123. + DWC_TIMER_ALLOC("hc timer", hc_xfer_timeout,
  97124. + &hcd->core_if->hc_xfer_info[i]);
  97125. +#endif
  97126. + DWC_DEBUGPL(DBG_HCDV, "HCD Added channel #%d, hc=%p\n", i,
  97127. + channel);
  97128. + }
  97129. +
  97130. + if (fiq_enable) {
  97131. + hcd->fiq_state = DWC_ALLOC(sizeof(struct fiq_state) + (sizeof(struct fiq_channel_state) * num_channels));
  97132. + if (!hcd->fiq_state) {
  97133. + retval = -DWC_E_NO_MEMORY;
  97134. + DWC_ERROR("%s: cannot allocate fiq_state structure\n", __func__);
  97135. + dwc_otg_hcd_free(hcd);
  97136. + goto out;
  97137. + }
  97138. + DWC_MEMSET(hcd->fiq_state, 0, (sizeof(struct fiq_state) + (sizeof(struct fiq_channel_state) * num_channels)));
  97139. +
  97140. + for (i = 0; i < num_channels; i++) {
  97141. + hcd->fiq_state->channel[i].fsm = FIQ_PASSTHROUGH;
  97142. + }
  97143. + hcd->fiq_state->dummy_send = DWC_ALLOC_ATOMIC(16);
  97144. +
  97145. + hcd->fiq_stack = DWC_ALLOC(sizeof(struct fiq_stack));
  97146. + if (!hcd->fiq_stack) {
  97147. + retval = -DWC_E_NO_MEMORY;
  97148. + DWC_ERROR("%s: cannot allocate fiq_stack structure\n", __func__);
  97149. + dwc_otg_hcd_free(hcd);
  97150. + goto out;
  97151. + }
  97152. + hcd->fiq_stack->magic1 = 0xDEADBEEF;
  97153. + hcd->fiq_stack->magic2 = 0xD00DFEED;
  97154. + hcd->fiq_state->gintmsk_saved.d32 = ~0;
  97155. + hcd->fiq_state->haintmsk_saved.b2.chint = ~0;
  97156. +
  97157. + /* This bit is terrible and uses no API, but necessary. The FIQ has no concept of DMA pools
  97158. + * (and if it did, would be a lot slower). This allocates a chunk of memory (~9kiB for 8 host channels)
  97159. + * for use as transaction bounce buffers in a 2-D array. Our access into this chunk is done by some
  97160. + * moderately readable array casts.
  97161. + */
  97162. + hcd->fiq_dmab = DWC_DMA_ALLOC((sizeof(struct fiq_dma_channel) * num_channels), &hcd->fiq_state->dma_base);
  97163. + DWC_WARN("FIQ DMA bounce buffers: virt = 0x%08x dma = 0x%08x len=%d",
  97164. + (unsigned int)hcd->fiq_dmab, (unsigned int)hcd->fiq_state->dma_base,
  97165. + sizeof(struct fiq_dma_channel) * num_channels);
  97166. +
  97167. + DWC_MEMSET(hcd->fiq_dmab, 0x6b, 9024);
  97168. +
  97169. + /* pointer for debug in fiq_print */
  97170. + hcd->fiq_state->fiq_dmab = hcd->fiq_dmab;
  97171. + if (fiq_fsm_enable) {
  97172. + int i;
  97173. + for (i=0; i < hcd->core_if->core_params->host_channels; i++) {
  97174. + dwc_otg_cleanup_fiq_channel(hcd, i);
  97175. + }
  97176. + DWC_PRINTF("FIQ FSM acceleration enabled for :\n%s%s%s%s",
  97177. + (fiq_fsm_mask & 0x1) ? "Non-periodic Split Transactions\n" : "",
  97178. + (fiq_fsm_mask & 0x2) ? "Periodic Split Transactions\n" : "",
  97179. + (fiq_fsm_mask & 0x4) ? "High-Speed Isochronous Endpoints\n" : "",
  97180. + (fiq_fsm_mask & 0x8) ? "Interrupt/Control Split Transaction hack enabled\n" : "");
  97181. + }
  97182. + }
  97183. +
  97184. + /* Initialize the Connection timeout timer. */
  97185. + hcd->conn_timer = DWC_TIMER_ALLOC("Connection timer",
  97186. + dwc_otg_hcd_connect_timeout, 0);
  97187. +
  97188. + printk(KERN_DEBUG "dwc_otg: Microframe scheduler %s\n", microframe_schedule ? "enabled":"disabled");
  97189. + if (microframe_schedule)
  97190. + init_hcd_usecs(hcd);
  97191. +
  97192. + /* Initialize reset tasklet. */
  97193. + hcd->reset_tasklet = DWC_TASK_ALLOC("reset_tasklet", reset_tasklet_func, hcd);
  97194. +
  97195. + hcd->completion_tasklet = DWC_TASK_ALLOC("completion_tasklet",
  97196. + completion_tasklet_func, hcd);
  97197. +#ifdef DWC_DEV_SRPCAP
  97198. + if (hcd->core_if->power_down == 2) {
  97199. + /* Initialize Power on timer for Host power up in case hibernation */
  97200. + hcd->core_if->pwron_timer = DWC_TIMER_ALLOC("PWRON TIMER",
  97201. + dwc_otg_hcd_power_up, core_if);
  97202. + }
  97203. +#endif
  97204. +
  97205. + /*
  97206. + * Allocate space for storing data on status transactions. Normally no
  97207. + * data is sent, but this space acts as a bit bucket. This must be
  97208. + * done after usb_add_hcd since that function allocates the DMA buffer
  97209. + * pool.
  97210. + */
  97211. + if (hcd->core_if->dma_enable) {
  97212. + hcd->status_buf =
  97213. + DWC_DMA_ALLOC(DWC_OTG_HCD_STATUS_BUF_SIZE,
  97214. + &hcd->status_buf_dma);
  97215. + } else {
  97216. + hcd->status_buf = DWC_ALLOC(DWC_OTG_HCD_STATUS_BUF_SIZE);
  97217. + }
  97218. + if (!hcd->status_buf) {
  97219. + retval = -DWC_E_NO_MEMORY;
  97220. + DWC_ERROR("%s: status_buf allocation failed\n", __func__);
  97221. + dwc_otg_hcd_free(hcd);
  97222. + goto out;
  97223. + }
  97224. +
  97225. + hcd->otg_port = 1;
  97226. + hcd->frame_list = NULL;
  97227. + hcd->frame_list_dma = 0;
  97228. + hcd->periodic_qh_count = 0;
  97229. +
  97230. + DWC_MEMSET(hcd->hub_port, 0, sizeof(hcd->hub_port));
  97231. +#ifdef FIQ_DEBUG
  97232. + DWC_MEMSET(hcd->hub_port_alloc, -1, sizeof(hcd->hub_port_alloc));
  97233. +#endif
  97234. +
  97235. +out:
  97236. + return retval;
  97237. +}
  97238. +
  97239. +void dwc_otg_hcd_remove(dwc_otg_hcd_t * hcd)
  97240. +{
  97241. + /* Turn off all host-specific interrupts. */
  97242. + dwc_otg_disable_host_interrupts(hcd->core_if);
  97243. +
  97244. + dwc_otg_hcd_free(hcd);
  97245. +}
  97246. +
  97247. +/**
  97248. + * Initializes dynamic portions of the DWC_otg HCD state.
  97249. + */
  97250. +static void dwc_otg_hcd_reinit(dwc_otg_hcd_t * hcd)
  97251. +{
  97252. + int num_channels;
  97253. + int i;
  97254. + dwc_hc_t *channel;
  97255. + dwc_hc_t *channel_tmp;
  97256. +
  97257. + hcd->flags.d32 = 0;
  97258. +
  97259. + hcd->non_periodic_qh_ptr = &hcd->non_periodic_sched_active;
  97260. + if (!microframe_schedule) {
  97261. + hcd->non_periodic_channels = 0;
  97262. + hcd->periodic_channels = 0;
  97263. + } else {
  97264. + hcd->available_host_channels = hcd->core_if->core_params->host_channels;
  97265. + }
  97266. + /*
  97267. + * Put all channels in the free channel list and clean up channel
  97268. + * states.
  97269. + */
  97270. + DWC_CIRCLEQ_FOREACH_SAFE(channel, channel_tmp,
  97271. + &hcd->free_hc_list, hc_list_entry) {
  97272. + DWC_CIRCLEQ_REMOVE(&hcd->free_hc_list, channel, hc_list_entry);
  97273. + }
  97274. +
  97275. + num_channels = hcd->core_if->core_params->host_channels;
  97276. + for (i = 0; i < num_channels; i++) {
  97277. + channel = hcd->hc_ptr_array[i];
  97278. + DWC_CIRCLEQ_INSERT_TAIL(&hcd->free_hc_list, channel,
  97279. + hc_list_entry);
  97280. + dwc_otg_hc_cleanup(hcd->core_if, channel);
  97281. + }
  97282. +
  97283. + /* Initialize the DWC core for host mode operation. */
  97284. + dwc_otg_core_host_init(hcd->core_if);
  97285. +
  97286. + /* Set core_if's lock pointer to the hcd->lock */
  97287. + hcd->core_if->lock = hcd->lock;
  97288. +}
  97289. +
  97290. +/**
  97291. + * Assigns transactions from a QTD to a free host channel and initializes the
  97292. + * host channel to perform the transactions. The host channel is removed from
  97293. + * the free list.
  97294. + *
  97295. + * @param hcd The HCD state structure.
  97296. + * @param qh Transactions from the first QTD for this QH are selected and
  97297. + * assigned to a free host channel.
  97298. + */
  97299. +static void assign_and_init_hc(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  97300. +{
  97301. + dwc_hc_t *hc;
  97302. + dwc_otg_qtd_t *qtd;
  97303. + dwc_otg_hcd_urb_t *urb;
  97304. + void* ptr = NULL;
  97305. + uint32_t intr_enable;
  97306. + unsigned long flags;
  97307. + gintmsk_data_t gintmsk = { .d32 = 0, };
  97308. +
  97309. + qtd = DWC_CIRCLEQ_FIRST(&qh->qtd_list);
  97310. +
  97311. + urb = qtd->urb;
  97312. +
  97313. + DWC_DEBUGPL(DBG_HCDV, "%s(%p,%p) - urb %x, actual_length %d\n", __func__, hcd, qh, (unsigned int)urb, urb->actual_length);
  97314. +
  97315. + if (((urb->actual_length < 0) || (urb->actual_length > urb->length)) && !dwc_otg_hcd_is_pipe_in(&urb->pipe_info))
  97316. + urb->actual_length = urb->length;
  97317. +
  97318. +
  97319. + hc = DWC_CIRCLEQ_FIRST(&hcd->free_hc_list);
  97320. +
  97321. + /* Remove the host channel from the free list. */
  97322. + DWC_CIRCLEQ_REMOVE_INIT(&hcd->free_hc_list, hc, hc_list_entry);
  97323. +
  97324. + qh->channel = hc;
  97325. +
  97326. + qtd->in_process = 1;
  97327. +
  97328. + /*
  97329. + * Use usb_pipedevice to determine device address. This address is
  97330. + * 0 before the SET_ADDRESS command and the correct address afterward.
  97331. + */
  97332. + hc->dev_addr = dwc_otg_hcd_get_dev_addr(&urb->pipe_info);
  97333. + hc->ep_num = dwc_otg_hcd_get_ep_num(&urb->pipe_info);
  97334. + hc->speed = qh->dev_speed;
  97335. + hc->max_packet = dwc_max_packet(qh->maxp);
  97336. +
  97337. + hc->xfer_started = 0;
  97338. + hc->halt_status = DWC_OTG_HC_XFER_NO_HALT_STATUS;
  97339. + hc->error_state = (qtd->error_count > 0);
  97340. + hc->halt_on_queue = 0;
  97341. + hc->halt_pending = 0;
  97342. + hc->requests = 0;
  97343. +
  97344. + /*
  97345. + * The following values may be modified in the transfer type section
  97346. + * below. The xfer_len value may be reduced when the transfer is
  97347. + * started to accommodate the max widths of the XferSize and PktCnt
  97348. + * fields in the HCTSIZn register.
  97349. + */
  97350. +
  97351. + hc->ep_is_in = (dwc_otg_hcd_is_pipe_in(&urb->pipe_info) != 0);
  97352. + if (hc->ep_is_in) {
  97353. + hc->do_ping = 0;
  97354. + } else {
  97355. + hc->do_ping = qh->ping_state;
  97356. + }
  97357. +
  97358. + hc->data_pid_start = qh->data_toggle;
  97359. + hc->multi_count = 1;
  97360. +
  97361. + if (hcd->core_if->dma_enable) {
  97362. + hc->xfer_buff = (uint8_t *) urb->dma + urb->actual_length;
  97363. +
  97364. + /* For non-dword aligned case */
  97365. + if (((unsigned long)hc->xfer_buff & 0x3)
  97366. + && !hcd->core_if->dma_desc_enable) {
  97367. + ptr = (uint8_t *) urb->buf + urb->actual_length;
  97368. + }
  97369. + } else {
  97370. + hc->xfer_buff = (uint8_t *) urb->buf + urb->actual_length;
  97371. + }
  97372. + hc->xfer_len = urb->length - urb->actual_length;
  97373. + hc->xfer_count = 0;
  97374. +
  97375. + /*
  97376. + * Set the split attributes
  97377. + */
  97378. + hc->do_split = 0;
  97379. + if (qh->do_split) {
  97380. + uint32_t hub_addr, port_addr;
  97381. + hc->do_split = 1;
  97382. + hc->xact_pos = qtd->isoc_split_pos;
  97383. + /* We don't need to do complete splits anymore */
  97384. +// if(fiq_fsm_enable)
  97385. + if (0)
  97386. + hc->complete_split = qtd->complete_split = 0;
  97387. + else
  97388. + hc->complete_split = qtd->complete_split;
  97389. +
  97390. + hcd->fops->hub_info(hcd, urb->priv, &hub_addr, &port_addr);
  97391. + hc->hub_addr = (uint8_t) hub_addr;
  97392. + hc->port_addr = (uint8_t) port_addr;
  97393. + }
  97394. +
  97395. + switch (dwc_otg_hcd_get_pipe_type(&urb->pipe_info)) {
  97396. + case UE_CONTROL:
  97397. + hc->ep_type = DWC_OTG_EP_TYPE_CONTROL;
  97398. + switch (qtd->control_phase) {
  97399. + case DWC_OTG_CONTROL_SETUP:
  97400. + DWC_DEBUGPL(DBG_HCDV, " Control setup transaction\n");
  97401. + hc->do_ping = 0;
  97402. + hc->ep_is_in = 0;
  97403. + hc->data_pid_start = DWC_OTG_HC_PID_SETUP;
  97404. + if (hcd->core_if->dma_enable) {
  97405. + hc->xfer_buff = (uint8_t *) urb->setup_dma;
  97406. + } else {
  97407. + hc->xfer_buff = (uint8_t *) urb->setup_packet;
  97408. + }
  97409. + hc->xfer_len = 8;
  97410. + ptr = NULL;
  97411. + break;
  97412. + case DWC_OTG_CONTROL_DATA:
  97413. + DWC_DEBUGPL(DBG_HCDV, " Control data transaction\n");
  97414. + hc->data_pid_start = qtd->data_toggle;
  97415. + break;
  97416. + case DWC_OTG_CONTROL_STATUS:
  97417. + /*
  97418. + * Direction is opposite of data direction or IN if no
  97419. + * data.
  97420. + */
  97421. + DWC_DEBUGPL(DBG_HCDV, " Control status transaction\n");
  97422. + if (urb->length == 0) {
  97423. + hc->ep_is_in = 1;
  97424. + } else {
  97425. + hc->ep_is_in =
  97426. + dwc_otg_hcd_is_pipe_out(&urb->pipe_info);
  97427. + }
  97428. + if (hc->ep_is_in) {
  97429. + hc->do_ping = 0;
  97430. + }
  97431. +
  97432. + hc->data_pid_start = DWC_OTG_HC_PID_DATA1;
  97433. +
  97434. + hc->xfer_len = 0;
  97435. + if (hcd->core_if->dma_enable) {
  97436. + hc->xfer_buff = (uint8_t *) hcd->status_buf_dma;
  97437. + } else {
  97438. + hc->xfer_buff = (uint8_t *) hcd->status_buf;
  97439. + }
  97440. + ptr = NULL;
  97441. + break;
  97442. + }
  97443. + break;
  97444. + case UE_BULK:
  97445. + hc->ep_type = DWC_OTG_EP_TYPE_BULK;
  97446. + break;
  97447. + case UE_INTERRUPT:
  97448. + hc->ep_type = DWC_OTG_EP_TYPE_INTR;
  97449. + break;
  97450. + case UE_ISOCHRONOUS:
  97451. + {
  97452. + struct dwc_otg_hcd_iso_packet_desc *frame_desc;
  97453. +
  97454. + hc->ep_type = DWC_OTG_EP_TYPE_ISOC;
  97455. +
  97456. + if (hcd->core_if->dma_desc_enable)
  97457. + break;
  97458. +
  97459. + frame_desc = &urb->iso_descs[qtd->isoc_frame_index];
  97460. +
  97461. + frame_desc->status = 0;
  97462. +
  97463. + if (hcd->core_if->dma_enable) {
  97464. + hc->xfer_buff = (uint8_t *) urb->dma;
  97465. + } else {
  97466. + hc->xfer_buff = (uint8_t *) urb->buf;
  97467. + }
  97468. + hc->xfer_buff +=
  97469. + frame_desc->offset + qtd->isoc_split_offset;
  97470. + hc->xfer_len =
  97471. + frame_desc->length - qtd->isoc_split_offset;
  97472. +
  97473. + /* For non-dword aligned buffers */
  97474. + if (((unsigned long)hc->xfer_buff & 0x3)
  97475. + && hcd->core_if->dma_enable) {
  97476. + ptr =
  97477. + (uint8_t *) urb->buf + frame_desc->offset +
  97478. + qtd->isoc_split_offset;
  97479. + } else
  97480. + ptr = NULL;
  97481. +
  97482. + if (hc->xact_pos == DWC_HCSPLIT_XACTPOS_ALL) {
  97483. + if (hc->xfer_len <= 188) {
  97484. + hc->xact_pos = DWC_HCSPLIT_XACTPOS_ALL;
  97485. + } else {
  97486. + hc->xact_pos =
  97487. + DWC_HCSPLIT_XACTPOS_BEGIN;
  97488. + }
  97489. + }
  97490. + }
  97491. + break;
  97492. + }
  97493. + /* non DWORD-aligned buffer case */
  97494. + if (ptr) {
  97495. + uint32_t buf_size;
  97496. + if (hc->ep_type != DWC_OTG_EP_TYPE_ISOC) {
  97497. + buf_size = hcd->core_if->core_params->max_transfer_size;
  97498. + } else {
  97499. + buf_size = 4096;
  97500. + }
  97501. + if (!qh->dw_align_buf) {
  97502. + qh->dw_align_buf = DWC_DMA_ALLOC_ATOMIC(buf_size,
  97503. + &qh->dw_align_buf_dma);
  97504. + if (!qh->dw_align_buf) {
  97505. + DWC_ERROR
  97506. + ("%s: Failed to allocate memory to handle "
  97507. + "non-dword aligned buffer case\n",
  97508. + __func__);
  97509. + return;
  97510. + }
  97511. + }
  97512. + if (!hc->ep_is_in) {
  97513. + dwc_memcpy(qh->dw_align_buf, ptr, hc->xfer_len);
  97514. + }
  97515. + hc->align_buff = qh->dw_align_buf_dma;
  97516. + } else {
  97517. + hc->align_buff = 0;
  97518. + }
  97519. +
  97520. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  97521. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  97522. + /*
  97523. + * This value may be modified when the transfer is started to
  97524. + * reflect the actual transfer length.
  97525. + */
  97526. + hc->multi_count = dwc_hb_mult(qh->maxp);
  97527. + }
  97528. +
  97529. + if (hcd->core_if->dma_desc_enable)
  97530. + hc->desc_list_addr = qh->desc_list_dma;
  97531. +
  97532. + dwc_otg_hc_init(hcd->core_if, hc);
  97533. +
  97534. + local_irq_save(flags);
  97535. + local_fiq_disable();
  97536. + fiq_fsm_spin_lock(&hcd->fiq_state->lock);
  97537. + /* Enable the top level host channel interrupt. */
  97538. + intr_enable = (1 << hc->hc_num);
  97539. + DWC_MODIFY_REG32(&hcd->core_if->host_if->host_global_regs->haintmsk, 0, intr_enable);
  97540. +
  97541. + /* Make sure host channel interrupts are enabled. */
  97542. + gintmsk.b.hcintr = 1;
  97543. + DWC_MODIFY_REG32(&hcd->core_if->core_global_regs->gintmsk, 0, gintmsk.d32);
  97544. + fiq_fsm_spin_unlock(&hcd->fiq_state->lock);
  97545. + local_fiq_enable();
  97546. + local_irq_restore(flags);
  97547. + hc->qh = qh;
  97548. +}
  97549. +
  97550. +
  97551. +/**
  97552. + * fiq_fsm_transaction_suitable() - Test a QH for compatibility with the FIQ
  97553. + * @qh: pointer to the endpoint's queue head
  97554. + *
  97555. + * Transaction start/end control flow is grafted onto the existing dwc_otg
  97556. + * mechanisms, to avoid spaghettifying the functions more than they already are.
  97557. + * This function's eligibility check is altered by debug parameter.
  97558. + *
  97559. + * Returns: 0 for unsuitable, 1 implies the FIQ can be enabled for this transaction.
  97560. + */
  97561. +
  97562. +int fiq_fsm_transaction_suitable(dwc_otg_qh_t *qh)
  97563. +{
  97564. + if (qh->do_split) {
  97565. + switch (qh->ep_type) {
  97566. + case UE_CONTROL:
  97567. + case UE_BULK:
  97568. + if (fiq_fsm_mask & (1 << 0))
  97569. + return 1;
  97570. + break;
  97571. + case UE_INTERRUPT:
  97572. + case UE_ISOCHRONOUS:
  97573. + if (fiq_fsm_mask & (1 << 1))
  97574. + return 1;
  97575. + break;
  97576. + default:
  97577. + break;
  97578. + }
  97579. + } else if (qh->ep_type == UE_ISOCHRONOUS) {
  97580. + if (fiq_fsm_mask & (1 << 2)) {
  97581. + /* HS ISOCH support. We test for compatibility:
  97582. + * - DWORD aligned buffers
  97583. + * - Must be at least 2 transfers (otherwise pointless to use the FIQ)
  97584. + * If yes, then the fsm enqueue function will handle the state machine setup.
  97585. + */
  97586. + dwc_otg_qtd_t *qtd = DWC_CIRCLEQ_FIRST(&qh->qtd_list);
  97587. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  97588. + struct dwc_otg_hcd_iso_packet_desc (*iso_descs)[0] = &urb->iso_descs;
  97589. + int nr_iso_frames = urb->packet_count;
  97590. + int i;
  97591. + uint32_t ptr;
  97592. +
  97593. + if (nr_iso_frames < 2)
  97594. + return 0;
  97595. + for (i = 0; i < nr_iso_frames; i++) {
  97596. + ptr = urb->dma + iso_descs[i]->offset;
  97597. + if (ptr & 0x3) {
  97598. + printk_ratelimited("%s: Non-Dword aligned isochronous frame offset."
  97599. + " Cannot queue FIQ-accelerated transfer to device %d endpoint %d\n",
  97600. + __FUNCTION__, qh->channel->dev_addr, qh->channel->ep_num);
  97601. + return 0;
  97602. + }
  97603. + }
  97604. + return 1;
  97605. + }
  97606. + }
  97607. + return 0;
  97608. +}
  97609. +
  97610. +/**
  97611. + * fiq_fsm_setup_periodic_dma() - Set up DMA bounce buffers
  97612. + * @hcd: Pointer to the dwc_otg_hcd struct
  97613. + * @qh: Pointer to the endpoint's queue head
  97614. + *
  97615. + * Periodic split transactions are transmitted modulo 188 bytes.
  97616. + * This necessitates slicing data up into buckets for isochronous out
  97617. + * and fixing up the DMA address for all IN transfers.
  97618. + *
  97619. + * Returns 1 if the DMA bounce buffers have been used, 0 if the default
  97620. + * HC buffer has been used.
  97621. + */
  97622. +int fiq_fsm_setup_periodic_dma(dwc_otg_hcd_t *hcd, struct fiq_channel_state *st, dwc_otg_qh_t *qh)
  97623. + {
  97624. + int frame_length, i = 0;
  97625. + uint8_t *ptr = NULL;
  97626. + dwc_hc_t *hc = qh->channel;
  97627. + struct fiq_dma_blob *blob;
  97628. + struct dwc_otg_hcd_iso_packet_desc *frame_desc;
  97629. +
  97630. + for (i = 0; i < 6; i++) {
  97631. + st->dma_info.slot_len[i] = 255;
  97632. + }
  97633. + st->dma_info.index = 0;
  97634. + i = 0;
  97635. + if (hc->ep_is_in) {
  97636. + /*
  97637. + * Set dma_regs to bounce buffer. FIQ will update the
  97638. + * state depending on transaction progress.
  97639. + */
  97640. + blob = (struct fiq_dma_blob *) hcd->fiq_state->dma_base;
  97641. + st->hcdma_copy.d32 = (uint32_t) &blob->channel[hc->hc_num].index[0].buf[0];
  97642. + /* Calculate the max number of CSPLITS such that the FIQ can time out
  97643. + * a transaction if it fails.
  97644. + */
  97645. + frame_length = st->hcchar_copy.b.mps;
  97646. + do {
  97647. + i++;
  97648. + frame_length -= 188;
  97649. + } while (frame_length >= 0);
  97650. + st->nrpackets = i;
  97651. + return 1;
  97652. + } else {
  97653. + if (qh->ep_type == UE_ISOCHRONOUS) {
  97654. +
  97655. + dwc_otg_qtd_t *qtd = DWC_CIRCLEQ_FIRST(&qh->qtd_list);
  97656. +
  97657. + frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
  97658. + frame_length = frame_desc->length;
  97659. +
  97660. + /* Virtual address for bounce buffers */
  97661. + blob = hcd->fiq_dmab;
  97662. +
  97663. + ptr = qtd->urb->buf + frame_desc->offset;
  97664. + if (frame_length == 0) {
  97665. + /*
  97666. + * for isochronous transactions, we must still transmit a packet
  97667. + * even if the length is zero.
  97668. + */
  97669. + st->dma_info.slot_len[0] = 0;
  97670. + st->nrpackets = 1;
  97671. + } else {
  97672. + do {
  97673. + if (frame_length <= 188) {
  97674. + dwc_memcpy(&blob->channel[hc->hc_num].index[i].buf[0], ptr, frame_length);
  97675. + st->dma_info.slot_len[i] = frame_length;
  97676. + ptr += frame_length;
  97677. + } else {
  97678. + dwc_memcpy(&blob->channel[hc->hc_num].index[i].buf[0], ptr, 188);
  97679. + st->dma_info.slot_len[i] = 188;
  97680. + ptr += 188;
  97681. + }
  97682. + i++;
  97683. + frame_length -= 188;
  97684. + } while (frame_length > 0);
  97685. + st->nrpackets = i;
  97686. + }
  97687. + ptr = qtd->urb->buf + frame_desc->offset;
  97688. + /* Point the HC at the DMA address of the bounce buffers */
  97689. + blob = (struct fiq_dma_blob *) hcd->fiq_state->dma_base;
  97690. + st->hcdma_copy.d32 = (uint32_t) &blob->channel[hc->hc_num].index[0].buf[0];
  97691. +
  97692. + /* fixup xfersize to the actual packet size */
  97693. + st->hctsiz_copy.b.pid = 0;
  97694. + st->hctsiz_copy.b.xfersize = st->dma_info.slot_len[0];
  97695. + return 1;
  97696. + } else {
  97697. + /* For interrupt, single OUT packet required, goes in the SSPLIT from hc_buff. */
  97698. + return 0;
  97699. + }
  97700. + }
  97701. +}
  97702. +
  97703. +/*
  97704. + * Pushing a periodic request into the queue near the EOF1 point
  97705. + * in a microframe causes erroneous behaviour (frmovrun) interrupt.
  97706. + * Usually, the request goes out on the bus causing a transfer but
  97707. + * the core does not transfer the data to memory.
  97708. + * This guard interval (in number of 60MHz clocks) is required which
  97709. + * must cater for CPU latency between reading the value and enabling
  97710. + * the channel.
  97711. + */
  97712. +#define PERIODIC_FRREM_BACKOFF 1000
  97713. +
  97714. +int fiq_fsm_queue_isoc_transaction(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh)
  97715. +{
  97716. + dwc_hc_t *hc = qh->channel;
  97717. + dwc_otg_hc_regs_t *hc_regs = hcd->core_if->host_if->hc_regs[hc->hc_num];
  97718. + dwc_otg_qtd_t *qtd = DWC_CIRCLEQ_FIRST(&qh->qtd_list);
  97719. + int frame;
  97720. + struct fiq_channel_state *st = &hcd->fiq_state->channel[hc->hc_num];
  97721. + int xfer_len, nrpackets;
  97722. + hcdma_data_t hcdma;
  97723. + hfnum_data_t hfnum;
  97724. +
  97725. + if (st->fsm != FIQ_PASSTHROUGH)
  97726. + return 0;
  97727. +
  97728. + st->nr_errors = 0;
  97729. +
  97730. + st->hcchar_copy.d32 = 0;
  97731. + st->hcchar_copy.b.mps = hc->max_packet;
  97732. + st->hcchar_copy.b.epdir = hc->ep_is_in;
  97733. + st->hcchar_copy.b.devaddr = hc->dev_addr;
  97734. + st->hcchar_copy.b.epnum = hc->ep_num;
  97735. + st->hcchar_copy.b.eptype = hc->ep_type;
  97736. +
  97737. + st->hcintmsk_copy.b.chhltd = 1;
  97738. +
  97739. + frame = dwc_otg_hcd_get_frame_number(hcd);
  97740. + st->hcchar_copy.b.oddfrm = (frame & 0x1) ? 0 : 1;
  97741. +
  97742. + st->hcchar_copy.b.lspddev = 0;
  97743. + /* Enable the channel later as a final register write. */
  97744. +
  97745. + st->hcsplt_copy.d32 = 0;
  97746. +
  97747. + st->hs_isoc_info.iso_desc = (struct dwc_otg_hcd_iso_packet_desc *) &qtd->urb->iso_descs;
  97748. + st->hs_isoc_info.nrframes = qtd->urb->packet_count;
  97749. + /* grab the next DMA address offset from the array */
  97750. + st->hcdma_copy.d32 = qtd->urb->dma;
  97751. + hcdma.d32 = st->hcdma_copy.d32 + st->hs_isoc_info.iso_desc[0].offset;
  97752. +
  97753. + /* We need to set multi_count. This is a bit tricky - has to be set per-transaction as
  97754. + * the core needs to be told to send the correct number. Caution: for IN transfers,
  97755. + * this is always set to the maximum size of the endpoint. */
  97756. + xfer_len = st->hs_isoc_info.iso_desc[0].length;
  97757. + nrpackets = (xfer_len + st->hcchar_copy.b.mps - 1) / st->hcchar_copy.b.mps;
  97758. + if (nrpackets == 0)
  97759. + nrpackets = 1;
  97760. + st->hcchar_copy.b.multicnt = nrpackets;
  97761. + st->hctsiz_copy.b.pktcnt = nrpackets;
  97762. +
  97763. + /* Initial PID also needs to be set */
  97764. + if (st->hcchar_copy.b.epdir == 0) {
  97765. + st->hctsiz_copy.b.xfersize = xfer_len;
  97766. + switch (st->hcchar_copy.b.multicnt) {
  97767. + case 1:
  97768. + st->hctsiz_copy.b.pid = DWC_PID_DATA0;
  97769. + break;
  97770. + case 2:
  97771. + case 3:
  97772. + st->hctsiz_copy.b.pid = DWC_PID_MDATA;
  97773. + break;
  97774. + }
  97775. +
  97776. + } else {
  97777. + st->hctsiz_copy.b.xfersize = nrpackets * st->hcchar_copy.b.mps;
  97778. + switch (st->hcchar_copy.b.multicnt) {
  97779. + case 1:
  97780. + st->hctsiz_copy.b.pid = DWC_PID_DATA0;
  97781. + break;
  97782. + case 2:
  97783. + st->hctsiz_copy.b.pid = DWC_PID_DATA1;
  97784. + break;
  97785. + case 3:
  97786. + st->hctsiz_copy.b.pid = DWC_PID_DATA2;
  97787. + break;
  97788. + }
  97789. + }
  97790. +
  97791. + fiq_print(FIQDBG_INT, hcd->fiq_state, "FSMQ %01d ", hc->hc_num);
  97792. + fiq_print(FIQDBG_INT, hcd->fiq_state, "%08x", st->hcchar_copy.d32);
  97793. + fiq_print(FIQDBG_INT, hcd->fiq_state, "%08x", st->hctsiz_copy.d32);
  97794. + fiq_print(FIQDBG_INT, hcd->fiq_state, "%08x", st->hcdma_copy.d32);
  97795. + hfnum.d32 = DWC_READ_REG32(&hcd->core_if->host_if->host_global_regs->hfnum);
  97796. + local_fiq_disable();
  97797. + fiq_fsm_spin_lock(&hcd->fiq_state->lock);
  97798. + DWC_WRITE_REG32(&hc_regs->hctsiz, st->hctsiz_copy.d32);
  97799. + DWC_WRITE_REG32(&hc_regs->hcsplt, st->hcsplt_copy.d32);
  97800. + DWC_WRITE_REG32(&hc_regs->hcdma, st->hcdma_copy.d32);
  97801. + DWC_WRITE_REG32(&hc_regs->hcchar, st->hcchar_copy.d32);
  97802. + DWC_WRITE_REG32(&hc_regs->hcintmsk, st->hcintmsk_copy.d32);
  97803. + if (hfnum.b.frrem < PERIODIC_FRREM_BACKOFF) {
  97804. + /* Prevent queueing near EOF1. Bad things happen if a periodic
  97805. + * split transaction is queued very close to EOF.
  97806. + */
  97807. + st->fsm = FIQ_HS_ISOC_SLEEPING;
  97808. + } else {
  97809. + st->fsm = FIQ_HS_ISOC_TURBO;
  97810. + st->hcchar_copy.b.chen = 1;
  97811. + DWC_WRITE_REG32(&hc_regs->hcchar, st->hcchar_copy.d32);
  97812. + }
  97813. + mb();
  97814. + st->hcchar_copy.b.chen = 0;
  97815. + fiq_fsm_spin_unlock(&hcd->fiq_state->lock);
  97816. + local_fiq_enable();
  97817. + return 0;
  97818. +}
  97819. +
  97820. +
  97821. +/**
  97822. + * fiq_fsm_queue_split_transaction() - Set up a host channel and FIQ state
  97823. + * @hcd: Pointer to the dwc_otg_hcd struct
  97824. + * @qh: Pointer to the endpoint's queue head
  97825. + *
  97826. + * This overrides the dwc_otg driver's normal method of queueing a transaction.
  97827. + * Called from dwc_otg_hcd_queue_transactions(), this performs specific setup
  97828. + * for the nominated host channel.
  97829. + *
  97830. + * For periodic transfers, it also peeks at the FIQ state to see if an immediate
  97831. + * start is possible. If not, then the FIQ is left to start the transfer.
  97832. + */
  97833. +int fiq_fsm_queue_split_transaction(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh)
  97834. +{
  97835. + int start_immediate = 1, i;
  97836. + hfnum_data_t hfnum;
  97837. + dwc_hc_t *hc = qh->channel;
  97838. + dwc_otg_hc_regs_t *hc_regs = hcd->core_if->host_if->hc_regs[hc->hc_num];
  97839. + /* Program HC registers, setup FIQ_state, examine FIQ if periodic, start transfer (not if uframe 5) */
  97840. + int hub_addr, port_addr, frame, uframe;
  97841. + struct fiq_channel_state *st = &hcd->fiq_state->channel[hc->hc_num];
  97842. +
  97843. + if (st->fsm != FIQ_PASSTHROUGH)
  97844. + return 0;
  97845. + st->nr_errors = 0;
  97846. +
  97847. + st->hcchar_copy.d32 = 0;
  97848. + st->hcchar_copy.b.mps = hc->max_packet;
  97849. + st->hcchar_copy.b.epdir = hc->ep_is_in;
  97850. + st->hcchar_copy.b.devaddr = hc->dev_addr;
  97851. + st->hcchar_copy.b.epnum = hc->ep_num;
  97852. + st->hcchar_copy.b.eptype = hc->ep_type;
  97853. + if (hc->ep_type & 0x1) {
  97854. + if (hc->ep_is_in)
  97855. + st->hcchar_copy.b.multicnt = 3;
  97856. + else
  97857. + /* Docs say set this to 1, but driver sets to 0! */
  97858. + st->hcchar_copy.b.multicnt = 0;
  97859. + } else {
  97860. + st->hcchar_copy.b.multicnt = 1;
  97861. + st->hcchar_copy.b.oddfrm = 0;
  97862. + }
  97863. + st->hcchar_copy.b.lspddev = (hc->speed == DWC_OTG_EP_SPEED_LOW) ? 1 : 0;
  97864. + /* Enable the channel later as a final register write. */
  97865. +
  97866. + st->hcsplt_copy.d32 = 0;
  97867. + if(qh->do_split) {
  97868. + hcd->fops->hub_info(hcd, DWC_CIRCLEQ_FIRST(&qh->qtd_list)->urb->priv, &hub_addr, &port_addr);
  97869. + st->hcsplt_copy.b.compsplt = 0;
  97870. + st->hcsplt_copy.b.spltena = 1;
  97871. + // XACTPOS is for isoc-out only but needs initialising anyway.
  97872. + st->hcsplt_copy.b.xactpos = ISOC_XACTPOS_ALL;
  97873. + if((qh->ep_type == DWC_OTG_EP_TYPE_ISOC) && (!qh->ep_is_in)) {
  97874. + /* For packetsize 0 < L < 188, ISOC_XACTPOS_ALL.
  97875. + * for longer than this, ISOC_XACTPOS_BEGIN and the FIQ
  97876. + * will update as necessary.
  97877. + */
  97878. + if (hc->xfer_len > 188) {
  97879. + st->hcsplt_copy.b.xactpos = ISOC_XACTPOS_BEGIN;
  97880. + }
  97881. + }
  97882. + st->hcsplt_copy.b.hubaddr = (uint8_t) hub_addr;
  97883. + st->hcsplt_copy.b.prtaddr = (uint8_t) port_addr;
  97884. + st->hub_addr = hub_addr;
  97885. + st->port_addr = port_addr;
  97886. + }
  97887. +
  97888. + st->hctsiz_copy.d32 = 0;
  97889. + st->hctsiz_copy.b.dopng = 0;
  97890. + st->hctsiz_copy.b.pid = hc->data_pid_start;
  97891. +
  97892. + if (hc->ep_is_in || (hc->xfer_len > hc->max_packet)) {
  97893. + hc->xfer_len = hc->max_packet;
  97894. + } else if (!hc->ep_is_in && (hc->xfer_len > 188)) {
  97895. + hc->xfer_len = 188;
  97896. + }
  97897. + st->hctsiz_copy.b.xfersize = hc->xfer_len;
  97898. +
  97899. + st->hctsiz_copy.b.pktcnt = 1;
  97900. +
  97901. + if (hc->ep_type & 0x1) {
  97902. + /*
  97903. + * For potentially multi-packet transfers, must use the DMA bounce buffers. For IN transfers,
  97904. + * the DMA address is the address of the first 188byte slot buffer in the bounce buffer array.
  97905. + * For multi-packet OUT transfers, we need to copy the data into the bounce buffer array so the FIQ can punt
  97906. + * the right address out as necessary. hc->xfer_buff and hc->xfer_len have already been set
  97907. + * in assign_and_init_hc(), but this is for the eventual transaction completion only. The FIQ
  97908. + * must not touch internal driver state.
  97909. + */
  97910. + if(!fiq_fsm_setup_periodic_dma(hcd, st, qh)) {
  97911. + if (hc->align_buff) {
  97912. + st->hcdma_copy.d32 = hc->align_buff;
  97913. + } else {
  97914. + st->hcdma_copy.d32 = ((unsigned long) hc->xfer_buff & 0xFFFFFFFF);
  97915. + }
  97916. + }
  97917. + } else {
  97918. + if (hc->align_buff) {
  97919. + st->hcdma_copy.d32 = hc->align_buff;
  97920. + } else {
  97921. + st->hcdma_copy.d32 = ((unsigned long) hc->xfer_buff & 0xFFFFFFFF);
  97922. + }
  97923. + }
  97924. + /* The FIQ depends upon no other interrupts being enabled except channel halt.
  97925. + * Fixup channel interrupt mask. */
  97926. + st->hcintmsk_copy.d32 = 0;
  97927. + st->hcintmsk_copy.b.chhltd = 1;
  97928. + st->hcintmsk_copy.b.ahberr = 1;
  97929. +
  97930. + /* Hack courtesy of FreeBSD: apparently forcing Interrupt Split transactions
  97931. + * as Control puts the transfer into the non-periodic request queue and the
  97932. + * non-periodic handler in the hub. Makes things lots easier.
  97933. + */
  97934. + if ((fiq_fsm_mask & 0x8) && hc->ep_type == UE_INTERRUPT) {
  97935. + st->hcchar_copy.b.multicnt = 0;
  97936. + st->hcchar_copy.b.oddfrm = 0;
  97937. + st->hcchar_copy.b.eptype = UE_CONTROL;
  97938. + if (hc->align_buff) {
  97939. + st->hcdma_copy.d32 = hc->align_buff;
  97940. + } else {
  97941. + st->hcdma_copy.d32 = ((unsigned long) hc->xfer_buff & 0xFFFFFFFF);
  97942. + }
  97943. + }
  97944. + DWC_WRITE_REG32(&hc_regs->hcdma, st->hcdma_copy.d32);
  97945. + DWC_WRITE_REG32(&hc_regs->hctsiz, st->hctsiz_copy.d32);
  97946. + DWC_WRITE_REG32(&hc_regs->hcsplt, st->hcsplt_copy.d32);
  97947. + DWC_WRITE_REG32(&hc_regs->hcchar, st->hcchar_copy.d32);
  97948. + DWC_WRITE_REG32(&hc_regs->hcintmsk, st->hcintmsk_copy.d32);
  97949. +
  97950. + local_fiq_disable();
  97951. + fiq_fsm_spin_lock(&hcd->fiq_state->lock);
  97952. +
  97953. + if (hc->ep_type & 0x1) {
  97954. + hfnum.d32 = DWC_READ_REG32(&hcd->core_if->host_if->host_global_regs->hfnum);
  97955. + frame = (hfnum.b.frnum & ~0x7) >> 3;
  97956. + uframe = hfnum.b.frnum & 0x7;
  97957. + if (hfnum.b.frrem < PERIODIC_FRREM_BACKOFF) {
  97958. + /* Prevent queueing near EOF1. Bad things happen if a periodic
  97959. + * split transaction is queued very close to EOF.
  97960. + */
  97961. + start_immediate = 0;
  97962. + } else if (uframe == 5) {
  97963. + start_immediate = 0;
  97964. + } else if (hc->ep_type == UE_ISOCHRONOUS && !hc->ep_is_in) {
  97965. + start_immediate = 0;
  97966. + } else if (hc->ep_is_in && fiq_fsm_too_late(hcd->fiq_state, hc->hc_num)) {
  97967. + start_immediate = 0;
  97968. + } else {
  97969. + /* Search through all host channels to determine if a transaction
  97970. + * is currently in progress */
  97971. + for (i = 0; i < hcd->core_if->core_params->host_channels; i++) {
  97972. + if (i == hc->hc_num || hcd->fiq_state->channel[i].fsm == FIQ_PASSTHROUGH)
  97973. + continue;
  97974. + switch (hcd->fiq_state->channel[i].fsm) {
  97975. + /* TT is reserved for channels that are in the middle of a periodic
  97976. + * split transaction.
  97977. + */
  97978. + case FIQ_PER_SSPLIT_STARTED:
  97979. + case FIQ_PER_CSPLIT_WAIT:
  97980. + case FIQ_PER_CSPLIT_NYET1:
  97981. + case FIQ_PER_CSPLIT_POLL:
  97982. + case FIQ_PER_ISO_OUT_ACTIVE:
  97983. + case FIQ_PER_ISO_OUT_LAST:
  97984. + if (hcd->fiq_state->channel[i].hub_addr == hub_addr &&
  97985. + hcd->fiq_state->channel[i].port_addr == port_addr) {
  97986. + start_immediate = 0;
  97987. + }
  97988. + break;
  97989. + default:
  97990. + break;
  97991. + }
  97992. + if (!start_immediate)
  97993. + break;
  97994. + }
  97995. + }
  97996. + }
  97997. + if ((fiq_fsm_mask & 0x8) && hc->ep_type == UE_INTERRUPT)
  97998. + start_immediate = 1;
  97999. +
  98000. + fiq_print(FIQDBG_INT, hcd->fiq_state, "FSMQ %01d %01d", hc->hc_num, start_immediate);
  98001. + fiq_print(FIQDBG_INT, hcd->fiq_state, "%08d", hfnum.b.frrem);
  98002. + //fiq_print(FIQDBG_INT, hcd->fiq_state, "H:%02dP:%02d", hub_addr, port_addr);
  98003. + //fiq_print(FIQDBG_INT, hcd->fiq_state, "%08x", st->hctsiz_copy.d32);
  98004. + //fiq_print(FIQDBG_INT, hcd->fiq_state, "%08x", st->hcdma_copy.d32);
  98005. + switch (hc->ep_type) {
  98006. + case UE_CONTROL:
  98007. + case UE_BULK:
  98008. + st->fsm = FIQ_NP_SSPLIT_STARTED;
  98009. + break;
  98010. + case UE_ISOCHRONOUS:
  98011. + if (hc->ep_is_in) {
  98012. + if (start_immediate) {
  98013. + st->fsm = FIQ_PER_SSPLIT_STARTED;
  98014. + } else {
  98015. + st->fsm = FIQ_PER_SSPLIT_QUEUED;
  98016. + }
  98017. + } else {
  98018. + if (start_immediate) {
  98019. + /* Single-isoc OUT packets don't require FIQ involvement */
  98020. + if (st->nrpackets == 1) {
  98021. + st->fsm = FIQ_PER_ISO_OUT_LAST;
  98022. + } else {
  98023. + st->fsm = FIQ_PER_ISO_OUT_ACTIVE;
  98024. + }
  98025. + } else {
  98026. + st->fsm = FIQ_PER_ISO_OUT_PENDING;
  98027. + }
  98028. + }
  98029. + break;
  98030. + case UE_INTERRUPT:
  98031. + if (fiq_fsm_mask & 0x8) {
  98032. + st->fsm = FIQ_NP_SSPLIT_STARTED;
  98033. + } else if (start_immediate) {
  98034. + st->fsm = FIQ_PER_SSPLIT_STARTED;
  98035. + } else {
  98036. + st->fsm = FIQ_PER_SSPLIT_QUEUED;
  98037. + }
  98038. + default:
  98039. + break;
  98040. + }
  98041. + if (start_immediate) {
  98042. + /* Set the oddfrm bit as close as possible to actual queueing */
  98043. + frame = dwc_otg_hcd_get_frame_number(hcd);
  98044. + st->expected_uframe = (frame + 1) & 0x3FFF;
  98045. + st->hcchar_copy.b.oddfrm = (frame & 0x1) ? 0 : 1;
  98046. + st->hcchar_copy.b.chen = 1;
  98047. + DWC_WRITE_REG32(&hc_regs->hcchar, st->hcchar_copy.d32);
  98048. + }
  98049. + mb();
  98050. + fiq_fsm_spin_unlock(&hcd->fiq_state->lock);
  98051. + local_fiq_enable();
  98052. + return 0;
  98053. +}
  98054. +
  98055. +
  98056. +/**
  98057. + * This function selects transactions from the HCD transfer schedule and
  98058. + * assigns them to available host channels. It is called from HCD interrupt
  98059. + * handler functions.
  98060. + *
  98061. + * @param hcd The HCD state structure.
  98062. + *
  98063. + * @return The types of new transactions that were assigned to host channels.
  98064. + */
  98065. +dwc_otg_transaction_type_e dwc_otg_hcd_select_transactions(dwc_otg_hcd_t * hcd)
  98066. +{
  98067. + dwc_list_link_t *qh_ptr;
  98068. + dwc_otg_qh_t *qh;
  98069. + int num_channels;
  98070. + dwc_irqflags_t flags;
  98071. + dwc_spinlock_t *channel_lock = hcd->channel_lock;
  98072. + dwc_otg_transaction_type_e ret_val = DWC_OTG_TRANSACTION_NONE;
  98073. +
  98074. +#ifdef DEBUG_HOST_CHANNELS
  98075. + last_sel_trans_num_per_scheduled = 0;
  98076. + last_sel_trans_num_nonper_scheduled = 0;
  98077. + last_sel_trans_num_avail_hc_at_start = hcd->available_host_channels;
  98078. +#endif /* DEBUG_HOST_CHANNELS */
  98079. +
  98080. + /* Process entries in the periodic ready list. */
  98081. + qh_ptr = DWC_LIST_FIRST(&hcd->periodic_sched_ready);
  98082. +
  98083. + while (qh_ptr != &hcd->periodic_sched_ready &&
  98084. + !DWC_CIRCLEQ_EMPTY(&hcd->free_hc_list)) {
  98085. +
  98086. + qh = DWC_LIST_ENTRY(qh_ptr, dwc_otg_qh_t, qh_list_entry);
  98087. +
  98088. + if (microframe_schedule) {
  98089. + // Make sure we leave one channel for non periodic transactions.
  98090. + DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
  98091. + if (hcd->available_host_channels <= 1) {
  98092. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  98093. + break;
  98094. + }
  98095. + hcd->available_host_channels--;
  98096. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  98097. +#ifdef DEBUG_HOST_CHANNELS
  98098. + last_sel_trans_num_per_scheduled++;
  98099. +#endif /* DEBUG_HOST_CHANNELS */
  98100. + }
  98101. + qh = DWC_LIST_ENTRY(qh_ptr, dwc_otg_qh_t, qh_list_entry);
  98102. + assign_and_init_hc(hcd, qh);
  98103. +
  98104. + /*
  98105. + * Move the QH from the periodic ready schedule to the
  98106. + * periodic assigned schedule.
  98107. + */
  98108. + qh_ptr = DWC_LIST_NEXT(qh_ptr);
  98109. + DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
  98110. + DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_assigned,
  98111. + &qh->qh_list_entry);
  98112. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  98113. + }
  98114. +
  98115. + /*
  98116. + * Process entries in the inactive portion of the non-periodic
  98117. + * schedule. Some free host channels may not be used if they are
  98118. + * reserved for periodic transfers.
  98119. + */
  98120. + qh_ptr = hcd->non_periodic_sched_inactive.next;
  98121. + num_channels = hcd->core_if->core_params->host_channels;
  98122. + while (qh_ptr != &hcd->non_periodic_sched_inactive &&
  98123. + (microframe_schedule || hcd->non_periodic_channels <
  98124. + num_channels - hcd->periodic_channels) &&
  98125. + !DWC_CIRCLEQ_EMPTY(&hcd->free_hc_list)) {
  98126. +
  98127. + qh = DWC_LIST_ENTRY(qh_ptr, dwc_otg_qh_t, qh_list_entry);
  98128. + /*
  98129. + * Check to see if this is a NAK'd retransmit, in which case ignore for retransmission
  98130. + * we hold off on bulk retransmissions to reduce NAK interrupt overhead for full-speed
  98131. + * cheeky devices that just hold off using NAKs
  98132. + */
  98133. + if (nak_holdoff && qh->do_split) {
  98134. + if (qh->nak_frame != 0xffff) {
  98135. + uint16_t next_frame = dwc_frame_num_inc(qh->nak_frame, (qh->ep_type == UE_BULK) ? nak_holdoff : 8);
  98136. + uint16_t frame = dwc_otg_hcd_get_frame_number(hcd);
  98137. + if (dwc_frame_num_le(frame, next_frame)) {
  98138. + if(dwc_frame_num_le(next_frame, hcd->fiq_state->next_sched_frame)) {
  98139. + hcd->fiq_state->next_sched_frame = next_frame;
  98140. + }
  98141. + qh_ptr = DWC_LIST_NEXT(qh_ptr);
  98142. + continue;
  98143. + } else {
  98144. + qh->nak_frame = 0xFFFF;
  98145. + }
  98146. + }
  98147. + }
  98148. +
  98149. + if (microframe_schedule) {
  98150. + DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
  98151. + if (hcd->available_host_channels < 1) {
  98152. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  98153. + break;
  98154. + }
  98155. + hcd->available_host_channels--;
  98156. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  98157. +#ifdef DEBUG_HOST_CHANNELS
  98158. + last_sel_trans_num_nonper_scheduled++;
  98159. +#endif /* DEBUG_HOST_CHANNELS */
  98160. + }
  98161. +
  98162. + assign_and_init_hc(hcd, qh);
  98163. +
  98164. + /*
  98165. + * Move the QH from the non-periodic inactive schedule to the
  98166. + * non-periodic active schedule.
  98167. + */
  98168. + qh_ptr = DWC_LIST_NEXT(qh_ptr);
  98169. + DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
  98170. + DWC_LIST_MOVE_HEAD(&hcd->non_periodic_sched_active,
  98171. + &qh->qh_list_entry);
  98172. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  98173. +
  98174. +
  98175. + if (!microframe_schedule)
  98176. + hcd->non_periodic_channels++;
  98177. + }
  98178. + /* we moved a non-periodic QH to the active schedule. If the inactive queue is empty,
  98179. + * stop the FIQ from kicking us. We could potentially still have elements here if we
  98180. + * ran out of host channels.
  98181. + */
  98182. + if (fiq_enable) {
  98183. + if (DWC_LIST_EMPTY(&hcd->non_periodic_sched_inactive)) {
  98184. + hcd->fiq_state->kick_np_queues = 0;
  98185. + } else {
  98186. + /* For each entry remaining in the NP inactive queue,
  98187. + * if this a NAK'd retransmit then don't set the kick flag.
  98188. + */
  98189. + if(nak_holdoff) {
  98190. + DWC_LIST_FOREACH(qh_ptr, &hcd->non_periodic_sched_inactive) {
  98191. + qh = DWC_LIST_ENTRY(qh_ptr, dwc_otg_qh_t, qh_list_entry);
  98192. + if (qh->nak_frame == 0xFFFF) {
  98193. + hcd->fiq_state->kick_np_queues = 1;
  98194. + }
  98195. + }
  98196. + }
  98197. + }
  98198. + }
  98199. + if(!DWC_LIST_EMPTY(&hcd->periodic_sched_assigned))
  98200. + ret_val |= DWC_OTG_TRANSACTION_PERIODIC;
  98201. +
  98202. + if(!DWC_LIST_EMPTY(&hcd->non_periodic_sched_active))
  98203. + ret_val |= DWC_OTG_TRANSACTION_NON_PERIODIC;
  98204. +
  98205. +
  98206. +#ifdef DEBUG_HOST_CHANNELS
  98207. + last_sel_trans_num_avail_hc_at_end = hcd->available_host_channels;
  98208. +#endif /* DEBUG_HOST_CHANNELS */
  98209. + return ret_val;
  98210. +}
  98211. +
  98212. +/**
  98213. + * Attempts to queue a single transaction request for a host channel
  98214. + * associated with either a periodic or non-periodic transfer. This function
  98215. + * assumes that there is space available in the appropriate request queue. For
  98216. + * an OUT transfer or SETUP transaction in Slave mode, it checks whether space
  98217. + * is available in the appropriate Tx FIFO.
  98218. + *
  98219. + * @param hcd The HCD state structure.
  98220. + * @param hc Host channel descriptor associated with either a periodic or
  98221. + * non-periodic transfer.
  98222. + * @param fifo_dwords_avail Number of DWORDs available in the periodic Tx
  98223. + * FIFO for periodic transfers or the non-periodic Tx FIFO for non-periodic
  98224. + * transfers.
  98225. + *
  98226. + * @return 1 if a request is queued and more requests may be needed to
  98227. + * complete the transfer, 0 if no more requests are required for this
  98228. + * transfer, -1 if there is insufficient space in the Tx FIFO.
  98229. + */
  98230. +static int queue_transaction(dwc_otg_hcd_t * hcd,
  98231. + dwc_hc_t * hc, uint16_t fifo_dwords_avail)
  98232. +{
  98233. + int retval;
  98234. +
  98235. + if (hcd->core_if->dma_enable) {
  98236. + if (hcd->core_if->dma_desc_enable) {
  98237. + if (!hc->xfer_started
  98238. + || (hc->ep_type == DWC_OTG_EP_TYPE_ISOC)) {
  98239. + dwc_otg_hcd_start_xfer_ddma(hcd, hc->qh);
  98240. + hc->qh->ping_state = 0;
  98241. + }
  98242. + } else if (!hc->xfer_started) {
  98243. + if (fiq_fsm_enable && hc->error_state) {
  98244. + hcd->fiq_state->channel[hc->hc_num].nr_errors =
  98245. + DWC_CIRCLEQ_FIRST(&hc->qh->qtd_list)->error_count;
  98246. + hcd->fiq_state->channel[hc->hc_num].fsm =
  98247. + FIQ_PASSTHROUGH_ERRORSTATE;
  98248. + }
  98249. + dwc_otg_hc_start_transfer(hcd->core_if, hc);
  98250. + hc->qh->ping_state = 0;
  98251. + }
  98252. + retval = 0;
  98253. + } else if (hc->halt_pending) {
  98254. + /* Don't queue a request if the channel has been halted. */
  98255. + retval = 0;
  98256. + } else if (hc->halt_on_queue) {
  98257. + dwc_otg_hc_halt(hcd->core_if, hc, hc->halt_status);
  98258. + retval = 0;
  98259. + } else if (hc->do_ping) {
  98260. + if (!hc->xfer_started) {
  98261. + dwc_otg_hc_start_transfer(hcd->core_if, hc);
  98262. + }
  98263. + retval = 0;
  98264. + } else if (!hc->ep_is_in || hc->data_pid_start == DWC_OTG_HC_PID_SETUP) {
  98265. + if ((fifo_dwords_avail * 4) >= hc->max_packet) {
  98266. + if (!hc->xfer_started) {
  98267. + dwc_otg_hc_start_transfer(hcd->core_if, hc);
  98268. + retval = 1;
  98269. + } else {
  98270. + retval =
  98271. + dwc_otg_hc_continue_transfer(hcd->core_if,
  98272. + hc);
  98273. + }
  98274. + } else {
  98275. + retval = -1;
  98276. + }
  98277. + } else {
  98278. + if (!hc->xfer_started) {
  98279. + dwc_otg_hc_start_transfer(hcd->core_if, hc);
  98280. + retval = 1;
  98281. + } else {
  98282. + retval = dwc_otg_hc_continue_transfer(hcd->core_if, hc);
  98283. + }
  98284. + }
  98285. +
  98286. + return retval;
  98287. +}
  98288. +
  98289. +/**
  98290. + * Processes periodic channels for the next frame and queues transactions for
  98291. + * these channels to the DWC_otg controller. After queueing transactions, the
  98292. + * Periodic Tx FIFO Empty interrupt is enabled if there are more transactions
  98293. + * to queue as Periodic Tx FIFO or request queue space becomes available.
  98294. + * Otherwise, the Periodic Tx FIFO Empty interrupt is disabled.
  98295. + */
  98296. +static void process_periodic_channels(dwc_otg_hcd_t * hcd)
  98297. +{
  98298. + hptxsts_data_t tx_status;
  98299. + dwc_list_link_t *qh_ptr;
  98300. + dwc_otg_qh_t *qh;
  98301. + int status = 0;
  98302. + int no_queue_space = 0;
  98303. + int no_fifo_space = 0;
  98304. +
  98305. + dwc_otg_host_global_regs_t *host_regs;
  98306. + host_regs = hcd->core_if->host_if->host_global_regs;
  98307. +
  98308. + DWC_DEBUGPL(DBG_HCDV, "Queue periodic transactions\n");
  98309. +#ifdef DEBUG
  98310. + tx_status.d32 = DWC_READ_REG32(&host_regs->hptxsts);
  98311. + DWC_DEBUGPL(DBG_HCDV,
  98312. + " P Tx Req Queue Space Avail (before queue): %d\n",
  98313. + tx_status.b.ptxqspcavail);
  98314. + DWC_DEBUGPL(DBG_HCDV, " P Tx FIFO Space Avail (before queue): %d\n",
  98315. + tx_status.b.ptxfspcavail);
  98316. +#endif
  98317. +
  98318. + qh_ptr = hcd->periodic_sched_assigned.next;
  98319. + while (qh_ptr != &hcd->periodic_sched_assigned) {
  98320. + tx_status.d32 = DWC_READ_REG32(&host_regs->hptxsts);
  98321. + if (tx_status.b.ptxqspcavail == 0) {
  98322. + no_queue_space = 1;
  98323. + break;
  98324. + }
  98325. +
  98326. + qh = DWC_LIST_ENTRY(qh_ptr, dwc_otg_qh_t, qh_list_entry);
  98327. +
  98328. + // Do not send a split start transaction any later than frame .6
  98329. + // Note, we have to schedule a periodic in .5 to make it go in .6
  98330. + if(fiq_fsm_enable && qh->do_split && ((dwc_otg_hcd_get_frame_number(hcd) + 1) & 7) > 6)
  98331. + {
  98332. + qh_ptr = qh_ptr->next;
  98333. + hcd->fiq_state->next_sched_frame = dwc_otg_hcd_get_frame_number(hcd) | 7;
  98334. + continue;
  98335. + }
  98336. +
  98337. + if (fiq_fsm_enable && fiq_fsm_transaction_suitable(qh)) {
  98338. + if (qh->do_split)
  98339. + fiq_fsm_queue_split_transaction(hcd, qh);
  98340. + else
  98341. + fiq_fsm_queue_isoc_transaction(hcd, qh);
  98342. + } else {
  98343. +
  98344. + /*
  98345. + * Set a flag if we're queueing high-bandwidth in slave mode.
  98346. + * The flag prevents any halts to get into the request queue in
  98347. + * the middle of multiple high-bandwidth packets getting queued.
  98348. + */
  98349. + if (!hcd->core_if->dma_enable && qh->channel->multi_count > 1) {
  98350. + hcd->core_if->queuing_high_bandwidth = 1;
  98351. + }
  98352. + status = queue_transaction(hcd, qh->channel,
  98353. + tx_status.b.ptxfspcavail);
  98354. + if (status < 0) {
  98355. + no_fifo_space = 1;
  98356. + break;
  98357. + }
  98358. + }
  98359. +
  98360. + /*
  98361. + * In Slave mode, stay on the current transfer until there is
  98362. + * nothing more to do or the high-bandwidth request count is
  98363. + * reached. In DMA mode, only need to queue one request. The
  98364. + * controller automatically handles multiple packets for
  98365. + * high-bandwidth transfers.
  98366. + */
  98367. + if (hcd->core_if->dma_enable || status == 0 ||
  98368. + qh->channel->requests == qh->channel->multi_count) {
  98369. + qh_ptr = qh_ptr->next;
  98370. + /*
  98371. + * Move the QH from the periodic assigned schedule to
  98372. + * the periodic queued schedule.
  98373. + */
  98374. + DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_queued,
  98375. + &qh->qh_list_entry);
  98376. +
  98377. + /* done queuing high bandwidth */
  98378. + hcd->core_if->queuing_high_bandwidth = 0;
  98379. + }
  98380. + }
  98381. +
  98382. + if (!hcd->core_if->dma_enable) {
  98383. + dwc_otg_core_global_regs_t *global_regs;
  98384. + gintmsk_data_t intr_mask = {.d32 = 0 };
  98385. +
  98386. + global_regs = hcd->core_if->core_global_regs;
  98387. + intr_mask.b.ptxfempty = 1;
  98388. +#ifdef DEBUG
  98389. + tx_status.d32 = DWC_READ_REG32(&host_regs->hptxsts);
  98390. + DWC_DEBUGPL(DBG_HCDV,
  98391. + " P Tx Req Queue Space Avail (after queue): %d\n",
  98392. + tx_status.b.ptxqspcavail);
  98393. + DWC_DEBUGPL(DBG_HCDV,
  98394. + " P Tx FIFO Space Avail (after queue): %d\n",
  98395. + tx_status.b.ptxfspcavail);
  98396. +#endif
  98397. + if (!DWC_LIST_EMPTY(&hcd->periodic_sched_assigned) ||
  98398. + no_queue_space || no_fifo_space) {
  98399. + /*
  98400. + * May need to queue more transactions as the request
  98401. + * queue or Tx FIFO empties. Enable the periodic Tx
  98402. + * FIFO empty interrupt. (Always use the half-empty
  98403. + * level to ensure that new requests are loaded as
  98404. + * soon as possible.)
  98405. + */
  98406. + DWC_MODIFY_REG32(&global_regs->gintmsk, 0,
  98407. + intr_mask.d32);
  98408. + } else {
  98409. + /*
  98410. + * Disable the Tx FIFO empty interrupt since there are
  98411. + * no more transactions that need to be queued right
  98412. + * now. This function is called from interrupt
  98413. + * handlers to queue more transactions as transfer
  98414. + * states change.
  98415. + */
  98416. + DWC_MODIFY_REG32(&global_regs->gintmsk, intr_mask.d32,
  98417. + 0);
  98418. + }
  98419. + }
  98420. +}
  98421. +
  98422. +/**
  98423. + * Processes active non-periodic channels and queues transactions for these
  98424. + * channels to the DWC_otg controller. After queueing transactions, the NP Tx
  98425. + * FIFO Empty interrupt is enabled if there are more transactions to queue as
  98426. + * NP Tx FIFO or request queue space becomes available. Otherwise, the NP Tx
  98427. + * FIFO Empty interrupt is disabled.
  98428. + */
  98429. +static void process_non_periodic_channels(dwc_otg_hcd_t * hcd)
  98430. +{
  98431. + gnptxsts_data_t tx_status;
  98432. + dwc_list_link_t *orig_qh_ptr;
  98433. + dwc_otg_qh_t *qh;
  98434. + int status;
  98435. + int no_queue_space = 0;
  98436. + int no_fifo_space = 0;
  98437. + int more_to_do = 0;
  98438. +
  98439. + dwc_otg_core_global_regs_t *global_regs =
  98440. + hcd->core_if->core_global_regs;
  98441. +
  98442. + DWC_DEBUGPL(DBG_HCDV, "Queue non-periodic transactions\n");
  98443. +#ifdef DEBUG
  98444. + tx_status.d32 = DWC_READ_REG32(&global_regs->gnptxsts);
  98445. + DWC_DEBUGPL(DBG_HCDV,
  98446. + " NP Tx Req Queue Space Avail (before queue): %d\n",
  98447. + tx_status.b.nptxqspcavail);
  98448. + DWC_DEBUGPL(DBG_HCDV, " NP Tx FIFO Space Avail (before queue): %d\n",
  98449. + tx_status.b.nptxfspcavail);
  98450. +#endif
  98451. + /*
  98452. + * Keep track of the starting point. Skip over the start-of-list
  98453. + * entry.
  98454. + */
  98455. + if (hcd->non_periodic_qh_ptr == &hcd->non_periodic_sched_active) {
  98456. + hcd->non_periodic_qh_ptr = hcd->non_periodic_qh_ptr->next;
  98457. + }
  98458. + orig_qh_ptr = hcd->non_periodic_qh_ptr;
  98459. +
  98460. + /*
  98461. + * Process once through the active list or until no more space is
  98462. + * available in the request queue or the Tx FIFO.
  98463. + */
  98464. + do {
  98465. + tx_status.d32 = DWC_READ_REG32(&global_regs->gnptxsts);
  98466. + if (!hcd->core_if->dma_enable && tx_status.b.nptxqspcavail == 0) {
  98467. + no_queue_space = 1;
  98468. + break;
  98469. + }
  98470. +
  98471. + qh = DWC_LIST_ENTRY(hcd->non_periodic_qh_ptr, dwc_otg_qh_t,
  98472. + qh_list_entry);
  98473. +
  98474. + if(fiq_fsm_enable && fiq_fsm_transaction_suitable(qh)) {
  98475. + fiq_fsm_queue_split_transaction(hcd, qh);
  98476. + } else {
  98477. + status = queue_transaction(hcd, qh->channel,
  98478. + tx_status.b.nptxfspcavail);
  98479. +
  98480. + if (status > 0) {
  98481. + more_to_do = 1;
  98482. + } else if (status < 0) {
  98483. + no_fifo_space = 1;
  98484. + break;
  98485. + }
  98486. + }
  98487. + /* Advance to next QH, skipping start-of-list entry. */
  98488. + hcd->non_periodic_qh_ptr = hcd->non_periodic_qh_ptr->next;
  98489. + if (hcd->non_periodic_qh_ptr == &hcd->non_periodic_sched_active) {
  98490. + hcd->non_periodic_qh_ptr =
  98491. + hcd->non_periodic_qh_ptr->next;
  98492. + }
  98493. +
  98494. + } while (hcd->non_periodic_qh_ptr != orig_qh_ptr);
  98495. +
  98496. + if (!hcd->core_if->dma_enable) {
  98497. + gintmsk_data_t intr_mask = {.d32 = 0 };
  98498. + intr_mask.b.nptxfempty = 1;
  98499. +
  98500. +#ifdef DEBUG
  98501. + tx_status.d32 = DWC_READ_REG32(&global_regs->gnptxsts);
  98502. + DWC_DEBUGPL(DBG_HCDV,
  98503. + " NP Tx Req Queue Space Avail (after queue): %d\n",
  98504. + tx_status.b.nptxqspcavail);
  98505. + DWC_DEBUGPL(DBG_HCDV,
  98506. + " NP Tx FIFO Space Avail (after queue): %d\n",
  98507. + tx_status.b.nptxfspcavail);
  98508. +#endif
  98509. + if (more_to_do || no_queue_space || no_fifo_space) {
  98510. + /*
  98511. + * May need to queue more transactions as the request
  98512. + * queue or Tx FIFO empties. Enable the non-periodic
  98513. + * Tx FIFO empty interrupt. (Always use the half-empty
  98514. + * level to ensure that new requests are loaded as
  98515. + * soon as possible.)
  98516. + */
  98517. + DWC_MODIFY_REG32(&global_regs->gintmsk, 0,
  98518. + intr_mask.d32);
  98519. + } else {
  98520. + /*
  98521. + * Disable the Tx FIFO empty interrupt since there are
  98522. + * no more transactions that need to be queued right
  98523. + * now. This function is called from interrupt
  98524. + * handlers to queue more transactions as transfer
  98525. + * states change.
  98526. + */
  98527. + DWC_MODIFY_REG32(&global_regs->gintmsk, intr_mask.d32,
  98528. + 0);
  98529. + }
  98530. + }
  98531. +}
  98532. +
  98533. +/**
  98534. + * This function processes the currently active host channels and queues
  98535. + * transactions for these channels to the DWC_otg controller. It is called
  98536. + * from HCD interrupt handler functions.
  98537. + *
  98538. + * @param hcd The HCD state structure.
  98539. + * @param tr_type The type(s) of transactions to queue (non-periodic,
  98540. + * periodic, or both).
  98541. + */
  98542. +void dwc_otg_hcd_queue_transactions(dwc_otg_hcd_t * hcd,
  98543. + dwc_otg_transaction_type_e tr_type)
  98544. +{
  98545. +#ifdef DEBUG_SOF
  98546. + DWC_DEBUGPL(DBG_HCD, "Queue Transactions\n");
  98547. +#endif
  98548. + /* Process host channels associated with periodic transfers. */
  98549. + if ((tr_type == DWC_OTG_TRANSACTION_PERIODIC ||
  98550. + tr_type == DWC_OTG_TRANSACTION_ALL) &&
  98551. + !DWC_LIST_EMPTY(&hcd->periodic_sched_assigned)) {
  98552. +
  98553. + process_periodic_channels(hcd);
  98554. + }
  98555. +
  98556. + /* Process host channels associated with non-periodic transfers. */
  98557. + if (tr_type == DWC_OTG_TRANSACTION_NON_PERIODIC ||
  98558. + tr_type == DWC_OTG_TRANSACTION_ALL) {
  98559. + if (!DWC_LIST_EMPTY(&hcd->non_periodic_sched_active)) {
  98560. + process_non_periodic_channels(hcd);
  98561. + } else {
  98562. + /*
  98563. + * Ensure NP Tx FIFO empty interrupt is disabled when
  98564. + * there are no non-periodic transfers to process.
  98565. + */
  98566. + gintmsk_data_t gintmsk = {.d32 = 0 };
  98567. + gintmsk.b.nptxfempty = 1;
  98568. +
  98569. + if (fiq_enable) {
  98570. + local_fiq_disable();
  98571. + fiq_fsm_spin_lock(&hcd->fiq_state->lock);
  98572. + DWC_MODIFY_REG32(&hcd->core_if->core_global_regs->gintmsk, gintmsk.d32, 0);
  98573. + fiq_fsm_spin_unlock(&hcd->fiq_state->lock);
  98574. + local_fiq_enable();
  98575. + } else {
  98576. + DWC_MODIFY_REG32(&hcd->core_if->core_global_regs->gintmsk, gintmsk.d32, 0);
  98577. + }
  98578. + }
  98579. + }
  98580. +}
  98581. +
  98582. +#ifdef DWC_HS_ELECT_TST
  98583. +/*
  98584. + * Quick and dirty hack to implement the HS Electrical Test
  98585. + * SINGLE_STEP_GET_DEVICE_DESCRIPTOR feature.
  98586. + *
  98587. + * This code was copied from our userspace app "hset". It sends a
  98588. + * Get Device Descriptor control sequence in two parts, first the
  98589. + * Setup packet by itself, followed some time later by the In and
  98590. + * Ack packets. Rather than trying to figure out how to add this
  98591. + * functionality to the normal driver code, we just hijack the
  98592. + * hardware, using these two function to drive the hardware
  98593. + * directly.
  98594. + */
  98595. +
  98596. +static dwc_otg_core_global_regs_t *global_regs;
  98597. +static dwc_otg_host_global_regs_t *hc_global_regs;
  98598. +static dwc_otg_hc_regs_t *hc_regs;
  98599. +static uint32_t *data_fifo;
  98600. +
  98601. +static void do_setup(void)
  98602. +{
  98603. + gintsts_data_t gintsts;
  98604. + hctsiz_data_t hctsiz;
  98605. + hcchar_data_t hcchar;
  98606. + haint_data_t haint;
  98607. + hcint_data_t hcint;
  98608. +
  98609. + /* Enable HAINTs */
  98610. + DWC_WRITE_REG32(&hc_global_regs->haintmsk, 0x0001);
  98611. +
  98612. + /* Enable HCINTs */
  98613. + DWC_WRITE_REG32(&hc_regs->hcintmsk, 0x04a3);
  98614. +
  98615. + /* Read GINTSTS */
  98616. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  98617. +
  98618. + /* Read HAINT */
  98619. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  98620. +
  98621. + /* Read HCINT */
  98622. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  98623. +
  98624. + /* Read HCCHAR */
  98625. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  98626. +
  98627. + /* Clear HCINT */
  98628. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  98629. +
  98630. + /* Clear HAINT */
  98631. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  98632. +
  98633. + /* Clear GINTSTS */
  98634. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  98635. +
  98636. + /* Read GINTSTS */
  98637. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  98638. +
  98639. + /*
  98640. + * Send Setup packet (Get Device Descriptor)
  98641. + */
  98642. +
  98643. + /* Make sure channel is disabled */
  98644. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  98645. + if (hcchar.b.chen) {
  98646. + hcchar.b.chdis = 1;
  98647. +// hcchar.b.chen = 1;
  98648. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  98649. + //sleep(1);
  98650. + dwc_mdelay(1000);
  98651. +
  98652. + /* Read GINTSTS */
  98653. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  98654. +
  98655. + /* Read HAINT */
  98656. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  98657. +
  98658. + /* Read HCINT */
  98659. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  98660. +
  98661. + /* Read HCCHAR */
  98662. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  98663. +
  98664. + /* Clear HCINT */
  98665. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  98666. +
  98667. + /* Clear HAINT */
  98668. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  98669. +
  98670. + /* Clear GINTSTS */
  98671. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  98672. +
  98673. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  98674. + }
  98675. +
  98676. + /* Set HCTSIZ */
  98677. + hctsiz.d32 = 0;
  98678. + hctsiz.b.xfersize = 8;
  98679. + hctsiz.b.pktcnt = 1;
  98680. + hctsiz.b.pid = DWC_OTG_HC_PID_SETUP;
  98681. + DWC_WRITE_REG32(&hc_regs->hctsiz, hctsiz.d32);
  98682. +
  98683. + /* Set HCCHAR */
  98684. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  98685. + hcchar.b.eptype = DWC_OTG_EP_TYPE_CONTROL;
  98686. + hcchar.b.epdir = 0;
  98687. + hcchar.b.epnum = 0;
  98688. + hcchar.b.mps = 8;
  98689. + hcchar.b.chen = 1;
  98690. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  98691. +
  98692. + /* Fill FIFO with Setup data for Get Device Descriptor */
  98693. + data_fifo = (uint32_t *) ((char *)global_regs + 0x1000);
  98694. + DWC_WRITE_REG32(data_fifo++, 0x01000680);
  98695. + DWC_WRITE_REG32(data_fifo++, 0x00080000);
  98696. +
  98697. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  98698. +
  98699. + /* Wait for host channel interrupt */
  98700. + do {
  98701. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  98702. + } while (gintsts.b.hcintr == 0);
  98703. +
  98704. + /* Disable HCINTs */
  98705. + DWC_WRITE_REG32(&hc_regs->hcintmsk, 0x0000);
  98706. +
  98707. + /* Disable HAINTs */
  98708. + DWC_WRITE_REG32(&hc_global_regs->haintmsk, 0x0000);
  98709. +
  98710. + /* Read HAINT */
  98711. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  98712. +
  98713. + /* Read HCINT */
  98714. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  98715. +
  98716. + /* Read HCCHAR */
  98717. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  98718. +
  98719. + /* Clear HCINT */
  98720. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  98721. +
  98722. + /* Clear HAINT */
  98723. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  98724. +
  98725. + /* Clear GINTSTS */
  98726. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  98727. +
  98728. + /* Read GINTSTS */
  98729. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  98730. +}
  98731. +
  98732. +static void do_in_ack(void)
  98733. +{
  98734. + gintsts_data_t gintsts;
  98735. + hctsiz_data_t hctsiz;
  98736. + hcchar_data_t hcchar;
  98737. + haint_data_t haint;
  98738. + hcint_data_t hcint;
  98739. + host_grxsts_data_t grxsts;
  98740. +
  98741. + /* Enable HAINTs */
  98742. + DWC_WRITE_REG32(&hc_global_regs->haintmsk, 0x0001);
  98743. +
  98744. + /* Enable HCINTs */
  98745. + DWC_WRITE_REG32(&hc_regs->hcintmsk, 0x04a3);
  98746. +
  98747. + /* Read GINTSTS */
  98748. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  98749. +
  98750. + /* Read HAINT */
  98751. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  98752. +
  98753. + /* Read HCINT */
  98754. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  98755. +
  98756. + /* Read HCCHAR */
  98757. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  98758. +
  98759. + /* Clear HCINT */
  98760. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  98761. +
  98762. + /* Clear HAINT */
  98763. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  98764. +
  98765. + /* Clear GINTSTS */
  98766. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  98767. +
  98768. + /* Read GINTSTS */
  98769. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  98770. +
  98771. + /*
  98772. + * Receive Control In packet
  98773. + */
  98774. +
  98775. + /* Make sure channel is disabled */
  98776. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  98777. + if (hcchar.b.chen) {
  98778. + hcchar.b.chdis = 1;
  98779. + hcchar.b.chen = 1;
  98780. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  98781. + //sleep(1);
  98782. + dwc_mdelay(1000);
  98783. +
  98784. + /* Read GINTSTS */
  98785. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  98786. +
  98787. + /* Read HAINT */
  98788. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  98789. +
  98790. + /* Read HCINT */
  98791. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  98792. +
  98793. + /* Read HCCHAR */
  98794. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  98795. +
  98796. + /* Clear HCINT */
  98797. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  98798. +
  98799. + /* Clear HAINT */
  98800. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  98801. +
  98802. + /* Clear GINTSTS */
  98803. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  98804. +
  98805. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  98806. + }
  98807. +
  98808. + /* Set HCTSIZ */
  98809. + hctsiz.d32 = 0;
  98810. + hctsiz.b.xfersize = 8;
  98811. + hctsiz.b.pktcnt = 1;
  98812. + hctsiz.b.pid = DWC_OTG_HC_PID_DATA1;
  98813. + DWC_WRITE_REG32(&hc_regs->hctsiz, hctsiz.d32);
  98814. +
  98815. + /* Set HCCHAR */
  98816. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  98817. + hcchar.b.eptype = DWC_OTG_EP_TYPE_CONTROL;
  98818. + hcchar.b.epdir = 1;
  98819. + hcchar.b.epnum = 0;
  98820. + hcchar.b.mps = 8;
  98821. + hcchar.b.chen = 1;
  98822. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  98823. +
  98824. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  98825. +
  98826. + /* Wait for receive status queue interrupt */
  98827. + do {
  98828. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  98829. + } while (gintsts.b.rxstsqlvl == 0);
  98830. +
  98831. + /* Read RXSTS */
  98832. + grxsts.d32 = DWC_READ_REG32(&global_regs->grxstsp);
  98833. +
  98834. + /* Clear RXSTSQLVL in GINTSTS */
  98835. + gintsts.d32 = 0;
  98836. + gintsts.b.rxstsqlvl = 1;
  98837. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  98838. +
  98839. + switch (grxsts.b.pktsts) {
  98840. + case DWC_GRXSTS_PKTSTS_IN:
  98841. + /* Read the data into the host buffer */
  98842. + if (grxsts.b.bcnt > 0) {
  98843. + int i;
  98844. + int word_count = (grxsts.b.bcnt + 3) / 4;
  98845. +
  98846. + data_fifo = (uint32_t *) ((char *)global_regs + 0x1000);
  98847. +
  98848. + for (i = 0; i < word_count; i++) {
  98849. + (void)DWC_READ_REG32(data_fifo++);
  98850. + }
  98851. + }
  98852. + break;
  98853. +
  98854. + default:
  98855. + break;
  98856. + }
  98857. +
  98858. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  98859. +
  98860. + /* Wait for receive status queue interrupt */
  98861. + do {
  98862. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  98863. + } while (gintsts.b.rxstsqlvl == 0);
  98864. +
  98865. + /* Read RXSTS */
  98866. + grxsts.d32 = DWC_READ_REG32(&global_regs->grxstsp);
  98867. +
  98868. + /* Clear RXSTSQLVL in GINTSTS */
  98869. + gintsts.d32 = 0;
  98870. + gintsts.b.rxstsqlvl = 1;
  98871. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  98872. +
  98873. + switch (grxsts.b.pktsts) {
  98874. + case DWC_GRXSTS_PKTSTS_IN_XFER_COMP:
  98875. + break;
  98876. +
  98877. + default:
  98878. + break;
  98879. + }
  98880. +
  98881. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  98882. +
  98883. + /* Wait for host channel interrupt */
  98884. + do {
  98885. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  98886. + } while (gintsts.b.hcintr == 0);
  98887. +
  98888. + /* Read HAINT */
  98889. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  98890. +
  98891. + /* Read HCINT */
  98892. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  98893. +
  98894. + /* Read HCCHAR */
  98895. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  98896. +
  98897. + /* Clear HCINT */
  98898. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  98899. +
  98900. + /* Clear HAINT */
  98901. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  98902. +
  98903. + /* Clear GINTSTS */
  98904. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  98905. +
  98906. + /* Read GINTSTS */
  98907. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  98908. +
  98909. +// usleep(100000);
  98910. +// mdelay(100);
  98911. + dwc_mdelay(1);
  98912. +
  98913. + /*
  98914. + * Send handshake packet
  98915. + */
  98916. +
  98917. + /* Read HAINT */
  98918. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  98919. +
  98920. + /* Read HCINT */
  98921. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  98922. +
  98923. + /* Read HCCHAR */
  98924. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  98925. +
  98926. + /* Clear HCINT */
  98927. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  98928. +
  98929. + /* Clear HAINT */
  98930. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  98931. +
  98932. + /* Clear GINTSTS */
  98933. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  98934. +
  98935. + /* Read GINTSTS */
  98936. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  98937. +
  98938. + /* Make sure channel is disabled */
  98939. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  98940. + if (hcchar.b.chen) {
  98941. + hcchar.b.chdis = 1;
  98942. + hcchar.b.chen = 1;
  98943. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  98944. + //sleep(1);
  98945. + dwc_mdelay(1000);
  98946. +
  98947. + /* Read GINTSTS */
  98948. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  98949. +
  98950. + /* Read HAINT */
  98951. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  98952. +
  98953. + /* Read HCINT */
  98954. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  98955. +
  98956. + /* Read HCCHAR */
  98957. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  98958. +
  98959. + /* Clear HCINT */
  98960. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  98961. +
  98962. + /* Clear HAINT */
  98963. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  98964. +
  98965. + /* Clear GINTSTS */
  98966. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  98967. +
  98968. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  98969. + }
  98970. +
  98971. + /* Set HCTSIZ */
  98972. + hctsiz.d32 = 0;
  98973. + hctsiz.b.xfersize = 0;
  98974. + hctsiz.b.pktcnt = 1;
  98975. + hctsiz.b.pid = DWC_OTG_HC_PID_DATA1;
  98976. + DWC_WRITE_REG32(&hc_regs->hctsiz, hctsiz.d32);
  98977. +
  98978. + /* Set HCCHAR */
  98979. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  98980. + hcchar.b.eptype = DWC_OTG_EP_TYPE_CONTROL;
  98981. + hcchar.b.epdir = 0;
  98982. + hcchar.b.epnum = 0;
  98983. + hcchar.b.mps = 8;
  98984. + hcchar.b.chen = 1;
  98985. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  98986. +
  98987. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  98988. +
  98989. + /* Wait for host channel interrupt */
  98990. + do {
  98991. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  98992. + } while (gintsts.b.hcintr == 0);
  98993. +
  98994. + /* Disable HCINTs */
  98995. + DWC_WRITE_REG32(&hc_regs->hcintmsk, 0x0000);
  98996. +
  98997. + /* Disable HAINTs */
  98998. + DWC_WRITE_REG32(&hc_global_regs->haintmsk, 0x0000);
  98999. +
  99000. + /* Read HAINT */
  99001. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  99002. +
  99003. + /* Read HCINT */
  99004. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  99005. +
  99006. + /* Read HCCHAR */
  99007. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  99008. +
  99009. + /* Clear HCINT */
  99010. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  99011. +
  99012. + /* Clear HAINT */
  99013. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  99014. +
  99015. + /* Clear GINTSTS */
  99016. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  99017. +
  99018. + /* Read GINTSTS */
  99019. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  99020. +}
  99021. +#endif
  99022. +
  99023. +/** Handles hub class-specific requests. */
  99024. +int dwc_otg_hcd_hub_control(dwc_otg_hcd_t * dwc_otg_hcd,
  99025. + uint16_t typeReq,
  99026. + uint16_t wValue,
  99027. + uint16_t wIndex, uint8_t * buf, uint16_t wLength)
  99028. +{
  99029. + int retval = 0;
  99030. +
  99031. + dwc_otg_core_if_t *core_if = dwc_otg_hcd->core_if;
  99032. + usb_hub_descriptor_t *hub_desc;
  99033. + hprt0_data_t hprt0 = {.d32 = 0 };
  99034. +
  99035. + uint32_t port_status;
  99036. +
  99037. + switch (typeReq) {
  99038. + case UCR_CLEAR_HUB_FEATURE:
  99039. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  99040. + "ClearHubFeature 0x%x\n", wValue);
  99041. + switch (wValue) {
  99042. + case UHF_C_HUB_LOCAL_POWER:
  99043. + case UHF_C_HUB_OVER_CURRENT:
  99044. + /* Nothing required here */
  99045. + break;
  99046. + default:
  99047. + retval = -DWC_E_INVALID;
  99048. + DWC_ERROR("DWC OTG HCD - "
  99049. + "ClearHubFeature request %xh unknown\n",
  99050. + wValue);
  99051. + }
  99052. + break;
  99053. + case UCR_CLEAR_PORT_FEATURE:
  99054. +#ifdef CONFIG_USB_DWC_OTG_LPM
  99055. + if (wValue != UHF_PORT_L1)
  99056. +#endif
  99057. + if (!wIndex || wIndex > 1)
  99058. + goto error;
  99059. +
  99060. + switch (wValue) {
  99061. + case UHF_PORT_ENABLE:
  99062. + DWC_DEBUGPL(DBG_ANY, "DWC OTG HCD HUB CONTROL - "
  99063. + "ClearPortFeature USB_PORT_FEAT_ENABLE\n");
  99064. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  99065. + hprt0.b.prtena = 1;
  99066. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  99067. + break;
  99068. + case UHF_PORT_SUSPEND:
  99069. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  99070. + "ClearPortFeature USB_PORT_FEAT_SUSPEND\n");
  99071. +
  99072. + if (core_if->power_down == 2) {
  99073. + dwc_otg_host_hibernation_restore(core_if, 0, 0);
  99074. + } else {
  99075. + DWC_WRITE_REG32(core_if->pcgcctl, 0);
  99076. + dwc_mdelay(5);
  99077. +
  99078. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  99079. + hprt0.b.prtres = 1;
  99080. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  99081. + hprt0.b.prtsusp = 0;
  99082. + /* Clear Resume bit */
  99083. + dwc_mdelay(100);
  99084. + hprt0.b.prtres = 0;
  99085. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  99086. + }
  99087. + break;
  99088. +#ifdef CONFIG_USB_DWC_OTG_LPM
  99089. + case UHF_PORT_L1:
  99090. + {
  99091. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  99092. + glpmcfg_data_t lpmcfg = {.d32 = 0 };
  99093. +
  99094. + lpmcfg.d32 =
  99095. + DWC_READ_REG32(&core_if->
  99096. + core_global_regs->glpmcfg);
  99097. + lpmcfg.b.en_utmi_sleep = 0;
  99098. + lpmcfg.b.hird_thres &= (~(1 << 4));
  99099. + lpmcfg.b.prt_sleep_sts = 1;
  99100. + DWC_WRITE_REG32(&core_if->
  99101. + core_global_regs->glpmcfg,
  99102. + lpmcfg.d32);
  99103. +
  99104. + /* Clear Enbl_L1Gating bit. */
  99105. + pcgcctl.b.enbl_sleep_gating = 1;
  99106. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32,
  99107. + 0);
  99108. +
  99109. + dwc_mdelay(5);
  99110. +
  99111. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  99112. + hprt0.b.prtres = 1;
  99113. + DWC_WRITE_REG32(core_if->host_if->hprt0,
  99114. + hprt0.d32);
  99115. + /* This bit will be cleared in wakeup interrupt handle */
  99116. + break;
  99117. + }
  99118. +#endif
  99119. + case UHF_PORT_POWER:
  99120. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  99121. + "ClearPortFeature USB_PORT_FEAT_POWER\n");
  99122. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  99123. + hprt0.b.prtpwr = 0;
  99124. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  99125. + break;
  99126. + case UHF_PORT_INDICATOR:
  99127. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  99128. + "ClearPortFeature USB_PORT_FEAT_INDICATOR\n");
  99129. + /* Port inidicator not supported */
  99130. + break;
  99131. + case UHF_C_PORT_CONNECTION:
  99132. + /* Clears drivers internal connect status change
  99133. + * flag */
  99134. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  99135. + "ClearPortFeature USB_PORT_FEAT_C_CONNECTION\n");
  99136. + dwc_otg_hcd->flags.b.port_connect_status_change = 0;
  99137. + break;
  99138. + case UHF_C_PORT_RESET:
  99139. + /* Clears the driver's internal Port Reset Change
  99140. + * flag */
  99141. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  99142. + "ClearPortFeature USB_PORT_FEAT_C_RESET\n");
  99143. + dwc_otg_hcd->flags.b.port_reset_change = 0;
  99144. + break;
  99145. + case UHF_C_PORT_ENABLE:
  99146. + /* Clears the driver's internal Port
  99147. + * Enable/Disable Change flag */
  99148. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  99149. + "ClearPortFeature USB_PORT_FEAT_C_ENABLE\n");
  99150. + dwc_otg_hcd->flags.b.port_enable_change = 0;
  99151. + break;
  99152. + case UHF_C_PORT_SUSPEND:
  99153. + /* Clears the driver's internal Port Suspend
  99154. + * Change flag, which is set when resume signaling on
  99155. + * the host port is complete */
  99156. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  99157. + "ClearPortFeature USB_PORT_FEAT_C_SUSPEND\n");
  99158. + dwc_otg_hcd->flags.b.port_suspend_change = 0;
  99159. + break;
  99160. +#ifdef CONFIG_USB_DWC_OTG_LPM
  99161. + case UHF_C_PORT_L1:
  99162. + dwc_otg_hcd->flags.b.port_l1_change = 0;
  99163. + break;
  99164. +#endif
  99165. + case UHF_C_PORT_OVER_CURRENT:
  99166. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  99167. + "ClearPortFeature USB_PORT_FEAT_C_OVER_CURRENT\n");
  99168. + dwc_otg_hcd->flags.b.port_over_current_change = 0;
  99169. + break;
  99170. + default:
  99171. + retval = -DWC_E_INVALID;
  99172. + DWC_ERROR("DWC OTG HCD - "
  99173. + "ClearPortFeature request %xh "
  99174. + "unknown or unsupported\n", wValue);
  99175. + }
  99176. + break;
  99177. + case UCR_GET_HUB_DESCRIPTOR:
  99178. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  99179. + "GetHubDescriptor\n");
  99180. + hub_desc = (usb_hub_descriptor_t *) buf;
  99181. + hub_desc->bDescLength = 9;
  99182. + hub_desc->bDescriptorType = 0x29;
  99183. + hub_desc->bNbrPorts = 1;
  99184. + USETW(hub_desc->wHubCharacteristics, 0x08);
  99185. + hub_desc->bPwrOn2PwrGood = 1;
  99186. + hub_desc->bHubContrCurrent = 0;
  99187. + hub_desc->DeviceRemovable[0] = 0;
  99188. + hub_desc->DeviceRemovable[1] = 0xff;
  99189. + break;
  99190. + case UCR_GET_HUB_STATUS:
  99191. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  99192. + "GetHubStatus\n");
  99193. + DWC_MEMSET(buf, 0, 4);
  99194. + break;
  99195. + case UCR_GET_PORT_STATUS:
  99196. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  99197. + "GetPortStatus wIndex = 0x%04x FLAGS=0x%08x\n",
  99198. + wIndex, dwc_otg_hcd->flags.d32);
  99199. + if (!wIndex || wIndex > 1)
  99200. + goto error;
  99201. +
  99202. + port_status = 0;
  99203. +
  99204. + if (dwc_otg_hcd->flags.b.port_connect_status_change)
  99205. + port_status |= (1 << UHF_C_PORT_CONNECTION);
  99206. +
  99207. + if (dwc_otg_hcd->flags.b.port_enable_change)
  99208. + port_status |= (1 << UHF_C_PORT_ENABLE);
  99209. +
  99210. + if (dwc_otg_hcd->flags.b.port_suspend_change)
  99211. + port_status |= (1 << UHF_C_PORT_SUSPEND);
  99212. +
  99213. + if (dwc_otg_hcd->flags.b.port_l1_change)
  99214. + port_status |= (1 << UHF_C_PORT_L1);
  99215. +
  99216. + if (dwc_otg_hcd->flags.b.port_reset_change) {
  99217. + port_status |= (1 << UHF_C_PORT_RESET);
  99218. + }
  99219. +
  99220. + if (dwc_otg_hcd->flags.b.port_over_current_change) {
  99221. + DWC_WARN("Overcurrent change detected\n");
  99222. + port_status |= (1 << UHF_C_PORT_OVER_CURRENT);
  99223. + }
  99224. +
  99225. + if (!dwc_otg_hcd->flags.b.port_connect_status) {
  99226. + /*
  99227. + * The port is disconnected, which means the core is
  99228. + * either in device mode or it soon will be. Just
  99229. + * return 0's for the remainder of the port status
  99230. + * since the port register can't be read if the core
  99231. + * is in device mode.
  99232. + */
  99233. + *((__le32 *) buf) = dwc_cpu_to_le32(&port_status);
  99234. + break;
  99235. + }
  99236. +
  99237. + hprt0.d32 = DWC_READ_REG32(core_if->host_if->hprt0);
  99238. + DWC_DEBUGPL(DBG_HCDV, " HPRT0: 0x%08x\n", hprt0.d32);
  99239. +
  99240. + if (hprt0.b.prtconnsts)
  99241. + port_status |= (1 << UHF_PORT_CONNECTION);
  99242. +
  99243. + if (hprt0.b.prtena)
  99244. + port_status |= (1 << UHF_PORT_ENABLE);
  99245. +
  99246. + if (hprt0.b.prtsusp)
  99247. + port_status |= (1 << UHF_PORT_SUSPEND);
  99248. +
  99249. + if (hprt0.b.prtovrcurract)
  99250. + port_status |= (1 << UHF_PORT_OVER_CURRENT);
  99251. +
  99252. + if (hprt0.b.prtrst)
  99253. + port_status |= (1 << UHF_PORT_RESET);
  99254. +
  99255. + if (hprt0.b.prtpwr)
  99256. + port_status |= (1 << UHF_PORT_POWER);
  99257. +
  99258. + if (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_HIGH_SPEED)
  99259. + port_status |= (1 << UHF_PORT_HIGH_SPEED);
  99260. + else if (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_LOW_SPEED)
  99261. + port_status |= (1 << UHF_PORT_LOW_SPEED);
  99262. +
  99263. + if (hprt0.b.prttstctl)
  99264. + port_status |= (1 << UHF_PORT_TEST);
  99265. + if (dwc_otg_get_lpm_portsleepstatus(dwc_otg_hcd->core_if)) {
  99266. + port_status |= (1 << UHF_PORT_L1);
  99267. + }
  99268. + /*
  99269. + For Synopsys HW emulation of Power down wkup_control asserts the
  99270. + hreset_n and prst_n on suspned. This causes the HPRT0 to be zero.
  99271. + We intentionally tell the software that port is in L2Suspend state.
  99272. + Only for STE.
  99273. + */
  99274. + if ((core_if->power_down == 2)
  99275. + && (core_if->hibernation_suspend == 1)) {
  99276. + port_status |= (1 << UHF_PORT_SUSPEND);
  99277. + }
  99278. + /* USB_PORT_FEAT_INDICATOR unsupported always 0 */
  99279. +
  99280. + *((__le32 *) buf) = dwc_cpu_to_le32(&port_status);
  99281. +
  99282. + break;
  99283. + case UCR_SET_HUB_FEATURE:
  99284. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  99285. + "SetHubFeature\n");
  99286. + /* No HUB features supported */
  99287. + break;
  99288. + case UCR_SET_PORT_FEATURE:
  99289. + if (wValue != UHF_PORT_TEST && (!wIndex || wIndex > 1))
  99290. + goto error;
  99291. +
  99292. + if (!dwc_otg_hcd->flags.b.port_connect_status) {
  99293. + /*
  99294. + * The port is disconnected, which means the core is
  99295. + * either in device mode or it soon will be. Just
  99296. + * return without doing anything since the port
  99297. + * register can't be written if the core is in device
  99298. + * mode.
  99299. + */
  99300. + break;
  99301. + }
  99302. +
  99303. + switch (wValue) {
  99304. + case UHF_PORT_SUSPEND:
  99305. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  99306. + "SetPortFeature - USB_PORT_FEAT_SUSPEND\n");
  99307. + if (dwc_otg_hcd_otg_port(dwc_otg_hcd) != wIndex) {
  99308. + goto error;
  99309. + }
  99310. + if (core_if->power_down == 2) {
  99311. + int timeout = 300;
  99312. + dwc_irqflags_t flags;
  99313. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  99314. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  99315. + gusbcfg_data_t gusbcfg = {.d32 = 0 };
  99316. +#ifdef DWC_DEV_SRPCAP
  99317. + int32_t otg_cap_param = core_if->core_params->otg_cap;
  99318. +#endif
  99319. + DWC_PRINTF("Preparing for complete power-off\n");
  99320. +
  99321. + /* Save registers before hibernation */
  99322. + dwc_otg_save_global_regs(core_if);
  99323. + dwc_otg_save_host_regs(core_if);
  99324. +
  99325. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  99326. + hprt0.b.prtsusp = 1;
  99327. + hprt0.b.prtena = 0;
  99328. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  99329. + /* Spin hprt0.b.prtsusp to became 1 */
  99330. + do {
  99331. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  99332. + if (hprt0.b.prtsusp) {
  99333. + break;
  99334. + }
  99335. + dwc_mdelay(1);
  99336. + } while (--timeout);
  99337. + if (!timeout) {
  99338. + DWC_WARN("Suspend wasn't genereted\n");
  99339. + }
  99340. + dwc_udelay(10);
  99341. +
  99342. + /*
  99343. + * We need to disable interrupts to prevent servicing of any IRQ
  99344. + * during going to hibernation
  99345. + */
  99346. + DWC_SPINLOCK_IRQSAVE(dwc_otg_hcd->lock, &flags);
  99347. + core_if->lx_state = DWC_OTG_L2;
  99348. +#ifdef DWC_DEV_SRPCAP
  99349. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  99350. + hprt0.b.prtpwr = 0;
  99351. + hprt0.b.prtena = 0;
  99352. + DWC_WRITE_REG32(core_if->host_if->hprt0,
  99353. + hprt0.d32);
  99354. +#endif
  99355. + gusbcfg.d32 =
  99356. + DWC_READ_REG32(&core_if->core_global_regs->
  99357. + gusbcfg);
  99358. + if (gusbcfg.b.ulpi_utmi_sel == 1) {
  99359. + /* ULPI interface */
  99360. + /* Suspend the Phy Clock */
  99361. + pcgcctl.d32 = 0;
  99362. + pcgcctl.b.stoppclk = 1;
  99363. + DWC_MODIFY_REG32(core_if->pcgcctl, 0,
  99364. + pcgcctl.d32);
  99365. + dwc_udelay(10);
  99366. + gpwrdn.b.pmuactv = 1;
  99367. + DWC_MODIFY_REG32(&core_if->
  99368. + core_global_regs->
  99369. + gpwrdn, 0, gpwrdn.d32);
  99370. + } else {
  99371. + /* UTMI+ Interface */
  99372. + gpwrdn.b.pmuactv = 1;
  99373. + DWC_MODIFY_REG32(&core_if->
  99374. + core_global_regs->
  99375. + gpwrdn, 0, gpwrdn.d32);
  99376. + dwc_udelay(10);
  99377. + pcgcctl.b.stoppclk = 1;
  99378. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, pcgcctl.d32);
  99379. + dwc_udelay(10);
  99380. + }
  99381. +#ifdef DWC_DEV_SRPCAP
  99382. + gpwrdn.d32 = 0;
  99383. + gpwrdn.b.dis_vbus = 1;
  99384. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  99385. + gpwrdn, 0, gpwrdn.d32);
  99386. +#endif
  99387. + gpwrdn.d32 = 0;
  99388. + gpwrdn.b.pmuintsel = 1;
  99389. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  99390. + gpwrdn, 0, gpwrdn.d32);
  99391. + dwc_udelay(10);
  99392. +
  99393. + gpwrdn.d32 = 0;
  99394. +#ifdef DWC_DEV_SRPCAP
  99395. + gpwrdn.b.srp_det_msk = 1;
  99396. +#endif
  99397. + gpwrdn.b.disconn_det_msk = 1;
  99398. + gpwrdn.b.lnstchng_msk = 1;
  99399. + gpwrdn.b.sts_chngint_msk = 1;
  99400. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  99401. + gpwrdn, 0, gpwrdn.d32);
  99402. + dwc_udelay(10);
  99403. +
  99404. + /* Enable Power Down Clamp and all interrupts in GPWRDN */
  99405. + gpwrdn.d32 = 0;
  99406. + gpwrdn.b.pwrdnclmp = 1;
  99407. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  99408. + gpwrdn, 0, gpwrdn.d32);
  99409. + dwc_udelay(10);
  99410. +
  99411. + /* Switch off VDD */
  99412. + gpwrdn.d32 = 0;
  99413. + gpwrdn.b.pwrdnswtch = 1;
  99414. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  99415. + gpwrdn, 0, gpwrdn.d32);
  99416. +
  99417. +#ifdef DWC_DEV_SRPCAP
  99418. + if (otg_cap_param == DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE)
  99419. + {
  99420. + core_if->pwron_timer_started = 1;
  99421. + DWC_TIMER_SCHEDULE(core_if->pwron_timer, 6000 /* 6 secs */ );
  99422. + }
  99423. +#endif
  99424. + /* Save gpwrdn register for further usage if stschng interrupt */
  99425. + core_if->gr_backup->gpwrdn_local =
  99426. + DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  99427. +
  99428. + /* Set flag to indicate that we are in hibernation */
  99429. + core_if->hibernation_suspend = 1;
  99430. + DWC_SPINUNLOCK_IRQRESTORE(dwc_otg_hcd->lock,flags);
  99431. +
  99432. + DWC_PRINTF("Host hibernation completed\n");
  99433. + // Exit from case statement
  99434. + break;
  99435. +
  99436. + }
  99437. + if (dwc_otg_hcd_otg_port(dwc_otg_hcd) == wIndex &&
  99438. + dwc_otg_hcd->fops->get_b_hnp_enable(dwc_otg_hcd)) {
  99439. + gotgctl_data_t gotgctl = {.d32 = 0 };
  99440. + gotgctl.b.hstsethnpen = 1;
  99441. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  99442. + gotgctl, 0, gotgctl.d32);
  99443. + core_if->op_state = A_SUSPEND;
  99444. + }
  99445. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  99446. + hprt0.b.prtsusp = 1;
  99447. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  99448. + {
  99449. + dwc_irqflags_t flags;
  99450. + /* Update lx_state */
  99451. + DWC_SPINLOCK_IRQSAVE(dwc_otg_hcd->lock, &flags);
  99452. + core_if->lx_state = DWC_OTG_L2;
  99453. + DWC_SPINUNLOCK_IRQRESTORE(dwc_otg_hcd->lock, flags);
  99454. + }
  99455. + /* Suspend the Phy Clock */
  99456. + {
  99457. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  99458. + pcgcctl.b.stoppclk = 1;
  99459. + DWC_MODIFY_REG32(core_if->pcgcctl, 0,
  99460. + pcgcctl.d32);
  99461. + dwc_udelay(10);
  99462. + }
  99463. +
  99464. + /* For HNP the bus must be suspended for at least 200ms. */
  99465. + if (dwc_otg_hcd->fops->get_b_hnp_enable(dwc_otg_hcd)) {
  99466. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  99467. + pcgcctl.b.stoppclk = 1;
  99468. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  99469. + dwc_mdelay(200);
  99470. + }
  99471. +
  99472. + /** @todo - check how sw can wait for 1 sec to check asesvld??? */
  99473. +#if 0 //vahrama !!!!!!!!!!!!!!!!!!
  99474. + if (core_if->adp_enable) {
  99475. + gotgctl_data_t gotgctl = {.d32 = 0 };
  99476. + gpwrdn_data_t gpwrdn;
  99477. +
  99478. + while (gotgctl.b.asesvld == 1) {
  99479. + gotgctl.d32 =
  99480. + DWC_READ_REG32(&core_if->
  99481. + core_global_regs->
  99482. + gotgctl);
  99483. + dwc_mdelay(100);
  99484. + }
  99485. +
  99486. + /* Enable Power Down Logic */
  99487. + gpwrdn.d32 = 0;
  99488. + gpwrdn.b.pmuactv = 1;
  99489. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  99490. + gpwrdn, 0, gpwrdn.d32);
  99491. +
  99492. + /* Unmask SRP detected interrupt from Power Down Logic */
  99493. + gpwrdn.d32 = 0;
  99494. + gpwrdn.b.srp_det_msk = 1;
  99495. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  99496. + gpwrdn, 0, gpwrdn.d32);
  99497. +
  99498. + dwc_otg_adp_probe_start(core_if);
  99499. + }
  99500. +#endif
  99501. + break;
  99502. + case UHF_PORT_POWER:
  99503. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  99504. + "SetPortFeature - USB_PORT_FEAT_POWER\n");
  99505. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  99506. + hprt0.b.prtpwr = 1;
  99507. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  99508. + break;
  99509. + case UHF_PORT_RESET:
  99510. + if ((core_if->power_down == 2)
  99511. + && (core_if->hibernation_suspend == 1)) {
  99512. + /* If we are going to exit from Hibernated
  99513. + * state via USB RESET.
  99514. + */
  99515. + dwc_otg_host_hibernation_restore(core_if, 0, 1);
  99516. + } else {
  99517. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  99518. +
  99519. + DWC_DEBUGPL(DBG_HCD,
  99520. + "DWC OTG HCD HUB CONTROL - "
  99521. + "SetPortFeature - USB_PORT_FEAT_RESET\n");
  99522. + {
  99523. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  99524. + pcgcctl.b.enbl_sleep_gating = 1;
  99525. + pcgcctl.b.stoppclk = 1;
  99526. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  99527. + DWC_WRITE_REG32(core_if->pcgcctl, 0);
  99528. + }
  99529. +#ifdef CONFIG_USB_DWC_OTG_LPM
  99530. + {
  99531. + glpmcfg_data_t lpmcfg;
  99532. + lpmcfg.d32 =
  99533. + DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  99534. + if (lpmcfg.b.prt_sleep_sts) {
  99535. + lpmcfg.b.en_utmi_sleep = 0;
  99536. + lpmcfg.b.hird_thres &= (~(1 << 4));
  99537. + DWC_WRITE_REG32
  99538. + (&core_if->core_global_regs->glpmcfg,
  99539. + lpmcfg.d32);
  99540. + dwc_mdelay(1);
  99541. + }
  99542. + }
  99543. +#endif
  99544. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  99545. + /* Clear suspend bit if resetting from suspended state. */
  99546. + hprt0.b.prtsusp = 0;
  99547. + /* When B-Host the Port reset bit is set in
  99548. + * the Start HCD Callback function, so that
  99549. + * the reset is started within 1ms of the HNP
  99550. + * success interrupt. */
  99551. + if (!dwc_otg_hcd_is_b_host(dwc_otg_hcd)) {
  99552. + hprt0.b.prtpwr = 1;
  99553. + hprt0.b.prtrst = 1;
  99554. + DWC_PRINTF("Indeed it is in host mode hprt0 = %08x\n",hprt0.d32);
  99555. + DWC_WRITE_REG32(core_if->host_if->hprt0,
  99556. + hprt0.d32);
  99557. + }
  99558. + /* Clear reset bit in 10ms (FS/LS) or 50ms (HS) */
  99559. + dwc_mdelay(60);
  99560. + hprt0.b.prtrst = 0;
  99561. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  99562. + core_if->lx_state = DWC_OTG_L0; /* Now back to the on state */
  99563. + }
  99564. + break;
  99565. +#ifdef DWC_HS_ELECT_TST
  99566. + case UHF_PORT_TEST:
  99567. + {
  99568. + uint32_t t;
  99569. + gintmsk_data_t gintmsk;
  99570. +
  99571. + t = (wIndex >> 8); /* MSB wIndex USB */
  99572. + DWC_DEBUGPL(DBG_HCD,
  99573. + "DWC OTG HCD HUB CONTROL - "
  99574. + "SetPortFeature - USB_PORT_FEAT_TEST %d\n",
  99575. + t);
  99576. + DWC_WARN("USB_PORT_FEAT_TEST %d\n", t);
  99577. + if (t < 6) {
  99578. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  99579. + hprt0.b.prttstctl = t;
  99580. + DWC_WRITE_REG32(core_if->host_if->hprt0,
  99581. + hprt0.d32);
  99582. + } else {
  99583. + /* Setup global vars with reg addresses (quick and
  99584. + * dirty hack, should be cleaned up)
  99585. + */
  99586. + global_regs = core_if->core_global_regs;
  99587. + hc_global_regs =
  99588. + core_if->host_if->host_global_regs;
  99589. + hc_regs =
  99590. + (dwc_otg_hc_regs_t *) ((char *)
  99591. + global_regs +
  99592. + 0x500);
  99593. + data_fifo =
  99594. + (uint32_t *) ((char *)global_regs +
  99595. + 0x1000);
  99596. +
  99597. + if (t == 6) { /* HS_HOST_PORT_SUSPEND_RESUME */
  99598. + /* Save current interrupt mask */
  99599. + gintmsk.d32 =
  99600. + DWC_READ_REG32
  99601. + (&global_regs->gintmsk);
  99602. +
  99603. + /* Disable all interrupts while we muck with
  99604. + * the hardware directly
  99605. + */
  99606. + DWC_WRITE_REG32(&global_regs->gintmsk, 0);
  99607. +
  99608. + /* 15 second delay per the test spec */
  99609. + dwc_mdelay(15000);
  99610. +
  99611. + /* Drive suspend on the root port */
  99612. + hprt0.d32 =
  99613. + dwc_otg_read_hprt0(core_if);
  99614. + hprt0.b.prtsusp = 1;
  99615. + hprt0.b.prtres = 0;
  99616. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  99617. +
  99618. + /* 15 second delay per the test spec */
  99619. + dwc_mdelay(15000);
  99620. +
  99621. + /* Drive resume on the root port */
  99622. + hprt0.d32 =
  99623. + dwc_otg_read_hprt0(core_if);
  99624. + hprt0.b.prtsusp = 0;
  99625. + hprt0.b.prtres = 1;
  99626. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  99627. + dwc_mdelay(100);
  99628. +
  99629. + /* Clear the resume bit */
  99630. + hprt0.b.prtres = 0;
  99631. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  99632. +
  99633. + /* Restore interrupts */
  99634. + DWC_WRITE_REG32(&global_regs->gintmsk, gintmsk.d32);
  99635. + } else if (t == 7) { /* SINGLE_STEP_GET_DEVICE_DESCRIPTOR setup */
  99636. + /* Save current interrupt mask */
  99637. + gintmsk.d32 =
  99638. + DWC_READ_REG32
  99639. + (&global_regs->gintmsk);
  99640. +
  99641. + /* Disable all interrupts while we muck with
  99642. + * the hardware directly
  99643. + */
  99644. + DWC_WRITE_REG32(&global_regs->gintmsk, 0);
  99645. +
  99646. + /* 15 second delay per the test spec */
  99647. + dwc_mdelay(15000);
  99648. +
  99649. + /* Send the Setup packet */
  99650. + do_setup();
  99651. +
  99652. + /* 15 second delay so nothing else happens for awhile */
  99653. + dwc_mdelay(15000);
  99654. +
  99655. + /* Restore interrupts */
  99656. + DWC_WRITE_REG32(&global_regs->gintmsk, gintmsk.d32);
  99657. + } else if (t == 8) { /* SINGLE_STEP_GET_DEVICE_DESCRIPTOR execute */
  99658. + /* Save current interrupt mask */
  99659. + gintmsk.d32 =
  99660. + DWC_READ_REG32
  99661. + (&global_regs->gintmsk);
  99662. +
  99663. + /* Disable all interrupts while we muck with
  99664. + * the hardware directly
  99665. + */
  99666. + DWC_WRITE_REG32(&global_regs->gintmsk, 0);
  99667. +
  99668. + /* Send the Setup packet */
  99669. + do_setup();
  99670. +
  99671. + /* 15 second delay so nothing else happens for awhile */
  99672. + dwc_mdelay(15000);
  99673. +
  99674. + /* Send the In and Ack packets */
  99675. + do_in_ack();
  99676. +
  99677. + /* 15 second delay so nothing else happens for awhile */
  99678. + dwc_mdelay(15000);
  99679. +
  99680. + /* Restore interrupts */
  99681. + DWC_WRITE_REG32(&global_regs->gintmsk, gintmsk.d32);
  99682. + }
  99683. + }
  99684. + break;
  99685. + }
  99686. +#endif /* DWC_HS_ELECT_TST */
  99687. +
  99688. + case UHF_PORT_INDICATOR:
  99689. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  99690. + "SetPortFeature - USB_PORT_FEAT_INDICATOR\n");
  99691. + /* Not supported */
  99692. + break;
  99693. + default:
  99694. + retval = -DWC_E_INVALID;
  99695. + DWC_ERROR("DWC OTG HCD - "
  99696. + "SetPortFeature request %xh "
  99697. + "unknown or unsupported\n", wValue);
  99698. + break;
  99699. + }
  99700. + break;
  99701. +#ifdef CONFIG_USB_DWC_OTG_LPM
  99702. + case UCR_SET_AND_TEST_PORT_FEATURE:
  99703. + if (wValue != UHF_PORT_L1) {
  99704. + goto error;
  99705. + }
  99706. + {
  99707. + int portnum, hird, devaddr, remwake;
  99708. + glpmcfg_data_t lpmcfg;
  99709. + uint32_t time_usecs;
  99710. + gintsts_data_t gintsts;
  99711. + gintmsk_data_t gintmsk;
  99712. +
  99713. + if (!dwc_otg_get_param_lpm_enable(core_if)) {
  99714. + goto error;
  99715. + }
  99716. + if (wValue != UHF_PORT_L1 || wLength != 1) {
  99717. + goto error;
  99718. + }
  99719. + /* Check if the port currently is in SLEEP state */
  99720. + lpmcfg.d32 =
  99721. + DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  99722. + if (lpmcfg.b.prt_sleep_sts) {
  99723. + DWC_INFO("Port is already in sleep mode\n");
  99724. + buf[0] = 0; /* Return success */
  99725. + break;
  99726. + }
  99727. +
  99728. + portnum = wIndex & 0xf;
  99729. + hird = (wIndex >> 4) & 0xf;
  99730. + devaddr = (wIndex >> 8) & 0x7f;
  99731. + remwake = (wIndex >> 15);
  99732. +
  99733. + if (portnum != 1) {
  99734. + retval = -DWC_E_INVALID;
  99735. + DWC_WARN
  99736. + ("Wrong port number(%d) in SetandTestPortFeature request\n",
  99737. + portnum);
  99738. + break;
  99739. + }
  99740. +
  99741. + DWC_PRINTF
  99742. + ("SetandTestPortFeature request: portnum = %d, hird = %d, devaddr = %d, rewake = %d\n",
  99743. + portnum, hird, devaddr, remwake);
  99744. + /* Disable LPM interrupt */
  99745. + gintmsk.d32 = 0;
  99746. + gintmsk.b.lpmtranrcvd = 1;
  99747. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk,
  99748. + gintmsk.d32, 0);
  99749. +
  99750. + if (dwc_otg_hcd_send_lpm
  99751. + (dwc_otg_hcd, devaddr, hird, remwake)) {
  99752. + retval = -DWC_E_INVALID;
  99753. + break;
  99754. + }
  99755. +
  99756. + time_usecs = 10 * (lpmcfg.b.retry_count + 1);
  99757. + /* We will consider timeout if time_usecs microseconds pass,
  99758. + * and we don't receive LPM transaction status.
  99759. + * After receiving non-error responce(ACK/NYET/STALL) from device,
  99760. + * core will set lpmtranrcvd bit.
  99761. + */
  99762. + do {
  99763. + gintsts.d32 =
  99764. + DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  99765. + if (gintsts.b.lpmtranrcvd) {
  99766. + break;
  99767. + }
  99768. + dwc_udelay(1);
  99769. + } while (--time_usecs);
  99770. + /* lpm_int bit will be cleared in LPM interrupt handler */
  99771. +
  99772. + /* Now fill status
  99773. + * 0x00 - Success
  99774. + * 0x10 - NYET
  99775. + * 0x11 - Timeout
  99776. + */
  99777. + if (!gintsts.b.lpmtranrcvd) {
  99778. + buf[0] = 0x3; /* Completion code is Timeout */
  99779. + dwc_otg_hcd_free_hc_from_lpm(dwc_otg_hcd);
  99780. + } else {
  99781. + lpmcfg.d32 =
  99782. + DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  99783. + if (lpmcfg.b.lpm_resp == 0x3) {
  99784. + /* ACK responce from the device */
  99785. + buf[0] = 0x00; /* Success */
  99786. + } else if (lpmcfg.b.lpm_resp == 0x2) {
  99787. + /* NYET responce from the device */
  99788. + buf[0] = 0x2;
  99789. + } else {
  99790. + /* Otherwise responce with Timeout */
  99791. + buf[0] = 0x3;
  99792. + }
  99793. + }
  99794. + DWC_PRINTF("Device responce to LPM trans is %x\n",
  99795. + lpmcfg.b.lpm_resp);
  99796. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, 0,
  99797. + gintmsk.d32);
  99798. +
  99799. + break;
  99800. + }
  99801. +#endif /* CONFIG_USB_DWC_OTG_LPM */
  99802. + default:
  99803. +error:
  99804. + retval = -DWC_E_INVALID;
  99805. + DWC_WARN("DWC OTG HCD - "
  99806. + "Unknown hub control request type or invalid typeReq: %xh wIndex: %xh wValue: %xh\n",
  99807. + typeReq, wIndex, wValue);
  99808. + break;
  99809. + }
  99810. +
  99811. + return retval;
  99812. +}
  99813. +
  99814. +#ifdef CONFIG_USB_DWC_OTG_LPM
  99815. +/** Returns index of host channel to perform LPM transaction. */
  99816. +int dwc_otg_hcd_get_hc_for_lpm_tran(dwc_otg_hcd_t * hcd, uint8_t devaddr)
  99817. +{
  99818. + dwc_otg_core_if_t *core_if = hcd->core_if;
  99819. + dwc_hc_t *hc;
  99820. + hcchar_data_t hcchar;
  99821. + gintmsk_data_t gintmsk = {.d32 = 0 };
  99822. +
  99823. + if (DWC_CIRCLEQ_EMPTY(&hcd->free_hc_list)) {
  99824. + DWC_PRINTF("No free channel to select for LPM transaction\n");
  99825. + return -1;
  99826. + }
  99827. +
  99828. + hc = DWC_CIRCLEQ_FIRST(&hcd->free_hc_list);
  99829. +
  99830. + /* Mask host channel interrupts. */
  99831. + gintmsk.b.hcintr = 1;
  99832. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, gintmsk.d32, 0);
  99833. +
  99834. + /* Fill fields that core needs for LPM transaction */
  99835. + hcchar.b.devaddr = devaddr;
  99836. + hcchar.b.epnum = 0;
  99837. + hcchar.b.eptype = DWC_OTG_EP_TYPE_CONTROL;
  99838. + hcchar.b.mps = 64;
  99839. + hcchar.b.lspddev = (hc->speed == DWC_OTG_EP_SPEED_LOW);
  99840. + hcchar.b.epdir = 0; /* OUT */
  99841. + DWC_WRITE_REG32(&core_if->host_if->hc_regs[hc->hc_num]->hcchar,
  99842. + hcchar.d32);
  99843. +
  99844. + /* Remove the host channel from the free list. */
  99845. + DWC_CIRCLEQ_REMOVE_INIT(&hcd->free_hc_list, hc, hc_list_entry);
  99846. +
  99847. + DWC_PRINTF("hcnum = %d devaddr = %d\n", hc->hc_num, devaddr);
  99848. +
  99849. + return hc->hc_num;
  99850. +}
  99851. +
  99852. +/** Release hc after performing LPM transaction */
  99853. +void dwc_otg_hcd_free_hc_from_lpm(dwc_otg_hcd_t * hcd)
  99854. +{
  99855. + dwc_hc_t *hc;
  99856. + glpmcfg_data_t lpmcfg;
  99857. + uint8_t hc_num;
  99858. +
  99859. + lpmcfg.d32 = DWC_READ_REG32(&hcd->core_if->core_global_regs->glpmcfg);
  99860. + hc_num = lpmcfg.b.lpm_chan_index;
  99861. +
  99862. + hc = hcd->hc_ptr_array[hc_num];
  99863. +
  99864. + DWC_PRINTF("Freeing channel %d after LPM\n", hc_num);
  99865. + /* Return host channel to free list */
  99866. + DWC_CIRCLEQ_INSERT_TAIL(&hcd->free_hc_list, hc, hc_list_entry);
  99867. +}
  99868. +
  99869. +int dwc_otg_hcd_send_lpm(dwc_otg_hcd_t * hcd, uint8_t devaddr, uint8_t hird,
  99870. + uint8_t bRemoteWake)
  99871. +{
  99872. + glpmcfg_data_t lpmcfg;
  99873. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  99874. + int channel;
  99875. +
  99876. + channel = dwc_otg_hcd_get_hc_for_lpm_tran(hcd, devaddr);
  99877. + if (channel < 0) {
  99878. + return channel;
  99879. + }
  99880. +
  99881. + pcgcctl.b.enbl_sleep_gating = 1;
  99882. + DWC_MODIFY_REG32(hcd->core_if->pcgcctl, 0, pcgcctl.d32);
  99883. +
  99884. + /* Read LPM config register */
  99885. + lpmcfg.d32 = DWC_READ_REG32(&hcd->core_if->core_global_regs->glpmcfg);
  99886. +
  99887. + /* Program LPM transaction fields */
  99888. + lpmcfg.b.rem_wkup_en = bRemoteWake;
  99889. + lpmcfg.b.hird = hird;
  99890. + lpmcfg.b.hird_thres = 0x1c;
  99891. + lpmcfg.b.lpm_chan_index = channel;
  99892. + lpmcfg.b.en_utmi_sleep = 1;
  99893. + /* Program LPM config register */
  99894. + DWC_WRITE_REG32(&hcd->core_if->core_global_regs->glpmcfg, lpmcfg.d32);
  99895. +
  99896. + /* Send LPM transaction */
  99897. + lpmcfg.b.send_lpm = 1;
  99898. + DWC_WRITE_REG32(&hcd->core_if->core_global_regs->glpmcfg, lpmcfg.d32);
  99899. +
  99900. + return 0;
  99901. +}
  99902. +
  99903. +#endif /* CONFIG_USB_DWC_OTG_LPM */
  99904. +
  99905. +int dwc_otg_hcd_is_status_changed(dwc_otg_hcd_t * hcd, int port)
  99906. +{
  99907. + int retval;
  99908. +
  99909. + if (port != 1) {
  99910. + return -DWC_E_INVALID;
  99911. + }
  99912. +
  99913. + retval = (hcd->flags.b.port_connect_status_change ||
  99914. + hcd->flags.b.port_reset_change ||
  99915. + hcd->flags.b.port_enable_change ||
  99916. + hcd->flags.b.port_suspend_change ||
  99917. + hcd->flags.b.port_over_current_change);
  99918. +#ifdef DEBUG
  99919. + if (retval) {
  99920. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB STATUS DATA:"
  99921. + " Root port status changed\n");
  99922. + DWC_DEBUGPL(DBG_HCDV, " port_connect_status_change: %d\n",
  99923. + hcd->flags.b.port_connect_status_change);
  99924. + DWC_DEBUGPL(DBG_HCDV, " port_reset_change: %d\n",
  99925. + hcd->flags.b.port_reset_change);
  99926. + DWC_DEBUGPL(DBG_HCDV, " port_enable_change: %d\n",
  99927. + hcd->flags.b.port_enable_change);
  99928. + DWC_DEBUGPL(DBG_HCDV, " port_suspend_change: %d\n",
  99929. + hcd->flags.b.port_suspend_change);
  99930. + DWC_DEBUGPL(DBG_HCDV, " port_over_current_change: %d\n",
  99931. + hcd->flags.b.port_over_current_change);
  99932. + }
  99933. +#endif
  99934. + return retval;
  99935. +}
  99936. +
  99937. +int dwc_otg_hcd_get_frame_number(dwc_otg_hcd_t * dwc_otg_hcd)
  99938. +{
  99939. + hfnum_data_t hfnum;
  99940. + hfnum.d32 =
  99941. + DWC_READ_REG32(&dwc_otg_hcd->core_if->host_if->host_global_regs->
  99942. + hfnum);
  99943. +
  99944. +#ifdef DEBUG_SOF
  99945. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD GET FRAME NUMBER %d\n",
  99946. + hfnum.b.frnum);
  99947. +#endif
  99948. + return hfnum.b.frnum;
  99949. +}
  99950. +
  99951. +int dwc_otg_hcd_start(dwc_otg_hcd_t * hcd,
  99952. + struct dwc_otg_hcd_function_ops *fops)
  99953. +{
  99954. + int retval = 0;
  99955. +
  99956. + hcd->fops = fops;
  99957. + if (!dwc_otg_is_device_mode(hcd->core_if) &&
  99958. + (!hcd->core_if->adp_enable || hcd->core_if->adp.adp_started)) {
  99959. + dwc_otg_hcd_reinit(hcd);
  99960. + } else {
  99961. + retval = -DWC_E_NO_DEVICE;
  99962. + }
  99963. +
  99964. + return retval;
  99965. +}
  99966. +
  99967. +void *dwc_otg_hcd_get_priv_data(dwc_otg_hcd_t * hcd)
  99968. +{
  99969. + return hcd->priv;
  99970. +}
  99971. +
  99972. +void dwc_otg_hcd_set_priv_data(dwc_otg_hcd_t * hcd, void *priv_data)
  99973. +{
  99974. + hcd->priv = priv_data;
  99975. +}
  99976. +
  99977. +uint32_t dwc_otg_hcd_otg_port(dwc_otg_hcd_t * hcd)
  99978. +{
  99979. + return hcd->otg_port;
  99980. +}
  99981. +
  99982. +uint32_t dwc_otg_hcd_is_b_host(dwc_otg_hcd_t * hcd)
  99983. +{
  99984. + uint32_t is_b_host;
  99985. + if (hcd->core_if->op_state == B_HOST) {
  99986. + is_b_host = 1;
  99987. + } else {
  99988. + is_b_host = 0;
  99989. + }
  99990. +
  99991. + return is_b_host;
  99992. +}
  99993. +
  99994. +dwc_otg_hcd_urb_t *dwc_otg_hcd_urb_alloc(dwc_otg_hcd_t * hcd,
  99995. + int iso_desc_count, int atomic_alloc)
  99996. +{
  99997. + dwc_otg_hcd_urb_t *dwc_otg_urb;
  99998. + uint32_t size;
  99999. +
  100000. + size =
  100001. + sizeof(*dwc_otg_urb) +
  100002. + iso_desc_count * sizeof(struct dwc_otg_hcd_iso_packet_desc);
  100003. + if (atomic_alloc)
  100004. + dwc_otg_urb = DWC_ALLOC_ATOMIC(size);
  100005. + else
  100006. + dwc_otg_urb = DWC_ALLOC(size);
  100007. +
  100008. + if (dwc_otg_urb)
  100009. + dwc_otg_urb->packet_count = iso_desc_count;
  100010. + else {
  100011. + DWC_ERROR("**** DWC OTG HCD URB alloc - "
  100012. + "%salloc of %db failed\n",
  100013. + atomic_alloc?"atomic ":"", size);
  100014. + }
  100015. + return dwc_otg_urb;
  100016. +}
  100017. +
  100018. +void dwc_otg_hcd_urb_set_pipeinfo(dwc_otg_hcd_urb_t * dwc_otg_urb,
  100019. + uint8_t dev_addr, uint8_t ep_num,
  100020. + uint8_t ep_type, uint8_t ep_dir, uint16_t mps)
  100021. +{
  100022. + dwc_otg_hcd_fill_pipe(&dwc_otg_urb->pipe_info, dev_addr, ep_num,
  100023. + ep_type, ep_dir, mps);
  100024. +#if 0
  100025. + DWC_PRINTF
  100026. + ("addr = %d, ep_num = %d, ep_dir = 0x%x, ep_type = 0x%x, mps = %d\n",
  100027. + dev_addr, ep_num, ep_dir, ep_type, mps);
  100028. +#endif
  100029. +}
  100030. +
  100031. +void dwc_otg_hcd_urb_set_params(dwc_otg_hcd_urb_t * dwc_otg_urb,
  100032. + void *urb_handle, void *buf, dwc_dma_t dma,
  100033. + uint32_t buflen, void *setup_packet,
  100034. + dwc_dma_t setup_dma, uint32_t flags,
  100035. + uint16_t interval)
  100036. +{
  100037. + dwc_otg_urb->priv = urb_handle;
  100038. + dwc_otg_urb->buf = buf;
  100039. + dwc_otg_urb->dma = dma;
  100040. + dwc_otg_urb->length = buflen;
  100041. + dwc_otg_urb->setup_packet = setup_packet;
  100042. + dwc_otg_urb->setup_dma = setup_dma;
  100043. + dwc_otg_urb->flags = flags;
  100044. + dwc_otg_urb->interval = interval;
  100045. + dwc_otg_urb->status = -DWC_E_IN_PROGRESS;
  100046. +}
  100047. +
  100048. +uint32_t dwc_otg_hcd_urb_get_status(dwc_otg_hcd_urb_t * dwc_otg_urb)
  100049. +{
  100050. + return dwc_otg_urb->status;
  100051. +}
  100052. +
  100053. +uint32_t dwc_otg_hcd_urb_get_actual_length(dwc_otg_hcd_urb_t * dwc_otg_urb)
  100054. +{
  100055. + return dwc_otg_urb->actual_length;
  100056. +}
  100057. +
  100058. +uint32_t dwc_otg_hcd_urb_get_error_count(dwc_otg_hcd_urb_t * dwc_otg_urb)
  100059. +{
  100060. + return dwc_otg_urb->error_count;
  100061. +}
  100062. +
  100063. +void dwc_otg_hcd_urb_set_iso_desc_params(dwc_otg_hcd_urb_t * dwc_otg_urb,
  100064. + int desc_num, uint32_t offset,
  100065. + uint32_t length)
  100066. +{
  100067. + dwc_otg_urb->iso_descs[desc_num].offset = offset;
  100068. + dwc_otg_urb->iso_descs[desc_num].length = length;
  100069. +}
  100070. +
  100071. +uint32_t dwc_otg_hcd_urb_get_iso_desc_status(dwc_otg_hcd_urb_t * dwc_otg_urb,
  100072. + int desc_num)
  100073. +{
  100074. + return dwc_otg_urb->iso_descs[desc_num].status;
  100075. +}
  100076. +
  100077. +uint32_t dwc_otg_hcd_urb_get_iso_desc_actual_length(dwc_otg_hcd_urb_t *
  100078. + dwc_otg_urb, int desc_num)
  100079. +{
  100080. + return dwc_otg_urb->iso_descs[desc_num].actual_length;
  100081. +}
  100082. +
  100083. +int dwc_otg_hcd_is_bandwidth_allocated(dwc_otg_hcd_t * hcd, void *ep_handle)
  100084. +{
  100085. + int allocated = 0;
  100086. + dwc_otg_qh_t *qh = (dwc_otg_qh_t *) ep_handle;
  100087. +
  100088. + if (qh) {
  100089. + if (!DWC_LIST_EMPTY(&qh->qh_list_entry)) {
  100090. + allocated = 1;
  100091. + }
  100092. + }
  100093. + return allocated;
  100094. +}
  100095. +
  100096. +int dwc_otg_hcd_is_bandwidth_freed(dwc_otg_hcd_t * hcd, void *ep_handle)
  100097. +{
  100098. + dwc_otg_qh_t *qh = (dwc_otg_qh_t *) ep_handle;
  100099. + int freed = 0;
  100100. + DWC_ASSERT(qh, "qh is not allocated\n");
  100101. +
  100102. + if (DWC_LIST_EMPTY(&qh->qh_list_entry)) {
  100103. + freed = 1;
  100104. + }
  100105. +
  100106. + return freed;
  100107. +}
  100108. +
  100109. +uint8_t dwc_otg_hcd_get_ep_bandwidth(dwc_otg_hcd_t * hcd, void *ep_handle)
  100110. +{
  100111. + dwc_otg_qh_t *qh = (dwc_otg_qh_t *) ep_handle;
  100112. + DWC_ASSERT(qh, "qh is not allocated\n");
  100113. + return qh->usecs;
  100114. +}
  100115. +
  100116. +void dwc_otg_hcd_dump_state(dwc_otg_hcd_t * hcd)
  100117. +{
  100118. +#ifdef DEBUG
  100119. + int num_channels;
  100120. + int i;
  100121. + gnptxsts_data_t np_tx_status;
  100122. + hptxsts_data_t p_tx_status;
  100123. +
  100124. + num_channels = hcd->core_if->core_params->host_channels;
  100125. + DWC_PRINTF("\n");
  100126. + DWC_PRINTF
  100127. + ("************************************************************\n");
  100128. + DWC_PRINTF("HCD State:\n");
  100129. + DWC_PRINTF(" Num channels: %d\n", num_channels);
  100130. + for (i = 0; i < num_channels; i++) {
  100131. + dwc_hc_t *hc = hcd->hc_ptr_array[i];
  100132. + DWC_PRINTF(" Channel %d:\n", i);
  100133. + DWC_PRINTF(" dev_addr: %d, ep_num: %d, ep_is_in: %d\n",
  100134. + hc->dev_addr, hc->ep_num, hc->ep_is_in);
  100135. + DWC_PRINTF(" speed: %d\n", hc->speed);
  100136. + DWC_PRINTF(" ep_type: %d\n", hc->ep_type);
  100137. + DWC_PRINTF(" max_packet: %d\n", hc->max_packet);
  100138. + DWC_PRINTF(" data_pid_start: %d\n", hc->data_pid_start);
  100139. + DWC_PRINTF(" multi_count: %d\n", hc->multi_count);
  100140. + DWC_PRINTF(" xfer_started: %d\n", hc->xfer_started);
  100141. + DWC_PRINTF(" xfer_buff: %p\n", hc->xfer_buff);
  100142. + DWC_PRINTF(" xfer_len: %d\n", hc->xfer_len);
  100143. + DWC_PRINTF(" xfer_count: %d\n", hc->xfer_count);
  100144. + DWC_PRINTF(" halt_on_queue: %d\n", hc->halt_on_queue);
  100145. + DWC_PRINTF(" halt_pending: %d\n", hc->halt_pending);
  100146. + DWC_PRINTF(" halt_status: %d\n", hc->halt_status);
  100147. + DWC_PRINTF(" do_split: %d\n", hc->do_split);
  100148. + DWC_PRINTF(" complete_split: %d\n", hc->complete_split);
  100149. + DWC_PRINTF(" hub_addr: %d\n", hc->hub_addr);
  100150. + DWC_PRINTF(" port_addr: %d\n", hc->port_addr);
  100151. + DWC_PRINTF(" xact_pos: %d\n", hc->xact_pos);
  100152. + DWC_PRINTF(" requests: %d\n", hc->requests);
  100153. + DWC_PRINTF(" qh: %p\n", hc->qh);
  100154. + if (hc->xfer_started) {
  100155. + hfnum_data_t hfnum;
  100156. + hcchar_data_t hcchar;
  100157. + hctsiz_data_t hctsiz;
  100158. + hcint_data_t hcint;
  100159. + hcintmsk_data_t hcintmsk;
  100160. + hfnum.d32 =
  100161. + DWC_READ_REG32(&hcd->core_if->
  100162. + host_if->host_global_regs->hfnum);
  100163. + hcchar.d32 =
  100164. + DWC_READ_REG32(&hcd->core_if->host_if->
  100165. + hc_regs[i]->hcchar);
  100166. + hctsiz.d32 =
  100167. + DWC_READ_REG32(&hcd->core_if->host_if->
  100168. + hc_regs[i]->hctsiz);
  100169. + hcint.d32 =
  100170. + DWC_READ_REG32(&hcd->core_if->host_if->
  100171. + hc_regs[i]->hcint);
  100172. + hcintmsk.d32 =
  100173. + DWC_READ_REG32(&hcd->core_if->host_if->
  100174. + hc_regs[i]->hcintmsk);
  100175. + DWC_PRINTF(" hfnum: 0x%08x\n", hfnum.d32);
  100176. + DWC_PRINTF(" hcchar: 0x%08x\n", hcchar.d32);
  100177. + DWC_PRINTF(" hctsiz: 0x%08x\n", hctsiz.d32);
  100178. + DWC_PRINTF(" hcint: 0x%08x\n", hcint.d32);
  100179. + DWC_PRINTF(" hcintmsk: 0x%08x\n", hcintmsk.d32);
  100180. + }
  100181. + if (hc->xfer_started && hc->qh) {
  100182. + dwc_otg_qtd_t *qtd;
  100183. + dwc_otg_hcd_urb_t *urb;
  100184. +
  100185. + DWC_CIRCLEQ_FOREACH(qtd, &hc->qh->qtd_list, qtd_list_entry) {
  100186. + if (!qtd->in_process)
  100187. + break;
  100188. +
  100189. + urb = qtd->urb;
  100190. + DWC_PRINTF(" URB Info:\n");
  100191. + DWC_PRINTF(" qtd: %p, urb: %p\n", qtd, urb);
  100192. + if (urb) {
  100193. + DWC_PRINTF(" Dev: %d, EP: %d %s\n",
  100194. + dwc_otg_hcd_get_dev_addr(&urb->
  100195. + pipe_info),
  100196. + dwc_otg_hcd_get_ep_num(&urb->
  100197. + pipe_info),
  100198. + dwc_otg_hcd_is_pipe_in(&urb->
  100199. + pipe_info) ?
  100200. + "IN" : "OUT");
  100201. + DWC_PRINTF(" Max packet size: %d\n",
  100202. + dwc_otg_hcd_get_mps(&urb->
  100203. + pipe_info));
  100204. + DWC_PRINTF(" transfer_buffer: %p\n",
  100205. + urb->buf);
  100206. + DWC_PRINTF(" transfer_dma: %p\n",
  100207. + (void *)urb->dma);
  100208. + DWC_PRINTF(" transfer_buffer_length: %d\n",
  100209. + urb->length);
  100210. + DWC_PRINTF(" actual_length: %d\n",
  100211. + urb->actual_length);
  100212. + }
  100213. + }
  100214. + }
  100215. + }
  100216. + DWC_PRINTF(" non_periodic_channels: %d\n", hcd->non_periodic_channels);
  100217. + DWC_PRINTF(" periodic_channels: %d\n", hcd->periodic_channels);
  100218. + DWC_PRINTF(" periodic_usecs: %d\n", hcd->periodic_usecs);
  100219. + np_tx_status.d32 =
  100220. + DWC_READ_REG32(&hcd->core_if->core_global_regs->gnptxsts);
  100221. + DWC_PRINTF(" NP Tx Req Queue Space Avail: %d\n",
  100222. + np_tx_status.b.nptxqspcavail);
  100223. + DWC_PRINTF(" NP Tx FIFO Space Avail: %d\n",
  100224. + np_tx_status.b.nptxfspcavail);
  100225. + p_tx_status.d32 =
  100226. + DWC_READ_REG32(&hcd->core_if->host_if->host_global_regs->hptxsts);
  100227. + DWC_PRINTF(" P Tx Req Queue Space Avail: %d\n",
  100228. + p_tx_status.b.ptxqspcavail);
  100229. + DWC_PRINTF(" P Tx FIFO Space Avail: %d\n", p_tx_status.b.ptxfspcavail);
  100230. + dwc_otg_hcd_dump_frrem(hcd);
  100231. + dwc_otg_dump_global_registers(hcd->core_if);
  100232. + dwc_otg_dump_host_registers(hcd->core_if);
  100233. + DWC_PRINTF
  100234. + ("************************************************************\n");
  100235. + DWC_PRINTF("\n");
  100236. +#endif
  100237. +}
  100238. +
  100239. +#ifdef DEBUG
  100240. +void dwc_print_setup_data(uint8_t * setup)
  100241. +{
  100242. + int i;
  100243. + if (CHK_DEBUG_LEVEL(DBG_HCD)) {
  100244. + DWC_PRINTF("Setup Data = MSB ");
  100245. + for (i = 7; i >= 0; i--)
  100246. + DWC_PRINTF("%02x ", setup[i]);
  100247. + DWC_PRINTF("\n");
  100248. + DWC_PRINTF(" bmRequestType Tranfer = %s\n",
  100249. + (setup[0] & 0x80) ? "Device-to-Host" :
  100250. + "Host-to-Device");
  100251. + DWC_PRINTF(" bmRequestType Type = ");
  100252. + switch ((setup[0] & 0x60) >> 5) {
  100253. + case 0:
  100254. + DWC_PRINTF("Standard\n");
  100255. + break;
  100256. + case 1:
  100257. + DWC_PRINTF("Class\n");
  100258. + break;
  100259. + case 2:
  100260. + DWC_PRINTF("Vendor\n");
  100261. + break;
  100262. + case 3:
  100263. + DWC_PRINTF("Reserved\n");
  100264. + break;
  100265. + }
  100266. + DWC_PRINTF(" bmRequestType Recipient = ");
  100267. + switch (setup[0] & 0x1f) {
  100268. + case 0:
  100269. + DWC_PRINTF("Device\n");
  100270. + break;
  100271. + case 1:
  100272. + DWC_PRINTF("Interface\n");
  100273. + break;
  100274. + case 2:
  100275. + DWC_PRINTF("Endpoint\n");
  100276. + break;
  100277. + case 3:
  100278. + DWC_PRINTF("Other\n");
  100279. + break;
  100280. + default:
  100281. + DWC_PRINTF("Reserved\n");
  100282. + break;
  100283. + }
  100284. + DWC_PRINTF(" bRequest = 0x%0x\n", setup[1]);
  100285. + DWC_PRINTF(" wValue = 0x%0x\n", *((uint16_t *) & setup[2]));
  100286. + DWC_PRINTF(" wIndex = 0x%0x\n", *((uint16_t *) & setup[4]));
  100287. + DWC_PRINTF(" wLength = 0x%0x\n\n", *((uint16_t *) & setup[6]));
  100288. + }
  100289. +}
  100290. +#endif
  100291. +
  100292. +void dwc_otg_hcd_dump_frrem(dwc_otg_hcd_t * hcd)
  100293. +{
  100294. +#if 0
  100295. + DWC_PRINTF("Frame remaining at SOF:\n");
  100296. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  100297. + hcd->frrem_samples, hcd->frrem_accum,
  100298. + (hcd->frrem_samples > 0) ?
  100299. + hcd->frrem_accum / hcd->frrem_samples : 0);
  100300. +
  100301. + DWC_PRINTF("\n");
  100302. + DWC_PRINTF("Frame remaining at start_transfer (uframe 7):\n");
  100303. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  100304. + hcd->core_if->hfnum_7_samples,
  100305. + hcd->core_if->hfnum_7_frrem_accum,
  100306. + (hcd->core_if->hfnum_7_samples >
  100307. + 0) ? hcd->core_if->hfnum_7_frrem_accum /
  100308. + hcd->core_if->hfnum_7_samples : 0);
  100309. + DWC_PRINTF("Frame remaining at start_transfer (uframe 0):\n");
  100310. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  100311. + hcd->core_if->hfnum_0_samples,
  100312. + hcd->core_if->hfnum_0_frrem_accum,
  100313. + (hcd->core_if->hfnum_0_samples >
  100314. + 0) ? hcd->core_if->hfnum_0_frrem_accum /
  100315. + hcd->core_if->hfnum_0_samples : 0);
  100316. + DWC_PRINTF("Frame remaining at start_transfer (uframe 1-6):\n");
  100317. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  100318. + hcd->core_if->hfnum_other_samples,
  100319. + hcd->core_if->hfnum_other_frrem_accum,
  100320. + (hcd->core_if->hfnum_other_samples >
  100321. + 0) ? hcd->core_if->hfnum_other_frrem_accum /
  100322. + hcd->core_if->hfnum_other_samples : 0);
  100323. +
  100324. + DWC_PRINTF("\n");
  100325. + DWC_PRINTF("Frame remaining at sample point A (uframe 7):\n");
  100326. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  100327. + hcd->hfnum_7_samples_a, hcd->hfnum_7_frrem_accum_a,
  100328. + (hcd->hfnum_7_samples_a > 0) ?
  100329. + hcd->hfnum_7_frrem_accum_a / hcd->hfnum_7_samples_a : 0);
  100330. + DWC_PRINTF("Frame remaining at sample point A (uframe 0):\n");
  100331. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  100332. + hcd->hfnum_0_samples_a, hcd->hfnum_0_frrem_accum_a,
  100333. + (hcd->hfnum_0_samples_a > 0) ?
  100334. + hcd->hfnum_0_frrem_accum_a / hcd->hfnum_0_samples_a : 0);
  100335. + DWC_PRINTF("Frame remaining at sample point A (uframe 1-6):\n");
  100336. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  100337. + hcd->hfnum_other_samples_a, hcd->hfnum_other_frrem_accum_a,
  100338. + (hcd->hfnum_other_samples_a > 0) ?
  100339. + hcd->hfnum_other_frrem_accum_a /
  100340. + hcd->hfnum_other_samples_a : 0);
  100341. +
  100342. + DWC_PRINTF("\n");
  100343. + DWC_PRINTF("Frame remaining at sample point B (uframe 7):\n");
  100344. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  100345. + hcd->hfnum_7_samples_b, hcd->hfnum_7_frrem_accum_b,
  100346. + (hcd->hfnum_7_samples_b > 0) ?
  100347. + hcd->hfnum_7_frrem_accum_b / hcd->hfnum_7_samples_b : 0);
  100348. + DWC_PRINTF("Frame remaining at sample point B (uframe 0):\n");
  100349. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  100350. + hcd->hfnum_0_samples_b, hcd->hfnum_0_frrem_accum_b,
  100351. + (hcd->hfnum_0_samples_b > 0) ?
  100352. + hcd->hfnum_0_frrem_accum_b / hcd->hfnum_0_samples_b : 0);
  100353. + DWC_PRINTF("Frame remaining at sample point B (uframe 1-6):\n");
  100354. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  100355. + hcd->hfnum_other_samples_b, hcd->hfnum_other_frrem_accum_b,
  100356. + (hcd->hfnum_other_samples_b > 0) ?
  100357. + hcd->hfnum_other_frrem_accum_b /
  100358. + hcd->hfnum_other_samples_b : 0);
  100359. +#endif
  100360. +}
  100361. +
  100362. +#endif /* DWC_DEVICE_ONLY */
  100363. diff -Nur linux-3.18.8/drivers/usb/host/dwc_otg/dwc_otg_hcd_ddma.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd_ddma.c
  100364. --- linux-3.18.8/drivers/usb/host/dwc_otg/dwc_otg_hcd_ddma.c 1970-01-01 01:00:00.000000000 +0100
  100365. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd_ddma.c 2015-03-05 14:40:16.561715806 +0100
  100366. @@ -0,0 +1,1132 @@
  100367. +/*==========================================================================
  100368. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd_ddma.c $
  100369. + * $Revision: #10 $
  100370. + * $Date: 2011/10/20 $
  100371. + * $Change: 1869464 $
  100372. + *
  100373. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  100374. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  100375. + * otherwise expressly agreed to in writing between Synopsys and you.
  100376. + *
  100377. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  100378. + * any End User Software License Agreement or Agreement for Licensed Product
  100379. + * with Synopsys or any supplement thereto. You are permitted to use and
  100380. + * redistribute this Software in source and binary forms, with or without
  100381. + * modification, provided that redistributions of source code must retain this
  100382. + * notice. You may not view, use, disclose, copy or distribute this file or
  100383. + * any information contained herein except pursuant to this license grant from
  100384. + * Synopsys. If you do not agree with this notice, including the disclaimer
  100385. + * below, then you are not authorized to use the Software.
  100386. + *
  100387. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  100388. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  100389. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  100390. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  100391. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  100392. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  100393. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  100394. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  100395. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  100396. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  100397. + * DAMAGE.
  100398. + * ========================================================================== */
  100399. +#ifndef DWC_DEVICE_ONLY
  100400. +
  100401. +/** @file
  100402. + * This file contains Descriptor DMA support implementation for host mode.
  100403. + */
  100404. +
  100405. +#include "dwc_otg_hcd.h"
  100406. +#include "dwc_otg_regs.h"
  100407. +
  100408. +extern bool microframe_schedule;
  100409. +
  100410. +static inline uint8_t frame_list_idx(uint16_t frame)
  100411. +{
  100412. + return (frame & (MAX_FRLIST_EN_NUM - 1));
  100413. +}
  100414. +
  100415. +static inline uint16_t desclist_idx_inc(uint16_t idx, uint16_t inc, uint8_t speed)
  100416. +{
  100417. + return (idx + inc) &
  100418. + (((speed ==
  100419. + DWC_OTG_EP_SPEED_HIGH) ? MAX_DMA_DESC_NUM_HS_ISOC :
  100420. + MAX_DMA_DESC_NUM_GENERIC) - 1);
  100421. +}
  100422. +
  100423. +static inline uint16_t desclist_idx_dec(uint16_t idx, uint16_t inc, uint8_t speed)
  100424. +{
  100425. + return (idx - inc) &
  100426. + (((speed ==
  100427. + DWC_OTG_EP_SPEED_HIGH) ? MAX_DMA_DESC_NUM_HS_ISOC :
  100428. + MAX_DMA_DESC_NUM_GENERIC) - 1);
  100429. +}
  100430. +
  100431. +static inline uint16_t max_desc_num(dwc_otg_qh_t * qh)
  100432. +{
  100433. + return (((qh->ep_type == UE_ISOCHRONOUS)
  100434. + && (qh->dev_speed == DWC_OTG_EP_SPEED_HIGH))
  100435. + ? MAX_DMA_DESC_NUM_HS_ISOC : MAX_DMA_DESC_NUM_GENERIC);
  100436. +}
  100437. +static inline uint16_t frame_incr_val(dwc_otg_qh_t * qh)
  100438. +{
  100439. + return ((qh->dev_speed == DWC_OTG_EP_SPEED_HIGH)
  100440. + ? ((qh->interval + 8 - 1) / 8)
  100441. + : qh->interval);
  100442. +}
  100443. +
  100444. +static int desc_list_alloc(dwc_otg_qh_t * qh)
  100445. +{
  100446. + int retval = 0;
  100447. +
  100448. + qh->desc_list = (dwc_otg_host_dma_desc_t *)
  100449. + DWC_DMA_ALLOC(sizeof(dwc_otg_host_dma_desc_t) * max_desc_num(qh),
  100450. + &qh->desc_list_dma);
  100451. +
  100452. + if (!qh->desc_list) {
  100453. + retval = -DWC_E_NO_MEMORY;
  100454. + DWC_ERROR("%s: DMA descriptor list allocation failed\n", __func__);
  100455. +
  100456. + }
  100457. +
  100458. + dwc_memset(qh->desc_list, 0x00,
  100459. + sizeof(dwc_otg_host_dma_desc_t) * max_desc_num(qh));
  100460. +
  100461. + qh->n_bytes =
  100462. + (uint32_t *) DWC_ALLOC(sizeof(uint32_t) * max_desc_num(qh));
  100463. +
  100464. + if (!qh->n_bytes) {
  100465. + retval = -DWC_E_NO_MEMORY;
  100466. + DWC_ERROR
  100467. + ("%s: Failed to allocate array for descriptors' size actual values\n",
  100468. + __func__);
  100469. +
  100470. + }
  100471. + return retval;
  100472. +
  100473. +}
  100474. +
  100475. +static void desc_list_free(dwc_otg_qh_t * qh)
  100476. +{
  100477. + if (qh->desc_list) {
  100478. + DWC_DMA_FREE(max_desc_num(qh), qh->desc_list,
  100479. + qh->desc_list_dma);
  100480. + qh->desc_list = NULL;
  100481. + }
  100482. +
  100483. + if (qh->n_bytes) {
  100484. + DWC_FREE(qh->n_bytes);
  100485. + qh->n_bytes = NULL;
  100486. + }
  100487. +}
  100488. +
  100489. +static int frame_list_alloc(dwc_otg_hcd_t * hcd)
  100490. +{
  100491. + int retval = 0;
  100492. + if (hcd->frame_list)
  100493. + return 0;
  100494. +
  100495. + hcd->frame_list = DWC_DMA_ALLOC(4 * MAX_FRLIST_EN_NUM,
  100496. + &hcd->frame_list_dma);
  100497. + if (!hcd->frame_list) {
  100498. + retval = -DWC_E_NO_MEMORY;
  100499. + DWC_ERROR("%s: Frame List allocation failed\n", __func__);
  100500. + }
  100501. +
  100502. + dwc_memset(hcd->frame_list, 0x00, 4 * MAX_FRLIST_EN_NUM);
  100503. +
  100504. + return retval;
  100505. +}
  100506. +
  100507. +static void frame_list_free(dwc_otg_hcd_t * hcd)
  100508. +{
  100509. + if (!hcd->frame_list)
  100510. + return;
  100511. +
  100512. + DWC_DMA_FREE(4 * MAX_FRLIST_EN_NUM, hcd->frame_list, hcd->frame_list_dma);
  100513. + hcd->frame_list = NULL;
  100514. +}
  100515. +
  100516. +static void per_sched_enable(dwc_otg_hcd_t * hcd, uint16_t fr_list_en)
  100517. +{
  100518. +
  100519. + hcfg_data_t hcfg;
  100520. +
  100521. + hcfg.d32 = DWC_READ_REG32(&hcd->core_if->host_if->host_global_regs->hcfg);
  100522. +
  100523. + if (hcfg.b.perschedena) {
  100524. + /* already enabled */
  100525. + return;
  100526. + }
  100527. +
  100528. + DWC_WRITE_REG32(&hcd->core_if->host_if->host_global_regs->hflbaddr,
  100529. + hcd->frame_list_dma);
  100530. +
  100531. + switch (fr_list_en) {
  100532. + case 64:
  100533. + hcfg.b.frlisten = 3;
  100534. + break;
  100535. + case 32:
  100536. + hcfg.b.frlisten = 2;
  100537. + break;
  100538. + case 16:
  100539. + hcfg.b.frlisten = 1;
  100540. + break;
  100541. + case 8:
  100542. + hcfg.b.frlisten = 0;
  100543. + break;
  100544. + default:
  100545. + break;
  100546. + }
  100547. +
  100548. + hcfg.b.perschedena = 1;
  100549. +
  100550. + DWC_DEBUGPL(DBG_HCD, "Enabling Periodic schedule\n");
  100551. + DWC_WRITE_REG32(&hcd->core_if->host_if->host_global_regs->hcfg, hcfg.d32);
  100552. +
  100553. +}
  100554. +
  100555. +static void per_sched_disable(dwc_otg_hcd_t * hcd)
  100556. +{
  100557. + hcfg_data_t hcfg;
  100558. +
  100559. + hcfg.d32 = DWC_READ_REG32(&hcd->core_if->host_if->host_global_regs->hcfg);
  100560. +
  100561. + if (!hcfg.b.perschedena) {
  100562. + /* already disabled */
  100563. + return;
  100564. + }
  100565. + hcfg.b.perschedena = 0;
  100566. +
  100567. + DWC_DEBUGPL(DBG_HCD, "Disabling Periodic schedule\n");
  100568. + DWC_WRITE_REG32(&hcd->core_if->host_if->host_global_regs->hcfg, hcfg.d32);
  100569. +}
  100570. +
  100571. +/*
  100572. + * Activates/Deactivates FrameList entries for the channel
  100573. + * based on endpoint servicing period.
  100574. + */
  100575. +void update_frame_list(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh, uint8_t enable)
  100576. +{
  100577. + uint16_t i, j, inc;
  100578. + dwc_hc_t *hc = NULL;
  100579. +
  100580. + if (!qh->channel) {
  100581. + DWC_ERROR("qh->channel = %p", qh->channel);
  100582. + return;
  100583. + }
  100584. +
  100585. + if (!hcd) {
  100586. + DWC_ERROR("------hcd = %p", hcd);
  100587. + return;
  100588. + }
  100589. +
  100590. + if (!hcd->frame_list) {
  100591. + DWC_ERROR("-------hcd->frame_list = %p", hcd->frame_list);
  100592. + return;
  100593. + }
  100594. +
  100595. + hc = qh->channel;
  100596. + inc = frame_incr_val(qh);
  100597. + if (qh->ep_type == UE_ISOCHRONOUS)
  100598. + i = frame_list_idx(qh->sched_frame);
  100599. + else
  100600. + i = 0;
  100601. +
  100602. + j = i;
  100603. + do {
  100604. + if (enable)
  100605. + hcd->frame_list[j] |= (1 << hc->hc_num);
  100606. + else
  100607. + hcd->frame_list[j] &= ~(1 << hc->hc_num);
  100608. + j = (j + inc) & (MAX_FRLIST_EN_NUM - 1);
  100609. + }
  100610. + while (j != i);
  100611. + if (!enable)
  100612. + return;
  100613. + hc->schinfo = 0;
  100614. + if (qh->channel->speed == DWC_OTG_EP_SPEED_HIGH) {
  100615. + j = 1;
  100616. + /* TODO - check this */
  100617. + inc = (8 + qh->interval - 1) / qh->interval;
  100618. + for (i = 0; i < inc; i++) {
  100619. + hc->schinfo |= j;
  100620. + j = j << qh->interval;
  100621. + }
  100622. + } else {
  100623. + hc->schinfo = 0xff;
  100624. + }
  100625. +}
  100626. +
  100627. +#if 1
  100628. +void dump_frame_list(dwc_otg_hcd_t * hcd)
  100629. +{
  100630. + int i = 0;
  100631. + DWC_PRINTF("--FRAME LIST (hex) --\n");
  100632. + for (i = 0; i < MAX_FRLIST_EN_NUM; i++) {
  100633. + DWC_PRINTF("%x\t", hcd->frame_list[i]);
  100634. + if (!(i % 8) && i)
  100635. + DWC_PRINTF("\n");
  100636. + }
  100637. + DWC_PRINTF("\n----\n");
  100638. +
  100639. +}
  100640. +#endif
  100641. +
  100642. +static void release_channel_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  100643. +{
  100644. + dwc_irqflags_t flags;
  100645. + dwc_spinlock_t *channel_lock = hcd->channel_lock;
  100646. +
  100647. + dwc_hc_t *hc = qh->channel;
  100648. + if (dwc_qh_is_non_per(qh)) {
  100649. + DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
  100650. + if (!microframe_schedule)
  100651. + hcd->non_periodic_channels--;
  100652. + else
  100653. + hcd->available_host_channels++;
  100654. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  100655. + } else
  100656. + update_frame_list(hcd, qh, 0);
  100657. +
  100658. + /*
  100659. + * The condition is added to prevent double cleanup try in case of device
  100660. + * disconnect. See channel cleanup in dwc_otg_hcd_disconnect_cb().
  100661. + */
  100662. + if (hc->qh) {
  100663. + dwc_otg_hc_cleanup(hcd->core_if, hc);
  100664. + DWC_CIRCLEQ_INSERT_TAIL(&hcd->free_hc_list, hc, hc_list_entry);
  100665. + hc->qh = NULL;
  100666. + }
  100667. +
  100668. + qh->channel = NULL;
  100669. + qh->ntd = 0;
  100670. +
  100671. + if (qh->desc_list) {
  100672. + dwc_memset(qh->desc_list, 0x00,
  100673. + sizeof(dwc_otg_host_dma_desc_t) * max_desc_num(qh));
  100674. + }
  100675. +}
  100676. +
  100677. +/**
  100678. + * Initializes a QH structure's Descriptor DMA related members.
  100679. + * Allocates memory for descriptor list.
  100680. + * On first periodic QH, allocates memory for FrameList
  100681. + * and enables periodic scheduling.
  100682. + *
  100683. + * @param hcd The HCD state structure for the DWC OTG controller.
  100684. + * @param qh The QH to init.
  100685. + *
  100686. + * @return 0 if successful, negative error code otherwise.
  100687. + */
  100688. +int dwc_otg_hcd_qh_init_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  100689. +{
  100690. + int retval = 0;
  100691. +
  100692. + if (qh->do_split) {
  100693. + DWC_ERROR("SPLIT Transfers are not supported in Descriptor DMA.\n");
  100694. + return -1;
  100695. + }
  100696. +
  100697. + retval = desc_list_alloc(qh);
  100698. +
  100699. + if ((retval == 0)
  100700. + && (qh->ep_type == UE_ISOCHRONOUS || qh->ep_type == UE_INTERRUPT)) {
  100701. + if (!hcd->frame_list) {
  100702. + retval = frame_list_alloc(hcd);
  100703. + /* Enable periodic schedule on first periodic QH */
  100704. + if (retval == 0)
  100705. + per_sched_enable(hcd, MAX_FRLIST_EN_NUM);
  100706. + }
  100707. + }
  100708. +
  100709. + qh->ntd = 0;
  100710. +
  100711. + return retval;
  100712. +}
  100713. +
  100714. +/**
  100715. + * Frees descriptor list memory associated with the QH.
  100716. + * If QH is periodic and the last, frees FrameList memory
  100717. + * and disables periodic scheduling.
  100718. + *
  100719. + * @param hcd The HCD state structure for the DWC OTG controller.
  100720. + * @param qh The QH to init.
  100721. + */
  100722. +void dwc_otg_hcd_qh_free_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  100723. +{
  100724. + desc_list_free(qh);
  100725. +
  100726. + /*
  100727. + * Channel still assigned due to some reasons.
  100728. + * Seen on Isoc URB dequeue. Channel halted but no subsequent
  100729. + * ChHalted interrupt to release the channel. Afterwards
  100730. + * when it comes here from endpoint disable routine
  100731. + * channel remains assigned.
  100732. + */
  100733. + if (qh->channel)
  100734. + release_channel_ddma(hcd, qh);
  100735. +
  100736. + if ((qh->ep_type == UE_ISOCHRONOUS || qh->ep_type == UE_INTERRUPT)
  100737. + && (microframe_schedule || !hcd->periodic_channels) && hcd->frame_list) {
  100738. +
  100739. + per_sched_disable(hcd);
  100740. + frame_list_free(hcd);
  100741. + }
  100742. +}
  100743. +
  100744. +static uint8_t frame_to_desc_idx(dwc_otg_qh_t * qh, uint16_t frame_idx)
  100745. +{
  100746. + if (qh->dev_speed == DWC_OTG_EP_SPEED_HIGH) {
  100747. + /*
  100748. + * Descriptor set(8 descriptors) index
  100749. + * which is 8-aligned.
  100750. + */
  100751. + return (frame_idx & ((MAX_DMA_DESC_NUM_HS_ISOC / 8) - 1)) * 8;
  100752. + } else {
  100753. + return (frame_idx & (MAX_DMA_DESC_NUM_GENERIC - 1));
  100754. + }
  100755. +}
  100756. +
  100757. +/*
  100758. + * Determine starting frame for Isochronous transfer.
  100759. + * Few frames skipped to prevent race condition with HC.
  100760. + */
  100761. +static uint8_t calc_starting_frame(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh,
  100762. + uint8_t * skip_frames)
  100763. +{
  100764. + uint16_t frame = 0;
  100765. + hcd->frame_number = dwc_otg_hcd_get_frame_number(hcd);
  100766. +
  100767. + /* sched_frame is always frame number(not uFrame) both in FS and HS !! */
  100768. +
  100769. + /*
  100770. + * skip_frames is used to limit activated descriptors number
  100771. + * to avoid the situation when HC services the last activated
  100772. + * descriptor firstly.
  100773. + * Example for FS:
  100774. + * Current frame is 1, scheduled frame is 3. Since HC always fetches the descriptor
  100775. + * corresponding to curr_frame+1, the descriptor corresponding to frame 2
  100776. + * will be fetched. If the number of descriptors is max=64 (or greather) the
  100777. + * list will be fully programmed with Active descriptors and it is possible
  100778. + * case(rare) that the latest descriptor(considering rollback) corresponding
  100779. + * to frame 2 will be serviced first. HS case is more probable because, in fact,
  100780. + * up to 11 uframes(16 in the code) may be skipped.
  100781. + */
  100782. + if (qh->dev_speed == DWC_OTG_EP_SPEED_HIGH) {
  100783. + /*
  100784. + * Consider uframe counter also, to start xfer asap.
  100785. + * If half of the frame elapsed skip 2 frames otherwise
  100786. + * just 1 frame.
  100787. + * Starting descriptor index must be 8-aligned, so
  100788. + * if the current frame is near to complete the next one
  100789. + * is skipped as well.
  100790. + */
  100791. +
  100792. + if (dwc_micro_frame_num(hcd->frame_number) >= 5) {
  100793. + *skip_frames = 2 * 8;
  100794. + frame = dwc_frame_num_inc(hcd->frame_number, *skip_frames);
  100795. + } else {
  100796. + *skip_frames = 1 * 8;
  100797. + frame = dwc_frame_num_inc(hcd->frame_number, *skip_frames);
  100798. + }
  100799. +
  100800. + frame = dwc_full_frame_num(frame);
  100801. + } else {
  100802. + /*
  100803. + * Two frames are skipped for FS - the current and the next.
  100804. + * But for descriptor programming, 1 frame(descriptor) is enough,
  100805. + * see example above.
  100806. + */
  100807. + *skip_frames = 1;
  100808. + frame = dwc_frame_num_inc(hcd->frame_number, 2);
  100809. + }
  100810. +
  100811. + return frame;
  100812. +}
  100813. +
  100814. +/*
  100815. + * Calculate initial descriptor index for isochronous transfer
  100816. + * based on scheduled frame.
  100817. + */
  100818. +static uint8_t recalc_initial_desc_idx(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  100819. +{
  100820. + uint16_t frame = 0, fr_idx, fr_idx_tmp;
  100821. + uint8_t skip_frames = 0;
  100822. + /*
  100823. + * With current ISOC processing algorithm the channel is being
  100824. + * released when no more QTDs in the list(qh->ntd == 0).
  100825. + * Thus this function is called only when qh->ntd == 0 and qh->channel == 0.
  100826. + *
  100827. + * So qh->channel != NULL branch is not used and just not removed from the
  100828. + * source file. It is required for another possible approach which is,
  100829. + * do not disable and release the channel when ISOC session completed,
  100830. + * just move QH to inactive schedule until new QTD arrives.
  100831. + * On new QTD, the QH moved back to 'ready' schedule,
  100832. + * starting frame and therefore starting desc_index are recalculated.
  100833. + * In this case channel is released only on ep_disable.
  100834. + */
  100835. +
  100836. + /* Calculate starting descriptor index. For INTERRUPT endpoint it is always 0. */
  100837. + if (qh->channel) {
  100838. + frame = calc_starting_frame(hcd, qh, &skip_frames);
  100839. + /*
  100840. + * Calculate initial descriptor index based on FrameList current bitmap
  100841. + * and servicing period.
  100842. + */
  100843. + fr_idx_tmp = frame_list_idx(frame);
  100844. + fr_idx =
  100845. + (MAX_FRLIST_EN_NUM + frame_list_idx(qh->sched_frame) -
  100846. + fr_idx_tmp)
  100847. + % frame_incr_val(qh);
  100848. + fr_idx = (fr_idx + fr_idx_tmp) % MAX_FRLIST_EN_NUM;
  100849. + } else {
  100850. + qh->sched_frame = calc_starting_frame(hcd, qh, &skip_frames);
  100851. + fr_idx = frame_list_idx(qh->sched_frame);
  100852. + }
  100853. +
  100854. + qh->td_first = qh->td_last = frame_to_desc_idx(qh, fr_idx);
  100855. +
  100856. + return skip_frames;
  100857. +}
  100858. +
  100859. +#define ISOC_URB_GIVEBACK_ASAP
  100860. +
  100861. +#define MAX_ISOC_XFER_SIZE_FS 1023
  100862. +#define MAX_ISOC_XFER_SIZE_HS 3072
  100863. +#define DESCNUM_THRESHOLD 4
  100864. +
  100865. +static void init_isoc_dma_desc(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh,
  100866. + uint8_t skip_frames)
  100867. +{
  100868. + struct dwc_otg_hcd_iso_packet_desc *frame_desc;
  100869. + dwc_otg_qtd_t *qtd;
  100870. + dwc_otg_host_dma_desc_t *dma_desc;
  100871. + uint16_t idx, inc, n_desc, ntd_max, max_xfer_size;
  100872. +
  100873. + idx = qh->td_last;
  100874. + inc = qh->interval;
  100875. + n_desc = 0;
  100876. +
  100877. + ntd_max = (max_desc_num(qh) + qh->interval - 1) / qh->interval;
  100878. + if (skip_frames && !qh->channel)
  100879. + ntd_max = ntd_max - skip_frames / qh->interval;
  100880. +
  100881. + max_xfer_size =
  100882. + (qh->dev_speed ==
  100883. + DWC_OTG_EP_SPEED_HIGH) ? MAX_ISOC_XFER_SIZE_HS :
  100884. + MAX_ISOC_XFER_SIZE_FS;
  100885. +
  100886. + DWC_CIRCLEQ_FOREACH(qtd, &qh->qtd_list, qtd_list_entry) {
  100887. + while ((qh->ntd < ntd_max)
  100888. + && (qtd->isoc_frame_index_last <
  100889. + qtd->urb->packet_count)) {
  100890. +
  100891. + dma_desc = &qh->desc_list[idx];
  100892. + dwc_memset(dma_desc, 0x00, sizeof(dwc_otg_host_dma_desc_t));
  100893. +
  100894. + frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index_last];
  100895. +
  100896. + if (frame_desc->length > max_xfer_size)
  100897. + qh->n_bytes[idx] = max_xfer_size;
  100898. + else
  100899. + qh->n_bytes[idx] = frame_desc->length;
  100900. + dma_desc->status.b_isoc.n_bytes = qh->n_bytes[idx];
  100901. + dma_desc->status.b_isoc.a = 1;
  100902. + dma_desc->status.b_isoc.sts = 0;
  100903. +
  100904. + dma_desc->buf = qtd->urb->dma + frame_desc->offset;
  100905. +
  100906. + qh->ntd++;
  100907. +
  100908. + qtd->isoc_frame_index_last++;
  100909. +
  100910. +#ifdef ISOC_URB_GIVEBACK_ASAP
  100911. + /*
  100912. + * Set IOC for each descriptor corresponding to the
  100913. + * last frame of the URB.
  100914. + */
  100915. + if (qtd->isoc_frame_index_last ==
  100916. + qtd->urb->packet_count)
  100917. + dma_desc->status.b_isoc.ioc = 1;
  100918. +
  100919. +#endif
  100920. + idx = desclist_idx_inc(idx, inc, qh->dev_speed);
  100921. + n_desc++;
  100922. +
  100923. + }
  100924. + qtd->in_process = 1;
  100925. + }
  100926. +
  100927. + qh->td_last = idx;
  100928. +
  100929. +#ifdef ISOC_URB_GIVEBACK_ASAP
  100930. + /* Set IOC for the last descriptor if descriptor list is full */
  100931. + if (qh->ntd == ntd_max) {
  100932. + idx = desclist_idx_dec(qh->td_last, inc, qh->dev_speed);
  100933. + qh->desc_list[idx].status.b_isoc.ioc = 1;
  100934. + }
  100935. +#else
  100936. + /*
  100937. + * Set IOC bit only for one descriptor.
  100938. + * Always try to be ahead of HW processing,
  100939. + * i.e. on IOC generation driver activates next descriptors but
  100940. + * core continues to process descriptors followed the one with IOC set.
  100941. + */
  100942. +
  100943. + if (n_desc > DESCNUM_THRESHOLD) {
  100944. + /*
  100945. + * Move IOC "up". Required even if there is only one QTD
  100946. + * in the list, cause QTDs migth continue to be queued,
  100947. + * but during the activation it was only one queued.
  100948. + * Actually more than one QTD might be in the list if this function called
  100949. + * from XferCompletion - QTDs was queued during HW processing of the previous
  100950. + * descriptor chunk.
  100951. + */
  100952. + idx = dwc_desclist_idx_dec(idx, inc * ((qh->ntd + 1) / 2), qh->dev_speed);
  100953. + } else {
  100954. + /*
  100955. + * Set the IOC for the latest descriptor
  100956. + * if either number of descriptor is not greather than threshold
  100957. + * or no more new descriptors activated.
  100958. + */
  100959. + idx = dwc_desclist_idx_dec(qh->td_last, inc, qh->dev_speed);
  100960. + }
  100961. +
  100962. + qh->desc_list[idx].status.b_isoc.ioc = 1;
  100963. +#endif
  100964. +}
  100965. +
  100966. +static void init_non_isoc_dma_desc(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  100967. +{
  100968. +
  100969. + dwc_hc_t *hc;
  100970. + dwc_otg_host_dma_desc_t *dma_desc;
  100971. + dwc_otg_qtd_t *qtd;
  100972. + int num_packets, len, n_desc = 0;
  100973. +
  100974. + hc = qh->channel;
  100975. +
  100976. + /*
  100977. + * Start with hc->xfer_buff initialized in
  100978. + * assign_and_init_hc(), then if SG transfer consists of multiple URBs,
  100979. + * this pointer re-assigned to the buffer of the currently processed QTD.
  100980. + * For non-SG request there is always one QTD active.
  100981. + */
  100982. +
  100983. + DWC_CIRCLEQ_FOREACH(qtd, &qh->qtd_list, qtd_list_entry) {
  100984. +
  100985. + if (n_desc) {
  100986. + /* SG request - more than 1 QTDs */
  100987. + hc->xfer_buff = (uint8_t *)qtd->urb->dma + qtd->urb->actual_length;
  100988. + hc->xfer_len = qtd->urb->length - qtd->urb->actual_length;
  100989. + }
  100990. +
  100991. + qtd->n_desc = 0;
  100992. +
  100993. + do {
  100994. + dma_desc = &qh->desc_list[n_desc];
  100995. + len = hc->xfer_len;
  100996. +
  100997. + if (len > MAX_DMA_DESC_SIZE)
  100998. + len = MAX_DMA_DESC_SIZE - hc->max_packet + 1;
  100999. +
  101000. + if (hc->ep_is_in) {
  101001. + if (len > 0) {
  101002. + num_packets = (len + hc->max_packet - 1) / hc->max_packet;
  101003. + } else {
  101004. + /* Need 1 packet for transfer length of 0. */
  101005. + num_packets = 1;
  101006. + }
  101007. + /* Always program an integral # of max packets for IN transfers. */
  101008. + len = num_packets * hc->max_packet;
  101009. + }
  101010. +
  101011. + dma_desc->status.b.n_bytes = len;
  101012. +
  101013. + qh->n_bytes[n_desc] = len;
  101014. +
  101015. + if ((qh->ep_type == UE_CONTROL)
  101016. + && (qtd->control_phase == DWC_OTG_CONTROL_SETUP))
  101017. + dma_desc->status.b.sup = 1; /* Setup Packet */
  101018. +
  101019. + dma_desc->status.b.a = 1; /* Active descriptor */
  101020. + dma_desc->status.b.sts = 0;
  101021. +
  101022. + dma_desc->buf =
  101023. + ((unsigned long)hc->xfer_buff & 0xffffffff);
  101024. +
  101025. + /*
  101026. + * Last descriptor(or single) of IN transfer
  101027. + * with actual size less than MaxPacket.
  101028. + */
  101029. + if (len > hc->xfer_len) {
  101030. + hc->xfer_len = 0;
  101031. + } else {
  101032. + hc->xfer_buff += len;
  101033. + hc->xfer_len -= len;
  101034. + }
  101035. +
  101036. + qtd->n_desc++;
  101037. + n_desc++;
  101038. + }
  101039. + while ((hc->xfer_len > 0) && (n_desc != MAX_DMA_DESC_NUM_GENERIC));
  101040. +
  101041. +
  101042. + qtd->in_process = 1;
  101043. +
  101044. + if (qh->ep_type == UE_CONTROL)
  101045. + break;
  101046. +
  101047. + if (n_desc == MAX_DMA_DESC_NUM_GENERIC)
  101048. + break;
  101049. + }
  101050. +
  101051. + if (n_desc) {
  101052. + /* Request Transfer Complete interrupt for the last descriptor */
  101053. + qh->desc_list[n_desc - 1].status.b.ioc = 1;
  101054. + /* End of List indicator */
  101055. + qh->desc_list[n_desc - 1].status.b.eol = 1;
  101056. +
  101057. + hc->ntd = n_desc;
  101058. + }
  101059. +}
  101060. +
  101061. +/**
  101062. + * For Control and Bulk endpoints initializes descriptor list
  101063. + * and starts the transfer.
  101064. + *
  101065. + * For Interrupt and Isochronous endpoints initializes descriptor list
  101066. + * then updates FrameList, marking appropriate entries as active.
  101067. + * In case of Isochronous, the starting descriptor index is calculated based
  101068. + * on the scheduled frame, but only on the first transfer descriptor within a session.
  101069. + * Then starts the transfer via enabling the channel.
  101070. + * For Isochronous endpoint the channel is not halted on XferComplete
  101071. + * interrupt so remains assigned to the endpoint(QH) until session is done.
  101072. + *
  101073. + * @param hcd The HCD state structure for the DWC OTG controller.
  101074. + * @param qh The QH to init.
  101075. + *
  101076. + * @return 0 if successful, negative error code otherwise.
  101077. + */
  101078. +void dwc_otg_hcd_start_xfer_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  101079. +{
  101080. + /* Channel is already assigned */
  101081. + dwc_hc_t *hc = qh->channel;
  101082. + uint8_t skip_frames = 0;
  101083. +
  101084. + switch (hc->ep_type) {
  101085. + case DWC_OTG_EP_TYPE_CONTROL:
  101086. + case DWC_OTG_EP_TYPE_BULK:
  101087. + init_non_isoc_dma_desc(hcd, qh);
  101088. +
  101089. + dwc_otg_hc_start_transfer_ddma(hcd->core_if, hc);
  101090. + break;
  101091. + case DWC_OTG_EP_TYPE_INTR:
  101092. + init_non_isoc_dma_desc(hcd, qh);
  101093. +
  101094. + update_frame_list(hcd, qh, 1);
  101095. +
  101096. + dwc_otg_hc_start_transfer_ddma(hcd->core_if, hc);
  101097. + break;
  101098. + case DWC_OTG_EP_TYPE_ISOC:
  101099. +
  101100. + if (!qh->ntd)
  101101. + skip_frames = recalc_initial_desc_idx(hcd, qh);
  101102. +
  101103. + init_isoc_dma_desc(hcd, qh, skip_frames);
  101104. +
  101105. + if (!hc->xfer_started) {
  101106. +
  101107. + update_frame_list(hcd, qh, 1);
  101108. +
  101109. + /*
  101110. + * Always set to max, instead of actual size.
  101111. + * Otherwise ntd will be changed with
  101112. + * channel being enabled. Not recommended.
  101113. + *
  101114. + */
  101115. + hc->ntd = max_desc_num(qh);
  101116. + /* Enable channel only once for ISOC */
  101117. + dwc_otg_hc_start_transfer_ddma(hcd->core_if, hc);
  101118. + }
  101119. +
  101120. + break;
  101121. + default:
  101122. +
  101123. + break;
  101124. + }
  101125. +}
  101126. +
  101127. +static void complete_isoc_xfer_ddma(dwc_otg_hcd_t * hcd,
  101128. + dwc_hc_t * hc,
  101129. + dwc_otg_hc_regs_t * hc_regs,
  101130. + dwc_otg_halt_status_e halt_status)
  101131. +{
  101132. + struct dwc_otg_hcd_iso_packet_desc *frame_desc;
  101133. + dwc_otg_qtd_t *qtd, *qtd_tmp;
  101134. + dwc_otg_qh_t *qh;
  101135. + dwc_otg_host_dma_desc_t *dma_desc;
  101136. + uint16_t idx, remain;
  101137. + uint8_t urb_compl;
  101138. +
  101139. + qh = hc->qh;
  101140. + idx = qh->td_first;
  101141. +
  101142. + if (hc->halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE) {
  101143. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp, &hc->qh->qtd_list, qtd_list_entry)
  101144. + qtd->in_process = 0;
  101145. + return;
  101146. + } else if ((halt_status == DWC_OTG_HC_XFER_AHB_ERR) ||
  101147. + (halt_status == DWC_OTG_HC_XFER_BABBLE_ERR)) {
  101148. + /*
  101149. + * Channel is halted in these error cases.
  101150. + * Considered as serious issues.
  101151. + * Complete all URBs marking all frames as failed,
  101152. + * irrespective whether some of the descriptors(frames) succeeded or no.
  101153. + * Pass error code to completion routine as well, to
  101154. + * update urb->status, some of class drivers might use it to stop
  101155. + * queing transfer requests.
  101156. + */
  101157. + int err = (halt_status == DWC_OTG_HC_XFER_AHB_ERR)
  101158. + ? (-DWC_E_IO)
  101159. + : (-DWC_E_OVERFLOW);
  101160. +
  101161. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp, &hc->qh->qtd_list, qtd_list_entry) {
  101162. + for (idx = 0; idx < qtd->urb->packet_count; idx++) {
  101163. + frame_desc = &qtd->urb->iso_descs[idx];
  101164. + frame_desc->status = err;
  101165. + }
  101166. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, err);
  101167. + dwc_otg_hcd_qtd_remove_and_free(hcd, qtd, qh);
  101168. + }
  101169. + return;
  101170. + }
  101171. +
  101172. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp, &hc->qh->qtd_list, qtd_list_entry) {
  101173. +
  101174. + if (!qtd->in_process)
  101175. + break;
  101176. +
  101177. + urb_compl = 0;
  101178. +
  101179. + do {
  101180. +
  101181. + dma_desc = &qh->desc_list[idx];
  101182. +
  101183. + frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
  101184. + remain = hc->ep_is_in ? dma_desc->status.b_isoc.n_bytes : 0;
  101185. +
  101186. + if (dma_desc->status.b_isoc.sts == DMA_DESC_STS_PKTERR) {
  101187. + /*
  101188. + * XactError or, unable to complete all the transactions
  101189. + * in the scheduled micro-frame/frame,
  101190. + * both indicated by DMA_DESC_STS_PKTERR.
  101191. + */
  101192. + qtd->urb->error_count++;
  101193. + frame_desc->actual_length = qh->n_bytes[idx] - remain;
  101194. + frame_desc->status = -DWC_E_PROTOCOL;
  101195. + } else {
  101196. + /* Success */
  101197. +
  101198. + frame_desc->actual_length = qh->n_bytes[idx] - remain;
  101199. + frame_desc->status = 0;
  101200. + }
  101201. +
  101202. + if (++qtd->isoc_frame_index == qtd->urb->packet_count) {
  101203. + /*
  101204. + * urb->status is not used for isoc transfers here.
  101205. + * The individual frame_desc status are used instead.
  101206. + */
  101207. +
  101208. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
  101209. + dwc_otg_hcd_qtd_remove_and_free(hcd, qtd, qh);
  101210. +
  101211. + /*
  101212. + * This check is necessary because urb_dequeue can be called
  101213. + * from urb complete callback(sound driver example).
  101214. + * All pending URBs are dequeued there, so no need for
  101215. + * further processing.
  101216. + */
  101217. + if (hc->halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE) {
  101218. + return;
  101219. + }
  101220. +
  101221. + urb_compl = 1;
  101222. +
  101223. + }
  101224. +
  101225. + qh->ntd--;
  101226. +
  101227. + /* Stop if IOC requested descriptor reached */
  101228. + if (dma_desc->status.b_isoc.ioc) {
  101229. + idx = desclist_idx_inc(idx, qh->interval, hc->speed);
  101230. + goto stop_scan;
  101231. + }
  101232. +
  101233. + idx = desclist_idx_inc(idx, qh->interval, hc->speed);
  101234. +
  101235. + if (urb_compl)
  101236. + break;
  101237. + }
  101238. + while (idx != qh->td_first);
  101239. + }
  101240. +stop_scan:
  101241. + qh->td_first = idx;
  101242. +}
  101243. +
  101244. +uint8_t update_non_isoc_urb_state_ddma(dwc_otg_hcd_t * hcd,
  101245. + dwc_hc_t * hc,
  101246. + dwc_otg_qtd_t * qtd,
  101247. + dwc_otg_host_dma_desc_t * dma_desc,
  101248. + dwc_otg_halt_status_e halt_status,
  101249. + uint32_t n_bytes, uint8_t * xfer_done)
  101250. +{
  101251. +
  101252. + uint16_t remain = hc->ep_is_in ? dma_desc->status.b.n_bytes : 0;
  101253. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  101254. +
  101255. + if (halt_status == DWC_OTG_HC_XFER_AHB_ERR) {
  101256. + urb->status = -DWC_E_IO;
  101257. + return 1;
  101258. + }
  101259. + if (dma_desc->status.b.sts == DMA_DESC_STS_PKTERR) {
  101260. + switch (halt_status) {
  101261. + case DWC_OTG_HC_XFER_STALL:
  101262. + urb->status = -DWC_E_PIPE;
  101263. + break;
  101264. + case DWC_OTG_HC_XFER_BABBLE_ERR:
  101265. + urb->status = -DWC_E_OVERFLOW;
  101266. + break;
  101267. + case DWC_OTG_HC_XFER_XACT_ERR:
  101268. + urb->status = -DWC_E_PROTOCOL;
  101269. + break;
  101270. + default:
  101271. + DWC_ERROR("%s: Unhandled descriptor error status (%d)\n", __func__,
  101272. + halt_status);
  101273. + break;
  101274. + }
  101275. + return 1;
  101276. + }
  101277. +
  101278. + if (dma_desc->status.b.a == 1) {
  101279. + DWC_DEBUGPL(DBG_HCDV,
  101280. + "Active descriptor encountered on channel %d\n",
  101281. + hc->hc_num);
  101282. + return 0;
  101283. + }
  101284. +
  101285. + if (hc->ep_type == DWC_OTG_EP_TYPE_CONTROL) {
  101286. + if (qtd->control_phase == DWC_OTG_CONTROL_DATA) {
  101287. + urb->actual_length += n_bytes - remain;
  101288. + if (remain || urb->actual_length == urb->length) {
  101289. + /*
  101290. + * For Control Data stage do not set urb->status=0 to prevent
  101291. + * URB callback. Set it when Status phase done. See below.
  101292. + */
  101293. + *xfer_done = 1;
  101294. + }
  101295. +
  101296. + } else if (qtd->control_phase == DWC_OTG_CONTROL_STATUS) {
  101297. + urb->status = 0;
  101298. + *xfer_done = 1;
  101299. + }
  101300. + /* No handling for SETUP stage */
  101301. + } else {
  101302. + /* BULK and INTR */
  101303. + urb->actual_length += n_bytes - remain;
  101304. + if (remain || urb->actual_length == urb->length) {
  101305. + urb->status = 0;
  101306. + *xfer_done = 1;
  101307. + }
  101308. + }
  101309. +
  101310. + return 0;
  101311. +}
  101312. +
  101313. +static void complete_non_isoc_xfer_ddma(dwc_otg_hcd_t * hcd,
  101314. + dwc_hc_t * hc,
  101315. + dwc_otg_hc_regs_t * hc_regs,
  101316. + dwc_otg_halt_status_e halt_status)
  101317. +{
  101318. + dwc_otg_hcd_urb_t *urb = NULL;
  101319. + dwc_otg_qtd_t *qtd, *qtd_tmp;
  101320. + dwc_otg_qh_t *qh;
  101321. + dwc_otg_host_dma_desc_t *dma_desc;
  101322. + uint32_t n_bytes, n_desc, i;
  101323. + uint8_t failed = 0, xfer_done;
  101324. +
  101325. + n_desc = 0;
  101326. +
  101327. + qh = hc->qh;
  101328. +
  101329. + if (hc->halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE) {
  101330. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp, &hc->qh->qtd_list, qtd_list_entry) {
  101331. + qtd->in_process = 0;
  101332. + }
  101333. + return;
  101334. + }
  101335. +
  101336. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp, &qh->qtd_list, qtd_list_entry) {
  101337. +
  101338. + urb = qtd->urb;
  101339. +
  101340. + n_bytes = 0;
  101341. + xfer_done = 0;
  101342. +
  101343. + for (i = 0; i < qtd->n_desc; i++) {
  101344. + dma_desc = &qh->desc_list[n_desc];
  101345. +
  101346. + n_bytes = qh->n_bytes[n_desc];
  101347. +
  101348. + failed =
  101349. + update_non_isoc_urb_state_ddma(hcd, hc, qtd,
  101350. + dma_desc,
  101351. + halt_status, n_bytes,
  101352. + &xfer_done);
  101353. +
  101354. + if (failed
  101355. + || (xfer_done
  101356. + && (urb->status != -DWC_E_IN_PROGRESS))) {
  101357. +
  101358. + hcd->fops->complete(hcd, urb->priv, urb,
  101359. + urb->status);
  101360. + dwc_otg_hcd_qtd_remove_and_free(hcd, qtd, qh);
  101361. +
  101362. + if (failed)
  101363. + goto stop_scan;
  101364. + } else if (qh->ep_type == UE_CONTROL) {
  101365. + if (qtd->control_phase == DWC_OTG_CONTROL_SETUP) {
  101366. + if (urb->length > 0) {
  101367. + qtd->control_phase = DWC_OTG_CONTROL_DATA;
  101368. + } else {
  101369. + qtd->control_phase = DWC_OTG_CONTROL_STATUS;
  101370. + }
  101371. + DWC_DEBUGPL(DBG_HCDV, " Control setup transaction done\n");
  101372. + } else if (qtd->control_phase == DWC_OTG_CONTROL_DATA) {
  101373. + if (xfer_done) {
  101374. + qtd->control_phase = DWC_OTG_CONTROL_STATUS;
  101375. + DWC_DEBUGPL(DBG_HCDV, " Control data transfer done\n");
  101376. + } else if (i + 1 == qtd->n_desc) {
  101377. + /*
  101378. + * Last descriptor for Control data stage which is
  101379. + * not completed yet.
  101380. + */
  101381. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  101382. + }
  101383. + }
  101384. + }
  101385. +
  101386. + n_desc++;
  101387. + }
  101388. +
  101389. + }
  101390. +
  101391. +stop_scan:
  101392. +
  101393. + if (qh->ep_type != UE_CONTROL) {
  101394. + /*
  101395. + * Resetting the data toggle for bulk
  101396. + * and interrupt endpoints in case of stall. See handle_hc_stall_intr()
  101397. + */
  101398. + if (halt_status == DWC_OTG_HC_XFER_STALL)
  101399. + qh->data_toggle = DWC_OTG_HC_PID_DATA0;
  101400. + else
  101401. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  101402. + }
  101403. +
  101404. + if (halt_status == DWC_OTG_HC_XFER_COMPLETE) {
  101405. + hcint_data_t hcint;
  101406. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  101407. + if (hcint.b.nyet) {
  101408. + /*
  101409. + * Got a NYET on the last transaction of the transfer. It
  101410. + * means that the endpoint should be in the PING state at the
  101411. + * beginning of the next transfer.
  101412. + */
  101413. + qh->ping_state = 1;
  101414. + clear_hc_int(hc_regs, nyet);
  101415. + }
  101416. +
  101417. + }
  101418. +
  101419. +}
  101420. +
  101421. +/**
  101422. + * This function is called from interrupt handlers.
  101423. + * Scans the descriptor list, updates URB's status and
  101424. + * calls completion routine for the URB if it's done.
  101425. + * Releases the channel to be used by other transfers.
  101426. + * In case of Isochronous endpoint the channel is not halted until
  101427. + * the end of the session, i.e. QTD list is empty.
  101428. + * If periodic channel released the FrameList is updated accordingly.
  101429. + *
  101430. + * Calls transaction selection routines to activate pending transfers.
  101431. + *
  101432. + * @param hcd The HCD state structure for the DWC OTG controller.
  101433. + * @param hc Host channel, the transfer is completed on.
  101434. + * @param hc_regs Host channel registers.
  101435. + * @param halt_status Reason the channel is being halted,
  101436. + * or just XferComplete for isochronous transfer
  101437. + */
  101438. +void dwc_otg_hcd_complete_xfer_ddma(dwc_otg_hcd_t * hcd,
  101439. + dwc_hc_t * hc,
  101440. + dwc_otg_hc_regs_t * hc_regs,
  101441. + dwc_otg_halt_status_e halt_status)
  101442. +{
  101443. + uint8_t continue_isoc_xfer = 0;
  101444. + dwc_otg_transaction_type_e tr_type;
  101445. + dwc_otg_qh_t *qh = hc->qh;
  101446. +
  101447. + if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  101448. +
  101449. + complete_isoc_xfer_ddma(hcd, hc, hc_regs, halt_status);
  101450. +
  101451. + /* Release the channel if halted or session completed */
  101452. + if (halt_status != DWC_OTG_HC_XFER_COMPLETE ||
  101453. + DWC_CIRCLEQ_EMPTY(&qh->qtd_list)) {
  101454. +
  101455. + /* Halt the channel if session completed */
  101456. + if (halt_status == DWC_OTG_HC_XFER_COMPLETE) {
  101457. + dwc_otg_hc_halt(hcd->core_if, hc, halt_status);
  101458. + }
  101459. +
  101460. + release_channel_ddma(hcd, qh);
  101461. + dwc_otg_hcd_qh_remove(hcd, qh);
  101462. + } else {
  101463. + /* Keep in assigned schedule to continue transfer */
  101464. + DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_assigned,
  101465. + &qh->qh_list_entry);
  101466. + continue_isoc_xfer = 1;
  101467. +
  101468. + }
  101469. + /** @todo Consider the case when period exceeds FrameList size.
  101470. + * Frame Rollover interrupt should be used.
  101471. + */
  101472. + } else {
  101473. + /* Scan descriptor list to complete the URB(s), then release the channel */
  101474. + complete_non_isoc_xfer_ddma(hcd, hc, hc_regs, halt_status);
  101475. +
  101476. + release_channel_ddma(hcd, qh);
  101477. + dwc_otg_hcd_qh_remove(hcd, qh);
  101478. +
  101479. + if (!DWC_CIRCLEQ_EMPTY(&qh->qtd_list)) {
  101480. + /* Add back to inactive non-periodic schedule on normal completion */
  101481. + dwc_otg_hcd_qh_add(hcd, qh);
  101482. + }
  101483. +
  101484. + }
  101485. + tr_type = dwc_otg_hcd_select_transactions(hcd);
  101486. + if (tr_type != DWC_OTG_TRANSACTION_NONE || continue_isoc_xfer) {
  101487. + if (continue_isoc_xfer) {
  101488. + if (tr_type == DWC_OTG_TRANSACTION_NONE) {
  101489. + tr_type = DWC_OTG_TRANSACTION_PERIODIC;
  101490. + } else if (tr_type == DWC_OTG_TRANSACTION_NON_PERIODIC) {
  101491. + tr_type = DWC_OTG_TRANSACTION_ALL;
  101492. + }
  101493. + }
  101494. + dwc_otg_hcd_queue_transactions(hcd, tr_type);
  101495. + }
  101496. +}
  101497. +
  101498. +#endif /* DWC_DEVICE_ONLY */
  101499. diff -Nur linux-3.18.8/drivers/usb/host/dwc_otg/dwc_otg_hcd.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd.h
  101500. --- linux-3.18.8/drivers/usb/host/dwc_otg/dwc_otg_hcd.h 1970-01-01 01:00:00.000000000 +0100
  101501. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd.h 2015-03-05 14:40:16.557715806 +0100
  101502. @@ -0,0 +1,862 @@
  101503. +/* ==========================================================================
  101504. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd.h $
  101505. + * $Revision: #58 $
  101506. + * $Date: 2011/09/15 $
  101507. + * $Change: 1846647 $
  101508. + *
  101509. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  101510. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  101511. + * otherwise expressly agreed to in writing between Synopsys and you.
  101512. + *
  101513. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  101514. + * any End User Software License Agreement or Agreement for Licensed Product
  101515. + * with Synopsys or any supplement thereto. You are permitted to use and
  101516. + * redistribute this Software in source and binary forms, with or without
  101517. + * modification, provided that redistributions of source code must retain this
  101518. + * notice. You may not view, use, disclose, copy or distribute this file or
  101519. + * any information contained herein except pursuant to this license grant from
  101520. + * Synopsys. If you do not agree with this notice, including the disclaimer
  101521. + * below, then you are not authorized to use the Software.
  101522. + *
  101523. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  101524. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  101525. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  101526. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  101527. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  101528. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  101529. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  101530. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  101531. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  101532. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  101533. + * DAMAGE.
  101534. + * ========================================================================== */
  101535. +#ifndef DWC_DEVICE_ONLY
  101536. +#ifndef __DWC_HCD_H__
  101537. +#define __DWC_HCD_H__
  101538. +
  101539. +#include "dwc_otg_os_dep.h"
  101540. +#include "usb.h"
  101541. +#include "dwc_otg_hcd_if.h"
  101542. +#include "dwc_otg_core_if.h"
  101543. +#include "dwc_list.h"
  101544. +#include "dwc_otg_cil.h"
  101545. +#include "dwc_otg_fiq_fsm.h"
  101546. +
  101547. +
  101548. +/**
  101549. + * @file
  101550. + *
  101551. + * This file contains the structures, constants, and interfaces for
  101552. + * the Host Contoller Driver (HCD).
  101553. + *
  101554. + * The Host Controller Driver (HCD) is responsible for translating requests
  101555. + * from the USB Driver into the appropriate actions on the DWC_otg controller.
  101556. + * It isolates the USBD from the specifics of the controller by providing an
  101557. + * API to the USBD.
  101558. + */
  101559. +
  101560. +struct dwc_otg_hcd_pipe_info {
  101561. + uint8_t dev_addr;
  101562. + uint8_t ep_num;
  101563. + uint8_t pipe_type;
  101564. + uint8_t pipe_dir;
  101565. + uint16_t mps;
  101566. +};
  101567. +
  101568. +struct dwc_otg_hcd_iso_packet_desc {
  101569. + uint32_t offset;
  101570. + uint32_t length;
  101571. + uint32_t actual_length;
  101572. + uint32_t status;
  101573. +};
  101574. +
  101575. +struct dwc_otg_qtd;
  101576. +
  101577. +struct dwc_otg_hcd_urb {
  101578. + void *priv;
  101579. + struct dwc_otg_qtd *qtd;
  101580. + void *buf;
  101581. + dwc_dma_t dma;
  101582. + void *setup_packet;
  101583. + dwc_dma_t setup_dma;
  101584. + uint32_t length;
  101585. + uint32_t actual_length;
  101586. + uint32_t status;
  101587. + uint32_t error_count;
  101588. + uint32_t packet_count;
  101589. + uint32_t flags;
  101590. + uint16_t interval;
  101591. + struct dwc_otg_hcd_pipe_info pipe_info;
  101592. + struct dwc_otg_hcd_iso_packet_desc iso_descs[0];
  101593. +};
  101594. +
  101595. +static inline uint8_t dwc_otg_hcd_get_ep_num(struct dwc_otg_hcd_pipe_info *pipe)
  101596. +{
  101597. + return pipe->ep_num;
  101598. +}
  101599. +
  101600. +static inline uint8_t dwc_otg_hcd_get_pipe_type(struct dwc_otg_hcd_pipe_info
  101601. + *pipe)
  101602. +{
  101603. + return pipe->pipe_type;
  101604. +}
  101605. +
  101606. +static inline uint16_t dwc_otg_hcd_get_mps(struct dwc_otg_hcd_pipe_info *pipe)
  101607. +{
  101608. + return pipe->mps;
  101609. +}
  101610. +
  101611. +static inline uint8_t dwc_otg_hcd_get_dev_addr(struct dwc_otg_hcd_pipe_info
  101612. + *pipe)
  101613. +{
  101614. + return pipe->dev_addr;
  101615. +}
  101616. +
  101617. +static inline uint8_t dwc_otg_hcd_is_pipe_isoc(struct dwc_otg_hcd_pipe_info
  101618. + *pipe)
  101619. +{
  101620. + return (pipe->pipe_type == UE_ISOCHRONOUS);
  101621. +}
  101622. +
  101623. +static inline uint8_t dwc_otg_hcd_is_pipe_int(struct dwc_otg_hcd_pipe_info
  101624. + *pipe)
  101625. +{
  101626. + return (pipe->pipe_type == UE_INTERRUPT);
  101627. +}
  101628. +
  101629. +static inline uint8_t dwc_otg_hcd_is_pipe_bulk(struct dwc_otg_hcd_pipe_info
  101630. + *pipe)
  101631. +{
  101632. + return (pipe->pipe_type == UE_BULK);
  101633. +}
  101634. +
  101635. +static inline uint8_t dwc_otg_hcd_is_pipe_control(struct dwc_otg_hcd_pipe_info
  101636. + *pipe)
  101637. +{
  101638. + return (pipe->pipe_type == UE_CONTROL);
  101639. +}
  101640. +
  101641. +static inline uint8_t dwc_otg_hcd_is_pipe_in(struct dwc_otg_hcd_pipe_info *pipe)
  101642. +{
  101643. + return (pipe->pipe_dir == UE_DIR_IN);
  101644. +}
  101645. +
  101646. +static inline uint8_t dwc_otg_hcd_is_pipe_out(struct dwc_otg_hcd_pipe_info
  101647. + *pipe)
  101648. +{
  101649. + return (!dwc_otg_hcd_is_pipe_in(pipe));
  101650. +}
  101651. +
  101652. +static inline void dwc_otg_hcd_fill_pipe(struct dwc_otg_hcd_pipe_info *pipe,
  101653. + uint8_t devaddr, uint8_t ep_num,
  101654. + uint8_t pipe_type, uint8_t pipe_dir,
  101655. + uint16_t mps)
  101656. +{
  101657. + pipe->dev_addr = devaddr;
  101658. + pipe->ep_num = ep_num;
  101659. + pipe->pipe_type = pipe_type;
  101660. + pipe->pipe_dir = pipe_dir;
  101661. + pipe->mps = mps;
  101662. +}
  101663. +
  101664. +/**
  101665. + * Phases for control transfers.
  101666. + */
  101667. +typedef enum dwc_otg_control_phase {
  101668. + DWC_OTG_CONTROL_SETUP,
  101669. + DWC_OTG_CONTROL_DATA,
  101670. + DWC_OTG_CONTROL_STATUS
  101671. +} dwc_otg_control_phase_e;
  101672. +
  101673. +/** Transaction types. */
  101674. +typedef enum dwc_otg_transaction_type {
  101675. + DWC_OTG_TRANSACTION_NONE = 0,
  101676. + DWC_OTG_TRANSACTION_PERIODIC = 1,
  101677. + DWC_OTG_TRANSACTION_NON_PERIODIC = 2,
  101678. + DWC_OTG_TRANSACTION_ALL = DWC_OTG_TRANSACTION_PERIODIC + DWC_OTG_TRANSACTION_NON_PERIODIC
  101679. +} dwc_otg_transaction_type_e;
  101680. +
  101681. +struct dwc_otg_qh;
  101682. +
  101683. +/**
  101684. + * A Queue Transfer Descriptor (QTD) holds the state of a bulk, control,
  101685. + * interrupt, or isochronous transfer. A single QTD is created for each URB
  101686. + * (of one of these types) submitted to the HCD. The transfer associated with
  101687. + * a QTD may require one or multiple transactions.
  101688. + *
  101689. + * A QTD is linked to a Queue Head, which is entered in either the
  101690. + * non-periodic or periodic schedule for execution. When a QTD is chosen for
  101691. + * execution, some or all of its transactions may be executed. After
  101692. + * execution, the state of the QTD is updated. The QTD may be retired if all
  101693. + * its transactions are complete or if an error occurred. Otherwise, it
  101694. + * remains in the schedule so more transactions can be executed later.
  101695. + */
  101696. +typedef struct dwc_otg_qtd {
  101697. + /**
  101698. + * Determines the PID of the next data packet for the data phase of
  101699. + * control transfers. Ignored for other transfer types.<br>
  101700. + * One of the following values:
  101701. + * - DWC_OTG_HC_PID_DATA0
  101702. + * - DWC_OTG_HC_PID_DATA1
  101703. + */
  101704. + uint8_t data_toggle;
  101705. +
  101706. + /** Current phase for control transfers (Setup, Data, or Status). */
  101707. + dwc_otg_control_phase_e control_phase;
  101708. +
  101709. + /** Keep track of the current split type
  101710. + * for FS/LS endpoints on a HS Hub */
  101711. + uint8_t complete_split;
  101712. +
  101713. + /** How many bytes transferred during SSPLIT OUT */
  101714. + uint32_t ssplit_out_xfer_count;
  101715. +
  101716. + /**
  101717. + * Holds the number of bus errors that have occurred for a transaction
  101718. + * within this transfer.
  101719. + */
  101720. + uint8_t error_count;
  101721. +
  101722. + /**
  101723. + * Index of the next frame descriptor for an isochronous transfer. A
  101724. + * frame descriptor describes the buffer position and length of the
  101725. + * data to be transferred in the next scheduled (micro)frame of an
  101726. + * isochronous transfer. It also holds status for that transaction.
  101727. + * The frame index starts at 0.
  101728. + */
  101729. + uint16_t isoc_frame_index;
  101730. +
  101731. + /** Position of the ISOC split on full/low speed */
  101732. + uint8_t isoc_split_pos;
  101733. +
  101734. + /** Position of the ISOC split in the buffer for the current frame */
  101735. + uint16_t isoc_split_offset;
  101736. +
  101737. + /** URB for this transfer */
  101738. + struct dwc_otg_hcd_urb *urb;
  101739. +
  101740. + struct dwc_otg_qh *qh;
  101741. +
  101742. + /** This list of QTDs */
  101743. + DWC_CIRCLEQ_ENTRY(dwc_otg_qtd) qtd_list_entry;
  101744. +
  101745. + /** Indicates if this QTD is currently processed by HW. */
  101746. + uint8_t in_process;
  101747. +
  101748. + /** Number of DMA descriptors for this QTD */
  101749. + uint8_t n_desc;
  101750. +
  101751. + /**
  101752. + * Last activated frame(packet) index.
  101753. + * Used in Descriptor DMA mode only.
  101754. + */
  101755. + uint16_t isoc_frame_index_last;
  101756. +
  101757. +} dwc_otg_qtd_t;
  101758. +
  101759. +DWC_CIRCLEQ_HEAD(dwc_otg_qtd_list, dwc_otg_qtd);
  101760. +
  101761. +/**
  101762. + * A Queue Head (QH) holds the static characteristics of an endpoint and
  101763. + * maintains a list of transfers (QTDs) for that endpoint. A QH structure may
  101764. + * be entered in either the non-periodic or periodic schedule.
  101765. + */
  101766. +typedef struct dwc_otg_qh {
  101767. + /**
  101768. + * Endpoint type.
  101769. + * One of the following values:
  101770. + * - UE_CONTROL
  101771. + * - UE_BULK
  101772. + * - UE_INTERRUPT
  101773. + * - UE_ISOCHRONOUS
  101774. + */
  101775. + uint8_t ep_type;
  101776. + uint8_t ep_is_in;
  101777. +
  101778. + /** wMaxPacketSize Field of Endpoint Descriptor. */
  101779. + uint16_t maxp;
  101780. +
  101781. + /**
  101782. + * Device speed.
  101783. + * One of the following values:
  101784. + * - DWC_OTG_EP_SPEED_LOW
  101785. + * - DWC_OTG_EP_SPEED_FULL
  101786. + * - DWC_OTG_EP_SPEED_HIGH
  101787. + */
  101788. + uint8_t dev_speed;
  101789. +
  101790. + /**
  101791. + * Determines the PID of the next data packet for non-control
  101792. + * transfers. Ignored for control transfers.<br>
  101793. + * One of the following values:
  101794. + * - DWC_OTG_HC_PID_DATA0
  101795. + * - DWC_OTG_HC_PID_DATA1
  101796. + */
  101797. + uint8_t data_toggle;
  101798. +
  101799. + /** Ping state if 1. */
  101800. + uint8_t ping_state;
  101801. +
  101802. + /**
  101803. + * List of QTDs for this QH.
  101804. + */
  101805. + struct dwc_otg_qtd_list qtd_list;
  101806. +
  101807. + /** Host channel currently processing transfers for this QH. */
  101808. + struct dwc_hc *channel;
  101809. +
  101810. + /** Full/low speed endpoint on high-speed hub requires split. */
  101811. + uint8_t do_split;
  101812. +
  101813. + /** @name Periodic schedule information */
  101814. + /** @{ */
  101815. +
  101816. + /** Bandwidth in microseconds per (micro)frame. */
  101817. + uint16_t usecs;
  101818. +
  101819. + /** Interval between transfers in (micro)frames. */
  101820. + uint16_t interval;
  101821. +
  101822. + /**
  101823. + * (micro)frame to initialize a periodic transfer. The transfer
  101824. + * executes in the following (micro)frame.
  101825. + */
  101826. + uint16_t sched_frame;
  101827. +
  101828. + /*
  101829. + ** Frame a NAK was received on this queue head, used to minimise NAK retransmission
  101830. + */
  101831. + uint16_t nak_frame;
  101832. +
  101833. + /** (micro)frame at which last start split was initialized. */
  101834. + uint16_t start_split_frame;
  101835. +
  101836. + /** @} */
  101837. +
  101838. + /**
  101839. + * Used instead of original buffer if
  101840. + * it(physical address) is not dword-aligned.
  101841. + */
  101842. + uint8_t *dw_align_buf;
  101843. + dwc_dma_t dw_align_buf_dma;
  101844. +
  101845. + /** Entry for QH in either the periodic or non-periodic schedule. */
  101846. + dwc_list_link_t qh_list_entry;
  101847. +
  101848. + /** @name Descriptor DMA support */
  101849. + /** @{ */
  101850. +
  101851. + /** Descriptor List. */
  101852. + dwc_otg_host_dma_desc_t *desc_list;
  101853. +
  101854. + /** Descriptor List physical address. */
  101855. + dwc_dma_t desc_list_dma;
  101856. +
  101857. + /**
  101858. + * Xfer Bytes array.
  101859. + * Each element corresponds to a descriptor and indicates
  101860. + * original XferSize size value for the descriptor.
  101861. + */
  101862. + uint32_t *n_bytes;
  101863. +
  101864. + /** Actual number of transfer descriptors in a list. */
  101865. + uint16_t ntd;
  101866. +
  101867. + /** First activated isochronous transfer descriptor index. */
  101868. + uint8_t td_first;
  101869. + /** Last activated isochronous transfer descriptor index. */
  101870. + uint8_t td_last;
  101871. +
  101872. + /** @} */
  101873. +
  101874. +
  101875. + uint16_t speed;
  101876. + uint16_t frame_usecs[8];
  101877. +
  101878. + uint32_t skip_count;
  101879. +} dwc_otg_qh_t;
  101880. +
  101881. +DWC_CIRCLEQ_HEAD(hc_list, dwc_hc);
  101882. +
  101883. +typedef struct urb_tq_entry {
  101884. + struct urb *urb;
  101885. + DWC_TAILQ_ENTRY(urb_tq_entry) urb_tq_entries;
  101886. +} urb_tq_entry_t;
  101887. +
  101888. +DWC_TAILQ_HEAD(urb_list, urb_tq_entry);
  101889. +
  101890. +/**
  101891. + * This structure holds the state of the HCD, including the non-periodic and
  101892. + * periodic schedules.
  101893. + */
  101894. +struct dwc_otg_hcd {
  101895. + /** The DWC otg device pointer */
  101896. + struct dwc_otg_device *otg_dev;
  101897. + /** DWC OTG Core Interface Layer */
  101898. + dwc_otg_core_if_t *core_if;
  101899. +
  101900. + /** Function HCD driver callbacks */
  101901. + struct dwc_otg_hcd_function_ops *fops;
  101902. +
  101903. + /** Internal DWC HCD Flags */
  101904. + volatile union dwc_otg_hcd_internal_flags {
  101905. + uint32_t d32;
  101906. + struct {
  101907. + unsigned port_connect_status_change:1;
  101908. + unsigned port_connect_status:1;
  101909. + unsigned port_reset_change:1;
  101910. + unsigned port_enable_change:1;
  101911. + unsigned port_suspend_change:1;
  101912. + unsigned port_over_current_change:1;
  101913. + unsigned port_l1_change:1;
  101914. + unsigned reserved:26;
  101915. + } b;
  101916. + } flags;
  101917. +
  101918. + /**
  101919. + * Inactive items in the non-periodic schedule. This is a list of
  101920. + * Queue Heads. Transfers associated with these Queue Heads are not
  101921. + * currently assigned to a host channel.
  101922. + */
  101923. + dwc_list_link_t non_periodic_sched_inactive;
  101924. +
  101925. + /**
  101926. + * Active items in the non-periodic schedule. This is a list of
  101927. + * Queue Heads. Transfers associated with these Queue Heads are
  101928. + * currently assigned to a host channel.
  101929. + */
  101930. + dwc_list_link_t non_periodic_sched_active;
  101931. +
  101932. + /**
  101933. + * Pointer to the next Queue Head to process in the active
  101934. + * non-periodic schedule.
  101935. + */
  101936. + dwc_list_link_t *non_periodic_qh_ptr;
  101937. +
  101938. + /**
  101939. + * Inactive items in the periodic schedule. This is a list of QHs for
  101940. + * periodic transfers that are _not_ scheduled for the next frame.
  101941. + * Each QH in the list has an interval counter that determines when it
  101942. + * needs to be scheduled for execution. This scheduling mechanism
  101943. + * allows only a simple calculation for periodic bandwidth used (i.e.
  101944. + * must assume that all periodic transfers may need to execute in the
  101945. + * same frame). However, it greatly simplifies scheduling and should
  101946. + * be sufficient for the vast majority of OTG hosts, which need to
  101947. + * connect to a small number of peripherals at one time.
  101948. + *
  101949. + * Items move from this list to periodic_sched_ready when the QH
  101950. + * interval counter is 0 at SOF.
  101951. + */
  101952. + dwc_list_link_t periodic_sched_inactive;
  101953. +
  101954. + /**
  101955. + * List of periodic QHs that are ready for execution in the next
  101956. + * frame, but have not yet been assigned to host channels.
  101957. + *
  101958. + * Items move from this list to periodic_sched_assigned as host
  101959. + * channels become available during the current frame.
  101960. + */
  101961. + dwc_list_link_t periodic_sched_ready;
  101962. +
  101963. + /**
  101964. + * List of periodic QHs to be executed in the next frame that are
  101965. + * assigned to host channels.
  101966. + *
  101967. + * Items move from this list to periodic_sched_queued as the
  101968. + * transactions for the QH are queued to the DWC_otg controller.
  101969. + */
  101970. + dwc_list_link_t periodic_sched_assigned;
  101971. +
  101972. + /**
  101973. + * List of periodic QHs that have been queued for execution.
  101974. + *
  101975. + * Items move from this list to either periodic_sched_inactive or
  101976. + * periodic_sched_ready when the channel associated with the transfer
  101977. + * is released. If the interval for the QH is 1, the item moves to
  101978. + * periodic_sched_ready because it must be rescheduled for the next
  101979. + * frame. Otherwise, the item moves to periodic_sched_inactive.
  101980. + */
  101981. + dwc_list_link_t periodic_sched_queued;
  101982. +
  101983. + /**
  101984. + * Total bandwidth claimed so far for periodic transfers. This value
  101985. + * is in microseconds per (micro)frame. The assumption is that all
  101986. + * periodic transfers may occur in the same (micro)frame.
  101987. + */
  101988. + uint16_t periodic_usecs;
  101989. +
  101990. + /**
  101991. + * Total bandwidth claimed so far for all periodic transfers
  101992. + * in a frame.
  101993. + * This will include a mixture of HS and FS transfers.
  101994. + * Units are microseconds per (micro)frame.
  101995. + * We have a budget per frame and have to schedule
  101996. + * transactions accordingly.
  101997. + * Watch out for the fact that things are actually scheduled for the
  101998. + * "next frame".
  101999. + */
  102000. + uint16_t frame_usecs[8];
  102001. +
  102002. +
  102003. + /**
  102004. + * Frame number read from the core at SOF. The value ranges from 0 to
  102005. + * DWC_HFNUM_MAX_FRNUM.
  102006. + */
  102007. + uint16_t frame_number;
  102008. +
  102009. + /**
  102010. + * Count of periodic QHs, if using several eps. For SOF enable/disable.
  102011. + */
  102012. + uint16_t periodic_qh_count;
  102013. +
  102014. + /**
  102015. + * Free host channels in the controller. This is a list of
  102016. + * dwc_hc_t items.
  102017. + */
  102018. + struct hc_list free_hc_list;
  102019. + /**
  102020. + * Number of host channels assigned to periodic transfers. Currently
  102021. + * assuming that there is a dedicated host channel for each periodic
  102022. + * transaction and at least one host channel available for
  102023. + * non-periodic transactions.
  102024. + */
  102025. + int periodic_channels; /* microframe_schedule==0 */
  102026. +
  102027. + /**
  102028. + * Number of host channels assigned to non-periodic transfers.
  102029. + */
  102030. + int non_periodic_channels; /* microframe_schedule==0 */
  102031. +
  102032. + /**
  102033. + * Number of host channels assigned to non-periodic transfers.
  102034. + */
  102035. + int available_host_channels;
  102036. +
  102037. + /**
  102038. + * Array of pointers to the host channel descriptors. Allows accessing
  102039. + * a host channel descriptor given the host channel number. This is
  102040. + * useful in interrupt handlers.
  102041. + */
  102042. + struct dwc_hc *hc_ptr_array[MAX_EPS_CHANNELS];
  102043. +
  102044. + /**
  102045. + * Buffer to use for any data received during the status phase of a
  102046. + * control transfer. Normally no data is transferred during the status
  102047. + * phase. This buffer is used as a bit bucket.
  102048. + */
  102049. + uint8_t *status_buf;
  102050. +
  102051. + /**
  102052. + * DMA address for status_buf.
  102053. + */
  102054. + dma_addr_t status_buf_dma;
  102055. +#define DWC_OTG_HCD_STATUS_BUF_SIZE 64
  102056. +
  102057. + /**
  102058. + * Connection timer. An OTG host must display a message if the device
  102059. + * does not connect. Started when the VBus power is turned on via
  102060. + * sysfs attribute "buspower".
  102061. + */
  102062. + dwc_timer_t *conn_timer;
  102063. +
  102064. + /* Tasket to do a reset */
  102065. + dwc_tasklet_t *reset_tasklet;
  102066. +
  102067. + dwc_tasklet_t *completion_tasklet;
  102068. + struct urb_list completed_urb_list;
  102069. +
  102070. + /* */
  102071. + dwc_spinlock_t *lock;
  102072. + dwc_spinlock_t *channel_lock;
  102073. + /**
  102074. + * Private data that could be used by OS wrapper.
  102075. + */
  102076. + void *priv;
  102077. +
  102078. + uint8_t otg_port;
  102079. +
  102080. + /** Frame List */
  102081. + uint32_t *frame_list;
  102082. +
  102083. + /** Hub - Port assignment */
  102084. + int hub_port[128];
  102085. +#ifdef FIQ_DEBUG
  102086. + int hub_port_alloc[2048];
  102087. +#endif
  102088. +
  102089. + /** Frame List DMA address */
  102090. + dma_addr_t frame_list_dma;
  102091. +
  102092. + struct fiq_stack *fiq_stack;
  102093. + struct fiq_state *fiq_state;
  102094. +
  102095. + /** Virtual address for split transaction DMA bounce buffers */
  102096. + struct fiq_dma_blob *fiq_dmab;
  102097. +
  102098. +#ifdef DEBUG
  102099. + uint32_t frrem_samples;
  102100. + uint64_t frrem_accum;
  102101. +
  102102. + uint32_t hfnum_7_samples_a;
  102103. + uint64_t hfnum_7_frrem_accum_a;
  102104. + uint32_t hfnum_0_samples_a;
  102105. + uint64_t hfnum_0_frrem_accum_a;
  102106. + uint32_t hfnum_other_samples_a;
  102107. + uint64_t hfnum_other_frrem_accum_a;
  102108. +
  102109. + uint32_t hfnum_7_samples_b;
  102110. + uint64_t hfnum_7_frrem_accum_b;
  102111. + uint32_t hfnum_0_samples_b;
  102112. + uint64_t hfnum_0_frrem_accum_b;
  102113. + uint32_t hfnum_other_samples_b;
  102114. + uint64_t hfnum_other_frrem_accum_b;
  102115. +#endif
  102116. +};
  102117. +
  102118. +/** @name Transaction Execution Functions */
  102119. +/** @{ */
  102120. +extern dwc_otg_transaction_type_e dwc_otg_hcd_select_transactions(dwc_otg_hcd_t
  102121. + * hcd);
  102122. +extern void dwc_otg_hcd_queue_transactions(dwc_otg_hcd_t * hcd,
  102123. + dwc_otg_transaction_type_e tr_type);
  102124. +
  102125. +int dwc_otg_hcd_allocate_port(dwc_otg_hcd_t * hcd, dwc_otg_qh_t *qh);
  102126. +void dwc_otg_hcd_release_port(dwc_otg_hcd_t * dwc_otg_hcd, dwc_otg_qh_t *qh);
  102127. +
  102128. +extern int fiq_fsm_queue_transaction(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh);
  102129. +extern int fiq_fsm_transaction_suitable(dwc_otg_qh_t *qh);
  102130. +extern void dwc_otg_cleanup_fiq_channel(dwc_otg_hcd_t *hcd, uint32_t num);
  102131. +
  102132. +/** @} */
  102133. +
  102134. +/** @name Interrupt Handler Functions */
  102135. +/** @{ */
  102136. +extern int32_t dwc_otg_hcd_handle_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  102137. +extern int32_t dwc_otg_hcd_handle_sof_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  102138. +extern int32_t dwc_otg_hcd_handle_rx_status_q_level_intr(dwc_otg_hcd_t *
  102139. + dwc_otg_hcd);
  102140. +extern int32_t dwc_otg_hcd_handle_np_tx_fifo_empty_intr(dwc_otg_hcd_t *
  102141. + dwc_otg_hcd);
  102142. +extern int32_t dwc_otg_hcd_handle_perio_tx_fifo_empty_intr(dwc_otg_hcd_t *
  102143. + dwc_otg_hcd);
  102144. +extern int32_t dwc_otg_hcd_handle_incomplete_periodic_intr(dwc_otg_hcd_t *
  102145. + dwc_otg_hcd);
  102146. +extern int32_t dwc_otg_hcd_handle_port_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  102147. +extern int32_t dwc_otg_hcd_handle_conn_id_status_change_intr(dwc_otg_hcd_t *
  102148. + dwc_otg_hcd);
  102149. +extern int32_t dwc_otg_hcd_handle_disconnect_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  102150. +extern int32_t dwc_otg_hcd_handle_hc_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  102151. +extern int32_t dwc_otg_hcd_handle_hc_n_intr(dwc_otg_hcd_t * dwc_otg_hcd,
  102152. + uint32_t num);
  102153. +extern int32_t dwc_otg_hcd_handle_session_req_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  102154. +extern int32_t dwc_otg_hcd_handle_wakeup_detected_intr(dwc_otg_hcd_t *
  102155. + dwc_otg_hcd);
  102156. +/** @} */
  102157. +
  102158. +/** @name Schedule Queue Functions */
  102159. +/** @{ */
  102160. +
  102161. +/* Implemented in dwc_otg_hcd_queue.c */
  102162. +extern dwc_otg_qh_t *dwc_otg_hcd_qh_create(dwc_otg_hcd_t * hcd,
  102163. + dwc_otg_hcd_urb_t * urb, int atomic_alloc);
  102164. +extern void dwc_otg_hcd_qh_free(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh);
  102165. +extern int dwc_otg_hcd_qh_add(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh);
  102166. +extern void dwc_otg_hcd_qh_remove(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh);
  102167. +extern void dwc_otg_hcd_qh_deactivate(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh,
  102168. + int sched_csplit);
  102169. +
  102170. +/** Remove and free a QH */
  102171. +static inline void dwc_otg_hcd_qh_remove_and_free(dwc_otg_hcd_t * hcd,
  102172. + dwc_otg_qh_t * qh)
  102173. +{
  102174. + dwc_irqflags_t flags;
  102175. + DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
  102176. + dwc_otg_hcd_qh_remove(hcd, qh);
  102177. + DWC_SPINUNLOCK_IRQRESTORE(hcd->lock, flags);
  102178. + dwc_otg_hcd_qh_free(hcd, qh);
  102179. +}
  102180. +
  102181. +/** Allocates memory for a QH structure.
  102182. + * @return Returns the memory allocate or NULL on error. */
  102183. +static inline dwc_otg_qh_t *dwc_otg_hcd_qh_alloc(int atomic_alloc)
  102184. +{
  102185. + if (atomic_alloc)
  102186. + return (dwc_otg_qh_t *) DWC_ALLOC_ATOMIC(sizeof(dwc_otg_qh_t));
  102187. + else
  102188. + return (dwc_otg_qh_t *) DWC_ALLOC(sizeof(dwc_otg_qh_t));
  102189. +}
  102190. +
  102191. +extern dwc_otg_qtd_t *dwc_otg_hcd_qtd_create(dwc_otg_hcd_urb_t * urb,
  102192. + int atomic_alloc);
  102193. +extern void dwc_otg_hcd_qtd_init(dwc_otg_qtd_t * qtd, dwc_otg_hcd_urb_t * urb);
  102194. +extern int dwc_otg_hcd_qtd_add(dwc_otg_qtd_t * qtd, dwc_otg_hcd_t * dwc_otg_hcd,
  102195. + dwc_otg_qh_t ** qh, int atomic_alloc);
  102196. +
  102197. +/** Allocates memory for a QTD structure.
  102198. + * @return Returns the memory allocate or NULL on error. */
  102199. +static inline dwc_otg_qtd_t *dwc_otg_hcd_qtd_alloc(int atomic_alloc)
  102200. +{
  102201. + if (atomic_alloc)
  102202. + return (dwc_otg_qtd_t *) DWC_ALLOC_ATOMIC(sizeof(dwc_otg_qtd_t));
  102203. + else
  102204. + return (dwc_otg_qtd_t *) DWC_ALLOC(sizeof(dwc_otg_qtd_t));
  102205. +}
  102206. +
  102207. +/** Frees the memory for a QTD structure. QTD should already be removed from
  102208. + * list.
  102209. + * @param qtd QTD to free.*/
  102210. +static inline void dwc_otg_hcd_qtd_free(dwc_otg_qtd_t * qtd)
  102211. +{
  102212. + DWC_FREE(qtd);
  102213. +}
  102214. +
  102215. +/** Removes a QTD from list.
  102216. + * @param hcd HCD instance.
  102217. + * @param qtd QTD to remove from list.
  102218. + * @param qh QTD belongs to.
  102219. + */
  102220. +static inline void dwc_otg_hcd_qtd_remove(dwc_otg_hcd_t * hcd,
  102221. + dwc_otg_qtd_t * qtd,
  102222. + dwc_otg_qh_t * qh)
  102223. +{
  102224. + DWC_CIRCLEQ_REMOVE(&qh->qtd_list, qtd, qtd_list_entry);
  102225. +}
  102226. +
  102227. +/** Remove and free a QTD
  102228. + * Need to disable IRQ and hold hcd lock while calling this function out of
  102229. + * interrupt servicing chain */
  102230. +static inline void dwc_otg_hcd_qtd_remove_and_free(dwc_otg_hcd_t * hcd,
  102231. + dwc_otg_qtd_t * qtd,
  102232. + dwc_otg_qh_t * qh)
  102233. +{
  102234. + dwc_otg_hcd_qtd_remove(hcd, qtd, qh);
  102235. + dwc_otg_hcd_qtd_free(qtd);
  102236. +}
  102237. +
  102238. +/** @} */
  102239. +
  102240. +/** @name Descriptor DMA Supporting Functions */
  102241. +/** @{ */
  102242. +
  102243. +extern void dwc_otg_hcd_start_xfer_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh);
  102244. +extern void dwc_otg_hcd_complete_xfer_ddma(dwc_otg_hcd_t * hcd,
  102245. + dwc_hc_t * hc,
  102246. + dwc_otg_hc_regs_t * hc_regs,
  102247. + dwc_otg_halt_status_e halt_status);
  102248. +
  102249. +extern int dwc_otg_hcd_qh_init_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh);
  102250. +extern void dwc_otg_hcd_qh_free_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh);
  102251. +
  102252. +/** @} */
  102253. +
  102254. +/** @name Internal Functions */
  102255. +/** @{ */
  102256. +dwc_otg_qh_t *dwc_urb_to_qh(dwc_otg_hcd_urb_t * urb);
  102257. +/** @} */
  102258. +
  102259. +#ifdef CONFIG_USB_DWC_OTG_LPM
  102260. +extern int dwc_otg_hcd_get_hc_for_lpm_tran(dwc_otg_hcd_t * hcd,
  102261. + uint8_t devaddr);
  102262. +extern void dwc_otg_hcd_free_hc_from_lpm(dwc_otg_hcd_t * hcd);
  102263. +#endif
  102264. +
  102265. +/** Gets the QH that contains the list_head */
  102266. +#define dwc_list_to_qh(_list_head_ptr_) container_of(_list_head_ptr_, dwc_otg_qh_t, qh_list_entry)
  102267. +
  102268. +/** Gets the QTD that contains the list_head */
  102269. +#define dwc_list_to_qtd(_list_head_ptr_) container_of(_list_head_ptr_, dwc_otg_qtd_t, qtd_list_entry)
  102270. +
  102271. +/** Check if QH is non-periodic */
  102272. +#define dwc_qh_is_non_per(_qh_ptr_) ((_qh_ptr_->ep_type == UE_BULK) || \
  102273. + (_qh_ptr_->ep_type == UE_CONTROL))
  102274. +
  102275. +/** High bandwidth multiplier as encoded in highspeed endpoint descriptors */
  102276. +#define dwc_hb_mult(wMaxPacketSize) (1 + (((wMaxPacketSize) >> 11) & 0x03))
  102277. +
  102278. +/** Packet size for any kind of endpoint descriptor */
  102279. +#define dwc_max_packet(wMaxPacketSize) ((wMaxPacketSize) & 0x07ff)
  102280. +
  102281. +/**
  102282. + * Returns true if _frame1 is less than or equal to _frame2. The comparison is
  102283. + * done modulo DWC_HFNUM_MAX_FRNUM. This accounts for the rollover of the
  102284. + * frame number when the max frame number is reached.
  102285. + */
  102286. +static inline int dwc_frame_num_le(uint16_t frame1, uint16_t frame2)
  102287. +{
  102288. + return ((frame2 - frame1) & DWC_HFNUM_MAX_FRNUM) <=
  102289. + (DWC_HFNUM_MAX_FRNUM >> 1);
  102290. +}
  102291. +
  102292. +/**
  102293. + * Returns true if _frame1 is greater than _frame2. The comparison is done
  102294. + * modulo DWC_HFNUM_MAX_FRNUM. This accounts for the rollover of the frame
  102295. + * number when the max frame number is reached.
  102296. + */
  102297. +static inline int dwc_frame_num_gt(uint16_t frame1, uint16_t frame2)
  102298. +{
  102299. + return (frame1 != frame2) &&
  102300. + (((frame1 - frame2) & DWC_HFNUM_MAX_FRNUM) <
  102301. + (DWC_HFNUM_MAX_FRNUM >> 1));
  102302. +}
  102303. +
  102304. +/**
  102305. + * Increments _frame by the amount specified by _inc. The addition is done
  102306. + * modulo DWC_HFNUM_MAX_FRNUM. Returns the incremented value.
  102307. + */
  102308. +static inline uint16_t dwc_frame_num_inc(uint16_t frame, uint16_t inc)
  102309. +{
  102310. + return (frame + inc) & DWC_HFNUM_MAX_FRNUM;
  102311. +}
  102312. +
  102313. +static inline uint16_t dwc_full_frame_num(uint16_t frame)
  102314. +{
  102315. + return (frame & DWC_HFNUM_MAX_FRNUM) >> 3;
  102316. +}
  102317. +
  102318. +static inline uint16_t dwc_micro_frame_num(uint16_t frame)
  102319. +{
  102320. + return frame & 0x7;
  102321. +}
  102322. +
  102323. +void dwc_otg_hcd_save_data_toggle(dwc_hc_t * hc,
  102324. + dwc_otg_hc_regs_t * hc_regs,
  102325. + dwc_otg_qtd_t * qtd);
  102326. +
  102327. +#ifdef DEBUG
  102328. +/**
  102329. + * Macro to sample the remaining PHY clocks left in the current frame. This
  102330. + * may be used during debugging to determine the average time it takes to
  102331. + * execute sections of code. There are two possible sample points, "a" and
  102332. + * "b", so the _letter argument must be one of these values.
  102333. + *
  102334. + * To dump the average sample times, read the "hcd_frrem" sysfs attribute. For
  102335. + * example, "cat /sys/devices/lm0/hcd_frrem".
  102336. + */
  102337. +#define dwc_sample_frrem(_hcd, _qh, _letter) \
  102338. +{ \
  102339. + hfnum_data_t hfnum; \
  102340. + dwc_otg_qtd_t *qtd; \
  102341. + qtd = list_entry(_qh->qtd_list.next, dwc_otg_qtd_t, qtd_list_entry); \
  102342. + if (usb_pipeint(qtd->urb->pipe) && _qh->start_split_frame != 0 && !qtd->complete_split) { \
  102343. + hfnum.d32 = DWC_READ_REG32(&_hcd->core_if->host_if->host_global_regs->hfnum); \
  102344. + switch (hfnum.b.frnum & 0x7) { \
  102345. + case 7: \
  102346. + _hcd->hfnum_7_samples_##_letter++; \
  102347. + _hcd->hfnum_7_frrem_accum_##_letter += hfnum.b.frrem; \
  102348. + break; \
  102349. + case 0: \
  102350. + _hcd->hfnum_0_samples_##_letter++; \
  102351. + _hcd->hfnum_0_frrem_accum_##_letter += hfnum.b.frrem; \
  102352. + break; \
  102353. + default: \
  102354. + _hcd->hfnum_other_samples_##_letter++; \
  102355. + _hcd->hfnum_other_frrem_accum_##_letter += hfnum.b.frrem; \
  102356. + break; \
  102357. + } \
  102358. + } \
  102359. +}
  102360. +#else
  102361. +#define dwc_sample_frrem(_hcd, _qh, _letter)
  102362. +#endif
  102363. +#endif
  102364. +#endif /* DWC_DEVICE_ONLY */
  102365. diff -Nur linux-3.18.8/drivers/usb/host/dwc_otg/dwc_otg_hcd_if.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd_if.h
  102366. --- linux-3.18.8/drivers/usb/host/dwc_otg/dwc_otg_hcd_if.h 1970-01-01 01:00:00.000000000 +0100
  102367. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd_if.h 2015-03-05 14:40:16.561715806 +0100
  102368. @@ -0,0 +1,417 @@
  102369. +/* ==========================================================================
  102370. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd_if.h $
  102371. + * $Revision: #12 $
  102372. + * $Date: 2011/10/26 $
  102373. + * $Change: 1873028 $
  102374. + *
  102375. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  102376. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  102377. + * otherwise expressly agreed to in writing between Synopsys and you.
  102378. + *
  102379. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  102380. + * any End User Software License Agreement or Agreement for Licensed Product
  102381. + * with Synopsys or any supplement thereto. You are permitted to use and
  102382. + * redistribute this Software in source and binary forms, with or without
  102383. + * modification, provided that redistributions of source code must retain this
  102384. + * notice. You may not view, use, disclose, copy or distribute this file or
  102385. + * any information contained herein except pursuant to this license grant from
  102386. + * Synopsys. If you do not agree with this notice, including the disclaimer
  102387. + * below, then you are not authorized to use the Software.
  102388. + *
  102389. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  102390. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  102391. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  102392. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  102393. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  102394. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  102395. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  102396. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  102397. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  102398. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  102399. + * DAMAGE.
  102400. + * ========================================================================== */
  102401. +#ifndef DWC_DEVICE_ONLY
  102402. +#ifndef __DWC_HCD_IF_H__
  102403. +#define __DWC_HCD_IF_H__
  102404. +
  102405. +#include "dwc_otg_core_if.h"
  102406. +
  102407. +/** @file
  102408. + * This file defines DWC_OTG HCD Core API.
  102409. + */
  102410. +
  102411. +struct dwc_otg_hcd;
  102412. +typedef struct dwc_otg_hcd dwc_otg_hcd_t;
  102413. +
  102414. +struct dwc_otg_hcd_urb;
  102415. +typedef struct dwc_otg_hcd_urb dwc_otg_hcd_urb_t;
  102416. +
  102417. +/** @name HCD Function Driver Callbacks */
  102418. +/** @{ */
  102419. +
  102420. +/** This function is called whenever core switches to host mode. */
  102421. +typedef int (*dwc_otg_hcd_start_cb_t) (dwc_otg_hcd_t * hcd);
  102422. +
  102423. +/** This function is called when device has been disconnected */
  102424. +typedef int (*dwc_otg_hcd_disconnect_cb_t) (dwc_otg_hcd_t * hcd);
  102425. +
  102426. +/** Wrapper provides this function to HCD to core, so it can get hub information to which device is connected */
  102427. +typedef int (*dwc_otg_hcd_hub_info_from_urb_cb_t) (dwc_otg_hcd_t * hcd,
  102428. + void *urb_handle,
  102429. + uint32_t * hub_addr,
  102430. + uint32_t * port_addr);
  102431. +/** Via this function HCD core gets device speed */
  102432. +typedef int (*dwc_otg_hcd_speed_from_urb_cb_t) (dwc_otg_hcd_t * hcd,
  102433. + void *urb_handle);
  102434. +
  102435. +/** This function is called when urb is completed */
  102436. +typedef int (*dwc_otg_hcd_complete_urb_cb_t) (dwc_otg_hcd_t * hcd,
  102437. + void *urb_handle,
  102438. + dwc_otg_hcd_urb_t * dwc_otg_urb,
  102439. + int32_t status);
  102440. +
  102441. +/** Via this function HCD core gets b_hnp_enable parameter */
  102442. +typedef int (*dwc_otg_hcd_get_b_hnp_enable) (dwc_otg_hcd_t * hcd);
  102443. +
  102444. +struct dwc_otg_hcd_function_ops {
  102445. + dwc_otg_hcd_start_cb_t start;
  102446. + dwc_otg_hcd_disconnect_cb_t disconnect;
  102447. + dwc_otg_hcd_hub_info_from_urb_cb_t hub_info;
  102448. + dwc_otg_hcd_speed_from_urb_cb_t speed;
  102449. + dwc_otg_hcd_complete_urb_cb_t complete;
  102450. + dwc_otg_hcd_get_b_hnp_enable get_b_hnp_enable;
  102451. +};
  102452. +/** @} */
  102453. +
  102454. +/** @name HCD Core API */
  102455. +/** @{ */
  102456. +/** This function allocates dwc_otg_hcd structure and returns pointer on it. */
  102457. +extern dwc_otg_hcd_t *dwc_otg_hcd_alloc_hcd(void);
  102458. +
  102459. +/** This function should be called to initiate HCD Core.
  102460. + *
  102461. + * @param hcd The HCD
  102462. + * @param core_if The DWC_OTG Core
  102463. + *
  102464. + * Returns -DWC_E_NO_MEMORY if no enough memory.
  102465. + * Returns 0 on success
  102466. + */
  102467. +extern int dwc_otg_hcd_init(dwc_otg_hcd_t * hcd, dwc_otg_core_if_t * core_if);
  102468. +
  102469. +/** Frees HCD
  102470. + *
  102471. + * @param hcd The HCD
  102472. + */
  102473. +extern void dwc_otg_hcd_remove(dwc_otg_hcd_t * hcd);
  102474. +
  102475. +/** This function should be called on every hardware interrupt.
  102476. + *
  102477. + * @param dwc_otg_hcd The HCD
  102478. + *
  102479. + * Returns non zero if interrupt is handled
  102480. + * Return 0 if interrupt is not handled
  102481. + */
  102482. +extern int32_t dwc_otg_hcd_handle_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  102483. +
  102484. +/** This function is used to handle the fast interrupt
  102485. + *
  102486. + */
  102487. +extern void __attribute__ ((naked)) dwc_otg_hcd_handle_fiq(void);
  102488. +
  102489. +/**
  102490. + * Returns private data set by
  102491. + * dwc_otg_hcd_set_priv_data function.
  102492. + *
  102493. + * @param hcd The HCD
  102494. + */
  102495. +extern void *dwc_otg_hcd_get_priv_data(dwc_otg_hcd_t * hcd);
  102496. +
  102497. +/**
  102498. + * Set private data.
  102499. + *
  102500. + * @param hcd The HCD
  102501. + * @param priv_data pointer to be stored in private data
  102502. + */
  102503. +extern void dwc_otg_hcd_set_priv_data(dwc_otg_hcd_t * hcd, void *priv_data);
  102504. +
  102505. +/**
  102506. + * This function initializes the HCD Core.
  102507. + *
  102508. + * @param hcd The HCD
  102509. + * @param fops The Function Driver Operations data structure containing pointers to all callbacks.
  102510. + *
  102511. + * Returns -DWC_E_NO_DEVICE if Core is currently is in device mode.
  102512. + * Returns 0 on success
  102513. + */
  102514. +extern int dwc_otg_hcd_start(dwc_otg_hcd_t * hcd,
  102515. + struct dwc_otg_hcd_function_ops *fops);
  102516. +
  102517. +/**
  102518. + * Halts the DWC_otg host mode operations in a clean manner. USB transfers are
  102519. + * stopped.
  102520. + *
  102521. + * @param hcd The HCD
  102522. + */
  102523. +extern void dwc_otg_hcd_stop(dwc_otg_hcd_t * hcd);
  102524. +
  102525. +/**
  102526. + * Handles hub class-specific requests.
  102527. + *
  102528. + * @param dwc_otg_hcd The HCD
  102529. + * @param typeReq Request Type
  102530. + * @param wValue wValue from control request
  102531. + * @param wIndex wIndex from control request
  102532. + * @param buf data buffer
  102533. + * @param wLength data buffer length
  102534. + *
  102535. + * Returns -DWC_E_INVALID if invalid argument is passed
  102536. + * Returns 0 on success
  102537. + */
  102538. +extern int dwc_otg_hcd_hub_control(dwc_otg_hcd_t * dwc_otg_hcd,
  102539. + uint16_t typeReq, uint16_t wValue,
  102540. + uint16_t wIndex, uint8_t * buf,
  102541. + uint16_t wLength);
  102542. +
  102543. +/**
  102544. + * Returns otg port number.
  102545. + *
  102546. + * @param hcd The HCD
  102547. + */
  102548. +extern uint32_t dwc_otg_hcd_otg_port(dwc_otg_hcd_t * hcd);
  102549. +
  102550. +/**
  102551. + * Returns OTG version - either 1.3 or 2.0.
  102552. + *
  102553. + * @param core_if The core_if structure pointer
  102554. + */
  102555. +extern uint16_t dwc_otg_get_otg_version(dwc_otg_core_if_t * core_if);
  102556. +
  102557. +/**
  102558. + * Returns 1 if currently core is acting as B host, and 0 otherwise.
  102559. + *
  102560. + * @param hcd The HCD
  102561. + */
  102562. +extern uint32_t dwc_otg_hcd_is_b_host(dwc_otg_hcd_t * hcd);
  102563. +
  102564. +/**
  102565. + * Returns current frame number.
  102566. + *
  102567. + * @param hcd The HCD
  102568. + */
  102569. +extern int dwc_otg_hcd_get_frame_number(dwc_otg_hcd_t * hcd);
  102570. +
  102571. +/**
  102572. + * Dumps hcd state.
  102573. + *
  102574. + * @param hcd The HCD
  102575. + */
  102576. +extern void dwc_otg_hcd_dump_state(dwc_otg_hcd_t * hcd);
  102577. +
  102578. +/**
  102579. + * Dump the average frame remaining at SOF. This can be used to
  102580. + * determine average interrupt latency. Frame remaining is also shown for
  102581. + * start transfer and two additional sample points.
  102582. + * Currently this function is not implemented.
  102583. + *
  102584. + * @param hcd The HCD
  102585. + */
  102586. +extern void dwc_otg_hcd_dump_frrem(dwc_otg_hcd_t * hcd);
  102587. +
  102588. +/**
  102589. + * Sends LPM transaction to the local device.
  102590. + *
  102591. + * @param hcd The HCD
  102592. + * @param devaddr Device Address
  102593. + * @param hird Host initiated resume duration
  102594. + * @param bRemoteWake Value of bRemoteWake field in LPM transaction
  102595. + *
  102596. + * Returns negative value if sending LPM transaction was not succeeded.
  102597. + * Returns 0 on success.
  102598. + */
  102599. +extern int dwc_otg_hcd_send_lpm(dwc_otg_hcd_t * hcd, uint8_t devaddr,
  102600. + uint8_t hird, uint8_t bRemoteWake);
  102601. +
  102602. +/* URB interface */
  102603. +
  102604. +/**
  102605. + * Allocates memory for dwc_otg_hcd_urb structure.
  102606. + * Allocated memory should be freed by call of DWC_FREE.
  102607. + *
  102608. + * @param hcd The HCD
  102609. + * @param iso_desc_count Count of ISOC descriptors
  102610. + * @param atomic_alloc Specefies whether to perform atomic allocation.
  102611. + */
  102612. +extern dwc_otg_hcd_urb_t *dwc_otg_hcd_urb_alloc(dwc_otg_hcd_t * hcd,
  102613. + int iso_desc_count,
  102614. + int atomic_alloc);
  102615. +
  102616. +/**
  102617. + * Set pipe information in URB.
  102618. + *
  102619. + * @param hcd_urb DWC_OTG URB
  102620. + * @param devaddr Device Address
  102621. + * @param ep_num Endpoint Number
  102622. + * @param ep_type Endpoint Type
  102623. + * @param ep_dir Endpoint Direction
  102624. + * @param mps Max Packet Size
  102625. + */
  102626. +extern void dwc_otg_hcd_urb_set_pipeinfo(dwc_otg_hcd_urb_t * hcd_urb,
  102627. + uint8_t devaddr, uint8_t ep_num,
  102628. + uint8_t ep_type, uint8_t ep_dir,
  102629. + uint16_t mps);
  102630. +
  102631. +/* Transfer flags */
  102632. +#define URB_GIVEBACK_ASAP 0x1
  102633. +#define URB_SEND_ZERO_PACKET 0x2
  102634. +
  102635. +/**
  102636. + * Sets dwc_otg_hcd_urb parameters.
  102637. + *
  102638. + * @param urb DWC_OTG URB allocated by dwc_otg_hcd_urb_alloc function.
  102639. + * @param urb_handle Unique handle for request, this will be passed back
  102640. + * to function driver in completion callback.
  102641. + * @param buf The buffer for the data
  102642. + * @param dma The DMA buffer for the data
  102643. + * @param buflen Transfer length
  102644. + * @param sp Buffer for setup data
  102645. + * @param sp_dma DMA address of setup data buffer
  102646. + * @param flags Transfer flags
  102647. + * @param interval Polling interval for interrupt or isochronous transfers.
  102648. + */
  102649. +extern void dwc_otg_hcd_urb_set_params(dwc_otg_hcd_urb_t * urb,
  102650. + void *urb_handle, void *buf,
  102651. + dwc_dma_t dma, uint32_t buflen, void *sp,
  102652. + dwc_dma_t sp_dma, uint32_t flags,
  102653. + uint16_t interval);
  102654. +
  102655. +/** Gets status from dwc_otg_hcd_urb
  102656. + *
  102657. + * @param dwc_otg_urb DWC_OTG URB
  102658. + */
  102659. +extern uint32_t dwc_otg_hcd_urb_get_status(dwc_otg_hcd_urb_t * dwc_otg_urb);
  102660. +
  102661. +/** Gets actual length from dwc_otg_hcd_urb
  102662. + *
  102663. + * @param dwc_otg_urb DWC_OTG URB
  102664. + */
  102665. +extern uint32_t dwc_otg_hcd_urb_get_actual_length(dwc_otg_hcd_urb_t *
  102666. + dwc_otg_urb);
  102667. +
  102668. +/** Gets error count from dwc_otg_hcd_urb. Only for ISOC URBs
  102669. + *
  102670. + * @param dwc_otg_urb DWC_OTG URB
  102671. + */
  102672. +extern uint32_t dwc_otg_hcd_urb_get_error_count(dwc_otg_hcd_urb_t *
  102673. + dwc_otg_urb);
  102674. +
  102675. +/** Set ISOC descriptor offset and length
  102676. + *
  102677. + * @param dwc_otg_urb DWC_OTG URB
  102678. + * @param desc_num ISOC descriptor number
  102679. + * @param offset Offset from beginig of buffer.
  102680. + * @param length Transaction length
  102681. + */
  102682. +extern void dwc_otg_hcd_urb_set_iso_desc_params(dwc_otg_hcd_urb_t * dwc_otg_urb,
  102683. + int desc_num, uint32_t offset,
  102684. + uint32_t length);
  102685. +
  102686. +/** Get status of ISOC descriptor, specified by desc_num
  102687. + *
  102688. + * @param dwc_otg_urb DWC_OTG URB
  102689. + * @param desc_num ISOC descriptor number
  102690. + */
  102691. +extern uint32_t dwc_otg_hcd_urb_get_iso_desc_status(dwc_otg_hcd_urb_t *
  102692. + dwc_otg_urb, int desc_num);
  102693. +
  102694. +/** Get actual length of ISOC descriptor, specified by desc_num
  102695. + *
  102696. + * @param dwc_otg_urb DWC_OTG URB
  102697. + * @param desc_num ISOC descriptor number
  102698. + */
  102699. +extern uint32_t dwc_otg_hcd_urb_get_iso_desc_actual_length(dwc_otg_hcd_urb_t *
  102700. + dwc_otg_urb,
  102701. + int desc_num);
  102702. +
  102703. +/** Queue URB. After transfer is completes, the complete callback will be called with the URB status
  102704. + *
  102705. + * @param dwc_otg_hcd The HCD
  102706. + * @param dwc_otg_urb DWC_OTG URB
  102707. + * @param ep_handle Out parameter for returning endpoint handle
  102708. + * @param atomic_alloc Flag to do atomic allocation if needed
  102709. + *
  102710. + * Returns -DWC_E_NO_DEVICE if no device is connected.
  102711. + * Returns -DWC_E_NO_MEMORY if there is no enough memory.
  102712. + * Returns 0 on success.
  102713. + */
  102714. +extern int dwc_otg_hcd_urb_enqueue(dwc_otg_hcd_t * dwc_otg_hcd,
  102715. + dwc_otg_hcd_urb_t * dwc_otg_urb,
  102716. + void **ep_handle, int atomic_alloc);
  102717. +
  102718. +/** De-queue the specified URB
  102719. + *
  102720. + * @param dwc_otg_hcd The HCD
  102721. + * @param dwc_otg_urb DWC_OTG URB
  102722. + */
  102723. +extern int dwc_otg_hcd_urb_dequeue(dwc_otg_hcd_t * dwc_otg_hcd,
  102724. + dwc_otg_hcd_urb_t * dwc_otg_urb);
  102725. +
  102726. +/** Frees resources in the DWC_otg controller related to a given endpoint.
  102727. + * Any URBs for the endpoint must already be dequeued.
  102728. + *
  102729. + * @param hcd The HCD
  102730. + * @param ep_handle Endpoint handle, returned by dwc_otg_hcd_urb_enqueue function
  102731. + * @param retry Number of retries if there are queued transfers.
  102732. + *
  102733. + * Returns -DWC_E_INVALID if invalid arguments are passed.
  102734. + * Returns 0 on success
  102735. + */
  102736. +extern int dwc_otg_hcd_endpoint_disable(dwc_otg_hcd_t * hcd, void *ep_handle,
  102737. + int retry);
  102738. +
  102739. +/* Resets the data toggle in qh structure. This function can be called from
  102740. + * usb_clear_halt routine.
  102741. + *
  102742. + * @param hcd The HCD
  102743. + * @param ep_handle Endpoint handle, returned by dwc_otg_hcd_urb_enqueue function
  102744. + *
  102745. + * Returns -DWC_E_INVALID if invalid arguments are passed.
  102746. + * Returns 0 on success
  102747. + */
  102748. +extern int dwc_otg_hcd_endpoint_reset(dwc_otg_hcd_t * hcd, void *ep_handle);
  102749. +
  102750. +/** Returns 1 if status of specified port is changed and 0 otherwise.
  102751. + *
  102752. + * @param hcd The HCD
  102753. + * @param port Port number
  102754. + */
  102755. +extern int dwc_otg_hcd_is_status_changed(dwc_otg_hcd_t * hcd, int port);
  102756. +
  102757. +/** Call this function to check if bandwidth was allocated for specified endpoint.
  102758. + * Only for ISOC and INTERRUPT endpoints.
  102759. + *
  102760. + * @param hcd The HCD
  102761. + * @param ep_handle Endpoint handle
  102762. + */
  102763. +extern int dwc_otg_hcd_is_bandwidth_allocated(dwc_otg_hcd_t * hcd,
  102764. + void *ep_handle);
  102765. +
  102766. +/** Call this function to check if bandwidth was freed for specified endpoint.
  102767. + *
  102768. + * @param hcd The HCD
  102769. + * @param ep_handle Endpoint handle
  102770. + */
  102771. +extern int dwc_otg_hcd_is_bandwidth_freed(dwc_otg_hcd_t * hcd, void *ep_handle);
  102772. +
  102773. +/** Returns bandwidth allocated for specified endpoint in microseconds.
  102774. + * Only for ISOC and INTERRUPT endpoints.
  102775. + *
  102776. + * @param hcd The HCD
  102777. + * @param ep_handle Endpoint handle
  102778. + */
  102779. +extern uint8_t dwc_otg_hcd_get_ep_bandwidth(dwc_otg_hcd_t * hcd,
  102780. + void *ep_handle);
  102781. +
  102782. +/** @} */
  102783. +
  102784. +#endif /* __DWC_HCD_IF_H__ */
  102785. +#endif /* DWC_DEVICE_ONLY */
  102786. diff -Nur linux-3.18.8/drivers/usb/host/dwc_otg/dwc_otg_hcd_intr.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd_intr.c
  102787. --- linux-3.18.8/drivers/usb/host/dwc_otg/dwc_otg_hcd_intr.c 1970-01-01 01:00:00.000000000 +0100
  102788. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd_intr.c 2015-03-05 14:40:16.561715806 +0100
  102789. @@ -0,0 +1,2713 @@
  102790. +/* ==========================================================================
  102791. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd_intr.c $
  102792. + * $Revision: #89 $
  102793. + * $Date: 2011/10/20 $
  102794. + * $Change: 1869487 $
  102795. + *
  102796. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  102797. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  102798. + * otherwise expressly agreed to in writing between Synopsys and you.
  102799. + *
  102800. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  102801. + * any End User Software License Agreement or Agreement for Licensed Product
  102802. + * with Synopsys or any supplement thereto. You are permitted to use and
  102803. + * redistribute this Software in source and binary forms, with or without
  102804. + * modification, provided that redistributions of source code must retain this
  102805. + * notice. You may not view, use, disclose, copy or distribute this file or
  102806. + * any information contained herein except pursuant to this license grant from
  102807. + * Synopsys. If you do not agree with this notice, including the disclaimer
  102808. + * below, then you are not authorized to use the Software.
  102809. + *
  102810. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  102811. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  102812. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  102813. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  102814. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  102815. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  102816. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  102817. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  102818. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  102819. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  102820. + * DAMAGE.
  102821. + * ========================================================================== */
  102822. +#ifndef DWC_DEVICE_ONLY
  102823. +
  102824. +#include "dwc_otg_hcd.h"
  102825. +#include "dwc_otg_regs.h"
  102826. +
  102827. +#include <linux/jiffies.h>
  102828. +#include <mach/hardware.h>
  102829. +#include <asm/fiq.h>
  102830. +
  102831. +
  102832. +extern bool microframe_schedule;
  102833. +
  102834. +/** @file
  102835. + * This file contains the implementation of the HCD Interrupt handlers.
  102836. + */
  102837. +
  102838. +int fiq_done, int_done;
  102839. +
  102840. +#ifdef FIQ_DEBUG
  102841. +char buffer[1000*16];
  102842. +int wptr;
  102843. +void notrace _fiq_print(FIQDBG_T dbg_lvl, char *fmt, ...)
  102844. +{
  102845. + FIQDBG_T dbg_lvl_req = FIQDBG_PORTHUB;
  102846. + va_list args;
  102847. + char text[17];
  102848. + hfnum_data_t hfnum = { .d32 = FIQ_READ(dwc_regs_base + 0x408) };
  102849. +
  102850. + if(dbg_lvl & dbg_lvl_req || dbg_lvl == FIQDBG_ERR)
  102851. + {
  102852. + local_fiq_disable();
  102853. + snprintf(text, 9, "%4d%d:%d ", hfnum.b.frnum/8, hfnum.b.frnum%8, 8 - hfnum.b.frrem/937);
  102854. + va_start(args, fmt);
  102855. + vsnprintf(text+8, 9, fmt, args);
  102856. + va_end(args);
  102857. +
  102858. + memcpy(buffer + wptr, text, 16);
  102859. + wptr = (wptr + 16) % sizeof(buffer);
  102860. + local_fiq_enable();
  102861. + }
  102862. +}
  102863. +#endif
  102864. +
  102865. +/** This function handles interrupts for the HCD. */
  102866. +int32_t dwc_otg_hcd_handle_intr(dwc_otg_hcd_t * dwc_otg_hcd)
  102867. +{
  102868. + int retval = 0;
  102869. + static int last_time;
  102870. + dwc_otg_core_if_t *core_if = dwc_otg_hcd->core_if;
  102871. + gintsts_data_t gintsts;
  102872. + gintmsk_data_t gintmsk;
  102873. + hfnum_data_t hfnum;
  102874. + haintmsk_data_t haintmsk;
  102875. +
  102876. +#ifdef DEBUG
  102877. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  102878. +
  102879. +#endif
  102880. +
  102881. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  102882. + gintmsk.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
  102883. +
  102884. + /* Exit from ISR if core is hibernated */
  102885. + if (core_if->hibernation_suspend == 1) {
  102886. + goto exit_handler_routine;
  102887. + }
  102888. + DWC_SPINLOCK(dwc_otg_hcd->lock);
  102889. + /* Check if HOST Mode */
  102890. + if (dwc_otg_is_host_mode(core_if)) {
  102891. + if (fiq_enable) {
  102892. + local_fiq_disable();
  102893. + fiq_fsm_spin_lock(&dwc_otg_hcd->fiq_state->lock);
  102894. + /* Pull in from the FIQ's disabled mask */
  102895. + gintmsk.d32 = gintmsk.d32 | ~(dwc_otg_hcd->fiq_state->gintmsk_saved.d32);
  102896. + dwc_otg_hcd->fiq_state->gintmsk_saved.d32 = ~0;
  102897. + }
  102898. +
  102899. + if (fiq_fsm_enable && ( 0x0000FFFF & ~(dwc_otg_hcd->fiq_state->haintmsk_saved.b2.chint))) {
  102900. + gintsts.b.hcintr = 1;
  102901. + }
  102902. +
  102903. + /* Danger will robinson: fake a SOF if necessary */
  102904. + if (fiq_fsm_enable && (dwc_otg_hcd->fiq_state->gintmsk_saved.b.sofintr == 1)) {
  102905. + gintsts.b.sofintr = 1;
  102906. + }
  102907. + gintsts.d32 &= gintmsk.d32;
  102908. +
  102909. + if (fiq_enable) {
  102910. + fiq_fsm_spin_unlock(&dwc_otg_hcd->fiq_state->lock);
  102911. + local_fiq_enable();
  102912. + }
  102913. +
  102914. + if (!gintsts.d32) {
  102915. + goto exit_handler_routine;
  102916. + }
  102917. +
  102918. +#ifdef DEBUG
  102919. + // We should be OK doing this because the common interrupts should already have been serviced
  102920. + /* Don't print debug message in the interrupt handler on SOF */
  102921. +#ifndef DEBUG_SOF
  102922. + if (gintsts.d32 != DWC_SOF_INTR_MASK)
  102923. +#endif
  102924. + DWC_DEBUGPL(DBG_HCDI, "\n");
  102925. +#endif
  102926. +
  102927. +#ifdef DEBUG
  102928. +#ifndef DEBUG_SOF
  102929. + if (gintsts.d32 != DWC_SOF_INTR_MASK)
  102930. +#endif
  102931. + DWC_DEBUGPL(DBG_HCDI,
  102932. + "DWC OTG HCD Interrupt Detected gintsts&gintmsk=0x%08x core_if=%p\n",
  102933. + gintsts.d32, core_if);
  102934. +#endif
  102935. + hfnum.d32 = DWC_READ_REG32(&dwc_otg_hcd->core_if->host_if->host_global_regs->hfnum);
  102936. + if (gintsts.b.sofintr) {
  102937. + retval |= dwc_otg_hcd_handle_sof_intr(dwc_otg_hcd);
  102938. + }
  102939. +
  102940. + if (gintsts.b.rxstsqlvl) {
  102941. + retval |=
  102942. + dwc_otg_hcd_handle_rx_status_q_level_intr
  102943. + (dwc_otg_hcd);
  102944. + }
  102945. + if (gintsts.b.nptxfempty) {
  102946. + retval |=
  102947. + dwc_otg_hcd_handle_np_tx_fifo_empty_intr
  102948. + (dwc_otg_hcd);
  102949. + }
  102950. + if (gintsts.b.i2cintr) {
  102951. + /** @todo Implement i2cintr handler. */
  102952. + }
  102953. + if (gintsts.b.portintr) {
  102954. +
  102955. + gintmsk_data_t gintmsk = { .b.portintr = 1};
  102956. + retval |= dwc_otg_hcd_handle_port_intr(dwc_otg_hcd);
  102957. + if (fiq_enable) {
  102958. + local_fiq_disable();
  102959. + fiq_fsm_spin_lock(&dwc_otg_hcd->fiq_state->lock);
  102960. + DWC_MODIFY_REG32(&dwc_otg_hcd->core_if->core_global_regs->gintmsk, 0, gintmsk.d32);
  102961. + fiq_fsm_spin_unlock(&dwc_otg_hcd->fiq_state->lock);
  102962. + local_fiq_enable();
  102963. + } else {
  102964. + DWC_MODIFY_REG32(&dwc_otg_hcd->core_if->core_global_regs->gintmsk, 0, gintmsk.d32);
  102965. + }
  102966. + }
  102967. + if (gintsts.b.hcintr) {
  102968. + retval |= dwc_otg_hcd_handle_hc_intr(dwc_otg_hcd);
  102969. + }
  102970. + if (gintsts.b.ptxfempty) {
  102971. + retval |=
  102972. + dwc_otg_hcd_handle_perio_tx_fifo_empty_intr
  102973. + (dwc_otg_hcd);
  102974. + }
  102975. +#ifdef DEBUG
  102976. +#ifndef DEBUG_SOF
  102977. + if (gintsts.d32 != DWC_SOF_INTR_MASK)
  102978. +#endif
  102979. + {
  102980. + DWC_DEBUGPL(DBG_HCDI,
  102981. + "DWC OTG HCD Finished Servicing Interrupts\n");
  102982. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD gintsts=0x%08x\n",
  102983. + DWC_READ_REG32(&global_regs->gintsts));
  102984. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD gintmsk=0x%08x\n",
  102985. + DWC_READ_REG32(&global_regs->gintmsk));
  102986. + }
  102987. +#endif
  102988. +
  102989. +#ifdef DEBUG
  102990. +#ifndef DEBUG_SOF
  102991. + if (gintsts.d32 != DWC_SOF_INTR_MASK)
  102992. +#endif
  102993. + DWC_DEBUGPL(DBG_HCDI, "\n");
  102994. +#endif
  102995. +
  102996. + }
  102997. +
  102998. +exit_handler_routine:
  102999. + if (fiq_enable) {
  103000. + gintmsk_data_t gintmsk_new;
  103001. + haintmsk_data_t haintmsk_new;
  103002. + local_fiq_disable();
  103003. + fiq_fsm_spin_lock(&dwc_otg_hcd->fiq_state->lock);
  103004. + gintmsk_new.d32 = *(volatile uint32_t *)&dwc_otg_hcd->fiq_state->gintmsk_saved.d32;
  103005. + if(fiq_fsm_enable)
  103006. + haintmsk_new.d32 = *(volatile uint32_t *)&dwc_otg_hcd->fiq_state->haintmsk_saved.d32;
  103007. + else
  103008. + haintmsk_new.d32 = 0x0000FFFF;
  103009. +
  103010. + /* The FIQ could have sneaked another interrupt in. If so, don't clear MPHI */
  103011. + if ((gintmsk_new.d32 == ~0) && (haintmsk_new.d32 == 0x0000FFFF)) {
  103012. + DWC_WRITE_REG32(dwc_otg_hcd->fiq_state->mphi_regs.intstat, (1<<16));
  103013. + if (dwc_otg_hcd->fiq_state->mphi_int_count >= 50) {
  103014. + fiq_print(FIQDBG_INT, dwc_otg_hcd->fiq_state, "MPHI CLR");
  103015. + DWC_WRITE_REG32(dwc_otg_hcd->fiq_state->mphi_regs.ctrl, ((1<<31) + (1<<16)));
  103016. + while (!(DWC_READ_REG32(dwc_otg_hcd->fiq_state->mphi_regs.ctrl) & (1 << 17)))
  103017. + ;
  103018. + DWC_WRITE_REG32(dwc_otg_hcd->fiq_state->mphi_regs.ctrl, (1<<31));
  103019. + dwc_otg_hcd->fiq_state->mphi_int_count = 0;
  103020. + }
  103021. + int_done++;
  103022. + }
  103023. + haintmsk.d32 = DWC_READ_REG32(&core_if->host_if->host_global_regs->haintmsk);
  103024. + /* Re-enable interrupts that the FIQ masked (first time round) */
  103025. + FIQ_WRITE(dwc_otg_hcd->fiq_state->dwc_regs_base + GINTMSK, gintmsk.d32);
  103026. + fiq_fsm_spin_unlock(&dwc_otg_hcd->fiq_state->lock);
  103027. + local_fiq_enable();
  103028. +
  103029. + if ((jiffies / HZ) > last_time) {
  103030. + //dwc_otg_qh_t *qh;
  103031. + //dwc_list_link_t *cur;
  103032. + /* Once a second output the fiq and irq numbers, useful for debug */
  103033. + last_time = jiffies / HZ;
  103034. + // DWC_WARN("np_kick=%d AHC=%d sched_frame=%d cur_frame=%d int_done=%d fiq_done=%d",
  103035. + // dwc_otg_hcd->fiq_state->kick_np_queues, dwc_otg_hcd->available_host_channels,
  103036. + // dwc_otg_hcd->fiq_state->next_sched_frame, hfnum.b.frnum, int_done, dwc_otg_hcd->fiq_state->fiq_done);
  103037. + //printk(KERN_WARNING "Periodic queues:\n");
  103038. + }
  103039. + }
  103040. +
  103041. + DWC_SPINUNLOCK(dwc_otg_hcd->lock);
  103042. + return retval;
  103043. +}
  103044. +
  103045. +#ifdef DWC_TRACK_MISSED_SOFS
  103046. +
  103047. +#warning Compiling code to track missed SOFs
  103048. +#define FRAME_NUM_ARRAY_SIZE 1000
  103049. +/**
  103050. + * This function is for debug only.
  103051. + */
  103052. +static inline void track_missed_sofs(uint16_t curr_frame_number)
  103053. +{
  103054. + static uint16_t frame_num_array[FRAME_NUM_ARRAY_SIZE];
  103055. + static uint16_t last_frame_num_array[FRAME_NUM_ARRAY_SIZE];
  103056. + static int frame_num_idx = 0;
  103057. + static uint16_t last_frame_num = DWC_HFNUM_MAX_FRNUM;
  103058. + static int dumped_frame_num_array = 0;
  103059. +
  103060. + if (frame_num_idx < FRAME_NUM_ARRAY_SIZE) {
  103061. + if (((last_frame_num + 1) & DWC_HFNUM_MAX_FRNUM) !=
  103062. + curr_frame_number) {
  103063. + frame_num_array[frame_num_idx] = curr_frame_number;
  103064. + last_frame_num_array[frame_num_idx++] = last_frame_num;
  103065. + }
  103066. + } else if (!dumped_frame_num_array) {
  103067. + int i;
  103068. + DWC_PRINTF("Frame Last Frame\n");
  103069. + DWC_PRINTF("----- ----------\n");
  103070. + for (i = 0; i < FRAME_NUM_ARRAY_SIZE; i++) {
  103071. + DWC_PRINTF("0x%04x 0x%04x\n",
  103072. + frame_num_array[i], last_frame_num_array[i]);
  103073. + }
  103074. + dumped_frame_num_array = 1;
  103075. + }
  103076. + last_frame_num = curr_frame_number;
  103077. +}
  103078. +#endif
  103079. +
  103080. +/**
  103081. + * Handles the start-of-frame interrupt in host mode. Non-periodic
  103082. + * transactions may be queued to the DWC_otg controller for the current
  103083. + * (micro)frame. Periodic transactions may be queued to the controller for the
  103084. + * next (micro)frame.
  103085. + */
  103086. +int32_t dwc_otg_hcd_handle_sof_intr(dwc_otg_hcd_t * hcd)
  103087. +{
  103088. + hfnum_data_t hfnum;
  103089. + gintsts_data_t gintsts = { .d32 = 0 };
  103090. + dwc_list_link_t *qh_entry;
  103091. + dwc_otg_qh_t *qh;
  103092. + dwc_otg_transaction_type_e tr_type;
  103093. + int did_something = 0;
  103094. + int32_t next_sched_frame = -1;
  103095. +
  103096. + hfnum.d32 =
  103097. + DWC_READ_REG32(&hcd->core_if->host_if->host_global_regs->hfnum);
  103098. +
  103099. +#ifdef DEBUG_SOF
  103100. + DWC_DEBUGPL(DBG_HCD, "--Start of Frame Interrupt--\n");
  103101. +#endif
  103102. + hcd->frame_number = hfnum.b.frnum;
  103103. +
  103104. +#ifdef DEBUG
  103105. + hcd->frrem_accum += hfnum.b.frrem;
  103106. + hcd->frrem_samples++;
  103107. +#endif
  103108. +
  103109. +#ifdef DWC_TRACK_MISSED_SOFS
  103110. + track_missed_sofs(hcd->frame_number);
  103111. +#endif
  103112. + /* Determine whether any periodic QHs should be executed. */
  103113. + qh_entry = DWC_LIST_FIRST(&hcd->periodic_sched_inactive);
  103114. + while (qh_entry != &hcd->periodic_sched_inactive) {
  103115. + qh = DWC_LIST_ENTRY(qh_entry, dwc_otg_qh_t, qh_list_entry);
  103116. + qh_entry = qh_entry->next;
  103117. + if (dwc_frame_num_le(qh->sched_frame, hcd->frame_number)) {
  103118. +
  103119. + /*
  103120. + * Move QH to the ready list to be executed next
  103121. + * (micro)frame.
  103122. + */
  103123. + DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_ready,
  103124. + &qh->qh_list_entry);
  103125. +
  103126. + did_something = 1;
  103127. + }
  103128. + else
  103129. + {
  103130. + if(next_sched_frame < 0 || dwc_frame_num_le(qh->sched_frame, next_sched_frame))
  103131. + {
  103132. + next_sched_frame = qh->sched_frame;
  103133. + }
  103134. + }
  103135. + }
  103136. + if (fiq_enable)
  103137. + hcd->fiq_state->next_sched_frame = next_sched_frame;
  103138. +
  103139. + tr_type = dwc_otg_hcd_select_transactions(hcd);
  103140. + if (tr_type != DWC_OTG_TRANSACTION_NONE) {
  103141. + dwc_otg_hcd_queue_transactions(hcd, tr_type);
  103142. + did_something = 1;
  103143. + }
  103144. +
  103145. + /* Clear interrupt - but do not trample on the FIQ sof */
  103146. + if (!fiq_fsm_enable) {
  103147. + gintsts.b.sofintr = 1;
  103148. + DWC_WRITE_REG32(&hcd->core_if->core_global_regs->gintsts, gintsts.d32);
  103149. + }
  103150. + return 1;
  103151. +}
  103152. +
  103153. +/** Handles the Rx Status Queue Level Interrupt, which indicates that there is at
  103154. + * least one packet in the Rx FIFO. The packets are moved from the FIFO to
  103155. + * memory if the DWC_otg controller is operating in Slave mode. */
  103156. +int32_t dwc_otg_hcd_handle_rx_status_q_level_intr(dwc_otg_hcd_t * dwc_otg_hcd)
  103157. +{
  103158. + host_grxsts_data_t grxsts;
  103159. + dwc_hc_t *hc = NULL;
  103160. +
  103161. + DWC_DEBUGPL(DBG_HCD, "--RxStsQ Level Interrupt--\n");
  103162. +
  103163. + grxsts.d32 =
  103164. + DWC_READ_REG32(&dwc_otg_hcd->core_if->core_global_regs->grxstsp);
  103165. +
  103166. + hc = dwc_otg_hcd->hc_ptr_array[grxsts.b.chnum];
  103167. + if (!hc) {
  103168. + DWC_ERROR("Unable to get corresponding channel\n");
  103169. + return 0;
  103170. + }
  103171. +
  103172. + /* Packet Status */
  103173. + DWC_DEBUGPL(DBG_HCDV, " Ch num = %d\n", grxsts.b.chnum);
  103174. + DWC_DEBUGPL(DBG_HCDV, " Count = %d\n", grxsts.b.bcnt);
  103175. + DWC_DEBUGPL(DBG_HCDV, " DPID = %d, hc.dpid = %d\n", grxsts.b.dpid,
  103176. + hc->data_pid_start);
  103177. + DWC_DEBUGPL(DBG_HCDV, " PStatus = %d\n", grxsts.b.pktsts);
  103178. +
  103179. + switch (grxsts.b.pktsts) {
  103180. + case DWC_GRXSTS_PKTSTS_IN:
  103181. + /* Read the data into the host buffer. */
  103182. + if (grxsts.b.bcnt > 0) {
  103183. + dwc_otg_read_packet(dwc_otg_hcd->core_if,
  103184. + hc->xfer_buff, grxsts.b.bcnt);
  103185. +
  103186. + /* Update the HC fields for the next packet received. */
  103187. + hc->xfer_count += grxsts.b.bcnt;
  103188. + hc->xfer_buff += grxsts.b.bcnt;
  103189. + }
  103190. +
  103191. + case DWC_GRXSTS_PKTSTS_IN_XFER_COMP:
  103192. + case DWC_GRXSTS_PKTSTS_DATA_TOGGLE_ERR:
  103193. + case DWC_GRXSTS_PKTSTS_CH_HALTED:
  103194. + /* Handled in interrupt, just ignore data */
  103195. + break;
  103196. + default:
  103197. + DWC_ERROR("RX_STS_Q Interrupt: Unknown status %d\n",
  103198. + grxsts.b.pktsts);
  103199. + break;
  103200. + }
  103201. +
  103202. + return 1;
  103203. +}
  103204. +
  103205. +/** This interrupt occurs when the non-periodic Tx FIFO is half-empty. More
  103206. + * data packets may be written to the FIFO for OUT transfers. More requests
  103207. + * may be written to the non-periodic request queue for IN transfers. This
  103208. + * interrupt is enabled only in Slave mode. */
  103209. +int32_t dwc_otg_hcd_handle_np_tx_fifo_empty_intr(dwc_otg_hcd_t * dwc_otg_hcd)
  103210. +{
  103211. + DWC_DEBUGPL(DBG_HCD, "--Non-Periodic TxFIFO Empty Interrupt--\n");
  103212. + dwc_otg_hcd_queue_transactions(dwc_otg_hcd,
  103213. + DWC_OTG_TRANSACTION_NON_PERIODIC);
  103214. + return 1;
  103215. +}
  103216. +
  103217. +/** This interrupt occurs when the periodic Tx FIFO is half-empty. More data
  103218. + * packets may be written to the FIFO for OUT transfers. More requests may be
  103219. + * written to the periodic request queue for IN transfers. This interrupt is
  103220. + * enabled only in Slave mode. */
  103221. +int32_t dwc_otg_hcd_handle_perio_tx_fifo_empty_intr(dwc_otg_hcd_t * dwc_otg_hcd)
  103222. +{
  103223. + DWC_DEBUGPL(DBG_HCD, "--Periodic TxFIFO Empty Interrupt--\n");
  103224. + dwc_otg_hcd_queue_transactions(dwc_otg_hcd,
  103225. + DWC_OTG_TRANSACTION_PERIODIC);
  103226. + return 1;
  103227. +}
  103228. +
  103229. +/** There are multiple conditions that can cause a port interrupt. This function
  103230. + * determines which interrupt conditions have occurred and handles them
  103231. + * appropriately. */
  103232. +int32_t dwc_otg_hcd_handle_port_intr(dwc_otg_hcd_t * dwc_otg_hcd)
  103233. +{
  103234. + int retval = 0;
  103235. + hprt0_data_t hprt0;
  103236. + hprt0_data_t hprt0_modify;
  103237. +
  103238. + hprt0.d32 = DWC_READ_REG32(dwc_otg_hcd->core_if->host_if->hprt0);
  103239. + hprt0_modify.d32 = DWC_READ_REG32(dwc_otg_hcd->core_if->host_if->hprt0);
  103240. +
  103241. + /* Clear appropriate bits in HPRT0 to clear the interrupt bit in
  103242. + * GINTSTS */
  103243. +
  103244. + hprt0_modify.b.prtena = 0;
  103245. + hprt0_modify.b.prtconndet = 0;
  103246. + hprt0_modify.b.prtenchng = 0;
  103247. + hprt0_modify.b.prtovrcurrchng = 0;
  103248. +
  103249. + /* Port Connect Detected
  103250. + * Set flag and clear if detected */
  103251. + if (dwc_otg_hcd->core_if->hibernation_suspend == 1) {
  103252. + // Dont modify port status if we are in hibernation state
  103253. + hprt0_modify.b.prtconndet = 1;
  103254. + hprt0_modify.b.prtenchng = 1;
  103255. + DWC_WRITE_REG32(dwc_otg_hcd->core_if->host_if->hprt0, hprt0_modify.d32);
  103256. + hprt0.d32 = DWC_READ_REG32(dwc_otg_hcd->core_if->host_if->hprt0);
  103257. + return retval;
  103258. + }
  103259. +
  103260. + if (hprt0.b.prtconndet) {
  103261. + /** @todo - check if steps performed in 'else' block should be perfromed regardles adp */
  103262. + if (dwc_otg_hcd->core_if->adp_enable &&
  103263. + dwc_otg_hcd->core_if->adp.vbuson_timer_started == 1) {
  103264. + DWC_PRINTF("PORT CONNECT DETECTED ----------------\n");
  103265. + DWC_TIMER_CANCEL(dwc_otg_hcd->core_if->adp.vbuson_timer);
  103266. + dwc_otg_hcd->core_if->adp.vbuson_timer_started = 0;
  103267. + /* TODO - check if this is required, as
  103268. + * host initialization was already performed
  103269. + * after initial ADP probing
  103270. + */
  103271. + /*dwc_otg_hcd->core_if->adp.vbuson_timer_started = 0;
  103272. + dwc_otg_core_init(dwc_otg_hcd->core_if);
  103273. + dwc_otg_enable_global_interrupts(dwc_otg_hcd->core_if);
  103274. + cil_hcd_start(dwc_otg_hcd->core_if);*/
  103275. + } else {
  103276. +
  103277. + DWC_DEBUGPL(DBG_HCD, "--Port Interrupt HPRT0=0x%08x "
  103278. + "Port Connect Detected--\n", hprt0.d32);
  103279. + dwc_otg_hcd->flags.b.port_connect_status_change = 1;
  103280. + dwc_otg_hcd->flags.b.port_connect_status = 1;
  103281. + hprt0_modify.b.prtconndet = 1;
  103282. +
  103283. + /* B-Device has connected, Delete the connection timer. */
  103284. + DWC_TIMER_CANCEL(dwc_otg_hcd->conn_timer);
  103285. + }
  103286. + /* The Hub driver asserts a reset when it sees port connect
  103287. + * status change flag */
  103288. + retval |= 1;
  103289. + }
  103290. +
  103291. + /* Port Enable Changed
  103292. + * Clear if detected - Set internal flag if disabled */
  103293. + if (hprt0.b.prtenchng) {
  103294. + DWC_DEBUGPL(DBG_HCD, " --Port Interrupt HPRT0=0x%08x "
  103295. + "Port Enable Changed--\n", hprt0.d32);
  103296. + hprt0_modify.b.prtenchng = 1;
  103297. + if (hprt0.b.prtena == 1) {
  103298. + hfir_data_t hfir;
  103299. + int do_reset = 0;
  103300. + dwc_otg_core_params_t *params =
  103301. + dwc_otg_hcd->core_if->core_params;
  103302. + dwc_otg_core_global_regs_t *global_regs =
  103303. + dwc_otg_hcd->core_if->core_global_regs;
  103304. + dwc_otg_host_if_t *host_if =
  103305. + dwc_otg_hcd->core_if->host_if;
  103306. +
  103307. + /* Every time when port enables calculate
  103308. + * HFIR.FrInterval
  103309. + */
  103310. + hfir.d32 = DWC_READ_REG32(&host_if->host_global_regs->hfir);
  103311. + hfir.b.frint = calc_frame_interval(dwc_otg_hcd->core_if);
  103312. + DWC_WRITE_REG32(&host_if->host_global_regs->hfir, hfir.d32);
  103313. +
  103314. + /* Check if we need to adjust the PHY clock speed for
  103315. + * low power and adjust it */
  103316. + if (params->host_support_fs_ls_low_power) {
  103317. + gusbcfg_data_t usbcfg;
  103318. +
  103319. + usbcfg.d32 =
  103320. + DWC_READ_REG32(&global_regs->gusbcfg);
  103321. +
  103322. + if (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_LOW_SPEED
  103323. + || hprt0.b.prtspd ==
  103324. + DWC_HPRT0_PRTSPD_FULL_SPEED) {
  103325. + /*
  103326. + * Low power
  103327. + */
  103328. + hcfg_data_t hcfg;
  103329. + if (usbcfg.b.phylpwrclksel == 0) {
  103330. + /* Set PHY low power clock select for FS/LS devices */
  103331. + usbcfg.b.phylpwrclksel = 1;
  103332. + DWC_WRITE_REG32
  103333. + (&global_regs->gusbcfg,
  103334. + usbcfg.d32);
  103335. + do_reset = 1;
  103336. + }
  103337. +
  103338. + hcfg.d32 =
  103339. + DWC_READ_REG32
  103340. + (&host_if->host_global_regs->hcfg);
  103341. +
  103342. + if (hprt0.b.prtspd ==
  103343. + DWC_HPRT0_PRTSPD_LOW_SPEED
  103344. + && params->host_ls_low_power_phy_clk
  103345. + ==
  103346. + DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ)
  103347. + {
  103348. + /* 6 MHZ */
  103349. + DWC_DEBUGPL(DBG_CIL,
  103350. + "FS_PHY programming HCFG to 6 MHz (Low Power)\n");
  103351. + if (hcfg.b.fslspclksel !=
  103352. + DWC_HCFG_6_MHZ) {
  103353. + hcfg.b.fslspclksel =
  103354. + DWC_HCFG_6_MHZ;
  103355. + DWC_WRITE_REG32
  103356. + (&host_if->host_global_regs->hcfg,
  103357. + hcfg.d32);
  103358. + do_reset = 1;
  103359. + }
  103360. + } else {
  103361. + /* 48 MHZ */
  103362. + DWC_DEBUGPL(DBG_CIL,
  103363. + "FS_PHY programming HCFG to 48 MHz ()\n");
  103364. + if (hcfg.b.fslspclksel !=
  103365. + DWC_HCFG_48_MHZ) {
  103366. + hcfg.b.fslspclksel =
  103367. + DWC_HCFG_48_MHZ;
  103368. + DWC_WRITE_REG32
  103369. + (&host_if->host_global_regs->hcfg,
  103370. + hcfg.d32);
  103371. + do_reset = 1;
  103372. + }
  103373. + }
  103374. + } else {
  103375. + /*
  103376. + * Not low power
  103377. + */
  103378. + if (usbcfg.b.phylpwrclksel == 1) {
  103379. + usbcfg.b.phylpwrclksel = 0;
  103380. + DWC_WRITE_REG32
  103381. + (&global_regs->gusbcfg,
  103382. + usbcfg.d32);
  103383. + do_reset = 1;
  103384. + }
  103385. + }
  103386. +
  103387. + if (do_reset) {
  103388. + DWC_TASK_SCHEDULE(dwc_otg_hcd->reset_tasklet);
  103389. + }
  103390. + }
  103391. +
  103392. + if (!do_reset) {
  103393. + /* Port has been enabled set the reset change flag */
  103394. + dwc_otg_hcd->flags.b.port_reset_change = 1;
  103395. + }
  103396. + } else {
  103397. + dwc_otg_hcd->flags.b.port_enable_change = 1;
  103398. + }
  103399. + retval |= 1;
  103400. + }
  103401. +
  103402. + /** Overcurrent Change Interrupt */
  103403. + if (hprt0.b.prtovrcurrchng) {
  103404. + DWC_DEBUGPL(DBG_HCD, " --Port Interrupt HPRT0=0x%08x "
  103405. + "Port Overcurrent Changed--\n", hprt0.d32);
  103406. + dwc_otg_hcd->flags.b.port_over_current_change = 1;
  103407. + hprt0_modify.b.prtovrcurrchng = 1;
  103408. + retval |= 1;
  103409. + }
  103410. +
  103411. + /* Clear Port Interrupts */
  103412. + DWC_WRITE_REG32(dwc_otg_hcd->core_if->host_if->hprt0, hprt0_modify.d32);
  103413. +
  103414. + return retval;
  103415. +}
  103416. +
  103417. +/** This interrupt indicates that one or more host channels has a pending
  103418. + * interrupt. There are multiple conditions that can cause each host channel
  103419. + * interrupt. This function determines which conditions have occurred for each
  103420. + * host channel interrupt and handles them appropriately. */
  103421. +int32_t dwc_otg_hcd_handle_hc_intr(dwc_otg_hcd_t * dwc_otg_hcd)
  103422. +{
  103423. + int i;
  103424. + int retval = 0;
  103425. + haint_data_t haint = { .d32 = 0 } ;
  103426. +
  103427. + /* Clear appropriate bits in HCINTn to clear the interrupt bit in
  103428. + * GINTSTS */
  103429. +
  103430. + if (!fiq_fsm_enable)
  103431. + haint.d32 = dwc_otg_read_host_all_channels_intr(dwc_otg_hcd->core_if);
  103432. +
  103433. + // Overwrite with saved interrupts from fiq handler
  103434. + if(fiq_fsm_enable)
  103435. + {
  103436. + /* check the mask? */
  103437. + local_fiq_disable();
  103438. + fiq_fsm_spin_lock(&dwc_otg_hcd->fiq_state->lock);
  103439. + haint.b2.chint |= ~(dwc_otg_hcd->fiq_state->haintmsk_saved.b2.chint);
  103440. + dwc_otg_hcd->fiq_state->haintmsk_saved.b2.chint = ~0;
  103441. + fiq_fsm_spin_unlock(&dwc_otg_hcd->fiq_state->lock);
  103442. + local_fiq_enable();
  103443. + }
  103444. +
  103445. + for (i = 0; i < dwc_otg_hcd->core_if->core_params->host_channels; i++) {
  103446. + if (haint.b2.chint & (1 << i)) {
  103447. + retval |= dwc_otg_hcd_handle_hc_n_intr(dwc_otg_hcd, i);
  103448. + }
  103449. + }
  103450. +
  103451. + return retval;
  103452. +}
  103453. +
  103454. +/**
  103455. + * Gets the actual length of a transfer after the transfer halts. _halt_status
  103456. + * holds the reason for the halt.
  103457. + *
  103458. + * For IN transfers where halt_status is DWC_OTG_HC_XFER_COMPLETE,
  103459. + * *short_read is set to 1 upon return if less than the requested
  103460. + * number of bytes were transferred. Otherwise, *short_read is set to 0 upon
  103461. + * return. short_read may also be NULL on entry, in which case it remains
  103462. + * unchanged.
  103463. + */
  103464. +static uint32_t get_actual_xfer_length(dwc_hc_t * hc,
  103465. + dwc_otg_hc_regs_t * hc_regs,
  103466. + dwc_otg_qtd_t * qtd,
  103467. + dwc_otg_halt_status_e halt_status,
  103468. + int *short_read)
  103469. +{
  103470. + hctsiz_data_t hctsiz;
  103471. + uint32_t length;
  103472. +
  103473. + if (short_read != NULL) {
  103474. + *short_read = 0;
  103475. + }
  103476. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  103477. +
  103478. + if (halt_status == DWC_OTG_HC_XFER_COMPLETE) {
  103479. + if (hc->ep_is_in) {
  103480. + length = hc->xfer_len - hctsiz.b.xfersize;
  103481. + if (short_read != NULL) {
  103482. + *short_read = (hctsiz.b.xfersize != 0);
  103483. + }
  103484. + } else if (hc->qh->do_split) {
  103485. + //length = split_out_xfersize[hc->hc_num];
  103486. + length = qtd->ssplit_out_xfer_count;
  103487. + } else {
  103488. + length = hc->xfer_len;
  103489. + }
  103490. + } else {
  103491. + /*
  103492. + * Must use the hctsiz.pktcnt field to determine how much data
  103493. + * has been transferred. This field reflects the number of
  103494. + * packets that have been transferred via the USB. This is
  103495. + * always an integral number of packets if the transfer was
  103496. + * halted before its normal completion. (Can't use the
  103497. + * hctsiz.xfersize field because that reflects the number of
  103498. + * bytes transferred via the AHB, not the USB).
  103499. + */
  103500. + length =
  103501. + (hc->start_pkt_count - hctsiz.b.pktcnt) * hc->max_packet;
  103502. + }
  103503. +
  103504. + return length;
  103505. +}
  103506. +
  103507. +/**
  103508. + * Updates the state of the URB after a Transfer Complete interrupt on the
  103509. + * host channel. Updates the actual_length field of the URB based on the
  103510. + * number of bytes transferred via the host channel. Sets the URB status
  103511. + * if the data transfer is finished.
  103512. + *
  103513. + * @return 1 if the data transfer specified by the URB is completely finished,
  103514. + * 0 otherwise.
  103515. + */
  103516. +static int update_urb_state_xfer_comp(dwc_hc_t * hc,
  103517. + dwc_otg_hc_regs_t * hc_regs,
  103518. + dwc_otg_hcd_urb_t * urb,
  103519. + dwc_otg_qtd_t * qtd)
  103520. +{
  103521. + int xfer_done = 0;
  103522. + int short_read = 0;
  103523. +
  103524. + int xfer_length;
  103525. +
  103526. + xfer_length = get_actual_xfer_length(hc, hc_regs, qtd,
  103527. + DWC_OTG_HC_XFER_COMPLETE,
  103528. + &short_read);
  103529. +
  103530. + /* non DWORD-aligned buffer case handling. */
  103531. + if (hc->align_buff && xfer_length && hc->ep_is_in) {
  103532. + dwc_memcpy(urb->buf + urb->actual_length, hc->qh->dw_align_buf,
  103533. + xfer_length);
  103534. + }
  103535. +
  103536. + urb->actual_length += xfer_length;
  103537. +
  103538. + if (xfer_length && (hc->ep_type == DWC_OTG_EP_TYPE_BULK) &&
  103539. + (urb->flags & URB_SEND_ZERO_PACKET)
  103540. + && (urb->actual_length == urb->length)
  103541. + && !(urb->length % hc->max_packet)) {
  103542. + xfer_done = 0;
  103543. + } else if (short_read || urb->actual_length >= urb->length) {
  103544. + xfer_done = 1;
  103545. + urb->status = 0;
  103546. + }
  103547. +
  103548. +#ifdef DEBUG
  103549. + {
  103550. + hctsiz_data_t hctsiz;
  103551. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  103552. + DWC_DEBUGPL(DBG_HCDV, "DWC_otg: %s: %s, channel %d\n",
  103553. + __func__, (hc->ep_is_in ? "IN" : "OUT"),
  103554. + hc->hc_num);
  103555. + DWC_DEBUGPL(DBG_HCDV, " hc->xfer_len %d\n", hc->xfer_len);
  103556. + DWC_DEBUGPL(DBG_HCDV, " hctsiz.xfersize %d\n",
  103557. + hctsiz.b.xfersize);
  103558. + DWC_DEBUGPL(DBG_HCDV, " urb->transfer_buffer_length %d\n",
  103559. + urb->length);
  103560. + DWC_DEBUGPL(DBG_HCDV, " urb->actual_length %d\n",
  103561. + urb->actual_length);
  103562. + DWC_DEBUGPL(DBG_HCDV, " short_read %d, xfer_done %d\n",
  103563. + short_read, xfer_done);
  103564. + }
  103565. +#endif
  103566. +
  103567. + return xfer_done;
  103568. +}
  103569. +
  103570. +/*
  103571. + * Save the starting data toggle for the next transfer. The data toggle is
  103572. + * saved in the QH for non-control transfers and it's saved in the QTD for
  103573. + * control transfers.
  103574. + */
  103575. +void dwc_otg_hcd_save_data_toggle(dwc_hc_t * hc,
  103576. + dwc_otg_hc_regs_t * hc_regs, dwc_otg_qtd_t * qtd)
  103577. +{
  103578. + hctsiz_data_t hctsiz;
  103579. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  103580. +
  103581. + if (hc->ep_type != DWC_OTG_EP_TYPE_CONTROL) {
  103582. + dwc_otg_qh_t *qh = hc->qh;
  103583. + if (hctsiz.b.pid == DWC_HCTSIZ_DATA0) {
  103584. + qh->data_toggle = DWC_OTG_HC_PID_DATA0;
  103585. + } else {
  103586. + qh->data_toggle = DWC_OTG_HC_PID_DATA1;
  103587. + }
  103588. + } else {
  103589. + if (hctsiz.b.pid == DWC_HCTSIZ_DATA0) {
  103590. + qtd->data_toggle = DWC_OTG_HC_PID_DATA0;
  103591. + } else {
  103592. + qtd->data_toggle = DWC_OTG_HC_PID_DATA1;
  103593. + }
  103594. + }
  103595. +}
  103596. +
  103597. +/**
  103598. + * Updates the state of an Isochronous URB when the transfer is stopped for
  103599. + * any reason. The fields of the current entry in the frame descriptor array
  103600. + * are set based on the transfer state and the input _halt_status. Completes
  103601. + * the Isochronous URB if all the URB frames have been completed.
  103602. + *
  103603. + * @return DWC_OTG_HC_XFER_COMPLETE if there are more frames remaining to be
  103604. + * transferred in the URB. Otherwise return DWC_OTG_HC_XFER_URB_COMPLETE.
  103605. + */
  103606. +static dwc_otg_halt_status_e
  103607. +update_isoc_urb_state(dwc_otg_hcd_t * hcd,
  103608. + dwc_hc_t * hc,
  103609. + dwc_otg_hc_regs_t * hc_regs,
  103610. + dwc_otg_qtd_t * qtd, dwc_otg_halt_status_e halt_status)
  103611. +{
  103612. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  103613. + dwc_otg_halt_status_e ret_val = halt_status;
  103614. + struct dwc_otg_hcd_iso_packet_desc *frame_desc;
  103615. +
  103616. + frame_desc = &urb->iso_descs[qtd->isoc_frame_index];
  103617. + switch (halt_status) {
  103618. + case DWC_OTG_HC_XFER_COMPLETE:
  103619. + frame_desc->status = 0;
  103620. + frame_desc->actual_length =
  103621. + get_actual_xfer_length(hc, hc_regs, qtd, halt_status, NULL);
  103622. +
  103623. + /* non DWORD-aligned buffer case handling. */
  103624. + if (hc->align_buff && frame_desc->actual_length && hc->ep_is_in) {
  103625. + dwc_memcpy(urb->buf + frame_desc->offset + qtd->isoc_split_offset,
  103626. + hc->qh->dw_align_buf, frame_desc->actual_length);
  103627. + }
  103628. +
  103629. + break;
  103630. + case DWC_OTG_HC_XFER_FRAME_OVERRUN:
  103631. + urb->error_count++;
  103632. + if (hc->ep_is_in) {
  103633. + frame_desc->status = -DWC_E_NO_STREAM_RES;
  103634. + } else {
  103635. + frame_desc->status = -DWC_E_COMMUNICATION;
  103636. + }
  103637. + frame_desc->actual_length = 0;
  103638. + break;
  103639. + case DWC_OTG_HC_XFER_BABBLE_ERR:
  103640. + urb->error_count++;
  103641. + frame_desc->status = -DWC_E_OVERFLOW;
  103642. + /* Don't need to update actual_length in this case. */
  103643. + break;
  103644. + case DWC_OTG_HC_XFER_XACT_ERR:
  103645. + urb->error_count++;
  103646. + frame_desc->status = -DWC_E_PROTOCOL;
  103647. + frame_desc->actual_length =
  103648. + get_actual_xfer_length(hc, hc_regs, qtd, halt_status, NULL);
  103649. +
  103650. + /* non DWORD-aligned buffer case handling. */
  103651. + if (hc->align_buff && frame_desc->actual_length && hc->ep_is_in) {
  103652. + dwc_memcpy(urb->buf + frame_desc->offset + qtd->isoc_split_offset,
  103653. + hc->qh->dw_align_buf, frame_desc->actual_length);
  103654. + }
  103655. + /* Skip whole frame */
  103656. + if (hc->qh->do_split && (hc->ep_type == DWC_OTG_EP_TYPE_ISOC) &&
  103657. + hc->ep_is_in && hcd->core_if->dma_enable) {
  103658. + qtd->complete_split = 0;
  103659. + qtd->isoc_split_offset = 0;
  103660. + }
  103661. +
  103662. + break;
  103663. + default:
  103664. + DWC_ASSERT(1, "Unhandled _halt_status (%d)\n", halt_status);
  103665. + break;
  103666. + }
  103667. + if (++qtd->isoc_frame_index == urb->packet_count) {
  103668. + /*
  103669. + * urb->status is not used for isoc transfers.
  103670. + * The individual frame_desc statuses are used instead.
  103671. + */
  103672. + hcd->fops->complete(hcd, urb->priv, urb, 0);
  103673. + ret_val = DWC_OTG_HC_XFER_URB_COMPLETE;
  103674. + } else {
  103675. + ret_val = DWC_OTG_HC_XFER_COMPLETE;
  103676. + }
  103677. + return ret_val;
  103678. +}
  103679. +
  103680. +/**
  103681. + * Frees the first QTD in the QH's list if free_qtd is 1. For non-periodic
  103682. + * QHs, removes the QH from the active non-periodic schedule. If any QTDs are
  103683. + * still linked to the QH, the QH is added to the end of the inactive
  103684. + * non-periodic schedule. For periodic QHs, removes the QH from the periodic
  103685. + * schedule if no more QTDs are linked to the QH.
  103686. + */
  103687. +static void deactivate_qh(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh, int free_qtd)
  103688. +{
  103689. + int continue_split = 0;
  103690. + dwc_otg_qtd_t *qtd;
  103691. +
  103692. + DWC_DEBUGPL(DBG_HCDV, " %s(%p,%p,%d)\n", __func__, hcd, qh, free_qtd);
  103693. +
  103694. + qtd = DWC_CIRCLEQ_FIRST(&qh->qtd_list);
  103695. +
  103696. + if (qtd->complete_split) {
  103697. + continue_split = 1;
  103698. + } else if (qtd->isoc_split_pos == DWC_HCSPLIT_XACTPOS_MID ||
  103699. + qtd->isoc_split_pos == DWC_HCSPLIT_XACTPOS_END) {
  103700. + continue_split = 1;
  103701. + }
  103702. +
  103703. + if (free_qtd) {
  103704. + dwc_otg_hcd_qtd_remove_and_free(hcd, qtd, qh);
  103705. + continue_split = 0;
  103706. + }
  103707. +
  103708. + qh->channel = NULL;
  103709. + dwc_otg_hcd_qh_deactivate(hcd, qh, continue_split);
  103710. +}
  103711. +
  103712. +/**
  103713. + * Releases a host channel for use by other transfers. Attempts to select and
  103714. + * queue more transactions since at least one host channel is available.
  103715. + *
  103716. + * @param hcd The HCD state structure.
  103717. + * @param hc The host channel to release.
  103718. + * @param qtd The QTD associated with the host channel. This QTD may be freed
  103719. + * if the transfer is complete or an error has occurred.
  103720. + * @param halt_status Reason the channel is being released. This status
  103721. + * determines the actions taken by this function.
  103722. + */
  103723. +static void release_channel(dwc_otg_hcd_t * hcd,
  103724. + dwc_hc_t * hc,
  103725. + dwc_otg_qtd_t * qtd,
  103726. + dwc_otg_halt_status_e halt_status)
  103727. +{
  103728. + dwc_otg_transaction_type_e tr_type;
  103729. + int free_qtd;
  103730. + dwc_irqflags_t flags;
  103731. + dwc_spinlock_t *channel_lock = hcd->channel_lock;
  103732. +
  103733. + int hog_port = 0;
  103734. +
  103735. + DWC_DEBUGPL(DBG_HCDV, " %s: channel %d, halt_status %d, xfer_len %d\n",
  103736. + __func__, hc->hc_num, halt_status, hc->xfer_len);
  103737. +
  103738. + if(fiq_fsm_enable && hc->do_split) {
  103739. + if(!hc->ep_is_in && hc->ep_type == UE_ISOCHRONOUS) {
  103740. + if(hc->xact_pos == DWC_HCSPLIT_XACTPOS_MID ||
  103741. + hc->xact_pos == DWC_HCSPLIT_XACTPOS_BEGIN) {
  103742. + hog_port = 0;
  103743. + }
  103744. + }
  103745. + }
  103746. +
  103747. + switch (halt_status) {
  103748. + case DWC_OTG_HC_XFER_URB_COMPLETE:
  103749. + free_qtd = 1;
  103750. + break;
  103751. + case DWC_OTG_HC_XFER_AHB_ERR:
  103752. + case DWC_OTG_HC_XFER_STALL:
  103753. + case DWC_OTG_HC_XFER_BABBLE_ERR:
  103754. + free_qtd = 1;
  103755. + break;
  103756. + case DWC_OTG_HC_XFER_XACT_ERR:
  103757. + if (qtd->error_count >= 3) {
  103758. + DWC_DEBUGPL(DBG_HCDV,
  103759. + " Complete URB with transaction error\n");
  103760. + free_qtd = 1;
  103761. + qtd->urb->status = -DWC_E_PROTOCOL;
  103762. + hcd->fops->complete(hcd, qtd->urb->priv,
  103763. + qtd->urb, -DWC_E_PROTOCOL);
  103764. + } else {
  103765. + free_qtd = 0;
  103766. + }
  103767. + break;
  103768. + case DWC_OTG_HC_XFER_URB_DEQUEUE:
  103769. + /*
  103770. + * The QTD has already been removed and the QH has been
  103771. + * deactivated. Don't want to do anything except release the
  103772. + * host channel and try to queue more transfers.
  103773. + */
  103774. + goto cleanup;
  103775. + case DWC_OTG_HC_XFER_NO_HALT_STATUS:
  103776. + free_qtd = 0;
  103777. + break;
  103778. + case DWC_OTG_HC_XFER_PERIODIC_INCOMPLETE:
  103779. + DWC_DEBUGPL(DBG_HCDV,
  103780. + " Complete URB with I/O error\n");
  103781. + free_qtd = 1;
  103782. + qtd->urb->status = -DWC_E_IO;
  103783. + hcd->fops->complete(hcd, qtd->urb->priv,
  103784. + qtd->urb, -DWC_E_IO);
  103785. + break;
  103786. + default:
  103787. + free_qtd = 0;
  103788. + break;
  103789. + }
  103790. +
  103791. + deactivate_qh(hcd, hc->qh, free_qtd);
  103792. +
  103793. +cleanup:
  103794. + /*
  103795. + * Release the host channel for use by other transfers. The cleanup
  103796. + * function clears the channel interrupt enables and conditions, so
  103797. + * there's no need to clear the Channel Halted interrupt separately.
  103798. + */
  103799. + if (fiq_fsm_enable && hcd->fiq_state->channel[hc->hc_num].fsm != FIQ_PASSTHROUGH)
  103800. + dwc_otg_cleanup_fiq_channel(hcd, hc->hc_num);
  103801. + dwc_otg_hc_cleanup(hcd->core_if, hc);
  103802. + DWC_CIRCLEQ_INSERT_TAIL(&hcd->free_hc_list, hc, hc_list_entry);
  103803. +
  103804. + if (!microframe_schedule) {
  103805. + switch (hc->ep_type) {
  103806. + case DWC_OTG_EP_TYPE_CONTROL:
  103807. + case DWC_OTG_EP_TYPE_BULK:
  103808. + hcd->non_periodic_channels--;
  103809. + break;
  103810. +
  103811. + default:
  103812. + /*
  103813. + * Don't release reservations for periodic channels here.
  103814. + * That's done when a periodic transfer is descheduled (i.e.
  103815. + * when the QH is removed from the periodic schedule).
  103816. + */
  103817. + break;
  103818. + }
  103819. + } else {
  103820. +
  103821. + DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
  103822. + hcd->available_host_channels++;
  103823. + fiq_print(FIQDBG_INT, hcd->fiq_state, "AHC = %d ", hcd->available_host_channels);
  103824. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  103825. + }
  103826. +
  103827. + /* Try to queue more transfers now that there's a free channel. */
  103828. + tr_type = dwc_otg_hcd_select_transactions(hcd);
  103829. + if (tr_type != DWC_OTG_TRANSACTION_NONE) {
  103830. + dwc_otg_hcd_queue_transactions(hcd, tr_type);
  103831. + }
  103832. +}
  103833. +
  103834. +/**
  103835. + * Halts a host channel. If the channel cannot be halted immediately because
  103836. + * the request queue is full, this function ensures that the FIFO empty
  103837. + * interrupt for the appropriate queue is enabled so that the halt request can
  103838. + * be queued when there is space in the request queue.
  103839. + *
  103840. + * This function may also be called in DMA mode. In that case, the channel is
  103841. + * simply released since the core always halts the channel automatically in
  103842. + * DMA mode.
  103843. + */
  103844. +static void halt_channel(dwc_otg_hcd_t * hcd,
  103845. + dwc_hc_t * hc,
  103846. + dwc_otg_qtd_t * qtd, dwc_otg_halt_status_e halt_status)
  103847. +{
  103848. + if (hcd->core_if->dma_enable) {
  103849. + release_channel(hcd, hc, qtd, halt_status);
  103850. + return;
  103851. + }
  103852. +
  103853. + /* Slave mode processing... */
  103854. + dwc_otg_hc_halt(hcd->core_if, hc, halt_status);
  103855. +
  103856. + if (hc->halt_on_queue) {
  103857. + gintmsk_data_t gintmsk = {.d32 = 0 };
  103858. + dwc_otg_core_global_regs_t *global_regs;
  103859. + global_regs = hcd->core_if->core_global_regs;
  103860. +
  103861. + if (hc->ep_type == DWC_OTG_EP_TYPE_CONTROL ||
  103862. + hc->ep_type == DWC_OTG_EP_TYPE_BULK) {
  103863. + /*
  103864. + * Make sure the Non-periodic Tx FIFO empty interrupt
  103865. + * is enabled so that the non-periodic schedule will
  103866. + * be processed.
  103867. + */
  103868. + gintmsk.b.nptxfempty = 1;
  103869. + if (fiq_enable) {
  103870. + local_fiq_disable();
  103871. + fiq_fsm_spin_lock(&hcd->fiq_state->lock);
  103872. + DWC_MODIFY_REG32(&global_regs->gintmsk, 0, gintmsk.d32);
  103873. + fiq_fsm_spin_unlock(&hcd->fiq_state->lock);
  103874. + local_fiq_enable();
  103875. + } else {
  103876. + DWC_MODIFY_REG32(&global_regs->gintmsk, 0, gintmsk.d32);
  103877. + }
  103878. + } else {
  103879. + /*
  103880. + * Move the QH from the periodic queued schedule to
  103881. + * the periodic assigned schedule. This allows the
  103882. + * halt to be queued when the periodic schedule is
  103883. + * processed.
  103884. + */
  103885. + DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_assigned,
  103886. + &hc->qh->qh_list_entry);
  103887. +
  103888. + /*
  103889. + * Make sure the Periodic Tx FIFO Empty interrupt is
  103890. + * enabled so that the periodic schedule will be
  103891. + * processed.
  103892. + */
  103893. + gintmsk.b.ptxfempty = 1;
  103894. + if (fiq_enable) {
  103895. + local_fiq_disable();
  103896. + fiq_fsm_spin_lock(&hcd->fiq_state->lock);
  103897. + DWC_MODIFY_REG32(&global_regs->gintmsk, 0, gintmsk.d32);
  103898. + fiq_fsm_spin_unlock(&hcd->fiq_state->lock);
  103899. + local_fiq_enable();
  103900. + } else {
  103901. + DWC_MODIFY_REG32(&global_regs->gintmsk, 0, gintmsk.d32);
  103902. + }
  103903. + }
  103904. + }
  103905. +}
  103906. +
  103907. +/**
  103908. + * Performs common cleanup for non-periodic transfers after a Transfer
  103909. + * Complete interrupt. This function should be called after any endpoint type
  103910. + * specific handling is finished to release the host channel.
  103911. + */
  103912. +static void complete_non_periodic_xfer(dwc_otg_hcd_t * hcd,
  103913. + dwc_hc_t * hc,
  103914. + dwc_otg_hc_regs_t * hc_regs,
  103915. + dwc_otg_qtd_t * qtd,
  103916. + dwc_otg_halt_status_e halt_status)
  103917. +{
  103918. + hcint_data_t hcint;
  103919. +
  103920. + qtd->error_count = 0;
  103921. +
  103922. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  103923. + if (hcint.b.nyet) {
  103924. + /*
  103925. + * Got a NYET on the last transaction of the transfer. This
  103926. + * means that the endpoint should be in the PING state at the
  103927. + * beginning of the next transfer.
  103928. + */
  103929. + hc->qh->ping_state = 1;
  103930. + clear_hc_int(hc_regs, nyet);
  103931. + }
  103932. +
  103933. + /*
  103934. + * Always halt and release the host channel to make it available for
  103935. + * more transfers. There may still be more phases for a control
  103936. + * transfer or more data packets for a bulk transfer at this point,
  103937. + * but the host channel is still halted. A channel will be reassigned
  103938. + * to the transfer when the non-periodic schedule is processed after
  103939. + * the channel is released. This allows transactions to be queued
  103940. + * properly via dwc_otg_hcd_queue_transactions, which also enables the
  103941. + * Tx FIFO Empty interrupt if necessary.
  103942. + */
  103943. + if (hc->ep_is_in) {
  103944. + /*
  103945. + * IN transfers in Slave mode require an explicit disable to
  103946. + * halt the channel. (In DMA mode, this call simply releases
  103947. + * the channel.)
  103948. + */
  103949. + halt_channel(hcd, hc, qtd, halt_status);
  103950. + } else {
  103951. + /*
  103952. + * The channel is automatically disabled by the core for OUT
  103953. + * transfers in Slave mode.
  103954. + */
  103955. + release_channel(hcd, hc, qtd, halt_status);
  103956. + }
  103957. +}
  103958. +
  103959. +/**
  103960. + * Performs common cleanup for periodic transfers after a Transfer Complete
  103961. + * interrupt. This function should be called after any endpoint type specific
  103962. + * handling is finished to release the host channel.
  103963. + */
  103964. +static void complete_periodic_xfer(dwc_otg_hcd_t * hcd,
  103965. + dwc_hc_t * hc,
  103966. + dwc_otg_hc_regs_t * hc_regs,
  103967. + dwc_otg_qtd_t * qtd,
  103968. + dwc_otg_halt_status_e halt_status)
  103969. +{
  103970. + hctsiz_data_t hctsiz;
  103971. + qtd->error_count = 0;
  103972. +
  103973. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  103974. + if (!hc->ep_is_in || hctsiz.b.pktcnt == 0) {
  103975. + /* Core halts channel in these cases. */
  103976. + release_channel(hcd, hc, qtd, halt_status);
  103977. + } else {
  103978. + /* Flush any outstanding requests from the Tx queue. */
  103979. + halt_channel(hcd, hc, qtd, halt_status);
  103980. + }
  103981. +}
  103982. +
  103983. +static int32_t handle_xfercomp_isoc_split_in(dwc_otg_hcd_t * hcd,
  103984. + dwc_hc_t * hc,
  103985. + dwc_otg_hc_regs_t * hc_regs,
  103986. + dwc_otg_qtd_t * qtd)
  103987. +{
  103988. + uint32_t len;
  103989. + struct dwc_otg_hcd_iso_packet_desc *frame_desc;
  103990. + frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
  103991. +
  103992. + len = get_actual_xfer_length(hc, hc_regs, qtd,
  103993. + DWC_OTG_HC_XFER_COMPLETE, NULL);
  103994. +
  103995. + if (!len) {
  103996. + qtd->complete_split = 0;
  103997. + qtd->isoc_split_offset = 0;
  103998. + return 0;
  103999. + }
  104000. + frame_desc->actual_length += len;
  104001. +
  104002. + if (hc->align_buff && len)
  104003. + dwc_memcpy(qtd->urb->buf + frame_desc->offset +
  104004. + qtd->isoc_split_offset, hc->qh->dw_align_buf, len);
  104005. + qtd->isoc_split_offset += len;
  104006. +
  104007. + if (frame_desc->length == frame_desc->actual_length) {
  104008. + frame_desc->status = 0;
  104009. + qtd->isoc_frame_index++;
  104010. + qtd->complete_split = 0;
  104011. + qtd->isoc_split_offset = 0;
  104012. + }
  104013. +
  104014. + if (qtd->isoc_frame_index == qtd->urb->packet_count) {
  104015. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
  104016. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  104017. + } else {
  104018. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NO_HALT_STATUS);
  104019. + }
  104020. +
  104021. + return 1; /* Indicates that channel released */
  104022. +}
  104023. +
  104024. +/**
  104025. + * Handles a host channel Transfer Complete interrupt. This handler may be
  104026. + * called in either DMA mode or Slave mode.
  104027. + */
  104028. +static int32_t handle_hc_xfercomp_intr(dwc_otg_hcd_t * hcd,
  104029. + dwc_hc_t * hc,
  104030. + dwc_otg_hc_regs_t * hc_regs,
  104031. + dwc_otg_qtd_t * qtd)
  104032. +{
  104033. + int urb_xfer_done;
  104034. + dwc_otg_halt_status_e halt_status = DWC_OTG_HC_XFER_COMPLETE;
  104035. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  104036. + int pipe_type = dwc_otg_hcd_get_pipe_type(&urb->pipe_info);
  104037. +
  104038. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  104039. + "Transfer Complete--\n", hc->hc_num);
  104040. +
  104041. + if (hcd->core_if->dma_desc_enable) {
  104042. + dwc_otg_hcd_complete_xfer_ddma(hcd, hc, hc_regs, halt_status);
  104043. + if (pipe_type == UE_ISOCHRONOUS) {
  104044. + /* Do not disable the interrupt, just clear it */
  104045. + clear_hc_int(hc_regs, xfercomp);
  104046. + return 1;
  104047. + }
  104048. + goto handle_xfercomp_done;
  104049. + }
  104050. +
  104051. + /*
  104052. + * Handle xfer complete on CSPLIT.
  104053. + */
  104054. +
  104055. + if (hc->qh->do_split) {
  104056. + if ((hc->ep_type == DWC_OTG_EP_TYPE_ISOC) && hc->ep_is_in
  104057. + && hcd->core_if->dma_enable) {
  104058. + if (qtd->complete_split
  104059. + && handle_xfercomp_isoc_split_in(hcd, hc, hc_regs,
  104060. + qtd))
  104061. + goto handle_xfercomp_done;
  104062. + } else {
  104063. + qtd->complete_split = 0;
  104064. + }
  104065. + }
  104066. +
  104067. + /* Update the QTD and URB states. */
  104068. + switch (pipe_type) {
  104069. + case UE_CONTROL:
  104070. + switch (qtd->control_phase) {
  104071. + case DWC_OTG_CONTROL_SETUP:
  104072. + if (urb->length > 0) {
  104073. + qtd->control_phase = DWC_OTG_CONTROL_DATA;
  104074. + } else {
  104075. + qtd->control_phase = DWC_OTG_CONTROL_STATUS;
  104076. + }
  104077. + DWC_DEBUGPL(DBG_HCDV,
  104078. + " Control setup transaction done\n");
  104079. + halt_status = DWC_OTG_HC_XFER_COMPLETE;
  104080. + break;
  104081. + case DWC_OTG_CONTROL_DATA:{
  104082. + urb_xfer_done =
  104083. + update_urb_state_xfer_comp(hc, hc_regs, urb,
  104084. + qtd);
  104085. + if (urb_xfer_done) {
  104086. + qtd->control_phase =
  104087. + DWC_OTG_CONTROL_STATUS;
  104088. + DWC_DEBUGPL(DBG_HCDV,
  104089. + " Control data transfer done\n");
  104090. + } else {
  104091. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  104092. + }
  104093. + halt_status = DWC_OTG_HC_XFER_COMPLETE;
  104094. + break;
  104095. + }
  104096. + case DWC_OTG_CONTROL_STATUS:
  104097. + DWC_DEBUGPL(DBG_HCDV, " Control transfer complete\n");
  104098. + if (urb->status == -DWC_E_IN_PROGRESS) {
  104099. + urb->status = 0;
  104100. + }
  104101. + hcd->fops->complete(hcd, urb->priv, urb, urb->status);
  104102. + halt_status = DWC_OTG_HC_XFER_URB_COMPLETE;
  104103. + break;
  104104. + }
  104105. +
  104106. + complete_non_periodic_xfer(hcd, hc, hc_regs, qtd, halt_status);
  104107. + break;
  104108. + case UE_BULK:
  104109. + DWC_DEBUGPL(DBG_HCDV, " Bulk transfer complete\n");
  104110. + urb_xfer_done =
  104111. + update_urb_state_xfer_comp(hc, hc_regs, urb, qtd);
  104112. + if (urb_xfer_done) {
  104113. + hcd->fops->complete(hcd, urb->priv, urb, urb->status);
  104114. + halt_status = DWC_OTG_HC_XFER_URB_COMPLETE;
  104115. + } else {
  104116. + halt_status = DWC_OTG_HC_XFER_COMPLETE;
  104117. + }
  104118. +
  104119. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  104120. + complete_non_periodic_xfer(hcd, hc, hc_regs, qtd, halt_status);
  104121. + break;
  104122. + case UE_INTERRUPT:
  104123. + DWC_DEBUGPL(DBG_HCDV, " Interrupt transfer complete\n");
  104124. + urb_xfer_done =
  104125. + update_urb_state_xfer_comp(hc, hc_regs, urb, qtd);
  104126. +
  104127. + /*
  104128. + * Interrupt URB is done on the first transfer complete
  104129. + * interrupt.
  104130. + */
  104131. + if (urb_xfer_done) {
  104132. + hcd->fops->complete(hcd, urb->priv, urb, urb->status);
  104133. + halt_status = DWC_OTG_HC_XFER_URB_COMPLETE;
  104134. + } else {
  104135. + halt_status = DWC_OTG_HC_XFER_COMPLETE;
  104136. + }
  104137. +
  104138. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  104139. + complete_periodic_xfer(hcd, hc, hc_regs, qtd, halt_status);
  104140. + break;
  104141. + case UE_ISOCHRONOUS:
  104142. + DWC_DEBUGPL(DBG_HCDV, " Isochronous transfer complete\n");
  104143. + if (qtd->isoc_split_pos == DWC_HCSPLIT_XACTPOS_ALL) {
  104144. + halt_status =
  104145. + update_isoc_urb_state(hcd, hc, hc_regs, qtd,
  104146. + DWC_OTG_HC_XFER_COMPLETE);
  104147. + }
  104148. + complete_periodic_xfer(hcd, hc, hc_regs, qtd, halt_status);
  104149. + break;
  104150. + }
  104151. +
  104152. +handle_xfercomp_done:
  104153. + disable_hc_int(hc_regs, xfercompl);
  104154. +
  104155. + return 1;
  104156. +}
  104157. +
  104158. +/**
  104159. + * Handles a host channel STALL interrupt. This handler may be called in
  104160. + * either DMA mode or Slave mode.
  104161. + */
  104162. +static int32_t handle_hc_stall_intr(dwc_otg_hcd_t * hcd,
  104163. + dwc_hc_t * hc,
  104164. + dwc_otg_hc_regs_t * hc_regs,
  104165. + dwc_otg_qtd_t * qtd)
  104166. +{
  104167. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  104168. + int pipe_type = dwc_otg_hcd_get_pipe_type(&urb->pipe_info);
  104169. +
  104170. + DWC_DEBUGPL(DBG_HCD, "--Host Channel %d Interrupt: "
  104171. + "STALL Received--\n", hc->hc_num);
  104172. +
  104173. + if (hcd->core_if->dma_desc_enable) {
  104174. + dwc_otg_hcd_complete_xfer_ddma(hcd, hc, hc_regs, DWC_OTG_HC_XFER_STALL);
  104175. + goto handle_stall_done;
  104176. + }
  104177. +
  104178. + if (pipe_type == UE_CONTROL) {
  104179. + hcd->fops->complete(hcd, urb->priv, urb, -DWC_E_PIPE);
  104180. + }
  104181. +
  104182. + if (pipe_type == UE_BULK || pipe_type == UE_INTERRUPT) {
  104183. + hcd->fops->complete(hcd, urb->priv, urb, -DWC_E_PIPE);
  104184. + /*
  104185. + * USB protocol requires resetting the data toggle for bulk
  104186. + * and interrupt endpoints when a CLEAR_FEATURE(ENDPOINT_HALT)
  104187. + * setup command is issued to the endpoint. Anticipate the
  104188. + * CLEAR_FEATURE command since a STALL has occurred and reset
  104189. + * the data toggle now.
  104190. + */
  104191. + hc->qh->data_toggle = 0;
  104192. + }
  104193. +
  104194. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_STALL);
  104195. +
  104196. +handle_stall_done:
  104197. + disable_hc_int(hc_regs, stall);
  104198. +
  104199. + return 1;
  104200. +}
  104201. +
  104202. +/*
  104203. + * Updates the state of the URB when a transfer has been stopped due to an
  104204. + * abnormal condition before the transfer completes. Modifies the
  104205. + * actual_length field of the URB to reflect the number of bytes that have
  104206. + * actually been transferred via the host channel.
  104207. + */
  104208. +static void update_urb_state_xfer_intr(dwc_hc_t * hc,
  104209. + dwc_otg_hc_regs_t * hc_regs,
  104210. + dwc_otg_hcd_urb_t * urb,
  104211. + dwc_otg_qtd_t * qtd,
  104212. + dwc_otg_halt_status_e halt_status)
  104213. +{
  104214. + uint32_t bytes_transferred = get_actual_xfer_length(hc, hc_regs, qtd,
  104215. + halt_status, NULL);
  104216. + /* non DWORD-aligned buffer case handling. */
  104217. + if (hc->align_buff && bytes_transferred && hc->ep_is_in) {
  104218. + dwc_memcpy(urb->buf + urb->actual_length, hc->qh->dw_align_buf,
  104219. + bytes_transferred);
  104220. + }
  104221. +
  104222. + urb->actual_length += bytes_transferred;
  104223. +
  104224. +#ifdef DEBUG
  104225. + {
  104226. + hctsiz_data_t hctsiz;
  104227. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  104228. + DWC_DEBUGPL(DBG_HCDV, "DWC_otg: %s: %s, channel %d\n",
  104229. + __func__, (hc->ep_is_in ? "IN" : "OUT"),
  104230. + hc->hc_num);
  104231. + DWC_DEBUGPL(DBG_HCDV, " hc->start_pkt_count %d\n",
  104232. + hc->start_pkt_count);
  104233. + DWC_DEBUGPL(DBG_HCDV, " hctsiz.pktcnt %d\n", hctsiz.b.pktcnt);
  104234. + DWC_DEBUGPL(DBG_HCDV, " hc->max_packet %d\n", hc->max_packet);
  104235. + DWC_DEBUGPL(DBG_HCDV, " bytes_transferred %d\n",
  104236. + bytes_transferred);
  104237. + DWC_DEBUGPL(DBG_HCDV, " urb->actual_length %d\n",
  104238. + urb->actual_length);
  104239. + DWC_DEBUGPL(DBG_HCDV, " urb->transfer_buffer_length %d\n",
  104240. + urb->length);
  104241. + }
  104242. +#endif
  104243. +}
  104244. +
  104245. +/**
  104246. + * Handles a host channel NAK interrupt. This handler may be called in either
  104247. + * DMA mode or Slave mode.
  104248. + */
  104249. +static int32_t handle_hc_nak_intr(dwc_otg_hcd_t * hcd,
  104250. + dwc_hc_t * hc,
  104251. + dwc_otg_hc_regs_t * hc_regs,
  104252. + dwc_otg_qtd_t * qtd)
  104253. +{
  104254. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  104255. + "NAK Received--\n", hc->hc_num);
  104256. +
  104257. + /*
  104258. + * When we get bulk NAKs then remember this so we holdoff on this qh until
  104259. + * the beginning of the next frame
  104260. + */
  104261. + switch(dwc_otg_hcd_get_pipe_type(&qtd->urb->pipe_info)) {
  104262. + case UE_BULK:
  104263. + case UE_CONTROL:
  104264. + if (nak_holdoff && qtd->qh->do_split)
  104265. + hc->qh->nak_frame = dwc_otg_hcd_get_frame_number(hcd);
  104266. + }
  104267. +
  104268. + /*
  104269. + * Handle NAK for IN/OUT SSPLIT/CSPLIT transfers, bulk, control, and
  104270. + * interrupt. Re-start the SSPLIT transfer.
  104271. + */
  104272. + if (hc->do_split) {
  104273. + if (hc->complete_split) {
  104274. + qtd->error_count = 0;
  104275. + }
  104276. + qtd->complete_split = 0;
  104277. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NAK);
  104278. + goto handle_nak_done;
  104279. + }
  104280. +
  104281. + switch (dwc_otg_hcd_get_pipe_type(&qtd->urb->pipe_info)) {
  104282. + case UE_CONTROL:
  104283. + case UE_BULK:
  104284. + if (hcd->core_if->dma_enable && hc->ep_is_in) {
  104285. + /*
  104286. + * NAK interrupts are enabled on bulk/control IN
  104287. + * transfers in DMA mode for the sole purpose of
  104288. + * resetting the error count after a transaction error
  104289. + * occurs. The core will continue transferring data.
  104290. + * Disable other interrupts unmasked for the same
  104291. + * reason.
  104292. + */
  104293. + disable_hc_int(hc_regs, datatglerr);
  104294. + disable_hc_int(hc_regs, ack);
  104295. + qtd->error_count = 0;
  104296. + goto handle_nak_done;
  104297. + }
  104298. +
  104299. + /*
  104300. + * NAK interrupts normally occur during OUT transfers in DMA
  104301. + * or Slave mode. For IN transfers, more requests will be
  104302. + * queued as request queue space is available.
  104303. + */
  104304. + qtd->error_count = 0;
  104305. +
  104306. + if (!hc->qh->ping_state) {
  104307. + update_urb_state_xfer_intr(hc, hc_regs,
  104308. + qtd->urb, qtd,
  104309. + DWC_OTG_HC_XFER_NAK);
  104310. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  104311. +
  104312. + if (hc->speed == DWC_OTG_EP_SPEED_HIGH)
  104313. + hc->qh->ping_state = 1;
  104314. + }
  104315. +
  104316. + /*
  104317. + * Halt the channel so the transfer can be re-started from
  104318. + * the appropriate point or the PING protocol will
  104319. + * start/continue.
  104320. + */
  104321. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NAK);
  104322. + break;
  104323. + case UE_INTERRUPT:
  104324. + qtd->error_count = 0;
  104325. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NAK);
  104326. + break;
  104327. + case UE_ISOCHRONOUS:
  104328. + /* Should never get called for isochronous transfers. */
  104329. + DWC_ASSERT(1, "NACK interrupt for ISOC transfer\n");
  104330. + break;
  104331. + }
  104332. +
  104333. +handle_nak_done:
  104334. + disable_hc_int(hc_regs, nak);
  104335. +
  104336. + return 1;
  104337. +}
  104338. +
  104339. +/**
  104340. + * Handles a host channel ACK interrupt. This interrupt is enabled when
  104341. + * performing the PING protocol in Slave mode, when errors occur during
  104342. + * either Slave mode or DMA mode, and during Start Split transactions.
  104343. + */
  104344. +static int32_t handle_hc_ack_intr(dwc_otg_hcd_t * hcd,
  104345. + dwc_hc_t * hc,
  104346. + dwc_otg_hc_regs_t * hc_regs,
  104347. + dwc_otg_qtd_t * qtd)
  104348. +{
  104349. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  104350. + "ACK Received--\n", hc->hc_num);
  104351. +
  104352. + if (hc->do_split) {
  104353. + /*
  104354. + * Handle ACK on SSPLIT.
  104355. + * ACK should not occur in CSPLIT.
  104356. + */
  104357. + if (!hc->ep_is_in && hc->data_pid_start != DWC_OTG_HC_PID_SETUP) {
  104358. + qtd->ssplit_out_xfer_count = hc->xfer_len;
  104359. + }
  104360. + if (!(hc->ep_type == DWC_OTG_EP_TYPE_ISOC && !hc->ep_is_in)) {
  104361. + /* Don't need complete for isochronous out transfers. */
  104362. + qtd->complete_split = 1;
  104363. + }
  104364. +
  104365. + /* ISOC OUT */
  104366. + if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC && !hc->ep_is_in) {
  104367. + switch (hc->xact_pos) {
  104368. + case DWC_HCSPLIT_XACTPOS_ALL:
  104369. + break;
  104370. + case DWC_HCSPLIT_XACTPOS_END:
  104371. + qtd->isoc_split_pos = DWC_HCSPLIT_XACTPOS_ALL;
  104372. + qtd->isoc_split_offset = 0;
  104373. + break;
  104374. + case DWC_HCSPLIT_XACTPOS_BEGIN:
  104375. + case DWC_HCSPLIT_XACTPOS_MID:
  104376. + /*
  104377. + * For BEGIN or MID, calculate the length for
  104378. + * the next microframe to determine the correct
  104379. + * SSPLIT token, either MID or END.
  104380. + */
  104381. + {
  104382. + struct dwc_otg_hcd_iso_packet_desc
  104383. + *frame_desc;
  104384. +
  104385. + frame_desc =
  104386. + &qtd->urb->
  104387. + iso_descs[qtd->isoc_frame_index];
  104388. + qtd->isoc_split_offset += 188;
  104389. +
  104390. + if ((frame_desc->length -
  104391. + qtd->isoc_split_offset) <= 188) {
  104392. + qtd->isoc_split_pos =
  104393. + DWC_HCSPLIT_XACTPOS_END;
  104394. + } else {
  104395. + qtd->isoc_split_pos =
  104396. + DWC_HCSPLIT_XACTPOS_MID;
  104397. + }
  104398. +
  104399. + }
  104400. + break;
  104401. + }
  104402. + } else {
  104403. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_ACK);
  104404. + }
  104405. + } else {
  104406. + /*
  104407. + * An unmasked ACK on a non-split DMA transaction is
  104408. + * for the sole purpose of resetting error counts. Disable other
  104409. + * interrupts unmasked for the same reason.
  104410. + */
  104411. + if(hcd->core_if->dma_enable) {
  104412. + disable_hc_int(hc_regs, datatglerr);
  104413. + disable_hc_int(hc_regs, nak);
  104414. + }
  104415. + qtd->error_count = 0;
  104416. +
  104417. + if (hc->qh->ping_state) {
  104418. + hc->qh->ping_state = 0;
  104419. + /*
  104420. + * Halt the channel so the transfer can be re-started
  104421. + * from the appropriate point. This only happens in
  104422. + * Slave mode. In DMA mode, the ping_state is cleared
  104423. + * when the transfer is started because the core
  104424. + * automatically executes the PING, then the transfer.
  104425. + */
  104426. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_ACK);
  104427. + }
  104428. + }
  104429. +
  104430. + /*
  104431. + * If the ACK occurred when _not_ in the PING state, let the channel
  104432. + * continue transferring data after clearing the error count.
  104433. + */
  104434. +
  104435. + disable_hc_int(hc_regs, ack);
  104436. +
  104437. + return 1;
  104438. +}
  104439. +
  104440. +/**
  104441. + * Handles a host channel NYET interrupt. This interrupt should only occur on
  104442. + * Bulk and Control OUT endpoints and for complete split transactions. If a
  104443. + * NYET occurs at the same time as a Transfer Complete interrupt, it is
  104444. + * handled in the xfercomp interrupt handler, not here. This handler may be
  104445. + * called in either DMA mode or Slave mode.
  104446. + */
  104447. +static int32_t handle_hc_nyet_intr(dwc_otg_hcd_t * hcd,
  104448. + dwc_hc_t * hc,
  104449. + dwc_otg_hc_regs_t * hc_regs,
  104450. + dwc_otg_qtd_t * qtd)
  104451. +{
  104452. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  104453. + "NYET Received--\n", hc->hc_num);
  104454. +
  104455. + /*
  104456. + * NYET on CSPLIT
  104457. + * re-do the CSPLIT immediately on non-periodic
  104458. + */
  104459. + if (hc->do_split && hc->complete_split) {
  104460. + if (hc->ep_is_in && (hc->ep_type == DWC_OTG_EP_TYPE_ISOC)
  104461. + && hcd->core_if->dma_enable) {
  104462. + qtd->complete_split = 0;
  104463. + qtd->isoc_split_offset = 0;
  104464. + if (++qtd->isoc_frame_index == qtd->urb->packet_count) {
  104465. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
  104466. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  104467. + }
  104468. + else
  104469. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NO_HALT_STATUS);
  104470. + goto handle_nyet_done;
  104471. + }
  104472. +
  104473. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  104474. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  104475. + int frnum = dwc_otg_hcd_get_frame_number(hcd);
  104476. +
  104477. + // With the FIQ running we only ever see the failed NYET
  104478. + if (dwc_full_frame_num(frnum) !=
  104479. + dwc_full_frame_num(hc->qh->sched_frame) ||
  104480. + fiq_fsm_enable) {
  104481. + /*
  104482. + * No longer in the same full speed frame.
  104483. + * Treat this as a transaction error.
  104484. + */
  104485. +#if 0
  104486. + /** @todo Fix system performance so this can
  104487. + * be treated as an error. Right now complete
  104488. + * splits cannot be scheduled precisely enough
  104489. + * due to other system activity, so this error
  104490. + * occurs regularly in Slave mode.
  104491. + */
  104492. + qtd->error_count++;
  104493. +#endif
  104494. + qtd->complete_split = 0;
  104495. + halt_channel(hcd, hc, qtd,
  104496. + DWC_OTG_HC_XFER_XACT_ERR);
  104497. + /** @todo add support for isoc release */
  104498. + goto handle_nyet_done;
  104499. + }
  104500. + }
  104501. +
  104502. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NYET);
  104503. + goto handle_nyet_done;
  104504. + }
  104505. +
  104506. + hc->qh->ping_state = 1;
  104507. + qtd->error_count = 0;
  104508. +
  104509. + update_urb_state_xfer_intr(hc, hc_regs, qtd->urb, qtd,
  104510. + DWC_OTG_HC_XFER_NYET);
  104511. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  104512. +
  104513. + /*
  104514. + * Halt the channel and re-start the transfer so the PING
  104515. + * protocol will start.
  104516. + */
  104517. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NYET);
  104518. +
  104519. +handle_nyet_done:
  104520. + disable_hc_int(hc_regs, nyet);
  104521. + return 1;
  104522. +}
  104523. +
  104524. +/**
  104525. + * Handles a host channel babble interrupt. This handler may be called in
  104526. + * either DMA mode or Slave mode.
  104527. + */
  104528. +static int32_t handle_hc_babble_intr(dwc_otg_hcd_t * hcd,
  104529. + dwc_hc_t * hc,
  104530. + dwc_otg_hc_regs_t * hc_regs,
  104531. + dwc_otg_qtd_t * qtd)
  104532. +{
  104533. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  104534. + "Babble Error--\n", hc->hc_num);
  104535. +
  104536. + if (hcd->core_if->dma_desc_enable) {
  104537. + dwc_otg_hcd_complete_xfer_ddma(hcd, hc, hc_regs,
  104538. + DWC_OTG_HC_XFER_BABBLE_ERR);
  104539. + goto handle_babble_done;
  104540. + }
  104541. +
  104542. + if (hc->ep_type != DWC_OTG_EP_TYPE_ISOC) {
  104543. + hcd->fops->complete(hcd, qtd->urb->priv,
  104544. + qtd->urb, -DWC_E_OVERFLOW);
  104545. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_BABBLE_ERR);
  104546. + } else {
  104547. + dwc_otg_halt_status_e halt_status;
  104548. + halt_status = update_isoc_urb_state(hcd, hc, hc_regs, qtd,
  104549. + DWC_OTG_HC_XFER_BABBLE_ERR);
  104550. + halt_channel(hcd, hc, qtd, halt_status);
  104551. + }
  104552. +
  104553. +handle_babble_done:
  104554. + disable_hc_int(hc_regs, bblerr);
  104555. + return 1;
  104556. +}
  104557. +
  104558. +/**
  104559. + * Handles a host channel AHB error interrupt. This handler is only called in
  104560. + * DMA mode.
  104561. + */
  104562. +static int32_t handle_hc_ahberr_intr(dwc_otg_hcd_t * hcd,
  104563. + dwc_hc_t * hc,
  104564. + dwc_otg_hc_regs_t * hc_regs,
  104565. + dwc_otg_qtd_t * qtd)
  104566. +{
  104567. + hcchar_data_t hcchar;
  104568. + hcsplt_data_t hcsplt;
  104569. + hctsiz_data_t hctsiz;
  104570. + uint32_t hcdma;
  104571. + char *pipetype, *speed;
  104572. +
  104573. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  104574. +
  104575. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  104576. + "AHB Error--\n", hc->hc_num);
  104577. +
  104578. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  104579. + hcsplt.d32 = DWC_READ_REG32(&hc_regs->hcsplt);
  104580. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  104581. + hcdma = DWC_READ_REG32(&hc_regs->hcdma);
  104582. +
  104583. + DWC_ERROR("AHB ERROR, Channel %d\n", hc->hc_num);
  104584. + DWC_ERROR(" hcchar 0x%08x, hcsplt 0x%08x\n", hcchar.d32, hcsplt.d32);
  104585. + DWC_ERROR(" hctsiz 0x%08x, hcdma 0x%08x\n", hctsiz.d32, hcdma);
  104586. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD URB Enqueue\n");
  104587. + DWC_ERROR(" Device address: %d\n",
  104588. + dwc_otg_hcd_get_dev_addr(&urb->pipe_info));
  104589. + DWC_ERROR(" Endpoint: %d, %s\n",
  104590. + dwc_otg_hcd_get_ep_num(&urb->pipe_info),
  104591. + (dwc_otg_hcd_is_pipe_in(&urb->pipe_info) ? "IN" : "OUT"));
  104592. +
  104593. + switch (dwc_otg_hcd_get_pipe_type(&urb->pipe_info)) {
  104594. + case UE_CONTROL:
  104595. + pipetype = "CONTROL";
  104596. + break;
  104597. + case UE_BULK:
  104598. + pipetype = "BULK";
  104599. + break;
  104600. + case UE_INTERRUPT:
  104601. + pipetype = "INTERRUPT";
  104602. + break;
  104603. + case UE_ISOCHRONOUS:
  104604. + pipetype = "ISOCHRONOUS";
  104605. + break;
  104606. + default:
  104607. + pipetype = "UNKNOWN";
  104608. + break;
  104609. + }
  104610. +
  104611. + DWC_ERROR(" Endpoint type: %s\n", pipetype);
  104612. +
  104613. + switch (hc->speed) {
  104614. + case DWC_OTG_EP_SPEED_HIGH:
  104615. + speed = "HIGH";
  104616. + break;
  104617. + case DWC_OTG_EP_SPEED_FULL:
  104618. + speed = "FULL";
  104619. + break;
  104620. + case DWC_OTG_EP_SPEED_LOW:
  104621. + speed = "LOW";
  104622. + break;
  104623. + default:
  104624. + speed = "UNKNOWN";
  104625. + break;
  104626. + };
  104627. +
  104628. + DWC_ERROR(" Speed: %s\n", speed);
  104629. +
  104630. + DWC_ERROR(" Max packet size: %d\n",
  104631. + dwc_otg_hcd_get_mps(&urb->pipe_info));
  104632. + DWC_ERROR(" Data buffer length: %d\n", urb->length);
  104633. + DWC_ERROR(" Transfer buffer: %p, Transfer DMA: %p\n",
  104634. + urb->buf, (void *)urb->dma);
  104635. + DWC_ERROR(" Setup buffer: %p, Setup DMA: %p\n",
  104636. + urb->setup_packet, (void *)urb->setup_dma);
  104637. + DWC_ERROR(" Interval: %d\n", urb->interval);
  104638. +
  104639. + /* Core haltes the channel for Descriptor DMA mode */
  104640. + if (hcd->core_if->dma_desc_enable) {
  104641. + dwc_otg_hcd_complete_xfer_ddma(hcd, hc, hc_regs,
  104642. + DWC_OTG_HC_XFER_AHB_ERR);
  104643. + goto handle_ahberr_done;
  104644. + }
  104645. +
  104646. + hcd->fops->complete(hcd, urb->priv, urb, -DWC_E_IO);
  104647. +
  104648. + /*
  104649. + * Force a channel halt. Don't call halt_channel because that won't
  104650. + * write to the HCCHARn register in DMA mode to force the halt.
  104651. + */
  104652. + dwc_otg_hc_halt(hcd->core_if, hc, DWC_OTG_HC_XFER_AHB_ERR);
  104653. +handle_ahberr_done:
  104654. + disable_hc_int(hc_regs, ahberr);
  104655. + return 1;
  104656. +}
  104657. +
  104658. +/**
  104659. + * Handles a host channel transaction error interrupt. This handler may be
  104660. + * called in either DMA mode or Slave mode.
  104661. + */
  104662. +static int32_t handle_hc_xacterr_intr(dwc_otg_hcd_t * hcd,
  104663. + dwc_hc_t * hc,
  104664. + dwc_otg_hc_regs_t * hc_regs,
  104665. + dwc_otg_qtd_t * qtd)
  104666. +{
  104667. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  104668. + "Transaction Error--\n", hc->hc_num);
  104669. +
  104670. + if (hcd->core_if->dma_desc_enable) {
  104671. + dwc_otg_hcd_complete_xfer_ddma(hcd, hc, hc_regs,
  104672. + DWC_OTG_HC_XFER_XACT_ERR);
  104673. + goto handle_xacterr_done;
  104674. + }
  104675. +
  104676. + switch (dwc_otg_hcd_get_pipe_type(&qtd->urb->pipe_info)) {
  104677. + case UE_CONTROL:
  104678. + case UE_BULK:
  104679. + qtd->error_count++;
  104680. + if (!hc->qh->ping_state) {
  104681. +
  104682. + update_urb_state_xfer_intr(hc, hc_regs,
  104683. + qtd->urb, qtd,
  104684. + DWC_OTG_HC_XFER_XACT_ERR);
  104685. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  104686. + if (!hc->ep_is_in && hc->speed == DWC_OTG_EP_SPEED_HIGH) {
  104687. + hc->qh->ping_state = 1;
  104688. + }
  104689. + }
  104690. +
  104691. + /*
  104692. + * Halt the channel so the transfer can be re-started from
  104693. + * the appropriate point or the PING protocol will start.
  104694. + */
  104695. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  104696. + break;
  104697. + case UE_INTERRUPT:
  104698. + qtd->error_count++;
  104699. + if (hc->do_split && hc->complete_split) {
  104700. + qtd->complete_split = 0;
  104701. + }
  104702. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  104703. + break;
  104704. + case UE_ISOCHRONOUS:
  104705. + {
  104706. + dwc_otg_halt_status_e halt_status;
  104707. + halt_status =
  104708. + update_isoc_urb_state(hcd, hc, hc_regs, qtd,
  104709. + DWC_OTG_HC_XFER_XACT_ERR);
  104710. +
  104711. + halt_channel(hcd, hc, qtd, halt_status);
  104712. + }
  104713. + break;
  104714. + }
  104715. +handle_xacterr_done:
  104716. + disable_hc_int(hc_regs, xacterr);
  104717. +
  104718. + return 1;
  104719. +}
  104720. +
  104721. +/**
  104722. + * Handles a host channel frame overrun interrupt. This handler may be called
  104723. + * in either DMA mode or Slave mode.
  104724. + */
  104725. +static int32_t handle_hc_frmovrun_intr(dwc_otg_hcd_t * hcd,
  104726. + dwc_hc_t * hc,
  104727. + dwc_otg_hc_regs_t * hc_regs,
  104728. + dwc_otg_qtd_t * qtd)
  104729. +{
  104730. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  104731. + "Frame Overrun--\n", hc->hc_num);
  104732. +
  104733. + switch (dwc_otg_hcd_get_pipe_type(&qtd->urb->pipe_info)) {
  104734. + case UE_CONTROL:
  104735. + case UE_BULK:
  104736. + break;
  104737. + case UE_INTERRUPT:
  104738. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_FRAME_OVERRUN);
  104739. + break;
  104740. + case UE_ISOCHRONOUS:
  104741. + {
  104742. + dwc_otg_halt_status_e halt_status;
  104743. + halt_status =
  104744. + update_isoc_urb_state(hcd, hc, hc_regs, qtd,
  104745. + DWC_OTG_HC_XFER_FRAME_OVERRUN);
  104746. +
  104747. + halt_channel(hcd, hc, qtd, halt_status);
  104748. + }
  104749. + break;
  104750. + }
  104751. +
  104752. + disable_hc_int(hc_regs, frmovrun);
  104753. +
  104754. + return 1;
  104755. +}
  104756. +
  104757. +/**
  104758. + * Handles a host channel data toggle error interrupt. This handler may be
  104759. + * called in either DMA mode or Slave mode.
  104760. + */
  104761. +static int32_t handle_hc_datatglerr_intr(dwc_otg_hcd_t * hcd,
  104762. + dwc_hc_t * hc,
  104763. + dwc_otg_hc_regs_t * hc_regs,
  104764. + dwc_otg_qtd_t * qtd)
  104765. +{
  104766. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  104767. + "Data Toggle Error on %s transfer--\n",
  104768. + hc->hc_num, (hc->ep_is_in ? "IN" : "OUT"));
  104769. +
  104770. + /* Data toggles on split transactions cause the hc to halt.
  104771. + * restart transfer */
  104772. + if(hc->qh->do_split)
  104773. + {
  104774. + qtd->error_count++;
  104775. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  104776. + update_urb_state_xfer_intr(hc, hc_regs,
  104777. + qtd->urb, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  104778. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  104779. + } else if (hc->ep_is_in) {
  104780. + /* An unmasked data toggle error on a non-split DMA transaction is
  104781. + * for the sole purpose of resetting error counts. Disable other
  104782. + * interrupts unmasked for the same reason.
  104783. + */
  104784. + if(hcd->core_if->dma_enable) {
  104785. + disable_hc_int(hc_regs, ack);
  104786. + disable_hc_int(hc_regs, nak);
  104787. + }
  104788. + qtd->error_count = 0;
  104789. + }
  104790. +
  104791. + disable_hc_int(hc_regs, datatglerr);
  104792. +
  104793. + return 1;
  104794. +}
  104795. +
  104796. +#ifdef DEBUG
  104797. +/**
  104798. + * This function is for debug only. It checks that a valid halt status is set
  104799. + * and that HCCHARn.chdis is clear. If there's a problem, corrective action is
  104800. + * taken and a warning is issued.
  104801. + * @return 1 if halt status is ok, 0 otherwise.
  104802. + */
  104803. +static inline int halt_status_ok(dwc_otg_hcd_t * hcd,
  104804. + dwc_hc_t * hc,
  104805. + dwc_otg_hc_regs_t * hc_regs,
  104806. + dwc_otg_qtd_t * qtd)
  104807. +{
  104808. + hcchar_data_t hcchar;
  104809. + hctsiz_data_t hctsiz;
  104810. + hcint_data_t hcint;
  104811. + hcintmsk_data_t hcintmsk;
  104812. + hcsplt_data_t hcsplt;
  104813. +
  104814. + if (hc->halt_status == DWC_OTG_HC_XFER_NO_HALT_STATUS) {
  104815. + /*
  104816. + * This code is here only as a check. This condition should
  104817. + * never happen. Ignore the halt if it does occur.
  104818. + */
  104819. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  104820. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  104821. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  104822. + hcintmsk.d32 = DWC_READ_REG32(&hc_regs->hcintmsk);
  104823. + hcsplt.d32 = DWC_READ_REG32(&hc_regs->hcsplt);
  104824. + DWC_WARN
  104825. + ("%s: hc->halt_status == DWC_OTG_HC_XFER_NO_HALT_STATUS, "
  104826. + "channel %d, hcchar 0x%08x, hctsiz 0x%08x, "
  104827. + "hcint 0x%08x, hcintmsk 0x%08x, "
  104828. + "hcsplt 0x%08x, qtd->complete_split %d\n", __func__,
  104829. + hc->hc_num, hcchar.d32, hctsiz.d32, hcint.d32,
  104830. + hcintmsk.d32, hcsplt.d32, qtd->complete_split);
  104831. +
  104832. + DWC_WARN("%s: no halt status, channel %d, ignoring interrupt\n",
  104833. + __func__, hc->hc_num);
  104834. + DWC_WARN("\n");
  104835. + clear_hc_int(hc_regs, chhltd);
  104836. + return 0;
  104837. + }
  104838. +
  104839. + /*
  104840. + * This code is here only as a check. hcchar.chdis should
  104841. + * never be set when the halt interrupt occurs. Halt the
  104842. + * channel again if it does occur.
  104843. + */
  104844. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  104845. + if (hcchar.b.chdis) {
  104846. + DWC_WARN("%s: hcchar.chdis set unexpectedly, "
  104847. + "hcchar 0x%08x, trying to halt again\n",
  104848. + __func__, hcchar.d32);
  104849. + clear_hc_int(hc_regs, chhltd);
  104850. + hc->halt_pending = 0;
  104851. + halt_channel(hcd, hc, qtd, hc->halt_status);
  104852. + return 0;
  104853. + }
  104854. +
  104855. + return 1;
  104856. +}
  104857. +#endif
  104858. +
  104859. +/**
  104860. + * Handles a host Channel Halted interrupt in DMA mode. This handler
  104861. + * determines the reason the channel halted and proceeds accordingly.
  104862. + */
  104863. +static void handle_hc_chhltd_intr_dma(dwc_otg_hcd_t * hcd,
  104864. + dwc_hc_t * hc,
  104865. + dwc_otg_hc_regs_t * hc_regs,
  104866. + dwc_otg_qtd_t * qtd)
  104867. +{
  104868. + int out_nak_enh = 0;
  104869. + hcint_data_t hcint;
  104870. + hcintmsk_data_t hcintmsk;
  104871. + /* For core with OUT NAK enhancement, the flow for high-
  104872. + * speed CONTROL/BULK OUT is handled a little differently.
  104873. + */
  104874. + if (hcd->core_if->snpsid >= OTG_CORE_REV_2_71a) {
  104875. + if (hc->speed == DWC_OTG_EP_SPEED_HIGH && !hc->ep_is_in &&
  104876. + (hc->ep_type == DWC_OTG_EP_TYPE_CONTROL ||
  104877. + hc->ep_type == DWC_OTG_EP_TYPE_BULK)) {
  104878. + out_nak_enh = 1;
  104879. + }
  104880. + }
  104881. +
  104882. + if (hc->halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE ||
  104883. + (hc->halt_status == DWC_OTG_HC_XFER_AHB_ERR
  104884. + && !hcd->core_if->dma_desc_enable)) {
  104885. + /*
  104886. + * Just release the channel. A dequeue can happen on a
  104887. + * transfer timeout. In the case of an AHB Error, the channel
  104888. + * was forced to halt because there's no way to gracefully
  104889. + * recover.
  104890. + */
  104891. + if (hcd->core_if->dma_desc_enable)
  104892. + dwc_otg_hcd_complete_xfer_ddma(hcd, hc, hc_regs,
  104893. + hc->halt_status);
  104894. + else
  104895. + release_channel(hcd, hc, qtd, hc->halt_status);
  104896. + return;
  104897. + }
  104898. +
  104899. + /* Read the HCINTn register to determine the cause for the halt. */
  104900. +
  104901. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  104902. + hcintmsk.d32 = DWC_READ_REG32(&hc_regs->hcintmsk);
  104903. +
  104904. + if (hcint.b.xfercomp) {
  104905. + /** @todo This is here because of a possible hardware bug. Spec
  104906. + * says that on SPLIT-ISOC OUT transfers in DMA mode that a HALT
  104907. + * interrupt w/ACK bit set should occur, but I only see the
  104908. + * XFERCOMP bit, even with it masked out. This is a workaround
  104909. + * for that behavior. Should fix this when hardware is fixed.
  104910. + */
  104911. + if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC && !hc->ep_is_in) {
  104912. + handle_hc_ack_intr(hcd, hc, hc_regs, qtd);
  104913. + }
  104914. + handle_hc_xfercomp_intr(hcd, hc, hc_regs, qtd);
  104915. + } else if (hcint.b.stall) {
  104916. + handle_hc_stall_intr(hcd, hc, hc_regs, qtd);
  104917. + } else if (hcint.b.xacterr && !hcd->core_if->dma_desc_enable) {
  104918. + if (out_nak_enh) {
  104919. + if (hcint.b.nyet || hcint.b.nak || hcint.b.ack) {
  104920. + DWC_DEBUGPL(DBG_HCD, "XactErr with NYET/NAK/ACK\n");
  104921. + qtd->error_count = 0;
  104922. + } else {
  104923. + DWC_DEBUGPL(DBG_HCD, "XactErr without NYET/NAK/ACK\n");
  104924. + }
  104925. + }
  104926. +
  104927. + /*
  104928. + * Must handle xacterr before nak or ack. Could get a xacterr
  104929. + * at the same time as either of these on a BULK/CONTROL OUT
  104930. + * that started with a PING. The xacterr takes precedence.
  104931. + */
  104932. + handle_hc_xacterr_intr(hcd, hc, hc_regs, qtd);
  104933. + } else if (hcint.b.xcs_xact && hcd->core_if->dma_desc_enable) {
  104934. + handle_hc_xacterr_intr(hcd, hc, hc_regs, qtd);
  104935. + } else if (hcint.b.ahberr && hcd->core_if->dma_desc_enable) {
  104936. + handle_hc_ahberr_intr(hcd, hc, hc_regs, qtd);
  104937. + } else if (hcint.b.bblerr) {
  104938. + handle_hc_babble_intr(hcd, hc, hc_regs, qtd);
  104939. + } else if (hcint.b.frmovrun) {
  104940. + handle_hc_frmovrun_intr(hcd, hc, hc_regs, qtd);
  104941. + } else if (hcint.b.datatglerr) {
  104942. + handle_hc_datatglerr_intr(hcd, hc, hc_regs, qtd);
  104943. + } else if (!out_nak_enh) {
  104944. + if (hcint.b.nyet) {
  104945. + /*
  104946. + * Must handle nyet before nak or ack. Could get a nyet at the
  104947. + * same time as either of those on a BULK/CONTROL OUT that
  104948. + * started with a PING. The nyet takes precedence.
  104949. + */
  104950. + handle_hc_nyet_intr(hcd, hc, hc_regs, qtd);
  104951. + } else if (hcint.b.nak && !hcintmsk.b.nak) {
  104952. + /*
  104953. + * If nak is not masked, it's because a non-split IN transfer
  104954. + * is in an error state. In that case, the nak is handled by
  104955. + * the nak interrupt handler, not here. Handle nak here for
  104956. + * BULK/CONTROL OUT transfers, which halt on a NAK to allow
  104957. + * rewinding the buffer pointer.
  104958. + */
  104959. + handle_hc_nak_intr(hcd, hc, hc_regs, qtd);
  104960. + } else if (hcint.b.ack && !hcintmsk.b.ack) {
  104961. + /*
  104962. + * If ack is not masked, it's because a non-split IN transfer
  104963. + * is in an error state. In that case, the ack is handled by
  104964. + * the ack interrupt handler, not here. Handle ack here for
  104965. + * split transfers. Start splits halt on ACK.
  104966. + */
  104967. + handle_hc_ack_intr(hcd, hc, hc_regs, qtd);
  104968. + } else {
  104969. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  104970. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  104971. + /*
  104972. + * A periodic transfer halted with no other channel
  104973. + * interrupts set. Assume it was halted by the core
  104974. + * because it could not be completed in its scheduled
  104975. + * (micro)frame.
  104976. + */
  104977. +#ifdef DEBUG
  104978. + DWC_PRINTF
  104979. + ("%s: Halt channel %d (assume incomplete periodic transfer)\n",
  104980. + __func__, hc->hc_num);
  104981. +#endif
  104982. + halt_channel(hcd, hc, qtd,
  104983. + DWC_OTG_HC_XFER_PERIODIC_INCOMPLETE);
  104984. + } else {
  104985. + DWC_ERROR
  104986. + ("%s: Channel %d, DMA Mode -- ChHltd set, but reason "
  104987. + "for halting is unknown, hcint 0x%08x, intsts 0x%08x\n",
  104988. + __func__, hc->hc_num, hcint.d32,
  104989. + DWC_READ_REG32(&hcd->
  104990. + core_if->core_global_regs->
  104991. + gintsts));
  104992. + /* Failthrough: use 3-strikes rule */
  104993. + qtd->error_count++;
  104994. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  104995. + update_urb_state_xfer_intr(hc, hc_regs,
  104996. + qtd->urb, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  104997. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  104998. + }
  104999. +
  105000. + }
  105001. + } else {
  105002. + DWC_PRINTF("NYET/NAK/ACK/other in non-error case, 0x%08x\n",
  105003. + hcint.d32);
  105004. + /* Failthrough: use 3-strikes rule */
  105005. + qtd->error_count++;
  105006. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  105007. + update_urb_state_xfer_intr(hc, hc_regs,
  105008. + qtd->urb, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  105009. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  105010. + }
  105011. +}
  105012. +
  105013. +/**
  105014. + * Handles a host channel Channel Halted interrupt.
  105015. + *
  105016. + * In slave mode, this handler is called only when the driver specifically
  105017. + * requests a halt. This occurs during handling other host channel interrupts
  105018. + * (e.g. nak, xacterr, stall, nyet, etc.).
  105019. + *
  105020. + * In DMA mode, this is the interrupt that occurs when the core has finished
  105021. + * processing a transfer on a channel. Other host channel interrupts (except
  105022. + * ahberr) are disabled in DMA mode.
  105023. + */
  105024. +static int32_t handle_hc_chhltd_intr(dwc_otg_hcd_t * hcd,
  105025. + dwc_hc_t * hc,
  105026. + dwc_otg_hc_regs_t * hc_regs,
  105027. + dwc_otg_qtd_t * qtd)
  105028. +{
  105029. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  105030. + "Channel Halted--\n", hc->hc_num);
  105031. +
  105032. + if (hcd->core_if->dma_enable) {
  105033. + handle_hc_chhltd_intr_dma(hcd, hc, hc_regs, qtd);
  105034. + } else {
  105035. +#ifdef DEBUG
  105036. + if (!halt_status_ok(hcd, hc, hc_regs, qtd)) {
  105037. + return 1;
  105038. + }
  105039. +#endif
  105040. + release_channel(hcd, hc, qtd, hc->halt_status);
  105041. + }
  105042. +
  105043. + return 1;
  105044. +}
  105045. +
  105046. +
  105047. +/**
  105048. + * dwc_otg_fiq_unmangle_isoc() - Update the iso_frame_desc structure on
  105049. + * FIQ transfer completion
  105050. + * @hcd: Pointer to dwc_otg_hcd struct
  105051. + * @num: Host channel number
  105052. + *
  105053. + * 1. Un-mangle the status as recorded in each iso_frame_desc status
  105054. + * 2. Copy it from the dwc_otg_urb into the real URB
  105055. + */
  105056. +void dwc_otg_fiq_unmangle_isoc(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh, dwc_otg_qtd_t *qtd, uint32_t num)
  105057. +{
  105058. + struct dwc_otg_hcd_urb *dwc_urb = qtd->urb;
  105059. + int nr_frames = dwc_urb->packet_count;
  105060. + int i;
  105061. + hcint_data_t frame_hcint;
  105062. +
  105063. + for (i = 0; i < nr_frames; i++) {
  105064. + frame_hcint.d32 = dwc_urb->iso_descs[i].status;
  105065. + if (frame_hcint.b.xfercomp) {
  105066. + dwc_urb->iso_descs[i].status = 0;
  105067. + dwc_urb->actual_length += dwc_urb->iso_descs[i].actual_length;
  105068. + } else if (frame_hcint.b.frmovrun) {
  105069. + if (qh->ep_is_in)
  105070. + dwc_urb->iso_descs[i].status = -DWC_E_NO_STREAM_RES;
  105071. + else
  105072. + dwc_urb->iso_descs[i].status = -DWC_E_COMMUNICATION;
  105073. + dwc_urb->error_count++;
  105074. + dwc_urb->iso_descs[i].actual_length = 0;
  105075. + } else if (frame_hcint.b.xacterr) {
  105076. + dwc_urb->iso_descs[i].status = -DWC_E_PROTOCOL;
  105077. + dwc_urb->error_count++;
  105078. + dwc_urb->iso_descs[i].actual_length = 0;
  105079. + } else if (frame_hcint.b.bblerr) {
  105080. + dwc_urb->iso_descs[i].status = -DWC_E_OVERFLOW;
  105081. + dwc_urb->error_count++;
  105082. + dwc_urb->iso_descs[i].actual_length = 0;
  105083. + } else {
  105084. + /* Something went wrong */
  105085. + dwc_urb->iso_descs[i].status = -1;
  105086. + dwc_urb->iso_descs[i].actual_length = 0;
  105087. + dwc_urb->error_count++;
  105088. + }
  105089. + }
  105090. + //printk_ratelimited(KERN_INFO "%s: HS isochronous of %d/%d frames with %d errors complete\n",
  105091. + // __FUNCTION__, i, dwc_urb->packet_count, dwc_urb->error_count);
  105092. + hcd->fops->complete(hcd, dwc_urb->priv, dwc_urb, 0);
  105093. + release_channel(hcd, qh->channel, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  105094. +}
  105095. +
  105096. +/**
  105097. + * dwc_otg_fiq_unsetup_per_dma() - Remove data from bounce buffers for split transactions
  105098. + * @hcd: Pointer to dwc_otg_hcd struct
  105099. + * @num: Host channel number
  105100. + *
  105101. + * Copies data from the FIQ bounce buffers into the URB's transfer buffer. Does not modify URB state.
  105102. + * Returns total length of data or -1 if the buffers were not used.
  105103. + *
  105104. + */
  105105. +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)
  105106. +{
  105107. + dwc_hc_t *hc = qh->channel;
  105108. + struct fiq_dma_blob *blob = hcd->fiq_dmab;
  105109. + struct fiq_channel_state *st = &hcd->fiq_state->channel[num];
  105110. + uint8_t *ptr = NULL;
  105111. + int index = 0, len = 0;
  105112. + int i = 0;
  105113. + if (hc->ep_is_in) {
  105114. + /* Copy data out of the DMA bounce buffers to the URB's buffer.
  105115. + * The align_buf is ignored as this is ignored on FSM enqueue. */
  105116. + ptr = qtd->urb->buf;
  105117. + if (qh->ep_type == UE_ISOCHRONOUS) {
  105118. + /* Isoc IN transactions - grab the offset of the iso_frame_desc into the URB transfer buffer */
  105119. + index = qtd->isoc_frame_index;
  105120. + ptr += qtd->urb->iso_descs[index].offset;
  105121. + } else {
  105122. + /* Need to increment by actual_length for interrupt IN */
  105123. + ptr += qtd->urb->actual_length;
  105124. + }
  105125. +
  105126. + for (i = 0; i < st->dma_info.index; i++) {
  105127. + len += st->dma_info.slot_len[i];
  105128. + dwc_memcpy(ptr, &blob->channel[num].index[i].buf[0], st->dma_info.slot_len[i]);
  105129. + ptr += st->dma_info.slot_len[i];
  105130. + }
  105131. + return len;
  105132. + } else {
  105133. + /* OUT endpoints - nothing to do. */
  105134. + return -1;
  105135. + }
  105136. +
  105137. +}
  105138. +/**
  105139. + * dwc_otg_hcd_handle_hc_fsm() - handle an unmasked channel interrupt
  105140. + * from a channel handled in the FIQ
  105141. + * @hcd: Pointer to dwc_otg_hcd struct
  105142. + * @num: Host channel number
  105143. + *
  105144. + * If a host channel interrupt was received by the IRQ and this was a channel
  105145. + * used by the FIQ, the execution flow for transfer completion is substantially
  105146. + * different from the normal (messy) path. This function and its friends handles
  105147. + * channel cleanup and transaction completion from a FIQ transaction.
  105148. + */
  105149. +void dwc_otg_hcd_handle_hc_fsm(dwc_otg_hcd_t *hcd, uint32_t num)
  105150. +{
  105151. + struct fiq_channel_state *st = &hcd->fiq_state->channel[num];
  105152. + dwc_hc_t *hc = hcd->hc_ptr_array[num];
  105153. + dwc_otg_qtd_t *qtd = DWC_CIRCLEQ_FIRST(&hc->qh->qtd_list);
  105154. + dwc_otg_qh_t *qh = hc->qh;
  105155. + dwc_otg_hc_regs_t *hc_regs = hcd->core_if->host_if->hc_regs[num];
  105156. + hcint_data_t hcint = hcd->fiq_state->channel[num].hcint_copy;
  105157. + int hostchannels = 0;
  105158. + fiq_print(FIQDBG_INT, hcd->fiq_state, "OUT %01d %01d ", num , st->fsm);
  105159. +
  105160. + hostchannels = hcd->available_host_channels;
  105161. + switch (st->fsm) {
  105162. + case FIQ_TEST:
  105163. + break;
  105164. +
  105165. + case FIQ_DEQUEUE_ISSUED:
  105166. + /* hc_halt was called. QTD no longer exists. */
  105167. + /* TODO: for a nonperiodic split transaction, need to issue a
  105168. + * CLEAR_TT_BUFFER hub command if we were in the start-split phase.
  105169. + */
  105170. + release_channel(hcd, hc, NULL, hc->halt_status);
  105171. + break;
  105172. +
  105173. + case FIQ_NP_SPLIT_DONE:
  105174. + /* Nonperiodic transaction complete. */
  105175. + if (!hc->ep_is_in) {
  105176. + qtd->ssplit_out_xfer_count = hc->xfer_len;
  105177. + }
  105178. + if (hcint.b.xfercomp) {
  105179. + handle_hc_xfercomp_intr(hcd, hc, hc_regs, qtd);
  105180. + } else if (hcint.b.nak) {
  105181. + handle_hc_nak_intr(hcd, hc, hc_regs, qtd);
  105182. + }
  105183. + break;
  105184. +
  105185. + case FIQ_NP_SPLIT_HS_ABORTED:
  105186. + /* A HS abort is a 3-strikes on the HS bus at any point in the transaction.
  105187. + * Normally a CLEAR_TT_BUFFER hub command would be required: we can't do that
  105188. + * because there's no guarantee which order a non-periodic split happened in.
  105189. + * We could end up clearing a perfectly good transaction out of the buffer.
  105190. + */
  105191. + if (hcint.b.xacterr) {
  105192. + qtd->error_count += st->nr_errors;
  105193. + handle_hc_xacterr_intr(hcd, hc, hc_regs, qtd);
  105194. + } else if (hcint.b.ahberr) {
  105195. + handle_hc_ahberr_intr(hcd, hc, hc_regs, qtd);
  105196. + } else {
  105197. + local_fiq_disable();
  105198. + BUG();
  105199. + }
  105200. + break;
  105201. +
  105202. + case FIQ_NP_SPLIT_LS_ABORTED:
  105203. + /* A few cases can cause this - either an unknown state on a SSPLIT or
  105204. + * STALL/data toggle error response on a CSPLIT */
  105205. + if (hcint.b.stall) {
  105206. + handle_hc_stall_intr(hcd, hc, hc_regs, qtd);
  105207. + } else if (hcint.b.datatglerr) {
  105208. + handle_hc_datatglerr_intr(hcd, hc, hc_regs, qtd);
  105209. + } else if (hcint.b.bblerr) {
  105210. + handle_hc_babble_intr(hcd, hc, hc_regs, qtd);
  105211. + } else if (hcint.b.ahberr) {
  105212. + handle_hc_ahberr_intr(hcd, hc, hc_regs, qtd);
  105213. + } else {
  105214. + local_fiq_disable();
  105215. + BUG();
  105216. + }
  105217. + break;
  105218. +
  105219. + case FIQ_PER_SPLIT_DONE:
  105220. + /* Isoc IN or Interrupt IN/OUT */
  105221. +
  105222. + /* Flow control here is different from the normal execution by the driver.
  105223. + * We need to completely ignore most of the driver's method of handling
  105224. + * split transactions and do it ourselves.
  105225. + */
  105226. + if (hc->ep_type == UE_INTERRUPT) {
  105227. + if (hcint.b.nak) {
  105228. + handle_hc_nak_intr(hcd, hc, hc_regs, qtd);
  105229. + } else if (hc->ep_is_in) {
  105230. + int len;
  105231. + len = dwc_otg_fiq_unsetup_per_dma(hcd, hc->qh, qtd, num);
  105232. + //printk(KERN_NOTICE "FIQ Transaction: hc=%d len=%d urb_len = %d\n", num, len, qtd->urb->length);
  105233. + qtd->urb->actual_length += len;
  105234. + if (qtd->urb->actual_length >= qtd->urb->length) {
  105235. + qtd->urb->status = 0;
  105236. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, qtd->urb->status);
  105237. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  105238. + } else {
  105239. + /* Interrupt transfer not complete yet - is it a short read? */
  105240. + if (len < hc->max_packet) {
  105241. + /* Interrupt transaction complete */
  105242. + qtd->urb->status = 0;
  105243. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, qtd->urb->status);
  105244. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  105245. + } else {
  105246. + /* Further transactions required */
  105247. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_COMPLETE);
  105248. + }
  105249. + }
  105250. + } else {
  105251. + /* Interrupt OUT complete. */
  105252. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  105253. + qtd->urb->actual_length += hc->xfer_len;
  105254. + if (qtd->urb->actual_length >= qtd->urb->length) {
  105255. + qtd->urb->status = 0;
  105256. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, qtd->urb->status);
  105257. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  105258. + } else {
  105259. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_COMPLETE);
  105260. + }
  105261. + }
  105262. + } else {
  105263. + /* ISOC IN complete. */
  105264. + struct dwc_otg_hcd_iso_packet_desc *frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
  105265. + int len = 0;
  105266. + /* Record errors, update qtd. */
  105267. + if (st->nr_errors) {
  105268. + frame_desc->actual_length = 0;
  105269. + frame_desc->status = -DWC_E_PROTOCOL;
  105270. + } else {
  105271. + frame_desc->status = 0;
  105272. + /* Unswizzle dma */
  105273. + len = dwc_otg_fiq_unsetup_per_dma(hcd, qh, qtd, num);
  105274. + frame_desc->actual_length = len;
  105275. + }
  105276. + qtd->isoc_frame_index++;
  105277. + if (qtd->isoc_frame_index == qtd->urb->packet_count) {
  105278. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
  105279. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  105280. + } else {
  105281. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_COMPLETE);
  105282. + }
  105283. + }
  105284. + break;
  105285. +
  105286. + case FIQ_PER_ISO_OUT_DONE: {
  105287. + struct dwc_otg_hcd_iso_packet_desc *frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
  105288. + /* Record errors, update qtd. */
  105289. + if (st->nr_errors) {
  105290. + frame_desc->actual_length = 0;
  105291. + frame_desc->status = -DWC_E_PROTOCOL;
  105292. + } else {
  105293. + frame_desc->status = 0;
  105294. + frame_desc->actual_length = frame_desc->length;
  105295. + }
  105296. + qtd->isoc_frame_index++;
  105297. + qtd->isoc_split_offset = 0;
  105298. + if (qtd->isoc_frame_index == qtd->urb->packet_count) {
  105299. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
  105300. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  105301. + } else {
  105302. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_COMPLETE);
  105303. + }
  105304. + }
  105305. + break;
  105306. +
  105307. + case FIQ_PER_SPLIT_NYET_ABORTED:
  105308. + /* Doh. lost the data. */
  105309. + printk_ratelimited(KERN_INFO "Transfer to device %d endpoint 0x%x frame %d failed "
  105310. + "- FIQ reported NYET. Data may have been lost.\n",
  105311. + hc->dev_addr, hc->ep_num, dwc_otg_hcd_get_frame_number(hcd) >> 3);
  105312. + if (hc->ep_type == UE_ISOCHRONOUS) {
  105313. + struct dwc_otg_hcd_iso_packet_desc *frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
  105314. + /* Record errors, update qtd. */
  105315. + frame_desc->actual_length = 0;
  105316. + frame_desc->status = -DWC_E_PROTOCOL;
  105317. + qtd->isoc_frame_index++;
  105318. + qtd->isoc_split_offset = 0;
  105319. + if (qtd->isoc_frame_index == qtd->urb->packet_count) {
  105320. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
  105321. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  105322. + } else {
  105323. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_COMPLETE);
  105324. + }
  105325. + } else {
  105326. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NO_HALT_STATUS);
  105327. + }
  105328. + break;
  105329. +
  105330. + case FIQ_HS_ISOC_DONE:
  105331. + /* The FIQ has performed a whole pile of isochronous transactions.
  105332. + * The status is recorded as the interrupt state should the transaction
  105333. + * fail.
  105334. + */
  105335. + dwc_otg_fiq_unmangle_isoc(hcd, qh, qtd, num);
  105336. + break;
  105337. +
  105338. + case FIQ_PER_SPLIT_LS_ABORTED:
  105339. + if (hcint.b.xacterr) {
  105340. + /* Hub has responded with an ERR packet. Device
  105341. + * has been unplugged or the port has been disabled.
  105342. + * TODO: need to issue a reset to the hub port. */
  105343. + qtd->error_count += 3;
  105344. + handle_hc_xacterr_intr(hcd, hc, hc_regs, qtd);
  105345. + } else if (hcint.b.stall) {
  105346. + handle_hc_stall_intr(hcd, hc, hc_regs, qtd);
  105347. + } else if (hcint.b.bblerr) {
  105348. + handle_hc_babble_intr(hcd, hc, hc_regs, qtd);
  105349. + } else {
  105350. + printk_ratelimited(KERN_INFO "Transfer to device %d endpoint 0x%x failed "
  105351. + "- FIQ reported FSM=%d. Data may have been lost.\n",
  105352. + st->fsm, hc->dev_addr, hc->ep_num);
  105353. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NO_HALT_STATUS);
  105354. + }
  105355. + break;
  105356. +
  105357. + case FIQ_PER_SPLIT_HS_ABORTED:
  105358. + /* Either the SSPLIT phase suffered transaction errors or something
  105359. + * unexpected happened.
  105360. + */
  105361. + qtd->error_count += 3;
  105362. + handle_hc_xacterr_intr(hcd, hc, hc_regs, qtd);
  105363. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NO_HALT_STATUS);
  105364. + break;
  105365. +
  105366. + case FIQ_PER_SPLIT_TIMEOUT:
  105367. + /* Couldn't complete in the nominated frame */
  105368. + printk(KERN_INFO "Transfer to device %d endpoint 0x%x frame %d failed "
  105369. + "- FIQ timed out. Data may have been lost.\n",
  105370. + hc->dev_addr, hc->ep_num, dwc_otg_hcd_get_frame_number(hcd) >> 3);
  105371. + if (hc->ep_type == UE_ISOCHRONOUS) {
  105372. + struct dwc_otg_hcd_iso_packet_desc *frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
  105373. + /* Record errors, update qtd. */
  105374. + frame_desc->actual_length = 0;
  105375. + if (hc->ep_is_in) {
  105376. + frame_desc->status = -DWC_E_NO_STREAM_RES;
  105377. + } else {
  105378. + frame_desc->status = -DWC_E_COMMUNICATION;
  105379. + }
  105380. + qtd->isoc_frame_index++;
  105381. + if (qtd->isoc_frame_index == qtd->urb->packet_count) {
  105382. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
  105383. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  105384. + } else {
  105385. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_COMPLETE);
  105386. + }
  105387. + } else {
  105388. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NO_HALT_STATUS);
  105389. + }
  105390. + break;
  105391. +
  105392. + default:
  105393. + DWC_WARN("Unexpected state received on hc=%d fsm=%d on transfer to device %d ep 0x%x",
  105394. + hc->hc_num, st->fsm, hc->dev_addr, hc->ep_num);
  105395. + qtd->error_count++;
  105396. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NO_HALT_STATUS);
  105397. + }
  105398. + return;
  105399. +}
  105400. +
  105401. +/** Handles interrupt for a specific Host Channel */
  105402. +int32_t dwc_otg_hcd_handle_hc_n_intr(dwc_otg_hcd_t * dwc_otg_hcd, uint32_t num)
  105403. +{
  105404. + int retval = 0;
  105405. + hcint_data_t hcint;
  105406. + hcintmsk_data_t hcintmsk;
  105407. + dwc_hc_t *hc;
  105408. + dwc_otg_hc_regs_t *hc_regs;
  105409. + dwc_otg_qtd_t *qtd;
  105410. +
  105411. + DWC_DEBUGPL(DBG_HCDV, "--Host Channel Interrupt--, Channel %d\n", num);
  105412. +
  105413. + hc = dwc_otg_hcd->hc_ptr_array[num];
  105414. + hc_regs = dwc_otg_hcd->core_if->host_if->hc_regs[num];
  105415. + if(hc->halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE) {
  105416. + /* We are responding to a channel disable. Driver
  105417. + * state is cleared - our qtd has gone away.
  105418. + */
  105419. + release_channel(dwc_otg_hcd, hc, NULL, hc->halt_status);
  105420. + return 1;
  105421. + }
  105422. + qtd = DWC_CIRCLEQ_FIRST(&hc->qh->qtd_list);
  105423. +
  105424. + /*
  105425. + * FSM mode: Check to see if this is a HC interrupt from a channel handled by the FIQ.
  105426. + * Execution path is fundamentally different for the channels after a FIQ has completed
  105427. + * a split transaction.
  105428. + */
  105429. + if (fiq_fsm_enable) {
  105430. + switch (dwc_otg_hcd->fiq_state->channel[num].fsm) {
  105431. + case FIQ_PASSTHROUGH:
  105432. + break;
  105433. + case FIQ_PASSTHROUGH_ERRORSTATE:
  105434. + /* Hook into the error count */
  105435. + fiq_print(FIQDBG_ERR, dwc_otg_hcd->fiq_state, "HCDERR%02d", num);
  105436. + if (!dwc_otg_hcd->fiq_state->channel[num].nr_errors) {
  105437. + qtd->error_count = 0;
  105438. + fiq_print(FIQDBG_ERR, dwc_otg_hcd->fiq_state, "RESET ");
  105439. + }
  105440. + break;
  105441. + default:
  105442. + dwc_otg_hcd_handle_hc_fsm(dwc_otg_hcd, num);
  105443. + return 1;
  105444. + }
  105445. + }
  105446. +
  105447. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  105448. + hcintmsk.d32 = DWC_READ_REG32(&hc_regs->hcintmsk);
  105449. + hcint.d32 = hcint.d32 & hcintmsk.d32;
  105450. + if (!dwc_otg_hcd->core_if->dma_enable) {
  105451. + if (hcint.b.chhltd && hcint.d32 != 0x2) {
  105452. + hcint.b.chhltd = 0;
  105453. + }
  105454. + }
  105455. +
  105456. + if (hcint.b.xfercomp) {
  105457. + retval |=
  105458. + handle_hc_xfercomp_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  105459. + /*
  105460. + * If NYET occurred at same time as Xfer Complete, the NYET is
  105461. + * handled by the Xfer Complete interrupt handler. Don't want
  105462. + * to call the NYET interrupt handler in this case.
  105463. + */
  105464. + hcint.b.nyet = 0;
  105465. + }
  105466. + if (hcint.b.chhltd) {
  105467. + retval |= handle_hc_chhltd_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  105468. + }
  105469. + if (hcint.b.ahberr) {
  105470. + retval |= handle_hc_ahberr_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  105471. + }
  105472. + if (hcint.b.stall) {
  105473. + retval |= handle_hc_stall_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  105474. + }
  105475. + if (hcint.b.nak) {
  105476. + retval |= handle_hc_nak_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  105477. + }
  105478. + if (hcint.b.ack) {
  105479. + if(!hcint.b.chhltd)
  105480. + retval |= handle_hc_ack_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  105481. + }
  105482. + if (hcint.b.nyet) {
  105483. + retval |= handle_hc_nyet_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  105484. + }
  105485. + if (hcint.b.xacterr) {
  105486. + retval |= handle_hc_xacterr_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  105487. + }
  105488. + if (hcint.b.bblerr) {
  105489. + retval |= handle_hc_babble_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  105490. + }
  105491. + if (hcint.b.frmovrun) {
  105492. + retval |=
  105493. + handle_hc_frmovrun_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  105494. + }
  105495. + if (hcint.b.datatglerr) {
  105496. + retval |=
  105497. + handle_hc_datatglerr_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  105498. + }
  105499. +
  105500. + return retval;
  105501. +}
  105502. +#endif /* DWC_DEVICE_ONLY */
  105503. diff -Nur linux-3.18.8/drivers/usb/host/dwc_otg/dwc_otg_hcd_linux.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd_linux.c
  105504. --- linux-3.18.8/drivers/usb/host/dwc_otg/dwc_otg_hcd_linux.c 1970-01-01 01:00:00.000000000 +0100
  105505. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd_linux.c 2015-03-05 14:40:16.561715806 +0100
  105506. @@ -0,0 +1,994 @@
  105507. +
  105508. +/* ==========================================================================
  105509. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd_linux.c $
  105510. + * $Revision: #20 $
  105511. + * $Date: 2011/10/26 $
  105512. + * $Change: 1872981 $
  105513. + *
  105514. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  105515. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  105516. + * otherwise expressly agreed to in writing between Synopsys and you.
  105517. + *
  105518. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  105519. + * any End User Software License Agreement or Agreement for Licensed Product
  105520. + * with Synopsys or any supplement thereto. You are permitted to use and
  105521. + * redistribute this Software in source and binary forms, with or without
  105522. + * modification, provided that redistributions of source code must retain this
  105523. + * notice. You may not view, use, disclose, copy or distribute this file or
  105524. + * any information contained herein except pursuant to this license grant from
  105525. + * Synopsys. If you do not agree with this notice, including the disclaimer
  105526. + * below, then you are not authorized to use the Software.
  105527. + *
  105528. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  105529. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  105530. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  105531. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  105532. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  105533. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  105534. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  105535. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  105536. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  105537. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  105538. + * DAMAGE.
  105539. + * ========================================================================== */
  105540. +#ifndef DWC_DEVICE_ONLY
  105541. +
  105542. +/**
  105543. + * @file
  105544. + *
  105545. + * This file contains the implementation of the HCD. In Linux, the HCD
  105546. + * implements the hc_driver API.
  105547. + */
  105548. +#include <linux/kernel.h>
  105549. +#include <linux/module.h>
  105550. +#include <linux/moduleparam.h>
  105551. +#include <linux/init.h>
  105552. +#include <linux/device.h>
  105553. +#include <linux/errno.h>
  105554. +#include <linux/list.h>
  105555. +#include <linux/interrupt.h>
  105556. +#include <linux/string.h>
  105557. +#include <linux/dma-mapping.h>
  105558. +#include <linux/version.h>
  105559. +#include <asm/io.h>
  105560. +#include <asm/fiq.h>
  105561. +#include <linux/usb.h>
  105562. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,35)
  105563. +#include <../drivers/usb/core/hcd.h>
  105564. +#else
  105565. +#include <linux/usb/hcd.h>
  105566. +#endif
  105567. +#include <asm/bug.h>
  105568. +
  105569. +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30))
  105570. +#define USB_URB_EP_LINKING 1
  105571. +#else
  105572. +#define USB_URB_EP_LINKING 0
  105573. +#endif
  105574. +
  105575. +#include "dwc_otg_hcd_if.h"
  105576. +#include "dwc_otg_dbg.h"
  105577. +#include "dwc_otg_driver.h"
  105578. +#include "dwc_otg_hcd.h"
  105579. +
  105580. +extern unsigned char _dwc_otg_fiq_stub, _dwc_otg_fiq_stub_end;
  105581. +
  105582. +/**
  105583. + * Gets the endpoint number from a _bEndpointAddress argument. The endpoint is
  105584. + * qualified with its direction (possible 32 endpoints per device).
  105585. + */
  105586. +#define dwc_ep_addr_to_endpoint(_bEndpointAddress_) ((_bEndpointAddress_ & USB_ENDPOINT_NUMBER_MASK) | \
  105587. + ((_bEndpointAddress_ & USB_DIR_IN) != 0) << 4)
  105588. +
  105589. +static const char dwc_otg_hcd_name[] = "dwc_otg_hcd";
  105590. +
  105591. +extern bool fiq_enable;
  105592. +
  105593. +/** @name Linux HC Driver API Functions */
  105594. +/** @{ */
  105595. +/* manage i/o requests, device state */
  105596. +static int dwc_otg_urb_enqueue(struct usb_hcd *hcd,
  105597. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  105598. + struct usb_host_endpoint *ep,
  105599. +#endif
  105600. + struct urb *urb, gfp_t mem_flags);
  105601. +
  105602. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30)
  105603. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  105604. +static int dwc_otg_urb_dequeue(struct usb_hcd *hcd, struct urb *urb);
  105605. +#endif
  105606. +#else /* kernels at or post 2.6.30 */
  105607. +static int dwc_otg_urb_dequeue(struct usb_hcd *hcd,
  105608. + struct urb *urb, int status);
  105609. +#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30) */
  105610. +
  105611. +static void endpoint_disable(struct usb_hcd *hcd, struct usb_host_endpoint *ep);
  105612. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30)
  105613. +static void endpoint_reset(struct usb_hcd *hcd, struct usb_host_endpoint *ep);
  105614. +#endif
  105615. +static irqreturn_t dwc_otg_hcd_irq(struct usb_hcd *hcd);
  105616. +extern int hcd_start(struct usb_hcd *hcd);
  105617. +extern void hcd_stop(struct usb_hcd *hcd);
  105618. +static int get_frame_number(struct usb_hcd *hcd);
  105619. +extern int hub_status_data(struct usb_hcd *hcd, char *buf);
  105620. +extern int hub_control(struct usb_hcd *hcd,
  105621. + u16 typeReq,
  105622. + u16 wValue, u16 wIndex, char *buf, u16 wLength);
  105623. +
  105624. +struct wrapper_priv_data {
  105625. + dwc_otg_hcd_t *dwc_otg_hcd;
  105626. +};
  105627. +
  105628. +/** @} */
  105629. +
  105630. +static struct hc_driver dwc_otg_hc_driver = {
  105631. +
  105632. + .description = dwc_otg_hcd_name,
  105633. + .product_desc = "DWC OTG Controller",
  105634. + .hcd_priv_size = sizeof(struct wrapper_priv_data),
  105635. +
  105636. + .irq = dwc_otg_hcd_irq,
  105637. +
  105638. + .flags = HCD_MEMORY | HCD_USB2,
  105639. +
  105640. + //.reset =
  105641. + .start = hcd_start,
  105642. + //.suspend =
  105643. + //.resume =
  105644. + .stop = hcd_stop,
  105645. +
  105646. + .urb_enqueue = dwc_otg_urb_enqueue,
  105647. + .urb_dequeue = dwc_otg_urb_dequeue,
  105648. + .endpoint_disable = endpoint_disable,
  105649. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30)
  105650. + .endpoint_reset = endpoint_reset,
  105651. +#endif
  105652. + .get_frame_number = get_frame_number,
  105653. +
  105654. + .hub_status_data = hub_status_data,
  105655. + .hub_control = hub_control,
  105656. + //.bus_suspend =
  105657. + //.bus_resume =
  105658. +};
  105659. +
  105660. +/** Gets the dwc_otg_hcd from a struct usb_hcd */
  105661. +static inline dwc_otg_hcd_t *hcd_to_dwc_otg_hcd(struct usb_hcd *hcd)
  105662. +{
  105663. + struct wrapper_priv_data *p;
  105664. + p = (struct wrapper_priv_data *)(hcd->hcd_priv);
  105665. + return p->dwc_otg_hcd;
  105666. +}
  105667. +
  105668. +/** Gets the struct usb_hcd that contains a dwc_otg_hcd_t. */
  105669. +static inline struct usb_hcd *dwc_otg_hcd_to_hcd(dwc_otg_hcd_t * dwc_otg_hcd)
  105670. +{
  105671. + return dwc_otg_hcd_get_priv_data(dwc_otg_hcd);
  105672. +}
  105673. +
  105674. +/** Gets the usb_host_endpoint associated with an URB. */
  105675. +inline struct usb_host_endpoint *dwc_urb_to_endpoint(struct urb *urb)
  105676. +{
  105677. + struct usb_device *dev = urb->dev;
  105678. + int ep_num = usb_pipeendpoint(urb->pipe);
  105679. +
  105680. + if (usb_pipein(urb->pipe))
  105681. + return dev->ep_in[ep_num];
  105682. + else
  105683. + return dev->ep_out[ep_num];
  105684. +}
  105685. +
  105686. +static int _disconnect(dwc_otg_hcd_t * hcd)
  105687. +{
  105688. + struct usb_hcd *usb_hcd = dwc_otg_hcd_to_hcd(hcd);
  105689. +
  105690. + usb_hcd->self.is_b_host = 0;
  105691. + return 0;
  105692. +}
  105693. +
  105694. +static int _start(dwc_otg_hcd_t * hcd)
  105695. +{
  105696. + struct usb_hcd *usb_hcd = dwc_otg_hcd_to_hcd(hcd);
  105697. +
  105698. + usb_hcd->self.is_b_host = dwc_otg_hcd_is_b_host(hcd);
  105699. + hcd_start(usb_hcd);
  105700. +
  105701. + return 0;
  105702. +}
  105703. +
  105704. +static int _hub_info(dwc_otg_hcd_t * hcd, void *urb_handle, uint32_t * hub_addr,
  105705. + uint32_t * port_addr)
  105706. +{
  105707. + struct urb *urb = (struct urb *)urb_handle;
  105708. + struct usb_bus *bus;
  105709. +#if 1 //GRAYG - temporary
  105710. + if (NULL == urb_handle)
  105711. + DWC_ERROR("**** %s - NULL URB handle\n", __func__);//GRAYG
  105712. + if (NULL == urb->dev)
  105713. + DWC_ERROR("**** %s - URB has no device\n", __func__);//GRAYG
  105714. + if (NULL == port_addr)
  105715. + DWC_ERROR("**** %s - NULL port_address\n", __func__);//GRAYG
  105716. +#endif
  105717. + if (urb->dev->tt) {
  105718. + if (NULL == urb->dev->tt->hub) {
  105719. + DWC_ERROR("**** %s - (URB's transactor has no TT - giving no hub)\n",
  105720. + __func__); //GRAYG
  105721. + //*hub_addr = (u8)usb_pipedevice(urb->pipe); //GRAYG
  105722. + *hub_addr = 0; //GRAYG
  105723. + // we probably shouldn't have a transaction translator if
  105724. + // there's no associated hub?
  105725. + } else {
  105726. + bus = hcd_to_bus(dwc_otg_hcd_to_hcd(hcd));
  105727. + if (urb->dev->tt->hub == bus->root_hub)
  105728. + *hub_addr = 0;
  105729. + else
  105730. + *hub_addr = urb->dev->tt->hub->devnum;
  105731. + }
  105732. + *port_addr = urb->dev->tt->multi ? urb->dev->ttport : 1;
  105733. + } else {
  105734. + *hub_addr = 0;
  105735. + *port_addr = urb->dev->ttport;
  105736. + }
  105737. + return 0;
  105738. +}
  105739. +
  105740. +static int _speed(dwc_otg_hcd_t * hcd, void *urb_handle)
  105741. +{
  105742. + struct urb *urb = (struct urb *)urb_handle;
  105743. + return urb->dev->speed;
  105744. +}
  105745. +
  105746. +static int _get_b_hnp_enable(dwc_otg_hcd_t * hcd)
  105747. +{
  105748. + struct usb_hcd *usb_hcd = dwc_otg_hcd_to_hcd(hcd);
  105749. + return usb_hcd->self.b_hnp_enable;
  105750. +}
  105751. +
  105752. +static void allocate_bus_bandwidth(struct usb_hcd *hcd, uint32_t bw,
  105753. + struct urb *urb)
  105754. +{
  105755. + hcd_to_bus(hcd)->bandwidth_allocated += bw / urb->interval;
  105756. + if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
  105757. + hcd_to_bus(hcd)->bandwidth_isoc_reqs++;
  105758. + } else {
  105759. + hcd_to_bus(hcd)->bandwidth_int_reqs++;
  105760. + }
  105761. +}
  105762. +
  105763. +static void free_bus_bandwidth(struct usb_hcd *hcd, uint32_t bw,
  105764. + struct urb *urb)
  105765. +{
  105766. + hcd_to_bus(hcd)->bandwidth_allocated -= bw / urb->interval;
  105767. + if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
  105768. + hcd_to_bus(hcd)->bandwidth_isoc_reqs--;
  105769. + } else {
  105770. + hcd_to_bus(hcd)->bandwidth_int_reqs--;
  105771. + }
  105772. +}
  105773. +
  105774. +/**
  105775. + * Sets the final status of an URB and returns it to the device driver. Any
  105776. + * required cleanup of the URB is performed. The HCD lock should be held on
  105777. + * entry.
  105778. + */
  105779. +static int _complete(dwc_otg_hcd_t * hcd, void *urb_handle,
  105780. + dwc_otg_hcd_urb_t * dwc_otg_urb, int32_t status)
  105781. +{
  105782. + struct urb *urb = (struct urb *)urb_handle;
  105783. + urb_tq_entry_t *new_entry;
  105784. + int rc = 0;
  105785. + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
  105786. + DWC_PRINTF("%s: urb %p, device %d, ep %d %s, status=%d\n",
  105787. + __func__, urb, usb_pipedevice(urb->pipe),
  105788. + usb_pipeendpoint(urb->pipe),
  105789. + usb_pipein(urb->pipe) ? "IN" : "OUT", status);
  105790. + if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
  105791. + int i;
  105792. + for (i = 0; i < urb->number_of_packets; i++) {
  105793. + DWC_PRINTF(" ISO Desc %d status: %d\n",
  105794. + i, urb->iso_frame_desc[i].status);
  105795. + }
  105796. + }
  105797. + }
  105798. + new_entry = DWC_ALLOC_ATOMIC(sizeof(urb_tq_entry_t));
  105799. + urb->actual_length = dwc_otg_hcd_urb_get_actual_length(dwc_otg_urb);
  105800. + /* Convert status value. */
  105801. + switch (status) {
  105802. + case -DWC_E_PROTOCOL:
  105803. + status = -EPROTO;
  105804. + break;
  105805. + case -DWC_E_IN_PROGRESS:
  105806. + status = -EINPROGRESS;
  105807. + break;
  105808. + case -DWC_E_PIPE:
  105809. + status = -EPIPE;
  105810. + break;
  105811. + case -DWC_E_IO:
  105812. + status = -EIO;
  105813. + break;
  105814. + case -DWC_E_TIMEOUT:
  105815. + status = -ETIMEDOUT;
  105816. + break;
  105817. + case -DWC_E_OVERFLOW:
  105818. + status = -EOVERFLOW;
  105819. + break;
  105820. + case -DWC_E_SHUTDOWN:
  105821. + status = -ESHUTDOWN;
  105822. + break;
  105823. + default:
  105824. + if (status) {
  105825. + DWC_PRINTF("Uknown urb status %d\n", status);
  105826. +
  105827. + }
  105828. + }
  105829. +
  105830. + if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
  105831. + int i;
  105832. +
  105833. + urb->error_count = dwc_otg_hcd_urb_get_error_count(dwc_otg_urb);
  105834. + for (i = 0; i < urb->number_of_packets; ++i) {
  105835. + urb->iso_frame_desc[i].actual_length =
  105836. + dwc_otg_hcd_urb_get_iso_desc_actual_length
  105837. + (dwc_otg_urb, i);
  105838. + urb->iso_frame_desc[i].status =
  105839. + dwc_otg_hcd_urb_get_iso_desc_status(dwc_otg_urb, i);
  105840. + }
  105841. + }
  105842. +
  105843. + urb->status = status;
  105844. + urb->hcpriv = NULL;
  105845. + if (!status) {
  105846. + if ((urb->transfer_flags & URB_SHORT_NOT_OK) &&
  105847. + (urb->actual_length < urb->transfer_buffer_length)) {
  105848. + urb->status = -EREMOTEIO;
  105849. + }
  105850. + }
  105851. +
  105852. + if ((usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) ||
  105853. + (usb_pipetype(urb->pipe) == PIPE_INTERRUPT)) {
  105854. + struct usb_host_endpoint *ep = dwc_urb_to_endpoint(urb);
  105855. + if (ep) {
  105856. + free_bus_bandwidth(dwc_otg_hcd_to_hcd(hcd),
  105857. + dwc_otg_hcd_get_ep_bandwidth(hcd,
  105858. + ep->hcpriv),
  105859. + urb);
  105860. + }
  105861. + }
  105862. + DWC_FREE(dwc_otg_urb);
  105863. + if (!new_entry) {
  105864. + DWC_ERROR("dwc_otg_hcd: complete: cannot allocate URB TQ entry\n");
  105865. + urb->status = -EPROTO;
  105866. + /* don't schedule the tasklet -
  105867. + * directly return the packet here with error. */
  105868. +#if USB_URB_EP_LINKING
  105869. + usb_hcd_unlink_urb_from_ep(dwc_otg_hcd_to_hcd(hcd), urb);
  105870. +#endif
  105871. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  105872. + usb_hcd_giveback_urb(dwc_otg_hcd_to_hcd(hcd), urb);
  105873. +#else
  105874. + usb_hcd_giveback_urb(dwc_otg_hcd_to_hcd(hcd), urb, urb->status);
  105875. +#endif
  105876. + } else {
  105877. + new_entry->urb = urb;
  105878. +#if USB_URB_EP_LINKING
  105879. + rc = usb_hcd_check_unlink_urb(dwc_otg_hcd_to_hcd(hcd), urb, urb->status);
  105880. + if(0 == rc) {
  105881. + usb_hcd_unlink_urb_from_ep(dwc_otg_hcd_to_hcd(hcd), urb);
  105882. + }
  105883. +#endif
  105884. + if(0 == rc) {
  105885. + DWC_TAILQ_INSERT_TAIL(&hcd->completed_urb_list, new_entry,
  105886. + urb_tq_entries);
  105887. + DWC_TASK_HI_SCHEDULE(hcd->completion_tasklet);
  105888. + }
  105889. + }
  105890. + return 0;
  105891. +}
  105892. +
  105893. +static struct dwc_otg_hcd_function_ops hcd_fops = {
  105894. + .start = _start,
  105895. + .disconnect = _disconnect,
  105896. + .hub_info = _hub_info,
  105897. + .speed = _speed,
  105898. + .complete = _complete,
  105899. + .get_b_hnp_enable = _get_b_hnp_enable,
  105900. +};
  105901. +
  105902. +static struct fiq_handler fh = {
  105903. + .name = "usb_fiq",
  105904. +};
  105905. +
  105906. +static void hcd_init_fiq(void *cookie)
  105907. +{
  105908. + dwc_otg_device_t *otg_dev = cookie;
  105909. + dwc_otg_hcd_t *dwc_otg_hcd = otg_dev->hcd;
  105910. + struct pt_regs regs;
  105911. +
  105912. + if (claim_fiq(&fh)) {
  105913. + DWC_ERROR("Can't claim FIQ");
  105914. + BUG();
  105915. + }
  105916. + DWC_WARN("FIQ on core %d at 0x%08x",
  105917. + smp_processor_id(),
  105918. + (fiq_fsm_enable ? (int)&dwc_otg_fiq_fsm : (int)&dwc_otg_fiq_nop));
  105919. + DWC_WARN("FIQ ASM at 0x%08x length %d", (int)&_dwc_otg_fiq_stub, (int)(&_dwc_otg_fiq_stub_end - &_dwc_otg_fiq_stub));
  105920. + set_fiq_handler((void *) &_dwc_otg_fiq_stub, &_dwc_otg_fiq_stub_end - &_dwc_otg_fiq_stub);
  105921. + memset(&regs,0,sizeof(regs));
  105922. +
  105923. + regs.ARM_r8 = (long) dwc_otg_hcd->fiq_state;
  105924. + if (fiq_fsm_enable) {
  105925. + regs.ARM_r9 = dwc_otg_hcd->core_if->core_params->host_channels;
  105926. + //regs.ARM_r10 = dwc_otg_hcd->dma;
  105927. + regs.ARM_fp = (long) dwc_otg_fiq_fsm;
  105928. + } else {
  105929. + regs.ARM_fp = (long) dwc_otg_fiq_nop;
  105930. + }
  105931. +
  105932. + regs.ARM_sp = (long) dwc_otg_hcd->fiq_stack + (sizeof(struct fiq_stack) - 4);
  105933. +
  105934. +// __show_regs(&regs);
  105935. + set_fiq_regs(&regs);
  105936. +
  105937. + //Set the mphi periph to the required registers
  105938. + dwc_otg_hcd->fiq_state->mphi_regs.base = otg_dev->os_dep.mphi_base;
  105939. + dwc_otg_hcd->fiq_state->mphi_regs.ctrl = otg_dev->os_dep.mphi_base + 0x4c;
  105940. + dwc_otg_hcd->fiq_state->mphi_regs.outdda = otg_dev->os_dep.mphi_base + 0x28;
  105941. + dwc_otg_hcd->fiq_state->mphi_regs.outddb = otg_dev->os_dep.mphi_base + 0x2c;
  105942. + dwc_otg_hcd->fiq_state->mphi_regs.intstat = otg_dev->os_dep.mphi_base + 0x50;
  105943. + dwc_otg_hcd->fiq_state->dwc_regs_base = otg_dev->os_dep.base;
  105944. + DWC_WARN("MPHI regs_base at 0x%08x", (int)dwc_otg_hcd->fiq_state->mphi_regs.base);
  105945. + //Enable mphi peripheral
  105946. + writel((1<<31),dwc_otg_hcd->fiq_state->mphi_regs.ctrl);
  105947. +#ifdef DEBUG
  105948. + if (readl(dwc_otg_hcd->fiq_state->mphi_regs.ctrl) & 0x80000000)
  105949. + DWC_WARN("MPHI periph has been enabled");
  105950. + else
  105951. + DWC_WARN("MPHI periph has NOT been enabled");
  105952. +#endif
  105953. + // Enable FIQ interrupt from USB peripheral
  105954. + enable_fiq(INTERRUPT_VC_USB);
  105955. + local_fiq_enable();
  105956. +}
  105957. +
  105958. +/**
  105959. + * Initializes the HCD. This function allocates memory for and initializes the
  105960. + * static parts of the usb_hcd and dwc_otg_hcd structures. It also registers the
  105961. + * USB bus with the core and calls the hc_driver->start() function. It returns
  105962. + * a negative error on failure.
  105963. + */
  105964. +int hcd_init(dwc_bus_dev_t *_dev)
  105965. +{
  105966. + struct usb_hcd *hcd = NULL;
  105967. + dwc_otg_hcd_t *dwc_otg_hcd = NULL;
  105968. + dwc_otg_device_t *otg_dev = DWC_OTG_BUSDRVDATA(_dev);
  105969. + int retval = 0;
  105970. + u64 dmamask;
  105971. +
  105972. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD INIT otg_dev=%p\n", otg_dev);
  105973. +
  105974. + /* Set device flags indicating whether the HCD supports DMA. */
  105975. + if (dwc_otg_is_dma_enable(otg_dev->core_if))
  105976. + dmamask = DMA_BIT_MASK(32);
  105977. + else
  105978. + dmamask = 0;
  105979. +
  105980. +#if defined(LM_INTERFACE) || defined(PLATFORM_INTERFACE)
  105981. + dma_set_mask(&_dev->dev, dmamask);
  105982. + dma_set_coherent_mask(&_dev->dev, dmamask);
  105983. +#elif defined(PCI_INTERFACE)
  105984. + pci_set_dma_mask(_dev, dmamask);
  105985. + pci_set_consistent_dma_mask(_dev, dmamask);
  105986. +#endif
  105987. +
  105988. + /*
  105989. + * Allocate memory for the base HCD plus the DWC OTG HCD.
  105990. + * Initialize the base HCD.
  105991. + */
  105992. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30)
  105993. + hcd = usb_create_hcd(&dwc_otg_hc_driver, &_dev->dev, _dev->dev.bus_id);
  105994. +#else
  105995. + hcd = usb_create_hcd(&dwc_otg_hc_driver, &_dev->dev, dev_name(&_dev->dev));
  105996. + hcd->has_tt = 1;
  105997. +// hcd->uses_new_polling = 1;
  105998. +// hcd->poll_rh = 0;
  105999. +#endif
  106000. + if (!hcd) {
  106001. + retval = -ENOMEM;
  106002. + goto error1;
  106003. + }
  106004. +
  106005. + hcd->regs = otg_dev->os_dep.base;
  106006. +
  106007. +
  106008. + /* Initialize the DWC OTG HCD. */
  106009. + dwc_otg_hcd = dwc_otg_hcd_alloc_hcd();
  106010. + if (!dwc_otg_hcd) {
  106011. + goto error2;
  106012. + }
  106013. + ((struct wrapper_priv_data *)(hcd->hcd_priv))->dwc_otg_hcd =
  106014. + dwc_otg_hcd;
  106015. + otg_dev->hcd = dwc_otg_hcd;
  106016. +
  106017. + if (dwc_otg_hcd_init(dwc_otg_hcd, otg_dev->core_if)) {
  106018. + goto error2;
  106019. + }
  106020. +
  106021. + if (fiq_enable) {
  106022. + if (num_online_cpus() > 1) {
  106023. + /* bcm2709: can run the FIQ on a separate core to IRQs */
  106024. + smp_call_function_single(1, hcd_init_fiq, otg_dev, 1);
  106025. + } else {
  106026. + smp_call_function_single(0, hcd_init_fiq, otg_dev, 1);
  106027. + }
  106028. + }
  106029. +
  106030. + otg_dev->hcd->otg_dev = otg_dev;
  106031. + hcd->self.otg_port = dwc_otg_hcd_otg_port(dwc_otg_hcd);
  106032. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,33) //don't support for LM(with 2.6.20.1 kernel)
  106033. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,35) //version field absent later
  106034. + hcd->self.otg_version = dwc_otg_get_otg_version(otg_dev->core_if);
  106035. +#endif
  106036. + /* Don't support SG list at this point */
  106037. + hcd->self.sg_tablesize = 0;
  106038. +#endif
  106039. + /*
  106040. + * Finish generic HCD initialization and start the HCD. This function
  106041. + * allocates the DMA buffer pool, registers the USB bus, requests the
  106042. + * IRQ line, and calls hcd_start method.
  106043. + */
  106044. +#ifdef PLATFORM_INTERFACE
  106045. + retval = usb_add_hcd(hcd, platform_get_irq(_dev, fiq_enable ? 0 : 1), IRQF_SHARED | IRQF_DISABLED);
  106046. +#else
  106047. + retval = usb_add_hcd(hcd, _dev->irq, IRQF_SHARED | IRQF_DISABLED);
  106048. +#endif
  106049. + if (retval < 0) {
  106050. + goto error2;
  106051. + }
  106052. +
  106053. + dwc_otg_hcd_set_priv_data(dwc_otg_hcd, hcd);
  106054. + return 0;
  106055. +
  106056. +error2:
  106057. + usb_put_hcd(hcd);
  106058. +error1:
  106059. + return retval;
  106060. +}
  106061. +
  106062. +/**
  106063. + * Removes the HCD.
  106064. + * Frees memory and resources associated with the HCD and deregisters the bus.
  106065. + */
  106066. +void hcd_remove(dwc_bus_dev_t *_dev)
  106067. +{
  106068. + dwc_otg_device_t *otg_dev = DWC_OTG_BUSDRVDATA(_dev);
  106069. + dwc_otg_hcd_t *dwc_otg_hcd;
  106070. + struct usb_hcd *hcd;
  106071. +
  106072. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD REMOVE otg_dev=%p\n", otg_dev);
  106073. +
  106074. + if (!otg_dev) {
  106075. + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev NULL!\n", __func__);
  106076. + return;
  106077. + }
  106078. +
  106079. + dwc_otg_hcd = otg_dev->hcd;
  106080. +
  106081. + if (!dwc_otg_hcd) {
  106082. + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev->hcd NULL!\n", __func__);
  106083. + return;
  106084. + }
  106085. +
  106086. + hcd = dwc_otg_hcd_to_hcd(dwc_otg_hcd);
  106087. +
  106088. + if (!hcd) {
  106089. + DWC_DEBUGPL(DBG_ANY,
  106090. + "%s: dwc_otg_hcd_to_hcd(dwc_otg_hcd) NULL!\n",
  106091. + __func__);
  106092. + return;
  106093. + }
  106094. + usb_remove_hcd(hcd);
  106095. + dwc_otg_hcd_set_priv_data(dwc_otg_hcd, NULL);
  106096. + dwc_otg_hcd_remove(dwc_otg_hcd);
  106097. + usb_put_hcd(hcd);
  106098. +}
  106099. +
  106100. +/* =========================================================================
  106101. + * Linux HC Driver Functions
  106102. + * ========================================================================= */
  106103. +
  106104. +/** Initializes the DWC_otg controller and its root hub and prepares it for host
  106105. + * mode operation. Activates the root port. Returns 0 on success and a negative
  106106. + * error code on failure. */
  106107. +int hcd_start(struct usb_hcd *hcd)
  106108. +{
  106109. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  106110. + struct usb_bus *bus;
  106111. +
  106112. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD START\n");
  106113. + bus = hcd_to_bus(hcd);
  106114. +
  106115. + hcd->state = HC_STATE_RUNNING;
  106116. + if (dwc_otg_hcd_start(dwc_otg_hcd, &hcd_fops)) {
  106117. + return 0;
  106118. + }
  106119. +
  106120. + /* Initialize and connect root hub if one is not already attached */
  106121. + if (bus->root_hub) {
  106122. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD Has Root Hub\n");
  106123. + /* Inform the HUB driver to resume. */
  106124. + usb_hcd_resume_root_hub(hcd);
  106125. + }
  106126. +
  106127. + return 0;
  106128. +}
  106129. +
  106130. +/**
  106131. + * Halts the DWC_otg host mode operations in a clean manner. USB transfers are
  106132. + * stopped.
  106133. + */
  106134. +void hcd_stop(struct usb_hcd *hcd)
  106135. +{
  106136. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  106137. +
  106138. + dwc_otg_hcd_stop(dwc_otg_hcd);
  106139. +}
  106140. +
  106141. +/** Returns the current frame number. */
  106142. +static int get_frame_number(struct usb_hcd *hcd)
  106143. +{
  106144. + hprt0_data_t hprt0;
  106145. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  106146. + hprt0.d32 = DWC_READ_REG32(dwc_otg_hcd->core_if->host_if->hprt0);
  106147. + if (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_HIGH_SPEED)
  106148. + return dwc_otg_hcd_get_frame_number(dwc_otg_hcd) >> 3;
  106149. + else
  106150. + return dwc_otg_hcd_get_frame_number(dwc_otg_hcd);
  106151. +}
  106152. +
  106153. +#ifdef DEBUG
  106154. +static void dump_urb_info(struct urb *urb, char *fn_name)
  106155. +{
  106156. + DWC_PRINTF("%s, urb %p\n", fn_name, urb);
  106157. + DWC_PRINTF(" Device address: %d\n", usb_pipedevice(urb->pipe));
  106158. + DWC_PRINTF(" Endpoint: %d, %s\n", usb_pipeendpoint(urb->pipe),
  106159. + (usb_pipein(urb->pipe) ? "IN" : "OUT"));
  106160. + DWC_PRINTF(" Endpoint type: %s\n", ( {
  106161. + char *pipetype;
  106162. + switch (usb_pipetype(urb->pipe)) {
  106163. +case PIPE_CONTROL:
  106164. +pipetype = "CONTROL"; break; case PIPE_BULK:
  106165. +pipetype = "BULK"; break; case PIPE_INTERRUPT:
  106166. +pipetype = "INTERRUPT"; break; case PIPE_ISOCHRONOUS:
  106167. +pipetype = "ISOCHRONOUS"; break; default:
  106168. + pipetype = "UNKNOWN"; break;};
  106169. + pipetype;}
  106170. + )) ;
  106171. + DWC_PRINTF(" Speed: %s\n", ( {
  106172. + char *speed; switch (urb->dev->speed) {
  106173. +case USB_SPEED_HIGH:
  106174. +speed = "HIGH"; break; case USB_SPEED_FULL:
  106175. +speed = "FULL"; break; case USB_SPEED_LOW:
  106176. +speed = "LOW"; break; default:
  106177. + speed = "UNKNOWN"; break;};
  106178. + speed;}
  106179. + )) ;
  106180. + DWC_PRINTF(" Max packet size: %d\n",
  106181. + usb_maxpacket(urb->dev, urb->pipe, usb_pipeout(urb->pipe)));
  106182. + DWC_PRINTF(" Data buffer length: %d\n", urb->transfer_buffer_length);
  106183. + DWC_PRINTF(" Transfer buffer: %p, Transfer DMA: %p\n",
  106184. + urb->transfer_buffer, (void *)urb->transfer_dma);
  106185. + DWC_PRINTF(" Setup buffer: %p, Setup DMA: %p\n",
  106186. + urb->setup_packet, (void *)urb->setup_dma);
  106187. + DWC_PRINTF(" Interval: %d\n", urb->interval);
  106188. + if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
  106189. + int i;
  106190. + for (i = 0; i < urb->number_of_packets; i++) {
  106191. + DWC_PRINTF(" ISO Desc %d:\n", i);
  106192. + DWC_PRINTF(" offset: %d, length %d\n",
  106193. + urb->iso_frame_desc[i].offset,
  106194. + urb->iso_frame_desc[i].length);
  106195. + }
  106196. + }
  106197. +}
  106198. +#endif
  106199. +
  106200. +/** Starts processing a USB transfer request specified by a USB Request Block
  106201. + * (URB). mem_flags indicates the type of memory allocation to use while
  106202. + * processing this URB. */
  106203. +static int dwc_otg_urb_enqueue(struct usb_hcd *hcd,
  106204. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  106205. + struct usb_host_endpoint *ep,
  106206. +#endif
  106207. + struct urb *urb, gfp_t mem_flags)
  106208. +{
  106209. + int retval = 0;
  106210. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,28)
  106211. + struct usb_host_endpoint *ep = urb->ep;
  106212. +#endif
  106213. + dwc_irqflags_t irqflags;
  106214. + void **ref_ep_hcpriv = &ep->hcpriv;
  106215. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  106216. + dwc_otg_hcd_urb_t *dwc_otg_urb;
  106217. + int i;
  106218. + int alloc_bandwidth = 0;
  106219. + uint8_t ep_type = 0;
  106220. + uint32_t flags = 0;
  106221. + void *buf;
  106222. +
  106223. +#ifdef DEBUG
  106224. + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
  106225. + dump_urb_info(urb, "dwc_otg_urb_enqueue");
  106226. + }
  106227. +#endif
  106228. +
  106229. + if (!urb->transfer_buffer && urb->transfer_buffer_length)
  106230. + return -EINVAL;
  106231. +
  106232. + if ((usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS)
  106233. + || (usb_pipetype(urb->pipe) == PIPE_INTERRUPT)) {
  106234. + if (!dwc_otg_hcd_is_bandwidth_allocated
  106235. + (dwc_otg_hcd, ref_ep_hcpriv)) {
  106236. + alloc_bandwidth = 1;
  106237. + }
  106238. + }
  106239. +
  106240. + switch (usb_pipetype(urb->pipe)) {
  106241. + case PIPE_CONTROL:
  106242. + ep_type = USB_ENDPOINT_XFER_CONTROL;
  106243. + break;
  106244. + case PIPE_ISOCHRONOUS:
  106245. + ep_type = USB_ENDPOINT_XFER_ISOC;
  106246. + break;
  106247. + case PIPE_BULK:
  106248. + ep_type = USB_ENDPOINT_XFER_BULK;
  106249. + break;
  106250. + case PIPE_INTERRUPT:
  106251. + ep_type = USB_ENDPOINT_XFER_INT;
  106252. + break;
  106253. + default:
  106254. + DWC_WARN("Wrong EP type - %d\n", usb_pipetype(urb->pipe));
  106255. + }
  106256. +
  106257. + /* # of packets is often 0 - do we really need to call this then? */
  106258. + dwc_otg_urb = dwc_otg_hcd_urb_alloc(dwc_otg_hcd,
  106259. + urb->number_of_packets,
  106260. + mem_flags == GFP_ATOMIC ? 1 : 0);
  106261. +
  106262. + if(dwc_otg_urb == NULL)
  106263. + return -ENOMEM;
  106264. +
  106265. + if (!dwc_otg_urb && urb->number_of_packets)
  106266. + return -ENOMEM;
  106267. +
  106268. + dwc_otg_hcd_urb_set_pipeinfo(dwc_otg_urb, usb_pipedevice(urb->pipe),
  106269. + usb_pipeendpoint(urb->pipe), ep_type,
  106270. + usb_pipein(urb->pipe),
  106271. + usb_maxpacket(urb->dev, urb->pipe,
  106272. + !(usb_pipein(urb->pipe))));
  106273. +
  106274. + buf = urb->transfer_buffer;
  106275. + if (hcd->self.uses_dma) {
  106276. + /*
  106277. + * Calculate virtual address from physical address,
  106278. + * because some class driver may not fill transfer_buffer.
  106279. + * In Buffer DMA mode virual address is used,
  106280. + * when handling non DWORD aligned buffers.
  106281. + */
  106282. + //buf = phys_to_virt(urb->transfer_dma);
  106283. + // DMA addresses are bus addresses not physical addresses!
  106284. + buf = dma_to_virt(&urb->dev->dev, urb->transfer_dma);
  106285. + }
  106286. +
  106287. + if (!(urb->transfer_flags & URB_NO_INTERRUPT))
  106288. + flags |= URB_GIVEBACK_ASAP;
  106289. + if (urb->transfer_flags & URB_ZERO_PACKET)
  106290. + flags |= URB_SEND_ZERO_PACKET;
  106291. +
  106292. + dwc_otg_hcd_urb_set_params(dwc_otg_urb, urb, buf,
  106293. + urb->transfer_dma,
  106294. + urb->transfer_buffer_length,
  106295. + urb->setup_packet,
  106296. + urb->setup_dma, flags, urb->interval);
  106297. +
  106298. + for (i = 0; i < urb->number_of_packets; ++i) {
  106299. + dwc_otg_hcd_urb_set_iso_desc_params(dwc_otg_urb, i,
  106300. + urb->
  106301. + iso_frame_desc[i].offset,
  106302. + urb->
  106303. + iso_frame_desc[i].length);
  106304. + }
  106305. +
  106306. + DWC_SPINLOCK_IRQSAVE(dwc_otg_hcd->lock, &irqflags);
  106307. + urb->hcpriv = dwc_otg_urb;
  106308. +#if USB_URB_EP_LINKING
  106309. + retval = usb_hcd_link_urb_to_ep(hcd, urb);
  106310. + if (0 == retval)
  106311. +#endif
  106312. + {
  106313. + retval = dwc_otg_hcd_urb_enqueue(dwc_otg_hcd, dwc_otg_urb,
  106314. + /*(dwc_otg_qh_t **)*/
  106315. + ref_ep_hcpriv, 1);
  106316. + if (0 == retval) {
  106317. + if (alloc_bandwidth) {
  106318. + allocate_bus_bandwidth(hcd,
  106319. + dwc_otg_hcd_get_ep_bandwidth(
  106320. + dwc_otg_hcd, *ref_ep_hcpriv),
  106321. + urb);
  106322. + }
  106323. + } else {
  106324. + DWC_DEBUGPL(DBG_HCD, "DWC OTG dwc_otg_hcd_urb_enqueue failed rc %d\n", retval);
  106325. +#if USB_URB_EP_LINKING
  106326. + usb_hcd_unlink_urb_from_ep(hcd, urb);
  106327. +#endif
  106328. + DWC_FREE(dwc_otg_urb);
  106329. + urb->hcpriv = NULL;
  106330. + if (retval == -DWC_E_NO_DEVICE)
  106331. + retval = -ENODEV;
  106332. + }
  106333. + }
  106334. +#if USB_URB_EP_LINKING
  106335. + else
  106336. + {
  106337. + DWC_FREE(dwc_otg_urb);
  106338. + urb->hcpriv = NULL;
  106339. + }
  106340. +#endif
  106341. + DWC_SPINUNLOCK_IRQRESTORE(dwc_otg_hcd->lock, irqflags);
  106342. + return retval;
  106343. +}
  106344. +
  106345. +/** Aborts/cancels a USB transfer request. Always returns 0 to indicate
  106346. + * success. */
  106347. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  106348. +static int dwc_otg_urb_dequeue(struct usb_hcd *hcd, struct urb *urb)
  106349. +#else
  106350. +static int dwc_otg_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
  106351. +#endif
  106352. +{
  106353. + dwc_irqflags_t flags;
  106354. + dwc_otg_hcd_t *dwc_otg_hcd;
  106355. + int rc;
  106356. +
  106357. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD URB Dequeue\n");
  106358. +
  106359. + dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  106360. +
  106361. +#ifdef DEBUG
  106362. + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
  106363. + dump_urb_info(urb, "dwc_otg_urb_dequeue");
  106364. + }
  106365. +#endif
  106366. +
  106367. + DWC_SPINLOCK_IRQSAVE(dwc_otg_hcd->lock, &flags);
  106368. + rc = usb_hcd_check_unlink_urb(hcd, urb, status);
  106369. + if (0 == rc) {
  106370. + if(urb->hcpriv != NULL) {
  106371. + dwc_otg_hcd_urb_dequeue(dwc_otg_hcd,
  106372. + (dwc_otg_hcd_urb_t *)urb->hcpriv);
  106373. +
  106374. + DWC_FREE(urb->hcpriv);
  106375. + urb->hcpriv = NULL;
  106376. + }
  106377. + }
  106378. +
  106379. + if (0 == rc) {
  106380. + /* Higher layer software sets URB status. */
  106381. +#if USB_URB_EP_LINKING
  106382. + usb_hcd_unlink_urb_from_ep(hcd, urb);
  106383. +#endif
  106384. + DWC_SPINUNLOCK_IRQRESTORE(dwc_otg_hcd->lock, flags);
  106385. +
  106386. +
  106387. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  106388. + usb_hcd_giveback_urb(hcd, urb);
  106389. +#else
  106390. + usb_hcd_giveback_urb(hcd, urb, status);
  106391. +#endif
  106392. + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
  106393. + DWC_PRINTF("Called usb_hcd_giveback_urb() \n");
  106394. + DWC_PRINTF(" 1urb->status = %d\n", urb->status);
  106395. + }
  106396. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD URB Dequeue OK\n");
  106397. + } else {
  106398. + DWC_SPINUNLOCK_IRQRESTORE(dwc_otg_hcd->lock, flags);
  106399. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD URB Dequeue failed - rc %d\n",
  106400. + rc);
  106401. + }
  106402. +
  106403. + return rc;
  106404. +}
  106405. +
  106406. +/* Frees resources in the DWC_otg controller related to a given endpoint. Also
  106407. + * clears state in the HCD related to the endpoint. Any URBs for the endpoint
  106408. + * must already be dequeued. */
  106409. +static void endpoint_disable(struct usb_hcd *hcd, struct usb_host_endpoint *ep)
  106410. +{
  106411. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  106412. +
  106413. + DWC_DEBUGPL(DBG_HCD,
  106414. + "DWC OTG HCD EP DISABLE: _bEndpointAddress=0x%02x, "
  106415. + "endpoint=%d\n", ep->desc.bEndpointAddress,
  106416. + dwc_ep_addr_to_endpoint(ep->desc.bEndpointAddress));
  106417. + dwc_otg_hcd_endpoint_disable(dwc_otg_hcd, ep->hcpriv, 250);
  106418. + ep->hcpriv = NULL;
  106419. +}
  106420. +
  106421. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30)
  106422. +/* Resets endpoint specific parameter values, in current version used to reset
  106423. + * the data toggle(as a WA). This function can be called from usb_clear_halt routine */
  106424. +static void endpoint_reset(struct usb_hcd *hcd, struct usb_host_endpoint *ep)
  106425. +{
  106426. + dwc_irqflags_t flags;
  106427. + struct usb_device *udev = NULL;
  106428. + int epnum = usb_endpoint_num(&ep->desc);
  106429. + int is_out = usb_endpoint_dir_out(&ep->desc);
  106430. + int is_control = usb_endpoint_xfer_control(&ep->desc);
  106431. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  106432. + struct device *dev = DWC_OTG_OS_GETDEV(dwc_otg_hcd->otg_dev->os_dep);
  106433. +
  106434. + if (dev)
  106435. + udev = to_usb_device(dev);
  106436. + else
  106437. + return;
  106438. +
  106439. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD EP RESET: Endpoint Num=0x%02d\n", epnum);
  106440. +
  106441. + DWC_SPINLOCK_IRQSAVE(dwc_otg_hcd->lock, &flags);
  106442. + usb_settoggle(udev, epnum, is_out, 0);
  106443. + if (is_control)
  106444. + usb_settoggle(udev, epnum, !is_out, 0);
  106445. +
  106446. + if (ep->hcpriv) {
  106447. + dwc_otg_hcd_endpoint_reset(dwc_otg_hcd, ep->hcpriv);
  106448. + }
  106449. + DWC_SPINUNLOCK_IRQRESTORE(dwc_otg_hcd->lock, flags);
  106450. +}
  106451. +#endif
  106452. +
  106453. +/** Handles host mode interrupts for the DWC_otg controller. Returns IRQ_NONE if
  106454. + * there was no interrupt to handle. Returns IRQ_HANDLED if there was a valid
  106455. + * interrupt.
  106456. + *
  106457. + * This function is called by the USB core when an interrupt occurs */
  106458. +static irqreturn_t dwc_otg_hcd_irq(struct usb_hcd *hcd)
  106459. +{
  106460. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  106461. + int32_t retval = dwc_otg_hcd_handle_intr(dwc_otg_hcd);
  106462. + if (retval != 0) {
  106463. + S3C2410X_CLEAR_EINTPEND();
  106464. + }
  106465. + return IRQ_RETVAL(retval);
  106466. +}
  106467. +
  106468. +/** Creates Status Change bitmap for the root hub and root port. The bitmap is
  106469. + * returned in buf. Bit 0 is the status change indicator for the root hub. Bit 1
  106470. + * is the status change indicator for the single root port. Returns 1 if either
  106471. + * change indicator is 1, otherwise returns 0. */
  106472. +int hub_status_data(struct usb_hcd *hcd, char *buf)
  106473. +{
  106474. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  106475. +
  106476. + buf[0] = 0;
  106477. + buf[0] |= (dwc_otg_hcd_is_status_changed(dwc_otg_hcd, 1)) << 1;
  106478. +
  106479. + return (buf[0] != 0);
  106480. +}
  106481. +
  106482. +/** Handles hub class-specific requests. */
  106483. +int hub_control(struct usb_hcd *hcd,
  106484. + u16 typeReq, u16 wValue, u16 wIndex, char *buf, u16 wLength)
  106485. +{
  106486. + int retval;
  106487. +
  106488. + retval = dwc_otg_hcd_hub_control(hcd_to_dwc_otg_hcd(hcd),
  106489. + typeReq, wValue, wIndex, buf, wLength);
  106490. +
  106491. + switch (retval) {
  106492. + case -DWC_E_INVALID:
  106493. + retval = -EINVAL;
  106494. + break;
  106495. + }
  106496. +
  106497. + return retval;
  106498. +}
  106499. +
  106500. +#endif /* DWC_DEVICE_ONLY */
  106501. diff -Nur linux-3.18.8/drivers/usb/host/dwc_otg/dwc_otg_hcd_queue.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd_queue.c
  106502. --- linux-3.18.8/drivers/usb/host/dwc_otg/dwc_otg_hcd_queue.c 1970-01-01 01:00:00.000000000 +0100
  106503. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd_queue.c 2015-03-05 14:40:16.561715806 +0100
  106504. @@ -0,0 +1,957 @@
  106505. +/* ==========================================================================
  106506. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd_queue.c $
  106507. + * $Revision: #44 $
  106508. + * $Date: 2011/10/26 $
  106509. + * $Change: 1873028 $
  106510. + *
  106511. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  106512. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  106513. + * otherwise expressly agreed to in writing between Synopsys and you.
  106514. + *
  106515. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  106516. + * any End User Software License Agreement or Agreement for Licensed Product
  106517. + * with Synopsys or any supplement thereto. You are permitted to use and
  106518. + * redistribute this Software in source and binary forms, with or without
  106519. + * modification, provided that redistributions of source code must retain this
  106520. + * notice. You may not view, use, disclose, copy or distribute this file or
  106521. + * any information contained herein except pursuant to this license grant from
  106522. + * Synopsys. If you do not agree with this notice, including the disclaimer
  106523. + * below, then you are not authorized to use the Software.
  106524. + *
  106525. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  106526. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  106527. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  106528. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  106529. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  106530. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  106531. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  106532. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  106533. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  106534. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  106535. + * DAMAGE.
  106536. + * ========================================================================== */
  106537. +#ifndef DWC_DEVICE_ONLY
  106538. +
  106539. +/**
  106540. + * @file
  106541. + *
  106542. + * This file contains the functions to manage Queue Heads and Queue
  106543. + * Transfer Descriptors.
  106544. + */
  106545. +
  106546. +#include "dwc_otg_hcd.h"
  106547. +#include "dwc_otg_regs.h"
  106548. +
  106549. +extern bool microframe_schedule;
  106550. +
  106551. +/**
  106552. + * Free each QTD in the QH's QTD-list then free the QH. QH should already be
  106553. + * removed from a list. QTD list should already be empty if called from URB
  106554. + * Dequeue.
  106555. + *
  106556. + * @param hcd HCD instance.
  106557. + * @param qh The QH to free.
  106558. + */
  106559. +void dwc_otg_hcd_qh_free(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  106560. +{
  106561. + dwc_otg_qtd_t *qtd, *qtd_tmp;
  106562. + dwc_irqflags_t flags;
  106563. +
  106564. + /* Free each QTD in the QTD list */
  106565. + DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
  106566. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp, &qh->qtd_list, qtd_list_entry) {
  106567. + DWC_CIRCLEQ_REMOVE(&qh->qtd_list, qtd, qtd_list_entry);
  106568. + dwc_otg_hcd_qtd_free(qtd);
  106569. + }
  106570. +
  106571. + if (hcd->core_if->dma_desc_enable) {
  106572. + dwc_otg_hcd_qh_free_ddma(hcd, qh);
  106573. + } else if (qh->dw_align_buf) {
  106574. + uint32_t buf_size;
  106575. + if (qh->ep_type == UE_ISOCHRONOUS) {
  106576. + buf_size = 4096;
  106577. + } else {
  106578. + buf_size = hcd->core_if->core_params->max_transfer_size;
  106579. + }
  106580. + DWC_DMA_FREE(buf_size, qh->dw_align_buf, qh->dw_align_buf_dma);
  106581. + }
  106582. +
  106583. + DWC_FREE(qh);
  106584. + DWC_SPINUNLOCK_IRQRESTORE(hcd->lock, flags);
  106585. + return;
  106586. +}
  106587. +
  106588. +#define BitStuffTime(bytecount) ((8 * 7* bytecount) / 6)
  106589. +#define HS_HOST_DELAY 5 /* nanoseconds */
  106590. +#define FS_LS_HOST_DELAY 1000 /* nanoseconds */
  106591. +#define HUB_LS_SETUP 333 /* nanoseconds */
  106592. +#define NS_TO_US(ns) ((ns + 500) / 1000)
  106593. + /* convert & round nanoseconds to microseconds */
  106594. +
  106595. +static uint32_t calc_bus_time(int speed, int is_in, int is_isoc, int bytecount)
  106596. +{
  106597. + unsigned long retval;
  106598. +
  106599. + switch (speed) {
  106600. + case USB_SPEED_HIGH:
  106601. + if (is_isoc) {
  106602. + retval =
  106603. + ((38 * 8 * 2083) +
  106604. + (2083 * (3 + BitStuffTime(bytecount)))) / 1000 +
  106605. + HS_HOST_DELAY;
  106606. + } else {
  106607. + retval =
  106608. + ((55 * 8 * 2083) +
  106609. + (2083 * (3 + BitStuffTime(bytecount)))) / 1000 +
  106610. + HS_HOST_DELAY;
  106611. + }
  106612. + break;
  106613. + case USB_SPEED_FULL:
  106614. + if (is_isoc) {
  106615. + retval =
  106616. + (8354 * (31 + 10 * BitStuffTime(bytecount))) / 1000;
  106617. + if (is_in) {
  106618. + retval = 7268 + FS_LS_HOST_DELAY + retval;
  106619. + } else {
  106620. + retval = 6265 + FS_LS_HOST_DELAY + retval;
  106621. + }
  106622. + } else {
  106623. + retval =
  106624. + (8354 * (31 + 10 * BitStuffTime(bytecount))) / 1000;
  106625. + retval = 9107 + FS_LS_HOST_DELAY + retval;
  106626. + }
  106627. + break;
  106628. + case USB_SPEED_LOW:
  106629. + if (is_in) {
  106630. + retval =
  106631. + (67667 * (31 + 10 * BitStuffTime(bytecount))) /
  106632. + 1000;
  106633. + retval =
  106634. + 64060 + (2 * HUB_LS_SETUP) + FS_LS_HOST_DELAY +
  106635. + retval;
  106636. + } else {
  106637. + retval =
  106638. + (66700 * (31 + 10 * BitStuffTime(bytecount))) /
  106639. + 1000;
  106640. + retval =
  106641. + 64107 + (2 * HUB_LS_SETUP) + FS_LS_HOST_DELAY +
  106642. + retval;
  106643. + }
  106644. + break;
  106645. + default:
  106646. + DWC_WARN("Unknown device speed\n");
  106647. + retval = -1;
  106648. + }
  106649. +
  106650. + return NS_TO_US(retval);
  106651. +}
  106652. +
  106653. +/**
  106654. + * Initializes a QH structure.
  106655. + *
  106656. + * @param hcd The HCD state structure for the DWC OTG controller.
  106657. + * @param qh The QH to init.
  106658. + * @param urb Holds the information about the device/endpoint that we need
  106659. + * to initialize the QH.
  106660. + */
  106661. +#define SCHEDULE_SLOP 10
  106662. +void qh_init(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh, dwc_otg_hcd_urb_t * urb)
  106663. +{
  106664. + char *speed, *type;
  106665. + int dev_speed;
  106666. + uint32_t hub_addr, hub_port;
  106667. +
  106668. + dwc_memset(qh, 0, sizeof(dwc_otg_qh_t));
  106669. +
  106670. + /* Initialize QH */
  106671. + qh->ep_type = dwc_otg_hcd_get_pipe_type(&urb->pipe_info);
  106672. + qh->ep_is_in = dwc_otg_hcd_is_pipe_in(&urb->pipe_info) ? 1 : 0;
  106673. +
  106674. + qh->data_toggle = DWC_OTG_HC_PID_DATA0;
  106675. + qh->maxp = dwc_otg_hcd_get_mps(&urb->pipe_info);
  106676. + DWC_CIRCLEQ_INIT(&qh->qtd_list);
  106677. + DWC_LIST_INIT(&qh->qh_list_entry);
  106678. + qh->channel = NULL;
  106679. +
  106680. + /* FS/LS Enpoint on HS Hub
  106681. + * NOT virtual root hub */
  106682. + dev_speed = hcd->fops->speed(hcd, urb->priv);
  106683. +
  106684. + hcd->fops->hub_info(hcd, urb->priv, &hub_addr, &hub_port);
  106685. + qh->do_split = 0;
  106686. + if (microframe_schedule)
  106687. + qh->speed = dev_speed;
  106688. +
  106689. + qh->nak_frame = 0xffff;
  106690. +
  106691. + if (((dev_speed == USB_SPEED_LOW) ||
  106692. + (dev_speed == USB_SPEED_FULL)) &&
  106693. + (hub_addr != 0 && hub_addr != 1)) {
  106694. + DWC_DEBUGPL(DBG_HCD,
  106695. + "QH init: EP %d: TT found at hub addr %d, for port %d\n",
  106696. + dwc_otg_hcd_get_ep_num(&urb->pipe_info), hub_addr,
  106697. + hub_port);
  106698. + qh->do_split = 1;
  106699. + qh->skip_count = 0;
  106700. + }
  106701. +
  106702. + if (qh->ep_type == UE_INTERRUPT || qh->ep_type == UE_ISOCHRONOUS) {
  106703. + /* Compute scheduling parameters once and save them. */
  106704. + hprt0_data_t hprt;
  106705. +
  106706. + /** @todo Account for split transfers in the bus time. */
  106707. + int bytecount =
  106708. + dwc_hb_mult(qh->maxp) * dwc_max_packet(qh->maxp);
  106709. +
  106710. + qh->usecs =
  106711. + calc_bus_time((qh->do_split ? USB_SPEED_HIGH : dev_speed),
  106712. + qh->ep_is_in, (qh->ep_type == UE_ISOCHRONOUS),
  106713. + bytecount);
  106714. + /* Start in a slightly future (micro)frame. */
  106715. + qh->sched_frame = dwc_frame_num_inc(hcd->frame_number,
  106716. + SCHEDULE_SLOP);
  106717. + qh->interval = urb->interval;
  106718. +
  106719. +#if 0
  106720. + /* Increase interrupt polling rate for debugging. */
  106721. + if (qh->ep_type == UE_INTERRUPT) {
  106722. + qh->interval = 8;
  106723. + }
  106724. +#endif
  106725. + hprt.d32 = DWC_READ_REG32(hcd->core_if->host_if->hprt0);
  106726. + if ((hprt.b.prtspd == DWC_HPRT0_PRTSPD_HIGH_SPEED) &&
  106727. + ((dev_speed == USB_SPEED_LOW) ||
  106728. + (dev_speed == USB_SPEED_FULL))) {
  106729. + qh->interval *= 8;
  106730. + qh->sched_frame |= 0x7;
  106731. + qh->start_split_frame = qh->sched_frame;
  106732. + }
  106733. +
  106734. + }
  106735. +
  106736. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD QH Initialized\n");
  106737. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - qh = %p\n", qh);
  106738. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - Device Address = %d\n",
  106739. + dwc_otg_hcd_get_dev_addr(&urb->pipe_info));
  106740. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - Endpoint %d, %s\n",
  106741. + dwc_otg_hcd_get_ep_num(&urb->pipe_info),
  106742. + dwc_otg_hcd_is_pipe_in(&urb->pipe_info) ? "IN" : "OUT");
  106743. + switch (dev_speed) {
  106744. + case USB_SPEED_LOW:
  106745. + qh->dev_speed = DWC_OTG_EP_SPEED_LOW;
  106746. + speed = "low";
  106747. + break;
  106748. + case USB_SPEED_FULL:
  106749. + qh->dev_speed = DWC_OTG_EP_SPEED_FULL;
  106750. + speed = "full";
  106751. + break;
  106752. + case USB_SPEED_HIGH:
  106753. + qh->dev_speed = DWC_OTG_EP_SPEED_HIGH;
  106754. + speed = "high";
  106755. + break;
  106756. + default:
  106757. + speed = "?";
  106758. + break;
  106759. + }
  106760. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - Speed = %s\n", speed);
  106761. +
  106762. + switch (qh->ep_type) {
  106763. + case UE_ISOCHRONOUS:
  106764. + type = "isochronous";
  106765. + break;
  106766. + case UE_INTERRUPT:
  106767. + type = "interrupt";
  106768. + break;
  106769. + case UE_CONTROL:
  106770. + type = "control";
  106771. + break;
  106772. + case UE_BULK:
  106773. + type = "bulk";
  106774. + break;
  106775. + default:
  106776. + type = "?";
  106777. + break;
  106778. + }
  106779. +
  106780. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - Type = %s\n", type);
  106781. +
  106782. +#ifdef DEBUG
  106783. + if (qh->ep_type == UE_INTERRUPT) {
  106784. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - usecs = %d\n",
  106785. + qh->usecs);
  106786. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - interval = %d\n",
  106787. + qh->interval);
  106788. + }
  106789. +#endif
  106790. +
  106791. +}
  106792. +
  106793. +/**
  106794. + * This function allocates and initializes a QH.
  106795. + *
  106796. + * @param hcd The HCD state structure for the DWC OTG controller.
  106797. + * @param urb Holds the information about the device/endpoint that we need
  106798. + * to initialize the QH.
  106799. + * @param atomic_alloc Flag to do atomic allocation if needed
  106800. + *
  106801. + * @return Returns pointer to the newly allocated QH, or NULL on error. */
  106802. +dwc_otg_qh_t *dwc_otg_hcd_qh_create(dwc_otg_hcd_t * hcd,
  106803. + dwc_otg_hcd_urb_t * urb, int atomic_alloc)
  106804. +{
  106805. + dwc_otg_qh_t *qh;
  106806. +
  106807. + /* Allocate memory */
  106808. + /** @todo add memflags argument */
  106809. + qh = dwc_otg_hcd_qh_alloc(atomic_alloc);
  106810. + if (qh == NULL) {
  106811. + DWC_ERROR("qh allocation failed");
  106812. + return NULL;
  106813. + }
  106814. +
  106815. + qh_init(hcd, qh, urb);
  106816. +
  106817. + if (hcd->core_if->dma_desc_enable
  106818. + && (dwc_otg_hcd_qh_init_ddma(hcd, qh) < 0)) {
  106819. + dwc_otg_hcd_qh_free(hcd, qh);
  106820. + return NULL;
  106821. + }
  106822. +
  106823. + return qh;
  106824. +}
  106825. +
  106826. +/* microframe_schedule=0 start */
  106827. +
  106828. +/**
  106829. + * Checks that a channel is available for a periodic transfer.
  106830. + *
  106831. + * @return 0 if successful, negative error code otherise.
  106832. + */
  106833. +static int periodic_channel_available(dwc_otg_hcd_t * hcd)
  106834. +{
  106835. + /*
  106836. + * Currently assuming that there is a dedicated host channnel for each
  106837. + * periodic transaction plus at least one host channel for
  106838. + * non-periodic transactions.
  106839. + */
  106840. + int status;
  106841. + int num_channels;
  106842. +
  106843. + num_channels = hcd->core_if->core_params->host_channels;
  106844. + if ((hcd->periodic_channels + hcd->non_periodic_channels < num_channels)
  106845. + && (hcd->periodic_channels < num_channels - 1)) {
  106846. + status = 0;
  106847. + } else {
  106848. + DWC_INFO("%s: Total channels: %d, Periodic: %d, Non-periodic: %d\n",
  106849. + __func__, num_channels, hcd->periodic_channels, hcd->non_periodic_channels); //NOTICE
  106850. + status = -DWC_E_NO_SPACE;
  106851. + }
  106852. +
  106853. + return status;
  106854. +}
  106855. +
  106856. +/**
  106857. + * Checks that there is sufficient bandwidth for the specified QH in the
  106858. + * periodic schedule. For simplicity, this calculation assumes that all the
  106859. + * transfers in the periodic schedule may occur in the same (micro)frame.
  106860. + *
  106861. + * @param hcd The HCD state structure for the DWC OTG controller.
  106862. + * @param qh QH containing periodic bandwidth required.
  106863. + *
  106864. + * @return 0 if successful, negative error code otherwise.
  106865. + */
  106866. +static int check_periodic_bandwidth(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  106867. +{
  106868. + int status;
  106869. + int16_t max_claimed_usecs;
  106870. +
  106871. + status = 0;
  106872. +
  106873. + if ((qh->dev_speed == DWC_OTG_EP_SPEED_HIGH) || qh->do_split) {
  106874. + /*
  106875. + * High speed mode.
  106876. + * Max periodic usecs is 80% x 125 usec = 100 usec.
  106877. + */
  106878. +
  106879. + max_claimed_usecs = 100 - qh->usecs;
  106880. + } else {
  106881. + /*
  106882. + * Full speed mode.
  106883. + * Max periodic usecs is 90% x 1000 usec = 900 usec.
  106884. + */
  106885. + max_claimed_usecs = 900 - qh->usecs;
  106886. + }
  106887. +
  106888. + if (hcd->periodic_usecs > max_claimed_usecs) {
  106889. + DWC_INFO("%s: already claimed usecs %d, required usecs %d\n", __func__, hcd->periodic_usecs, qh->usecs); //NOTICE
  106890. + status = -DWC_E_NO_SPACE;
  106891. + }
  106892. +
  106893. + return status;
  106894. +}
  106895. +
  106896. +/* microframe_schedule=0 end */
  106897. +
  106898. +/**
  106899. + * Microframe scheduler
  106900. + * track the total use in hcd->frame_usecs
  106901. + * keep each qh use in qh->frame_usecs
  106902. + * when surrendering the qh then donate the time back
  106903. + */
  106904. +const unsigned short max_uframe_usecs[]={ 100, 100, 100, 100, 100, 100, 30, 0 };
  106905. +
  106906. +/*
  106907. + * called from dwc_otg_hcd.c:dwc_otg_hcd_init
  106908. + */
  106909. +int init_hcd_usecs(dwc_otg_hcd_t *_hcd)
  106910. +{
  106911. + int i;
  106912. + for (i=0; i<8; i++) {
  106913. + _hcd->frame_usecs[i] = max_uframe_usecs[i];
  106914. + }
  106915. + return 0;
  106916. +}
  106917. +
  106918. +static int find_single_uframe(dwc_otg_hcd_t * _hcd, dwc_otg_qh_t * _qh)
  106919. +{
  106920. + int i;
  106921. + unsigned short utime;
  106922. + int t_left;
  106923. + int ret;
  106924. + int done;
  106925. +
  106926. + ret = -1;
  106927. + utime = _qh->usecs;
  106928. + t_left = utime;
  106929. + i = 0;
  106930. + done = 0;
  106931. + while (done == 0) {
  106932. + /* At the start _hcd->frame_usecs[i] = max_uframe_usecs[i]; */
  106933. + if (utime <= _hcd->frame_usecs[i]) {
  106934. + _hcd->frame_usecs[i] -= utime;
  106935. + _qh->frame_usecs[i] += utime;
  106936. + t_left -= utime;
  106937. + ret = i;
  106938. + done = 1;
  106939. + return ret;
  106940. + } else {
  106941. + i++;
  106942. + if (i == 8) {
  106943. + done = 1;
  106944. + ret = -1;
  106945. + }
  106946. + }
  106947. + }
  106948. + return ret;
  106949. + }
  106950. +
  106951. +/*
  106952. + * use this for FS apps that can span multiple uframes
  106953. + */
  106954. +static int find_multi_uframe(dwc_otg_hcd_t * _hcd, dwc_otg_qh_t * _qh)
  106955. +{
  106956. + int i;
  106957. + int j;
  106958. + unsigned short utime;
  106959. + int t_left;
  106960. + int ret;
  106961. + int done;
  106962. + unsigned short xtime;
  106963. +
  106964. + ret = -1;
  106965. + utime = _qh->usecs;
  106966. + t_left = utime;
  106967. + i = 0;
  106968. + done = 0;
  106969. +loop:
  106970. + while (done == 0) {
  106971. + if(_hcd->frame_usecs[i] <= 0) {
  106972. + i++;
  106973. + if (i == 8) {
  106974. + done = 1;
  106975. + ret = -1;
  106976. + }
  106977. + goto loop;
  106978. + }
  106979. +
  106980. + /*
  106981. + * we need n consecutive slots
  106982. + * so use j as a start slot j plus j+1 must be enough time (for now)
  106983. + */
  106984. + xtime= _hcd->frame_usecs[i];
  106985. + for (j = i+1 ; j < 8 ; j++ ) {
  106986. + /*
  106987. + * if we add this frame remaining time to xtime we may
  106988. + * be OK, if not we need to test j for a complete frame
  106989. + */
  106990. + if ((xtime+_hcd->frame_usecs[j]) < utime) {
  106991. + if (_hcd->frame_usecs[j] < max_uframe_usecs[j]) {
  106992. + j = 8;
  106993. + ret = -1;
  106994. + continue;
  106995. + }
  106996. + }
  106997. + if (xtime >= utime) {
  106998. + ret = i;
  106999. + j = 8; /* stop loop with a good value ret */
  107000. + continue;
  107001. + }
  107002. + /* add the frame time to x time */
  107003. + xtime += _hcd->frame_usecs[j];
  107004. + /* we must have a fully available next frame or break */
  107005. + if ((xtime < utime)
  107006. + && (_hcd->frame_usecs[j] == max_uframe_usecs[j])) {
  107007. + ret = -1;
  107008. + j = 8; /* stop loop with a bad value ret */
  107009. + continue;
  107010. + }
  107011. + }
  107012. + if (ret >= 0) {
  107013. + t_left = utime;
  107014. + for (j = i; (t_left>0) && (j < 8); j++ ) {
  107015. + t_left -= _hcd->frame_usecs[j];
  107016. + if ( t_left <= 0 ) {
  107017. + _qh->frame_usecs[j] += _hcd->frame_usecs[j] + t_left;
  107018. + _hcd->frame_usecs[j]= -t_left;
  107019. + ret = i;
  107020. + done = 1;
  107021. + } else {
  107022. + _qh->frame_usecs[j] += _hcd->frame_usecs[j];
  107023. + _hcd->frame_usecs[j] = 0;
  107024. + }
  107025. + }
  107026. + } else {
  107027. + i++;
  107028. + if (i == 8) {
  107029. + done = 1;
  107030. + ret = -1;
  107031. + }
  107032. + }
  107033. + }
  107034. + return ret;
  107035. +}
  107036. +
  107037. +static int find_uframe(dwc_otg_hcd_t * _hcd, dwc_otg_qh_t * _qh)
  107038. +{
  107039. + int ret;
  107040. + ret = -1;
  107041. +
  107042. + if (_qh->speed == USB_SPEED_HIGH) {
  107043. + /* if this is a hs transaction we need a full frame */
  107044. + ret = find_single_uframe(_hcd, _qh);
  107045. + } else {
  107046. + /* if this is a fs transaction we may need a sequence of frames */
  107047. + ret = find_multi_uframe(_hcd, _qh);
  107048. + }
  107049. + return ret;
  107050. +}
  107051. +
  107052. +/**
  107053. + * Checks that the max transfer size allowed in a host channel is large enough
  107054. + * to handle the maximum data transfer in a single (micro)frame for a periodic
  107055. + * transfer.
  107056. + *
  107057. + * @param hcd The HCD state structure for the DWC OTG controller.
  107058. + * @param qh QH for a periodic endpoint.
  107059. + *
  107060. + * @return 0 if successful, negative error code otherwise.
  107061. + */
  107062. +static int check_max_xfer_size(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  107063. +{
  107064. + int status;
  107065. + uint32_t max_xfer_size;
  107066. + uint32_t max_channel_xfer_size;
  107067. +
  107068. + status = 0;
  107069. +
  107070. + max_xfer_size = dwc_max_packet(qh->maxp) * dwc_hb_mult(qh->maxp);
  107071. + max_channel_xfer_size = hcd->core_if->core_params->max_transfer_size;
  107072. +
  107073. + if (max_xfer_size > max_channel_xfer_size) {
  107074. + DWC_INFO("%s: Periodic xfer length %d > " "max xfer length for channel %d\n",
  107075. + __func__, max_xfer_size, max_channel_xfer_size); //NOTICE
  107076. + status = -DWC_E_NO_SPACE;
  107077. + }
  107078. +
  107079. + return status;
  107080. +}
  107081. +
  107082. +
  107083. +
  107084. +/**
  107085. + * Schedules an interrupt or isochronous transfer in the periodic schedule.
  107086. + *
  107087. + * @param hcd The HCD state structure for the DWC OTG controller.
  107088. + * @param qh QH for the periodic transfer. The QH should already contain the
  107089. + * scheduling information.
  107090. + *
  107091. + * @return 0 if successful, negative error code otherwise.
  107092. + */
  107093. +static int schedule_periodic(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  107094. +{
  107095. + int status = 0;
  107096. +
  107097. + if (microframe_schedule) {
  107098. + int frame;
  107099. + status = find_uframe(hcd, qh);
  107100. + frame = -1;
  107101. + if (status == 0) {
  107102. + frame = 7;
  107103. + } else {
  107104. + if (status > 0 )
  107105. + frame = status-1;
  107106. + }
  107107. +
  107108. + /* Set the new frame up */
  107109. + if (frame > -1) {
  107110. + qh->sched_frame &= ~0x7;
  107111. + qh->sched_frame |= (frame & 7);
  107112. + }
  107113. +
  107114. + if (status != -1)
  107115. + status = 0;
  107116. + } else {
  107117. + status = periodic_channel_available(hcd);
  107118. + if (status) {
  107119. + DWC_INFO("%s: No host channel available for periodic " "transfer.\n", __func__); //NOTICE
  107120. + return status;
  107121. + }
  107122. +
  107123. + status = check_periodic_bandwidth(hcd, qh);
  107124. + }
  107125. + if (status) {
  107126. + DWC_INFO("%s: Insufficient periodic bandwidth for "
  107127. + "periodic transfer.\n", __func__);
  107128. + return status;
  107129. + }
  107130. + status = check_max_xfer_size(hcd, qh);
  107131. + if (status) {
  107132. + DWC_INFO("%s: Channel max transfer size too small "
  107133. + "for periodic transfer.\n", __func__);
  107134. + return status;
  107135. + }
  107136. +
  107137. + if (hcd->core_if->dma_desc_enable) {
  107138. + /* Don't rely on SOF and start in ready schedule */
  107139. + DWC_LIST_INSERT_TAIL(&hcd->periodic_sched_ready, &qh->qh_list_entry);
  107140. + }
  107141. + else {
  107142. + if(fiq_enable && (DWC_LIST_EMPTY(&hcd->periodic_sched_inactive) || dwc_frame_num_le(qh->sched_frame, hcd->fiq_state->next_sched_frame)))
  107143. + {
  107144. + hcd->fiq_state->next_sched_frame = qh->sched_frame;
  107145. +
  107146. + }
  107147. + /* Always start in the inactive schedule. */
  107148. + DWC_LIST_INSERT_TAIL(&hcd->periodic_sched_inactive, &qh->qh_list_entry);
  107149. + }
  107150. +
  107151. + if (!microframe_schedule) {
  107152. + /* Reserve the periodic channel. */
  107153. + hcd->periodic_channels++;
  107154. + }
  107155. +
  107156. + /* Update claimed usecs per (micro)frame. */
  107157. + hcd->periodic_usecs += qh->usecs;
  107158. +
  107159. + return status;
  107160. +}
  107161. +
  107162. +
  107163. +/**
  107164. + * This function adds a QH to either the non periodic or periodic schedule if
  107165. + * it is not already in the schedule. If the QH is already in the schedule, no
  107166. + * action is taken.
  107167. + *
  107168. + * @return 0 if successful, negative error code otherwise.
  107169. + */
  107170. +int dwc_otg_hcd_qh_add(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  107171. +{
  107172. + int status = 0;
  107173. + gintmsk_data_t intr_mask = {.d32 = 0 };
  107174. +
  107175. + if (!DWC_LIST_EMPTY(&qh->qh_list_entry)) {
  107176. + /* QH already in a schedule. */
  107177. + return status;
  107178. + }
  107179. +
  107180. + /* Add the new QH to the appropriate schedule */
  107181. + if (dwc_qh_is_non_per(qh)) {
  107182. + /* Always start in the inactive schedule. */
  107183. + DWC_LIST_INSERT_TAIL(&hcd->non_periodic_sched_inactive,
  107184. + &qh->qh_list_entry);
  107185. + //hcd->fiq_state->kick_np_queues = 1;
  107186. + } else {
  107187. + status = schedule_periodic(hcd, qh);
  107188. + if ( !hcd->periodic_qh_count ) {
  107189. + intr_mask.b.sofintr = 1;
  107190. + if (fiq_enable) {
  107191. + local_fiq_disable();
  107192. + fiq_fsm_spin_lock(&hcd->fiq_state->lock);
  107193. + DWC_MODIFY_REG32(&hcd->core_if->core_global_regs->gintmsk, intr_mask.d32, intr_mask.d32);
  107194. + fiq_fsm_spin_unlock(&hcd->fiq_state->lock);
  107195. + local_fiq_enable();
  107196. + } else {
  107197. + DWC_MODIFY_REG32(&hcd->core_if->core_global_regs->gintmsk, intr_mask.d32, intr_mask.d32);
  107198. + }
  107199. + }
  107200. + hcd->periodic_qh_count++;
  107201. + }
  107202. +
  107203. + return status;
  107204. +}
  107205. +
  107206. +/**
  107207. + * Removes an interrupt or isochronous transfer from the periodic schedule.
  107208. + *
  107209. + * @param hcd The HCD state structure for the DWC OTG controller.
  107210. + * @param qh QH for the periodic transfer.
  107211. + */
  107212. +static void deschedule_periodic(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  107213. +{
  107214. + int i;
  107215. + DWC_LIST_REMOVE_INIT(&qh->qh_list_entry);
  107216. +
  107217. + /* Update claimed usecs per (micro)frame. */
  107218. + hcd->periodic_usecs -= qh->usecs;
  107219. +
  107220. + if (!microframe_schedule) {
  107221. + /* Release the periodic channel reservation. */
  107222. + hcd->periodic_channels--;
  107223. + } else {
  107224. + for (i = 0; i < 8; i++) {
  107225. + hcd->frame_usecs[i] += qh->frame_usecs[i];
  107226. + qh->frame_usecs[i] = 0;
  107227. + }
  107228. + }
  107229. +}
  107230. +
  107231. +/**
  107232. + * Removes a QH from either the non-periodic or periodic schedule. Memory is
  107233. + * not freed.
  107234. + *
  107235. + * @param hcd The HCD state structure.
  107236. + * @param qh QH to remove from schedule. */
  107237. +void dwc_otg_hcd_qh_remove(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  107238. +{
  107239. + gintmsk_data_t intr_mask = {.d32 = 0 };
  107240. +
  107241. + if (DWC_LIST_EMPTY(&qh->qh_list_entry)) {
  107242. + /* QH is not in a schedule. */
  107243. + return;
  107244. + }
  107245. +
  107246. + if (dwc_qh_is_non_per(qh)) {
  107247. + if (hcd->non_periodic_qh_ptr == &qh->qh_list_entry) {
  107248. + hcd->non_periodic_qh_ptr =
  107249. + hcd->non_periodic_qh_ptr->next;
  107250. + }
  107251. + DWC_LIST_REMOVE_INIT(&qh->qh_list_entry);
  107252. + //if (!DWC_LIST_EMPTY(&hcd->non_periodic_sched_inactive))
  107253. + // hcd->fiq_state->kick_np_queues = 1;
  107254. + } else {
  107255. + deschedule_periodic(hcd, qh);
  107256. + hcd->periodic_qh_count--;
  107257. + if( !hcd->periodic_qh_count && !fiq_fsm_enable ) {
  107258. + intr_mask.b.sofintr = 1;
  107259. + if (fiq_enable) {
  107260. + local_fiq_disable();
  107261. + fiq_fsm_spin_lock(&hcd->fiq_state->lock);
  107262. + DWC_MODIFY_REG32(&hcd->core_if->core_global_regs->gintmsk, intr_mask.d32, 0);
  107263. + fiq_fsm_spin_unlock(&hcd->fiq_state->lock);
  107264. + local_fiq_enable();
  107265. + } else {
  107266. + DWC_MODIFY_REG32(&hcd->core_if->core_global_regs->gintmsk, intr_mask.d32, 0);
  107267. + }
  107268. + }
  107269. + }
  107270. +}
  107271. +
  107272. +/**
  107273. + * Deactivates a QH. For non-periodic QHs, removes the QH from the active
  107274. + * non-periodic schedule. The QH is added to the inactive non-periodic
  107275. + * schedule if any QTDs are still attached to the QH.
  107276. + *
  107277. + * For periodic QHs, the QH is removed from the periodic queued schedule. If
  107278. + * there are any QTDs still attached to the QH, the QH is added to either the
  107279. + * periodic inactive schedule or the periodic ready schedule and its next
  107280. + * scheduled frame is calculated. The QH is placed in the ready schedule if
  107281. + * the scheduled frame has been reached already. Otherwise it's placed in the
  107282. + * inactive schedule. If there are no QTDs attached to the QH, the QH is
  107283. + * completely removed from the periodic schedule.
  107284. + */
  107285. +void dwc_otg_hcd_qh_deactivate(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh,
  107286. + int sched_next_periodic_split)
  107287. +{
  107288. + if (dwc_qh_is_non_per(qh)) {
  107289. + dwc_otg_hcd_qh_remove(hcd, qh);
  107290. + if (!DWC_CIRCLEQ_EMPTY(&qh->qtd_list)) {
  107291. + /* Add back to inactive non-periodic schedule. */
  107292. + dwc_otg_hcd_qh_add(hcd, qh);
  107293. + //hcd->fiq_state->kick_np_queues = 1;
  107294. + }
  107295. + } else {
  107296. + uint16_t frame_number = dwc_otg_hcd_get_frame_number(hcd);
  107297. +
  107298. + if (qh->do_split) {
  107299. + /* Schedule the next continuing periodic split transfer */
  107300. + if (sched_next_periodic_split) {
  107301. +
  107302. + qh->sched_frame = frame_number;
  107303. +
  107304. + if (dwc_frame_num_le(frame_number,
  107305. + dwc_frame_num_inc
  107306. + (qh->start_split_frame,
  107307. + 1))) {
  107308. + /*
  107309. + * Allow one frame to elapse after start
  107310. + * split microframe before scheduling
  107311. + * complete split, but DONT if we are
  107312. + * doing the next start split in the
  107313. + * same frame for an ISOC out.
  107314. + */
  107315. + if ((qh->ep_type != UE_ISOCHRONOUS) ||
  107316. + (qh->ep_is_in != 0)) {
  107317. + qh->sched_frame =
  107318. + dwc_frame_num_inc(qh->sched_frame, 1);
  107319. + }
  107320. + }
  107321. + } else {
  107322. + qh->sched_frame =
  107323. + dwc_frame_num_inc(qh->start_split_frame,
  107324. + qh->interval);
  107325. + if (dwc_frame_num_le
  107326. + (qh->sched_frame, frame_number)) {
  107327. + qh->sched_frame = frame_number;
  107328. + }
  107329. + qh->sched_frame |= 0x7;
  107330. + qh->start_split_frame = qh->sched_frame;
  107331. + }
  107332. + } else {
  107333. + qh->sched_frame =
  107334. + dwc_frame_num_inc(qh->sched_frame, qh->interval);
  107335. + if (dwc_frame_num_le(qh->sched_frame, frame_number)) {
  107336. + qh->sched_frame = frame_number;
  107337. + }
  107338. + }
  107339. +
  107340. + if (DWC_CIRCLEQ_EMPTY(&qh->qtd_list)) {
  107341. + dwc_otg_hcd_qh_remove(hcd, qh);
  107342. + } else {
  107343. + /*
  107344. + * Remove from periodic_sched_queued and move to
  107345. + * appropriate queue.
  107346. + */
  107347. + if ((microframe_schedule && dwc_frame_num_le(qh->sched_frame, frame_number)) ||
  107348. + (!microframe_schedule && qh->sched_frame == frame_number)) {
  107349. + DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_ready,
  107350. + &qh->qh_list_entry);
  107351. + } else {
  107352. + if(fiq_enable && !dwc_frame_num_le(hcd->fiq_state->next_sched_frame, qh->sched_frame))
  107353. + {
  107354. + hcd->fiq_state->next_sched_frame = qh->sched_frame;
  107355. + }
  107356. +
  107357. + DWC_LIST_MOVE_HEAD
  107358. + (&hcd->periodic_sched_inactive,
  107359. + &qh->qh_list_entry);
  107360. + }
  107361. + }
  107362. + }
  107363. +}
  107364. +
  107365. +/**
  107366. + * This function allocates and initializes a QTD.
  107367. + *
  107368. + * @param urb The URB to create a QTD from. Each URB-QTD pair will end up
  107369. + * pointing to each other so each pair should have a unique correlation.
  107370. + * @param atomic_alloc Flag to do atomic alloc if needed
  107371. + *
  107372. + * @return Returns pointer to the newly allocated QTD, or NULL on error. */
  107373. +dwc_otg_qtd_t *dwc_otg_hcd_qtd_create(dwc_otg_hcd_urb_t * urb, int atomic_alloc)
  107374. +{
  107375. + dwc_otg_qtd_t *qtd;
  107376. +
  107377. + qtd = dwc_otg_hcd_qtd_alloc(atomic_alloc);
  107378. + if (qtd == NULL) {
  107379. + return NULL;
  107380. + }
  107381. +
  107382. + dwc_otg_hcd_qtd_init(qtd, urb);
  107383. + return qtd;
  107384. +}
  107385. +
  107386. +/**
  107387. + * Initializes a QTD structure.
  107388. + *
  107389. + * @param qtd The QTD to initialize.
  107390. + * @param urb The URB to use for initialization. */
  107391. +void dwc_otg_hcd_qtd_init(dwc_otg_qtd_t * qtd, dwc_otg_hcd_urb_t * urb)
  107392. +{
  107393. + dwc_memset(qtd, 0, sizeof(dwc_otg_qtd_t));
  107394. + qtd->urb = urb;
  107395. + if (dwc_otg_hcd_get_pipe_type(&urb->pipe_info) == UE_CONTROL) {
  107396. + /*
  107397. + * The only time the QTD data toggle is used is on the data
  107398. + * phase of control transfers. This phase always starts with
  107399. + * DATA1.
  107400. + */
  107401. + qtd->data_toggle = DWC_OTG_HC_PID_DATA1;
  107402. + qtd->control_phase = DWC_OTG_CONTROL_SETUP;
  107403. + }
  107404. +
  107405. + /* start split */
  107406. + qtd->complete_split = 0;
  107407. + qtd->isoc_split_pos = DWC_HCSPLIT_XACTPOS_ALL;
  107408. + qtd->isoc_split_offset = 0;
  107409. + qtd->in_process = 0;
  107410. +
  107411. + /* Store the qtd ptr in the urb to reference what QTD. */
  107412. + urb->qtd = qtd;
  107413. + return;
  107414. +}
  107415. +
  107416. +/**
  107417. + * This function adds a QTD to the QTD-list of a QH. It will find the correct
  107418. + * QH to place the QTD into. If it does not find a QH, then it will create a
  107419. + * new QH. If the QH to which the QTD is added is not currently scheduled, it
  107420. + * is placed into the proper schedule based on its EP type.
  107421. + * HCD lock must be held and interrupts must be disabled on entry
  107422. + *
  107423. + * @param[in] qtd The QTD to add
  107424. + * @param[in] hcd The DWC HCD structure
  107425. + * @param[out] qh out parameter to return queue head
  107426. + * @param atomic_alloc Flag to do atomic alloc if needed
  107427. + *
  107428. + * @return 0 if successful, negative error code otherwise.
  107429. + */
  107430. +int dwc_otg_hcd_qtd_add(dwc_otg_qtd_t * qtd,
  107431. + dwc_otg_hcd_t * hcd, dwc_otg_qh_t ** qh, int atomic_alloc)
  107432. +{
  107433. + int retval = 0;
  107434. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  107435. +
  107436. + /*
  107437. + * Get the QH which holds the QTD-list to insert to. Create QH if it
  107438. + * doesn't exist.
  107439. + */
  107440. + if (*qh == NULL) {
  107441. + *qh = dwc_otg_hcd_qh_create(hcd, urb, atomic_alloc);
  107442. + if (*qh == NULL) {
  107443. + retval = -DWC_E_NO_MEMORY;
  107444. + goto done;
  107445. + } else {
  107446. + if (fiq_enable)
  107447. + hcd->fiq_state->kick_np_queues = 1;
  107448. + }
  107449. + }
  107450. + retval = dwc_otg_hcd_qh_add(hcd, *qh);
  107451. + if (retval == 0) {
  107452. + DWC_CIRCLEQ_INSERT_TAIL(&((*qh)->qtd_list), qtd,
  107453. + qtd_list_entry);
  107454. + qtd->qh = *qh;
  107455. + }
  107456. +done:
  107457. +
  107458. + return retval;
  107459. +}
  107460. +
  107461. +#endif /* DWC_DEVICE_ONLY */
  107462. diff -Nur linux-3.18.8/drivers/usb/host/dwc_otg/dwc_otg_os_dep.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_os_dep.h
  107463. --- linux-3.18.8/drivers/usb/host/dwc_otg/dwc_otg_os_dep.h 1970-01-01 01:00:00.000000000 +0100
  107464. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_os_dep.h 2015-03-05 14:40:16.561715806 +0100
  107465. @@ -0,0 +1,188 @@
  107466. +#ifndef _DWC_OS_DEP_H_
  107467. +#define _DWC_OS_DEP_H_
  107468. +
  107469. +/**
  107470. + * @file
  107471. + *
  107472. + * This file contains OS dependent structures.
  107473. + *
  107474. + */
  107475. +
  107476. +#include <linux/kernel.h>
  107477. +#include <linux/module.h>
  107478. +#include <linux/moduleparam.h>
  107479. +#include <linux/init.h>
  107480. +#include <linux/device.h>
  107481. +#include <linux/errno.h>
  107482. +#include <linux/types.h>
  107483. +#include <linux/slab.h>
  107484. +#include <linux/list.h>
  107485. +#include <linux/interrupt.h>
  107486. +#include <linux/ctype.h>
  107487. +#include <linux/string.h>
  107488. +#include <linux/dma-mapping.h>
  107489. +#include <linux/jiffies.h>
  107490. +#include <linux/delay.h>
  107491. +#include <linux/timer.h>
  107492. +#include <linux/workqueue.h>
  107493. +#include <linux/stat.h>
  107494. +#include <linux/pci.h>
  107495. +
  107496. +#include <linux/version.h>
  107497. +
  107498. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
  107499. +# include <linux/irq.h>
  107500. +#endif
  107501. +
  107502. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21)
  107503. +# include <linux/usb/ch9.h>
  107504. +#else
  107505. +# include <linux/usb_ch9.h>
  107506. +#endif
  107507. +
  107508. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
  107509. +# include <linux/usb/gadget.h>
  107510. +#else
  107511. +# include <linux/usb_gadget.h>
  107512. +#endif
  107513. +
  107514. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
  107515. +# include <asm/irq.h>
  107516. +#endif
  107517. +
  107518. +#ifdef PCI_INTERFACE
  107519. +# include <asm/io.h>
  107520. +#endif
  107521. +
  107522. +#ifdef LM_INTERFACE
  107523. +# include <asm/unaligned.h>
  107524. +# include <asm/sizes.h>
  107525. +# include <asm/param.h>
  107526. +# include <asm/io.h>
  107527. +# if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30))
  107528. +# include <asm/arch/hardware.h>
  107529. +# include <asm/arch/lm.h>
  107530. +# include <asm/arch/irqs.h>
  107531. +# include <asm/arch/regs-irq.h>
  107532. +# else
  107533. +/* in 2.6.31, at least, we seem to have lost the generic LM infrastructure -
  107534. + here we assume that the machine architecture provides definitions
  107535. + in its own header
  107536. +*/
  107537. +# include <mach/lm.h>
  107538. +# include <mach/hardware.h>
  107539. +# endif
  107540. +#endif
  107541. +
  107542. +#ifdef PLATFORM_INTERFACE
  107543. +#include <linux/platform_device.h>
  107544. +#include <asm/mach/map.h>
  107545. +#endif
  107546. +
  107547. +/** The OS page size */
  107548. +#define DWC_OS_PAGE_SIZE PAGE_SIZE
  107549. +
  107550. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,14)
  107551. +typedef int gfp_t;
  107552. +#endif
  107553. +
  107554. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18)
  107555. +# define IRQF_SHARED SA_SHIRQ
  107556. +#endif
  107557. +
  107558. +typedef struct os_dependent {
  107559. + /** Base address returned from ioremap() */
  107560. + void *base;
  107561. +
  107562. + /** Register offset for Diagnostic API */
  107563. + uint32_t reg_offset;
  107564. +
  107565. + /** Base address for MPHI peripheral */
  107566. + void *mphi_base;
  107567. +
  107568. +#ifdef LM_INTERFACE
  107569. + struct lm_device *lmdev;
  107570. +#elif defined(PCI_INTERFACE)
  107571. + struct pci_dev *pcidev;
  107572. +
  107573. + /** Start address of a PCI region */
  107574. + resource_size_t rsrc_start;
  107575. +
  107576. + /** Length address of a PCI region */
  107577. + resource_size_t rsrc_len;
  107578. +#elif defined(PLATFORM_INTERFACE)
  107579. + struct platform_device *platformdev;
  107580. +#endif
  107581. +
  107582. +} os_dependent_t;
  107583. +
  107584. +#ifdef __cplusplus
  107585. +}
  107586. +#endif
  107587. +
  107588. +
  107589. +
  107590. +/* Type for the our device on the chosen bus */
  107591. +#if defined(LM_INTERFACE)
  107592. +typedef struct lm_device dwc_bus_dev_t;
  107593. +#elif defined(PCI_INTERFACE)
  107594. +typedef struct pci_dev dwc_bus_dev_t;
  107595. +#elif defined(PLATFORM_INTERFACE)
  107596. +typedef struct platform_device dwc_bus_dev_t;
  107597. +#endif
  107598. +
  107599. +/* Helper macro to retrieve drvdata from the device on the chosen bus */
  107600. +#if defined(LM_INTERFACE)
  107601. +#define DWC_OTG_BUSDRVDATA(_dev) lm_get_drvdata(_dev)
  107602. +#elif defined(PCI_INTERFACE)
  107603. +#define DWC_OTG_BUSDRVDATA(_dev) pci_get_drvdata(_dev)
  107604. +#elif defined(PLATFORM_INTERFACE)
  107605. +#define DWC_OTG_BUSDRVDATA(_dev) platform_get_drvdata(_dev)
  107606. +#endif
  107607. +
  107608. +/**
  107609. + * Helper macro returning the otg_device structure of a given struct device
  107610. + *
  107611. + * c.f. static dwc_otg_device_t *dwc_otg_drvdev(struct device *_dev)
  107612. + */
  107613. +#ifdef LM_INTERFACE
  107614. +#define DWC_OTG_GETDRVDEV(_var, _dev) do { \
  107615. + struct lm_device *lm_dev = \
  107616. + container_of(_dev, struct lm_device, dev); \
  107617. + _var = lm_get_drvdata(lm_dev); \
  107618. + } while (0)
  107619. +
  107620. +#elif defined(PCI_INTERFACE)
  107621. +#define DWC_OTG_GETDRVDEV(_var, _dev) do { \
  107622. + _var = dev_get_drvdata(_dev); \
  107623. + } while (0)
  107624. +
  107625. +#elif defined(PLATFORM_INTERFACE)
  107626. +#define DWC_OTG_GETDRVDEV(_var, _dev) do { \
  107627. + struct platform_device *platform_dev = \
  107628. + container_of(_dev, struct platform_device, dev); \
  107629. + _var = platform_get_drvdata(platform_dev); \
  107630. + } while (0)
  107631. +#endif
  107632. +
  107633. +
  107634. +/**
  107635. + * Helper macro returning the struct dev of the given struct os_dependent
  107636. + *
  107637. + * c.f. static struct device *dwc_otg_getdev(struct os_dependent *osdep)
  107638. + */
  107639. +#ifdef LM_INTERFACE
  107640. +#define DWC_OTG_OS_GETDEV(_osdep) \
  107641. + ((_osdep).lmdev == NULL? NULL: &(_osdep).lmdev->dev)
  107642. +#elif defined(PCI_INTERFACE)
  107643. +#define DWC_OTG_OS_GETDEV(_osdep) \
  107644. + ((_osdep).pci_dev == NULL? NULL: &(_osdep).pci_dev->dev)
  107645. +#elif defined(PLATFORM_INTERFACE)
  107646. +#define DWC_OTG_OS_GETDEV(_osdep) \
  107647. + ((_osdep).platformdev == NULL? NULL: &(_osdep).platformdev->dev)
  107648. +#endif
  107649. +
  107650. +
  107651. +
  107652. +
  107653. +#endif /* _DWC_OS_DEP_H_ */
  107654. diff -Nur linux-3.18.8/drivers/usb/host/dwc_otg/dwc_otg_pcd.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_pcd.c
  107655. --- linux-3.18.8/drivers/usb/host/dwc_otg/dwc_otg_pcd.c 1970-01-01 01:00:00.000000000 +0100
  107656. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_pcd.c 2015-03-05 14:40:16.561715806 +0100
  107657. @@ -0,0 +1,2712 @@
  107658. +/* ==========================================================================
  107659. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_pcd.c $
  107660. + * $Revision: #101 $
  107661. + * $Date: 2012/08/10 $
  107662. + * $Change: 2047372 $
  107663. + *
  107664. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  107665. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  107666. + * otherwise expressly agreed to in writing between Synopsys and you.
  107667. + *
  107668. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  107669. + * any End User Software License Agreement or Agreement for Licensed Product
  107670. + * with Synopsys or any supplement thereto. You are permitted to use and
  107671. + * redistribute this Software in source and binary forms, with or without
  107672. + * modification, provided that redistributions of source code must retain this
  107673. + * notice. You may not view, use, disclose, copy or distribute this file or
  107674. + * any information contained herein except pursuant to this license grant from
  107675. + * Synopsys. If you do not agree with this notice, including the disclaimer
  107676. + * below, then you are not authorized to use the Software.
  107677. + *
  107678. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  107679. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  107680. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  107681. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  107682. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  107683. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  107684. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  107685. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  107686. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  107687. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  107688. + * DAMAGE.
  107689. + * ========================================================================== */
  107690. +#ifndef DWC_HOST_ONLY
  107691. +
  107692. +/** @file
  107693. + * This file implements PCD Core. All code in this file is portable and doesn't
  107694. + * use any OS specific functions.
  107695. + * PCD Core provides Interface, defined in <code><dwc_otg_pcd_if.h></code>
  107696. + * header file, which can be used to implement OS specific PCD interface.
  107697. + *
  107698. + * An important function of the PCD is managing interrupts generated
  107699. + * by the DWC_otg controller. The implementation of the DWC_otg device
  107700. + * mode interrupt service routines is in dwc_otg_pcd_intr.c.
  107701. + *
  107702. + * @todo Add Device Mode test modes (Test J mode, Test K mode, etc).
  107703. + * @todo Does it work when the request size is greater than DEPTSIZ
  107704. + * transfer size
  107705. + *
  107706. + */
  107707. +
  107708. +#include "dwc_otg_pcd.h"
  107709. +
  107710. +#ifdef DWC_UTE_CFI
  107711. +#include "dwc_otg_cfi.h"
  107712. +
  107713. +extern int init_cfi(cfiobject_t * cfiobj);
  107714. +#endif
  107715. +
  107716. +/**
  107717. + * Choose endpoint from ep arrays using usb_ep structure.
  107718. + */
  107719. +static dwc_otg_pcd_ep_t *get_ep_from_handle(dwc_otg_pcd_t * pcd, void *handle)
  107720. +{
  107721. + int i;
  107722. + if (pcd->ep0.priv == handle) {
  107723. + return &pcd->ep0;
  107724. + }
  107725. + for (i = 0; i < MAX_EPS_CHANNELS - 1; i++) {
  107726. + if (pcd->in_ep[i].priv == handle)
  107727. + return &pcd->in_ep[i];
  107728. + if (pcd->out_ep[i].priv == handle)
  107729. + return &pcd->out_ep[i];
  107730. + }
  107731. +
  107732. + return NULL;
  107733. +}
  107734. +
  107735. +/**
  107736. + * This function completes a request. It call's the request call back.
  107737. + */
  107738. +void dwc_otg_request_done(dwc_otg_pcd_ep_t * ep, dwc_otg_pcd_request_t * req,
  107739. + int32_t status)
  107740. +{
  107741. + unsigned stopped = ep->stopped;
  107742. +
  107743. + DWC_DEBUGPL(DBG_PCDV, "%s(ep %p req %p)\n", __func__, ep, req);
  107744. + DWC_CIRCLEQ_REMOVE_INIT(&ep->queue, req, queue_entry);
  107745. +
  107746. + /* don't modify queue heads during completion callback */
  107747. + ep->stopped = 1;
  107748. + /* spin_unlock/spin_lock now done in fops->complete() */
  107749. + ep->pcd->fops->complete(ep->pcd, ep->priv, req->priv, status,
  107750. + req->actual);
  107751. +
  107752. + if (ep->pcd->request_pending > 0) {
  107753. + --ep->pcd->request_pending;
  107754. + }
  107755. +
  107756. + ep->stopped = stopped;
  107757. + DWC_FREE(req);
  107758. +}
  107759. +
  107760. +/**
  107761. + * This function terminates all the requsts in the EP request queue.
  107762. + */
  107763. +void dwc_otg_request_nuke(dwc_otg_pcd_ep_t * ep)
  107764. +{
  107765. + dwc_otg_pcd_request_t *req;
  107766. +
  107767. + ep->stopped = 1;
  107768. +
  107769. + /* called with irqs blocked?? */
  107770. + while (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  107771. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  107772. + dwc_otg_request_done(ep, req, -DWC_E_SHUTDOWN);
  107773. + }
  107774. +}
  107775. +
  107776. +void dwc_otg_pcd_start(dwc_otg_pcd_t * pcd,
  107777. + const struct dwc_otg_pcd_function_ops *fops)
  107778. +{
  107779. + pcd->fops = fops;
  107780. +}
  107781. +
  107782. +/**
  107783. + * PCD Callback function for initializing the PCD when switching to
  107784. + * device mode.
  107785. + *
  107786. + * @param p void pointer to the <code>dwc_otg_pcd_t</code>
  107787. + */
  107788. +static int32_t dwc_otg_pcd_start_cb(void *p)
  107789. +{
  107790. + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *) p;
  107791. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  107792. +
  107793. + /*
  107794. + * Initialized the Core for Device mode.
  107795. + */
  107796. + if (dwc_otg_is_device_mode(core_if)) {
  107797. + dwc_otg_core_dev_init(core_if);
  107798. + /* Set core_if's lock pointer to the pcd->lock */
  107799. + core_if->lock = pcd->lock;
  107800. + }
  107801. + return 1;
  107802. +}
  107803. +
  107804. +/** CFI-specific buffer allocation function for EP */
  107805. +#ifdef DWC_UTE_CFI
  107806. +uint8_t *cfiw_ep_alloc_buffer(dwc_otg_pcd_t * pcd, void *pep, dwc_dma_t * addr,
  107807. + size_t buflen, int flags)
  107808. +{
  107809. + dwc_otg_pcd_ep_t *ep;
  107810. + ep = get_ep_from_handle(pcd, pep);
  107811. + if (!ep) {
  107812. + DWC_WARN("bad ep\n");
  107813. + return -DWC_E_INVALID;
  107814. + }
  107815. +
  107816. + return pcd->cfi->ops.ep_alloc_buf(pcd->cfi, pcd, ep, addr, buflen,
  107817. + flags);
  107818. +}
  107819. +#else
  107820. +uint8_t *cfiw_ep_alloc_buffer(dwc_otg_pcd_t * pcd, void *pep, dwc_dma_t * addr,
  107821. + size_t buflen, int flags);
  107822. +#endif
  107823. +
  107824. +/**
  107825. + * PCD Callback function for notifying the PCD when resuming from
  107826. + * suspend.
  107827. + *
  107828. + * @param p void pointer to the <code>dwc_otg_pcd_t</code>
  107829. + */
  107830. +static int32_t dwc_otg_pcd_resume_cb(void *p)
  107831. +{
  107832. + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *) p;
  107833. +
  107834. + if (pcd->fops->resume) {
  107835. + pcd->fops->resume(pcd);
  107836. + }
  107837. +
  107838. + /* Stop the SRP timeout timer. */
  107839. + if ((GET_CORE_IF(pcd)->core_params->phy_type != DWC_PHY_TYPE_PARAM_FS)
  107840. + || (!GET_CORE_IF(pcd)->core_params->i2c_enable)) {
  107841. + if (GET_CORE_IF(pcd)->srp_timer_started) {
  107842. + GET_CORE_IF(pcd)->srp_timer_started = 0;
  107843. + DWC_TIMER_CANCEL(GET_CORE_IF(pcd)->srp_timer);
  107844. + }
  107845. + }
  107846. + return 1;
  107847. +}
  107848. +
  107849. +/**
  107850. + * PCD Callback function for notifying the PCD device is suspended.
  107851. + *
  107852. + * @param p void pointer to the <code>dwc_otg_pcd_t</code>
  107853. + */
  107854. +static int32_t dwc_otg_pcd_suspend_cb(void *p)
  107855. +{
  107856. + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *) p;
  107857. +
  107858. + if (pcd->fops->suspend) {
  107859. + DWC_SPINUNLOCK(pcd->lock);
  107860. + pcd->fops->suspend(pcd);
  107861. + DWC_SPINLOCK(pcd->lock);
  107862. + }
  107863. +
  107864. + return 1;
  107865. +}
  107866. +
  107867. +/**
  107868. + * PCD Callback function for stopping the PCD when switching to Host
  107869. + * mode.
  107870. + *
  107871. + * @param p void pointer to the <code>dwc_otg_pcd_t</code>
  107872. + */
  107873. +static int32_t dwc_otg_pcd_stop_cb(void *p)
  107874. +{
  107875. + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *) p;
  107876. + extern void dwc_otg_pcd_stop(dwc_otg_pcd_t * _pcd);
  107877. +
  107878. + dwc_otg_pcd_stop(pcd);
  107879. + return 1;
  107880. +}
  107881. +
  107882. +/**
  107883. + * PCD Callback structure for handling mode switching.
  107884. + */
  107885. +static dwc_otg_cil_callbacks_t pcd_callbacks = {
  107886. + .start = dwc_otg_pcd_start_cb,
  107887. + .stop = dwc_otg_pcd_stop_cb,
  107888. + .suspend = dwc_otg_pcd_suspend_cb,
  107889. + .resume_wakeup = dwc_otg_pcd_resume_cb,
  107890. + .p = 0, /* Set at registration */
  107891. +};
  107892. +
  107893. +/**
  107894. + * This function allocates a DMA Descriptor chain for the Endpoint
  107895. + * buffer to be used for a transfer to/from the specified endpoint.
  107896. + */
  107897. +dwc_otg_dev_dma_desc_t *dwc_otg_ep_alloc_desc_chain(dwc_dma_t * dma_desc_addr,
  107898. + uint32_t count)
  107899. +{
  107900. + return DWC_DMA_ALLOC_ATOMIC(count * sizeof(dwc_otg_dev_dma_desc_t),
  107901. + dma_desc_addr);
  107902. +}
  107903. +
  107904. +/**
  107905. + * This function frees a DMA Descriptor chain that was allocated by ep_alloc_desc.
  107906. + */
  107907. +void dwc_otg_ep_free_desc_chain(dwc_otg_dev_dma_desc_t * desc_addr,
  107908. + uint32_t dma_desc_addr, uint32_t count)
  107909. +{
  107910. + DWC_DMA_FREE(count * sizeof(dwc_otg_dev_dma_desc_t), desc_addr,
  107911. + dma_desc_addr);
  107912. +}
  107913. +
  107914. +#ifdef DWC_EN_ISOC
  107915. +
  107916. +/**
  107917. + * This function initializes a descriptor chain for Isochronous transfer
  107918. + *
  107919. + * @param core_if Programming view of DWC_otg controller.
  107920. + * @param dwc_ep The EP to start the transfer on.
  107921. + *
  107922. + */
  107923. +void dwc_otg_iso_ep_start_ddma_transfer(dwc_otg_core_if_t * core_if,
  107924. + dwc_ep_t * dwc_ep)
  107925. +{
  107926. +
  107927. + dsts_data_t dsts = {.d32 = 0 };
  107928. + depctl_data_t depctl = {.d32 = 0 };
  107929. + volatile uint32_t *addr;
  107930. + int i, j;
  107931. + uint32_t len;
  107932. +
  107933. + if (dwc_ep->is_in)
  107934. + dwc_ep->desc_cnt = dwc_ep->buf_proc_intrvl / dwc_ep->bInterval;
  107935. + else
  107936. + dwc_ep->desc_cnt =
  107937. + dwc_ep->buf_proc_intrvl * dwc_ep->pkt_per_frm /
  107938. + dwc_ep->bInterval;
  107939. +
  107940. + /** Allocate descriptors for double buffering */
  107941. + dwc_ep->iso_desc_addr =
  107942. + dwc_otg_ep_alloc_desc_chain(&dwc_ep->iso_dma_desc_addr,
  107943. + dwc_ep->desc_cnt * 2);
  107944. + if (dwc_ep->desc_addr) {
  107945. + DWC_WARN("%s, can't allocate DMA descriptor chain\n", __func__);
  107946. + return;
  107947. + }
  107948. +
  107949. + dsts.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  107950. +
  107951. + /** ISO OUT EP */
  107952. + if (dwc_ep->is_in == 0) {
  107953. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  107954. + dwc_otg_dev_dma_desc_t *dma_desc = dwc_ep->iso_desc_addr;
  107955. + dma_addr_t dma_ad;
  107956. + uint32_t data_per_desc;
  107957. + dwc_otg_dev_out_ep_regs_t *out_regs =
  107958. + core_if->dev_if->out_ep_regs[dwc_ep->num];
  107959. + int offset;
  107960. +
  107961. + addr = &core_if->dev_if->out_ep_regs[dwc_ep->num]->doepctl;
  107962. + dma_ad = (dma_addr_t) DWC_READ_REG32(&(out_regs->doepdma));
  107963. +
  107964. + /** Buffer 0 descriptors setup */
  107965. + dma_ad = dwc_ep->dma_addr0;
  107966. +
  107967. + sts.b_iso_out.bs = BS_HOST_READY;
  107968. + sts.b_iso_out.rxsts = 0;
  107969. + sts.b_iso_out.l = 0;
  107970. + sts.b_iso_out.sp = 0;
  107971. + sts.b_iso_out.ioc = 0;
  107972. + sts.b_iso_out.pid = 0;
  107973. + sts.b_iso_out.framenum = 0;
  107974. +
  107975. + offset = 0;
  107976. + for (i = 0; i < dwc_ep->desc_cnt - dwc_ep->pkt_per_frm;
  107977. + i += dwc_ep->pkt_per_frm) {
  107978. +
  107979. + for (j = 0; j < dwc_ep->pkt_per_frm; ++j) {
  107980. + uint32_t len = (j + 1) * dwc_ep->maxpacket;
  107981. + if (len > dwc_ep->data_per_frame)
  107982. + data_per_desc =
  107983. + dwc_ep->data_per_frame -
  107984. + j * dwc_ep->maxpacket;
  107985. + else
  107986. + data_per_desc = dwc_ep->maxpacket;
  107987. + len = data_per_desc % 4;
  107988. + if (len)
  107989. + data_per_desc += 4 - len;
  107990. +
  107991. + sts.b_iso_out.rxbytes = data_per_desc;
  107992. + dma_desc->buf = dma_ad;
  107993. + dma_desc->status.d32 = sts.d32;
  107994. +
  107995. + offset += data_per_desc;
  107996. + dma_desc++;
  107997. + dma_ad += data_per_desc;
  107998. + }
  107999. + }
  108000. +
  108001. + for (j = 0; j < dwc_ep->pkt_per_frm - 1; ++j) {
  108002. + uint32_t len = (j + 1) * dwc_ep->maxpacket;
  108003. + if (len > dwc_ep->data_per_frame)
  108004. + data_per_desc =
  108005. + dwc_ep->data_per_frame -
  108006. + j * dwc_ep->maxpacket;
  108007. + else
  108008. + data_per_desc = dwc_ep->maxpacket;
  108009. + len = data_per_desc % 4;
  108010. + if (len)
  108011. + data_per_desc += 4 - len;
  108012. + sts.b_iso_out.rxbytes = data_per_desc;
  108013. + dma_desc->buf = dma_ad;
  108014. + dma_desc->status.d32 = sts.d32;
  108015. +
  108016. + offset += data_per_desc;
  108017. + dma_desc++;
  108018. + dma_ad += data_per_desc;
  108019. + }
  108020. +
  108021. + sts.b_iso_out.ioc = 1;
  108022. + len = (j + 1) * dwc_ep->maxpacket;
  108023. + if (len > dwc_ep->data_per_frame)
  108024. + data_per_desc =
  108025. + dwc_ep->data_per_frame - j * dwc_ep->maxpacket;
  108026. + else
  108027. + data_per_desc = dwc_ep->maxpacket;
  108028. + len = data_per_desc % 4;
  108029. + if (len)
  108030. + data_per_desc += 4 - len;
  108031. + sts.b_iso_out.rxbytes = data_per_desc;
  108032. +
  108033. + dma_desc->buf = dma_ad;
  108034. + dma_desc->status.d32 = sts.d32;
  108035. + dma_desc++;
  108036. +
  108037. + /** Buffer 1 descriptors setup */
  108038. + sts.b_iso_out.ioc = 0;
  108039. + dma_ad = dwc_ep->dma_addr1;
  108040. +
  108041. + offset = 0;
  108042. + for (i = 0; i < dwc_ep->desc_cnt - dwc_ep->pkt_per_frm;
  108043. + i += dwc_ep->pkt_per_frm) {
  108044. + for (j = 0; j < dwc_ep->pkt_per_frm; ++j) {
  108045. + uint32_t len = (j + 1) * dwc_ep->maxpacket;
  108046. + if (len > dwc_ep->data_per_frame)
  108047. + data_per_desc =
  108048. + dwc_ep->data_per_frame -
  108049. + j * dwc_ep->maxpacket;
  108050. + else
  108051. + data_per_desc = dwc_ep->maxpacket;
  108052. + len = data_per_desc % 4;
  108053. + if (len)
  108054. + data_per_desc += 4 - len;
  108055. +
  108056. + data_per_desc =
  108057. + sts.b_iso_out.rxbytes = data_per_desc;
  108058. + dma_desc->buf = dma_ad;
  108059. + dma_desc->status.d32 = sts.d32;
  108060. +
  108061. + offset += data_per_desc;
  108062. + dma_desc++;
  108063. + dma_ad += data_per_desc;
  108064. + }
  108065. + }
  108066. + for (j = 0; j < dwc_ep->pkt_per_frm - 1; ++j) {
  108067. + data_per_desc =
  108068. + ((j + 1) * dwc_ep->maxpacket >
  108069. + dwc_ep->data_per_frame) ? dwc_ep->data_per_frame -
  108070. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  108071. + data_per_desc +=
  108072. + (data_per_desc % 4) ? (4 - data_per_desc % 4) : 0;
  108073. + sts.b_iso_out.rxbytes = data_per_desc;
  108074. + dma_desc->buf = dma_ad;
  108075. + dma_desc->status.d32 = sts.d32;
  108076. +
  108077. + offset += data_per_desc;
  108078. + dma_desc++;
  108079. + dma_ad += data_per_desc;
  108080. + }
  108081. +
  108082. + sts.b_iso_out.ioc = 1;
  108083. + sts.b_iso_out.l = 1;
  108084. + data_per_desc =
  108085. + ((j + 1) * dwc_ep->maxpacket >
  108086. + dwc_ep->data_per_frame) ? dwc_ep->data_per_frame -
  108087. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  108088. + data_per_desc +=
  108089. + (data_per_desc % 4) ? (4 - data_per_desc % 4) : 0;
  108090. + sts.b_iso_out.rxbytes = data_per_desc;
  108091. +
  108092. + dma_desc->buf = dma_ad;
  108093. + dma_desc->status.d32 = sts.d32;
  108094. +
  108095. + dwc_ep->next_frame = 0;
  108096. +
  108097. + /** Write dma_ad into DOEPDMA register */
  108098. + DWC_WRITE_REG32(&(out_regs->doepdma),
  108099. + (uint32_t) dwc_ep->iso_dma_desc_addr);
  108100. +
  108101. + }
  108102. + /** ISO IN EP */
  108103. + else {
  108104. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  108105. + dwc_otg_dev_dma_desc_t *dma_desc = dwc_ep->iso_desc_addr;
  108106. + dma_addr_t dma_ad;
  108107. + dwc_otg_dev_in_ep_regs_t *in_regs =
  108108. + core_if->dev_if->in_ep_regs[dwc_ep->num];
  108109. + unsigned int frmnumber;
  108110. + fifosize_data_t txfifosize, rxfifosize;
  108111. +
  108112. + txfifosize.d32 =
  108113. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[dwc_ep->num]->
  108114. + dtxfsts);
  108115. + rxfifosize.d32 =
  108116. + DWC_READ_REG32(&core_if->core_global_regs->grxfsiz);
  108117. +
  108118. + addr = &core_if->dev_if->in_ep_regs[dwc_ep->num]->diepctl;
  108119. +
  108120. + dma_ad = dwc_ep->dma_addr0;
  108121. +
  108122. + dsts.d32 =
  108123. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  108124. +
  108125. + sts.b_iso_in.bs = BS_HOST_READY;
  108126. + sts.b_iso_in.txsts = 0;
  108127. + sts.b_iso_in.sp =
  108128. + (dwc_ep->data_per_frame % dwc_ep->maxpacket) ? 1 : 0;
  108129. + sts.b_iso_in.ioc = 0;
  108130. + sts.b_iso_in.pid = dwc_ep->pkt_per_frm;
  108131. +
  108132. + frmnumber = dwc_ep->next_frame;
  108133. +
  108134. + sts.b_iso_in.framenum = frmnumber;
  108135. + sts.b_iso_in.txbytes = dwc_ep->data_per_frame;
  108136. + sts.b_iso_in.l = 0;
  108137. +
  108138. + /** Buffer 0 descriptors setup */
  108139. + for (i = 0; i < dwc_ep->desc_cnt - 1; i++) {
  108140. + dma_desc->buf = dma_ad;
  108141. + dma_desc->status.d32 = sts.d32;
  108142. + dma_desc++;
  108143. +
  108144. + dma_ad += dwc_ep->data_per_frame;
  108145. + sts.b_iso_in.framenum += dwc_ep->bInterval;
  108146. + }
  108147. +
  108148. + sts.b_iso_in.ioc = 1;
  108149. + dma_desc->buf = dma_ad;
  108150. + dma_desc->status.d32 = sts.d32;
  108151. + ++dma_desc;
  108152. +
  108153. + /** Buffer 1 descriptors setup */
  108154. + sts.b_iso_in.ioc = 0;
  108155. + dma_ad = dwc_ep->dma_addr1;
  108156. +
  108157. + for (i = 0; i < dwc_ep->desc_cnt - dwc_ep->pkt_per_frm;
  108158. + i += dwc_ep->pkt_per_frm) {
  108159. + dma_desc->buf = dma_ad;
  108160. + dma_desc->status.d32 = sts.d32;
  108161. + dma_desc++;
  108162. +
  108163. + dma_ad += dwc_ep->data_per_frame;
  108164. + sts.b_iso_in.framenum += dwc_ep->bInterval;
  108165. +
  108166. + sts.b_iso_in.ioc = 0;
  108167. + }
  108168. + sts.b_iso_in.ioc = 1;
  108169. + sts.b_iso_in.l = 1;
  108170. +
  108171. + dma_desc->buf = dma_ad;
  108172. + dma_desc->status.d32 = sts.d32;
  108173. +
  108174. + dwc_ep->next_frame = sts.b_iso_in.framenum + dwc_ep->bInterval;
  108175. +
  108176. + /** Write dma_ad into diepdma register */
  108177. + DWC_WRITE_REG32(&(in_regs->diepdma),
  108178. + (uint32_t) dwc_ep->iso_dma_desc_addr);
  108179. + }
  108180. + /** Enable endpoint, clear nak */
  108181. + depctl.d32 = 0;
  108182. + depctl.b.epena = 1;
  108183. + depctl.b.usbactep = 1;
  108184. + depctl.b.cnak = 1;
  108185. +
  108186. + DWC_MODIFY_REG32(addr, depctl.d32, depctl.d32);
  108187. + depctl.d32 = DWC_READ_REG32(addr);
  108188. +}
  108189. +
  108190. +/**
  108191. + * This function initializes a descriptor chain for Isochronous transfer
  108192. + *
  108193. + * @param core_if Programming view of DWC_otg controller.
  108194. + * @param ep The EP to start the transfer on.
  108195. + *
  108196. + */
  108197. +void dwc_otg_iso_ep_start_buf_transfer(dwc_otg_core_if_t * core_if,
  108198. + dwc_ep_t * ep)
  108199. +{
  108200. + depctl_data_t depctl = {.d32 = 0 };
  108201. + volatile uint32_t *addr;
  108202. +
  108203. + if (ep->is_in) {
  108204. + addr = &core_if->dev_if->in_ep_regs[ep->num]->diepctl;
  108205. + } else {
  108206. + addr = &core_if->dev_if->out_ep_regs[ep->num]->doepctl;
  108207. + }
  108208. +
  108209. + if (core_if->dma_enable == 0 || core_if->dma_desc_enable != 0) {
  108210. + return;
  108211. + } else {
  108212. + deptsiz_data_t deptsiz = {.d32 = 0 };
  108213. +
  108214. + ep->xfer_len =
  108215. + ep->data_per_frame * ep->buf_proc_intrvl / ep->bInterval;
  108216. + ep->pkt_cnt =
  108217. + (ep->xfer_len - 1 + ep->maxpacket) / ep->maxpacket;
  108218. + ep->xfer_count = 0;
  108219. + ep->xfer_buff =
  108220. + (ep->proc_buf_num) ? ep->xfer_buff1 : ep->xfer_buff0;
  108221. + ep->dma_addr =
  108222. + (ep->proc_buf_num) ? ep->dma_addr1 : ep->dma_addr0;
  108223. +
  108224. + if (ep->is_in) {
  108225. + /* Program the transfer size and packet count
  108226. + * as follows: xfersize = N * maxpacket +
  108227. + * short_packet pktcnt = N + (short_packet
  108228. + * exist ? 1 : 0)
  108229. + */
  108230. + deptsiz.b.mc = ep->pkt_per_frm;
  108231. + deptsiz.b.xfersize = ep->xfer_len;
  108232. + deptsiz.b.pktcnt =
  108233. + (ep->xfer_len - 1 + ep->maxpacket) / ep->maxpacket;
  108234. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  108235. + dieptsiz, deptsiz.d32);
  108236. +
  108237. + /* Write the DMA register */
  108238. + DWC_WRITE_REG32(&
  108239. + (core_if->dev_if->in_ep_regs[ep->num]->
  108240. + diepdma), (uint32_t) ep->dma_addr);
  108241. +
  108242. + } else {
  108243. + deptsiz.b.pktcnt =
  108244. + (ep->xfer_len + (ep->maxpacket - 1)) /
  108245. + ep->maxpacket;
  108246. + deptsiz.b.xfersize = deptsiz.b.pktcnt * ep->maxpacket;
  108247. +
  108248. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[ep->num]->
  108249. + doeptsiz, deptsiz.d32);
  108250. +
  108251. + /* Write the DMA register */
  108252. + DWC_WRITE_REG32(&
  108253. + (core_if->dev_if->out_ep_regs[ep->num]->
  108254. + doepdma), (uint32_t) ep->dma_addr);
  108255. +
  108256. + }
  108257. + /** Enable endpoint, clear nak */
  108258. + depctl.d32 = 0;
  108259. + depctl.b.epena = 1;
  108260. + depctl.b.cnak = 1;
  108261. +
  108262. + DWC_MODIFY_REG32(addr, depctl.d32, depctl.d32);
  108263. + }
  108264. +}
  108265. +
  108266. +/**
  108267. + * This function does the setup for a data transfer for an EP and
  108268. + * starts the transfer. For an IN transfer, the packets will be
  108269. + * loaded into the appropriate Tx FIFO in the ISR. For OUT transfers,
  108270. + * the packets are unloaded from the Rx FIFO in the ISR.
  108271. + *
  108272. + * @param core_if Programming view of DWC_otg controller.
  108273. + * @param ep The EP to start the transfer on.
  108274. + */
  108275. +
  108276. +static void dwc_otg_iso_ep_start_transfer(dwc_otg_core_if_t * core_if,
  108277. + dwc_ep_t * ep)
  108278. +{
  108279. + if (core_if->dma_enable) {
  108280. + if (core_if->dma_desc_enable) {
  108281. + if (ep->is_in) {
  108282. + ep->desc_cnt = ep->pkt_cnt / ep->pkt_per_frm;
  108283. + } else {
  108284. + ep->desc_cnt = ep->pkt_cnt;
  108285. + }
  108286. + dwc_otg_iso_ep_start_ddma_transfer(core_if, ep);
  108287. + } else {
  108288. + if (core_if->pti_enh_enable) {
  108289. + dwc_otg_iso_ep_start_buf_transfer(core_if, ep);
  108290. + } else {
  108291. + ep->cur_pkt_addr =
  108292. + (ep->proc_buf_num) ? ep->xfer_buff1 : ep->
  108293. + xfer_buff0;
  108294. + ep->cur_pkt_dma_addr =
  108295. + (ep->proc_buf_num) ? ep->dma_addr1 : ep->
  108296. + dma_addr0;
  108297. + dwc_otg_iso_ep_start_frm_transfer(core_if, ep);
  108298. + }
  108299. + }
  108300. + } else {
  108301. + ep->cur_pkt_addr =
  108302. + (ep->proc_buf_num) ? ep->xfer_buff1 : ep->xfer_buff0;
  108303. + ep->cur_pkt_dma_addr =
  108304. + (ep->proc_buf_num) ? ep->dma_addr1 : ep->dma_addr0;
  108305. + dwc_otg_iso_ep_start_frm_transfer(core_if, ep);
  108306. + }
  108307. +}
  108308. +
  108309. +/**
  108310. + * This function stops transfer for an EP and
  108311. + * resets the ep's variables.
  108312. + *
  108313. + * @param core_if Programming view of DWC_otg controller.
  108314. + * @param ep The EP to start the transfer on.
  108315. + */
  108316. +
  108317. +void dwc_otg_iso_ep_stop_transfer(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  108318. +{
  108319. + depctl_data_t depctl = {.d32 = 0 };
  108320. + volatile uint32_t *addr;
  108321. +
  108322. + if (ep->is_in == 1) {
  108323. + addr = &core_if->dev_if->in_ep_regs[ep->num]->diepctl;
  108324. + } else {
  108325. + addr = &core_if->dev_if->out_ep_regs[ep->num]->doepctl;
  108326. + }
  108327. +
  108328. + /* disable the ep */
  108329. + depctl.d32 = DWC_READ_REG32(addr);
  108330. +
  108331. + depctl.b.epdis = 1;
  108332. + depctl.b.snak = 1;
  108333. +
  108334. + DWC_WRITE_REG32(addr, depctl.d32);
  108335. +
  108336. + if (core_if->dma_desc_enable &&
  108337. + ep->iso_desc_addr && ep->iso_dma_desc_addr) {
  108338. + dwc_otg_ep_free_desc_chain(ep->iso_desc_addr,
  108339. + ep->iso_dma_desc_addr,
  108340. + ep->desc_cnt * 2);
  108341. + }
  108342. +
  108343. + /* reset varibales */
  108344. + ep->dma_addr0 = 0;
  108345. + ep->dma_addr1 = 0;
  108346. + ep->xfer_buff0 = 0;
  108347. + ep->xfer_buff1 = 0;
  108348. + ep->data_per_frame = 0;
  108349. + ep->data_pattern_frame = 0;
  108350. + ep->sync_frame = 0;
  108351. + ep->buf_proc_intrvl = 0;
  108352. + ep->bInterval = 0;
  108353. + ep->proc_buf_num = 0;
  108354. + ep->pkt_per_frm = 0;
  108355. + ep->pkt_per_frm = 0;
  108356. + ep->desc_cnt = 0;
  108357. + ep->iso_desc_addr = 0;
  108358. + ep->iso_dma_desc_addr = 0;
  108359. +}
  108360. +
  108361. +int dwc_otg_pcd_iso_ep_start(dwc_otg_pcd_t * pcd, void *ep_handle,
  108362. + uint8_t * buf0, uint8_t * buf1, dwc_dma_t dma0,
  108363. + dwc_dma_t dma1, int sync_frame, int dp_frame,
  108364. + int data_per_frame, int start_frame,
  108365. + int buf_proc_intrvl, void *req_handle,
  108366. + int atomic_alloc)
  108367. +{
  108368. + dwc_otg_pcd_ep_t *ep;
  108369. + dwc_irqflags_t flags = 0;
  108370. + dwc_ep_t *dwc_ep;
  108371. + int32_t frm_data;
  108372. + dsts_data_t dsts;
  108373. + dwc_otg_core_if_t *core_if;
  108374. +
  108375. + ep = get_ep_from_handle(pcd, ep_handle);
  108376. +
  108377. + if (!ep || !ep->desc || ep->dwc_ep.num == 0) {
  108378. + DWC_WARN("bad ep\n");
  108379. + return -DWC_E_INVALID;
  108380. + }
  108381. +
  108382. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  108383. + core_if = GET_CORE_IF(pcd);
  108384. + dwc_ep = &ep->dwc_ep;
  108385. +
  108386. + if (ep->iso_req_handle) {
  108387. + DWC_WARN("ISO request in progress\n");
  108388. + }
  108389. +
  108390. + dwc_ep->dma_addr0 = dma0;
  108391. + dwc_ep->dma_addr1 = dma1;
  108392. +
  108393. + dwc_ep->xfer_buff0 = buf0;
  108394. + dwc_ep->xfer_buff1 = buf1;
  108395. +
  108396. + dwc_ep->data_per_frame = data_per_frame;
  108397. +
  108398. + /** @todo - pattern data support is to be implemented in the future */
  108399. + dwc_ep->data_pattern_frame = dp_frame;
  108400. + dwc_ep->sync_frame = sync_frame;
  108401. +
  108402. + dwc_ep->buf_proc_intrvl = buf_proc_intrvl;
  108403. +
  108404. + dwc_ep->bInterval = 1 << (ep->desc->bInterval - 1);
  108405. +
  108406. + dwc_ep->proc_buf_num = 0;
  108407. +
  108408. + dwc_ep->pkt_per_frm = 0;
  108409. + frm_data = ep->dwc_ep.data_per_frame;
  108410. + while (frm_data > 0) {
  108411. + dwc_ep->pkt_per_frm++;
  108412. + frm_data -= ep->dwc_ep.maxpacket;
  108413. + }
  108414. +
  108415. + dsts.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  108416. +
  108417. + if (start_frame == -1) {
  108418. + dwc_ep->next_frame = dsts.b.soffn + 1;
  108419. + if (dwc_ep->bInterval != 1) {
  108420. + dwc_ep->next_frame =
  108421. + dwc_ep->next_frame + (dwc_ep->bInterval - 1 -
  108422. + dwc_ep->next_frame %
  108423. + dwc_ep->bInterval);
  108424. + }
  108425. + } else {
  108426. + dwc_ep->next_frame = start_frame;
  108427. + }
  108428. +
  108429. + if (!core_if->pti_enh_enable) {
  108430. + dwc_ep->pkt_cnt =
  108431. + dwc_ep->buf_proc_intrvl * dwc_ep->pkt_per_frm /
  108432. + dwc_ep->bInterval;
  108433. + } else {
  108434. + dwc_ep->pkt_cnt =
  108435. + (dwc_ep->data_per_frame *
  108436. + (dwc_ep->buf_proc_intrvl / dwc_ep->bInterval)
  108437. + - 1 + dwc_ep->maxpacket) / dwc_ep->maxpacket;
  108438. + }
  108439. +
  108440. + if (core_if->dma_desc_enable) {
  108441. + dwc_ep->desc_cnt =
  108442. + dwc_ep->buf_proc_intrvl * dwc_ep->pkt_per_frm /
  108443. + dwc_ep->bInterval;
  108444. + }
  108445. +
  108446. + if (atomic_alloc) {
  108447. + dwc_ep->pkt_info =
  108448. + DWC_ALLOC_ATOMIC(sizeof(iso_pkt_info_t) * dwc_ep->pkt_cnt);
  108449. + } else {
  108450. + dwc_ep->pkt_info =
  108451. + DWC_ALLOC(sizeof(iso_pkt_info_t) * dwc_ep->pkt_cnt);
  108452. + }
  108453. + if (!dwc_ep->pkt_info) {
  108454. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  108455. + return -DWC_E_NO_MEMORY;
  108456. + }
  108457. + if (core_if->pti_enh_enable) {
  108458. + dwc_memset(dwc_ep->pkt_info, 0,
  108459. + sizeof(iso_pkt_info_t) * dwc_ep->pkt_cnt);
  108460. + }
  108461. +
  108462. + dwc_ep->cur_pkt = 0;
  108463. + ep->iso_req_handle = req_handle;
  108464. +
  108465. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  108466. + dwc_otg_iso_ep_start_transfer(core_if, dwc_ep);
  108467. + return 0;
  108468. +}
  108469. +
  108470. +int dwc_otg_pcd_iso_ep_stop(dwc_otg_pcd_t * pcd, void *ep_handle,
  108471. + void *req_handle)
  108472. +{
  108473. + dwc_irqflags_t flags = 0;
  108474. + dwc_otg_pcd_ep_t *ep;
  108475. + dwc_ep_t *dwc_ep;
  108476. +
  108477. + ep = get_ep_from_handle(pcd, ep_handle);
  108478. + if (!ep || !ep->desc || ep->dwc_ep.num == 0) {
  108479. + DWC_WARN("bad ep\n");
  108480. + return -DWC_E_INVALID;
  108481. + }
  108482. + dwc_ep = &ep->dwc_ep;
  108483. +
  108484. + dwc_otg_iso_ep_stop_transfer(GET_CORE_IF(pcd), dwc_ep);
  108485. +
  108486. + DWC_FREE(dwc_ep->pkt_info);
  108487. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  108488. + if (ep->iso_req_handle != req_handle) {
  108489. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  108490. + return -DWC_E_INVALID;
  108491. + }
  108492. +
  108493. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  108494. +
  108495. + ep->iso_req_handle = 0;
  108496. + return 0;
  108497. +}
  108498. +
  108499. +/**
  108500. + * This function is used for perodical data exchnage between PCD and gadget drivers.
  108501. + * for Isochronous EPs
  108502. + *
  108503. + * - Every time a sync period completes this function is called to
  108504. + * perform data exchange between PCD and gadget
  108505. + */
  108506. +void dwc_otg_iso_buffer_done(dwc_otg_pcd_t * pcd, dwc_otg_pcd_ep_t * ep,
  108507. + void *req_handle)
  108508. +{
  108509. + int i;
  108510. + dwc_ep_t *dwc_ep;
  108511. +
  108512. + dwc_ep = &ep->dwc_ep;
  108513. +
  108514. + DWC_SPINUNLOCK(ep->pcd->lock);
  108515. + pcd->fops->isoc_complete(pcd, ep->priv, ep->iso_req_handle,
  108516. + dwc_ep->proc_buf_num ^ 0x1);
  108517. + DWC_SPINLOCK(ep->pcd->lock);
  108518. +
  108519. + for (i = 0; i < dwc_ep->pkt_cnt; ++i) {
  108520. + dwc_ep->pkt_info[i].status = 0;
  108521. + dwc_ep->pkt_info[i].offset = 0;
  108522. + dwc_ep->pkt_info[i].length = 0;
  108523. + }
  108524. +}
  108525. +
  108526. +int dwc_otg_pcd_get_iso_packet_count(dwc_otg_pcd_t * pcd, void *ep_handle,
  108527. + void *iso_req_handle)
  108528. +{
  108529. + dwc_otg_pcd_ep_t *ep;
  108530. + dwc_ep_t *dwc_ep;
  108531. +
  108532. + ep = get_ep_from_handle(pcd, ep_handle);
  108533. + if (!ep->desc || ep->dwc_ep.num == 0) {
  108534. + DWC_WARN("bad ep\n");
  108535. + return -DWC_E_INVALID;
  108536. + }
  108537. + dwc_ep = &ep->dwc_ep;
  108538. +
  108539. + return dwc_ep->pkt_cnt;
  108540. +}
  108541. +
  108542. +void dwc_otg_pcd_get_iso_packet_params(dwc_otg_pcd_t * pcd, void *ep_handle,
  108543. + void *iso_req_handle, int packet,
  108544. + int *status, int *actual, int *offset)
  108545. +{
  108546. + dwc_otg_pcd_ep_t *ep;
  108547. + dwc_ep_t *dwc_ep;
  108548. +
  108549. + ep = get_ep_from_handle(pcd, ep_handle);
  108550. + if (!ep)
  108551. + DWC_WARN("bad ep\n");
  108552. +
  108553. + dwc_ep = &ep->dwc_ep;
  108554. +
  108555. + *status = dwc_ep->pkt_info[packet].status;
  108556. + *actual = dwc_ep->pkt_info[packet].length;
  108557. + *offset = dwc_ep->pkt_info[packet].offset;
  108558. +}
  108559. +
  108560. +#endif /* DWC_EN_ISOC */
  108561. +
  108562. +static void dwc_otg_pcd_init_ep(dwc_otg_pcd_t * pcd, dwc_otg_pcd_ep_t * pcd_ep,
  108563. + uint32_t is_in, uint32_t ep_num)
  108564. +{
  108565. + /* Init EP structure */
  108566. + pcd_ep->desc = 0;
  108567. + pcd_ep->pcd = pcd;
  108568. + pcd_ep->stopped = 1;
  108569. + pcd_ep->queue_sof = 0;
  108570. +
  108571. + /* Init DWC ep structure */
  108572. + pcd_ep->dwc_ep.is_in = is_in;
  108573. + pcd_ep->dwc_ep.num = ep_num;
  108574. + pcd_ep->dwc_ep.active = 0;
  108575. + pcd_ep->dwc_ep.tx_fifo_num = 0;
  108576. + /* Control until ep is actvated */
  108577. + pcd_ep->dwc_ep.type = DWC_OTG_EP_TYPE_CONTROL;
  108578. + pcd_ep->dwc_ep.maxpacket = MAX_PACKET_SIZE;
  108579. + pcd_ep->dwc_ep.dma_addr = 0;
  108580. + pcd_ep->dwc_ep.start_xfer_buff = 0;
  108581. + pcd_ep->dwc_ep.xfer_buff = 0;
  108582. + pcd_ep->dwc_ep.xfer_len = 0;
  108583. + pcd_ep->dwc_ep.xfer_count = 0;
  108584. + pcd_ep->dwc_ep.sent_zlp = 0;
  108585. + pcd_ep->dwc_ep.total_len = 0;
  108586. + pcd_ep->dwc_ep.desc_addr = 0;
  108587. + pcd_ep->dwc_ep.dma_desc_addr = 0;
  108588. + DWC_CIRCLEQ_INIT(&pcd_ep->queue);
  108589. +}
  108590. +
  108591. +/**
  108592. + * Initialize ep's
  108593. + */
  108594. +static void dwc_otg_pcd_reinit(dwc_otg_pcd_t * pcd)
  108595. +{
  108596. + int i;
  108597. + uint32_t hwcfg1;
  108598. + dwc_otg_pcd_ep_t *ep;
  108599. + int in_ep_cntr, out_ep_cntr;
  108600. + uint32_t num_in_eps = (GET_CORE_IF(pcd))->dev_if->num_in_eps;
  108601. + uint32_t num_out_eps = (GET_CORE_IF(pcd))->dev_if->num_out_eps;
  108602. +
  108603. + /**
  108604. + * Initialize the EP0 structure.
  108605. + */
  108606. + ep = &pcd->ep0;
  108607. + dwc_otg_pcd_init_ep(pcd, ep, 0, 0);
  108608. +
  108609. + in_ep_cntr = 0;
  108610. + hwcfg1 = (GET_CORE_IF(pcd))->hwcfg1.d32 >> 3;
  108611. + for (i = 1; in_ep_cntr < num_in_eps; i++) {
  108612. + if ((hwcfg1 & 0x1) == 0) {
  108613. + dwc_otg_pcd_ep_t *ep = &pcd->in_ep[in_ep_cntr];
  108614. + in_ep_cntr++;
  108615. + /**
  108616. + * @todo NGS: Add direction to EP, based on contents
  108617. + * of HWCFG1. Need a copy of HWCFG1 in pcd structure?
  108618. + * sprintf(";r
  108619. + */
  108620. + dwc_otg_pcd_init_ep(pcd, ep, 1 /* IN */ , i);
  108621. +
  108622. + DWC_CIRCLEQ_INIT(&ep->queue);
  108623. + }
  108624. + hwcfg1 >>= 2;
  108625. + }
  108626. +
  108627. + out_ep_cntr = 0;
  108628. + hwcfg1 = (GET_CORE_IF(pcd))->hwcfg1.d32 >> 2;
  108629. + for (i = 1; out_ep_cntr < num_out_eps; i++) {
  108630. + if ((hwcfg1 & 0x1) == 0) {
  108631. + dwc_otg_pcd_ep_t *ep = &pcd->out_ep[out_ep_cntr];
  108632. + out_ep_cntr++;
  108633. + /**
  108634. + * @todo NGS: Add direction to EP, based on contents
  108635. + * of HWCFG1. Need a copy of HWCFG1 in pcd structure?
  108636. + * sprintf(";r
  108637. + */
  108638. + dwc_otg_pcd_init_ep(pcd, ep, 0 /* OUT */ , i);
  108639. + DWC_CIRCLEQ_INIT(&ep->queue);
  108640. + }
  108641. + hwcfg1 >>= 2;
  108642. + }
  108643. +
  108644. + pcd->ep0state = EP0_DISCONNECT;
  108645. + pcd->ep0.dwc_ep.maxpacket = MAX_EP0_SIZE;
  108646. + pcd->ep0.dwc_ep.type = DWC_OTG_EP_TYPE_CONTROL;
  108647. +}
  108648. +
  108649. +/**
  108650. + * This function is called when the SRP timer expires. The SRP should
  108651. + * complete within 6 seconds.
  108652. + */
  108653. +static void srp_timeout(void *ptr)
  108654. +{
  108655. + gotgctl_data_t gotgctl;
  108656. + dwc_otg_core_if_t *core_if = (dwc_otg_core_if_t *) ptr;
  108657. + volatile uint32_t *addr = &core_if->core_global_regs->gotgctl;
  108658. +
  108659. + gotgctl.d32 = DWC_READ_REG32(addr);
  108660. +
  108661. + core_if->srp_timer_started = 0;
  108662. +
  108663. + if (core_if->adp_enable) {
  108664. + if (gotgctl.b.bsesvld == 0) {
  108665. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  108666. + DWC_PRINTF("SRP Timeout BSESSVLD = 0\n");
  108667. + /* Power off the core */
  108668. + if (core_if->power_down == 2) {
  108669. + gpwrdn.b.pwrdnswtch = 1;
  108670. + DWC_MODIFY_REG32(&core_if->
  108671. + core_global_regs->gpwrdn,
  108672. + gpwrdn.d32, 0);
  108673. + }
  108674. +
  108675. + gpwrdn.d32 = 0;
  108676. + gpwrdn.b.pmuintsel = 1;
  108677. + gpwrdn.b.pmuactv = 1;
  108678. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0,
  108679. + gpwrdn.d32);
  108680. + dwc_otg_adp_probe_start(core_if);
  108681. + } else {
  108682. + DWC_PRINTF("SRP Timeout BSESSVLD = 1\n");
  108683. + core_if->op_state = B_PERIPHERAL;
  108684. + dwc_otg_core_init(core_if);
  108685. + dwc_otg_enable_global_interrupts(core_if);
  108686. + cil_pcd_start(core_if);
  108687. + }
  108688. + }
  108689. +
  108690. + if ((core_if->core_params->phy_type == DWC_PHY_TYPE_PARAM_FS) &&
  108691. + (core_if->core_params->i2c_enable)) {
  108692. + DWC_PRINTF("SRP Timeout\n");
  108693. +
  108694. + if ((core_if->srp_success) && (gotgctl.b.bsesvld)) {
  108695. + if (core_if->pcd_cb && core_if->pcd_cb->resume_wakeup) {
  108696. + core_if->pcd_cb->resume_wakeup(core_if->pcd_cb->p);
  108697. + }
  108698. +
  108699. + /* Clear Session Request */
  108700. + gotgctl.d32 = 0;
  108701. + gotgctl.b.sesreq = 1;
  108702. + DWC_MODIFY_REG32(&core_if->core_global_regs->gotgctl,
  108703. + gotgctl.d32, 0);
  108704. +
  108705. + core_if->srp_success = 0;
  108706. + } else {
  108707. + __DWC_ERROR("Device not connected/responding\n");
  108708. + gotgctl.b.sesreq = 0;
  108709. + DWC_WRITE_REG32(addr, gotgctl.d32);
  108710. + }
  108711. + } else if (gotgctl.b.sesreq) {
  108712. + DWC_PRINTF("SRP Timeout\n");
  108713. +
  108714. + __DWC_ERROR("Device not connected/responding\n");
  108715. + gotgctl.b.sesreq = 0;
  108716. + DWC_WRITE_REG32(addr, gotgctl.d32);
  108717. + } else {
  108718. + DWC_PRINTF(" SRP GOTGCTL=%0x\n", gotgctl.d32);
  108719. + }
  108720. +}
  108721. +
  108722. +/**
  108723. + * Tasklet
  108724. + *
  108725. + */
  108726. +extern void start_next_request(dwc_otg_pcd_ep_t * ep);
  108727. +
  108728. +static void start_xfer_tasklet_func(void *data)
  108729. +{
  108730. + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *) data;
  108731. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  108732. +
  108733. + int i;
  108734. + depctl_data_t diepctl;
  108735. +
  108736. + DWC_DEBUGPL(DBG_PCDV, "Start xfer tasklet\n");
  108737. +
  108738. + diepctl.d32 = DWC_READ_REG32(&core_if->dev_if->in_ep_regs[0]->diepctl);
  108739. +
  108740. + if (pcd->ep0.queue_sof) {
  108741. + pcd->ep0.queue_sof = 0;
  108742. + start_next_request(&pcd->ep0);
  108743. + // break;
  108744. + }
  108745. +
  108746. + for (i = 0; i < core_if->dev_if->num_in_eps; i++) {
  108747. + depctl_data_t diepctl;
  108748. + diepctl.d32 =
  108749. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[i]->diepctl);
  108750. +
  108751. + if (pcd->in_ep[i].queue_sof) {
  108752. + pcd->in_ep[i].queue_sof = 0;
  108753. + start_next_request(&pcd->in_ep[i]);
  108754. + // break;
  108755. + }
  108756. + }
  108757. +
  108758. + return;
  108759. +}
  108760. +
  108761. +/**
  108762. + * This function initialized the PCD portion of the driver.
  108763. + *
  108764. + */
  108765. +dwc_otg_pcd_t *dwc_otg_pcd_init(dwc_otg_core_if_t * core_if)
  108766. +{
  108767. + dwc_otg_pcd_t *pcd = NULL;
  108768. + dwc_otg_dev_if_t *dev_if;
  108769. + int i;
  108770. +
  108771. + /*
  108772. + * Allocate PCD structure
  108773. + */
  108774. + pcd = DWC_ALLOC(sizeof(dwc_otg_pcd_t));
  108775. +
  108776. + if (pcd == NULL) {
  108777. + return NULL;
  108778. + }
  108779. +
  108780. +#if (defined(DWC_LINUX) && defined(CONFIG_DEBUG_SPINLOCK))
  108781. + DWC_SPINLOCK_ALLOC_LINUX_DEBUG(pcd->lock);
  108782. +#else
  108783. + pcd->lock = DWC_SPINLOCK_ALLOC();
  108784. +#endif
  108785. + DWC_DEBUGPL(DBG_HCDV, "Init of PCD %p given core_if %p\n",
  108786. + pcd, core_if);//GRAYG
  108787. + if (!pcd->lock) {
  108788. + DWC_ERROR("Could not allocate lock for pcd");
  108789. + DWC_FREE(pcd);
  108790. + return NULL;
  108791. + }
  108792. + /* Set core_if's lock pointer to hcd->lock */
  108793. + core_if->lock = pcd->lock;
  108794. + pcd->core_if = core_if;
  108795. +
  108796. + dev_if = core_if->dev_if;
  108797. + dev_if->isoc_ep = NULL;
  108798. +
  108799. + if (core_if->hwcfg4.b.ded_fifo_en) {
  108800. + DWC_PRINTF("Dedicated Tx FIFOs mode\n");
  108801. + } else {
  108802. + DWC_PRINTF("Shared Tx FIFO mode\n");
  108803. + }
  108804. +
  108805. + /*
  108806. + * Initialized the Core for Device mode here if there is nod ADP support.
  108807. + * Otherwise it will be done later in dwc_otg_adp_start routine.
  108808. + */
  108809. + if (dwc_otg_is_device_mode(core_if) /*&& !core_if->adp_enable*/) {
  108810. + dwc_otg_core_dev_init(core_if);
  108811. + }
  108812. +
  108813. + /*
  108814. + * Register the PCD Callbacks.
  108815. + */
  108816. + dwc_otg_cil_register_pcd_callbacks(core_if, &pcd_callbacks, pcd);
  108817. +
  108818. + /*
  108819. + * Initialize the DMA buffer for SETUP packets
  108820. + */
  108821. + if (GET_CORE_IF(pcd)->dma_enable) {
  108822. + pcd->setup_pkt =
  108823. + DWC_DMA_ALLOC(sizeof(*pcd->setup_pkt) * 5,
  108824. + &pcd->setup_pkt_dma_handle);
  108825. + if (pcd->setup_pkt == NULL) {
  108826. + DWC_FREE(pcd);
  108827. + return NULL;
  108828. + }
  108829. +
  108830. + pcd->status_buf =
  108831. + DWC_DMA_ALLOC(sizeof(uint16_t),
  108832. + &pcd->status_buf_dma_handle);
  108833. + if (pcd->status_buf == NULL) {
  108834. + DWC_DMA_FREE(sizeof(*pcd->setup_pkt) * 5,
  108835. + pcd->setup_pkt, pcd->setup_pkt_dma_handle);
  108836. + DWC_FREE(pcd);
  108837. + return NULL;
  108838. + }
  108839. +
  108840. + if (GET_CORE_IF(pcd)->dma_desc_enable) {
  108841. + dev_if->setup_desc_addr[0] =
  108842. + dwc_otg_ep_alloc_desc_chain
  108843. + (&dev_if->dma_setup_desc_addr[0], 1);
  108844. + dev_if->setup_desc_addr[1] =
  108845. + dwc_otg_ep_alloc_desc_chain
  108846. + (&dev_if->dma_setup_desc_addr[1], 1);
  108847. + dev_if->in_desc_addr =
  108848. + dwc_otg_ep_alloc_desc_chain
  108849. + (&dev_if->dma_in_desc_addr, 1);
  108850. + dev_if->out_desc_addr =
  108851. + dwc_otg_ep_alloc_desc_chain
  108852. + (&dev_if->dma_out_desc_addr, 1);
  108853. + pcd->data_terminated = 0;
  108854. +
  108855. + if (dev_if->setup_desc_addr[0] == 0
  108856. + || dev_if->setup_desc_addr[1] == 0
  108857. + || dev_if->in_desc_addr == 0
  108858. + || dev_if->out_desc_addr == 0) {
  108859. +
  108860. + if (dev_if->out_desc_addr)
  108861. + dwc_otg_ep_free_desc_chain
  108862. + (dev_if->out_desc_addr,
  108863. + dev_if->dma_out_desc_addr, 1);
  108864. + if (dev_if->in_desc_addr)
  108865. + dwc_otg_ep_free_desc_chain
  108866. + (dev_if->in_desc_addr,
  108867. + dev_if->dma_in_desc_addr, 1);
  108868. + if (dev_if->setup_desc_addr[1])
  108869. + dwc_otg_ep_free_desc_chain
  108870. + (dev_if->setup_desc_addr[1],
  108871. + dev_if->dma_setup_desc_addr[1], 1);
  108872. + if (dev_if->setup_desc_addr[0])
  108873. + dwc_otg_ep_free_desc_chain
  108874. + (dev_if->setup_desc_addr[0],
  108875. + dev_if->dma_setup_desc_addr[0], 1);
  108876. +
  108877. + DWC_DMA_FREE(sizeof(*pcd->setup_pkt) * 5,
  108878. + pcd->setup_pkt,
  108879. + pcd->setup_pkt_dma_handle);
  108880. + DWC_DMA_FREE(sizeof(*pcd->status_buf),
  108881. + pcd->status_buf,
  108882. + pcd->status_buf_dma_handle);
  108883. +
  108884. + DWC_FREE(pcd);
  108885. +
  108886. + return NULL;
  108887. + }
  108888. + }
  108889. + } else {
  108890. + pcd->setup_pkt = DWC_ALLOC(sizeof(*pcd->setup_pkt) * 5);
  108891. + if (pcd->setup_pkt == NULL) {
  108892. + DWC_FREE(pcd);
  108893. + return NULL;
  108894. + }
  108895. +
  108896. + pcd->status_buf = DWC_ALLOC(sizeof(uint16_t));
  108897. + if (pcd->status_buf == NULL) {
  108898. + DWC_FREE(pcd->setup_pkt);
  108899. + DWC_FREE(pcd);
  108900. + return NULL;
  108901. + }
  108902. + }
  108903. +
  108904. + dwc_otg_pcd_reinit(pcd);
  108905. +
  108906. + /* Allocate the cfi object for the PCD */
  108907. +#ifdef DWC_UTE_CFI
  108908. + pcd->cfi = DWC_ALLOC(sizeof(cfiobject_t));
  108909. + if (NULL == pcd->cfi)
  108910. + goto fail;
  108911. + if (init_cfi(pcd->cfi)) {
  108912. + CFI_INFO("%s: Failed to init the CFI object\n", __func__);
  108913. + goto fail;
  108914. + }
  108915. +#endif
  108916. +
  108917. + /* Initialize tasklets */
  108918. + pcd->start_xfer_tasklet = DWC_TASK_ALLOC("xfer_tasklet",
  108919. + start_xfer_tasklet_func, pcd);
  108920. + pcd->test_mode_tasklet = DWC_TASK_ALLOC("test_mode_tasklet",
  108921. + do_test_mode, pcd);
  108922. +
  108923. + /* Initialize SRP timer */
  108924. + core_if->srp_timer = DWC_TIMER_ALLOC("SRP TIMER", srp_timeout, core_if);
  108925. +
  108926. + if (core_if->core_params->dev_out_nak) {
  108927. + /**
  108928. + * Initialize xfer timeout timer. Implemented for
  108929. + * 2.93a feature "Device DDMA OUT NAK Enhancement"
  108930. + */
  108931. + for(i = 0; i < MAX_EPS_CHANNELS; i++) {
  108932. + pcd->core_if->ep_xfer_timer[i] =
  108933. + DWC_TIMER_ALLOC("ep timer", ep_xfer_timeout,
  108934. + &pcd->core_if->ep_xfer_info[i]);
  108935. + }
  108936. + }
  108937. +
  108938. + return pcd;
  108939. +#ifdef DWC_UTE_CFI
  108940. +fail:
  108941. +#endif
  108942. + if (pcd->setup_pkt)
  108943. + DWC_FREE(pcd->setup_pkt);
  108944. + if (pcd->status_buf)
  108945. + DWC_FREE(pcd->status_buf);
  108946. +#ifdef DWC_UTE_CFI
  108947. + if (pcd->cfi)
  108948. + DWC_FREE(pcd->cfi);
  108949. +#endif
  108950. + if (pcd)
  108951. + DWC_FREE(pcd);
  108952. + return NULL;
  108953. +
  108954. +}
  108955. +
  108956. +/**
  108957. + * Remove PCD specific data
  108958. + */
  108959. +void dwc_otg_pcd_remove(dwc_otg_pcd_t * pcd)
  108960. +{
  108961. + dwc_otg_dev_if_t *dev_if = GET_CORE_IF(pcd)->dev_if;
  108962. + int i;
  108963. + if (pcd->core_if->core_params->dev_out_nak) {
  108964. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  108965. + DWC_TIMER_CANCEL(pcd->core_if->ep_xfer_timer[i]);
  108966. + pcd->core_if->ep_xfer_info[i].state = 0;
  108967. + }
  108968. + }
  108969. +
  108970. + if (GET_CORE_IF(pcd)->dma_enable) {
  108971. + DWC_DMA_FREE(sizeof(*pcd->setup_pkt) * 5, pcd->setup_pkt,
  108972. + pcd->setup_pkt_dma_handle);
  108973. + DWC_DMA_FREE(sizeof(uint16_t), pcd->status_buf,
  108974. + pcd->status_buf_dma_handle);
  108975. + if (GET_CORE_IF(pcd)->dma_desc_enable) {
  108976. + dwc_otg_ep_free_desc_chain(dev_if->setup_desc_addr[0],
  108977. + dev_if->dma_setup_desc_addr
  108978. + [0], 1);
  108979. + dwc_otg_ep_free_desc_chain(dev_if->setup_desc_addr[1],
  108980. + dev_if->dma_setup_desc_addr
  108981. + [1], 1);
  108982. + dwc_otg_ep_free_desc_chain(dev_if->in_desc_addr,
  108983. + dev_if->dma_in_desc_addr, 1);
  108984. + dwc_otg_ep_free_desc_chain(dev_if->out_desc_addr,
  108985. + dev_if->dma_out_desc_addr,
  108986. + 1);
  108987. + }
  108988. + } else {
  108989. + DWC_FREE(pcd->setup_pkt);
  108990. + DWC_FREE(pcd->status_buf);
  108991. + }
  108992. + DWC_SPINLOCK_FREE(pcd->lock);
  108993. + /* Set core_if's lock pointer to NULL */
  108994. + pcd->core_if->lock = NULL;
  108995. +
  108996. + DWC_TASK_FREE(pcd->start_xfer_tasklet);
  108997. + DWC_TASK_FREE(pcd->test_mode_tasklet);
  108998. + if (pcd->core_if->core_params->dev_out_nak) {
  108999. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  109000. + if (pcd->core_if->ep_xfer_timer[i]) {
  109001. + DWC_TIMER_FREE(pcd->core_if->ep_xfer_timer[i]);
  109002. + }
  109003. + }
  109004. + }
  109005. +
  109006. +/* Release the CFI object's dynamic memory */
  109007. +#ifdef DWC_UTE_CFI
  109008. + if (pcd->cfi->ops.release) {
  109009. + pcd->cfi->ops.release(pcd->cfi);
  109010. + }
  109011. +#endif
  109012. +
  109013. + DWC_FREE(pcd);
  109014. +}
  109015. +
  109016. +/**
  109017. + * Returns whether registered pcd is dual speed or not
  109018. + */
  109019. +uint32_t dwc_otg_pcd_is_dualspeed(dwc_otg_pcd_t * pcd)
  109020. +{
  109021. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  109022. +
  109023. + if ((core_if->core_params->speed == DWC_SPEED_PARAM_FULL) ||
  109024. + ((core_if->hwcfg2.b.hs_phy_type == 2) &&
  109025. + (core_if->hwcfg2.b.fs_phy_type == 1) &&
  109026. + (core_if->core_params->ulpi_fs_ls))) {
  109027. + return 0;
  109028. + }
  109029. +
  109030. + return 1;
  109031. +}
  109032. +
  109033. +/**
  109034. + * Returns whether registered pcd is OTG capable or not
  109035. + */
  109036. +uint32_t dwc_otg_pcd_is_otg(dwc_otg_pcd_t * pcd)
  109037. +{
  109038. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  109039. + gusbcfg_data_t usbcfg = {.d32 = 0 };
  109040. +
  109041. + usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  109042. + if (!usbcfg.b.srpcap || !usbcfg.b.hnpcap) {
  109043. + return 0;
  109044. + }
  109045. +
  109046. + return 1;
  109047. +}
  109048. +
  109049. +/**
  109050. + * This function assigns periodic Tx FIFO to an periodic EP
  109051. + * in shared Tx FIFO mode
  109052. + */
  109053. +static uint32_t assign_tx_fifo(dwc_otg_core_if_t * core_if)
  109054. +{
  109055. + uint32_t TxMsk = 1;
  109056. + int i;
  109057. +
  109058. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; ++i) {
  109059. + if ((TxMsk & core_if->tx_msk) == 0) {
  109060. + core_if->tx_msk |= TxMsk;
  109061. + return i + 1;
  109062. + }
  109063. + TxMsk <<= 1;
  109064. + }
  109065. + return 0;
  109066. +}
  109067. +
  109068. +/**
  109069. + * This function assigns periodic Tx FIFO to an periodic EP
  109070. + * in shared Tx FIFO mode
  109071. + */
  109072. +static uint32_t assign_perio_tx_fifo(dwc_otg_core_if_t * core_if)
  109073. +{
  109074. + uint32_t PerTxMsk = 1;
  109075. + int i;
  109076. + for (i = 0; i < core_if->hwcfg4.b.num_dev_perio_in_ep; ++i) {
  109077. + if ((PerTxMsk & core_if->p_tx_msk) == 0) {
  109078. + core_if->p_tx_msk |= PerTxMsk;
  109079. + return i + 1;
  109080. + }
  109081. + PerTxMsk <<= 1;
  109082. + }
  109083. + return 0;
  109084. +}
  109085. +
  109086. +/**
  109087. + * This function releases periodic Tx FIFO
  109088. + * in shared Tx FIFO mode
  109089. + */
  109090. +static void release_perio_tx_fifo(dwc_otg_core_if_t * core_if,
  109091. + uint32_t fifo_num)
  109092. +{
  109093. + core_if->p_tx_msk =
  109094. + (core_if->p_tx_msk & (1 << (fifo_num - 1))) ^ core_if->p_tx_msk;
  109095. +}
  109096. +
  109097. +/**
  109098. + * This function releases periodic Tx FIFO
  109099. + * in shared Tx FIFO mode
  109100. + */
  109101. +static void release_tx_fifo(dwc_otg_core_if_t * core_if, uint32_t fifo_num)
  109102. +{
  109103. + core_if->tx_msk =
  109104. + (core_if->tx_msk & (1 << (fifo_num - 1))) ^ core_if->tx_msk;
  109105. +}
  109106. +
  109107. +/**
  109108. + * This function is being called from gadget
  109109. + * to enable PCD endpoint.
  109110. + */
  109111. +int dwc_otg_pcd_ep_enable(dwc_otg_pcd_t * pcd,
  109112. + const uint8_t * ep_desc, void *usb_ep)
  109113. +{
  109114. + int num, dir;
  109115. + dwc_otg_pcd_ep_t *ep = NULL;
  109116. + const usb_endpoint_descriptor_t *desc;
  109117. + dwc_irqflags_t flags;
  109118. + fifosize_data_t dptxfsiz = {.d32 = 0 };
  109119. + gdfifocfg_data_t gdfifocfg = {.d32 = 0 };
  109120. + gdfifocfg_data_t gdfifocfgbase = {.d32 = 0 };
  109121. + int retval = 0;
  109122. + int i, epcount;
  109123. +
  109124. + desc = (const usb_endpoint_descriptor_t *)ep_desc;
  109125. +
  109126. + if (!desc) {
  109127. + pcd->ep0.priv = usb_ep;
  109128. + ep = &pcd->ep0;
  109129. + retval = -DWC_E_INVALID;
  109130. + goto out;
  109131. + }
  109132. +
  109133. + num = UE_GET_ADDR(desc->bEndpointAddress);
  109134. + dir = UE_GET_DIR(desc->bEndpointAddress);
  109135. +
  109136. + if (!desc->wMaxPacketSize) {
  109137. + DWC_WARN("bad maxpacketsize\n");
  109138. + retval = -DWC_E_INVALID;
  109139. + goto out;
  109140. + }
  109141. +
  109142. + if (dir == UE_DIR_IN) {
  109143. + epcount = pcd->core_if->dev_if->num_in_eps;
  109144. + for (i = 0; i < epcount; i++) {
  109145. + if (num == pcd->in_ep[i].dwc_ep.num) {
  109146. + ep = &pcd->in_ep[i];
  109147. + break;
  109148. + }
  109149. + }
  109150. + } else {
  109151. + epcount = pcd->core_if->dev_if->num_out_eps;
  109152. + for (i = 0; i < epcount; i++) {
  109153. + if (num == pcd->out_ep[i].dwc_ep.num) {
  109154. + ep = &pcd->out_ep[i];
  109155. + break;
  109156. + }
  109157. + }
  109158. + }
  109159. +
  109160. + if (!ep) {
  109161. + DWC_WARN("bad address\n");
  109162. + retval = -DWC_E_INVALID;
  109163. + goto out;
  109164. + }
  109165. +
  109166. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  109167. +
  109168. + ep->desc = desc;
  109169. + ep->priv = usb_ep;
  109170. +
  109171. + /*
  109172. + * Activate the EP
  109173. + */
  109174. + ep->stopped = 0;
  109175. +
  109176. + ep->dwc_ep.is_in = (dir == UE_DIR_IN);
  109177. + ep->dwc_ep.maxpacket = UGETW(desc->wMaxPacketSize);
  109178. +
  109179. + ep->dwc_ep.type = desc->bmAttributes & UE_XFERTYPE;
  109180. +
  109181. + if (ep->dwc_ep.is_in) {
  109182. + if (!GET_CORE_IF(pcd)->en_multiple_tx_fifo) {
  109183. + ep->dwc_ep.tx_fifo_num = 0;
  109184. +
  109185. + if (ep->dwc_ep.type == UE_ISOCHRONOUS) {
  109186. + /*
  109187. + * if ISOC EP then assign a Periodic Tx FIFO.
  109188. + */
  109189. + ep->dwc_ep.tx_fifo_num =
  109190. + assign_perio_tx_fifo(GET_CORE_IF(pcd));
  109191. + }
  109192. + } else {
  109193. + /*
  109194. + * if Dedicated FIFOs mode is on then assign a Tx FIFO.
  109195. + */
  109196. + ep->dwc_ep.tx_fifo_num =
  109197. + assign_tx_fifo(GET_CORE_IF(pcd));
  109198. + }
  109199. +
  109200. + /* Calculating EP info controller base address */
  109201. + if (ep->dwc_ep.tx_fifo_num
  109202. + && GET_CORE_IF(pcd)->en_multiple_tx_fifo) {
  109203. + gdfifocfg.d32 =
  109204. + DWC_READ_REG32(&GET_CORE_IF(pcd)->
  109205. + core_global_regs->gdfifocfg);
  109206. + gdfifocfgbase.d32 = gdfifocfg.d32 >> 16;
  109207. + dptxfsiz.d32 =
  109208. + (DWC_READ_REG32
  109209. + (&GET_CORE_IF(pcd)->core_global_regs->
  109210. + dtxfsiz[ep->dwc_ep.tx_fifo_num - 1]) >> 16);
  109211. + gdfifocfg.b.epinfobase =
  109212. + gdfifocfgbase.d32 + dptxfsiz.d32;
  109213. + if (GET_CORE_IF(pcd)->snpsid <= OTG_CORE_REV_2_94a) {
  109214. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->
  109215. + core_global_regs->gdfifocfg,
  109216. + gdfifocfg.d32);
  109217. + }
  109218. + }
  109219. + }
  109220. + /* Set initial data PID. */
  109221. + if (ep->dwc_ep.type == UE_BULK) {
  109222. + ep->dwc_ep.data_pid_start = 0;
  109223. + }
  109224. +
  109225. + /* Alloc DMA Descriptors */
  109226. + if (GET_CORE_IF(pcd)->dma_desc_enable) {
  109227. +#ifndef DWC_UTE_PER_IO
  109228. + if (ep->dwc_ep.type != UE_ISOCHRONOUS) {
  109229. +#endif
  109230. + ep->dwc_ep.desc_addr =
  109231. + dwc_otg_ep_alloc_desc_chain(&ep->
  109232. + dwc_ep.dma_desc_addr,
  109233. + MAX_DMA_DESC_CNT);
  109234. + if (!ep->dwc_ep.desc_addr) {
  109235. + DWC_WARN("%s, can't allocate DMA descriptor\n",
  109236. + __func__);
  109237. + retval = -DWC_E_SHUTDOWN;
  109238. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  109239. + goto out;
  109240. + }
  109241. +#ifndef DWC_UTE_PER_IO
  109242. + }
  109243. +#endif
  109244. + }
  109245. +
  109246. + DWC_DEBUGPL(DBG_PCD, "Activate %s: type=%d, mps=%d desc=%p\n",
  109247. + (ep->dwc_ep.is_in ? "IN" : "OUT"),
  109248. + ep->dwc_ep.type, ep->dwc_ep.maxpacket, ep->desc);
  109249. +#ifdef DWC_UTE_PER_IO
  109250. + ep->dwc_ep.xiso_bInterval = 1 << (ep->desc->bInterval - 1);
  109251. +#endif
  109252. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  109253. + ep->dwc_ep.bInterval = 1 << (ep->desc->bInterval - 1);
  109254. + ep->dwc_ep.frame_num = 0xFFFFFFFF;
  109255. + }
  109256. +
  109257. + dwc_otg_ep_activate(GET_CORE_IF(pcd), &ep->dwc_ep);
  109258. +
  109259. +#ifdef DWC_UTE_CFI
  109260. + if (pcd->cfi->ops.ep_enable) {
  109261. + pcd->cfi->ops.ep_enable(pcd->cfi, pcd, ep);
  109262. + }
  109263. +#endif
  109264. +
  109265. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  109266. +
  109267. +out:
  109268. + return retval;
  109269. +}
  109270. +
  109271. +/**
  109272. + * This function is being called from gadget
  109273. + * to disable PCD endpoint.
  109274. + */
  109275. +int dwc_otg_pcd_ep_disable(dwc_otg_pcd_t * pcd, void *ep_handle)
  109276. +{
  109277. + dwc_otg_pcd_ep_t *ep;
  109278. + dwc_irqflags_t flags;
  109279. + dwc_otg_dev_dma_desc_t *desc_addr;
  109280. + dwc_dma_t dma_desc_addr;
  109281. + gdfifocfg_data_t gdfifocfgbase = {.d32 = 0 };
  109282. + gdfifocfg_data_t gdfifocfg = {.d32 = 0 };
  109283. + fifosize_data_t dptxfsiz = {.d32 = 0 };
  109284. +
  109285. + ep = get_ep_from_handle(pcd, ep_handle);
  109286. +
  109287. + if (!ep || !ep->desc) {
  109288. + DWC_DEBUGPL(DBG_PCD, "bad ep address\n");
  109289. + return -DWC_E_INVALID;
  109290. + }
  109291. +
  109292. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  109293. +
  109294. + dwc_otg_request_nuke(ep);
  109295. +
  109296. + dwc_otg_ep_deactivate(GET_CORE_IF(pcd), &ep->dwc_ep);
  109297. + if (pcd->core_if->core_params->dev_out_nak) {
  109298. + DWC_TIMER_CANCEL(pcd->core_if->ep_xfer_timer[ep->dwc_ep.num]);
  109299. + pcd->core_if->ep_xfer_info[ep->dwc_ep.num].state = 0;
  109300. + }
  109301. + ep->desc = NULL;
  109302. + ep->stopped = 1;
  109303. +
  109304. + gdfifocfg.d32 =
  109305. + DWC_READ_REG32(&GET_CORE_IF(pcd)->core_global_regs->gdfifocfg);
  109306. + gdfifocfgbase.d32 = gdfifocfg.d32 >> 16;
  109307. +
  109308. + if (ep->dwc_ep.is_in) {
  109309. + if (GET_CORE_IF(pcd)->en_multiple_tx_fifo) {
  109310. + /* Flush the Tx FIFO */
  109311. + dwc_otg_flush_tx_fifo(GET_CORE_IF(pcd),
  109312. + ep->dwc_ep.tx_fifo_num);
  109313. + }
  109314. + release_perio_tx_fifo(GET_CORE_IF(pcd), ep->dwc_ep.tx_fifo_num);
  109315. + release_tx_fifo(GET_CORE_IF(pcd), ep->dwc_ep.tx_fifo_num);
  109316. + if (GET_CORE_IF(pcd)->en_multiple_tx_fifo) {
  109317. + /* Decreasing EPinfo Base Addr */
  109318. + dptxfsiz.d32 =
  109319. + (DWC_READ_REG32
  109320. + (&GET_CORE_IF(pcd)->
  109321. + core_global_regs->dtxfsiz[ep->dwc_ep.tx_fifo_num-1]) >> 16);
  109322. + gdfifocfg.b.epinfobase = gdfifocfgbase.d32 - dptxfsiz.d32;
  109323. + if (GET_CORE_IF(pcd)->snpsid <= OTG_CORE_REV_2_94a) {
  109324. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gdfifocfg,
  109325. + gdfifocfg.d32);
  109326. + }
  109327. + }
  109328. + }
  109329. +
  109330. + /* Free DMA Descriptors */
  109331. + if (GET_CORE_IF(pcd)->dma_desc_enable) {
  109332. + if (ep->dwc_ep.type != UE_ISOCHRONOUS) {
  109333. + desc_addr = ep->dwc_ep.desc_addr;
  109334. + dma_desc_addr = ep->dwc_ep.dma_desc_addr;
  109335. +
  109336. + /* Cannot call dma_free_coherent() with IRQs disabled */
  109337. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  109338. + dwc_otg_ep_free_desc_chain(desc_addr, dma_desc_addr,
  109339. + MAX_DMA_DESC_CNT);
  109340. +
  109341. + goto out_unlocked;
  109342. + }
  109343. + }
  109344. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  109345. +
  109346. +out_unlocked:
  109347. + DWC_DEBUGPL(DBG_PCD, "%d %s disabled\n", ep->dwc_ep.num,
  109348. + ep->dwc_ep.is_in ? "IN" : "OUT");
  109349. + return 0;
  109350. +
  109351. +}
  109352. +
  109353. +/******************************************************************************/
  109354. +#ifdef DWC_UTE_PER_IO
  109355. +
  109356. +/**
  109357. + * Free the request and its extended parts
  109358. + *
  109359. + */
  109360. +void dwc_pcd_xiso_ereq_free(dwc_otg_pcd_ep_t * ep, dwc_otg_pcd_request_t * req)
  109361. +{
  109362. + DWC_FREE(req->ext_req.per_io_frame_descs);
  109363. + DWC_FREE(req);
  109364. +}
  109365. +
  109366. +/**
  109367. + * Start the next request in the endpoint's queue.
  109368. + *
  109369. + */
  109370. +int dwc_otg_pcd_xiso_start_next_request(dwc_otg_pcd_t * pcd,
  109371. + dwc_otg_pcd_ep_t * ep)
  109372. +{
  109373. + int i;
  109374. + dwc_otg_pcd_request_t *req = NULL;
  109375. + dwc_ep_t *dwcep = NULL;
  109376. + struct dwc_iso_xreq_port *ereq = NULL;
  109377. + struct dwc_iso_pkt_desc_port *ddesc_iso;
  109378. + uint16_t nat;
  109379. + depctl_data_t diepctl;
  109380. +
  109381. + dwcep = &ep->dwc_ep;
  109382. +
  109383. + if (dwcep->xiso_active_xfers > 0) {
  109384. +#if 0 //Disable this to decrease s/w overhead that is crucial for Isoc transfers
  109385. + DWC_WARN("There are currently active transfers for EP%d \
  109386. + (active=%d; queued=%d)", dwcep->num, dwcep->xiso_active_xfers,
  109387. + dwcep->xiso_queued_xfers);
  109388. +#endif
  109389. + return 0;
  109390. + }
  109391. +
  109392. + nat = UGETW(ep->desc->wMaxPacketSize);
  109393. + nat = (nat >> 11) & 0x03;
  109394. +
  109395. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  109396. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  109397. + ereq = &req->ext_req;
  109398. + ep->stopped = 0;
  109399. +
  109400. + /* Get the frame number */
  109401. + dwcep->xiso_frame_num =
  109402. + dwc_otg_get_frame_number(GET_CORE_IF(pcd));
  109403. + DWC_DEBUG("FRM_NUM=%d", dwcep->xiso_frame_num);
  109404. +
  109405. + ddesc_iso = ereq->per_io_frame_descs;
  109406. +
  109407. + if (dwcep->is_in) {
  109408. + /* Setup DMA Descriptor chain for IN Isoc request */
  109409. + for (i = 0; i < ereq->pio_pkt_count; i++) {
  109410. + //if ((i % (nat + 1)) == 0)
  109411. + if ( i > 0 )
  109412. + dwcep->xiso_frame_num =
  109413. + (dwcep->xiso_bInterval +
  109414. + dwcep->xiso_frame_num) & 0x3FFF;
  109415. + dwcep->desc_addr[i].buf =
  109416. + req->dma + ddesc_iso[i].offset;
  109417. + dwcep->desc_addr[i].status.b_iso_in.txbytes =
  109418. + ddesc_iso[i].length;
  109419. + dwcep->desc_addr[i].status.b_iso_in.framenum =
  109420. + dwcep->xiso_frame_num;
  109421. + dwcep->desc_addr[i].status.b_iso_in.bs =
  109422. + BS_HOST_READY;
  109423. + dwcep->desc_addr[i].status.b_iso_in.txsts = 0;
  109424. + dwcep->desc_addr[i].status.b_iso_in.sp =
  109425. + (ddesc_iso[i].length %
  109426. + dwcep->maxpacket) ? 1 : 0;
  109427. + dwcep->desc_addr[i].status.b_iso_in.ioc = 0;
  109428. + dwcep->desc_addr[i].status.b_iso_in.pid = nat + 1;
  109429. + dwcep->desc_addr[i].status.b_iso_in.l = 0;
  109430. +
  109431. + /* Process the last descriptor */
  109432. + if (i == ereq->pio_pkt_count - 1) {
  109433. + dwcep->desc_addr[i].status.b_iso_in.ioc = 1;
  109434. + dwcep->desc_addr[i].status.b_iso_in.l = 1;
  109435. + }
  109436. + }
  109437. +
  109438. + /* Setup and start the transfer for this endpoint */
  109439. + dwcep->xiso_active_xfers++;
  109440. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->dev_if->
  109441. + in_ep_regs[dwcep->num]->diepdma,
  109442. + dwcep->dma_desc_addr);
  109443. + diepctl.d32 = 0;
  109444. + diepctl.b.epena = 1;
  109445. + diepctl.b.cnak = 1;
  109446. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->dev_if->
  109447. + in_ep_regs[dwcep->num]->diepctl, 0,
  109448. + diepctl.d32);
  109449. + } else {
  109450. + /* Setup DMA Descriptor chain for OUT Isoc request */
  109451. + for (i = 0; i < ereq->pio_pkt_count; i++) {
  109452. + //if ((i % (nat + 1)) == 0)
  109453. + dwcep->xiso_frame_num = (dwcep->xiso_bInterval +
  109454. + dwcep->xiso_frame_num) & 0x3FFF;
  109455. + dwcep->desc_addr[i].buf =
  109456. + req->dma + ddesc_iso[i].offset;
  109457. + dwcep->desc_addr[i].status.b_iso_out.rxbytes =
  109458. + ddesc_iso[i].length;
  109459. + dwcep->desc_addr[i].status.b_iso_out.framenum =
  109460. + dwcep->xiso_frame_num;
  109461. + dwcep->desc_addr[i].status.b_iso_out.bs =
  109462. + BS_HOST_READY;
  109463. + dwcep->desc_addr[i].status.b_iso_out.rxsts = 0;
  109464. + dwcep->desc_addr[i].status.b_iso_out.sp =
  109465. + (ddesc_iso[i].length %
  109466. + dwcep->maxpacket) ? 1 : 0;
  109467. + dwcep->desc_addr[i].status.b_iso_out.ioc = 0;
  109468. + dwcep->desc_addr[i].status.b_iso_out.pid = nat + 1;
  109469. + dwcep->desc_addr[i].status.b_iso_out.l = 0;
  109470. +
  109471. + /* Process the last descriptor */
  109472. + if (i == ereq->pio_pkt_count - 1) {
  109473. + dwcep->desc_addr[i].status.b_iso_out.ioc = 1;
  109474. + dwcep->desc_addr[i].status.b_iso_out.l = 1;
  109475. + }
  109476. + }
  109477. +
  109478. + /* Setup and start the transfer for this endpoint */
  109479. + dwcep->xiso_active_xfers++;
  109480. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->
  109481. + dev_if->out_ep_regs[dwcep->num]->
  109482. + doepdma, dwcep->dma_desc_addr);
  109483. + diepctl.d32 = 0;
  109484. + diepctl.b.epena = 1;
  109485. + diepctl.b.cnak = 1;
  109486. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->
  109487. + dev_if->out_ep_regs[dwcep->num]->
  109488. + doepctl, 0, diepctl.d32);
  109489. + }
  109490. +
  109491. + } else {
  109492. + ep->stopped = 1;
  109493. + }
  109494. +
  109495. + return 0;
  109496. +}
  109497. +
  109498. +/**
  109499. + * - Remove the request from the queue
  109500. + */
  109501. +void complete_xiso_ep(dwc_otg_pcd_ep_t * ep)
  109502. +{
  109503. + dwc_otg_pcd_request_t *req = NULL;
  109504. + struct dwc_iso_xreq_port *ereq = NULL;
  109505. + struct dwc_iso_pkt_desc_port *ddesc_iso = NULL;
  109506. + dwc_ep_t *dwcep = NULL;
  109507. + int i;
  109508. +
  109509. + //DWC_DEBUG();
  109510. + dwcep = &ep->dwc_ep;
  109511. +
  109512. + /* Get the first pending request from the queue */
  109513. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  109514. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  109515. + if (!req) {
  109516. + DWC_PRINTF("complete_ep 0x%p, req = NULL!\n", ep);
  109517. + return;
  109518. + }
  109519. + dwcep->xiso_active_xfers--;
  109520. + dwcep->xiso_queued_xfers--;
  109521. + /* Remove this request from the queue */
  109522. + DWC_CIRCLEQ_REMOVE_INIT(&ep->queue, req, queue_entry);
  109523. + } else {
  109524. + DWC_PRINTF("complete_ep 0x%p, ep->queue empty!\n", ep);
  109525. + return;
  109526. + }
  109527. +
  109528. + ep->stopped = 1;
  109529. + ereq = &req->ext_req;
  109530. + ddesc_iso = ereq->per_io_frame_descs;
  109531. +
  109532. + if (dwcep->xiso_active_xfers < 0) {
  109533. + DWC_WARN("EP#%d (xiso_active_xfers=%d)", dwcep->num,
  109534. + dwcep->xiso_active_xfers);
  109535. + }
  109536. +
  109537. + /* Fill the Isoc descs of portable extended req from dma descriptors */
  109538. + for (i = 0; i < ereq->pio_pkt_count; i++) {
  109539. + if (dwcep->is_in) { /* IN endpoints */
  109540. + ddesc_iso[i].actual_length = ddesc_iso[i].length -
  109541. + dwcep->desc_addr[i].status.b_iso_in.txbytes;
  109542. + ddesc_iso[i].status =
  109543. + dwcep->desc_addr[i].status.b_iso_in.txsts;
  109544. + } else { /* OUT endpoints */
  109545. + ddesc_iso[i].actual_length = ddesc_iso[i].length -
  109546. + dwcep->desc_addr[i].status.b_iso_out.rxbytes;
  109547. + ddesc_iso[i].status =
  109548. + dwcep->desc_addr[i].status.b_iso_out.rxsts;
  109549. + }
  109550. + }
  109551. +
  109552. + DWC_SPINUNLOCK(ep->pcd->lock);
  109553. +
  109554. + /* Call the completion function in the non-portable logic */
  109555. + ep->pcd->fops->xisoc_complete(ep->pcd, ep->priv, req->priv, 0,
  109556. + &req->ext_req);
  109557. +
  109558. + DWC_SPINLOCK(ep->pcd->lock);
  109559. +
  109560. + /* Free the request - specific freeing needed for extended request object */
  109561. + dwc_pcd_xiso_ereq_free(ep, req);
  109562. +
  109563. + /* Start the next request */
  109564. + dwc_otg_pcd_xiso_start_next_request(ep->pcd, ep);
  109565. +
  109566. + return;
  109567. +}
  109568. +
  109569. +/**
  109570. + * Create and initialize the Isoc pkt descriptors of the extended request.
  109571. + *
  109572. + */
  109573. +static int dwc_otg_pcd_xiso_create_pkt_descs(dwc_otg_pcd_request_t * req,
  109574. + void *ereq_nonport,
  109575. + int atomic_alloc)
  109576. +{
  109577. + struct dwc_iso_xreq_port *ereq = NULL;
  109578. + struct dwc_iso_xreq_port *req_mapped = NULL;
  109579. + struct dwc_iso_pkt_desc_port *ipds = NULL; /* To be created in this function */
  109580. + uint32_t pkt_count;
  109581. + int i;
  109582. +
  109583. + ereq = &req->ext_req;
  109584. + req_mapped = (struct dwc_iso_xreq_port *)ereq_nonport;
  109585. + pkt_count = req_mapped->pio_pkt_count;
  109586. +
  109587. + /* Create the isoc descs */
  109588. + if (atomic_alloc) {
  109589. + ipds = DWC_ALLOC_ATOMIC(sizeof(*ipds) * pkt_count);
  109590. + } else {
  109591. + ipds = DWC_ALLOC(sizeof(*ipds) * pkt_count);
  109592. + }
  109593. +
  109594. + if (!ipds) {
  109595. + DWC_ERROR("Failed to allocate isoc descriptors");
  109596. + return -DWC_E_NO_MEMORY;
  109597. + }
  109598. +
  109599. + /* Initialize the extended request fields */
  109600. + ereq->per_io_frame_descs = ipds;
  109601. + ereq->error_count = 0;
  109602. + ereq->pio_alloc_pkt_count = pkt_count;
  109603. + ereq->pio_pkt_count = pkt_count;
  109604. + ereq->tr_sub_flags = req_mapped->tr_sub_flags;
  109605. +
  109606. + /* Init the Isoc descriptors */
  109607. + for (i = 0; i < pkt_count; i++) {
  109608. + ipds[i].length = req_mapped->per_io_frame_descs[i].length;
  109609. + ipds[i].offset = req_mapped->per_io_frame_descs[i].offset;
  109610. + ipds[i].status = req_mapped->per_io_frame_descs[i].status; /* 0 */
  109611. + ipds[i].actual_length =
  109612. + req_mapped->per_io_frame_descs[i].actual_length;
  109613. + }
  109614. +
  109615. + return 0;
  109616. +}
  109617. +
  109618. +static void prn_ext_request(struct dwc_iso_xreq_port *ereq)
  109619. +{
  109620. + struct dwc_iso_pkt_desc_port *xfd = NULL;
  109621. + int i;
  109622. +
  109623. + DWC_DEBUG("per_io_frame_descs=%p", ereq->per_io_frame_descs);
  109624. + DWC_DEBUG("tr_sub_flags=%d", ereq->tr_sub_flags);
  109625. + DWC_DEBUG("error_count=%d", ereq->error_count);
  109626. + DWC_DEBUG("pio_alloc_pkt_count=%d", ereq->pio_alloc_pkt_count);
  109627. + DWC_DEBUG("pio_pkt_count=%d", ereq->pio_pkt_count);
  109628. + DWC_DEBUG("res=%d", ereq->res);
  109629. +
  109630. + for (i = 0; i < ereq->pio_pkt_count; i++) {
  109631. + xfd = &ereq->per_io_frame_descs[0];
  109632. + DWC_DEBUG("FD #%d", i);
  109633. +
  109634. + DWC_DEBUG("xfd->actual_length=%d", xfd->actual_length);
  109635. + DWC_DEBUG("xfd->length=%d", xfd->length);
  109636. + DWC_DEBUG("xfd->offset=%d", xfd->offset);
  109637. + DWC_DEBUG("xfd->status=%d", xfd->status);
  109638. + }
  109639. +}
  109640. +
  109641. +/**
  109642. + *
  109643. + */
  109644. +int dwc_otg_pcd_xiso_ep_queue(dwc_otg_pcd_t * pcd, void *ep_handle,
  109645. + uint8_t * buf, dwc_dma_t dma_buf, uint32_t buflen,
  109646. + int zero, void *req_handle, int atomic_alloc,
  109647. + void *ereq_nonport)
  109648. +{
  109649. + dwc_otg_pcd_request_t *req = NULL;
  109650. + dwc_otg_pcd_ep_t *ep;
  109651. + dwc_irqflags_t flags;
  109652. + int res;
  109653. +
  109654. + ep = get_ep_from_handle(pcd, ep_handle);
  109655. + if (!ep) {
  109656. + DWC_WARN("bad ep\n");
  109657. + return -DWC_E_INVALID;
  109658. + }
  109659. +
  109660. + /* We support this extension only for DDMA mode */
  109661. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC)
  109662. + if (!GET_CORE_IF(pcd)->dma_desc_enable)
  109663. + return -DWC_E_INVALID;
  109664. +
  109665. + /* Create a dwc_otg_pcd_request_t object */
  109666. + if (atomic_alloc) {
  109667. + req = DWC_ALLOC_ATOMIC(sizeof(*req));
  109668. + } else {
  109669. + req = DWC_ALLOC(sizeof(*req));
  109670. + }
  109671. +
  109672. + if (!req) {
  109673. + return -DWC_E_NO_MEMORY;
  109674. + }
  109675. +
  109676. + /* Create the Isoc descs for this request which shall be the exact match
  109677. + * of the structure sent to us from the non-portable logic */
  109678. + res =
  109679. + dwc_otg_pcd_xiso_create_pkt_descs(req, ereq_nonport, atomic_alloc);
  109680. + if (res) {
  109681. + DWC_WARN("Failed to init the Isoc descriptors");
  109682. + DWC_FREE(req);
  109683. + return res;
  109684. + }
  109685. +
  109686. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  109687. +
  109688. + DWC_CIRCLEQ_INIT_ENTRY(req, queue_entry);
  109689. + req->buf = buf;
  109690. + req->dma = dma_buf;
  109691. + req->length = buflen;
  109692. + req->sent_zlp = zero;
  109693. + req->priv = req_handle;
  109694. +
  109695. + //DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  109696. + ep->dwc_ep.dma_addr = dma_buf;
  109697. + ep->dwc_ep.start_xfer_buff = buf;
  109698. + ep->dwc_ep.xfer_buff = buf;
  109699. + ep->dwc_ep.xfer_len = 0;
  109700. + ep->dwc_ep.xfer_count = 0;
  109701. + ep->dwc_ep.sent_zlp = 0;
  109702. + ep->dwc_ep.total_len = buflen;
  109703. +
  109704. + /* Add this request to the tail */
  109705. + DWC_CIRCLEQ_INSERT_TAIL(&ep->queue, req, queue_entry);
  109706. + ep->dwc_ep.xiso_queued_xfers++;
  109707. +
  109708. +//DWC_DEBUG("CP_0");
  109709. +//DWC_DEBUG("req->ext_req.tr_sub_flags=%d", req->ext_req.tr_sub_flags);
  109710. +//prn_ext_request((struct dwc_iso_xreq_port *) ereq_nonport);
  109711. +//prn_ext_request(&req->ext_req);
  109712. +
  109713. + //DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  109714. +
  109715. + /* If the req->status == ASAP then check if there is any active transfer
  109716. + * for this endpoint. If no active transfers, then get the first entry
  109717. + * from the queue and start that transfer
  109718. + */
  109719. + if (req->ext_req.tr_sub_flags == DWC_EREQ_TF_ASAP) {
  109720. + res = dwc_otg_pcd_xiso_start_next_request(pcd, ep);
  109721. + if (res) {
  109722. + DWC_WARN("Failed to start the next Isoc transfer");
  109723. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  109724. + DWC_FREE(req);
  109725. + return res;
  109726. + }
  109727. + }
  109728. +
  109729. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  109730. + return 0;
  109731. +}
  109732. +
  109733. +#endif
  109734. +/* END ifdef DWC_UTE_PER_IO ***************************************************/
  109735. +int dwc_otg_pcd_ep_queue(dwc_otg_pcd_t * pcd, void *ep_handle,
  109736. + uint8_t * buf, dwc_dma_t dma_buf, uint32_t buflen,
  109737. + int zero, void *req_handle, int atomic_alloc)
  109738. +{
  109739. + dwc_irqflags_t flags;
  109740. + dwc_otg_pcd_request_t *req;
  109741. + dwc_otg_pcd_ep_t *ep;
  109742. + uint32_t max_transfer;
  109743. +
  109744. + ep = get_ep_from_handle(pcd, ep_handle);
  109745. + if (!ep || (!ep->desc && ep->dwc_ep.num != 0)) {
  109746. + DWC_WARN("bad ep\n");
  109747. + return -DWC_E_INVALID;
  109748. + }
  109749. +
  109750. + if (atomic_alloc) {
  109751. + req = DWC_ALLOC_ATOMIC(sizeof(*req));
  109752. + } else {
  109753. + req = DWC_ALLOC(sizeof(*req));
  109754. + }
  109755. +
  109756. + if (!req) {
  109757. + return -DWC_E_NO_MEMORY;
  109758. + }
  109759. + DWC_CIRCLEQ_INIT_ENTRY(req, queue_entry);
  109760. + if (!GET_CORE_IF(pcd)->core_params->opt) {
  109761. + if (ep->dwc_ep.num != 0) {
  109762. + DWC_ERROR("queue req %p, len %d buf %p\n",
  109763. + req_handle, buflen, buf);
  109764. + }
  109765. + }
  109766. +
  109767. + req->buf = buf;
  109768. + req->dma = dma_buf;
  109769. + req->length = buflen;
  109770. + req->sent_zlp = zero;
  109771. + req->priv = req_handle;
  109772. + req->dw_align_buf = NULL;
  109773. + if ((dma_buf & 0x3) && GET_CORE_IF(pcd)->dma_enable
  109774. + && !GET_CORE_IF(pcd)->dma_desc_enable)
  109775. + req->dw_align_buf = DWC_DMA_ALLOC(buflen,
  109776. + &req->dw_align_buf_dma);
  109777. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  109778. +
  109779. + /*
  109780. + * After adding request to the queue for IN ISOC wait for In Token Received
  109781. + * when TX FIFO is empty interrupt and for OUT ISOC wait for OUT Token
  109782. + * Received when EP is disabled interrupt to obtain starting microframe
  109783. + * (odd/even) start transfer
  109784. + */
  109785. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  109786. + if (req != 0) {
  109787. + depctl_data_t depctl = {.d32 =
  109788. + DWC_READ_REG32(&pcd->core_if->dev_if->
  109789. + in_ep_regs[ep->dwc_ep.num]->
  109790. + diepctl) };
  109791. + ++pcd->request_pending;
  109792. +
  109793. + DWC_CIRCLEQ_INSERT_TAIL(&ep->queue, req, queue_entry);
  109794. + if (ep->dwc_ep.is_in) {
  109795. + depctl.b.cnak = 1;
  109796. + DWC_WRITE_REG32(&pcd->core_if->dev_if->
  109797. + in_ep_regs[ep->dwc_ep.num]->
  109798. + diepctl, depctl.d32);
  109799. + }
  109800. +
  109801. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  109802. + }
  109803. + return 0;
  109804. + }
  109805. +
  109806. + /*
  109807. + * For EP0 IN without premature status, zlp is required?
  109808. + */
  109809. + if (ep->dwc_ep.num == 0 && ep->dwc_ep.is_in) {
  109810. + DWC_DEBUGPL(DBG_PCDV, "%d-OUT ZLP\n", ep->dwc_ep.num);
  109811. + //_req->zero = 1;
  109812. + }
  109813. +
  109814. + /* Start the transfer */
  109815. + if (DWC_CIRCLEQ_EMPTY(&ep->queue) && !ep->stopped) {
  109816. + /* EP0 Transfer? */
  109817. + if (ep->dwc_ep.num == 0) {
  109818. + switch (pcd->ep0state) {
  109819. + case EP0_IN_DATA_PHASE:
  109820. + DWC_DEBUGPL(DBG_PCD,
  109821. + "%s ep0: EP0_IN_DATA_PHASE\n",
  109822. + __func__);
  109823. + break;
  109824. +
  109825. + case EP0_OUT_DATA_PHASE:
  109826. + DWC_DEBUGPL(DBG_PCD,
  109827. + "%s ep0: EP0_OUT_DATA_PHASE\n",
  109828. + __func__);
  109829. + if (pcd->request_config) {
  109830. + /* Complete STATUS PHASE */
  109831. + ep->dwc_ep.is_in = 1;
  109832. + pcd->ep0state = EP0_IN_STATUS_PHASE;
  109833. + }
  109834. + break;
  109835. +
  109836. + case EP0_IN_STATUS_PHASE:
  109837. + DWC_DEBUGPL(DBG_PCD,
  109838. + "%s ep0: EP0_IN_STATUS_PHASE\n",
  109839. + __func__);
  109840. + break;
  109841. +
  109842. + default:
  109843. + DWC_DEBUGPL(DBG_ANY, "ep0: odd state %d\n",
  109844. + pcd->ep0state);
  109845. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  109846. + return -DWC_E_SHUTDOWN;
  109847. + }
  109848. +
  109849. + ep->dwc_ep.dma_addr = dma_buf;
  109850. + ep->dwc_ep.start_xfer_buff = buf;
  109851. + ep->dwc_ep.xfer_buff = buf;
  109852. + ep->dwc_ep.xfer_len = buflen;
  109853. + ep->dwc_ep.xfer_count = 0;
  109854. + ep->dwc_ep.sent_zlp = 0;
  109855. + ep->dwc_ep.total_len = ep->dwc_ep.xfer_len;
  109856. +
  109857. + if (zero) {
  109858. + if ((ep->dwc_ep.xfer_len %
  109859. + ep->dwc_ep.maxpacket == 0)
  109860. + && (ep->dwc_ep.xfer_len != 0)) {
  109861. + ep->dwc_ep.sent_zlp = 1;
  109862. + }
  109863. +
  109864. + }
  109865. +
  109866. + dwc_otg_ep0_start_transfer(GET_CORE_IF(pcd),
  109867. + &ep->dwc_ep);
  109868. + } // non-ep0 endpoints
  109869. + else {
  109870. +#ifdef DWC_UTE_CFI
  109871. + if (ep->dwc_ep.buff_mode != BM_STANDARD) {
  109872. + /* store the request length */
  109873. + ep->dwc_ep.cfi_req_len = buflen;
  109874. + pcd->cfi->ops.build_descriptors(pcd->cfi, pcd,
  109875. + ep, req);
  109876. + } else {
  109877. +#endif
  109878. + max_transfer =
  109879. + GET_CORE_IF(ep->pcd)->core_params->
  109880. + max_transfer_size;
  109881. +
  109882. + /* Setup and start the Transfer */
  109883. + if (req->dw_align_buf){
  109884. + if (ep->dwc_ep.is_in)
  109885. + dwc_memcpy(req->dw_align_buf,
  109886. + buf, buflen);
  109887. + ep->dwc_ep.dma_addr =
  109888. + req->dw_align_buf_dma;
  109889. + ep->dwc_ep.start_xfer_buff =
  109890. + req->dw_align_buf;
  109891. + ep->dwc_ep.xfer_buff =
  109892. + req->dw_align_buf;
  109893. + } else {
  109894. + ep->dwc_ep.dma_addr = dma_buf;
  109895. + ep->dwc_ep.start_xfer_buff = buf;
  109896. + ep->dwc_ep.xfer_buff = buf;
  109897. + }
  109898. + ep->dwc_ep.xfer_len = 0;
  109899. + ep->dwc_ep.xfer_count = 0;
  109900. + ep->dwc_ep.sent_zlp = 0;
  109901. + ep->dwc_ep.total_len = buflen;
  109902. +
  109903. + ep->dwc_ep.maxxfer = max_transfer;
  109904. + if (GET_CORE_IF(pcd)->dma_desc_enable) {
  109905. + uint32_t out_max_xfer =
  109906. + DDMA_MAX_TRANSFER_SIZE -
  109907. + (DDMA_MAX_TRANSFER_SIZE % 4);
  109908. + if (ep->dwc_ep.is_in) {
  109909. + if (ep->dwc_ep.maxxfer >
  109910. + DDMA_MAX_TRANSFER_SIZE) {
  109911. + ep->dwc_ep.maxxfer =
  109912. + DDMA_MAX_TRANSFER_SIZE;
  109913. + }
  109914. + } else {
  109915. + if (ep->dwc_ep.maxxfer >
  109916. + out_max_xfer) {
  109917. + ep->dwc_ep.maxxfer =
  109918. + out_max_xfer;
  109919. + }
  109920. + }
  109921. + }
  109922. + if (ep->dwc_ep.maxxfer < ep->dwc_ep.total_len) {
  109923. + ep->dwc_ep.maxxfer -=
  109924. + (ep->dwc_ep.maxxfer %
  109925. + ep->dwc_ep.maxpacket);
  109926. + }
  109927. +
  109928. + if (zero) {
  109929. + if ((ep->dwc_ep.total_len %
  109930. + ep->dwc_ep.maxpacket == 0)
  109931. + && (ep->dwc_ep.total_len != 0)) {
  109932. + ep->dwc_ep.sent_zlp = 1;
  109933. + }
  109934. + }
  109935. +#ifdef DWC_UTE_CFI
  109936. + }
  109937. +#endif
  109938. + dwc_otg_ep_start_transfer(GET_CORE_IF(pcd),
  109939. + &ep->dwc_ep);
  109940. + }
  109941. + }
  109942. +
  109943. + if (req != 0) {
  109944. + ++pcd->request_pending;
  109945. + DWC_CIRCLEQ_INSERT_TAIL(&ep->queue, req, queue_entry);
  109946. + if (ep->dwc_ep.is_in && ep->stopped
  109947. + && !(GET_CORE_IF(pcd)->dma_enable)) {
  109948. + /** @todo NGS Create a function for this. */
  109949. + diepmsk_data_t diepmsk = {.d32 = 0 };
  109950. + diepmsk.b.intktxfemp = 1;
  109951. + if (GET_CORE_IF(pcd)->multiproc_int_enable) {
  109952. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->
  109953. + dev_if->dev_global_regs->diepeachintmsk
  109954. + [ep->dwc_ep.num], 0,
  109955. + diepmsk.d32);
  109956. + } else {
  109957. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->
  109958. + dev_if->dev_global_regs->
  109959. + diepmsk, 0, diepmsk.d32);
  109960. + }
  109961. +
  109962. + }
  109963. + }
  109964. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  109965. +
  109966. + return 0;
  109967. +}
  109968. +
  109969. +int dwc_otg_pcd_ep_dequeue(dwc_otg_pcd_t * pcd, void *ep_handle,
  109970. + void *req_handle)
  109971. +{
  109972. + dwc_irqflags_t flags;
  109973. + dwc_otg_pcd_request_t *req;
  109974. + dwc_otg_pcd_ep_t *ep;
  109975. +
  109976. + ep = get_ep_from_handle(pcd, ep_handle);
  109977. + if (!ep || (!ep->desc && ep->dwc_ep.num != 0)) {
  109978. + DWC_WARN("bad argument\n");
  109979. + return -DWC_E_INVALID;
  109980. + }
  109981. +
  109982. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  109983. +
  109984. + /* make sure it's actually queued on this endpoint */
  109985. + DWC_CIRCLEQ_FOREACH(req, &ep->queue, queue_entry) {
  109986. + if (req->priv == (void *)req_handle) {
  109987. + break;
  109988. + }
  109989. + }
  109990. +
  109991. + if (req->priv != (void *)req_handle) {
  109992. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  109993. + return -DWC_E_INVALID;
  109994. + }
  109995. +
  109996. + if (!DWC_CIRCLEQ_EMPTY_ENTRY(req, queue_entry)) {
  109997. + dwc_otg_request_done(ep, req, -DWC_E_RESTART);
  109998. + } else {
  109999. + req = NULL;
  110000. + }
  110001. +
  110002. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  110003. +
  110004. + return req ? 0 : -DWC_E_SHUTDOWN;
  110005. +
  110006. +}
  110007. +
  110008. +/**
  110009. + * dwc_otg_pcd_ep_wedge - sets the halt feature and ignores clear requests
  110010. + *
  110011. + * Use this to stall an endpoint and ignore CLEAR_FEATURE(HALT_ENDPOINT)
  110012. + * requests. If the gadget driver clears the halt status, it will
  110013. + * automatically unwedge the endpoint.
  110014. + *
  110015. + * Returns zero on success, else negative DWC error code.
  110016. + */
  110017. +int dwc_otg_pcd_ep_wedge(dwc_otg_pcd_t * pcd, void *ep_handle)
  110018. +{
  110019. + dwc_otg_pcd_ep_t *ep;
  110020. + dwc_irqflags_t flags;
  110021. + int retval = 0;
  110022. +
  110023. + ep = get_ep_from_handle(pcd, ep_handle);
  110024. +
  110025. + if ((!ep->desc && ep != &pcd->ep0) ||
  110026. + (ep->desc && (ep->desc->bmAttributes == UE_ISOCHRONOUS))) {
  110027. + DWC_WARN("%s, bad ep\n", __func__);
  110028. + return -DWC_E_INVALID;
  110029. + }
  110030. +
  110031. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  110032. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  110033. + DWC_WARN("%d %s XFer In process\n", ep->dwc_ep.num,
  110034. + ep->dwc_ep.is_in ? "IN" : "OUT");
  110035. + retval = -DWC_E_AGAIN;
  110036. + } else {
  110037. + /* This code needs to be reviewed */
  110038. + if (ep->dwc_ep.is_in == 1 && GET_CORE_IF(pcd)->dma_desc_enable) {
  110039. + dtxfsts_data_t txstatus;
  110040. + fifosize_data_t txfifosize;
  110041. +
  110042. + txfifosize.d32 =
  110043. + DWC_READ_REG32(&GET_CORE_IF(pcd)->
  110044. + core_global_regs->dtxfsiz[ep->dwc_ep.
  110045. + tx_fifo_num]);
  110046. + txstatus.d32 =
  110047. + DWC_READ_REG32(&GET_CORE_IF(pcd)->
  110048. + dev_if->in_ep_regs[ep->dwc_ep.num]->
  110049. + dtxfsts);
  110050. +
  110051. + if (txstatus.b.txfspcavail < txfifosize.b.depth) {
  110052. + DWC_WARN("%s() Data In Tx Fifo\n", __func__);
  110053. + retval = -DWC_E_AGAIN;
  110054. + } else {
  110055. + if (ep->dwc_ep.num == 0) {
  110056. + pcd->ep0state = EP0_STALL;
  110057. + }
  110058. +
  110059. + ep->stopped = 1;
  110060. + dwc_otg_ep_set_stall(GET_CORE_IF(pcd),
  110061. + &ep->dwc_ep);
  110062. + }
  110063. + } else {
  110064. + if (ep->dwc_ep.num == 0) {
  110065. + pcd->ep0state = EP0_STALL;
  110066. + }
  110067. +
  110068. + ep->stopped = 1;
  110069. + dwc_otg_ep_set_stall(GET_CORE_IF(pcd), &ep->dwc_ep);
  110070. + }
  110071. + }
  110072. +
  110073. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  110074. +
  110075. + return retval;
  110076. +}
  110077. +
  110078. +int dwc_otg_pcd_ep_halt(dwc_otg_pcd_t * pcd, void *ep_handle, int value)
  110079. +{
  110080. + dwc_otg_pcd_ep_t *ep;
  110081. + dwc_irqflags_t flags;
  110082. + int retval = 0;
  110083. +
  110084. + ep = get_ep_from_handle(pcd, ep_handle);
  110085. +
  110086. + if (!ep || (!ep->desc && ep != &pcd->ep0) ||
  110087. + (ep->desc && (ep->desc->bmAttributes == UE_ISOCHRONOUS))) {
  110088. + DWC_WARN("%s, bad ep\n", __func__);
  110089. + return -DWC_E_INVALID;
  110090. + }
  110091. +
  110092. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  110093. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  110094. + DWC_WARN("%d %s XFer In process\n", ep->dwc_ep.num,
  110095. + ep->dwc_ep.is_in ? "IN" : "OUT");
  110096. + retval = -DWC_E_AGAIN;
  110097. + } else if (value == 0) {
  110098. + dwc_otg_ep_clear_stall(GET_CORE_IF(pcd), &ep->dwc_ep);
  110099. + } else if (value == 1) {
  110100. + if (ep->dwc_ep.is_in == 1 && GET_CORE_IF(pcd)->dma_desc_enable) {
  110101. + dtxfsts_data_t txstatus;
  110102. + fifosize_data_t txfifosize;
  110103. +
  110104. + txfifosize.d32 =
  110105. + DWC_READ_REG32(&GET_CORE_IF(pcd)->core_global_regs->
  110106. + dtxfsiz[ep->dwc_ep.tx_fifo_num]);
  110107. + txstatus.d32 =
  110108. + DWC_READ_REG32(&GET_CORE_IF(pcd)->dev_if->
  110109. + in_ep_regs[ep->dwc_ep.num]->dtxfsts);
  110110. +
  110111. + if (txstatus.b.txfspcavail < txfifosize.b.depth) {
  110112. + DWC_WARN("%s() Data In Tx Fifo\n", __func__);
  110113. + retval = -DWC_E_AGAIN;
  110114. + } else {
  110115. + if (ep->dwc_ep.num == 0) {
  110116. + pcd->ep0state = EP0_STALL;
  110117. + }
  110118. +
  110119. + ep->stopped = 1;
  110120. + dwc_otg_ep_set_stall(GET_CORE_IF(pcd),
  110121. + &ep->dwc_ep);
  110122. + }
  110123. + } else {
  110124. + if (ep->dwc_ep.num == 0) {
  110125. + pcd->ep0state = EP0_STALL;
  110126. + }
  110127. +
  110128. + ep->stopped = 1;
  110129. + dwc_otg_ep_set_stall(GET_CORE_IF(pcd), &ep->dwc_ep);
  110130. + }
  110131. + } else if (value == 2) {
  110132. + ep->dwc_ep.stall_clear_flag = 0;
  110133. + } else if (value == 3) {
  110134. + ep->dwc_ep.stall_clear_flag = 1;
  110135. + }
  110136. +
  110137. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  110138. +
  110139. + return retval;
  110140. +}
  110141. +
  110142. +/**
  110143. + * This function initiates remote wakeup of the host from suspend state.
  110144. + */
  110145. +void dwc_otg_pcd_rem_wkup_from_suspend(dwc_otg_pcd_t * pcd, int set)
  110146. +{
  110147. + dctl_data_t dctl = { 0 };
  110148. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  110149. + dsts_data_t dsts;
  110150. +
  110151. + dsts.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  110152. + if (!dsts.b.suspsts) {
  110153. + DWC_WARN("Remote wakeup while is not in suspend state\n");
  110154. + }
  110155. + /* Check if DEVICE_REMOTE_WAKEUP feature enabled */
  110156. + if (pcd->remote_wakeup_enable) {
  110157. + if (set) {
  110158. +
  110159. + if (core_if->adp_enable) {
  110160. + gpwrdn_data_t gpwrdn;
  110161. +
  110162. + dwc_otg_adp_probe_stop(core_if);
  110163. +
  110164. + /* Mask SRP detected interrupt from Power Down Logic */
  110165. + gpwrdn.d32 = 0;
  110166. + gpwrdn.b.srp_det_msk = 1;
  110167. + DWC_MODIFY_REG32(&core_if->
  110168. + core_global_regs->gpwrdn,
  110169. + gpwrdn.d32, 0);
  110170. +
  110171. + /* Disable Power Down Logic */
  110172. + gpwrdn.d32 = 0;
  110173. + gpwrdn.b.pmuactv = 1;
  110174. + DWC_MODIFY_REG32(&core_if->
  110175. + core_global_regs->gpwrdn,
  110176. + gpwrdn.d32, 0);
  110177. +
  110178. + /*
  110179. + * Initialize the Core for Device mode.
  110180. + */
  110181. + core_if->op_state = B_PERIPHERAL;
  110182. + dwc_otg_core_init(core_if);
  110183. + dwc_otg_enable_global_interrupts(core_if);
  110184. + cil_pcd_start(core_if);
  110185. +
  110186. + dwc_otg_initiate_srp(core_if);
  110187. + }
  110188. +
  110189. + dctl.b.rmtwkupsig = 1;
  110190. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  110191. + dctl, 0, dctl.d32);
  110192. + DWC_DEBUGPL(DBG_PCD, "Set Remote Wakeup\n");
  110193. +
  110194. + dwc_mdelay(2);
  110195. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  110196. + dctl, dctl.d32, 0);
  110197. + DWC_DEBUGPL(DBG_PCD, "Clear Remote Wakeup\n");
  110198. + }
  110199. + } else {
  110200. + DWC_DEBUGPL(DBG_PCD, "Remote Wakeup is disabled\n");
  110201. + }
  110202. +}
  110203. +
  110204. +#ifdef CONFIG_USB_DWC_OTG_LPM
  110205. +/**
  110206. + * This function initiates remote wakeup of the host from L1 sleep state.
  110207. + */
  110208. +void dwc_otg_pcd_rem_wkup_from_sleep(dwc_otg_pcd_t * pcd, int set)
  110209. +{
  110210. + glpmcfg_data_t lpmcfg;
  110211. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  110212. +
  110213. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  110214. +
  110215. + /* Check if we are in L1 state */
  110216. + if (!lpmcfg.b.prt_sleep_sts) {
  110217. + DWC_DEBUGPL(DBG_PCD, "Device is not in sleep state\n");
  110218. + return;
  110219. + }
  110220. +
  110221. + /* Check if host allows remote wakeup */
  110222. + if (!lpmcfg.b.rem_wkup_en) {
  110223. + DWC_DEBUGPL(DBG_PCD, "Host does not allow remote wakeup\n");
  110224. + return;
  110225. + }
  110226. +
  110227. + /* Check if Resume OK */
  110228. + if (!lpmcfg.b.sleep_state_resumeok) {
  110229. + DWC_DEBUGPL(DBG_PCD, "Sleep state resume is not OK\n");
  110230. + return;
  110231. + }
  110232. +
  110233. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  110234. + lpmcfg.b.en_utmi_sleep = 0;
  110235. + lpmcfg.b.hird_thres &= (~(1 << 4));
  110236. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg, lpmcfg.d32);
  110237. +
  110238. + if (set) {
  110239. + dctl_data_t dctl = {.d32 = 0 };
  110240. + dctl.b.rmtwkupsig = 1;
  110241. + /* Set RmtWkUpSig bit to start remote wakup signaling.
  110242. + * Hardware will automatically clear this bit.
  110243. + */
  110244. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl,
  110245. + 0, dctl.d32);
  110246. + DWC_DEBUGPL(DBG_PCD, "Set Remote Wakeup\n");
  110247. + }
  110248. +
  110249. +}
  110250. +#endif
  110251. +
  110252. +/**
  110253. + * Performs remote wakeup.
  110254. + */
  110255. +void dwc_otg_pcd_remote_wakeup(dwc_otg_pcd_t * pcd, int set)
  110256. +{
  110257. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  110258. + dwc_irqflags_t flags;
  110259. + if (dwc_otg_is_device_mode(core_if)) {
  110260. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  110261. +#ifdef CONFIG_USB_DWC_OTG_LPM
  110262. + if (core_if->lx_state == DWC_OTG_L1) {
  110263. + dwc_otg_pcd_rem_wkup_from_sleep(pcd, set);
  110264. + } else {
  110265. +#endif
  110266. + dwc_otg_pcd_rem_wkup_from_suspend(pcd, set);
  110267. +#ifdef CONFIG_USB_DWC_OTG_LPM
  110268. + }
  110269. +#endif
  110270. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  110271. + }
  110272. + return;
  110273. +}
  110274. +
  110275. +void dwc_otg_pcd_disconnect_us(dwc_otg_pcd_t * pcd, int no_of_usecs)
  110276. +{
  110277. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  110278. + dctl_data_t dctl = { 0 };
  110279. +
  110280. + if (dwc_otg_is_device_mode(core_if)) {
  110281. + dctl.b.sftdiscon = 1;
  110282. + DWC_PRINTF("Soft disconnect for %d useconds\n",no_of_usecs);
  110283. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0, dctl.d32);
  110284. + dwc_udelay(no_of_usecs);
  110285. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32,0);
  110286. +
  110287. + } else{
  110288. + DWC_PRINTF("NOT SUPPORTED IN HOST MODE\n");
  110289. + }
  110290. + return;
  110291. +
  110292. +}
  110293. +
  110294. +int dwc_otg_pcd_wakeup(dwc_otg_pcd_t * pcd)
  110295. +{
  110296. + dsts_data_t dsts;
  110297. + gotgctl_data_t gotgctl;
  110298. +
  110299. + /*
  110300. + * This function starts the Protocol if no session is in progress. If
  110301. + * a session is already in progress, but the device is suspended,
  110302. + * remote wakeup signaling is started.
  110303. + */
  110304. +
  110305. + /* Check if valid session */
  110306. + gotgctl.d32 =
  110307. + DWC_READ_REG32(&(GET_CORE_IF(pcd)->core_global_regs->gotgctl));
  110308. + if (gotgctl.b.bsesvld) {
  110309. + /* Check if suspend state */
  110310. + dsts.d32 =
  110311. + DWC_READ_REG32(&
  110312. + (GET_CORE_IF(pcd)->dev_if->
  110313. + dev_global_regs->dsts));
  110314. + if (dsts.b.suspsts) {
  110315. + dwc_otg_pcd_remote_wakeup(pcd, 1);
  110316. + }
  110317. + } else {
  110318. + dwc_otg_pcd_initiate_srp(pcd);
  110319. + }
  110320. +
  110321. + return 0;
  110322. +
  110323. +}
  110324. +
  110325. +/**
  110326. + * Start the SRP timer to detect when the SRP does not complete within
  110327. + * 6 seconds.
  110328. + *
  110329. + * @param pcd the pcd structure.
  110330. + */
  110331. +void dwc_otg_pcd_initiate_srp(dwc_otg_pcd_t * pcd)
  110332. +{
  110333. + dwc_irqflags_t flags;
  110334. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  110335. + dwc_otg_initiate_srp(GET_CORE_IF(pcd));
  110336. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  110337. +}
  110338. +
  110339. +int dwc_otg_pcd_get_frame_number(dwc_otg_pcd_t * pcd)
  110340. +{
  110341. + return dwc_otg_get_frame_number(GET_CORE_IF(pcd));
  110342. +}
  110343. +
  110344. +int dwc_otg_pcd_is_lpm_enabled(dwc_otg_pcd_t * pcd)
  110345. +{
  110346. + return GET_CORE_IF(pcd)->core_params->lpm_enable;
  110347. +}
  110348. +
  110349. +uint32_t get_b_hnp_enable(dwc_otg_pcd_t * pcd)
  110350. +{
  110351. + return pcd->b_hnp_enable;
  110352. +}
  110353. +
  110354. +uint32_t get_a_hnp_support(dwc_otg_pcd_t * pcd)
  110355. +{
  110356. + return pcd->a_hnp_support;
  110357. +}
  110358. +
  110359. +uint32_t get_a_alt_hnp_support(dwc_otg_pcd_t * pcd)
  110360. +{
  110361. + return pcd->a_alt_hnp_support;
  110362. +}
  110363. +
  110364. +int dwc_otg_pcd_get_rmwkup_enable(dwc_otg_pcd_t * pcd)
  110365. +{
  110366. + return pcd->remote_wakeup_enable;
  110367. +}
  110368. +
  110369. +#endif /* DWC_HOST_ONLY */
  110370. diff -Nur linux-3.18.8/drivers/usb/host/dwc_otg/dwc_otg_pcd.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_pcd.h
  110371. --- linux-3.18.8/drivers/usb/host/dwc_otg/dwc_otg_pcd.h 1970-01-01 01:00:00.000000000 +0100
  110372. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_pcd.h 2015-03-05 14:40:16.561715806 +0100
  110373. @@ -0,0 +1,266 @@
  110374. +/* ==========================================================================
  110375. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_pcd.h $
  110376. + * $Revision: #48 $
  110377. + * $Date: 2012/08/10 $
  110378. + * $Change: 2047372 $
  110379. + *
  110380. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  110381. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  110382. + * otherwise expressly agreed to in writing between Synopsys and you.
  110383. + *
  110384. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  110385. + * any End User Software License Agreement or Agreement for Licensed Product
  110386. + * with Synopsys or any supplement thereto. You are permitted to use and
  110387. + * redistribute this Software in source and binary forms, with or without
  110388. + * modification, provided that redistributions of source code must retain this
  110389. + * notice. You may not view, use, disclose, copy or distribute this file or
  110390. + * any information contained herein except pursuant to this license grant from
  110391. + * Synopsys. If you do not agree with this notice, including the disclaimer
  110392. + * below, then you are not authorized to use the Software.
  110393. + *
  110394. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  110395. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  110396. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  110397. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  110398. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  110399. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  110400. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  110401. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  110402. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  110403. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  110404. + * DAMAGE.
  110405. + * ========================================================================== */
  110406. +#ifndef DWC_HOST_ONLY
  110407. +#if !defined(__DWC_PCD_H__)
  110408. +#define __DWC_PCD_H__
  110409. +
  110410. +#include "dwc_otg_os_dep.h"
  110411. +#include "usb.h"
  110412. +#include "dwc_otg_cil.h"
  110413. +#include "dwc_otg_pcd_if.h"
  110414. +struct cfiobject;
  110415. +
  110416. +/**
  110417. + * @file
  110418. + *
  110419. + * This file contains the structures, constants, and interfaces for
  110420. + * the Perpherial Contoller Driver (PCD).
  110421. + *
  110422. + * The Peripheral Controller Driver (PCD) for Linux will implement the
  110423. + * Gadget API, so that the existing Gadget drivers can be used. For
  110424. + * the Mass Storage Function driver the File-backed USB Storage Gadget
  110425. + * (FBS) driver will be used. The FBS driver supports the
  110426. + * Control-Bulk (CB), Control-Bulk-Interrupt (CBI), and Bulk-Only
  110427. + * transports.
  110428. + *
  110429. + */
  110430. +
  110431. +/** Invalid DMA Address */
  110432. +#define DWC_DMA_ADDR_INVALID (~(dwc_dma_t)0)
  110433. +
  110434. +/** Max Transfer size for any EP */
  110435. +#define DDMA_MAX_TRANSFER_SIZE 65535
  110436. +
  110437. +/**
  110438. + * Get the pointer to the core_if from the pcd pointer.
  110439. + */
  110440. +#define GET_CORE_IF( _pcd ) (_pcd->core_if)
  110441. +
  110442. +/**
  110443. + * States of EP0.
  110444. + */
  110445. +typedef enum ep0_state {
  110446. + EP0_DISCONNECT, /* no host */
  110447. + EP0_IDLE,
  110448. + EP0_IN_DATA_PHASE,
  110449. + EP0_OUT_DATA_PHASE,
  110450. + EP0_IN_STATUS_PHASE,
  110451. + EP0_OUT_STATUS_PHASE,
  110452. + EP0_STALL,
  110453. +} ep0state_e;
  110454. +
  110455. +/** Fordward declaration.*/
  110456. +struct dwc_otg_pcd;
  110457. +
  110458. +/** DWC_otg iso request structure.
  110459. + *
  110460. + */
  110461. +typedef struct usb_iso_request dwc_otg_pcd_iso_request_t;
  110462. +
  110463. +#ifdef DWC_UTE_PER_IO
  110464. +
  110465. +/**
  110466. + * This shall be the exact analogy of the same type structure defined in the
  110467. + * usb_gadget.h. Each descriptor contains
  110468. + */
  110469. +struct dwc_iso_pkt_desc_port {
  110470. + uint32_t offset;
  110471. + uint32_t length; /* expected length */
  110472. + uint32_t actual_length;
  110473. + uint32_t status;
  110474. +};
  110475. +
  110476. +struct dwc_iso_xreq_port {
  110477. + /** transfer/submission flag */
  110478. + uint32_t tr_sub_flags;
  110479. + /** Start the request ASAP */
  110480. +#define DWC_EREQ_TF_ASAP 0x00000002
  110481. + /** Just enqueue the request w/o initiating a transfer */
  110482. +#define DWC_EREQ_TF_ENQUEUE 0x00000004
  110483. +
  110484. + /**
  110485. + * count of ISO packets attached to this request - shall
  110486. + * not exceed the pio_alloc_pkt_count
  110487. + */
  110488. + uint32_t pio_pkt_count;
  110489. + /** count of ISO packets allocated for this request */
  110490. + uint32_t pio_alloc_pkt_count;
  110491. + /** number of ISO packet errors */
  110492. + uint32_t error_count;
  110493. + /** reserved for future extension */
  110494. + uint32_t res;
  110495. + /** Will be allocated and freed in the UTE gadget and based on the CFC value */
  110496. + struct dwc_iso_pkt_desc_port *per_io_frame_descs;
  110497. +};
  110498. +#endif
  110499. +/** DWC_otg request structure.
  110500. + * This structure is a list of requests.
  110501. + */
  110502. +typedef struct dwc_otg_pcd_request {
  110503. + void *priv;
  110504. + void *buf;
  110505. + dwc_dma_t dma;
  110506. + uint32_t length;
  110507. + uint32_t actual;
  110508. + unsigned sent_zlp:1;
  110509. + /**
  110510. + * Used instead of original buffer if
  110511. + * it(physical address) is not dword-aligned.
  110512. + **/
  110513. + uint8_t *dw_align_buf;
  110514. + dwc_dma_t dw_align_buf_dma;
  110515. +
  110516. + DWC_CIRCLEQ_ENTRY(dwc_otg_pcd_request) queue_entry;
  110517. +#ifdef DWC_UTE_PER_IO
  110518. + struct dwc_iso_xreq_port ext_req;
  110519. + //void *priv_ereq_nport; /* */
  110520. +#endif
  110521. +} dwc_otg_pcd_request_t;
  110522. +
  110523. +DWC_CIRCLEQ_HEAD(req_list, dwc_otg_pcd_request);
  110524. +
  110525. +/** PCD EP structure.
  110526. + * This structure describes an EP, there is an array of EPs in the PCD
  110527. + * structure.
  110528. + */
  110529. +typedef struct dwc_otg_pcd_ep {
  110530. + /** USB EP Descriptor */
  110531. + const usb_endpoint_descriptor_t *desc;
  110532. +
  110533. + /** queue of dwc_otg_pcd_requests. */
  110534. + struct req_list queue;
  110535. + unsigned stopped:1;
  110536. + unsigned disabling:1;
  110537. + unsigned dma:1;
  110538. + unsigned queue_sof:1;
  110539. +
  110540. +#ifdef DWC_EN_ISOC
  110541. + /** ISOC req handle passed */
  110542. + void *iso_req_handle;
  110543. +#endif //_EN_ISOC_
  110544. +
  110545. + /** DWC_otg ep data. */
  110546. + dwc_ep_t dwc_ep;
  110547. +
  110548. + /** Pointer to PCD */
  110549. + struct dwc_otg_pcd *pcd;
  110550. +
  110551. + void *priv;
  110552. +} dwc_otg_pcd_ep_t;
  110553. +
  110554. +/** DWC_otg PCD Structure.
  110555. + * This structure encapsulates the data for the dwc_otg PCD.
  110556. + */
  110557. +struct dwc_otg_pcd {
  110558. + const struct dwc_otg_pcd_function_ops *fops;
  110559. + /** The DWC otg device pointer */
  110560. + struct dwc_otg_device *otg_dev;
  110561. + /** Core Interface */
  110562. + dwc_otg_core_if_t *core_if;
  110563. + /** State of EP0 */
  110564. + ep0state_e ep0state;
  110565. + /** EP0 Request is pending */
  110566. + unsigned ep0_pending:1;
  110567. + /** Indicates when SET CONFIGURATION Request is in process */
  110568. + unsigned request_config:1;
  110569. + /** The state of the Remote Wakeup Enable. */
  110570. + unsigned remote_wakeup_enable:1;
  110571. + /** The state of the B-Device HNP Enable. */
  110572. + unsigned b_hnp_enable:1;
  110573. + /** The state of A-Device HNP Support. */
  110574. + unsigned a_hnp_support:1;
  110575. + /** The state of the A-Device Alt HNP support. */
  110576. + unsigned a_alt_hnp_support:1;
  110577. + /** Count of pending Requests */
  110578. + unsigned request_pending;
  110579. +
  110580. + /** SETUP packet for EP0
  110581. + * This structure is allocated as a DMA buffer on PCD initialization
  110582. + * with enough space for up to 3 setup packets.
  110583. + */
  110584. + union {
  110585. + usb_device_request_t req;
  110586. + uint32_t d32[2];
  110587. + } *setup_pkt;
  110588. +
  110589. + dwc_dma_t setup_pkt_dma_handle;
  110590. +
  110591. + /* Additional buffer and flag for CTRL_WR premature case */
  110592. + uint8_t *backup_buf;
  110593. + unsigned data_terminated;
  110594. +
  110595. + /** 2-byte dma buffer used to return status from GET_STATUS */
  110596. + uint16_t *status_buf;
  110597. + dwc_dma_t status_buf_dma_handle;
  110598. +
  110599. + /** EP0 */
  110600. + dwc_otg_pcd_ep_t ep0;
  110601. +
  110602. + /** Array of IN EPs. */
  110603. + dwc_otg_pcd_ep_t in_ep[MAX_EPS_CHANNELS - 1];
  110604. + /** Array of OUT EPs. */
  110605. + dwc_otg_pcd_ep_t out_ep[MAX_EPS_CHANNELS - 1];
  110606. + /** number of valid EPs in the above array. */
  110607. +// unsigned num_eps : 4;
  110608. + dwc_spinlock_t *lock;
  110609. +
  110610. + /** Tasklet to defer starting of TEST mode transmissions until
  110611. + * Status Phase has been completed.
  110612. + */
  110613. + dwc_tasklet_t *test_mode_tasklet;
  110614. +
  110615. + /** Tasklet to delay starting of xfer in DMA mode */
  110616. + dwc_tasklet_t *start_xfer_tasklet;
  110617. +
  110618. + /** The test mode to enter when the tasklet is executed. */
  110619. + unsigned test_mode;
  110620. + /** The cfi_api structure that implements most of the CFI API
  110621. + * and OTG specific core configuration functionality
  110622. + */
  110623. +#ifdef DWC_UTE_CFI
  110624. + struct cfiobject *cfi;
  110625. +#endif
  110626. +
  110627. +};
  110628. +
  110629. +//FIXME this functions should be static, and this prototypes should be removed
  110630. +extern void dwc_otg_request_nuke(dwc_otg_pcd_ep_t * ep);
  110631. +extern void dwc_otg_request_done(dwc_otg_pcd_ep_t * ep,
  110632. + dwc_otg_pcd_request_t * req, int32_t status);
  110633. +
  110634. +void dwc_otg_iso_buffer_done(dwc_otg_pcd_t * pcd, dwc_otg_pcd_ep_t * ep,
  110635. + void *req_handle);
  110636. +
  110637. +extern void do_test_mode(void *data);
  110638. +#endif
  110639. +#endif /* DWC_HOST_ONLY */
  110640. diff -Nur linux-3.18.8/drivers/usb/host/dwc_otg/dwc_otg_pcd_if.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_pcd_if.h
  110641. --- linux-3.18.8/drivers/usb/host/dwc_otg/dwc_otg_pcd_if.h 1970-01-01 01:00:00.000000000 +0100
  110642. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_pcd_if.h 2015-03-05 14:40:16.561715806 +0100
  110643. @@ -0,0 +1,360 @@
  110644. +/* ==========================================================================
  110645. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_pcd_if.h $
  110646. + * $Revision: #11 $
  110647. + * $Date: 2011/10/26 $
  110648. + * $Change: 1873028 $
  110649. + *
  110650. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  110651. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  110652. + * otherwise expressly agreed to in writing between Synopsys and you.
  110653. + *
  110654. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  110655. + * any End User Software License Agreement or Agreement for Licensed Product
  110656. + * with Synopsys or any supplement thereto. You are permitted to use and
  110657. + * redistribute this Software in source and binary forms, with or without
  110658. + * modification, provided that redistributions of source code must retain this
  110659. + * notice. You may not view, use, disclose, copy or distribute this file or
  110660. + * any information contained herein except pursuant to this license grant from
  110661. + * Synopsys. If you do not agree with this notice, including the disclaimer
  110662. + * below, then you are not authorized to use the Software.
  110663. + *
  110664. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  110665. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  110666. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  110667. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  110668. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  110669. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  110670. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  110671. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  110672. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  110673. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  110674. + * DAMAGE.
  110675. + * ========================================================================== */
  110676. +#ifndef DWC_HOST_ONLY
  110677. +
  110678. +#if !defined(__DWC_PCD_IF_H__)
  110679. +#define __DWC_PCD_IF_H__
  110680. +
  110681. +//#include "dwc_os.h"
  110682. +#include "dwc_otg_core_if.h"
  110683. +
  110684. +/** @file
  110685. + * This file defines DWC_OTG PCD Core API.
  110686. + */
  110687. +
  110688. +struct dwc_otg_pcd;
  110689. +typedef struct dwc_otg_pcd dwc_otg_pcd_t;
  110690. +
  110691. +/** Maxpacket size for EP0 */
  110692. +#define MAX_EP0_SIZE 64
  110693. +/** Maxpacket size for any EP */
  110694. +#define MAX_PACKET_SIZE 1024
  110695. +
  110696. +/** @name Function Driver Callbacks */
  110697. +/** @{ */
  110698. +
  110699. +/** This function will be called whenever a previously queued request has
  110700. + * completed. The status value will be set to -DWC_E_SHUTDOWN to indicated a
  110701. + * failed or aborted transfer, or -DWC_E_RESTART to indicate the device was reset,
  110702. + * or -DWC_E_TIMEOUT to indicate it timed out, or -DWC_E_INVALID to indicate invalid
  110703. + * parameters. */
  110704. +typedef int (*dwc_completion_cb_t) (dwc_otg_pcd_t * pcd, void *ep_handle,
  110705. + void *req_handle, int32_t status,
  110706. + uint32_t actual);
  110707. +/**
  110708. + * This function will be called whenever a previousle queued ISOC request has
  110709. + * completed. Count of ISOC packets could be read using dwc_otg_pcd_get_iso_packet_count
  110710. + * function.
  110711. + * The status of each ISOC packet could be read using dwc_otg_pcd_get_iso_packet_*
  110712. + * functions.
  110713. + */
  110714. +typedef int (*dwc_isoc_completion_cb_t) (dwc_otg_pcd_t * pcd, void *ep_handle,
  110715. + void *req_handle, int proc_buf_num);
  110716. +/** This function should handle any SETUP request that cannot be handled by the
  110717. + * PCD Core. This includes most GET_DESCRIPTORs, SET_CONFIGS, Any
  110718. + * class-specific requests, etc. The function must non-blocking.
  110719. + *
  110720. + * Returns 0 on success.
  110721. + * Returns -DWC_E_NOT_SUPPORTED if the request is not supported.
  110722. + * Returns -DWC_E_INVALID if the setup request had invalid parameters or bytes.
  110723. + * Returns -DWC_E_SHUTDOWN on any other error. */
  110724. +typedef int (*dwc_setup_cb_t) (dwc_otg_pcd_t * pcd, uint8_t * bytes);
  110725. +/** This is called whenever the device has been disconnected. The function
  110726. + * driver should take appropriate action to clean up all pending requests in the
  110727. + * PCD Core, remove all endpoints (except ep0), and initialize back to reset
  110728. + * state. */
  110729. +typedef int (*dwc_disconnect_cb_t) (dwc_otg_pcd_t * pcd);
  110730. +/** This function is called when device has been connected. */
  110731. +typedef int (*dwc_connect_cb_t) (dwc_otg_pcd_t * pcd, int speed);
  110732. +/** This function is called when device has been suspended */
  110733. +typedef int (*dwc_suspend_cb_t) (dwc_otg_pcd_t * pcd);
  110734. +/** This function is called when device has received LPM tokens, i.e.
  110735. + * device has been sent to sleep state. */
  110736. +typedef int (*dwc_sleep_cb_t) (dwc_otg_pcd_t * pcd);
  110737. +/** This function is called when device has been resumed
  110738. + * from suspend(L2) or L1 sleep state. */
  110739. +typedef int (*dwc_resume_cb_t) (dwc_otg_pcd_t * pcd);
  110740. +/** This function is called whenever hnp params has been changed.
  110741. + * User can call get_b_hnp_enable, get_a_hnp_support, get_a_alt_hnp_support functions
  110742. + * to get hnp parameters. */
  110743. +typedef int (*dwc_hnp_params_changed_cb_t) (dwc_otg_pcd_t * pcd);
  110744. +/** This function is called whenever USB RESET is detected. */
  110745. +typedef int (*dwc_reset_cb_t) (dwc_otg_pcd_t * pcd);
  110746. +
  110747. +typedef int (*cfi_setup_cb_t) (dwc_otg_pcd_t * pcd, void *ctrl_req_bytes);
  110748. +
  110749. +/**
  110750. + *
  110751. + * @param ep_handle Void pointer to the usb_ep structure
  110752. + * @param ereq_port Pointer to the extended request structure created in the
  110753. + * portable part.
  110754. + */
  110755. +typedef int (*xiso_completion_cb_t) (dwc_otg_pcd_t * pcd, void *ep_handle,
  110756. + void *req_handle, int32_t status,
  110757. + void *ereq_port);
  110758. +/** Function Driver Ops Data Structure */
  110759. +struct dwc_otg_pcd_function_ops {
  110760. + dwc_connect_cb_t connect;
  110761. + dwc_disconnect_cb_t disconnect;
  110762. + dwc_setup_cb_t setup;
  110763. + dwc_completion_cb_t complete;
  110764. + dwc_isoc_completion_cb_t isoc_complete;
  110765. + dwc_suspend_cb_t suspend;
  110766. + dwc_sleep_cb_t sleep;
  110767. + dwc_resume_cb_t resume;
  110768. + dwc_reset_cb_t reset;
  110769. + dwc_hnp_params_changed_cb_t hnp_changed;
  110770. + cfi_setup_cb_t cfi_setup;
  110771. +#ifdef DWC_UTE_PER_IO
  110772. + xiso_completion_cb_t xisoc_complete;
  110773. +#endif
  110774. +};
  110775. +/** @} */
  110776. +
  110777. +/** @name Function Driver Functions */
  110778. +/** @{ */
  110779. +
  110780. +/** Call this function to get pointer on dwc_otg_pcd_t,
  110781. + * this pointer will be used for all PCD API functions.
  110782. + *
  110783. + * @param core_if The DWC_OTG Core
  110784. + */
  110785. +extern dwc_otg_pcd_t *dwc_otg_pcd_init(dwc_otg_core_if_t * core_if);
  110786. +
  110787. +/** Frees PCD allocated by dwc_otg_pcd_init
  110788. + *
  110789. + * @param pcd The PCD
  110790. + */
  110791. +extern void dwc_otg_pcd_remove(dwc_otg_pcd_t * pcd);
  110792. +
  110793. +/** Call this to bind the function driver to the PCD Core.
  110794. + *
  110795. + * @param pcd Pointer on dwc_otg_pcd_t returned by dwc_otg_pcd_init function.
  110796. + * @param fops The Function Driver Ops data structure containing pointers to all callbacks.
  110797. + */
  110798. +extern void dwc_otg_pcd_start(dwc_otg_pcd_t * pcd,
  110799. + const struct dwc_otg_pcd_function_ops *fops);
  110800. +
  110801. +/** Enables an endpoint for use. This function enables an endpoint in
  110802. + * the PCD. The endpoint is described by the ep_desc which has the
  110803. + * same format as a USB ep descriptor. The ep_handle parameter is used to refer
  110804. + * to the endpoint from other API functions and in callbacks. Normally this
  110805. + * should be called after a SET_CONFIGURATION/SET_INTERFACE to configure the
  110806. + * core for that interface.
  110807. + *
  110808. + * Returns -DWC_E_INVALID if invalid parameters were passed.
  110809. + * Returns -DWC_E_SHUTDOWN if any other error ocurred.
  110810. + * Returns 0 on success.
  110811. + *
  110812. + * @param pcd The PCD
  110813. + * @param ep_desc Endpoint descriptor
  110814. + * @param usb_ep Handle on endpoint, that will be used to identify endpoint.
  110815. + */
  110816. +extern int dwc_otg_pcd_ep_enable(dwc_otg_pcd_t * pcd,
  110817. + const uint8_t * ep_desc, void *usb_ep);
  110818. +
  110819. +/** Disable the endpoint referenced by ep_handle.
  110820. + *
  110821. + * Returns -DWC_E_INVALID if invalid parameters were passed.
  110822. + * Returns -DWC_E_SHUTDOWN if any other error occurred.
  110823. + * Returns 0 on success. */
  110824. +extern int dwc_otg_pcd_ep_disable(dwc_otg_pcd_t * pcd, void *ep_handle);
  110825. +
  110826. +/** Queue a data transfer request on the endpoint referenced by ep_handle.
  110827. + * After the transfer is completes, the complete callback will be called with
  110828. + * the request status.
  110829. + *
  110830. + * @param pcd The PCD
  110831. + * @param ep_handle The handle of the endpoint
  110832. + * @param buf The buffer for the data
  110833. + * @param dma_buf The DMA buffer for the data
  110834. + * @param buflen The length of the data transfer
  110835. + * @param zero Specifies whether to send zero length last packet.
  110836. + * @param req_handle Set this handle to any value to use to reference this
  110837. + * request in the ep_dequeue function or from the complete callback
  110838. + * @param atomic_alloc If driver need to perform atomic allocations
  110839. + * for internal data structures.
  110840. + *
  110841. + * Returns -DWC_E_INVALID if invalid parameters were passed.
  110842. + * Returns -DWC_E_SHUTDOWN if any other error ocurred.
  110843. + * Returns 0 on success. */
  110844. +extern int dwc_otg_pcd_ep_queue(dwc_otg_pcd_t * pcd, void *ep_handle,
  110845. + uint8_t * buf, dwc_dma_t dma_buf,
  110846. + uint32_t buflen, int zero, void *req_handle,
  110847. + int atomic_alloc);
  110848. +#ifdef DWC_UTE_PER_IO
  110849. +/**
  110850. + *
  110851. + * @param ereq_nonport Pointer to the extended request part of the
  110852. + * usb_request structure defined in usb_gadget.h file.
  110853. + */
  110854. +extern int dwc_otg_pcd_xiso_ep_queue(dwc_otg_pcd_t * pcd, void *ep_handle,
  110855. + uint8_t * buf, dwc_dma_t dma_buf,
  110856. + uint32_t buflen, int zero,
  110857. + void *req_handle, int atomic_alloc,
  110858. + void *ereq_nonport);
  110859. +
  110860. +#endif
  110861. +
  110862. +/** De-queue the specified data transfer that has not yet completed.
  110863. + *
  110864. + * Returns -DWC_E_INVALID if invalid parameters were passed.
  110865. + * Returns -DWC_E_SHUTDOWN if any other error ocurred.
  110866. + * Returns 0 on success. */
  110867. +extern int dwc_otg_pcd_ep_dequeue(dwc_otg_pcd_t * pcd, void *ep_handle,
  110868. + void *req_handle);
  110869. +
  110870. +/** Halt (STALL) an endpoint or clear it.
  110871. + *
  110872. + * Returns -DWC_E_INVALID if invalid parameters were passed.
  110873. + * Returns -DWC_E_SHUTDOWN if any other error ocurred.
  110874. + * Returns -DWC_E_AGAIN if the STALL cannot be sent and must be tried again later
  110875. + * Returns 0 on success. */
  110876. +extern int dwc_otg_pcd_ep_halt(dwc_otg_pcd_t * pcd, void *ep_handle, int value);
  110877. +
  110878. +/** This function */
  110879. +extern int dwc_otg_pcd_ep_wedge(dwc_otg_pcd_t * pcd, void *ep_handle);
  110880. +
  110881. +/** This function should be called on every hardware interrupt */
  110882. +extern int32_t dwc_otg_pcd_handle_intr(dwc_otg_pcd_t * pcd);
  110883. +
  110884. +/** This function returns current frame number */
  110885. +extern int dwc_otg_pcd_get_frame_number(dwc_otg_pcd_t * pcd);
  110886. +
  110887. +/**
  110888. + * Start isochronous transfers on the endpoint referenced by ep_handle.
  110889. + * For isochronous transfers duble buffering is used.
  110890. + * After processing each of buffers comlete callback will be called with
  110891. + * status for each transaction.
  110892. + *
  110893. + * @param pcd The PCD
  110894. + * @param ep_handle The handle of the endpoint
  110895. + * @param buf0 The virtual address of first data buffer
  110896. + * @param buf1 The virtual address of second data buffer
  110897. + * @param dma0 The DMA address of first data buffer
  110898. + * @param dma1 The DMA address of second data buffer
  110899. + * @param sync_frame Data pattern frame number
  110900. + * @param dp_frame Data size for pattern frame
  110901. + * @param data_per_frame Data size for regular frame
  110902. + * @param start_frame Frame number to start transfers, if -1 then start transfers ASAP.
  110903. + * @param buf_proc_intrvl Interval of ISOC Buffer processing
  110904. + * @param req_handle Handle of ISOC request
  110905. + * @param atomic_alloc Specefies whether to perform atomic allocation for
  110906. + * internal data structures.
  110907. + *
  110908. + * Returns -DWC_E_NO_MEMORY if there is no enough memory.
  110909. + * Returns -DWC_E_INVALID if incorrect arguments are passed to the function.
  110910. + * Returns -DW_E_SHUTDOWN for any other error.
  110911. + * Returns 0 on success
  110912. + */
  110913. +extern int dwc_otg_pcd_iso_ep_start(dwc_otg_pcd_t * pcd, void *ep_handle,
  110914. + uint8_t * buf0, uint8_t * buf1,
  110915. + dwc_dma_t dma0, dwc_dma_t dma1,
  110916. + int sync_frame, int dp_frame,
  110917. + int data_per_frame, int start_frame,
  110918. + int buf_proc_intrvl, void *req_handle,
  110919. + int atomic_alloc);
  110920. +
  110921. +/** Stop ISOC transfers on endpoint referenced by ep_handle.
  110922. + *
  110923. + * @param pcd The PCD
  110924. + * @param ep_handle The handle of the endpoint
  110925. + * @param req_handle Handle of ISOC request
  110926. + *
  110927. + * Returns -DWC_E_INVALID if incorrect arguments are passed to the function
  110928. + * Returns 0 on success
  110929. + */
  110930. +int dwc_otg_pcd_iso_ep_stop(dwc_otg_pcd_t * pcd, void *ep_handle,
  110931. + void *req_handle);
  110932. +
  110933. +/** Get ISOC packet status.
  110934. + *
  110935. + * @param pcd The PCD
  110936. + * @param ep_handle The handle of the endpoint
  110937. + * @param iso_req_handle Isochronoush request handle
  110938. + * @param packet Number of packet
  110939. + * @param status Out parameter for returning status
  110940. + * @param actual Out parameter for returning actual length
  110941. + * @param offset Out parameter for returning offset
  110942. + *
  110943. + */
  110944. +extern void dwc_otg_pcd_get_iso_packet_params(dwc_otg_pcd_t * pcd,
  110945. + void *ep_handle,
  110946. + void *iso_req_handle, int packet,
  110947. + int *status, int *actual,
  110948. + int *offset);
  110949. +
  110950. +/** Get ISOC packet count.
  110951. + *
  110952. + * @param pcd The PCD
  110953. + * @param ep_handle The handle of the endpoint
  110954. + * @param iso_req_handle
  110955. + */
  110956. +extern int dwc_otg_pcd_get_iso_packet_count(dwc_otg_pcd_t * pcd,
  110957. + void *ep_handle,
  110958. + void *iso_req_handle);
  110959. +
  110960. +/** This function starts the SRP Protocol if no session is in progress. If
  110961. + * a session is already in progress, but the device is suspended,
  110962. + * remote wakeup signaling is started.
  110963. + */
  110964. +extern int dwc_otg_pcd_wakeup(dwc_otg_pcd_t * pcd);
  110965. +
  110966. +/** This function returns 1 if LPM support is enabled, and 0 otherwise. */
  110967. +extern int dwc_otg_pcd_is_lpm_enabled(dwc_otg_pcd_t * pcd);
  110968. +
  110969. +/** This function returns 1 if remote wakeup is allowed and 0, otherwise. */
  110970. +extern int dwc_otg_pcd_get_rmwkup_enable(dwc_otg_pcd_t * pcd);
  110971. +
  110972. +/** Initiate SRP */
  110973. +extern void dwc_otg_pcd_initiate_srp(dwc_otg_pcd_t * pcd);
  110974. +
  110975. +/** Starts remote wakeup signaling. */
  110976. +extern void dwc_otg_pcd_remote_wakeup(dwc_otg_pcd_t * pcd, int set);
  110977. +
  110978. +/** Starts micorsecond soft disconnect. */
  110979. +extern void dwc_otg_pcd_disconnect_us(dwc_otg_pcd_t * pcd, int no_of_usecs);
  110980. +/** This function returns whether device is dualspeed.*/
  110981. +extern uint32_t dwc_otg_pcd_is_dualspeed(dwc_otg_pcd_t * pcd);
  110982. +
  110983. +/** This function returns whether device is otg. */
  110984. +extern uint32_t dwc_otg_pcd_is_otg(dwc_otg_pcd_t * pcd);
  110985. +
  110986. +/** These functions allow to get hnp parameters */
  110987. +extern uint32_t get_b_hnp_enable(dwc_otg_pcd_t * pcd);
  110988. +extern uint32_t get_a_hnp_support(dwc_otg_pcd_t * pcd);
  110989. +extern uint32_t get_a_alt_hnp_support(dwc_otg_pcd_t * pcd);
  110990. +
  110991. +/** CFI specific Interface functions */
  110992. +/** Allocate a cfi buffer */
  110993. +extern uint8_t *cfiw_ep_alloc_buffer(dwc_otg_pcd_t * pcd, void *pep,
  110994. + dwc_dma_t * addr, size_t buflen,
  110995. + int flags);
  110996. +
  110997. +/******************************************************************************/
  110998. +
  110999. +/** @} */
  111000. +
  111001. +#endif /* __DWC_PCD_IF_H__ */
  111002. +
  111003. +#endif /* DWC_HOST_ONLY */
  111004. diff -Nur linux-3.18.8/drivers/usb/host/dwc_otg/dwc_otg_pcd_intr.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_pcd_intr.c
  111005. --- linux-3.18.8/drivers/usb/host/dwc_otg/dwc_otg_pcd_intr.c 1970-01-01 01:00:00.000000000 +0100
  111006. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_pcd_intr.c 2015-03-05 14:40:16.561715806 +0100
  111007. @@ -0,0 +1,5147 @@
  111008. +/* ==========================================================================
  111009. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_pcd_intr.c $
  111010. + * $Revision: #116 $
  111011. + * $Date: 2012/08/10 $
  111012. + * $Change: 2047372 $
  111013. + *
  111014. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  111015. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  111016. + * otherwise expressly agreed to in writing between Synopsys and you.
  111017. + *
  111018. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  111019. + * any End User Software License Agreement or Agreement for Licensed Product
  111020. + * with Synopsys or any supplement thereto. You are permitted to use and
  111021. + * redistribute this Software in source and binary forms, with or without
  111022. + * modification, provided that redistributions of source code must retain this
  111023. + * notice. You may not view, use, disclose, copy or distribute this file or
  111024. + * any information contained herein except pursuant to this license grant from
  111025. + * Synopsys. If you do not agree with this notice, including the disclaimer
  111026. + * below, then you are not authorized to use the Software.
  111027. + *
  111028. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  111029. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  111030. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  111031. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  111032. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  111033. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  111034. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  111035. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  111036. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  111037. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  111038. + * DAMAGE.
  111039. + * ========================================================================== */
  111040. +#ifndef DWC_HOST_ONLY
  111041. +
  111042. +#include "dwc_otg_pcd.h"
  111043. +
  111044. +#ifdef DWC_UTE_CFI
  111045. +#include "dwc_otg_cfi.h"
  111046. +#endif
  111047. +
  111048. +#ifdef DWC_UTE_PER_IO
  111049. +extern void complete_xiso_ep(dwc_otg_pcd_ep_t * ep);
  111050. +#endif
  111051. +//#define PRINT_CFI_DMA_DESCS
  111052. +
  111053. +#define DEBUG_EP0
  111054. +
  111055. +/**
  111056. + * This function updates OTG.
  111057. + */
  111058. +static void dwc_otg_pcd_update_otg(dwc_otg_pcd_t * pcd, const unsigned reset)
  111059. +{
  111060. +
  111061. + if (reset) {
  111062. + pcd->b_hnp_enable = 0;
  111063. + pcd->a_hnp_support = 0;
  111064. + pcd->a_alt_hnp_support = 0;
  111065. + }
  111066. +
  111067. + if (pcd->fops->hnp_changed) {
  111068. + pcd->fops->hnp_changed(pcd);
  111069. + }
  111070. +}
  111071. +
  111072. +/** @file
  111073. + * This file contains the implementation of the PCD Interrupt handlers.
  111074. + *
  111075. + * The PCD handles the device interrupts. Many conditions can cause a
  111076. + * device interrupt. When an interrupt occurs, the device interrupt
  111077. + * service routine determines the cause of the interrupt and
  111078. + * dispatches handling to the appropriate function. These interrupt
  111079. + * handling functions are described below.
  111080. + * All interrupt registers are processed from LSB to MSB.
  111081. + */
  111082. +
  111083. +/**
  111084. + * This function prints the ep0 state for debug purposes.
  111085. + */
  111086. +static inline void print_ep0_state(dwc_otg_pcd_t * pcd)
  111087. +{
  111088. +#ifdef DEBUG
  111089. + char str[40];
  111090. +
  111091. + switch (pcd->ep0state) {
  111092. + case EP0_DISCONNECT:
  111093. + dwc_strcpy(str, "EP0_DISCONNECT");
  111094. + break;
  111095. + case EP0_IDLE:
  111096. + dwc_strcpy(str, "EP0_IDLE");
  111097. + break;
  111098. + case EP0_IN_DATA_PHASE:
  111099. + dwc_strcpy(str, "EP0_IN_DATA_PHASE");
  111100. + break;
  111101. + case EP0_OUT_DATA_PHASE:
  111102. + dwc_strcpy(str, "EP0_OUT_DATA_PHASE");
  111103. + break;
  111104. + case EP0_IN_STATUS_PHASE:
  111105. + dwc_strcpy(str, "EP0_IN_STATUS_PHASE");
  111106. + break;
  111107. + case EP0_OUT_STATUS_PHASE:
  111108. + dwc_strcpy(str, "EP0_OUT_STATUS_PHASE");
  111109. + break;
  111110. + case EP0_STALL:
  111111. + dwc_strcpy(str, "EP0_STALL");
  111112. + break;
  111113. + default:
  111114. + dwc_strcpy(str, "EP0_INVALID");
  111115. + }
  111116. +
  111117. + DWC_DEBUGPL(DBG_ANY, "%s(%d)\n", str, pcd->ep0state);
  111118. +#endif
  111119. +}
  111120. +
  111121. +/**
  111122. + * This function calculate the size of the payload in the memory
  111123. + * for out endpoints and prints size for debug purposes(used in
  111124. + * 2.93a DevOutNak feature).
  111125. + */
  111126. +static inline void print_memory_payload(dwc_otg_pcd_t * pcd, dwc_ep_t * ep)
  111127. +{
  111128. +#ifdef DEBUG
  111129. + deptsiz_data_t deptsiz_init = {.d32 = 0 };
  111130. + deptsiz_data_t deptsiz_updt = {.d32 = 0 };
  111131. + int pack_num;
  111132. + unsigned payload;
  111133. +
  111134. + deptsiz_init.d32 = pcd->core_if->start_doeptsiz_val[ep->num];
  111135. + deptsiz_updt.d32 =
  111136. + DWC_READ_REG32(&pcd->core_if->dev_if->
  111137. + out_ep_regs[ep->num]->doeptsiz);
  111138. + /* Payload will be */
  111139. + payload = deptsiz_init.b.xfersize - deptsiz_updt.b.xfersize;
  111140. + /* Packet count is decremented every time a packet
  111141. + * is written to the RxFIFO not in to the external memory
  111142. + * So, if payload == 0, then it means no packet was sent to ext memory*/
  111143. + pack_num = (!payload) ? 0 : (deptsiz_init.b.pktcnt - deptsiz_updt.b.pktcnt);
  111144. + DWC_DEBUGPL(DBG_PCDV,
  111145. + "Payload for EP%d-%s\n",
  111146. + ep->num, (ep->is_in ? "IN" : "OUT"));
  111147. + DWC_DEBUGPL(DBG_PCDV,
  111148. + "Number of transfered bytes = 0x%08x\n", payload);
  111149. + DWC_DEBUGPL(DBG_PCDV,
  111150. + "Number of transfered packets = %d\n", pack_num);
  111151. +#endif
  111152. +}
  111153. +
  111154. +
  111155. +#ifdef DWC_UTE_CFI
  111156. +static inline void print_desc(struct dwc_otg_dma_desc *ddesc,
  111157. + const uint8_t * epname, int descnum)
  111158. +{
  111159. + CFI_INFO
  111160. + ("%s DMA_DESC(%d) buf=0x%08x bytes=0x%04x; sp=0x%x; l=0x%x; sts=0x%02x; bs=0x%02x\n",
  111161. + epname, descnum, ddesc->buf, ddesc->status.b.bytes,
  111162. + ddesc->status.b.sp, ddesc->status.b.l, ddesc->status.b.sts,
  111163. + ddesc->status.b.bs);
  111164. +}
  111165. +#endif
  111166. +
  111167. +/**
  111168. + * This function returns pointer to in ep struct with number ep_num
  111169. + */
  111170. +static inline dwc_otg_pcd_ep_t *get_in_ep(dwc_otg_pcd_t * pcd, uint32_t ep_num)
  111171. +{
  111172. + int i;
  111173. + int num_in_eps = GET_CORE_IF(pcd)->dev_if->num_in_eps;
  111174. + if (ep_num == 0) {
  111175. + return &pcd->ep0;
  111176. + } else {
  111177. + for (i = 0; i < num_in_eps; ++i) {
  111178. + if (pcd->in_ep[i].dwc_ep.num == ep_num)
  111179. + return &pcd->in_ep[i];
  111180. + }
  111181. + return 0;
  111182. + }
  111183. +}
  111184. +
  111185. +/**
  111186. + * This function returns pointer to out ep struct with number ep_num
  111187. + */
  111188. +static inline dwc_otg_pcd_ep_t *get_out_ep(dwc_otg_pcd_t * pcd, uint32_t ep_num)
  111189. +{
  111190. + int i;
  111191. + int num_out_eps = GET_CORE_IF(pcd)->dev_if->num_out_eps;
  111192. + if (ep_num == 0) {
  111193. + return &pcd->ep0;
  111194. + } else {
  111195. + for (i = 0; i < num_out_eps; ++i) {
  111196. + if (pcd->out_ep[i].dwc_ep.num == ep_num)
  111197. + return &pcd->out_ep[i];
  111198. + }
  111199. + return 0;
  111200. + }
  111201. +}
  111202. +
  111203. +/**
  111204. + * This functions gets a pointer to an EP from the wIndex address
  111205. + * value of the control request.
  111206. + */
  111207. +dwc_otg_pcd_ep_t *get_ep_by_addr(dwc_otg_pcd_t * pcd, u16 wIndex)
  111208. +{
  111209. + dwc_otg_pcd_ep_t *ep;
  111210. + uint32_t ep_num = UE_GET_ADDR(wIndex);
  111211. +
  111212. + if (ep_num == 0) {
  111213. + ep = &pcd->ep0;
  111214. + } else if (UE_GET_DIR(wIndex) == UE_DIR_IN) { /* in ep */
  111215. + ep = &pcd->in_ep[ep_num - 1];
  111216. + } else {
  111217. + ep = &pcd->out_ep[ep_num - 1];
  111218. + }
  111219. +
  111220. + return ep;
  111221. +}
  111222. +
  111223. +/**
  111224. + * This function checks the EP request queue, if the queue is not
  111225. + * empty the next request is started.
  111226. + */
  111227. +void start_next_request(dwc_otg_pcd_ep_t * ep)
  111228. +{
  111229. + dwc_otg_pcd_request_t *req = 0;
  111230. + uint32_t max_transfer =
  111231. + GET_CORE_IF(ep->pcd)->core_params->max_transfer_size;
  111232. +
  111233. +#ifdef DWC_UTE_CFI
  111234. + struct dwc_otg_pcd *pcd;
  111235. + pcd = ep->pcd;
  111236. +#endif
  111237. +
  111238. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  111239. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  111240. +
  111241. +#ifdef DWC_UTE_CFI
  111242. + if (ep->dwc_ep.buff_mode != BM_STANDARD) {
  111243. + ep->dwc_ep.cfi_req_len = req->length;
  111244. + pcd->cfi->ops.build_descriptors(pcd->cfi, pcd, ep, req);
  111245. + } else {
  111246. +#endif
  111247. + /* Setup and start the Transfer */
  111248. + if (req->dw_align_buf) {
  111249. + ep->dwc_ep.dma_addr = req->dw_align_buf_dma;
  111250. + ep->dwc_ep.start_xfer_buff = req->dw_align_buf;
  111251. + ep->dwc_ep.xfer_buff = req->dw_align_buf;
  111252. + } else {
  111253. + ep->dwc_ep.dma_addr = req->dma;
  111254. + ep->dwc_ep.start_xfer_buff = req->buf;
  111255. + ep->dwc_ep.xfer_buff = req->buf;
  111256. + }
  111257. + ep->dwc_ep.sent_zlp = 0;
  111258. + ep->dwc_ep.total_len = req->length;
  111259. + ep->dwc_ep.xfer_len = 0;
  111260. + ep->dwc_ep.xfer_count = 0;
  111261. +
  111262. + ep->dwc_ep.maxxfer = max_transfer;
  111263. + if (GET_CORE_IF(ep->pcd)->dma_desc_enable) {
  111264. + uint32_t out_max_xfer = DDMA_MAX_TRANSFER_SIZE
  111265. + - (DDMA_MAX_TRANSFER_SIZE % 4);
  111266. + if (ep->dwc_ep.is_in) {
  111267. + if (ep->dwc_ep.maxxfer >
  111268. + DDMA_MAX_TRANSFER_SIZE) {
  111269. + ep->dwc_ep.maxxfer =
  111270. + DDMA_MAX_TRANSFER_SIZE;
  111271. + }
  111272. + } else {
  111273. + if (ep->dwc_ep.maxxfer > out_max_xfer) {
  111274. + ep->dwc_ep.maxxfer =
  111275. + out_max_xfer;
  111276. + }
  111277. + }
  111278. + }
  111279. + if (ep->dwc_ep.maxxfer < ep->dwc_ep.total_len) {
  111280. + ep->dwc_ep.maxxfer -=
  111281. + (ep->dwc_ep.maxxfer % ep->dwc_ep.maxpacket);
  111282. + }
  111283. + if (req->sent_zlp) {
  111284. + if ((ep->dwc_ep.total_len %
  111285. + ep->dwc_ep.maxpacket == 0)
  111286. + && (ep->dwc_ep.total_len != 0)) {
  111287. + ep->dwc_ep.sent_zlp = 1;
  111288. + }
  111289. +
  111290. + }
  111291. +#ifdef DWC_UTE_CFI
  111292. + }
  111293. +#endif
  111294. + dwc_otg_ep_start_transfer(GET_CORE_IF(ep->pcd), &ep->dwc_ep);
  111295. + } else if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  111296. + DWC_PRINTF("There are no more ISOC requests \n");
  111297. + ep->dwc_ep.frame_num = 0xFFFFFFFF;
  111298. + }
  111299. +}
  111300. +
  111301. +/**
  111302. + * This function handles the SOF Interrupts. At this time the SOF
  111303. + * Interrupt is disabled.
  111304. + */
  111305. +int32_t dwc_otg_pcd_handle_sof_intr(dwc_otg_pcd_t * pcd)
  111306. +{
  111307. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  111308. +
  111309. + gintsts_data_t gintsts;
  111310. +
  111311. + DWC_DEBUGPL(DBG_PCD, "SOF\n");
  111312. +
  111313. + /* Clear interrupt */
  111314. + gintsts.d32 = 0;
  111315. + gintsts.b.sofintr = 1;
  111316. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  111317. +
  111318. + return 1;
  111319. +}
  111320. +
  111321. +/**
  111322. + * This function handles the Rx Status Queue Level Interrupt, which
  111323. + * indicates that there is a least one packet in the Rx FIFO. The
  111324. + * packets are moved from the FIFO to memory, where they will be
  111325. + * processed when the Endpoint Interrupt Register indicates Transfer
  111326. + * Complete or SETUP Phase Done.
  111327. + *
  111328. + * Repeat the following until the Rx Status Queue is empty:
  111329. + * -# Read the Receive Status Pop Register (GRXSTSP) to get Packet
  111330. + * info
  111331. + * -# If Receive FIFO is empty then skip to step Clear the interrupt
  111332. + * and exit
  111333. + * -# If SETUP Packet call dwc_otg_read_setup_packet to copy the
  111334. + * SETUP data to the buffer
  111335. + * -# If OUT Data Packet call dwc_otg_read_packet to copy the data
  111336. + * to the destination buffer
  111337. + */
  111338. +int32_t dwc_otg_pcd_handle_rx_status_q_level_intr(dwc_otg_pcd_t * pcd)
  111339. +{
  111340. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  111341. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  111342. + gintmsk_data_t gintmask = {.d32 = 0 };
  111343. + device_grxsts_data_t status;
  111344. + dwc_otg_pcd_ep_t *ep;
  111345. + gintsts_data_t gintsts;
  111346. +#ifdef DEBUG
  111347. + static char *dpid_str[] = { "D0", "D2", "D1", "MDATA" };
  111348. +#endif
  111349. +
  111350. + //DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, _pcd);
  111351. + /* Disable the Rx Status Queue Level interrupt */
  111352. + gintmask.b.rxstsqlvl = 1;
  111353. + DWC_MODIFY_REG32(&global_regs->gintmsk, gintmask.d32, 0);
  111354. +
  111355. + /* Get the Status from the top of the FIFO */
  111356. + status.d32 = DWC_READ_REG32(&global_regs->grxstsp);
  111357. +
  111358. + DWC_DEBUGPL(DBG_PCD, "EP:%d BCnt:%d DPID:%s "
  111359. + "pktsts:%x Frame:%d(0x%0x)\n",
  111360. + status.b.epnum, status.b.bcnt,
  111361. + dpid_str[status.b.dpid],
  111362. + status.b.pktsts, status.b.fn, status.b.fn);
  111363. + /* Get pointer to EP structure */
  111364. + ep = get_out_ep(pcd, status.b.epnum);
  111365. +
  111366. + switch (status.b.pktsts) {
  111367. + case DWC_DSTS_GOUT_NAK:
  111368. + DWC_DEBUGPL(DBG_PCDV, "Global OUT NAK\n");
  111369. + break;
  111370. + case DWC_STS_DATA_UPDT:
  111371. + DWC_DEBUGPL(DBG_PCDV, "OUT Data Packet\n");
  111372. + if (status.b.bcnt && ep->dwc_ep.xfer_buff) {
  111373. + /** @todo NGS Check for buffer overflow? */
  111374. + dwc_otg_read_packet(core_if,
  111375. + ep->dwc_ep.xfer_buff,
  111376. + status.b.bcnt);
  111377. + ep->dwc_ep.xfer_count += status.b.bcnt;
  111378. + ep->dwc_ep.xfer_buff += status.b.bcnt;
  111379. + }
  111380. + break;
  111381. + case DWC_STS_XFER_COMP:
  111382. + DWC_DEBUGPL(DBG_PCDV, "OUT Complete\n");
  111383. + break;
  111384. + case DWC_DSTS_SETUP_COMP:
  111385. +#ifdef DEBUG_EP0
  111386. + DWC_DEBUGPL(DBG_PCDV, "Setup Complete\n");
  111387. +#endif
  111388. + break;
  111389. + case DWC_DSTS_SETUP_UPDT:
  111390. + dwc_otg_read_setup_packet(core_if, pcd->setup_pkt->d32);
  111391. +#ifdef DEBUG_EP0
  111392. + DWC_DEBUGPL(DBG_PCD,
  111393. + "SETUP PKT: %02x.%02x v%04x i%04x l%04x\n",
  111394. + pcd->setup_pkt->req.bmRequestType,
  111395. + pcd->setup_pkt->req.bRequest,
  111396. + UGETW(pcd->setup_pkt->req.wValue),
  111397. + UGETW(pcd->setup_pkt->req.wIndex),
  111398. + UGETW(pcd->setup_pkt->req.wLength));
  111399. +#endif
  111400. + ep->dwc_ep.xfer_count += status.b.bcnt;
  111401. + break;
  111402. + default:
  111403. + DWC_DEBUGPL(DBG_PCDV, "Invalid Packet Status (0x%0x)\n",
  111404. + status.b.pktsts);
  111405. + break;
  111406. + }
  111407. +
  111408. + /* Enable the Rx Status Queue Level interrupt */
  111409. + DWC_MODIFY_REG32(&global_regs->gintmsk, 0, gintmask.d32);
  111410. + /* Clear interrupt */
  111411. + gintsts.d32 = 0;
  111412. + gintsts.b.rxstsqlvl = 1;
  111413. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  111414. +
  111415. + //DWC_DEBUGPL(DBG_PCDV, "EXIT: %s\n", __func__);
  111416. + return 1;
  111417. +}
  111418. +
  111419. +/**
  111420. + * This function examines the Device IN Token Learning Queue to
  111421. + * determine the EP number of the last IN token received. This
  111422. + * implementation is for the Mass Storage device where there are only
  111423. + * 2 IN EPs (Control-IN and BULK-IN).
  111424. + *
  111425. + * The EP numbers for the first six IN Tokens are in DTKNQR1 and there
  111426. + * are 8 EP Numbers in each of the other possible DTKNQ Registers.
  111427. + *
  111428. + * @param core_if Programming view of DWC_otg controller.
  111429. + *
  111430. + */
  111431. +static inline int get_ep_of_last_in_token(dwc_otg_core_if_t * core_if)
  111432. +{
  111433. + dwc_otg_device_global_regs_t *dev_global_regs =
  111434. + core_if->dev_if->dev_global_regs;
  111435. + const uint32_t TOKEN_Q_DEPTH = core_if->hwcfg2.b.dev_token_q_depth;
  111436. + /* Number of Token Queue Registers */
  111437. + const int DTKNQ_REG_CNT = (TOKEN_Q_DEPTH + 7) / 8;
  111438. + dtknq1_data_t dtknqr1;
  111439. + uint32_t in_tkn_epnums[4];
  111440. + int ndx = 0;
  111441. + int i = 0;
  111442. + volatile uint32_t *addr = &dev_global_regs->dtknqr1;
  111443. + int epnum = 0;
  111444. +
  111445. + //DWC_DEBUGPL(DBG_PCD,"dev_token_q_depth=%d\n",TOKEN_Q_DEPTH);
  111446. +
  111447. + /* Read the DTKNQ Registers */
  111448. + for (i = 0; i < DTKNQ_REG_CNT; i++) {
  111449. + in_tkn_epnums[i] = DWC_READ_REG32(addr);
  111450. + DWC_DEBUGPL(DBG_PCDV, "DTKNQR%d=0x%08x\n", i + 1,
  111451. + in_tkn_epnums[i]);
  111452. + if (addr == &dev_global_regs->dvbusdis) {
  111453. + addr = &dev_global_regs->dtknqr3_dthrctl;
  111454. + } else {
  111455. + ++addr;
  111456. + }
  111457. +
  111458. + }
  111459. +
  111460. + /* Copy the DTKNQR1 data to the bit field. */
  111461. + dtknqr1.d32 = in_tkn_epnums[0];
  111462. + /* Get the EP numbers */
  111463. + in_tkn_epnums[0] = dtknqr1.b.epnums0_5;
  111464. + ndx = dtknqr1.b.intknwptr - 1;
  111465. +
  111466. + //DWC_DEBUGPL(DBG_PCDV,"ndx=%d\n",ndx);
  111467. + if (ndx == -1) {
  111468. + /** @todo Find a simpler way to calculate the max
  111469. + * queue position.*/
  111470. + int cnt = TOKEN_Q_DEPTH;
  111471. + if (TOKEN_Q_DEPTH <= 6) {
  111472. + cnt = TOKEN_Q_DEPTH - 1;
  111473. + } else if (TOKEN_Q_DEPTH <= 14) {
  111474. + cnt = TOKEN_Q_DEPTH - 7;
  111475. + } else if (TOKEN_Q_DEPTH <= 22) {
  111476. + cnt = TOKEN_Q_DEPTH - 15;
  111477. + } else {
  111478. + cnt = TOKEN_Q_DEPTH - 23;
  111479. + }
  111480. + epnum = (in_tkn_epnums[DTKNQ_REG_CNT - 1] >> (cnt * 4)) & 0xF;
  111481. + } else {
  111482. + if (ndx <= 5) {
  111483. + epnum = (in_tkn_epnums[0] >> (ndx * 4)) & 0xF;
  111484. + } else if (ndx <= 13) {
  111485. + ndx -= 6;
  111486. + epnum = (in_tkn_epnums[1] >> (ndx * 4)) & 0xF;
  111487. + } else if (ndx <= 21) {
  111488. + ndx -= 14;
  111489. + epnum = (in_tkn_epnums[2] >> (ndx * 4)) & 0xF;
  111490. + } else if (ndx <= 29) {
  111491. + ndx -= 22;
  111492. + epnum = (in_tkn_epnums[3] >> (ndx * 4)) & 0xF;
  111493. + }
  111494. + }
  111495. + //DWC_DEBUGPL(DBG_PCD,"epnum=%d\n",epnum);
  111496. + return epnum;
  111497. +}
  111498. +
  111499. +/**
  111500. + * This interrupt occurs when the non-periodic Tx FIFO is half-empty.
  111501. + * The active request is checked for the next packet to be loaded into
  111502. + * the non-periodic Tx FIFO.
  111503. + */
  111504. +int32_t dwc_otg_pcd_handle_np_tx_fifo_empty_intr(dwc_otg_pcd_t * pcd)
  111505. +{
  111506. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  111507. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  111508. + dwc_otg_dev_in_ep_regs_t *ep_regs;
  111509. + gnptxsts_data_t txstatus = {.d32 = 0 };
  111510. + gintsts_data_t gintsts;
  111511. +
  111512. + int epnum = 0;
  111513. + dwc_otg_pcd_ep_t *ep = 0;
  111514. + uint32_t len = 0;
  111515. + int dwords;
  111516. +
  111517. + /* Get the epnum from the IN Token Learning Queue. */
  111518. + epnum = get_ep_of_last_in_token(core_if);
  111519. + ep = get_in_ep(pcd, epnum);
  111520. +
  111521. + DWC_DEBUGPL(DBG_PCD, "NP TxFifo Empty: %d \n", epnum);
  111522. +
  111523. + ep_regs = core_if->dev_if->in_ep_regs[epnum];
  111524. +
  111525. + len = ep->dwc_ep.xfer_len - ep->dwc_ep.xfer_count;
  111526. + if (len > ep->dwc_ep.maxpacket) {
  111527. + len = ep->dwc_ep.maxpacket;
  111528. + }
  111529. + dwords = (len + 3) / 4;
  111530. +
  111531. + /* While there is space in the queue and space in the FIFO and
  111532. + * More data to tranfer, Write packets to the Tx FIFO */
  111533. + txstatus.d32 = DWC_READ_REG32(&global_regs->gnptxsts);
  111534. + DWC_DEBUGPL(DBG_PCDV, "b4 GNPTXSTS=0x%08x\n", txstatus.d32);
  111535. +
  111536. + while (txstatus.b.nptxqspcavail > 0 &&
  111537. + txstatus.b.nptxfspcavail > dwords &&
  111538. + ep->dwc_ep.xfer_count < ep->dwc_ep.xfer_len) {
  111539. + /* Write the FIFO */
  111540. + dwc_otg_ep_write_packet(core_if, &ep->dwc_ep, 0);
  111541. + len = ep->dwc_ep.xfer_len - ep->dwc_ep.xfer_count;
  111542. +
  111543. + if (len > ep->dwc_ep.maxpacket) {
  111544. + len = ep->dwc_ep.maxpacket;
  111545. + }
  111546. +
  111547. + dwords = (len + 3) / 4;
  111548. + txstatus.d32 = DWC_READ_REG32(&global_regs->gnptxsts);
  111549. + DWC_DEBUGPL(DBG_PCDV, "GNPTXSTS=0x%08x\n", txstatus.d32);
  111550. + }
  111551. +
  111552. + DWC_DEBUGPL(DBG_PCDV, "GNPTXSTS=0x%08x\n",
  111553. + DWC_READ_REG32(&global_regs->gnptxsts));
  111554. +
  111555. + /* Clear interrupt */
  111556. + gintsts.d32 = 0;
  111557. + gintsts.b.nptxfempty = 1;
  111558. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  111559. +
  111560. + return 1;
  111561. +}
  111562. +
  111563. +/**
  111564. + * This function is called when dedicated Tx FIFO Empty interrupt occurs.
  111565. + * The active request is checked for the next packet to be loaded into
  111566. + * apropriate Tx FIFO.
  111567. + */
  111568. +static int32_t write_empty_tx_fifo(dwc_otg_pcd_t * pcd, uint32_t epnum)
  111569. +{
  111570. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  111571. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  111572. + dwc_otg_dev_in_ep_regs_t *ep_regs;
  111573. + dtxfsts_data_t txstatus = {.d32 = 0 };
  111574. + dwc_otg_pcd_ep_t *ep = 0;
  111575. + uint32_t len = 0;
  111576. + int dwords;
  111577. +
  111578. + ep = get_in_ep(pcd, epnum);
  111579. +
  111580. + DWC_DEBUGPL(DBG_PCD, "Dedicated TxFifo Empty: %d \n", epnum);
  111581. +
  111582. + ep_regs = core_if->dev_if->in_ep_regs[epnum];
  111583. +
  111584. + len = ep->dwc_ep.xfer_len - ep->dwc_ep.xfer_count;
  111585. +
  111586. + if (len > ep->dwc_ep.maxpacket) {
  111587. + len = ep->dwc_ep.maxpacket;
  111588. + }
  111589. +
  111590. + dwords = (len + 3) / 4;
  111591. +
  111592. + /* While there is space in the queue and space in the FIFO and
  111593. + * More data to tranfer, Write packets to the Tx FIFO */
  111594. + txstatus.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dtxfsts);
  111595. + DWC_DEBUGPL(DBG_PCDV, "b4 dtxfsts[%d]=0x%08x\n", epnum, txstatus.d32);
  111596. +
  111597. + while (txstatus.b.txfspcavail > dwords &&
  111598. + ep->dwc_ep.xfer_count < ep->dwc_ep.xfer_len &&
  111599. + ep->dwc_ep.xfer_len != 0) {
  111600. + /* Write the FIFO */
  111601. + dwc_otg_ep_write_packet(core_if, &ep->dwc_ep, 0);
  111602. +
  111603. + len = ep->dwc_ep.xfer_len - ep->dwc_ep.xfer_count;
  111604. + if (len > ep->dwc_ep.maxpacket) {
  111605. + len = ep->dwc_ep.maxpacket;
  111606. + }
  111607. +
  111608. + dwords = (len + 3) / 4;
  111609. + txstatus.d32 =
  111610. + DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dtxfsts);
  111611. + DWC_DEBUGPL(DBG_PCDV, "dtxfsts[%d]=0x%08x\n", epnum,
  111612. + txstatus.d32);
  111613. + }
  111614. +
  111615. + DWC_DEBUGPL(DBG_PCDV, "b4 dtxfsts[%d]=0x%08x\n", epnum,
  111616. + DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dtxfsts));
  111617. +
  111618. + return 1;
  111619. +}
  111620. +
  111621. +/**
  111622. + * This function is called when the Device is disconnected. It stops
  111623. + * any active requests and informs the Gadget driver of the
  111624. + * disconnect.
  111625. + */
  111626. +void dwc_otg_pcd_stop(dwc_otg_pcd_t * pcd)
  111627. +{
  111628. + int i, num_in_eps, num_out_eps;
  111629. + dwc_otg_pcd_ep_t *ep;
  111630. +
  111631. + gintmsk_data_t intr_mask = {.d32 = 0 };
  111632. +
  111633. + DWC_SPINLOCK(pcd->lock);
  111634. +
  111635. + num_in_eps = GET_CORE_IF(pcd)->dev_if->num_in_eps;
  111636. + num_out_eps = GET_CORE_IF(pcd)->dev_if->num_out_eps;
  111637. +
  111638. + DWC_DEBUGPL(DBG_PCDV, "%s() \n", __func__);
  111639. + /* don't disconnect drivers more than once */
  111640. + if (pcd->ep0state == EP0_DISCONNECT) {
  111641. + DWC_DEBUGPL(DBG_ANY, "%s() Already Disconnected\n", __func__);
  111642. + DWC_SPINUNLOCK(pcd->lock);
  111643. + return;
  111644. + }
  111645. + pcd->ep0state = EP0_DISCONNECT;
  111646. +
  111647. + /* Reset the OTG state. */
  111648. + dwc_otg_pcd_update_otg(pcd, 1);
  111649. +
  111650. + /* Disable the NP Tx Fifo Empty Interrupt. */
  111651. + intr_mask.b.nptxfempty = 1;
  111652. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  111653. + intr_mask.d32, 0);
  111654. +
  111655. + /* Flush the FIFOs */
  111656. + /**@todo NGS Flush Periodic FIFOs */
  111657. + dwc_otg_flush_tx_fifo(GET_CORE_IF(pcd), 0x10);
  111658. + dwc_otg_flush_rx_fifo(GET_CORE_IF(pcd));
  111659. +
  111660. + /* prevent new request submissions, kill any outstanding requests */
  111661. + ep = &pcd->ep0;
  111662. + dwc_otg_request_nuke(ep);
  111663. + /* prevent new request submissions, kill any outstanding requests */
  111664. + for (i = 0; i < num_in_eps; i++) {
  111665. + dwc_otg_pcd_ep_t *ep = &pcd->in_ep[i];
  111666. + dwc_otg_request_nuke(ep);
  111667. + }
  111668. + /* prevent new request submissions, kill any outstanding requests */
  111669. + for (i = 0; i < num_out_eps; i++) {
  111670. + dwc_otg_pcd_ep_t *ep = &pcd->out_ep[i];
  111671. + dwc_otg_request_nuke(ep);
  111672. + }
  111673. +
  111674. + /* report disconnect; the driver is already quiesced */
  111675. + if (pcd->fops->disconnect) {
  111676. + DWC_SPINUNLOCK(pcd->lock);
  111677. + pcd->fops->disconnect(pcd);
  111678. + DWC_SPINLOCK(pcd->lock);
  111679. + }
  111680. + DWC_SPINUNLOCK(pcd->lock);
  111681. +}
  111682. +
  111683. +/**
  111684. + * This interrupt indicates that ...
  111685. + */
  111686. +int32_t dwc_otg_pcd_handle_i2c_intr(dwc_otg_pcd_t * pcd)
  111687. +{
  111688. + gintmsk_data_t intr_mask = {.d32 = 0 };
  111689. + gintsts_data_t gintsts;
  111690. +
  111691. + DWC_PRINTF("INTERRUPT Handler not implemented for %s\n", "i2cintr");
  111692. + intr_mask.b.i2cintr = 1;
  111693. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  111694. + intr_mask.d32, 0);
  111695. +
  111696. + /* Clear interrupt */
  111697. + gintsts.d32 = 0;
  111698. + gintsts.b.i2cintr = 1;
  111699. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  111700. + gintsts.d32);
  111701. + return 1;
  111702. +}
  111703. +
  111704. +/**
  111705. + * This interrupt indicates that ...
  111706. + */
  111707. +int32_t dwc_otg_pcd_handle_early_suspend_intr(dwc_otg_pcd_t * pcd)
  111708. +{
  111709. + gintsts_data_t gintsts;
  111710. +#if defined(VERBOSE)
  111711. + DWC_PRINTF("Early Suspend Detected\n");
  111712. +#endif
  111713. +
  111714. + /* Clear interrupt */
  111715. + gintsts.d32 = 0;
  111716. + gintsts.b.erlysuspend = 1;
  111717. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  111718. + gintsts.d32);
  111719. + return 1;
  111720. +}
  111721. +
  111722. +/**
  111723. + * This function configures EPO to receive SETUP packets.
  111724. + *
  111725. + * @todo NGS: Update the comments from the HW FS.
  111726. + *
  111727. + * -# Program the following fields in the endpoint specific registers
  111728. + * for Control OUT EP 0, in order to receive a setup packet
  111729. + * - DOEPTSIZ0.Packet Count = 3 (To receive up to 3 back to back
  111730. + * setup packets)
  111731. + * - DOEPTSIZE0.Transfer Size = 24 Bytes (To receive up to 3 back
  111732. + * to back setup packets)
  111733. + * - In DMA mode, DOEPDMA0 Register with a memory address to
  111734. + * store any setup packets received
  111735. + *
  111736. + * @param core_if Programming view of DWC_otg controller.
  111737. + * @param pcd Programming view of the PCD.
  111738. + */
  111739. +static inline void ep0_out_start(dwc_otg_core_if_t * core_if,
  111740. + dwc_otg_pcd_t * pcd)
  111741. +{
  111742. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  111743. + deptsiz0_data_t doeptsize0 = {.d32 = 0 };
  111744. + dwc_otg_dev_dma_desc_t *dma_desc;
  111745. + depctl_data_t doepctl = {.d32 = 0 };
  111746. +
  111747. +#ifdef VERBOSE
  111748. + DWC_DEBUGPL(DBG_PCDV, "%s() doepctl0=%0x\n", __func__,
  111749. + DWC_READ_REG32(&dev_if->out_ep_regs[0]->doepctl));
  111750. +#endif
  111751. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  111752. + doepctl.d32 = DWC_READ_REG32(&dev_if->out_ep_regs[0]->doepctl);
  111753. + if (doepctl.b.epena) {
  111754. + return;
  111755. + }
  111756. + }
  111757. +
  111758. + doeptsize0.b.supcnt = 3;
  111759. + doeptsize0.b.pktcnt = 1;
  111760. + doeptsize0.b.xfersize = 8 * 3;
  111761. +
  111762. + if (core_if->dma_enable) {
  111763. + if (!core_if->dma_desc_enable) {
  111764. + /** put here as for Hermes mode deptisz register should not be written */
  111765. + DWC_WRITE_REG32(&dev_if->out_ep_regs[0]->doeptsiz,
  111766. + doeptsize0.d32);
  111767. +
  111768. + /** @todo dma needs to handle multiple setup packets (up to 3) */
  111769. + DWC_WRITE_REG32(&dev_if->out_ep_regs[0]->doepdma,
  111770. + pcd->setup_pkt_dma_handle);
  111771. + } else {
  111772. + dev_if->setup_desc_index =
  111773. + (dev_if->setup_desc_index + 1) & 1;
  111774. + dma_desc =
  111775. + dev_if->setup_desc_addr[dev_if->setup_desc_index];
  111776. +
  111777. + /** DMA Descriptor Setup */
  111778. + dma_desc->status.b.bs = BS_HOST_BUSY;
  111779. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  111780. + dma_desc->status.b.sr = 0;
  111781. + dma_desc->status.b.mtrf = 0;
  111782. + }
  111783. + dma_desc->status.b.l = 1;
  111784. + dma_desc->status.b.ioc = 1;
  111785. + dma_desc->status.b.bytes = pcd->ep0.dwc_ep.maxpacket;
  111786. + dma_desc->buf = pcd->setup_pkt_dma_handle;
  111787. + dma_desc->status.b.sts = 0;
  111788. + dma_desc->status.b.bs = BS_HOST_READY;
  111789. +
  111790. + /** DOEPDMA0 Register write */
  111791. + DWC_WRITE_REG32(&dev_if->out_ep_regs[0]->doepdma,
  111792. + dev_if->dma_setup_desc_addr
  111793. + [dev_if->setup_desc_index]);
  111794. + }
  111795. +
  111796. + } else {
  111797. + /** put here as for Hermes mode deptisz register should not be written */
  111798. + DWC_WRITE_REG32(&dev_if->out_ep_regs[0]->doeptsiz,
  111799. + doeptsize0.d32);
  111800. + }
  111801. +
  111802. + /** DOEPCTL0 Register write cnak will be set after setup interrupt */
  111803. + doepctl.d32 = 0;
  111804. + doepctl.b.epena = 1;
  111805. + if (core_if->snpsid <= OTG_CORE_REV_2_94a) {
  111806. + doepctl.b.cnak = 1;
  111807. + DWC_WRITE_REG32(&dev_if->out_ep_regs[0]->doepctl, doepctl.d32);
  111808. + } else {
  111809. + DWC_MODIFY_REG32(&dev_if->out_ep_regs[0]->doepctl, 0, doepctl.d32);
  111810. + }
  111811. +
  111812. +#ifdef VERBOSE
  111813. + DWC_DEBUGPL(DBG_PCDV, "doepctl0=%0x\n",
  111814. + DWC_READ_REG32(&dev_if->out_ep_regs[0]->doepctl));
  111815. + DWC_DEBUGPL(DBG_PCDV, "diepctl0=%0x\n",
  111816. + DWC_READ_REG32(&dev_if->in_ep_regs[0]->diepctl));
  111817. +#endif
  111818. +}
  111819. +
  111820. +/**
  111821. + * This interrupt occurs when a USB Reset is detected. When the USB
  111822. + * Reset Interrupt occurs the device state is set to DEFAULT and the
  111823. + * EP0 state is set to IDLE.
  111824. + * -# Set the NAK bit for all OUT endpoints (DOEPCTLn.SNAK = 1)
  111825. + * -# Unmask the following interrupt bits
  111826. + * - DAINTMSK.INEP0 = 1 (Control 0 IN endpoint)
  111827. + * - DAINTMSK.OUTEP0 = 1 (Control 0 OUT endpoint)
  111828. + * - DOEPMSK.SETUP = 1
  111829. + * - DOEPMSK.XferCompl = 1
  111830. + * - DIEPMSK.XferCompl = 1
  111831. + * - DIEPMSK.TimeOut = 1
  111832. + * -# Program the following fields in the endpoint specific registers
  111833. + * for Control OUT EP 0, in order to receive a setup packet
  111834. + * - DOEPTSIZ0.Packet Count = 3 (To receive up to 3 back to back
  111835. + * setup packets)
  111836. + * - DOEPTSIZE0.Transfer Size = 24 Bytes (To receive up to 3 back
  111837. + * to back setup packets)
  111838. + * - In DMA mode, DOEPDMA0 Register with a memory address to
  111839. + * store any setup packets received
  111840. + * At this point, all the required initialization, except for enabling
  111841. + * the control 0 OUT endpoint is done, for receiving SETUP packets.
  111842. + */
  111843. +int32_t dwc_otg_pcd_handle_usb_reset_intr(dwc_otg_pcd_t * pcd)
  111844. +{
  111845. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  111846. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  111847. + depctl_data_t doepctl = {.d32 = 0 };
  111848. + depctl_data_t diepctl = {.d32 = 0 };
  111849. + daint_data_t daintmsk = {.d32 = 0 };
  111850. + doepmsk_data_t doepmsk = {.d32 = 0 };
  111851. + diepmsk_data_t diepmsk = {.d32 = 0 };
  111852. + dcfg_data_t dcfg = {.d32 = 0 };
  111853. + grstctl_t resetctl = {.d32 = 0 };
  111854. + dctl_data_t dctl = {.d32 = 0 };
  111855. + int i = 0;
  111856. + gintsts_data_t gintsts;
  111857. + pcgcctl_data_t power = {.d32 = 0 };
  111858. +
  111859. + power.d32 = DWC_READ_REG32(core_if->pcgcctl);
  111860. + if (power.b.stoppclk) {
  111861. + power.d32 = 0;
  111862. + power.b.stoppclk = 1;
  111863. + DWC_MODIFY_REG32(core_if->pcgcctl, power.d32, 0);
  111864. +
  111865. + power.b.pwrclmp = 1;
  111866. + DWC_MODIFY_REG32(core_if->pcgcctl, power.d32, 0);
  111867. +
  111868. + power.b.rstpdwnmodule = 1;
  111869. + DWC_MODIFY_REG32(core_if->pcgcctl, power.d32, 0);
  111870. + }
  111871. +
  111872. + core_if->lx_state = DWC_OTG_L0;
  111873. +
  111874. + DWC_PRINTF("USB RESET\n");
  111875. +#ifdef DWC_EN_ISOC
  111876. + for (i = 1; i < 16; ++i) {
  111877. + dwc_otg_pcd_ep_t *ep;
  111878. + dwc_ep_t *dwc_ep;
  111879. + ep = get_in_ep(pcd, i);
  111880. + if (ep != 0) {
  111881. + dwc_ep = &ep->dwc_ep;
  111882. + dwc_ep->next_frame = 0xffffffff;
  111883. + }
  111884. + }
  111885. +#endif /* DWC_EN_ISOC */
  111886. +
  111887. + /* reset the HNP settings */
  111888. + dwc_otg_pcd_update_otg(pcd, 1);
  111889. +
  111890. + /* Clear the Remote Wakeup Signalling */
  111891. + dctl.b.rmtwkupsig = 1;
  111892. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32, 0);
  111893. +
  111894. + /* Set NAK for all OUT EPs */
  111895. + doepctl.b.snak = 1;
  111896. + for (i = 0; i <= dev_if->num_out_eps; i++) {
  111897. + DWC_WRITE_REG32(&dev_if->out_ep_regs[i]->doepctl, doepctl.d32);
  111898. + }
  111899. +
  111900. + /* Flush the NP Tx FIFO */
  111901. + dwc_otg_flush_tx_fifo(core_if, 0x10);
  111902. + /* Flush the Learning Queue */
  111903. + resetctl.b.intknqflsh = 1;
  111904. + DWC_WRITE_REG32(&core_if->core_global_regs->grstctl, resetctl.d32);
  111905. +
  111906. + if (!core_if->core_params->en_multiple_tx_fifo && core_if->dma_enable) {
  111907. + core_if->start_predict = 0;
  111908. + for (i = 0; i<= core_if->dev_if->num_in_eps; ++i) {
  111909. + core_if->nextep_seq[i] = 0xff; // 0xff - EP not active
  111910. + }
  111911. + core_if->nextep_seq[0] = 0;
  111912. + core_if->first_in_nextep_seq = 0;
  111913. + diepctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[0]->diepctl);
  111914. + diepctl.b.nextep = 0;
  111915. + DWC_WRITE_REG32(&dev_if->in_ep_regs[0]->diepctl, diepctl.d32);
  111916. +
  111917. + /* Update IN Endpoint Mismatch Count by active IN NP EP count + 1 */
  111918. + dcfg.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dcfg);
  111919. + dcfg.b.epmscnt = 2;
  111920. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dcfg, dcfg.d32);
  111921. +
  111922. + DWC_DEBUGPL(DBG_PCDV,
  111923. + "%s first_in_nextep_seq= %2d; nextep_seq[]:\n",
  111924. + __func__, core_if->first_in_nextep_seq);
  111925. + for (i=0; i <= core_if->dev_if->num_in_eps; i++) {
  111926. + DWC_DEBUGPL(DBG_PCDV, "%2d\n", core_if->nextep_seq[i]);
  111927. + }
  111928. + }
  111929. +
  111930. + if (core_if->multiproc_int_enable) {
  111931. + daintmsk.b.inep0 = 1;
  111932. + daintmsk.b.outep0 = 1;
  111933. + DWC_WRITE_REG32(&dev_if->dev_global_regs->deachintmsk,
  111934. + daintmsk.d32);
  111935. +
  111936. + doepmsk.b.setup = 1;
  111937. + doepmsk.b.xfercompl = 1;
  111938. + doepmsk.b.ahberr = 1;
  111939. + doepmsk.b.epdisabled = 1;
  111940. +
  111941. + if ((core_if->dma_desc_enable) ||
  111942. + (core_if->dma_enable
  111943. + && core_if->snpsid >= OTG_CORE_REV_3_00a)) {
  111944. + doepmsk.b.stsphsercvd = 1;
  111945. + }
  111946. + if (core_if->dma_desc_enable)
  111947. + doepmsk.b.bna = 1;
  111948. +/*
  111949. + doepmsk.b.babble = 1;
  111950. + doepmsk.b.nyet = 1;
  111951. +
  111952. + if (core_if->dma_enable) {
  111953. + doepmsk.b.nak = 1;
  111954. + }
  111955. +*/
  111956. + DWC_WRITE_REG32(&dev_if->dev_global_regs->doepeachintmsk[0],
  111957. + doepmsk.d32);
  111958. +
  111959. + diepmsk.b.xfercompl = 1;
  111960. + diepmsk.b.timeout = 1;
  111961. + diepmsk.b.epdisabled = 1;
  111962. + diepmsk.b.ahberr = 1;
  111963. + diepmsk.b.intknepmis = 1;
  111964. + if (!core_if->en_multiple_tx_fifo && core_if->dma_enable)
  111965. + diepmsk.b.intknepmis = 0;
  111966. +
  111967. +/* if (core_if->dma_desc_enable) {
  111968. + diepmsk.b.bna = 1;
  111969. + }
  111970. +*/
  111971. +/*
  111972. + if (core_if->dma_enable) {
  111973. + diepmsk.b.nak = 1;
  111974. + }
  111975. +*/
  111976. + DWC_WRITE_REG32(&dev_if->dev_global_regs->diepeachintmsk[0],
  111977. + diepmsk.d32);
  111978. + } else {
  111979. + daintmsk.b.inep0 = 1;
  111980. + daintmsk.b.outep0 = 1;
  111981. + DWC_WRITE_REG32(&dev_if->dev_global_regs->daintmsk,
  111982. + daintmsk.d32);
  111983. +
  111984. + doepmsk.b.setup = 1;
  111985. + doepmsk.b.xfercompl = 1;
  111986. + doepmsk.b.ahberr = 1;
  111987. + doepmsk.b.epdisabled = 1;
  111988. +
  111989. + if ((core_if->dma_desc_enable) ||
  111990. + (core_if->dma_enable
  111991. + && core_if->snpsid >= OTG_CORE_REV_3_00a)) {
  111992. + doepmsk.b.stsphsercvd = 1;
  111993. + }
  111994. + if (core_if->dma_desc_enable)
  111995. + doepmsk.b.bna = 1;
  111996. + DWC_WRITE_REG32(&dev_if->dev_global_regs->doepmsk, doepmsk.d32);
  111997. +
  111998. + diepmsk.b.xfercompl = 1;
  111999. + diepmsk.b.timeout = 1;
  112000. + diepmsk.b.epdisabled = 1;
  112001. + diepmsk.b.ahberr = 1;
  112002. + if (!core_if->en_multiple_tx_fifo && core_if->dma_enable)
  112003. + diepmsk.b.intknepmis = 0;
  112004. +/*
  112005. + if (core_if->dma_desc_enable) {
  112006. + diepmsk.b.bna = 1;
  112007. + }
  112008. +*/
  112009. +
  112010. + DWC_WRITE_REG32(&dev_if->dev_global_regs->diepmsk, diepmsk.d32);
  112011. + }
  112012. +
  112013. + /* Reset Device Address */
  112014. + dcfg.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dcfg);
  112015. + dcfg.b.devaddr = 0;
  112016. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dcfg, dcfg.d32);
  112017. +
  112018. + /* setup EP0 to receive SETUP packets */
  112019. + if (core_if->snpsid <= OTG_CORE_REV_2_94a)
  112020. + ep0_out_start(core_if, pcd);
  112021. +
  112022. + /* Clear interrupt */
  112023. + gintsts.d32 = 0;
  112024. + gintsts.b.usbreset = 1;
  112025. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  112026. +
  112027. + return 1;
  112028. +}
  112029. +
  112030. +/**
  112031. + * Get the device speed from the device status register and convert it
  112032. + * to USB speed constant.
  112033. + *
  112034. + * @param core_if Programming view of DWC_otg controller.
  112035. + */
  112036. +static int get_device_speed(dwc_otg_core_if_t * core_if)
  112037. +{
  112038. + dsts_data_t dsts;
  112039. + int speed = 0;
  112040. + dsts.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  112041. +
  112042. + switch (dsts.b.enumspd) {
  112043. + case DWC_DSTS_ENUMSPD_HS_PHY_30MHZ_OR_60MHZ:
  112044. + speed = USB_SPEED_HIGH;
  112045. + break;
  112046. + case DWC_DSTS_ENUMSPD_FS_PHY_30MHZ_OR_60MHZ:
  112047. + case DWC_DSTS_ENUMSPD_FS_PHY_48MHZ:
  112048. + speed = USB_SPEED_FULL;
  112049. + break;
  112050. +
  112051. + case DWC_DSTS_ENUMSPD_LS_PHY_6MHZ:
  112052. + speed = USB_SPEED_LOW;
  112053. + break;
  112054. + }
  112055. +
  112056. + return speed;
  112057. +}
  112058. +
  112059. +/**
  112060. + * Read the device status register and set the device speed in the
  112061. + * data structure.
  112062. + * Set up EP0 to receive SETUP packets by calling dwc_ep0_activate.
  112063. + */
  112064. +int32_t dwc_otg_pcd_handle_enum_done_intr(dwc_otg_pcd_t * pcd)
  112065. +{
  112066. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  112067. + gintsts_data_t gintsts;
  112068. + gusbcfg_data_t gusbcfg;
  112069. + dwc_otg_core_global_regs_t *global_regs =
  112070. + GET_CORE_IF(pcd)->core_global_regs;
  112071. + uint8_t utmi16b, utmi8b;
  112072. + int speed;
  112073. + DWC_DEBUGPL(DBG_PCD, "SPEED ENUM\n");
  112074. +
  112075. + if (GET_CORE_IF(pcd)->snpsid >= OTG_CORE_REV_2_60a) {
  112076. + utmi16b = 6; //vahrama old value was 6;
  112077. + utmi8b = 9;
  112078. + } else {
  112079. + utmi16b = 4;
  112080. + utmi8b = 8;
  112081. + }
  112082. + dwc_otg_ep0_activate(GET_CORE_IF(pcd), &ep0->dwc_ep);
  112083. + if (GET_CORE_IF(pcd)->snpsid >= OTG_CORE_REV_3_00a) {
  112084. + ep0_out_start(GET_CORE_IF(pcd), pcd);
  112085. + }
  112086. +
  112087. +#ifdef DEBUG_EP0
  112088. + print_ep0_state(pcd);
  112089. +#endif
  112090. +
  112091. + if (pcd->ep0state == EP0_DISCONNECT) {
  112092. + pcd->ep0state = EP0_IDLE;
  112093. + } else if (pcd->ep0state == EP0_STALL) {
  112094. + pcd->ep0state = EP0_IDLE;
  112095. + }
  112096. +
  112097. + pcd->ep0state = EP0_IDLE;
  112098. +
  112099. + ep0->stopped = 0;
  112100. +
  112101. + speed = get_device_speed(GET_CORE_IF(pcd));
  112102. + pcd->fops->connect(pcd, speed);
  112103. +
  112104. + /* Set USB turnaround time based on device speed and PHY interface. */
  112105. + gusbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  112106. + if (speed == USB_SPEED_HIGH) {
  112107. + if (GET_CORE_IF(pcd)->hwcfg2.b.hs_phy_type ==
  112108. + DWC_HWCFG2_HS_PHY_TYPE_ULPI) {
  112109. + /* ULPI interface */
  112110. + gusbcfg.b.usbtrdtim = 9;
  112111. + }
  112112. + if (GET_CORE_IF(pcd)->hwcfg2.b.hs_phy_type ==
  112113. + DWC_HWCFG2_HS_PHY_TYPE_UTMI) {
  112114. + /* UTMI+ interface */
  112115. + if (GET_CORE_IF(pcd)->hwcfg4.b.utmi_phy_data_width == 0) {
  112116. + gusbcfg.b.usbtrdtim = utmi8b;
  112117. + } else if (GET_CORE_IF(pcd)->hwcfg4.
  112118. + b.utmi_phy_data_width == 1) {
  112119. + gusbcfg.b.usbtrdtim = utmi16b;
  112120. + } else if (GET_CORE_IF(pcd)->
  112121. + core_params->phy_utmi_width == 8) {
  112122. + gusbcfg.b.usbtrdtim = utmi8b;
  112123. + } else {
  112124. + gusbcfg.b.usbtrdtim = utmi16b;
  112125. + }
  112126. + }
  112127. + if (GET_CORE_IF(pcd)->hwcfg2.b.hs_phy_type ==
  112128. + DWC_HWCFG2_HS_PHY_TYPE_UTMI_ULPI) {
  112129. + /* UTMI+ OR ULPI interface */
  112130. + if (gusbcfg.b.ulpi_utmi_sel == 1) {
  112131. + /* ULPI interface */
  112132. + gusbcfg.b.usbtrdtim = 9;
  112133. + } else {
  112134. + /* UTMI+ interface */
  112135. + if (GET_CORE_IF(pcd)->
  112136. + core_params->phy_utmi_width == 16) {
  112137. + gusbcfg.b.usbtrdtim = utmi16b;
  112138. + } else {
  112139. + gusbcfg.b.usbtrdtim = utmi8b;
  112140. + }
  112141. + }
  112142. + }
  112143. + } else {
  112144. + /* Full or low speed */
  112145. + gusbcfg.b.usbtrdtim = 9;
  112146. + }
  112147. + DWC_WRITE_REG32(&global_regs->gusbcfg, gusbcfg.d32);
  112148. +
  112149. + /* Clear interrupt */
  112150. + gintsts.d32 = 0;
  112151. + gintsts.b.enumdone = 1;
  112152. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  112153. + gintsts.d32);
  112154. + return 1;
  112155. +}
  112156. +
  112157. +/**
  112158. + * This interrupt indicates that the ISO OUT Packet was dropped due to
  112159. + * Rx FIFO full or Rx Status Queue Full. If this interrupt occurs
  112160. + * read all the data from the Rx FIFO.
  112161. + */
  112162. +int32_t dwc_otg_pcd_handle_isoc_out_packet_dropped_intr(dwc_otg_pcd_t * pcd)
  112163. +{
  112164. + gintmsk_data_t intr_mask = {.d32 = 0 };
  112165. + gintsts_data_t gintsts;
  112166. +
  112167. + DWC_WARN("INTERRUPT Handler not implemented for %s\n",
  112168. + "ISOC Out Dropped");
  112169. +
  112170. + intr_mask.b.isooutdrop = 1;
  112171. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  112172. + intr_mask.d32, 0);
  112173. +
  112174. + /* Clear interrupt */
  112175. + gintsts.d32 = 0;
  112176. + gintsts.b.isooutdrop = 1;
  112177. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  112178. + gintsts.d32);
  112179. +
  112180. + return 1;
  112181. +}
  112182. +
  112183. +/**
  112184. + * This interrupt indicates the end of the portion of the micro-frame
  112185. + * for periodic transactions. If there is a periodic transaction for
  112186. + * the next frame, load the packets into the EP periodic Tx FIFO.
  112187. + */
  112188. +int32_t dwc_otg_pcd_handle_end_periodic_frame_intr(dwc_otg_pcd_t * pcd)
  112189. +{
  112190. + gintmsk_data_t intr_mask = {.d32 = 0 };
  112191. + gintsts_data_t gintsts;
  112192. + DWC_PRINTF("INTERRUPT Handler not implemented for %s\n", "EOP");
  112193. +
  112194. + intr_mask.b.eopframe = 1;
  112195. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  112196. + intr_mask.d32, 0);
  112197. +
  112198. + /* Clear interrupt */
  112199. + gintsts.d32 = 0;
  112200. + gintsts.b.eopframe = 1;
  112201. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  112202. + gintsts.d32);
  112203. +
  112204. + return 1;
  112205. +}
  112206. +
  112207. +/**
  112208. + * This interrupt indicates that EP of the packet on the top of the
  112209. + * non-periodic Tx FIFO does not match EP of the IN Token received.
  112210. + *
  112211. + * The "Device IN Token Queue" Registers are read to determine the
  112212. + * order the IN Tokens have been received. The non-periodic Tx FIFO
  112213. + * is flushed, so it can be reloaded in the order seen in the IN Token
  112214. + * Queue.
  112215. + */
  112216. +int32_t dwc_otg_pcd_handle_ep_mismatch_intr(dwc_otg_pcd_t * pcd)
  112217. +{
  112218. + gintsts_data_t gintsts;
  112219. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  112220. + dctl_data_t dctl;
  112221. + gintmsk_data_t intr_mask = {.d32 = 0 };
  112222. +
  112223. + if (!core_if->en_multiple_tx_fifo && core_if->dma_enable) {
  112224. + core_if->start_predict = 1;
  112225. +
  112226. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, core_if);
  112227. +
  112228. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  112229. + if (!gintsts.b.ginnakeff) {
  112230. + /* Disable EP Mismatch interrupt */
  112231. + intr_mask.d32 = 0;
  112232. + intr_mask.b.epmismatch = 1;
  112233. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, intr_mask.d32, 0);
  112234. + /* Enable the Global IN NAK Effective Interrupt */
  112235. + intr_mask.d32 = 0;
  112236. + intr_mask.b.ginnakeff = 1;
  112237. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, 0, intr_mask.d32);
  112238. + /* Set the global non-periodic IN NAK handshake */
  112239. + dctl.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dctl);
  112240. + dctl.b.sgnpinnak = 1;
  112241. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32);
  112242. + } else {
  112243. + DWC_PRINTF("gintsts.b.ginnakeff = 1! dctl.b.sgnpinnak not set\n");
  112244. + }
  112245. + /* Disabling of all EP's will be done in dwc_otg_pcd_handle_in_nak_effective()
  112246. + * handler after Global IN NAK Effective interrupt will be asserted */
  112247. + }
  112248. + /* Clear interrupt */
  112249. + gintsts.d32 = 0;
  112250. + gintsts.b.epmismatch = 1;
  112251. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  112252. +
  112253. + return 1;
  112254. +}
  112255. +
  112256. +/**
  112257. + * This interrupt is valid only in DMA mode. This interrupt indicates that the
  112258. + * core has stopped fetching data for IN endpoints due to the unavailability of
  112259. + * TxFIFO space or Request Queue space. This interrupt is used by the
  112260. + * application for an endpoint mismatch algorithm.
  112261. + *
  112262. + * @param pcd The PCD
  112263. + */
  112264. +int32_t dwc_otg_pcd_handle_ep_fetsusp_intr(dwc_otg_pcd_t * pcd)
  112265. +{
  112266. + gintsts_data_t gintsts;
  112267. + gintmsk_data_t gintmsk_data;
  112268. + dctl_data_t dctl;
  112269. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  112270. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, core_if);
  112271. +
  112272. + /* Clear the global non-periodic IN NAK handshake */
  112273. + dctl.d32 = 0;
  112274. + dctl.b.cgnpinnak = 1;
  112275. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32, dctl.d32);
  112276. +
  112277. + /* Mask GINTSTS.FETSUSP interrupt */
  112278. + gintmsk_data.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
  112279. + gintmsk_data.b.fetsusp = 0;
  112280. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, gintmsk_data.d32);
  112281. +
  112282. + /* Clear interrupt */
  112283. + gintsts.d32 = 0;
  112284. + gintsts.b.fetsusp = 1;
  112285. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  112286. +
  112287. + return 1;
  112288. +}
  112289. +/**
  112290. + * This funcion stalls EP0.
  112291. + */
  112292. +static inline void ep0_do_stall(dwc_otg_pcd_t * pcd, const int err_val)
  112293. +{
  112294. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  112295. + usb_device_request_t *ctrl = &pcd->setup_pkt->req;
  112296. + DWC_WARN("req %02x.%02x protocol STALL; err %d\n",
  112297. + ctrl->bmRequestType, ctrl->bRequest, err_val);
  112298. +
  112299. + ep0->dwc_ep.is_in = 1;
  112300. + dwc_otg_ep_set_stall(GET_CORE_IF(pcd), &ep0->dwc_ep);
  112301. + pcd->ep0.stopped = 1;
  112302. + pcd->ep0state = EP0_IDLE;
  112303. + ep0_out_start(GET_CORE_IF(pcd), pcd);
  112304. +}
  112305. +
  112306. +/**
  112307. + * This functions delegates the setup command to the gadget driver.
  112308. + */
  112309. +static inline void do_gadget_setup(dwc_otg_pcd_t * pcd,
  112310. + usb_device_request_t * ctrl)
  112311. +{
  112312. + int ret = 0;
  112313. + DWC_SPINUNLOCK(pcd->lock);
  112314. + ret = pcd->fops->setup(pcd, (uint8_t *) ctrl);
  112315. + DWC_SPINLOCK(pcd->lock);
  112316. + if (ret < 0) {
  112317. + ep0_do_stall(pcd, ret);
  112318. + }
  112319. +
  112320. + /** @todo This is a g_file_storage gadget driver specific
  112321. + * workaround: a DELAYED_STATUS result from the fsg_setup
  112322. + * routine will result in the gadget queueing a EP0 IN status
  112323. + * phase for a two-stage control transfer. Exactly the same as
  112324. + * a SET_CONFIGURATION/SET_INTERFACE except that this is a class
  112325. + * specific request. Need a generic way to know when the gadget
  112326. + * driver will queue the status phase. Can we assume when we
  112327. + * call the gadget driver setup() function that it will always
  112328. + * queue and require the following flag? Need to look into
  112329. + * this.
  112330. + */
  112331. +
  112332. + if (ret == 256 + 999) {
  112333. + pcd->request_config = 1;
  112334. + }
  112335. +}
  112336. +
  112337. +#ifdef DWC_UTE_CFI
  112338. +/**
  112339. + * This functions delegates the CFI setup commands to the gadget driver.
  112340. + * This function will return a negative value to indicate a failure.
  112341. + */
  112342. +static inline int cfi_gadget_setup(dwc_otg_pcd_t * pcd,
  112343. + struct cfi_usb_ctrlrequest *ctrl_req)
  112344. +{
  112345. + int ret = 0;
  112346. +
  112347. + if (pcd->fops && pcd->fops->cfi_setup) {
  112348. + DWC_SPINUNLOCK(pcd->lock);
  112349. + ret = pcd->fops->cfi_setup(pcd, ctrl_req);
  112350. + DWC_SPINLOCK(pcd->lock);
  112351. + if (ret < 0) {
  112352. + ep0_do_stall(pcd, ret);
  112353. + return ret;
  112354. + }
  112355. + }
  112356. +
  112357. + return ret;
  112358. +}
  112359. +#endif
  112360. +
  112361. +/**
  112362. + * This function starts the Zero-Length Packet for the IN status phase
  112363. + * of a 2 stage control transfer.
  112364. + */
  112365. +static inline void do_setup_in_status_phase(dwc_otg_pcd_t * pcd)
  112366. +{
  112367. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  112368. + if (pcd->ep0state == EP0_STALL) {
  112369. + return;
  112370. + }
  112371. +
  112372. + pcd->ep0state = EP0_IN_STATUS_PHASE;
  112373. +
  112374. + /* Prepare for more SETUP Packets */
  112375. + DWC_DEBUGPL(DBG_PCD, "EP0 IN ZLP\n");
  112376. + if ((GET_CORE_IF(pcd)->snpsid >= OTG_CORE_REV_3_00a)
  112377. + && (pcd->core_if->dma_desc_enable)
  112378. + && (ep0->dwc_ep.xfer_count < ep0->dwc_ep.total_len)) {
  112379. + DWC_DEBUGPL(DBG_PCDV,
  112380. + "Data terminated wait next packet in out_desc_addr\n");
  112381. + pcd->backup_buf = phys_to_virt(ep0->dwc_ep.dma_addr);
  112382. + pcd->data_terminated = 1;
  112383. + }
  112384. + ep0->dwc_ep.xfer_len = 0;
  112385. + ep0->dwc_ep.xfer_count = 0;
  112386. + ep0->dwc_ep.is_in = 1;
  112387. + ep0->dwc_ep.dma_addr = pcd->setup_pkt_dma_handle;
  112388. + dwc_otg_ep0_start_transfer(GET_CORE_IF(pcd), &ep0->dwc_ep);
  112389. +
  112390. + /* Prepare for more SETUP Packets */
  112391. + //ep0_out_start(GET_CORE_IF(pcd), pcd);
  112392. +}
  112393. +
  112394. +/**
  112395. + * This function starts the Zero-Length Packet for the OUT status phase
  112396. + * of a 2 stage control transfer.
  112397. + */
  112398. +static inline void do_setup_out_status_phase(dwc_otg_pcd_t * pcd)
  112399. +{
  112400. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  112401. + if (pcd->ep0state == EP0_STALL) {
  112402. + DWC_DEBUGPL(DBG_PCD, "EP0 STALLED\n");
  112403. + return;
  112404. + }
  112405. + pcd->ep0state = EP0_OUT_STATUS_PHASE;
  112406. +
  112407. + DWC_DEBUGPL(DBG_PCD, "EP0 OUT ZLP\n");
  112408. + ep0->dwc_ep.xfer_len = 0;
  112409. + ep0->dwc_ep.xfer_count = 0;
  112410. + ep0->dwc_ep.is_in = 0;
  112411. + ep0->dwc_ep.dma_addr = pcd->setup_pkt_dma_handle;
  112412. + dwc_otg_ep0_start_transfer(GET_CORE_IF(pcd), &ep0->dwc_ep);
  112413. +
  112414. + /* Prepare for more SETUP Packets */
  112415. + if (GET_CORE_IF(pcd)->dma_enable == 0) {
  112416. + ep0_out_start(GET_CORE_IF(pcd), pcd);
  112417. + }
  112418. +}
  112419. +
  112420. +/**
  112421. + * Clear the EP halt (STALL) and if pending requests start the
  112422. + * transfer.
  112423. + */
  112424. +static inline void pcd_clear_halt(dwc_otg_pcd_t * pcd, dwc_otg_pcd_ep_t * ep)
  112425. +{
  112426. + if (ep->dwc_ep.stall_clear_flag == 0)
  112427. + dwc_otg_ep_clear_stall(GET_CORE_IF(pcd), &ep->dwc_ep);
  112428. +
  112429. + /* Reactive the EP */
  112430. + dwc_otg_ep_activate(GET_CORE_IF(pcd), &ep->dwc_ep);
  112431. + if (ep->stopped) {
  112432. + ep->stopped = 0;
  112433. + /* If there is a request in the EP queue start it */
  112434. +
  112435. + /** @todo FIXME: this causes an EP mismatch in DMA mode.
  112436. + * epmismatch not yet implemented. */
  112437. +
  112438. + /*
  112439. + * Above fixme is solved by implmenting a tasklet to call the
  112440. + * start_next_request(), outside of interrupt context at some
  112441. + * time after the current time, after a clear-halt setup packet.
  112442. + * Still need to implement ep mismatch in the future if a gadget
  112443. + * ever uses more than one endpoint at once
  112444. + */
  112445. + ep->queue_sof = 1;
  112446. + DWC_TASK_SCHEDULE(pcd->start_xfer_tasklet);
  112447. + }
  112448. + /* Start Control Status Phase */
  112449. + do_setup_in_status_phase(pcd);
  112450. +}
  112451. +
  112452. +/**
  112453. + * This function is called when the SET_FEATURE TEST_MODE Setup packet
  112454. + * is sent from the host. The Device Control register is written with
  112455. + * the Test Mode bits set to the specified Test Mode. This is done as
  112456. + * a tasklet so that the "Status" phase of the control transfer
  112457. + * completes before transmitting the TEST packets.
  112458. + *
  112459. + * @todo This has not been tested since the tasklet struct was put
  112460. + * into the PCD struct!
  112461. + *
  112462. + */
  112463. +void do_test_mode(void *data)
  112464. +{
  112465. + dctl_data_t dctl;
  112466. + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *) data;
  112467. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  112468. + int test_mode = pcd->test_mode;
  112469. +
  112470. +// DWC_WARN("%s() has not been tested since being rewritten!\n", __func__);
  112471. +
  112472. + dctl.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dctl);
  112473. + switch (test_mode) {
  112474. + case 1: // TEST_J
  112475. + dctl.b.tstctl = 1;
  112476. + break;
  112477. +
  112478. + case 2: // TEST_K
  112479. + dctl.b.tstctl = 2;
  112480. + break;
  112481. +
  112482. + case 3: // TEST_SE0_NAK
  112483. + dctl.b.tstctl = 3;
  112484. + break;
  112485. +
  112486. + case 4: // TEST_PACKET
  112487. + dctl.b.tstctl = 4;
  112488. + break;
  112489. +
  112490. + case 5: // TEST_FORCE_ENABLE
  112491. + dctl.b.tstctl = 5;
  112492. + break;
  112493. + }
  112494. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32);
  112495. +}
  112496. +
  112497. +/**
  112498. + * This function process the GET_STATUS Setup Commands.
  112499. + */
  112500. +static inline void do_get_status(dwc_otg_pcd_t * pcd)
  112501. +{
  112502. + usb_device_request_t ctrl = pcd->setup_pkt->req;
  112503. + dwc_otg_pcd_ep_t *ep;
  112504. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  112505. + uint16_t *status = pcd->status_buf;
  112506. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  112507. +
  112508. +#ifdef DEBUG_EP0
  112509. + DWC_DEBUGPL(DBG_PCD,
  112510. + "GET_STATUS %02x.%02x v%04x i%04x l%04x\n",
  112511. + ctrl.bmRequestType, ctrl.bRequest,
  112512. + UGETW(ctrl.wValue), UGETW(ctrl.wIndex),
  112513. + UGETW(ctrl.wLength));
  112514. +#endif
  112515. +
  112516. + switch (UT_GET_RECIPIENT(ctrl.bmRequestType)) {
  112517. + case UT_DEVICE:
  112518. + if(UGETW(ctrl.wIndex) == 0xF000) { /* OTG Status selector */
  112519. + DWC_PRINTF("wIndex - %d\n", UGETW(ctrl.wIndex));
  112520. + DWC_PRINTF("OTG VERSION - %d\n", core_if->otg_ver);
  112521. + DWC_PRINTF("OTG CAP - %d, %d\n",
  112522. + core_if->core_params->otg_cap,
  112523. + DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE);
  112524. + if (core_if->otg_ver == 1
  112525. + && core_if->core_params->otg_cap ==
  112526. + DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE) {
  112527. + uint8_t *otgsts = (uint8_t*)pcd->status_buf;
  112528. + *otgsts = (core_if->otg_sts & 0x1);
  112529. + pcd->ep0_pending = 1;
  112530. + ep0->dwc_ep.start_xfer_buff =
  112531. + (uint8_t *) otgsts;
  112532. + ep0->dwc_ep.xfer_buff = (uint8_t *) otgsts;
  112533. + ep0->dwc_ep.dma_addr =
  112534. + pcd->status_buf_dma_handle;
  112535. + ep0->dwc_ep.xfer_len = 1;
  112536. + ep0->dwc_ep.xfer_count = 0;
  112537. + ep0->dwc_ep.total_len = ep0->dwc_ep.xfer_len;
  112538. + dwc_otg_ep0_start_transfer(GET_CORE_IF(pcd),
  112539. + &ep0->dwc_ep);
  112540. + return;
  112541. + } else {
  112542. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  112543. + return;
  112544. + }
  112545. + break;
  112546. + } else {
  112547. + *status = 0x1; /* Self powered */
  112548. + *status |= pcd->remote_wakeup_enable << 1;
  112549. + break;
  112550. + }
  112551. + case UT_INTERFACE:
  112552. + *status = 0;
  112553. + break;
  112554. +
  112555. + case UT_ENDPOINT:
  112556. + ep = get_ep_by_addr(pcd, UGETW(ctrl.wIndex));
  112557. + if (ep == 0 || UGETW(ctrl.wLength) > 2) {
  112558. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  112559. + return;
  112560. + }
  112561. + /** @todo check for EP stall */
  112562. + *status = ep->stopped;
  112563. + break;
  112564. + }
  112565. + pcd->ep0_pending = 1;
  112566. + ep0->dwc_ep.start_xfer_buff = (uint8_t *) status;
  112567. + ep0->dwc_ep.xfer_buff = (uint8_t *) status;
  112568. + ep0->dwc_ep.dma_addr = pcd->status_buf_dma_handle;
  112569. + ep0->dwc_ep.xfer_len = 2;
  112570. + ep0->dwc_ep.xfer_count = 0;
  112571. + ep0->dwc_ep.total_len = ep0->dwc_ep.xfer_len;
  112572. + dwc_otg_ep0_start_transfer(GET_CORE_IF(pcd), &ep0->dwc_ep);
  112573. +}
  112574. +
  112575. +/**
  112576. + * This function process the SET_FEATURE Setup Commands.
  112577. + */
  112578. +static inline void do_set_feature(dwc_otg_pcd_t * pcd)
  112579. +{
  112580. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  112581. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  112582. + usb_device_request_t ctrl = pcd->setup_pkt->req;
  112583. + dwc_otg_pcd_ep_t *ep = 0;
  112584. + int32_t otg_cap_param = core_if->core_params->otg_cap;
  112585. + gotgctl_data_t gotgctl = {.d32 = 0 };
  112586. +
  112587. + DWC_DEBUGPL(DBG_PCD, "SET_FEATURE:%02x.%02x v%04x i%04x l%04x\n",
  112588. + ctrl.bmRequestType, ctrl.bRequest,
  112589. + UGETW(ctrl.wValue), UGETW(ctrl.wIndex),
  112590. + UGETW(ctrl.wLength));
  112591. + DWC_DEBUGPL(DBG_PCD, "otg_cap=%d\n", otg_cap_param);
  112592. +
  112593. + switch (UT_GET_RECIPIENT(ctrl.bmRequestType)) {
  112594. + case UT_DEVICE:
  112595. + switch (UGETW(ctrl.wValue)) {
  112596. + case UF_DEVICE_REMOTE_WAKEUP:
  112597. + pcd->remote_wakeup_enable = 1;
  112598. + break;
  112599. +
  112600. + case UF_TEST_MODE:
  112601. + /* Setup the Test Mode tasklet to do the Test
  112602. + * Packet generation after the SETUP Status
  112603. + * phase has completed. */
  112604. +
  112605. + /** @todo This has not been tested since the
  112606. + * tasklet struct was put into the PCD
  112607. + * struct! */
  112608. + pcd->test_mode = UGETW(ctrl.wIndex) >> 8;
  112609. + DWC_TASK_SCHEDULE(pcd->test_mode_tasklet);
  112610. + break;
  112611. +
  112612. + case UF_DEVICE_B_HNP_ENABLE:
  112613. + DWC_DEBUGPL(DBG_PCDV,
  112614. + "SET_FEATURE: USB_DEVICE_B_HNP_ENABLE\n");
  112615. +
  112616. + /* dev may initiate HNP */
  112617. + if (otg_cap_param == DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE) {
  112618. + pcd->b_hnp_enable = 1;
  112619. + dwc_otg_pcd_update_otg(pcd, 0);
  112620. + DWC_DEBUGPL(DBG_PCD, "Request B HNP\n");
  112621. + /**@todo Is the gotgctl.devhnpen cleared
  112622. + * by a USB Reset? */
  112623. + gotgctl.b.devhnpen = 1;
  112624. + gotgctl.b.hnpreq = 1;
  112625. + DWC_WRITE_REG32(&global_regs->gotgctl,
  112626. + gotgctl.d32);
  112627. + } else {
  112628. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  112629. + return;
  112630. + }
  112631. + break;
  112632. +
  112633. + case UF_DEVICE_A_HNP_SUPPORT:
  112634. + /* RH port supports HNP */
  112635. + DWC_DEBUGPL(DBG_PCDV,
  112636. + "SET_FEATURE: USB_DEVICE_A_HNP_SUPPORT\n");
  112637. + if (otg_cap_param == DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE) {
  112638. + pcd->a_hnp_support = 1;
  112639. + dwc_otg_pcd_update_otg(pcd, 0);
  112640. + } else {
  112641. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  112642. + return;
  112643. + }
  112644. + break;
  112645. +
  112646. + case UF_DEVICE_A_ALT_HNP_SUPPORT:
  112647. + /* other RH port does */
  112648. + DWC_DEBUGPL(DBG_PCDV,
  112649. + "SET_FEATURE: USB_DEVICE_A_ALT_HNP_SUPPORT\n");
  112650. + if (otg_cap_param == DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE) {
  112651. + pcd->a_alt_hnp_support = 1;
  112652. + dwc_otg_pcd_update_otg(pcd, 0);
  112653. + } else {
  112654. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  112655. + return;
  112656. + }
  112657. + break;
  112658. +
  112659. + default:
  112660. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  112661. + return;
  112662. +
  112663. + }
  112664. + do_setup_in_status_phase(pcd);
  112665. + break;
  112666. +
  112667. + case UT_INTERFACE:
  112668. + do_gadget_setup(pcd, &ctrl);
  112669. + break;
  112670. +
  112671. + case UT_ENDPOINT:
  112672. + if (UGETW(ctrl.wValue) == UF_ENDPOINT_HALT) {
  112673. + ep = get_ep_by_addr(pcd, UGETW(ctrl.wIndex));
  112674. + if (ep == 0) {
  112675. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  112676. + return;
  112677. + }
  112678. + ep->stopped = 1;
  112679. + dwc_otg_ep_set_stall(core_if, &ep->dwc_ep);
  112680. + }
  112681. + do_setup_in_status_phase(pcd);
  112682. + break;
  112683. + }
  112684. +}
  112685. +
  112686. +/**
  112687. + * This function process the CLEAR_FEATURE Setup Commands.
  112688. + */
  112689. +static inline void do_clear_feature(dwc_otg_pcd_t * pcd)
  112690. +{
  112691. + usb_device_request_t ctrl = pcd->setup_pkt->req;
  112692. + dwc_otg_pcd_ep_t *ep = 0;
  112693. +
  112694. + DWC_DEBUGPL(DBG_PCD,
  112695. + "CLEAR_FEATURE:%02x.%02x v%04x i%04x l%04x\n",
  112696. + ctrl.bmRequestType, ctrl.bRequest,
  112697. + UGETW(ctrl.wValue), UGETW(ctrl.wIndex),
  112698. + UGETW(ctrl.wLength));
  112699. +
  112700. + switch (UT_GET_RECIPIENT(ctrl.bmRequestType)) {
  112701. + case UT_DEVICE:
  112702. + switch (UGETW(ctrl.wValue)) {
  112703. + case UF_DEVICE_REMOTE_WAKEUP:
  112704. + pcd->remote_wakeup_enable = 0;
  112705. + break;
  112706. +
  112707. + case UF_TEST_MODE:
  112708. + /** @todo Add CLEAR_FEATURE for TEST modes. */
  112709. + break;
  112710. +
  112711. + default:
  112712. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  112713. + return;
  112714. + }
  112715. + do_setup_in_status_phase(pcd);
  112716. + break;
  112717. +
  112718. + case UT_ENDPOINT:
  112719. + ep = get_ep_by_addr(pcd, UGETW(ctrl.wIndex));
  112720. + if (ep == 0) {
  112721. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  112722. + return;
  112723. + }
  112724. +
  112725. + pcd_clear_halt(pcd, ep);
  112726. +
  112727. + break;
  112728. + }
  112729. +}
  112730. +
  112731. +/**
  112732. + * This function process the SET_ADDRESS Setup Commands.
  112733. + */
  112734. +static inline void do_set_address(dwc_otg_pcd_t * pcd)
  112735. +{
  112736. + dwc_otg_dev_if_t *dev_if = GET_CORE_IF(pcd)->dev_if;
  112737. + usb_device_request_t ctrl = pcd->setup_pkt->req;
  112738. +
  112739. + if (ctrl.bmRequestType == UT_DEVICE) {
  112740. + dcfg_data_t dcfg = {.d32 = 0 };
  112741. +
  112742. +#ifdef DEBUG_EP0
  112743. +// DWC_DEBUGPL(DBG_PCDV, "SET_ADDRESS:%d\n", ctrl.wValue);
  112744. +#endif
  112745. + dcfg.b.devaddr = UGETW(ctrl.wValue);
  112746. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dcfg, 0, dcfg.d32);
  112747. + do_setup_in_status_phase(pcd);
  112748. + }
  112749. +}
  112750. +
  112751. +/**
  112752. + * This function processes SETUP commands. In Linux, the USB Command
  112753. + * processing is done in two places - the first being the PCD and the
  112754. + * second in the Gadget Driver (for example, the File-Backed Storage
  112755. + * Gadget Driver).
  112756. + *
  112757. + * <table>
  112758. + * <tr><td>Command </td><td>Driver </td><td>Description</td></tr>
  112759. + *
  112760. + * <tr><td>GET_STATUS </td><td>PCD </td><td>Command is processed as
  112761. + * defined in chapter 9 of the USB 2.0 Specification chapter 9
  112762. + * </td></tr>
  112763. + *
  112764. + * <tr><td>CLEAR_FEATURE </td><td>PCD </td><td>The Device and Endpoint
  112765. + * requests are the ENDPOINT_HALT feature is procesed, all others the
  112766. + * interface requests are ignored.</td></tr>
  112767. + *
  112768. + * <tr><td>SET_FEATURE </td><td>PCD </td><td>The Device and Endpoint
  112769. + * requests are processed by the PCD. Interface requests are passed
  112770. + * to the Gadget Driver.</td></tr>
  112771. + *
  112772. + * <tr><td>SET_ADDRESS </td><td>PCD </td><td>Program the DCFG reg,
  112773. + * with device address received </td></tr>
  112774. + *
  112775. + * <tr><td>GET_DESCRIPTOR </td><td>Gadget Driver </td><td>Return the
  112776. + * requested descriptor</td></tr>
  112777. + *
  112778. + * <tr><td>SET_DESCRIPTOR </td><td>Gadget Driver </td><td>Optional -
  112779. + * not implemented by any of the existing Gadget Drivers.</td></tr>
  112780. + *
  112781. + * <tr><td>SET_CONFIGURATION </td><td>Gadget Driver </td><td>Disable
  112782. + * all EPs and enable EPs for new configuration.</td></tr>
  112783. + *
  112784. + * <tr><td>GET_CONFIGURATION </td><td>Gadget Driver </td><td>Return
  112785. + * the current configuration</td></tr>
  112786. + *
  112787. + * <tr><td>SET_INTERFACE </td><td>Gadget Driver </td><td>Disable all
  112788. + * EPs and enable EPs for new configuration.</td></tr>
  112789. + *
  112790. + * <tr><td>GET_INTERFACE </td><td>Gadget Driver </td><td>Return the
  112791. + * current interface.</td></tr>
  112792. + *
  112793. + * <tr><td>SYNC_FRAME </td><td>PCD </td><td>Display debug
  112794. + * message.</td></tr>
  112795. + * </table>
  112796. + *
  112797. + * When the SETUP Phase Done interrupt occurs, the PCD SETUP commands are
  112798. + * processed by pcd_setup. Calling the Function Driver's setup function from
  112799. + * pcd_setup processes the gadget SETUP commands.
  112800. + */
  112801. +static inline void pcd_setup(dwc_otg_pcd_t * pcd)
  112802. +{
  112803. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  112804. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  112805. + usb_device_request_t ctrl = pcd->setup_pkt->req;
  112806. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  112807. +
  112808. + deptsiz0_data_t doeptsize0 = {.d32 = 0 };
  112809. +
  112810. +#ifdef DWC_UTE_CFI
  112811. + int retval = 0;
  112812. + struct cfi_usb_ctrlrequest cfi_req;
  112813. +#endif
  112814. +
  112815. + doeptsize0.d32 = DWC_READ_REG32(&dev_if->out_ep_regs[0]->doeptsiz);
  112816. +
  112817. + /** In BDMA more then 1 setup packet is not supported till 3.00a */
  112818. + if (core_if->dma_enable && core_if->dma_desc_enable == 0
  112819. + && (doeptsize0.b.supcnt < 2)
  112820. + && (core_if->snpsid < OTG_CORE_REV_2_94a)) {
  112821. + DWC_ERROR
  112822. + ("\n\n----------- CANNOT handle > 1 setup packet in DMA mode\n\n");
  112823. + }
  112824. + if ((core_if->snpsid >= OTG_CORE_REV_3_00a)
  112825. + && (core_if->dma_enable == 1) && (core_if->dma_desc_enable == 0)) {
  112826. + ctrl =
  112827. + (pcd->setup_pkt +
  112828. + (3 - doeptsize0.b.supcnt - 1 +
  112829. + ep0->dwc_ep.stp_rollover))->req;
  112830. + }
  112831. +#ifdef DEBUG_EP0
  112832. + DWC_DEBUGPL(DBG_PCD, "SETUP %02x.%02x v%04x i%04x l%04x\n",
  112833. + ctrl.bmRequestType, ctrl.bRequest,
  112834. + UGETW(ctrl.wValue), UGETW(ctrl.wIndex),
  112835. + UGETW(ctrl.wLength));
  112836. +#endif
  112837. +
  112838. + /* Clean up the request queue */
  112839. + dwc_otg_request_nuke(ep0);
  112840. + ep0->stopped = 0;
  112841. +
  112842. + if (ctrl.bmRequestType & UE_DIR_IN) {
  112843. + ep0->dwc_ep.is_in = 1;
  112844. + pcd->ep0state = EP0_IN_DATA_PHASE;
  112845. + } else {
  112846. + ep0->dwc_ep.is_in = 0;
  112847. + pcd->ep0state = EP0_OUT_DATA_PHASE;
  112848. + }
  112849. +
  112850. + if (UGETW(ctrl.wLength) == 0) {
  112851. + ep0->dwc_ep.is_in = 1;
  112852. + pcd->ep0state = EP0_IN_STATUS_PHASE;
  112853. + }
  112854. +
  112855. + if (UT_GET_TYPE(ctrl.bmRequestType) != UT_STANDARD) {
  112856. +
  112857. +#ifdef DWC_UTE_CFI
  112858. + DWC_MEMCPY(&cfi_req, &ctrl, sizeof(usb_device_request_t));
  112859. +
  112860. + //printk(KERN_ALERT "CFI: req_type=0x%02x; req=0x%02x\n",
  112861. + ctrl.bRequestType, ctrl.bRequest);
  112862. + if (UT_GET_TYPE(cfi_req.bRequestType) == UT_VENDOR) {
  112863. + if (cfi_req.bRequest > 0xB0 && cfi_req.bRequest < 0xBF) {
  112864. + retval = cfi_setup(pcd, &cfi_req);
  112865. + if (retval < 0) {
  112866. + ep0_do_stall(pcd, retval);
  112867. + pcd->ep0_pending = 0;
  112868. + return;
  112869. + }
  112870. +
  112871. + /* if need gadget setup then call it and check the retval */
  112872. + if (pcd->cfi->need_gadget_att) {
  112873. + retval =
  112874. + cfi_gadget_setup(pcd,
  112875. + &pcd->
  112876. + cfi->ctrl_req);
  112877. + if (retval < 0) {
  112878. + pcd->ep0_pending = 0;
  112879. + return;
  112880. + }
  112881. + }
  112882. +
  112883. + if (pcd->cfi->need_status_in_complete) {
  112884. + do_setup_in_status_phase(pcd);
  112885. + }
  112886. + return;
  112887. + }
  112888. + }
  112889. +#endif
  112890. +
  112891. + /* handle non-standard (class/vendor) requests in the gadget driver */
  112892. + do_gadget_setup(pcd, &ctrl);
  112893. + return;
  112894. + }
  112895. +
  112896. + /** @todo NGS: Handle bad setup packet? */
  112897. +
  112898. +///////////////////////////////////////////
  112899. +//// --- Standard Request handling --- ////
  112900. +
  112901. + switch (ctrl.bRequest) {
  112902. + case UR_GET_STATUS:
  112903. + do_get_status(pcd);
  112904. + break;
  112905. +
  112906. + case UR_CLEAR_FEATURE:
  112907. + do_clear_feature(pcd);
  112908. + break;
  112909. +
  112910. + case UR_SET_FEATURE:
  112911. + do_set_feature(pcd);
  112912. + break;
  112913. +
  112914. + case UR_SET_ADDRESS:
  112915. + do_set_address(pcd);
  112916. + break;
  112917. +
  112918. + case UR_SET_INTERFACE:
  112919. + case UR_SET_CONFIG:
  112920. +// _pcd->request_config = 1; /* Configuration changed */
  112921. + do_gadget_setup(pcd, &ctrl);
  112922. + break;
  112923. +
  112924. + case UR_SYNCH_FRAME:
  112925. + do_gadget_setup(pcd, &ctrl);
  112926. + break;
  112927. +
  112928. + default:
  112929. + /* Call the Gadget Driver's setup functions */
  112930. + do_gadget_setup(pcd, &ctrl);
  112931. + break;
  112932. + }
  112933. +}
  112934. +
  112935. +/**
  112936. + * This function completes the ep0 control transfer.
  112937. + */
  112938. +static int32_t ep0_complete_request(dwc_otg_pcd_ep_t * ep)
  112939. +{
  112940. + dwc_otg_core_if_t *core_if = GET_CORE_IF(ep->pcd);
  112941. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  112942. + dwc_otg_dev_in_ep_regs_t *in_ep_regs =
  112943. + dev_if->in_ep_regs[ep->dwc_ep.num];
  112944. +#ifdef DEBUG_EP0
  112945. + dwc_otg_dev_out_ep_regs_t *out_ep_regs =
  112946. + dev_if->out_ep_regs[ep->dwc_ep.num];
  112947. +#endif
  112948. + deptsiz0_data_t deptsiz;
  112949. + dev_dma_desc_sts_t desc_sts;
  112950. + dwc_otg_pcd_request_t *req;
  112951. + int is_last = 0;
  112952. + dwc_otg_pcd_t *pcd = ep->pcd;
  112953. +
  112954. +#ifdef DWC_UTE_CFI
  112955. + struct cfi_usb_ctrlrequest *ctrlreq;
  112956. + int retval = -DWC_E_NOT_SUPPORTED;
  112957. +#endif
  112958. +
  112959. + desc_sts.b.bytes = 0;
  112960. +
  112961. + if (pcd->ep0_pending && DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  112962. + if (ep->dwc_ep.is_in) {
  112963. +#ifdef DEBUG_EP0
  112964. + DWC_DEBUGPL(DBG_PCDV, "Do setup OUT status phase\n");
  112965. +#endif
  112966. + do_setup_out_status_phase(pcd);
  112967. + } else {
  112968. +#ifdef DEBUG_EP0
  112969. + DWC_DEBUGPL(DBG_PCDV, "Do setup IN status phase\n");
  112970. +#endif
  112971. +
  112972. +#ifdef DWC_UTE_CFI
  112973. + ctrlreq = &pcd->cfi->ctrl_req;
  112974. +
  112975. + if (UT_GET_TYPE(ctrlreq->bRequestType) == UT_VENDOR) {
  112976. + if (ctrlreq->bRequest > 0xB0
  112977. + && ctrlreq->bRequest < 0xBF) {
  112978. +
  112979. + /* Return if the PCD failed to handle the request */
  112980. + if ((retval =
  112981. + pcd->cfi->ops.
  112982. + ctrl_write_complete(pcd->cfi,
  112983. + pcd)) < 0) {
  112984. + CFI_INFO
  112985. + ("ERROR setting a new value in the PCD(%d)\n",
  112986. + retval);
  112987. + ep0_do_stall(pcd, retval);
  112988. + pcd->ep0_pending = 0;
  112989. + return 0;
  112990. + }
  112991. +
  112992. + /* If the gadget needs to be notified on the request */
  112993. + if (pcd->cfi->need_gadget_att == 1) {
  112994. + //retval = do_gadget_setup(pcd, &pcd->cfi->ctrl_req);
  112995. + retval =
  112996. + cfi_gadget_setup(pcd,
  112997. + &pcd->cfi->
  112998. + ctrl_req);
  112999. +
  113000. + /* Return from the function if the gadget failed to process
  113001. + * the request properly - this should never happen !!!
  113002. + */
  113003. + if (retval < 0) {
  113004. + CFI_INFO
  113005. + ("ERROR setting a new value in the gadget(%d)\n",
  113006. + retval);
  113007. + pcd->ep0_pending = 0;
  113008. + return 0;
  113009. + }
  113010. + }
  113011. +
  113012. + CFI_INFO("%s: RETVAL=%d\n", __func__,
  113013. + retval);
  113014. + /* If we hit here then the PCD and the gadget has properly
  113015. + * handled the request - so send the ZLP IN to the host.
  113016. + */
  113017. + /* @todo: MAS - decide whether we need to start the setup
  113018. + * stage based on the need_setup value of the cfi object
  113019. + */
  113020. + do_setup_in_status_phase(pcd);
  113021. + pcd->ep0_pending = 0;
  113022. + return 1;
  113023. + }
  113024. + }
  113025. +#endif
  113026. +
  113027. + do_setup_in_status_phase(pcd);
  113028. + }
  113029. + pcd->ep0_pending = 0;
  113030. + return 1;
  113031. + }
  113032. +
  113033. + if (DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  113034. + return 0;
  113035. + }
  113036. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  113037. +
  113038. + if (pcd->ep0state == EP0_OUT_STATUS_PHASE
  113039. + || pcd->ep0state == EP0_IN_STATUS_PHASE) {
  113040. + is_last = 1;
  113041. + } else if (ep->dwc_ep.is_in) {
  113042. + deptsiz.d32 = DWC_READ_REG32(&in_ep_regs->dieptsiz);
  113043. + if (core_if->dma_desc_enable != 0)
  113044. + desc_sts = dev_if->in_desc_addr->status;
  113045. +#ifdef DEBUG_EP0
  113046. + DWC_DEBUGPL(DBG_PCDV, "%d len=%d xfersize=%d pktcnt=%d\n",
  113047. + ep->dwc_ep.num, ep->dwc_ep.xfer_len,
  113048. + deptsiz.b.xfersize, deptsiz.b.pktcnt);
  113049. +#endif
  113050. +
  113051. + if (((core_if->dma_desc_enable == 0)
  113052. + && (deptsiz.b.xfersize == 0))
  113053. + || ((core_if->dma_desc_enable != 0)
  113054. + && (desc_sts.b.bytes == 0))) {
  113055. + req->actual = ep->dwc_ep.xfer_count;
  113056. + /* Is a Zero Len Packet needed? */
  113057. + if (req->sent_zlp) {
  113058. +#ifdef DEBUG_EP0
  113059. + DWC_DEBUGPL(DBG_PCD, "Setup Rx ZLP\n");
  113060. +#endif
  113061. + req->sent_zlp = 0;
  113062. + }
  113063. + do_setup_out_status_phase(pcd);
  113064. + }
  113065. + } else {
  113066. + /* ep0-OUT */
  113067. +#ifdef DEBUG_EP0
  113068. + deptsiz.d32 = DWC_READ_REG32(&out_ep_regs->doeptsiz);
  113069. + DWC_DEBUGPL(DBG_PCDV, "%d len=%d xsize=%d pktcnt=%d\n",
  113070. + ep->dwc_ep.num, ep->dwc_ep.xfer_len,
  113071. + deptsiz.b.xfersize, deptsiz.b.pktcnt);
  113072. +#endif
  113073. + req->actual = ep->dwc_ep.xfer_count;
  113074. +
  113075. + /* Is a Zero Len Packet needed? */
  113076. + if (req->sent_zlp) {
  113077. +#ifdef DEBUG_EP0
  113078. + DWC_DEBUGPL(DBG_PCDV, "Setup Tx ZLP\n");
  113079. +#endif
  113080. + req->sent_zlp = 0;
  113081. + }
  113082. + /* For older cores do setup in status phase in Slave/BDMA modes,
  113083. + * starting from 3.00 do that only in slave, and for DMA modes
  113084. + * just re-enable ep 0 OUT here*/
  113085. + if (core_if->dma_enable == 0
  113086. + || (core_if->dma_desc_enable == 0
  113087. + && core_if->snpsid <= OTG_CORE_REV_2_94a)) {
  113088. + do_setup_in_status_phase(pcd);
  113089. + } else if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  113090. + DWC_DEBUGPL(DBG_PCDV,
  113091. + "Enable out ep before in status phase\n");
  113092. + ep0_out_start(core_if, pcd);
  113093. + }
  113094. + }
  113095. +
  113096. + /* Complete the request */
  113097. + if (is_last) {
  113098. + dwc_otg_request_done(ep, req, 0);
  113099. + ep->dwc_ep.start_xfer_buff = 0;
  113100. + ep->dwc_ep.xfer_buff = 0;
  113101. + ep->dwc_ep.xfer_len = 0;
  113102. + return 1;
  113103. + }
  113104. + return 0;
  113105. +}
  113106. +
  113107. +#ifdef DWC_UTE_CFI
  113108. +/**
  113109. + * This function calculates traverses all the CFI DMA descriptors and
  113110. + * and accumulates the bytes that are left to be transfered.
  113111. + *
  113112. + * @return The total bytes left to transfered, or a negative value as failure
  113113. + */
  113114. +static inline int cfi_calc_desc_residue(dwc_otg_pcd_ep_t * ep)
  113115. +{
  113116. + int32_t ret = 0;
  113117. + int i;
  113118. + struct dwc_otg_dma_desc *ddesc = NULL;
  113119. + struct cfi_ep *cfiep;
  113120. +
  113121. + /* See if the pcd_ep has its respective cfi_ep mapped */
  113122. + cfiep = get_cfi_ep_by_pcd_ep(ep->pcd->cfi, ep);
  113123. + if (!cfiep) {
  113124. + CFI_INFO("%s: Failed to find ep\n", __func__);
  113125. + return -1;
  113126. + }
  113127. +
  113128. + ddesc = ep->dwc_ep.descs;
  113129. +
  113130. + for (i = 0; (i < cfiep->desc_count) && (i < MAX_DMA_DESCS_PER_EP); i++) {
  113131. +
  113132. +#if defined(PRINT_CFI_DMA_DESCS)
  113133. + print_desc(ddesc, ep->ep.name, i);
  113134. +#endif
  113135. + ret += ddesc->status.b.bytes;
  113136. + ddesc++;
  113137. + }
  113138. +
  113139. + if (ret)
  113140. + CFI_INFO("!!!!!!!!!! WARNING (%s) - residue=%d\n", __func__,
  113141. + ret);
  113142. +
  113143. + return ret;
  113144. +}
  113145. +#endif
  113146. +
  113147. +/**
  113148. + * This function completes the request for the EP. If there are
  113149. + * additional requests for the EP in the queue they will be started.
  113150. + */
  113151. +static void complete_ep(dwc_otg_pcd_ep_t * ep)
  113152. +{
  113153. + dwc_otg_core_if_t *core_if = GET_CORE_IF(ep->pcd);
  113154. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  113155. + dwc_otg_dev_in_ep_regs_t *in_ep_regs =
  113156. + dev_if->in_ep_regs[ep->dwc_ep.num];
  113157. + deptsiz_data_t deptsiz;
  113158. + dev_dma_desc_sts_t desc_sts;
  113159. + dwc_otg_pcd_request_t *req = 0;
  113160. + dwc_otg_dev_dma_desc_t *dma_desc;
  113161. + uint32_t byte_count = 0;
  113162. + int is_last = 0;
  113163. + int i;
  113164. +
  113165. + DWC_DEBUGPL(DBG_PCDV, "%s() %d-%s\n", __func__, ep->dwc_ep.num,
  113166. + (ep->dwc_ep.is_in ? "IN" : "OUT"));
  113167. +
  113168. + /* Get any pending requests */
  113169. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  113170. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  113171. + if (!req) {
  113172. + DWC_PRINTF("complete_ep 0x%p, req = NULL!\n", ep);
  113173. + return;
  113174. + }
  113175. + } else {
  113176. + DWC_PRINTF("complete_ep 0x%p, ep->queue empty!\n", ep);
  113177. + return;
  113178. + }
  113179. +
  113180. + DWC_DEBUGPL(DBG_PCD, "Requests %d\n", ep->pcd->request_pending);
  113181. +
  113182. + if (ep->dwc_ep.is_in) {
  113183. + deptsiz.d32 = DWC_READ_REG32(&in_ep_regs->dieptsiz);
  113184. +
  113185. + if (core_if->dma_enable) {
  113186. + if (core_if->dma_desc_enable == 0) {
  113187. + if (deptsiz.b.xfersize == 0
  113188. + && deptsiz.b.pktcnt == 0) {
  113189. + byte_count =
  113190. + ep->dwc_ep.xfer_len -
  113191. + ep->dwc_ep.xfer_count;
  113192. +
  113193. + ep->dwc_ep.xfer_buff += byte_count;
  113194. + ep->dwc_ep.dma_addr += byte_count;
  113195. + ep->dwc_ep.xfer_count += byte_count;
  113196. +
  113197. + DWC_DEBUGPL(DBG_PCDV,
  113198. + "%d-%s len=%d xfersize=%d pktcnt=%d\n",
  113199. + ep->dwc_ep.num,
  113200. + (ep->dwc_ep.
  113201. + is_in ? "IN" : "OUT"),
  113202. + ep->dwc_ep.xfer_len,
  113203. + deptsiz.b.xfersize,
  113204. + deptsiz.b.pktcnt);
  113205. +
  113206. + if (ep->dwc_ep.xfer_len <
  113207. + ep->dwc_ep.total_len) {
  113208. + dwc_otg_ep_start_transfer
  113209. + (core_if, &ep->dwc_ep);
  113210. + } else if (ep->dwc_ep.sent_zlp) {
  113211. + /*
  113212. + * This fragment of code should initiate 0
  113213. + * length transfer in case if it is queued
  113214. + * a transfer with size divisible to EPs max
  113215. + * packet size and with usb_request zero field
  113216. + * is set, which means that after data is transfered,
  113217. + * it is also should be transfered
  113218. + * a 0 length packet at the end. For Slave and
  113219. + * Buffer DMA modes in this case SW has
  113220. + * to initiate 2 transfers one with transfer size,
  113221. + * and the second with 0 size. For Descriptor
  113222. + * DMA mode SW is able to initiate a transfer,
  113223. + * which will handle all the packets including
  113224. + * the last 0 length.
  113225. + */
  113226. + ep->dwc_ep.sent_zlp = 0;
  113227. + dwc_otg_ep_start_zl_transfer
  113228. + (core_if, &ep->dwc_ep);
  113229. + } else {
  113230. + is_last = 1;
  113231. + }
  113232. + } else {
  113233. + if (ep->dwc_ep.type ==
  113234. + DWC_OTG_EP_TYPE_ISOC) {
  113235. + req->actual = 0;
  113236. + dwc_otg_request_done(ep, req, 0);
  113237. +
  113238. + ep->dwc_ep.start_xfer_buff = 0;
  113239. + ep->dwc_ep.xfer_buff = 0;
  113240. + ep->dwc_ep.xfer_len = 0;
  113241. +
  113242. + /* If there is a request in the queue start it. */
  113243. + start_next_request(ep);
  113244. + } else
  113245. + DWC_WARN
  113246. + ("Incomplete transfer (%d - %s [siz=%d pkt=%d])\n",
  113247. + ep->dwc_ep.num,
  113248. + (ep->dwc_ep.is_in ? "IN" : "OUT"),
  113249. + deptsiz.b.xfersize,
  113250. + deptsiz.b.pktcnt);
  113251. + }
  113252. + } else {
  113253. + dma_desc = ep->dwc_ep.desc_addr;
  113254. + byte_count = 0;
  113255. + ep->dwc_ep.sent_zlp = 0;
  113256. +
  113257. +#ifdef DWC_UTE_CFI
  113258. + CFI_INFO("%s: BUFFER_MODE=%d\n", __func__,
  113259. + ep->dwc_ep.buff_mode);
  113260. + if (ep->dwc_ep.buff_mode != BM_STANDARD) {
  113261. + int residue;
  113262. +
  113263. + residue = cfi_calc_desc_residue(ep);
  113264. + if (residue < 0)
  113265. + return;
  113266. +
  113267. + byte_count = residue;
  113268. + } else {
  113269. +#endif
  113270. + for (i = 0; i < ep->dwc_ep.desc_cnt;
  113271. + ++i) {
  113272. + desc_sts = dma_desc->status;
  113273. + byte_count += desc_sts.b.bytes;
  113274. + dma_desc++;
  113275. + }
  113276. +#ifdef DWC_UTE_CFI
  113277. + }
  113278. +#endif
  113279. + if (byte_count == 0) {
  113280. + ep->dwc_ep.xfer_count =
  113281. + ep->dwc_ep.total_len;
  113282. + is_last = 1;
  113283. + } else {
  113284. + DWC_WARN("Incomplete transfer\n");
  113285. + }
  113286. + }
  113287. + } else {
  113288. + if (deptsiz.b.xfersize == 0 && deptsiz.b.pktcnt == 0) {
  113289. + DWC_DEBUGPL(DBG_PCDV,
  113290. + "%d-%s len=%d xfersize=%d pktcnt=%d\n",
  113291. + ep->dwc_ep.num,
  113292. + ep->dwc_ep.is_in ? "IN" : "OUT",
  113293. + ep->dwc_ep.xfer_len,
  113294. + deptsiz.b.xfersize,
  113295. + deptsiz.b.pktcnt);
  113296. +
  113297. + /* Check if the whole transfer was completed,
  113298. + * if no, setup transfer for next portion of data
  113299. + */
  113300. + if (ep->dwc_ep.xfer_len < ep->dwc_ep.total_len) {
  113301. + dwc_otg_ep_start_transfer(core_if,
  113302. + &ep->dwc_ep);
  113303. + } else if (ep->dwc_ep.sent_zlp) {
  113304. + /*
  113305. + * This fragment of code should initiate 0
  113306. + * length trasfer in case if it is queued
  113307. + * a trasfer with size divisible to EPs max
  113308. + * packet size and with usb_request zero field
  113309. + * is set, which means that after data is transfered,
  113310. + * it is also should be transfered
  113311. + * a 0 length packet at the end. For Slave and
  113312. + * Buffer DMA modes in this case SW has
  113313. + * to initiate 2 transfers one with transfer size,
  113314. + * and the second with 0 size. For Desriptor
  113315. + * DMA mode SW is able to initiate a transfer,
  113316. + * which will handle all the packets including
  113317. + * the last 0 legth.
  113318. + */
  113319. + ep->dwc_ep.sent_zlp = 0;
  113320. + dwc_otg_ep_start_zl_transfer(core_if,
  113321. + &ep->dwc_ep);
  113322. + } else {
  113323. + is_last = 1;
  113324. + }
  113325. + } else {
  113326. + DWC_WARN
  113327. + ("Incomplete transfer (%d-%s [siz=%d pkt=%d])\n",
  113328. + ep->dwc_ep.num,
  113329. + (ep->dwc_ep.is_in ? "IN" : "OUT"),
  113330. + deptsiz.b.xfersize, deptsiz.b.pktcnt);
  113331. + }
  113332. + }
  113333. + } else {
  113334. + dwc_otg_dev_out_ep_regs_t *out_ep_regs =
  113335. + dev_if->out_ep_regs[ep->dwc_ep.num];
  113336. + desc_sts.d32 = 0;
  113337. + if (core_if->dma_enable) {
  113338. + if (core_if->dma_desc_enable) {
  113339. + dma_desc = ep->dwc_ep.desc_addr;
  113340. + byte_count = 0;
  113341. + ep->dwc_ep.sent_zlp = 0;
  113342. +
  113343. +#ifdef DWC_UTE_CFI
  113344. + CFI_INFO("%s: BUFFER_MODE=%d\n", __func__,
  113345. + ep->dwc_ep.buff_mode);
  113346. + if (ep->dwc_ep.buff_mode != BM_STANDARD) {
  113347. + int residue;
  113348. + residue = cfi_calc_desc_residue(ep);
  113349. + if (residue < 0)
  113350. + return;
  113351. + byte_count = residue;
  113352. + } else {
  113353. +#endif
  113354. +
  113355. + for (i = 0; i < ep->dwc_ep.desc_cnt;
  113356. + ++i) {
  113357. + desc_sts = dma_desc->status;
  113358. + byte_count += desc_sts.b.bytes;
  113359. + dma_desc++;
  113360. + }
  113361. +
  113362. +#ifdef DWC_UTE_CFI
  113363. + }
  113364. +#endif
  113365. + /* Checking for interrupt Out transfers with not
  113366. + * dword aligned mps sizes
  113367. + */
  113368. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_INTR &&
  113369. + (ep->dwc_ep.maxpacket%4)) {
  113370. + ep->dwc_ep.xfer_count =
  113371. + ep->dwc_ep.total_len - byte_count;
  113372. + if ((ep->dwc_ep.xfer_len %
  113373. + ep->dwc_ep.maxpacket)
  113374. + && (ep->dwc_ep.xfer_len /
  113375. + ep->dwc_ep.maxpacket <
  113376. + MAX_DMA_DESC_CNT))
  113377. + ep->dwc_ep.xfer_len -=
  113378. + (ep->dwc_ep.desc_cnt -
  113379. + 1) * ep->dwc_ep.maxpacket +
  113380. + ep->dwc_ep.xfer_len %
  113381. + ep->dwc_ep.maxpacket;
  113382. + else
  113383. + ep->dwc_ep.xfer_len -=
  113384. + ep->dwc_ep.desc_cnt *
  113385. + ep->dwc_ep.maxpacket;
  113386. + if (ep->dwc_ep.xfer_len > 0) {
  113387. + dwc_otg_ep_start_transfer
  113388. + (core_if, &ep->dwc_ep);
  113389. + } else {
  113390. + is_last = 1;
  113391. + }
  113392. + } else {
  113393. + ep->dwc_ep.xfer_count =
  113394. + ep->dwc_ep.total_len - byte_count +
  113395. + ((4 -
  113396. + (ep->dwc_ep.
  113397. + total_len & 0x3)) & 0x3);
  113398. + is_last = 1;
  113399. + }
  113400. + } else {
  113401. + deptsiz.d32 = 0;
  113402. + deptsiz.d32 =
  113403. + DWC_READ_REG32(&out_ep_regs->doeptsiz);
  113404. +
  113405. + byte_count = (ep->dwc_ep.xfer_len -
  113406. + ep->dwc_ep.xfer_count -
  113407. + deptsiz.b.xfersize);
  113408. + ep->dwc_ep.xfer_buff += byte_count;
  113409. + ep->dwc_ep.dma_addr += byte_count;
  113410. + ep->dwc_ep.xfer_count += byte_count;
  113411. +
  113412. + /* Check if the whole transfer was completed,
  113413. + * if no, setup transfer for next portion of data
  113414. + */
  113415. + if (ep->dwc_ep.xfer_len < ep->dwc_ep.total_len) {
  113416. + dwc_otg_ep_start_transfer(core_if,
  113417. + &ep->dwc_ep);
  113418. + } else if (ep->dwc_ep.sent_zlp) {
  113419. + /*
  113420. + * This fragment of code should initiate 0
  113421. + * length trasfer in case if it is queued
  113422. + * a trasfer with size divisible to EPs max
  113423. + * packet size and with usb_request zero field
  113424. + * is set, which means that after data is transfered,
  113425. + * it is also should be transfered
  113426. + * a 0 length packet at the end. For Slave and
  113427. + * Buffer DMA modes in this case SW has
  113428. + * to initiate 2 transfers one with transfer size,
  113429. + * and the second with 0 size. For Desriptor
  113430. + * DMA mode SW is able to initiate a transfer,
  113431. + * which will handle all the packets including
  113432. + * the last 0 legth.
  113433. + */
  113434. + ep->dwc_ep.sent_zlp = 0;
  113435. + dwc_otg_ep_start_zl_transfer(core_if,
  113436. + &ep->dwc_ep);
  113437. + } else {
  113438. + is_last = 1;
  113439. + }
  113440. + }
  113441. + } else {
  113442. + /* Check if the whole transfer was completed,
  113443. + * if no, setup transfer for next portion of data
  113444. + */
  113445. + if (ep->dwc_ep.xfer_len < ep->dwc_ep.total_len) {
  113446. + dwc_otg_ep_start_transfer(core_if, &ep->dwc_ep);
  113447. + } else if (ep->dwc_ep.sent_zlp) {
  113448. + /*
  113449. + * This fragment of code should initiate 0
  113450. + * length transfer in case if it is queued
  113451. + * a transfer with size divisible to EPs max
  113452. + * packet size and with usb_request zero field
  113453. + * is set, which means that after data is transfered,
  113454. + * it is also should be transfered
  113455. + * a 0 length packet at the end. For Slave and
  113456. + * Buffer DMA modes in this case SW has
  113457. + * to initiate 2 transfers one with transfer size,
  113458. + * and the second with 0 size. For Descriptor
  113459. + * DMA mode SW is able to initiate a transfer,
  113460. + * which will handle all the packets including
  113461. + * the last 0 length.
  113462. + */
  113463. + ep->dwc_ep.sent_zlp = 0;
  113464. + dwc_otg_ep_start_zl_transfer(core_if,
  113465. + &ep->dwc_ep);
  113466. + } else {
  113467. + is_last = 1;
  113468. + }
  113469. + }
  113470. +
  113471. + DWC_DEBUGPL(DBG_PCDV,
  113472. + "addr %p, %d-%s len=%d cnt=%d xsize=%d pktcnt=%d\n",
  113473. + &out_ep_regs->doeptsiz, ep->dwc_ep.num,
  113474. + ep->dwc_ep.is_in ? "IN" : "OUT",
  113475. + ep->dwc_ep.xfer_len, ep->dwc_ep.xfer_count,
  113476. + deptsiz.b.xfersize, deptsiz.b.pktcnt);
  113477. + }
  113478. +
  113479. + /* Complete the request */
  113480. + if (is_last) {
  113481. +#ifdef DWC_UTE_CFI
  113482. + if (ep->dwc_ep.buff_mode != BM_STANDARD) {
  113483. + req->actual = ep->dwc_ep.cfi_req_len - byte_count;
  113484. + } else {
  113485. +#endif
  113486. + req->actual = ep->dwc_ep.xfer_count;
  113487. +#ifdef DWC_UTE_CFI
  113488. + }
  113489. +#endif
  113490. + if (req->dw_align_buf) {
  113491. + if (!ep->dwc_ep.is_in) {
  113492. + dwc_memcpy(req->buf, req->dw_align_buf, req->length);
  113493. + }
  113494. + DWC_DMA_FREE(req->length, req->dw_align_buf,
  113495. + req->dw_align_buf_dma);
  113496. + }
  113497. +
  113498. + dwc_otg_request_done(ep, req, 0);
  113499. +
  113500. + ep->dwc_ep.start_xfer_buff = 0;
  113501. + ep->dwc_ep.xfer_buff = 0;
  113502. + ep->dwc_ep.xfer_len = 0;
  113503. +
  113504. + /* If there is a request in the queue start it. */
  113505. + start_next_request(ep);
  113506. + }
  113507. +}
  113508. +
  113509. +#ifdef DWC_EN_ISOC
  113510. +
  113511. +/**
  113512. + * This function BNA interrupt for Isochronous EPs
  113513. + *
  113514. + */
  113515. +static void dwc_otg_pcd_handle_iso_bna(dwc_otg_pcd_ep_t * ep)
  113516. +{
  113517. + dwc_ep_t *dwc_ep = &ep->dwc_ep;
  113518. + volatile uint32_t *addr;
  113519. + depctl_data_t depctl = {.d32 = 0 };
  113520. + dwc_otg_pcd_t *pcd = ep->pcd;
  113521. + dwc_otg_dev_dma_desc_t *dma_desc;
  113522. + int i;
  113523. +
  113524. + dma_desc =
  113525. + dwc_ep->iso_desc_addr + dwc_ep->desc_cnt * (dwc_ep->proc_buf_num);
  113526. +
  113527. + if (dwc_ep->is_in) {
  113528. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  113529. + for (i = 0; i < dwc_ep->desc_cnt; ++i, ++dma_desc) {
  113530. + sts.d32 = dma_desc->status.d32;
  113531. + sts.b_iso_in.bs = BS_HOST_READY;
  113532. + dma_desc->status.d32 = sts.d32;
  113533. + }
  113534. + } else {
  113535. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  113536. + for (i = 0; i < dwc_ep->desc_cnt; ++i, ++dma_desc) {
  113537. + sts.d32 = dma_desc->status.d32;
  113538. + sts.b_iso_out.bs = BS_HOST_READY;
  113539. + dma_desc->status.d32 = sts.d32;
  113540. + }
  113541. + }
  113542. +
  113543. + if (dwc_ep->is_in == 0) {
  113544. + addr =
  113545. + &GET_CORE_IF(pcd)->dev_if->out_ep_regs[dwc_ep->
  113546. + num]->doepctl;
  113547. + } else {
  113548. + addr =
  113549. + &GET_CORE_IF(pcd)->dev_if->in_ep_regs[dwc_ep->num]->diepctl;
  113550. + }
  113551. + depctl.b.epena = 1;
  113552. + DWC_MODIFY_REG32(addr, depctl.d32, depctl.d32);
  113553. +}
  113554. +
  113555. +/**
  113556. + * This function sets latest iso packet information(non-PTI mode)
  113557. + *
  113558. + * @param core_if Programming view of DWC_otg controller.
  113559. + * @param ep The EP to start the transfer on.
  113560. + *
  113561. + */
  113562. +void set_current_pkt_info(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  113563. +{
  113564. + deptsiz_data_t deptsiz = {.d32 = 0 };
  113565. + dma_addr_t dma_addr;
  113566. + uint32_t offset;
  113567. +
  113568. + if (ep->proc_buf_num)
  113569. + dma_addr = ep->dma_addr1;
  113570. + else
  113571. + dma_addr = ep->dma_addr0;
  113572. +
  113573. + if (ep->is_in) {
  113574. + deptsiz.d32 =
  113575. + DWC_READ_REG32(&core_if->dev_if->
  113576. + in_ep_regs[ep->num]->dieptsiz);
  113577. + offset = ep->data_per_frame;
  113578. + } else {
  113579. + deptsiz.d32 =
  113580. + DWC_READ_REG32(&core_if->dev_if->
  113581. + out_ep_regs[ep->num]->doeptsiz);
  113582. + offset =
  113583. + ep->data_per_frame +
  113584. + (0x4 & (0x4 - (ep->data_per_frame & 0x3)));
  113585. + }
  113586. +
  113587. + if (!deptsiz.b.xfersize) {
  113588. + ep->pkt_info[ep->cur_pkt].length = ep->data_per_frame;
  113589. + ep->pkt_info[ep->cur_pkt].offset =
  113590. + ep->cur_pkt_dma_addr - dma_addr;
  113591. + ep->pkt_info[ep->cur_pkt].status = 0;
  113592. + } else {
  113593. + ep->pkt_info[ep->cur_pkt].length = ep->data_per_frame;
  113594. + ep->pkt_info[ep->cur_pkt].offset =
  113595. + ep->cur_pkt_dma_addr - dma_addr;
  113596. + ep->pkt_info[ep->cur_pkt].status = -DWC_E_NO_DATA;
  113597. + }
  113598. + ep->cur_pkt_addr += offset;
  113599. + ep->cur_pkt_dma_addr += offset;
  113600. + ep->cur_pkt++;
  113601. +}
  113602. +
  113603. +/**
  113604. + * This function sets latest iso packet information(DDMA mode)
  113605. + *
  113606. + * @param core_if Programming view of DWC_otg controller.
  113607. + * @param dwc_ep The EP to start the transfer on.
  113608. + *
  113609. + */
  113610. +static void set_ddma_iso_pkts_info(dwc_otg_core_if_t * core_if,
  113611. + dwc_ep_t * dwc_ep)
  113612. +{
  113613. + dwc_otg_dev_dma_desc_t *dma_desc;
  113614. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  113615. + iso_pkt_info_t *iso_packet;
  113616. + uint32_t data_per_desc;
  113617. + uint32_t offset;
  113618. + int i, j;
  113619. +
  113620. + iso_packet = dwc_ep->pkt_info;
  113621. +
  113622. + /** Reinit closed DMA Descriptors*/
  113623. + /** ISO OUT EP */
  113624. + if (dwc_ep->is_in == 0) {
  113625. + dma_desc =
  113626. + dwc_ep->iso_desc_addr +
  113627. + dwc_ep->desc_cnt * dwc_ep->proc_buf_num;
  113628. + offset = 0;
  113629. +
  113630. + for (i = 0; i < dwc_ep->desc_cnt - dwc_ep->pkt_per_frm;
  113631. + i += dwc_ep->pkt_per_frm) {
  113632. + for (j = 0; j < dwc_ep->pkt_per_frm; ++j) {
  113633. + data_per_desc =
  113634. + ((j + 1) * dwc_ep->maxpacket >
  113635. + dwc_ep->
  113636. + data_per_frame) ? dwc_ep->data_per_frame -
  113637. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  113638. + data_per_desc +=
  113639. + (data_per_desc % 4) ? (4 -
  113640. + data_per_desc %
  113641. + 4) : 0;
  113642. +
  113643. + sts.d32 = dma_desc->status.d32;
  113644. +
  113645. + /* Write status in iso_packet_decsriptor */
  113646. + iso_packet->status =
  113647. + sts.b_iso_out.rxsts +
  113648. + (sts.b_iso_out.bs ^ BS_DMA_DONE);
  113649. + if (iso_packet->status) {
  113650. + iso_packet->status = -DWC_E_NO_DATA;
  113651. + }
  113652. +
  113653. + /* Received data length */
  113654. + if (!sts.b_iso_out.rxbytes) {
  113655. + iso_packet->length =
  113656. + data_per_desc -
  113657. + sts.b_iso_out.rxbytes;
  113658. + } else {
  113659. + iso_packet->length =
  113660. + data_per_desc -
  113661. + sts.b_iso_out.rxbytes + (4 -
  113662. + dwc_ep->data_per_frame
  113663. + % 4);
  113664. + }
  113665. +
  113666. + iso_packet->offset = offset;
  113667. +
  113668. + offset += data_per_desc;
  113669. + dma_desc++;
  113670. + iso_packet++;
  113671. + }
  113672. + }
  113673. +
  113674. + for (j = 0; j < dwc_ep->pkt_per_frm - 1; ++j) {
  113675. + data_per_desc =
  113676. + ((j + 1) * dwc_ep->maxpacket >
  113677. + dwc_ep->data_per_frame) ? dwc_ep->data_per_frame -
  113678. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  113679. + data_per_desc +=
  113680. + (data_per_desc % 4) ? (4 - data_per_desc % 4) : 0;
  113681. +
  113682. + sts.d32 = dma_desc->status.d32;
  113683. +
  113684. + /* Write status in iso_packet_decsriptor */
  113685. + iso_packet->status =
  113686. + sts.b_iso_out.rxsts +
  113687. + (sts.b_iso_out.bs ^ BS_DMA_DONE);
  113688. + if (iso_packet->status) {
  113689. + iso_packet->status = -DWC_E_NO_DATA;
  113690. + }
  113691. +
  113692. + /* Received data length */
  113693. + iso_packet->length =
  113694. + dwc_ep->data_per_frame - sts.b_iso_out.rxbytes;
  113695. +
  113696. + iso_packet->offset = offset;
  113697. +
  113698. + offset += data_per_desc;
  113699. + iso_packet++;
  113700. + dma_desc++;
  113701. + }
  113702. +
  113703. + sts.d32 = dma_desc->status.d32;
  113704. +
  113705. + /* Write status in iso_packet_decsriptor */
  113706. + iso_packet->status =
  113707. + sts.b_iso_out.rxsts + (sts.b_iso_out.bs ^ BS_DMA_DONE);
  113708. + if (iso_packet->status) {
  113709. + iso_packet->status = -DWC_E_NO_DATA;
  113710. + }
  113711. + /* Received data length */
  113712. + if (!sts.b_iso_out.rxbytes) {
  113713. + iso_packet->length =
  113714. + dwc_ep->data_per_frame - sts.b_iso_out.rxbytes;
  113715. + } else {
  113716. + iso_packet->length =
  113717. + dwc_ep->data_per_frame - sts.b_iso_out.rxbytes +
  113718. + (4 - dwc_ep->data_per_frame % 4);
  113719. + }
  113720. +
  113721. + iso_packet->offset = offset;
  113722. + } else {
  113723. +/** ISO IN EP */
  113724. +
  113725. + dma_desc =
  113726. + dwc_ep->iso_desc_addr +
  113727. + dwc_ep->desc_cnt * dwc_ep->proc_buf_num;
  113728. +
  113729. + for (i = 0; i < dwc_ep->desc_cnt - 1; i++) {
  113730. + sts.d32 = dma_desc->status.d32;
  113731. +
  113732. + /* Write status in iso packet descriptor */
  113733. + iso_packet->status =
  113734. + sts.b_iso_in.txsts +
  113735. + (sts.b_iso_in.bs ^ BS_DMA_DONE);
  113736. + if (iso_packet->status != 0) {
  113737. + iso_packet->status = -DWC_E_NO_DATA;
  113738. +
  113739. + }
  113740. + /* Bytes has been transfered */
  113741. + iso_packet->length =
  113742. + dwc_ep->data_per_frame - sts.b_iso_in.txbytes;
  113743. +
  113744. + dma_desc++;
  113745. + iso_packet++;
  113746. + }
  113747. +
  113748. + sts.d32 = dma_desc->status.d32;
  113749. + while (sts.b_iso_in.bs == BS_DMA_BUSY) {
  113750. + sts.d32 = dma_desc->status.d32;
  113751. + }
  113752. +
  113753. + /* Write status in iso packet descriptor ??? do be done with ERROR codes */
  113754. + iso_packet->status =
  113755. + sts.b_iso_in.txsts + (sts.b_iso_in.bs ^ BS_DMA_DONE);
  113756. + if (iso_packet->status != 0) {
  113757. + iso_packet->status = -DWC_E_NO_DATA;
  113758. + }
  113759. +
  113760. + /* Bytes has been transfered */
  113761. + iso_packet->length =
  113762. + dwc_ep->data_per_frame - sts.b_iso_in.txbytes;
  113763. + }
  113764. +}
  113765. +
  113766. +/**
  113767. + * This function reinitialize DMA Descriptors for Isochronous transfer
  113768. + *
  113769. + * @param core_if Programming view of DWC_otg controller.
  113770. + * @param dwc_ep The EP to start the transfer on.
  113771. + *
  113772. + */
  113773. +static void reinit_ddma_iso_xfer(dwc_otg_core_if_t * core_if, dwc_ep_t * dwc_ep)
  113774. +{
  113775. + int i, j;
  113776. + dwc_otg_dev_dma_desc_t *dma_desc;
  113777. + dma_addr_t dma_ad;
  113778. + volatile uint32_t *addr;
  113779. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  113780. + uint32_t data_per_desc;
  113781. +
  113782. + if (dwc_ep->is_in == 0) {
  113783. + addr = &core_if->dev_if->out_ep_regs[dwc_ep->num]->doepctl;
  113784. + } else {
  113785. + addr = &core_if->dev_if->in_ep_regs[dwc_ep->num]->diepctl;
  113786. + }
  113787. +
  113788. + if (dwc_ep->proc_buf_num == 0) {
  113789. + /** Buffer 0 descriptors setup */
  113790. + dma_ad = dwc_ep->dma_addr0;
  113791. + } else {
  113792. + /** Buffer 1 descriptors setup */
  113793. + dma_ad = dwc_ep->dma_addr1;
  113794. + }
  113795. +
  113796. + /** Reinit closed DMA Descriptors*/
  113797. + /** ISO OUT EP */
  113798. + if (dwc_ep->is_in == 0) {
  113799. + dma_desc =
  113800. + dwc_ep->iso_desc_addr +
  113801. + dwc_ep->desc_cnt * dwc_ep->proc_buf_num;
  113802. +
  113803. + sts.b_iso_out.bs = BS_HOST_READY;
  113804. + sts.b_iso_out.rxsts = 0;
  113805. + sts.b_iso_out.l = 0;
  113806. + sts.b_iso_out.sp = 0;
  113807. + sts.b_iso_out.ioc = 0;
  113808. + sts.b_iso_out.pid = 0;
  113809. + sts.b_iso_out.framenum = 0;
  113810. +
  113811. + for (i = 0; i < dwc_ep->desc_cnt - dwc_ep->pkt_per_frm;
  113812. + i += dwc_ep->pkt_per_frm) {
  113813. + for (j = 0; j < dwc_ep->pkt_per_frm; ++j) {
  113814. + data_per_desc =
  113815. + ((j + 1) * dwc_ep->maxpacket >
  113816. + dwc_ep->
  113817. + data_per_frame) ? dwc_ep->data_per_frame -
  113818. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  113819. + data_per_desc +=
  113820. + (data_per_desc % 4) ? (4 -
  113821. + data_per_desc %
  113822. + 4) : 0;
  113823. + sts.b_iso_out.rxbytes = data_per_desc;
  113824. + dma_desc->buf = dma_ad;
  113825. + dma_desc->status.d32 = sts.d32;
  113826. +
  113827. + dma_ad += data_per_desc;
  113828. + dma_desc++;
  113829. + }
  113830. + }
  113831. +
  113832. + for (j = 0; j < dwc_ep->pkt_per_frm - 1; ++j) {
  113833. +
  113834. + data_per_desc =
  113835. + ((j + 1) * dwc_ep->maxpacket >
  113836. + dwc_ep->data_per_frame) ? dwc_ep->data_per_frame -
  113837. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  113838. + data_per_desc +=
  113839. + (data_per_desc % 4) ? (4 - data_per_desc % 4) : 0;
  113840. + sts.b_iso_out.rxbytes = data_per_desc;
  113841. +
  113842. + dma_desc->buf = dma_ad;
  113843. + dma_desc->status.d32 = sts.d32;
  113844. +
  113845. + dma_desc++;
  113846. + dma_ad += data_per_desc;
  113847. + }
  113848. +
  113849. + sts.b_iso_out.ioc = 1;
  113850. + sts.b_iso_out.l = dwc_ep->proc_buf_num;
  113851. +
  113852. + data_per_desc =
  113853. + ((j + 1) * dwc_ep->maxpacket >
  113854. + dwc_ep->data_per_frame) ? dwc_ep->data_per_frame -
  113855. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  113856. + data_per_desc +=
  113857. + (data_per_desc % 4) ? (4 - data_per_desc % 4) : 0;
  113858. + sts.b_iso_out.rxbytes = data_per_desc;
  113859. +
  113860. + dma_desc->buf = dma_ad;
  113861. + dma_desc->status.d32 = sts.d32;
  113862. + } else {
  113863. +/** ISO IN EP */
  113864. +
  113865. + dma_desc =
  113866. + dwc_ep->iso_desc_addr +
  113867. + dwc_ep->desc_cnt * dwc_ep->proc_buf_num;
  113868. +
  113869. + sts.b_iso_in.bs = BS_HOST_READY;
  113870. + sts.b_iso_in.txsts = 0;
  113871. + sts.b_iso_in.sp = 0;
  113872. + sts.b_iso_in.ioc = 0;
  113873. + sts.b_iso_in.pid = dwc_ep->pkt_per_frm;
  113874. + sts.b_iso_in.framenum = dwc_ep->next_frame;
  113875. + sts.b_iso_in.txbytes = dwc_ep->data_per_frame;
  113876. + sts.b_iso_in.l = 0;
  113877. +
  113878. + for (i = 0; i < dwc_ep->desc_cnt - 1; i++) {
  113879. + dma_desc->buf = dma_ad;
  113880. + dma_desc->status.d32 = sts.d32;
  113881. +
  113882. + sts.b_iso_in.framenum += dwc_ep->bInterval;
  113883. + dma_ad += dwc_ep->data_per_frame;
  113884. + dma_desc++;
  113885. + }
  113886. +
  113887. + sts.b_iso_in.ioc = 1;
  113888. + sts.b_iso_in.l = dwc_ep->proc_buf_num;
  113889. +
  113890. + dma_desc->buf = dma_ad;
  113891. + dma_desc->status.d32 = sts.d32;
  113892. +
  113893. + dwc_ep->next_frame =
  113894. + sts.b_iso_in.framenum + dwc_ep->bInterval * 1;
  113895. + }
  113896. + dwc_ep->proc_buf_num = (dwc_ep->proc_buf_num ^ 1) & 0x1;
  113897. +}
  113898. +
  113899. +/**
  113900. + * This function is to handle Iso EP transfer complete interrupt
  113901. + * in case Iso out packet was dropped
  113902. + *
  113903. + * @param core_if Programming view of DWC_otg controller.
  113904. + * @param dwc_ep The EP for wihich transfer complete was asserted
  113905. + *
  113906. + */
  113907. +static uint32_t handle_iso_out_pkt_dropped(dwc_otg_core_if_t * core_if,
  113908. + dwc_ep_t * dwc_ep)
  113909. +{
  113910. + uint32_t dma_addr;
  113911. + uint32_t drp_pkt;
  113912. + uint32_t drp_pkt_cnt;
  113913. + deptsiz_data_t deptsiz = {.d32 = 0 };
  113914. + depctl_data_t depctl = {.d32 = 0 };
  113915. + int i;
  113916. +
  113917. + deptsiz.d32 =
  113918. + DWC_READ_REG32(&core_if->dev_if->
  113919. + out_ep_regs[dwc_ep->num]->doeptsiz);
  113920. +
  113921. + drp_pkt = dwc_ep->pkt_cnt - deptsiz.b.pktcnt;
  113922. + drp_pkt_cnt = dwc_ep->pkt_per_frm - (drp_pkt % dwc_ep->pkt_per_frm);
  113923. +
  113924. + /* Setting dropped packets status */
  113925. + for (i = 0; i < drp_pkt_cnt; ++i) {
  113926. + dwc_ep->pkt_info[drp_pkt].status = -DWC_E_NO_DATA;
  113927. + drp_pkt++;
  113928. + deptsiz.b.pktcnt--;
  113929. + }
  113930. +
  113931. + if (deptsiz.b.pktcnt > 0) {
  113932. + deptsiz.b.xfersize =
  113933. + dwc_ep->xfer_len - (dwc_ep->pkt_cnt -
  113934. + deptsiz.b.pktcnt) * dwc_ep->maxpacket;
  113935. + } else {
  113936. + deptsiz.b.xfersize = 0;
  113937. + deptsiz.b.pktcnt = 0;
  113938. + }
  113939. +
  113940. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[dwc_ep->num]->doeptsiz,
  113941. + deptsiz.d32);
  113942. +
  113943. + if (deptsiz.b.pktcnt > 0) {
  113944. + if (dwc_ep->proc_buf_num) {
  113945. + dma_addr =
  113946. + dwc_ep->dma_addr1 + dwc_ep->xfer_len -
  113947. + deptsiz.b.xfersize;
  113948. + } else {
  113949. + dma_addr =
  113950. + dwc_ep->dma_addr0 + dwc_ep->xfer_len -
  113951. + deptsiz.b.xfersize;;
  113952. + }
  113953. +
  113954. + DWC_WRITE_REG32(&core_if->dev_if->
  113955. + out_ep_regs[dwc_ep->num]->doepdma, dma_addr);
  113956. +
  113957. + /** Re-enable endpoint, clear nak */
  113958. + depctl.d32 = 0;
  113959. + depctl.b.epena = 1;
  113960. + depctl.b.cnak = 1;
  113961. +
  113962. + DWC_MODIFY_REG32(&core_if->dev_if->
  113963. + out_ep_regs[dwc_ep->num]->doepctl, depctl.d32,
  113964. + depctl.d32);
  113965. + return 0;
  113966. + } else {
  113967. + return 1;
  113968. + }
  113969. +}
  113970. +
  113971. +/**
  113972. + * This function sets iso packets information(PTI mode)
  113973. + *
  113974. + * @param core_if Programming view of DWC_otg controller.
  113975. + * @param ep The EP to start the transfer on.
  113976. + *
  113977. + */
  113978. +static uint32_t set_iso_pkts_info(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  113979. +{
  113980. + int i, j;
  113981. + dma_addr_t dma_ad;
  113982. + iso_pkt_info_t *packet_info = ep->pkt_info;
  113983. + uint32_t offset;
  113984. + uint32_t frame_data;
  113985. + deptsiz_data_t deptsiz;
  113986. +
  113987. + if (ep->proc_buf_num == 0) {
  113988. + /** Buffer 0 descriptors setup */
  113989. + dma_ad = ep->dma_addr0;
  113990. + } else {
  113991. + /** Buffer 1 descriptors setup */
  113992. + dma_ad = ep->dma_addr1;
  113993. + }
  113994. +
  113995. + if (ep->is_in) {
  113996. + deptsiz.d32 =
  113997. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  113998. + dieptsiz);
  113999. + } else {
  114000. + deptsiz.d32 =
  114001. + DWC_READ_REG32(&core_if->dev_if->out_ep_regs[ep->num]->
  114002. + doeptsiz);
  114003. + }
  114004. +
  114005. + if (!deptsiz.b.xfersize) {
  114006. + offset = 0;
  114007. + for (i = 0; i < ep->pkt_cnt; i += ep->pkt_per_frm) {
  114008. + frame_data = ep->data_per_frame;
  114009. + for (j = 0; j < ep->pkt_per_frm; ++j) {
  114010. +
  114011. + /* Packet status - is not set as initially
  114012. + * it is set to 0 and if packet was sent
  114013. + successfully, status field will remain 0*/
  114014. +
  114015. + /* Bytes has been transfered */
  114016. + packet_info->length =
  114017. + (ep->maxpacket <
  114018. + frame_data) ? ep->maxpacket : frame_data;
  114019. +
  114020. + /* Received packet offset */
  114021. + packet_info->offset = offset;
  114022. + offset += packet_info->length;
  114023. + frame_data -= packet_info->length;
  114024. +
  114025. + packet_info++;
  114026. + }
  114027. + }
  114028. + return 1;
  114029. + } else {
  114030. + /* This is a workaround for in case of Transfer Complete with
  114031. + * PktDrpSts interrupts merging - in this case Transfer complete
  114032. + * interrupt for Isoc Out Endpoint is asserted without PktDrpSts
  114033. + * set and with DOEPTSIZ register non zero. Investigations showed,
  114034. + * that this happens when Out packet is dropped, but because of
  114035. + * interrupts merging during first interrupt handling PktDrpSts
  114036. + * bit is cleared and for next merged interrupts it is not reset.
  114037. + * In this case SW hadles the interrupt as if PktDrpSts bit is set.
  114038. + */
  114039. + if (ep->is_in) {
  114040. + return 1;
  114041. + } else {
  114042. + return handle_iso_out_pkt_dropped(core_if, ep);
  114043. + }
  114044. + }
  114045. +}
  114046. +
  114047. +/**
  114048. + * This function is to handle Iso EP transfer complete interrupt
  114049. + *
  114050. + * @param pcd The PCD
  114051. + * @param ep The EP for which transfer complete was asserted
  114052. + *
  114053. + */
  114054. +static void complete_iso_ep(dwc_otg_pcd_t * pcd, dwc_otg_pcd_ep_t * ep)
  114055. +{
  114056. + dwc_otg_core_if_t *core_if = GET_CORE_IF(ep->pcd);
  114057. + dwc_ep_t *dwc_ep = &ep->dwc_ep;
  114058. + uint8_t is_last = 0;
  114059. +
  114060. + if (ep->dwc_ep.next_frame == 0xffffffff) {
  114061. + DWC_WARN("Next frame is not set!\n");
  114062. + return;
  114063. + }
  114064. +
  114065. + if (core_if->dma_enable) {
  114066. + if (core_if->dma_desc_enable) {
  114067. + set_ddma_iso_pkts_info(core_if, dwc_ep);
  114068. + reinit_ddma_iso_xfer(core_if, dwc_ep);
  114069. + is_last = 1;
  114070. + } else {
  114071. + if (core_if->pti_enh_enable) {
  114072. + if (set_iso_pkts_info(core_if, dwc_ep)) {
  114073. + dwc_ep->proc_buf_num =
  114074. + (dwc_ep->proc_buf_num ^ 1) & 0x1;
  114075. + dwc_otg_iso_ep_start_buf_transfer
  114076. + (core_if, dwc_ep);
  114077. + is_last = 1;
  114078. + }
  114079. + } else {
  114080. + set_current_pkt_info(core_if, dwc_ep);
  114081. + if (dwc_ep->cur_pkt >= dwc_ep->pkt_cnt) {
  114082. + is_last = 1;
  114083. + dwc_ep->cur_pkt = 0;
  114084. + dwc_ep->proc_buf_num =
  114085. + (dwc_ep->proc_buf_num ^ 1) & 0x1;
  114086. + if (dwc_ep->proc_buf_num) {
  114087. + dwc_ep->cur_pkt_addr =
  114088. + dwc_ep->xfer_buff1;
  114089. + dwc_ep->cur_pkt_dma_addr =
  114090. + dwc_ep->dma_addr1;
  114091. + } else {
  114092. + dwc_ep->cur_pkt_addr =
  114093. + dwc_ep->xfer_buff0;
  114094. + dwc_ep->cur_pkt_dma_addr =
  114095. + dwc_ep->dma_addr0;
  114096. + }
  114097. +
  114098. + }
  114099. + dwc_otg_iso_ep_start_frm_transfer(core_if,
  114100. + dwc_ep);
  114101. + }
  114102. + }
  114103. + } else {
  114104. + set_current_pkt_info(core_if, dwc_ep);
  114105. + if (dwc_ep->cur_pkt >= dwc_ep->pkt_cnt) {
  114106. + is_last = 1;
  114107. + dwc_ep->cur_pkt = 0;
  114108. + dwc_ep->proc_buf_num = (dwc_ep->proc_buf_num ^ 1) & 0x1;
  114109. + if (dwc_ep->proc_buf_num) {
  114110. + dwc_ep->cur_pkt_addr = dwc_ep->xfer_buff1;
  114111. + dwc_ep->cur_pkt_dma_addr = dwc_ep->dma_addr1;
  114112. + } else {
  114113. + dwc_ep->cur_pkt_addr = dwc_ep->xfer_buff0;
  114114. + dwc_ep->cur_pkt_dma_addr = dwc_ep->dma_addr0;
  114115. + }
  114116. +
  114117. + }
  114118. + dwc_otg_iso_ep_start_frm_transfer(core_if, dwc_ep);
  114119. + }
  114120. + if (is_last)
  114121. + dwc_otg_iso_buffer_done(pcd, ep, ep->iso_req_handle);
  114122. +}
  114123. +#endif /* DWC_EN_ISOC */
  114124. +
  114125. +/**
  114126. + * This function handle BNA interrupt for Non Isochronous EPs
  114127. + *
  114128. + */
  114129. +static void dwc_otg_pcd_handle_noniso_bna(dwc_otg_pcd_ep_t * ep)
  114130. +{
  114131. + dwc_ep_t *dwc_ep = &ep->dwc_ep;
  114132. + volatile uint32_t *addr;
  114133. + depctl_data_t depctl = {.d32 = 0 };
  114134. + dwc_otg_pcd_t *pcd = ep->pcd;
  114135. + dwc_otg_dev_dma_desc_t *dma_desc;
  114136. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  114137. + dwc_otg_core_if_t *core_if = ep->pcd->core_if;
  114138. + int i, start;
  114139. +
  114140. + if (!dwc_ep->desc_cnt)
  114141. + DWC_WARN("Ep%d %s Descriptor count = %d \n", dwc_ep->num,
  114142. + (dwc_ep->is_in ? "IN" : "OUT"), dwc_ep->desc_cnt);
  114143. +
  114144. + if (core_if->core_params->cont_on_bna && !dwc_ep->is_in
  114145. + && dwc_ep->type != DWC_OTG_EP_TYPE_CONTROL) {
  114146. + uint32_t doepdma;
  114147. + dwc_otg_dev_out_ep_regs_t *out_regs =
  114148. + core_if->dev_if->out_ep_regs[dwc_ep->num];
  114149. + doepdma = DWC_READ_REG32(&(out_regs->doepdma));
  114150. + start = (doepdma - dwc_ep->dma_desc_addr)/sizeof(dwc_otg_dev_dma_desc_t);
  114151. + dma_desc = &(dwc_ep->desc_addr[start]);
  114152. + } else {
  114153. + start = 0;
  114154. + dma_desc = dwc_ep->desc_addr;
  114155. + }
  114156. +
  114157. +
  114158. + for (i = start; i < dwc_ep->desc_cnt; ++i, ++dma_desc) {
  114159. + sts.d32 = dma_desc->status.d32;
  114160. + sts.b.bs = BS_HOST_READY;
  114161. + dma_desc->status.d32 = sts.d32;
  114162. + }
  114163. +
  114164. + if (dwc_ep->is_in == 0) {
  114165. + addr =
  114166. + &GET_CORE_IF(pcd)->dev_if->out_ep_regs[dwc_ep->num]->
  114167. + doepctl;
  114168. + } else {
  114169. + addr =
  114170. + &GET_CORE_IF(pcd)->dev_if->in_ep_regs[dwc_ep->num]->diepctl;
  114171. + }
  114172. + depctl.b.epena = 1;
  114173. + depctl.b.cnak = 1;
  114174. + DWC_MODIFY_REG32(addr, 0, depctl.d32);
  114175. +}
  114176. +
  114177. +/**
  114178. + * This function handles EP0 Control transfers.
  114179. + *
  114180. + * The state of the control transfers are tracked in
  114181. + * <code>ep0state</code>.
  114182. + */
  114183. +static void handle_ep0(dwc_otg_pcd_t * pcd)
  114184. +{
  114185. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  114186. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  114187. + dev_dma_desc_sts_t desc_sts;
  114188. + deptsiz0_data_t deptsiz;
  114189. + uint32_t byte_count;
  114190. +
  114191. +#ifdef DEBUG_EP0
  114192. + DWC_DEBUGPL(DBG_PCDV, "%s()\n", __func__);
  114193. + print_ep0_state(pcd);
  114194. +#endif
  114195. +
  114196. +// DWC_PRINTF("HANDLE EP0\n");
  114197. +
  114198. + switch (pcd->ep0state) {
  114199. + case EP0_DISCONNECT:
  114200. + break;
  114201. +
  114202. + case EP0_IDLE:
  114203. + pcd->request_config = 0;
  114204. +
  114205. + pcd_setup(pcd);
  114206. + break;
  114207. +
  114208. + case EP0_IN_DATA_PHASE:
  114209. +#ifdef DEBUG_EP0
  114210. + DWC_DEBUGPL(DBG_PCD, "DATA_IN EP%d-%s: type=%d, mps=%d\n",
  114211. + ep0->dwc_ep.num, (ep0->dwc_ep.is_in ? "IN" : "OUT"),
  114212. + ep0->dwc_ep.type, ep0->dwc_ep.maxpacket);
  114213. +#endif
  114214. +
  114215. + if (core_if->dma_enable != 0) {
  114216. + /*
  114217. + * For EP0 we can only program 1 packet at a time so we
  114218. + * need to do the make calculations after each complete.
  114219. + * Call write_packet to make the calculations, as in
  114220. + * slave mode, and use those values to determine if we
  114221. + * can complete.
  114222. + */
  114223. + if (core_if->dma_desc_enable == 0) {
  114224. + deptsiz.d32 =
  114225. + DWC_READ_REG32(&core_if->
  114226. + dev_if->in_ep_regs[0]->
  114227. + dieptsiz);
  114228. + byte_count =
  114229. + ep0->dwc_ep.xfer_len - deptsiz.b.xfersize;
  114230. + } else {
  114231. + desc_sts =
  114232. + core_if->dev_if->in_desc_addr->status;
  114233. + byte_count =
  114234. + ep0->dwc_ep.xfer_len - desc_sts.b.bytes;
  114235. + }
  114236. + ep0->dwc_ep.xfer_count += byte_count;
  114237. + ep0->dwc_ep.xfer_buff += byte_count;
  114238. + ep0->dwc_ep.dma_addr += byte_count;
  114239. + }
  114240. + if (ep0->dwc_ep.xfer_count < ep0->dwc_ep.total_len) {
  114241. + dwc_otg_ep0_continue_transfer(GET_CORE_IF(pcd),
  114242. + &ep0->dwc_ep);
  114243. + DWC_DEBUGPL(DBG_PCD, "CONTINUE TRANSFER\n");
  114244. + } else if (ep0->dwc_ep.sent_zlp) {
  114245. + dwc_otg_ep0_continue_transfer(GET_CORE_IF(pcd),
  114246. + &ep0->dwc_ep);
  114247. + ep0->dwc_ep.sent_zlp = 0;
  114248. + DWC_DEBUGPL(DBG_PCD, "CONTINUE TRANSFER sent zlp\n");
  114249. + } else {
  114250. + ep0_complete_request(ep0);
  114251. + DWC_DEBUGPL(DBG_PCD, "COMPLETE TRANSFER\n");
  114252. + }
  114253. + break;
  114254. + case EP0_OUT_DATA_PHASE:
  114255. +#ifdef DEBUG_EP0
  114256. + DWC_DEBUGPL(DBG_PCD, "DATA_OUT EP%d-%s: type=%d, mps=%d\n",
  114257. + ep0->dwc_ep.num, (ep0->dwc_ep.is_in ? "IN" : "OUT"),
  114258. + ep0->dwc_ep.type, ep0->dwc_ep.maxpacket);
  114259. +#endif
  114260. + if (core_if->dma_enable != 0) {
  114261. + if (core_if->dma_desc_enable == 0) {
  114262. + deptsiz.d32 =
  114263. + DWC_READ_REG32(&core_if->
  114264. + dev_if->out_ep_regs[0]->
  114265. + doeptsiz);
  114266. + byte_count =
  114267. + ep0->dwc_ep.maxpacket - deptsiz.b.xfersize;
  114268. + } else {
  114269. + desc_sts =
  114270. + core_if->dev_if->out_desc_addr->status;
  114271. + byte_count =
  114272. + ep0->dwc_ep.maxpacket - desc_sts.b.bytes;
  114273. + }
  114274. + ep0->dwc_ep.xfer_count += byte_count;
  114275. + ep0->dwc_ep.xfer_buff += byte_count;
  114276. + ep0->dwc_ep.dma_addr += byte_count;
  114277. + }
  114278. + if (ep0->dwc_ep.xfer_count < ep0->dwc_ep.total_len) {
  114279. + dwc_otg_ep0_continue_transfer(GET_CORE_IF(pcd),
  114280. + &ep0->dwc_ep);
  114281. + DWC_DEBUGPL(DBG_PCD, "CONTINUE TRANSFER\n");
  114282. + } else if (ep0->dwc_ep.sent_zlp) {
  114283. + dwc_otg_ep0_continue_transfer(GET_CORE_IF(pcd),
  114284. + &ep0->dwc_ep);
  114285. + ep0->dwc_ep.sent_zlp = 0;
  114286. + DWC_DEBUGPL(DBG_PCD, "CONTINUE TRANSFER sent zlp\n");
  114287. + } else {
  114288. + ep0_complete_request(ep0);
  114289. + DWC_DEBUGPL(DBG_PCD, "COMPLETE TRANSFER\n");
  114290. + }
  114291. + break;
  114292. +
  114293. + case EP0_IN_STATUS_PHASE:
  114294. + case EP0_OUT_STATUS_PHASE:
  114295. + DWC_DEBUGPL(DBG_PCD, "CASE: EP0_STATUS\n");
  114296. + ep0_complete_request(ep0);
  114297. + pcd->ep0state = EP0_IDLE;
  114298. + ep0->stopped = 1;
  114299. + ep0->dwc_ep.is_in = 0; /* OUT for next SETUP */
  114300. +
  114301. + /* Prepare for more SETUP Packets */
  114302. + if (core_if->dma_enable) {
  114303. + ep0_out_start(core_if, pcd);
  114304. + }
  114305. + break;
  114306. +
  114307. + case EP0_STALL:
  114308. + DWC_ERROR("EP0 STALLed, should not get here pcd_setup()\n");
  114309. + break;
  114310. + }
  114311. +#ifdef DEBUG_EP0
  114312. + print_ep0_state(pcd);
  114313. +#endif
  114314. +}
  114315. +
  114316. +/**
  114317. + * Restart transfer
  114318. + */
  114319. +static void restart_transfer(dwc_otg_pcd_t * pcd, const uint32_t epnum)
  114320. +{
  114321. + dwc_otg_core_if_t *core_if;
  114322. + dwc_otg_dev_if_t *dev_if;
  114323. + deptsiz_data_t dieptsiz = {.d32 = 0 };
  114324. + dwc_otg_pcd_ep_t *ep;
  114325. +
  114326. + ep = get_in_ep(pcd, epnum);
  114327. +
  114328. +#ifdef DWC_EN_ISOC
  114329. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  114330. + return;
  114331. + }
  114332. +#endif /* DWC_EN_ISOC */
  114333. +
  114334. + core_if = GET_CORE_IF(pcd);
  114335. + dev_if = core_if->dev_if;
  114336. +
  114337. + dieptsiz.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dieptsiz);
  114338. +
  114339. + DWC_DEBUGPL(DBG_PCD, "xfer_buff=%p xfer_count=%0x xfer_len=%0x"
  114340. + " stopped=%d\n", ep->dwc_ep.xfer_buff,
  114341. + ep->dwc_ep.xfer_count, ep->dwc_ep.xfer_len, ep->stopped);
  114342. + /*
  114343. + * If xfersize is 0 and pktcnt in not 0, resend the last packet.
  114344. + */
  114345. + if (dieptsiz.b.pktcnt && dieptsiz.b.xfersize == 0 &&
  114346. + ep->dwc_ep.start_xfer_buff != 0) {
  114347. + if (ep->dwc_ep.total_len <= ep->dwc_ep.maxpacket) {
  114348. + ep->dwc_ep.xfer_count = 0;
  114349. + ep->dwc_ep.xfer_buff = ep->dwc_ep.start_xfer_buff;
  114350. + ep->dwc_ep.xfer_len = ep->dwc_ep.xfer_count;
  114351. + } else {
  114352. + ep->dwc_ep.xfer_count -= ep->dwc_ep.maxpacket;
  114353. + /* convert packet size to dwords. */
  114354. + ep->dwc_ep.xfer_buff -= ep->dwc_ep.maxpacket;
  114355. + ep->dwc_ep.xfer_len = ep->dwc_ep.xfer_count;
  114356. + }
  114357. + ep->stopped = 0;
  114358. + DWC_DEBUGPL(DBG_PCD, "xfer_buff=%p xfer_count=%0x "
  114359. + "xfer_len=%0x stopped=%d\n",
  114360. + ep->dwc_ep.xfer_buff,
  114361. + ep->dwc_ep.xfer_count, ep->dwc_ep.xfer_len,
  114362. + ep->stopped);
  114363. + if (epnum == 0) {
  114364. + dwc_otg_ep0_start_transfer(core_if, &ep->dwc_ep);
  114365. + } else {
  114366. + dwc_otg_ep_start_transfer(core_if, &ep->dwc_ep);
  114367. + }
  114368. + }
  114369. +}
  114370. +
  114371. +/*
  114372. + * This function create new nextep sequnce based on Learn Queue.
  114373. + *
  114374. + * @param core_if Programming view of DWC_otg controller
  114375. + */
  114376. +void predict_nextep_seq( dwc_otg_core_if_t * core_if)
  114377. +{
  114378. + dwc_otg_device_global_regs_t *dev_global_regs =
  114379. + core_if->dev_if->dev_global_regs;
  114380. + const uint32_t TOKEN_Q_DEPTH = core_if->hwcfg2.b.dev_token_q_depth;
  114381. + /* Number of Token Queue Registers */
  114382. + const int DTKNQ_REG_CNT = (TOKEN_Q_DEPTH + 7) / 8;
  114383. + dtknq1_data_t dtknqr1;
  114384. + uint32_t in_tkn_epnums[4];
  114385. + uint8_t seqnum[MAX_EPS_CHANNELS];
  114386. + uint8_t intkn_seq[TOKEN_Q_DEPTH];
  114387. + grstctl_t resetctl = {.d32 = 0 };
  114388. + uint8_t temp;
  114389. + int ndx = 0;
  114390. + int start = 0;
  114391. + int end = 0;
  114392. + int sort_done = 0;
  114393. + int i = 0;
  114394. + volatile uint32_t *addr = &dev_global_regs->dtknqr1;
  114395. +
  114396. +
  114397. + DWC_DEBUGPL(DBG_PCD,"dev_token_q_depth=%d\n",TOKEN_Q_DEPTH);
  114398. +
  114399. + /* Read the DTKNQ Registers */
  114400. + for (i = 0; i < DTKNQ_REG_CNT; i++) {
  114401. + in_tkn_epnums[i] = DWC_READ_REG32(addr);
  114402. + DWC_DEBUGPL(DBG_PCDV, "DTKNQR%d=0x%08x\n", i + 1,
  114403. + in_tkn_epnums[i]);
  114404. + if (addr == &dev_global_regs->dvbusdis) {
  114405. + addr = &dev_global_regs->dtknqr3_dthrctl;
  114406. + } else {
  114407. + ++addr;
  114408. + }
  114409. +
  114410. + }
  114411. +
  114412. + /* Copy the DTKNQR1 data to the bit field. */
  114413. + dtknqr1.d32 = in_tkn_epnums[0];
  114414. + if (dtknqr1.b.wrap_bit) {
  114415. + ndx = dtknqr1.b.intknwptr;
  114416. + end = ndx -1;
  114417. + if (end < 0)
  114418. + end = TOKEN_Q_DEPTH -1;
  114419. + } else {
  114420. + ndx = 0;
  114421. + end = dtknqr1.b.intknwptr -1;
  114422. + if (end < 0)
  114423. + end = 0;
  114424. + }
  114425. + start = ndx;
  114426. +
  114427. + /* Fill seqnum[] by initial values: EP number + 31 */
  114428. + for (i=0; i <= core_if->dev_if->num_in_eps; i++) {
  114429. + seqnum[i] = i +31;
  114430. + }
  114431. +
  114432. + /* Fill intkn_seq[] from in_tkn_epnums[0] */
  114433. + for (i=0; i < 6; i++)
  114434. + intkn_seq[i] = (in_tkn_epnums[0] >> ((7-i) * 4)) & 0xf;
  114435. +
  114436. + if (TOKEN_Q_DEPTH > 6) {
  114437. + /* Fill intkn_seq[] from in_tkn_epnums[1] */
  114438. + for (i=6; i < 14; i++)
  114439. + intkn_seq[i] =
  114440. + (in_tkn_epnums[1] >> ((7 - (i - 6)) * 4)) & 0xf;
  114441. + }
  114442. +
  114443. + if (TOKEN_Q_DEPTH > 14) {
  114444. + /* Fill intkn_seq[] from in_tkn_epnums[1] */
  114445. + for (i=14; i < 22; i++)
  114446. + intkn_seq[i] =
  114447. + (in_tkn_epnums[2] >> ((7 - (i - 14)) * 4)) & 0xf;
  114448. + }
  114449. +
  114450. + if (TOKEN_Q_DEPTH > 22) {
  114451. + /* Fill intkn_seq[] from in_tkn_epnums[1] */
  114452. + for (i=22; i < 30; i++)
  114453. + intkn_seq[i] =
  114454. + (in_tkn_epnums[3] >> ((7 - (i - 22)) * 4)) & 0xf;
  114455. + }
  114456. +
  114457. + DWC_DEBUGPL(DBG_PCDV, "%s start=%d end=%d intkn_seq[]:\n", __func__,
  114458. + start, end);
  114459. + for (i=0; i<TOKEN_Q_DEPTH; i++)
  114460. + DWC_DEBUGPL(DBG_PCDV,"%d\n", intkn_seq[i]);
  114461. +
  114462. + /* Update seqnum based on intkn_seq[] */
  114463. + i = 0;
  114464. + do {
  114465. + seqnum[intkn_seq[ndx]] = i;
  114466. + ndx++;
  114467. + i++;
  114468. + if (ndx == TOKEN_Q_DEPTH)
  114469. + ndx = 0;
  114470. + } while ( i < TOKEN_Q_DEPTH );
  114471. +
  114472. + /* Mark non active EP's in seqnum[] by 0xff */
  114473. + for (i=0; i<=core_if->dev_if->num_in_eps; i++) {
  114474. + if (core_if->nextep_seq[i] == 0xff )
  114475. + seqnum[i] = 0xff;
  114476. + }
  114477. +
  114478. + /* Sort seqnum[] */
  114479. + sort_done = 0;
  114480. + while (!sort_done) {
  114481. + sort_done = 1;
  114482. + for (i=0; i<core_if->dev_if->num_in_eps; i++) {
  114483. + if (seqnum[i] > seqnum[i+1]) {
  114484. + temp = seqnum[i];
  114485. + seqnum[i] = seqnum[i+1];
  114486. + seqnum[i+1] = temp;
  114487. + sort_done = 0;
  114488. + }
  114489. + }
  114490. + }
  114491. +
  114492. + ndx = start + seqnum[0];
  114493. + if (ndx >= TOKEN_Q_DEPTH)
  114494. + ndx = ndx % TOKEN_Q_DEPTH;
  114495. + core_if->first_in_nextep_seq = intkn_seq[ndx];
  114496. +
  114497. + /* Update seqnum[] by EP numbers */
  114498. + for (i=0; i<=core_if->dev_if->num_in_eps; i++) {
  114499. + ndx = start + i;
  114500. + if (seqnum[i] < 31) {
  114501. + ndx = start + seqnum[i];
  114502. + if (ndx >= TOKEN_Q_DEPTH)
  114503. + ndx = ndx % TOKEN_Q_DEPTH;
  114504. + seqnum[i] = intkn_seq[ndx];
  114505. + } else {
  114506. + if (seqnum[i] < 0xff) {
  114507. + seqnum[i] = seqnum[i] - 31;
  114508. + } else {
  114509. + break;
  114510. + }
  114511. + }
  114512. + }
  114513. +
  114514. + /* Update nextep_seq[] based on seqnum[] */
  114515. + for (i=0; i<core_if->dev_if->num_in_eps; i++) {
  114516. + if (seqnum[i] != 0xff) {
  114517. + if (seqnum[i+1] != 0xff) {
  114518. + core_if->nextep_seq[seqnum[i]] = seqnum[i+1];
  114519. + } else {
  114520. + core_if->nextep_seq[seqnum[i]] = core_if->first_in_nextep_seq;
  114521. + break;
  114522. + }
  114523. + } else {
  114524. + break;
  114525. + }
  114526. + }
  114527. +
  114528. + DWC_DEBUGPL(DBG_PCDV, "%s first_in_nextep_seq= %2d; nextep_seq[]:\n",
  114529. + __func__, core_if->first_in_nextep_seq);
  114530. + for (i=0; i <= core_if->dev_if->num_in_eps; i++) {
  114531. + DWC_DEBUGPL(DBG_PCDV,"%2d\n", core_if->nextep_seq[i]);
  114532. + }
  114533. +
  114534. + /* Flush the Learning Queue */
  114535. + resetctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->grstctl);
  114536. + resetctl.b.intknqflsh = 1;
  114537. + DWC_WRITE_REG32(&core_if->core_global_regs->grstctl, resetctl.d32);
  114538. +
  114539. +
  114540. +}
  114541. +
  114542. +/**
  114543. + * handle the IN EP disable interrupt.
  114544. + */
  114545. +static inline void handle_in_ep_disable_intr(dwc_otg_pcd_t * pcd,
  114546. + const uint32_t epnum)
  114547. +{
  114548. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  114549. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  114550. + deptsiz_data_t dieptsiz = {.d32 = 0 };
  114551. + dctl_data_t dctl = {.d32 = 0 };
  114552. + dwc_otg_pcd_ep_t *ep;
  114553. + dwc_ep_t *dwc_ep;
  114554. + gintmsk_data_t gintmsk_data;
  114555. + depctl_data_t depctl;
  114556. + uint32_t diepdma;
  114557. + uint32_t remain_to_transfer = 0;
  114558. + uint8_t i;
  114559. + uint32_t xfer_size;
  114560. +
  114561. + ep = get_in_ep(pcd, epnum);
  114562. + dwc_ep = &ep->dwc_ep;
  114563. +
  114564. + if (dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  114565. + dwc_otg_flush_tx_fifo(core_if, dwc_ep->tx_fifo_num);
  114566. + complete_ep(ep);
  114567. + return;
  114568. + }
  114569. +
  114570. + DWC_DEBUGPL(DBG_PCD, "diepctl%d=%0x\n", epnum,
  114571. + DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->diepctl));
  114572. + dieptsiz.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dieptsiz);
  114573. + depctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->diepctl);
  114574. +
  114575. + DWC_DEBUGPL(DBG_ANY, "pktcnt=%d size=%d\n",
  114576. + dieptsiz.b.pktcnt, dieptsiz.b.xfersize);
  114577. +
  114578. + if ((core_if->start_predict == 0) || (depctl.b.eptype & 1)) {
  114579. + if (ep->stopped) {
  114580. + if (core_if->en_multiple_tx_fifo)
  114581. + /* Flush the Tx FIFO */
  114582. + dwc_otg_flush_tx_fifo(core_if, dwc_ep->tx_fifo_num);
  114583. + /* Clear the Global IN NP NAK */
  114584. + dctl.d32 = 0;
  114585. + dctl.b.cgnpinnak = 1;
  114586. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dctl, dctl.d32, dctl.d32);
  114587. + /* Restart the transaction */
  114588. + if (dieptsiz.b.pktcnt != 0 || dieptsiz.b.xfersize != 0) {
  114589. + restart_transfer(pcd, epnum);
  114590. + }
  114591. + } else {
  114592. + /* Restart the transaction */
  114593. + if (dieptsiz.b.pktcnt != 0 || dieptsiz.b.xfersize != 0) {
  114594. + restart_transfer(pcd, epnum);
  114595. + }
  114596. + DWC_DEBUGPL(DBG_ANY, "STOPPED!!!\n");
  114597. + }
  114598. + return;
  114599. + }
  114600. +
  114601. + if (core_if->start_predict > 2) { // NP IN EP
  114602. + core_if->start_predict--;
  114603. + return;
  114604. + }
  114605. +
  114606. + core_if->start_predict--;
  114607. +
  114608. + if (core_if->start_predict == 1) { // All NP IN Ep's disabled now
  114609. +
  114610. + predict_nextep_seq(core_if);
  114611. +
  114612. + /* Update all active IN EP's NextEP field based of nextep_seq[] */
  114613. + for ( i = 0; i <= core_if->dev_if->num_in_eps; i++) {
  114614. + depctl.d32 =
  114615. + DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  114616. + if (core_if->nextep_seq[i] != 0xff) { // Active NP IN EP
  114617. + depctl.b.nextep = core_if->nextep_seq[i];
  114618. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepctl, depctl.d32);
  114619. + }
  114620. + }
  114621. + /* Flush Shared NP TxFIFO */
  114622. + dwc_otg_flush_tx_fifo(core_if, 0);
  114623. + /* Rewind buffers */
  114624. + if (!core_if->dma_desc_enable) {
  114625. + i = core_if->first_in_nextep_seq;
  114626. + do {
  114627. + ep = get_in_ep(pcd, i);
  114628. + dieptsiz.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->dieptsiz);
  114629. + xfer_size = ep->dwc_ep.total_len - ep->dwc_ep.xfer_count;
  114630. + if (xfer_size > ep->dwc_ep.maxxfer)
  114631. + xfer_size = ep->dwc_ep.maxxfer;
  114632. + depctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  114633. + if (dieptsiz.b.pktcnt != 0) {
  114634. + if (xfer_size == 0) {
  114635. + remain_to_transfer = 0;
  114636. + } else {
  114637. + if ((xfer_size % ep->dwc_ep.maxpacket) == 0) {
  114638. + remain_to_transfer =
  114639. + dieptsiz.b.pktcnt * ep->dwc_ep.maxpacket;
  114640. + } else {
  114641. + remain_to_transfer = ((dieptsiz.b.pktcnt -1) * ep->dwc_ep.maxpacket)
  114642. + + (xfer_size % ep->dwc_ep.maxpacket);
  114643. + }
  114644. + }
  114645. + diepdma = DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepdma);
  114646. + dieptsiz.b.xfersize = remain_to_transfer;
  114647. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->dieptsiz, dieptsiz.d32);
  114648. + diepdma = ep->dwc_ep.dma_addr + (xfer_size - remain_to_transfer);
  114649. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepdma, diepdma);
  114650. + }
  114651. + i = core_if->nextep_seq[i];
  114652. + } while (i != core_if->first_in_nextep_seq);
  114653. + } else { // dma_desc_enable
  114654. + DWC_PRINTF("%s Learning Queue not supported in DDMA\n", __func__);
  114655. + }
  114656. +
  114657. + /* Restart transfers in predicted sequences */
  114658. + i = core_if->first_in_nextep_seq;
  114659. + do {
  114660. + dieptsiz.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->dieptsiz);
  114661. + depctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  114662. + if (dieptsiz.b.pktcnt != 0) {
  114663. + depctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  114664. + depctl.b.epena = 1;
  114665. + depctl.b.cnak = 1;
  114666. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepctl, depctl.d32);
  114667. + }
  114668. + i = core_if->nextep_seq[i];
  114669. + } while (i != core_if->first_in_nextep_seq);
  114670. +
  114671. + /* Clear the global non-periodic IN NAK handshake */
  114672. + dctl.d32 = 0;
  114673. + dctl.b.cgnpinnak = 1;
  114674. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dctl, dctl.d32, dctl.d32);
  114675. +
  114676. + /* Unmask EP Mismatch interrupt */
  114677. + gintmsk_data.d32 = 0;
  114678. + gintmsk_data.b.epmismatch = 1;
  114679. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, 0, gintmsk_data.d32);
  114680. +
  114681. + core_if->start_predict = 0;
  114682. +
  114683. + }
  114684. +}
  114685. +
  114686. +/**
  114687. + * Handler for the IN EP timeout handshake interrupt.
  114688. + */
  114689. +static inline void handle_in_ep_timeout_intr(dwc_otg_pcd_t * pcd,
  114690. + const uint32_t epnum)
  114691. +{
  114692. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  114693. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  114694. +
  114695. +#ifdef DEBUG
  114696. + deptsiz_data_t dieptsiz = {.d32 = 0 };
  114697. + uint32_t num = 0;
  114698. +#endif
  114699. + dctl_data_t dctl = {.d32 = 0 };
  114700. + dwc_otg_pcd_ep_t *ep;
  114701. +
  114702. + gintmsk_data_t intr_mask = {.d32 = 0 };
  114703. +
  114704. + ep = get_in_ep(pcd, epnum);
  114705. +
  114706. + /* Disable the NP Tx Fifo Empty Interrrupt */
  114707. + if (!core_if->dma_enable) {
  114708. + intr_mask.b.nptxfempty = 1;
  114709. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk,
  114710. + intr_mask.d32, 0);
  114711. + }
  114712. + /** @todo NGS Check EP type.
  114713. + * Implement for Periodic EPs */
  114714. + /*
  114715. + * Non-periodic EP
  114716. + */
  114717. + /* Enable the Global IN NAK Effective Interrupt */
  114718. + intr_mask.b.ginnakeff = 1;
  114719. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, 0, intr_mask.d32);
  114720. +
  114721. + /* Set Global IN NAK */
  114722. + dctl.b.sgnpinnak = 1;
  114723. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dctl, dctl.d32, dctl.d32);
  114724. +
  114725. + ep->stopped = 1;
  114726. +
  114727. +#ifdef DEBUG
  114728. + dieptsiz.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[num]->dieptsiz);
  114729. + DWC_DEBUGPL(DBG_ANY, "pktcnt=%d size=%d\n",
  114730. + dieptsiz.b.pktcnt, dieptsiz.b.xfersize);
  114731. +#endif
  114732. +
  114733. +#ifdef DISABLE_PERIODIC_EP
  114734. + /*
  114735. + * Set the NAK bit for this EP to
  114736. + * start the disable process.
  114737. + */
  114738. + diepctl.d32 = 0;
  114739. + diepctl.b.snak = 1;
  114740. + DWC_MODIFY_REG32(&dev_if->in_ep_regs[num]->diepctl, diepctl.d32,
  114741. + diepctl.d32);
  114742. + ep->disabling = 1;
  114743. + ep->stopped = 1;
  114744. +#endif
  114745. +}
  114746. +
  114747. +/**
  114748. + * Handler for the IN EP NAK interrupt.
  114749. + */
  114750. +static inline int32_t handle_in_ep_nak_intr(dwc_otg_pcd_t * pcd,
  114751. + const uint32_t epnum)
  114752. +{
  114753. + /** @todo implement ISR */
  114754. + dwc_otg_core_if_t *core_if;
  114755. + diepmsk_data_t intr_mask = {.d32 = 0 };
  114756. +
  114757. + DWC_PRINTF("INTERRUPT Handler not implemented for %s\n", "IN EP NAK");
  114758. + core_if = GET_CORE_IF(pcd);
  114759. + intr_mask.b.nak = 1;
  114760. +
  114761. + if (core_if->multiproc_int_enable) {
  114762. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  114763. + diepeachintmsk[epnum], intr_mask.d32, 0);
  114764. + } else {
  114765. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->diepmsk,
  114766. + intr_mask.d32, 0);
  114767. + }
  114768. +
  114769. + return 1;
  114770. +}
  114771. +
  114772. +/**
  114773. + * Handler for the OUT EP Babble interrupt.
  114774. + */
  114775. +static inline int32_t handle_out_ep_babble_intr(dwc_otg_pcd_t * pcd,
  114776. + const uint32_t epnum)
  114777. +{
  114778. + /** @todo implement ISR */
  114779. + dwc_otg_core_if_t *core_if;
  114780. + doepmsk_data_t intr_mask = {.d32 = 0 };
  114781. +
  114782. + DWC_PRINTF("INTERRUPT Handler not implemented for %s\n",
  114783. + "OUT EP Babble");
  114784. + core_if = GET_CORE_IF(pcd);
  114785. + intr_mask.b.babble = 1;
  114786. +
  114787. + if (core_if->multiproc_int_enable) {
  114788. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  114789. + doepeachintmsk[epnum], intr_mask.d32, 0);
  114790. + } else {
  114791. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->doepmsk,
  114792. + intr_mask.d32, 0);
  114793. + }
  114794. +
  114795. + return 1;
  114796. +}
  114797. +
  114798. +/**
  114799. + * Handler for the OUT EP NAK interrupt.
  114800. + */
  114801. +static inline int32_t handle_out_ep_nak_intr(dwc_otg_pcd_t * pcd,
  114802. + const uint32_t epnum)
  114803. +{
  114804. + /** @todo implement ISR */
  114805. + dwc_otg_core_if_t *core_if;
  114806. + doepmsk_data_t intr_mask = {.d32 = 0 };
  114807. +
  114808. + DWC_DEBUGPL(DBG_ANY, "INTERRUPT Handler not implemented for %s\n", "OUT EP NAK");
  114809. + core_if = GET_CORE_IF(pcd);
  114810. + intr_mask.b.nak = 1;
  114811. +
  114812. + if (core_if->multiproc_int_enable) {
  114813. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  114814. + doepeachintmsk[epnum], intr_mask.d32, 0);
  114815. + } else {
  114816. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->doepmsk,
  114817. + intr_mask.d32, 0);
  114818. + }
  114819. +
  114820. + return 1;
  114821. +}
  114822. +
  114823. +/**
  114824. + * Handler for the OUT EP NYET interrupt.
  114825. + */
  114826. +static inline int32_t handle_out_ep_nyet_intr(dwc_otg_pcd_t * pcd,
  114827. + const uint32_t epnum)
  114828. +{
  114829. + /** @todo implement ISR */
  114830. + dwc_otg_core_if_t *core_if;
  114831. + doepmsk_data_t intr_mask = {.d32 = 0 };
  114832. +
  114833. + DWC_PRINTF("INTERRUPT Handler not implemented for %s\n", "OUT EP NYET");
  114834. + core_if = GET_CORE_IF(pcd);
  114835. + intr_mask.b.nyet = 1;
  114836. +
  114837. + if (core_if->multiproc_int_enable) {
  114838. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  114839. + doepeachintmsk[epnum], intr_mask.d32, 0);
  114840. + } else {
  114841. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->doepmsk,
  114842. + intr_mask.d32, 0);
  114843. + }
  114844. +
  114845. + return 1;
  114846. +}
  114847. +
  114848. +/**
  114849. + * This interrupt indicates that an IN EP has a pending Interrupt.
  114850. + * The sequence for handling the IN EP interrupt is shown below:
  114851. + * -# Read the Device All Endpoint Interrupt register
  114852. + * -# Repeat the following for each IN EP interrupt bit set (from
  114853. + * LSB to MSB).
  114854. + * -# Read the Device Endpoint Interrupt (DIEPINTn) register
  114855. + * -# If "Transfer Complete" call the request complete function
  114856. + * -# If "Endpoint Disabled" complete the EP disable procedure.
  114857. + * -# If "AHB Error Interrupt" log error
  114858. + * -# If "Time-out Handshake" log error
  114859. + * -# If "IN Token Received when TxFIFO Empty" write packet to Tx
  114860. + * FIFO.
  114861. + * -# If "IN Token EP Mismatch" (disable, this is handled by EP
  114862. + * Mismatch Interrupt)
  114863. + */
  114864. +static int32_t dwc_otg_pcd_handle_in_ep_intr(dwc_otg_pcd_t * pcd)
  114865. +{
  114866. +#define CLEAR_IN_EP_INTR(__core_if,__epnum,__intr) \
  114867. +do { \
  114868. + diepint_data_t diepint = {.d32=0}; \
  114869. + diepint.b.__intr = 1; \
  114870. + DWC_WRITE_REG32(&__core_if->dev_if->in_ep_regs[__epnum]->diepint, \
  114871. + diepint.d32); \
  114872. +} while (0)
  114873. +
  114874. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  114875. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  114876. + diepint_data_t diepint = {.d32 = 0 };
  114877. + depctl_data_t depctl = {.d32 = 0 };
  114878. + uint32_t ep_intr;
  114879. + uint32_t epnum = 0;
  114880. + dwc_otg_pcd_ep_t *ep;
  114881. + dwc_ep_t *dwc_ep;
  114882. + gintmsk_data_t intr_mask = {.d32 = 0 };
  114883. +
  114884. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, pcd);
  114885. +
  114886. + /* Read in the device interrupt bits */
  114887. + ep_intr = dwc_otg_read_dev_all_in_ep_intr(core_if);
  114888. +
  114889. + /* Service the Device IN interrupts for each endpoint */
  114890. + while (ep_intr) {
  114891. + if (ep_intr & 0x1) {
  114892. + uint32_t empty_msk;
  114893. + /* Get EP pointer */
  114894. + ep = get_in_ep(pcd, epnum);
  114895. + dwc_ep = &ep->dwc_ep;
  114896. +
  114897. + depctl.d32 =
  114898. + DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->diepctl);
  114899. + empty_msk =
  114900. + DWC_READ_REG32(&dev_if->
  114901. + dev_global_regs->dtknqr4_fifoemptymsk);
  114902. +
  114903. + DWC_DEBUGPL(DBG_PCDV,
  114904. + "IN EP INTERRUPT - %d\nepmty_msk - %8x diepctl - %8x\n",
  114905. + epnum, empty_msk, depctl.d32);
  114906. +
  114907. + DWC_DEBUGPL(DBG_PCD,
  114908. + "EP%d-%s: type=%d, mps=%d\n",
  114909. + dwc_ep->num, (dwc_ep->is_in ? "IN" : "OUT"),
  114910. + dwc_ep->type, dwc_ep->maxpacket);
  114911. +
  114912. + diepint.d32 =
  114913. + dwc_otg_read_dev_in_ep_intr(core_if, dwc_ep);
  114914. +
  114915. + DWC_DEBUGPL(DBG_PCDV,
  114916. + "EP %d Interrupt Register - 0x%x\n", epnum,
  114917. + diepint.d32);
  114918. + /* Transfer complete */
  114919. + if (diepint.b.xfercompl) {
  114920. + /* Disable the NP Tx FIFO Empty
  114921. + * Interrupt */
  114922. + if (core_if->en_multiple_tx_fifo == 0) {
  114923. + intr_mask.b.nptxfempty = 1;
  114924. + DWC_MODIFY_REG32
  114925. + (&core_if->core_global_regs->gintmsk,
  114926. + intr_mask.d32, 0);
  114927. + } else {
  114928. + /* Disable the Tx FIFO Empty Interrupt for this EP */
  114929. + uint32_t fifoemptymsk =
  114930. + 0x1 << dwc_ep->num;
  114931. + DWC_MODIFY_REG32(&core_if->
  114932. + dev_if->dev_global_regs->dtknqr4_fifoemptymsk,
  114933. + fifoemptymsk, 0);
  114934. + }
  114935. + /* Clear the bit in DIEPINTn for this interrupt */
  114936. + CLEAR_IN_EP_INTR(core_if, epnum, xfercompl);
  114937. +
  114938. + /* Complete the transfer */
  114939. + if (epnum == 0) {
  114940. + handle_ep0(pcd);
  114941. + }
  114942. +#ifdef DWC_EN_ISOC
  114943. + else if (dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  114944. + if (!ep->stopped)
  114945. + complete_iso_ep(pcd, ep);
  114946. + }
  114947. +#endif /* DWC_EN_ISOC */
  114948. +#ifdef DWC_UTE_PER_IO
  114949. + else if (dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  114950. + if (!ep->stopped)
  114951. + complete_xiso_ep(ep);
  114952. + }
  114953. +#endif /* DWC_UTE_PER_IO */
  114954. + else {
  114955. + if (dwc_ep->type == DWC_OTG_EP_TYPE_ISOC &&
  114956. + dwc_ep->bInterval > 1) {
  114957. + dwc_ep->frame_num += dwc_ep->bInterval;
  114958. + if (dwc_ep->frame_num > 0x3FFF)
  114959. + {
  114960. + dwc_ep->frm_overrun = 1;
  114961. + dwc_ep->frame_num &= 0x3FFF;
  114962. + } else
  114963. + dwc_ep->frm_overrun = 0;
  114964. + }
  114965. + complete_ep(ep);
  114966. + if(diepint.b.nak)
  114967. + CLEAR_IN_EP_INTR(core_if, epnum, nak);
  114968. + }
  114969. + }
  114970. + /* Endpoint disable */
  114971. + if (diepint.b.epdisabled) {
  114972. + DWC_DEBUGPL(DBG_ANY, "EP%d IN disabled\n",
  114973. + epnum);
  114974. + handle_in_ep_disable_intr(pcd, epnum);
  114975. +
  114976. + /* Clear the bit in DIEPINTn for this interrupt */
  114977. + CLEAR_IN_EP_INTR(core_if, epnum, epdisabled);
  114978. + }
  114979. + /* AHB Error */
  114980. + if (diepint.b.ahberr) {
  114981. + DWC_ERROR("EP%d IN AHB Error\n", epnum);
  114982. + /* Clear the bit in DIEPINTn for this interrupt */
  114983. + CLEAR_IN_EP_INTR(core_if, epnum, ahberr);
  114984. + }
  114985. + /* TimeOUT Handshake (non-ISOC IN EPs) */
  114986. + if (diepint.b.timeout) {
  114987. + DWC_ERROR("EP%d IN Time-out\n", epnum);
  114988. + handle_in_ep_timeout_intr(pcd, epnum);
  114989. +
  114990. + CLEAR_IN_EP_INTR(core_if, epnum, timeout);
  114991. + }
  114992. + /** IN Token received with TxF Empty */
  114993. + if (diepint.b.intktxfemp) {
  114994. + DWC_DEBUGPL(DBG_ANY,
  114995. + "EP%d IN TKN TxFifo Empty\n",
  114996. + epnum);
  114997. + if (!ep->stopped && epnum != 0) {
  114998. +
  114999. + diepmsk_data_t diepmsk = {.d32 = 0 };
  115000. + diepmsk.b.intktxfemp = 1;
  115001. +
  115002. + if (core_if->multiproc_int_enable) {
  115003. + DWC_MODIFY_REG32
  115004. + (&dev_if->dev_global_regs->diepeachintmsk
  115005. + [epnum], diepmsk.d32, 0);
  115006. + } else {
  115007. + DWC_MODIFY_REG32
  115008. + (&dev_if->dev_global_regs->diepmsk,
  115009. + diepmsk.d32, 0);
  115010. + }
  115011. + } else if (core_if->dma_desc_enable
  115012. + && epnum == 0
  115013. + && pcd->ep0state ==
  115014. + EP0_OUT_STATUS_PHASE) {
  115015. + // EP0 IN set STALL
  115016. + depctl.d32 =
  115017. + DWC_READ_REG32(&dev_if->in_ep_regs
  115018. + [epnum]->diepctl);
  115019. +
  115020. + /* set the disable and stall bits */
  115021. + if (depctl.b.epena) {
  115022. + depctl.b.epdis = 1;
  115023. + }
  115024. + depctl.b.stall = 1;
  115025. + DWC_WRITE_REG32(&dev_if->in_ep_regs
  115026. + [epnum]->diepctl,
  115027. + depctl.d32);
  115028. + }
  115029. + CLEAR_IN_EP_INTR(core_if, epnum, intktxfemp);
  115030. + }
  115031. + /** IN Token Received with EP mismatch */
  115032. + if (diepint.b.intknepmis) {
  115033. + DWC_DEBUGPL(DBG_ANY,
  115034. + "EP%d IN TKN EP Mismatch\n", epnum);
  115035. + CLEAR_IN_EP_INTR(core_if, epnum, intknepmis);
  115036. + }
  115037. + /** IN Endpoint NAK Effective */
  115038. + if (diepint.b.inepnakeff) {
  115039. + DWC_DEBUGPL(DBG_ANY,
  115040. + "EP%d IN EP NAK Effective\n",
  115041. + epnum);
  115042. + /* Periodic EP */
  115043. + if (ep->disabling) {
  115044. + depctl.d32 = 0;
  115045. + depctl.b.snak = 1;
  115046. + depctl.b.epdis = 1;
  115047. + DWC_MODIFY_REG32(&dev_if->in_ep_regs
  115048. + [epnum]->diepctl,
  115049. + depctl.d32,
  115050. + depctl.d32);
  115051. + }
  115052. + CLEAR_IN_EP_INTR(core_if, epnum, inepnakeff);
  115053. +
  115054. + }
  115055. +
  115056. + /** IN EP Tx FIFO Empty Intr */
  115057. + if (diepint.b.emptyintr) {
  115058. + DWC_DEBUGPL(DBG_ANY,
  115059. + "EP%d Tx FIFO Empty Intr \n",
  115060. + epnum);
  115061. + write_empty_tx_fifo(pcd, epnum);
  115062. +
  115063. + CLEAR_IN_EP_INTR(core_if, epnum, emptyintr);
  115064. +
  115065. + }
  115066. +
  115067. + /** IN EP BNA Intr */
  115068. + if (diepint.b.bna) {
  115069. + CLEAR_IN_EP_INTR(core_if, epnum, bna);
  115070. + if (core_if->dma_desc_enable) {
  115071. +#ifdef DWC_EN_ISOC
  115072. + if (dwc_ep->type ==
  115073. + DWC_OTG_EP_TYPE_ISOC) {
  115074. + /*
  115075. + * This checking is performed to prevent first "false" BNA
  115076. + * handling occuring right after reconnect
  115077. + */
  115078. + if (dwc_ep->next_frame !=
  115079. + 0xffffffff)
  115080. + dwc_otg_pcd_handle_iso_bna(ep);
  115081. + } else
  115082. +#endif /* DWC_EN_ISOC */
  115083. + {
  115084. + dwc_otg_pcd_handle_noniso_bna(ep);
  115085. + }
  115086. + }
  115087. + }
  115088. + /* NAK Interrutp */
  115089. + if (diepint.b.nak) {
  115090. + DWC_DEBUGPL(DBG_ANY, "EP%d IN NAK Interrupt\n",
  115091. + epnum);
  115092. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  115093. + depctl_data_t depctl;
  115094. + if (ep->dwc_ep.frame_num == 0xFFFFFFFF) {
  115095. + ep->dwc_ep.frame_num = core_if->frame_num;
  115096. + if (ep->dwc_ep.bInterval > 1) {
  115097. + depctl.d32 = 0;
  115098. + depctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->diepctl);
  115099. + if (ep->dwc_ep.frame_num & 0x1) {
  115100. + depctl.b.setd1pid = 1;
  115101. + depctl.b.setd0pid = 0;
  115102. + } else {
  115103. + depctl.b.setd0pid = 1;
  115104. + depctl.b.setd1pid = 0;
  115105. + }
  115106. + DWC_WRITE_REG32(&dev_if->in_ep_regs[epnum]->diepctl, depctl.d32);
  115107. + }
  115108. + start_next_request(ep);
  115109. + }
  115110. + ep->dwc_ep.frame_num += ep->dwc_ep.bInterval;
  115111. + if (dwc_ep->frame_num > 0x3FFF) {
  115112. + dwc_ep->frm_overrun = 1;
  115113. + dwc_ep->frame_num &= 0x3FFF;
  115114. + } else
  115115. + dwc_ep->frm_overrun = 0;
  115116. + }
  115117. +
  115118. + CLEAR_IN_EP_INTR(core_if, epnum, nak);
  115119. + }
  115120. + }
  115121. + epnum++;
  115122. + ep_intr >>= 1;
  115123. + }
  115124. +
  115125. + return 1;
  115126. +#undef CLEAR_IN_EP_INTR
  115127. +}
  115128. +
  115129. +/**
  115130. + * This interrupt indicates that an OUT EP has a pending Interrupt.
  115131. + * The sequence for handling the OUT EP interrupt is shown below:
  115132. + * -# Read the Device All Endpoint Interrupt register
  115133. + * -# Repeat the following for each OUT EP interrupt bit set (from
  115134. + * LSB to MSB).
  115135. + * -# Read the Device Endpoint Interrupt (DOEPINTn) register
  115136. + * -# If "Transfer Complete" call the request complete function
  115137. + * -# If "Endpoint Disabled" complete the EP disable procedure.
  115138. + * -# If "AHB Error Interrupt" log error
  115139. + * -# If "Setup Phase Done" process Setup Packet (See Standard USB
  115140. + * Command Processing)
  115141. + */
  115142. +static int32_t dwc_otg_pcd_handle_out_ep_intr(dwc_otg_pcd_t * pcd)
  115143. +{
  115144. +#define CLEAR_OUT_EP_INTR(__core_if,__epnum,__intr) \
  115145. +do { \
  115146. + doepint_data_t doepint = {.d32=0}; \
  115147. + doepint.b.__intr = 1; \
  115148. + DWC_WRITE_REG32(&__core_if->dev_if->out_ep_regs[__epnum]->doepint, \
  115149. + doepint.d32); \
  115150. +} while (0)
  115151. +
  115152. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  115153. + uint32_t ep_intr;
  115154. + doepint_data_t doepint = {.d32 = 0 };
  115155. + uint32_t epnum = 0;
  115156. + dwc_otg_pcd_ep_t *ep;
  115157. + dwc_ep_t *dwc_ep;
  115158. + dctl_data_t dctl = {.d32 = 0 };
  115159. + gintmsk_data_t gintmsk = {.d32 = 0 };
  115160. +
  115161. +
  115162. + DWC_DEBUGPL(DBG_PCDV, "%s()\n", __func__);
  115163. +
  115164. + /* Read in the device interrupt bits */
  115165. + ep_intr = dwc_otg_read_dev_all_out_ep_intr(core_if);
  115166. +
  115167. + while (ep_intr) {
  115168. + if (ep_intr & 0x1) {
  115169. + /* Get EP pointer */
  115170. + ep = get_out_ep(pcd, epnum);
  115171. + dwc_ep = &ep->dwc_ep;
  115172. +
  115173. +#ifdef VERBOSE
  115174. + DWC_DEBUGPL(DBG_PCDV,
  115175. + "EP%d-%s: type=%d, mps=%d\n",
  115176. + dwc_ep->num, (dwc_ep->is_in ? "IN" : "OUT"),
  115177. + dwc_ep->type, dwc_ep->maxpacket);
  115178. +#endif
  115179. + doepint.d32 =
  115180. + dwc_otg_read_dev_out_ep_intr(core_if, dwc_ep);
  115181. + /* Moved this interrupt upper due to core deffect of asserting
  115182. + * OUT EP 0 xfercompl along with stsphsrcvd in BDMA */
  115183. + if (doepint.b.stsphsercvd) {
  115184. + deptsiz0_data_t deptsiz;
  115185. + CLEAR_OUT_EP_INTR(core_if, epnum, stsphsercvd);
  115186. + deptsiz.d32 =
  115187. + DWC_READ_REG32(&core_if->dev_if->
  115188. + out_ep_regs[0]->doeptsiz);
  115189. + if (core_if->snpsid >= OTG_CORE_REV_3_00a
  115190. + && core_if->dma_enable
  115191. + && core_if->dma_desc_enable == 0
  115192. + && doepint.b.xfercompl
  115193. + && deptsiz.b.xfersize == 24) {
  115194. + CLEAR_OUT_EP_INTR(core_if, epnum,
  115195. + xfercompl);
  115196. + doepint.b.xfercompl = 0;
  115197. + ep0_out_start(core_if, pcd);
  115198. + }
  115199. + if ((core_if->dma_desc_enable) ||
  115200. + (core_if->dma_enable
  115201. + && core_if->snpsid >=
  115202. + OTG_CORE_REV_3_00a)) {
  115203. + do_setup_in_status_phase(pcd);
  115204. + }
  115205. + }
  115206. + /* Transfer complete */
  115207. + if (doepint.b.xfercompl) {
  115208. +
  115209. + if (epnum == 0) {
  115210. + /* Clear the bit in DOEPINTn for this interrupt */
  115211. + CLEAR_OUT_EP_INTR(core_if, epnum, xfercompl);
  115212. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  115213. + DWC_DEBUGPL(DBG_PCDV, "DOEPINT=%x doepint=%x\n",
  115214. + DWC_READ_REG32(&core_if->dev_if->out_ep_regs[0]->doepint),
  115215. + doepint.d32);
  115216. + DWC_DEBUGPL(DBG_PCDV, "DOEPCTL=%x \n",
  115217. + DWC_READ_REG32(&core_if->dev_if->out_ep_regs[0]->doepctl));
  115218. +
  115219. + if (core_if->snpsid >= OTG_CORE_REV_3_00a
  115220. + && core_if->dma_enable == 0) {
  115221. + doepint_data_t doepint;
  115222. + doepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  115223. + out_ep_regs[0]->doepint);
  115224. + if (pcd->ep0state == EP0_IDLE && doepint.b.sr) {
  115225. + CLEAR_OUT_EP_INTR(core_if, epnum, sr);
  115226. + goto exit_xfercompl;
  115227. + }
  115228. + }
  115229. + /* In case of DDMA look at SR bit to go to the Data Stage */
  115230. + if (core_if->dma_desc_enable) {
  115231. + dev_dma_desc_sts_t status = {.d32 = 0};
  115232. + if (pcd->ep0state == EP0_IDLE) {
  115233. + status.d32 = core_if->dev_if->setup_desc_addr[core_if->
  115234. + dev_if->setup_desc_index]->status.d32;
  115235. + if(pcd->data_terminated) {
  115236. + pcd->data_terminated = 0;
  115237. + status.d32 = core_if->dev_if->out_desc_addr->status.d32;
  115238. + dwc_memcpy(&pcd->setup_pkt->req, pcd->backup_buf, 8);
  115239. + }
  115240. + if (status.b.sr) {
  115241. + if (doepint.b.setup) {
  115242. + DWC_DEBUGPL(DBG_PCDV, "DMA DESC EP0_IDLE SR=1 setup=1\n");
  115243. + /* Already started data stage, clear setup */
  115244. + CLEAR_OUT_EP_INTR(core_if, epnum, setup);
  115245. + doepint.b.setup = 0;
  115246. + handle_ep0(pcd);
  115247. + /* Prepare for more setup packets */
  115248. + if (pcd->ep0state == EP0_IN_STATUS_PHASE ||
  115249. + pcd->ep0state == EP0_IN_DATA_PHASE) {
  115250. + ep0_out_start(core_if, pcd);
  115251. + }
  115252. +
  115253. + goto exit_xfercompl;
  115254. + } else {
  115255. + /* Prepare for more setup packets */
  115256. + DWC_DEBUGPL(DBG_PCDV,
  115257. + "EP0_IDLE SR=1 setup=0 new setup comes\n");
  115258. + ep0_out_start(core_if, pcd);
  115259. + }
  115260. + }
  115261. + } else {
  115262. + dwc_otg_pcd_request_t *req;
  115263. + dev_dma_desc_sts_t status = {.d32 = 0};
  115264. + diepint_data_t diepint0;
  115265. + diepint0.d32 = DWC_READ_REG32(&core_if->dev_if->
  115266. + in_ep_regs[0]->diepint);
  115267. +
  115268. + if (pcd->ep0state == EP0_STALL || pcd->ep0state == EP0_DISCONNECT) {
  115269. + DWC_ERROR("EP0 is stalled/disconnected\n");
  115270. + }
  115271. +
  115272. + /* Clear IN xfercompl if set */
  115273. + if (diepint0.b.xfercompl && (pcd->ep0state == EP0_IN_STATUS_PHASE
  115274. + || pcd->ep0state == EP0_IN_DATA_PHASE)) {
  115275. + DWC_WRITE_REG32(&core_if->dev_if->
  115276. + in_ep_regs[0]->diepint, diepint0.d32);
  115277. + }
  115278. +
  115279. + status.d32 = core_if->dev_if->setup_desc_addr[core_if->
  115280. + dev_if->setup_desc_index]->status.d32;
  115281. +
  115282. + if (ep->dwc_ep.xfer_count != ep->dwc_ep.total_len
  115283. + && (pcd->ep0state == EP0_OUT_DATA_PHASE))
  115284. + status.d32 = core_if->dev_if->out_desc_addr->status.d32;
  115285. + if (pcd->ep0state == EP0_OUT_STATUS_PHASE)
  115286. + status.d32 = core_if->dev_if->
  115287. + out_desc_addr->status.d32;
  115288. +
  115289. + if (status.b.sr) {
  115290. + if (DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  115291. + DWC_DEBUGPL(DBG_PCDV, "Request queue empty!!\n");
  115292. + } else {
  115293. + DWC_DEBUGPL(DBG_PCDV, "complete req!!\n");
  115294. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  115295. + if (ep->dwc_ep.xfer_count != ep->dwc_ep.total_len &&
  115296. + pcd->ep0state == EP0_OUT_DATA_PHASE) {
  115297. + /* Read arrived setup packet from req->buf */
  115298. + dwc_memcpy(&pcd->setup_pkt->req,
  115299. + req->buf + ep->dwc_ep.xfer_count, 8);
  115300. + }
  115301. + req->actual = ep->dwc_ep.xfer_count;
  115302. + dwc_otg_request_done(ep, req, -ECONNRESET);
  115303. + ep->dwc_ep.start_xfer_buff = 0;
  115304. + ep->dwc_ep.xfer_buff = 0;
  115305. + ep->dwc_ep.xfer_len = 0;
  115306. + }
  115307. + pcd->ep0state = EP0_IDLE;
  115308. + if (doepint.b.setup) {
  115309. + DWC_DEBUGPL(DBG_PCDV, "EP0_IDLE SR=1 setup=1\n");
  115310. + /* Data stage started, clear setup */
  115311. + CLEAR_OUT_EP_INTR(core_if, epnum, setup);
  115312. + doepint.b.setup = 0;
  115313. + handle_ep0(pcd);
  115314. + /* Prepare for setup packets if ep0in was enabled*/
  115315. + if (pcd->ep0state == EP0_IN_STATUS_PHASE) {
  115316. + ep0_out_start(core_if, pcd);
  115317. + }
  115318. +
  115319. + goto exit_xfercompl;
  115320. + } else {
  115321. + /* Prepare for more setup packets */
  115322. + DWC_DEBUGPL(DBG_PCDV,
  115323. + "EP0_IDLE SR=1 setup=0 new setup comes 2\n");
  115324. + ep0_out_start(core_if, pcd);
  115325. + }
  115326. + }
  115327. + }
  115328. + }
  115329. + if (core_if->snpsid >= OTG_CORE_REV_2_94a && core_if->dma_enable
  115330. + && core_if->dma_desc_enable == 0) {
  115331. + doepint_data_t doepint_temp = {.d32 = 0};
  115332. + deptsiz0_data_t doeptsize0 = {.d32 = 0 };
  115333. + doepint_temp.d32 = DWC_READ_REG32(&core_if->dev_if->
  115334. + out_ep_regs[ep->dwc_ep.num]->doepint);
  115335. + doeptsize0.d32 = DWC_READ_REG32(&core_if->dev_if->
  115336. + out_ep_regs[ep->dwc_ep.num]->doeptsiz);
  115337. + if (pcd->ep0state == EP0_IDLE) {
  115338. + if (doepint_temp.b.sr) {
  115339. + CLEAR_OUT_EP_INTR(core_if, epnum, sr);
  115340. + }
  115341. + doepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  115342. + out_ep_regs[0]->doepint);
  115343. + if (doeptsize0.b.supcnt == 3) {
  115344. + DWC_DEBUGPL(DBG_ANY, "Rolling over!!!!!!!\n");
  115345. + ep->dwc_ep.stp_rollover = 1;
  115346. + }
  115347. + if (doepint.b.setup) {
  115348. +retry:
  115349. + /* Already started data stage, clear setup */
  115350. + CLEAR_OUT_EP_INTR(core_if, epnum, setup);
  115351. + doepint.b.setup = 0;
  115352. + handle_ep0(pcd);
  115353. + ep->dwc_ep.stp_rollover = 0;
  115354. + /* Prepare for more setup packets */
  115355. + if (pcd->ep0state == EP0_IN_STATUS_PHASE ||
  115356. + pcd->ep0state == EP0_IN_DATA_PHASE) {
  115357. + ep0_out_start(core_if, pcd);
  115358. + }
  115359. + goto exit_xfercompl;
  115360. + } else {
  115361. + /* Prepare for more setup packets */
  115362. + DWC_DEBUGPL(DBG_ANY,
  115363. + "EP0_IDLE SR=1 setup=0 new setup comes\n");
  115364. + doepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  115365. + out_ep_regs[0]->doepint);
  115366. + if(doepint.b.setup)
  115367. + goto retry;
  115368. + ep0_out_start(core_if, pcd);
  115369. + }
  115370. + } else {
  115371. + dwc_otg_pcd_request_t *req;
  115372. + diepint_data_t diepint0 = {.d32 = 0};
  115373. + doepint_data_t doepint_temp = {.d32 = 0};
  115374. + depctl_data_t diepctl0;
  115375. + diepint0.d32 = DWC_READ_REG32(&core_if->dev_if->
  115376. + in_ep_regs[0]->diepint);
  115377. + diepctl0.d32 = DWC_READ_REG32(&core_if->dev_if->
  115378. + in_ep_regs[0]->diepctl);
  115379. +
  115380. + if (pcd->ep0state == EP0_IN_DATA_PHASE
  115381. + || pcd->ep0state == EP0_IN_STATUS_PHASE) {
  115382. + if (diepint0.b.xfercompl) {
  115383. + DWC_WRITE_REG32(&core_if->dev_if->
  115384. + in_ep_regs[0]->diepint, diepint0.d32);
  115385. + }
  115386. + if (diepctl0.b.epena) {
  115387. + diepint_data_t diepint = {.d32 = 0};
  115388. + diepctl0.b.snak = 1;
  115389. + DWC_WRITE_REG32(&core_if->dev_if->
  115390. + in_ep_regs[0]->diepctl, diepctl0.d32);
  115391. + do {
  115392. + dwc_udelay(10);
  115393. + diepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  115394. + in_ep_regs[0]->diepint);
  115395. + } while (!diepint.b.inepnakeff);
  115396. + diepint.b.inepnakeff = 1;
  115397. + DWC_WRITE_REG32(&core_if->dev_if->
  115398. + in_ep_regs[0]->diepint, diepint.d32);
  115399. + diepctl0.d32 = 0;
  115400. + diepctl0.b.epdis = 1;
  115401. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[0]->diepctl,
  115402. + diepctl0.d32);
  115403. + do {
  115404. + dwc_udelay(10);
  115405. + diepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  115406. + in_ep_regs[0]->diepint);
  115407. + } while (!diepint.b.epdisabled);
  115408. + diepint.b.epdisabled = 1;
  115409. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[0]->diepint,
  115410. + diepint.d32);
  115411. + }
  115412. + }
  115413. + doepint_temp.d32 = DWC_READ_REG32(&core_if->dev_if->
  115414. + out_ep_regs[ep->dwc_ep.num]->doepint);
  115415. + if (doepint_temp.b.sr) {
  115416. + CLEAR_OUT_EP_INTR(core_if, epnum, sr);
  115417. + if (DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  115418. + DWC_DEBUGPL(DBG_PCDV, "Request queue empty!!\n");
  115419. + } else {
  115420. + DWC_DEBUGPL(DBG_PCDV, "complete req!!\n");
  115421. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  115422. + if (ep->dwc_ep.xfer_count != ep->dwc_ep.total_len &&
  115423. + pcd->ep0state == EP0_OUT_DATA_PHASE) {
  115424. + /* Read arrived setup packet from req->buf */
  115425. + dwc_memcpy(&pcd->setup_pkt->req,
  115426. + req->buf + ep->dwc_ep.xfer_count, 8);
  115427. + }
  115428. + req->actual = ep->dwc_ep.xfer_count;
  115429. + dwc_otg_request_done(ep, req, -ECONNRESET);
  115430. + ep->dwc_ep.start_xfer_buff = 0;
  115431. + ep->dwc_ep.xfer_buff = 0;
  115432. + ep->dwc_ep.xfer_len = 0;
  115433. + }
  115434. + pcd->ep0state = EP0_IDLE;
  115435. + if (doepint.b.setup) {
  115436. + DWC_DEBUGPL(DBG_PCDV, "EP0_IDLE SR=1 setup=1\n");
  115437. + /* Data stage started, clear setup */
  115438. + CLEAR_OUT_EP_INTR(core_if, epnum, setup);
  115439. + doepint.b.setup = 0;
  115440. + handle_ep0(pcd);
  115441. + /* Prepare for setup packets if ep0in was enabled*/
  115442. + if (pcd->ep0state == EP0_IN_STATUS_PHASE) {
  115443. + ep0_out_start(core_if, pcd);
  115444. + }
  115445. + goto exit_xfercompl;
  115446. + } else {
  115447. + /* Prepare for more setup packets */
  115448. + DWC_DEBUGPL(DBG_PCDV,
  115449. + "EP0_IDLE SR=1 setup=0 new setup comes 2\n");
  115450. + ep0_out_start(core_if, pcd);
  115451. + }
  115452. + }
  115453. + }
  115454. + }
  115455. + if (core_if->dma_enable == 0 || pcd->ep0state != EP0_IDLE)
  115456. + handle_ep0(pcd);
  115457. +exit_xfercompl:
  115458. + DWC_DEBUGPL(DBG_PCDV, "DOEPINT=%x doepint=%x\n",
  115459. + dwc_otg_read_dev_out_ep_intr(core_if, dwc_ep), doepint.d32);
  115460. + } else {
  115461. + if (core_if->dma_desc_enable == 0
  115462. + || pcd->ep0state != EP0_IDLE)
  115463. + handle_ep0(pcd);
  115464. + }
  115465. +#ifdef DWC_EN_ISOC
  115466. + } else if (dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  115467. + if (doepint.b.pktdrpsts == 0) {
  115468. + /* Clear the bit in DOEPINTn for this interrupt */
  115469. + CLEAR_OUT_EP_INTR(core_if,
  115470. + epnum,
  115471. + xfercompl);
  115472. + complete_iso_ep(pcd, ep);
  115473. + } else {
  115474. +
  115475. + doepint_data_t doepint = {.d32 = 0 };
  115476. + doepint.b.xfercompl = 1;
  115477. + doepint.b.pktdrpsts = 1;
  115478. + DWC_WRITE_REG32
  115479. + (&core_if->dev_if->out_ep_regs
  115480. + [epnum]->doepint,
  115481. + doepint.d32);
  115482. + if (handle_iso_out_pkt_dropped
  115483. + (core_if, dwc_ep)) {
  115484. + complete_iso_ep(pcd,
  115485. + ep);
  115486. + }
  115487. + }
  115488. +#endif /* DWC_EN_ISOC */
  115489. +#ifdef DWC_UTE_PER_IO
  115490. + } else if (dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  115491. + CLEAR_OUT_EP_INTR(core_if, epnum, xfercompl);
  115492. + if (!ep->stopped)
  115493. + complete_xiso_ep(ep);
  115494. +#endif /* DWC_UTE_PER_IO */
  115495. + } else {
  115496. + /* Clear the bit in DOEPINTn for this interrupt */
  115497. + CLEAR_OUT_EP_INTR(core_if, epnum,
  115498. + xfercompl);
  115499. +
  115500. + if (core_if->core_params->dev_out_nak) {
  115501. + DWC_TIMER_CANCEL(pcd->core_if->ep_xfer_timer[epnum]);
  115502. + pcd->core_if->ep_xfer_info[epnum].state = 0;
  115503. +#ifdef DEBUG
  115504. + print_memory_payload(pcd, dwc_ep);
  115505. +#endif
  115506. + }
  115507. + complete_ep(ep);
  115508. + }
  115509. +
  115510. + }
  115511. +
  115512. + /* Endpoint disable */
  115513. + if (doepint.b.epdisabled) {
  115514. +
  115515. + /* Clear the bit in DOEPINTn for this interrupt */
  115516. + CLEAR_OUT_EP_INTR(core_if, epnum, epdisabled);
  115517. + if (core_if->core_params->dev_out_nak) {
  115518. +#ifdef DEBUG
  115519. + print_memory_payload(pcd, dwc_ep);
  115520. +#endif
  115521. + /* In case of timeout condition */
  115522. + if (core_if->ep_xfer_info[epnum].state == 2) {
  115523. + dctl.d32 = DWC_READ_REG32(&core_if->dev_if->
  115524. + dev_global_regs->dctl);
  115525. + dctl.b.cgoutnak = 1;
  115526. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl,
  115527. + dctl.d32);
  115528. + /* Unmask goutnakeff interrupt which was masked
  115529. + * during handle nak out interrupt */
  115530. + gintmsk.b.goutnakeff = 1;
  115531. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk,
  115532. + 0, gintmsk.d32);
  115533. +
  115534. + complete_ep(ep);
  115535. + }
  115536. + }
  115537. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC)
  115538. + {
  115539. + dctl_data_t dctl;
  115540. + gintmsk_data_t intr_mask = {.d32 = 0};
  115541. + dwc_otg_pcd_request_t *req = 0;
  115542. +
  115543. + dctl.d32 = DWC_READ_REG32(&core_if->dev_if->
  115544. + dev_global_regs->dctl);
  115545. + dctl.b.cgoutnak = 1;
  115546. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl,
  115547. + dctl.d32);
  115548. +
  115549. + intr_mask.d32 = 0;
  115550. + intr_mask.b.incomplisoout = 1;
  115551. +
  115552. + /* Get any pending requests */
  115553. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  115554. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  115555. + if (!req) {
  115556. + DWC_PRINTF("complete_ep 0x%p, req = NULL!\n", ep);
  115557. + } else {
  115558. + dwc_otg_request_done(ep, req, 0);
  115559. + start_next_request(ep);
  115560. + }
  115561. + } else {
  115562. + DWC_PRINTF("complete_ep 0x%p, ep->queue empty!\n", ep);
  115563. + }
  115564. + }
  115565. + }
  115566. + /* AHB Error */
  115567. + if (doepint.b.ahberr) {
  115568. + DWC_ERROR("EP%d OUT AHB Error\n", epnum);
  115569. + DWC_ERROR("EP%d DEPDMA=0x%08x \n",
  115570. + epnum, core_if->dev_if->out_ep_regs[epnum]->doepdma);
  115571. + CLEAR_OUT_EP_INTR(core_if, epnum, ahberr);
  115572. + }
  115573. + /* Setup Phase Done (contorl EPs) */
  115574. + if (doepint.b.setup) {
  115575. +#ifdef DEBUG_EP0
  115576. + DWC_DEBUGPL(DBG_PCD, "EP%d SETUP Done\n", epnum);
  115577. +#endif
  115578. + CLEAR_OUT_EP_INTR(core_if, epnum, setup);
  115579. +
  115580. + handle_ep0(pcd);
  115581. + }
  115582. +
  115583. + /** OUT EP BNA Intr */
  115584. + if (doepint.b.bna) {
  115585. + CLEAR_OUT_EP_INTR(core_if, epnum, bna);
  115586. + if (core_if->dma_desc_enable) {
  115587. +#ifdef DWC_EN_ISOC
  115588. + if (dwc_ep->type ==
  115589. + DWC_OTG_EP_TYPE_ISOC) {
  115590. + /*
  115591. + * This checking is performed to prevent first "false" BNA
  115592. + * handling occuring right after reconnect
  115593. + */
  115594. + if (dwc_ep->next_frame !=
  115595. + 0xffffffff)
  115596. + dwc_otg_pcd_handle_iso_bna(ep);
  115597. + } else
  115598. +#endif /* DWC_EN_ISOC */
  115599. + {
  115600. + dwc_otg_pcd_handle_noniso_bna(ep);
  115601. + }
  115602. + }
  115603. + }
  115604. + /* Babble Interrupt */
  115605. + if (doepint.b.babble) {
  115606. + DWC_DEBUGPL(DBG_ANY, "EP%d OUT Babble\n",
  115607. + epnum);
  115608. + handle_out_ep_babble_intr(pcd, epnum);
  115609. +
  115610. + CLEAR_OUT_EP_INTR(core_if, epnum, babble);
  115611. + }
  115612. + if (doepint.b.outtknepdis) {
  115613. + DWC_DEBUGPL(DBG_ANY, "EP%d OUT Token received when EP is \
  115614. + disabled\n",epnum);
  115615. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  115616. + doepmsk_data_t doepmsk = {.d32 = 0};
  115617. + ep->dwc_ep.frame_num = core_if->frame_num;
  115618. + if (ep->dwc_ep.bInterval > 1) {
  115619. + depctl_data_t depctl;
  115620. + depctl.d32 = DWC_READ_REG32(&core_if->dev_if->
  115621. + out_ep_regs[epnum]->doepctl);
  115622. + if (ep->dwc_ep.frame_num & 0x1) {
  115623. + depctl.b.setd1pid = 1;
  115624. + depctl.b.setd0pid = 0;
  115625. + } else {
  115626. + depctl.b.setd0pid = 1;
  115627. + depctl.b.setd1pid = 0;
  115628. + }
  115629. + DWC_WRITE_REG32(&core_if->dev_if->
  115630. + out_ep_regs[epnum]->doepctl, depctl.d32);
  115631. + }
  115632. + start_next_request(ep);
  115633. + doepmsk.b.outtknepdis = 1;
  115634. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->doepmsk,
  115635. + doepmsk.d32, 0);
  115636. + }
  115637. + CLEAR_OUT_EP_INTR(core_if, epnum, outtknepdis);
  115638. + }
  115639. +
  115640. + /* NAK Interrutp */
  115641. + if (doepint.b.nak) {
  115642. + DWC_DEBUGPL(DBG_ANY, "EP%d OUT NAK\n", epnum);
  115643. + handle_out_ep_nak_intr(pcd, epnum);
  115644. +
  115645. + CLEAR_OUT_EP_INTR(core_if, epnum, nak);
  115646. + }
  115647. + /* NYET Interrutp */
  115648. + if (doepint.b.nyet) {
  115649. + DWC_DEBUGPL(DBG_ANY, "EP%d OUT NYET\n", epnum);
  115650. + handle_out_ep_nyet_intr(pcd, epnum);
  115651. +
  115652. + CLEAR_OUT_EP_INTR(core_if, epnum, nyet);
  115653. + }
  115654. + }
  115655. +
  115656. + epnum++;
  115657. + ep_intr >>= 1;
  115658. + }
  115659. +
  115660. + return 1;
  115661. +
  115662. +#undef CLEAR_OUT_EP_INTR
  115663. +}
  115664. +static int drop_transfer(uint32_t trgt_fr, uint32_t curr_fr, uint8_t frm_overrun)
  115665. +{
  115666. + int retval = 0;
  115667. + if(!frm_overrun && curr_fr >= trgt_fr)
  115668. + retval = 1;
  115669. + else if (frm_overrun
  115670. + && (curr_fr >= trgt_fr && ((curr_fr - trgt_fr) < 0x3FFF / 2)))
  115671. + retval = 1;
  115672. + return retval;
  115673. +}
  115674. +/**
  115675. + * Incomplete ISO IN Transfer Interrupt.
  115676. + * This interrupt indicates one of the following conditions occurred
  115677. + * while transmitting an ISOC transaction.
  115678. + * - Corrupted IN Token for ISOC EP.
  115679. + * - Packet not complete in FIFO.
  115680. + * The follow actions will be taken:
  115681. + * -# Determine the EP
  115682. + * -# Set incomplete flag in dwc_ep structure
  115683. + * -# Disable EP; when "Endpoint Disabled" interrupt is received
  115684. + * Flush FIFO
  115685. + */
  115686. +int32_t dwc_otg_pcd_handle_incomplete_isoc_in_intr(dwc_otg_pcd_t * pcd)
  115687. +{
  115688. + gintsts_data_t gintsts;
  115689. +
  115690. +#ifdef DWC_EN_ISOC
  115691. + dwc_otg_dev_if_t *dev_if;
  115692. + deptsiz_data_t deptsiz = {.d32 = 0 };
  115693. + depctl_data_t depctl = {.d32 = 0 };
  115694. + dsts_data_t dsts = {.d32 = 0 };
  115695. + dwc_ep_t *dwc_ep;
  115696. + int i;
  115697. +
  115698. + dev_if = GET_CORE_IF(pcd)->dev_if;
  115699. +
  115700. + for (i = 1; i <= dev_if->num_in_eps; ++i) {
  115701. + dwc_ep = &pcd->in_ep[i].dwc_ep;
  115702. + if (dwc_ep->active && dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  115703. + deptsiz.d32 =
  115704. + DWC_READ_REG32(&dev_if->in_ep_regs[i]->dieptsiz);
  115705. + depctl.d32 =
  115706. + DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  115707. +
  115708. + if (depctl.b.epdis && deptsiz.d32) {
  115709. + set_current_pkt_info(GET_CORE_IF(pcd), dwc_ep);
  115710. + if (dwc_ep->cur_pkt >= dwc_ep->pkt_cnt) {
  115711. + dwc_ep->cur_pkt = 0;
  115712. + dwc_ep->proc_buf_num =
  115713. + (dwc_ep->proc_buf_num ^ 1) & 0x1;
  115714. +
  115715. + if (dwc_ep->proc_buf_num) {
  115716. + dwc_ep->cur_pkt_addr =
  115717. + dwc_ep->xfer_buff1;
  115718. + dwc_ep->cur_pkt_dma_addr =
  115719. + dwc_ep->dma_addr1;
  115720. + } else {
  115721. + dwc_ep->cur_pkt_addr =
  115722. + dwc_ep->xfer_buff0;
  115723. + dwc_ep->cur_pkt_dma_addr =
  115724. + dwc_ep->dma_addr0;
  115725. + }
  115726. +
  115727. + }
  115728. +
  115729. + dsts.d32 =
  115730. + DWC_READ_REG32(&GET_CORE_IF(pcd)->dev_if->
  115731. + dev_global_regs->dsts);
  115732. + dwc_ep->next_frame = dsts.b.soffn;
  115733. +
  115734. + dwc_otg_iso_ep_start_frm_transfer(GET_CORE_IF
  115735. + (pcd),
  115736. + dwc_ep);
  115737. + }
  115738. + }
  115739. + }
  115740. +
  115741. +#else
  115742. + depctl_data_t depctl = {.d32 = 0 };
  115743. + dwc_ep_t *dwc_ep;
  115744. + dwc_otg_dev_if_t *dev_if;
  115745. + int i;
  115746. + dev_if = GET_CORE_IF(pcd)->dev_if;
  115747. +
  115748. + DWC_DEBUGPL(DBG_PCD,"Incomplete ISO IN \n");
  115749. +
  115750. + for (i = 1; i <= dev_if->num_in_eps; ++i) {
  115751. + dwc_ep = &pcd->in_ep[i-1].dwc_ep;
  115752. + depctl.d32 =
  115753. + DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  115754. + if (depctl.b.epena && dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  115755. + if (drop_transfer(dwc_ep->frame_num, GET_CORE_IF(pcd)->frame_num,
  115756. + dwc_ep->frm_overrun))
  115757. + {
  115758. + depctl.d32 =
  115759. + DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  115760. + depctl.b.snak = 1;
  115761. + depctl.b.epdis = 1;
  115762. + DWC_MODIFY_REG32(&dev_if->in_ep_regs[i]->diepctl, depctl.d32, depctl.d32);
  115763. + }
  115764. + }
  115765. + }
  115766. +
  115767. + /*intr_mask.b.incomplisoin = 1;
  115768. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  115769. + intr_mask.d32, 0); */
  115770. +#endif //DWC_EN_ISOC
  115771. +
  115772. + /* Clear interrupt */
  115773. + gintsts.d32 = 0;
  115774. + gintsts.b.incomplisoin = 1;
  115775. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  115776. + gintsts.d32);
  115777. +
  115778. + return 1;
  115779. +}
  115780. +
  115781. +/**
  115782. + * Incomplete ISO OUT Transfer Interrupt.
  115783. + *
  115784. + * This interrupt indicates that the core has dropped an ISO OUT
  115785. + * packet. The following conditions can be the cause:
  115786. + * - FIFO Full, the entire packet would not fit in the FIFO.
  115787. + * - CRC Error
  115788. + * - Corrupted Token
  115789. + * The follow actions will be taken:
  115790. + * -# Determine the EP
  115791. + * -# Set incomplete flag in dwc_ep structure
  115792. + * -# Read any data from the FIFO
  115793. + * -# Disable EP. When "Endpoint Disabled" interrupt is received
  115794. + * re-enable EP.
  115795. + */
  115796. +int32_t dwc_otg_pcd_handle_incomplete_isoc_out_intr(dwc_otg_pcd_t * pcd)
  115797. +{
  115798. +
  115799. + gintsts_data_t gintsts;
  115800. +
  115801. +#ifdef DWC_EN_ISOC
  115802. + dwc_otg_dev_if_t *dev_if;
  115803. + deptsiz_data_t deptsiz = {.d32 = 0 };
  115804. + depctl_data_t depctl = {.d32 = 0 };
  115805. + dsts_data_t dsts = {.d32 = 0 };
  115806. + dwc_ep_t *dwc_ep;
  115807. + int i;
  115808. +
  115809. + dev_if = GET_CORE_IF(pcd)->dev_if;
  115810. +
  115811. + for (i = 1; i <= dev_if->num_out_eps; ++i) {
  115812. + dwc_ep = &pcd->in_ep[i].dwc_ep;
  115813. + if (pcd->out_ep[i].dwc_ep.active &&
  115814. + pcd->out_ep[i].dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  115815. + deptsiz.d32 =
  115816. + DWC_READ_REG32(&dev_if->out_ep_regs[i]->doeptsiz);
  115817. + depctl.d32 =
  115818. + DWC_READ_REG32(&dev_if->out_ep_regs[i]->doepctl);
  115819. +
  115820. + if (depctl.b.epdis && deptsiz.d32) {
  115821. + set_current_pkt_info(GET_CORE_IF(pcd),
  115822. + &pcd->out_ep[i].dwc_ep);
  115823. + if (dwc_ep->cur_pkt >= dwc_ep->pkt_cnt) {
  115824. + dwc_ep->cur_pkt = 0;
  115825. + dwc_ep->proc_buf_num =
  115826. + (dwc_ep->proc_buf_num ^ 1) & 0x1;
  115827. +
  115828. + if (dwc_ep->proc_buf_num) {
  115829. + dwc_ep->cur_pkt_addr =
  115830. + dwc_ep->xfer_buff1;
  115831. + dwc_ep->cur_pkt_dma_addr =
  115832. + dwc_ep->dma_addr1;
  115833. + } else {
  115834. + dwc_ep->cur_pkt_addr =
  115835. + dwc_ep->xfer_buff0;
  115836. + dwc_ep->cur_pkt_dma_addr =
  115837. + dwc_ep->dma_addr0;
  115838. + }
  115839. +
  115840. + }
  115841. +
  115842. + dsts.d32 =
  115843. + DWC_READ_REG32(&GET_CORE_IF(pcd)->dev_if->
  115844. + dev_global_regs->dsts);
  115845. + dwc_ep->next_frame = dsts.b.soffn;
  115846. +
  115847. + dwc_otg_iso_ep_start_frm_transfer(GET_CORE_IF
  115848. + (pcd),
  115849. + dwc_ep);
  115850. + }
  115851. + }
  115852. + }
  115853. +#else
  115854. + /** @todo implement ISR */
  115855. + gintmsk_data_t intr_mask = {.d32 = 0 };
  115856. + dwc_otg_core_if_t *core_if;
  115857. + deptsiz_data_t deptsiz = {.d32 = 0 };
  115858. + depctl_data_t depctl = {.d32 = 0 };
  115859. + dctl_data_t dctl = {.d32 = 0 };
  115860. + dwc_ep_t *dwc_ep = NULL;
  115861. + int i;
  115862. + core_if = GET_CORE_IF(pcd);
  115863. +
  115864. + for (i = 0; i < core_if->dev_if->num_out_eps; ++i) {
  115865. + dwc_ep = &pcd->out_ep[i].dwc_ep;
  115866. + depctl.d32 =
  115867. + DWC_READ_REG32(&core_if->dev_if->out_ep_regs[dwc_ep->num]->doepctl);
  115868. + if (depctl.b.epena && depctl.b.dpid == (core_if->frame_num & 0x1)) {
  115869. + core_if->dev_if->isoc_ep = dwc_ep;
  115870. + deptsiz.d32 =
  115871. + DWC_READ_REG32(&core_if->dev_if->out_ep_regs[dwc_ep->num]->doeptsiz);
  115872. + break;
  115873. + }
  115874. + }
  115875. + dctl.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dctl);
  115876. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  115877. + intr_mask.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
  115878. +
  115879. + if (!intr_mask.b.goutnakeff) {
  115880. + /* Unmask it */
  115881. + intr_mask.b.goutnakeff = 1;
  115882. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, intr_mask.d32);
  115883. + }
  115884. + if (!gintsts.b.goutnakeff) {
  115885. + dctl.b.sgoutnak = 1;
  115886. + }
  115887. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32);
  115888. +
  115889. + depctl.d32 = DWC_READ_REG32(&core_if->dev_if->out_ep_regs[dwc_ep->num]->doepctl);
  115890. + if (depctl.b.epena) {
  115891. + depctl.b.epdis = 1;
  115892. + depctl.b.snak = 1;
  115893. + }
  115894. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[dwc_ep->num]->doepctl, depctl.d32);
  115895. +
  115896. + intr_mask.d32 = 0;
  115897. + intr_mask.b.incomplisoout = 1;
  115898. +
  115899. +#endif /* DWC_EN_ISOC */
  115900. +
  115901. + /* Clear interrupt */
  115902. + gintsts.d32 = 0;
  115903. + gintsts.b.incomplisoout = 1;
  115904. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  115905. + gintsts.d32);
  115906. +
  115907. + return 1;
  115908. +}
  115909. +
  115910. +/**
  115911. + * This function handles the Global IN NAK Effective interrupt.
  115912. + *
  115913. + */
  115914. +int32_t dwc_otg_pcd_handle_in_nak_effective(dwc_otg_pcd_t * pcd)
  115915. +{
  115916. + dwc_otg_dev_if_t *dev_if = GET_CORE_IF(pcd)->dev_if;
  115917. + depctl_data_t diepctl = {.d32 = 0 };
  115918. + gintmsk_data_t intr_mask = {.d32 = 0 };
  115919. + gintsts_data_t gintsts;
  115920. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  115921. + int i;
  115922. +
  115923. + DWC_DEBUGPL(DBG_PCD, "Global IN NAK Effective\n");
  115924. +
  115925. + /* Disable all active IN EPs */
  115926. + for (i = 0; i <= dev_if->num_in_eps; i++) {
  115927. + diepctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  115928. + if (!(diepctl.b.eptype & 1) && diepctl.b.epena) {
  115929. + if (core_if->start_predict > 0)
  115930. + core_if->start_predict++;
  115931. + diepctl.b.epdis = 1;
  115932. + diepctl.b.snak = 1;
  115933. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepctl, diepctl.d32);
  115934. + }
  115935. + }
  115936. +
  115937. +
  115938. + /* Disable the Global IN NAK Effective Interrupt */
  115939. + intr_mask.b.ginnakeff = 1;
  115940. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  115941. + intr_mask.d32, 0);
  115942. +
  115943. + /* Clear interrupt */
  115944. + gintsts.d32 = 0;
  115945. + gintsts.b.ginnakeff = 1;
  115946. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  115947. + gintsts.d32);
  115948. +
  115949. + return 1;
  115950. +}
  115951. +
  115952. +/**
  115953. + * OUT NAK Effective.
  115954. + *
  115955. + */
  115956. +int32_t dwc_otg_pcd_handle_out_nak_effective(dwc_otg_pcd_t * pcd)
  115957. +{
  115958. + dwc_otg_dev_if_t *dev_if = GET_CORE_IF(pcd)->dev_if;
  115959. + gintmsk_data_t intr_mask = {.d32 = 0 };
  115960. + gintsts_data_t gintsts;
  115961. + depctl_data_t doepctl;
  115962. + int i;
  115963. +
  115964. + /* Disable the Global OUT NAK Effective Interrupt */
  115965. + intr_mask.b.goutnakeff = 1;
  115966. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  115967. + intr_mask.d32, 0);
  115968. +
  115969. + /* If DEV OUT NAK enabled*/
  115970. + if (pcd->core_if->core_params->dev_out_nak) {
  115971. + /* Run over all out endpoints to determine the ep number on
  115972. + * which the timeout has happened
  115973. + */
  115974. + for (i = 0; i <= dev_if->num_out_eps; i++) {
  115975. + if ( pcd->core_if->ep_xfer_info[i].state == 2 )
  115976. + break;
  115977. + }
  115978. + if (i > dev_if->num_out_eps) {
  115979. + dctl_data_t dctl;
  115980. + dctl.d32 =
  115981. + DWC_READ_REG32(&dev_if->dev_global_regs->dctl);
  115982. + dctl.b.cgoutnak = 1;
  115983. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dctl,
  115984. + dctl.d32);
  115985. + goto out;
  115986. + }
  115987. +
  115988. + /* Disable the endpoint */
  115989. + doepctl.d32 = DWC_READ_REG32(&dev_if->out_ep_regs[i]->doepctl);
  115990. + if (doepctl.b.epena) {
  115991. + doepctl.b.epdis = 1;
  115992. + doepctl.b.snak = 1;
  115993. + }
  115994. + DWC_WRITE_REG32(&dev_if->out_ep_regs[i]->doepctl, doepctl.d32);
  115995. + return 1;
  115996. + }
  115997. + /* We come here from Incomplete ISO OUT handler */
  115998. + if (dev_if->isoc_ep) {
  115999. + dwc_ep_t *dwc_ep = (dwc_ep_t *)dev_if->isoc_ep;
  116000. + uint32_t epnum = dwc_ep->num;
  116001. + doepint_data_t doepint;
  116002. + doepint.d32 =
  116003. + DWC_READ_REG32(&dev_if->out_ep_regs[dwc_ep->num]->doepint);
  116004. + dev_if->isoc_ep = NULL;
  116005. + doepctl.d32 =
  116006. + DWC_READ_REG32(&dev_if->out_ep_regs[epnum]->doepctl);
  116007. + DWC_PRINTF("Before disable DOEPCTL = %08x\n", doepctl.d32);
  116008. + if (doepctl.b.epena) {
  116009. + doepctl.b.epdis = 1;
  116010. + doepctl.b.snak = 1;
  116011. + }
  116012. + DWC_WRITE_REG32(&dev_if->out_ep_regs[epnum]->doepctl,
  116013. + doepctl.d32);
  116014. + return 1;
  116015. + } else
  116016. + DWC_PRINTF("INTERRUPT Handler not implemented for %s\n",
  116017. + "Global OUT NAK Effective\n");
  116018. +
  116019. +out:
  116020. + /* Clear interrupt */
  116021. + gintsts.d32 = 0;
  116022. + gintsts.b.goutnakeff = 1;
  116023. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  116024. + gintsts.d32);
  116025. +
  116026. + return 1;
  116027. +}
  116028. +
  116029. +/**
  116030. + * PCD interrupt handler.
  116031. + *
  116032. + * The PCD handles the device interrupts. Many conditions can cause a
  116033. + * device interrupt. When an interrupt occurs, the device interrupt
  116034. + * service routine determines the cause of the interrupt and
  116035. + * dispatches handling to the appropriate function. These interrupt
  116036. + * handling functions are described below.
  116037. + *
  116038. + * All interrupt registers are processed from LSB to MSB.
  116039. + *
  116040. + */
  116041. +int32_t dwc_otg_pcd_handle_intr(dwc_otg_pcd_t * pcd)
  116042. +{
  116043. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  116044. +#ifdef VERBOSE
  116045. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  116046. +#endif
  116047. + gintsts_data_t gintr_status;
  116048. + int32_t retval = 0;
  116049. +
  116050. + /* Exit from ISR if core is hibernated */
  116051. + if (core_if->hibernation_suspend == 1) {
  116052. + return retval;
  116053. + }
  116054. +#ifdef VERBOSE
  116055. + DWC_DEBUGPL(DBG_ANY, "%s() gintsts=%08x gintmsk=%08x\n",
  116056. + __func__,
  116057. + DWC_READ_REG32(&global_regs->gintsts),
  116058. + DWC_READ_REG32(&global_regs->gintmsk));
  116059. +#endif
  116060. +
  116061. + if (dwc_otg_is_device_mode(core_if)) {
  116062. + DWC_SPINLOCK(pcd->lock);
  116063. +#ifdef VERBOSE
  116064. + DWC_DEBUGPL(DBG_PCDV, "%s() gintsts=%08x gintmsk=%08x\n",
  116065. + __func__,
  116066. + DWC_READ_REG32(&global_regs->gintsts),
  116067. + DWC_READ_REG32(&global_regs->gintmsk));
  116068. +#endif
  116069. +
  116070. + gintr_status.d32 = dwc_otg_read_core_intr(core_if);
  116071. +
  116072. + DWC_DEBUGPL(DBG_PCDV, "%s: gintsts&gintmsk=%08x\n",
  116073. + __func__, gintr_status.d32);
  116074. +
  116075. + if (gintr_status.b.sofintr) {
  116076. + retval |= dwc_otg_pcd_handle_sof_intr(pcd);
  116077. + }
  116078. + if (gintr_status.b.rxstsqlvl) {
  116079. + retval |=
  116080. + dwc_otg_pcd_handle_rx_status_q_level_intr(pcd);
  116081. + }
  116082. + if (gintr_status.b.nptxfempty) {
  116083. + retval |= dwc_otg_pcd_handle_np_tx_fifo_empty_intr(pcd);
  116084. + }
  116085. + if (gintr_status.b.goutnakeff) {
  116086. + retval |= dwc_otg_pcd_handle_out_nak_effective(pcd);
  116087. + }
  116088. + if (gintr_status.b.i2cintr) {
  116089. + retval |= dwc_otg_pcd_handle_i2c_intr(pcd);
  116090. + }
  116091. + if (gintr_status.b.erlysuspend) {
  116092. + retval |= dwc_otg_pcd_handle_early_suspend_intr(pcd);
  116093. + }
  116094. + if (gintr_status.b.usbreset) {
  116095. + retval |= dwc_otg_pcd_handle_usb_reset_intr(pcd);
  116096. + }
  116097. + if (gintr_status.b.enumdone) {
  116098. + retval |= dwc_otg_pcd_handle_enum_done_intr(pcd);
  116099. + }
  116100. + if (gintr_status.b.isooutdrop) {
  116101. + retval |=
  116102. + dwc_otg_pcd_handle_isoc_out_packet_dropped_intr
  116103. + (pcd);
  116104. + }
  116105. + if (gintr_status.b.eopframe) {
  116106. + retval |=
  116107. + dwc_otg_pcd_handle_end_periodic_frame_intr(pcd);
  116108. + }
  116109. + if (gintr_status.b.inepint) {
  116110. + if (!core_if->multiproc_int_enable) {
  116111. + retval |= dwc_otg_pcd_handle_in_ep_intr(pcd);
  116112. + }
  116113. + }
  116114. + if (gintr_status.b.outepintr) {
  116115. + if (!core_if->multiproc_int_enable) {
  116116. + retval |= dwc_otg_pcd_handle_out_ep_intr(pcd);
  116117. + }
  116118. + }
  116119. + if (gintr_status.b.epmismatch) {
  116120. + retval |= dwc_otg_pcd_handle_ep_mismatch_intr(pcd);
  116121. + }
  116122. + if (gintr_status.b.fetsusp) {
  116123. + retval |= dwc_otg_pcd_handle_ep_fetsusp_intr(pcd);
  116124. + }
  116125. + if (gintr_status.b.ginnakeff) {
  116126. + retval |= dwc_otg_pcd_handle_in_nak_effective(pcd);
  116127. + }
  116128. + if (gintr_status.b.incomplisoin) {
  116129. + retval |=
  116130. + dwc_otg_pcd_handle_incomplete_isoc_in_intr(pcd);
  116131. + }
  116132. + if (gintr_status.b.incomplisoout) {
  116133. + retval |=
  116134. + dwc_otg_pcd_handle_incomplete_isoc_out_intr(pcd);
  116135. + }
  116136. +
  116137. + /* In MPI mode Device Endpoints interrupts are asserted
  116138. + * without setting outepintr and inepint bits set, so these
  116139. + * Interrupt handlers are called without checking these bit-fields
  116140. + */
  116141. + if (core_if->multiproc_int_enable) {
  116142. + retval |= dwc_otg_pcd_handle_in_ep_intr(pcd);
  116143. + retval |= dwc_otg_pcd_handle_out_ep_intr(pcd);
  116144. + }
  116145. +#ifdef VERBOSE
  116146. + DWC_DEBUGPL(DBG_PCDV, "%s() gintsts=%0x\n", __func__,
  116147. + DWC_READ_REG32(&global_regs->gintsts));
  116148. +#endif
  116149. + DWC_SPINUNLOCK(pcd->lock);
  116150. + }
  116151. + return retval;
  116152. +}
  116153. +
  116154. +#endif /* DWC_HOST_ONLY */
  116155. diff -Nur linux-3.18.8/drivers/usb/host/dwc_otg/dwc_otg_pcd_linux.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_pcd_linux.c
  116156. --- linux-3.18.8/drivers/usb/host/dwc_otg/dwc_otg_pcd_linux.c 1970-01-01 01:00:00.000000000 +0100
  116157. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_pcd_linux.c 2015-03-05 14:40:16.561715806 +0100
  116158. @@ -0,0 +1,1360 @@
  116159. + /* ==========================================================================
  116160. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_pcd_linux.c $
  116161. + * $Revision: #21 $
  116162. + * $Date: 2012/08/10 $
  116163. + * $Change: 2047372 $
  116164. + *
  116165. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  116166. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  116167. + * otherwise expressly agreed to in writing between Synopsys and you.
  116168. + *
  116169. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  116170. + * any End User Software License Agreement or Agreement for Licensed Product
  116171. + * with Synopsys or any supplement thereto. You are permitted to use and
  116172. + * redistribute this Software in source and binary forms, with or without
  116173. + * modification, provided that redistributions of source code must retain this
  116174. + * notice. You may not view, use, disclose, copy or distribute this file or
  116175. + * any information contained herein except pursuant to this license grant from
  116176. + * Synopsys. If you do not agree with this notice, including the disclaimer
  116177. + * below, then you are not authorized to use the Software.
  116178. + *
  116179. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  116180. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  116181. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  116182. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  116183. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  116184. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  116185. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  116186. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  116187. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  116188. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  116189. + * DAMAGE.
  116190. + * ========================================================================== */
  116191. +#ifndef DWC_HOST_ONLY
  116192. +
  116193. +/** @file
  116194. + * This file implements the Peripheral Controller Driver.
  116195. + *
  116196. + * The Peripheral Controller Driver (PCD) is responsible for
  116197. + * translating requests from the Function Driver into the appropriate
  116198. + * actions on the DWC_otg controller. It isolates the Function Driver
  116199. + * from the specifics of the controller by providing an API to the
  116200. + * Function Driver.
  116201. + *
  116202. + * The Peripheral Controller Driver for Linux will implement the
  116203. + * Gadget API, so that the existing Gadget drivers can be used.
  116204. + * (Gadget Driver is the Linux terminology for a Function Driver.)
  116205. + *
  116206. + * The Linux Gadget API is defined in the header file
  116207. + * <code><linux/usb_gadget.h></code>. The USB EP operations API is
  116208. + * defined in the structure <code>usb_ep_ops</code> and the USB
  116209. + * Controller API is defined in the structure
  116210. + * <code>usb_gadget_ops</code>.
  116211. + *
  116212. + */
  116213. +
  116214. +#include "dwc_otg_os_dep.h"
  116215. +#include "dwc_otg_pcd_if.h"
  116216. +#include "dwc_otg_pcd.h"
  116217. +#include "dwc_otg_driver.h"
  116218. +#include "dwc_otg_dbg.h"
  116219. +
  116220. +extern bool fiq_enable;
  116221. +
  116222. +static struct gadget_wrapper {
  116223. + dwc_otg_pcd_t *pcd;
  116224. +
  116225. + struct usb_gadget gadget;
  116226. + struct usb_gadget_driver *driver;
  116227. +
  116228. + struct usb_ep ep0;
  116229. + struct usb_ep in_ep[16];
  116230. + struct usb_ep out_ep[16];
  116231. +
  116232. +} *gadget_wrapper;
  116233. +
  116234. +/* Display the contents of the buffer */
  116235. +extern void dump_msg(const u8 * buf, unsigned int length);
  116236. +/**
  116237. + * Get the dwc_otg_pcd_ep_t* from usb_ep* pointer - NULL in case
  116238. + * if the endpoint is not found
  116239. + */
  116240. +static struct dwc_otg_pcd_ep *ep_from_handle(dwc_otg_pcd_t * pcd, void *handle)
  116241. +{
  116242. + int i;
  116243. + if (pcd->ep0.priv == handle) {
  116244. + return &pcd->ep0;
  116245. + }
  116246. +
  116247. + for (i = 0; i < MAX_EPS_CHANNELS - 1; i++) {
  116248. + if (pcd->in_ep[i].priv == handle)
  116249. + return &pcd->in_ep[i];
  116250. + if (pcd->out_ep[i].priv == handle)
  116251. + return &pcd->out_ep[i];
  116252. + }
  116253. +
  116254. + return NULL;
  116255. +}
  116256. +
  116257. +/* USB Endpoint Operations */
  116258. +/*
  116259. + * The following sections briefly describe the behavior of the Gadget
  116260. + * API endpoint operations implemented in the DWC_otg driver
  116261. + * software. Detailed descriptions of the generic behavior of each of
  116262. + * these functions can be found in the Linux header file
  116263. + * include/linux/usb_gadget.h.
  116264. + *
  116265. + * The Gadget API provides wrapper functions for each of the function
  116266. + * pointers defined in usb_ep_ops. The Gadget Driver calls the wrapper
  116267. + * function, which then calls the underlying PCD function. The
  116268. + * following sections are named according to the wrapper
  116269. + * functions. Within each section, the corresponding DWC_otg PCD
  116270. + * function name is specified.
  116271. + *
  116272. + */
  116273. +
  116274. +/**
  116275. + * This function is called by the Gadget Driver for each EP to be
  116276. + * configured for the current configuration (SET_CONFIGURATION).
  116277. + *
  116278. + * This function initializes the dwc_otg_ep_t data structure, and then
  116279. + * calls dwc_otg_ep_activate.
  116280. + */
  116281. +static int ep_enable(struct usb_ep *usb_ep,
  116282. + const struct usb_endpoint_descriptor *ep_desc)
  116283. +{
  116284. + int retval;
  116285. +
  116286. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%p)\n", __func__, usb_ep, ep_desc);
  116287. +
  116288. + if (!usb_ep || !ep_desc || ep_desc->bDescriptorType != USB_DT_ENDPOINT) {
  116289. + DWC_WARN("%s, bad ep or descriptor\n", __func__);
  116290. + return -EINVAL;
  116291. + }
  116292. + if (usb_ep == &gadget_wrapper->ep0) {
  116293. + DWC_WARN("%s, bad ep(0)\n", __func__);
  116294. + return -EINVAL;
  116295. + }
  116296. +
  116297. + /* Check FIFO size? */
  116298. + if (!ep_desc->wMaxPacketSize) {
  116299. + DWC_WARN("%s, bad %s maxpacket\n", __func__, usb_ep->name);
  116300. + return -ERANGE;
  116301. + }
  116302. +
  116303. + if (!gadget_wrapper->driver ||
  116304. + gadget_wrapper->gadget.speed == USB_SPEED_UNKNOWN) {
  116305. + DWC_WARN("%s, bogus device state\n", __func__);
  116306. + return -ESHUTDOWN;
  116307. + }
  116308. +
  116309. + /* Delete after check - MAS */
  116310. +#if 0
  116311. + nat = (uint32_t) ep_desc->wMaxPacketSize;
  116312. + printk(KERN_ALERT "%s: nat (before) =%d\n", __func__, nat);
  116313. + nat = (nat >> 11) & 0x03;
  116314. + printk(KERN_ALERT "%s: nat (after) =%d\n", __func__, nat);
  116315. +#endif
  116316. + retval = dwc_otg_pcd_ep_enable(gadget_wrapper->pcd,
  116317. + (const uint8_t *)ep_desc,
  116318. + (void *)usb_ep);
  116319. + if (retval) {
  116320. + DWC_WARN("dwc_otg_pcd_ep_enable failed\n");
  116321. + return -EINVAL;
  116322. + }
  116323. +
  116324. + usb_ep->maxpacket = le16_to_cpu(ep_desc->wMaxPacketSize);
  116325. +
  116326. + return 0;
  116327. +}
  116328. +
  116329. +/**
  116330. + * This function is called when an EP is disabled due to disconnect or
  116331. + * change in configuration. Any pending requests will terminate with a
  116332. + * status of -ESHUTDOWN.
  116333. + *
  116334. + * This function modifies the dwc_otg_ep_t data structure for this EP,
  116335. + * and then calls dwc_otg_ep_deactivate.
  116336. + */
  116337. +static int ep_disable(struct usb_ep *usb_ep)
  116338. +{
  116339. + int retval;
  116340. +
  116341. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, usb_ep);
  116342. + if (!usb_ep) {
  116343. + DWC_DEBUGPL(DBG_PCD, "%s, %s not enabled\n", __func__,
  116344. + usb_ep ? usb_ep->name : NULL);
  116345. + return -EINVAL;
  116346. + }
  116347. +
  116348. + retval = dwc_otg_pcd_ep_disable(gadget_wrapper->pcd, usb_ep);
  116349. + if (retval) {
  116350. + retval = -EINVAL;
  116351. + }
  116352. +
  116353. + return retval;
  116354. +}
  116355. +
  116356. +/**
  116357. + * This function allocates a request object to use with the specified
  116358. + * endpoint.
  116359. + *
  116360. + * @param ep The endpoint to be used with with the request
  116361. + * @param gfp_flags the GFP_* flags to use.
  116362. + */
  116363. +static struct usb_request *dwc_otg_pcd_alloc_request(struct usb_ep *ep,
  116364. + gfp_t gfp_flags)
  116365. +{
  116366. + struct usb_request *usb_req;
  116367. +
  116368. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%d)\n", __func__, ep, gfp_flags);
  116369. + if (0 == ep) {
  116370. + DWC_WARN("%s() %s\n", __func__, "Invalid EP!\n");
  116371. + return 0;
  116372. + }
  116373. + usb_req = kmalloc(sizeof(*usb_req), gfp_flags);
  116374. + if (0 == usb_req) {
  116375. + DWC_WARN("%s() %s\n", __func__, "request allocation failed!\n");
  116376. + return 0;
  116377. + }
  116378. + memset(usb_req, 0, sizeof(*usb_req));
  116379. + usb_req->dma = DWC_DMA_ADDR_INVALID;
  116380. +
  116381. + return usb_req;
  116382. +}
  116383. +
  116384. +/**
  116385. + * This function frees a request object.
  116386. + *
  116387. + * @param ep The endpoint associated with the request
  116388. + * @param req The request being freed
  116389. + */
  116390. +static void dwc_otg_pcd_free_request(struct usb_ep *ep, struct usb_request *req)
  116391. +{
  116392. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%p)\n", __func__, ep, req);
  116393. +
  116394. + if (0 == ep || 0 == req) {
  116395. + DWC_WARN("%s() %s\n", __func__,
  116396. + "Invalid ep or req argument!\n");
  116397. + return;
  116398. + }
  116399. +
  116400. + kfree(req);
  116401. +}
  116402. +
  116403. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  116404. +/**
  116405. + * This function allocates an I/O buffer to be used for a transfer
  116406. + * to/from the specified endpoint.
  116407. + *
  116408. + * @param usb_ep The endpoint to be used with with the request
  116409. + * @param bytes The desired number of bytes for the buffer
  116410. + * @param dma Pointer to the buffer's DMA address; must be valid
  116411. + * @param gfp_flags the GFP_* flags to use.
  116412. + * @return address of a new buffer or null is buffer could not be allocated.
  116413. + */
  116414. +static void *dwc_otg_pcd_alloc_buffer(struct usb_ep *usb_ep, unsigned bytes,
  116415. + dma_addr_t * dma, gfp_t gfp_flags)
  116416. +{
  116417. + void *buf;
  116418. + dwc_otg_pcd_t *pcd = 0;
  116419. +
  116420. + pcd = gadget_wrapper->pcd;
  116421. +
  116422. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%d,%p,%0x)\n", __func__, usb_ep, bytes,
  116423. + dma, gfp_flags);
  116424. +
  116425. + /* Check dword alignment */
  116426. + if ((bytes & 0x3UL) != 0) {
  116427. + DWC_WARN("%s() Buffer size is not a multiple of"
  116428. + "DWORD size (%d)", __func__, bytes);
  116429. + }
  116430. +
  116431. + buf = dma_alloc_coherent(NULL, bytes, dma, gfp_flags);
  116432. +
  116433. + /* Check dword alignment */
  116434. + if (((int)buf & 0x3UL) != 0) {
  116435. + DWC_WARN("%s() Buffer is not DWORD aligned (%p)",
  116436. + __func__, buf);
  116437. + }
  116438. +
  116439. + return buf;
  116440. +}
  116441. +
  116442. +/**
  116443. + * This function frees an I/O buffer that was allocated by alloc_buffer.
  116444. + *
  116445. + * @param usb_ep the endpoint associated with the buffer
  116446. + * @param buf address of the buffer
  116447. + * @param dma The buffer's DMA address
  116448. + * @param bytes The number of bytes of the buffer
  116449. + */
  116450. +static void dwc_otg_pcd_free_buffer(struct usb_ep *usb_ep, void *buf,
  116451. + dma_addr_t dma, unsigned bytes)
  116452. +{
  116453. + dwc_otg_pcd_t *pcd = 0;
  116454. +
  116455. + pcd = gadget_wrapper->pcd;
  116456. +
  116457. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%0x,%d)\n", __func__, buf, dma, bytes);
  116458. +
  116459. + dma_free_coherent(NULL, bytes, buf, dma);
  116460. +}
  116461. +#endif
  116462. +
  116463. +/**
  116464. + * This function is used to submit an I/O Request to an EP.
  116465. + *
  116466. + * - When the request completes the request's completion callback
  116467. + * is called to return the request to the driver.
  116468. + * - An EP, except control EPs, may have multiple requests
  116469. + * pending.
  116470. + * - Once submitted the request cannot be examined or modified.
  116471. + * - Each request is turned into one or more packets.
  116472. + * - A BULK EP can queue any amount of data; the transfer is
  116473. + * packetized.
  116474. + * - Zero length Packets are specified with the request 'zero'
  116475. + * flag.
  116476. + */
  116477. +static int ep_queue(struct usb_ep *usb_ep, struct usb_request *usb_req,
  116478. + gfp_t gfp_flags)
  116479. +{
  116480. + dwc_otg_pcd_t *pcd;
  116481. + struct dwc_otg_pcd_ep *ep = NULL;
  116482. + int retval = 0, is_isoc_ep = 0;
  116483. + dma_addr_t dma_addr = DWC_DMA_ADDR_INVALID;
  116484. +
  116485. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%p,%d)\n",
  116486. + __func__, usb_ep, usb_req, gfp_flags);
  116487. +
  116488. + if (!usb_req || !usb_req->complete || !usb_req->buf) {
  116489. + DWC_WARN("bad params\n");
  116490. + return -EINVAL;
  116491. + }
  116492. +
  116493. + if (!usb_ep) {
  116494. + DWC_WARN("bad ep\n");
  116495. + return -EINVAL;
  116496. + }
  116497. +
  116498. + pcd = gadget_wrapper->pcd;
  116499. + if (!gadget_wrapper->driver ||
  116500. + gadget_wrapper->gadget.speed == USB_SPEED_UNKNOWN) {
  116501. + DWC_DEBUGPL(DBG_PCDV, "gadget.speed=%d\n",
  116502. + gadget_wrapper->gadget.speed);
  116503. + DWC_WARN("bogus device state\n");
  116504. + return -ESHUTDOWN;
  116505. + }
  116506. +
  116507. + DWC_DEBUGPL(DBG_PCD, "%s queue req %p, len %d buf %p\n",
  116508. + usb_ep->name, usb_req, usb_req->length, usb_req->buf);
  116509. +
  116510. + usb_req->status = -EINPROGRESS;
  116511. + usb_req->actual = 0;
  116512. +
  116513. + ep = ep_from_handle(pcd, usb_ep);
  116514. + if (ep == NULL)
  116515. + is_isoc_ep = 0;
  116516. + else
  116517. + is_isoc_ep = (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) ? 1 : 0;
  116518. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  116519. + dma_addr = usb_req->dma;
  116520. +#else
  116521. + if (GET_CORE_IF(pcd)->dma_enable) {
  116522. + dwc_otg_device_t *otg_dev = gadget_wrapper->pcd->otg_dev;
  116523. + struct device *dev = NULL;
  116524. +
  116525. + if (otg_dev != NULL)
  116526. + dev = DWC_OTG_OS_GETDEV(otg_dev->os_dep);
  116527. +
  116528. + if (usb_req->length != 0 &&
  116529. + usb_req->dma == DWC_DMA_ADDR_INVALID) {
  116530. + dma_addr = dma_map_single(dev, usb_req->buf,
  116531. + usb_req->length,
  116532. + ep->dwc_ep.is_in ?
  116533. + DMA_TO_DEVICE:
  116534. + DMA_FROM_DEVICE);
  116535. + }
  116536. + }
  116537. +#endif
  116538. +
  116539. +#ifdef DWC_UTE_PER_IO
  116540. + if (is_isoc_ep == 1) {
  116541. + retval = dwc_otg_pcd_xiso_ep_queue(pcd, usb_ep, usb_req->buf, dma_addr,
  116542. + usb_req->length, usb_req->zero, usb_req,
  116543. + gfp_flags == GFP_ATOMIC ? 1 : 0, &usb_req->ext_req);
  116544. + if (retval)
  116545. + return -EINVAL;
  116546. +
  116547. + return 0;
  116548. + }
  116549. +#endif
  116550. + retval = dwc_otg_pcd_ep_queue(pcd, usb_ep, usb_req->buf, dma_addr,
  116551. + usb_req->length, usb_req->zero, usb_req,
  116552. + gfp_flags == GFP_ATOMIC ? 1 : 0);
  116553. + if (retval) {
  116554. + return -EINVAL;
  116555. + }
  116556. +
  116557. + return 0;
  116558. +}
  116559. +
  116560. +/**
  116561. + * This function cancels an I/O request from an EP.
  116562. + */
  116563. +static int ep_dequeue(struct usb_ep *usb_ep, struct usb_request *usb_req)
  116564. +{
  116565. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%p)\n", __func__, usb_ep, usb_req);
  116566. +
  116567. + if (!usb_ep || !usb_req) {
  116568. + DWC_WARN("bad argument\n");
  116569. + return -EINVAL;
  116570. + }
  116571. + if (!gadget_wrapper->driver ||
  116572. + gadget_wrapper->gadget.speed == USB_SPEED_UNKNOWN) {
  116573. + DWC_WARN("bogus device state\n");
  116574. + return -ESHUTDOWN;
  116575. + }
  116576. + if (dwc_otg_pcd_ep_dequeue(gadget_wrapper->pcd, usb_ep, usb_req)) {
  116577. + return -EINVAL;
  116578. + }
  116579. +
  116580. + return 0;
  116581. +}
  116582. +
  116583. +/**
  116584. + * usb_ep_set_halt stalls an endpoint.
  116585. + *
  116586. + * usb_ep_clear_halt clears an endpoint halt and resets its data
  116587. + * toggle.
  116588. + *
  116589. + * Both of these functions are implemented with the same underlying
  116590. + * function. The behavior depends on the value argument.
  116591. + *
  116592. + * @param[in] usb_ep the Endpoint to halt or clear halt.
  116593. + * @param[in] value
  116594. + * - 0 means clear_halt.
  116595. + * - 1 means set_halt,
  116596. + * - 2 means clear stall lock flag.
  116597. + * - 3 means set stall lock flag.
  116598. + */
  116599. +static int ep_halt(struct usb_ep *usb_ep, int value)
  116600. +{
  116601. + int retval = 0;
  116602. +
  116603. + DWC_DEBUGPL(DBG_PCD, "HALT %s %d\n", usb_ep->name, value);
  116604. +
  116605. + if (!usb_ep) {
  116606. + DWC_WARN("bad ep\n");
  116607. + return -EINVAL;
  116608. + }
  116609. +
  116610. + retval = dwc_otg_pcd_ep_halt(gadget_wrapper->pcd, usb_ep, value);
  116611. + if (retval == -DWC_E_AGAIN) {
  116612. + return -EAGAIN;
  116613. + } else if (retval) {
  116614. + retval = -EINVAL;
  116615. + }
  116616. +
  116617. + return retval;
  116618. +}
  116619. +
  116620. +//#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30))
  116621. +#if 0
  116622. +/**
  116623. + * ep_wedge: sets the halt feature and ignores clear requests
  116624. + *
  116625. + * @usb_ep: the endpoint being wedged
  116626. + *
  116627. + * Use this to stall an endpoint and ignore CLEAR_FEATURE(HALT_ENDPOINT)
  116628. + * requests. If the gadget driver clears the halt status, it will
  116629. + * automatically unwedge the endpoint.
  116630. + *
  116631. + * Returns zero on success, else negative errno. *
  116632. + * Check usb_ep_set_wedge() at "usb_gadget.h" for details
  116633. + */
  116634. +static int ep_wedge(struct usb_ep *usb_ep)
  116635. +{
  116636. + int retval = 0;
  116637. +
  116638. + DWC_DEBUGPL(DBG_PCD, "WEDGE %s\n", usb_ep->name);
  116639. +
  116640. + if (!usb_ep) {
  116641. + DWC_WARN("bad ep\n");
  116642. + return -EINVAL;
  116643. + }
  116644. +
  116645. + retval = dwc_otg_pcd_ep_wedge(gadget_wrapper->pcd, usb_ep);
  116646. + if (retval == -DWC_E_AGAIN) {
  116647. + retval = -EAGAIN;
  116648. + } else if (retval) {
  116649. + retval = -EINVAL;
  116650. + }
  116651. +
  116652. + return retval;
  116653. +}
  116654. +#endif
  116655. +
  116656. +#ifdef DWC_EN_ISOC
  116657. +/**
  116658. + * This function is used to submit an ISOC Transfer Request to an EP.
  116659. + *
  116660. + * - Every time a sync period completes the request's completion callback
  116661. + * is called to provide data to the gadget driver.
  116662. + * - Once submitted the request cannot be modified.
  116663. + * - Each request is turned into periodic data packets untill ISO
  116664. + * Transfer is stopped..
  116665. + */
  116666. +static int iso_ep_start(struct usb_ep *usb_ep, struct usb_iso_request *req,
  116667. + gfp_t gfp_flags)
  116668. +{
  116669. + int retval = 0;
  116670. +
  116671. + if (!req || !req->process_buffer || !req->buf0 || !req->buf1) {
  116672. + DWC_WARN("bad params\n");
  116673. + return -EINVAL;
  116674. + }
  116675. +
  116676. + if (!usb_ep) {
  116677. + DWC_PRINTF("bad params\n");
  116678. + return -EINVAL;
  116679. + }
  116680. +
  116681. + req->status = -EINPROGRESS;
  116682. +
  116683. + retval =
  116684. + dwc_otg_pcd_iso_ep_start(gadget_wrapper->pcd, usb_ep, req->buf0,
  116685. + req->buf1, req->dma0, req->dma1,
  116686. + req->sync_frame, req->data_pattern_frame,
  116687. + req->data_per_frame,
  116688. + req->
  116689. + flags & USB_REQ_ISO_ASAP ? -1 :
  116690. + req->start_frame, req->buf_proc_intrvl,
  116691. + req, gfp_flags == GFP_ATOMIC ? 1 : 0);
  116692. +
  116693. + if (retval) {
  116694. + return -EINVAL;
  116695. + }
  116696. +
  116697. + return retval;
  116698. +}
  116699. +
  116700. +/**
  116701. + * This function stops ISO EP Periodic Data Transfer.
  116702. + */
  116703. +static int iso_ep_stop(struct usb_ep *usb_ep, struct usb_iso_request *req)
  116704. +{
  116705. + int retval = 0;
  116706. + if (!usb_ep) {
  116707. + DWC_WARN("bad ep\n");
  116708. + }
  116709. +
  116710. + if (!gadget_wrapper->driver ||
  116711. + gadget_wrapper->gadget.speed == USB_SPEED_UNKNOWN) {
  116712. + DWC_DEBUGPL(DBG_PCDV, "gadget.speed=%d\n",
  116713. + gadget_wrapper->gadget.speed);
  116714. + DWC_WARN("bogus device state\n");
  116715. + }
  116716. +
  116717. + dwc_otg_pcd_iso_ep_stop(gadget_wrapper->pcd, usb_ep, req);
  116718. + if (retval) {
  116719. + retval = -EINVAL;
  116720. + }
  116721. +
  116722. + return retval;
  116723. +}
  116724. +
  116725. +static struct usb_iso_request *alloc_iso_request(struct usb_ep *ep,
  116726. + int packets, gfp_t gfp_flags)
  116727. +{
  116728. + struct usb_iso_request *pReq = NULL;
  116729. + uint32_t req_size;
  116730. +
  116731. + req_size = sizeof(struct usb_iso_request);
  116732. + req_size +=
  116733. + (2 * packets * (sizeof(struct usb_gadget_iso_packet_descriptor)));
  116734. +
  116735. + pReq = kmalloc(req_size, gfp_flags);
  116736. + if (!pReq) {
  116737. + DWC_WARN("Can't allocate Iso Request\n");
  116738. + return 0;
  116739. + }
  116740. + pReq->iso_packet_desc0 = (void *)(pReq + 1);
  116741. +
  116742. + pReq->iso_packet_desc1 = pReq->iso_packet_desc0 + packets;
  116743. +
  116744. + return pReq;
  116745. +}
  116746. +
  116747. +static void free_iso_request(struct usb_ep *ep, struct usb_iso_request *req)
  116748. +{
  116749. + kfree(req);
  116750. +}
  116751. +
  116752. +static struct usb_isoc_ep_ops dwc_otg_pcd_ep_ops = {
  116753. + .ep_ops = {
  116754. + .enable = ep_enable,
  116755. + .disable = ep_disable,
  116756. +
  116757. + .alloc_request = dwc_otg_pcd_alloc_request,
  116758. + .free_request = dwc_otg_pcd_free_request,
  116759. +
  116760. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  116761. + .alloc_buffer = dwc_otg_pcd_alloc_buffer,
  116762. + .free_buffer = dwc_otg_pcd_free_buffer,
  116763. +#endif
  116764. +
  116765. + .queue = ep_queue,
  116766. + .dequeue = ep_dequeue,
  116767. +
  116768. + .set_halt = ep_halt,
  116769. + .fifo_status = 0,
  116770. + .fifo_flush = 0,
  116771. + },
  116772. + .iso_ep_start = iso_ep_start,
  116773. + .iso_ep_stop = iso_ep_stop,
  116774. + .alloc_iso_request = alloc_iso_request,
  116775. + .free_iso_request = free_iso_request,
  116776. +};
  116777. +
  116778. +#else
  116779. +
  116780. + int (*enable) (struct usb_ep *ep,
  116781. + const struct usb_endpoint_descriptor *desc);
  116782. + int (*disable) (struct usb_ep *ep);
  116783. +
  116784. + struct usb_request *(*alloc_request) (struct usb_ep *ep,
  116785. + gfp_t gfp_flags);
  116786. + void (*free_request) (struct usb_ep *ep, struct usb_request *req);
  116787. +
  116788. + int (*queue) (struct usb_ep *ep, struct usb_request *req,
  116789. + gfp_t gfp_flags);
  116790. + int (*dequeue) (struct usb_ep *ep, struct usb_request *req);
  116791. +
  116792. + int (*set_halt) (struct usb_ep *ep, int value);
  116793. + int (*set_wedge) (struct usb_ep *ep);
  116794. +
  116795. + int (*fifo_status) (struct usb_ep *ep);
  116796. + void (*fifo_flush) (struct usb_ep *ep);
  116797. +static struct usb_ep_ops dwc_otg_pcd_ep_ops = {
  116798. + .enable = ep_enable,
  116799. + .disable = ep_disable,
  116800. +
  116801. + .alloc_request = dwc_otg_pcd_alloc_request,
  116802. + .free_request = dwc_otg_pcd_free_request,
  116803. +
  116804. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  116805. + .alloc_buffer = dwc_otg_pcd_alloc_buffer,
  116806. + .free_buffer = dwc_otg_pcd_free_buffer,
  116807. +#else
  116808. + /* .set_wedge = ep_wedge, */
  116809. + .set_wedge = NULL, /* uses set_halt instead */
  116810. +#endif
  116811. +
  116812. + .queue = ep_queue,
  116813. + .dequeue = ep_dequeue,
  116814. +
  116815. + .set_halt = ep_halt,
  116816. + .fifo_status = 0,
  116817. + .fifo_flush = 0,
  116818. +
  116819. +};
  116820. +
  116821. +#endif /* _EN_ISOC_ */
  116822. +/* Gadget Operations */
  116823. +/**
  116824. + * The following gadget operations will be implemented in the DWC_otg
  116825. + * PCD. Functions in the API that are not described below are not
  116826. + * implemented.
  116827. + *
  116828. + * The Gadget API provides wrapper functions for each of the function
  116829. + * pointers defined in usb_gadget_ops. The Gadget Driver calls the
  116830. + * wrapper function, which then calls the underlying PCD function. The
  116831. + * following sections are named according to the wrapper functions
  116832. + * (except for ioctl, which doesn't have a wrapper function). Within
  116833. + * each section, the corresponding DWC_otg PCD function name is
  116834. + * specified.
  116835. + *
  116836. + */
  116837. +
  116838. +/**
  116839. + *Gets the USB Frame number of the last SOF.
  116840. + */
  116841. +static int get_frame_number(struct usb_gadget *gadget)
  116842. +{
  116843. + struct gadget_wrapper *d;
  116844. +
  116845. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, gadget);
  116846. +
  116847. + if (gadget == 0) {
  116848. + return -ENODEV;
  116849. + }
  116850. +
  116851. + d = container_of(gadget, struct gadget_wrapper, gadget);
  116852. + return dwc_otg_pcd_get_frame_number(d->pcd);
  116853. +}
  116854. +
  116855. +#ifdef CONFIG_USB_DWC_OTG_LPM
  116856. +static int test_lpm_enabled(struct usb_gadget *gadget)
  116857. +{
  116858. + struct gadget_wrapper *d;
  116859. +
  116860. + d = container_of(gadget, struct gadget_wrapper, gadget);
  116861. +
  116862. + return dwc_otg_pcd_is_lpm_enabled(d->pcd);
  116863. +}
  116864. +#endif
  116865. +
  116866. +/**
  116867. + * Initiates Session Request Protocol (SRP) to wakeup the host if no
  116868. + * session is in progress. If a session is already in progress, but
  116869. + * the device is suspended, remote wakeup signaling is started.
  116870. + *
  116871. + */
  116872. +static int wakeup(struct usb_gadget *gadget)
  116873. +{
  116874. + struct gadget_wrapper *d;
  116875. +
  116876. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, gadget);
  116877. +
  116878. + if (gadget == 0) {
  116879. + return -ENODEV;
  116880. + } else {
  116881. + d = container_of(gadget, struct gadget_wrapper, gadget);
  116882. + }
  116883. + dwc_otg_pcd_wakeup(d->pcd);
  116884. + return 0;
  116885. +}
  116886. +
  116887. +static const struct usb_gadget_ops dwc_otg_pcd_ops = {
  116888. + .get_frame = get_frame_number,
  116889. + .wakeup = wakeup,
  116890. +#ifdef CONFIG_USB_DWC_OTG_LPM
  116891. + .lpm_support = test_lpm_enabled,
  116892. +#endif
  116893. + // current versions must always be self-powered
  116894. +};
  116895. +
  116896. +static int _setup(dwc_otg_pcd_t * pcd, uint8_t * bytes)
  116897. +{
  116898. + int retval = -DWC_E_NOT_SUPPORTED;
  116899. + if (gadget_wrapper->driver && gadget_wrapper->driver->setup) {
  116900. + retval = gadget_wrapper->driver->setup(&gadget_wrapper->gadget,
  116901. + (struct usb_ctrlrequest
  116902. + *)bytes);
  116903. + }
  116904. +
  116905. + if (retval == -ENOTSUPP) {
  116906. + retval = -DWC_E_NOT_SUPPORTED;
  116907. + } else if (retval < 0) {
  116908. + retval = -DWC_E_INVALID;
  116909. + }
  116910. +
  116911. + return retval;
  116912. +}
  116913. +
  116914. +#ifdef DWC_EN_ISOC
  116915. +static int _isoc_complete(dwc_otg_pcd_t * pcd, void *ep_handle,
  116916. + void *req_handle, int proc_buf_num)
  116917. +{
  116918. + int i, packet_count;
  116919. + struct usb_gadget_iso_packet_descriptor *iso_packet = 0;
  116920. + struct usb_iso_request *iso_req = req_handle;
  116921. +
  116922. + if (proc_buf_num) {
  116923. + iso_packet = iso_req->iso_packet_desc1;
  116924. + } else {
  116925. + iso_packet = iso_req->iso_packet_desc0;
  116926. + }
  116927. + packet_count =
  116928. + dwc_otg_pcd_get_iso_packet_count(pcd, ep_handle, req_handle);
  116929. + for (i = 0; i < packet_count; ++i) {
  116930. + int status;
  116931. + int actual;
  116932. + int offset;
  116933. + dwc_otg_pcd_get_iso_packet_params(pcd, ep_handle, req_handle,
  116934. + i, &status, &actual, &offset);
  116935. + switch (status) {
  116936. + case -DWC_E_NO_DATA:
  116937. + status = -ENODATA;
  116938. + break;
  116939. + default:
  116940. + if (status) {
  116941. + DWC_PRINTF("unknown status in isoc packet\n");
  116942. + }
  116943. +
  116944. + }
  116945. + iso_packet[i].status = status;
  116946. + iso_packet[i].offset = offset;
  116947. + iso_packet[i].actual_length = actual;
  116948. + }
  116949. +
  116950. + iso_req->status = 0;
  116951. + iso_req->process_buffer(ep_handle, iso_req);
  116952. +
  116953. + return 0;
  116954. +}
  116955. +#endif /* DWC_EN_ISOC */
  116956. +
  116957. +#ifdef DWC_UTE_PER_IO
  116958. +/**
  116959. + * Copy the contents of the extended request to the Linux usb_request's
  116960. + * extended part and call the gadget's completion.
  116961. + *
  116962. + * @param pcd Pointer to the pcd structure
  116963. + * @param ep_handle Void pointer to the usb_ep structure
  116964. + * @param req_handle Void pointer to the usb_request structure
  116965. + * @param status Request status returned from the portable logic
  116966. + * @param ereq_port Void pointer to the extended request structure
  116967. + * created in the the portable part that contains the
  116968. + * results of the processed iso packets.
  116969. + */
  116970. +static int _xisoc_complete(dwc_otg_pcd_t * pcd, void *ep_handle,
  116971. + void *req_handle, int32_t status, void *ereq_port)
  116972. +{
  116973. + struct dwc_ute_iso_req_ext *ereqorg = NULL;
  116974. + struct dwc_iso_xreq_port *ereqport = NULL;
  116975. + struct dwc_ute_iso_packet_descriptor *desc_org = NULL;
  116976. + int i;
  116977. + struct usb_request *req;
  116978. + //struct dwc_ute_iso_packet_descriptor *
  116979. + //int status = 0;
  116980. +
  116981. + req = (struct usb_request *)req_handle;
  116982. + ereqorg = &req->ext_req;
  116983. + ereqport = (struct dwc_iso_xreq_port *)ereq_port;
  116984. + desc_org = ereqorg->per_io_frame_descs;
  116985. +
  116986. + if (req && req->complete) {
  116987. + /* Copy the request data from the portable logic to our request */
  116988. + for (i = 0; i < ereqport->pio_pkt_count; i++) {
  116989. + desc_org[i].actual_length =
  116990. + ereqport->per_io_frame_descs[i].actual_length;
  116991. + desc_org[i].status =
  116992. + ereqport->per_io_frame_descs[i].status;
  116993. + }
  116994. +
  116995. + switch (status) {
  116996. + case -DWC_E_SHUTDOWN:
  116997. + req->status = -ESHUTDOWN;
  116998. + break;
  116999. + case -DWC_E_RESTART:
  117000. + req->status = -ECONNRESET;
  117001. + break;
  117002. + case -DWC_E_INVALID:
  117003. + req->status = -EINVAL;
  117004. + break;
  117005. + case -DWC_E_TIMEOUT:
  117006. + req->status = -ETIMEDOUT;
  117007. + break;
  117008. + default:
  117009. + req->status = status;
  117010. + }
  117011. +
  117012. + /* And call the gadget's completion */
  117013. + req->complete(ep_handle, req);
  117014. + }
  117015. +
  117016. + return 0;
  117017. +}
  117018. +#endif /* DWC_UTE_PER_IO */
  117019. +
  117020. +static int _complete(dwc_otg_pcd_t * pcd, void *ep_handle,
  117021. + void *req_handle, int32_t status, uint32_t actual)
  117022. +{
  117023. + struct usb_request *req = (struct usb_request *)req_handle;
  117024. +#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,27)
  117025. + struct dwc_otg_pcd_ep *ep = NULL;
  117026. +#endif
  117027. +
  117028. + if (req && req->complete) {
  117029. + switch (status) {
  117030. + case -DWC_E_SHUTDOWN:
  117031. + req->status = -ESHUTDOWN;
  117032. + break;
  117033. + case -DWC_E_RESTART:
  117034. + req->status = -ECONNRESET;
  117035. + break;
  117036. + case -DWC_E_INVALID:
  117037. + req->status = -EINVAL;
  117038. + break;
  117039. + case -DWC_E_TIMEOUT:
  117040. + req->status = -ETIMEDOUT;
  117041. + break;
  117042. + default:
  117043. + req->status = status;
  117044. +
  117045. + }
  117046. +
  117047. + req->actual = actual;
  117048. + DWC_SPINUNLOCK(pcd->lock);
  117049. + req->complete(ep_handle, req);
  117050. + DWC_SPINLOCK(pcd->lock);
  117051. + }
  117052. +#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,27)
  117053. + ep = ep_from_handle(pcd, ep_handle);
  117054. + if (GET_CORE_IF(pcd)->dma_enable) {
  117055. + if (req->length != 0) {
  117056. + dwc_otg_device_t *otg_dev = gadget_wrapper->pcd->otg_dev;
  117057. + struct device *dev = NULL;
  117058. +
  117059. + if (otg_dev != NULL)
  117060. + dev = DWC_OTG_OS_GETDEV(otg_dev->os_dep);
  117061. +
  117062. + dma_unmap_single(dev, req->dma, req->length,
  117063. + ep->dwc_ep.is_in ?
  117064. + DMA_TO_DEVICE: DMA_FROM_DEVICE);
  117065. + }
  117066. + }
  117067. +#endif
  117068. +
  117069. + return 0;
  117070. +}
  117071. +
  117072. +static int _connect(dwc_otg_pcd_t * pcd, int speed)
  117073. +{
  117074. + gadget_wrapper->gadget.speed = speed;
  117075. + return 0;
  117076. +}
  117077. +
  117078. +static int _disconnect(dwc_otg_pcd_t * pcd)
  117079. +{
  117080. + if (gadget_wrapper->driver && gadget_wrapper->driver->disconnect) {
  117081. + gadget_wrapper->driver->disconnect(&gadget_wrapper->gadget);
  117082. + }
  117083. + return 0;
  117084. +}
  117085. +
  117086. +static int _resume(dwc_otg_pcd_t * pcd)
  117087. +{
  117088. + if (gadget_wrapper->driver && gadget_wrapper->driver->resume) {
  117089. + gadget_wrapper->driver->resume(&gadget_wrapper->gadget);
  117090. + }
  117091. +
  117092. + return 0;
  117093. +}
  117094. +
  117095. +static int _suspend(dwc_otg_pcd_t * pcd)
  117096. +{
  117097. + if (gadget_wrapper->driver && gadget_wrapper->driver->suspend) {
  117098. + gadget_wrapper->driver->suspend(&gadget_wrapper->gadget);
  117099. + }
  117100. + return 0;
  117101. +}
  117102. +
  117103. +/**
  117104. + * This function updates the otg values in the gadget structure.
  117105. + */
  117106. +static int _hnp_changed(dwc_otg_pcd_t * pcd)
  117107. +{
  117108. +
  117109. + if (!gadget_wrapper->gadget.is_otg)
  117110. + return 0;
  117111. +
  117112. + gadget_wrapper->gadget.b_hnp_enable = get_b_hnp_enable(pcd);
  117113. + gadget_wrapper->gadget.a_hnp_support = get_a_hnp_support(pcd);
  117114. + gadget_wrapper->gadget.a_alt_hnp_support = get_a_alt_hnp_support(pcd);
  117115. + return 0;
  117116. +}
  117117. +
  117118. +static int _reset(dwc_otg_pcd_t * pcd)
  117119. +{
  117120. + return 0;
  117121. +}
  117122. +
  117123. +#ifdef DWC_UTE_CFI
  117124. +static int _cfi_setup(dwc_otg_pcd_t * pcd, void *cfi_req)
  117125. +{
  117126. + int retval = -DWC_E_INVALID;
  117127. + if (gadget_wrapper->driver->cfi_feature_setup) {
  117128. + retval =
  117129. + gadget_wrapper->driver->
  117130. + cfi_feature_setup(&gadget_wrapper->gadget,
  117131. + (struct cfi_usb_ctrlrequest *)cfi_req);
  117132. + }
  117133. +
  117134. + return retval;
  117135. +}
  117136. +#endif
  117137. +
  117138. +static const struct dwc_otg_pcd_function_ops fops = {
  117139. + .complete = _complete,
  117140. +#ifdef DWC_EN_ISOC
  117141. + .isoc_complete = _isoc_complete,
  117142. +#endif
  117143. + .setup = _setup,
  117144. + .disconnect = _disconnect,
  117145. + .connect = _connect,
  117146. + .resume = _resume,
  117147. + .suspend = _suspend,
  117148. + .hnp_changed = _hnp_changed,
  117149. + .reset = _reset,
  117150. +#ifdef DWC_UTE_CFI
  117151. + .cfi_setup = _cfi_setup,
  117152. +#endif
  117153. +#ifdef DWC_UTE_PER_IO
  117154. + .xisoc_complete = _xisoc_complete,
  117155. +#endif
  117156. +};
  117157. +
  117158. +/**
  117159. + * This function is the top level PCD interrupt handler.
  117160. + */
  117161. +static irqreturn_t dwc_otg_pcd_irq(int irq, void *dev)
  117162. +{
  117163. + dwc_otg_pcd_t *pcd = dev;
  117164. + int32_t retval = IRQ_NONE;
  117165. +
  117166. + retval = dwc_otg_pcd_handle_intr(pcd);
  117167. + if (retval != 0) {
  117168. + S3C2410X_CLEAR_EINTPEND();
  117169. + }
  117170. + return IRQ_RETVAL(retval);
  117171. +}
  117172. +
  117173. +/**
  117174. + * This function initialized the usb_ep structures to there default
  117175. + * state.
  117176. + *
  117177. + * @param d Pointer on gadget_wrapper.
  117178. + */
  117179. +void gadget_add_eps(struct gadget_wrapper *d)
  117180. +{
  117181. + static const char *names[] = {
  117182. +
  117183. + "ep0",
  117184. + "ep1in",
  117185. + "ep2in",
  117186. + "ep3in",
  117187. + "ep4in",
  117188. + "ep5in",
  117189. + "ep6in",
  117190. + "ep7in",
  117191. + "ep8in",
  117192. + "ep9in",
  117193. + "ep10in",
  117194. + "ep11in",
  117195. + "ep12in",
  117196. + "ep13in",
  117197. + "ep14in",
  117198. + "ep15in",
  117199. + "ep1out",
  117200. + "ep2out",
  117201. + "ep3out",
  117202. + "ep4out",
  117203. + "ep5out",
  117204. + "ep6out",
  117205. + "ep7out",
  117206. + "ep8out",
  117207. + "ep9out",
  117208. + "ep10out",
  117209. + "ep11out",
  117210. + "ep12out",
  117211. + "ep13out",
  117212. + "ep14out",
  117213. + "ep15out"
  117214. + };
  117215. +
  117216. + int i;
  117217. + struct usb_ep *ep;
  117218. + int8_t dev_endpoints;
  117219. +
  117220. + DWC_DEBUGPL(DBG_PCDV, "%s\n", __func__);
  117221. +
  117222. + INIT_LIST_HEAD(&d->gadget.ep_list);
  117223. + d->gadget.ep0 = &d->ep0;
  117224. + d->gadget.speed = USB_SPEED_UNKNOWN;
  117225. +
  117226. + INIT_LIST_HEAD(&d->gadget.ep0->ep_list);
  117227. +
  117228. + /**
  117229. + * Initialize the EP0 structure.
  117230. + */
  117231. + ep = &d->ep0;
  117232. +
  117233. + /* Init the usb_ep structure. */
  117234. + ep->name = names[0];
  117235. + ep->ops = (struct usb_ep_ops *)&dwc_otg_pcd_ep_ops;
  117236. +
  117237. + /**
  117238. + * @todo NGS: What should the max packet size be set to
  117239. + * here? Before EP type is set?
  117240. + */
  117241. + ep->maxpacket = MAX_PACKET_SIZE;
  117242. + dwc_otg_pcd_ep_enable(d->pcd, NULL, ep);
  117243. +
  117244. + list_add_tail(&ep->ep_list, &d->gadget.ep_list);
  117245. +
  117246. + /**
  117247. + * Initialize the EP structures.
  117248. + */
  117249. + dev_endpoints = d->pcd->core_if->dev_if->num_in_eps;
  117250. +
  117251. + for (i = 0; i < dev_endpoints; i++) {
  117252. + ep = &d->in_ep[i];
  117253. +
  117254. + /* Init the usb_ep structure. */
  117255. + ep->name = names[d->pcd->in_ep[i].dwc_ep.num];
  117256. + ep->ops = (struct usb_ep_ops *)&dwc_otg_pcd_ep_ops;
  117257. +
  117258. + /**
  117259. + * @todo NGS: What should the max packet size be set to
  117260. + * here? Before EP type is set?
  117261. + */
  117262. + ep->maxpacket = MAX_PACKET_SIZE;
  117263. + list_add_tail(&ep->ep_list, &d->gadget.ep_list);
  117264. + }
  117265. +
  117266. + dev_endpoints = d->pcd->core_if->dev_if->num_out_eps;
  117267. +
  117268. + for (i = 0; i < dev_endpoints; i++) {
  117269. + ep = &d->out_ep[i];
  117270. +
  117271. + /* Init the usb_ep structure. */
  117272. + ep->name = names[15 + d->pcd->out_ep[i].dwc_ep.num];
  117273. + ep->ops = (struct usb_ep_ops *)&dwc_otg_pcd_ep_ops;
  117274. +
  117275. + /**
  117276. + * @todo NGS: What should the max packet size be set to
  117277. + * here? Before EP type is set?
  117278. + */
  117279. + ep->maxpacket = MAX_PACKET_SIZE;
  117280. +
  117281. + list_add_tail(&ep->ep_list, &d->gadget.ep_list);
  117282. + }
  117283. +
  117284. + /* remove ep0 from the list. There is a ep0 pointer. */
  117285. + list_del_init(&d->ep0.ep_list);
  117286. +
  117287. + d->ep0.maxpacket = MAX_EP0_SIZE;
  117288. +}
  117289. +
  117290. +/**
  117291. + * This function releases the Gadget device.
  117292. + * required by device_unregister().
  117293. + *
  117294. + * @todo Should this do something? Should it free the PCD?
  117295. + */
  117296. +static void dwc_otg_pcd_gadget_release(struct device *dev)
  117297. +{
  117298. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, dev);
  117299. +}
  117300. +
  117301. +static struct gadget_wrapper *alloc_wrapper(dwc_bus_dev_t *_dev)
  117302. +{
  117303. + static char pcd_name[] = "dwc_otg_pcd";
  117304. + dwc_otg_device_t *otg_dev = DWC_OTG_BUSDRVDATA(_dev);
  117305. + struct gadget_wrapper *d;
  117306. + int retval;
  117307. +
  117308. + d = DWC_ALLOC(sizeof(*d));
  117309. + if (d == NULL) {
  117310. + return NULL;
  117311. + }
  117312. +
  117313. + memset(d, 0, sizeof(*d));
  117314. +
  117315. + d->gadget.name = pcd_name;
  117316. + d->pcd = otg_dev->pcd;
  117317. +
  117318. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30)
  117319. + strcpy(d->gadget.dev.bus_id, "gadget");
  117320. +#else
  117321. + dev_set_name(&d->gadget.dev, "%s", "gadget");
  117322. +#endif
  117323. +
  117324. + d->gadget.dev.parent = &_dev->dev;
  117325. + d->gadget.dev.release = dwc_otg_pcd_gadget_release;
  117326. + d->gadget.ops = &dwc_otg_pcd_ops;
  117327. + d->gadget.max_speed = dwc_otg_pcd_is_dualspeed(otg_dev->pcd) ? USB_SPEED_HIGH:USB_SPEED_FULL;
  117328. + d->gadget.is_otg = dwc_otg_pcd_is_otg(otg_dev->pcd);
  117329. +
  117330. + d->driver = 0;
  117331. + /* Register the gadget device */
  117332. + retval = device_register(&d->gadget.dev);
  117333. + if (retval != 0) {
  117334. + DWC_ERROR("device_register failed\n");
  117335. + DWC_FREE(d);
  117336. + return NULL;
  117337. + }
  117338. +
  117339. + return d;
  117340. +}
  117341. +
  117342. +static void free_wrapper(struct gadget_wrapper *d)
  117343. +{
  117344. + if (d->driver) {
  117345. + /* should have been done already by driver model core */
  117346. + DWC_WARN("driver '%s' is still registered\n",
  117347. + d->driver->driver.name);
  117348. + usb_gadget_unregister_driver(d->driver);
  117349. + }
  117350. +
  117351. + device_unregister(&d->gadget.dev);
  117352. + DWC_FREE(d);
  117353. +}
  117354. +
  117355. +/**
  117356. + * This function initialized the PCD portion of the driver.
  117357. + *
  117358. + */
  117359. +int pcd_init(dwc_bus_dev_t *_dev)
  117360. +{
  117361. + dwc_otg_device_t *otg_dev = DWC_OTG_BUSDRVDATA(_dev);
  117362. + int retval = 0;
  117363. +
  117364. + DWC_DEBUGPL(DBG_PCDV, "%s(%p) otg_dev=%p\n", __func__, _dev, otg_dev);
  117365. +
  117366. + otg_dev->pcd = dwc_otg_pcd_init(otg_dev->core_if);
  117367. +
  117368. + if (!otg_dev->pcd) {
  117369. + DWC_ERROR("dwc_otg_pcd_init failed\n");
  117370. + return -ENOMEM;
  117371. + }
  117372. +
  117373. + otg_dev->pcd->otg_dev = otg_dev;
  117374. + gadget_wrapper = alloc_wrapper(_dev);
  117375. +
  117376. + /*
  117377. + * Initialize EP structures
  117378. + */
  117379. + gadget_add_eps(gadget_wrapper);
  117380. + /*
  117381. + * Setup interupt handler
  117382. + */
  117383. +#ifdef PLATFORM_INTERFACE
  117384. + DWC_DEBUGPL(DBG_ANY, "registering handler for irq%d\n",
  117385. + platform_get_irq(_dev, fiq_enable ? 0 : 1));
  117386. + retval = request_irq(platform_get_irq(_dev, fiq_enable ? 0 : 1), dwc_otg_pcd_irq,
  117387. + IRQF_SHARED, gadget_wrapper->gadget.name,
  117388. + otg_dev->pcd);
  117389. + if (retval != 0) {
  117390. + DWC_ERROR("request of irq%d failed\n",
  117391. + platform_get_irq(_dev, fiq_enable ? 0 : 1));
  117392. + free_wrapper(gadget_wrapper);
  117393. + return -EBUSY;
  117394. + }
  117395. +#else
  117396. + DWC_DEBUGPL(DBG_ANY, "registering handler for irq%d\n",
  117397. + _dev->irq);
  117398. + retval = request_irq(_dev->irq, dwc_otg_pcd_irq,
  117399. + IRQF_SHARED | IRQF_DISABLED,
  117400. + gadget_wrapper->gadget.name, otg_dev->pcd);
  117401. + if (retval != 0) {
  117402. + DWC_ERROR("request of irq%d failed\n", _dev->irq);
  117403. + free_wrapper(gadget_wrapper);
  117404. + return -EBUSY;
  117405. + }
  117406. +#endif
  117407. +
  117408. + dwc_otg_pcd_start(gadget_wrapper->pcd, &fops);
  117409. +
  117410. + return retval;
  117411. +}
  117412. +
  117413. +/**
  117414. + * Cleanup the PCD.
  117415. + */
  117416. +void pcd_remove(dwc_bus_dev_t *_dev)
  117417. +{
  117418. + dwc_otg_device_t *otg_dev = DWC_OTG_BUSDRVDATA(_dev);
  117419. + dwc_otg_pcd_t *pcd = otg_dev->pcd;
  117420. +
  117421. + DWC_DEBUGPL(DBG_PCDV, "%s(%p) otg_dev %p\n", __func__, _dev, otg_dev);
  117422. +
  117423. + /*
  117424. + * Free the IRQ
  117425. + */
  117426. +#ifdef PLATFORM_INTERFACE
  117427. + free_irq(platform_get_irq(_dev, 0), pcd);
  117428. +#else
  117429. + free_irq(_dev->irq, pcd);
  117430. +#endif
  117431. + dwc_otg_pcd_remove(otg_dev->pcd);
  117432. + free_wrapper(gadget_wrapper);
  117433. + otg_dev->pcd = 0;
  117434. +}
  117435. +
  117436. +/**
  117437. + * This function registers a gadget driver with the PCD.
  117438. + *
  117439. + * When a driver is successfully registered, it will receive control
  117440. + * requests including set_configuration(), which enables non-control
  117441. + * requests. then usb traffic follows until a disconnect is reported.
  117442. + * then a host may connect again, or the driver might get unbound.
  117443. + *
  117444. + * @param driver The driver being registered
  117445. + * @param bind The bind function of gadget driver
  117446. + */
  117447. +
  117448. +int usb_gadget_probe_driver(struct usb_gadget_driver *driver)
  117449. +{
  117450. + int retval;
  117451. +
  117452. + DWC_DEBUGPL(DBG_PCD, "registering gadget driver '%s'\n",
  117453. + driver->driver.name);
  117454. +
  117455. + if (!driver || driver->max_speed == USB_SPEED_UNKNOWN ||
  117456. + !driver->bind ||
  117457. + !driver->unbind || !driver->disconnect || !driver->setup) {
  117458. + DWC_DEBUGPL(DBG_PCDV, "EINVAL\n");
  117459. + return -EINVAL;
  117460. + }
  117461. + if (gadget_wrapper == 0) {
  117462. + DWC_DEBUGPL(DBG_PCDV, "ENODEV\n");
  117463. + return -ENODEV;
  117464. + }
  117465. + if (gadget_wrapper->driver != 0) {
  117466. + DWC_DEBUGPL(DBG_PCDV, "EBUSY (%p)\n", gadget_wrapper->driver);
  117467. + return -EBUSY;
  117468. + }
  117469. +
  117470. + /* hook up the driver */
  117471. + gadget_wrapper->driver = driver;
  117472. + gadget_wrapper->gadget.dev.driver = &driver->driver;
  117473. +
  117474. + DWC_DEBUGPL(DBG_PCD, "bind to driver %s\n", driver->driver.name);
  117475. + retval = driver->bind(&gadget_wrapper->gadget, gadget_wrapper->driver);
  117476. + if (retval) {
  117477. + DWC_ERROR("bind to driver %s --> error %d\n",
  117478. + driver->driver.name, retval);
  117479. + gadget_wrapper->driver = 0;
  117480. + gadget_wrapper->gadget.dev.driver = 0;
  117481. + return retval;
  117482. + }
  117483. + DWC_DEBUGPL(DBG_ANY, "registered gadget driver '%s'\n",
  117484. + driver->driver.name);
  117485. + return 0;
  117486. +}
  117487. +EXPORT_SYMBOL(usb_gadget_probe_driver);
  117488. +
  117489. +/**
  117490. + * This function unregisters a gadget driver
  117491. + *
  117492. + * @param driver The driver being unregistered
  117493. + */
  117494. +int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
  117495. +{
  117496. + //DWC_DEBUGPL(DBG_PCDV,"%s(%p)\n", __func__, _driver);
  117497. +
  117498. + if (gadget_wrapper == 0) {
  117499. + DWC_DEBUGPL(DBG_ANY, "%s Return(%d): s_pcd==0\n", __func__,
  117500. + -ENODEV);
  117501. + return -ENODEV;
  117502. + }
  117503. + if (driver == 0 || driver != gadget_wrapper->driver) {
  117504. + DWC_DEBUGPL(DBG_ANY, "%s Return(%d): driver?\n", __func__,
  117505. + -EINVAL);
  117506. + return -EINVAL;
  117507. + }
  117508. +
  117509. + driver->unbind(&gadget_wrapper->gadget);
  117510. + gadget_wrapper->driver = 0;
  117511. +
  117512. + DWC_DEBUGPL(DBG_ANY, "unregistered driver '%s'\n", driver->driver.name);
  117513. + return 0;
  117514. +}
  117515. +
  117516. +EXPORT_SYMBOL(usb_gadget_unregister_driver);
  117517. +
  117518. +#endif /* DWC_HOST_ONLY */
  117519. diff -Nur linux-3.18.8/drivers/usb/host/dwc_otg/dwc_otg_regs.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_regs.h
  117520. --- linux-3.18.8/drivers/usb/host/dwc_otg/dwc_otg_regs.h 1970-01-01 01:00:00.000000000 +0100
  117521. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_regs.h 2015-03-05 14:40:16.561715806 +0100
  117522. @@ -0,0 +1,2550 @@
  117523. +/* ==========================================================================
  117524. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_regs.h $
  117525. + * $Revision: #98 $
  117526. + * $Date: 2012/08/10 $
  117527. + * $Change: 2047372 $
  117528. + *
  117529. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  117530. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  117531. + * otherwise expressly agreed to in writing between Synopsys and you.
  117532. + *
  117533. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  117534. + * any End User Software License Agreement or Agreement for Licensed Product
  117535. + * with Synopsys or any supplement thereto. You are permitted to use and
  117536. + * redistribute this Software in source and binary forms, with or without
  117537. + * modification, provided that redistributions of source code must retain this
  117538. + * notice. You may not view, use, disclose, copy or distribute this file or
  117539. + * any information contained herein except pursuant to this license grant from
  117540. + * Synopsys. If you do not agree with this notice, including the disclaimer
  117541. + * below, then you are not authorized to use the Software.
  117542. + *
  117543. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  117544. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  117545. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  117546. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  117547. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  117548. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  117549. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  117550. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  117551. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  117552. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  117553. + * DAMAGE.
  117554. + * ========================================================================== */
  117555. +
  117556. +#ifndef __DWC_OTG_REGS_H__
  117557. +#define __DWC_OTG_REGS_H__
  117558. +
  117559. +#include "dwc_otg_core_if.h"
  117560. +
  117561. +/**
  117562. + * @file
  117563. + *
  117564. + * This file contains the data structures for accessing the DWC_otg core registers.
  117565. + *
  117566. + * The application interfaces with the HS OTG core by reading from and
  117567. + * writing to the Control and Status Register (CSR) space through the
  117568. + * AHB Slave interface. These registers are 32 bits wide, and the
  117569. + * addresses are 32-bit-block aligned.
  117570. + * CSRs are classified as follows:
  117571. + * - Core Global Registers
  117572. + * - Device Mode Registers
  117573. + * - Device Global Registers
  117574. + * - Device Endpoint Specific Registers
  117575. + * - Host Mode Registers
  117576. + * - Host Global Registers
  117577. + * - Host Port CSRs
  117578. + * - Host Channel Specific Registers
  117579. + *
  117580. + * Only the Core Global registers can be accessed in both Device and
  117581. + * Host modes. When the HS OTG core is operating in one mode, either
  117582. + * Device or Host, the application must not access registers from the
  117583. + * other mode. When the core switches from one mode to another, the
  117584. + * registers in the new mode of operation must be reprogrammed as they
  117585. + * would be after a power-on reset.
  117586. + */
  117587. +
  117588. +/****************************************************************************/
  117589. +/** DWC_otg Core registers .
  117590. + * The dwc_otg_core_global_regs structure defines the size
  117591. + * and relative field offsets for the Core Global registers.
  117592. + */
  117593. +typedef struct dwc_otg_core_global_regs {
  117594. + /** OTG Control and Status Register. <i>Offset: 000h</i> */
  117595. + volatile uint32_t gotgctl;
  117596. + /** OTG Interrupt Register. <i>Offset: 004h</i> */
  117597. + volatile uint32_t gotgint;
  117598. + /**Core AHB Configuration Register. <i>Offset: 008h</i> */
  117599. + volatile uint32_t gahbcfg;
  117600. +
  117601. +#define DWC_GLBINTRMASK 0x0001
  117602. +#define DWC_DMAENABLE 0x0020
  117603. +#define DWC_NPTXEMPTYLVL_EMPTY 0x0080
  117604. +#define DWC_NPTXEMPTYLVL_HALFEMPTY 0x0000
  117605. +#define DWC_PTXEMPTYLVL_EMPTY 0x0100
  117606. +#define DWC_PTXEMPTYLVL_HALFEMPTY 0x0000
  117607. +
  117608. + /**Core USB Configuration Register. <i>Offset: 00Ch</i> */
  117609. + volatile uint32_t gusbcfg;
  117610. + /**Core Reset Register. <i>Offset: 010h</i> */
  117611. + volatile uint32_t grstctl;
  117612. + /**Core Interrupt Register. <i>Offset: 014h</i> */
  117613. + volatile uint32_t gintsts;
  117614. + /**Core Interrupt Mask Register. <i>Offset: 018h</i> */
  117615. + volatile uint32_t gintmsk;
  117616. + /**Receive Status Queue Read Register (Read Only). <i>Offset: 01Ch</i> */
  117617. + volatile uint32_t grxstsr;
  117618. + /**Receive Status Queue Read & POP Register (Read Only). <i>Offset: 020h</i>*/
  117619. + volatile uint32_t grxstsp;
  117620. + /**Receive FIFO Size Register. <i>Offset: 024h</i> */
  117621. + volatile uint32_t grxfsiz;
  117622. + /**Non Periodic Transmit FIFO Size Register. <i>Offset: 028h</i> */
  117623. + volatile uint32_t gnptxfsiz;
  117624. + /**Non Periodic Transmit FIFO/Queue Status Register (Read
  117625. + * Only). <i>Offset: 02Ch</i> */
  117626. + volatile uint32_t gnptxsts;
  117627. + /**I2C Access Register. <i>Offset: 030h</i> */
  117628. + volatile uint32_t gi2cctl;
  117629. + /**PHY Vendor Control Register. <i>Offset: 034h</i> */
  117630. + volatile uint32_t gpvndctl;
  117631. + /**General Purpose Input/Output Register. <i>Offset: 038h</i> */
  117632. + volatile uint32_t ggpio;
  117633. + /**User ID Register. <i>Offset: 03Ch</i> */
  117634. + volatile uint32_t guid;
  117635. + /**Synopsys ID Register (Read Only). <i>Offset: 040h</i> */
  117636. + volatile uint32_t gsnpsid;
  117637. + /**User HW Config1 Register (Read Only). <i>Offset: 044h</i> */
  117638. + volatile uint32_t ghwcfg1;
  117639. + /**User HW Config2 Register (Read Only). <i>Offset: 048h</i> */
  117640. + volatile uint32_t ghwcfg2;
  117641. +#define DWC_SLAVE_ONLY_ARCH 0
  117642. +#define DWC_EXT_DMA_ARCH 1
  117643. +#define DWC_INT_DMA_ARCH 2
  117644. +
  117645. +#define DWC_MODE_HNP_SRP_CAPABLE 0
  117646. +#define DWC_MODE_SRP_ONLY_CAPABLE 1
  117647. +#define DWC_MODE_NO_HNP_SRP_CAPABLE 2
  117648. +#define DWC_MODE_SRP_CAPABLE_DEVICE 3
  117649. +#define DWC_MODE_NO_SRP_CAPABLE_DEVICE 4
  117650. +#define DWC_MODE_SRP_CAPABLE_HOST 5
  117651. +#define DWC_MODE_NO_SRP_CAPABLE_HOST 6
  117652. +
  117653. + /**User HW Config3 Register (Read Only). <i>Offset: 04Ch</i> */
  117654. + volatile uint32_t ghwcfg3;
  117655. + /**User HW Config4 Register (Read Only). <i>Offset: 050h</i>*/
  117656. + volatile uint32_t ghwcfg4;
  117657. + /** Core LPM Configuration register <i>Offset: 054h</i>*/
  117658. + volatile uint32_t glpmcfg;
  117659. + /** Global PowerDn Register <i>Offset: 058h</i> */
  117660. + volatile uint32_t gpwrdn;
  117661. + /** Global DFIFO SW Config Register <i>Offset: 05Ch</i> */
  117662. + volatile uint32_t gdfifocfg;
  117663. + /** ADP Control Register <i>Offset: 060h</i> */
  117664. + volatile uint32_t adpctl;
  117665. + /** Reserved <i>Offset: 064h-0FFh</i> */
  117666. + volatile uint32_t reserved39[39];
  117667. + /** Host Periodic Transmit FIFO Size Register. <i>Offset: 100h</i> */
  117668. + volatile uint32_t hptxfsiz;
  117669. + /** Device Periodic Transmit FIFO#n Register if dedicated fifos are disabled,
  117670. + otherwise Device Transmit FIFO#n Register.
  117671. + * <i>Offset: 104h + (FIFO_Number-1)*04h, 1 <= FIFO Number <= 15 (1<=n<=15).</i> */
  117672. + volatile uint32_t dtxfsiz[15];
  117673. +} dwc_otg_core_global_regs_t;
  117674. +
  117675. +/**
  117676. + * This union represents the bit fields of the Core OTG Control
  117677. + * and Status Register (GOTGCTL). Set the bits using the bit
  117678. + * fields then write the <i>d32</i> value to the register.
  117679. + */
  117680. +typedef union gotgctl_data {
  117681. + /** raw register data */
  117682. + uint32_t d32;
  117683. + /** register bits */
  117684. + struct {
  117685. + unsigned sesreqscs:1;
  117686. + unsigned sesreq:1;
  117687. + unsigned vbvalidoven:1;
  117688. + unsigned vbvalidovval:1;
  117689. + unsigned avalidoven:1;
  117690. + unsigned avalidovval:1;
  117691. + unsigned bvalidoven:1;
  117692. + unsigned bvalidovval:1;
  117693. + unsigned hstnegscs:1;
  117694. + unsigned hnpreq:1;
  117695. + unsigned hstsethnpen:1;
  117696. + unsigned devhnpen:1;
  117697. + unsigned reserved12_15:4;
  117698. + unsigned conidsts:1;
  117699. + unsigned dbnctime:1;
  117700. + unsigned asesvld:1;
  117701. + unsigned bsesvld:1;
  117702. + unsigned otgver:1;
  117703. + unsigned reserved1:1;
  117704. + unsigned multvalidbc:5;
  117705. + unsigned chirpen:1;
  117706. + unsigned reserved28_31:4;
  117707. + } b;
  117708. +} gotgctl_data_t;
  117709. +
  117710. +/**
  117711. + * This union represents the bit fields of the Core OTG Interrupt Register
  117712. + * (GOTGINT). Set/clear the bits using the bit fields then write the <i>d32</i>
  117713. + * value to the register.
  117714. + */
  117715. +typedef union gotgint_data {
  117716. + /** raw register data */
  117717. + uint32_t d32;
  117718. + /** register bits */
  117719. + struct {
  117720. + /** Current Mode */
  117721. + unsigned reserved0_1:2;
  117722. +
  117723. + /** Session End Detected */
  117724. + unsigned sesenddet:1;
  117725. +
  117726. + unsigned reserved3_7:5;
  117727. +
  117728. + /** Session Request Success Status Change */
  117729. + unsigned sesreqsucstschng:1;
  117730. + /** Host Negotiation Success Status Change */
  117731. + unsigned hstnegsucstschng:1;
  117732. +
  117733. + unsigned reserved10_16:7;
  117734. +
  117735. + /** Host Negotiation Detected */
  117736. + unsigned hstnegdet:1;
  117737. + /** A-Device Timeout Change */
  117738. + unsigned adevtoutchng:1;
  117739. + /** Debounce Done */
  117740. + unsigned debdone:1;
  117741. + /** Multi-Valued input changed */
  117742. + unsigned mvic:1;
  117743. +
  117744. + unsigned reserved31_21:11;
  117745. +
  117746. + } b;
  117747. +} gotgint_data_t;
  117748. +
  117749. +/**
  117750. + * This union represents the bit fields of the Core AHB Configuration
  117751. + * Register (GAHBCFG). Set/clear the bits using the bit fields then
  117752. + * write the <i>d32</i> value to the register.
  117753. + */
  117754. +typedef union gahbcfg_data {
  117755. + /** raw register data */
  117756. + uint32_t d32;
  117757. + /** register bits */
  117758. + struct {
  117759. + unsigned glblintrmsk:1;
  117760. +#define DWC_GAHBCFG_GLBINT_ENABLE 1
  117761. +
  117762. + unsigned hburstlen:4;
  117763. +#define DWC_GAHBCFG_INT_DMA_BURST_SINGLE 0
  117764. +#define DWC_GAHBCFG_INT_DMA_BURST_INCR 1
  117765. +#define DWC_GAHBCFG_INT_DMA_BURST_INCR4 3
  117766. +#define DWC_GAHBCFG_INT_DMA_BURST_INCR8 5
  117767. +#define DWC_GAHBCFG_INT_DMA_BURST_INCR16 7
  117768. +
  117769. + unsigned dmaenable:1;
  117770. +#define DWC_GAHBCFG_DMAENABLE 1
  117771. + unsigned reserved:1;
  117772. + unsigned nptxfemplvl_txfemplvl:1;
  117773. + unsigned ptxfemplvl:1;
  117774. +#define DWC_GAHBCFG_TXFEMPTYLVL_EMPTY 1
  117775. +#define DWC_GAHBCFG_TXFEMPTYLVL_HALFEMPTY 0
  117776. + unsigned reserved9_20:12;
  117777. + unsigned remmemsupp:1;
  117778. + unsigned notialldmawrit:1;
  117779. + unsigned ahbsingle:1;
  117780. + unsigned reserved24_31:8;
  117781. + } b;
  117782. +} gahbcfg_data_t;
  117783. +
  117784. +/**
  117785. + * This union represents the bit fields of the Core USB Configuration
  117786. + * Register (GUSBCFG). Set the bits using the bit fields then write
  117787. + * the <i>d32</i> value to the register.
  117788. + */
  117789. +typedef union gusbcfg_data {
  117790. + /** raw register data */
  117791. + uint32_t d32;
  117792. + /** register bits */
  117793. + struct {
  117794. + unsigned toutcal:3;
  117795. + unsigned phyif:1;
  117796. + unsigned ulpi_utmi_sel:1;
  117797. + unsigned fsintf:1;
  117798. + unsigned physel:1;
  117799. + unsigned ddrsel:1;
  117800. + unsigned srpcap:1;
  117801. + unsigned hnpcap:1;
  117802. + unsigned usbtrdtim:4;
  117803. + unsigned reserved1:1;
  117804. + unsigned phylpwrclksel:1;
  117805. + unsigned otgutmifssel:1;
  117806. + unsigned ulpi_fsls:1;
  117807. + unsigned ulpi_auto_res:1;
  117808. + unsigned ulpi_clk_sus_m:1;
  117809. + unsigned ulpi_ext_vbus_drv:1;
  117810. + unsigned ulpi_int_vbus_indicator:1;
  117811. + unsigned term_sel_dl_pulse:1;
  117812. + unsigned indicator_complement:1;
  117813. + unsigned indicator_pass_through:1;
  117814. + unsigned ulpi_int_prot_dis:1;
  117815. + unsigned ic_usb_cap:1;
  117816. + unsigned ic_traffic_pull_remove:1;
  117817. + unsigned tx_end_delay:1;
  117818. + unsigned force_host_mode:1;
  117819. + unsigned force_dev_mode:1;
  117820. + unsigned reserved31:1;
  117821. + } b;
  117822. +} gusbcfg_data_t;
  117823. +
  117824. +/**
  117825. + * This union represents the bit fields of the Core Reset Register
  117826. + * (GRSTCTL). Set/clear the bits using the bit fields then write the
  117827. + * <i>d32</i> value to the register.
  117828. + */
  117829. +typedef union grstctl_data {
  117830. + /** raw register data */
  117831. + uint32_t d32;
  117832. + /** register bits */
  117833. + struct {
  117834. + /** Core Soft Reset (CSftRst) (Device and Host)
  117835. + *
  117836. + * The application can flush the control logic in the
  117837. + * entire core using this bit. This bit resets the
  117838. + * pipelines in the AHB Clock domain as well as the
  117839. + * PHY Clock domain.
  117840. + *
  117841. + * The state machines are reset to an IDLE state, the
  117842. + * control bits in the CSRs are cleared, all the
  117843. + * transmit FIFOs and the receive FIFO are flushed.
  117844. + *
  117845. + * The status mask bits that control the generation of
  117846. + * the interrupt, are cleared, to clear the
  117847. + * interrupt. The interrupt status bits are not
  117848. + * cleared, so the application can get the status of
  117849. + * any events that occurred in the core after it has
  117850. + * set this bit.
  117851. + *
  117852. + * Any transactions on the AHB are terminated as soon
  117853. + * as possible following the protocol. Any
  117854. + * transactions on the USB are terminated immediately.
  117855. + *
  117856. + * The configuration settings in the CSRs are
  117857. + * unchanged, so the software doesn't have to
  117858. + * reprogram these registers (Device
  117859. + * Configuration/Host Configuration/Core System
  117860. + * Configuration/Core PHY Configuration).
  117861. + *
  117862. + * The application can write to this bit, any time it
  117863. + * wants to reset the core. This is a self clearing
  117864. + * bit and the core clears this bit after all the
  117865. + * necessary logic is reset in the core, which may
  117866. + * take several clocks, depending on the current state
  117867. + * of the core.
  117868. + */
  117869. + unsigned csftrst:1;
  117870. + /** Hclk Soft Reset
  117871. + *
  117872. + * The application uses this bit to reset the control logic in
  117873. + * the AHB clock domain. Only AHB clock domain pipelines are
  117874. + * reset.
  117875. + */
  117876. + unsigned hsftrst:1;
  117877. + /** Host Frame Counter Reset (Host Only)<br>
  117878. + *
  117879. + * The application can reset the (micro)frame number
  117880. + * counter inside the core, using this bit. When the
  117881. + * (micro)frame counter is reset, the subsequent SOF
  117882. + * sent out by the core, will have a (micro)frame
  117883. + * number of 0.
  117884. + */
  117885. + unsigned hstfrm:1;
  117886. + /** In Token Sequence Learning Queue Flush
  117887. + * (INTknQFlsh) (Device Only)
  117888. + */
  117889. + unsigned intknqflsh:1;
  117890. + /** RxFIFO Flush (RxFFlsh) (Device and Host)
  117891. + *
  117892. + * The application can flush the entire Receive FIFO
  117893. + * using this bit. The application must first
  117894. + * ensure that the core is not in the middle of a
  117895. + * transaction. The application should write into
  117896. + * this bit, only after making sure that neither the
  117897. + * DMA engine is reading from the RxFIFO nor the MAC
  117898. + * is writing the data in to the FIFO. The
  117899. + * application should wait until the bit is cleared
  117900. + * before performing any other operations. This bit
  117901. + * will takes 8 clocks (slowest of PHY or AHB clock)
  117902. + * to clear.
  117903. + */
  117904. + unsigned rxfflsh:1;
  117905. + /** TxFIFO Flush (TxFFlsh) (Device and Host).
  117906. + *
  117907. + * This bit is used to selectively flush a single or
  117908. + * all transmit FIFOs. The application must first
  117909. + * ensure that the core is not in the middle of a
  117910. + * transaction. The application should write into
  117911. + * this bit, only after making sure that neither the
  117912. + * DMA engine is writing into the TxFIFO nor the MAC
  117913. + * is reading the data out of the FIFO. The
  117914. + * application should wait until the core clears this
  117915. + * bit, before performing any operations. This bit
  117916. + * will takes 8 clocks (slowest of PHY or AHB clock)
  117917. + * to clear.
  117918. + */
  117919. + unsigned txfflsh:1;
  117920. +
  117921. + /** TxFIFO Number (TxFNum) (Device and Host).
  117922. + *
  117923. + * This is the FIFO number which needs to be flushed,
  117924. + * using the TxFIFO Flush bit. This field should not
  117925. + * be changed until the TxFIFO Flush bit is cleared by
  117926. + * the core.
  117927. + * - 0x0 : Non Periodic TxFIFO Flush
  117928. + * - 0x1 : Periodic TxFIFO #1 Flush in device mode
  117929. + * or Periodic TxFIFO in host mode
  117930. + * - 0x2 : Periodic TxFIFO #2 Flush in device mode.
  117931. + * - ...
  117932. + * - 0xF : Periodic TxFIFO #15 Flush in device mode
  117933. + * - 0x10: Flush all the Transmit NonPeriodic and
  117934. + * Transmit Periodic FIFOs in the core
  117935. + */
  117936. + unsigned txfnum:5;
  117937. + /** Reserved */
  117938. + unsigned reserved11_29:19;
  117939. + /** DMA Request Signal. Indicated DMA request is in
  117940. + * probress. Used for debug purpose. */
  117941. + unsigned dmareq:1;
  117942. + /** AHB Master Idle. Indicates the AHB Master State
  117943. + * Machine is in IDLE condition. */
  117944. + unsigned ahbidle:1;
  117945. + } b;
  117946. +} grstctl_t;
  117947. +
  117948. +/**
  117949. + * This union represents the bit fields of the Core Interrupt Mask
  117950. + * Register (GINTMSK). Set/clear the bits using the bit fields then
  117951. + * write the <i>d32</i> value to the register.
  117952. + */
  117953. +typedef union gintmsk_data {
  117954. + /** raw register data */
  117955. + uint32_t d32;
  117956. + /** register bits */
  117957. + struct {
  117958. + unsigned reserved0:1;
  117959. + unsigned modemismatch:1;
  117960. + unsigned otgintr:1;
  117961. + unsigned sofintr:1;
  117962. + unsigned rxstsqlvl:1;
  117963. + unsigned nptxfempty:1;
  117964. + unsigned ginnakeff:1;
  117965. + unsigned goutnakeff:1;
  117966. + unsigned ulpickint:1;
  117967. + unsigned i2cintr:1;
  117968. + unsigned erlysuspend:1;
  117969. + unsigned usbsuspend:1;
  117970. + unsigned usbreset:1;
  117971. + unsigned enumdone:1;
  117972. + unsigned isooutdrop:1;
  117973. + unsigned eopframe:1;
  117974. + unsigned restoredone:1;
  117975. + unsigned epmismatch:1;
  117976. + unsigned inepintr:1;
  117977. + unsigned outepintr:1;
  117978. + unsigned incomplisoin:1;
  117979. + unsigned incomplisoout:1;
  117980. + unsigned fetsusp:1;
  117981. + unsigned resetdet:1;
  117982. + unsigned portintr:1;
  117983. + unsigned hcintr:1;
  117984. + unsigned ptxfempty:1;
  117985. + unsigned lpmtranrcvd:1;
  117986. + unsigned conidstschng:1;
  117987. + unsigned disconnect:1;
  117988. + unsigned sessreqintr:1;
  117989. + unsigned wkupintr:1;
  117990. + } b;
  117991. +} gintmsk_data_t;
  117992. +/**
  117993. + * This union represents the bit fields of the Core Interrupt Register
  117994. + * (GINTSTS). Set/clear the bits using the bit fields then write the
  117995. + * <i>d32</i> value to the register.
  117996. + */
  117997. +typedef union gintsts_data {
  117998. + /** raw register data */
  117999. + uint32_t d32;
  118000. +#define DWC_SOF_INTR_MASK 0x0008
  118001. + /** register bits */
  118002. + struct {
  118003. +#define DWC_HOST_MODE 1
  118004. + unsigned curmode:1;
  118005. + unsigned modemismatch:1;
  118006. + unsigned otgintr:1;
  118007. + unsigned sofintr:1;
  118008. + unsigned rxstsqlvl:1;
  118009. + unsigned nptxfempty:1;
  118010. + unsigned ginnakeff:1;
  118011. + unsigned goutnakeff:1;
  118012. + unsigned ulpickint:1;
  118013. + unsigned i2cintr:1;
  118014. + unsigned erlysuspend:1;
  118015. + unsigned usbsuspend:1;
  118016. + unsigned usbreset:1;
  118017. + unsigned enumdone:1;
  118018. + unsigned isooutdrop:1;
  118019. + unsigned eopframe:1;
  118020. + unsigned restoredone:1;
  118021. + unsigned epmismatch:1;
  118022. + unsigned inepint:1;
  118023. + unsigned outepintr:1;
  118024. + unsigned incomplisoin:1;
  118025. + unsigned incomplisoout:1;
  118026. + unsigned fetsusp:1;
  118027. + unsigned resetdet:1;
  118028. + unsigned portintr:1;
  118029. + unsigned hcintr:1;
  118030. + unsigned ptxfempty:1;
  118031. + unsigned lpmtranrcvd:1;
  118032. + unsigned conidstschng:1;
  118033. + unsigned disconnect:1;
  118034. + unsigned sessreqintr:1;
  118035. + unsigned wkupintr:1;
  118036. + } b;
  118037. +} gintsts_data_t;
  118038. +
  118039. +/**
  118040. + * This union represents the bit fields in the Device Receive Status Read and
  118041. + * Pop Registers (GRXSTSR, GRXSTSP) Read the register into the <i>d32</i>
  118042. + * element then read out the bits using the <i>b</i>it elements.
  118043. + */
  118044. +typedef union device_grxsts_data {
  118045. + /** raw register data */
  118046. + uint32_t d32;
  118047. + /** register bits */
  118048. + struct {
  118049. + unsigned epnum:4;
  118050. + unsigned bcnt:11;
  118051. + unsigned dpid:2;
  118052. +
  118053. +#define DWC_STS_DATA_UPDT 0x2 // OUT Data Packet
  118054. +#define DWC_STS_XFER_COMP 0x3 // OUT Data Transfer Complete
  118055. +
  118056. +#define DWC_DSTS_GOUT_NAK 0x1 // Global OUT NAK
  118057. +#define DWC_DSTS_SETUP_COMP 0x4 // Setup Phase Complete
  118058. +#define DWC_DSTS_SETUP_UPDT 0x6 // SETUP Packet
  118059. + unsigned pktsts:4;
  118060. + unsigned fn:4;
  118061. + unsigned reserved25_31:7;
  118062. + } b;
  118063. +} device_grxsts_data_t;
  118064. +
  118065. +/**
  118066. + * This union represents the bit fields in the Host Receive Status Read and
  118067. + * Pop Registers (GRXSTSR, GRXSTSP) Read the register into the <i>d32</i>
  118068. + * element then read out the bits using the <i>b</i>it elements.
  118069. + */
  118070. +typedef union host_grxsts_data {
  118071. + /** raw register data */
  118072. + uint32_t d32;
  118073. + /** register bits */
  118074. + struct {
  118075. + unsigned chnum:4;
  118076. + unsigned bcnt:11;
  118077. + unsigned dpid:2;
  118078. +
  118079. + unsigned pktsts:4;
  118080. +#define DWC_GRXSTS_PKTSTS_IN 0x2
  118081. +#define DWC_GRXSTS_PKTSTS_IN_XFER_COMP 0x3
  118082. +#define DWC_GRXSTS_PKTSTS_DATA_TOGGLE_ERR 0x5
  118083. +#define DWC_GRXSTS_PKTSTS_CH_HALTED 0x7
  118084. +
  118085. + unsigned reserved21_31:11;
  118086. + } b;
  118087. +} host_grxsts_data_t;
  118088. +
  118089. +/**
  118090. + * This union represents the bit fields in the FIFO Size Registers (HPTXFSIZ,
  118091. + * GNPTXFSIZ, DPTXFSIZn, DIEPTXFn). Read the register into the <i>d32</i> element
  118092. + * then read out the bits using the <i>b</i>it elements.
  118093. + */
  118094. +typedef union fifosize_data {
  118095. + /** raw register data */
  118096. + uint32_t d32;
  118097. + /** register bits */
  118098. + struct {
  118099. + unsigned startaddr:16;
  118100. + unsigned depth:16;
  118101. + } b;
  118102. +} fifosize_data_t;
  118103. +
  118104. +/**
  118105. + * This union represents the bit fields in the Non-Periodic Transmit
  118106. + * FIFO/Queue Status Register (GNPTXSTS). Read the register into the
  118107. + * <i>d32</i> element then read out the bits using the <i>b</i>it
  118108. + * elements.
  118109. + */
  118110. +typedef union gnptxsts_data {
  118111. + /** raw register data */
  118112. + uint32_t d32;
  118113. + /** register bits */
  118114. + struct {
  118115. + unsigned nptxfspcavail:16;
  118116. + unsigned nptxqspcavail:8;
  118117. + /** Top of the Non-Periodic Transmit Request Queue
  118118. + * - bit 24 - Terminate (Last entry for the selected
  118119. + * channel/EP)
  118120. + * - bits 26:25 - Token Type
  118121. + * - 2'b00 - IN/OUT
  118122. + * - 2'b01 - Zero Length OUT
  118123. + * - 2'b10 - PING/Complete Split
  118124. + * - 2'b11 - Channel Halt
  118125. + * - bits 30:27 - Channel/EP Number
  118126. + */
  118127. + unsigned nptxqtop_terminate:1;
  118128. + unsigned nptxqtop_token:2;
  118129. + unsigned nptxqtop_chnep:4;
  118130. + unsigned reserved:1;
  118131. + } b;
  118132. +} gnptxsts_data_t;
  118133. +
  118134. +/**
  118135. + * This union represents the bit fields in the Transmit
  118136. + * FIFO Status Register (DTXFSTS). Read the register into the
  118137. + * <i>d32</i> element then read out the bits using the <i>b</i>it
  118138. + * elements.
  118139. + */
  118140. +typedef union dtxfsts_data {
  118141. + /** raw register data */
  118142. + uint32_t d32;
  118143. + /** register bits */
  118144. + struct {
  118145. + unsigned txfspcavail:16;
  118146. + unsigned reserved:16;
  118147. + } b;
  118148. +} dtxfsts_data_t;
  118149. +
  118150. +/**
  118151. + * This union represents the bit fields in the I2C Control Register
  118152. + * (I2CCTL). Read the register into the <i>d32</i> element then read out the
  118153. + * bits using the <i>b</i>it elements.
  118154. + */
  118155. +typedef union gi2cctl_data {
  118156. + /** raw register data */
  118157. + uint32_t d32;
  118158. + /** register bits */
  118159. + struct {
  118160. + unsigned rwdata:8;
  118161. + unsigned regaddr:8;
  118162. + unsigned addr:7;
  118163. + unsigned i2cen:1;
  118164. + unsigned ack:1;
  118165. + unsigned i2csuspctl:1;
  118166. + unsigned i2cdevaddr:2;
  118167. + unsigned i2cdatse0:1;
  118168. + unsigned reserved:1;
  118169. + unsigned rw:1;
  118170. + unsigned bsydne:1;
  118171. + } b;
  118172. +} gi2cctl_data_t;
  118173. +
  118174. +/**
  118175. + * This union represents the bit fields in the PHY Vendor Control Register
  118176. + * (GPVNDCTL). Read the register into the <i>d32</i> element then read out the
  118177. + * bits using the <i>b</i>it elements.
  118178. + */
  118179. +typedef union gpvndctl_data {
  118180. + /** raw register data */
  118181. + uint32_t d32;
  118182. + /** register bits */
  118183. + struct {
  118184. + unsigned regdata:8;
  118185. + unsigned vctrl:8;
  118186. + unsigned regaddr16_21:6;
  118187. + unsigned regwr:1;
  118188. + unsigned reserved23_24:2;
  118189. + unsigned newregreq:1;
  118190. + unsigned vstsbsy:1;
  118191. + unsigned vstsdone:1;
  118192. + unsigned reserved28_30:3;
  118193. + unsigned disulpidrvr:1;
  118194. + } b;
  118195. +} gpvndctl_data_t;
  118196. +
  118197. +/**
  118198. + * This union represents the bit fields in the General Purpose
  118199. + * Input/Output Register (GGPIO).
  118200. + * Read the register into the <i>d32</i> element then read out the
  118201. + * bits using the <i>b</i>it elements.
  118202. + */
  118203. +typedef union ggpio_data {
  118204. + /** raw register data */
  118205. + uint32_t d32;
  118206. + /** register bits */
  118207. + struct {
  118208. + unsigned gpi:16;
  118209. + unsigned gpo:16;
  118210. + } b;
  118211. +} ggpio_data_t;
  118212. +
  118213. +/**
  118214. + * This union represents the bit fields in the User ID Register
  118215. + * (GUID). Read the register into the <i>d32</i> element then read out the
  118216. + * bits using the <i>b</i>it elements.
  118217. + */
  118218. +typedef union guid_data {
  118219. + /** raw register data */
  118220. + uint32_t d32;
  118221. + /** register bits */
  118222. + struct {
  118223. + unsigned rwdata:32;
  118224. + } b;
  118225. +} guid_data_t;
  118226. +
  118227. +/**
  118228. + * This union represents the bit fields in the Synopsys ID Register
  118229. + * (GSNPSID). Read the register into the <i>d32</i> element then read out the
  118230. + * bits using the <i>b</i>it elements.
  118231. + */
  118232. +typedef union gsnpsid_data {
  118233. + /** raw register data */
  118234. + uint32_t d32;
  118235. + /** register bits */
  118236. + struct {
  118237. + unsigned rwdata:32;
  118238. + } b;
  118239. +} gsnpsid_data_t;
  118240. +
  118241. +/**
  118242. + * This union represents the bit fields in the User HW Config1
  118243. + * Register. Read the register into the <i>d32</i> element then read
  118244. + * out the bits using the <i>b</i>it elements.
  118245. + */
  118246. +typedef union hwcfg1_data {
  118247. + /** raw register data */
  118248. + uint32_t d32;
  118249. + /** register bits */
  118250. + struct {
  118251. + unsigned ep_dir0:2;
  118252. + unsigned ep_dir1:2;
  118253. + unsigned ep_dir2:2;
  118254. + unsigned ep_dir3:2;
  118255. + unsigned ep_dir4:2;
  118256. + unsigned ep_dir5:2;
  118257. + unsigned ep_dir6:2;
  118258. + unsigned ep_dir7:2;
  118259. + unsigned ep_dir8:2;
  118260. + unsigned ep_dir9:2;
  118261. + unsigned ep_dir10:2;
  118262. + unsigned ep_dir11:2;
  118263. + unsigned ep_dir12:2;
  118264. + unsigned ep_dir13:2;
  118265. + unsigned ep_dir14:2;
  118266. + unsigned ep_dir15:2;
  118267. + } b;
  118268. +} hwcfg1_data_t;
  118269. +
  118270. +/**
  118271. + * This union represents the bit fields in the User HW Config2
  118272. + * Register. Read the register into the <i>d32</i> element then read
  118273. + * out the bits using the <i>b</i>it elements.
  118274. + */
  118275. +typedef union hwcfg2_data {
  118276. + /** raw register data */
  118277. + uint32_t d32;
  118278. + /** register bits */
  118279. + struct {
  118280. + /* GHWCFG2 */
  118281. + unsigned op_mode:3;
  118282. +#define DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG 0
  118283. +#define DWC_HWCFG2_OP_MODE_SRP_ONLY_CAPABLE_OTG 1
  118284. +#define DWC_HWCFG2_OP_MODE_NO_HNP_SRP_CAPABLE_OTG 2
  118285. +#define DWC_HWCFG2_OP_MODE_SRP_CAPABLE_DEVICE 3
  118286. +#define DWC_HWCFG2_OP_MODE_NO_SRP_CAPABLE_DEVICE 4
  118287. +#define DWC_HWCFG2_OP_MODE_SRP_CAPABLE_HOST 5
  118288. +#define DWC_HWCFG2_OP_MODE_NO_SRP_CAPABLE_HOST 6
  118289. +
  118290. + unsigned architecture:2;
  118291. + unsigned point2point:1;
  118292. + unsigned hs_phy_type:2;
  118293. +#define DWC_HWCFG2_HS_PHY_TYPE_NOT_SUPPORTED 0
  118294. +#define DWC_HWCFG2_HS_PHY_TYPE_UTMI 1
  118295. +#define DWC_HWCFG2_HS_PHY_TYPE_ULPI 2
  118296. +#define DWC_HWCFG2_HS_PHY_TYPE_UTMI_ULPI 3
  118297. +
  118298. + unsigned fs_phy_type:2;
  118299. + unsigned num_dev_ep:4;
  118300. + unsigned num_host_chan:4;
  118301. + unsigned perio_ep_supported:1;
  118302. + unsigned dynamic_fifo:1;
  118303. + unsigned multi_proc_int:1;
  118304. + unsigned reserved21:1;
  118305. + unsigned nonperio_tx_q_depth:2;
  118306. + unsigned host_perio_tx_q_depth:2;
  118307. + unsigned dev_token_q_depth:5;
  118308. + unsigned otg_enable_ic_usb:1;
  118309. + } b;
  118310. +} hwcfg2_data_t;
  118311. +
  118312. +/**
  118313. + * This union represents the bit fields in the User HW Config3
  118314. + * Register. Read the register into the <i>d32</i> element then read
  118315. + * out the bits using the <i>b</i>it elements.
  118316. + */
  118317. +typedef union hwcfg3_data {
  118318. + /** raw register data */
  118319. + uint32_t d32;
  118320. + /** register bits */
  118321. + struct {
  118322. + /* GHWCFG3 */
  118323. + unsigned xfer_size_cntr_width:4;
  118324. + unsigned packet_size_cntr_width:3;
  118325. + unsigned otg_func:1;
  118326. + unsigned i2c:1;
  118327. + unsigned vendor_ctrl_if:1;
  118328. + unsigned optional_features:1;
  118329. + unsigned synch_reset_type:1;
  118330. + unsigned adp_supp:1;
  118331. + unsigned otg_enable_hsic:1;
  118332. + unsigned bc_support:1;
  118333. + unsigned otg_lpm_en:1;
  118334. + unsigned dfifo_depth:16;
  118335. + } b;
  118336. +} hwcfg3_data_t;
  118337. +
  118338. +/**
  118339. + * This union represents the bit fields in the User HW Config4
  118340. + * Register. Read the register into the <i>d32</i> element then read
  118341. + * out the bits using the <i>b</i>it elements.
  118342. + */
  118343. +typedef union hwcfg4_data {
  118344. + /** raw register data */
  118345. + uint32_t d32;
  118346. + /** register bits */
  118347. + struct {
  118348. + unsigned num_dev_perio_in_ep:4;
  118349. + unsigned power_optimiz:1;
  118350. + unsigned min_ahb_freq:1;
  118351. + unsigned hiber:1;
  118352. + unsigned xhiber:1;
  118353. + unsigned reserved:6;
  118354. + unsigned utmi_phy_data_width:2;
  118355. + unsigned num_dev_mode_ctrl_ep:4;
  118356. + unsigned iddig_filt_en:1;
  118357. + unsigned vbus_valid_filt_en:1;
  118358. + unsigned a_valid_filt_en:1;
  118359. + unsigned b_valid_filt_en:1;
  118360. + unsigned session_end_filt_en:1;
  118361. + unsigned ded_fifo_en:1;
  118362. + unsigned num_in_eps:4;
  118363. + unsigned desc_dma:1;
  118364. + unsigned desc_dma_dyn:1;
  118365. + } b;
  118366. +} hwcfg4_data_t;
  118367. +
  118368. +/**
  118369. + * This union represents the bit fields of the Core LPM Configuration
  118370. + * Register (GLPMCFG). Set the bits using bit fields then write
  118371. + * the <i>d32</i> value to the register.
  118372. + */
  118373. +typedef union glpmctl_data {
  118374. + /** raw register data */
  118375. + uint32_t d32;
  118376. + /** register bits */
  118377. + struct {
  118378. + /** LPM-Capable (LPMCap) (Device and Host)
  118379. + * The application uses this bit to control
  118380. + * the DWC_otg core LPM capabilities.
  118381. + */
  118382. + unsigned lpm_cap_en:1;
  118383. + /** LPM response programmed by application (AppL1Res) (Device)
  118384. + * Handshake response to LPM token pre-programmed
  118385. + * by device application software.
  118386. + */
  118387. + unsigned appl_resp:1;
  118388. + /** Host Initiated Resume Duration (HIRD) (Device and Host)
  118389. + * In Host mode this field indicates the value of HIRD
  118390. + * to be sent in an LPM transaction.
  118391. + * In Device mode this field is updated with the
  118392. + * Received LPM Token HIRD bmAttribute
  118393. + * when an ACK/NYET/STALL response is sent
  118394. + * to an LPM transaction.
  118395. + */
  118396. + unsigned hird:4;
  118397. + /** RemoteWakeEnable (bRemoteWake) (Device and Host)
  118398. + * In Host mode this bit indicates the value of remote
  118399. + * wake up to be sent in wIndex field of LPM transaction.
  118400. + * In Device mode this field is updated with the
  118401. + * Received LPM Token bRemoteWake bmAttribute
  118402. + * when an ACK/NYET/STALL response is sent
  118403. + * to an LPM transaction.
  118404. + */
  118405. + unsigned rem_wkup_en:1;
  118406. + /** Enable utmi_sleep_n (EnblSlpM) (Device and Host)
  118407. + * The application uses this bit to control
  118408. + * the utmi_sleep_n assertion to the PHY when in L1 state.
  118409. + */
  118410. + unsigned en_utmi_sleep:1;
  118411. + /** HIRD Threshold (HIRD_Thres) (Device and Host)
  118412. + */
  118413. + unsigned hird_thres:5;
  118414. + /** LPM Response (CoreL1Res) (Device and Host)
  118415. + * In Host mode this bit contains handsake response to
  118416. + * LPM transaction.
  118417. + * In Device mode the response of the core to
  118418. + * LPM transaction received is reflected in these two bits.
  118419. + - 0x0 : ERROR (No handshake response)
  118420. + - 0x1 : STALL
  118421. + - 0x2 : NYET
  118422. + - 0x3 : ACK
  118423. + */
  118424. + unsigned lpm_resp:2;
  118425. + /** Port Sleep Status (SlpSts) (Device and Host)
  118426. + * This bit is set as long as a Sleep condition
  118427. + * is present on the USB bus.
  118428. + */
  118429. + unsigned prt_sleep_sts:1;
  118430. + /** Sleep State Resume OK (L1ResumeOK) (Device and Host)
  118431. + * Indicates that the application or host
  118432. + * can start resume from Sleep state.
  118433. + */
  118434. + unsigned sleep_state_resumeok:1;
  118435. + /** LPM channel Index (LPM_Chnl_Indx) (Host)
  118436. + * The channel number on which the LPM transaction
  118437. + * has to be applied while sending
  118438. + * an LPM transaction to the local device.
  118439. + */
  118440. + unsigned lpm_chan_index:4;
  118441. + /** LPM Retry Count (LPM_Retry_Cnt) (Host)
  118442. + * Number host retries that would be performed
  118443. + * if the device response was not valid response.
  118444. + */
  118445. + unsigned retry_count:3;
  118446. + /** Send LPM Transaction (SndLPM) (Host)
  118447. + * When set by application software,
  118448. + * an LPM transaction containing two tokens
  118449. + * is sent.
  118450. + */
  118451. + unsigned send_lpm:1;
  118452. + /** LPM Retry status (LPM_RetryCnt_Sts) (Host)
  118453. + * Number of LPM Host Retries still remaining
  118454. + * to be transmitted for the current LPM sequence
  118455. + */
  118456. + unsigned retry_count_sts:3;
  118457. + unsigned reserved28_29:2;
  118458. + /** In host mode once this bit is set, the host
  118459. + * configures to drive the HSIC Idle state on the bus.
  118460. + * It then waits for the device to initiate the Connect sequence.
  118461. + * In device mode once this bit is set, the device waits for
  118462. + * the HSIC Idle line state on the bus. Upon receving the Idle
  118463. + * line state, it initiates the HSIC Connect sequence.
  118464. + */
  118465. + unsigned hsic_connect:1;
  118466. + /** This bit overrides and functionally inverts
  118467. + * the if_select_hsic input port signal.
  118468. + */
  118469. + unsigned inv_sel_hsic:1;
  118470. + } b;
  118471. +} glpmcfg_data_t;
  118472. +
  118473. +/**
  118474. + * This union represents the bit fields of the Core ADP Timer, Control and
  118475. + * Status Register (ADPTIMCTLSTS). Set the bits using bit fields then write
  118476. + * the <i>d32</i> value to the register.
  118477. + */
  118478. +typedef union adpctl_data {
  118479. + /** raw register data */
  118480. + uint32_t d32;
  118481. + /** register bits */
  118482. + struct {
  118483. + /** Probe Discharge (PRB_DSCHG)
  118484. + * These bits set the times for TADP_DSCHG.
  118485. + * These bits are defined as follows:
  118486. + * 2'b00 - 4 msec
  118487. + * 2'b01 - 8 msec
  118488. + * 2'b10 - 16 msec
  118489. + * 2'b11 - 32 msec
  118490. + */
  118491. + unsigned prb_dschg:2;
  118492. + /** Probe Delta (PRB_DELTA)
  118493. + * These bits set the resolution for RTIM value.
  118494. + * The bits are defined in units of 32 kHz clock cycles as follows:
  118495. + * 2'b00 - 1 cycles
  118496. + * 2'b01 - 2 cycles
  118497. + * 2'b10 - 3 cycles
  118498. + * 2'b11 - 4 cycles
  118499. + * For example if this value is chosen to 2'b01, it means that RTIM
  118500. + * increments for every 3(three) 32Khz clock cycles.
  118501. + */
  118502. + unsigned prb_delta:2;
  118503. + /** Probe Period (PRB_PER)
  118504. + * These bits sets the TADP_PRD as shown in Figure 4 as follows:
  118505. + * 2'b00 - 0.625 to 0.925 sec (typical 0.775 sec)
  118506. + * 2'b01 - 1.25 to 1.85 sec (typical 1.55 sec)
  118507. + * 2'b10 - 1.9 to 2.6 sec (typical 2.275 sec)
  118508. + * 2'b11 - Reserved
  118509. + */
  118510. + unsigned prb_per:2;
  118511. + /** These bits capture the latest time it took for VBUS to ramp from
  118512. + * VADP_SINK to VADP_PRB.
  118513. + * 0x000 - 1 cycles
  118514. + * 0x001 - 2 cycles
  118515. + * 0x002 - 3 cycles
  118516. + * etc
  118517. + * 0x7FF - 2048 cycles
  118518. + * A time of 1024 cycles at 32 kHz corresponds to a time of 32 msec.
  118519. + */
  118520. + unsigned rtim:11;
  118521. + /** Enable Probe (EnaPrb)
  118522. + * When programmed to 1'b1, the core performs a probe operation.
  118523. + * This bit is valid only if OTG_Ver = 1'b1.
  118524. + */
  118525. + unsigned enaprb:1;
  118526. + /** Enable Sense (EnaSns)
  118527. + * When programmed to 1'b1, the core performs a Sense operation.
  118528. + * This bit is valid only if OTG_Ver = 1'b1.
  118529. + */
  118530. + unsigned enasns:1;
  118531. + /** ADP Reset (ADPRes)
  118532. + * When set, ADP controller is reset.
  118533. + * This bit is valid only if OTG_Ver = 1'b1.
  118534. + */
  118535. + unsigned adpres:1;
  118536. + /** ADP Enable (ADPEn)
  118537. + * When set, the core performs either ADP probing or sensing
  118538. + * based on EnaPrb or EnaSns.
  118539. + * This bit is valid only if OTG_Ver = 1'b1.
  118540. + */
  118541. + unsigned adpen:1;
  118542. + /** ADP Probe Interrupt (ADP_PRB_INT)
  118543. + * When this bit is set, it means that the VBUS
  118544. + * voltage is greater than VADP_PRB or VADP_PRB is reached.
  118545. + * This bit is valid only if OTG_Ver = 1'b1.
  118546. + */
  118547. + unsigned adp_prb_int:1;
  118548. + /**
  118549. + * ADP Sense Interrupt (ADP_SNS_INT)
  118550. + * When this bit is set, it means that the VBUS voltage is greater than
  118551. + * VADP_SNS value or VADP_SNS is reached.
  118552. + * This bit is valid only if OTG_Ver = 1'b1.
  118553. + */
  118554. + unsigned adp_sns_int:1;
  118555. + /** ADP Tomeout Interrupt (ADP_TMOUT_INT)
  118556. + * This bit is relevant only for an ADP probe.
  118557. + * When this bit is set, it means that the ramp time has
  118558. + * completed ie ADPCTL.RTIM has reached its terminal value
  118559. + * of 0x7FF. This is a debug feature that allows software
  118560. + * to read the ramp time after each cycle.
  118561. + * This bit is valid only if OTG_Ver = 1'b1.
  118562. + */
  118563. + unsigned adp_tmout_int:1;
  118564. + /** ADP Probe Interrupt Mask (ADP_PRB_INT_MSK)
  118565. + * When this bit is set, it unmasks the interrupt due to ADP_PRB_INT.
  118566. + * This bit is valid only if OTG_Ver = 1'b1.
  118567. + */
  118568. + unsigned adp_prb_int_msk:1;
  118569. + /** ADP Sense Interrupt Mask (ADP_SNS_INT_MSK)
  118570. + * When this bit is set, it unmasks the interrupt due to ADP_SNS_INT.
  118571. + * This bit is valid only if OTG_Ver = 1'b1.
  118572. + */
  118573. + unsigned adp_sns_int_msk:1;
  118574. + /** ADP Timoeout Interrupt Mask (ADP_TMOUT_MSK)
  118575. + * When this bit is set, it unmasks the interrupt due to ADP_TMOUT_INT.
  118576. + * This bit is valid only if OTG_Ver = 1'b1.
  118577. + */
  118578. + unsigned adp_tmout_int_msk:1;
  118579. + /** Access Request
  118580. + * 2'b00 - Read/Write Valid (updated by the core)
  118581. + * 2'b01 - Read
  118582. + * 2'b00 - Write
  118583. + * 2'b00 - Reserved
  118584. + */
  118585. + unsigned ar:2;
  118586. + /** Reserved */
  118587. + unsigned reserved29_31:3;
  118588. + } b;
  118589. +} adpctl_data_t;
  118590. +
  118591. +////////////////////////////////////////////
  118592. +// Device Registers
  118593. +/**
  118594. + * Device Global Registers. <i>Offsets 800h-BFFh</i>
  118595. + *
  118596. + * The following structures define the size and relative field offsets
  118597. + * for the Device Mode Registers.
  118598. + *
  118599. + * <i>These registers are visible only in Device mode and must not be
  118600. + * accessed in Host mode, as the results are unknown.</i>
  118601. + */
  118602. +typedef struct dwc_otg_dev_global_regs {
  118603. + /** Device Configuration Register. <i>Offset 800h</i> */
  118604. + volatile uint32_t dcfg;
  118605. + /** Device Control Register. <i>Offset: 804h</i> */
  118606. + volatile uint32_t dctl;
  118607. + /** Device Status Register (Read Only). <i>Offset: 808h</i> */
  118608. + volatile uint32_t dsts;
  118609. + /** Reserved. <i>Offset: 80Ch</i> */
  118610. + uint32_t unused;
  118611. + /** Device IN Endpoint Common Interrupt Mask
  118612. + * Register. <i>Offset: 810h</i> */
  118613. + volatile uint32_t diepmsk;
  118614. + /** Device OUT Endpoint Common Interrupt Mask
  118615. + * Register. <i>Offset: 814h</i> */
  118616. + volatile uint32_t doepmsk;
  118617. + /** Device All Endpoints Interrupt Register. <i>Offset: 818h</i> */
  118618. + volatile uint32_t daint;
  118619. + /** Device All Endpoints Interrupt Mask Register. <i>Offset:
  118620. + * 81Ch</i> */
  118621. + volatile uint32_t daintmsk;
  118622. + /** Device IN Token Queue Read Register-1 (Read Only).
  118623. + * <i>Offset: 820h</i> */
  118624. + volatile uint32_t dtknqr1;
  118625. + /** Device IN Token Queue Read Register-2 (Read Only).
  118626. + * <i>Offset: 824h</i> */
  118627. + volatile uint32_t dtknqr2;
  118628. + /** Device VBUS discharge Register. <i>Offset: 828h</i> */
  118629. + volatile uint32_t dvbusdis;
  118630. + /** Device VBUS Pulse Register. <i>Offset: 82Ch</i> */
  118631. + volatile uint32_t dvbuspulse;
  118632. + /** Device IN Token Queue Read Register-3 (Read Only). /
  118633. + * Device Thresholding control register (Read/Write)
  118634. + * <i>Offset: 830h</i> */
  118635. + volatile uint32_t dtknqr3_dthrctl;
  118636. + /** Device IN Token Queue Read Register-4 (Read Only). /
  118637. + * Device IN EPs empty Inr. Mask Register (Read/Write)
  118638. + * <i>Offset: 834h</i> */
  118639. + volatile uint32_t dtknqr4_fifoemptymsk;
  118640. + /** Device Each Endpoint Interrupt Register (Read Only). /
  118641. + * <i>Offset: 838h</i> */
  118642. + volatile uint32_t deachint;
  118643. + /** Device Each Endpoint Interrupt mask Register (Read/Write). /
  118644. + * <i>Offset: 83Ch</i> */
  118645. + volatile uint32_t deachintmsk;
  118646. + /** Device Each In Endpoint Interrupt mask Register (Read/Write). /
  118647. + * <i>Offset: 840h</i> */
  118648. + volatile uint32_t diepeachintmsk[MAX_EPS_CHANNELS];
  118649. + /** Device Each Out Endpoint Interrupt mask Register (Read/Write). /
  118650. + * <i>Offset: 880h</i> */
  118651. + volatile uint32_t doepeachintmsk[MAX_EPS_CHANNELS];
  118652. +} dwc_otg_device_global_regs_t;
  118653. +
  118654. +/**
  118655. + * This union represents the bit fields in the Device Configuration
  118656. + * Register. Read the register into the <i>d32</i> member then
  118657. + * set/clear the bits using the <i>b</i>it elements. Write the
  118658. + * <i>d32</i> member to the dcfg register.
  118659. + */
  118660. +typedef union dcfg_data {
  118661. + /** raw register data */
  118662. + uint32_t d32;
  118663. + /** register bits */
  118664. + struct {
  118665. + /** Device Speed */
  118666. + unsigned devspd:2;
  118667. + /** Non Zero Length Status OUT Handshake */
  118668. + unsigned nzstsouthshk:1;
  118669. +#define DWC_DCFG_SEND_STALL 1
  118670. +
  118671. + unsigned ena32khzs:1;
  118672. + /** Device Addresses */
  118673. + unsigned devaddr:7;
  118674. + /** Periodic Frame Interval */
  118675. + unsigned perfrint:2;
  118676. +#define DWC_DCFG_FRAME_INTERVAL_80 0
  118677. +#define DWC_DCFG_FRAME_INTERVAL_85 1
  118678. +#define DWC_DCFG_FRAME_INTERVAL_90 2
  118679. +#define DWC_DCFG_FRAME_INTERVAL_95 3
  118680. +
  118681. + /** Enable Device OUT NAK for bulk in DDMA mode */
  118682. + unsigned endevoutnak:1;
  118683. +
  118684. + unsigned reserved14_17:4;
  118685. + /** In Endpoint Mis-match count */
  118686. + unsigned epmscnt:5;
  118687. + /** Enable Descriptor DMA in Device mode */
  118688. + unsigned descdma:1;
  118689. + unsigned perschintvl:2;
  118690. + unsigned resvalid:6;
  118691. + } b;
  118692. +} dcfg_data_t;
  118693. +
  118694. +/**
  118695. + * This union represents the bit fields in the Device Control
  118696. + * Register. Read the register into the <i>d32</i> member then
  118697. + * set/clear the bits using the <i>b</i>it elements.
  118698. + */
  118699. +typedef union dctl_data {
  118700. + /** raw register data */
  118701. + uint32_t d32;
  118702. + /** register bits */
  118703. + struct {
  118704. + /** Remote Wakeup */
  118705. + unsigned rmtwkupsig:1;
  118706. + /** Soft Disconnect */
  118707. + unsigned sftdiscon:1;
  118708. + /** Global Non-Periodic IN NAK Status */
  118709. + unsigned gnpinnaksts:1;
  118710. + /** Global OUT NAK Status */
  118711. + unsigned goutnaksts:1;
  118712. + /** Test Control */
  118713. + unsigned tstctl:3;
  118714. + /** Set Global Non-Periodic IN NAK */
  118715. + unsigned sgnpinnak:1;
  118716. + /** Clear Global Non-Periodic IN NAK */
  118717. + unsigned cgnpinnak:1;
  118718. + /** Set Global OUT NAK */
  118719. + unsigned sgoutnak:1;
  118720. + /** Clear Global OUT NAK */
  118721. + unsigned cgoutnak:1;
  118722. + /** Power-On Programming Done */
  118723. + unsigned pwronprgdone:1;
  118724. + /** Reserved */
  118725. + unsigned reserved:1;
  118726. + /** Global Multi Count */
  118727. + unsigned gmc:2;
  118728. + /** Ignore Frame Number for ISOC EPs */
  118729. + unsigned ifrmnum:1;
  118730. + /** NAK on Babble */
  118731. + unsigned nakonbble:1;
  118732. + /** Enable Continue on BNA */
  118733. + unsigned encontonbna:1;
  118734. +
  118735. + unsigned reserved18_31:14;
  118736. + } b;
  118737. +} dctl_data_t;
  118738. +
  118739. +/**
  118740. + * This union represents the bit fields in the Device Status
  118741. + * Register. Read the register into the <i>d32</i> member then
  118742. + * set/clear the bits using the <i>b</i>it elements.
  118743. + */
  118744. +typedef union dsts_data {
  118745. + /** raw register data */
  118746. + uint32_t d32;
  118747. + /** register bits */
  118748. + struct {
  118749. + /** Suspend Status */
  118750. + unsigned suspsts:1;
  118751. + /** Enumerated Speed */
  118752. + unsigned enumspd:2;
  118753. +#define DWC_DSTS_ENUMSPD_HS_PHY_30MHZ_OR_60MHZ 0
  118754. +#define DWC_DSTS_ENUMSPD_FS_PHY_30MHZ_OR_60MHZ 1
  118755. +#define DWC_DSTS_ENUMSPD_LS_PHY_6MHZ 2
  118756. +#define DWC_DSTS_ENUMSPD_FS_PHY_48MHZ 3
  118757. + /** Erratic Error */
  118758. + unsigned errticerr:1;
  118759. + unsigned reserved4_7:4;
  118760. + /** Frame or Microframe Number of the received SOF */
  118761. + unsigned soffn:14;
  118762. + unsigned reserved22_31:10;
  118763. + } b;
  118764. +} dsts_data_t;
  118765. +
  118766. +/**
  118767. + * This union represents the bit fields in the Device IN EP Interrupt
  118768. + * Register and the Device IN EP Common Mask Register.
  118769. + *
  118770. + * - Read the register into the <i>d32</i> member then set/clear the
  118771. + * bits using the <i>b</i>it elements.
  118772. + */
  118773. +typedef union diepint_data {
  118774. + /** raw register data */
  118775. + uint32_t d32;
  118776. + /** register bits */
  118777. + struct {
  118778. + /** Transfer complete mask */
  118779. + unsigned xfercompl:1;
  118780. + /** Endpoint disable mask */
  118781. + unsigned epdisabled:1;
  118782. + /** AHB Error mask */
  118783. + unsigned ahberr:1;
  118784. + /** TimeOUT Handshake mask (non-ISOC EPs) */
  118785. + unsigned timeout:1;
  118786. + /** IN Token received with TxF Empty mask */
  118787. + unsigned intktxfemp:1;
  118788. + /** IN Token Received with EP mismatch mask */
  118789. + unsigned intknepmis:1;
  118790. + /** IN Endpoint NAK Effective mask */
  118791. + unsigned inepnakeff:1;
  118792. + /** Reserved */
  118793. + unsigned emptyintr:1;
  118794. +
  118795. + unsigned txfifoundrn:1;
  118796. +
  118797. + /** BNA Interrupt mask */
  118798. + unsigned bna:1;
  118799. +
  118800. + unsigned reserved10_12:3;
  118801. + /** BNA Interrupt mask */
  118802. + unsigned nak:1;
  118803. +
  118804. + unsigned reserved14_31:18;
  118805. + } b;
  118806. +} diepint_data_t;
  118807. +
  118808. +/**
  118809. + * This union represents the bit fields in the Device IN EP
  118810. + * Common/Dedicated Interrupt Mask Register.
  118811. + */
  118812. +typedef union diepint_data diepmsk_data_t;
  118813. +
  118814. +/**
  118815. + * This union represents the bit fields in the Device OUT EP Interrupt
  118816. + * Registerand Device OUT EP Common Interrupt Mask Register.
  118817. + *
  118818. + * - Read the register into the <i>d32</i> member then set/clear the
  118819. + * bits using the <i>b</i>it elements.
  118820. + */
  118821. +typedef union doepint_data {
  118822. + /** raw register data */
  118823. + uint32_t d32;
  118824. + /** register bits */
  118825. + struct {
  118826. + /** Transfer complete */
  118827. + unsigned xfercompl:1;
  118828. + /** Endpoint disable */
  118829. + unsigned epdisabled:1;
  118830. + /** AHB Error */
  118831. + unsigned ahberr:1;
  118832. + /** Setup Phase Done (contorl EPs) */
  118833. + unsigned setup:1;
  118834. + /** OUT Token Received when Endpoint Disabled */
  118835. + unsigned outtknepdis:1;
  118836. +
  118837. + unsigned stsphsercvd:1;
  118838. + /** Back-to-Back SETUP Packets Received */
  118839. + unsigned back2backsetup:1;
  118840. +
  118841. + unsigned reserved7:1;
  118842. + /** OUT packet Error */
  118843. + unsigned outpkterr:1;
  118844. + /** BNA Interrupt */
  118845. + unsigned bna:1;
  118846. +
  118847. + unsigned reserved10:1;
  118848. + /** Packet Drop Status */
  118849. + unsigned pktdrpsts:1;
  118850. + /** Babble Interrupt */
  118851. + unsigned babble:1;
  118852. + /** NAK Interrupt */
  118853. + unsigned nak:1;
  118854. + /** NYET Interrupt */
  118855. + unsigned nyet:1;
  118856. + /** Bit indicating setup packet received */
  118857. + unsigned sr:1;
  118858. +
  118859. + unsigned reserved16_31:16;
  118860. + } b;
  118861. +} doepint_data_t;
  118862. +
  118863. +/**
  118864. + * This union represents the bit fields in the Device OUT EP
  118865. + * Common/Dedicated Interrupt Mask Register.
  118866. + */
  118867. +typedef union doepint_data doepmsk_data_t;
  118868. +
  118869. +/**
  118870. + * This union represents the bit fields in the Device All EP Interrupt
  118871. + * and Mask Registers.
  118872. + * - Read the register into the <i>d32</i> member then set/clear the
  118873. + * bits using the <i>b</i>it elements.
  118874. + */
  118875. +typedef union daint_data {
  118876. + /** raw register data */
  118877. + uint32_t d32;
  118878. + /** register bits */
  118879. + struct {
  118880. + /** IN Endpoint bits */
  118881. + unsigned in:16;
  118882. + /** OUT Endpoint bits */
  118883. + unsigned out:16;
  118884. + } ep;
  118885. + struct {
  118886. + /** IN Endpoint bits */
  118887. + unsigned inep0:1;
  118888. + unsigned inep1:1;
  118889. + unsigned inep2:1;
  118890. + unsigned inep3:1;
  118891. + unsigned inep4:1;
  118892. + unsigned inep5:1;
  118893. + unsigned inep6:1;
  118894. + unsigned inep7:1;
  118895. + unsigned inep8:1;
  118896. + unsigned inep9:1;
  118897. + unsigned inep10:1;
  118898. + unsigned inep11:1;
  118899. + unsigned inep12:1;
  118900. + unsigned inep13:1;
  118901. + unsigned inep14:1;
  118902. + unsigned inep15:1;
  118903. + /** OUT Endpoint bits */
  118904. + unsigned outep0:1;
  118905. + unsigned outep1:1;
  118906. + unsigned outep2:1;
  118907. + unsigned outep3:1;
  118908. + unsigned outep4:1;
  118909. + unsigned outep5:1;
  118910. + unsigned outep6:1;
  118911. + unsigned outep7:1;
  118912. + unsigned outep8:1;
  118913. + unsigned outep9:1;
  118914. + unsigned outep10:1;
  118915. + unsigned outep11:1;
  118916. + unsigned outep12:1;
  118917. + unsigned outep13:1;
  118918. + unsigned outep14:1;
  118919. + unsigned outep15:1;
  118920. + } b;
  118921. +} daint_data_t;
  118922. +
  118923. +/**
  118924. + * This union represents the bit fields in the Device IN Token Queue
  118925. + * Read Registers.
  118926. + * - Read the register into the <i>d32</i> member.
  118927. + * - READ-ONLY Register
  118928. + */
  118929. +typedef union dtknq1_data {
  118930. + /** raw register data */
  118931. + uint32_t d32;
  118932. + /** register bits */
  118933. + struct {
  118934. + /** In Token Queue Write Pointer */
  118935. + unsigned intknwptr:5;
  118936. + /** Reserved */
  118937. + unsigned reserved05_06:2;
  118938. + /** write pointer has wrapped. */
  118939. + unsigned wrap_bit:1;
  118940. + /** EP Numbers of IN Tokens 0 ... 4 */
  118941. + unsigned epnums0_5:24;
  118942. + } b;
  118943. +} dtknq1_data_t;
  118944. +
  118945. +/**
  118946. + * This union represents Threshold control Register
  118947. + * - Read and write the register into the <i>d32</i> member.
  118948. + * - READ-WRITABLE Register
  118949. + */
  118950. +typedef union dthrctl_data {
  118951. + /** raw register data */
  118952. + uint32_t d32;
  118953. + /** register bits */
  118954. + struct {
  118955. + /** non ISO Tx Thr. Enable */
  118956. + unsigned non_iso_thr_en:1;
  118957. + /** ISO Tx Thr. Enable */
  118958. + unsigned iso_thr_en:1;
  118959. + /** Tx Thr. Length */
  118960. + unsigned tx_thr_len:9;
  118961. + /** AHB Threshold ratio */
  118962. + unsigned ahb_thr_ratio:2;
  118963. + /** Reserved */
  118964. + unsigned reserved13_15:3;
  118965. + /** Rx Thr. Enable */
  118966. + unsigned rx_thr_en:1;
  118967. + /** Rx Thr. Length */
  118968. + unsigned rx_thr_len:9;
  118969. + unsigned reserved26:1;
  118970. + /** Arbiter Parking Enable*/
  118971. + unsigned arbprken:1;
  118972. + /** Reserved */
  118973. + unsigned reserved28_31:4;
  118974. + } b;
  118975. +} dthrctl_data_t;
  118976. +
  118977. +/**
  118978. + * Device Logical IN Endpoint-Specific Registers. <i>Offsets
  118979. + * 900h-AFCh</i>
  118980. + *
  118981. + * There will be one set of endpoint registers per logical endpoint
  118982. + * implemented.
  118983. + *
  118984. + * <i>These registers are visible only in Device mode and must not be
  118985. + * accessed in Host mode, as the results are unknown.</i>
  118986. + */
  118987. +typedef struct dwc_otg_dev_in_ep_regs {
  118988. + /** Device IN Endpoint Control Register. <i>Offset:900h +
  118989. + * (ep_num * 20h) + 00h</i> */
  118990. + volatile uint32_t diepctl;
  118991. + /** Reserved. <i>Offset:900h + (ep_num * 20h) + 04h</i> */
  118992. + uint32_t reserved04;
  118993. + /** Device IN Endpoint Interrupt Register. <i>Offset:900h +
  118994. + * (ep_num * 20h) + 08h</i> */
  118995. + volatile uint32_t diepint;
  118996. + /** Reserved. <i>Offset:900h + (ep_num * 20h) + 0Ch</i> */
  118997. + uint32_t reserved0C;
  118998. + /** Device IN Endpoint Transfer Size
  118999. + * Register. <i>Offset:900h + (ep_num * 20h) + 10h</i> */
  119000. + volatile uint32_t dieptsiz;
  119001. + /** Device IN Endpoint DMA Address Register. <i>Offset:900h +
  119002. + * (ep_num * 20h) + 14h</i> */
  119003. + volatile uint32_t diepdma;
  119004. + /** Device IN Endpoint Transmit FIFO Status Register. <i>Offset:900h +
  119005. + * (ep_num * 20h) + 18h</i> */
  119006. + volatile uint32_t dtxfsts;
  119007. + /** Device IN Endpoint DMA Buffer Register. <i>Offset:900h +
  119008. + * (ep_num * 20h) + 1Ch</i> */
  119009. + volatile uint32_t diepdmab;
  119010. +} dwc_otg_dev_in_ep_regs_t;
  119011. +
  119012. +/**
  119013. + * Device Logical OUT Endpoint-Specific Registers. <i>Offsets:
  119014. + * B00h-CFCh</i>
  119015. + *
  119016. + * There will be one set of endpoint registers per logical endpoint
  119017. + * implemented.
  119018. + *
  119019. + * <i>These registers are visible only in Device mode and must not be
  119020. + * accessed in Host mode, as the results are unknown.</i>
  119021. + */
  119022. +typedef struct dwc_otg_dev_out_ep_regs {
  119023. + /** Device OUT Endpoint Control Register. <i>Offset:B00h +
  119024. + * (ep_num * 20h) + 00h</i> */
  119025. + volatile uint32_t doepctl;
  119026. + /** Reserved. <i>Offset:B00h + (ep_num * 20h) + 04h</i> */
  119027. + uint32_t reserved04;
  119028. + /** Device OUT Endpoint Interrupt Register. <i>Offset:B00h +
  119029. + * (ep_num * 20h) + 08h</i> */
  119030. + volatile uint32_t doepint;
  119031. + /** Reserved. <i>Offset:B00h + (ep_num * 20h) + 0Ch</i> */
  119032. + uint32_t reserved0C;
  119033. + /** Device OUT Endpoint Transfer Size Register. <i>Offset:
  119034. + * B00h + (ep_num * 20h) + 10h</i> */
  119035. + volatile uint32_t doeptsiz;
  119036. + /** Device OUT Endpoint DMA Address Register. <i>Offset:B00h
  119037. + * + (ep_num * 20h) + 14h</i> */
  119038. + volatile uint32_t doepdma;
  119039. + /** Reserved. <i>Offset:B00h + * (ep_num * 20h) + 18h</i> */
  119040. + uint32_t unused;
  119041. + /** Device OUT Endpoint DMA Buffer Register. <i>Offset:B00h
  119042. + * + (ep_num * 20h) + 1Ch</i> */
  119043. + uint32_t doepdmab;
  119044. +} dwc_otg_dev_out_ep_regs_t;
  119045. +
  119046. +/**
  119047. + * This union represents the bit fields in the Device EP Control
  119048. + * Register. Read the register into the <i>d32</i> member then
  119049. + * set/clear the bits using the <i>b</i>it elements.
  119050. + */
  119051. +typedef union depctl_data {
  119052. + /** raw register data */
  119053. + uint32_t d32;
  119054. + /** register bits */
  119055. + struct {
  119056. + /** Maximum Packet Size
  119057. + * IN/OUT EPn
  119058. + * IN/OUT EP0 - 2 bits
  119059. + * 2'b00: 64 Bytes
  119060. + * 2'b01: 32
  119061. + * 2'b10: 16
  119062. + * 2'b11: 8 */
  119063. + unsigned mps:11;
  119064. +#define DWC_DEP0CTL_MPS_64 0
  119065. +#define DWC_DEP0CTL_MPS_32 1
  119066. +#define DWC_DEP0CTL_MPS_16 2
  119067. +#define DWC_DEP0CTL_MPS_8 3
  119068. +
  119069. + /** Next Endpoint
  119070. + * IN EPn/IN EP0
  119071. + * OUT EPn/OUT EP0 - reserved */
  119072. + unsigned nextep:4;
  119073. +
  119074. + /** USB Active Endpoint */
  119075. + unsigned usbactep:1;
  119076. +
  119077. + /** Endpoint DPID (INTR/Bulk IN and OUT endpoints)
  119078. + * This field contains the PID of the packet going to
  119079. + * be received or transmitted on this endpoint. The
  119080. + * application should program the PID of the first
  119081. + * packet going to be received or transmitted on this
  119082. + * endpoint , after the endpoint is
  119083. + * activated. Application use the SetD1PID and
  119084. + * SetD0PID fields of this register to program either
  119085. + * D0 or D1 PID.
  119086. + *
  119087. + * The encoding for this field is
  119088. + * - 0: D0
  119089. + * - 1: D1
  119090. + */
  119091. + unsigned dpid:1;
  119092. +
  119093. + /** NAK Status */
  119094. + unsigned naksts:1;
  119095. +
  119096. + /** Endpoint Type
  119097. + * 2'b00: Control
  119098. + * 2'b01: Isochronous
  119099. + * 2'b10: Bulk
  119100. + * 2'b11: Interrupt */
  119101. + unsigned eptype:2;
  119102. +
  119103. + /** Snoop Mode
  119104. + * OUT EPn/OUT EP0
  119105. + * IN EPn/IN EP0 - reserved */
  119106. + unsigned snp:1;
  119107. +
  119108. + /** Stall Handshake */
  119109. + unsigned stall:1;
  119110. +
  119111. + /** Tx Fifo Number
  119112. + * IN EPn/IN EP0
  119113. + * OUT EPn/OUT EP0 - reserved */
  119114. + unsigned txfnum:4;
  119115. +
  119116. + /** Clear NAK */
  119117. + unsigned cnak:1;
  119118. + /** Set NAK */
  119119. + unsigned snak:1;
  119120. + /** Set DATA0 PID (INTR/Bulk IN and OUT endpoints)
  119121. + * Writing to this field sets the Endpoint DPID (DPID)
  119122. + * field in this register to DATA0. Set Even
  119123. + * (micro)frame (SetEvenFr) (ISO IN and OUT Endpoints)
  119124. + * Writing to this field sets the Even/Odd
  119125. + * (micro)frame (EO_FrNum) field to even (micro)
  119126. + * frame.
  119127. + */
  119128. + unsigned setd0pid:1;
  119129. + /** Set DATA1 PID (INTR/Bulk IN and OUT endpoints)
  119130. + * Writing to this field sets the Endpoint DPID (DPID)
  119131. + * field in this register to DATA1 Set Odd
  119132. + * (micro)frame (SetOddFr) (ISO IN and OUT Endpoints)
  119133. + * Writing to this field sets the Even/Odd
  119134. + * (micro)frame (EO_FrNum) field to odd (micro) frame.
  119135. + */
  119136. + unsigned setd1pid:1;
  119137. +
  119138. + /** Endpoint Disable */
  119139. + unsigned epdis:1;
  119140. + /** Endpoint Enable */
  119141. + unsigned epena:1;
  119142. + } b;
  119143. +} depctl_data_t;
  119144. +
  119145. +/**
  119146. + * This union represents the bit fields in the Device EP Transfer
  119147. + * Size Register. Read the register into the <i>d32</i> member then
  119148. + * set/clear the bits using the <i>b</i>it elements.
  119149. + */
  119150. +typedef union deptsiz_data {
  119151. + /** raw register data */
  119152. + uint32_t d32;
  119153. + /** register bits */
  119154. + struct {
  119155. + /** Transfer size */
  119156. + unsigned xfersize:19;
  119157. +/** Max packet count for EP (pow(2,10)-1) */
  119158. +#define MAX_PKT_CNT 1023
  119159. + /** Packet Count */
  119160. + unsigned pktcnt:10;
  119161. + /** Multi Count - Periodic IN endpoints */
  119162. + unsigned mc:2;
  119163. + unsigned reserved:1;
  119164. + } b;
  119165. +} deptsiz_data_t;
  119166. +
  119167. +/**
  119168. + * This union represents the bit fields in the Device EP 0 Transfer
  119169. + * Size Register. Read the register into the <i>d32</i> member then
  119170. + * set/clear the bits using the <i>b</i>it elements.
  119171. + */
  119172. +typedef union deptsiz0_data {
  119173. + /** raw register data */
  119174. + uint32_t d32;
  119175. + /** register bits */
  119176. + struct {
  119177. + /** Transfer size */
  119178. + unsigned xfersize:7;
  119179. + /** Reserved */
  119180. + unsigned reserved7_18:12;
  119181. + /** Packet Count */
  119182. + unsigned pktcnt:2;
  119183. + /** Reserved */
  119184. + unsigned reserved21_28:8;
  119185. + /**Setup Packet Count (DOEPTSIZ0 Only) */
  119186. + unsigned supcnt:2;
  119187. + unsigned reserved31;
  119188. + } b;
  119189. +} deptsiz0_data_t;
  119190. +
  119191. +/////////////////////////////////////////////////
  119192. +// DMA Descriptor Specific Structures
  119193. +//
  119194. +
  119195. +/** Buffer status definitions */
  119196. +
  119197. +#define BS_HOST_READY 0x0
  119198. +#define BS_DMA_BUSY 0x1
  119199. +#define BS_DMA_DONE 0x2
  119200. +#define BS_HOST_BUSY 0x3
  119201. +
  119202. +/** Receive/Transmit status definitions */
  119203. +
  119204. +#define RTS_SUCCESS 0x0
  119205. +#define RTS_BUFFLUSH 0x1
  119206. +#define RTS_RESERVED 0x2
  119207. +#define RTS_BUFERR 0x3
  119208. +
  119209. +/**
  119210. + * This union represents the bit fields in the DMA Descriptor
  119211. + * status quadlet. Read the quadlet into the <i>d32</i> member then
  119212. + * set/clear the bits using the <i>b</i>it, <i>b_iso_out</i> and
  119213. + * <i>b_iso_in</i> elements.
  119214. + */
  119215. +typedef union dev_dma_desc_sts {
  119216. + /** raw register data */
  119217. + uint32_t d32;
  119218. + /** quadlet bits */
  119219. + struct {
  119220. + /** Received number of bytes */
  119221. + unsigned bytes:16;
  119222. + /** NAK bit - only for OUT EPs */
  119223. + unsigned nak:1;
  119224. + unsigned reserved17_22:6;
  119225. + /** Multiple Transfer - only for OUT EPs */
  119226. + unsigned mtrf:1;
  119227. + /** Setup Packet received - only for OUT EPs */
  119228. + unsigned sr:1;
  119229. + /** Interrupt On Complete */
  119230. + unsigned ioc:1;
  119231. + /** Short Packet */
  119232. + unsigned sp:1;
  119233. + /** Last */
  119234. + unsigned l:1;
  119235. + /** Receive Status */
  119236. + unsigned sts:2;
  119237. + /** Buffer Status */
  119238. + unsigned bs:2;
  119239. + } b;
  119240. +
  119241. +//#ifdef DWC_EN_ISOC
  119242. + /** iso out quadlet bits */
  119243. + struct {
  119244. + /** Received number of bytes */
  119245. + unsigned rxbytes:11;
  119246. +
  119247. + unsigned reserved11:1;
  119248. + /** Frame Number */
  119249. + unsigned framenum:11;
  119250. + /** Received ISO Data PID */
  119251. + unsigned pid:2;
  119252. + /** Interrupt On Complete */
  119253. + unsigned ioc:1;
  119254. + /** Short Packet */
  119255. + unsigned sp:1;
  119256. + /** Last */
  119257. + unsigned l:1;
  119258. + /** Receive Status */
  119259. + unsigned rxsts:2;
  119260. + /** Buffer Status */
  119261. + unsigned bs:2;
  119262. + } b_iso_out;
  119263. +
  119264. + /** iso in quadlet bits */
  119265. + struct {
  119266. + /** Transmited number of bytes */
  119267. + unsigned txbytes:12;
  119268. + /** Frame Number */
  119269. + unsigned framenum:11;
  119270. + /** Transmited ISO Data PID */
  119271. + unsigned pid:2;
  119272. + /** Interrupt On Complete */
  119273. + unsigned ioc:1;
  119274. + /** Short Packet */
  119275. + unsigned sp:1;
  119276. + /** Last */
  119277. + unsigned l:1;
  119278. + /** Transmit Status */
  119279. + unsigned txsts:2;
  119280. + /** Buffer Status */
  119281. + unsigned bs:2;
  119282. + } b_iso_in;
  119283. +//#endif /* DWC_EN_ISOC */
  119284. +} dev_dma_desc_sts_t;
  119285. +
  119286. +/**
  119287. + * DMA Descriptor structure
  119288. + *
  119289. + * DMA Descriptor structure contains two quadlets:
  119290. + * Status quadlet and Data buffer pointer.
  119291. + */
  119292. +typedef struct dwc_otg_dev_dma_desc {
  119293. + /** DMA Descriptor status quadlet */
  119294. + dev_dma_desc_sts_t status;
  119295. + /** DMA Descriptor data buffer pointer */
  119296. + uint32_t buf;
  119297. +} dwc_otg_dev_dma_desc_t;
  119298. +
  119299. +/**
  119300. + * The dwc_otg_dev_if structure contains information needed to manage
  119301. + * the DWC_otg controller acting in device mode. It represents the
  119302. + * programming view of the device-specific aspects of the controller.
  119303. + */
  119304. +typedef struct dwc_otg_dev_if {
  119305. + /** Pointer to device Global registers.
  119306. + * Device Global Registers starting at offset 800h
  119307. + */
  119308. + dwc_otg_device_global_regs_t *dev_global_regs;
  119309. +#define DWC_DEV_GLOBAL_REG_OFFSET 0x800
  119310. +
  119311. + /**
  119312. + * Device Logical IN Endpoint-Specific Registers 900h-AFCh
  119313. + */
  119314. + dwc_otg_dev_in_ep_regs_t *in_ep_regs[MAX_EPS_CHANNELS];
  119315. +#define DWC_DEV_IN_EP_REG_OFFSET 0x900
  119316. +#define DWC_EP_REG_OFFSET 0x20
  119317. +
  119318. + /** Device Logical OUT Endpoint-Specific Registers B00h-CFCh */
  119319. + dwc_otg_dev_out_ep_regs_t *out_ep_regs[MAX_EPS_CHANNELS];
  119320. +#define DWC_DEV_OUT_EP_REG_OFFSET 0xB00
  119321. +
  119322. + /* Device configuration information */
  119323. + uint8_t speed; /**< Device Speed 0: Unknown, 1: LS, 2:FS, 3: HS */
  119324. + uint8_t num_in_eps; /**< Number # of Tx EP range: 0-15 exept ep0 */
  119325. + uint8_t num_out_eps; /**< Number # of Rx EP range: 0-15 exept ep 0*/
  119326. +
  119327. + /** Size of periodic FIFOs (Bytes) */
  119328. + uint16_t perio_tx_fifo_size[MAX_PERIO_FIFOS];
  119329. +
  119330. + /** Size of Tx FIFOs (Bytes) */
  119331. + uint16_t tx_fifo_size[MAX_TX_FIFOS];
  119332. +
  119333. + /** Thresholding enable flags and length varaiables **/
  119334. + uint16_t rx_thr_en;
  119335. + uint16_t iso_tx_thr_en;
  119336. + uint16_t non_iso_tx_thr_en;
  119337. +
  119338. + uint16_t rx_thr_length;
  119339. + uint16_t tx_thr_length;
  119340. +
  119341. + /**
  119342. + * Pointers to the DMA Descriptors for EP0 Control
  119343. + * transfers (virtual and physical)
  119344. + */
  119345. +
  119346. + /** 2 descriptors for SETUP packets */
  119347. + dwc_dma_t dma_setup_desc_addr[2];
  119348. + dwc_otg_dev_dma_desc_t *setup_desc_addr[2];
  119349. +
  119350. + /** Pointer to Descriptor with latest SETUP packet */
  119351. + dwc_otg_dev_dma_desc_t *psetup;
  119352. +
  119353. + /** Index of current SETUP handler descriptor */
  119354. + uint32_t setup_desc_index;
  119355. +
  119356. + /** Descriptor for Data In or Status In phases */
  119357. + dwc_dma_t dma_in_desc_addr;
  119358. + dwc_otg_dev_dma_desc_t *in_desc_addr;
  119359. +
  119360. + /** Descriptor for Data Out or Status Out phases */
  119361. + dwc_dma_t dma_out_desc_addr;
  119362. + dwc_otg_dev_dma_desc_t *out_desc_addr;
  119363. +
  119364. + /** Setup Packet Detected - if set clear NAK when queueing */
  119365. + uint32_t spd;
  119366. + /** Isoc ep pointer on which incomplete happens */
  119367. + void *isoc_ep;
  119368. +
  119369. +} dwc_otg_dev_if_t;
  119370. +
  119371. +/////////////////////////////////////////////////
  119372. +// Host Mode Register Structures
  119373. +//
  119374. +/**
  119375. + * The Host Global Registers structure defines the size and relative
  119376. + * field offsets for the Host Mode Global Registers. Host Global
  119377. + * Registers offsets 400h-7FFh.
  119378. +*/
  119379. +typedef struct dwc_otg_host_global_regs {
  119380. + /** Host Configuration Register. <i>Offset: 400h</i> */
  119381. + volatile uint32_t hcfg;
  119382. + /** Host Frame Interval Register. <i>Offset: 404h</i> */
  119383. + volatile uint32_t hfir;
  119384. + /** Host Frame Number / Frame Remaining Register. <i>Offset: 408h</i> */
  119385. + volatile uint32_t hfnum;
  119386. + /** Reserved. <i>Offset: 40Ch</i> */
  119387. + uint32_t reserved40C;
  119388. + /** Host Periodic Transmit FIFO/ Queue Status Register. <i>Offset: 410h</i> */
  119389. + volatile uint32_t hptxsts;
  119390. + /** Host All Channels Interrupt Register. <i>Offset: 414h</i> */
  119391. + volatile uint32_t haint;
  119392. + /** Host All Channels Interrupt Mask Register. <i>Offset: 418h</i> */
  119393. + volatile uint32_t haintmsk;
  119394. + /** Host Frame List Base Address Register . <i>Offset: 41Ch</i> */
  119395. + volatile uint32_t hflbaddr;
  119396. +} dwc_otg_host_global_regs_t;
  119397. +
  119398. +/**
  119399. + * This union represents the bit fields in the Host Configuration Register.
  119400. + * Read the register into the <i>d32</i> member then set/clear the bits using
  119401. + * the <i>b</i>it elements. Write the <i>d32</i> member to the hcfg register.
  119402. + */
  119403. +typedef union hcfg_data {
  119404. + /** raw register data */
  119405. + uint32_t d32;
  119406. +
  119407. + /** register bits */
  119408. + struct {
  119409. + /** FS/LS Phy Clock Select */
  119410. + unsigned fslspclksel:2;
  119411. +#define DWC_HCFG_30_60_MHZ 0
  119412. +#define DWC_HCFG_48_MHZ 1
  119413. +#define DWC_HCFG_6_MHZ 2
  119414. +
  119415. + /** FS/LS Only Support */
  119416. + unsigned fslssupp:1;
  119417. + unsigned reserved3_6:4;
  119418. + /** Enable 32-KHz Suspend Mode */
  119419. + unsigned ena32khzs:1;
  119420. + /** Resume Validation Periiod */
  119421. + unsigned resvalid:8;
  119422. + unsigned reserved16_22:7;
  119423. + /** Enable Scatter/gather DMA in Host mode */
  119424. + unsigned descdma:1;
  119425. + /** Frame List Entries */
  119426. + unsigned frlisten:2;
  119427. + /** Enable Periodic Scheduling */
  119428. + unsigned perschedena:1;
  119429. + unsigned reserved27_30:4;
  119430. + unsigned modechtimen:1;
  119431. + } b;
  119432. +} hcfg_data_t;
  119433. +
  119434. +/**
  119435. + * This union represents the bit fields in the Host Frame Remaing/Number
  119436. + * Register.
  119437. + */
  119438. +typedef union hfir_data {
  119439. + /** raw register data */
  119440. + uint32_t d32;
  119441. +
  119442. + /** register bits */
  119443. + struct {
  119444. + unsigned frint:16;
  119445. + unsigned hfirrldctrl:1;
  119446. + unsigned reserved:15;
  119447. + } b;
  119448. +} hfir_data_t;
  119449. +
  119450. +/**
  119451. + * This union represents the bit fields in the Host Frame Remaing/Number
  119452. + * Register.
  119453. + */
  119454. +typedef union hfnum_data {
  119455. + /** raw register data */
  119456. + uint32_t d32;
  119457. +
  119458. + /** register bits */
  119459. + struct {
  119460. + unsigned frnum:16;
  119461. +#define DWC_HFNUM_MAX_FRNUM 0x3FFF
  119462. + unsigned frrem:16;
  119463. + } b;
  119464. +} hfnum_data_t;
  119465. +
  119466. +typedef union hptxsts_data {
  119467. + /** raw register data */
  119468. + uint32_t d32;
  119469. +
  119470. + /** register bits */
  119471. + struct {
  119472. + unsigned ptxfspcavail:16;
  119473. + unsigned ptxqspcavail:8;
  119474. + /** Top of the Periodic Transmit Request Queue
  119475. + * - bit 24 - Terminate (last entry for the selected channel)
  119476. + * - bits 26:25 - Token Type
  119477. + * - 2'b00 - Zero length
  119478. + * - 2'b01 - Ping
  119479. + * - 2'b10 - Disable
  119480. + * - bits 30:27 - Channel Number
  119481. + * - bit 31 - Odd/even microframe
  119482. + */
  119483. + unsigned ptxqtop_terminate:1;
  119484. + unsigned ptxqtop_token:2;
  119485. + unsigned ptxqtop_chnum:4;
  119486. + unsigned ptxqtop_odd:1;
  119487. + } b;
  119488. +} hptxsts_data_t;
  119489. +
  119490. +/**
  119491. + * This union represents the bit fields in the Host Port Control and Status
  119492. + * Register. Read the register into the <i>d32</i> member then set/clear the
  119493. + * bits using the <i>b</i>it elements. Write the <i>d32</i> member to the
  119494. + * hprt0 register.
  119495. + */
  119496. +typedef union hprt0_data {
  119497. + /** raw register data */
  119498. + uint32_t d32;
  119499. + /** register bits */
  119500. + struct {
  119501. + unsigned prtconnsts:1;
  119502. + unsigned prtconndet:1;
  119503. + unsigned prtena:1;
  119504. + unsigned prtenchng:1;
  119505. + unsigned prtovrcurract:1;
  119506. + unsigned prtovrcurrchng:1;
  119507. + unsigned prtres:1;
  119508. + unsigned prtsusp:1;
  119509. + unsigned prtrst:1;
  119510. + unsigned reserved9:1;
  119511. + unsigned prtlnsts:2;
  119512. + unsigned prtpwr:1;
  119513. + unsigned prttstctl:4;
  119514. + unsigned prtspd:2;
  119515. +#define DWC_HPRT0_PRTSPD_HIGH_SPEED 0
  119516. +#define DWC_HPRT0_PRTSPD_FULL_SPEED 1
  119517. +#define DWC_HPRT0_PRTSPD_LOW_SPEED 2
  119518. + unsigned reserved19_31:13;
  119519. + } b;
  119520. +} hprt0_data_t;
  119521. +
  119522. +/**
  119523. + * This union represents the bit fields in the Host All Interrupt
  119524. + * Register.
  119525. + */
  119526. +typedef union haint_data {
  119527. + /** raw register data */
  119528. + uint32_t d32;
  119529. + /** register bits */
  119530. + struct {
  119531. + unsigned ch0:1;
  119532. + unsigned ch1:1;
  119533. + unsigned ch2:1;
  119534. + unsigned ch3:1;
  119535. + unsigned ch4:1;
  119536. + unsigned ch5:1;
  119537. + unsigned ch6:1;
  119538. + unsigned ch7:1;
  119539. + unsigned ch8:1;
  119540. + unsigned ch9:1;
  119541. + unsigned ch10:1;
  119542. + unsigned ch11:1;
  119543. + unsigned ch12:1;
  119544. + unsigned ch13:1;
  119545. + unsigned ch14:1;
  119546. + unsigned ch15:1;
  119547. + unsigned reserved:16;
  119548. + } b;
  119549. +
  119550. + struct {
  119551. + unsigned chint:16;
  119552. + unsigned reserved:16;
  119553. + } b2;
  119554. +} haint_data_t;
  119555. +
  119556. +/**
  119557. + * This union represents the bit fields in the Host All Interrupt
  119558. + * Register.
  119559. + */
  119560. +typedef union haintmsk_data {
  119561. + /** raw register data */
  119562. + uint32_t d32;
  119563. + /** register bits */
  119564. + struct {
  119565. + unsigned ch0:1;
  119566. + unsigned ch1:1;
  119567. + unsigned ch2:1;
  119568. + unsigned ch3:1;
  119569. + unsigned ch4:1;
  119570. + unsigned ch5:1;
  119571. + unsigned ch6:1;
  119572. + unsigned ch7:1;
  119573. + unsigned ch8:1;
  119574. + unsigned ch9:1;
  119575. + unsigned ch10:1;
  119576. + unsigned ch11:1;
  119577. + unsigned ch12:1;
  119578. + unsigned ch13:1;
  119579. + unsigned ch14:1;
  119580. + unsigned ch15:1;
  119581. + unsigned reserved:16;
  119582. + } b;
  119583. +
  119584. + struct {
  119585. + unsigned chint:16;
  119586. + unsigned reserved:16;
  119587. + } b2;
  119588. +} haintmsk_data_t;
  119589. +
  119590. +/**
  119591. + * Host Channel Specific Registers. <i>500h-5FCh</i>
  119592. + */
  119593. +typedef struct dwc_otg_hc_regs {
  119594. + /** Host Channel 0 Characteristic Register. <i>Offset: 500h + (chan_num * 20h) + 00h</i> */
  119595. + volatile uint32_t hcchar;
  119596. + /** Host Channel 0 Split Control Register. <i>Offset: 500h + (chan_num * 20h) + 04h</i> */
  119597. + volatile uint32_t hcsplt;
  119598. + /** Host Channel 0 Interrupt Register. <i>Offset: 500h + (chan_num * 20h) + 08h</i> */
  119599. + volatile uint32_t hcint;
  119600. + /** Host Channel 0 Interrupt Mask Register. <i>Offset: 500h + (chan_num * 20h) + 0Ch</i> */
  119601. + volatile uint32_t hcintmsk;
  119602. + /** Host Channel 0 Transfer Size Register. <i>Offset: 500h + (chan_num * 20h) + 10h</i> */
  119603. + volatile uint32_t hctsiz;
  119604. + /** Host Channel 0 DMA Address Register. <i>Offset: 500h + (chan_num * 20h) + 14h</i> */
  119605. + volatile uint32_t hcdma;
  119606. + volatile uint32_t reserved;
  119607. + /** Host Channel 0 DMA Buffer Address Register. <i>Offset: 500h + (chan_num * 20h) + 1Ch</i> */
  119608. + volatile uint32_t hcdmab;
  119609. +} dwc_otg_hc_regs_t;
  119610. +
  119611. +/**
  119612. + * This union represents the bit fields in the Host Channel Characteristics
  119613. + * Register. Read the register into the <i>d32</i> member then set/clear the
  119614. + * bits using the <i>b</i>it elements. Write the <i>d32</i> member to the
  119615. + * hcchar register.
  119616. + */
  119617. +typedef union hcchar_data {
  119618. + /** raw register data */
  119619. + uint32_t d32;
  119620. +
  119621. + /** register bits */
  119622. + struct {
  119623. + /** Maximum packet size in bytes */
  119624. + unsigned mps:11;
  119625. +
  119626. + /** Endpoint number */
  119627. + unsigned epnum:4;
  119628. +
  119629. + /** 0: OUT, 1: IN */
  119630. + unsigned epdir:1;
  119631. +
  119632. + unsigned reserved:1;
  119633. +
  119634. + /** 0: Full/high speed device, 1: Low speed device */
  119635. + unsigned lspddev:1;
  119636. +
  119637. + /** 0: Control, 1: Isoc, 2: Bulk, 3: Intr */
  119638. + unsigned eptype:2;
  119639. +
  119640. + /** Packets per frame for periodic transfers. 0 is reserved. */
  119641. + unsigned multicnt:2;
  119642. +
  119643. + /** Device address */
  119644. + unsigned devaddr:7;
  119645. +
  119646. + /**
  119647. + * Frame to transmit periodic transaction.
  119648. + * 0: even, 1: odd
  119649. + */
  119650. + unsigned oddfrm:1;
  119651. +
  119652. + /** Channel disable */
  119653. + unsigned chdis:1;
  119654. +
  119655. + /** Channel enable */
  119656. + unsigned chen:1;
  119657. + } b;
  119658. +} hcchar_data_t;
  119659. +
  119660. +typedef union hcsplt_data {
  119661. + /** raw register data */
  119662. + uint32_t d32;
  119663. +
  119664. + /** register bits */
  119665. + struct {
  119666. + /** Port Address */
  119667. + unsigned prtaddr:7;
  119668. +
  119669. + /** Hub Address */
  119670. + unsigned hubaddr:7;
  119671. +
  119672. + /** Transaction Position */
  119673. + unsigned xactpos:2;
  119674. +#define DWC_HCSPLIT_XACTPOS_MID 0
  119675. +#define DWC_HCSPLIT_XACTPOS_END 1
  119676. +#define DWC_HCSPLIT_XACTPOS_BEGIN 2
  119677. +#define DWC_HCSPLIT_XACTPOS_ALL 3
  119678. +
  119679. + /** Do Complete Split */
  119680. + unsigned compsplt:1;
  119681. +
  119682. + /** Reserved */
  119683. + unsigned reserved:14;
  119684. +
  119685. + /** Split Enble */
  119686. + unsigned spltena:1;
  119687. + } b;
  119688. +} hcsplt_data_t;
  119689. +
  119690. +/**
  119691. + * This union represents the bit fields in the Host All Interrupt
  119692. + * Register.
  119693. + */
  119694. +typedef union hcint_data {
  119695. + /** raw register data */
  119696. + uint32_t d32;
  119697. + /** register bits */
  119698. + struct {
  119699. + /** Transfer Complete */
  119700. + unsigned xfercomp:1;
  119701. + /** Channel Halted */
  119702. + unsigned chhltd:1;
  119703. + /** AHB Error */
  119704. + unsigned ahberr:1;
  119705. + /** STALL Response Received */
  119706. + unsigned stall:1;
  119707. + /** NAK Response Received */
  119708. + unsigned nak:1;
  119709. + /** ACK Response Received */
  119710. + unsigned ack:1;
  119711. + /** NYET Response Received */
  119712. + unsigned nyet:1;
  119713. + /** Transaction Err */
  119714. + unsigned xacterr:1;
  119715. + /** Babble Error */
  119716. + unsigned bblerr:1;
  119717. + /** Frame Overrun */
  119718. + unsigned frmovrun:1;
  119719. + /** Data Toggle Error */
  119720. + unsigned datatglerr:1;
  119721. + /** Buffer Not Available (only for DDMA mode) */
  119722. + unsigned bna:1;
  119723. + /** Exessive transaction error (only for DDMA mode) */
  119724. + unsigned xcs_xact:1;
  119725. + /** Frame List Rollover interrupt */
  119726. + unsigned frm_list_roll:1;
  119727. + /** Reserved */
  119728. + unsigned reserved14_31:18;
  119729. + } b;
  119730. +} hcint_data_t;
  119731. +
  119732. +/**
  119733. + * This union represents the bit fields in the Host Channel Interrupt Mask
  119734. + * Register. Read the register into the <i>d32</i> member then set/clear the
  119735. + * bits using the <i>b</i>it elements. Write the <i>d32</i> member to the
  119736. + * hcintmsk register.
  119737. + */
  119738. +typedef union hcintmsk_data {
  119739. + /** raw register data */
  119740. + uint32_t d32;
  119741. +
  119742. + /** register bits */
  119743. + struct {
  119744. + unsigned xfercompl:1;
  119745. + unsigned chhltd:1;
  119746. + unsigned ahberr:1;
  119747. + unsigned stall:1;
  119748. + unsigned nak:1;
  119749. + unsigned ack:1;
  119750. + unsigned nyet:1;
  119751. + unsigned xacterr:1;
  119752. + unsigned bblerr:1;
  119753. + unsigned frmovrun:1;
  119754. + unsigned datatglerr:1;
  119755. + unsigned bna:1;
  119756. + unsigned xcs_xact:1;
  119757. + unsigned frm_list_roll:1;
  119758. + unsigned reserved14_31:18;
  119759. + } b;
  119760. +} hcintmsk_data_t;
  119761. +
  119762. +/**
  119763. + * This union represents the bit fields in the Host Channel Transfer Size
  119764. + * Register. Read the register into the <i>d32</i> member then set/clear the
  119765. + * bits using the <i>b</i>it elements. Write the <i>d32</i> member to the
  119766. + * hcchar register.
  119767. + */
  119768. +
  119769. +typedef union hctsiz_data {
  119770. + /** raw register data */
  119771. + uint32_t d32;
  119772. +
  119773. + /** register bits */
  119774. + struct {
  119775. + /** Total transfer size in bytes */
  119776. + unsigned xfersize:19;
  119777. +
  119778. + /** Data packets to transfer */
  119779. + unsigned pktcnt:10;
  119780. +
  119781. + /**
  119782. + * Packet ID for next data packet
  119783. + * 0: DATA0
  119784. + * 1: DATA2
  119785. + * 2: DATA1
  119786. + * 3: MDATA (non-Control), SETUP (Control)
  119787. + */
  119788. + unsigned pid:2;
  119789. +#define DWC_HCTSIZ_DATA0 0
  119790. +#define DWC_HCTSIZ_DATA1 2
  119791. +#define DWC_HCTSIZ_DATA2 1
  119792. +#define DWC_HCTSIZ_MDATA 3
  119793. +#define DWC_HCTSIZ_SETUP 3
  119794. +
  119795. + /** Do PING protocol when 1 */
  119796. + unsigned dopng:1;
  119797. + } b;
  119798. +
  119799. + /** register bits */
  119800. + struct {
  119801. + /** Scheduling information */
  119802. + unsigned schinfo:8;
  119803. +
  119804. + /** Number of transfer descriptors.
  119805. + * Max value:
  119806. + * 64 in general,
  119807. + * 256 only for HS isochronous endpoint.
  119808. + */
  119809. + unsigned ntd:8;
  119810. +
  119811. + /** Data packets to transfer */
  119812. + unsigned reserved16_28:13;
  119813. +
  119814. + /**
  119815. + * Packet ID for next data packet
  119816. + * 0: DATA0
  119817. + * 1: DATA2
  119818. + * 2: DATA1
  119819. + * 3: MDATA (non-Control)
  119820. + */
  119821. + unsigned pid:2;
  119822. +
  119823. + /** Do PING protocol when 1 */
  119824. + unsigned dopng:1;
  119825. + } b_ddma;
  119826. +} hctsiz_data_t;
  119827. +
  119828. +/**
  119829. + * This union represents the bit fields in the Host DMA Address
  119830. + * Register used in Descriptor DMA mode.
  119831. + */
  119832. +typedef union hcdma_data {
  119833. + /** raw register data */
  119834. + uint32_t d32;
  119835. + /** register bits */
  119836. + struct {
  119837. + unsigned reserved0_2:3;
  119838. + /** Current Transfer Descriptor. Not used for ISOC */
  119839. + unsigned ctd:8;
  119840. + /** Start Address of Descriptor List */
  119841. + unsigned dma_addr:21;
  119842. + } b;
  119843. +} hcdma_data_t;
  119844. +
  119845. +/**
  119846. + * This union represents the bit fields in the DMA Descriptor
  119847. + * status quadlet for host mode. Read the quadlet into the <i>d32</i> member then
  119848. + * set/clear the bits using the <i>b</i>it elements.
  119849. + */
  119850. +typedef union host_dma_desc_sts {
  119851. + /** raw register data */
  119852. + uint32_t d32;
  119853. + /** quadlet bits */
  119854. +
  119855. + /* for non-isochronous */
  119856. + struct {
  119857. + /** Number of bytes */
  119858. + unsigned n_bytes:17;
  119859. + /** QTD offset to jump when Short Packet received - only for IN EPs */
  119860. + unsigned qtd_offset:6;
  119861. + /**
  119862. + * Set to request the core to jump to alternate QTD if
  119863. + * Short Packet received - only for IN EPs
  119864. + */
  119865. + unsigned a_qtd:1;
  119866. + /**
  119867. + * Setup Packet bit. When set indicates that buffer contains
  119868. + * setup packet.
  119869. + */
  119870. + unsigned sup:1;
  119871. + /** Interrupt On Complete */
  119872. + unsigned ioc:1;
  119873. + /** End of List */
  119874. + unsigned eol:1;
  119875. + unsigned reserved27:1;
  119876. + /** Rx/Tx Status */
  119877. + unsigned sts:2;
  119878. +#define DMA_DESC_STS_PKTERR 1
  119879. + unsigned reserved30:1;
  119880. + /** Active Bit */
  119881. + unsigned a:1;
  119882. + } b;
  119883. + /* for isochronous */
  119884. + struct {
  119885. + /** Number of bytes */
  119886. + unsigned n_bytes:12;
  119887. + unsigned reserved12_24:13;
  119888. + /** Interrupt On Complete */
  119889. + unsigned ioc:1;
  119890. + unsigned reserved26_27:2;
  119891. + /** Rx/Tx Status */
  119892. + unsigned sts:2;
  119893. + unsigned reserved30:1;
  119894. + /** Active Bit */
  119895. + unsigned a:1;
  119896. + } b_isoc;
  119897. +} host_dma_desc_sts_t;
  119898. +
  119899. +#define MAX_DMA_DESC_SIZE 131071
  119900. +#define MAX_DMA_DESC_NUM_GENERIC 64
  119901. +#define MAX_DMA_DESC_NUM_HS_ISOC 256
  119902. +#define MAX_FRLIST_EN_NUM 64
  119903. +/**
  119904. + * Host-mode DMA Descriptor structure
  119905. + *
  119906. + * DMA Descriptor structure contains two quadlets:
  119907. + * Status quadlet and Data buffer pointer.
  119908. + */
  119909. +typedef struct dwc_otg_host_dma_desc {
  119910. + /** DMA Descriptor status quadlet */
  119911. + host_dma_desc_sts_t status;
  119912. + /** DMA Descriptor data buffer pointer */
  119913. + uint32_t buf;
  119914. +} dwc_otg_host_dma_desc_t;
  119915. +
  119916. +/** OTG Host Interface Structure.
  119917. + *
  119918. + * The OTG Host Interface Structure structure contains information
  119919. + * needed to manage the DWC_otg controller acting in host mode. It
  119920. + * represents the programming view of the host-specific aspects of the
  119921. + * controller.
  119922. + */
  119923. +typedef struct dwc_otg_host_if {
  119924. + /** Host Global Registers starting at offset 400h.*/
  119925. + dwc_otg_host_global_regs_t *host_global_regs;
  119926. +#define DWC_OTG_HOST_GLOBAL_REG_OFFSET 0x400
  119927. +
  119928. + /** Host Port 0 Control and Status Register */
  119929. + volatile uint32_t *hprt0;
  119930. +#define DWC_OTG_HOST_PORT_REGS_OFFSET 0x440
  119931. +
  119932. + /** Host Channel Specific Registers at offsets 500h-5FCh. */
  119933. + dwc_otg_hc_regs_t *hc_regs[MAX_EPS_CHANNELS];
  119934. +#define DWC_OTG_HOST_CHAN_REGS_OFFSET 0x500
  119935. +#define DWC_OTG_CHAN_REGS_OFFSET 0x20
  119936. +
  119937. + /* Host configuration information */
  119938. + /** Number of Host Channels (range: 1-16) */
  119939. + uint8_t num_host_channels;
  119940. + /** Periodic EPs supported (0: no, 1: yes) */
  119941. + uint8_t perio_eps_supported;
  119942. + /** Periodic Tx FIFO Size (Only 1 host periodic Tx FIFO) */
  119943. + uint16_t perio_tx_fifo_size;
  119944. +
  119945. +} dwc_otg_host_if_t;
  119946. +
  119947. +/**
  119948. + * This union represents the bit fields in the Power and Clock Gating Control
  119949. + * Register. Read the register into the <i>d32</i> member then set/clear the
  119950. + * bits using the <i>b</i>it elements.
  119951. + */
  119952. +typedef union pcgcctl_data {
  119953. + /** raw register data */
  119954. + uint32_t d32;
  119955. +
  119956. + /** register bits */
  119957. + struct {
  119958. + /** Stop Pclk */
  119959. + unsigned stoppclk:1;
  119960. + /** Gate Hclk */
  119961. + unsigned gatehclk:1;
  119962. + /** Power Clamp */
  119963. + unsigned pwrclmp:1;
  119964. + /** Reset Power Down Modules */
  119965. + unsigned rstpdwnmodule:1;
  119966. + /** Reserved */
  119967. + unsigned reserved:1;
  119968. + /** Enable Sleep Clock Gating (Enbl_L1Gating) */
  119969. + unsigned enbl_sleep_gating:1;
  119970. + /** PHY In Sleep (PhySleep) */
  119971. + unsigned phy_in_sleep:1;
  119972. + /** Deep Sleep*/
  119973. + unsigned deep_sleep:1;
  119974. + unsigned resetaftsusp:1;
  119975. + unsigned restoremode:1;
  119976. + unsigned enbl_extnd_hiber:1;
  119977. + unsigned extnd_hiber_pwrclmp:1;
  119978. + unsigned extnd_hiber_switch:1;
  119979. + unsigned ess_reg_restored:1;
  119980. + unsigned prt_clk_sel:2;
  119981. + unsigned port_power:1;
  119982. + unsigned max_xcvrselect:2;
  119983. + unsigned max_termsel:1;
  119984. + unsigned mac_dev_addr:7;
  119985. + unsigned p2hd_dev_enum_spd:2;
  119986. + unsigned p2hd_prt_spd:2;
  119987. + unsigned if_dev_mode:1;
  119988. + } b;
  119989. +} pcgcctl_data_t;
  119990. +
  119991. +/**
  119992. + * This union represents the bit fields in the Global Data FIFO Software
  119993. + * Configuration Register. Read the register into the <i>d32</i> member then
  119994. + * set/clear the bits using the <i>b</i>it elements.
  119995. + */
  119996. +typedef union gdfifocfg_data {
  119997. + /* raw register data */
  119998. + uint32_t d32;
  119999. + /** register bits */
  120000. + struct {
  120001. + /** OTG Data FIFO depth */
  120002. + unsigned gdfifocfg:16;
  120003. + /** Start address of EP info controller */
  120004. + unsigned epinfobase:16;
  120005. + } b;
  120006. +} gdfifocfg_data_t;
  120007. +
  120008. +/**
  120009. + * This union represents the bit fields in the Global Power Down Register
  120010. + * Register. Read the register into the <i>d32</i> member then set/clear the
  120011. + * bits using the <i>b</i>it elements.
  120012. + */
  120013. +typedef union gpwrdn_data {
  120014. + /* raw register data */
  120015. + uint32_t d32;
  120016. +
  120017. + /** register bits */
  120018. + struct {
  120019. + /** PMU Interrupt Select */
  120020. + unsigned pmuintsel:1;
  120021. + /** PMU Active */
  120022. + unsigned pmuactv:1;
  120023. + /** Restore */
  120024. + unsigned restore:1;
  120025. + /** Power Down Clamp */
  120026. + unsigned pwrdnclmp:1;
  120027. + /** Power Down Reset */
  120028. + unsigned pwrdnrstn:1;
  120029. + /** Power Down Switch */
  120030. + unsigned pwrdnswtch:1;
  120031. + /** Disable VBUS */
  120032. + unsigned dis_vbus:1;
  120033. + /** Line State Change */
  120034. + unsigned lnstschng:1;
  120035. + /** Line state change mask */
  120036. + unsigned lnstchng_msk:1;
  120037. + /** Reset Detected */
  120038. + unsigned rst_det:1;
  120039. + /** Reset Detect mask */
  120040. + unsigned rst_det_msk:1;
  120041. + /** Disconnect Detected */
  120042. + unsigned disconn_det:1;
  120043. + /** Disconnect Detect mask */
  120044. + unsigned disconn_det_msk:1;
  120045. + /** Connect Detected*/
  120046. + unsigned connect_det:1;
  120047. + /** Connect Detected Mask*/
  120048. + unsigned connect_det_msk:1;
  120049. + /** SRP Detected */
  120050. + unsigned srp_det:1;
  120051. + /** SRP Detect mask */
  120052. + unsigned srp_det_msk:1;
  120053. + /** Status Change Interrupt */
  120054. + unsigned sts_chngint:1;
  120055. + /** Status Change Interrupt Mask */
  120056. + unsigned sts_chngint_msk:1;
  120057. + /** Line State */
  120058. + unsigned linestate:2;
  120059. + /** Indicates current mode(status of IDDIG signal) */
  120060. + unsigned idsts:1;
  120061. + /** B Session Valid signal status*/
  120062. + unsigned bsessvld:1;
  120063. + /** ADP Event Detected */
  120064. + unsigned adp_int:1;
  120065. + /** Multi Valued ID pin */
  120066. + unsigned mult_val_id_bc:5;
  120067. + /** Reserved 24_31 */
  120068. + unsigned reserved29_31:3;
  120069. + } b;
  120070. +} gpwrdn_data_t;
  120071. +
  120072. +#endif
  120073. diff -Nur linux-3.18.8/drivers/usb/host/dwc_otg/Makefile linux-rpi/drivers/usb/host/dwc_otg/Makefile
  120074. --- linux-3.18.8/drivers/usb/host/dwc_otg/Makefile 1970-01-01 01:00:00.000000000 +0100
  120075. +++ linux-rpi/drivers/usb/host/dwc_otg/Makefile 2015-03-05 14:40:16.557715806 +0100
  120076. @@ -0,0 +1,82 @@
  120077. +#
  120078. +# Makefile for DWC_otg Highspeed USB controller driver
  120079. +#
  120080. +
  120081. +ifneq ($(KERNELRELEASE),)
  120082. +
  120083. +# Use the BUS_INTERFACE variable to compile the software for either
  120084. +# PCI(PCI_INTERFACE) or LM(LM_INTERFACE) bus.
  120085. +ifeq ($(BUS_INTERFACE),)
  120086. +# BUS_INTERFACE = -DPCI_INTERFACE
  120087. +# BUS_INTERFACE = -DLM_INTERFACE
  120088. + BUS_INTERFACE = -DPLATFORM_INTERFACE
  120089. +endif
  120090. +
  120091. +#ccflags-y += -DDEBUG
  120092. +#ccflags-y += -DDWC_OTG_DEBUGLEV=1 # reduce common debug msgs
  120093. +
  120094. +# Use one of the following flags to compile the software in host-only or
  120095. +# device-only mode.
  120096. +#ccflags-y += -DDWC_HOST_ONLY
  120097. +#ccflags-y += -DDWC_DEVICE_ONLY
  120098. +
  120099. +ccflags-y += -Dlinux -DDWC_HS_ELECT_TST
  120100. +#ccflags-y += -DDWC_EN_ISOC
  120101. +ccflags-y += -I$(obj)/../dwc_common_port
  120102. +#ccflags-y += -I$(PORTLIB)
  120103. +ccflags-y += -DDWC_LINUX
  120104. +ccflags-y += $(CFI)
  120105. +ccflags-y += $(BUS_INTERFACE)
  120106. +#ccflags-y += -DDWC_DEV_SRPCAP
  120107. +
  120108. +obj-$(CONFIG_USB_DWCOTG) += dwc_otg.o
  120109. +
  120110. +dwc_otg-objs := dwc_otg_driver.o dwc_otg_attr.o
  120111. +dwc_otg-objs += dwc_otg_cil.o dwc_otg_cil_intr.o
  120112. +dwc_otg-objs += dwc_otg_pcd_linux.o dwc_otg_pcd.o dwc_otg_pcd_intr.o
  120113. +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
  120114. +dwc_otg-objs += dwc_otg_adp.o
  120115. +dwc_otg-objs += dwc_otg_fiq_fsm.o
  120116. +dwc_otg-objs += dwc_otg_fiq_stub.o
  120117. +ifneq ($(CFI),)
  120118. +dwc_otg-objs += dwc_otg_cfi.o
  120119. +endif
  120120. +
  120121. +kernrelwd := $(subst ., ,$(KERNELRELEASE))
  120122. +kernrel3 := $(word 1,$(kernrelwd)).$(word 2,$(kernrelwd)).$(word 3,$(kernrelwd))
  120123. +
  120124. +ifneq ($(kernrel3),2.6.20)
  120125. +ccflags-y += $(CPPFLAGS)
  120126. +endif
  120127. +
  120128. +else
  120129. +
  120130. +PWD := $(shell pwd)
  120131. +PORTLIB := $(PWD)/../dwc_common_port
  120132. +
  120133. +# Command paths
  120134. +CTAGS := $(CTAGS)
  120135. +DOXYGEN := $(DOXYGEN)
  120136. +
  120137. +default: portlib
  120138. + $(MAKE) -C$(KDIR) M=$(PWD) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) modules
  120139. +
  120140. +install: default
  120141. + $(MAKE) -C$(KDIR) M=$(PORTLIB) modules_install
  120142. + $(MAKE) -C$(KDIR) M=$(PWD) modules_install
  120143. +
  120144. +portlib:
  120145. + $(MAKE) -C$(KDIR) M=$(PORTLIB) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) modules
  120146. + cp $(PORTLIB)/Module.symvers $(PWD)/
  120147. +
  120148. +docs: $(wildcard *.[hc]) doc/doxygen.cfg
  120149. + $(DOXYGEN) doc/doxygen.cfg
  120150. +
  120151. +tags: $(wildcard *.[hc])
  120152. + $(CTAGS) -e $(wildcard *.[hc]) $(wildcard linux/*.[hc]) $(wildcard $(KDIR)/include/linux/usb*.h)
  120153. +
  120154. +
  120155. +clean:
  120156. + rm -rf *.o *.ko .*cmd *.mod.c .tmp_versions Module.symvers
  120157. +
  120158. +endif
  120159. diff -Nur linux-3.18.8/drivers/usb/host/dwc_otg/test/dwc_otg_test.pm linux-rpi/drivers/usb/host/dwc_otg/test/dwc_otg_test.pm
  120160. --- linux-3.18.8/drivers/usb/host/dwc_otg/test/dwc_otg_test.pm 1970-01-01 01:00:00.000000000 +0100
  120161. +++ linux-rpi/drivers/usb/host/dwc_otg/test/dwc_otg_test.pm 2015-03-05 14:40:16.561715806 +0100
  120162. @@ -0,0 +1,337 @@
  120163. +package dwc_otg_test;
  120164. +
  120165. +use strict;
  120166. +use Exporter ();
  120167. +
  120168. +use vars qw(@ISA @EXPORT
  120169. +$sysfsdir $paramdir $errors $params
  120170. +);
  120171. +
  120172. +@ISA = qw(Exporter);
  120173. +
  120174. +#
  120175. +# Globals
  120176. +#
  120177. +$sysfsdir = "/sys/devices/lm0";
  120178. +$paramdir = "/sys/module/dwc_otg";
  120179. +$errors = 0;
  120180. +
  120181. +$params = [
  120182. + {
  120183. + NAME => "otg_cap",
  120184. + DEFAULT => 0,
  120185. + ENUM => [],
  120186. + LOW => 0,
  120187. + HIGH => 2
  120188. + },
  120189. + {
  120190. + NAME => "dma_enable",
  120191. + DEFAULT => 0,
  120192. + ENUM => [],
  120193. + LOW => 0,
  120194. + HIGH => 1
  120195. + },
  120196. + {
  120197. + NAME => "dma_burst_size",
  120198. + DEFAULT => 32,
  120199. + ENUM => [1, 4, 8, 16, 32, 64, 128, 256],
  120200. + LOW => 1,
  120201. + HIGH => 256
  120202. + },
  120203. + {
  120204. + NAME => "host_speed",
  120205. + DEFAULT => 0,
  120206. + ENUM => [],
  120207. + LOW => 0,
  120208. + HIGH => 1
  120209. + },
  120210. + {
  120211. + NAME => "host_support_fs_ls_low_power",
  120212. + DEFAULT => 0,
  120213. + ENUM => [],
  120214. + LOW => 0,
  120215. + HIGH => 1
  120216. + },
  120217. + {
  120218. + NAME => "host_ls_low_power_phy_clk",
  120219. + DEFAULT => 0,
  120220. + ENUM => [],
  120221. + LOW => 0,
  120222. + HIGH => 1
  120223. + },
  120224. + {
  120225. + NAME => "dev_speed",
  120226. + DEFAULT => 0,
  120227. + ENUM => [],
  120228. + LOW => 0,
  120229. + HIGH => 1
  120230. + },
  120231. + {
  120232. + NAME => "enable_dynamic_fifo",
  120233. + DEFAULT => 1,
  120234. + ENUM => [],
  120235. + LOW => 0,
  120236. + HIGH => 1
  120237. + },
  120238. + {
  120239. + NAME => "data_fifo_size",
  120240. + DEFAULT => 8192,
  120241. + ENUM => [],
  120242. + LOW => 32,
  120243. + HIGH => 32768
  120244. + },
  120245. + {
  120246. + NAME => "dev_rx_fifo_size",
  120247. + DEFAULT => 1064,
  120248. + ENUM => [],
  120249. + LOW => 16,
  120250. + HIGH => 32768
  120251. + },
  120252. + {
  120253. + NAME => "dev_nperio_tx_fifo_size",
  120254. + DEFAULT => 1024,
  120255. + ENUM => [],
  120256. + LOW => 16,
  120257. + HIGH => 32768
  120258. + },
  120259. + {
  120260. + NAME => "dev_perio_tx_fifo_size_1",
  120261. + DEFAULT => 256,
  120262. + ENUM => [],
  120263. + LOW => 4,
  120264. + HIGH => 768
  120265. + },
  120266. + {
  120267. + NAME => "dev_perio_tx_fifo_size_2",
  120268. + DEFAULT => 256,
  120269. + ENUM => [],
  120270. + LOW => 4,
  120271. + HIGH => 768
  120272. + },
  120273. + {
  120274. + NAME => "dev_perio_tx_fifo_size_3",
  120275. + DEFAULT => 256,
  120276. + ENUM => [],
  120277. + LOW => 4,
  120278. + HIGH => 768
  120279. + },
  120280. + {
  120281. + NAME => "dev_perio_tx_fifo_size_4",
  120282. + DEFAULT => 256,
  120283. + ENUM => [],
  120284. + LOW => 4,
  120285. + HIGH => 768
  120286. + },
  120287. + {
  120288. + NAME => "dev_perio_tx_fifo_size_5",
  120289. + DEFAULT => 256,
  120290. + ENUM => [],
  120291. + LOW => 4,
  120292. + HIGH => 768
  120293. + },
  120294. + {
  120295. + NAME => "dev_perio_tx_fifo_size_6",
  120296. + DEFAULT => 256,
  120297. + ENUM => [],
  120298. + LOW => 4,
  120299. + HIGH => 768
  120300. + },
  120301. + {
  120302. + NAME => "dev_perio_tx_fifo_size_7",
  120303. + DEFAULT => 256,
  120304. + ENUM => [],
  120305. + LOW => 4,
  120306. + HIGH => 768
  120307. + },
  120308. + {
  120309. + NAME => "dev_perio_tx_fifo_size_8",
  120310. + DEFAULT => 256,
  120311. + ENUM => [],
  120312. + LOW => 4,
  120313. + HIGH => 768
  120314. + },
  120315. + {
  120316. + NAME => "dev_perio_tx_fifo_size_9",
  120317. + DEFAULT => 256,
  120318. + ENUM => [],
  120319. + LOW => 4,
  120320. + HIGH => 768
  120321. + },
  120322. + {
  120323. + NAME => "dev_perio_tx_fifo_size_10",
  120324. + DEFAULT => 256,
  120325. + ENUM => [],
  120326. + LOW => 4,
  120327. + HIGH => 768
  120328. + },
  120329. + {
  120330. + NAME => "dev_perio_tx_fifo_size_11",
  120331. + DEFAULT => 256,
  120332. + ENUM => [],
  120333. + LOW => 4,
  120334. + HIGH => 768
  120335. + },
  120336. + {
  120337. + NAME => "dev_perio_tx_fifo_size_12",
  120338. + DEFAULT => 256,
  120339. + ENUM => [],
  120340. + LOW => 4,
  120341. + HIGH => 768
  120342. + },
  120343. + {
  120344. + NAME => "dev_perio_tx_fifo_size_13",
  120345. + DEFAULT => 256,
  120346. + ENUM => [],
  120347. + LOW => 4,
  120348. + HIGH => 768
  120349. + },
  120350. + {
  120351. + NAME => "dev_perio_tx_fifo_size_14",
  120352. + DEFAULT => 256,
  120353. + ENUM => [],
  120354. + LOW => 4,
  120355. + HIGH => 768
  120356. + },
  120357. + {
  120358. + NAME => "dev_perio_tx_fifo_size_15",
  120359. + DEFAULT => 256,
  120360. + ENUM => [],
  120361. + LOW => 4,
  120362. + HIGH => 768
  120363. + },
  120364. + {
  120365. + NAME => "host_rx_fifo_size",
  120366. + DEFAULT => 1024,
  120367. + ENUM => [],
  120368. + LOW => 16,
  120369. + HIGH => 32768
  120370. + },
  120371. + {
  120372. + NAME => "host_nperio_tx_fifo_size",
  120373. + DEFAULT => 1024,
  120374. + ENUM => [],
  120375. + LOW => 16,
  120376. + HIGH => 32768
  120377. + },
  120378. + {
  120379. + NAME => "host_perio_tx_fifo_size",
  120380. + DEFAULT => 1024,
  120381. + ENUM => [],
  120382. + LOW => 16,
  120383. + HIGH => 32768
  120384. + },
  120385. + {
  120386. + NAME => "max_transfer_size",
  120387. + DEFAULT => 65535,
  120388. + ENUM => [],
  120389. + LOW => 2047,
  120390. + HIGH => 65535
  120391. + },
  120392. + {
  120393. + NAME => "max_packet_count",
  120394. + DEFAULT => 511,
  120395. + ENUM => [],
  120396. + LOW => 15,
  120397. + HIGH => 511
  120398. + },
  120399. + {
  120400. + NAME => "host_channels",
  120401. + DEFAULT => 12,
  120402. + ENUM => [],
  120403. + LOW => 1,
  120404. + HIGH => 16
  120405. + },
  120406. + {
  120407. + NAME => "dev_endpoints",
  120408. + DEFAULT => 6,
  120409. + ENUM => [],
  120410. + LOW => 1,
  120411. + HIGH => 15
  120412. + },
  120413. + {
  120414. + NAME => "phy_type",
  120415. + DEFAULT => 1,
  120416. + ENUM => [],
  120417. + LOW => 0,
  120418. + HIGH => 2
  120419. + },
  120420. + {
  120421. + NAME => "phy_utmi_width",
  120422. + DEFAULT => 16,
  120423. + ENUM => [8, 16],
  120424. + LOW => 8,
  120425. + HIGH => 16
  120426. + },
  120427. + {
  120428. + NAME => "phy_ulpi_ddr",
  120429. + DEFAULT => 0,
  120430. + ENUM => [],
  120431. + LOW => 0,
  120432. + HIGH => 1
  120433. + },
  120434. + ];
  120435. +
  120436. +
  120437. +#
  120438. +#
  120439. +sub check_arch {
  120440. + $_ = `uname -m`;
  120441. + chomp;
  120442. + unless (m/armv4tl/) {
  120443. + warn "# \n# Can't execute on $_. Run on integrator platform.\n# \n";
  120444. + return 0;
  120445. + }
  120446. + return 1;
  120447. +}
  120448. +
  120449. +#
  120450. +#
  120451. +sub load_module {
  120452. + my $params = shift;
  120453. + print "\nRemoving Module\n";
  120454. + system "rmmod dwc_otg";
  120455. + print "Loading Module\n";
  120456. + if ($params ne "") {
  120457. + print "Module Parameters: $params\n";
  120458. + }
  120459. + if (system("modprobe dwc_otg $params")) {
  120460. + warn "Unable to load module\n";
  120461. + return 0;
  120462. + }
  120463. + return 1;
  120464. +}
  120465. +
  120466. +#
  120467. +#
  120468. +sub test_status {
  120469. + my $arg = shift;
  120470. +
  120471. + print "\n";
  120472. +
  120473. + if (defined $arg) {
  120474. + warn "WARNING: $arg\n";
  120475. + }
  120476. +
  120477. + if ($errors > 0) {
  120478. + warn "TEST FAILED with $errors errors\n";
  120479. + return 0;
  120480. + } else {
  120481. + print "TEST PASSED\n";
  120482. + return 0 if (defined $arg);
  120483. + }
  120484. + return 1;
  120485. +}
  120486. +
  120487. +#
  120488. +#
  120489. +@EXPORT = qw(
  120490. +$sysfsdir
  120491. +$paramdir
  120492. +$params
  120493. +$errors
  120494. +check_arch
  120495. +load_module
  120496. +test_status
  120497. +);
  120498. +
  120499. +1;
  120500. diff -Nur linux-3.18.8/drivers/usb/host/dwc_otg/test/Makefile linux-rpi/drivers/usb/host/dwc_otg/test/Makefile
  120501. --- linux-3.18.8/drivers/usb/host/dwc_otg/test/Makefile 1970-01-01 01:00:00.000000000 +0100
  120502. +++ linux-rpi/drivers/usb/host/dwc_otg/test/Makefile 2015-03-05 14:40:16.561715806 +0100
  120503. @@ -0,0 +1,16 @@
  120504. +
  120505. +PERL=/usr/bin/perl
  120506. +PL_TESTS=test_sysfs.pl test_mod_param.pl
  120507. +
  120508. +.PHONY : test
  120509. +test : perl_tests
  120510. +
  120511. +perl_tests :
  120512. + @echo
  120513. + @echo Running perl tests
  120514. + @for test in $(PL_TESTS); do \
  120515. + if $(PERL) ./$$test ; then \
  120516. + echo "=======> $$test, PASSED" ; \
  120517. + else echo "=======> $$test, FAILED" ; \
  120518. + fi \
  120519. + done
  120520. diff -Nur linux-3.18.8/drivers/usb/host/dwc_otg/test/test_mod_param.pl linux-rpi/drivers/usb/host/dwc_otg/test/test_mod_param.pl
  120521. --- linux-3.18.8/drivers/usb/host/dwc_otg/test/test_mod_param.pl 1970-01-01 01:00:00.000000000 +0100
  120522. +++ linux-rpi/drivers/usb/host/dwc_otg/test/test_mod_param.pl 2015-03-05 14:40:16.561715806 +0100
  120523. @@ -0,0 +1,133 @@
  120524. +#!/usr/bin/perl -w
  120525. +#
  120526. +# Run this program on the integrator.
  120527. +#
  120528. +# - Tests module parameter default values.
  120529. +# - Tests setting of valid module parameter values via modprobe.
  120530. +# - Tests invalid module parameter values.
  120531. +# -----------------------------------------------------------------------------
  120532. +use strict;
  120533. +use dwc_otg_test;
  120534. +
  120535. +check_arch() or die;
  120536. +
  120537. +#
  120538. +#
  120539. +sub test {
  120540. + my ($param,$expected) = @_;
  120541. + my $value = get($param);
  120542. +
  120543. + if ($value == $expected) {
  120544. + print "$param = $value, okay\n";
  120545. + }
  120546. +
  120547. + else {
  120548. + warn "ERROR: value of $param != $expected, $value\n";
  120549. + $errors ++;
  120550. + }
  120551. +}
  120552. +
  120553. +#
  120554. +#
  120555. +sub get {
  120556. + my $param = shift;
  120557. + my $tmp = `cat $paramdir/$param`;
  120558. + chomp $tmp;
  120559. + return $tmp;
  120560. +}
  120561. +
  120562. +#
  120563. +#
  120564. +sub test_main {
  120565. +
  120566. + print "\nTesting Module Parameters\n";
  120567. +
  120568. + load_module("") or die;
  120569. +
  120570. + # Test initial values
  120571. + print "\nTesting Default Values\n";
  120572. + foreach (@{$params}) {
  120573. + test ($_->{NAME}, $_->{DEFAULT});
  120574. + }
  120575. +
  120576. + # Test low value
  120577. + print "\nTesting Low Value\n";
  120578. + my $cmd_params = "";
  120579. + foreach (@{$params}) {
  120580. + $cmd_params = $cmd_params . "$_->{NAME}=$_->{LOW} ";
  120581. + }
  120582. + load_module($cmd_params) or die;
  120583. +
  120584. + foreach (@{$params}) {
  120585. + test ($_->{NAME}, $_->{LOW});
  120586. + }
  120587. +
  120588. + # Test high value
  120589. + print "\nTesting High Value\n";
  120590. + $cmd_params = "";
  120591. + foreach (@{$params}) {
  120592. + $cmd_params = $cmd_params . "$_->{NAME}=$_->{HIGH} ";
  120593. + }
  120594. + load_module($cmd_params) or die;
  120595. +
  120596. + foreach (@{$params}) {
  120597. + test ($_->{NAME}, $_->{HIGH});
  120598. + }
  120599. +
  120600. + # Test Enum
  120601. + print "\nTesting Enumerated\n";
  120602. + foreach (@{$params}) {
  120603. + if (defined $_->{ENUM}) {
  120604. + my $value;
  120605. + foreach $value (@{$_->{ENUM}}) {
  120606. + $cmd_params = "$_->{NAME}=$value";
  120607. + load_module($cmd_params) or die;
  120608. + test ($_->{NAME}, $value);
  120609. + }
  120610. + }
  120611. + }
  120612. +
  120613. + # Test Invalid Values
  120614. + print "\nTesting Invalid Values\n";
  120615. + $cmd_params = "";
  120616. + foreach (@{$params}) {
  120617. + $cmd_params = $cmd_params . sprintf "$_->{NAME}=%d ", $_->{LOW}-1;
  120618. + }
  120619. + load_module($cmd_params) or die;
  120620. +
  120621. + foreach (@{$params}) {
  120622. + test ($_->{NAME}, $_->{DEFAULT});
  120623. + }
  120624. +
  120625. + $cmd_params = "";
  120626. + foreach (@{$params}) {
  120627. + $cmd_params = $cmd_params . sprintf "$_->{NAME}=%d ", $_->{HIGH}+1;
  120628. + }
  120629. + load_module($cmd_params) or die;
  120630. +
  120631. + foreach (@{$params}) {
  120632. + test ($_->{NAME}, $_->{DEFAULT});
  120633. + }
  120634. +
  120635. + print "\nTesting Enumerated\n";
  120636. + foreach (@{$params}) {
  120637. + if (defined $_->{ENUM}) {
  120638. + my $value;
  120639. + foreach $value (@{$_->{ENUM}}) {
  120640. + $value = $value + 1;
  120641. + $cmd_params = "$_->{NAME}=$value";
  120642. + load_module($cmd_params) or die;
  120643. + test ($_->{NAME}, $_->{DEFAULT});
  120644. + $value = $value - 2;
  120645. + $cmd_params = "$_->{NAME}=$value";
  120646. + load_module($cmd_params) or die;
  120647. + test ($_->{NAME}, $_->{DEFAULT});
  120648. + }
  120649. + }
  120650. + }
  120651. +
  120652. + test_status() or die;
  120653. +}
  120654. +
  120655. +test_main();
  120656. +0;
  120657. diff -Nur linux-3.18.8/drivers/usb/host/dwc_otg/test/test_sysfs.pl linux-rpi/drivers/usb/host/dwc_otg/test/test_sysfs.pl
  120658. --- linux-3.18.8/drivers/usb/host/dwc_otg/test/test_sysfs.pl 1970-01-01 01:00:00.000000000 +0100
  120659. +++ linux-rpi/drivers/usb/host/dwc_otg/test/test_sysfs.pl 2015-03-05 14:40:16.561715806 +0100
  120660. @@ -0,0 +1,193 @@
  120661. +#!/usr/bin/perl -w
  120662. +#
  120663. +# Run this program on the integrator
  120664. +# - Tests select sysfs attributes.
  120665. +# - Todo ... test more attributes, hnp/srp, buspower/bussuspend, etc.
  120666. +# -----------------------------------------------------------------------------
  120667. +use strict;
  120668. +use dwc_otg_test;
  120669. +
  120670. +check_arch() or die;
  120671. +
  120672. +#
  120673. +#
  120674. +sub test {
  120675. + my ($attr,$expected) = @_;
  120676. + my $string = get($attr);
  120677. +
  120678. + if ($string eq $expected) {
  120679. + printf("$attr = $string, okay\n");
  120680. + }
  120681. + else {
  120682. + warn "ERROR: value of $attr != $expected, $string\n";
  120683. + $errors ++;
  120684. + }
  120685. +}
  120686. +
  120687. +#
  120688. +#
  120689. +sub set {
  120690. + my ($reg, $value) = @_;
  120691. + system "echo $value > $sysfsdir/$reg";
  120692. +}
  120693. +
  120694. +#
  120695. +#
  120696. +sub get {
  120697. + my $attr = shift;
  120698. + my $string = `cat $sysfsdir/$attr`;
  120699. + chomp $string;
  120700. + if ($string =~ m/\s\=\s/) {
  120701. + my $tmp;
  120702. + ($tmp, $string) = split /\s=\s/, $string;
  120703. + }
  120704. + return $string;
  120705. +}
  120706. +
  120707. +#
  120708. +#
  120709. +sub test_main {
  120710. + print("\nTesting Sysfs Attributes\n");
  120711. +
  120712. + load_module("") or die;
  120713. +
  120714. + # Test initial values of regoffset/regvalue/guid/gsnpsid
  120715. + print("\nTesting Default Values\n");
  120716. +
  120717. + test("regoffset", "0xffffffff");
  120718. + test("regvalue", "invalid offset");
  120719. + test("guid", "0x12345678"); # this will fail if it has been changed
  120720. + test("gsnpsid", "0x4f54200a");
  120721. +
  120722. + # Test operation of regoffset/regvalue
  120723. + print("\nTesting regoffset\n");
  120724. + set('regoffset', '5a5a5a5a');
  120725. + test("regoffset", "0xffffffff");
  120726. +
  120727. + set('regoffset', '0');
  120728. + test("regoffset", "0x00000000");
  120729. +
  120730. + set('regoffset', '40000');
  120731. + test("regoffset", "0x00000000");
  120732. +
  120733. + set('regoffset', '3ffff');
  120734. + test("regoffset", "0x0003ffff");
  120735. +
  120736. + set('regoffset', '1');
  120737. + test("regoffset", "0x00000001");
  120738. +
  120739. + print("\nTesting regvalue\n");
  120740. + set('regoffset', '3c');
  120741. + test("regvalue", "0x12345678");
  120742. + set('regvalue', '5a5a5a5a');
  120743. + test("regvalue", "0x5a5a5a5a");
  120744. + set('regvalue','a5a5a5a5');
  120745. + test("regvalue", "0xa5a5a5a5");
  120746. + set('guid','12345678');
  120747. +
  120748. + # Test HNP Capable
  120749. + print("\nTesting HNP Capable bit\n");
  120750. + set('hnpcapable', '1');
  120751. + test("hnpcapable", "0x1");
  120752. + set('hnpcapable','0');
  120753. + test("hnpcapable", "0x0");
  120754. +
  120755. + set('regoffset','0c');
  120756. +
  120757. + my $old = get('gusbcfg');
  120758. + print("setting hnpcapable\n");
  120759. + set('hnpcapable', '1');
  120760. + test("hnpcapable", "0x1");
  120761. + test('gusbcfg', sprintf "0x%08x", (oct ($old) | (1<<9)));
  120762. + test('regvalue', sprintf "0x%08x", (oct ($old) | (1<<9)));
  120763. +
  120764. + $old = get('gusbcfg');
  120765. + print("clearing hnpcapable\n");
  120766. + set('hnpcapable', '0');
  120767. + test("hnpcapable", "0x0");
  120768. + test ('gusbcfg', sprintf "0x%08x", oct ($old) & (~(1<<9)));
  120769. + test ('regvalue', sprintf "0x%08x", oct ($old) & (~(1<<9)));
  120770. +
  120771. + # Test SRP Capable
  120772. + print("\nTesting SRP Capable bit\n");
  120773. + set('srpcapable', '1');
  120774. + test("srpcapable", "0x1");
  120775. + set('srpcapable','0');
  120776. + test("srpcapable", "0x0");
  120777. +
  120778. + set('regoffset','0c');
  120779. +
  120780. + $old = get('gusbcfg');
  120781. + print("setting srpcapable\n");
  120782. + set('srpcapable', '1');
  120783. + test("srpcapable", "0x1");
  120784. + test('gusbcfg', sprintf "0x%08x", (oct ($old) | (1<<8)));
  120785. + test('regvalue', sprintf "0x%08x", (oct ($old) | (1<<8)));
  120786. +
  120787. + $old = get('gusbcfg');
  120788. + print("clearing srpcapable\n");
  120789. + set('srpcapable', '0');
  120790. + test("srpcapable", "0x0");
  120791. + test('gusbcfg', sprintf "0x%08x", oct ($old) & (~(1<<8)));
  120792. + test('regvalue', sprintf "0x%08x", oct ($old) & (~(1<<8)));
  120793. +
  120794. + # Test GGPIO
  120795. + print("\nTesting GGPIO\n");
  120796. + set('ggpio','5a5a5a5a');
  120797. + test('ggpio','0x5a5a0000');
  120798. + set('ggpio','a5a5a5a5');
  120799. + test('ggpio','0xa5a50000');
  120800. + set('ggpio','11110000');
  120801. + test('ggpio','0x11110000');
  120802. + set('ggpio','00001111');
  120803. + test('ggpio','0x00000000');
  120804. +
  120805. + # Test DEVSPEED
  120806. + print("\nTesting DEVSPEED\n");
  120807. + set('regoffset','800');
  120808. + $old = get('regvalue');
  120809. + set('devspeed','0');
  120810. + test('devspeed','0x0');
  120811. + test('regvalue',sprintf("0x%08x", oct($old) & ~(0x3)));
  120812. + set('devspeed','1');
  120813. + test('devspeed','0x1');
  120814. + test('regvalue',sprintf("0x%08x", oct($old) & ~(0x3) | 1));
  120815. + set('devspeed','2');
  120816. + test('devspeed','0x2');
  120817. + test('regvalue',sprintf("0x%08x", oct($old) & ~(0x3) | 2));
  120818. + set('devspeed','3');
  120819. + test('devspeed','0x3');
  120820. + test('regvalue',sprintf("0x%08x", oct($old) & ~(0x3) | 3));
  120821. + set('devspeed','4');
  120822. + test('devspeed','0x0');
  120823. + test('regvalue',sprintf("0x%08x", oct($old) & ~(0x3)));
  120824. + set('devspeed','5');
  120825. + test('devspeed','0x1');
  120826. + test('regvalue',sprintf("0x%08x", oct($old) & ~(0x3) | 1));
  120827. +
  120828. +
  120829. + # mode Returns the current mode:0 for device mode1 for host mode Read
  120830. + # hnp Initiate the Host Negotiation Protocol. Read returns the status. Read/Write
  120831. + # srp Initiate the Session Request Protocol. Read returns the status. Read/Write
  120832. + # buspower Get or Set the Power State of the bus (0 - Off or 1 - On) Read/Write
  120833. + # bussuspend Suspend the USB bus. Read/Write
  120834. + # busconnected Get the connection status of the bus Read
  120835. +
  120836. + # gotgctl Get or set the Core Control Status Register. Read/Write
  120837. + ## gusbcfg Get or set the Core USB Configuration Register Read/Write
  120838. + # grxfsiz Get or set the Receive FIFO Size Register Read/Write
  120839. + # gnptxfsiz Get or set the non-periodic Transmit Size Register Read/Write
  120840. + # gpvndctl Get or set the PHY Vendor Control Register Read/Write
  120841. + ## ggpio Get the value in the lower 16-bits of the General Purpose IO Register or Set the upper 16 bits. Read/Write
  120842. + ## guid Get or set the value of the User ID Register Read/Write
  120843. + ## gsnpsid Get the value of the Synopsys ID Regester Read
  120844. + ## devspeed Get or set the device speed setting in the DCFG register Read/Write
  120845. + # enumspeed Gets the device enumeration Speed. Read
  120846. + # hptxfsiz Get the value of the Host Periodic Transmit FIFO Read
  120847. + # hprt0 Get or Set the value in the Host Port Control and Status Register Read/Write
  120848. +
  120849. + test_status("TEST NYI") or die;
  120850. +}
  120851. +
  120852. +test_main();
  120853. +0;
  120854. diff -Nur linux-3.18.8/drivers/usb/host/Kconfig linux-rpi/drivers/usb/host/Kconfig
  120855. --- linux-3.18.8/drivers/usb/host/Kconfig 2015-02-27 02:49:36.000000000 +0100
  120856. +++ linux-rpi/drivers/usb/host/Kconfig 2015-03-05 14:40:16.553715806 +0100
  120857. @@ -744,6 +744,19 @@
  120858. To compile this driver a module, choose M here: the module
  120859. will be called "hwa-hc".
  120860. +config USB_DWCOTG
  120861. + tristate "Synopsis DWC host support"
  120862. + depends on USB
  120863. + help
  120864. + The Synopsis DWC controller is a dual-role
  120865. + host/peripheral/OTG ("On The Go") USB controllers.
  120866. +
  120867. + Enable this option to support this IP in host controller mode.
  120868. + If unsure, say N.
  120869. +
  120870. + To compile this driver as a module, choose M here: the
  120871. + modules built will be called dwc_otg and dwc_common_port.
  120872. +
  120873. config USB_IMX21_HCD
  120874. tristate "i.MX21 HCD support"
  120875. depends on ARM && ARCH_MXC
  120876. diff -Nur linux-3.18.8/drivers/usb/host/Makefile linux-rpi/drivers/usb/host/Makefile
  120877. --- linux-3.18.8/drivers/usb/host/Makefile 2015-02-27 02:49:36.000000000 +0100
  120878. +++ linux-rpi/drivers/usb/host/Makefile 2015-03-05 14:40:16.553715806 +0100
  120879. @@ -71,6 +71,8 @@
  120880. obj-$(CONFIG_USB_R8A66597_HCD) += r8a66597-hcd.o
  120881. obj-$(CONFIG_USB_ISP1760_HCD) += isp1760.o
  120882. obj-$(CONFIG_USB_HWA_HCD) += hwa-hc.o
  120883. +
  120884. +obj-$(CONFIG_USB_DWCOTG) += dwc_otg/ dwc_common_port/
  120885. obj-$(CONFIG_USB_IMX21_HCD) += imx21-hcd.o
  120886. obj-$(CONFIG_USB_FSL_MPH_DR_OF) += fsl-mph-dr-of.o
  120887. obj-$(CONFIG_USB_OCTEON2_COMMON) += octeon2-common.o
  120888. diff -Nur linux-3.18.8/drivers/usb/Makefile linux-rpi/drivers/usb/Makefile
  120889. --- linux-3.18.8/drivers/usb/Makefile 2015-02-27 02:49:36.000000000 +0100
  120890. +++ linux-rpi/drivers/usb/Makefile 2015-03-05 14:40:16.525715806 +0100
  120891. @@ -24,6 +24,7 @@
  120892. obj-$(CONFIG_USB_R8A66597_HCD) += host/
  120893. obj-$(CONFIG_USB_HWA_HCD) += host/
  120894. obj-$(CONFIG_USB_ISP1760_HCD) += host/
  120895. +obj-$(CONFIG_USB_DWCOTG) += host/
  120896. obj-$(CONFIG_USB_IMX21_HCD) += host/
  120897. obj-$(CONFIG_USB_FSL_MPH_DR_OF) += host/
  120898. obj-$(CONFIG_USB_FUSBH200_HCD) += host/
  120899. diff -Nur linux-3.18.8/drivers/video/fbdev/bcm2708_fb.c linux-rpi/drivers/video/fbdev/bcm2708_fb.c
  120900. --- linux-3.18.8/drivers/video/fbdev/bcm2708_fb.c 1970-01-01 01:00:00.000000000 +0100
  120901. +++ linux-rpi/drivers/video/fbdev/bcm2708_fb.c 2015-03-05 14:40:16.889715804 +0100
  120902. @@ -0,0 +1,818 @@
  120903. +/*
  120904. + * linux/drivers/video/bcm2708_fb.c
  120905. + *
  120906. + * Copyright (C) 2010 Broadcom
  120907. + *
  120908. + * This file is subject to the terms and conditions of the GNU General Public
  120909. + * License. See the file COPYING in the main directory of this archive
  120910. + * for more details.
  120911. + *
  120912. + * Broadcom simple framebuffer driver
  120913. + *
  120914. + * This file is derived from cirrusfb.c
  120915. + * Copyright 1999-2001 Jeff Garzik <jgarzik@pobox.com>
  120916. + *
  120917. + */
  120918. +#include <linux/module.h>
  120919. +#include <linux/kernel.h>
  120920. +#include <linux/errno.h>
  120921. +#include <linux/string.h>
  120922. +#include <linux/slab.h>
  120923. +#include <linux/mm.h>
  120924. +#include <linux/fb.h>
  120925. +#include <linux/init.h>
  120926. +#include <linux/interrupt.h>
  120927. +#include <linux/ioport.h>
  120928. +#include <linux/list.h>
  120929. +#include <linux/platform_device.h>
  120930. +#include <linux/clk.h>
  120931. +#include <linux/printk.h>
  120932. +#include <linux/console.h>
  120933. +#include <linux/debugfs.h>
  120934. +
  120935. +#include <mach/dma.h>
  120936. +#include <mach/platform.h>
  120937. +#include <mach/vcio.h>
  120938. +
  120939. +#include <asm/sizes.h>
  120940. +#include <linux/io.h>
  120941. +#include <linux/dma-mapping.h>
  120942. +
  120943. +//#define BCM2708_FB_DEBUG
  120944. +#define MODULE_NAME "bcm2708_fb"
  120945. +
  120946. +#ifdef BCM2708_FB_DEBUG
  120947. +#define print_debug(fmt,...) pr_debug("%s:%s:%d: "fmt, MODULE_NAME, __func__, __LINE__, ##__VA_ARGS__)
  120948. +#else
  120949. +#define print_debug(fmt,...)
  120950. +#endif
  120951. +
  120952. +/* This is limited to 16 characters when displayed by X startup */
  120953. +static const char *bcm2708_name = "BCM2708 FB";
  120954. +
  120955. +#define DRIVER_NAME "bcm2708_fb"
  120956. +
  120957. +static int fbwidth = 800; /* module parameter */
  120958. +static int fbheight = 480; /* module parameter */
  120959. +static int fbdepth = 16; /* module parameter */
  120960. +static int fbswap = 0; /* module parameter */
  120961. +
  120962. +static u32 dma_busy_wait_threshold = 1<<15;
  120963. +module_param(dma_busy_wait_threshold, int, 0644);
  120964. +MODULE_PARM_DESC(dma_busy_wait_threshold, "Busy-wait for DMA completion below this area");
  120965. +
  120966. +/* this data structure describes each frame buffer device we find */
  120967. +
  120968. +struct fbinfo_s {
  120969. + u32 xres, yres, xres_virtual, yres_virtual;
  120970. + u32 pitch, bpp;
  120971. + u32 xoffset, yoffset;
  120972. + u32 base;
  120973. + u32 screen_size;
  120974. + u16 cmap[256];
  120975. +};
  120976. +
  120977. +struct bcm2708_fb_stats {
  120978. + struct debugfs_regset32 regset;
  120979. + u32 dma_copies;
  120980. + u32 dma_irqs;
  120981. +};
  120982. +
  120983. +struct bcm2708_fb {
  120984. + struct fb_info fb;
  120985. + struct platform_device *dev;
  120986. + struct fbinfo_s *info;
  120987. + dma_addr_t dma;
  120988. + u32 cmap[16];
  120989. + int dma_chan;
  120990. + int dma_irq;
  120991. + void __iomem *dma_chan_base;
  120992. + void *cb_base; /* DMA control blocks */
  120993. + dma_addr_t cb_handle;
  120994. + struct dentry *debugfs_dir;
  120995. + wait_queue_head_t dma_waitq;
  120996. + struct bcm2708_fb_stats stats;
  120997. + unsigned long fb_bus_address;
  120998. +};
  120999. +
  121000. +#define to_bcm2708(info) container_of(info, struct bcm2708_fb, fb)
  121001. +
  121002. +static void bcm2708_fb_debugfs_deinit(struct bcm2708_fb *fb)
  121003. +{
  121004. + debugfs_remove_recursive(fb->debugfs_dir);
  121005. + fb->debugfs_dir = NULL;
  121006. +}
  121007. +
  121008. +static int bcm2708_fb_debugfs_init(struct bcm2708_fb *fb)
  121009. +{
  121010. + static struct debugfs_reg32 stats_registers[] = {
  121011. + {
  121012. + "dma_copies",
  121013. + offsetof(struct bcm2708_fb_stats, dma_copies)
  121014. + },
  121015. + {
  121016. + "dma_irqs",
  121017. + offsetof(struct bcm2708_fb_stats, dma_irqs)
  121018. + },
  121019. + };
  121020. +
  121021. + fb->debugfs_dir = debugfs_create_dir(DRIVER_NAME, NULL);
  121022. + if (!fb->debugfs_dir) {
  121023. + pr_warn("%s: could not create debugfs entry\n",
  121024. + __func__);
  121025. + return -EFAULT;
  121026. + }
  121027. +
  121028. + fb->stats.regset.regs = stats_registers;
  121029. + fb->stats.regset.nregs = ARRAY_SIZE(stats_registers);
  121030. + fb->stats.regset.base = &fb->stats;
  121031. +
  121032. + if (!debugfs_create_regset32(
  121033. + "stats", 0444, fb->debugfs_dir, &fb->stats.regset)) {
  121034. + pr_warn("%s: could not create statistics registers\n",
  121035. + __func__);
  121036. + goto fail;
  121037. + }
  121038. + return 0;
  121039. +
  121040. +fail:
  121041. + bcm2708_fb_debugfs_deinit(fb);
  121042. + return -EFAULT;
  121043. +}
  121044. +
  121045. +static int bcm2708_fb_set_bitfields(struct fb_var_screeninfo *var)
  121046. +{
  121047. + int ret = 0;
  121048. +
  121049. + memset(&var->transp, 0, sizeof(var->transp));
  121050. +
  121051. + var->red.msb_right = 0;
  121052. + var->green.msb_right = 0;
  121053. + var->blue.msb_right = 0;
  121054. +
  121055. + switch (var->bits_per_pixel) {
  121056. + case 1:
  121057. + case 2:
  121058. + case 4:
  121059. + case 8:
  121060. + var->red.length = var->bits_per_pixel;
  121061. + var->red.offset = 0;
  121062. + var->green.length = var->bits_per_pixel;
  121063. + var->green.offset = 0;
  121064. + var->blue.length = var->bits_per_pixel;
  121065. + var->blue.offset = 0;
  121066. + break;
  121067. + case 16:
  121068. + var->red.length = 5;
  121069. + var->blue.length = 5;
  121070. + /*
  121071. + * Green length can be 5 or 6 depending whether
  121072. + * we're operating in RGB555 or RGB565 mode.
  121073. + */
  121074. + if (var->green.length != 5 && var->green.length != 6)
  121075. + var->green.length = 6;
  121076. + break;
  121077. + case 24:
  121078. + var->red.length = 8;
  121079. + var->blue.length = 8;
  121080. + var->green.length = 8;
  121081. + break;
  121082. + case 32:
  121083. + var->red.length = 8;
  121084. + var->green.length = 8;
  121085. + var->blue.length = 8;
  121086. + var->transp.length = 8;
  121087. + break;
  121088. + default:
  121089. + ret = -EINVAL;
  121090. + break;
  121091. + }
  121092. +
  121093. + /*
  121094. + * >= 16bpp displays have separate colour component bitfields
  121095. + * encoded in the pixel data. Calculate their position from
  121096. + * the bitfield length defined above.
  121097. + */
  121098. + if (ret == 0 && var->bits_per_pixel >= 24 && fbswap) {
  121099. + var->blue.offset = 0;
  121100. + var->green.offset = var->blue.offset + var->blue.length;
  121101. + var->red.offset = var->green.offset + var->green.length;
  121102. + var->transp.offset = var->red.offset + var->red.length;
  121103. + } else if (ret == 0 && var->bits_per_pixel >= 24) {
  121104. + var->red.offset = 0;
  121105. + var->green.offset = var->red.offset + var->red.length;
  121106. + var->blue.offset = var->green.offset + var->green.length;
  121107. + var->transp.offset = var->blue.offset + var->blue.length;
  121108. + } else if (ret == 0 && var->bits_per_pixel >= 16) {
  121109. + var->blue.offset = 0;
  121110. + var->green.offset = var->blue.offset + var->blue.length;
  121111. + var->red.offset = var->green.offset + var->green.length;
  121112. + var->transp.offset = var->red.offset + var->red.length;
  121113. + }
  121114. +
  121115. + return ret;
  121116. +}
  121117. +
  121118. +static int bcm2708_fb_check_var(struct fb_var_screeninfo *var,
  121119. + struct fb_info *info)
  121120. +{
  121121. + /* info input, var output */
  121122. + int yres;
  121123. +
  121124. + /* info input, var output */
  121125. + print_debug("bcm2708_fb_check_var info(%p) %dx%d (%dx%d), %d, %d\n", info,
  121126. + info->var.xres, info->var.yres, info->var.xres_virtual,
  121127. + info->var.yres_virtual, (int)info->screen_size,
  121128. + info->var.bits_per_pixel);
  121129. + print_debug("bcm2708_fb_check_var var(%p) %dx%d (%dx%d), %d\n", var,
  121130. + var->xres, var->yres, var->xres_virtual, var->yres_virtual,
  121131. + var->bits_per_pixel);
  121132. +
  121133. + if (!var->bits_per_pixel)
  121134. + var->bits_per_pixel = 16;
  121135. +
  121136. + if (bcm2708_fb_set_bitfields(var) != 0) {
  121137. + pr_err("bcm2708_fb_check_var: invalid bits_per_pixel %d\n",
  121138. + var->bits_per_pixel);
  121139. + return -EINVAL;
  121140. + }
  121141. +
  121142. +
  121143. + if (var->xres_virtual < var->xres)
  121144. + var->xres_virtual = var->xres;
  121145. + /* use highest possible virtual resolution */
  121146. + if (var->yres_virtual == -1) {
  121147. + var->yres_virtual = 480;
  121148. +
  121149. + pr_err
  121150. + ("bcm2708_fb_check_var: virtual resolution set to maximum of %dx%d\n",
  121151. + var->xres_virtual, var->yres_virtual);
  121152. + }
  121153. + if (var->yres_virtual < var->yres)
  121154. + var->yres_virtual = var->yres;
  121155. +
  121156. + if (var->xoffset < 0)
  121157. + var->xoffset = 0;
  121158. + if (var->yoffset < 0)
  121159. + var->yoffset = 0;
  121160. +
  121161. + /* truncate xoffset and yoffset to maximum if too high */
  121162. + if (var->xoffset > var->xres_virtual - var->xres)
  121163. + var->xoffset = var->xres_virtual - var->xres - 1;
  121164. + if (var->yoffset > var->yres_virtual - var->yres)
  121165. + var->yoffset = var->yres_virtual - var->yres - 1;
  121166. +
  121167. + yres = var->yres;
  121168. + if (var->vmode & FB_VMODE_DOUBLE)
  121169. + yres *= 2;
  121170. + else if (var->vmode & FB_VMODE_INTERLACED)
  121171. + yres = (yres + 1) / 2;
  121172. +
  121173. + return 0;
  121174. +}
  121175. +
  121176. +static int bcm2708_fb_set_par(struct fb_info *info)
  121177. +{
  121178. + uint32_t val = 0;
  121179. + struct bcm2708_fb *fb = to_bcm2708(info);
  121180. + volatile struct fbinfo_s *fbinfo = fb->info;
  121181. + fbinfo->xres = info->var.xres;
  121182. + fbinfo->yres = info->var.yres;
  121183. + fbinfo->xres_virtual = info->var.xres_virtual;
  121184. + fbinfo->yres_virtual = info->var.yres_virtual;
  121185. + fbinfo->bpp = info->var.bits_per_pixel;
  121186. + fbinfo->xoffset = info->var.xoffset;
  121187. + fbinfo->yoffset = info->var.yoffset;
  121188. + fbinfo->base = 0; /* filled in by VC */
  121189. + fbinfo->pitch = 0; /* filled in by VC */
  121190. +
  121191. + print_debug("bcm2708_fb_set_par info(%p) %dx%d (%dx%d), %d, %d\n", info,
  121192. + info->var.xres, info->var.yres, info->var.xres_virtual,
  121193. + info->var.yres_virtual, (int)info->screen_size,
  121194. + info->var.bits_per_pixel);
  121195. +
  121196. + /* ensure last write to fbinfo is visible to GPU */
  121197. + wmb();
  121198. +
  121199. + /* inform vc about new framebuffer */
  121200. + bcm_mailbox_write(MBOX_CHAN_FB, fb->dma);
  121201. +
  121202. + /* TODO: replace fb driver with vchiq version */
  121203. + /* wait for response */
  121204. + bcm_mailbox_read(MBOX_CHAN_FB, &val);
  121205. +
  121206. + /* ensure GPU writes are visible to us */
  121207. + rmb();
  121208. +
  121209. + if (val == 0) {
  121210. + fb->fb.fix.line_length = fbinfo->pitch;
  121211. +
  121212. + if (info->var.bits_per_pixel <= 8)
  121213. + fb->fb.fix.visual = FB_VISUAL_PSEUDOCOLOR;
  121214. + else
  121215. + fb->fb.fix.visual = FB_VISUAL_TRUECOLOR;
  121216. +
  121217. + fb->fb_bus_address = fbinfo->base;
  121218. + fbinfo->base &= ~0xc0000000;
  121219. + fb->fb.fix.smem_start = fbinfo->base;
  121220. + fb->fb.fix.smem_len = fbinfo->pitch * fbinfo->yres_virtual;
  121221. + fb->fb.screen_size = fbinfo->screen_size;
  121222. + if (fb->fb.screen_base)
  121223. + iounmap(fb->fb.screen_base);
  121224. + fb->fb.screen_base =
  121225. + (void *)ioremap_wc(fbinfo->base, fb->fb.screen_size);
  121226. + if (!fb->fb.screen_base) {
  121227. + /* the console may currently be locked */
  121228. + console_trylock();
  121229. + console_unlock();
  121230. +
  121231. + BUG(); /* what can we do here */
  121232. + }
  121233. + }
  121234. + print_debug
  121235. + ("BCM2708FB: start = %p,%p width=%d, height=%d, bpp=%d, pitch=%d size=%d success=%d\n",
  121236. + (void *)fb->fb.screen_base, (void *)fb->fb_bus_address,
  121237. + fbinfo->xres, fbinfo->yres, fbinfo->bpp,
  121238. + fbinfo->pitch, (int)fb->fb.screen_size, val);
  121239. +
  121240. + return val;
  121241. +}
  121242. +
  121243. +static inline u32 convert_bitfield(int val, struct fb_bitfield *bf)
  121244. +{
  121245. + unsigned int mask = (1 << bf->length) - 1;
  121246. +
  121247. + return (val >> (16 - bf->length) & mask) << bf->offset;
  121248. +}
  121249. +
  121250. +
  121251. +static int bcm2708_fb_setcolreg(unsigned int regno, unsigned int red,
  121252. + unsigned int green, unsigned int blue,
  121253. + unsigned int transp, struct fb_info *info)
  121254. +{
  121255. + struct bcm2708_fb *fb = to_bcm2708(info);
  121256. +
  121257. + /*print_debug("BCM2708FB: setcolreg %d:(%02x,%02x,%02x,%02x) %x\n", regno, red, green, blue, transp, fb->fb.fix.visual);*/
  121258. + if (fb->fb.var.bits_per_pixel <= 8) {
  121259. + if (regno < 256) {
  121260. + /* blue [0:4], green [5:10], red [11:15] */
  121261. + fb->info->cmap[regno] = ((red >> (16-5)) & 0x1f) << 11 |
  121262. + ((green >> (16-6)) & 0x3f) << 5 |
  121263. + ((blue >> (16-5)) & 0x1f) << 0;
  121264. + }
  121265. + /* 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 */
  121266. + /* So just call it for what looks like the last colour in a list for now. */
  121267. + if (regno == 15 || regno == 255)
  121268. + bcm2708_fb_set_par(info);
  121269. + } else if (regno < 16) {
  121270. + fb->cmap[regno] = convert_bitfield(transp, &fb->fb.var.transp) |
  121271. + convert_bitfield(blue, &fb->fb.var.blue) |
  121272. + convert_bitfield(green, &fb->fb.var.green) |
  121273. + convert_bitfield(red, &fb->fb.var.red);
  121274. + }
  121275. + return regno > 255;
  121276. +}
  121277. +
  121278. +static int bcm2708_fb_blank(int blank_mode, struct fb_info *info)
  121279. +{
  121280. + s32 result = -1;
  121281. + u32 p[7];
  121282. + if ( (blank_mode == FB_BLANK_NORMAL) ||
  121283. + (blank_mode == FB_BLANK_UNBLANK)) {
  121284. +
  121285. + p[0] = 28; // size = sizeof u32 * length of p
  121286. + p[1] = VCMSG_PROCESS_REQUEST; // process request
  121287. + p[2] = VCMSG_SET_BLANK_SCREEN; // (the tag id)
  121288. + p[3] = 4; // (size of the response buffer)
  121289. + p[4] = 4; // (size of the request data)
  121290. + p[5] = blank_mode;
  121291. + p[6] = VCMSG_PROPERTY_END; // end tag
  121292. +
  121293. + bcm_mailbox_property(&p, p[0]);
  121294. +
  121295. + if ( p[1] == VCMSG_REQUEST_SUCCESSFUL )
  121296. + result = 0;
  121297. + else
  121298. + pr_err("bcm2708_fb_blank(%d) returns=%d p[1]=0x%x\n", blank_mode, p[5], p[1]);
  121299. + }
  121300. + return result;
  121301. +}
  121302. +
  121303. +static int bcm2708_fb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
  121304. +{
  121305. + s32 result = -1;
  121306. + info->var.xoffset = var->xoffset;
  121307. + info->var.yoffset = var->yoffset;
  121308. + result = bcm2708_fb_set_par(info);
  121309. + if (result != 0)
  121310. + pr_err("bcm2708_fb_pan_display(%d,%d) returns=%d\n", var->xoffset, var->yoffset, result);
  121311. + return result;
  121312. +}
  121313. +
  121314. +static int bcm2708_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg)
  121315. +{
  121316. + s32 result = -1;
  121317. + u32 p[7];
  121318. + if (cmd == FBIO_WAITFORVSYNC) {
  121319. + p[0] = 28; // size = sizeof u32 * length of p
  121320. + p[1] = VCMSG_PROCESS_REQUEST; // process request
  121321. + p[2] = VCMSG_SET_VSYNC; // (the tag id)
  121322. + p[3] = 4; // (size of the response buffer)
  121323. + p[4] = 4; // (size of the request data)
  121324. + p[5] = 0; // dummy
  121325. + p[6] = VCMSG_PROPERTY_END; // end tag
  121326. +
  121327. + bcm_mailbox_property(&p, p[0]);
  121328. +
  121329. + pr_info("bcm2708_fb_ioctl %x,%lx returns=%d p[1]=0x%x\n", cmd, arg, p[5], p[1]);
  121330. +
  121331. + if ( p[1] == VCMSG_REQUEST_SUCCESSFUL )
  121332. + result = 0;
  121333. + }
  121334. + return result;
  121335. +}
  121336. +static void bcm2708_fb_fillrect(struct fb_info *info,
  121337. + const struct fb_fillrect *rect)
  121338. +{
  121339. + /* (is called) print_debug("bcm2708_fb_fillrect\n"); */
  121340. + cfb_fillrect(info, rect);
  121341. +}
  121342. +
  121343. +/* A helper function for configuring dma control block */
  121344. +static void set_dma_cb(struct bcm2708_dma_cb *cb,
  121345. + int burst_size,
  121346. + dma_addr_t dst,
  121347. + int dst_stride,
  121348. + dma_addr_t src,
  121349. + int src_stride,
  121350. + int w,
  121351. + int h)
  121352. +{
  121353. + cb->info = BCM2708_DMA_BURST(burst_size) | BCM2708_DMA_S_WIDTH |
  121354. + BCM2708_DMA_S_INC | BCM2708_DMA_D_WIDTH |
  121355. + BCM2708_DMA_D_INC | BCM2708_DMA_TDMODE;
  121356. + cb->dst = dst;
  121357. + cb->src = src;
  121358. + /*
  121359. + * This is not really obvious from the DMA documentation,
  121360. + * but the top 16 bits must be programmmed to "height -1"
  121361. + * and not "height" in 2D mode.
  121362. + */
  121363. + cb->length = ((h - 1) << 16) | w;
  121364. + cb->stride = ((dst_stride - w) << 16) | (u16)(src_stride - w);
  121365. + cb->pad[0] = 0;
  121366. + cb->pad[1] = 0;
  121367. +}
  121368. +
  121369. +static void bcm2708_fb_copyarea(struct fb_info *info,
  121370. + const struct fb_copyarea *region)
  121371. +{
  121372. + struct bcm2708_fb *fb = to_bcm2708(info);
  121373. + struct bcm2708_dma_cb *cb = fb->cb_base;
  121374. + int bytes_per_pixel = (info->var.bits_per_pixel + 7) >> 3;
  121375. + /* Channel 0 supports larger bursts and is a bit faster */
  121376. + int burst_size = (fb->dma_chan == 0) ? 8 : 2;
  121377. + int pixels = region->width * region->height;
  121378. +
  121379. + /* Fallback to cfb_copyarea() if we don't like something */
  121380. + if (in_atomic() ||
  121381. + bytes_per_pixel > 4 ||
  121382. + info->var.xres * info->var.yres > 1920 * 1200 ||
  121383. + region->width <= 0 || region->width > info->var.xres ||
  121384. + region->height <= 0 || region->height > info->var.yres ||
  121385. + region->sx < 0 || region->sx >= info->var.xres ||
  121386. + region->sy < 0 || region->sy >= info->var.yres ||
  121387. + region->dx < 0 || region->dx >= info->var.xres ||
  121388. + region->dy < 0 || region->dy >= info->var.yres ||
  121389. + region->sx + region->width > info->var.xres ||
  121390. + region->dx + region->width > info->var.xres ||
  121391. + region->sy + region->height > info->var.yres ||
  121392. + region->dy + region->height > info->var.yres) {
  121393. + cfb_copyarea(info, region);
  121394. + return;
  121395. + }
  121396. +
  121397. + if (region->dy == region->sy && region->dx > region->sx) {
  121398. + /*
  121399. + * A difficult case of overlapped copy. Because DMA can't
  121400. + * copy individual scanlines in backwards direction, we need
  121401. + * two-pass processing. We do it by programming a chain of dma
  121402. + * control blocks in the first 16K part of the buffer and use
  121403. + * the remaining 48K as the intermediate temporary scratch
  121404. + * buffer. The buffer size is sufficient to handle up to
  121405. + * 1920x1200 resolution at 32bpp pixel depth.
  121406. + */
  121407. + int y;
  121408. + dma_addr_t control_block_pa = fb->cb_handle;
  121409. + dma_addr_t scratchbuf = fb->cb_handle + 16 * 1024;
  121410. + int scanline_size = bytes_per_pixel * region->width;
  121411. + int scanlines_per_cb = (64 * 1024 - 16 * 1024) / scanline_size;
  121412. +
  121413. + for (y = 0; y < region->height; y += scanlines_per_cb) {
  121414. + dma_addr_t src =
  121415. + fb->fb_bus_address +
  121416. + bytes_per_pixel * region->sx +
  121417. + (region->sy + y) * fb->fb.fix.line_length;
  121418. + dma_addr_t dst =
  121419. + fb->fb_bus_address +
  121420. + bytes_per_pixel * region->dx +
  121421. + (region->dy + y) * fb->fb.fix.line_length;
  121422. +
  121423. + if (region->height - y < scanlines_per_cb)
  121424. + scanlines_per_cb = region->height - y;
  121425. +
  121426. + set_dma_cb(cb, burst_size, scratchbuf, scanline_size,
  121427. + src, fb->fb.fix.line_length,
  121428. + scanline_size, scanlines_per_cb);
  121429. + control_block_pa += sizeof(struct bcm2708_dma_cb);
  121430. + cb->next = control_block_pa;
  121431. + cb++;
  121432. +
  121433. + set_dma_cb(cb, burst_size, dst, fb->fb.fix.line_length,
  121434. + scratchbuf, scanline_size,
  121435. + scanline_size, scanlines_per_cb);
  121436. + control_block_pa += sizeof(struct bcm2708_dma_cb);
  121437. + cb->next = control_block_pa;
  121438. + cb++;
  121439. + }
  121440. + /* move the pointer back to the last dma control block */
  121441. + cb--;
  121442. + } else {
  121443. + /* A single dma control block is enough. */
  121444. + int sy, dy, stride;
  121445. + if (region->dy <= region->sy) {
  121446. + /* processing from top to bottom */
  121447. + dy = region->dy;
  121448. + sy = region->sy;
  121449. + stride = fb->fb.fix.line_length;
  121450. + } else {
  121451. + /* processing from bottom to top */
  121452. + dy = region->dy + region->height - 1;
  121453. + sy = region->sy + region->height - 1;
  121454. + stride = -fb->fb.fix.line_length;
  121455. + }
  121456. + set_dma_cb(cb, burst_size,
  121457. + fb->fb_bus_address + dy * fb->fb.fix.line_length +
  121458. + bytes_per_pixel * region->dx,
  121459. + stride,
  121460. + fb->fb_bus_address + sy * fb->fb.fix.line_length +
  121461. + bytes_per_pixel * region->sx,
  121462. + stride,
  121463. + region->width * bytes_per_pixel,
  121464. + region->height);
  121465. + }
  121466. +
  121467. + /* end of dma control blocks chain */
  121468. + cb->next = 0;
  121469. +
  121470. +
  121471. + if (pixels < dma_busy_wait_threshold) {
  121472. + bcm_dma_start(fb->dma_chan_base, fb->cb_handle);
  121473. + bcm_dma_wait_idle(fb->dma_chan_base);
  121474. + } else {
  121475. + void __iomem *dma_chan = fb->dma_chan_base;
  121476. + cb->info |= BCM2708_DMA_INT_EN;
  121477. + bcm_dma_start(fb->dma_chan_base, fb->cb_handle);
  121478. + while (bcm_dma_is_busy(dma_chan)) {
  121479. + wait_event_interruptible(
  121480. + fb->dma_waitq,
  121481. + !bcm_dma_is_busy(dma_chan));
  121482. + }
  121483. + fb->stats.dma_irqs++;
  121484. + }
  121485. + fb->stats.dma_copies++;
  121486. +}
  121487. +
  121488. +static void bcm2708_fb_imageblit(struct fb_info *info,
  121489. + const struct fb_image *image)
  121490. +{
  121491. + /* (is called) print_debug("bcm2708_fb_imageblit\n"); */
  121492. + cfb_imageblit(info, image);
  121493. +}
  121494. +
  121495. +static irqreturn_t bcm2708_fb_dma_irq(int irq, void *cxt)
  121496. +{
  121497. + struct bcm2708_fb *fb = cxt;
  121498. +
  121499. + /* FIXME: should read status register to check if this is
  121500. + * actually interrupting us or not, in case this interrupt
  121501. + * ever becomes shared amongst several DMA channels
  121502. + *
  121503. + * readl(dma_chan_base + BCM2708_DMA_CS) & BCM2708_DMA_IRQ;
  121504. + */
  121505. +
  121506. + /* acknowledge the interrupt */
  121507. + writel(BCM2708_DMA_INT, fb->dma_chan_base + BCM2708_DMA_CS);
  121508. +
  121509. + wake_up(&fb->dma_waitq);
  121510. + return IRQ_HANDLED;
  121511. +}
  121512. +
  121513. +static struct fb_ops bcm2708_fb_ops = {
  121514. + .owner = THIS_MODULE,
  121515. + .fb_check_var = bcm2708_fb_check_var,
  121516. + .fb_set_par = bcm2708_fb_set_par,
  121517. + .fb_setcolreg = bcm2708_fb_setcolreg,
  121518. + .fb_blank = bcm2708_fb_blank,
  121519. + .fb_fillrect = bcm2708_fb_fillrect,
  121520. + .fb_copyarea = bcm2708_fb_copyarea,
  121521. + .fb_imageblit = bcm2708_fb_imageblit,
  121522. + .fb_pan_display = bcm2708_fb_pan_display,
  121523. + .fb_ioctl = bcm2708_ioctl,
  121524. +};
  121525. +
  121526. +static int bcm2708_fb_register(struct bcm2708_fb *fb)
  121527. +{
  121528. + int ret;
  121529. + dma_addr_t dma;
  121530. + void *mem;
  121531. +
  121532. + mem =
  121533. + dma_alloc_coherent(NULL, PAGE_ALIGN(sizeof(*fb->info)), &dma,
  121534. + GFP_KERNEL);
  121535. +
  121536. + if (NULL == mem) {
  121537. + pr_err(": unable to allocate fbinfo buffer\n");
  121538. + ret = -ENOMEM;
  121539. + } else {
  121540. + fb->info = (struct fbinfo_s *)mem;
  121541. + fb->dma = dma;
  121542. + }
  121543. + fb->fb.fbops = &bcm2708_fb_ops;
  121544. + fb->fb.flags = FBINFO_FLAG_DEFAULT | FBINFO_HWACCEL_COPYAREA;
  121545. + fb->fb.pseudo_palette = fb->cmap;
  121546. +
  121547. + strncpy(fb->fb.fix.id, bcm2708_name, sizeof(fb->fb.fix.id));
  121548. + fb->fb.fix.type = FB_TYPE_PACKED_PIXELS;
  121549. + fb->fb.fix.type_aux = 0;
  121550. + fb->fb.fix.xpanstep = 1;
  121551. + fb->fb.fix.ypanstep = 1;
  121552. + fb->fb.fix.ywrapstep = 0;
  121553. + fb->fb.fix.accel = FB_ACCEL_NONE;
  121554. +
  121555. + fb->fb.var.xres = fbwidth;
  121556. + fb->fb.var.yres = fbheight;
  121557. + fb->fb.var.xres_virtual = fbwidth;
  121558. + fb->fb.var.yres_virtual = fbheight;
  121559. + fb->fb.var.bits_per_pixel = fbdepth;
  121560. + fb->fb.var.vmode = FB_VMODE_NONINTERLACED;
  121561. + fb->fb.var.activate = FB_ACTIVATE_NOW;
  121562. + fb->fb.var.nonstd = 0;
  121563. + fb->fb.var.height = -1; /* height of picture in mm */
  121564. + fb->fb.var.width = -1; /* width of picture in mm */
  121565. + fb->fb.var.accel_flags = 0;
  121566. +
  121567. + fb->fb.monspecs.hfmin = 0;
  121568. + fb->fb.monspecs.hfmax = 100000;
  121569. + fb->fb.monspecs.vfmin = 0;
  121570. + fb->fb.monspecs.vfmax = 400;
  121571. + fb->fb.monspecs.dclkmin = 1000000;
  121572. + fb->fb.monspecs.dclkmax = 100000000;
  121573. +
  121574. + bcm2708_fb_set_bitfields(&fb->fb.var);
  121575. + init_waitqueue_head(&fb->dma_waitq);
  121576. +
  121577. + /*
  121578. + * Allocate colourmap.
  121579. + */
  121580. +
  121581. + fb_set_var(&fb->fb, &fb->fb.var);
  121582. + bcm2708_fb_set_par(&fb->fb);
  121583. +
  121584. + print_debug("BCM2708FB: registering framebuffer (%dx%d@%d) (%d)\n", fbwidth
  121585. + fbheight, fbdepth, fbswap);
  121586. +
  121587. + ret = register_framebuffer(&fb->fb);
  121588. + print_debug("BCM2708FB: register framebuffer (%d)\n", ret);
  121589. + if (ret == 0)
  121590. + goto out;
  121591. +
  121592. + print_debug("BCM2708FB: cannot register framebuffer (%d)\n", ret);
  121593. +out:
  121594. + return ret;
  121595. +}
  121596. +
  121597. +static int bcm2708_fb_probe(struct platform_device *dev)
  121598. +{
  121599. + struct bcm2708_fb *fb;
  121600. + int ret;
  121601. +
  121602. + fb = kzalloc(sizeof(struct bcm2708_fb), GFP_KERNEL);
  121603. + if (!fb) {
  121604. + dev_err(&dev->dev,
  121605. + "could not allocate new bcm2708_fb struct\n");
  121606. + ret = -ENOMEM;
  121607. + goto free_region;
  121608. + }
  121609. +
  121610. + bcm2708_fb_debugfs_init(fb);
  121611. +
  121612. + fb->cb_base = dma_alloc_writecombine(&dev->dev, SZ_64K,
  121613. + &fb->cb_handle, GFP_KERNEL);
  121614. + if (!fb->cb_base) {
  121615. + dev_err(&dev->dev, "cannot allocate DMA CBs\n");
  121616. + ret = -ENOMEM;
  121617. + goto free_fb;
  121618. + }
  121619. +
  121620. + pr_info("BCM2708FB: allocated DMA memory %08x\n",
  121621. + fb->cb_handle);
  121622. +
  121623. + ret = bcm_dma_chan_alloc(BCM_DMA_FEATURE_BULK,
  121624. + &fb->dma_chan_base, &fb->dma_irq);
  121625. + if (ret < 0) {
  121626. + dev_err(&dev->dev, "couldn't allocate a DMA channel\n");
  121627. + goto free_cb;
  121628. + }
  121629. + fb->dma_chan = ret;
  121630. +
  121631. + ret = request_irq(fb->dma_irq, bcm2708_fb_dma_irq,
  121632. + 0, "bcm2708_fb dma", fb);
  121633. + if (ret) {
  121634. + pr_err("%s: failed to request DMA irq\n", __func__);
  121635. + goto free_dma_chan;
  121636. + }
  121637. +
  121638. +
  121639. + pr_info("BCM2708FB: allocated DMA channel %d @ %p\n",
  121640. + fb->dma_chan, fb->dma_chan_base);
  121641. +
  121642. + fb->dev = dev;
  121643. +
  121644. + ret = bcm2708_fb_register(fb);
  121645. + if (ret == 0) {
  121646. + platform_set_drvdata(dev, fb);
  121647. + goto out;
  121648. + }
  121649. +
  121650. +free_dma_chan:
  121651. + bcm_dma_chan_free(fb->dma_chan);
  121652. +free_cb:
  121653. + dma_free_writecombine(&dev->dev, SZ_64K, fb->cb_base, fb->cb_handle);
  121654. +free_fb:
  121655. + kfree(fb);
  121656. +free_region:
  121657. + dev_err(&dev->dev, "probe failed, err %d\n", ret);
  121658. +out:
  121659. + return ret;
  121660. +}
  121661. +
  121662. +static int bcm2708_fb_remove(struct platform_device *dev)
  121663. +{
  121664. + struct bcm2708_fb *fb = platform_get_drvdata(dev);
  121665. +
  121666. + platform_set_drvdata(dev, NULL);
  121667. +
  121668. + if (fb->fb.screen_base)
  121669. + iounmap(fb->fb.screen_base);
  121670. + unregister_framebuffer(&fb->fb);
  121671. +
  121672. + dma_free_writecombine(&dev->dev, SZ_64K, fb->cb_base, fb->cb_handle);
  121673. + bcm_dma_chan_free(fb->dma_chan);
  121674. +
  121675. + dma_free_coherent(NULL, PAGE_ALIGN(sizeof(*fb->info)), (void *)fb->info,
  121676. + fb->dma);
  121677. + bcm2708_fb_debugfs_deinit(fb);
  121678. +
  121679. + free_irq(fb->dma_irq, fb);
  121680. +
  121681. + kfree(fb);
  121682. +
  121683. + return 0;
  121684. +}
  121685. +
  121686. +static struct platform_driver bcm2708_fb_driver = {
  121687. + .probe = bcm2708_fb_probe,
  121688. + .remove = bcm2708_fb_remove,
  121689. + .driver = {
  121690. + .name = DRIVER_NAME,
  121691. + .owner = THIS_MODULE,
  121692. + },
  121693. +};
  121694. +
  121695. +static int __init bcm2708_fb_init(void)
  121696. +{
  121697. + return platform_driver_register(&bcm2708_fb_driver);
  121698. +}
  121699. +
  121700. +module_init(bcm2708_fb_init);
  121701. +
  121702. +static void __exit bcm2708_fb_exit(void)
  121703. +{
  121704. + platform_driver_unregister(&bcm2708_fb_driver);
  121705. +}
  121706. +
  121707. +module_exit(bcm2708_fb_exit);
  121708. +
  121709. +module_param(fbwidth, int, 0644);
  121710. +module_param(fbheight, int, 0644);
  121711. +module_param(fbdepth, int, 0644);
  121712. +module_param(fbswap, int, 0644);
  121713. +
  121714. +MODULE_DESCRIPTION("BCM2708 framebuffer driver");
  121715. +MODULE_LICENSE("GPL");
  121716. +
  121717. +MODULE_PARM_DESC(fbwidth, "Width of ARM Framebuffer");
  121718. +MODULE_PARM_DESC(fbheight, "Height of ARM Framebuffer");
  121719. +MODULE_PARM_DESC(fbdepth, "Bit depth of ARM Framebuffer");
  121720. +MODULE_PARM_DESC(fbswap, "Swap order of red and blue in 24 and 32 bit modes");
  121721. diff -Nur linux-3.18.8/drivers/video/fbdev/core/cfbimgblt.c linux-rpi/drivers/video/fbdev/core/cfbimgblt.c
  121722. --- linux-3.18.8/drivers/video/fbdev/core/cfbimgblt.c 2015-02-27 02:49:36.000000000 +0100
  121723. +++ linux-rpi/drivers/video/fbdev/core/cfbimgblt.c 2015-03-05 14:40:16.893715804 +0100
  121724. @@ -28,6 +28,11 @@
  121725. *
  121726. * Also need to add code to deal with cards endians that are different than
  121727. * the native cpu endians. I also need to deal with MSB position in the word.
  121728. + * Modified by Harm Hanemaaijer (fgenfb@yahoo.com) 2013:
  121729. + * - Provide optimized versions of fast_imageblit for 16 and 32bpp that are
  121730. + * significantly faster than the previous implementation.
  121731. + * - Simplify the fast/slow_imageblit selection code, avoiding integer
  121732. + * divides.
  121733. */
  121734. #include <linux/module.h>
  121735. #include <linux/string.h>
  121736. @@ -262,6 +267,133 @@
  121737. }
  121738. }
  121739. +/*
  121740. + * Optimized fast_imageblit for bpp == 16. ppw = 2, bit_mask = 3 folded
  121741. + * into the code, main loop unrolled.
  121742. + */
  121743. +
  121744. +static inline void fast_imageblit16(const struct fb_image *image,
  121745. + struct fb_info *p, u8 __iomem * dst1,
  121746. + u32 fgcolor, u32 bgcolor)
  121747. +{
  121748. + u32 fgx = fgcolor, bgx = bgcolor;
  121749. + u32 spitch = (image->width + 7) / 8;
  121750. + u32 end_mask, eorx;
  121751. + const char *s = image->data, *src;
  121752. + u32 __iomem *dst;
  121753. + const u32 *tab = NULL;
  121754. + int i, j, k;
  121755. +
  121756. + tab = fb_be_math(p) ? cfb_tab16_be : cfb_tab16_le;
  121757. +
  121758. + fgx <<= 16;
  121759. + bgx <<= 16;
  121760. + fgx |= fgcolor;
  121761. + bgx |= bgcolor;
  121762. +
  121763. + eorx = fgx ^ bgx;
  121764. + k = image->width / 2;
  121765. +
  121766. + for (i = image->height; i--;) {
  121767. + dst = (u32 __iomem *) dst1;
  121768. + src = s;
  121769. +
  121770. + j = k;
  121771. + while (j >= 4) {
  121772. + u8 bits = *src;
  121773. + end_mask = tab[(bits >> 6) & 3];
  121774. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  121775. + end_mask = tab[(bits >> 4) & 3];
  121776. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  121777. + end_mask = tab[(bits >> 2) & 3];
  121778. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  121779. + end_mask = tab[bits & 3];
  121780. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  121781. + src++;
  121782. + j -= 4;
  121783. + }
  121784. + if (j != 0) {
  121785. + u8 bits = *src;
  121786. + end_mask = tab[(bits >> 6) & 3];
  121787. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  121788. + if (j >= 2) {
  121789. + end_mask = tab[(bits >> 4) & 3];
  121790. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  121791. + if (j == 3) {
  121792. + end_mask = tab[(bits >> 2) & 3];
  121793. + FB_WRITEL((end_mask & eorx) ^ bgx, dst);
  121794. + }
  121795. + }
  121796. + }
  121797. + dst1 += p->fix.line_length;
  121798. + s += spitch;
  121799. + }
  121800. +}
  121801. +
  121802. +/*
  121803. + * Optimized fast_imageblit for bpp == 32. ppw = 1, bit_mask = 1 folded
  121804. + * into the code, main loop unrolled.
  121805. + */
  121806. +
  121807. +static inline void fast_imageblit32(const struct fb_image *image,
  121808. + struct fb_info *p, u8 __iomem * dst1,
  121809. + u32 fgcolor, u32 bgcolor)
  121810. +{
  121811. + u32 fgx = fgcolor, bgx = bgcolor;
  121812. + u32 spitch = (image->width + 7) / 8;
  121813. + u32 end_mask, eorx;
  121814. + const char *s = image->data, *src;
  121815. + u32 __iomem *dst;
  121816. + const u32 *tab = NULL;
  121817. + int i, j, k;
  121818. +
  121819. + tab = cfb_tab32;
  121820. +
  121821. + eorx = fgx ^ bgx;
  121822. + k = image->width;
  121823. +
  121824. + for (i = image->height; i--;) {
  121825. + dst = (u32 __iomem *) dst1;
  121826. + src = s;
  121827. +
  121828. + j = k;
  121829. + while (j >= 8) {
  121830. + u8 bits = *src;
  121831. + end_mask = tab[(bits >> 7) & 1];
  121832. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  121833. + end_mask = tab[(bits >> 6) & 1];
  121834. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  121835. + end_mask = tab[(bits >> 5) & 1];
  121836. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  121837. + end_mask = tab[(bits >> 4) & 1];
  121838. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  121839. + end_mask = tab[(bits >> 3) & 1];
  121840. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  121841. + end_mask = tab[(bits >> 2) & 1];
  121842. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  121843. + end_mask = tab[(bits >> 1) & 1];
  121844. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  121845. + end_mask = tab[bits & 1];
  121846. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  121847. + src++;
  121848. + j -= 8;
  121849. + }
  121850. + if (j != 0) {
  121851. + u32 bits = (u32) * src;
  121852. + while (j > 1) {
  121853. + end_mask = tab[(bits >> 7) & 1];
  121854. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  121855. + bits <<= 1;
  121856. + j--;
  121857. + }
  121858. + end_mask = tab[(bits >> 7) & 1];
  121859. + FB_WRITEL((end_mask & eorx) ^ bgx, dst);
  121860. + }
  121861. + dst1 += p->fix.line_length;
  121862. + s += spitch;
  121863. + }
  121864. +}
  121865. +
  121866. void cfb_imageblit(struct fb_info *p, const struct fb_image *image)
  121867. {
  121868. u32 fgcolor, bgcolor, start_index, bitstart, pitch_index = 0;
  121869. @@ -294,11 +426,21 @@
  121870. bgcolor = image->bg_color;
  121871. }
  121872. - if (32 % bpp == 0 && !start_index && !pitch_index &&
  121873. - ((width & (32/bpp-1)) == 0) &&
  121874. - bpp >= 8 && bpp <= 32)
  121875. - fast_imageblit(image, p, dst1, fgcolor, bgcolor);
  121876. - else
  121877. + if (!start_index && !pitch_index) {
  121878. + if (bpp == 32)
  121879. + fast_imageblit32(image, p, dst1, fgcolor,
  121880. + bgcolor);
  121881. + else if (bpp == 16 && (width & 1) == 0)
  121882. + fast_imageblit16(image, p, dst1, fgcolor,
  121883. + bgcolor);
  121884. + else if (bpp == 8 && (width & 3) == 0)
  121885. + fast_imageblit(image, p, dst1, fgcolor,
  121886. + bgcolor);
  121887. + else
  121888. + slow_imageblit(image, p, dst1, fgcolor,
  121889. + bgcolor,
  121890. + start_index, pitch_index);
  121891. + } else
  121892. slow_imageblit(image, p, dst1, fgcolor, bgcolor,
  121893. start_index, pitch_index);
  121894. } else
  121895. diff -Nur linux-3.18.8/drivers/video/fbdev/core/fbmem.c linux-rpi/drivers/video/fbdev/core/fbmem.c
  121896. --- linux-3.18.8/drivers/video/fbdev/core/fbmem.c 2015-02-27 02:49:36.000000000 +0100
  121897. +++ linux-rpi/drivers/video/fbdev/core/fbmem.c 2015-03-05 14:40:16.893715804 +0100
  121898. @@ -1084,6 +1084,25 @@
  121899. }
  121900. EXPORT_SYMBOL(fb_blank);
  121901. +static int fb_copyarea_user(struct fb_info *info,
  121902. + struct fb_copyarea *copy)
  121903. +{
  121904. + int ret = 0;
  121905. + if (!lock_fb_info(info))
  121906. + return -ENODEV;
  121907. + if (copy->dx + copy->width > info->var.xres ||
  121908. + copy->sx + copy->width > info->var.xres ||
  121909. + copy->dy + copy->height > info->var.yres ||
  121910. + copy->sy + copy->height > info->var.yres) {
  121911. + ret = -EINVAL;
  121912. + goto out;
  121913. + }
  121914. + info->fbops->fb_copyarea(info, copy);
  121915. +out:
  121916. + unlock_fb_info(info);
  121917. + return ret;
  121918. +}
  121919. +
  121920. static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
  121921. unsigned long arg)
  121922. {
  121923. @@ -1094,6 +1113,7 @@
  121924. struct fb_cmap cmap_from;
  121925. struct fb_cmap_user cmap;
  121926. struct fb_event event;
  121927. + struct fb_copyarea copy;
  121928. void __user *argp = (void __user *)arg;
  121929. long ret = 0;
  121930. @@ -1211,6 +1231,15 @@
  121931. unlock_fb_info(info);
  121932. console_unlock();
  121933. break;
  121934. + case FBIOCOPYAREA:
  121935. + if (info->flags & FBINFO_HWACCEL_COPYAREA) {
  121936. + /* only provide this ioctl if it is accelerated */
  121937. + if (copy_from_user(&copy, argp, sizeof(copy)))
  121938. + return -EFAULT;
  121939. + ret = fb_copyarea_user(info, &copy);
  121940. + break;
  121941. + }
  121942. + /* fall through */
  121943. default:
  121944. if (!lock_fb_info(info))
  121945. return -ENODEV;
  121946. @@ -1365,6 +1394,7 @@
  121947. case FBIOPAN_DISPLAY:
  121948. case FBIOGET_CON2FBMAP:
  121949. case FBIOPUT_CON2FBMAP:
  121950. + case FBIOCOPYAREA:
  121951. arg = (unsigned long) compat_ptr(arg);
  121952. case FBIOBLANK:
  121953. ret = do_fb_ioctl(info, cmd, arg);
  121954. diff -Nur linux-3.18.8/drivers/video/fbdev/Kconfig linux-rpi/drivers/video/fbdev/Kconfig
  121955. --- linux-3.18.8/drivers/video/fbdev/Kconfig 2015-02-27 02:49:36.000000000 +0100
  121956. +++ linux-rpi/drivers/video/fbdev/Kconfig 2015-03-05 14:40:16.885715804 +0100
  121957. @@ -224,6 +224,20 @@
  121958. comment "Frame buffer hardware drivers"
  121959. depends on FB
  121960. +config FB_BCM2708
  121961. + tristate "BCM2708 framebuffer support"
  121962. + depends on FB && ARM
  121963. + select FB_CFB_FILLRECT
  121964. + select FB_CFB_COPYAREA
  121965. + select FB_CFB_IMAGEBLIT
  121966. + help
  121967. + This framebuffer device driver is for the BCM2708 framebuffer.
  121968. +
  121969. + If you want to compile this as a module (=code which can be
  121970. + inserted into and removed from the running kernel), say M
  121971. + here and read <file:Documentation/kbuild/modules.txt>. The module
  121972. + will be called bcm2708_fb.
  121973. +
  121974. config FB_GRVGA
  121975. tristate "Aeroflex Gaisler framebuffer support"
  121976. depends on FB && SPARC
  121977. diff -Nur linux-3.18.8/drivers/video/fbdev/Makefile linux-rpi/drivers/video/fbdev/Makefile
  121978. --- linux-3.18.8/drivers/video/fbdev/Makefile 2015-02-27 02:49:36.000000000 +0100
  121979. +++ linux-rpi/drivers/video/fbdev/Makefile 2015-03-05 14:40:16.885715804 +0100
  121980. @@ -12,6 +12,7 @@
  121981. obj-$(CONFIG_FB_WMT_GE_ROPS) += wmt_ge_rops.o
  121982. # Hardware specific drivers go first
  121983. +obj-$(CONFIG_FB_BCM2708) += bcm2708_fb.o
  121984. obj-$(CONFIG_FB_AMIGA) += amifb.o c2p_planar.o
  121985. obj-$(CONFIG_FB_ARC) += arcfb.o
  121986. obj-$(CONFIG_FB_CLPS711X) += clps711x-fb.o
  121987. diff -Nur linux-3.18.8/drivers/video/logo/logo_linux_clut224.ppm linux-rpi/drivers/video/logo/logo_linux_clut224.ppm
  121988. --- linux-3.18.8/drivers/video/logo/logo_linux_clut224.ppm 2015-02-27 02:49:36.000000000 +0100
  121989. +++ linux-rpi/drivers/video/logo/logo_linux_clut224.ppm 2015-03-05 14:40:16.933715804 +0100
  121990. @@ -1,1604 +1,883 @@
  121991. P3
  121992. -# Standard 224-color Linux logo
  121993. -80 80
  121994. +63 80
  121995. 255
  121996. - 0 0 0 0 0 0 0 0 0 0 0 0
  121997. - 0 0 0 0 0 0 0 0 0 0 0 0
  121998. - 0 0 0 0 0 0 0 0 0 0 0 0
  121999. - 0 0 0 0 0 0 0 0 0 0 0 0
  122000. - 0 0 0 0 0 0 0 0 0 0 0 0
  122001. - 0 0 0 0 0 0 0 0 0 0 0 0
  122002. - 0 0 0 0 0 0 0 0 0 0 0 0
  122003. - 0 0 0 0 0 0 0 0 0 0 0 0
  122004. - 0 0 0 0 0 0 0 0 0 0 0 0
  122005. - 6 6 6 6 6 6 10 10 10 10 10 10
  122006. - 10 10 10 6 6 6 6 6 6 6 6 6
  122007. - 0 0 0 0 0 0 0 0 0 0 0 0
  122008. - 0 0 0 0 0 0 0 0 0 0 0 0
  122009. - 0 0 0 0 0 0 0 0 0 0 0 0
  122010. - 0 0 0 0 0 0 0 0 0 0 0 0
  122011. - 0 0 0 0 0 0 0 0 0 0 0 0
  122012. - 0 0 0 0 0 0 0 0 0 0 0 0
  122013. - 0 0 0 0 0 0 0 0 0 0 0 0
  122014. - 0 0 0 0 0 0 0 0 0 0 0 0
  122015. - 0 0 0 0 0 0 0 0 0 0 0 0
  122016. - 0 0 0 0 0 0 0 0 0 0 0 0
  122017. - 0 0 0 0 0 0 0 0 0 0 0 0
  122018. - 0 0 0 0 0 0 0 0 0 0 0 0
  122019. - 0 0 0 0 0 0 0 0 0 0 0 0
  122020. - 0 0 0 0 0 0 0 0 0 0 0 0
  122021. - 0 0 0 0 0 0 0 0 0 0 0 0
  122022. - 0 0 0 0 0 0 0 0 0 0 0 0
  122023. - 0 0 0 0 0 0 0 0 0 0 0 0
  122024. - 0 0 0 6 6 6 10 10 10 14 14 14
  122025. - 22 22 22 26 26 26 30 30 30 34 34 34
  122026. - 30 30 30 30 30 30 26 26 26 18 18 18
  122027. - 14 14 14 10 10 10 6 6 6 0 0 0
  122028. - 0 0 0 0 0 0 0 0 0 0 0 0
  122029. - 0 0 0 0 0 0 0 0 0 0 0 0
  122030. - 0 0 0 0 0 0 0 0 0 0 0 0
  122031. - 0 0 0 0 0 0 0 0 0 0 0 0
  122032. - 0 0 0 0 0 0 0 0 0 0 0 0
  122033. - 0 0 0 0 0 0 0 0 0 0 0 0
  122034. - 0 0 0 0 0 0 0 0 0 0 0 0
  122035. - 0 0 0 0 0 0 0 0 0 0 0 0
  122036. - 0 0 0 0 0 0 0 0 0 0 0 0
  122037. - 0 0 0 0 0 1 0 0 1 0 0 0
  122038. - 0 0 0 0 0 0 0 0 0 0 0 0
  122039. - 0 0 0 0 0 0 0 0 0 0 0 0
  122040. - 0 0 0 0 0 0 0 0 0 0 0 0
  122041. - 0 0 0 0 0 0 0 0 0 0 0 0
  122042. - 0 0 0 0 0 0 0 0 0 0 0 0
  122043. - 0 0 0 0 0 0 0 0 0 0 0 0
  122044. - 6 6 6 14 14 14 26 26 26 42 42 42
  122045. - 54 54 54 66 66 66 78 78 78 78 78 78
  122046. - 78 78 78 74 74 74 66 66 66 54 54 54
  122047. - 42 42 42 26 26 26 18 18 18 10 10 10
  122048. - 6 6 6 0 0 0 0 0 0 0 0 0
  122049. - 0 0 0 0 0 0 0 0 0 0 0 0
  122050. - 0 0 0 0 0 0 0 0 0 0 0 0
  122051. - 0 0 0 0 0 0 0 0 0 0 0 0
  122052. - 0 0 0 0 0 0 0 0 0 0 0 0
  122053. - 0 0 0 0 0 0 0 0 0 0 0 0
  122054. - 0 0 0 0 0 0 0 0 0 0 0 0
  122055. - 0 0 0 0 0 0 0 0 0 0 0 0
  122056. - 0 0 0 0 0 0 0 0 0 0 0 0
  122057. - 0 0 1 0 0 0 0 0 0 0 0 0
  122058. - 0 0 0 0 0 0 0 0 0 0 0 0
  122059. - 0 0 0 0 0 0 0 0 0 0 0 0
  122060. - 0 0 0 0 0 0 0 0 0 0 0 0
  122061. - 0 0 0 0 0 0 0 0 0 0 0 0
  122062. - 0 0 0 0 0 0 0 0 0 0 0 0
  122063. - 0 0 0 0 0 0 0 0 0 10 10 10
  122064. - 22 22 22 42 42 42 66 66 66 86 86 86
  122065. - 66 66 66 38 38 38 38 38 38 22 22 22
  122066. - 26 26 26 34 34 34 54 54 54 66 66 66
  122067. - 86 86 86 70 70 70 46 46 46 26 26 26
  122068. - 14 14 14 6 6 6 0 0 0 0 0 0
  122069. - 0 0 0 0 0 0 0 0 0 0 0 0
  122070. - 0 0 0 0 0 0 0 0 0 0 0 0
  122071. - 0 0 0 0 0 0 0 0 0 0 0 0
  122072. - 0 0 0 0 0 0 0 0 0 0 0 0
  122073. - 0 0 0 0 0 0 0 0 0 0 0 0
  122074. - 0 0 0 0 0 0 0 0 0 0 0 0
  122075. - 0 0 0 0 0 0 0 0 0 0 0 0
  122076. - 0 0 0 0 0 0 0 0 0 0 0 0
  122077. - 0 0 1 0 0 1 0 0 1 0 0 0
  122078. - 0 0 0 0 0 0 0 0 0 0 0 0
  122079. - 0 0 0 0 0 0 0 0 0 0 0 0
  122080. - 0 0 0 0 0 0 0 0 0 0 0 0
  122081. - 0 0 0 0 0 0 0 0 0 0 0 0
  122082. - 0 0 0 0 0 0 0 0 0 0 0 0
  122083. - 0 0 0 0 0 0 10 10 10 26 26 26
  122084. - 50 50 50 82 82 82 58 58 58 6 6 6
  122085. - 2 2 6 2 2 6 2 2 6 2 2 6
  122086. - 2 2 6 2 2 6 2 2 6 2 2 6
  122087. - 6 6 6 54 54 54 86 86 86 66 66 66
  122088. - 38 38 38 18 18 18 6 6 6 0 0 0
  122089. - 0 0 0 0 0 0 0 0 0 0 0 0
  122090. - 0 0 0 0 0 0 0 0 0 0 0 0
  122091. - 0 0 0 0 0 0 0 0 0 0 0 0
  122092. - 0 0 0 0 0 0 0 0 0 0 0 0
  122093. - 0 0 0 0 0 0 0 0 0 0 0 0
  122094. - 0 0 0 0 0 0 0 0 0 0 0 0
  122095. - 0 0 0 0 0 0 0 0 0 0 0 0
  122096. - 0 0 0 0 0 0 0 0 0 0 0 0
  122097. - 0 0 0 0 0 0 0 0 0 0 0 0
  122098. - 0 0 0 0 0 0 0 0 0 0 0 0
  122099. - 0 0 0 0 0 0 0 0 0 0 0 0
  122100. - 0 0 0 0 0 0 0 0 0 0 0 0
  122101. - 0 0 0 0 0 0 0 0 0 0 0 0
  122102. - 0 0 0 0 0 0 0 0 0 0 0 0
  122103. - 0 0 0 6 6 6 22 22 22 50 50 50
  122104. - 78 78 78 34 34 34 2 2 6 2 2 6
  122105. - 2 2 6 2 2 6 2 2 6 2 2 6
  122106. - 2 2 6 2 2 6 2 2 6 2 2 6
  122107. - 2 2 6 2 2 6 6 6 6 70 70 70
  122108. - 78 78 78 46 46 46 22 22 22 6 6 6
  122109. - 0 0 0 0 0 0 0 0 0 0 0 0
  122110. - 0 0 0 0 0 0 0 0 0 0 0 0
  122111. - 0 0 0 0 0 0 0 0 0 0 0 0
  122112. - 0 0 0 0 0 0 0 0 0 0 0 0
  122113. - 0 0 0 0 0 0 0 0 0 0 0 0
  122114. - 0 0 0 0 0 0 0 0 0 0 0 0
  122115. - 0 0 0 0 0 0 0 0 0 0 0 0
  122116. - 0 0 0 0 0 0 0 0 0 0 0 0
  122117. - 0 0 1 0 0 1 0 0 1 0 0 0
  122118. - 0 0 0 0 0 0 0 0 0 0 0 0
  122119. - 0 0 0 0 0 0 0 0 0 0 0 0
  122120. - 0 0 0 0 0 0 0 0 0 0 0 0
  122121. - 0 0 0 0 0 0 0 0 0 0 0 0
  122122. - 0 0 0 0 0 0 0 0 0 0 0 0
  122123. - 6 6 6 18 18 18 42 42 42 82 82 82
  122124. - 26 26 26 2 2 6 2 2 6 2 2 6
  122125. - 2 2 6 2 2 6 2 2 6 2 2 6
  122126. - 2 2 6 2 2 6 2 2 6 14 14 14
  122127. - 46 46 46 34 34 34 6 6 6 2 2 6
  122128. - 42 42 42 78 78 78 42 42 42 18 18 18
  122129. - 6 6 6 0 0 0 0 0 0 0 0 0
  122130. - 0 0 0 0 0 0 0 0 0 0 0 0
  122131. - 0 0 0 0 0 0 0 0 0 0 0 0
  122132. - 0 0 0 0 0 0 0 0 0 0 0 0
  122133. - 0 0 0 0 0 0 0 0 0 0 0 0
  122134. - 0 0 0 0 0 0 0 0 0 0 0 0
  122135. - 0 0 0 0 0 0 0 0 0 0 0 0
  122136. - 0 0 0 0 0 0 0 0 0 0 0 0
  122137. - 0 0 1 0 0 0 0 0 1 0 0 0
  122138. - 0 0 0 0 0 0 0 0 0 0 0 0
  122139. - 0 0 0 0 0 0 0 0 0 0 0 0
  122140. - 0 0 0 0 0 0 0 0 0 0 0 0
  122141. - 0 0 0 0 0 0 0 0 0 0 0 0
  122142. - 0 0 0 0 0 0 0 0 0 0 0 0
  122143. - 10 10 10 30 30 30 66 66 66 58 58 58
  122144. - 2 2 6 2 2 6 2 2 6 2 2 6
  122145. - 2 2 6 2 2 6 2 2 6 2 2 6
  122146. - 2 2 6 2 2 6 2 2 6 26 26 26
  122147. - 86 86 86 101 101 101 46 46 46 10 10 10
  122148. - 2 2 6 58 58 58 70 70 70 34 34 34
  122149. - 10 10 10 0 0 0 0 0 0 0 0 0
  122150. - 0 0 0 0 0 0 0 0 0 0 0 0
  122151. - 0 0 0 0 0 0 0 0 0 0 0 0
  122152. - 0 0 0 0 0 0 0 0 0 0 0 0
  122153. - 0 0 0 0 0 0 0 0 0 0 0 0
  122154. - 0 0 0 0 0 0 0 0 0 0 0 0
  122155. - 0 0 0 0 0 0 0 0 0 0 0 0
  122156. - 0 0 0 0 0 0 0 0 0 0 0 0
  122157. - 0 0 1 0 0 1 0 0 1 0 0 0
  122158. - 0 0 0 0 0 0 0 0 0 0 0 0
  122159. - 0 0 0 0 0 0 0 0 0 0 0 0
  122160. - 0 0 0 0 0 0 0 0 0 0 0 0
  122161. - 0 0 0 0 0 0 0 0 0 0 0 0
  122162. - 0 0 0 0 0 0 0 0 0 0 0 0
  122163. - 14 14 14 42 42 42 86 86 86 10 10 10
  122164. - 2 2 6 2 2 6 2 2 6 2 2 6
  122165. - 2 2 6 2 2 6 2 2 6 2 2 6
  122166. - 2 2 6 2 2 6 2 2 6 30 30 30
  122167. - 94 94 94 94 94 94 58 58 58 26 26 26
  122168. - 2 2 6 6 6 6 78 78 78 54 54 54
  122169. - 22 22 22 6 6 6 0 0 0 0 0 0
  122170. - 0 0 0 0 0 0 0 0 0 0 0 0
  122171. - 0 0 0 0 0 0 0 0 0 0 0 0
  122172. - 0 0 0 0 0 0 0 0 0 0 0 0
  122173. - 0 0 0 0 0 0 0 0 0 0 0 0
  122174. - 0 0 0 0 0 0 0 0 0 0 0 0
  122175. - 0 0 0 0 0 0 0 0 0 0 0 0
  122176. - 0 0 0 0 0 0 0 0 0 0 0 0
  122177. - 0 0 0 0 0 0 0 0 0 0 0 0
  122178. - 0 0 0 0 0 0 0 0 0 0 0 0
  122179. - 0 0 0 0 0 0 0 0 0 0 0 0
  122180. - 0 0 0 0 0 0 0 0 0 0 0 0
  122181. - 0 0 0 0 0 0 0 0 0 0 0 0
  122182. - 0 0 0 0 0 0 0 0 0 6 6 6
  122183. - 22 22 22 62 62 62 62 62 62 2 2 6
  122184. - 2 2 6 2 2 6 2 2 6 2 2 6
  122185. - 2 2 6 2 2 6 2 2 6 2 2 6
  122186. - 2 2 6 2 2 6 2 2 6 26 26 26
  122187. - 54 54 54 38 38 38 18 18 18 10 10 10
  122188. - 2 2 6 2 2 6 34 34 34 82 82 82
  122189. - 38 38 38 14 14 14 0 0 0 0 0 0
  122190. - 0 0 0 0 0 0 0 0 0 0 0 0
  122191. - 0 0 0 0 0 0 0 0 0 0 0 0
  122192. - 0 0 0 0 0 0 0 0 0 0 0 0
  122193. - 0 0 0 0 0 0 0 0 0 0 0 0
  122194. - 0 0 0 0 0 0 0 0 0 0 0 0
  122195. - 0 0 0 0 0 0 0 0 0 0 0 0
  122196. - 0 0 0 0 0 0 0 0 0 0 0 0
  122197. - 0 0 0 0 0 1 0 0 1 0 0 0
  122198. - 0 0 0 0 0 0 0 0 0 0 0 0
  122199. - 0 0 0 0 0 0 0 0 0 0 0 0
  122200. - 0 0 0 0 0 0 0 0 0 0 0 0
  122201. - 0 0 0 0 0 0 0 0 0 0 0 0
  122202. - 0 0 0 0 0 0 0 0 0 6 6 6
  122203. - 30 30 30 78 78 78 30 30 30 2 2 6
  122204. - 2 2 6 2 2 6 2 2 6 2 2 6
  122205. - 2 2 6 2 2 6 2 2 6 2 2 6
  122206. - 2 2 6 2 2 6 2 2 6 10 10 10
  122207. - 10 10 10 2 2 6 2 2 6 2 2 6
  122208. - 2 2 6 2 2 6 2 2 6 78 78 78
  122209. - 50 50 50 18 18 18 6 6 6 0 0 0
  122210. - 0 0 0 0 0 0 0 0 0 0 0 0
  122211. - 0 0 0 0 0 0 0 0 0 0 0 0
  122212. - 0 0 0 0 0 0 0 0 0 0 0 0
  122213. - 0 0 0 0 0 0 0 0 0 0 0 0
  122214. - 0 0 0 0 0 0 0 0 0 0 0 0
  122215. - 0 0 0 0 0 0 0 0 0 0 0 0
  122216. - 0 0 0 0 0 0 0 0 0 0 0 0
  122217. - 0 0 1 0 0 0 0 0 0 0 0 0
  122218. - 0 0 0 0 0 0 0 0 0 0 0 0
  122219. - 0 0 0 0 0 0 0 0 0 0 0 0
  122220. - 0 0 0 0 0 0 0 0 0 0 0 0
  122221. - 0 0 0 0 0 0 0 0 0 0 0 0
  122222. - 0 0 0 0 0 0 0 0 0 10 10 10
  122223. - 38 38 38 86 86 86 14 14 14 2 2 6
  122224. - 2 2 6 2 2 6 2 2 6 2 2 6
  122225. - 2 2 6 2 2 6 2 2 6 2 2 6
  122226. - 2 2 6 2 2 6 2 2 6 2 2 6
  122227. - 2 2 6 2 2 6 2 2 6 2 2 6
  122228. - 2 2 6 2 2 6 2 2 6 54 54 54
  122229. - 66 66 66 26 26 26 6 6 6 0 0 0
  122230. - 0 0 0 0 0 0 0 0 0 0 0 0
  122231. - 0 0 0 0 0 0 0 0 0 0 0 0
  122232. - 0 0 0 0 0 0 0 0 0 0 0 0
  122233. - 0 0 0 0 0 0 0 0 0 0 0 0
  122234. - 0 0 0 0 0 0 0 0 0 0 0 0
  122235. - 0 0 0 0 0 0 0 0 0 0 0 0
  122236. - 0 0 0 0 0 0 0 0 0 0 0 0
  122237. - 0 0 0 0 0 1 0 0 1 0 0 0
  122238. - 0 0 0 0 0 0 0 0 0 0 0 0
  122239. - 0 0 0 0 0 0 0 0 0 0 0 0
  122240. - 0 0 0 0 0 0 0 0 0 0 0 0
  122241. - 0 0 0 0 0 0 0 0 0 0 0 0
  122242. - 0 0 0 0 0 0 0 0 0 14 14 14
  122243. - 42 42 42 82 82 82 2 2 6 2 2 6
  122244. - 2 2 6 6 6 6 10 10 10 2 2 6
  122245. - 2 2 6 2 2 6 2 2 6 2 2 6
  122246. - 2 2 6 2 2 6 2 2 6 6 6 6
  122247. - 14 14 14 10 10 10 2 2 6 2 2 6
  122248. - 2 2 6 2 2 6 2 2 6 18 18 18
  122249. - 82 82 82 34 34 34 10 10 10 0 0 0
  122250. - 0 0 0 0 0 0 0 0 0 0 0 0
  122251. - 0 0 0 0 0 0 0 0 0 0 0 0
  122252. - 0 0 0 0 0 0 0 0 0 0 0 0
  122253. - 0 0 0 0 0 0 0 0 0 0 0 0
  122254. - 0 0 0 0 0 0 0 0 0 0 0 0
  122255. - 0 0 0 0 0 0 0 0 0 0 0 0
  122256. - 0 0 0 0 0 0 0 0 0 0 0 0
  122257. - 0 0 1 0 0 0 0 0 0 0 0 0
  122258. - 0 0 0 0 0 0 0 0 0 0 0 0
  122259. - 0 0 0 0 0 0 0 0 0 0 0 0
  122260. - 0 0 0 0 0 0 0 0 0 0 0 0
  122261. - 0 0 0 0 0 0 0 0 0 0 0 0
  122262. - 0 0 0 0 0 0 0 0 0 14 14 14
  122263. - 46 46 46 86 86 86 2 2 6 2 2 6
  122264. - 6 6 6 6 6 6 22 22 22 34 34 34
  122265. - 6 6 6 2 2 6 2 2 6 2 2 6
  122266. - 2 2 6 2 2 6 18 18 18 34 34 34
  122267. - 10 10 10 50 50 50 22 22 22 2 2 6
  122268. - 2 2 6 2 2 6 2 2 6 10 10 10
  122269. - 86 86 86 42 42 42 14 14 14 0 0 0
  122270. - 0 0 0 0 0 0 0 0 0 0 0 0
  122271. - 0 0 0 0 0 0 0 0 0 0 0 0
  122272. - 0 0 0 0 0 0 0 0 0 0 0 0
  122273. - 0 0 0 0 0 0 0 0 0 0 0 0
  122274. - 0 0 0 0 0 0 0 0 0 0 0 0
  122275. - 0 0 0 0 0 0 0 0 0 0 0 0
  122276. - 0 0 0 0 0 0 0 0 0 0 0 0
  122277. - 0 0 1 0 0 1 0 0 1 0 0 0
  122278. - 0 0 0 0 0 0 0 0 0 0 0 0
  122279. - 0 0 0 0 0 0 0 0 0 0 0 0
  122280. - 0 0 0 0 0 0 0 0 0 0 0 0
  122281. - 0 0 0 0 0 0 0 0 0 0 0 0
  122282. - 0 0 0 0 0 0 0 0 0 14 14 14
  122283. - 46 46 46 86 86 86 2 2 6 2 2 6
  122284. - 38 38 38 116 116 116 94 94 94 22 22 22
  122285. - 22 22 22 2 2 6 2 2 6 2 2 6
  122286. - 14 14 14 86 86 86 138 138 138 162 162 162
  122287. -154 154 154 38 38 38 26 26 26 6 6 6
  122288. - 2 2 6 2 2 6 2 2 6 2 2 6
  122289. - 86 86 86 46 46 46 14 14 14 0 0 0
  122290. - 0 0 0 0 0 0 0 0 0 0 0 0
  122291. - 0 0 0 0 0 0 0 0 0 0 0 0
  122292. - 0 0 0 0 0 0 0 0 0 0 0 0
  122293. - 0 0 0 0 0 0 0 0 0 0 0 0
  122294. - 0 0 0 0 0 0 0 0 0 0 0 0
  122295. - 0 0 0 0 0 0 0 0 0 0 0 0
  122296. - 0 0 0 0 0 0 0 0 0 0 0 0
  122297. - 0 0 0 0 0 0 0 0 0 0 0 0
  122298. - 0 0 0 0 0 0 0 0 0 0 0 0
  122299. - 0 0 0 0 0 0 0 0 0 0 0 0
  122300. - 0 0 0 0 0 0 0 0 0 0 0 0
  122301. - 0 0 0 0 0 0 0 0 0 0 0 0
  122302. - 0 0 0 0 0 0 0 0 0 14 14 14
  122303. - 46 46 46 86 86 86 2 2 6 14 14 14
  122304. -134 134 134 198 198 198 195 195 195 116 116 116
  122305. - 10 10 10 2 2 6 2 2 6 6 6 6
  122306. -101 98 89 187 187 187 210 210 210 218 218 218
  122307. -214 214 214 134 134 134 14 14 14 6 6 6
  122308. - 2 2 6 2 2 6 2 2 6 2 2 6
  122309. - 86 86 86 50 50 50 18 18 18 6 6 6
  122310. - 0 0 0 0 0 0 0 0 0 0 0 0
  122311. - 0 0 0 0 0 0 0 0 0 0 0 0
  122312. - 0 0 0 0 0 0 0 0 0 0 0 0
  122313. - 0 0 0 0 0 0 0 0 0 0 0 0
  122314. - 0 0 0 0 0 0 0 0 0 0 0 0
  122315. - 0 0 0 0 0 0 0 0 0 0 0 0
  122316. - 0 0 0 0 0 0 0 0 1 0 0 0
  122317. - 0 0 1 0 0 1 0 0 1 0 0 0
  122318. - 0 0 0 0 0 0 0 0 0 0 0 0
  122319. - 0 0 0 0 0 0 0 0 0 0 0 0
  122320. - 0 0 0 0 0 0 0 0 0 0 0 0
  122321. - 0 0 0 0 0 0 0 0 0 0 0 0
  122322. - 0 0 0 0 0 0 0 0 0 14 14 14
  122323. - 46 46 46 86 86 86 2 2 6 54 54 54
  122324. -218 218 218 195 195 195 226 226 226 246 246 246
  122325. - 58 58 58 2 2 6 2 2 6 30 30 30
  122326. -210 210 210 253 253 253 174 174 174 123 123 123
  122327. -221 221 221 234 234 234 74 74 74 2 2 6
  122328. - 2 2 6 2 2 6 2 2 6 2 2 6
  122329. - 70 70 70 58 58 58 22 22 22 6 6 6
  122330. - 0 0 0 0 0 0 0 0 0 0 0 0
  122331. - 0 0 0 0 0 0 0 0 0 0 0 0
  122332. - 0 0 0 0 0 0 0 0 0 0 0 0
  122333. - 0 0 0 0 0 0 0 0 0 0 0 0
  122334. - 0 0 0 0 0 0 0 0 0 0 0 0
  122335. - 0 0 0 0 0 0 0 0 0 0 0 0
  122336. - 0 0 0 0 0 0 0 0 0 0 0 0
  122337. - 0 0 0 0 0 0 0 0 0 0 0 0
  122338. - 0 0 0 0 0 0 0 0 0 0 0 0
  122339. - 0 0 0 0 0 0 0 0 0 0 0 0
  122340. - 0 0 0 0 0 0 0 0 0 0 0 0
  122341. - 0 0 0 0 0 0 0 0 0 0 0 0
  122342. - 0 0 0 0 0 0 0 0 0 14 14 14
  122343. - 46 46 46 82 82 82 2 2 6 106 106 106
  122344. -170 170 170 26 26 26 86 86 86 226 226 226
  122345. -123 123 123 10 10 10 14 14 14 46 46 46
  122346. -231 231 231 190 190 190 6 6 6 70 70 70
  122347. - 90 90 90 238 238 238 158 158 158 2 2 6
  122348. - 2 2 6 2 2 6 2 2 6 2 2 6
  122349. - 70 70 70 58 58 58 22 22 22 6 6 6
  122350. - 0 0 0 0 0 0 0 0 0 0 0 0
  122351. - 0 0 0 0 0 0 0 0 0 0 0 0
  122352. - 0 0 0 0 0 0 0 0 0 0 0 0
  122353. - 0 0 0 0 0 0 0 0 0 0 0 0
  122354. - 0 0 0 0 0 0 0 0 0 0 0 0
  122355. - 0 0 0 0 0 0 0 0 0 0 0 0
  122356. - 0 0 0 0 0 0 0 0 1 0 0 0
  122357. - 0 0 1 0 0 1 0 0 1 0 0 0
  122358. - 0 0 0 0 0 0 0 0 0 0 0 0
  122359. - 0 0 0 0 0 0 0 0 0 0 0 0
  122360. - 0 0 0 0 0 0 0 0 0 0 0 0
  122361. - 0 0 0 0 0 0 0 0 0 0 0 0
  122362. - 0 0 0 0 0 0 0 0 0 14 14 14
  122363. - 42 42 42 86 86 86 6 6 6 116 116 116
  122364. -106 106 106 6 6 6 70 70 70 149 149 149
  122365. -128 128 128 18 18 18 38 38 38 54 54 54
  122366. -221 221 221 106 106 106 2 2 6 14 14 14
  122367. - 46 46 46 190 190 190 198 198 198 2 2 6
  122368. - 2 2 6 2 2 6 2 2 6 2 2 6
  122369. - 74 74 74 62 62 62 22 22 22 6 6 6
  122370. - 0 0 0 0 0 0 0 0 0 0 0 0
  122371. - 0 0 0 0 0 0 0 0 0 0 0 0
  122372. - 0 0 0 0 0 0 0 0 0 0 0 0
  122373. - 0 0 0 0 0 0 0 0 0 0 0 0
  122374. - 0 0 0 0 0 0 0 0 0 0 0 0
  122375. - 0 0 0 0 0 0 0 0 0 0 0 0
  122376. - 0 0 0 0 0 0 0 0 1 0 0 0
  122377. - 0 0 1 0 0 0 0 0 1 0 0 0
  122378. - 0 0 0 0 0 0 0 0 0 0 0 0
  122379. - 0 0 0 0 0 0 0 0 0 0 0 0
  122380. - 0 0 0 0 0 0 0 0 0 0 0 0
  122381. - 0 0 0 0 0 0 0 0 0 0 0 0
  122382. - 0 0 0 0 0 0 0 0 0 14 14 14
  122383. - 42 42 42 94 94 94 14 14 14 101 101 101
  122384. -128 128 128 2 2 6 18 18 18 116 116 116
  122385. -118 98 46 121 92 8 121 92 8 98 78 10
  122386. -162 162 162 106 106 106 2 2 6 2 2 6
  122387. - 2 2 6 195 195 195 195 195 195 6 6 6
  122388. - 2 2 6 2 2 6 2 2 6 2 2 6
  122389. - 74 74 74 62 62 62 22 22 22 6 6 6
  122390. - 0 0 0 0 0 0 0 0 0 0 0 0
  122391. - 0 0 0 0 0 0 0 0 0 0 0 0
  122392. - 0 0 0 0 0 0 0 0 0 0 0 0
  122393. - 0 0 0 0 0 0 0 0 0 0 0 0
  122394. - 0 0 0 0 0 0 0 0 0 0 0 0
  122395. - 0 0 0 0 0 0 0 0 0 0 0 0
  122396. - 0 0 0 0 0 0 0 0 1 0 0 1
  122397. - 0 0 1 0 0 0 0 0 1 0 0 0
  122398. - 0 0 0 0 0 0 0 0 0 0 0 0
  122399. - 0 0 0 0 0 0 0 0 0 0 0 0
  122400. - 0 0 0 0 0 0 0 0 0 0 0 0
  122401. - 0 0 0 0 0 0 0 0 0 0 0 0
  122402. - 0 0 0 0 0 0 0 0 0 10 10 10
  122403. - 38 38 38 90 90 90 14 14 14 58 58 58
  122404. -210 210 210 26 26 26 54 38 6 154 114 10
  122405. -226 170 11 236 186 11 225 175 15 184 144 12
  122406. -215 174 15 175 146 61 37 26 9 2 2 6
  122407. - 70 70 70 246 246 246 138 138 138 2 2 6
  122408. - 2 2 6 2 2 6 2 2 6 2 2 6
  122409. - 70 70 70 66 66 66 26 26 26 6 6 6
  122410. - 0 0 0 0 0 0 0 0 0 0 0 0
  122411. - 0 0 0 0 0 0 0 0 0 0 0 0
  122412. - 0 0 0 0 0 0 0 0 0 0 0 0
  122413. - 0 0 0 0 0 0 0 0 0 0 0 0
  122414. - 0 0 0 0 0 0 0 0 0 0 0 0
  122415. - 0 0 0 0 0 0 0 0 0 0 0 0
  122416. - 0 0 0 0 0 0 0 0 0 0 0 0
  122417. - 0 0 0 0 0 0 0 0 0 0 0 0
  122418. - 0 0 0 0 0 0 0 0 0 0 0 0
  122419. - 0 0 0 0 0 0 0 0 0 0 0 0
  122420. - 0 0 0 0 0 0 0 0 0 0 0 0
  122421. - 0 0 0 0 0 0 0 0 0 0 0 0
  122422. - 0 0 0 0 0 0 0 0 0 10 10 10
  122423. - 38 38 38 86 86 86 14 14 14 10 10 10
  122424. -195 195 195 188 164 115 192 133 9 225 175 15
  122425. -239 182 13 234 190 10 232 195 16 232 200 30
  122426. -245 207 45 241 208 19 232 195 16 184 144 12
  122427. -218 194 134 211 206 186 42 42 42 2 2 6
  122428. - 2 2 6 2 2 6 2 2 6 2 2 6
  122429. - 50 50 50 74 74 74 30 30 30 6 6 6
  122430. - 0 0 0 0 0 0 0 0 0 0 0 0
  122431. - 0 0 0 0 0 0 0 0 0 0 0 0
  122432. - 0 0 0 0 0 0 0 0 0 0 0 0
  122433. - 0 0 0 0 0 0 0 0 0 0 0 0
  122434. - 0 0 0 0 0 0 0 0 0 0 0 0
  122435. - 0 0 0 0 0 0 0 0 0 0 0 0
  122436. - 0 0 0 0 0 0 0 0 0 0 0 0
  122437. - 0 0 0 0 0 0 0 0 0 0 0 0
  122438. - 0 0 0 0 0 0 0 0 0 0 0 0
  122439. - 0 0 0 0 0 0 0 0 0 0 0 0
  122440. - 0 0 0 0 0 0 0 0 0 0 0 0
  122441. - 0 0 0 0 0 0 0 0 0 0 0 0
  122442. - 0 0 0 0 0 0 0 0 0 10 10 10
  122443. - 34 34 34 86 86 86 14 14 14 2 2 6
  122444. -121 87 25 192 133 9 219 162 10 239 182 13
  122445. -236 186 11 232 195 16 241 208 19 244 214 54
  122446. -246 218 60 246 218 38 246 215 20 241 208 19
  122447. -241 208 19 226 184 13 121 87 25 2 2 6
  122448. - 2 2 6 2 2 6 2 2 6 2 2 6
  122449. - 50 50 50 82 82 82 34 34 34 10 10 10
  122450. - 0 0 0 0 0 0 0 0 0 0 0 0
  122451. - 0 0 0 0 0 0 0 0 0 0 0 0
  122452. - 0 0 0 0 0 0 0 0 0 0 0 0
  122453. - 0 0 0 0 0 0 0 0 0 0 0 0
  122454. - 0 0 0 0 0 0 0 0 0 0 0 0
  122455. - 0 0 0 0 0 0 0 0 0 0 0 0
  122456. - 0 0 0 0 0 0 0 0 0 0 0 0
  122457. - 0 0 0 0 0 0 0 0 0 0 0 0
  122458. - 0 0 0 0 0 0 0 0 0 0 0 0
  122459. - 0 0 0 0 0 0 0 0 0 0 0 0
  122460. - 0 0 0 0 0 0 0 0 0 0 0 0
  122461. - 0 0 0 0 0 0 0 0 0 0 0 0
  122462. - 0 0 0 0 0 0 0 0 0 10 10 10
  122463. - 34 34 34 82 82 82 30 30 30 61 42 6
  122464. -180 123 7 206 145 10 230 174 11 239 182 13
  122465. -234 190 10 238 202 15 241 208 19 246 218 74
  122466. -246 218 38 246 215 20 246 215 20 246 215 20
  122467. -226 184 13 215 174 15 184 144 12 6 6 6
  122468. - 2 2 6 2 2 6 2 2 6 2 2 6
  122469. - 26 26 26 94 94 94 42 42 42 14 14 14
  122470. - 0 0 0 0 0 0 0 0 0 0 0 0
  122471. - 0 0 0 0 0 0 0 0 0 0 0 0
  122472. - 0 0 0 0 0 0 0 0 0 0 0 0
  122473. - 0 0 0 0 0 0 0 0 0 0 0 0
  122474. - 0 0 0 0 0 0 0 0 0 0 0 0
  122475. - 0 0 0 0 0 0 0 0 0 0 0 0
  122476. - 0 0 0 0 0 0 0 0 0 0 0 0
  122477. - 0 0 0 0 0 0 0 0 0 0 0 0
  122478. - 0 0 0 0 0 0 0 0 0 0 0 0
  122479. - 0 0 0 0 0 0 0 0 0 0 0 0
  122480. - 0 0 0 0 0 0 0 0 0 0 0 0
  122481. - 0 0 0 0 0 0 0 0 0 0 0 0
  122482. - 0 0 0 0 0 0 0 0 0 10 10 10
  122483. - 30 30 30 78 78 78 50 50 50 104 69 6
  122484. -192 133 9 216 158 10 236 178 12 236 186 11
  122485. -232 195 16 241 208 19 244 214 54 245 215 43
  122486. -246 215 20 246 215 20 241 208 19 198 155 10
  122487. -200 144 11 216 158 10 156 118 10 2 2 6
  122488. - 2 2 6 2 2 6 2 2 6 2 2 6
  122489. - 6 6 6 90 90 90 54 54 54 18 18 18
  122490. - 6 6 6 0 0 0 0 0 0 0 0 0
  122491. - 0 0 0 0 0 0 0 0 0 0 0 0
  122492. - 0 0 0 0 0 0 0 0 0 0 0 0
  122493. - 0 0 0 0 0 0 0 0 0 0 0 0
  122494. - 0 0 0 0 0 0 0 0 0 0 0 0
  122495. - 0 0 0 0 0 0 0 0 0 0 0 0
  122496. - 0 0 0 0 0 0 0 0 0 0 0 0
  122497. - 0 0 0 0 0 0 0 0 0 0 0 0
  122498. - 0 0 0 0 0 0 0 0 0 0 0 0
  122499. - 0 0 0 0 0 0 0 0 0 0 0 0
  122500. - 0 0 0 0 0 0 0 0 0 0 0 0
  122501. - 0 0 0 0 0 0 0 0 0 0 0 0
  122502. - 0 0 0 0 0 0 0 0 0 10 10 10
  122503. - 30 30 30 78 78 78 46 46 46 22 22 22
  122504. -137 92 6 210 162 10 239 182 13 238 190 10
  122505. -238 202 15 241 208 19 246 215 20 246 215 20
  122506. -241 208 19 203 166 17 185 133 11 210 150 10
  122507. -216 158 10 210 150 10 102 78 10 2 2 6
  122508. - 6 6 6 54 54 54 14 14 14 2 2 6
  122509. - 2 2 6 62 62 62 74 74 74 30 30 30
  122510. - 10 10 10 0 0 0 0 0 0 0 0 0
  122511. - 0 0 0 0 0 0 0 0 0 0 0 0
  122512. - 0 0 0 0 0 0 0 0 0 0 0 0
  122513. - 0 0 0 0 0 0 0 0 0 0 0 0
  122514. - 0 0 0 0 0 0 0 0 0 0 0 0
  122515. - 0 0 0 0 0 0 0 0 0 0 0 0
  122516. - 0 0 0 0 0 0 0 0 0 0 0 0
  122517. - 0 0 0 0 0 0 0 0 0 0 0 0
  122518. - 0 0 0 0 0 0 0 0 0 0 0 0
  122519. - 0 0 0 0 0 0 0 0 0 0 0 0
  122520. - 0 0 0 0 0 0 0 0 0 0 0 0
  122521. - 0 0 0 0 0 0 0 0 0 0 0 0
  122522. - 0 0 0 0 0 0 0 0 0 10 10 10
  122523. - 34 34 34 78 78 78 50 50 50 6 6 6
  122524. - 94 70 30 139 102 15 190 146 13 226 184 13
  122525. -232 200 30 232 195 16 215 174 15 190 146 13
  122526. -168 122 10 192 133 9 210 150 10 213 154 11
  122527. -202 150 34 182 157 106 101 98 89 2 2 6
  122528. - 2 2 6 78 78 78 116 116 116 58 58 58
  122529. - 2 2 6 22 22 22 90 90 90 46 46 46
  122530. - 18 18 18 6 6 6 0 0 0 0 0 0
  122531. - 0 0 0 0 0 0 0 0 0 0 0 0
  122532. - 0 0 0 0 0 0 0 0 0 0 0 0
  122533. - 0 0 0 0 0 0 0 0 0 0 0 0
  122534. - 0 0 0 0 0 0 0 0 0 0 0 0
  122535. - 0 0 0 0 0 0 0 0 0 0 0 0
  122536. - 0 0 0 0 0 0 0 0 0 0 0 0
  122537. - 0 0 0 0 0 0 0 0 0 0 0 0
  122538. - 0 0 0 0 0 0 0 0 0 0 0 0
  122539. - 0 0 0 0 0 0 0 0 0 0 0 0
  122540. - 0 0 0 0 0 0 0 0 0 0 0 0
  122541. - 0 0 0 0 0 0 0 0 0 0 0 0
  122542. - 0 0 0 0 0 0 0 0 0 10 10 10
  122543. - 38 38 38 86 86 86 50 50 50 6 6 6
  122544. -128 128 128 174 154 114 156 107 11 168 122 10
  122545. -198 155 10 184 144 12 197 138 11 200 144 11
  122546. -206 145 10 206 145 10 197 138 11 188 164 115
  122547. -195 195 195 198 198 198 174 174 174 14 14 14
  122548. - 2 2 6 22 22 22 116 116 116 116 116 116
  122549. - 22 22 22 2 2 6 74 74 74 70 70 70
  122550. - 30 30 30 10 10 10 0 0 0 0 0 0
  122551. - 0 0 0 0 0 0 0 0 0 0 0 0
  122552. - 0 0 0 0 0 0 0 0 0 0 0 0
  122553. - 0 0 0 0 0 0 0 0 0 0 0 0
  122554. - 0 0 0 0 0 0 0 0 0 0 0 0
  122555. - 0 0 0 0 0 0 0 0 0 0 0 0
  122556. - 0 0 0 0 0 0 0 0 0 0 0 0
  122557. - 0 0 0 0 0 0 0 0 0 0 0 0
  122558. - 0 0 0 0 0 0 0 0 0 0 0 0
  122559. - 0 0 0 0 0 0 0 0 0 0 0 0
  122560. - 0 0 0 0 0 0 0 0 0 0 0 0
  122561. - 0 0 0 0 0 0 0 0 0 0 0 0
  122562. - 0 0 0 0 0 0 6 6 6 18 18 18
  122563. - 50 50 50 101 101 101 26 26 26 10 10 10
  122564. -138 138 138 190 190 190 174 154 114 156 107 11
  122565. -197 138 11 200 144 11 197 138 11 192 133 9
  122566. -180 123 7 190 142 34 190 178 144 187 187 187
  122567. -202 202 202 221 221 221 214 214 214 66 66 66
  122568. - 2 2 6 2 2 6 50 50 50 62 62 62
  122569. - 6 6 6 2 2 6 10 10 10 90 90 90
  122570. - 50 50 50 18 18 18 6 6 6 0 0 0
  122571. - 0 0 0 0 0 0 0 0 0 0 0 0
  122572. - 0 0 0 0 0 0 0 0 0 0 0 0
  122573. - 0 0 0 0 0 0 0 0 0 0 0 0
  122574. - 0 0 0 0 0 0 0 0 0 0 0 0
  122575. - 0 0 0 0 0 0 0 0 0 0 0 0
  122576. - 0 0 0 0 0 0 0 0 0 0 0 0
  122577. - 0 0 0 0 0 0 0 0 0 0 0 0
  122578. - 0 0 0 0 0 0 0 0 0 0 0 0
  122579. - 0 0 0 0 0 0 0 0 0 0 0 0
  122580. - 0 0 0 0 0 0 0 0 0 0 0 0
  122581. - 0 0 0 0 0 0 0 0 0 0 0 0
  122582. - 0 0 0 0 0 0 10 10 10 34 34 34
  122583. - 74 74 74 74 74 74 2 2 6 6 6 6
  122584. -144 144 144 198 198 198 190 190 190 178 166 146
  122585. -154 121 60 156 107 11 156 107 11 168 124 44
  122586. -174 154 114 187 187 187 190 190 190 210 210 210
  122587. -246 246 246 253 253 253 253 253 253 182 182 182
  122588. - 6 6 6 2 2 6 2 2 6 2 2 6
  122589. - 2 2 6 2 2 6 2 2 6 62 62 62
  122590. - 74 74 74 34 34 34 14 14 14 0 0 0
  122591. - 0 0 0 0 0 0 0 0 0 0 0 0
  122592. - 0 0 0 0 0 0 0 0 0 0 0 0
  122593. - 0 0 0 0 0 0 0 0 0 0 0 0
  122594. - 0 0 0 0 0 0 0 0 0 0 0 0
  122595. - 0 0 0 0 0 0 0 0 0 0 0 0
  122596. - 0 0 0 0 0 0 0 0 0 0 0 0
  122597. - 0 0 0 0 0 0 0 0 0 0 0 0
  122598. - 0 0 0 0 0 0 0 0 0 0 0 0
  122599. - 0 0 0 0 0 0 0 0 0 0 0 0
  122600. - 0 0 0 0 0 0 0 0 0 0 0 0
  122601. - 0 0 0 0 0 0 0 0 0 0 0 0
  122602. - 0 0 0 10 10 10 22 22 22 54 54 54
  122603. - 94 94 94 18 18 18 2 2 6 46 46 46
  122604. -234 234 234 221 221 221 190 190 190 190 190 190
  122605. -190 190 190 187 187 187 187 187 187 190 190 190
  122606. -190 190 190 195 195 195 214 214 214 242 242 242
  122607. -253 253 253 253 253 253 253 253 253 253 253 253
  122608. - 82 82 82 2 2 6 2 2 6 2 2 6
  122609. - 2 2 6 2 2 6 2 2 6 14 14 14
  122610. - 86 86 86 54 54 54 22 22 22 6 6 6
  122611. - 0 0 0 0 0 0 0 0 0 0 0 0
  122612. - 0 0 0 0 0 0 0 0 0 0 0 0
  122613. - 0 0 0 0 0 0 0 0 0 0 0 0
  122614. - 0 0 0 0 0 0 0 0 0 0 0 0
  122615. - 0 0 0 0 0 0 0 0 0 0 0 0
  122616. - 0 0 0 0 0 0 0 0 0 0 0 0
  122617. - 0 0 0 0 0 0 0 0 0 0 0 0
  122618. - 0 0 0 0 0 0 0 0 0 0 0 0
  122619. - 0 0 0 0 0 0 0 0 0 0 0 0
  122620. - 0 0 0 0 0 0 0 0 0 0 0 0
  122621. - 0 0 0 0 0 0 0 0 0 0 0 0
  122622. - 6 6 6 18 18 18 46 46 46 90 90 90
  122623. - 46 46 46 18 18 18 6 6 6 182 182 182
  122624. -253 253 253 246 246 246 206 206 206 190 190 190
  122625. -190 190 190 190 190 190 190 190 190 190 190 190
  122626. -206 206 206 231 231 231 250 250 250 253 253 253
  122627. -253 253 253 253 253 253 253 253 253 253 253 253
  122628. -202 202 202 14 14 14 2 2 6 2 2 6
  122629. - 2 2 6 2 2 6 2 2 6 2 2 6
  122630. - 42 42 42 86 86 86 42 42 42 18 18 18
  122631. - 6 6 6 0 0 0 0 0 0 0 0 0
  122632. - 0 0 0 0 0 0 0 0 0 0 0 0
  122633. - 0 0 0 0 0 0 0 0 0 0 0 0
  122634. - 0 0 0 0 0 0 0 0 0 0 0 0
  122635. - 0 0 0 0 0 0 0 0 0 0 0 0
  122636. - 0 0 0 0 0 0 0 0 0 0 0 0
  122637. - 0 0 0 0 0 0 0 0 0 0 0 0
  122638. - 0 0 0 0 0 0 0 0 0 0 0 0
  122639. - 0 0 0 0 0 0 0 0 0 0 0 0
  122640. - 0 0 0 0 0 0 0 0 0 0 0 0
  122641. - 0 0 0 0 0 0 0 0 0 6 6 6
  122642. - 14 14 14 38 38 38 74 74 74 66 66 66
  122643. - 2 2 6 6 6 6 90 90 90 250 250 250
  122644. -253 253 253 253 253 253 238 238 238 198 198 198
  122645. -190 190 190 190 190 190 195 195 195 221 221 221
  122646. -246 246 246 253 253 253 253 253 253 253 253 253
  122647. -253 253 253 253 253 253 253 253 253 253 253 253
  122648. -253 253 253 82 82 82 2 2 6 2 2 6
  122649. - 2 2 6 2 2 6 2 2 6 2 2 6
  122650. - 2 2 6 78 78 78 70 70 70 34 34 34
  122651. - 14 14 14 6 6 6 0 0 0 0 0 0
  122652. - 0 0 0 0 0 0 0 0 0 0 0 0
  122653. - 0 0 0 0 0 0 0 0 0 0 0 0
  122654. - 0 0 0 0 0 0 0 0 0 0 0 0
  122655. - 0 0 0 0 0 0 0 0 0 0 0 0
  122656. - 0 0 0 0 0 0 0 0 0 0 0 0
  122657. - 0 0 0 0 0 0 0 0 0 0 0 0
  122658. - 0 0 0 0 0 0 0 0 0 0 0 0
  122659. - 0 0 0 0 0 0 0 0 0 0 0 0
  122660. - 0 0 0 0 0 0 0 0 0 0 0 0
  122661. - 0 0 0 0 0 0 0 0 0 14 14 14
  122662. - 34 34 34 66 66 66 78 78 78 6 6 6
  122663. - 2 2 6 18 18 18 218 218 218 253 253 253
  122664. -253 253 253 253 253 253 253 253 253 246 246 246
  122665. -226 226 226 231 231 231 246 246 246 253 253 253
  122666. -253 253 253 253 253 253 253 253 253 253 253 253
  122667. -253 253 253 253 253 253 253 253 253 253 253 253
  122668. -253 253 253 178 178 178 2 2 6 2 2 6
  122669. - 2 2 6 2 2 6 2 2 6 2 2 6
  122670. - 2 2 6 18 18 18 90 90 90 62 62 62
  122671. - 30 30 30 10 10 10 0 0 0 0 0 0
  122672. - 0 0 0 0 0 0 0 0 0 0 0 0
  122673. - 0 0 0 0 0 0 0 0 0 0 0 0
  122674. - 0 0 0 0 0 0 0 0 0 0 0 0
  122675. - 0 0 0 0 0 0 0 0 0 0 0 0
  122676. - 0 0 0 0 0 0 0 0 0 0 0 0
  122677. - 0 0 0 0 0 0 0 0 0 0 0 0
  122678. - 0 0 0 0 0 0 0 0 0 0 0 0
  122679. - 0 0 0 0 0 0 0 0 0 0 0 0
  122680. - 0 0 0 0 0 0 0 0 0 0 0 0
  122681. - 0 0 0 0 0 0 10 10 10 26 26 26
  122682. - 58 58 58 90 90 90 18 18 18 2 2 6
  122683. - 2 2 6 110 110 110 253 253 253 253 253 253
  122684. -253 253 253 253 253 253 253 253 253 253 253 253
  122685. -250 250 250 253 253 253 253 253 253 253 253 253
  122686. -253 253 253 253 253 253 253 253 253 253 253 253
  122687. -253 253 253 253 253 253 253 253 253 253 253 253
  122688. -253 253 253 231 231 231 18 18 18 2 2 6
  122689. - 2 2 6 2 2 6 2 2 6 2 2 6
  122690. - 2 2 6 2 2 6 18 18 18 94 94 94
  122691. - 54 54 54 26 26 26 10 10 10 0 0 0
  122692. - 0 0 0 0 0 0 0 0 0 0 0 0
  122693. - 0 0 0 0 0 0 0 0 0 0 0 0
  122694. - 0 0 0 0 0 0 0 0 0 0 0 0
  122695. - 0 0 0 0 0 0 0 0 0 0 0 0
  122696. - 0 0 0 0 0 0 0 0 0 0 0 0
  122697. - 0 0 0 0 0 0 0 0 0 0 0 0
  122698. - 0 0 0 0 0 0 0 0 0 0 0 0
  122699. - 0 0 0 0 0 0 0 0 0 0 0 0
  122700. - 0 0 0 0 0 0 0 0 0 0 0 0
  122701. - 0 0 0 6 6 6 22 22 22 50 50 50
  122702. - 90 90 90 26 26 26 2 2 6 2 2 6
  122703. - 14 14 14 195 195 195 250 250 250 253 253 253
  122704. -253 253 253 253 253 253 253 253 253 253 253 253
  122705. -253 253 253 253 253 253 253 253 253 253 253 253
  122706. -253 253 253 253 253 253 253 253 253 253 253 253
  122707. -253 253 253 253 253 253 253 253 253 253 253 253
  122708. -250 250 250 242 242 242 54 54 54 2 2 6
  122709. - 2 2 6 2 2 6 2 2 6 2 2 6
  122710. - 2 2 6 2 2 6 2 2 6 38 38 38
  122711. - 86 86 86 50 50 50 22 22 22 6 6 6
  122712. - 0 0 0 0 0 0 0 0 0 0 0 0
  122713. - 0 0 0 0 0 0 0 0 0 0 0 0
  122714. - 0 0 0 0 0 0 0 0 0 0 0 0
  122715. - 0 0 0 0 0 0 0 0 0 0 0 0
  122716. - 0 0 0 0 0 0 0 0 0 0 0 0
  122717. - 0 0 0 0 0 0 0 0 0 0 0 0
  122718. - 0 0 0 0 0 0 0 0 0 0 0 0
  122719. - 0 0 0 0 0 0 0 0 0 0 0 0
  122720. - 0 0 0 0 0 0 0 0 0 0 0 0
  122721. - 6 6 6 14 14 14 38 38 38 82 82 82
  122722. - 34 34 34 2 2 6 2 2 6 2 2 6
  122723. - 42 42 42 195 195 195 246 246 246 253 253 253
  122724. -253 253 253 253 253 253 253 253 253 250 250 250
  122725. -242 242 242 242 242 242 250 250 250 253 253 253
  122726. -253 253 253 253 253 253 253 253 253 253 253 253
  122727. -253 253 253 250 250 250 246 246 246 238 238 238
  122728. -226 226 226 231 231 231 101 101 101 6 6 6
  122729. - 2 2 6 2 2 6 2 2 6 2 2 6
  122730. - 2 2 6 2 2 6 2 2 6 2 2 6
  122731. - 38 38 38 82 82 82 42 42 42 14 14 14
  122732. - 6 6 6 0 0 0 0 0 0 0 0 0
  122733. - 0 0 0 0 0 0 0 0 0 0 0 0
  122734. - 0 0 0 0 0 0 0 0 0 0 0 0
  122735. - 0 0 0 0 0 0 0 0 0 0 0 0
  122736. - 0 0 0 0 0 0 0 0 0 0 0 0
  122737. - 0 0 0 0 0 0 0 0 0 0 0 0
  122738. - 0 0 0 0 0 0 0 0 0 0 0 0
  122739. - 0 0 0 0 0 0 0 0 0 0 0 0
  122740. - 0 0 0 0 0 0 0 0 0 0 0 0
  122741. - 10 10 10 26 26 26 62 62 62 66 66 66
  122742. - 2 2 6 2 2 6 2 2 6 6 6 6
  122743. - 70 70 70 170 170 170 206 206 206 234 234 234
  122744. -246 246 246 250 250 250 250 250 250 238 238 238
  122745. -226 226 226 231 231 231 238 238 238 250 250 250
  122746. -250 250 250 250 250 250 246 246 246 231 231 231
  122747. -214 214 214 206 206 206 202 202 202 202 202 202
  122748. -198 198 198 202 202 202 182 182 182 18 18 18
  122749. - 2 2 6 2 2 6 2 2 6 2 2 6
  122750. - 2 2 6 2 2 6 2 2 6 2 2 6
  122751. - 2 2 6 62 62 62 66 66 66 30 30 30
  122752. - 10 10 10 0 0 0 0 0 0 0 0 0
  122753. - 0 0 0 0 0 0 0 0 0 0 0 0
  122754. - 0 0 0 0 0 0 0 0 0 0 0 0
  122755. - 0 0 0 0 0 0 0 0 0 0 0 0
  122756. - 0 0 0 0 0 0 0 0 0 0 0 0
  122757. - 0 0 0 0 0 0 0 0 0 0 0 0
  122758. - 0 0 0 0 0 0 0 0 0 0 0 0
  122759. - 0 0 0 0 0 0 0 0 0 0 0 0
  122760. - 0 0 0 0 0 0 0 0 0 0 0 0
  122761. - 14 14 14 42 42 42 82 82 82 18 18 18
  122762. - 2 2 6 2 2 6 2 2 6 10 10 10
  122763. - 94 94 94 182 182 182 218 218 218 242 242 242
  122764. -250 250 250 253 253 253 253 253 253 250 250 250
  122765. -234 234 234 253 253 253 253 253 253 253 253 253
  122766. -253 253 253 253 253 253 253 253 253 246 246 246
  122767. -238 238 238 226 226 226 210 210 210 202 202 202
  122768. -195 195 195 195 195 195 210 210 210 158 158 158
  122769. - 6 6 6 14 14 14 50 50 50 14 14 14
  122770. - 2 2 6 2 2 6 2 2 6 2 2 6
  122771. - 2 2 6 6 6 6 86 86 86 46 46 46
  122772. - 18 18 18 6 6 6 0 0 0 0 0 0
  122773. - 0 0 0 0 0 0 0 0 0 0 0 0
  122774. - 0 0 0 0 0 0 0 0 0 0 0 0
  122775. - 0 0 0 0 0 0 0 0 0 0 0 0
  122776. - 0 0 0 0 0 0 0 0 0 0 0 0
  122777. - 0 0 0 0 0 0 0 0 0 0 0 0
  122778. - 0 0 0 0 0 0 0 0 0 0 0 0
  122779. - 0 0 0 0 0 0 0 0 0 0 0 0
  122780. - 0 0 0 0 0 0 0 0 0 6 6 6
  122781. - 22 22 22 54 54 54 70 70 70 2 2 6
  122782. - 2 2 6 10 10 10 2 2 6 22 22 22
  122783. -166 166 166 231 231 231 250 250 250 253 253 253
  122784. -253 253 253 253 253 253 253 253 253 250 250 250
  122785. -242 242 242 253 253 253 253 253 253 253 253 253
  122786. -253 253 253 253 253 253 253 253 253 253 253 253
  122787. -253 253 253 253 253 253 253 253 253 246 246 246
  122788. -231 231 231 206 206 206 198 198 198 226 226 226
  122789. - 94 94 94 2 2 6 6 6 6 38 38 38
  122790. - 30 30 30 2 2 6 2 2 6 2 2 6
  122791. - 2 2 6 2 2 6 62 62 62 66 66 66
  122792. - 26 26 26 10 10 10 0 0 0 0 0 0
  122793. - 0 0 0 0 0 0 0 0 0 0 0 0
  122794. - 0 0 0 0 0 0 0 0 0 0 0 0
  122795. - 0 0 0 0 0 0 0 0 0 0 0 0
  122796. - 0 0 0 0 0 0 0 0 0 0 0 0
  122797. - 0 0 0 0 0 0 0 0 0 0 0 0
  122798. - 0 0 0 0 0 0 0 0 0 0 0 0
  122799. - 0 0 0 0 0 0 0 0 0 0 0 0
  122800. - 0 0 0 0 0 0 0 0 0 10 10 10
  122801. - 30 30 30 74 74 74 50 50 50 2 2 6
  122802. - 26 26 26 26 26 26 2 2 6 106 106 106
  122803. -238 238 238 253 253 253 253 253 253 253 253 253
  122804. -253 253 253 253 253 253 253 253 253 253 253 253
  122805. -253 253 253 253 253 253 253 253 253 253 253 253
  122806. -253 253 253 253 253 253 253 253 253 253 253 253
  122807. -253 253 253 253 253 253 253 253 253 253 253 253
  122808. -253 253 253 246 246 246 218 218 218 202 202 202
  122809. -210 210 210 14 14 14 2 2 6 2 2 6
  122810. - 30 30 30 22 22 22 2 2 6 2 2 6
  122811. - 2 2 6 2 2 6 18 18 18 86 86 86
  122812. - 42 42 42 14 14 14 0 0 0 0 0 0
  122813. - 0 0 0 0 0 0 0 0 0 0 0 0
  122814. - 0 0 0 0 0 0 0 0 0 0 0 0
  122815. - 0 0 0 0 0 0 0 0 0 0 0 0
  122816. - 0 0 0 0 0 0 0 0 0 0 0 0
  122817. - 0 0 0 0 0 0 0 0 0 0 0 0
  122818. - 0 0 0 0 0 0 0 0 0 0 0 0
  122819. - 0 0 0 0 0 0 0 0 0 0 0 0
  122820. - 0 0 0 0 0 0 0 0 0 14 14 14
  122821. - 42 42 42 90 90 90 22 22 22 2 2 6
  122822. - 42 42 42 2 2 6 18 18 18 218 218 218
  122823. -253 253 253 253 253 253 253 253 253 253 253 253
  122824. -253 253 253 253 253 253 253 253 253 253 253 253
  122825. -253 253 253 253 253 253 253 253 253 253 253 253
  122826. -253 253 253 253 253 253 253 253 253 253 253 253
  122827. -253 253 253 253 253 253 253 253 253 253 253 253
  122828. -253 253 253 253 253 253 250 250 250 221 221 221
  122829. -218 218 218 101 101 101 2 2 6 14 14 14
  122830. - 18 18 18 38 38 38 10 10 10 2 2 6
  122831. - 2 2 6 2 2 6 2 2 6 78 78 78
  122832. - 58 58 58 22 22 22 6 6 6 0 0 0
  122833. - 0 0 0 0 0 0 0 0 0 0 0 0
  122834. - 0 0 0 0 0 0 0 0 0 0 0 0
  122835. - 0 0 0 0 0 0 0 0 0 0 0 0
  122836. - 0 0 0 0 0 0 0 0 0 0 0 0
  122837. - 0 0 0 0 0 0 0 0 0 0 0 0
  122838. - 0 0 0 0 0 0 0 0 0 0 0 0
  122839. - 0 0 0 0 0 0 0 0 0 0 0 0
  122840. - 0 0 0 0 0 0 6 6 6 18 18 18
  122841. - 54 54 54 82 82 82 2 2 6 26 26 26
  122842. - 22 22 22 2 2 6 123 123 123 253 253 253
  122843. -253 253 253 253 253 253 253 253 253 253 253 253
  122844. -253 253 253 253 253 253 253 253 253 253 253 253
  122845. -253 253 253 253 253 253 253 253 253 253 253 253
  122846. -253 253 253 253 253 253 253 253 253 253 253 253
  122847. -253 253 253 253 253 253 253 253 253 253 253 253
  122848. -253 253 253 253 253 253 253 253 253 250 250 250
  122849. -238 238 238 198 198 198 6 6 6 38 38 38
  122850. - 58 58 58 26 26 26 38 38 38 2 2 6
  122851. - 2 2 6 2 2 6 2 2 6 46 46 46
  122852. - 78 78 78 30 30 30 10 10 10 0 0 0
  122853. - 0 0 0 0 0 0 0 0 0 0 0 0
  122854. - 0 0 0 0 0 0 0 0 0 0 0 0
  122855. - 0 0 0 0 0 0 0 0 0 0 0 0
  122856. - 0 0 0 0 0 0 0 0 0 0 0 0
  122857. - 0 0 0 0 0 0 0 0 0 0 0 0
  122858. - 0 0 0 0 0 0 0 0 0 0 0 0
  122859. - 0 0 0 0 0 0 0 0 0 0 0 0
  122860. - 0 0 0 0 0 0 10 10 10 30 30 30
  122861. - 74 74 74 58 58 58 2 2 6 42 42 42
  122862. - 2 2 6 22 22 22 231 231 231 253 253 253
  122863. -253 253 253 253 253 253 253 253 253 253 253 253
  122864. -253 253 253 253 253 253 253 253 253 250 250 250
  122865. -253 253 253 253 253 253 253 253 253 253 253 253
  122866. -253 253 253 253 253 253 253 253 253 253 253 253
  122867. -253 253 253 253 253 253 253 253 253 253 253 253
  122868. -253 253 253 253 253 253 253 253 253 253 253 253
  122869. -253 253 253 246 246 246 46 46 46 38 38 38
  122870. - 42 42 42 14 14 14 38 38 38 14 14 14
  122871. - 2 2 6 2 2 6 2 2 6 6 6 6
  122872. - 86 86 86 46 46 46 14 14 14 0 0 0
  122873. - 0 0 0 0 0 0 0 0 0 0 0 0
  122874. - 0 0 0 0 0 0 0 0 0 0 0 0
  122875. - 0 0 0 0 0 0 0 0 0 0 0 0
  122876. - 0 0 0 0 0 0 0 0 0 0 0 0
  122877. - 0 0 0 0 0 0 0 0 0 0 0 0
  122878. - 0 0 0 0 0 0 0 0 0 0 0 0
  122879. - 0 0 0 0 0 0 0 0 0 0 0 0
  122880. - 0 0 0 6 6 6 14 14 14 42 42 42
  122881. - 90 90 90 18 18 18 18 18 18 26 26 26
  122882. - 2 2 6 116 116 116 253 253 253 253 253 253
  122883. -253 253 253 253 253 253 253 253 253 253 253 253
  122884. -253 253 253 253 253 253 250 250 250 238 238 238
  122885. -253 253 253 253 253 253 253 253 253 253 253 253
  122886. -253 253 253 253 253 253 253 253 253 253 253 253
  122887. -253 253 253 253 253 253 253 253 253 253 253 253
  122888. -253 253 253 253 253 253 253 253 253 253 253 253
  122889. -253 253 253 253 253 253 94 94 94 6 6 6
  122890. - 2 2 6 2 2 6 10 10 10 34 34 34
  122891. - 2 2 6 2 2 6 2 2 6 2 2 6
  122892. - 74 74 74 58 58 58 22 22 22 6 6 6
  122893. - 0 0 0 0 0 0 0 0 0 0 0 0
  122894. - 0 0 0 0 0 0 0 0 0 0 0 0
  122895. - 0 0 0 0 0 0 0 0 0 0 0 0
  122896. - 0 0 0 0 0 0 0 0 0 0 0 0
  122897. - 0 0 0 0 0 0 0 0 0 0 0 0
  122898. - 0 0 0 0 0 0 0 0 0 0 0 0
  122899. - 0 0 0 0 0 0 0 0 0 0 0 0
  122900. - 0 0 0 10 10 10 26 26 26 66 66 66
  122901. - 82 82 82 2 2 6 38 38 38 6 6 6
  122902. - 14 14 14 210 210 210 253 253 253 253 253 253
  122903. -253 253 253 253 253 253 253 253 253 253 253 253
  122904. -253 253 253 253 253 253 246 246 246 242 242 242
  122905. -253 253 253 253 253 253 253 253 253 253 253 253
  122906. -253 253 253 253 253 253 253 253 253 253 253 253
  122907. -253 253 253 253 253 253 253 253 253 253 253 253
  122908. -253 253 253 253 253 253 253 253 253 253 253 253
  122909. -253 253 253 253 253 253 144 144 144 2 2 6
  122910. - 2 2 6 2 2 6 2 2 6 46 46 46
  122911. - 2 2 6 2 2 6 2 2 6 2 2 6
  122912. - 42 42 42 74 74 74 30 30 30 10 10 10
  122913. - 0 0 0 0 0 0 0 0 0 0 0 0
  122914. - 0 0 0 0 0 0 0 0 0 0 0 0
  122915. - 0 0 0 0 0 0 0 0 0 0 0 0
  122916. - 0 0 0 0 0 0 0 0 0 0 0 0
  122917. - 0 0 0 0 0 0 0 0 0 0 0 0
  122918. - 0 0 0 0 0 0 0 0 0 0 0 0
  122919. - 0 0 0 0 0 0 0 0 0 0 0 0
  122920. - 6 6 6 14 14 14 42 42 42 90 90 90
  122921. - 26 26 26 6 6 6 42 42 42 2 2 6
  122922. - 74 74 74 250 250 250 253 253 253 253 253 253
  122923. -253 253 253 253 253 253 253 253 253 253 253 253
  122924. -253 253 253 253 253 253 242 242 242 242 242 242
  122925. -253 253 253 253 253 253 253 253 253 253 253 253
  122926. -253 253 253 253 253 253 253 253 253 253 253 253
  122927. -253 253 253 253 253 253 253 253 253 253 253 253
  122928. -253 253 253 253 253 253 253 253 253 253 253 253
  122929. -253 253 253 253 253 253 182 182 182 2 2 6
  122930. - 2 2 6 2 2 6 2 2 6 46 46 46
  122931. - 2 2 6 2 2 6 2 2 6 2 2 6
  122932. - 10 10 10 86 86 86 38 38 38 10 10 10
  122933. - 0 0 0 0 0 0 0 0 0 0 0 0
  122934. - 0 0 0 0 0 0 0 0 0 0 0 0
  122935. - 0 0 0 0 0 0 0 0 0 0 0 0
  122936. - 0 0 0 0 0 0 0 0 0 0 0 0
  122937. - 0 0 0 0 0 0 0 0 0 0 0 0
  122938. - 0 0 0 0 0 0 0 0 0 0 0 0
  122939. - 0 0 0 0 0 0 0 0 0 0 0 0
  122940. - 10 10 10 26 26 26 66 66 66 82 82 82
  122941. - 2 2 6 22 22 22 18 18 18 2 2 6
  122942. -149 149 149 253 253 253 253 253 253 253 253 253
  122943. -253 253 253 253 253 253 253 253 253 253 253 253
  122944. -253 253 253 253 253 253 234 234 234 242 242 242
  122945. -253 253 253 253 253 253 253 253 253 253 253 253
  122946. -253 253 253 253 253 253 253 253 253 253 253 253
  122947. -253 253 253 253 253 253 253 253 253 253 253 253
  122948. -253 253 253 253 253 253 253 253 253 253 253 253
  122949. -253 253 253 253 253 253 206 206 206 2 2 6
  122950. - 2 2 6 2 2 6 2 2 6 38 38 38
  122951. - 2 2 6 2 2 6 2 2 6 2 2 6
  122952. - 6 6 6 86 86 86 46 46 46 14 14 14
  122953. - 0 0 0 0 0 0 0 0 0 0 0 0
  122954. - 0 0 0 0 0 0 0 0 0 0 0 0
  122955. - 0 0 0 0 0 0 0 0 0 0 0 0
  122956. - 0 0 0 0 0 0 0 0 0 0 0 0
  122957. - 0 0 0 0 0 0 0 0 0 0 0 0
  122958. - 0 0 0 0 0 0 0 0 0 0 0 0
  122959. - 0 0 0 0 0 0 0 0 0 6 6 6
  122960. - 18 18 18 46 46 46 86 86 86 18 18 18
  122961. - 2 2 6 34 34 34 10 10 10 6 6 6
  122962. -210 210 210 253 253 253 253 253 253 253 253 253
  122963. -253 253 253 253 253 253 253 253 253 253 253 253
  122964. -253 253 253 253 253 253 234 234 234 242 242 242
  122965. -253 253 253 253 253 253 253 253 253 253 253 253
  122966. -253 253 253 253 253 253 253 253 253 253 253 253
  122967. -253 253 253 253 253 253 253 253 253 253 253 253
  122968. -253 253 253 253 253 253 253 253 253 253 253 253
  122969. -253 253 253 253 253 253 221 221 221 6 6 6
  122970. - 2 2 6 2 2 6 6 6 6 30 30 30
  122971. - 2 2 6 2 2 6 2 2 6 2 2 6
  122972. - 2 2 6 82 82 82 54 54 54 18 18 18
  122973. - 6 6 6 0 0 0 0 0 0 0 0 0
  122974. - 0 0 0 0 0 0 0 0 0 0 0 0
  122975. - 0 0 0 0 0 0 0 0 0 0 0 0
  122976. - 0 0 0 0 0 0 0 0 0 0 0 0
  122977. - 0 0 0 0 0 0 0 0 0 0 0 0
  122978. - 0 0 0 0 0 0 0 0 0 0 0 0
  122979. - 0 0 0 0 0 0 0 0 0 10 10 10
  122980. - 26 26 26 66 66 66 62 62 62 2 2 6
  122981. - 2 2 6 38 38 38 10 10 10 26 26 26
  122982. -238 238 238 253 253 253 253 253 253 253 253 253
  122983. -253 253 253 253 253 253 253 253 253 253 253 253
  122984. -253 253 253 253 253 253 231 231 231 238 238 238
  122985. -253 253 253 253 253 253 253 253 253 253 253 253
  122986. -253 253 253 253 253 253 253 253 253 253 253 253
  122987. -253 253 253 253 253 253 253 253 253 253 253 253
  122988. -253 253 253 253 253 253 253 253 253 253 253 253
  122989. -253 253 253 253 253 253 231 231 231 6 6 6
  122990. - 2 2 6 2 2 6 10 10 10 30 30 30
  122991. - 2 2 6 2 2 6 2 2 6 2 2 6
  122992. - 2 2 6 66 66 66 58 58 58 22 22 22
  122993. - 6 6 6 0 0 0 0 0 0 0 0 0
  122994. - 0 0 0 0 0 0 0 0 0 0 0 0
  122995. - 0 0 0 0 0 0 0 0 0 0 0 0
  122996. - 0 0 0 0 0 0 0 0 0 0 0 0
  122997. - 0 0 0 0 0 0 0 0 0 0 0 0
  122998. - 0 0 0 0 0 0 0 0 0 0 0 0
  122999. - 0 0 0 0 0 0 0 0 0 10 10 10
  123000. - 38 38 38 78 78 78 6 6 6 2 2 6
  123001. - 2 2 6 46 46 46 14 14 14 42 42 42
  123002. -246 246 246 253 253 253 253 253 253 253 253 253
  123003. -253 253 253 253 253 253 253 253 253 253 253 253
  123004. -253 253 253 253 253 253 231 231 231 242 242 242
  123005. -253 253 253 253 253 253 253 253 253 253 253 253
  123006. -253 253 253 253 253 253 253 253 253 253 253 253
  123007. -253 253 253 253 253 253 253 253 253 253 253 253
  123008. -253 253 253 253 253 253 253 253 253 253 253 253
  123009. -253 253 253 253 253 253 234 234 234 10 10 10
  123010. - 2 2 6 2 2 6 22 22 22 14 14 14
  123011. - 2 2 6 2 2 6 2 2 6 2 2 6
  123012. - 2 2 6 66 66 66 62 62 62 22 22 22
  123013. - 6 6 6 0 0 0 0 0 0 0 0 0
  123014. - 0 0 0 0 0 0 0 0 0 0 0 0
  123015. - 0 0 0 0 0 0 0 0 0 0 0 0
  123016. - 0 0 0 0 0 0 0 0 0 0 0 0
  123017. - 0 0 0 0 0 0 0 0 0 0 0 0
  123018. - 0 0 0 0 0 0 0 0 0 0 0 0
  123019. - 0 0 0 0 0 0 6 6 6 18 18 18
  123020. - 50 50 50 74 74 74 2 2 6 2 2 6
  123021. - 14 14 14 70 70 70 34 34 34 62 62 62
  123022. -250 250 250 253 253 253 253 253 253 253 253 253
  123023. -253 253 253 253 253 253 253 253 253 253 253 253
  123024. -253 253 253 253 253 253 231 231 231 246 246 246
  123025. -253 253 253 253 253 253 253 253 253 253 253 253
  123026. -253 253 253 253 253 253 253 253 253 253 253 253
  123027. -253 253 253 253 253 253 253 253 253 253 253 253
  123028. -253 253 253 253 253 253 253 253 253 253 253 253
  123029. -253 253 253 253 253 253 234 234 234 14 14 14
  123030. - 2 2 6 2 2 6 30 30 30 2 2 6
  123031. - 2 2 6 2 2 6 2 2 6 2 2 6
  123032. - 2 2 6 66 66 66 62 62 62 22 22 22
  123033. - 6 6 6 0 0 0 0 0 0 0 0 0
  123034. - 0 0 0 0 0 0 0 0 0 0 0 0
  123035. - 0 0 0 0 0 0 0 0 0 0 0 0
  123036. - 0 0 0 0 0 0 0 0 0 0 0 0
  123037. - 0 0 0 0 0 0 0 0 0 0 0 0
  123038. - 0 0 0 0 0 0 0 0 0 0 0 0
  123039. - 0 0 0 0 0 0 6 6 6 18 18 18
  123040. - 54 54 54 62 62 62 2 2 6 2 2 6
  123041. - 2 2 6 30 30 30 46 46 46 70 70 70
  123042. -250 250 250 253 253 253 253 253 253 253 253 253
  123043. -253 253 253 253 253 253 253 253 253 253 253 253
  123044. -253 253 253 253 253 253 231 231 231 246 246 246
  123045. -253 253 253 253 253 253 253 253 253 253 253 253
  123046. -253 253 253 253 253 253 253 253 253 253 253 253
  123047. -253 253 253 253 253 253 253 253 253 253 253 253
  123048. -253 253 253 253 253 253 253 253 253 253 253 253
  123049. -253 253 253 253 253 253 226 226 226 10 10 10
  123050. - 2 2 6 6 6 6 30 30 30 2 2 6
  123051. - 2 2 6 2 2 6 2 2 6 2 2 6
  123052. - 2 2 6 66 66 66 58 58 58 22 22 22
  123053. - 6 6 6 0 0 0 0 0 0 0 0 0
  123054. - 0 0 0 0 0 0 0 0 0 0 0 0
  123055. - 0 0 0 0 0 0 0 0 0 0 0 0
  123056. - 0 0 0 0 0 0 0 0 0 0 0 0
  123057. - 0 0 0 0 0 0 0 0 0 0 0 0
  123058. - 0 0 0 0 0 0 0 0 0 0 0 0
  123059. - 0 0 0 0 0 0 6 6 6 22 22 22
  123060. - 58 58 58 62 62 62 2 2 6 2 2 6
  123061. - 2 2 6 2 2 6 30 30 30 78 78 78
  123062. -250 250 250 253 253 253 253 253 253 253 253 253
  123063. -253 253 253 253 253 253 253 253 253 253 253 253
  123064. -253 253 253 253 253 253 231 231 231 246 246 246
  123065. -253 253 253 253 253 253 253 253 253 253 253 253
  123066. -253 253 253 253 253 253 253 253 253 253 253 253
  123067. -253 253 253 253 253 253 253 253 253 253 253 253
  123068. -253 253 253 253 253 253 253 253 253 253 253 253
  123069. -253 253 253 253 253 253 206 206 206 2 2 6
  123070. - 22 22 22 34 34 34 18 14 6 22 22 22
  123071. - 26 26 26 18 18 18 6 6 6 2 2 6
  123072. - 2 2 6 82 82 82 54 54 54 18 18 18
  123073. - 6 6 6 0 0 0 0 0 0 0 0 0
  123074. - 0 0 0 0 0 0 0 0 0 0 0 0
  123075. - 0 0 0 0 0 0 0 0 0 0 0 0
  123076. - 0 0 0 0 0 0 0 0 0 0 0 0
  123077. - 0 0 0 0 0 0 0 0 0 0 0 0
  123078. - 0 0 0 0 0 0 0 0 0 0 0 0
  123079. - 0 0 0 0 0 0 6 6 6 26 26 26
  123080. - 62 62 62 106 106 106 74 54 14 185 133 11
  123081. -210 162 10 121 92 8 6 6 6 62 62 62
  123082. -238 238 238 253 253 253 253 253 253 253 253 253
  123083. -253 253 253 253 253 253 253 253 253 253 253 253
  123084. -253 253 253 253 253 253 231 231 231 246 246 246
  123085. -253 253 253 253 253 253 253 253 253 253 253 253
  123086. -253 253 253 253 253 253 253 253 253 253 253 253
  123087. -253 253 253 253 253 253 253 253 253 253 253 253
  123088. -253 253 253 253 253 253 253 253 253 253 253 253
  123089. -253 253 253 253 253 253 158 158 158 18 18 18
  123090. - 14 14 14 2 2 6 2 2 6 2 2 6
  123091. - 6 6 6 18 18 18 66 66 66 38 38 38
  123092. - 6 6 6 94 94 94 50 50 50 18 18 18
  123093. - 6 6 6 0 0 0 0 0 0 0 0 0
  123094. - 0 0 0 0 0 0 0 0 0 0 0 0
  123095. - 0 0 0 0 0 0 0 0 0 0 0 0
  123096. - 0 0 0 0 0 0 0 0 0 0 0 0
  123097. - 0 0 0 0 0 0 0 0 0 0 0 0
  123098. - 0 0 0 0 0 0 0 0 0 6 6 6
  123099. - 10 10 10 10 10 10 18 18 18 38 38 38
  123100. - 78 78 78 142 134 106 216 158 10 242 186 14
  123101. -246 190 14 246 190 14 156 118 10 10 10 10
  123102. - 90 90 90 238 238 238 253 253 253 253 253 253
  123103. -253 253 253 253 253 253 253 253 253 253 253 253
  123104. -253 253 253 253 253 253 231 231 231 250 250 250
  123105. -253 253 253 253 253 253 253 253 253 253 253 253
  123106. -253 253 253 253 253 253 253 253 253 253 253 253
  123107. -253 253 253 253 253 253 253 253 253 253 253 253
  123108. -253 253 253 253 253 253 253 253 253 246 230 190
  123109. -238 204 91 238 204 91 181 142 44 37 26 9
  123110. - 2 2 6 2 2 6 2 2 6 2 2 6
  123111. - 2 2 6 2 2 6 38 38 38 46 46 46
  123112. - 26 26 26 106 106 106 54 54 54 18 18 18
  123113. - 6 6 6 0 0 0 0 0 0 0 0 0
  123114. - 0 0 0 0 0 0 0 0 0 0 0 0
  123115. - 0 0 0 0 0 0 0 0 0 0 0 0
  123116. - 0 0 0 0 0 0 0 0 0 0 0 0
  123117. - 0 0 0 0 0 0 0 0 0 0 0 0
  123118. - 0 0 0 6 6 6 14 14 14 22 22 22
  123119. - 30 30 30 38 38 38 50 50 50 70 70 70
  123120. -106 106 106 190 142 34 226 170 11 242 186 14
  123121. -246 190 14 246 190 14 246 190 14 154 114 10
  123122. - 6 6 6 74 74 74 226 226 226 253 253 253
  123123. -253 253 253 253 253 253 253 253 253 253 253 253
  123124. -253 253 253 253 253 253 231 231 231 250 250 250
  123125. -253 253 253 253 253 253 253 253 253 253 253 253
  123126. -253 253 253 253 253 253 253 253 253 253 253 253
  123127. -253 253 253 253 253 253 253 253 253 253 253 253
  123128. -253 253 253 253 253 253 253 253 253 228 184 62
  123129. -241 196 14 241 208 19 232 195 16 38 30 10
  123130. - 2 2 6 2 2 6 2 2 6 2 2 6
  123131. - 2 2 6 6 6 6 30 30 30 26 26 26
  123132. -203 166 17 154 142 90 66 66 66 26 26 26
  123133. - 6 6 6 0 0 0 0 0 0 0 0 0
  123134. - 0 0 0 0 0 0 0 0 0 0 0 0
  123135. - 0 0 0 0 0 0 0 0 0 0 0 0
  123136. - 0 0 0 0 0 0 0 0 0 0 0 0
  123137. - 0 0 0 0 0 0 0 0 0 0 0 0
  123138. - 6 6 6 18 18 18 38 38 38 58 58 58
  123139. - 78 78 78 86 86 86 101 101 101 123 123 123
  123140. -175 146 61 210 150 10 234 174 13 246 186 14
  123141. -246 190 14 246 190 14 246 190 14 238 190 10
  123142. -102 78 10 2 2 6 46 46 46 198 198 198
  123143. -253 253 253 253 253 253 253 253 253 253 253 253
  123144. -253 253 253 253 253 253 234 234 234 242 242 242
  123145. -253 253 253 253 253 253 253 253 253 253 253 253
  123146. -253 253 253 253 253 253 253 253 253 253 253 253
  123147. -253 253 253 253 253 253 253 253 253 253 253 253
  123148. -253 253 253 253 253 253 253 253 253 224 178 62
  123149. -242 186 14 241 196 14 210 166 10 22 18 6
  123150. - 2 2 6 2 2 6 2 2 6 2 2 6
  123151. - 2 2 6 2 2 6 6 6 6 121 92 8
  123152. -238 202 15 232 195 16 82 82 82 34 34 34
  123153. - 10 10 10 0 0 0 0 0 0 0 0 0
  123154. - 0 0 0 0 0 0 0 0 0 0 0 0
  123155. - 0 0 0 0 0 0 0 0 0 0 0 0
  123156. - 0 0 0 0 0 0 0 0 0 0 0 0
  123157. - 0 0 0 0 0 0 0 0 0 0 0 0
  123158. - 14 14 14 38 38 38 70 70 70 154 122 46
  123159. -190 142 34 200 144 11 197 138 11 197 138 11
  123160. -213 154 11 226 170 11 242 186 14 246 190 14
  123161. -246 190 14 246 190 14 246 190 14 246 190 14
  123162. -225 175 15 46 32 6 2 2 6 22 22 22
  123163. -158 158 158 250 250 250 253 253 253 253 253 253
  123164. -253 253 253 253 253 253 253 253 253 253 253 253
  123165. -253 253 253 253 253 253 253 253 253 253 253 253
  123166. -253 253 253 253 253 253 253 253 253 253 253 253
  123167. -253 253 253 253 253 253 253 253 253 253 253 253
  123168. -253 253 253 250 250 250 242 242 242 224 178 62
  123169. -239 182 13 236 186 11 213 154 11 46 32 6
  123170. - 2 2 6 2 2 6 2 2 6 2 2 6
  123171. - 2 2 6 2 2 6 61 42 6 225 175 15
  123172. -238 190 10 236 186 11 112 100 78 42 42 42
  123173. - 14 14 14 0 0 0 0 0 0 0 0 0
  123174. - 0 0 0 0 0 0 0 0 0 0 0 0
  123175. - 0 0 0 0 0 0 0 0 0 0 0 0
  123176. - 0 0 0 0 0 0 0 0 0 0 0 0
  123177. - 0 0 0 0 0 0 0 0 0 6 6 6
  123178. - 22 22 22 54 54 54 154 122 46 213 154 11
  123179. -226 170 11 230 174 11 226 170 11 226 170 11
  123180. -236 178 12 242 186 14 246 190 14 246 190 14
  123181. -246 190 14 246 190 14 246 190 14 246 190 14
  123182. -241 196 14 184 144 12 10 10 10 2 2 6
  123183. - 6 6 6 116 116 116 242 242 242 253 253 253
  123184. -253 253 253 253 253 253 253 253 253 253 253 253
  123185. -253 253 253 253 253 253 253 253 253 253 253 253
  123186. -253 253 253 253 253 253 253 253 253 253 253 253
  123187. -253 253 253 253 253 253 253 253 253 253 253 253
  123188. -253 253 253 231 231 231 198 198 198 214 170 54
  123189. -236 178 12 236 178 12 210 150 10 137 92 6
  123190. - 18 14 6 2 2 6 2 2 6 2 2 6
  123191. - 6 6 6 70 47 6 200 144 11 236 178 12
  123192. -239 182 13 239 182 13 124 112 88 58 58 58
  123193. - 22 22 22 6 6 6 0 0 0 0 0 0
  123194. - 0 0 0 0 0 0 0 0 0 0 0 0
  123195. - 0 0 0 0 0 0 0 0 0 0 0 0
  123196. - 0 0 0 0 0 0 0 0 0 0 0 0
  123197. - 0 0 0 0 0 0 0 0 0 10 10 10
  123198. - 30 30 30 70 70 70 180 133 36 226 170 11
  123199. -239 182 13 242 186 14 242 186 14 246 186 14
  123200. -246 190 14 246 190 14 246 190 14 246 190 14
  123201. -246 190 14 246 190 14 246 190 14 246 190 14
  123202. -246 190 14 232 195 16 98 70 6 2 2 6
  123203. - 2 2 6 2 2 6 66 66 66 221 221 221
  123204. -253 253 253 253 253 253 253 253 253 253 253 253
  123205. -253 253 253 253 253 253 253 253 253 253 253 253
  123206. -253 253 253 253 253 253 253 253 253 253 253 253
  123207. -253 253 253 253 253 253 253 253 253 253 253 253
  123208. -253 253 253 206 206 206 198 198 198 214 166 58
  123209. -230 174 11 230 174 11 216 158 10 192 133 9
  123210. -163 110 8 116 81 8 102 78 10 116 81 8
  123211. -167 114 7 197 138 11 226 170 11 239 182 13
  123212. -242 186 14 242 186 14 162 146 94 78 78 78
  123213. - 34 34 34 14 14 14 6 6 6 0 0 0
  123214. - 0 0 0 0 0 0 0 0 0 0 0 0
  123215. - 0 0 0 0 0 0 0 0 0 0 0 0
  123216. - 0 0 0 0 0 0 0 0 0 0 0 0
  123217. - 0 0 0 0 0 0 0 0 0 6 6 6
  123218. - 30 30 30 78 78 78 190 142 34 226 170 11
  123219. -239 182 13 246 190 14 246 190 14 246 190 14
  123220. -246 190 14 246 190 14 246 190 14 246 190 14
  123221. -246 190 14 246 190 14 246 190 14 246 190 14
  123222. -246 190 14 241 196 14 203 166 17 22 18 6
  123223. - 2 2 6 2 2 6 2 2 6 38 38 38
  123224. -218 218 218 253 253 253 253 253 253 253 253 253
  123225. -253 253 253 253 253 253 253 253 253 253 253 253
  123226. -253 253 253 253 253 253 253 253 253 253 253 253
  123227. -253 253 253 253 253 253 253 253 253 253 253 253
  123228. -250 250 250 206 206 206 198 198 198 202 162 69
  123229. -226 170 11 236 178 12 224 166 10 210 150 10
  123230. -200 144 11 197 138 11 192 133 9 197 138 11
  123231. -210 150 10 226 170 11 242 186 14 246 190 14
  123232. -246 190 14 246 186 14 225 175 15 124 112 88
  123233. - 62 62 62 30 30 30 14 14 14 6 6 6
  123234. - 0 0 0 0 0 0 0 0 0 0 0 0
  123235. - 0 0 0 0 0 0 0 0 0 0 0 0
  123236. - 0 0 0 0 0 0 0 0 0 0 0 0
  123237. - 0 0 0 0 0 0 0 0 0 10 10 10
  123238. - 30 30 30 78 78 78 174 135 50 224 166 10
  123239. -239 182 13 246 190 14 246 190 14 246 190 14
  123240. -246 190 14 246 190 14 246 190 14 246 190 14
  123241. -246 190 14 246 190 14 246 190 14 246 190 14
  123242. -246 190 14 246 190 14 241 196 14 139 102 15
  123243. - 2 2 6 2 2 6 2 2 6 2 2 6
  123244. - 78 78 78 250 250 250 253 253 253 253 253 253
  123245. -253 253 253 253 253 253 253 253 253 253 253 253
  123246. -253 253 253 253 253 253 253 253 253 253 253 253
  123247. -253 253 253 253 253 253 253 253 253 253 253 253
  123248. -250 250 250 214 214 214 198 198 198 190 150 46
  123249. -219 162 10 236 178 12 234 174 13 224 166 10
  123250. -216 158 10 213 154 11 213 154 11 216 158 10
  123251. -226 170 11 239 182 13 246 190 14 246 190 14
  123252. -246 190 14 246 190 14 242 186 14 206 162 42
  123253. -101 101 101 58 58 58 30 30 30 14 14 14
  123254. - 6 6 6 0 0 0 0 0 0 0 0 0
  123255. - 0 0 0 0 0 0 0 0 0 0 0 0
  123256. - 0 0 0 0 0 0 0 0 0 0 0 0
  123257. - 0 0 0 0 0 0 0 0 0 10 10 10
  123258. - 30 30 30 74 74 74 174 135 50 216 158 10
  123259. -236 178 12 246 190 14 246 190 14 246 190 14
  123260. -246 190 14 246 190 14 246 190 14 246 190 14
  123261. -246 190 14 246 190 14 246 190 14 246 190 14
  123262. -246 190 14 246 190 14 241 196 14 226 184 13
  123263. - 61 42 6 2 2 6 2 2 6 2 2 6
  123264. - 22 22 22 238 238 238 253 253 253 253 253 253
  123265. -253 253 253 253 253 253 253 253 253 253 253 253
  123266. -253 253 253 253 253 253 253 253 253 253 253 253
  123267. -253 253 253 253 253 253 253 253 253 253 253 253
  123268. -253 253 253 226 226 226 187 187 187 180 133 36
  123269. -216 158 10 236 178 12 239 182 13 236 178 12
  123270. -230 174 11 226 170 11 226 170 11 230 174 11
  123271. -236 178 12 242 186 14 246 190 14 246 190 14
  123272. -246 190 14 246 190 14 246 186 14 239 182 13
  123273. -206 162 42 106 106 106 66 66 66 34 34 34
  123274. - 14 14 14 6 6 6 0 0 0 0 0 0
  123275. - 0 0 0 0 0 0 0 0 0 0 0 0
  123276. - 0 0 0 0 0 0 0 0 0 0 0 0
  123277. - 0 0 0 0 0 0 0 0 0 6 6 6
  123278. - 26 26 26 70 70 70 163 133 67 213 154 11
  123279. -236 178 12 246 190 14 246 190 14 246 190 14
  123280. -246 190 14 246 190 14 246 190 14 246 190 14
  123281. -246 190 14 246 190 14 246 190 14 246 190 14
  123282. -246 190 14 246 190 14 246 190 14 241 196 14
  123283. -190 146 13 18 14 6 2 2 6 2 2 6
  123284. - 46 46 46 246 246 246 253 253 253 253 253 253
  123285. -253 253 253 253 253 253 253 253 253 253 253 253
  123286. -253 253 253 253 253 253 253 253 253 253 253 253
  123287. -253 253 253 253 253 253 253 253 253 253 253 253
  123288. -253 253 253 221 221 221 86 86 86 156 107 11
  123289. -216 158 10 236 178 12 242 186 14 246 186 14
  123290. -242 186 14 239 182 13 239 182 13 242 186 14
  123291. -242 186 14 246 186 14 246 190 14 246 190 14
  123292. -246 190 14 246 190 14 246 190 14 246 190 14
  123293. -242 186 14 225 175 15 142 122 72 66 66 66
  123294. - 30 30 30 10 10 10 0 0 0 0 0 0
  123295. - 0 0 0 0 0 0 0 0 0 0 0 0
  123296. - 0 0 0 0 0 0 0 0 0 0 0 0
  123297. - 0 0 0 0 0 0 0 0 0 6 6 6
  123298. - 26 26 26 70 70 70 163 133 67 210 150 10
  123299. -236 178 12 246 190 14 246 190 14 246 190 14
  123300. -246 190 14 246 190 14 246 190 14 246 190 14
  123301. -246 190 14 246 190 14 246 190 14 246 190 14
  123302. -246 190 14 246 190 14 246 190 14 246 190 14
  123303. -232 195 16 121 92 8 34 34 34 106 106 106
  123304. -221 221 221 253 253 253 253 253 253 253 253 253
  123305. -253 253 253 253 253 253 253 253 253 253 253 253
  123306. -253 253 253 253 253 253 253 253 253 253 253 253
  123307. -253 253 253 253 253 253 253 253 253 253 253 253
  123308. -242 242 242 82 82 82 18 14 6 163 110 8
  123309. -216 158 10 236 178 12 242 186 14 246 190 14
  123310. -246 190 14 246 190 14 246 190 14 246 190 14
  123311. -246 190 14 246 190 14 246 190 14 246 190 14
  123312. -246 190 14 246 190 14 246 190 14 246 190 14
  123313. -246 190 14 246 190 14 242 186 14 163 133 67
  123314. - 46 46 46 18 18 18 6 6 6 0 0 0
  123315. - 0 0 0 0 0 0 0 0 0 0 0 0
  123316. - 0 0 0 0 0 0 0 0 0 0 0 0
  123317. - 0 0 0 0 0 0 0 0 0 10 10 10
  123318. - 30 30 30 78 78 78 163 133 67 210 150 10
  123319. -236 178 12 246 186 14 246 190 14 246 190 14
  123320. -246 190 14 246 190 14 246 190 14 246 190 14
  123321. -246 190 14 246 190 14 246 190 14 246 190 14
  123322. -246 190 14 246 190 14 246 190 14 246 190 14
  123323. -241 196 14 215 174 15 190 178 144 253 253 253
  123324. -253 253 253 253 253 253 253 253 253 253 253 253
  123325. -253 253 253 253 253 253 253 253 253 253 253 253
  123326. -253 253 253 253 253 253 253 253 253 253 253 253
  123327. -253 253 253 253 253 253 253 253 253 218 218 218
  123328. - 58 58 58 2 2 6 22 18 6 167 114 7
  123329. -216 158 10 236 178 12 246 186 14 246 190 14
  123330. -246 190 14 246 190 14 246 190 14 246 190 14
  123331. -246 190 14 246 190 14 246 190 14 246 190 14
  123332. -246 190 14 246 190 14 246 190 14 246 190 14
  123333. -246 190 14 246 186 14 242 186 14 190 150 46
  123334. - 54 54 54 22 22 22 6 6 6 0 0 0
  123335. - 0 0 0 0 0 0 0 0 0 0 0 0
  123336. - 0 0 0 0 0 0 0 0 0 0 0 0
  123337. - 0 0 0 0 0 0 0 0 0 14 14 14
  123338. - 38 38 38 86 86 86 180 133 36 213 154 11
  123339. -236 178 12 246 186 14 246 190 14 246 190 14
  123340. -246 190 14 246 190 14 246 190 14 246 190 14
  123341. -246 190 14 246 190 14 246 190 14 246 190 14
  123342. -246 190 14 246 190 14 246 190 14 246 190 14
  123343. -246 190 14 232 195 16 190 146 13 214 214 214
  123344. -253 253 253 253 253 253 253 253 253 253 253 253
  123345. -253 253 253 253 253 253 253 253 253 253 253 253
  123346. -253 253 253 253 253 253 253 253 253 253 253 253
  123347. -253 253 253 250 250 250 170 170 170 26 26 26
  123348. - 2 2 6 2 2 6 37 26 9 163 110 8
  123349. -219 162 10 239 182 13 246 186 14 246 190 14
  123350. -246 190 14 246 190 14 246 190 14 246 190 14
  123351. -246 190 14 246 190 14 246 190 14 246 190 14
  123352. -246 190 14 246 190 14 246 190 14 246 190 14
  123353. -246 186 14 236 178 12 224 166 10 142 122 72
  123354. - 46 46 46 18 18 18 6 6 6 0 0 0
  123355. - 0 0 0 0 0 0 0 0 0 0 0 0
  123356. - 0 0 0 0 0 0 0 0 0 0 0 0
  123357. - 0 0 0 0 0 0 6 6 6 18 18 18
  123358. - 50 50 50 109 106 95 192 133 9 224 166 10
  123359. -242 186 14 246 190 14 246 190 14 246 190 14
  123360. -246 190 14 246 190 14 246 190 14 246 190 14
  123361. -246 190 14 246 190 14 246 190 14 246 190 14
  123362. -246 190 14 246 190 14 246 190 14 246 190 14
  123363. -242 186 14 226 184 13 210 162 10 142 110 46
  123364. -226 226 226 253 253 253 253 253 253 253 253 253
  123365. -253 253 253 253 253 253 253 253 253 253 253 253
  123366. -253 253 253 253 253 253 253 253 253 253 253 253
  123367. -198 198 198 66 66 66 2 2 6 2 2 6
  123368. - 2 2 6 2 2 6 50 34 6 156 107 11
  123369. -219 162 10 239 182 13 246 186 14 246 190 14
  123370. -246 190 14 246 190 14 246 190 14 246 190 14
  123371. -246 190 14 246 190 14 246 190 14 246 190 14
  123372. -246 190 14 246 190 14 246 190 14 242 186 14
  123373. -234 174 13 213 154 11 154 122 46 66 66 66
  123374. - 30 30 30 10 10 10 0 0 0 0 0 0
  123375. - 0 0 0 0 0 0 0 0 0 0 0 0
  123376. - 0 0 0 0 0 0 0 0 0 0 0 0
  123377. - 0 0 0 0 0 0 6 6 6 22 22 22
  123378. - 58 58 58 154 121 60 206 145 10 234 174 13
  123379. -242 186 14 246 186 14 246 190 14 246 190 14
  123380. -246 190 14 246 190 14 246 190 14 246 190 14
  123381. -246 190 14 246 190 14 246 190 14 246 190 14
  123382. -246 190 14 246 190 14 246 190 14 246 190 14
  123383. -246 186 14 236 178 12 210 162 10 163 110 8
  123384. - 61 42 6 138 138 138 218 218 218 250 250 250
  123385. -253 253 253 253 253 253 253 253 253 250 250 250
  123386. -242 242 242 210 210 210 144 144 144 66 66 66
  123387. - 6 6 6 2 2 6 2 2 6 2 2 6
  123388. - 2 2 6 2 2 6 61 42 6 163 110 8
  123389. -216 158 10 236 178 12 246 190 14 246 190 14
  123390. -246 190 14 246 190 14 246 190 14 246 190 14
  123391. -246 190 14 246 190 14 246 190 14 246 190 14
  123392. -246 190 14 239 182 13 230 174 11 216 158 10
  123393. -190 142 34 124 112 88 70 70 70 38 38 38
  123394. - 18 18 18 6 6 6 0 0 0 0 0 0
  123395. - 0 0 0 0 0 0 0 0 0 0 0 0
  123396. - 0 0 0 0 0 0 0 0 0 0 0 0
  123397. - 0 0 0 0 0 0 6 6 6 22 22 22
  123398. - 62 62 62 168 124 44 206 145 10 224 166 10
  123399. -236 178 12 239 182 13 242 186 14 242 186 14
  123400. -246 186 14 246 190 14 246 190 14 246 190 14
  123401. -246 190 14 246 190 14 246 190 14 246 190 14
  123402. -246 190 14 246 190 14 246 190 14 246 190 14
  123403. -246 190 14 236 178 12 216 158 10 175 118 6
  123404. - 80 54 7 2 2 6 6 6 6 30 30 30
  123405. - 54 54 54 62 62 62 50 50 50 38 38 38
  123406. - 14 14 14 2 2 6 2 2 6 2 2 6
  123407. - 2 2 6 2 2 6 2 2 6 2 2 6
  123408. - 2 2 6 6 6 6 80 54 7 167 114 7
  123409. -213 154 11 236 178 12 246 190 14 246 190 14
  123410. -246 190 14 246 190 14 246 190 14 246 190 14
  123411. -246 190 14 242 186 14 239 182 13 239 182 13
  123412. -230 174 11 210 150 10 174 135 50 124 112 88
  123413. - 82 82 82 54 54 54 34 34 34 18 18 18
  123414. - 6 6 6 0 0 0 0 0 0 0 0 0
  123415. - 0 0 0 0 0 0 0 0 0 0 0 0
  123416. - 0 0 0 0 0 0 0 0 0 0 0 0
  123417. - 0 0 0 0 0 0 6 6 6 18 18 18
  123418. - 50 50 50 158 118 36 192 133 9 200 144 11
  123419. -216 158 10 219 162 10 224 166 10 226 170 11
  123420. -230 174 11 236 178 12 239 182 13 239 182 13
  123421. -242 186 14 246 186 14 246 190 14 246 190 14
  123422. -246 190 14 246 190 14 246 190 14 246 190 14
  123423. -246 186 14 230 174 11 210 150 10 163 110 8
  123424. -104 69 6 10 10 10 2 2 6 2 2 6
  123425. - 2 2 6 2 2 6 2 2 6 2 2 6
  123426. - 2 2 6 2 2 6 2 2 6 2 2 6
  123427. - 2 2 6 2 2 6 2 2 6 2 2 6
  123428. - 2 2 6 6 6 6 91 60 6 167 114 7
  123429. -206 145 10 230 174 11 242 186 14 246 190 14
  123430. -246 190 14 246 190 14 246 186 14 242 186 14
  123431. -239 182 13 230 174 11 224 166 10 213 154 11
  123432. -180 133 36 124 112 88 86 86 86 58 58 58
  123433. - 38 38 38 22 22 22 10 10 10 6 6 6
  123434. - 0 0 0 0 0 0 0 0 0 0 0 0
  123435. - 0 0 0 0 0 0 0 0 0 0 0 0
  123436. - 0 0 0 0 0 0 0 0 0 0 0 0
  123437. - 0 0 0 0 0 0 0 0 0 14 14 14
  123438. - 34 34 34 70 70 70 138 110 50 158 118 36
  123439. -167 114 7 180 123 7 192 133 9 197 138 11
  123440. -200 144 11 206 145 10 213 154 11 219 162 10
  123441. -224 166 10 230 174 11 239 182 13 242 186 14
  123442. -246 186 14 246 186 14 246 186 14 246 186 14
  123443. -239 182 13 216 158 10 185 133 11 152 99 6
  123444. -104 69 6 18 14 6 2 2 6 2 2 6
  123445. - 2 2 6 2 2 6 2 2 6 2 2 6
  123446. - 2 2 6 2 2 6 2 2 6 2 2 6
  123447. - 2 2 6 2 2 6 2 2 6 2 2 6
  123448. - 2 2 6 6 6 6 80 54 7 152 99 6
  123449. -192 133 9 219 162 10 236 178 12 239 182 13
  123450. -246 186 14 242 186 14 239 182 13 236 178 12
  123451. -224 166 10 206 145 10 192 133 9 154 121 60
  123452. - 94 94 94 62 62 62 42 42 42 22 22 22
  123453. - 14 14 14 6 6 6 0 0 0 0 0 0
  123454. - 0 0 0 0 0 0 0 0 0 0 0 0
  123455. - 0 0 0 0 0 0 0 0 0 0 0 0
  123456. - 0 0 0 0 0 0 0 0 0 0 0 0
  123457. - 0 0 0 0 0 0 0 0 0 6 6 6
  123458. - 18 18 18 34 34 34 58 58 58 78 78 78
  123459. -101 98 89 124 112 88 142 110 46 156 107 11
  123460. -163 110 8 167 114 7 175 118 6 180 123 7
  123461. -185 133 11 197 138 11 210 150 10 219 162 10
  123462. -226 170 11 236 178 12 236 178 12 234 174 13
  123463. -219 162 10 197 138 11 163 110 8 130 83 6
  123464. - 91 60 6 10 10 10 2 2 6 2 2 6
  123465. - 18 18 18 38 38 38 38 38 38 38 38 38
  123466. - 38 38 38 38 38 38 38 38 38 38 38 38
  123467. - 38 38 38 38 38 38 26 26 26 2 2 6
  123468. - 2 2 6 6 6 6 70 47 6 137 92 6
  123469. -175 118 6 200 144 11 219 162 10 230 174 11
  123470. -234 174 13 230 174 11 219 162 10 210 150 10
  123471. -192 133 9 163 110 8 124 112 88 82 82 82
  123472. - 50 50 50 30 30 30 14 14 14 6 6 6
  123473. - 0 0 0 0 0 0 0 0 0 0 0 0
  123474. - 0 0 0 0 0 0 0 0 0 0 0 0
  123475. - 0 0 0 0 0 0 0 0 0 0 0 0
  123476. - 0 0 0 0 0 0 0 0 0 0 0 0
  123477. - 0 0 0 0 0 0 0 0 0 0 0 0
  123478. - 6 6 6 14 14 14 22 22 22 34 34 34
  123479. - 42 42 42 58 58 58 74 74 74 86 86 86
  123480. -101 98 89 122 102 70 130 98 46 121 87 25
  123481. -137 92 6 152 99 6 163 110 8 180 123 7
  123482. -185 133 11 197 138 11 206 145 10 200 144 11
  123483. -180 123 7 156 107 11 130 83 6 104 69 6
  123484. - 50 34 6 54 54 54 110 110 110 101 98 89
  123485. - 86 86 86 82 82 82 78 78 78 78 78 78
  123486. - 78 78 78 78 78 78 78 78 78 78 78 78
  123487. - 78 78 78 82 82 82 86 86 86 94 94 94
  123488. -106 106 106 101 101 101 86 66 34 124 80 6
  123489. -156 107 11 180 123 7 192 133 9 200 144 11
  123490. -206 145 10 200 144 11 192 133 9 175 118 6
  123491. -139 102 15 109 106 95 70 70 70 42 42 42
  123492. - 22 22 22 10 10 10 0 0 0 0 0 0
  123493. - 0 0 0 0 0 0 0 0 0 0 0 0
  123494. - 0 0 0 0 0 0 0 0 0 0 0 0
  123495. - 0 0 0 0 0 0 0 0 0 0 0 0
  123496. - 0 0 0 0 0 0 0 0 0 0 0 0
  123497. - 0 0 0 0 0 0 0 0 0 0 0 0
  123498. - 0 0 0 0 0 0 6 6 6 10 10 10
  123499. - 14 14 14 22 22 22 30 30 30 38 38 38
  123500. - 50 50 50 62 62 62 74 74 74 90 90 90
  123501. -101 98 89 112 100 78 121 87 25 124 80 6
  123502. -137 92 6 152 99 6 152 99 6 152 99 6
  123503. -138 86 6 124 80 6 98 70 6 86 66 30
  123504. -101 98 89 82 82 82 58 58 58 46 46 46
  123505. - 38 38 38 34 34 34 34 34 34 34 34 34
  123506. - 34 34 34 34 34 34 34 34 34 34 34 34
  123507. - 34 34 34 34 34 34 38 38 38 42 42 42
  123508. - 54 54 54 82 82 82 94 86 76 91 60 6
  123509. -134 86 6 156 107 11 167 114 7 175 118 6
  123510. -175 118 6 167 114 7 152 99 6 121 87 25
  123511. -101 98 89 62 62 62 34 34 34 18 18 18
  123512. - 6 6 6 0 0 0 0 0 0 0 0 0
  123513. - 0 0 0 0 0 0 0 0 0 0 0 0
  123514. - 0 0 0 0 0 0 0 0 0 0 0 0
  123515. - 0 0 0 0 0 0 0 0 0 0 0 0
  123516. - 0 0 0 0 0 0 0 0 0 0 0 0
  123517. - 0 0 0 0 0 0 0 0 0 0 0 0
  123518. - 0 0 0 0 0 0 0 0 0 0 0 0
  123519. - 0 0 0 6 6 6 6 6 6 10 10 10
  123520. - 18 18 18 22 22 22 30 30 30 42 42 42
  123521. - 50 50 50 66 66 66 86 86 86 101 98 89
  123522. -106 86 58 98 70 6 104 69 6 104 69 6
  123523. -104 69 6 91 60 6 82 62 34 90 90 90
  123524. - 62 62 62 38 38 38 22 22 22 14 14 14
  123525. - 10 10 10 10 10 10 10 10 10 10 10 10
  123526. - 10 10 10 10 10 10 6 6 6 10 10 10
  123527. - 10 10 10 10 10 10 10 10 10 14 14 14
  123528. - 22 22 22 42 42 42 70 70 70 89 81 66
  123529. - 80 54 7 104 69 6 124 80 6 137 92 6
  123530. -134 86 6 116 81 8 100 82 52 86 86 86
  123531. - 58 58 58 30 30 30 14 14 14 6 6 6
  123532. - 0 0 0 0 0 0 0 0 0 0 0 0
  123533. - 0 0 0 0 0 0 0 0 0 0 0 0
  123534. - 0 0 0 0 0 0 0 0 0 0 0 0
  123535. - 0 0 0 0 0 0 0 0 0 0 0 0
  123536. - 0 0 0 0 0 0 0 0 0 0 0 0
  123537. - 0 0 0 0 0 0 0 0 0 0 0 0
  123538. - 0 0 0 0 0 0 0 0 0 0 0 0
  123539. - 0 0 0 0 0 0 0 0 0 0 0 0
  123540. - 0 0 0 6 6 6 10 10 10 14 14 14
  123541. - 18 18 18 26 26 26 38 38 38 54 54 54
  123542. - 70 70 70 86 86 86 94 86 76 89 81 66
  123543. - 89 81 66 86 86 86 74 74 74 50 50 50
  123544. - 30 30 30 14 14 14 6 6 6 0 0 0
  123545. - 0 0 0 0 0 0 0 0 0 0 0 0
  123546. - 0 0 0 0 0 0 0 0 0 0 0 0
  123547. - 0 0 0 0 0 0 0 0 0 0 0 0
  123548. - 6 6 6 18 18 18 34 34 34 58 58 58
  123549. - 82 82 82 89 81 66 89 81 66 89 81 66
  123550. - 94 86 66 94 86 76 74 74 74 50 50 50
  123551. - 26 26 26 14 14 14 6 6 6 0 0 0
  123552. - 0 0 0 0 0 0 0 0 0 0 0 0
  123553. - 0 0 0 0 0 0 0 0 0 0 0 0
  123554. - 0 0 0 0 0 0 0 0 0 0 0 0
  123555. - 0 0 0 0 0 0 0 0 0 0 0 0
  123556. - 0 0 0 0 0 0 0 0 0 0 0 0
  123557. - 0 0 0 0 0 0 0 0 0 0 0 0
  123558. - 0 0 0 0 0 0 0 0 0 0 0 0
  123559. - 0 0 0 0 0 0 0 0 0 0 0 0
  123560. - 0 0 0 0 0 0 0 0 0 0 0 0
  123561. - 6 6 6 6 6 6 14 14 14 18 18 18
  123562. - 30 30 30 38 38 38 46 46 46 54 54 54
  123563. - 50 50 50 42 42 42 30 30 30 18 18 18
  123564. - 10 10 10 0 0 0 0 0 0 0 0 0
  123565. - 0 0 0 0 0 0 0 0 0 0 0 0
  123566. - 0 0 0 0 0 0 0 0 0 0 0 0
  123567. - 0 0 0 0 0 0 0 0 0 0 0 0
  123568. - 0 0 0 6 6 6 14 14 14 26 26 26
  123569. - 38 38 38 50 50 50 58 58 58 58 58 58
  123570. - 54 54 54 42 42 42 30 30 30 18 18 18
  123571. - 10 10 10 0 0 0 0 0 0 0 0 0
  123572. - 0 0 0 0 0 0 0 0 0 0 0 0
  123573. - 0 0 0 0 0 0 0 0 0 0 0 0
  123574. - 0 0 0 0 0 0 0 0 0 0 0 0
  123575. - 0 0 0 0 0 0 0 0 0 0 0 0
  123576. - 0 0 0 0 0 0 0 0 0 0 0 0
  123577. - 0 0 0 0 0 0 0 0 0 0 0 0
  123578. - 0 0 0 0 0 0 0 0 0 0 0 0
  123579. - 0 0 0 0 0 0 0 0 0 0 0 0
  123580. - 0 0 0 0 0 0 0 0 0 0 0 0
  123581. - 0 0 0 0 0 0 0 0 0 6 6 6
  123582. - 6 6 6 10 10 10 14 14 14 18 18 18
  123583. - 18 18 18 14 14 14 10 10 10 6 6 6
  123584. - 0 0 0 0 0 0 0 0 0 0 0 0
  123585. - 0 0 0 0 0 0 0 0 0 0 0 0
  123586. - 0 0 0 0 0 0 0 0 0 0 0 0
  123587. - 0 0 0 0 0 0 0 0 0 0 0 0
  123588. - 0 0 0 0 0 0 0 0 0 6 6 6
  123589. - 14 14 14 18 18 18 22 22 22 22 22 22
  123590. - 18 18 18 14 14 14 10 10 10 6 6 6
  123591. - 0 0 0 0 0 0 0 0 0 0 0 0
  123592. - 0 0 0 0 0 0 0 0 0 0 0 0
  123593. - 0 0 0 0 0 0 0 0 0 0 0 0
  123594. - 0 0 0 0 0 0 0 0 0 0 0 0
  123595. - 0 0 0 0 0 0 0 0 0 0 0 0
  123596. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123597. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123598. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123599. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123600. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123601. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123602. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123603. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123604. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123605. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123606. +0 0 0 0 0 0 0 0 0
  123607. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123608. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123609. +0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 1 0
  123610. +0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123611. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123612. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123613. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123614. +0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0
  123615. +0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123616. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123617. +0 0 0 0 0 0 0 0 0
  123618. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123619. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0
  123620. +10 15 3 2 3 1 12 18 4 42 61 14 19 27 6 11 16 4
  123621. +38 55 13 10 15 3 3 4 1 10 15 3 0 0 0 0 0 0
  123622. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123623. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123624. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 3 1
  123625. +12 18 4 1 1 0 23 34 8 31 45 11 10 15 3 32 47 11
  123626. +34 49 12 3 4 1 3 4 1 3 4 1 0 0 0 0 0 0
  123627. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123628. +0 0 0 0 0 0 0 0 0
  123629. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123630. +0 0 0 0 0 0 10 15 3 29 42 10 26 37 9 12 18 4
  123631. +55 80 19 81 118 28 55 80 19 92 132 31 106 153 36 69 100 23
  123632. +100 144 34 80 116 27 42 61 14 81 118 28 23 34 8 27 40 9
  123633. +15 21 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123634. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123635. +0 0 0 0 0 0 1 1 0 29 42 10 15 21 5 50 72 17
  123636. +74 107 25 45 64 15 102 148 35 80 116 27 84 121 28 111 160 38
  123637. +69 100 23 65 94 22 81 118 28 29 42 10 17 25 6 29 42 10
  123638. +23 34 8 2 3 1 0 0 0 0 0 0 0 0 0 0 0 0
  123639. +0 0 0 0 0 0 0 0 0
  123640. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 4 1
  123641. +15 21 5 15 21 5 34 49 12 101 146 34 111 161 38 97 141 33
  123642. +97 141 33 119 172 41 117 170 40 116 167 40 118 170 40 118 171 40
  123643. +117 169 40 118 170 40 111 160 38 118 170 40 96 138 32 89 128 30
  123644. +81 118 28 11 16 4 10 15 3 1 1 0 0 0 0 0 0 0
  123645. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123646. +3 4 1 3 4 1 34 49 12 101 146 34 79 115 27 111 160 38
  123647. +114 165 39 113 163 39 118 170 40 117 169 40 118 171 40 117 169 40
  123648. +116 167 40 119 172 41 113 163 39 92 132 31 105 151 36 113 163 39
  123649. +75 109 26 19 27 6 16 23 5 11 16 4 0 1 0 0 0 0
  123650. +0 0 0 0 0 0 0 0 0
  123651. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 15 3
  123652. +80 116 27 106 153 36 105 151 36 114 165 39 118 170 40 118 171 40
  123653. +118 171 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  123654. +117 169 40 117 169 40 117 170 40 117 169 40 118 170 40 118 170 40
  123655. +117 170 40 75 109 26 75 109 26 34 49 12 0 0 0 0 0 0
  123656. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 4 1
  123657. +64 92 22 65 94 22 100 144 34 118 171 40 118 170 40 117 169 40
  123658. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  123659. +117 169 40 117 169 40 117 169 40 118 171 41 118 170 40 117 169 40
  123660. +109 158 37 105 151 36 104 150 35 47 69 16 0 0 0 0 0 0
  123661. +0 0 0 0 0 0 0 0 0
  123662. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123663. +42 61 14 115 167 39 118 170 40 117 169 40 117 169 40 117 169 40
  123664. +117 170 40 117 170 40 117 169 40 117 169 40 117 169 40 117 169 40
  123665. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  123666. +117 169 40 117 169 40 118 170 40 96 138 32 17 25 6 0 0 0
  123667. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 47 69 16
  123668. +114 165 39 117 168 40 117 170 40 117 169 40 117 169 40 117 169 40
  123669. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  123670. +117 169 40 117 169 40 118 170 40 117 169 40 117 169 40 117 169 40
  123671. +117 170 40 119 172 41 96 138 32 12 18 4 0 0 0 0 0 0
  123672. +0 0 0 0 0 0 0 0 0
  123673. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 15 3
  123674. +32 47 11 105 151 36 118 170 40 117 169 40 117 169 40 116 168 40
  123675. +109 157 37 111 160 38 117 169 40 118 171 40 117 169 40 117 169 40
  123676. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  123677. +117 169 40 117 169 40 117 169 40 118 171 40 69 100 23 2 3 1
  123678. +0 0 0 0 0 0 0 0 0 0 0 0 19 27 6 101 146 34
  123679. +118 171 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  123680. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 170 40
  123681. +118 171 40 115 166 39 107 154 36 111 161 38 117 169 40 117 169 40
  123682. +117 169 40 118 171 40 75 109 26 19 27 6 2 3 1 0 0 0
  123683. +0 0 0 0 0 0 0 0 0
  123684. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 16 23 5
  123685. +89 128 30 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  123686. +111 160 38 92 132 31 79 115 27 96 138 32 115 166 39 119 171 41
  123687. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  123688. +117 169 40 117 169 40 117 169 40 118 170 40 109 157 37 26 37 9
  123689. +0 0 0 0 0 0 0 0 0 0 0 0 64 92 22 118 171 40
  123690. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  123691. +117 169 40 117 169 40 117 169 40 118 170 40 118 171 40 109 157 37
  123692. +89 128 30 81 118 28 100 144 34 115 166 39 117 169 40 117 169 40
  123693. +117 169 40 117 170 40 113 163 39 60 86 20 1 1 0 0 0 0
  123694. +0 0 0 0 0 0 0 0 0
  123695. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123696. +27 40 9 96 138 32 118 170 40 117 169 40 117 169 40 117 169 40
  123697. +117 170 40 117 169 40 101 146 34 67 96 23 55 80 19 84 121 28
  123698. +113 163 39 119 171 41 117 169 40 117 169 40 117 169 40 117 169 40
  123699. +117 169 40 117 169 40 117 169 40 117 169 40 119 171 41 65 94 22
  123700. +0 0 0 0 0 0 0 0 0 15 21 5 101 146 34 118 171 40
  123701. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  123702. +117 169 40 118 170 40 118 171 40 104 150 35 69 100 23 53 76 18
  123703. +81 118 28 111 160 38 118 170 40 117 169 40 117 169 40 117 169 40
  123704. +117 169 40 114 165 39 69 100 23 10 15 3 0 0 0 0 0 0
  123705. +0 0 0 0 0 0 0 0 0
  123706. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0
  123707. +31 45 11 77 111 26 117 169 40 117 169 40 117 169 40 117 169 40
  123708. +117 169 40 117 169 40 118 170 40 116 168 40 92 132 31 47 69 16
  123709. +38 55 13 81 118 28 113 163 39 119 171 41 117 169 40 117 169 40
  123710. +117 169 40 117 169 40 117 169 40 117 169 40 118 171 41 92 132 31
  123711. +10 15 3 0 0 0 0 0 0 36 52 12 115 166 39 117 169 40
  123712. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 118 170 40
  123713. +118 171 40 102 148 35 64 92 22 34 49 12 65 94 22 106 153 36
  123714. +118 171 40 117 170 40 117 169 40 117 169 40 117 169 40 117 169 40
  123715. +118 170 40 107 154 36 55 80 19 15 21 5 0 0 0 0 0 0
  123716. +0 0 0 0 0 0 0 0 0
  123717. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123718. +29 42 10 101 146 34 118 171 40 117 169 40 117 169 40 117 169 40
  123719. +117 169 40 117 169 40 117 169 40 117 169 40 118 171 40 113 163 39
  123720. +75 109 26 27 40 9 36 52 12 89 128 30 116 167 40 118 171 40
  123721. +117 169 40 117 169 40 117 169 40 117 169 40 118 170 40 104 150 35
  123722. +16 23 5 0 0 0 0 0 0 53 76 18 118 171 40 117 169 40
  123723. +117 169 40 117 169 40 117 169 40 117 169 40 119 171 41 109 157 37
  123724. +67 96 23 23 34 8 42 61 14 96 138 32 118 170 40 118 170 40
  123725. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  123726. +117 169 40 117 169 40 74 107 25 10 15 3 0 0 0 0 0 0
  123727. +0 0 0 0 0 0 0 0 0
  123728. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123729. +0 0 0 31 45 11 101 146 34 118 170 40 117 169 40 117 169 40
  123730. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  123731. +119 171 41 102 148 35 47 69 16 14 20 5 50 72 17 102 148 35
  123732. +118 171 40 117 169 40 117 169 40 117 169 40 118 170 40 102 148 35
  123733. +15 21 5 0 0 0 0 0 0 50 72 17 118 170 40 117 169 40
  123734. +117 169 40 117 169 40 118 170 40 116 167 40 84 121 28 27 40 9
  123735. +19 27 6 74 107 25 114 165 39 118 171 40 117 169 40 117 169 40
  123736. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  123737. +117 169 40 75 109 26 10 15 4 0 0 0 0 0 0 0 0 0
  123738. +0 0 0 0 0 0 0 0 0
  123739. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123740. +0 0 0 38 55 13 102 148 35 118 171 40 117 169 40 117 169 40
  123741. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  123742. +117 169 40 118 170 40 115 167 39 77 111 26 17 25 6 19 27 6
  123743. +77 111 26 115 166 39 118 170 40 117 169 40 119 172 41 81 118 28
  123744. +3 4 1 0 0 0 0 0 0 27 40 9 111 160 38 118 170 40
  123745. +117 169 40 118 171 40 105 151 36 50 72 17 10 15 3 38 55 13
  123746. +100 144 34 118 171 40 117 169 40 117 169 40 117 169 40 117 169 40
  123747. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  123748. +117 169 40 79 115 27 15 21 5 0 0 0 0 0 0 0 0 0
  123749. +0 0 0 0 0 0 0 0 0
  123750. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123751. +0 0 0 10 15 3 64 92 22 111 160 38 117 169 40 117 169 40
  123752. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  123753. +117 169 40 117 169 40 117 169 40 118 171 40 96 138 32 32 47 11
  123754. +3 4 1 50 72 17 107 154 36 120 173 41 105 151 36 31 45 11
  123755. +0 0 0 0 0 0 0 0 0 3 4 1 65 94 22 117 169 40
  123756. +118 170 40 89 128 30 26 37 9 3 4 1 60 86 20 111 161 38
  123757. +118 171 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  123758. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  123759. +97 141 33 36 52 12 1 1 0 0 0 0 0 0 0 0 0 0
  123760. +0 0 0 0 0 0 0 0 0
  123761. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123762. +0 0 0 0 0 0 14 20 5 75 109 26 117 168 40 117 169 40
  123763. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  123764. +117 169 40 117 169 40 117 169 40 117 169 40 118 171 40 107 154 36
  123765. +45 64 15 2 3 1 31 45 11 75 109 26 32 47 11 0 1 0
  123766. +0 0 0 0 0 0 0 0 0 0 0 0 10 15 3 55 80 19
  123767. +65 94 22 11 16 4 11 16 4 75 109 26 116 168 40 118 170 40
  123768. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  123769. +117 169 40 117 169 40 117 169 40 117 169 40 118 170 40 107 154 36
  123770. +47 69 16 3 4 1 0 0 0 0 0 0 0 0 0 0 0 0
  123771. +0 0 0 0 0 0 0 0 0
  123772. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123773. +0 0 0 0 0 0 12 18 4 69 100 23 111 161 38 118 171 40
  123774. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  123775. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 118 170 40
  123776. +111 160 38 50 72 17 2 3 1 2 3 1 0 0 0 0 0 0
  123777. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0
  123778. +1 1 0 12 18 4 81 118 28 118 170 40 117 169 40 117 169 40
  123779. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  123780. +117 169 40 117 169 40 117 169 40 117 170 40 118 171 40 101 146 34
  123781. +42 61 14 2 3 1 0 0 0 0 0 0 0 0 0 0 0 0
  123782. +0 0 0 0 0 0 0 0 0
  123783. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123784. +0 0 0 0 0 0 0 0 0 3 4 1 36 52 12 89 128 30
  123785. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  123786. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  123787. +118 171 41 101 146 34 14 20 5 0 0 0 0 0 0 0 0 0
  123788. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123789. +0 0 0 47 69 16 118 170 40 117 169 40 117 169 40 117 169 40
  123790. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  123791. +117 169 40 117 169 40 117 170 40 111 160 38 69 100 23 19 27 6
  123792. +0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123793. +0 0 0 0 0 0 0 0 0
  123794. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123795. +0 0 0 0 0 0 0 0 0 0 0 0 11 16 4 69 100 23
  123796. +115 167 39 119 172 41 117 169 40 117 169 40 117 169 40 117 169 40
  123797. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  123798. +119 172 41 75 109 26 3 4 1 0 0 0 0 0 0 0 0 0
  123799. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123800. +0 0 0 23 34 8 106 153 36 118 170 40 117 169 40 117 169 40
  123801. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  123802. +117 169 40 118 170 40 119 172 41 105 151 36 42 61 14 2 3 1
  123803. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123804. +0 0 0 0 0 0 0 0 0
  123805. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123806. +0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 15 21 5
  123807. +45 64 15 80 116 27 114 165 39 118 170 40 117 169 40 117 169 40
  123808. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 119 172 41
  123809. +97 141 33 20 30 7 0 0 0 0 0 0 0 0 0 0 0 0
  123810. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123811. +0 0 0 1 1 0 53 76 18 114 165 39 118 171 40 117 169 40
  123812. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  123813. +118 171 40 104 150 35 64 92 22 31 45 11 10 15 3 0 0 0
  123814. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123815. +0 0 0 0 0 0 0 0 0
  123816. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123817. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123818. +0 0 0 36 52 12 97 141 33 109 158 37 113 163 39 116 168 40
  123819. +117 169 40 117 170 40 118 170 40 119 172 41 115 167 39 84 121 28
  123820. +23 34 8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123821. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123822. +0 0 0 0 0 0 3 4 1 50 72 17 102 148 35 118 171 40
  123823. +119 171 41 118 170 40 117 169 40 117 169 40 115 166 39 111 161 38
  123824. +109 157 37 79 115 27 12 18 4 0 0 0 0 0 0 0 0 0
  123825. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123826. +0 0 0 0 0 0 0 0 0
  123827. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123828. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123829. +0 0 0 3 4 1 15 21 5 23 34 8 45 64 15 106 153 36
  123830. +116 167 40 111 160 38 101 146 34 79 115 27 42 61 14 10 15 3
  123831. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123832. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123833. +0 0 0 0 0 0 0 0 0 1 1 0 20 30 7 60 86 20
  123834. +89 128 30 106 153 36 113 163 39 117 169 40 84 121 28 29 42 10
  123835. +19 27 6 10 15 3 2 3 1 0 0 0 0 0 0 0 0 0
  123836. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123837. +0 0 0 0 0 0 0 0 0
  123838. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123839. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123840. +0 0 0 0 0 0 0 0 0 0 0 0 16 23 5 38 55 13
  123841. +36 52 12 26 37 9 12 18 4 2 3 1 0 0 0 0 0 0
  123842. +0 0 0 0 0 0 0 0 0 1 0 0 19 2 7 52 5 18
  123843. +78 7 27 88 8 31 81 7 29 56 5 19 25 2 9 3 0 1
  123844. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123845. +3 4 1 19 27 6 31 45 11 38 55 13 32 47 11 3 4 1
  123846. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123847. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123848. +0 0 0 0 0 0 0 0 0
  123849. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123850. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123851. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 0 1
  123852. +9 0 3 12 1 4 9 0 3 4 0 1 0 0 0 0 0 0
  123853. +0 0 0 0 0 0 28 3 10 99 9 35 156 14 55 182 16 64
  123854. +189 17 66 190 17 67 189 17 66 184 17 65 166 15 58 118 13 41
  123855. +45 4 16 3 0 1 0 0 0 0 0 0 0 0 0 0 0 0
  123856. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123857. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123858. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123859. +0 0 0 0 0 0 0 0 0
  123860. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123861. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123862. +0 0 0 0 0 0 11 1 4 52 5 18 101 9 35 134 12 47
  123863. +151 14 53 154 14 54 151 14 53 113 10 40 11 1 4 0 0 0
  123864. +3 0 1 67 6 24 159 14 56 190 17 67 190 17 67 188 17 66
  123865. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 191 17 67
  123866. +174 16 61 101 9 35 14 1 5 0 0 0 35 3 12 108 10 38
  123867. +122 11 43 122 11 43 112 10 39 87 8 30 50 5 17 13 1 5
  123868. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123869. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123870. +0 0 0 0 0 0 0 0 0
  123871. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123872. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123873. +3 0 1 56 5 19 141 13 49 182 16 64 191 17 67 191 17 67
  123874. +190 17 67 190 17 67 191 17 67 113 10 40 3 0 1 1 0 0
  123875. +79 7 28 180 16 63 190 17 67 188 17 66 188 17 66 188 17 66
  123876. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  123877. +189 17 66 188 17 66 122 11 43 11 1 4 41 4 14 176 16 62
  123878. +191 17 67 191 17 67 191 17 67 190 17 67 181 16 63 146 13 51
  123879. +75 7 26 10 1 4 0 0 0 0 0 0 0 0 0 0 0 0
  123880. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123881. +0 0 0 0 0 0 0 0 0
  123882. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123883. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7 1 2
  123884. +90 8 32 178 16 62 191 17 67 188 17 66 188 17 66 188 17 66
  123885. +188 17 66 190 17 67 141 13 49 22 2 8 0 0 0 41 4 14
  123886. +173 16 61 190 17 67 188 17 66 188 17 66 188 17 66 188 17 66
  123887. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  123888. +188 17 66 188 17 66 188 17 66 88 8 31 1 0 0 89 8 31
  123889. +185 17 65 189 17 66 188 17 66 188 17 66 189 17 66 191 17 67
  123890. +186 17 65 124 11 43 25 2 9 0 0 0 0 0 0 0 0 0
  123891. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123892. +0 0 0 0 0 0 0 0 0
  123893. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123894. +0 0 0 0 0 0 0 0 0 0 0 0 2 0 1 89 8 31
  123895. +184 17 65 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  123896. +190 17 67 151 14 53 34 3 12 0 0 0 0 0 0 79 7 28
  123897. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  123898. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  123899. +188 17 66 188 17 66 191 17 67 146 13 51 9 1 3 7 1 2
  123900. +108 10 38 187 17 66 189 17 66 188 17 66 188 17 66 188 17 66
  123901. +188 17 66 190 17 67 141 13 49 22 2 8 0 0 0 0 0 0
  123902. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123903. +0 0 0 0 0 0 0 0 0
  123904. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123905. +0 0 0 0 0 0 0 0 0 0 0 0 52 5 18 176 16 62
  123906. +189 17 66 188 17 66 188 17 66 188 17 66 188 17 66 190 17 67
  123907. +151 14 53 38 3 13 0 0 0 0 0 0 0 0 0 50 5 17
  123908. +180 16 63 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  123909. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  123910. +188 17 66 188 17 66 191 17 67 141 13 49 7 1 3 0 0 0
  123911. +11 1 4 112 10 39 187 17 66 189 17 66 188 17 66 188 17 66
  123912. +188 17 66 188 17 66 190 17 67 113 10 40 5 0 2 0 0 0
  123913. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123914. +0 0 0 0 0 0 0 0 0
  123915. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123916. +0 0 0 0 0 0 0 0 0 7 1 3 132 12 46 191 17 67
  123917. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 146 13 51
  123918. +35 3 12 0 0 0 0 0 0 0 0 0 0 0 0 5 0 2
  123919. +101 9 35 185 17 65 190 17 67 188 17 66 188 17 66 188 17 66
  123920. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  123921. +188 17 66 190 17 67 180 16 63 67 6 24 0 0 0 0 0 0
  123922. +0 0 0 11 1 4 108 10 38 186 17 65 189 17 66 188 17 66
  123923. +188 17 66 188 17 66 189 17 66 180 16 63 56 5 19 0 0 0
  123924. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123925. +0 0 0 0 0 0 0 0 0
  123926. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123927. +0 0 0 0 0 0 0 0 0 44 4 15 177 16 62 189 17 66
  123928. +188 17 66 188 17 66 189 17 66 189 17 66 134 12 47 28 3 10
  123929. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123930. +8 1 3 79 7 28 159 14 56 188 17 66 191 17 67 190 17 67
  123931. +189 17 66 189 17 66 189 17 66 189 17 66 190 17 67 191 17 67
  123932. +188 17 66 158 14 55 72 7 25 4 0 1 0 0 0 0 0 0
  123933. +0 0 0 0 0 0 8 1 3 95 9 33 182 16 64 189 17 67
  123934. +188 17 66 188 17 66 188 17 66 191 17 67 122 11 43 3 0 1
  123935. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123936. +0 0 0 0 0 0 0 0 0
  123937. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123938. +0 0 0 0 0 0 0 0 0 88 8 31 190 17 67 188 17 66
  123939. +188 17 66 189 17 66 185 17 65 113 10 40 18 2 6 0 0 0
  123940. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123941. +0 0 0 1 0 0 24 2 8 77 7 27 124 11 43 154 14 54
  123942. +168 15 59 173 16 61 173 16 61 168 15 59 154 14 54 124 11 43
  123943. +77 7 27 22 2 8 0 0 0 0 0 0 0 0 0 0 0 0
  123944. +0 0 0 0 0 0 0 0 0 5 0 2 77 7 27 173 16 61
  123945. +190 17 67 188 17 66 188 17 66 190 17 67 164 15 57 23 2 8
  123946. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123947. +0 0 0 0 0 0 0 0 0
  123948. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123949. +0 0 0 0 0 0 1 0 0 118 13 41 191 17 67 188 17 66
  123950. +190 17 67 174 16 61 87 8 30 8 1 3 0 0 0 0 0 0
  123951. +0 0 0 0 0 0 10 1 4 29 3 10 40 4 14 36 3 13
  123952. +18 2 6 2 0 1 0 0 0 0 0 0 3 0 1 14 1 5
  123953. +26 2 9 33 3 11 32 3 11 25 2 9 13 1 5 3 0 1
  123954. +0 0 0 14 1 5 56 5 19 95 9 33 109 10 38 101 9 35
  123955. +77 7 27 35 3 12 5 0 2 0 0 0 1 0 0 56 5 19
  123956. +156 14 55 190 17 67 188 17 66 188 17 66 182 16 64 50 5 17
  123957. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123958. +0 0 0 0 0 0 0 0 0
  123959. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123960. +0 0 0 0 0 0 5 0 2 134 12 47 191 17 67 189 17 66
  123961. +151 14 53 52 5 18 2 0 1 0 0 0 0 0 0 1 0 0
  123962. +28 3 10 90 8 32 146 13 51 170 15 60 178 16 62 174 16 61
  123963. +158 14 55 112 10 39 40 4 14 1 0 0 0 0 0 0 0 0
  123964. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 0 1
  123965. +56 5 19 146 13 51 183 17 64 191 17 67 191 17 67 191 17 67
  123966. +188 17 66 173 16 61 122 11 43 41 4 14 1 0 0 0 0 0
  123967. +30 3 10 124 11 43 185 17 65 190 17 67 187 17 66 67 6 24
  123968. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123969. +0 0 0 0 0 0 0 0 0
  123970. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123971. +0 0 0 0 0 0 6 1 2 134 12 47 168 15 59 99 9 35
  123972. +21 2 7 0 0 0 0 0 0 0 0 0 6 1 2 77 7 27
  123973. +162 15 57 190 17 67 191 17 67 189 17 66 189 17 66 189 17 66
  123974. +190 17 67 191 17 67 169 15 59 75 7 26 3 0 1 0 0 0
  123975. +0 0 0 0 0 0 0 0 0 0 0 0 2 0 1 79 7 28
  123976. +178 16 62 191 17 67 188 17 66 188 17 66 188 17 66 188 17 66
  123977. +188 17 66 189 17 66 191 17 67 170 15 60 79 7 28 5 0 2
  123978. +0 0 0 10 1 3 78 7 27 159 14 56 188 17 66 75 7 26
  123979. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123980. +0 0 0 0 0 0 0 0 0
  123981. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123982. +0 0 0 0 0 0 1 0 0 35 3 12 29 3 10 2 0 1
  123983. +0 0 0 0 0 0 0 0 0 9 1 3 101 9 35 183 17 64
  123984. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  123985. +188 17 66 188 17 66 190 17 67 178 16 63 67 6 23 0 0 0
  123986. +0 0 0 0 0 0 0 0 0 0 0 0 52 5 18 174 16 61
  123987. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  123988. +188 17 66 188 17 66 188 17 66 190 17 67 182 16 64 89 8 31
  123989. +4 0 1 0 0 0 0 0 0 25 2 9 73 7 26 31 3 11
  123990. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123991. +0 0 0 0 0 0 0 0 0
  123992. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123993. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  123994. +0 0 0 0 0 0 4 0 1 98 9 34 187 17 66 189 17 66
  123995. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  123996. +188 17 66 188 17 66 188 17 66 190 17 67 158 14 55 25 2 9
  123997. +0 0 0 0 0 0 0 0 0 8 1 3 134 12 47 191 17 67
  123998. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  123999. +188 17 66 188 17 66 188 17 66 188 17 66 189 17 66 180 16 63
  124000. +68 6 24 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124001. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124002. +0 0 0 0 0 0 0 0 0
  124003. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124004. +0 0 0 6 1 2 19 2 7 3 0 1 0 0 0 0 0 0
  124005. +0 0 0 0 0 0 65 6 23 180 16 63 189 17 66 188 17 66
  124006. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  124007. +188 17 66 188 17 66 188 17 66 188 17 66 189 17 66 83 8 29
  124008. +0 0 0 0 0 0 0 0 0 41 4 14 177 16 62 189 17 66
  124009. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  124010. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 190 17 67
  124011. +159 14 56 28 3 10 0 0 0 0 0 0 0 0 0 23 2 8
  124012. +41 4 14 5 0 2 0 0 0 0 0 0 0 0 0 0 0 0
  124013. +0 0 0 0 0 0 0 0 0
  124014. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124015. +23 2 8 113 10 40 159 14 56 65 6 23 0 0 0 0 0 0
  124016. +0 0 0 16 1 6 146 13 51 191 17 67 188 17 66 188 17 66
  124017. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  124018. +188 17 66 188 17 66 188 17 66 188 17 66 191 17 67 132 12 46
  124019. +5 0 2 0 0 0 0 0 0 77 7 27 189 17 66 188 17 66
  124020. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  124021. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  124022. +190 17 67 98 9 34 0 0 0 0 0 0 12 1 4 134 12 47
  124023. +178 16 63 108 10 38 16 1 6 0 0 0 0 0 0 0 0 0
  124024. +0 0 0 0 0 0 0 0 0
  124025. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 30 3 10
  124026. +141 13 49 190 17 67 191 17 67 134 12 47 6 1 2 0 0 0
  124027. +0 0 0 68 6 24 186 17 65 188 17 66 188 17 66 188 17 66
  124028. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  124029. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 156 14 55
  124030. +14 1 5 0 0 0 0 0 0 98 9 34 191 17 67 188 17 66
  124031. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  124032. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  124033. +190 17 67 156 14 55 19 2 7 0 0 0 47 4 16 181 16 63
  124034. +190 17 67 189 17 66 126 14 44 17 2 6 0 0 0 0 0 0
  124035. +0 0 0 0 0 0 0 0 0
  124036. +0 0 0 0 0 0 0 0 0 0 0 0 16 1 6 134 12 47
  124037. +191 17 67 188 17 66 190 17 67 162 15 57 19 2 7 0 0 0
  124038. +3 0 1 123 11 43 191 17 67 188 17 66 188 17 66 188 17 66
  124039. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  124040. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 163 15 57
  124041. +20 2 7 0 0 0 0 0 0 101 9 35 191 17 67 188 17 66
  124042. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  124043. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  124044. +188 17 66 182 16 64 52 5 18 0 0 0 73 7 26 188 17 66
  124045. +188 17 66 188 17 66 189 17 66 109 10 38 5 0 2 0 0 0
  124046. +0 0 0 0 0 0 0 0 0
  124047. +0 0 0 0 0 0 0 0 0 0 0 0 95 9 33 189 17 66
  124048. +188 17 66 188 17 66 189 17 66 171 15 60 29 3 10 0 0 0
  124049. +16 1 6 156 14 55 190 17 67 188 17 66 188 17 66 188 17 66
  124050. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  124051. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 158 14 55
  124052. +17 2 6 0 0 0 0 0 0 85 8 30 190 17 67 188 17 66
  124053. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  124054. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  124055. +188 17 66 189 17 66 81 7 29 0 0 0 85 8 30 190 17 67
  124056. +188 17 66 188 17 66 189 17 66 180 16 63 56 5 19 0 0 0
  124057. +0 0 0 0 0 0 0 0 0
  124058. +0 0 0 0 0 0 0 0 0 25 2 9 162 15 57 190 17 67
  124059. +188 17 66 188 17 66 189 17 66 173 16 61 31 3 11 0 0 0
  124060. +30 3 10 171 15 60 189 17 66 188 17 66 188 17 66 188 17 66
  124061. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  124062. +188 17 66 188 17 66 188 17 66 188 17 66 191 17 67 141 13 49
  124063. +7 1 2 0 0 0 0 0 0 56 5 19 183 17 64 188 17 66
  124064. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  124065. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  124066. +188 17 66 191 17 67 98 9 34 0 0 0 88 8 31 190 17 67
  124067. +188 17 66 188 17 66 188 17 66 191 17 67 124 11 43 5 0 2
  124068. +0 0 0 0 0 0 0 0 0
  124069. +0 0 0 0 0 0 0 0 0 68 6 24 187 17 66 188 17 66
  124070. +188 17 66 188 17 66 189 17 66 170 15 60 28 3 10 0 0 0
  124071. +34 3 12 174 16 61 189 17 66 188 17 66 188 17 66 188 17 66
  124072. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  124073. +188 17 66 188 17 66 188 17 66 188 17 66 191 17 67 101 9 35
  124074. +0 0 0 0 0 0 0 0 0 21 2 7 159 14 56 190 17 67
  124075. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  124076. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  124077. +188 17 66 191 17 67 98 9 34 0 0 0 81 7 29 189 17 66
  124078. +188 17 66 188 17 66 188 17 66 189 17 66 168 15 59 28 3 10
  124079. +0 0 0 0 0 0 0 0 0
  124080. +0 0 0 0 0 0 0 0 0 109 10 38 191 17 67 188 17 66
  124081. +188 17 66 188 17 66 190 17 67 163 15 57 21 2 7 0 0 0
  124082. +26 2 9 168 15 59 189 17 66 188 17 66 188 17 66 188 17 66
  124083. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  124084. +188 17 66 188 17 66 188 17 66 189 17 66 180 16 63 47 4 16
  124085. +0 0 0 0 0 0 0 0 0 0 0 0 108 10 38 190 17 67
  124086. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  124087. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  124088. +188 17 66 189 17 66 78 7 27 0 0 0 68 6 24 187 17 66
  124089. +188 17 66 188 17 66 188 17 66 188 17 66 183 17 64 56 5 19
  124090. +0 0 0 0 0 0 0 0 0
  124091. +0 0 0 0 0 0 3 0 1 131 12 46 191 17 67 188 17 66
  124092. +188 17 66 188 17 66 190 17 67 151 14 53 12 1 4 0 0 0
  124093. +11 1 4 146 13 51 190 17 67 188 17 66 188 17 66 188 17 66
  124094. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  124095. +188 17 66 188 17 66 188 17 66 191 17 67 126 14 44 7 1 2
  124096. +0 0 0 0 0 0 0 0 0 0 0 0 32 3 11 164 15 58
  124097. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  124098. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  124099. +189 17 66 178 16 62 44 4 15 0 0 0 50 5 17 182 16 64
  124100. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 72 7 25
  124101. +0 0 0 0 0 0 0 0 0
  124102. +0 0 0 0 0 0 5 0 2 134 12 47 191 17 67 188 17 66
  124103. +188 17 66 188 17 66 191 17 67 131 12 46 3 0 1 0 0 0
  124104. +0 0 0 101 9 35 190 17 67 188 17 66 188 17 66 188 17 66
  124105. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  124106. +188 17 66 188 17 66 190 17 67 170 15 60 44 4 15 0 0 0
  124107. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 77 7 27
  124108. +183 17 64 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  124109. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  124110. +191 17 67 134 12 47 9 1 3 0 0 0 31 3 11 171 15 60
  124111. +189 17 66 188 17 66 188 17 66 188 17 66 188 17 66 72 7 25
  124112. +0 0 0 0 0 0 0 0 0
  124113. +0 0 0 0 0 0 2 0 1 124 11 43 191 17 67 188 17 66
  124114. +188 17 66 188 17 66 191 17 67 101 9 35 0 0 0 0 0 0
  124115. +0 0 0 35 3 12 168 15 59 190 17 67 188 17 66 188 17 66
  124116. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  124117. +188 17 66 189 17 66 182 16 64 77 7 27 0 0 0 0 0 0
  124118. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 1 2
  124119. +99 9 35 185 17 65 189 17 66 188 17 66 188 17 66 188 17 66
  124120. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 189 17 66
  124121. +177 16 62 56 5 19 0 0 0 0 0 0 13 1 5 151 14 53
  124122. +190 17 67 188 17 66 188 17 66 188 17 66 185 17 65 56 5 19
  124123. +0 0 0 0 0 0 0 0 0
  124124. +0 0 0 0 0 0 0 0 0 99 9 35 191 17 67 188 17 66
  124125. +188 17 66 188 17 66 186 17 65 65 6 23 0 0 0 0 0 0
  124126. +0 0 0 0 0 0 79 7 28 182 16 64 190 17 67 188 17 66
  124127. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  124128. +191 17 67 177 16 62 83 8 29 4 0 1 0 0 0 0 0 0
  124129. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124130. +8 1 3 89 8 31 175 16 62 191 17 67 189 17 66 188 17 66
  124131. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 181 16 63
  124132. +85 8 30 3 0 1 0 0 0 0 0 0 1 0 0 118 13 41
  124133. +191 17 67 188 17 66 188 17 66 189 17 66 173 16 61 34 3 12
  124134. +0 0 0 0 0 0 0 0 0
  124135. +0 0 0 0 0 0 0 0 0 56 5 19 183 17 64 188 17 66
  124136. +188 17 66 189 17 66 169 15 59 30 3 10 0 0 0 0 0 0
  124137. +0 0 0 0 0 0 5 0 2 83 8 29 173 16 61 191 17 67
  124138. +190 17 67 189 17 66 189 17 66 190 17 67 191 17 67 187 17 66
  124139. +151 14 53 56 5 19 3 0 1 0 0 0 16 1 6 50 5 17
  124140. +79 7 28 95 9 33 95 9 33 75 7 26 41 4 14 10 1 4
  124141. +0 0 0 2 0 1 50 5 17 132 12 46 178 16 62 190 17 67
  124142. +191 17 67 191 17 67 191 17 67 186 17 65 154 14 54 68 6 24
  124143. +4 0 1 0 0 0 0 0 0 0 0 0 0 0 0 72 7 25
  124144. +187 17 66 188 17 66 188 17 66 191 17 67 141 13 49 9 1 3
  124145. +0 0 0 0 0 0 0 0 0
  124146. +0 0 0 0 0 0 0 0 0 14 1 5 151 14 53 190 17 67
  124147. +188 17 66 191 17 67 131 12 46 5 0 2 0 0 0 0 0 0
  124148. +0 0 0 0 0 0 0 0 0 2 0 1 44 4 15 113 10 40
  124149. +156 14 55 173 16 61 174 16 61 164 15 58 134 12 47 77 7 27
  124150. +18 2 6 0 0 0 16 1 6 85 8 30 151 14 53 182 16 64
  124151. +189 17 66 191 17 67 190 17 67 188 17 66 177 16 62 141 13 49
  124152. +68 6 24 8 1 3 0 0 0 8 1 3 44 4 15 88 8 31
  124153. +113 10 40 122 11 43 108 10 38 67 6 24 20 2 7 0 0 0
  124154. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 28 3 10
  124155. +166 15 58 190 17 67 188 17 66 187 17 66 79 7 28 0 0 0
  124156. +0 0 0 0 0 0 0 0 0
  124157. +0 0 0 0 0 0 0 0 0 0 0 0 73 7 26 185 17 65
  124158. +189 17 66 184 17 65 65 6 23 0 0 0 0 0 0 0 0 0
  124159. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 1
  124160. +17 2 6 32 3 11 34 3 12 22 2 8 6 1 2 0 0 0
  124161. +0 0 0 38 3 13 141 13 49 188 17 66 190 17 67 188 17 66
  124162. +188 17 66 188 17 66 188 17 66 188 17 66 189 17 66 191 17 67
  124163. +184 17 65 122 11 43 21 2 7 0 0 0 0 0 0 0 0 0
  124164. +0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124165. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0
  124166. +108 10 38 191 17 67 191 17 67 141 13 49 16 1 6 0 0 0
  124167. +0 0 0 0 0 0 0 0 0
  124168. +0 0 0 0 0 0 0 0 0 0 0 0 8 1 3 112 10 39
  124169. +186 17 65 124 11 43 10 1 4 0 0 0 0 0 0 0 0 0
  124170. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124171. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124172. +36 3 13 156 14 55 191 17 67 188 17 66 188 17 66 188 17 66
  124173. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  124174. +189 17 66 190 17 67 134 12 47 18 2 6 0 0 0 0 0 0
  124175. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124176. +0 0 0 7 1 2 41 4 14 75 7 26 66 5 23 19 2 7
  124177. +26 2 9 144 13 50 154 14 54 40 4 14 0 0 0 0 0 0
  124178. +0 0 0 0 0 0 0 0 0
  124179. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 13 1 5
  124180. +56 5 19 19 2 7 0 0 0 7 1 2 29 3 10 35 3 12
  124181. +19 2 7 2 0 1 0 0 0 0 0 0 0 0 0 0 0 0
  124182. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 13 1 5
  124183. +134 12 47 191 17 67 188 17 66 188 17 66 188 17 66 188 17 66
  124184. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  124185. +188 17 66 188 17 66 189 17 67 108 10 38 3 0 1 0 0 0
  124186. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0
  124187. +40 4 14 124 11 43 177 16 62 188 17 66 187 17 66 144 13 50
  124188. +24 2 8 17 2 6 22 2 8 0 0 0 0 0 0 0 0 0
  124189. +0 0 0 0 0 0 0 0 0
  124190. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124191. +0 0 0 0 0 0 19 2 7 122 11 43 171 15 60 175 16 62
  124192. +159 14 56 112 10 39 40 4 14 2 0 1 0 0 0 0 0 0
  124193. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 72 7 25
  124194. +186 17 65 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  124195. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  124196. +188 17 66 188 17 66 189 17 66 174 16 61 41 4 14 0 0 0
  124197. +0 0 0 0 0 0 0 0 0 0 0 0 3 0 1 72 7 25
  124198. +168 15 59 191 17 67 189 17 66 188 17 66 188 17 66 190 17 67
  124199. +95 9 33 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124200. +0 0 0 0 0 0 0 0 0
  124201. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124202. +0 0 0 0 0 0 95 9 33 191 17 67 189 17 66 189 17 66
  124203. +190 17 67 191 17 67 171 15 60 90 8 32 12 1 4 0 0 0
  124204. +0 0 0 0 0 0 0 0 0 0 0 0 5 0 2 132 12 46
  124205. +191 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  124206. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  124207. +188 17 66 188 17 66 188 17 66 190 17 67 98 9 34 0 0 0
  124208. +0 0 0 0 0 0 0 0 0 5 0 2 88 8 31 180 16 63
  124209. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 191 17 67
  124210. +146 13 51 11 1 4 0 0 0 0 0 0 0 0 0 0 0 0
  124211. +0 0 0 0 0 0 0 0 0
  124212. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124213. +0 0 0 9 1 3 144 13 50 191 17 67 188 17 66 188 17 66
  124214. +188 17 66 188 17 66 189 17 66 187 17 66 123 11 43 20 2 7
  124215. +0 0 0 0 0 0 0 0 0 0 0 0 21 2 7 163 15 57
  124216. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  124217. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  124218. +188 17 66 188 17 66 188 17 66 191 17 67 134 12 47 5 0 2
  124219. +0 0 0 0 0 0 3 0 1 88 8 31 182 16 64 189 17 66
  124220. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 189 17 66
  124221. +171 15 60 31 3 11 0 0 0 0 0 0 0 0 0 0 0 0
  124222. +0 0 0 0 0 0 0 0 0
  124223. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124224. +0 0 0 20 2 7 162 15 57 190 17 67 188 17 66 188 17 66
  124225. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 132 12 46
  124226. +20 2 7 0 0 0 0 0 0 0 0 0 32 3 11 173 16 61
  124227. +189 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  124228. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  124229. +188 17 66 188 17 66 188 17 66 190 17 67 151 14 53 12 1 4
  124230. +0 0 0 0 0 0 72 7 25 180 16 63 189 17 66 188 17 66
  124231. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  124232. +181 16 63 47 4 16 0 0 0 0 0 0 0 0 0 0 0 0
  124233. +0 0 0 0 0 0 0 0 0
  124234. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124235. +0 0 0 21 2 7 163 15 57 190 17 67 188 17 66 188 17 66
  124236. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 190 17 67
  124237. +122 11 43 9 1 3 0 0 0 0 0 0 30 3 10 171 15 60
  124238. +189 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  124239. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  124240. +188 17 66 188 17 66 188 17 66 190 17 67 146 13 51 10 1 4
  124241. +0 0 0 38 3 13 166 15 58 190 17 67 188 17 66 188 17 66
  124242. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  124243. +183 17 64 52 5 18 0 0 0 0 0 0 0 0 0 0 0 0
  124244. +0 0 0 0 0 0 0 0 0
  124245. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124246. +0 0 0 13 1 5 154 14 54 190 17 67 188 17 66 188 17 66
  124247. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  124248. +186 17 65 79 7 28 0 0 0 0 0 0 14 1 5 156 14 54
  124249. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  124250. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  124251. +188 17 66 188 17 66 188 17 66 191 17 67 124 11 43 2 0 1
  124252. +5 0 2 122 11 43 191 17 67 188 17 66 188 17 66 188 17 66
  124253. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  124254. +182 16 64 47 4 16 0 0 0 0 0 0 0 0 0 0 0 0
  124255. +0 0 0 0 0 0 0 0 0
  124256. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124257. +0 0 0 3 0 1 126 14 44 191 17 67 188 17 66 188 17 66
  124258. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  124259. +190 17 67 158 14 55 23 2 8 0 0 0 1 0 0 113 10 40
  124260. +191 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  124261. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  124262. +188 17 66 188 17 66 188 17 66 188 17 66 78 7 27 0 0 0
  124263. +47 4 16 177 16 62 189 17 66 188 17 66 188 17 66 188 17 66
  124264. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 189 17 66
  124265. +173 16 61 34 3 12 0 0 0 0 0 0 0 0 0 0 0 0
  124266. +0 0 0 0 0 0 0 0 0
  124267. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124268. +0 0 0 0 0 0 85 8 30 189 17 66 188 17 66 188 17 66
  124269. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  124270. +188 17 66 188 17 66 79 7 28 0 0 0 0 0 0 47 4 16
  124271. +175 16 62 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  124272. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  124273. +188 17 66 188 17 66 190 17 67 156 14 55 22 2 8 0 0 0
  124274. +109 10 38 191 17 67 188 17 66 188 17 66 188 17 66 188 17 66
  124275. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 190 17 67
  124276. +151 14 53 13 1 5 0 0 0 0 0 0 0 0 0 0 0 0
  124277. +0 0 0 0 0 0 0 0 0
  124278. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124279. +0 0 0 0 0 0 35 3 12 173 16 61 189 17 66 188 17 66
  124280. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  124281. +188 17 66 191 17 67 134 12 47 7 1 2 0 0 0 3 0 1
  124282. +99 9 35 188 17 66 189 17 66 188 17 66 188 17 66 188 17 66
  124283. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  124284. +188 17 66 189 17 66 181 16 63 68 6 24 0 0 0 18 2 6
  124285. +156 14 55 190 17 67 188 17 66 188 17 66 188 17 66 188 17 66
  124286. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 190 17 67
  124287. +101 9 35 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124288. +0 0 0 0 0 0 0 0 0
  124289. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124290. +0 0 0 0 0 0 3 0 1 118 13 41 191 17 67 188 17 66
  124291. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  124292. +188 17 66 189 17 66 168 15 59 28 3 10 0 0 0 0 0 0
  124293. +12 1 4 113 10 40 187 17 66 189 17 67 188 17 66 188 17 66
  124294. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  124295. +190 17 67 180 16 63 88 8 31 4 0 1 0 0 0 47 4 16
  124296. +180 16 63 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  124297. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 168 15 59
  124298. +36 3 13 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124299. +0 0 0 0 0 0 0 0 0
  124300. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124301. +0 0 0 0 0 0 0 0 0 38 3 13 164 15 58 190 17 67
  124302. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  124303. +188 17 66 188 17 66 182 16 64 50 5 17 0 0 0 0 0 0
  124304. +0 0 0 11 1 4 90 8 32 169 15 59 190 17 67 190 17 67
  124305. +189 17 66 189 17 66 189 17 66 189 17 66 191 17 67 189 17 66
  124306. +158 14 55 68 6 24 4 0 1 0 0 0 0 0 0 73 7 26
  124307. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  124308. +188 17 66 188 17 66 188 17 66 189 17 66 185 17 65 83 8 29
  124309. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124310. +0 0 0 0 0 0 0 0 0
  124311. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124312. +0 0 0 0 0 0 0 0 0 0 0 0 65 6 23 174 16 61
  124313. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  124314. +188 17 66 188 17 66 185 17 65 56 5 19 0 0 0 0 0 0
  124315. +0 0 0 0 0 0 2 0 1 35 3 12 99 9 35 146 13 51
  124316. +170 15 60 177 16 62 177 16 62 166 15 58 141 13 49 85 8 30
  124317. +24 2 8 0 0 0 0 0 0 0 0 0 0 0 0 85 8 30
  124318. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  124319. +188 17 66 188 17 66 188 17 66 189 17 66 112 10 39 8 1 3
  124320. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124321. +0 0 0 0 0 0 0 0 0
  124322. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124323. +0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 68 6 24
  124324. +170 15 60 191 17 67 188 17 66 188 17 66 188 17 66 188 17 66
  124325. +188 17 66 188 17 66 182 16 64 50 5 17 0 0 0 0 0 0
  124326. +0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 11 1 4
  124327. +28 3 10 40 4 14 38 3 13 25 2 9 8 1 3 0 0 0
  124328. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 78 7 27
  124329. +189 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  124330. +188 17 66 189 17 66 187 17 66 113 10 40 14 1 5 0 0 0
  124331. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124332. +0 0 0 0 0 0 0 0 0
  124333. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124334. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0
  124335. +47 4 16 141 13 49 186 17 65 191 17 67 190 17 67 189 17 66
  124336. +189 17 66 191 17 67 156 14 55 20 2 7 0 0 0 0 0 0
  124337. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124338. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124339. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 44 4 15
  124340. +178 16 62 190 17 67 188 17 66 188 17 66 188 17 66 190 17 67
  124341. +191 17 67 173 16 61 90 8 32 10 1 4 0 0 0 0 0 0
  124342. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124343. +0 0 0 0 0 0 0 0 0
  124344. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124345. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124346. +0 0 0 14 1 5 68 6 24 131 12 46 162 15 57 174 16 61
  124347. +171 15 60 146 13 51 56 5 19 0 0 0 0 0 0 0 0 0
  124348. +0 0 0 0 0 0 0 0 0 3 0 1 14 1 5 29 3 10
  124349. +41 4 14 47 4 16 50 5 17 45 4 16 34 3 12 18 2 6
  124350. +5 0 2 0 0 0 0 0 0 0 0 0 0 0 0 5 0 2
  124351. +90 8 32 169 15 59 185 17 65 187 17 66 182 16 64 163 15 57
  124352. +113 10 40 41 4 14 2 0 1 0 0 0 0 0 0 0 0 0
  124353. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124354. +0 0 0 0 0 0 0 0 0
  124355. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124356. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124357. +0 0 0 0 0 0 0 0 0 5 0 2 21 2 7 34 3 12
  124358. +29 3 10 11 1 4 0 0 0 0 0 0 0 0 0 0 0 0
  124359. +3 0 1 32 3 11 79 7 28 124 11 43 154 14 54 171 15 60
  124360. +180 16 63 182 16 64 182 16 64 180 16 63 174 16 61 159 14 56
  124361. +132 12 46 88 8 31 34 3 12 3 0 1 0 0 0 0 0 0
  124362. +3 0 1 29 3 10 56 5 19 65 6 23 50 5 17 23 2 8
  124363. +3 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124364. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124365. +0 0 0 0 0 0 0 0 0
  124366. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124367. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124368. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124369. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 25 2 9
  124370. +109 10 38 169 15 59 189 17 66 191 17 67 190 17 67 189 17 66
  124371. +189 17 66 188 17 66 188 17 66 188 17 66 189 17 66 190 17 67
  124372. +191 17 67 190 17 67 171 15 60 98 9 34 10 1 3 0 0 0
  124373. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124374. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124375. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124376. +0 0 0 0 0 0 0 0 0
  124377. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124378. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124379. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124380. +0 0 0 0 0 0 0 0 0 0 0 0 14 1 5 141 13 49
  124381. +191 17 67 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  124382. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  124383. +188 17 66 188 17 66 189 17 67 186 17 65 65 6 23 0 0 0
  124384. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124385. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124386. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124387. +0 0 0 0 0 0 0 0 0
  124388. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124389. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124390. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124391. +0 0 0 0 0 0 0 0 0 0 0 0 23 2 8 166 15 58
  124392. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  124393. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  124394. +188 17 66 188 17 66 189 17 66 176 16 62 45 4 16 0 0 0
  124395. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124396. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124397. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124398. +0 0 0 0 0 0 0 0 0
  124399. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124400. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124401. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124402. +0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 83 8 29
  124403. +183 17 64 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  124404. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  124405. +188 17 66 189 17 66 185 17 65 95 9 33 3 0 1 0 0 0
  124406. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124407. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124408. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124409. +0 0 0 0 0 0 0 0 0
  124410. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124411. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124412. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124413. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5 0 2
  124414. +85 8 30 176 16 62 191 17 67 188 17 66 188 17 66 188 17 66
  124415. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  124416. +191 17 67 180 16 63 95 9 33 7 1 3 0 0 0 0 0 0
  124417. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124418. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124419. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124420. +0 0 0 0 0 0 0 0 0
  124421. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124422. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124423. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124424. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124425. +2 0 1 52 5 18 141 13 49 185 17 65 191 17 67 189 17 67
  124426. +189 17 66 188 17 66 188 17 66 189 17 66 191 17 67 187 17 66
  124427. +146 13 51 56 5 19 4 0 1 0 0 0 0 0 0 0 0 0
  124428. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124429. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124430. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124431. +0 0 0 0 0 0 0 0 0
  124432. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124433. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124434. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124435. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124436. +0 0 0 0 0 0 14 1 5 68 6 24 131 12 46 166 15 58
  124437. +180 16 63 183 17 64 180 16 63 168 15 59 134 12 47 75 7 26
  124438. +17 2 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124439. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124440. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124441. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124442. +0 0 0 0 0 0 0 0 0
  124443. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124444. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124445. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124446. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124447. +0 0 0 0 0 0 0 0 0 0 0 0 5 0 2 24 2 8
  124448. +44 4 15 52 5 18 45 4 16 26 2 9 6 1 2 0 0 0
  124449. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124450. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124451. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124452. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124453. +0 0 0 0 0 0 0 0 0
  124454. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124455. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124456. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124457. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124458. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124459. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124460. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124461. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124462. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124463. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124464. +0 0 0 0 0 0 0 0 0
  124465. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124466. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124467. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124468. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124469. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124470. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124471. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124472. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124473. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124474. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  124475. +0 0 0 0 0 0 0 0 0
  124476. diff -Nur linux-3.18.8/drivers/w1/masters/w1-gpio.c linux-rpi/drivers/w1/masters/w1-gpio.c
  124477. --- linux-3.18.8/drivers/w1/masters/w1-gpio.c 2015-02-27 02:49:36.000000000 +0100
  124478. +++ linux-rpi/drivers/w1/masters/w1-gpio.c 2015-03-05 14:40:16.941715804 +0100
  124479. @@ -23,6 +23,19 @@
  124480. #include "../w1.h"
  124481. #include "../w1_int.h"
  124482. +static int w1_gpio_pullup = 0;
  124483. +static int w1_gpio_pullup_orig = 0;
  124484. +module_param_named(pullup, w1_gpio_pullup, int, 0);
  124485. +MODULE_PARM_DESC(pullup, "Enable parasitic power (power on data) mode");
  124486. +static int w1_gpio_pullup_pin = -1;
  124487. +static int w1_gpio_pullup_pin_orig = -1;
  124488. +module_param_named(extpullup, w1_gpio_pullup_pin, int, 0);
  124489. +MODULE_PARM_DESC(extpullup, "GPIO external pullup pin number");
  124490. +static int w1_gpio_pin = -1;
  124491. +static int w1_gpio_pin_orig = -1;
  124492. +module_param_named(gpiopin, w1_gpio_pin, int, 0);
  124493. +MODULE_PARM_DESC(gpiopin, "GPIO pin number");
  124494. +
  124495. static u8 w1_gpio_set_pullup(void *data, int delay)
  124496. {
  124497. struct w1_gpio_platform_data *pdata = data;
  124498. @@ -67,6 +80,16 @@
  124499. return gpio_get_value(pdata->pin) ? 1 : 0;
  124500. }
  124501. +static void w1_gpio_bitbang_pullup(void *data, u8 on)
  124502. +{
  124503. + struct w1_gpio_platform_data *pdata = data;
  124504. +
  124505. + if (on)
  124506. + gpio_direction_output(pdata->pin, 1);
  124507. + else
  124508. + gpio_direction_input(pdata->pin);
  124509. +}
  124510. +
  124511. #if defined(CONFIG_OF)
  124512. static struct of_device_id w1_gpio_dt_ids[] = {
  124513. { .compatible = "w1-gpio" },
  124514. @@ -80,6 +103,7 @@
  124515. struct w1_gpio_platform_data *pdata = dev_get_platdata(&pdev->dev);
  124516. struct device_node *np = pdev->dev.of_node;
  124517. int gpio;
  124518. + u32 value;
  124519. pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
  124520. if (!pdata)
  124521. @@ -88,6 +112,9 @@
  124522. if (of_get_property(np, "linux,open-drain", NULL))
  124523. pdata->is_open_drain = 1;
  124524. + if (of_property_read_u32(np, "rpi,parasitic-power", &value) == 0)
  124525. + pdata->parasitic_power = (value != 0);
  124526. +
  124527. gpio = of_get_gpio(np, 0);
  124528. if (gpio < 0) {
  124529. if (gpio != -EPROBE_DEFER)
  124530. @@ -103,7 +130,7 @@
  124531. if (gpio == -EPROBE_DEFER)
  124532. return gpio;
  124533. /* ignore other errors as the pullup gpio is optional */
  124534. - pdata->ext_pullup_enable_pin = gpio;
  124535. + pdata->ext_pullup_enable_pin = (gpio >= 0) ? gpio : -1;
  124536. pdev->dev.platform_data = pdata;
  124537. @@ -113,13 +140,15 @@
  124538. static int w1_gpio_probe(struct platform_device *pdev)
  124539. {
  124540. struct w1_bus_master *master;
  124541. - struct w1_gpio_platform_data *pdata;
  124542. + struct w1_gpio_platform_data *pdata = pdev->dev.platform_data;
  124543. int err;
  124544. - if (of_have_populated_dt()) {
  124545. - err = w1_gpio_probe_dt(pdev);
  124546. - if (err < 0)
  124547. - return err;
  124548. + if(pdata == NULL) {
  124549. + if (of_have_populated_dt()) {
  124550. + err = w1_gpio_probe_dt(pdev);
  124551. + if (err < 0)
  124552. + return err;
  124553. + }
  124554. }
  124555. pdata = dev_get_platdata(&pdev->dev);
  124556. @@ -136,6 +165,22 @@
  124557. return -ENOMEM;
  124558. }
  124559. + w1_gpio_pin_orig = pdata->pin;
  124560. + w1_gpio_pullup_pin_orig = pdata->ext_pullup_enable_pin;
  124561. + w1_gpio_pullup_orig = pdata->parasitic_power;
  124562. +
  124563. + if(gpio_is_valid(w1_gpio_pin)) {
  124564. + pdata->pin = w1_gpio_pin;
  124565. + pdata->ext_pullup_enable_pin = -1;
  124566. + pdata->parasitic_power = -1;
  124567. + }
  124568. + pdata->parasitic_power |= w1_gpio_pullup;
  124569. + if(gpio_is_valid(w1_gpio_pullup_pin)) {
  124570. + pdata->ext_pullup_enable_pin = w1_gpio_pullup_pin;
  124571. + }
  124572. +
  124573. + dev_info(&pdev->dev, "gpio pin %d, external pullup pin %d, parasitic power %d\n", pdata->pin, pdata->ext_pullup_enable_pin, pdata->parasitic_power);
  124574. +
  124575. err = devm_gpio_request(&pdev->dev, pdata->pin, "w1");
  124576. if (err) {
  124577. dev_err(&pdev->dev, "gpio_request (pin) failed\n");
  124578. @@ -165,6 +210,14 @@
  124579. master->set_pullup = w1_gpio_set_pullup;
  124580. }
  124581. + if (pdata->parasitic_power) {
  124582. + if (pdata->is_open_drain)
  124583. + printk(KERN_ERR "w1-gpio 'pullup'(parasitic power) "
  124584. + "option doesn't work with open drain GPIO\n");
  124585. + else
  124586. + master->bitbang_pullup = w1_gpio_bitbang_pullup;
  124587. + }
  124588. +
  124589. err = w1_add_master_device(master);
  124590. if (err) {
  124591. dev_err(&pdev->dev, "w1_add_master device failed\n");
  124592. @@ -195,6 +248,10 @@
  124593. w1_remove_master_device(master);
  124594. + pdata->pin = w1_gpio_pin_orig;
  124595. + pdata->ext_pullup_enable_pin = w1_gpio_pullup_pin_orig;
  124596. + pdata->parasitic_power = w1_gpio_pullup_orig;
  124597. +
  124598. return 0;
  124599. }
  124600. diff -Nur linux-3.18.8/drivers/w1/w1.h linux-rpi/drivers/w1/w1.h
  124601. --- linux-3.18.8/drivers/w1/w1.h 2015-02-27 02:49:36.000000000 +0100
  124602. +++ linux-rpi/drivers/w1/w1.h 2015-03-05 14:40:16.945715804 +0100
  124603. @@ -171,6 +171,12 @@
  124604. u8 (*set_pullup)(void *, int);
  124605. + /**
  124606. + * Turns the pullup on/off in bitbanging mode, takes an on/off argument.
  124607. + * @return -1=Error, 0=completed
  124608. + */
  124609. + void (*bitbang_pullup) (void *, u8);
  124610. +
  124611. void (*search)(void *, struct w1_master *,
  124612. u8, w1_slave_found_callback);
  124613. };
  124614. diff -Nur linux-3.18.8/drivers/w1/w1_int.c linux-rpi/drivers/w1/w1_int.c
  124615. --- linux-3.18.8/drivers/w1/w1_int.c 2015-02-27 02:49:36.000000000 +0100
  124616. +++ linux-rpi/drivers/w1/w1_int.c 2015-03-05 14:40:16.945715804 +0100
  124617. @@ -123,6 +123,20 @@
  124618. return(-EINVAL);
  124619. }
  124620. + /* bitbanging hardware uses bitbang_pullup, other hardware uses set_pullup
  124621. + * and takes care of timing itself */
  124622. + if (!master->write_byte && !master->touch_bit && master->set_pullup) {
  124623. + printk(KERN_ERR "w1_add_master_device: set_pullup requires "
  124624. + "write_byte or touch_bit, disabling\n");
  124625. + master->set_pullup = NULL;
  124626. + }
  124627. +
  124628. + if (master->set_pullup && master->bitbang_pullup) {
  124629. + printk(KERN_ERR "w1_add_master_device: set_pullup should not "
  124630. + "be set when bitbang_pullup is used, disabling\n");
  124631. + master->set_pullup = NULL;
  124632. + }
  124633. +
  124634. /* Lock until the device is added (or not) to w1_masters. */
  124635. mutex_lock(&w1_mlock);
  124636. /* Search for the first available id (starting at 1). */
  124637. diff -Nur linux-3.18.8/drivers/w1/w1_io.c linux-rpi/drivers/w1/w1_io.c
  124638. --- linux-3.18.8/drivers/w1/w1_io.c 2015-02-27 02:49:36.000000000 +0100
  124639. +++ linux-rpi/drivers/w1/w1_io.c 2015-03-05 14:40:16.945715804 +0100
  124640. @@ -134,10 +134,22 @@
  124641. static void w1_post_write(struct w1_master *dev)
  124642. {
  124643. if (dev->pullup_duration) {
  124644. - if (dev->enable_pullup && dev->bus_master->set_pullup)
  124645. - dev->bus_master->set_pullup(dev->bus_master->data, 0);
  124646. - else
  124647. + if (dev->enable_pullup) {
  124648. + if (dev->bus_master->set_pullup) {
  124649. + dev->bus_master->set_pullup(dev->
  124650. + bus_master->data,
  124651. + 0);
  124652. + } else if (dev->bus_master->bitbang_pullup) {
  124653. + dev->bus_master->
  124654. + bitbang_pullup(dev->bus_master->data, 1);
  124655. msleep(dev->pullup_duration);
  124656. + dev->bus_master->
  124657. + bitbang_pullup(dev->bus_master->data, 0);
  124658. + }
  124659. + } else {
  124660. + msleep(dev->pullup_duration);
  124661. + }
  124662. +
  124663. dev->pullup_duration = 0;
  124664. }
  124665. }
  124666. diff -Nur linux-3.18.8/drivers/watchdog/bcm2708_wdog.c linux-rpi/drivers/watchdog/bcm2708_wdog.c
  124667. --- linux-3.18.8/drivers/watchdog/bcm2708_wdog.c 1970-01-01 01:00:00.000000000 +0100
  124668. +++ linux-rpi/drivers/watchdog/bcm2708_wdog.c 2015-03-05 14:40:17.125715803 +0100
  124669. @@ -0,0 +1,382 @@
  124670. +/*
  124671. + * Broadcom BCM2708 watchdog driver.
  124672. + *
  124673. + * (c) Copyright 2010 Broadcom Europe Ltd
  124674. + *
  124675. + * This program is free software; you can redistribute it and/or
  124676. + * modify it under the terms of the GNU General Public License
  124677. + * as published by the Free Software Foundation; either version
  124678. + * 2 of the License, or (at your option) any later version.
  124679. + *
  124680. + * BCM2708 watchdog driver. Loosely based on wdt driver.
  124681. + */
  124682. +
  124683. +#include <linux/interrupt.h>
  124684. +#include <linux/module.h>
  124685. +#include <linux/moduleparam.h>
  124686. +#include <linux/types.h>
  124687. +#include <linux/miscdevice.h>
  124688. +#include <linux/watchdog.h>
  124689. +#include <linux/fs.h>
  124690. +#include <linux/ioport.h>
  124691. +#include <linux/notifier.h>
  124692. +#include <linux/reboot.h>
  124693. +#include <linux/init.h>
  124694. +#include <linux/io.h>
  124695. +#include <linux/uaccess.h>
  124696. +#include <mach/platform.h>
  124697. +
  124698. +#define SECS_TO_WDOG_TICKS(x) ((x) << 16)
  124699. +#define WDOG_TICKS_TO_SECS(x) ((x) >> 16)
  124700. +
  124701. +static unsigned long wdog_is_open;
  124702. +static uint32_t wdog_ticks; /* Ticks to load into wdog timer */
  124703. +static char expect_close;
  124704. +
  124705. +/*
  124706. + * Module parameters
  124707. + */
  124708. +
  124709. +#define WD_TIMO 10 /* Default heartbeat = 60 seconds */
  124710. +static int heartbeat = WD_TIMO; /* Heartbeat in seconds */
  124711. +
  124712. +module_param(heartbeat, int, 0);
  124713. +MODULE_PARM_DESC(heartbeat,
  124714. + "Watchdog heartbeat in seconds. (0 < heartbeat < 65536, default="
  124715. + __MODULE_STRING(WD_TIMO) ")");
  124716. +
  124717. +static int nowayout = WATCHDOG_NOWAYOUT;
  124718. +module_param(nowayout, int, 0);
  124719. +MODULE_PARM_DESC(nowayout,
  124720. + "Watchdog cannot be stopped once started (default="
  124721. + __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
  124722. +
  124723. +static DEFINE_SPINLOCK(wdog_lock);
  124724. +
  124725. +/**
  124726. + * Start the watchdog driver.
  124727. + */
  124728. +
  124729. +static int wdog_start(unsigned long timeout)
  124730. +{
  124731. + uint32_t cur;
  124732. + unsigned long flags;
  124733. + spin_lock_irqsave(&wdog_lock, flags);
  124734. +
  124735. + /* enable the watchdog */
  124736. + iowrite32(PM_PASSWORD | (timeout & PM_WDOG_TIME_SET),
  124737. + __io_address(PM_WDOG));
  124738. + cur = ioread32(__io_address(PM_RSTC));
  124739. + iowrite32(PM_PASSWORD | (cur & PM_RSTC_WRCFG_CLR) |
  124740. + PM_RSTC_WRCFG_FULL_RESET, __io_address(PM_RSTC));
  124741. +
  124742. + spin_unlock_irqrestore(&wdog_lock, flags);
  124743. + return 0;
  124744. +}
  124745. +
  124746. +/**
  124747. + * Stop the watchdog driver.
  124748. + */
  124749. +
  124750. +static int wdog_stop(void)
  124751. +{
  124752. + iowrite32(PM_PASSWORD | PM_RSTC_RESET, __io_address(PM_RSTC));
  124753. + printk(KERN_INFO "watchdog stopped\n");
  124754. + return 0;
  124755. +}
  124756. +
  124757. +/**
  124758. + * Reload counter one with the watchdog heartbeat. We don't bother
  124759. + * reloading the cascade counter.
  124760. + */
  124761. +
  124762. +static void wdog_ping(void)
  124763. +{
  124764. + wdog_start(wdog_ticks);
  124765. +}
  124766. +
  124767. +/**
  124768. + * @t: the new heartbeat value that needs to be set.
  124769. + *
  124770. + * Set a new heartbeat value for the watchdog device. If the heartbeat
  124771. + * value is incorrect we keep the old value and return -EINVAL. If
  124772. + * successful we return 0.
  124773. + */
  124774. +
  124775. +static int wdog_set_heartbeat(int t)
  124776. +{
  124777. + if (t < 1 || t > WDOG_TICKS_TO_SECS(PM_WDOG_TIME_SET))
  124778. + return -EINVAL;
  124779. +
  124780. + heartbeat = t;
  124781. + wdog_ticks = SECS_TO_WDOG_TICKS(t);
  124782. + return 0;
  124783. +}
  124784. +
  124785. +/**
  124786. + * @file: file handle to the watchdog
  124787. + * @buf: buffer to write (unused as data does not matter here
  124788. + * @count: count of bytes
  124789. + * @ppos: pointer to the position to write. No seeks allowed
  124790. + *
  124791. + * A write to a watchdog device is defined as a keepalive signal.
  124792. + *
  124793. + * if 'nowayout' is set then normally a close() is ignored. But
  124794. + * if you write 'V' first then the close() will stop the timer.
  124795. + */
  124796. +
  124797. +static ssize_t wdog_write(struct file *file, const char __user *buf,
  124798. + size_t count, loff_t *ppos)
  124799. +{
  124800. + if (count) {
  124801. + if (!nowayout) {
  124802. + size_t i;
  124803. +
  124804. + /* In case it was set long ago */
  124805. + expect_close = 0;
  124806. +
  124807. + for (i = 0; i != count; i++) {
  124808. + char c;
  124809. + if (get_user(c, buf + i))
  124810. + return -EFAULT;
  124811. + if (c == 'V')
  124812. + expect_close = 42;
  124813. + }
  124814. + }
  124815. + wdog_ping();
  124816. + }
  124817. + return count;
  124818. +}
  124819. +
  124820. +static int wdog_get_status(void)
  124821. +{
  124822. + unsigned long flags;
  124823. + int status = 0;
  124824. + spin_lock_irqsave(&wdog_lock, flags);
  124825. + /* FIXME: readback reset reason */
  124826. + spin_unlock_irqrestore(&wdog_lock, flags);
  124827. + return status;
  124828. +}
  124829. +
  124830. +static uint32_t wdog_get_remaining(void)
  124831. +{
  124832. + uint32_t ret = ioread32(__io_address(PM_WDOG));
  124833. + return ret & PM_WDOG_TIME_SET;
  124834. +}
  124835. +
  124836. +/**
  124837. + * @file: file handle to the device
  124838. + * @cmd: watchdog command
  124839. + * @arg: argument pointer
  124840. + *
  124841. + * The watchdog API defines a common set of functions for all watchdogs
  124842. + * according to their available features. We only actually usefully support
  124843. + * querying capabilities and current status.
  124844. + */
  124845. +
  124846. +static long wdog_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  124847. +{
  124848. + void __user *argp = (void __user *)arg;
  124849. + int __user *p = argp;
  124850. + int new_heartbeat;
  124851. + int status;
  124852. + int options;
  124853. + uint32_t remaining;
  124854. +
  124855. + struct watchdog_info ident = {
  124856. + .options = WDIOF_SETTIMEOUT|
  124857. + WDIOF_MAGICCLOSE|
  124858. + WDIOF_KEEPALIVEPING,
  124859. + .firmware_version = 1,
  124860. + .identity = "BCM2708",
  124861. + };
  124862. +
  124863. + switch (cmd) {
  124864. + case WDIOC_GETSUPPORT:
  124865. + return copy_to_user(argp, &ident, sizeof(ident)) ? -EFAULT : 0;
  124866. + case WDIOC_GETSTATUS:
  124867. + status = wdog_get_status();
  124868. + return put_user(status, p);
  124869. + case WDIOC_GETBOOTSTATUS:
  124870. + return put_user(0, p);
  124871. + case WDIOC_KEEPALIVE:
  124872. + wdog_ping();
  124873. + return 0;
  124874. + case WDIOC_SETTIMEOUT:
  124875. + if (get_user(new_heartbeat, p))
  124876. + return -EFAULT;
  124877. + if (wdog_set_heartbeat(new_heartbeat))
  124878. + return -EINVAL;
  124879. + wdog_ping();
  124880. + /* Fall */
  124881. + case WDIOC_GETTIMEOUT:
  124882. + return put_user(heartbeat, p);
  124883. + case WDIOC_GETTIMELEFT:
  124884. + remaining = WDOG_TICKS_TO_SECS(wdog_get_remaining());
  124885. + return put_user(remaining, p);
  124886. + case WDIOC_SETOPTIONS:
  124887. + if (get_user(options, p))
  124888. + return -EFAULT;
  124889. + if (options & WDIOS_DISABLECARD)
  124890. + wdog_stop();
  124891. + if (options & WDIOS_ENABLECARD)
  124892. + wdog_start(wdog_ticks);
  124893. + return 0;
  124894. + default:
  124895. + return -ENOTTY;
  124896. + }
  124897. +}
  124898. +
  124899. +/**
  124900. + * @inode: inode of device
  124901. + * @file: file handle to device
  124902. + *
  124903. + * The watchdog device has been opened. The watchdog device is single
  124904. + * open and on opening we load the counters.
  124905. + */
  124906. +
  124907. +static int wdog_open(struct inode *inode, struct file *file)
  124908. +{
  124909. + if (test_and_set_bit(0, &wdog_is_open))
  124910. + return -EBUSY;
  124911. + /*
  124912. + * Activate
  124913. + */
  124914. + wdog_start(wdog_ticks);
  124915. + return nonseekable_open(inode, file);
  124916. +}
  124917. +
  124918. +/**
  124919. + * @inode: inode to board
  124920. + * @file: file handle to board
  124921. + *
  124922. + * The watchdog has a configurable API. There is a religious dispute
  124923. + * between people who want their watchdog to be able to shut down and
  124924. + * those who want to be sure if the watchdog manager dies the machine
  124925. + * reboots. In the former case we disable the counters, in the latter
  124926. + * case you have to open it again very soon.
  124927. + */
  124928. +
  124929. +static int wdog_release(struct inode *inode, struct file *file)
  124930. +{
  124931. + if (expect_close == 42) {
  124932. + wdog_stop();
  124933. + } else {
  124934. + printk(KERN_CRIT
  124935. + "wdt: WDT device closed unexpectedly. WDT will not stop!\n");
  124936. + wdog_ping();
  124937. + }
  124938. + clear_bit(0, &wdog_is_open);
  124939. + expect_close = 0;
  124940. + return 0;
  124941. +}
  124942. +
  124943. +/**
  124944. + * @this: our notifier block
  124945. + * @code: the event being reported
  124946. + * @unused: unused
  124947. + *
  124948. + * Our notifier is called on system shutdowns. Turn the watchdog
  124949. + * off so that it does not fire during the next reboot.
  124950. + */
  124951. +
  124952. +static int wdog_notify_sys(struct notifier_block *this, unsigned long code,
  124953. + void *unused)
  124954. +{
  124955. + if (code == SYS_DOWN || code == SYS_HALT)
  124956. + wdog_stop();
  124957. + return NOTIFY_DONE;
  124958. +}
  124959. +
  124960. +/*
  124961. + * Kernel Interfaces
  124962. + */
  124963. +
  124964. +
  124965. +static const struct file_operations wdog_fops = {
  124966. + .owner = THIS_MODULE,
  124967. + .llseek = no_llseek,
  124968. + .write = wdog_write,
  124969. + .unlocked_ioctl = wdog_ioctl,
  124970. + .open = wdog_open,
  124971. + .release = wdog_release,
  124972. +};
  124973. +
  124974. +static struct miscdevice wdog_miscdev = {
  124975. + .minor = WATCHDOG_MINOR,
  124976. + .name = "watchdog",
  124977. + .fops = &wdog_fops,
  124978. +};
  124979. +
  124980. +/*
  124981. + * The WDT card needs to learn about soft shutdowns in order to
  124982. + * turn the timebomb registers off.
  124983. + */
  124984. +
  124985. +static struct notifier_block wdog_notifier = {
  124986. + .notifier_call = wdog_notify_sys,
  124987. +};
  124988. +
  124989. +/**
  124990. + * cleanup_module:
  124991. + *
  124992. + * Unload the watchdog. You cannot do this with any file handles open.
  124993. + * If your watchdog is set to continue ticking on close and you unload
  124994. + * it, well it keeps ticking. We won't get the interrupt but the board
  124995. + * will not touch PC memory so all is fine. You just have to load a new
  124996. + * module in 60 seconds or reboot.
  124997. + */
  124998. +
  124999. +static void __exit wdog_exit(void)
  125000. +{
  125001. + misc_deregister(&wdog_miscdev);
  125002. + unregister_reboot_notifier(&wdog_notifier);
  125003. +}
  125004. +
  125005. +static int __init wdog_init(void)
  125006. +{
  125007. + int ret;
  125008. +
  125009. + /* Check that the heartbeat value is within it's range;
  125010. + if not reset to the default */
  125011. + if (wdog_set_heartbeat(heartbeat)) {
  125012. + wdog_set_heartbeat(WD_TIMO);
  125013. + printk(KERN_INFO "bcm2708_wdog: heartbeat value must be "
  125014. + "0 < heartbeat < %d, using %d\n",
  125015. + WDOG_TICKS_TO_SECS(PM_WDOG_TIME_SET),
  125016. + WD_TIMO);
  125017. + }
  125018. +
  125019. + ret = register_reboot_notifier(&wdog_notifier);
  125020. + if (ret) {
  125021. + printk(KERN_ERR
  125022. + "wdt: cannot register reboot notifier (err=%d)\n", ret);
  125023. + goto out_reboot;
  125024. + }
  125025. +
  125026. + ret = misc_register(&wdog_miscdev);
  125027. + if (ret) {
  125028. + printk(KERN_ERR
  125029. + "wdt: cannot register miscdev on minor=%d (err=%d)\n",
  125030. + WATCHDOG_MINOR, ret);
  125031. + goto out_misc;
  125032. + }
  125033. +
  125034. + printk(KERN_INFO "bcm2708 watchdog, heartbeat=%d sec (nowayout=%d)\n",
  125035. + heartbeat, nowayout);
  125036. + return 0;
  125037. +
  125038. +out_misc:
  125039. + unregister_reboot_notifier(&wdog_notifier);
  125040. +out_reboot:
  125041. + return ret;
  125042. +}
  125043. +
  125044. +module_init(wdog_init);
  125045. +module_exit(wdog_exit);
  125046. +
  125047. +MODULE_AUTHOR("Luke Diamand");
  125048. +MODULE_DESCRIPTION("Driver for BCM2708 watchdog");
  125049. +MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
  125050. +MODULE_ALIAS_MISCDEV(TEMP_MINOR);
  125051. +MODULE_LICENSE("GPL");
  125052. diff -Nur linux-3.18.8/drivers/watchdog/Kconfig linux-rpi/drivers/watchdog/Kconfig
  125053. --- linux-3.18.8/drivers/watchdog/Kconfig 2015-02-27 02:49:36.000000000 +0100
  125054. +++ linux-rpi/drivers/watchdog/Kconfig 2015-03-05 14:40:16.945715804 +0100
  125055. @@ -452,6 +452,12 @@
  125056. To compile this driver as a module, choose M here: the
  125057. module will be called retu_wdt.
  125058. +config BCM2708_WDT
  125059. + tristate "BCM2708 Watchdog"
  125060. + depends on ARCH_BCM2708 || ARCH_BCM2709
  125061. + help
  125062. + Enables BCM2708 watchdog support.
  125063. +
  125064. config MOXART_WDT
  125065. tristate "MOXART watchdog"
  125066. depends on ARCH_MOXART
  125067. diff -Nur linux-3.18.8/drivers/watchdog/Makefile linux-rpi/drivers/watchdog/Makefile
  125068. --- linux-3.18.8/drivers/watchdog/Makefile 2015-02-27 02:49:36.000000000 +0100
  125069. +++ linux-rpi/drivers/watchdog/Makefile 2015-03-05 14:40:16.945715804 +0100
  125070. @@ -56,6 +56,7 @@
  125071. obj-$(CONFIG_IMX2_WDT) += imx2_wdt.o
  125072. obj-$(CONFIG_UX500_WATCHDOG) += ux500_wdt.o
  125073. obj-$(CONFIG_RETU_WATCHDOG) += retu_wdt.o
  125074. +obj-$(CONFIG_BCM2708_WDT) += bcm2708_wdog.o
  125075. obj-$(CONFIG_BCM2835_WDT) += bcm2835_wdt.o
  125076. obj-$(CONFIG_MOXART_WDT) += moxart_wdt.o
  125077. obj-$(CONFIG_SIRFSOC_WATCHDOG) += sirfsoc_wdt.o
  125078. diff -Nur linux-3.18.8/.git/config linux-rpi/.git/config
  125079. --- linux-3.18.8/.git/config 1970-01-01 01:00:00.000000000 +0100
  125080. +++ linux-rpi/.git/config 2015-03-05 14:40:10.485715843 +0100
  125081. @@ -0,0 +1,12 @@
  125082. +[core]
  125083. + repositoryformatversion = 0
  125084. + filemode = true
  125085. + bare = false
  125086. + logallrefupdates = true
  125087. +[remote "origin"]
  125088. + url = https://github.com/raspberrypi/linux.git
  125089. + fetch = +refs/heads/*:refs/remotes/origin/*
  125090. +[branch "rpi-3.18.y"]
  125091. + remote = origin
  125092. + merge = refs/heads/rpi-3.18.y
  125093. + rebase = true
  125094. diff -Nur linux-3.18.8/.git/description linux-rpi/.git/description
  125095. --- linux-3.18.8/.git/description 1970-01-01 01:00:00.000000000 +0100
  125096. +++ linux-rpi/.git/description 2015-03-05 14:30:30.653719385 +0100
  125097. @@ -0,0 +1 @@
  125098. +Unnamed repository; edit this file 'description' to name the repository.
  125099. diff -Nur linux-3.18.8/.git/HEAD linux-rpi/.git/HEAD
  125100. --- linux-3.18.8/.git/HEAD 1970-01-01 01:00:00.000000000 +0100
  125101. +++ linux-rpi/.git/HEAD 2015-03-05 14:40:10.453715844 +0100
  125102. @@ -0,0 +1 @@
  125103. +ref: refs/heads/rpi-3.18.y
  125104. diff -Nur linux-3.18.8/.git/hooks/applypatch-msg.sample linux-rpi/.git/hooks/applypatch-msg.sample
  125105. --- linux-3.18.8/.git/hooks/applypatch-msg.sample 1970-01-01 01:00:00.000000000 +0100
  125106. +++ linux-rpi/.git/hooks/applypatch-msg.sample 2015-03-05 14:30:30.665719385 +0100
  125107. @@ -0,0 +1,15 @@
  125108. +#!/bin/sh
  125109. +#
  125110. +# An example hook script to check the commit log message taken by
  125111. +# applypatch from an e-mail message.
  125112. +#
  125113. +# The hook should exit with non-zero status after issuing an
  125114. +# appropriate message if it wants to stop the commit. The hook is
  125115. +# allowed to edit the commit message file.
  125116. +#
  125117. +# To enable this hook, rename this file to "applypatch-msg".
  125118. +
  125119. +. git-sh-setup
  125120. +test -x "$GIT_DIR/hooks/commit-msg" &&
  125121. + exec "$GIT_DIR/hooks/commit-msg" ${1+"$@"}
  125122. +:
  125123. diff -Nur linux-3.18.8/.git/hooks/commit-msg.sample linux-rpi/.git/hooks/commit-msg.sample
  125124. --- linux-3.18.8/.git/hooks/commit-msg.sample 1970-01-01 01:00:00.000000000 +0100
  125125. +++ linux-rpi/.git/hooks/commit-msg.sample 2015-03-05 14:30:30.661719385 +0100
  125126. @@ -0,0 +1,24 @@
  125127. +#!/bin/sh
  125128. +#
  125129. +# An example hook script to check the commit log message.
  125130. +# Called by "git commit" with one argument, the name of the file
  125131. +# that has the commit message. The hook should exit with non-zero
  125132. +# status after issuing an appropriate message if it wants to stop the
  125133. +# commit. The hook is allowed to edit the commit message file.
  125134. +#
  125135. +# To enable this hook, rename this file to "commit-msg".
  125136. +
  125137. +# Uncomment the below to add a Signed-off-by line to the message.
  125138. +# Doing this in a hook is a bad idea in general, but the prepare-commit-msg
  125139. +# hook is more suited to it.
  125140. +#
  125141. +# SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p')
  125142. +# grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1"
  125143. +
  125144. +# This example catches duplicate Signed-off-by lines.
  125145. +
  125146. +test "" = "$(grep '^Signed-off-by: ' "$1" |
  125147. + sort | uniq -c | sed -e '/^[ ]*1[ ]/d')" || {
  125148. + echo >&2 Duplicate Signed-off-by lines.
  125149. + exit 1
  125150. +}
  125151. diff -Nur linux-3.18.8/.git/hooks/post-update.sample linux-rpi/.git/hooks/post-update.sample
  125152. --- linux-3.18.8/.git/hooks/post-update.sample 1970-01-01 01:00:00.000000000 +0100
  125153. +++ linux-rpi/.git/hooks/post-update.sample 2015-03-05 14:30:30.665719385 +0100
  125154. @@ -0,0 +1,8 @@
  125155. +#!/bin/sh
  125156. +#
  125157. +# An example hook script to prepare a packed repository for use over
  125158. +# dumb transports.
  125159. +#
  125160. +# To enable this hook, rename this file to "post-update".
  125161. +
  125162. +exec git update-server-info
  125163. diff -Nur linux-3.18.8/.git/hooks/pre-applypatch.sample linux-rpi/.git/hooks/pre-applypatch.sample
  125164. --- linux-3.18.8/.git/hooks/pre-applypatch.sample 1970-01-01 01:00:00.000000000 +0100
  125165. +++ linux-rpi/.git/hooks/pre-applypatch.sample 2015-03-05 14:30:30.661719385 +0100
  125166. @@ -0,0 +1,14 @@
  125167. +#!/bin/sh
  125168. +#
  125169. +# An example hook script to verify what is about to be committed
  125170. +# by applypatch from an e-mail message.
  125171. +#
  125172. +# The hook should exit with non-zero status after issuing an
  125173. +# appropriate message if it wants to stop the commit.
  125174. +#
  125175. +# To enable this hook, rename this file to "pre-applypatch".
  125176. +
  125177. +. git-sh-setup
  125178. +test -x "$GIT_DIR/hooks/pre-commit" &&
  125179. + exec "$GIT_DIR/hooks/pre-commit" ${1+"$@"}
  125180. +:
  125181. diff -Nur linux-3.18.8/.git/hooks/pre-commit.sample linux-rpi/.git/hooks/pre-commit.sample
  125182. --- linux-3.18.8/.git/hooks/pre-commit.sample 1970-01-01 01:00:00.000000000 +0100
  125183. +++ linux-rpi/.git/hooks/pre-commit.sample 2015-03-05 14:30:30.661719385 +0100
  125184. @@ -0,0 +1,49 @@
  125185. +#!/bin/sh
  125186. +#
  125187. +# An example hook script to verify what is about to be committed.
  125188. +# Called by "git commit" with no arguments. The hook should
  125189. +# exit with non-zero status after issuing an appropriate message if
  125190. +# it wants to stop the commit.
  125191. +#
  125192. +# To enable this hook, rename this file to "pre-commit".
  125193. +
  125194. +if git rev-parse --verify HEAD >/dev/null 2>&1
  125195. +then
  125196. + against=HEAD
  125197. +else
  125198. + # Initial commit: diff against an empty tree object
  125199. + against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
  125200. +fi
  125201. +
  125202. +# If you want to allow non-ASCII filenames set this variable to true.
  125203. +allownonascii=$(git config --bool hooks.allownonascii)
  125204. +
  125205. +# Redirect output to stderr.
  125206. +exec 1>&2
  125207. +
  125208. +# Cross platform projects tend to avoid non-ASCII filenames; prevent
  125209. +# them from being added to the repository. We exploit the fact that the
  125210. +# printable range starts at the space character and ends with tilde.
  125211. +if [ "$allownonascii" != "true" ] &&
  125212. + # Note that the use of brackets around a tr range is ok here, (it's
  125213. + # even required, for portability to Solaris 10's /usr/bin/tr), since
  125214. + # the square bracket bytes happen to fall in the designated range.
  125215. + test $(git diff --cached --name-only --diff-filter=A -z $against |
  125216. + LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0
  125217. +then
  125218. + cat <<\EOF
  125219. +Error: Attempt to add a non-ASCII file name.
  125220. +
  125221. +This can cause problems if you want to work with people on other platforms.
  125222. +
  125223. +To be portable it is advisable to rename the file.
  125224. +
  125225. +If you know what you are doing you can disable this check using:
  125226. +
  125227. + git config hooks.allownonascii true
  125228. +EOF
  125229. + exit 1
  125230. +fi
  125231. +
  125232. +# If there are whitespace errors, print the offending file names and fail.
  125233. +exec git diff-index --check --cached $against --
  125234. diff -Nur linux-3.18.8/.git/hooks/prepare-commit-msg.sample linux-rpi/.git/hooks/prepare-commit-msg.sample
  125235. --- linux-3.18.8/.git/hooks/prepare-commit-msg.sample 1970-01-01 01:00:00.000000000 +0100
  125236. +++ linux-rpi/.git/hooks/prepare-commit-msg.sample 2015-03-05 14:30:30.665719385 +0100
  125237. @@ -0,0 +1,36 @@
  125238. +#!/bin/sh
  125239. +#
  125240. +# An example hook script to prepare the commit log message.
  125241. +# Called by "git commit" with the name of the file that has the
  125242. +# commit message, followed by the description of the commit
  125243. +# message's source. The hook's purpose is to edit the commit
  125244. +# message file. If the hook fails with a non-zero status,
  125245. +# the commit is aborted.
  125246. +#
  125247. +# To enable this hook, rename this file to "prepare-commit-msg".
  125248. +
  125249. +# This hook includes three examples. The first comments out the
  125250. +# "Conflicts:" part of a merge commit.
  125251. +#
  125252. +# The second includes the output of "git diff --name-status -r"
  125253. +# into the message, just before the "git status" output. It is
  125254. +# commented because it doesn't cope with --amend or with squashed
  125255. +# commits.
  125256. +#
  125257. +# The third example adds a Signed-off-by line to the message, that can
  125258. +# still be edited. This is rarely a good idea.
  125259. +
  125260. +case "$2,$3" in
  125261. + merge,)
  125262. + /usr/bin/perl -i.bak -ne 's/^/# /, s/^# #/#/ if /^Conflicts/ .. /#/; print' "$1" ;;
  125263. +
  125264. +# ,|template,)
  125265. +# /usr/bin/perl -i.bak -pe '
  125266. +# print "\n" . `git diff --cached --name-status -r`
  125267. +# if /^#/ && $first++ == 0' "$1" ;;
  125268. +
  125269. + *) ;;
  125270. +esac
  125271. +
  125272. +# SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p')
  125273. +# grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1"
  125274. diff -Nur linux-3.18.8/.git/hooks/pre-push.sample linux-rpi/.git/hooks/pre-push.sample
  125275. --- linux-3.18.8/.git/hooks/pre-push.sample 1970-01-01 01:00:00.000000000 +0100
  125276. +++ linux-rpi/.git/hooks/pre-push.sample 2015-03-05 14:30:30.661719385 +0100
  125277. @@ -0,0 +1,54 @@
  125278. +#!/bin/sh
  125279. +
  125280. +# An example hook script to verify what is about to be pushed. Called by "git
  125281. +# push" after it has checked the remote status, but before anything has been
  125282. +# pushed. If this script exits with a non-zero status nothing will be pushed.
  125283. +#
  125284. +# This hook is called with the following parameters:
  125285. +#
  125286. +# $1 -- Name of the remote to which the push is being done
  125287. +# $2 -- URL to which the push is being done
  125288. +#
  125289. +# If pushing without using a named remote those arguments will be equal.
  125290. +#
  125291. +# Information about the commits which are being pushed is supplied as lines to
  125292. +# the standard input in the form:
  125293. +#
  125294. +# <local ref> <local sha1> <remote ref> <remote sha1>
  125295. +#
  125296. +# This sample shows how to prevent push of commits where the log message starts
  125297. +# with "WIP" (work in progress).
  125298. +
  125299. +remote="$1"
  125300. +url="$2"
  125301. +
  125302. +z40=0000000000000000000000000000000000000000
  125303. +
  125304. +IFS=' '
  125305. +while read local_ref local_sha remote_ref remote_sha
  125306. +do
  125307. + if [ "$local_sha" = $z40 ]
  125308. + then
  125309. + # Handle delete
  125310. + :
  125311. + else
  125312. + if [ "$remote_sha" = $z40 ]
  125313. + then
  125314. + # New branch, examine all commits
  125315. + range="$local_sha"
  125316. + else
  125317. + # Update to existing branch, examine new commits
  125318. + range="$remote_sha..$local_sha"
  125319. + fi
  125320. +
  125321. + # Check for WIP commit
  125322. + commit=`git rev-list -n 1 --grep '^WIP' "$range"`
  125323. + if [ -n "$commit" ]
  125324. + then
  125325. + echo "Found WIP commit in $local_ref, not pushing"
  125326. + exit 1
  125327. + fi
  125328. + fi
  125329. +done
  125330. +
  125331. +exit 0
  125332. diff -Nur linux-3.18.8/.git/hooks/pre-rebase.sample linux-rpi/.git/hooks/pre-rebase.sample
  125333. --- linux-3.18.8/.git/hooks/pre-rebase.sample 1970-01-01 01:00:00.000000000 +0100
  125334. +++ linux-rpi/.git/hooks/pre-rebase.sample 2015-03-05 14:30:30.661719385 +0100
  125335. @@ -0,0 +1,169 @@
  125336. +#!/bin/sh
  125337. +#
  125338. +# Copyright (c) 2006, 2008 Junio C Hamano
  125339. +#
  125340. +# The "pre-rebase" hook is run just before "git rebase" starts doing
  125341. +# its job, and can prevent the command from running by exiting with
  125342. +# non-zero status.
  125343. +#
  125344. +# The hook is called with the following parameters:
  125345. +#
  125346. +# $1 -- the upstream the series was forked from.
  125347. +# $2 -- the branch being rebased (or empty when rebasing the current branch).
  125348. +#
  125349. +# This sample shows how to prevent topic branches that are already
  125350. +# merged to 'next' branch from getting rebased, because allowing it
  125351. +# would result in rebasing already published history.
  125352. +
  125353. +publish=next
  125354. +basebranch="$1"
  125355. +if test "$#" = 2
  125356. +then
  125357. + topic="refs/heads/$2"
  125358. +else
  125359. + topic=`git symbolic-ref HEAD` ||
  125360. + exit 0 ;# we do not interrupt rebasing detached HEAD
  125361. +fi
  125362. +
  125363. +case "$topic" in
  125364. +refs/heads/??/*)
  125365. + ;;
  125366. +*)
  125367. + exit 0 ;# we do not interrupt others.
  125368. + ;;
  125369. +esac
  125370. +
  125371. +# Now we are dealing with a topic branch being rebased
  125372. +# on top of master. Is it OK to rebase it?
  125373. +
  125374. +# Does the topic really exist?
  125375. +git show-ref -q "$topic" || {
  125376. + echo >&2 "No such branch $topic"
  125377. + exit 1
  125378. +}
  125379. +
  125380. +# Is topic fully merged to master?
  125381. +not_in_master=`git rev-list --pretty=oneline ^master "$topic"`
  125382. +if test -z "$not_in_master"
  125383. +then
  125384. + echo >&2 "$topic is fully merged to master; better remove it."
  125385. + exit 1 ;# we could allow it, but there is no point.
  125386. +fi
  125387. +
  125388. +# Is topic ever merged to next? If so you should not be rebasing it.
  125389. +only_next_1=`git rev-list ^master "^$topic" ${publish} | sort`
  125390. +only_next_2=`git rev-list ^master ${publish} | sort`
  125391. +if test "$only_next_1" = "$only_next_2"
  125392. +then
  125393. + not_in_topic=`git rev-list "^$topic" master`
  125394. + if test -z "$not_in_topic"
  125395. + then
  125396. + echo >&2 "$topic is already up-to-date with master"
  125397. + exit 1 ;# we could allow it, but there is no point.
  125398. + else
  125399. + exit 0
  125400. + fi
  125401. +else
  125402. + not_in_next=`git rev-list --pretty=oneline ^${publish} "$topic"`
  125403. + /usr/bin/perl -e '
  125404. + my $topic = $ARGV[0];
  125405. + my $msg = "* $topic has commits already merged to public branch:\n";
  125406. + my (%not_in_next) = map {
  125407. + /^([0-9a-f]+) /;
  125408. + ($1 => 1);
  125409. + } split(/\n/, $ARGV[1]);
  125410. + for my $elem (map {
  125411. + /^([0-9a-f]+) (.*)$/;
  125412. + [$1 => $2];
  125413. + } split(/\n/, $ARGV[2])) {
  125414. + if (!exists $not_in_next{$elem->[0]}) {
  125415. + if ($msg) {
  125416. + print STDERR $msg;
  125417. + undef $msg;
  125418. + }
  125419. + print STDERR " $elem->[1]\n";
  125420. + }
  125421. + }
  125422. + ' "$topic" "$not_in_next" "$not_in_master"
  125423. + exit 1
  125424. +fi
  125425. +
  125426. +<<\DOC_END
  125427. +
  125428. +This sample hook safeguards topic branches that have been
  125429. +published from being rewound.
  125430. +
  125431. +The workflow assumed here is:
  125432. +
  125433. + * Once a topic branch forks from "master", "master" is never
  125434. + merged into it again (either directly or indirectly).
  125435. +
  125436. + * Once a topic branch is fully cooked and merged into "master",
  125437. + it is deleted. If you need to build on top of it to correct
  125438. + earlier mistakes, a new topic branch is created by forking at
  125439. + the tip of the "master". This is not strictly necessary, but
  125440. + it makes it easier to keep your history simple.
  125441. +
  125442. + * Whenever you need to test or publish your changes to topic
  125443. + branches, merge them into "next" branch.
  125444. +
  125445. +The script, being an example, hardcodes the publish branch name
  125446. +to be "next", but it is trivial to make it configurable via
  125447. +$GIT_DIR/config mechanism.
  125448. +
  125449. +With this workflow, you would want to know:
  125450. +
  125451. +(1) ... if a topic branch has ever been merged to "next". Young
  125452. + topic branches can have stupid mistakes you would rather
  125453. + clean up before publishing, and things that have not been
  125454. + merged into other branches can be easily rebased without
  125455. + affecting other people. But once it is published, you would
  125456. + not want to rewind it.
  125457. +
  125458. +(2) ... if a topic branch has been fully merged to "master".
  125459. + Then you can delete it. More importantly, you should not
  125460. + build on top of it -- other people may already want to
  125461. + change things related to the topic as patches against your
  125462. + "master", so if you need further changes, it is better to
  125463. + fork the topic (perhaps with the same name) afresh from the
  125464. + tip of "master".
  125465. +
  125466. +Let's look at this example:
  125467. +
  125468. + o---o---o---o---o---o---o---o---o---o "next"
  125469. + / / / /
  125470. + / a---a---b A / /
  125471. + / / / /
  125472. + / / c---c---c---c B /
  125473. + / / / \ /
  125474. + / / / b---b C \ /
  125475. + / / / / \ /
  125476. + ---o---o---o---o---o---o---o---o---o---o---o "master"
  125477. +
  125478. +
  125479. +A, B and C are topic branches.
  125480. +
  125481. + * A has one fix since it was merged up to "next".
  125482. +
  125483. + * B has finished. It has been fully merged up to "master" and "next",
  125484. + and is ready to be deleted.
  125485. +
  125486. + * C has not merged to "next" at all.
  125487. +
  125488. +We would want to allow C to be rebased, refuse A, and encourage
  125489. +B to be deleted.
  125490. +
  125491. +To compute (1):
  125492. +
  125493. + git rev-list ^master ^topic next
  125494. + git rev-list ^master next
  125495. +
  125496. + if these match, topic has not merged in next at all.
  125497. +
  125498. +To compute (2):
  125499. +
  125500. + git rev-list master..topic
  125501. +
  125502. + if this is empty, it is fully merged to "master".
  125503. +
  125504. +DOC_END
  125505. diff -Nur linux-3.18.8/.git/hooks/update.sample linux-rpi/.git/hooks/update.sample
  125506. --- linux-3.18.8/.git/hooks/update.sample 1970-01-01 01:00:00.000000000 +0100
  125507. +++ linux-rpi/.git/hooks/update.sample 2015-03-05 14:30:30.665719385 +0100
  125508. @@ -0,0 +1,128 @@
  125509. +#!/bin/sh
  125510. +#
  125511. +# An example hook script to blocks unannotated tags from entering.
  125512. +# Called by "git receive-pack" with arguments: refname sha1-old sha1-new
  125513. +#
  125514. +# To enable this hook, rename this file to "update".
  125515. +#
  125516. +# Config
  125517. +# ------
  125518. +# hooks.allowunannotated
  125519. +# This boolean sets whether unannotated tags will be allowed into the
  125520. +# repository. By default they won't be.
  125521. +# hooks.allowdeletetag
  125522. +# This boolean sets whether deleting tags will be allowed in the
  125523. +# repository. By default they won't be.
  125524. +# hooks.allowmodifytag
  125525. +# This boolean sets whether a tag may be modified after creation. By default
  125526. +# it won't be.
  125527. +# hooks.allowdeletebranch
  125528. +# This boolean sets whether deleting branches will be allowed in the
  125529. +# repository. By default they won't be.
  125530. +# hooks.denycreatebranch
  125531. +# This boolean sets whether remotely creating branches will be denied
  125532. +# in the repository. By default this is allowed.
  125533. +#
  125534. +
  125535. +# --- Command line
  125536. +refname="$1"
  125537. +oldrev="$2"
  125538. +newrev="$3"
  125539. +
  125540. +# --- Safety check
  125541. +if [ -z "$GIT_DIR" ]; then
  125542. + echo "Don't run this script from the command line." >&2
  125543. + echo " (if you want, you could supply GIT_DIR then run" >&2
  125544. + echo " $0 <ref> <oldrev> <newrev>)" >&2
  125545. + exit 1
  125546. +fi
  125547. +
  125548. +if [ -z "$refname" -o -z "$oldrev" -o -z "$newrev" ]; then
  125549. + echo "usage: $0 <ref> <oldrev> <newrev>" >&2
  125550. + exit 1
  125551. +fi
  125552. +
  125553. +# --- Config
  125554. +allowunannotated=$(git config --bool hooks.allowunannotated)
  125555. +allowdeletebranch=$(git config --bool hooks.allowdeletebranch)
  125556. +denycreatebranch=$(git config --bool hooks.denycreatebranch)
  125557. +allowdeletetag=$(git config --bool hooks.allowdeletetag)
  125558. +allowmodifytag=$(git config --bool hooks.allowmodifytag)
  125559. +
  125560. +# check for no description
  125561. +projectdesc=$(sed -e '1q' "$GIT_DIR/description")
  125562. +case "$projectdesc" in
  125563. +"Unnamed repository"* | "")
  125564. + echo "*** Project description file hasn't been set" >&2
  125565. + exit 1
  125566. + ;;
  125567. +esac
  125568. +
  125569. +# --- Check types
  125570. +# if $newrev is 0000...0000, it's a commit to delete a ref.
  125571. +zero="0000000000000000000000000000000000000000"
  125572. +if [ "$newrev" = "$zero" ]; then
  125573. + newrev_type=delete
  125574. +else
  125575. + newrev_type=$(git cat-file -t $newrev)
  125576. +fi
  125577. +
  125578. +case "$refname","$newrev_type" in
  125579. + refs/tags/*,commit)
  125580. + # un-annotated tag
  125581. + short_refname=${refname##refs/tags/}
  125582. + if [ "$allowunannotated" != "true" ]; then
  125583. + echo "*** The un-annotated tag, $short_refname, is not allowed in this repository" >&2
  125584. + echo "*** Use 'git tag [ -a | -s ]' for tags you want to propagate." >&2
  125585. + exit 1
  125586. + fi
  125587. + ;;
  125588. + refs/tags/*,delete)
  125589. + # delete tag
  125590. + if [ "$allowdeletetag" != "true" ]; then
  125591. + echo "*** Deleting a tag is not allowed in this repository" >&2
  125592. + exit 1
  125593. + fi
  125594. + ;;
  125595. + refs/tags/*,tag)
  125596. + # annotated tag
  125597. + if [ "$allowmodifytag" != "true" ] && git rev-parse $refname > /dev/null 2>&1
  125598. + then
  125599. + echo "*** Tag '$refname' already exists." >&2
  125600. + echo "*** Modifying a tag is not allowed in this repository." >&2
  125601. + exit 1
  125602. + fi
  125603. + ;;
  125604. + refs/heads/*,commit)
  125605. + # branch
  125606. + if [ "$oldrev" = "$zero" -a "$denycreatebranch" = "true" ]; then
  125607. + echo "*** Creating a branch is not allowed in this repository" >&2
  125608. + exit 1
  125609. + fi
  125610. + ;;
  125611. + refs/heads/*,delete)
  125612. + # delete branch
  125613. + if [ "$allowdeletebranch" != "true" ]; then
  125614. + echo "*** Deleting a branch is not allowed in this repository" >&2
  125615. + exit 1
  125616. + fi
  125617. + ;;
  125618. + refs/remotes/*,commit)
  125619. + # tracking branch
  125620. + ;;
  125621. + refs/remotes/*,delete)
  125622. + # delete tracking branch
  125623. + if [ "$allowdeletebranch" != "true" ]; then
  125624. + echo "*** Deleting a tracking branch is not allowed in this repository" >&2
  125625. + exit 1
  125626. + fi
  125627. + ;;
  125628. + *)
  125629. + # Anything else (is there anything else?)
  125630. + echo "*** Update hook: unknown type of update to ref $refname of type $newrev_type" >&2
  125631. + exit 1
  125632. + ;;
  125633. +esac
  125634. +
  125635. +# --- Finished
  125636. +exit 0
  125637. Binary files linux-3.18.8/.git/index and linux-rpi/.git/index differ
  125638. diff -Nur linux-3.18.8/.git/info/exclude linux-rpi/.git/info/exclude
  125639. --- linux-3.18.8/.git/info/exclude 1970-01-01 01:00:00.000000000 +0100
  125640. +++ linux-rpi/.git/info/exclude 2015-03-05 14:30:30.665719385 +0100
  125641. @@ -0,0 +1,6 @@
  125642. +# git ls-files --others --exclude-from=.git/info/exclude
  125643. +# Lines that start with '#' are comments.
  125644. +# For a project mostly in C, the following would be a good set of
  125645. +# exclude patterns (uncomment them if you want to use them):
  125646. +# *.[oa]
  125647. +# *~
  125648. diff -Nur linux-3.18.8/.git/logs/HEAD linux-rpi/.git/logs/HEAD
  125649. --- linux-3.18.8/.git/logs/HEAD 1970-01-01 01:00:00.000000000 +0100
  125650. +++ linux-rpi/.git/logs/HEAD 2015-03-05 14:40:10.473715843 +0100
  125651. @@ -0,0 +1 @@
  125652. +0000000000000000000000000000000000000000 91a03559bbc1b5cb2b1157150c1c698b22716d9a Waldemar Brodkorb <wbrodkorb@conet.de> 1425562810 +0100 clone: from https://github.com/raspberrypi/linux.git
  125653. diff -Nur linux-3.18.8/.git/logs/refs/heads/rpi-3.18.y linux-rpi/.git/logs/refs/heads/rpi-3.18.y
  125654. --- linux-3.18.8/.git/logs/refs/heads/rpi-3.18.y 1970-01-01 01:00:00.000000000 +0100
  125655. +++ linux-rpi/.git/logs/refs/heads/rpi-3.18.y 2015-03-05 14:40:10.473715843 +0100
  125656. @@ -0,0 +1 @@
  125657. +0000000000000000000000000000000000000000 91a03559bbc1b5cb2b1157150c1c698b22716d9a Waldemar Brodkorb <wbrodkorb@conet.de> 1425562810 +0100 clone: from https://github.com/raspberrypi/linux.git
  125658. diff -Nur linux-3.18.8/.git/logs/refs/remotes/origin/HEAD linux-rpi/.git/logs/refs/remotes/origin/HEAD
  125659. --- linux-3.18.8/.git/logs/refs/remotes/origin/HEAD 1970-01-01 01:00:00.000000000 +0100
  125660. +++ linux-rpi/.git/logs/refs/remotes/origin/HEAD 2015-03-05 14:40:10.453715844 +0100
  125661. @@ -0,0 +1 @@
  125662. +0000000000000000000000000000000000000000 91a03559bbc1b5cb2b1157150c1c698b22716d9a Waldemar Brodkorb <wbrodkorb@conet.de> 1425562810 +0100 clone: from https://github.com/raspberrypi/linux.git
  125663. Binary files linux-3.18.8/.git/objects/pack/pack-adde7c3e99c2b64cc24940bb435fac50f0e72e20.idx and linux-rpi/.git/objects/pack/pack-adde7c3e99c2b64cc24940bb435fac50f0e72e20.idx differ
  125664. Binary files linux-3.18.8/.git/objects/pack/pack-adde7c3e99c2b64cc24940bb435fac50f0e72e20.pack and linux-rpi/.git/objects/pack/pack-adde7c3e99c2b64cc24940bb435fac50f0e72e20.pack differ
  125665. diff -Nur linux-3.18.8/.git/packed-refs linux-rpi/.git/packed-refs
  125666. --- linux-3.18.8/.git/packed-refs 1970-01-01 01:00:00.000000000 +0100
  125667. +++ linux-rpi/.git/packed-refs 2015-03-05 14:40:10.453715844 +0100
  125668. @@ -0,0 +1,20 @@
  125669. +# pack-refs with: peeled fully-peeled
  125670. +645fd9b0c0b3c1f79f71f92dac79bd2f87010444 refs/remotes/origin/master
  125671. +1b49b450222df26e4abf7abb6d9302f72b2ed386 refs/remotes/origin/rpi-3.10.y
  125672. +d894df614c20e2f56ce0ff0576a4c517352684de refs/remotes/origin/rpi-3.10.y-next
  125673. +8f768c5f2a3314e4eacce8d667c787f8dadfda74 refs/remotes/origin/rpi-3.11.y
  125674. +ee9b8c7d46f2b1787b1e64604acafc70f70191cf refs/remotes/origin/rpi-3.12.y
  125675. +a26c4d1f1428082f6aba79207535527c91115c76 refs/remotes/origin/rpi-3.13.y
  125676. +2514e943096ff51dd5a83b28b4b4d45ec2693434 refs/remotes/origin/rpi-3.13.y-next
  125677. +e294028d7733a30f3befacc41d473c251096a515 refs/remotes/origin/rpi-3.14.y
  125678. +8812404b672364ee794411ed19080dc9b6287682 refs/remotes/origin/rpi-3.15.y
  125679. +377c82aa1d31b37f1096096b0e4c65beb0bc5c49 refs/remotes/origin/rpi-3.16.y
  125680. +a2a6c3e259254f3687bde843f4caff011611cf7e refs/remotes/origin/rpi-3.17.y
  125681. +91a03559bbc1b5cb2b1157150c1c698b22716d9a refs/remotes/origin/rpi-3.18.y
  125682. +086127cc3f5fa6818a993965f9c753ede3a569da refs/remotes/origin/rpi-3.18.y-rebase
  125683. +d4d542c792f6ab98cb76d4ae71a9497e98b20cfa refs/remotes/origin/rpi-3.19.y
  125684. +ada8b4415ff44d535d63e4291a0eca733bc2ad0f refs/remotes/origin/rpi-3.2.27
  125685. +2a8d45ec0883e3cbdce920855b3461ac77308a5f refs/remotes/origin/rpi-3.6.y
  125686. +d996a1b91b2bf3dc06f4f4f822a56f4496457aa1 refs/remotes/origin/rpi-3.8.y
  125687. +d5572370289f698b101f3d0198b1c99f17f0d278 refs/remotes/origin/rpi-3.9.y
  125688. +8fa2e19c4fdbe17704947e444674e19ea47c8ddd refs/remotes/origin/rpi-patches
  125689. diff -Nur linux-3.18.8/.git/refs/heads/rpi-3.18.y linux-rpi/.git/refs/heads/rpi-3.18.y
  125690. --- linux-3.18.8/.git/refs/heads/rpi-3.18.y 1970-01-01 01:00:00.000000000 +0100
  125691. +++ linux-rpi/.git/refs/heads/rpi-3.18.y 2015-03-05 14:40:10.473715843 +0100
  125692. @@ -0,0 +1 @@
  125693. +91a03559bbc1b5cb2b1157150c1c698b22716d9a
  125694. diff -Nur linux-3.18.8/.git/refs/remotes/origin/HEAD linux-rpi/.git/refs/remotes/origin/HEAD
  125695. --- linux-3.18.8/.git/refs/remotes/origin/HEAD 1970-01-01 01:00:00.000000000 +0100
  125696. +++ linux-rpi/.git/refs/remotes/origin/HEAD 2015-03-05 14:40:10.453715844 +0100
  125697. @@ -0,0 +1 @@
  125698. +ref: refs/remotes/origin/rpi-3.18.y
  125699. diff -Nur linux-3.18.8/include/linux/broadcom/vc_cma.h linux-rpi/include/linux/broadcom/vc_cma.h
  125700. --- linux-3.18.8/include/linux/broadcom/vc_cma.h 1970-01-01 01:00:00.000000000 +0100
  125701. +++ linux-rpi/include/linux/broadcom/vc_cma.h 2015-03-05 14:40:17.829715798 +0100
  125702. @@ -0,0 +1,29 @@
  125703. +/*****************************************************************************
  125704. +* Copyright 2012 Broadcom Corporation. All rights reserved.
  125705. +*
  125706. +* Unless you and Broadcom execute a separate written software license
  125707. +* agreement governing use of this software, this software is licensed to you
  125708. +* under the terms of the GNU General Public License version 2, available at
  125709. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  125710. +*
  125711. +* Notwithstanding the above, under no circumstances may you combine this
  125712. +* software in any way with any other Broadcom software provided under a
  125713. +* license other than the GPL, without Broadcom's express prior written
  125714. +* consent.
  125715. +*****************************************************************************/
  125716. +
  125717. +#if !defined( VC_CMA_H )
  125718. +#define VC_CMA_H
  125719. +
  125720. +#include <linux/ioctl.h>
  125721. +
  125722. +#define VC_CMA_IOC_MAGIC 0xc5
  125723. +
  125724. +#define VC_CMA_IOC_RESERVE _IO(VC_CMA_IOC_MAGIC, 0)
  125725. +
  125726. +#ifdef __KERNEL__
  125727. +extern void __init vc_cma_early_init(void);
  125728. +extern void __init vc_cma_reserve(void);
  125729. +#endif
  125730. +
  125731. +#endif /* VC_CMA_H */
  125732. diff -Nur linux-3.18.8/include/linux/mmc/host.h linux-rpi/include/linux/mmc/host.h
  125733. --- linux-3.18.8/include/linux/mmc/host.h 2015-02-27 02:49:36.000000000 +0100
  125734. +++ linux-rpi/include/linux/mmc/host.h 2015-03-05 14:40:18.025715797 +0100
  125735. @@ -290,6 +290,7 @@
  125736. #define MMC_CAP2_HS400 (MMC_CAP2_HS400_1_8V | \
  125737. MMC_CAP2_HS400_1_2V)
  125738. #define MMC_CAP2_SDIO_IRQ_NOTHREAD (1 << 17)
  125739. +#define MMC_CAP2_FORCE_MULTIBLOCK (1 << 31) /* Always use multiblock transfers */
  125740. mmc_pm_flag_t pm_caps; /* supported pm features */
  125741. diff -Nur linux-3.18.8/include/linux/mmc/sdhci.h linux-rpi/include/linux/mmc/sdhci.h
  125742. --- linux-3.18.8/include/linux/mmc/sdhci.h 2015-02-27 02:49:36.000000000 +0100
  125743. +++ linux-rpi/include/linux/mmc/sdhci.h 2015-03-05 14:40:18.025715797 +0100
  125744. @@ -130,6 +130,7 @@
  125745. #define SDHCI_SDIO_IRQ_ENABLED (1<<9) /* SDIO irq enabled */
  125746. #define SDHCI_SDR104_NEEDS_TUNING (1<<10) /* SDR104/HS200 needs tuning */
  125747. #define SDHCI_USING_RETUNING_TIMER (1<<11) /* Host is using a retuning timer for the card */
  125748. +#define SDHCI_USE_PLATDMA (1<<12) /* Host uses 3rd party DMA */
  125749. unsigned int version; /* SDHCI spec. version */
  125750. diff -Nur linux-3.18.8/include/linux/platform_data/bcm2708.h linux-rpi/include/linux/platform_data/bcm2708.h
  125751. --- linux-3.18.8/include/linux/platform_data/bcm2708.h 1970-01-01 01:00:00.000000000 +0100
  125752. +++ linux-rpi/include/linux/platform_data/bcm2708.h 2015-03-05 14:40:18.169715796 +0100
  125753. @@ -0,0 +1,23 @@
  125754. +/*
  125755. + * include/linux/platform_data/bcm2708.h
  125756. + *
  125757. + * This program is free software; you can redistribute it and/or modify
  125758. + * it under the terms of the GNU General Public License version 2 as
  125759. + * published by the Free Software Foundation.
  125760. + *
  125761. + * (C) 2014 Julian Scheel <julian@jusst.de>
  125762. + *
  125763. + */
  125764. +#ifndef __BCM2708_H_
  125765. +#define __BCM2708_H_
  125766. +
  125767. +typedef enum {
  125768. + BCM2708_PULL_OFF,
  125769. + BCM2708_PULL_UP,
  125770. + BCM2708_PULL_DOWN
  125771. +} bcm2708_gpio_pull_t;
  125772. +
  125773. +extern int bcm2708_gpio_setpull(struct gpio_chip *gc, unsigned offset,
  125774. + bcm2708_gpio_pull_t value);
  125775. +
  125776. +#endif
  125777. diff -Nur linux-3.18.8/include/linux/vmstat.h linux-rpi/include/linux/vmstat.h
  125778. --- linux-3.18.8/include/linux/vmstat.h 2015-02-27 02:49:36.000000000 +0100
  125779. +++ linux-rpi/include/linux/vmstat.h 2015-03-05 14:40:18.249715796 +0100
  125780. @@ -241,7 +241,11 @@
  125781. static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
  125782. {
  125783. atomic_long_dec(&zone->vm_stat[item]);
  125784. + if (item == NR_FILE_DIRTY && unlikely(atomic_long_read(&zone->vm_stat[item]) < 0))
  125785. + atomic_long_set(&zone->vm_stat[item], 0);
  125786. atomic_long_dec(&vm_stat[item]);
  125787. + if (item == NR_FILE_DIRTY && unlikely(atomic_long_read(&vm_stat[item]) < 0))
  125788. + atomic_long_set(&vm_stat[item], 0);
  125789. }
  125790. static inline void __inc_zone_page_state(struct page *page,
  125791. diff -Nur linux-3.18.8/include/linux/w1-gpio.h linux-rpi/include/linux/w1-gpio.h
  125792. --- linux-3.18.8/include/linux/w1-gpio.h 2015-02-27 02:49:36.000000000 +0100
  125793. +++ linux-rpi/include/linux/w1-gpio.h 2015-03-05 14:40:18.249715796 +0100
  125794. @@ -18,6 +18,7 @@
  125795. struct w1_gpio_platform_data {
  125796. unsigned int pin;
  125797. unsigned int is_open_drain:1;
  125798. + unsigned int parasitic_power:1;
  125799. void (*enable_external_pullup)(int enable);
  125800. unsigned int ext_pullup_enable_pin;
  125801. unsigned int pullup_duration;
  125802. diff -Nur linux-3.18.8/include/uapi/linux/fb.h linux-rpi/include/uapi/linux/fb.h
  125803. --- linux-3.18.8/include/uapi/linux/fb.h 2015-02-27 02:49:36.000000000 +0100
  125804. +++ linux-rpi/include/uapi/linux/fb.h 2015-03-05 14:40:18.293715796 +0100
  125805. @@ -34,6 +34,11 @@
  125806. #define FBIOPUT_MODEINFO 0x4617
  125807. #define FBIOGET_DISPINFO 0x4618
  125808. #define FBIO_WAITFORVSYNC _IOW('F', 0x20, __u32)
  125809. +/*
  125810. + * HACK: use 'z' in order not to clash with any other ioctl numbers which might
  125811. + * be concurrently added to the mainline kernel
  125812. + */
  125813. +#define FBIOCOPYAREA _IOW('z', 0x21, struct fb_copyarea)
  125814. #define FB_TYPE_PACKED_PIXELS 0 /* Packed Pixels */
  125815. #define FB_TYPE_PLANES 1 /* Non interleaved planes */
  125816. diff -Nur linux-3.18.8/kernel/cgroup.c linux-rpi/kernel/cgroup.c
  125817. --- linux-3.18.8/kernel/cgroup.c 2015-02-27 02:49:36.000000000 +0100
  125818. +++ linux-rpi/kernel/cgroup.c 2015-03-05 14:40:18.445715795 +0100
  125819. @@ -5322,6 +5322,29 @@
  125820. }
  125821. __setup("cgroup_disable=", cgroup_disable);
  125822. +static int __init cgroup_enable(char *str)
  125823. +{
  125824. + struct cgroup_subsys *ss;
  125825. + char *token;
  125826. + int i;
  125827. +
  125828. + while ((token = strsep(&str, ",")) != NULL) {
  125829. + if (!*token)
  125830. + continue;
  125831. +
  125832. + for_each_subsys(ss, i) {
  125833. + if (!strcmp(token, ss->name)) {
  125834. + ss->disabled = 0;
  125835. + printk(KERN_INFO "Enabling %s control group"
  125836. + " subsystem\n", ss->name);
  125837. + break;
  125838. + }
  125839. + }
  125840. + }
  125841. + return 1;
  125842. +}
  125843. +__setup("cgroup_enable=", cgroup_enable);
  125844. +
  125845. static int __init cgroup_set_legacy_files_on_dfl(char *str)
  125846. {
  125847. printk("cgroup: using legacy files on the default hierarchy\n");
  125848. diff -Nur linux-3.18.8/kernel/time/ntp.c linux-rpi/kernel/time/ntp.c
  125849. --- linux-3.18.8/kernel/time/ntp.c 2015-02-27 02:49:36.000000000 +0100
  125850. +++ linux-rpi/kernel/time/ntp.c 2015-03-05 14:40:18.469715795 +0100
  125851. @@ -634,9 +634,9 @@
  125852. return -EPERM;
  125853. if (txc->modes & ADJ_FREQUENCY) {
  125854. - if (LONG_MIN / PPM_SCALE > txc->freq)
  125855. + if (LLONG_MIN / PPM_SCALE > txc->freq)
  125856. return -EINVAL;
  125857. - if (LONG_MAX / PPM_SCALE < txc->freq)
  125858. + if (LLONG_MAX / PPM_SCALE < txc->freq)
  125859. return -EINVAL;
  125860. }
  125861. diff -Nur linux-3.18.8/mm/memcontrol.c linux-rpi/mm/memcontrol.c
  125862. --- linux-3.18.8/mm/memcontrol.c 2015-02-27 02:49:36.000000000 +0100
  125863. +++ linux-rpi/mm/memcontrol.c 2015-03-05 14:40:18.497715794 +0100
  125864. @@ -6207,6 +6207,7 @@
  125865. .bind = mem_cgroup_bind,
  125866. .legacy_cftypes = mem_cgroup_files,
  125867. .early_init = 0,
  125868. + .disabled = 1,
  125869. };
  125870. #ifdef CONFIG_MEMCG_SWAP
  125871. diff -Nur linux-3.18.8/scripts/dtc/checks.c linux-rpi/scripts/dtc/checks.c
  125872. --- linux-3.18.8/scripts/dtc/checks.c 2015-02-27 02:49:36.000000000 +0100
  125873. +++ linux-rpi/scripts/dtc/checks.c 2015-03-05 14:40:18.909715792 +0100
  125874. @@ -53,7 +53,7 @@
  125875. void *data;
  125876. bool warn, error;
  125877. enum checkstatus status;
  125878. - int inprogress;
  125879. + bool inprogress;
  125880. int num_prereqs;
  125881. struct check **prereq;
  125882. };
  125883. @@ -113,6 +113,7 @@
  125884. vfprintf(stderr, fmt, ap);
  125885. fprintf(stderr, "\n");
  125886. }
  125887. + va_end(ap);
  125888. }
  125889. #define FAIL(c, ...) \
  125890. @@ -141,9 +142,9 @@
  125891. check_nodes_props(c, dt, child);
  125892. }
  125893. -static int run_check(struct check *c, struct node *dt)
  125894. +static bool run_check(struct check *c, struct node *dt)
  125895. {
  125896. - int error = 0;
  125897. + bool error = false;
  125898. int i;
  125899. assert(!c->inprogress);
  125900. @@ -151,11 +152,11 @@
  125901. if (c->status != UNCHECKED)
  125902. goto out;
  125903. - c->inprogress = 1;
  125904. + c->inprogress = true;
  125905. for (i = 0; i < c->num_prereqs; i++) {
  125906. struct check *prq = c->prereq[i];
  125907. - error |= run_check(prq, dt);
  125908. + error = error || run_check(prq, dt);
  125909. if (prq->status != PASSED) {
  125910. c->status = PREREQ;
  125911. check_msg(c, "Failed prerequisite '%s'",
  125912. @@ -177,9 +178,9 @@
  125913. TRACE(c, "\tCompleted, status %d", c->status);
  125914. out:
  125915. - c->inprogress = 0;
  125916. + c->inprogress = false;
  125917. if ((c->status != PASSED) && (c->error))
  125918. - error = 1;
  125919. + error = true;
  125920. return error;
  125921. }
  125922. @@ -457,22 +458,93 @@
  125923. struct node *node, struct property *prop)
  125924. {
  125925. struct marker *m = prop->val.markers;
  125926. + struct fixup *f, **fp;
  125927. + struct fixup_entry *fe, **fep;
  125928. struct node *refnode;
  125929. cell_t phandle;
  125930. + int has_phandle_refs;
  125931. +
  125932. + has_phandle_refs = 0;
  125933. + for_each_marker_of_type(m, REF_PHANDLE) {
  125934. + has_phandle_refs = 1;
  125935. + break;
  125936. + }
  125937. +
  125938. + if (!has_phandle_refs)
  125939. + return;
  125940. for_each_marker_of_type(m, REF_PHANDLE) {
  125941. assert(m->offset + sizeof(cell_t) <= prop->val.len);
  125942. refnode = get_node_by_ref(dt, m->ref);
  125943. - if (! refnode) {
  125944. + if (!refnode && !symbol_fixup_support) {
  125945. FAIL(c, "Reference to non-existent node or label \"%s\"\n",
  125946. - m->ref);
  125947. + m->ref);
  125948. continue;
  125949. }
  125950. - phandle = get_node_phandle(dt, refnode);
  125951. - *((cell_t *)(prop->val.val + m->offset)) = cpu_to_fdt32(phandle);
  125952. + if (!refnode) {
  125953. + /* allocate fixup entry */
  125954. + fe = xmalloc(sizeof(*fe));
  125955. +
  125956. + fe->node = node;
  125957. + fe->prop = prop;
  125958. + fe->offset = m->offset;
  125959. + fe->next = NULL;
  125960. +
  125961. + /* search for an already existing fixup */
  125962. + for_each_fixup(dt, f)
  125963. + if (strcmp(f->ref, m->ref) == 0)
  125964. + break;
  125965. +
  125966. + /* no fixup found, add new */
  125967. + if (f == NULL) {
  125968. + f = xmalloc(sizeof(*f));
  125969. + f->ref = m->ref;
  125970. + f->entries = NULL;
  125971. + f->next = NULL;
  125972. +
  125973. + /* add it to the tree */
  125974. + fp = &dt->fixups;
  125975. + while (*fp)
  125976. + fp = &(*fp)->next;
  125977. + *fp = f;
  125978. + }
  125979. +
  125980. + /* and now append fixup entry */
  125981. + fep = &f->entries;
  125982. + while (*fep)
  125983. + fep = &(*fep)->next;
  125984. + *fep = fe;
  125985. +
  125986. + /* mark the entry as unresolved */
  125987. + phandle = 0xdeadbeef;
  125988. + } else {
  125989. + phandle = get_node_phandle(dt, refnode);
  125990. +
  125991. + /* if it's a plugin, we need to record it */
  125992. + if (symbol_fixup_support && dt->is_plugin) {
  125993. +
  125994. + /* allocate a new local fixup entry */
  125995. + fe = xmalloc(sizeof(*fe));
  125996. +
  125997. + fe->node = node;
  125998. + fe->prop = prop;
  125999. + fe->offset = m->offset;
  126000. + fe->next = NULL;
  126001. +
  126002. + /* append it to the local fixups */
  126003. + fep = &dt->local_fixups;
  126004. + while (*fep)
  126005. + fep = &(*fep)->next;
  126006. + *fep = fe;
  126007. + }
  126008. + }
  126009. +
  126010. + *((cell_t *)(prop->val.val + m->offset)) =
  126011. + cpu_to_fdt32(phandle);
  126012. }
  126013. +
  126014. }
  126015. ERROR(phandle_references, NULL, NULL, fixup_phandle_references, NULL,
  126016. &duplicate_node_names, &explicit_phandles);
  126017. @@ -624,11 +696,11 @@
  126018. if (!reg && !ranges)
  126019. return;
  126020. - if ((node->parent->addr_cells == -1))
  126021. + if (node->parent->addr_cells == -1)
  126022. FAIL(c, "Relying on default #address-cells value for %s",
  126023. node->fullpath);
  126024. - if ((node->parent->size_cells == -1))
  126025. + if (node->parent->size_cells == -1)
  126026. FAIL(c, "Relying on default #size-cells value for %s",
  126027. node->fullpath);
  126028. }
  126029. @@ -651,6 +723,45 @@
  126030. }
  126031. TREE_WARNING(obsolete_chosen_interrupt_controller, NULL);
  126032. +static void check_auto_label_phandles(struct check *c, struct node *dt,
  126033. + struct node *node)
  126034. +{
  126035. + struct label *l;
  126036. + struct symbol *s, **sp;
  126037. + int has_label;
  126038. +
  126039. + if (!symbol_fixup_support)
  126040. + return;
  126041. +
  126042. + has_label = 0;
  126043. + for_each_label(node->labels, l) {
  126044. + has_label = 1;
  126045. + break;
  126046. + }
  126047. +
  126048. + if (!has_label)
  126049. + return;
  126050. +
  126051. + /* force allocation of a phandle for this node */
  126052. + (void)get_node_phandle(dt, node);
  126053. +
  126054. + /* add the symbol */
  126055. + for_each_label(node->labels, l) {
  126056. +
  126057. + s = xmalloc(sizeof(*s));
  126058. + s->label = l;
  126059. + s->node = node;
  126060. + s->next = NULL;
  126061. +
  126062. + /* add it to the symbols list */
  126063. + sp = &dt->symbols;
  126064. + while (*sp)
  126065. + sp = &((*sp)->next);
  126066. + *sp = s;
  126067. + }
  126068. +}
  126069. +NODE_WARNING(auto_label_phandles, NULL);
  126070. +
  126071. static struct check *check_table[] = {
  126072. &duplicate_node_names, &duplicate_property_names,
  126073. &node_name_chars, &node_name_format, &property_name_chars,
  126074. @@ -669,6 +780,8 @@
  126075. &avoid_default_addr_size,
  126076. &obsolete_chosen_interrupt_controller,
  126077. + &auto_label_phandles,
  126078. +
  126079. &always_fail,
  126080. };
  126081. @@ -706,15 +819,15 @@
  126082. c->error = c->error && !error;
  126083. }
  126084. -void parse_checks_option(bool warn, bool error, const char *optarg)
  126085. +void parse_checks_option(bool warn, bool error, const char *arg)
  126086. {
  126087. int i;
  126088. - const char *name = optarg;
  126089. + const char *name = arg;
  126090. bool enable = true;
  126091. - if ((strncmp(optarg, "no-", 3) == 0)
  126092. - || (strncmp(optarg, "no_", 3) == 0)) {
  126093. - name = optarg + 3;
  126094. + if ((strncmp(arg, "no-", 3) == 0)
  126095. + || (strncmp(arg, "no_", 3) == 0)) {
  126096. + name = arg + 3;
  126097. enable = false;
  126098. }
  126099. @@ -733,7 +846,7 @@
  126100. die("Unrecognized check name \"%s\"\n", name);
  126101. }
  126102. -void process_checks(int force, struct boot_info *bi)
  126103. +void process_checks(bool force, struct boot_info *bi)
  126104. {
  126105. struct node *dt = bi->dt;
  126106. int i;
  126107. diff -Nur linux-3.18.8/scripts/dtc/data.c linux-rpi/scripts/dtc/data.c
  126108. --- linux-3.18.8/scripts/dtc/data.c 2015-02-27 02:49:36.000000000 +0100
  126109. +++ linux-rpi/scripts/dtc/data.c 2015-03-05 14:40:18.909715792 +0100
  126110. @@ -74,7 +74,7 @@
  126111. struct data d;
  126112. char *q;
  126113. - d = data_grow_for(empty_data, strlen(s)+1);
  126114. + d = data_grow_for(empty_data, len + 1);
  126115. q = d.val;
  126116. while (i < len) {
  126117. @@ -250,20 +250,20 @@
  126118. return data_append_markers(d, m);
  126119. }
  126120. -int data_is_one_string(struct data d)
  126121. +bool data_is_one_string(struct data d)
  126122. {
  126123. int i;
  126124. int len = d.len;
  126125. if (len == 0)
  126126. - return 0;
  126127. + return false;
  126128. for (i = 0; i < len-1; i++)
  126129. if (d.val[i] == '\0')
  126130. - return 0;
  126131. + return false;
  126132. if (d.val[len-1] != '\0')
  126133. - return 0;
  126134. + return false;
  126135. - return 1;
  126136. + return true;
  126137. }
  126138. diff -Nur linux-3.18.8/scripts/dtc/dtc.c linux-rpi/scripts/dtc/dtc.c
  126139. --- linux-3.18.8/scripts/dtc/dtc.c 2015-02-27 02:49:36.000000000 +0100
  126140. +++ linux-rpi/scripts/dtc/dtc.c 2015-03-05 14:40:18.913715792 +0100
  126141. @@ -29,6 +29,7 @@
  126142. int minsize; /* Minimum blob size */
  126143. int padsize; /* Additional padding to blob */
  126144. int phandle_format = PHANDLE_BOTH; /* Use linux,phandle or phandle properties */
  126145. +int symbol_fixup_support = 0;
  126146. static void fill_fullpaths(struct node *tree, const char *prefix)
  126147. {
  126148. @@ -48,8 +49,10 @@
  126149. }
  126150. /* Usage related data. */
  126151. +#define FDT_VERSION(version) _FDT_VERSION(version)
  126152. +#define _FDT_VERSION(version) #version
  126153. static const char usage_synopsis[] = "dtc [options] <input file>";
  126154. -static const char usage_short_opts[] = "qI:O:o:V:d:R:S:p:fb:i:H:sW:E:hv";
  126155. +static const char usage_short_opts[] = "qI:O:o:V:d:R:S:p:fb:i:H:sW:E:hv@";
  126156. static struct option const usage_long_opts[] = {
  126157. {"quiet", no_argument, NULL, 'q'},
  126158. {"in-format", a_argument, NULL, 'I'},
  126159. @@ -67,6 +70,7 @@
  126160. {"phandle", a_argument, NULL, 'H'},
  126161. {"warning", a_argument, NULL, 'W'},
  126162. {"error", a_argument, NULL, 'E'},
  126163. + {"symbols", a_argument, NULL, '@'},
  126164. {"help", no_argument, NULL, 'h'},
  126165. {"version", no_argument, NULL, 'v'},
  126166. {NULL, no_argument, NULL, 0x0},
  126167. @@ -82,9 +86,9 @@
  126168. "\t\tdts - device tree source text\n"
  126169. "\t\tdtb - device tree blob\n"
  126170. "\t\tasm - assembler source",
  126171. - "\n\tBlob version to produce, defaults to %d (for dtb and asm output)", //, DEFAULT_FDT_VERSION);
  126172. + "\n\tBlob version to produce, defaults to "FDT_VERSION(DEFAULT_FDT_VERSION)" (for dtb and asm output)",
  126173. "\n\tOutput dependency file",
  126174. - "\n\ttMake space for <number> reserve map entries (for dtb and asm output)",
  126175. + "\n\tMake space for <number> reserve map entries (for dtb and asm output)",
  126176. "\n\tMake the blob at least <bytes> long (extra space)",
  126177. "\n\tAdd padding to the blob of <bytes> long (extra space)",
  126178. "\n\tSet the physical boot cpu",
  126179. @@ -97,6 +101,7 @@
  126180. "\t\tboth - Both \"linux,phandle\" and \"phandle\" properties",
  126181. "\n\tEnable/disable warnings (prefix with \"no-\")",
  126182. "\n\tEnable/disable errors (prefix with \"no-\")",
  126183. + "\n\tSymbols and Fixups support",
  126184. "\n\tPrint this help and exit",
  126185. "\n\tPrint version and exit",
  126186. NULL,
  126187. @@ -109,7 +114,7 @@
  126188. const char *outform = "dts";
  126189. const char *outname = "-";
  126190. const char *depname = NULL;
  126191. - int force = 0, sort = 0;
  126192. + bool force = false, sort = false;
  126193. const char *arg;
  126194. int opt;
  126195. FILE *outf = NULL;
  126196. @@ -148,7 +153,7 @@
  126197. padsize = strtol(optarg, NULL, 0);
  126198. break;
  126199. case 'f':
  126200. - force = 1;
  126201. + force = true;
  126202. break;
  126203. case 'q':
  126204. quiet++;
  126205. @@ -174,7 +179,7 @@
  126206. break;
  126207. case 's':
  126208. - sort = 1;
  126209. + sort = true;
  126210. break;
  126211. case 'W':
  126212. @@ -184,7 +189,9 @@
  126213. case 'E':
  126214. parse_checks_option(false, true, optarg);
  126215. break;
  126216. -
  126217. + case '@':
  126218. + symbol_fixup_support = 1;
  126219. + break;
  126220. case 'h':
  126221. usage(NULL);
  126222. default:
  126223. @@ -237,7 +244,7 @@
  126224. if (streq(outname, "-")) {
  126225. outf = stdout;
  126226. } else {
  126227. - outf = fopen(outname, "w");
  126228. + outf = fopen(outname, "wb");
  126229. if (! outf)
  126230. die("Couldn't open output file %s: %s\n",
  126231. outname, strerror(errno));
  126232. diff -Nur linux-3.18.8/scripts/dtc/dtc.h linux-rpi/scripts/dtc/dtc.h
  126233. --- linux-3.18.8/scripts/dtc/dtc.h 2015-02-27 02:49:36.000000000 +0100
  126234. +++ linux-rpi/scripts/dtc/dtc.h 2015-03-05 14:40:18.913715792 +0100
  126235. @@ -38,9 +38,9 @@
  126236. #include "util.h"
  126237. #ifdef DEBUG
  126238. -#define debug(fmt,args...) printf(fmt, ##args)
  126239. +#define debug(...) printf(__VA_ARGS__)
  126240. #else
  126241. -#define debug(fmt,args...)
  126242. +#define debug(...)
  126243. #endif
  126244. @@ -54,6 +54,7 @@
  126245. extern int minsize; /* Minimum blob size */
  126246. extern int padsize; /* Additional padding to blob */
  126247. extern int phandle_format; /* Use linux,phandle or phandle properties */
  126248. +extern int symbol_fixup_support;/* enable symbols & fixup support */
  126249. #define PHANDLE_LEGACY 0x1
  126250. #define PHANDLE_EPAPR 0x2
  126251. @@ -88,7 +89,7 @@
  126252. };
  126253. -#define empty_data ((struct data){ /* all .members = 0 or NULL */ })
  126254. +#define empty_data ((struct data){ 0 /* all .members = 0 or NULL */ })
  126255. #define for_each_marker(m) \
  126256. for (; (m); (m) = (m)->next)
  126257. @@ -118,7 +119,7 @@
  126258. struct data data_add_marker(struct data d, enum markertype type, char *ref);
  126259. -int data_is_one_string(struct data d);
  126260. +bool data_is_one_string(struct data d);
  126261. /* DT constraints */
  126262. @@ -127,13 +128,32 @@
  126263. /* Live trees */
  126264. struct label {
  126265. - int deleted;
  126266. + bool deleted;
  126267. char *label;
  126268. struct label *next;
  126269. };
  126270. +struct fixup_entry {
  126271. + int offset;
  126272. + struct node *node;
  126273. + struct property *prop;
  126274. + struct fixup_entry *next;
  126275. +};
  126276. +
  126277. +struct fixup {
  126278. + char *ref;
  126279. + struct fixup_entry *entries;
  126280. + struct fixup *next;
  126281. +};
  126282. +
  126283. +struct symbol {
  126284. + struct label *label;
  126285. + struct node *node;
  126286. + struct symbol *next;
  126287. +};
  126288. +
  126289. struct property {
  126290. - int deleted;
  126291. + bool deleted;
  126292. char *name;
  126293. struct data val;
  126294. @@ -143,7 +163,7 @@
  126295. };
  126296. struct node {
  126297. - int deleted;
  126298. + bool deleted;
  126299. char *name;
  126300. struct property *proplist;
  126301. struct node *children;
  126302. @@ -158,6 +178,12 @@
  126303. int addr_cells, size_cells;
  126304. struct label *labels;
  126305. +
  126306. + int is_root;
  126307. + int is_plugin;
  126308. + struct fixup *fixups;
  126309. + struct symbol *symbols;
  126310. + struct fixup_entry *local_fixups;
  126311. };
  126312. #define for_each_label_withdel(l0, l) \
  126313. @@ -181,6 +207,18 @@
  126314. for_each_child_withdel(n, c) \
  126315. if (!(c)->deleted)
  126316. +#define for_each_fixup(n, f) \
  126317. + for ((f) = (n)->fixups; (f); (f) = (f)->next)
  126318. +
  126319. +#define for_each_fixup_entry(f, fe) \
  126320. + for ((fe) = (f)->entries; (fe); (fe) = (fe)->next)
  126321. +
  126322. +#define for_each_symbol(n, s) \
  126323. + for ((s) = (n)->symbols; (s); (s) = (s)->next)
  126324. +
  126325. +#define for_each_local_fixup_entry(n, fe) \
  126326. + for ((fe) = (n)->local_fixups; (fe); (fe) = (fe)->next)
  126327. +
  126328. void add_label(struct label **labels, char *label);
  126329. void delete_labels(struct label **labels);
  126330. @@ -247,8 +285,8 @@
  126331. /* Checks */
  126332. -void parse_checks_option(bool warn, bool error, const char *optarg);
  126333. -void process_checks(int force, struct boot_info *bi);
  126334. +void parse_checks_option(bool warn, bool error, const char *arg);
  126335. +void process_checks(bool force, struct boot_info *bi);
  126336. /* Flattened trees */
  126337. diff -Nur linux-3.18.8/scripts/dtc/dtc-lexer.l linux-rpi/scripts/dtc/dtc-lexer.l
  126338. --- linux-3.18.8/scripts/dtc/dtc-lexer.l 2015-02-27 02:49:36.000000000 +0100
  126339. +++ linux-rpi/scripts/dtc/dtc-lexer.l 2015-03-05 14:40:18.909715792 +0100
  126340. @@ -20,7 +20,6 @@
  126341. %option noyywrap nounput noinput never-interactive
  126342. -%x INCLUDE
  126343. %x BYTESTRING
  126344. %x PROPNODENAME
  126345. %s V1
  126346. @@ -40,6 +39,7 @@
  126347. #include "dtc-parser.tab.h"
  126348. YYLTYPE yylloc;
  126349. +extern bool treesource_error;
  126350. /* CAUTION: this will stop working if we ever use yyless() or yyunput() */
  126351. #define YY_USER_ACTION \
  126352. @@ -61,7 +61,8 @@
  126353. BEGIN(V1); \
  126354. static void push_input_file(const char *filename);
  126355. -static int pop_input_file(void);
  126356. +static bool pop_input_file(void);
  126357. +static void lexical_error(const char *fmt, ...);
  126358. %}
  126359. %%
  126360. @@ -75,11 +76,11 @@
  126361. char *line, *tmp, *fn;
  126362. /* skip text before line # */
  126363. line = yytext;
  126364. - while (!isdigit(*line))
  126365. + while (!isdigit((unsigned char)*line))
  126366. line++;
  126367. /* skip digits in line # */
  126368. tmp = line;
  126369. - while (!isspace(*tmp))
  126370. + while (!isspace((unsigned char)*tmp))
  126371. tmp++;
  126372. /* "NULL"-terminate line # */
  126373. *tmp = '\0';
  126374. @@ -112,6 +113,11 @@
  126375. return DT_V1;
  126376. }
  126377. +<*>"/plugin/" {
  126378. + DPRINT("Keyword: /plugin/\n");
  126379. + return DT_PLUGIN;
  126380. + }
  126381. +
  126382. <*>"/memreserve/" {
  126383. DPRINT("Keyword: /memreserve/\n");
  126384. BEGIN_DEFAULT();
  126385. @@ -146,15 +152,42 @@
  126386. }
  126387. <V1>([0-9]+|0[xX][0-9a-fA-F]+)(U|L|UL|LL|ULL)? {
  126388. - yylval.literal = xstrdup(yytext);
  126389. - DPRINT("Literal: '%s'\n", yylval.literal);
  126390. + char *e;
  126391. + DPRINT("Integer Literal: '%s'\n", yytext);
  126392. +
  126393. + errno = 0;
  126394. + yylval.integer = strtoull(yytext, &e, 0);
  126395. +
  126396. + assert(!(*e) || !e[strspn(e, "UL")]);
  126397. +
  126398. + if (errno == ERANGE)
  126399. + lexical_error("Integer literal '%s' out of range",
  126400. + yytext);
  126401. + else
  126402. + /* ERANGE is the only strtoull error triggerable
  126403. + * by strings matching the pattern */
  126404. + assert(errno == 0);
  126405. return DT_LITERAL;
  126406. }
  126407. <*>{CHAR_LITERAL} {
  126408. - yytext[yyleng-1] = '\0';
  126409. - yylval.literal = xstrdup(yytext+1);
  126410. - DPRINT("Character literal: %s\n", yylval.literal);
  126411. + struct data d;
  126412. + DPRINT("Character literal: %s\n", yytext);
  126413. +
  126414. + d = data_copy_escape_string(yytext+1, yyleng-2);
  126415. + if (d.len == 1) {
  126416. + lexical_error("Empty character literal");
  126417. + yylval.integer = 0;
  126418. + return DT_CHAR_LITERAL;
  126419. + }
  126420. +
  126421. + yylval.integer = (unsigned char)d.val[0];
  126422. +
  126423. + if (d.len > 2)
  126424. + lexical_error("Character literal has %d"
  126425. + " characters instead of 1",
  126426. + d.len - 1);
  126427. +
  126428. return DT_CHAR_LITERAL;
  126429. }
  126430. @@ -164,7 +197,7 @@
  126431. return DT_REF;
  126432. }
  126433. -<*>"&{/"{PATHCHAR}+\} { /* new-style path reference */
  126434. +<*>"&{/"{PATHCHAR}*\} { /* new-style path reference */
  126435. yytext[yyleng-1] = '\0';
  126436. DPRINT("Ref: %s\n", yytext+2);
  126437. yylval.labelref = xstrdup(yytext+2);
  126438. @@ -238,13 +271,24 @@
  126439. }
  126440. -static int pop_input_file(void)
  126441. +static bool pop_input_file(void)
  126442. {
  126443. if (srcfile_pop() == 0)
  126444. - return 0;
  126445. + return false;
  126446. yypop_buffer_state();
  126447. yyin = current_srcfile->f;
  126448. - return 1;
  126449. + return true;
  126450. +}
  126451. +
  126452. +static void lexical_error(const char *fmt, ...)
  126453. +{
  126454. + va_list ap;
  126455. +
  126456. + va_start(ap, fmt);
  126457. + srcpos_verror(&yylloc, "Lexical error", fmt, ap);
  126458. + va_end(ap);
  126459. +
  126460. + treesource_error = true;
  126461. }
  126462. diff -Nur linux-3.18.8/scripts/dtc/dtc-lexer.lex.c_shipped linux-rpi/scripts/dtc/dtc-lexer.lex.c_shipped
  126463. --- linux-3.18.8/scripts/dtc/dtc-lexer.lex.c_shipped 2015-02-27 02:49:36.000000000 +0100
  126464. +++ linux-rpi/scripts/dtc/dtc-lexer.lex.c_shipped 2015-03-05 14:40:18.913715792 +0100
  126465. @@ -372,8 +372,8 @@
  126466. *yy_cp = '\0'; \
  126467. (yy_c_buf_p) = yy_cp;
  126468. -#define YY_NUM_RULES 30
  126469. -#define YY_END_OF_BUFFER 31
  126470. +#define YY_NUM_RULES 31
  126471. +#define YY_END_OF_BUFFER 32
  126472. /* This struct is not used in this scanner,
  126473. but its presence is necessary. */
  126474. struct yy_trans_info
  126475. @@ -381,25 +381,26 @@
  126476. flex_int32_t yy_verify;
  126477. flex_int32_t yy_nxt;
  126478. };
  126479. -static yyconst flex_int16_t yy_accept[161] =
  126480. +static yyconst flex_int16_t yy_accept[166] =
  126481. { 0,
  126482. + 0, 0, 0, 0, 0, 0, 0, 0, 32, 30,
  126483. + 19, 19, 30, 30, 30, 30, 30, 30, 30, 30,
  126484. + 30, 30, 30, 30, 30, 30, 16, 17, 17, 30,
  126485. + 17, 11, 11, 19, 27, 0, 3, 0, 28, 13,
  126486. + 0, 0, 12, 0, 0, 0, 0, 0, 0, 0,
  126487. + 0, 22, 24, 26, 25, 23, 0, 10, 29, 0,
  126488. + 0, 0, 15, 15, 17, 17, 17, 11, 11, 11,
  126489. + 0, 13, 0, 12, 0, 0, 0, 21, 0, 0,
  126490. + 0, 0, 0, 0, 0, 0, 0, 17, 11, 11,
  126491. + 11, 0, 14, 20, 0, 0, 0, 0, 0, 0,
  126492. +
  126493. + 0, 0, 0, 0, 17, 0, 0, 0, 0, 0,
  126494. + 0, 0, 0, 0, 0, 17, 7, 0, 0, 0,
  126495. + 0, 0, 0, 0, 2, 0, 0, 0, 0, 0,
  126496. + 0, 0, 0, 0, 4, 18, 0, 0, 5, 2,
  126497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126498. - 31, 29, 18, 18, 29, 29, 29, 29, 29, 29,
  126499. - 29, 29, 29, 29, 29, 29, 29, 29, 15, 16,
  126500. - 16, 29, 16, 10, 10, 18, 26, 0, 3, 0,
  126501. - 27, 12, 0, 0, 11, 0, 0, 0, 0, 0,
  126502. - 0, 0, 21, 23, 25, 24, 22, 0, 9, 28,
  126503. - 0, 0, 0, 14, 14, 16, 16, 16, 10, 10,
  126504. - 10, 0, 12, 0, 11, 0, 0, 0, 20, 0,
  126505. - 0, 0, 0, 0, 0, 0, 0, 16, 10, 10,
  126506. - 10, 0, 19, 0, 0, 0, 0, 0, 0, 0,
  126507. -
  126508. - 0, 0, 16, 13, 0, 0, 0, 0, 0, 0,
  126509. - 0, 0, 0, 16, 6, 0, 0, 0, 0, 0,
  126510. - 0, 2, 0, 0, 0, 0, 0, 0, 0, 0,
  126511. - 4, 17, 0, 0, 2, 0, 0, 0, 0, 0,
  126512. - 0, 0, 0, 0, 0, 0, 0, 1, 0, 0,
  126513. - 0, 0, 5, 8, 0, 0, 0, 0, 7, 0
  126514. + 0, 0, 1, 0, 0, 0, 0, 6, 9, 0,
  126515. + 0, 0, 0, 8, 0
  126516. } ;
  126517. static yyconst flex_int32_t yy_ec[256] =
  126518. @@ -415,9 +416,9 @@
  126519. 22, 22, 22, 22, 24, 22, 22, 25, 22, 22,
  126520. 1, 26, 27, 1, 22, 1, 21, 28, 29, 30,
  126521. - 31, 21, 22, 22, 32, 22, 22, 33, 34, 35,
  126522. - 36, 37, 22, 38, 39, 40, 41, 42, 22, 25,
  126523. - 43, 22, 44, 45, 46, 1, 1, 1, 1, 1,
  126524. + 31, 21, 32, 22, 33, 22, 22, 34, 35, 36,
  126525. + 37, 38, 22, 39, 40, 41, 42, 43, 22, 25,
  126526. + 44, 22, 45, 46, 47, 1, 1, 1, 1, 1,
  126527. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  126528. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  126529. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  126530. @@ -434,163 +435,165 @@
  126531. 1, 1, 1, 1, 1
  126532. } ;
  126533. -static yyconst flex_int32_t yy_meta[47] =
  126534. +static yyconst flex_int32_t yy_meta[48] =
  126535. { 0,
  126536. 1, 1, 1, 1, 1, 1, 2, 3, 1, 2,
  126537. 2, 2, 4, 5, 5, 5, 6, 1, 1, 1,
  126538. 7, 8, 8, 8, 8, 1, 1, 7, 7, 7,
  126539. 7, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  126540. - 8, 8, 8, 3, 1, 1
  126541. + 8, 8, 8, 8, 3, 1, 4
  126542. } ;
  126543. -static yyconst flex_int16_t yy_base[175] =
  126544. +static yyconst flex_int16_t yy_base[180] =
  126545. { 0,
  126546. - 0, 385, 378, 40, 41, 383, 72, 382, 34, 44,
  126547. - 388, 393, 61, 117, 368, 116, 115, 115, 115, 48,
  126548. - 367, 107, 368, 339, 127, 120, 0, 147, 393, 0,
  126549. - 127, 0, 133, 156, 168, 153, 393, 125, 393, 380,
  126550. - 393, 0, 369, 127, 393, 160, 371, 377, 347, 21,
  126551. - 343, 346, 393, 393, 393, 393, 393, 359, 393, 393,
  126552. - 183, 343, 339, 393, 356, 0, 183, 340, 187, 348,
  126553. - 347, 0, 0, 0, 178, 359, 195, 365, 354, 326,
  126554. - 332, 325, 334, 328, 204, 326, 331, 324, 393, 335,
  126555. - 150, 311, 343, 342, 315, 322, 340, 179, 313, 207,
  126556. -
  126557. - 319, 316, 317, 393, 337, 333, 305, 302, 311, 301,
  126558. - 310, 190, 338, 337, 393, 307, 322, 301, 305, 277,
  126559. - 208, 311, 307, 278, 271, 270, 248, 246, 213, 130,
  126560. - 393, 393, 263, 235, 207, 221, 218, 229, 213, 213,
  126561. - 206, 234, 218, 210, 208, 193, 219, 393, 223, 204,
  126562. - 176, 157, 393, 393, 120, 106, 97, 119, 393, 393,
  126563. - 245, 251, 259, 263, 267, 273, 280, 284, 292, 300,
  126564. - 304, 310, 318, 326
  126565. + 0, 393, 35, 392, 66, 391, 38, 107, 397, 401,
  126566. + 55, 113, 377, 112, 111, 111, 114, 42, 376, 106,
  126567. + 377, 347, 126, 120, 0, 147, 401, 0, 124, 0,
  126568. + 137, 158, 170, 163, 401, 153, 401, 389, 401, 0,
  126569. + 378, 120, 401, 131, 380, 386, 355, 139, 351, 355,
  126570. + 351, 401, 401, 401, 401, 401, 367, 401, 401, 185,
  126571. + 350, 346, 401, 364, 0, 185, 347, 189, 356, 355,
  126572. + 0, 0, 330, 180, 366, 141, 372, 361, 332, 338,
  126573. + 331, 341, 334, 326, 205, 331, 337, 329, 401, 341,
  126574. + 167, 316, 401, 349, 348, 320, 328, 346, 180, 318,
  126575. +
  126576. + 324, 209, 324, 320, 322, 342, 338, 309, 306, 315,
  126577. + 305, 315, 312, 192, 342, 341, 401, 293, 306, 282,
  126578. + 268, 252, 255, 203, 285, 282, 272, 268, 252, 233,
  126579. + 232, 239, 208, 107, 401, 401, 238, 211, 401, 211,
  126580. + 212, 208, 228, 203, 215, 207, 233, 222, 212, 211,
  126581. + 203, 227, 401, 237, 225, 204, 185, 401, 401, 149,
  126582. + 128, 88, 42, 401, 401, 253, 259, 267, 271, 275,
  126583. + 281, 288, 292, 300, 308, 312, 318, 326, 334
  126584. } ;
  126585. -static yyconst flex_int16_t yy_def[175] =
  126586. +static yyconst flex_int16_t yy_def[180] =
  126587. { 0,
  126588. - 160, 1, 1, 1, 1, 5, 160, 7, 1, 1,
  126589. - 160, 160, 160, 160, 160, 161, 162, 163, 160, 160,
  126590. - 160, 160, 164, 160, 160, 160, 165, 164, 160, 166,
  126591. - 167, 166, 166, 160, 160, 160, 160, 161, 160, 161,
  126592. - 160, 168, 160, 163, 160, 163, 169, 170, 160, 160,
  126593. - 160, 160, 160, 160, 160, 160, 160, 164, 160, 160,
  126594. - 160, 160, 160, 160, 164, 166, 167, 166, 160, 160,
  126595. - 160, 171, 168, 172, 163, 169, 169, 170, 160, 160,
  126596. - 160, 160, 160, 160, 160, 160, 160, 166, 160, 160,
  126597. - 171, 172, 160, 160, 160, 160, 160, 160, 160, 160,
  126598. -
  126599. - 160, 160, 166, 160, 160, 160, 160, 160, 160, 160,
  126600. - 160, 173, 160, 166, 160, 160, 160, 160, 160, 160,
  126601. - 173, 160, 173, 160, 160, 160, 160, 160, 160, 160,
  126602. - 160, 160, 160, 160, 160, 160, 160, 160, 160, 160,
  126603. - 160, 160, 174, 160, 160, 160, 174, 160, 174, 160,
  126604. - 160, 160, 160, 160, 160, 160, 160, 160, 160, 0,
  126605. - 160, 160, 160, 160, 160, 160, 160, 160, 160, 160,
  126606. - 160, 160, 160, 160
  126607. + 165, 1, 1, 3, 165, 5, 1, 1, 165, 165,
  126608. + 165, 165, 165, 166, 167, 168, 165, 165, 165, 165,
  126609. + 169, 165, 165, 165, 170, 169, 165, 171, 172, 171,
  126610. + 171, 165, 165, 165, 165, 166, 165, 166, 165, 173,
  126611. + 165, 168, 165, 168, 174, 175, 165, 165, 165, 165,
  126612. + 165, 165, 165, 165, 165, 165, 169, 165, 165, 165,
  126613. + 165, 165, 165, 169, 171, 172, 171, 165, 165, 165,
  126614. + 176, 173, 177, 168, 174, 174, 175, 165, 165, 165,
  126615. + 165, 165, 165, 165, 165, 165, 165, 171, 165, 165,
  126616. + 176, 177, 165, 165, 165, 165, 165, 165, 165, 165,
  126617. +
  126618. + 165, 165, 165, 165, 171, 165, 165, 165, 165, 165,
  126619. + 165, 165, 165, 178, 165, 171, 165, 165, 165, 165,
  126620. + 165, 165, 165, 178, 165, 178, 165, 165, 165, 165,
  126621. + 165, 165, 165, 165, 165, 165, 165, 165, 165, 165,
  126622. + 165, 165, 165, 165, 165, 165, 165, 179, 165, 165,
  126623. + 165, 179, 165, 179, 165, 165, 165, 165, 165, 165,
  126624. + 165, 165, 165, 165, 0, 165, 165, 165, 165, 165,
  126625. + 165, 165, 165, 165, 165, 165, 165, 165, 165
  126626. } ;
  126627. -static yyconst flex_int16_t yy_nxt[440] =
  126628. +static yyconst flex_int16_t yy_nxt[449] =
  126629. { 0,
  126630. - 12, 13, 14, 13, 15, 16, 12, 17, 18, 12,
  126631. - 12, 12, 19, 12, 12, 12, 12, 20, 21, 22,
  126632. - 23, 23, 23, 23, 23, 12, 12, 23, 23, 23,
  126633. - 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
  126634. - 23, 23, 23, 12, 24, 12, 25, 34, 35, 35,
  126635. - 25, 81, 26, 26, 27, 27, 27, 34, 35, 35,
  126636. - 82, 28, 36, 36, 36, 53, 54, 29, 28, 28,
  126637. - 28, 28, 12, 13, 14, 13, 15, 16, 30, 17,
  126638. - 18, 30, 30, 30, 26, 30, 30, 30, 12, 20,
  126639. - 21, 22, 31, 31, 31, 31, 31, 32, 12, 31,
  126640. -
  126641. - 31, 31, 31, 31, 31, 31, 31, 31, 31, 31,
  126642. - 31, 31, 31, 31, 31, 12, 24, 12, 36, 36,
  126643. - 36, 39, 41, 45, 47, 56, 57, 48, 61, 47,
  126644. - 39, 159, 48, 66, 61, 45, 66, 66, 66, 158,
  126645. - 46, 40, 49, 59, 50, 157, 51, 49, 52, 50,
  126646. - 40, 63, 46, 52, 36, 36, 36, 156, 43, 62,
  126647. - 65, 65, 65, 59, 136, 68, 137, 65, 75, 69,
  126648. - 69, 69, 70, 71, 65, 65, 65, 65, 70, 71,
  126649. - 72, 69, 69, 69, 61, 46, 45, 155, 154, 66,
  126650. - 70, 71, 66, 66, 66, 122, 85, 85, 85, 59,
  126651. -
  126652. - 69, 69, 69, 46, 77, 100, 109, 93, 100, 70,
  126653. - 71, 110, 112, 122, 129, 123, 153, 85, 85, 85,
  126654. - 135, 135, 135, 148, 148, 160, 135, 135, 135, 152,
  126655. - 142, 142, 142, 123, 143, 142, 142, 142, 151, 143,
  126656. - 150, 146, 145, 149, 149, 38, 38, 38, 38, 38,
  126657. - 38, 38, 38, 42, 144, 141, 140, 42, 42, 44,
  126658. - 44, 44, 44, 44, 44, 44, 44, 58, 58, 58,
  126659. - 58, 64, 139, 64, 66, 138, 134, 66, 133, 66,
  126660. - 66, 67, 132, 131, 67, 67, 67, 67, 73, 130,
  126661. - 73, 73, 76, 76, 76, 76, 76, 76, 76, 76,
  126662. -
  126663. - 78, 78, 78, 78, 78, 78, 78, 78, 91, 160,
  126664. - 91, 92, 129, 92, 92, 128, 92, 92, 121, 121,
  126665. - 121, 121, 121, 121, 121, 121, 147, 147, 147, 147,
  126666. - 147, 147, 147, 147, 127, 126, 125, 124, 61, 61,
  126667. - 120, 119, 118, 117, 116, 115, 47, 114, 110, 113,
  126668. - 111, 108, 107, 106, 48, 105, 104, 89, 103, 102,
  126669. - 101, 99, 98, 97, 96, 95, 94, 79, 77, 90,
  126670. - 89, 88, 59, 87, 86, 59, 84, 83, 80, 79,
  126671. - 77, 74, 160, 60, 59, 55, 37, 160, 33, 25,
  126672. - 26, 25, 11, 160, 160, 160, 160, 160, 160, 160,
  126673. -
  126674. - 160, 160, 160, 160, 160, 160, 160, 160, 160, 160,
  126675. - 160, 160, 160, 160, 160, 160, 160, 160, 160, 160,
  126676. - 160, 160, 160, 160, 160, 160, 160, 160, 160, 160,
  126677. - 160, 160, 160, 160, 160, 160, 160, 160, 160
  126678. + 10, 11, 12, 11, 13, 14, 10, 15, 16, 10,
  126679. + 10, 10, 17, 10, 10, 10, 10, 18, 19, 20,
  126680. + 21, 21, 21, 21, 21, 10, 10, 21, 21, 21,
  126681. + 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
  126682. + 21, 21, 21, 21, 10, 22, 10, 24, 25, 25,
  126683. + 25, 32, 33, 33, 164, 26, 34, 34, 34, 52,
  126684. + 53, 27, 26, 26, 26, 26, 10, 11, 12, 11,
  126685. + 13, 14, 28, 15, 16, 28, 28, 28, 24, 28,
  126686. + 28, 28, 10, 18, 19, 20, 29, 29, 29, 29,
  126687. + 29, 30, 10, 29, 29, 29, 29, 29, 29, 29,
  126688. +
  126689. + 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
  126690. + 10, 22, 10, 23, 34, 34, 34, 37, 39, 43,
  126691. + 32, 33, 33, 45, 55, 56, 46, 60, 43, 45,
  126692. + 65, 163, 46, 65, 65, 65, 44, 38, 60, 74,
  126693. + 58, 47, 141, 48, 142, 44, 49, 47, 50, 48,
  126694. + 76, 51, 62, 94, 50, 41, 44, 51, 37, 61,
  126695. + 64, 64, 64, 58, 34, 34, 34, 64, 162, 80,
  126696. + 67, 68, 68, 68, 64, 64, 64, 64, 38, 81,
  126697. + 69, 70, 71, 68, 68, 68, 60, 161, 43, 69,
  126698. + 70, 65, 69, 70, 65, 65, 65, 125, 85, 85,
  126699. +
  126700. + 85, 58, 68, 68, 68, 44, 102, 110, 125, 133,
  126701. + 102, 69, 70, 111, 114, 160, 159, 126, 85, 85,
  126702. + 85, 140, 140, 140, 140, 140, 140, 153, 126, 147,
  126703. + 147, 147, 153, 148, 147, 147, 147, 158, 148, 165,
  126704. + 157, 156, 155, 151, 150, 149, 146, 154, 145, 144,
  126705. + 143, 139, 154, 36, 36, 36, 36, 36, 36, 36,
  126706. + 36, 40, 138, 137, 136, 40, 40, 42, 42, 42,
  126707. + 42, 42, 42, 42, 42, 57, 57, 57, 57, 63,
  126708. + 135, 63, 65, 134, 165, 65, 133, 65, 65, 66,
  126709. + 132, 131, 66, 66, 66, 66, 72, 130, 72, 72,
  126710. +
  126711. + 75, 75, 75, 75, 75, 75, 75, 75, 77, 77,
  126712. + 77, 77, 77, 77, 77, 77, 91, 129, 91, 92,
  126713. + 128, 92, 92, 127, 92, 92, 124, 124, 124, 124,
  126714. + 124, 124, 124, 124, 152, 152, 152, 152, 152, 152,
  126715. + 152, 152, 60, 60, 123, 122, 121, 120, 119, 118,
  126716. + 117, 45, 116, 111, 115, 113, 112, 109, 108, 107,
  126717. + 46, 106, 93, 89, 105, 104, 103, 101, 100, 99,
  126718. + 98, 97, 96, 95, 78, 76, 93, 90, 89, 88,
  126719. + 58, 87, 86, 58, 84, 83, 82, 79, 78, 76,
  126720. + 73, 165, 59, 58, 54, 35, 165, 31, 23, 23,
  126721. +
  126722. + 9, 165, 165, 165, 165, 165, 165, 165, 165, 165,
  126723. + 165, 165, 165, 165, 165, 165, 165, 165, 165, 165,
  126724. + 165, 165, 165, 165, 165, 165, 165, 165, 165, 165,
  126725. + 165, 165, 165, 165, 165, 165, 165, 165, 165, 165,
  126726. + 165, 165, 165, 165, 165, 165, 165, 165
  126727. } ;
  126728. -static yyconst flex_int16_t yy_chk[440] =
  126729. +static yyconst flex_int16_t yy_chk[449] =
  126730. { 0,
  126731. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  126732. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  126733. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  126734. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  126735. - 1, 1, 1, 1, 1, 1, 4, 9, 9, 9,
  126736. - 10, 50, 4, 5, 5, 5, 5, 10, 10, 10,
  126737. - 50, 5, 13, 13, 13, 20, 20, 5, 5, 5,
  126738. - 5, 5, 7, 7, 7, 7, 7, 7, 7, 7,
  126739. - 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  126740. - 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  126741. -
  126742. - 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  126743. - 7, 7, 7, 7, 7, 7, 7, 7, 14, 14,
  126744. - 14, 16, 17, 18, 19, 22, 22, 19, 25, 26,
  126745. - 38, 158, 26, 31, 33, 44, 31, 31, 31, 157,
  126746. - 18, 16, 19, 31, 19, 156, 19, 26, 19, 26,
  126747. - 38, 26, 44, 26, 36, 36, 36, 155, 17, 25,
  126748. - 28, 28, 28, 28, 130, 33, 130, 28, 46, 34,
  126749. - 34, 34, 91, 91, 28, 28, 28, 28, 34, 34,
  126750. - 34, 35, 35, 35, 61, 46, 75, 152, 151, 67,
  126751. - 35, 35, 67, 67, 67, 112, 61, 61, 61, 67,
  126752. -
  126753. - 69, 69, 69, 75, 77, 85, 98, 77, 100, 69,
  126754. - 69, 98, 100, 121, 129, 112, 150, 85, 85, 85,
  126755. - 135, 135, 135, 143, 147, 149, 129, 129, 129, 146,
  126756. - 138, 138, 138, 121, 138, 142, 142, 142, 145, 142,
  126757. - 144, 141, 140, 143, 147, 161, 161, 161, 161, 161,
  126758. - 161, 161, 161, 162, 139, 137, 136, 162, 162, 163,
  126759. - 163, 163, 163, 163, 163, 163, 163, 164, 164, 164,
  126760. - 164, 165, 134, 165, 166, 133, 128, 166, 127, 166,
  126761. - 166, 167, 126, 125, 167, 167, 167, 167, 168, 124,
  126762. - 168, 168, 169, 169, 169, 169, 169, 169, 169, 169,
  126763. -
  126764. - 170, 170, 170, 170, 170, 170, 170, 170, 171, 123,
  126765. - 171, 172, 122, 172, 172, 120, 172, 172, 173, 173,
  126766. - 173, 173, 173, 173, 173, 173, 174, 174, 174, 174,
  126767. - 174, 174, 174, 174, 119, 118, 117, 116, 114, 113,
  126768. - 111, 110, 109, 108, 107, 106, 105, 103, 102, 101,
  126769. - 99, 97, 96, 95, 94, 93, 92, 90, 88, 87,
  126770. - 86, 84, 83, 82, 81, 80, 79, 78, 76, 71,
  126771. - 70, 68, 65, 63, 62, 58, 52, 51, 49, 48,
  126772. - 47, 43, 40, 24, 23, 21, 15, 11, 8, 6,
  126773. - 3, 2, 160, 160, 160, 160, 160, 160, 160, 160,
  126774. -
  126775. - 160, 160, 160, 160, 160, 160, 160, 160, 160, 160,
  126776. - 160, 160, 160, 160, 160, 160, 160, 160, 160, 160,
  126777. - 160, 160, 160, 160, 160, 160, 160, 160, 160, 160,
  126778. - 160, 160, 160, 160, 160, 160, 160, 160, 160
  126779. + 1, 1, 1, 1, 1, 1, 1, 3, 3, 3,
  126780. + 3, 7, 7, 7, 163, 3, 11, 11, 11, 18,
  126781. + 18, 3, 3, 3, 3, 3, 5, 5, 5, 5,
  126782. + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
  126783. + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
  126784. + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
  126785. +
  126786. + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
  126787. + 5, 5, 5, 8, 12, 12, 12, 14, 15, 16,
  126788. + 8, 8, 8, 17, 20, 20, 17, 23, 42, 24,
  126789. + 29, 162, 24, 29, 29, 29, 16, 14, 31, 44,
  126790. + 29, 17, 134, 17, 134, 42, 17, 24, 17, 24,
  126791. + 76, 17, 24, 76, 24, 15, 44, 24, 36, 23,
  126792. + 26, 26, 26, 26, 34, 34, 34, 26, 161, 48,
  126793. + 31, 32, 32, 32, 26, 26, 26, 26, 36, 48,
  126794. + 32, 32, 32, 33, 33, 33, 60, 160, 74, 91,
  126795. + 91, 66, 33, 33, 66, 66, 66, 114, 60, 60,
  126796. +
  126797. + 60, 66, 68, 68, 68, 74, 85, 99, 124, 133,
  126798. + 102, 68, 68, 99, 102, 157, 156, 114, 85, 85,
  126799. + 85, 133, 133, 133, 140, 140, 140, 148, 124, 143,
  126800. + 143, 143, 152, 143, 147, 147, 147, 155, 147, 154,
  126801. + 151, 150, 149, 146, 145, 144, 142, 148, 141, 138,
  126802. + 137, 132, 152, 166, 166, 166, 166, 166, 166, 166,
  126803. + 166, 167, 131, 130, 129, 167, 167, 168, 168, 168,
  126804. + 168, 168, 168, 168, 168, 169, 169, 169, 169, 170,
  126805. + 128, 170, 171, 127, 126, 171, 125, 171, 171, 172,
  126806. + 123, 122, 172, 172, 172, 172, 173, 121, 173, 173,
  126807. +
  126808. + 174, 174, 174, 174, 174, 174, 174, 174, 175, 175,
  126809. + 175, 175, 175, 175, 175, 175, 176, 120, 176, 177,
  126810. + 119, 177, 177, 118, 177, 177, 178, 178, 178, 178,
  126811. + 178, 178, 178, 178, 179, 179, 179, 179, 179, 179,
  126812. + 179, 179, 116, 115, 113, 112, 111, 110, 109, 108,
  126813. + 107, 106, 105, 104, 103, 101, 100, 98, 97, 96,
  126814. + 95, 94, 92, 90, 88, 87, 86, 84, 83, 82,
  126815. + 81, 80, 79, 78, 77, 75, 73, 70, 69, 67,
  126816. + 64, 62, 61, 57, 51, 50, 49, 47, 46, 45,
  126817. + 41, 38, 22, 21, 19, 13, 9, 6, 4, 2,
  126818. +
  126819. + 165, 165, 165, 165, 165, 165, 165, 165, 165, 165,
  126820. + 165, 165, 165, 165, 165, 165, 165, 165, 165, 165,
  126821. + 165, 165, 165, 165, 165, 165, 165, 165, 165, 165,
  126822. + 165, 165, 165, 165, 165, 165, 165, 165, 165, 165,
  126823. + 165, 165, 165, 165, 165, 165, 165, 165
  126824. } ;
  126825. static yy_state_type yy_last_accepting_state;
  126826. @@ -631,13 +634,13 @@
  126827. -
  126828. -#line 38 "dtc-lexer.l"
  126829. +#line 37 "dtc-lexer.l"
  126830. #include "dtc.h"
  126831. #include "srcpos.h"
  126832. #include "dtc-parser.tab.h"
  126833. YYLTYPE yylloc;
  126834. +extern bool treesource_error;
  126835. /* CAUTION: this will stop working if we ever use yyless() or yyunput() */
  126836. #define YY_USER_ACTION \
  126837. @@ -659,14 +662,14 @@
  126838. BEGIN(V1); \
  126839. static void push_input_file(const char *filename);
  126840. -static int pop_input_file(void);
  126841. -#line 664 "dtc-lexer.lex.c"
  126842. +static bool pop_input_file(void);
  126843. +static void lexical_error(const char *fmt, ...);
  126844. +#line 668 "dtc-lexer.lex.c"
  126845. #define INITIAL 0
  126846. -#define INCLUDE 1
  126847. -#define BYTESTRING 2
  126848. -#define PROPNODENAME 3
  126849. -#define V1 4
  126850. +#define BYTESTRING 1
  126851. +#define PROPNODENAME 2
  126852. +#define V1 3
  126853. #ifndef YY_NO_UNISTD_H
  126854. /* Special case for "unistd.h", since it is non-ANSI. We include it way
  126855. @@ -852,9 +855,9 @@
  126856. register char *yy_cp, *yy_bp;
  126857. register int yy_act;
  126858. -#line 67 "dtc-lexer.l"
  126859. +#line 68 "dtc-lexer.l"
  126860. -#line 858 "dtc-lexer.lex.c"
  126861. +#line 861 "dtc-lexer.lex.c"
  126862. if ( !(yy_init) )
  126863. {
  126864. @@ -908,13 +911,13 @@
  126865. while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
  126866. {
  126867. yy_current_state = (int) yy_def[yy_current_state];
  126868. - if ( yy_current_state >= 161 )
  126869. + if ( yy_current_state >= 166 )
  126870. yy_c = yy_meta[(unsigned int) yy_c];
  126871. }
  126872. yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
  126873. ++yy_cp;
  126874. }
  126875. - while ( yy_current_state != 160 );
  126876. + while ( yy_current_state != 165 );
  126877. yy_cp = (yy_last_accepting_cpos);
  126878. yy_current_state = (yy_last_accepting_state);
  126879. @@ -937,7 +940,7 @@
  126880. case 1:
  126881. /* rule 1 can match eol */
  126882. YY_RULE_SETUP
  126883. -#line 68 "dtc-lexer.l"
  126884. +#line 69 "dtc-lexer.l"
  126885. {
  126886. char *name = strchr(yytext, '\"') + 1;
  126887. yytext[yyleng-1] = '\0';
  126888. @@ -947,16 +950,16 @@
  126889. case 2:
  126890. /* rule 2 can match eol */
  126891. YY_RULE_SETUP
  126892. -#line 74 "dtc-lexer.l"
  126893. +#line 75 "dtc-lexer.l"
  126894. {
  126895. char *line, *tmp, *fn;
  126896. /* skip text before line # */
  126897. line = yytext;
  126898. - while (!isdigit(*line))
  126899. + while (!isdigit((unsigned char)*line))
  126900. line++;
  126901. /* skip digits in line # */
  126902. tmp = line;
  126903. - while (!isspace(*tmp))
  126904. + while (!isspace((unsigned char)*tmp))
  126905. tmp++;
  126906. /* "NULL"-terminate line # */
  126907. *tmp = '\0';
  126908. @@ -970,11 +973,10 @@
  126909. }
  126910. YY_BREAK
  126911. case YY_STATE_EOF(INITIAL):
  126912. -case YY_STATE_EOF(INCLUDE):
  126913. case YY_STATE_EOF(BYTESTRING):
  126914. case YY_STATE_EOF(PROPNODENAME):
  126915. case YY_STATE_EOF(V1):
  126916. -#line 95 "dtc-lexer.l"
  126917. +#line 96 "dtc-lexer.l"
  126918. {
  126919. if (!pop_input_file()) {
  126920. yyterminate();
  126921. @@ -984,7 +986,7 @@
  126922. case 3:
  126923. /* rule 3 can match eol */
  126924. YY_RULE_SETUP
  126925. -#line 101 "dtc-lexer.l"
  126926. +#line 102 "dtc-lexer.l"
  126927. {
  126928. DPRINT("String: %s\n", yytext);
  126929. yylval.data = data_copy_escape_string(yytext+1,
  126930. @@ -994,7 +996,7 @@
  126931. YY_BREAK
  126932. case 4:
  126933. YY_RULE_SETUP
  126934. -#line 108 "dtc-lexer.l"
  126935. +#line 109 "dtc-lexer.l"
  126936. {
  126937. DPRINT("Keyword: /dts-v1/\n");
  126938. dts_version = 1;
  126939. @@ -1004,25 +1006,33 @@
  126940. YY_BREAK
  126941. case 5:
  126942. YY_RULE_SETUP
  126943. -#line 115 "dtc-lexer.l"
  126944. +#line 116 "dtc-lexer.l"
  126945. +{
  126946. + DPRINT("Keyword: /plugin/\n");
  126947. + return DT_PLUGIN;
  126948. + }
  126949. + YY_BREAK
  126950. +case 6:
  126951. +YY_RULE_SETUP
  126952. +#line 121 "dtc-lexer.l"
  126953. {
  126954. DPRINT("Keyword: /memreserve/\n");
  126955. BEGIN_DEFAULT();
  126956. return DT_MEMRESERVE;
  126957. }
  126958. YY_BREAK
  126959. -case 6:
  126960. +case 7:
  126961. YY_RULE_SETUP
  126962. -#line 121 "dtc-lexer.l"
  126963. +#line 127 "dtc-lexer.l"
  126964. {
  126965. DPRINT("Keyword: /bits/\n");
  126966. BEGIN_DEFAULT();
  126967. return DT_BITS;
  126968. }
  126969. YY_BREAK
  126970. -case 7:
  126971. +case 8:
  126972. YY_RULE_SETUP
  126973. -#line 127 "dtc-lexer.l"
  126974. +#line 133 "dtc-lexer.l"
  126975. {
  126976. DPRINT("Keyword: /delete-property/\n");
  126977. DPRINT("<PROPNODENAME>\n");
  126978. @@ -1030,9 +1040,9 @@
  126979. return DT_DEL_PROP;
  126980. }
  126981. YY_BREAK
  126982. -case 8:
  126983. +case 9:
  126984. YY_RULE_SETUP
  126985. -#line 134 "dtc-lexer.l"
  126986. +#line 140 "dtc-lexer.l"
  126987. {
  126988. DPRINT("Keyword: /delete-node/\n");
  126989. DPRINT("<PROPNODENAME>\n");
  126990. @@ -1040,9 +1050,9 @@
  126991. return DT_DEL_NODE;
  126992. }
  126993. YY_BREAK
  126994. -case 9:
  126995. +case 10:
  126996. YY_RULE_SETUP
  126997. -#line 141 "dtc-lexer.l"
  126998. +#line 147 "dtc-lexer.l"
  126999. {
  127000. DPRINT("Label: %s\n", yytext);
  127001. yylval.labelref = xstrdup(yytext);
  127002. @@ -1050,38 +1060,65 @@
  127003. return DT_LABEL;
  127004. }
  127005. YY_BREAK
  127006. -case 10:
  127007. +case 11:
  127008. YY_RULE_SETUP
  127009. -#line 148 "dtc-lexer.l"
  127010. +#line 154 "dtc-lexer.l"
  127011. {
  127012. - yylval.literal = xstrdup(yytext);
  127013. - DPRINT("Literal: '%s'\n", yylval.literal);
  127014. + char *e;
  127015. + DPRINT("Integer Literal: '%s'\n", yytext);
  127016. +
  127017. + errno = 0;
  127018. + yylval.integer = strtoull(yytext, &e, 0);
  127019. +
  127020. + assert(!(*e) || !e[strspn(e, "UL")]);
  127021. +
  127022. + if (errno == ERANGE)
  127023. + lexical_error("Integer literal '%s' out of range",
  127024. + yytext);
  127025. + else
  127026. + /* ERANGE is the only strtoull error triggerable
  127027. + * by strings matching the pattern */
  127028. + assert(errno == 0);
  127029. return DT_LITERAL;
  127030. }
  127031. YY_BREAK
  127032. -case 11:
  127033. -/* rule 11 can match eol */
  127034. +case 12:
  127035. +/* rule 12 can match eol */
  127036. YY_RULE_SETUP
  127037. -#line 154 "dtc-lexer.l"
  127038. +#line 173 "dtc-lexer.l"
  127039. {
  127040. - yytext[yyleng-1] = '\0';
  127041. - yylval.literal = xstrdup(yytext+1);
  127042. - DPRINT("Character literal: %s\n", yylval.literal);
  127043. + struct data d;
  127044. + DPRINT("Character literal: %s\n", yytext);
  127045. +
  127046. + d = data_copy_escape_string(yytext+1, yyleng-2);
  127047. + if (d.len == 1) {
  127048. + lexical_error("Empty character literal");
  127049. + yylval.integer = 0;
  127050. + return DT_CHAR_LITERAL;
  127051. + }
  127052. +
  127053. + yylval.integer = (unsigned char)d.val[0];
  127054. +
  127055. + if (d.len > 2)
  127056. + lexical_error("Character literal has %d"
  127057. + " characters instead of 1",
  127058. + d.len - 1);
  127059. +
  127060. return DT_CHAR_LITERAL;
  127061. }
  127062. YY_BREAK
  127063. -case 12:
  127064. +case 13:
  127065. YY_RULE_SETUP
  127066. -#line 161 "dtc-lexer.l"
  127067. +#line 194 "dtc-lexer.l"
  127068. { /* label reference */
  127069. DPRINT("Ref: %s\n", yytext+1);
  127070. yylval.labelref = xstrdup(yytext+1);
  127071. return DT_REF;
  127072. }
  127073. YY_BREAK
  127074. -case 13:
  127075. +case 14:
  127076. YY_RULE_SETUP
  127077. -#line 167 "dtc-lexer.l"
  127078. +#line 200 "dtc-lexer.l"
  127079. { /* new-style path reference */
  127080. yytext[yyleng-1] = '\0';
  127081. DPRINT("Ref: %s\n", yytext+2);
  127082. @@ -1089,27 +1126,27 @@
  127083. return DT_REF;
  127084. }
  127085. YY_BREAK
  127086. -case 14:
  127087. +case 15:
  127088. YY_RULE_SETUP
  127089. -#line 174 "dtc-lexer.l"
  127090. +#line 207 "dtc-lexer.l"
  127091. {
  127092. yylval.byte = strtol(yytext, NULL, 16);
  127093. DPRINT("Byte: %02x\n", (int)yylval.byte);
  127094. return DT_BYTE;
  127095. }
  127096. YY_BREAK
  127097. -case 15:
  127098. +case 16:
  127099. YY_RULE_SETUP
  127100. -#line 180 "dtc-lexer.l"
  127101. +#line 213 "dtc-lexer.l"
  127102. {
  127103. DPRINT("/BYTESTRING\n");
  127104. BEGIN_DEFAULT();
  127105. return ']';
  127106. }
  127107. YY_BREAK
  127108. -case 16:
  127109. +case 17:
  127110. YY_RULE_SETUP
  127111. -#line 186 "dtc-lexer.l"
  127112. +#line 219 "dtc-lexer.l"
  127113. {
  127114. DPRINT("PropNodeName: %s\n", yytext);
  127115. yylval.propnodename = xstrdup((yytext[0] == '\\') ?
  127116. @@ -1118,75 +1155,75 @@
  127117. return DT_PROPNODENAME;
  127118. }
  127119. YY_BREAK
  127120. -case 17:
  127121. +case 18:
  127122. YY_RULE_SETUP
  127123. -#line 194 "dtc-lexer.l"
  127124. +#line 227 "dtc-lexer.l"
  127125. {
  127126. DPRINT("Binary Include\n");
  127127. return DT_INCBIN;
  127128. }
  127129. YY_BREAK
  127130. -case 18:
  127131. -/* rule 18 can match eol */
  127132. -YY_RULE_SETUP
  127133. -#line 199 "dtc-lexer.l"
  127134. -/* eat whitespace */
  127135. - YY_BREAK
  127136. case 19:
  127137. /* rule 19 can match eol */
  127138. YY_RULE_SETUP
  127139. -#line 200 "dtc-lexer.l"
  127140. -/* eat C-style comments */
  127141. +#line 232 "dtc-lexer.l"
  127142. +/* eat whitespace */
  127143. YY_BREAK
  127144. case 20:
  127145. /* rule 20 can match eol */
  127146. YY_RULE_SETUP
  127147. -#line 201 "dtc-lexer.l"
  127148. -/* eat C++-style comments */
  127149. +#line 233 "dtc-lexer.l"
  127150. +/* eat C-style comments */
  127151. YY_BREAK
  127152. case 21:
  127153. +/* rule 21 can match eol */
  127154. YY_RULE_SETUP
  127155. -#line 203 "dtc-lexer.l"
  127156. -{ return DT_LSHIFT; };
  127157. +#line 234 "dtc-lexer.l"
  127158. +/* eat C++-style comments */
  127159. YY_BREAK
  127160. case 22:
  127161. YY_RULE_SETUP
  127162. -#line 204 "dtc-lexer.l"
  127163. -{ return DT_RSHIFT; };
  127164. +#line 236 "dtc-lexer.l"
  127165. +{ return DT_LSHIFT; };
  127166. YY_BREAK
  127167. case 23:
  127168. YY_RULE_SETUP
  127169. -#line 205 "dtc-lexer.l"
  127170. -{ return DT_LE; };
  127171. +#line 237 "dtc-lexer.l"
  127172. +{ return DT_RSHIFT; };
  127173. YY_BREAK
  127174. case 24:
  127175. YY_RULE_SETUP
  127176. -#line 206 "dtc-lexer.l"
  127177. -{ return DT_GE; };
  127178. +#line 238 "dtc-lexer.l"
  127179. +{ return DT_LE; };
  127180. YY_BREAK
  127181. case 25:
  127182. YY_RULE_SETUP
  127183. -#line 207 "dtc-lexer.l"
  127184. -{ return DT_EQ; };
  127185. +#line 239 "dtc-lexer.l"
  127186. +{ return DT_GE; };
  127187. YY_BREAK
  127188. case 26:
  127189. YY_RULE_SETUP
  127190. -#line 208 "dtc-lexer.l"
  127191. -{ return DT_NE; };
  127192. +#line 240 "dtc-lexer.l"
  127193. +{ return DT_EQ; };
  127194. YY_BREAK
  127195. case 27:
  127196. YY_RULE_SETUP
  127197. -#line 209 "dtc-lexer.l"
  127198. -{ return DT_AND; };
  127199. +#line 241 "dtc-lexer.l"
  127200. +{ return DT_NE; };
  127201. YY_BREAK
  127202. case 28:
  127203. YY_RULE_SETUP
  127204. -#line 210 "dtc-lexer.l"
  127205. -{ return DT_OR; };
  127206. +#line 242 "dtc-lexer.l"
  127207. +{ return DT_AND; };
  127208. YY_BREAK
  127209. case 29:
  127210. YY_RULE_SETUP
  127211. -#line 212 "dtc-lexer.l"
  127212. +#line 243 "dtc-lexer.l"
  127213. +{ return DT_OR; };
  127214. + YY_BREAK
  127215. +case 30:
  127216. +YY_RULE_SETUP
  127217. +#line 245 "dtc-lexer.l"
  127218. {
  127219. DPRINT("Char: %c (\\x%02x)\n", yytext[0],
  127220. (unsigned)yytext[0]);
  127221. @@ -1202,12 +1239,12 @@
  127222. return yytext[0];
  127223. }
  127224. YY_BREAK
  127225. -case 30:
  127226. +case 31:
  127227. YY_RULE_SETUP
  127228. -#line 227 "dtc-lexer.l"
  127229. +#line 260 "dtc-lexer.l"
  127230. ECHO;
  127231. YY_BREAK
  127232. -#line 1211 "dtc-lexer.lex.c"
  127233. +#line 1248 "dtc-lexer.lex.c"
  127234. case YY_END_OF_BUFFER:
  127235. {
  127236. @@ -1499,7 +1536,7 @@
  127237. while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
  127238. {
  127239. yy_current_state = (int) yy_def[yy_current_state];
  127240. - if ( yy_current_state >= 161 )
  127241. + if ( yy_current_state >= 166 )
  127242. yy_c = yy_meta[(unsigned int) yy_c];
  127243. }
  127244. yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
  127245. @@ -1527,11 +1564,11 @@
  127246. while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
  127247. {
  127248. yy_current_state = (int) yy_def[yy_current_state];
  127249. - if ( yy_current_state >= 161 )
  127250. + if ( yy_current_state >= 166 )
  127251. yy_c = yy_meta[(unsigned int) yy_c];
  127252. }
  127253. yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
  127254. - yy_is_jam = (yy_current_state == 160);
  127255. + yy_is_jam = (yy_current_state == 165);
  127256. return yy_is_jam ? 0 : yy_current_state;
  127257. }
  127258. @@ -2166,7 +2203,7 @@
  127259. #define YYTABLES_NAME "yytables"
  127260. -#line 227 "dtc-lexer.l"
  127261. +#line 260 "dtc-lexer.l"
  127262. @@ -2182,14 +2219,25 @@
  127263. }
  127264. -static int pop_input_file(void)
  127265. +static bool pop_input_file(void)
  127266. {
  127267. if (srcfile_pop() == 0)
  127268. - return 0;
  127269. + return false;
  127270. yypop_buffer_state();
  127271. yyin = current_srcfile->f;
  127272. - return 1;
  127273. + return true;
  127274. +}
  127275. +
  127276. +static void lexical_error(const char *fmt, ...)
  127277. +{
  127278. + va_list ap;
  127279. +
  127280. + va_start(ap, fmt);
  127281. + srcpos_verror(&yylloc, "Lexical error", fmt, ap);
  127282. + va_end(ap);
  127283. +
  127284. + treesource_error = true;
  127285. }
  127286. diff -Nur linux-3.18.8/scripts/dtc/dtc-parser.tab.c_shipped linux-rpi/scripts/dtc/dtc-parser.tab.c_shipped
  127287. --- linux-3.18.8/scripts/dtc/dtc-parser.tab.c_shipped 2015-02-27 02:49:36.000000000 +0100
  127288. +++ linux-rpi/scripts/dtc/dtc-parser.tab.c_shipped 2015-03-05 14:40:18.913715792 +0100
  127289. @@ -1,19 +1,19 @@
  127290. -/* A Bison parser, made by GNU Bison 2.7.12-4996. */
  127291. +/* A Bison parser, made by GNU Bison 3.0.2. */
  127292. /* Bison implementation for Yacc-like parsers in C
  127293. -
  127294. - Copyright (C) 1984, 1989-1990, 2000-2013 Free Software Foundation, Inc.
  127295. -
  127296. +
  127297. + Copyright (C) 1984, 1989-1990, 2000-2013 Free Software Foundation, Inc.
  127298. +
  127299. This program is free software: you can redistribute it and/or modify
  127300. it under the terms of the GNU General Public License as published by
  127301. the Free Software Foundation, either version 3 of the License, or
  127302. (at your option) any later version.
  127303. -
  127304. +
  127305. This program is distributed in the hope that it will be useful,
  127306. but WITHOUT ANY WARRANTY; without even the implied warranty of
  127307. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  127308. GNU General Public License for more details.
  127309. -
  127310. +
  127311. You should have received a copy of the GNU General Public License
  127312. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  127313. @@ -26,7 +26,7 @@
  127314. special exception, which will cause the skeleton and the resulting
  127315. Bison output files to be licensed under the GNU General Public
  127316. License without this special exception.
  127317. -
  127318. +
  127319. This special exception was added by the Free Software Foundation in
  127320. version 2.2 of Bison. */
  127321. @@ -44,7 +44,7 @@
  127322. #define YYBISON 1
  127323. /* Bison version. */
  127324. -#define YYBISON_VERSION "2.7.12-4996"
  127325. +#define YYBISON_VERSION "3.0.2"
  127326. /* Skeleton name. */
  127327. #define YYSKELETON_NAME "yacc.c"
  127328. @@ -62,34 +62,32 @@
  127329. /* Copy the first part of user declarations. */
  127330. -/* Line 371 of yacc.c */
  127331. -#line 21 "dtc-parser.y"
  127332. +#line 20 "dtc-parser.y" /* yacc.c:339 */
  127333. #include <stdio.h>
  127334. +#include <inttypes.h>
  127335. #include "dtc.h"
  127336. #include "srcpos.h"
  127337. -YYLTYPE yylloc;
  127338. -
  127339. extern int yylex(void);
  127340. -extern void print_error(char const *fmt, ...);
  127341. extern void yyerror(char const *s);
  127342. +#define ERROR(loc, ...) \
  127343. + do { \
  127344. + srcpos_error((loc), "Error", __VA_ARGS__); \
  127345. + treesource_error = true; \
  127346. + } while (0)
  127347. extern struct boot_info *the_boot_info;
  127348. -extern int treesource_error;
  127349. -
  127350. -static unsigned long long eval_literal(const char *s, int base, int bits);
  127351. -static unsigned char eval_char_literal(const char *s);
  127352. +extern bool treesource_error;
  127353. -/* Line 371 of yacc.c */
  127354. -#line 87 "dtc-parser.tab.c"
  127355. +#line 85 "dtc-parser.tab.c" /* yacc.c:339 */
  127356. -# ifndef YY_NULL
  127357. +# ifndef YY_NULLPTR
  127358. # if defined __cplusplus && 201103L <= __cplusplus
  127359. -# define YY_NULL nullptr
  127360. +# define YY_NULLPTR nullptr
  127361. # else
  127362. -# define YY_NULL 0
  127363. +# define YY_NULLPTR 0
  127364. # endif
  127365. # endif
  127366. @@ -105,7 +103,7 @@
  127367. by #include "dtc-parser.tab.h". */
  127368. #ifndef YY_YY_DTC_PARSER_TAB_H_INCLUDED
  127369. # define YY_YY_DTC_PARSER_TAB_H_INCLUDED
  127370. -/* Enabling traces. */
  127371. +/* Debug traces. */
  127372. #ifndef YYDEBUG
  127373. # define YYDEBUG 0
  127374. #endif
  127375. @@ -113,48 +111,45 @@
  127376. extern int yydebug;
  127377. #endif
  127378. -/* Tokens. */
  127379. +/* Token type. */
  127380. #ifndef YYTOKENTYPE
  127381. # define YYTOKENTYPE
  127382. - /* Put the tokens into the symbol table, so that GDB and other debuggers
  127383. - know about them. */
  127384. - enum yytokentype {
  127385. - DT_V1 = 258,
  127386. - DT_MEMRESERVE = 259,
  127387. - DT_LSHIFT = 260,
  127388. - DT_RSHIFT = 261,
  127389. - DT_LE = 262,
  127390. - DT_GE = 263,
  127391. - DT_EQ = 264,
  127392. - DT_NE = 265,
  127393. - DT_AND = 266,
  127394. - DT_OR = 267,
  127395. - DT_BITS = 268,
  127396. - DT_DEL_PROP = 269,
  127397. - DT_DEL_NODE = 270,
  127398. - DT_PROPNODENAME = 271,
  127399. - DT_LITERAL = 272,
  127400. - DT_CHAR_LITERAL = 273,
  127401. - DT_BASE = 274,
  127402. - DT_BYTE = 275,
  127403. - DT_STRING = 276,
  127404. - DT_LABEL = 277,
  127405. - DT_REF = 278,
  127406. - DT_INCBIN = 279
  127407. - };
  127408. + enum yytokentype
  127409. + {
  127410. + DT_V1 = 258,
  127411. + DT_PLUGIN = 259,
  127412. + DT_MEMRESERVE = 260,
  127413. + DT_LSHIFT = 261,
  127414. + DT_RSHIFT = 262,
  127415. + DT_LE = 263,
  127416. + DT_GE = 264,
  127417. + DT_EQ = 265,
  127418. + DT_NE = 266,
  127419. + DT_AND = 267,
  127420. + DT_OR = 268,
  127421. + DT_BITS = 269,
  127422. + DT_DEL_PROP = 270,
  127423. + DT_DEL_NODE = 271,
  127424. + DT_PROPNODENAME = 272,
  127425. + DT_LITERAL = 273,
  127426. + DT_CHAR_LITERAL = 274,
  127427. + DT_BYTE = 275,
  127428. + DT_STRING = 276,
  127429. + DT_LABEL = 277,
  127430. + DT_REF = 278,
  127431. + DT_INCBIN = 279
  127432. + };
  127433. #endif
  127434. -
  127435. +/* Value type. */
  127436. #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
  127437. -typedef union YYSTYPE
  127438. +typedef union YYSTYPE YYSTYPE;
  127439. +union YYSTYPE
  127440. {
  127441. -/* Line 387 of yacc.c */
  127442. -#line 40 "dtc-parser.y"
  127443. +#line 39 "dtc-parser.y" /* yacc.c:355 */
  127444. char *propnodename;
  127445. - char *literal;
  127446. char *labelref;
  127447. - unsigned int cbase;
  127448. uint8_t byte;
  127449. struct data data;
  127450. @@ -169,38 +164,38 @@
  127451. struct node *nodelist;
  127452. struct reserve_info *re;
  127453. uint64_t integer;
  127454. + int is_plugin;
  127455. -
  127456. -/* Line 387 of yacc.c */
  127457. -#line 176 "dtc-parser.tab.c"
  127458. -} YYSTYPE;
  127459. +#line 170 "dtc-parser.tab.c" /* yacc.c:355 */
  127460. +};
  127461. # define YYSTYPE_IS_TRIVIAL 1
  127462. -# define yystype YYSTYPE /* obsolescent; will be withdrawn */
  127463. # define YYSTYPE_IS_DECLARED 1
  127464. #endif
  127465. -extern YYSTYPE yylval;
  127466. -
  127467. -#ifdef YYPARSE_PARAM
  127468. -#if defined __STDC__ || defined __cplusplus
  127469. -int yyparse (void *YYPARSE_PARAM);
  127470. -#else
  127471. -int yyparse ();
  127472. +/* Location type. */
  127473. +#if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
  127474. +typedef struct YYLTYPE YYLTYPE;
  127475. +struct YYLTYPE
  127476. +{
  127477. + int first_line;
  127478. + int first_column;
  127479. + int last_line;
  127480. + int last_column;
  127481. +};
  127482. +# define YYLTYPE_IS_DECLARED 1
  127483. +# define YYLTYPE_IS_TRIVIAL 1
  127484. #endif
  127485. -#else /* ! YYPARSE_PARAM */
  127486. -#if defined __STDC__ || defined __cplusplus
  127487. +
  127488. +
  127489. +extern YYSTYPE yylval;
  127490. +extern YYLTYPE yylloc;
  127491. int yyparse (void);
  127492. -#else
  127493. -int yyparse ();
  127494. -#endif
  127495. -#endif /* ! YYPARSE_PARAM */
  127496. #endif /* !YY_YY_DTC_PARSER_TAB_H_INCLUDED */
  127497. /* Copy the second part of user declarations. */
  127498. -/* Line 390 of yacc.c */
  127499. -#line 204 "dtc-parser.tab.c"
  127500. +#line 199 "dtc-parser.tab.c" /* yacc.c:358 */
  127501. #ifdef short
  127502. # undef short
  127503. @@ -214,11 +209,8 @@
  127504. #ifdef YYTYPE_INT8
  127505. typedef YYTYPE_INT8 yytype_int8;
  127506. -#elif (defined __STDC__ || defined __C99__FUNC__ \
  127507. - || defined __cplusplus || defined _MSC_VER)
  127508. -typedef signed char yytype_int8;
  127509. #else
  127510. -typedef short int yytype_int8;
  127511. +typedef signed char yytype_int8;
  127512. #endif
  127513. #ifdef YYTYPE_UINT16
  127514. @@ -238,8 +230,7 @@
  127515. # define YYSIZE_T __SIZE_TYPE__
  127516. # elif defined size_t
  127517. # define YYSIZE_T size_t
  127518. -# elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \
  127519. - || defined __cplusplus || defined _MSC_VER)
  127520. +# elif ! defined YYSIZE_T
  127521. # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
  127522. # define YYSIZE_T size_t
  127523. # else
  127524. @@ -261,11 +252,30 @@
  127525. # endif
  127526. #endif
  127527. -#ifndef __attribute__
  127528. -/* This feature is available in gcc versions 2.5 and later. */
  127529. -# if (! defined __GNUC__ || __GNUC__ < 2 \
  127530. - || (__GNUC__ == 2 && __GNUC_MINOR__ < 5))
  127531. -# define __attribute__(Spec) /* empty */
  127532. +#ifndef YY_ATTRIBUTE
  127533. +# if (defined __GNUC__ \
  127534. + && (2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__))) \
  127535. + || defined __SUNPRO_C && 0x5110 <= __SUNPRO_C
  127536. +# define YY_ATTRIBUTE(Spec) __attribute__(Spec)
  127537. +# else
  127538. +# define YY_ATTRIBUTE(Spec) /* empty */
  127539. +# endif
  127540. +#endif
  127541. +
  127542. +#ifndef YY_ATTRIBUTE_PURE
  127543. +# define YY_ATTRIBUTE_PURE YY_ATTRIBUTE ((__pure__))
  127544. +#endif
  127545. +
  127546. +#ifndef YY_ATTRIBUTE_UNUSED
  127547. +# define YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE ((__unused__))
  127548. +#endif
  127549. +
  127550. +#if !defined _Noreturn \
  127551. + && (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112)
  127552. +# if defined _MSC_VER && 1200 <= _MSC_VER
  127553. +# define _Noreturn __declspec (noreturn)
  127554. +# else
  127555. +# define _Noreturn YY_ATTRIBUTE ((__noreturn__))
  127556. # endif
  127557. #endif
  127558. @@ -276,24 +286,25 @@
  127559. # define YYUSE(E) /* empty */
  127560. #endif
  127561. -
  127562. -/* Identity function, used to suppress warnings about constant conditions. */
  127563. -#ifndef lint
  127564. -# define YYID(N) (N)
  127565. -#else
  127566. -#if (defined __STDC__ || defined __C99__FUNC__ \
  127567. - || defined __cplusplus || defined _MSC_VER)
  127568. -static int
  127569. -YYID (int yyi)
  127570. +#if defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__
  127571. +/* Suppress an incorrect diagnostic about yylval being uninitialized. */
  127572. +# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
  127573. + _Pragma ("GCC diagnostic push") \
  127574. + _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\
  127575. + _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
  127576. +# define YY_IGNORE_MAYBE_UNINITIALIZED_END \
  127577. + _Pragma ("GCC diagnostic pop")
  127578. #else
  127579. -static int
  127580. -YYID (yyi)
  127581. - int yyi;
  127582. +# define YY_INITIAL_VALUE(Value) Value
  127583. #endif
  127584. -{
  127585. - return yyi;
  127586. -}
  127587. +#ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
  127588. +# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
  127589. +# define YY_IGNORE_MAYBE_UNINITIALIZED_END
  127590. #endif
  127591. +#ifndef YY_INITIAL_VALUE
  127592. +# define YY_INITIAL_VALUE(Value) /* Nothing. */
  127593. +#endif
  127594. +
  127595. #if ! defined yyoverflow || YYERROR_VERBOSE
  127596. @@ -312,8 +323,7 @@
  127597. # define alloca _alloca
  127598. # else
  127599. # define YYSTACK_ALLOC alloca
  127600. -# if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \
  127601. - || defined __cplusplus || defined _MSC_VER)
  127602. +# if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS
  127603. # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
  127604. /* Use EXIT_SUCCESS as a witness for stdlib.h. */
  127605. # ifndef EXIT_SUCCESS
  127606. @@ -325,8 +335,8 @@
  127607. # endif
  127608. # ifdef YYSTACK_ALLOC
  127609. - /* Pacify GCC's `empty if-body' warning. */
  127610. -# define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0))
  127611. + /* Pacify GCC's 'empty if-body' warning. */
  127612. +# define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
  127613. # ifndef YYSTACK_ALLOC_MAXIMUM
  127614. /* The OS might guarantee only one guard page at the bottom of the stack,
  127615. and a page size can be as small as 4096 bytes. So we cannot safely
  127616. @@ -342,7 +352,7 @@
  127617. # endif
  127618. # if (defined __cplusplus && ! defined EXIT_SUCCESS \
  127619. && ! ((defined YYMALLOC || defined malloc) \
  127620. - && (defined YYFREE || defined free)))
  127621. + && (defined YYFREE || defined free)))
  127622. # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
  127623. # ifndef EXIT_SUCCESS
  127624. # define EXIT_SUCCESS 0
  127625. @@ -350,15 +360,13 @@
  127626. # endif
  127627. # ifndef YYMALLOC
  127628. # define YYMALLOC malloc
  127629. -# if ! defined malloc && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \
  127630. - || defined __cplusplus || defined _MSC_VER)
  127631. +# if ! defined malloc && ! defined EXIT_SUCCESS
  127632. void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
  127633. # endif
  127634. # endif
  127635. # ifndef YYFREE
  127636. # define YYFREE free
  127637. -# if ! defined free && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \
  127638. - || defined __cplusplus || defined _MSC_VER)
  127639. +# if ! defined free && ! defined EXIT_SUCCESS
  127640. void free (void *); /* INFRINGES ON USER NAME SPACE */
  127641. # endif
  127642. # endif
  127643. @@ -368,13 +376,15 @@
  127644. #if (! defined yyoverflow \
  127645. && (! defined __cplusplus \
  127646. - || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
  127647. + || (defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL \
  127648. + && defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
  127649. /* A type that is properly aligned for any stack member. */
  127650. union yyalloc
  127651. {
  127652. yytype_int16 yyss_alloc;
  127653. YYSTYPE yyvs_alloc;
  127654. + YYLTYPE yyls_alloc;
  127655. };
  127656. /* The size of the maximum gap between one aligned stack and the next. */
  127657. @@ -383,8 +393,8 @@
  127658. /* The size of an array large to enough to hold all stacks, each with
  127659. N elements. */
  127660. # define YYSTACK_BYTES(N) \
  127661. - ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
  127662. - + YYSTACK_GAP_MAXIMUM)
  127663. + ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE) + sizeof (YYLTYPE)) \
  127664. + + 2 * YYSTACK_GAP_MAXIMUM)
  127665. # define YYCOPY_NEEDED 1
  127666. @@ -393,16 +403,16 @@
  127667. elements in the stack, and YYPTR gives the new location of the
  127668. stack. Advance YYPTR to a properly aligned location for the next
  127669. stack. */
  127670. -# define YYSTACK_RELOCATE(Stack_alloc, Stack) \
  127671. - do \
  127672. - { \
  127673. - YYSIZE_T yynewbytes; \
  127674. - YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \
  127675. - Stack = &yyptr->Stack_alloc; \
  127676. - yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
  127677. - yyptr += yynewbytes / sizeof (*yyptr); \
  127678. - } \
  127679. - while (YYID (0))
  127680. +# define YYSTACK_RELOCATE(Stack_alloc, Stack) \
  127681. + do \
  127682. + { \
  127683. + YYSIZE_T yynewbytes; \
  127684. + YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \
  127685. + Stack = &yyptr->Stack_alloc; \
  127686. + yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
  127687. + yyptr += yynewbytes / sizeof (*yyptr); \
  127688. + } \
  127689. + while (0)
  127690. #endif
  127691. @@ -421,7 +431,7 @@
  127692. for (yyi = 0; yyi < (Count); yyi++) \
  127693. (Dst)[yyi] = (Src)[yyi]; \
  127694. } \
  127695. - while (YYID (0))
  127696. + while (0)
  127697. # endif
  127698. # endif
  127699. #endif /* !YYCOPY_NEEDED */
  127700. @@ -429,25 +439,27 @@
  127701. /* YYFINAL -- State number of the termination state. */
  127702. #define YYFINAL 4
  127703. /* YYLAST -- Last index in YYTABLE. */
  127704. -#define YYLAST 133
  127705. +#define YYLAST 135
  127706. /* YYNTOKENS -- Number of terminals. */
  127707. #define YYNTOKENS 48
  127708. /* YYNNTS -- Number of nonterminals. */
  127709. -#define YYNNTS 28
  127710. +#define YYNNTS 29
  127711. /* YYNRULES -- Number of rules. */
  127712. -#define YYNRULES 79
  127713. -/* YYNRULES -- Number of states. */
  127714. -#define YYNSTATES 141
  127715. +#define YYNRULES 81
  127716. +/* YYNSTATES -- Number of states. */
  127717. +#define YYNSTATES 144
  127718. -/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
  127719. +/* YYTRANSLATE[YYX] -- Symbol number corresponding to YYX as returned
  127720. + by yylex, with out-of-bounds checking. */
  127721. #define YYUNDEFTOK 2
  127722. #define YYMAXUTOK 279
  127723. -#define YYTRANSLATE(YYX) \
  127724. +#define YYTRANSLATE(YYX) \
  127725. ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
  127726. -/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
  127727. +/* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM
  127728. + as returned by yylex, without out-of-bounds checking. */
  127729. static const yytype_uint8 yytranslate[] =
  127730. {
  127731. 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  127732. @@ -481,63 +493,18 @@
  127733. };
  127734. #if YYDEBUG
  127735. -/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
  127736. - YYRHS. */
  127737. -static const yytype_uint16 yyprhs[] =
  127738. -{
  127739. - 0, 0, 3, 8, 9, 12, 17, 20, 23, 27,
  127740. - 31, 36, 42, 43, 46, 51, 54, 58, 61, 64,
  127741. - 68, 73, 76, 86, 92, 95, 96, 99, 102, 106,
  127742. - 108, 111, 114, 117, 119, 121, 125, 127, 129, 135,
  127743. - 137, 141, 143, 147, 149, 153, 155, 159, 161, 165,
  127744. - 167, 171, 175, 177, 181, 185, 189, 193, 197, 201,
  127745. - 203, 207, 211, 213, 217, 221, 225, 227, 229, 232,
  127746. - 235, 238, 239, 242, 245, 246, 249, 252, 255, 259
  127747. -};
  127748. -
  127749. -/* YYRHS -- A `-1'-separated list of the rules' RHS. */
  127750. -static const yytype_int8 yyrhs[] =
  127751. -{
  127752. - 49, 0, -1, 3, 25, 50, 52, -1, -1, 51,
  127753. - 50, -1, 4, 59, 59, 25, -1, 22, 51, -1,
  127754. - 26, 53, -1, 52, 26, 53, -1, 52, 23, 53,
  127755. - -1, 52, 15, 23, 25, -1, 27, 54, 74, 28,
  127756. - 25, -1, -1, 54, 55, -1, 16, 29, 56, 25,
  127757. - -1, 16, 25, -1, 14, 16, 25, -1, 22, 55,
  127758. - -1, 57, 21, -1, 57, 58, 30, -1, 57, 31,
  127759. - 73, 32, -1, 57, 23, -1, 57, 24, 33, 21,
  127760. - 34, 59, 34, 59, 35, -1, 57, 24, 33, 21,
  127761. - 35, -1, 56, 22, -1, -1, 56, 34, -1, 57,
  127762. - 22, -1, 13, 17, 36, -1, 36, -1, 58, 59,
  127763. - -1, 58, 23, -1, 58, 22, -1, 17, -1, 18,
  127764. - -1, 33, 60, 35, -1, 61, -1, 62, -1, 62,
  127765. - 37, 60, 38, 61, -1, 63, -1, 62, 12, 63,
  127766. - -1, 64, -1, 63, 11, 64, -1, 65, -1, 64,
  127767. - 39, 65, -1, 66, -1, 65, 40, 66, -1, 67,
  127768. - -1, 66, 41, 67, -1, 68, -1, 67, 9, 68,
  127769. - -1, 67, 10, 68, -1, 69, -1, 68, 36, 69,
  127770. - -1, 68, 30, 69, -1, 68, 7, 69, -1, 68,
  127771. - 8, 69, -1, 69, 5, 70, -1, 69, 6, 70,
  127772. - -1, 70, -1, 70, 42, 71, -1, 70, 43, 71,
  127773. - -1, 71, -1, 71, 44, 72, -1, 71, 26, 72,
  127774. - -1, 71, 45, 72, -1, 72, -1, 59, -1, 43,
  127775. - 72, -1, 46, 72, -1, 47, 72, -1, -1, 73,
  127776. - 20, -1, 73, 22, -1, -1, 75, 74, -1, 75,
  127777. - 55, -1, 16, 53, -1, 15, 16, 25, -1, 22,
  127778. - 75, -1
  127779. -};
  127780. -
  127781. -/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
  127782. + /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
  127783. static const yytype_uint16 yyrline[] =
  127784. {
  127785. - 0, 109, 109, 118, 121, 128, 132, 140, 144, 148,
  127786. - 158, 172, 180, 183, 190, 194, 198, 202, 210, 214,
  127787. - 218, 222, 226, 243, 253, 261, 264, 268, 275, 290,
  127788. - 295, 315, 329, 336, 340, 344, 351, 355, 356, 360,
  127789. - 361, 365, 366, 370, 371, 375, 376, 380, 381, 385,
  127790. - 386, 387, 391, 392, 393, 394, 395, 399, 400, 401,
  127791. - 405, 406, 407, 411, 412, 413, 414, 418, 419, 420,
  127792. - 421, 426, 429, 433, 441, 444, 448, 456, 460, 464
  127793. + 0, 108, 108, 119, 122, 130, 133, 140, 144, 152,
  127794. + 156, 160, 170, 185, 193, 196, 203, 207, 211, 215,
  127795. + 223, 227, 231, 235, 239, 255, 265, 273, 276, 280,
  127796. + 287, 303, 308, 327, 341, 348, 349, 350, 357, 361,
  127797. + 362, 366, 367, 371, 372, 376, 377, 381, 382, 386,
  127798. + 387, 391, 392, 393, 397, 398, 399, 400, 401, 405,
  127799. + 406, 407, 411, 412, 413, 417, 418, 419, 420, 424,
  127800. + 425, 426, 427, 432, 435, 439, 447, 450, 454, 462,
  127801. + 466, 470
  127802. };
  127803. #endif
  127804. @@ -546,25 +513,25 @@
  127805. First, the terminals, then, starting at YYNTOKENS, nonterminals. */
  127806. static const char *const yytname[] =
  127807. {
  127808. - "$end", "error", "$undefined", "DT_V1", "DT_MEMRESERVE", "DT_LSHIFT",
  127809. - "DT_RSHIFT", "DT_LE", "DT_GE", "DT_EQ", "DT_NE", "DT_AND", "DT_OR",
  127810. - "DT_BITS", "DT_DEL_PROP", "DT_DEL_NODE", "DT_PROPNODENAME", "DT_LITERAL",
  127811. - "DT_CHAR_LITERAL", "DT_BASE", "DT_BYTE", "DT_STRING", "DT_LABEL",
  127812. + "$end", "error", "$undefined", "DT_V1", "DT_PLUGIN", "DT_MEMRESERVE",
  127813. + "DT_LSHIFT", "DT_RSHIFT", "DT_LE", "DT_GE", "DT_EQ", "DT_NE", "DT_AND",
  127814. + "DT_OR", "DT_BITS", "DT_DEL_PROP", "DT_DEL_NODE", "DT_PROPNODENAME",
  127815. + "DT_LITERAL", "DT_CHAR_LITERAL", "DT_BYTE", "DT_STRING", "DT_LABEL",
  127816. "DT_REF", "DT_INCBIN", "';'", "'/'", "'{'", "'}'", "'='", "'>'", "'['",
  127817. "']'", "'('", "','", "')'", "'<'", "'?'", "':'", "'|'", "'^'", "'&'",
  127818. "'+'", "'-'", "'*'", "'%'", "'~'", "'!'", "$accept", "sourcefile",
  127819. - "memreserves", "memreserve", "devicetree", "nodedef", "proplist",
  127820. - "propdef", "propdata", "propdataprefix", "arrayprefix", "integer_prim",
  127821. - "integer_expr", "integer_trinary", "integer_or", "integer_and",
  127822. - "integer_bitor", "integer_bitxor", "integer_bitand", "integer_eq",
  127823. - "integer_rela", "integer_shift", "integer_add", "integer_mul",
  127824. - "integer_unary", "bytestring", "subnodes", "subnode", YY_NULL
  127825. + "plugindecl", "memreserves", "memreserve", "devicetree", "nodedef",
  127826. + "proplist", "propdef", "propdata", "propdataprefix", "arrayprefix",
  127827. + "integer_prim", "integer_expr", "integer_trinary", "integer_or",
  127828. + "integer_and", "integer_bitor", "integer_bitxor", "integer_bitand",
  127829. + "integer_eq", "integer_rela", "integer_shift", "integer_add",
  127830. + "integer_mul", "integer_unary", "bytestring", "subnodes", "subnode", YY_NULLPTR
  127831. };
  127832. #endif
  127833. # ifdef YYPRINT
  127834. -/* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
  127835. - token YYLEX-NUM. */
  127836. +/* YYTOKNUM[NUM] -- (External) token number corresponding to the
  127837. + (internal) symbol number NUM (which must be that of a token). */
  127838. static const yytype_uint16 yytoknum[] =
  127839. {
  127840. 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
  127841. @@ -575,183 +542,173 @@
  127842. };
  127843. # endif
  127844. -/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
  127845. -static const yytype_uint8 yyr1[] =
  127846. -{
  127847. - 0, 48, 49, 50, 50, 51, 51, 52, 52, 52,
  127848. - 52, 53, 54, 54, 55, 55, 55, 55, 56, 56,
  127849. - 56, 56, 56, 56, 56, 57, 57, 57, 58, 58,
  127850. - 58, 58, 58, 59, 59, 59, 60, 61, 61, 62,
  127851. - 62, 63, 63, 64, 64, 65, 65, 66, 66, 67,
  127852. - 67, 67, 68, 68, 68, 68, 68, 69, 69, 69,
  127853. - 70, 70, 70, 71, 71, 71, 71, 72, 72, 72,
  127854. - 72, 73, 73, 73, 74, 74, 74, 75, 75, 75
  127855. -};
  127856. +#define YYPACT_NINF -41
  127857. -/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
  127858. -static const yytype_uint8 yyr2[] =
  127859. +#define yypact_value_is_default(Yystate) \
  127860. + (!!((Yystate) == (-41)))
  127861. +
  127862. +#define YYTABLE_NINF -1
  127863. +
  127864. +#define yytable_value_is_error(Yytable_value) \
  127865. + 0
  127866. +
  127867. + /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
  127868. + STATE-NUM. */
  127869. +static const yytype_int8 yypact[] =
  127870. {
  127871. - 0, 2, 4, 0, 2, 4, 2, 2, 3, 3,
  127872. - 4, 5, 0, 2, 4, 2, 3, 2, 2, 3,
  127873. - 4, 2, 9, 5, 2, 0, 2, 2, 3, 1,
  127874. - 2, 2, 2, 1, 1, 3, 1, 1, 5, 1,
  127875. - 3, 1, 3, 1, 3, 1, 3, 1, 3, 1,
  127876. - 3, 3, 1, 3, 3, 3, 3, 3, 3, 1,
  127877. - 3, 3, 1, 3, 3, 3, 1, 1, 2, 2,
  127878. - 2, 0, 2, 2, 0, 2, 2, 2, 3, 2
  127879. + 37, 10, 24, 78, -41, 20, 9, -41, 8, 9,
  127880. + 59, 9, -41, -41, -10, 8, -41, 60, 39, -41,
  127881. + -10, -10, -10, -41, 51, -41, -7, 76, 50, 52,
  127882. + 53, 49, 2, 65, 32, -1, -41, 66, -41, -41,
  127883. + 67, 60, 60, -41, -41, -41, -41, -10, -10, -10,
  127884. + -10, -10, -10, -10, -10, -10, -10, -10, -10, -10,
  127885. + -10, -10, -10, -10, -10, -10, -41, 41, 68, -41,
  127886. + -41, 76, 57, 50, 52, 53, 49, 2, 2, 65,
  127887. + 65, 65, 65, 32, 32, -1, -1, -41, -41, -41,
  127888. + 79, 80, -12, 41, -41, 70, 41, -41, -10, 74,
  127889. + 75, -41, -41, -41, -41, -41, 77, -41, -41, -41,
  127890. + -41, -41, 17, -2, -41, -41, -41, -41, 83, -41,
  127891. + -41, -41, 71, -41, -41, 31, 69, 82, -4, -41,
  127892. + -41, -41, -41, -41, 42, -41, -41, -41, 8, -41,
  127893. + 72, 8, 73, -41
  127894. };
  127895. -/* YYDEFACT[STATE-NAME] -- Default reduction number in state STATE-NUM.
  127896. - Performed when YYTABLE doesn't specify something else to do. Zero
  127897. - means the default is an error. */
  127898. + /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
  127899. + Performed when YYTABLE does not specify something else to do. Zero
  127900. + means the default is an error. */
  127901. static const yytype_uint8 yydefact[] =
  127902. {
  127903. - 0, 0, 0, 3, 1, 0, 0, 0, 3, 33,
  127904. - 34, 0, 0, 6, 0, 2, 4, 0, 0, 0,
  127905. - 67, 0, 36, 37, 39, 41, 43, 45, 47, 49,
  127906. - 52, 59, 62, 66, 0, 12, 7, 0, 0, 0,
  127907. - 68, 69, 70, 35, 0, 0, 0, 0, 0, 0,
  127908. + 0, 0, 0, 3, 1, 0, 5, 4, 0, 0,
  127909. + 0, 5, 35, 36, 0, 0, 8, 0, 2, 6,
  127910. + 0, 0, 0, 69, 0, 38, 39, 41, 43, 45,
  127911. + 47, 49, 51, 54, 61, 64, 68, 0, 14, 9,
  127912. + 0, 0, 0, 70, 71, 72, 37, 0, 0, 0,
  127913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127914. - 0, 0, 0, 5, 74, 0, 9, 8, 40, 0,
  127915. - 42, 44, 46, 48, 50, 51, 55, 56, 54, 53,
  127916. - 57, 58, 60, 61, 64, 63, 65, 0, 0, 0,
  127917. - 0, 13, 0, 74, 10, 0, 0, 0, 15, 25,
  127918. - 77, 17, 79, 0, 76, 75, 38, 16, 78, 0,
  127919. - 0, 11, 24, 14, 26, 0, 18, 27, 21, 0,
  127920. - 71, 29, 0, 0, 0, 0, 32, 31, 19, 30,
  127921. - 28, 0, 72, 73, 20, 0, 23, 0, 0, 0,
  127922. - 22
  127923. + 0, 0, 0, 0, 0, 0, 7, 76, 0, 11,
  127924. + 10, 42, 0, 44, 46, 48, 50, 52, 53, 57,
  127925. + 58, 56, 55, 59, 60, 62, 63, 66, 65, 67,
  127926. + 0, 0, 0, 0, 15, 0, 76, 12, 0, 0,
  127927. + 0, 17, 27, 79, 19, 81, 0, 78, 77, 40,
  127928. + 18, 80, 0, 0, 13, 26, 16, 28, 0, 20,
  127929. + 29, 23, 0, 73, 31, 0, 0, 0, 0, 34,
  127930. + 33, 21, 32, 30, 0, 74, 75, 22, 0, 25,
  127931. + 0, 0, 0, 24
  127932. };
  127933. -/* YYDEFGOTO[NTERM-NUM]. */
  127934. -static const yytype_int8 yydefgoto[] =
  127935. + /* YYPGOTO[NTERM-NUM]. */
  127936. +static const yytype_int8 yypgoto[] =
  127937. {
  127938. - -1, 2, 7, 8, 15, 36, 64, 91, 109, 110,
  127939. - 122, 20, 21, 22, 23, 24, 25, 26, 27, 28,
  127940. - 29, 30, 31, 32, 33, 125, 92, 93
  127941. + -41, -41, -41, 96, 100, -41, -40, -41, -23, -41,
  127942. + -41, -41, -8, 62, 13, -41, 81, 63, 64, 84,
  127943. + 61, 25, 11, 21, 22, -17, -41, 19, 23
  127944. };
  127945. -/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
  127946. - STATE-NUM. */
  127947. -#define YYPACT_NINF -78
  127948. -static const yytype_int8 yypact[] =
  127949. + /* YYDEFGOTO[NTERM-NUM]. */
  127950. +static const yytype_int16 yydefgoto[] =
  127951. {
  127952. - 22, 11, 51, 10, -78, 23, 10, 2, 10, -78,
  127953. - -78, -9, 23, -78, 30, 38, -78, -9, -9, -9,
  127954. - -78, 35, -78, -6, 52, 29, 48, 49, 33, 3,
  127955. - 71, 36, 0, -78, 64, -78, -78, 68, 30, 30,
  127956. - -78, -78, -78, -78, -9, -9, -9, -9, -9, -9,
  127957. - -9, -9, -9, -9, -9, -9, -9, -9, -9, -9,
  127958. - -9, -9, -9, -78, 44, 67, -78, -78, 52, 55,
  127959. - 29, 48, 49, 33, 3, 3, 71, 71, 71, 71,
  127960. - 36, 36, 0, 0, -78, -78, -78, 78, 79, 42,
  127961. - 44, -78, 69, 44, -78, -9, 73, 74, -78, -78,
  127962. - -78, -78, -78, 75, -78, -78, -78, -78, -78, -7,
  127963. - -1, -78, -78, -78, -78, 84, -78, -78, -78, 63,
  127964. - -78, -78, 32, 66, 82, -3, -78, -78, -78, -78,
  127965. - -78, 46, -78, -78, -78, 23, -78, 70, 23, 72,
  127966. - -78
  127967. + -1, 2, 6, 10, 11, 18, 39, 67, 94, 112,
  127968. + 113, 125, 23, 24, 25, 26, 27, 28, 29, 30,
  127969. + 31, 32, 33, 34, 35, 36, 128, 95, 96
  127970. };
  127971. -/* YYPGOTO[NTERM-NUM]. */
  127972. -static const yytype_int8 yypgoto[] =
  127973. + /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If
  127974. + positive, shift that token. If negative, reduce the rule whose
  127975. + number is the opposite. If YYTABLE_NINF, syntax error. */
  127976. +static const yytype_uint8 yytable[] =
  127977. {
  127978. - -78, -78, 97, 100, -78, -37, -78, -77, -78, -78,
  127979. - -78, -5, 65, 13, -78, 76, 77, 62, 80, 83,
  127980. - 34, 20, 26, 28, -14, -78, 18, 24
  127981. + 15, 69, 70, 43, 44, 45, 47, 37, 12, 13,
  127982. + 55, 56, 118, 101, 8, 38, 135, 102, 136, 119,
  127983. + 120, 121, 122, 14, 4, 63, 12, 13, 137, 123,
  127984. + 48, 9, 57, 20, 124, 3, 21, 22, 58, 115,
  127985. + 1, 14, 116, 64, 65, 7, 87, 88, 89, 12,
  127986. + 13, 117, 103, 129, 130, 40, 90, 91, 92, 53,
  127987. + 54, 131, 41, 93, 14, 42, 79, 80, 81, 82,
  127988. + 104, 59, 60, 107, 61, 62, 138, 139, 77, 78,
  127989. + 83, 84, 5, 85, 86, 17, 46, 38, 49, 50,
  127990. + 68, 66, 51, 97, 52, 98, 99, 100, 106, 110,
  127991. + 111, 126, 114, 134, 127, 133, 141, 19, 143, 16,
  127992. + 72, 109, 73, 76, 74, 108, 105, 132, 0, 0,
  127993. + 0, 0, 0, 0, 0, 0, 0, 0, 71, 0,
  127994. + 140, 0, 0, 142, 0, 75
  127995. };
  127996. -/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
  127997. - positive, shift that token. If negative, reduce the rule which
  127998. - number is the opposite. If YYTABLE_NINF, syntax error. */
  127999. -#define YYTABLE_NINF -1
  128000. -static const yytype_uint8 yytable[] =
  128001. +static const yytype_int16 yycheck[] =
  128002. {
  128003. - 12, 66, 67, 40, 41, 42, 44, 34, 9, 10,
  128004. - 52, 53, 115, 101, 5, 112, 104, 132, 113, 133,
  128005. - 116, 117, 118, 119, 11, 1, 60, 114, 14, 134,
  128006. - 120, 45, 6, 54, 17, 121, 3, 18, 19, 55,
  128007. - 9, 10, 50, 51, 61, 62, 84, 85, 86, 9,
  128008. - 10, 4, 100, 37, 126, 127, 11, 35, 87, 88,
  128009. - 89, 38, 128, 46, 39, 11, 90, 98, 47, 35,
  128010. - 43, 99, 76, 77, 78, 79, 56, 57, 58, 59,
  128011. - 135, 136, 80, 81, 74, 75, 82, 83, 48, 63,
  128012. - 49, 65, 94, 95, 96, 97, 124, 103, 107, 108,
  128013. - 111, 123, 130, 131, 138, 16, 13, 140, 106, 71,
  128014. - 69, 105, 0, 0, 102, 0, 0, 129, 0, 0,
  128015. - 68, 0, 0, 70, 0, 0, 0, 0, 72, 0,
  128016. - 137, 0, 73, 139
  128017. + 8, 41, 42, 20, 21, 22, 13, 15, 18, 19,
  128018. + 8, 9, 14, 25, 5, 27, 20, 29, 22, 21,
  128019. + 22, 23, 24, 33, 0, 26, 18, 19, 32, 31,
  128020. + 37, 22, 30, 43, 36, 25, 46, 47, 36, 22,
  128021. + 3, 33, 25, 44, 45, 25, 63, 64, 65, 18,
  128022. + 19, 34, 92, 22, 23, 16, 15, 16, 17, 10,
  128023. + 11, 30, 23, 22, 33, 26, 55, 56, 57, 58,
  128024. + 93, 6, 7, 96, 42, 43, 34, 35, 53, 54,
  128025. + 59, 60, 4, 61, 62, 26, 35, 27, 12, 39,
  128026. + 23, 25, 40, 25, 41, 38, 17, 17, 28, 25,
  128027. + 25, 18, 25, 21, 33, 36, 34, 11, 35, 9,
  128028. + 48, 98, 49, 52, 50, 96, 93, 125, -1, -1,
  128029. + -1, -1, -1, -1, -1, -1, -1, -1, 47, -1,
  128030. + 138, -1, -1, 141, -1, 51
  128031. };
  128032. -#define yypact_value_is_default(Yystate) \
  128033. - (!!((Yystate) == (-78)))
  128034. -
  128035. -#define yytable_value_is_error(Yytable_value) \
  128036. - YYID (0)
  128037. + /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
  128038. + symbol of state STATE-NUM. */
  128039. +static const yytype_uint8 yystos[] =
  128040. +{
  128041. + 0, 3, 49, 25, 0, 4, 50, 25, 5, 22,
  128042. + 51, 52, 18, 19, 33, 60, 52, 26, 53, 51,
  128043. + 43, 46, 47, 60, 61, 62, 63, 64, 65, 66,
  128044. + 67, 68, 69, 70, 71, 72, 73, 60, 27, 54,
  128045. + 16, 23, 26, 73, 73, 73, 35, 13, 37, 12,
  128046. + 39, 40, 41, 10, 11, 8, 9, 30, 36, 6,
  128047. + 7, 42, 43, 26, 44, 45, 25, 55, 23, 54,
  128048. + 54, 64, 61, 65, 66, 67, 68, 69, 69, 70,
  128049. + 70, 70, 70, 71, 71, 72, 72, 73, 73, 73,
  128050. + 15, 16, 17, 22, 56, 75, 76, 25, 38, 17,
  128051. + 17, 25, 29, 54, 56, 76, 28, 56, 75, 62,
  128052. + 25, 25, 57, 58, 25, 22, 25, 34, 14, 21,
  128053. + 22, 23, 24, 31, 36, 59, 18, 33, 74, 22,
  128054. + 23, 30, 60, 36, 21, 20, 22, 32, 34, 35,
  128055. + 60, 34, 60, 35
  128056. +};
  128057. -static const yytype_int16 yycheck[] =
  128058. + /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
  128059. +static const yytype_uint8 yyr1[] =
  128060. {
  128061. - 5, 38, 39, 17, 18, 19, 12, 12, 17, 18,
  128062. - 7, 8, 13, 90, 4, 22, 93, 20, 25, 22,
  128063. - 21, 22, 23, 24, 33, 3, 26, 34, 26, 32,
  128064. - 31, 37, 22, 30, 43, 36, 25, 46, 47, 36,
  128065. - 17, 18, 9, 10, 44, 45, 60, 61, 62, 17,
  128066. - 18, 0, 89, 15, 22, 23, 33, 27, 14, 15,
  128067. - 16, 23, 30, 11, 26, 33, 22, 25, 39, 27,
  128068. - 35, 29, 52, 53, 54, 55, 5, 6, 42, 43,
  128069. - 34, 35, 56, 57, 50, 51, 58, 59, 40, 25,
  128070. - 41, 23, 25, 38, 16, 16, 33, 28, 25, 25,
  128071. - 25, 17, 36, 21, 34, 8, 6, 35, 95, 47,
  128072. - 45, 93, -1, -1, 90, -1, -1, 122, -1, -1,
  128073. - 44, -1, -1, 46, -1, -1, -1, -1, 48, -1,
  128074. - 135, -1, 49, 138
  128075. + 0, 48, 49, 50, 50, 51, 51, 52, 52, 53,
  128076. + 53, 53, 53, 54, 55, 55, 56, 56, 56, 56,
  128077. + 57, 57, 57, 57, 57, 57, 57, 58, 58, 58,
  128078. + 59, 59, 59, 59, 59, 60, 60, 60, 61, 62,
  128079. + 62, 63, 63, 64, 64, 65, 65, 66, 66, 67,
  128080. + 67, 68, 68, 68, 69, 69, 69, 69, 69, 70,
  128081. + 70, 70, 71, 71, 71, 72, 72, 72, 72, 73,
  128082. + 73, 73, 73, 74, 74, 74, 75, 75, 75, 76,
  128083. + 76, 76
  128084. };
  128085. -/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
  128086. - symbol of state STATE-NUM. */
  128087. -static const yytype_uint8 yystos[] =
  128088. + /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */
  128089. +static const yytype_uint8 yyr2[] =
  128090. {
  128091. - 0, 3, 49, 25, 0, 4, 22, 50, 51, 17,
  128092. - 18, 33, 59, 51, 26, 52, 50, 43, 46, 47,
  128093. - 59, 60, 61, 62, 63, 64, 65, 66, 67, 68,
  128094. - 69, 70, 71, 72, 59, 27, 53, 15, 23, 26,
  128095. - 72, 72, 72, 35, 12, 37, 11, 39, 40, 41,
  128096. - 9, 10, 7, 8, 30, 36, 5, 6, 42, 43,
  128097. - 26, 44, 45, 25, 54, 23, 53, 53, 63, 60,
  128098. - 64, 65, 66, 67, 68, 68, 69, 69, 69, 69,
  128099. - 70, 70, 71, 71, 72, 72, 72, 14, 15, 16,
  128100. - 22, 55, 74, 75, 25, 38, 16, 16, 25, 29,
  128101. - 53, 55, 75, 28, 55, 74, 61, 25, 25, 56,
  128102. - 57, 25, 22, 25, 34, 13, 21, 22, 23, 24,
  128103. - 31, 36, 58, 17, 33, 73, 22, 23, 30, 59,
  128104. - 36, 21, 20, 22, 32, 34, 35, 59, 34, 59,
  128105. - 35
  128106. + 0, 2, 5, 0, 2, 0, 2, 4, 2, 2,
  128107. + 3, 3, 4, 5, 0, 2, 4, 2, 3, 2,
  128108. + 2, 3, 4, 2, 9, 5, 2, 0, 2, 2,
  128109. + 3, 1, 2, 2, 2, 1, 1, 3, 1, 1,
  128110. + 5, 1, 3, 1, 3, 1, 3, 1, 3, 1,
  128111. + 3, 1, 3, 3, 1, 3, 3, 3, 3, 3,
  128112. + 3, 1, 3, 3, 1, 3, 3, 3, 1, 1,
  128113. + 2, 2, 2, 0, 2, 2, 0, 2, 2, 2,
  128114. + 3, 2
  128115. };
  128116. -#define yyerrok (yyerrstatus = 0)
  128117. -#define yyclearin (yychar = YYEMPTY)
  128118. -#define YYEMPTY (-2)
  128119. -#define YYEOF 0
  128120. -
  128121. -#define YYACCEPT goto yyacceptlab
  128122. -#define YYABORT goto yyabortlab
  128123. -#define YYERROR goto yyerrorlab
  128124. -
  128125. -
  128126. -/* Like YYERROR except do call yyerror. This remains here temporarily
  128127. - to ease the transition to the new meaning of YYERROR, for GCC.
  128128. - Once GCC version 2 has supplanted version 1, this can go. However,
  128129. - YYFAIL appears to be in use. Nevertheless, it is formally deprecated
  128130. - in Bison 2.4.2's NEWS entry, where a plan to phase it out is
  128131. - discussed. */
  128132. -
  128133. -#define YYFAIL goto yyerrlab
  128134. -#if defined YYFAIL
  128135. - /* This is here to suppress warnings from the GCC cpp's
  128136. - -Wunused-macros. Normally we don't worry about that warning, but
  128137. - some users do, and we want to make it easy for users to remove
  128138. - YYFAIL uses, which will produce warnings from Bison 2.5. */
  128139. -#endif
  128140. +
  128141. +#define yyerrok (yyerrstatus = 0)
  128142. +#define yyclearin (yychar = YYEMPTY)
  128143. +#define YYEMPTY (-2)
  128144. +#define YYEOF 0
  128145. +
  128146. +#define YYACCEPT goto yyacceptlab
  128147. +#define YYABORT goto yyabortlab
  128148. +#define YYERROR goto yyerrorlab
  128149. +
  128150. #define YYRECOVERING() (!!yyerrstatus)
  128151. @@ -768,27 +725,41 @@
  128152. else \
  128153. { \
  128154. yyerror (YY_("syntax error: cannot back up")); \
  128155. - YYERROR; \
  128156. - } \
  128157. -while (YYID (0))
  128158. + YYERROR; \
  128159. + } \
  128160. +while (0)
  128161. /* Error token number */
  128162. -#define YYTERROR 1
  128163. -#define YYERRCODE 256
  128164. +#define YYTERROR 1
  128165. +#define YYERRCODE 256
  128166. -/* This macro is provided for backward compatibility. */
  128167. -#ifndef YY_LOCATION_PRINT
  128168. -# define YY_LOCATION_PRINT(File, Loc) ((void) 0)
  128169. +/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
  128170. + If N is 0, then set CURRENT to the empty location which ends
  128171. + the previous symbol: RHS[0] (always defined). */
  128172. +
  128173. +#ifndef YYLLOC_DEFAULT
  128174. +# define YYLLOC_DEFAULT(Current, Rhs, N) \
  128175. + do \
  128176. + if (N) \
  128177. + { \
  128178. + (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
  128179. + (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
  128180. + (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
  128181. + (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
  128182. + } \
  128183. + else \
  128184. + { \
  128185. + (Current).first_line = (Current).last_line = \
  128186. + YYRHSLOC (Rhs, 0).last_line; \
  128187. + (Current).first_column = (Current).last_column = \
  128188. + YYRHSLOC (Rhs, 0).last_column; \
  128189. + } \
  128190. + while (0)
  128191. #endif
  128192. +#define YYRHSLOC(Rhs, K) ((Rhs)[K])
  128193. -/* YYLEX -- calling `yylex' with the right arguments. */
  128194. -#ifdef YYLEX_PARAM
  128195. -# define YYLEX yylex (YYLEX_PARAM)
  128196. -#else
  128197. -# define YYLEX yylex ()
  128198. -#endif
  128199. /* Enable debugging if requested. */
  128200. #if YYDEBUG
  128201. @@ -798,50 +769,84 @@
  128202. # define YYFPRINTF fprintf
  128203. # endif
  128204. -# define YYDPRINTF(Args) \
  128205. -do { \
  128206. - if (yydebug) \
  128207. - YYFPRINTF Args; \
  128208. -} while (YYID (0))
  128209. -
  128210. -# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
  128211. -do { \
  128212. - if (yydebug) \
  128213. - { \
  128214. - YYFPRINTF (stderr, "%s ", Title); \
  128215. - yy_symbol_print (stderr, \
  128216. - Type, Value); \
  128217. - YYFPRINTF (stderr, "\n"); \
  128218. - } \
  128219. -} while (YYID (0))
  128220. +# define YYDPRINTF(Args) \
  128221. +do { \
  128222. + if (yydebug) \
  128223. + YYFPRINTF Args; \
  128224. +} while (0)
  128225. -/*--------------------------------.
  128226. -| Print this symbol on YYOUTPUT. |
  128227. -`--------------------------------*/
  128228. +/* YY_LOCATION_PRINT -- Print the location on the stream.
  128229. + This macro was not mandated originally: define only if we know
  128230. + we won't break user code: when these are the locations we know. */
  128231. -/*ARGSUSED*/
  128232. -#if (defined __STDC__ || defined __C99__FUNC__ \
  128233. - || defined __cplusplus || defined _MSC_VER)
  128234. -static void
  128235. -yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
  128236. -#else
  128237. -static void
  128238. -yy_symbol_value_print (yyoutput, yytype, yyvaluep)
  128239. - FILE *yyoutput;
  128240. - int yytype;
  128241. - YYSTYPE const * const yyvaluep;
  128242. +#ifndef YY_LOCATION_PRINT
  128243. +# if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
  128244. +
  128245. +/* Print *YYLOCP on YYO. Private, do not rely on its existence. */
  128246. +
  128247. +YY_ATTRIBUTE_UNUSED
  128248. +static unsigned
  128249. +yy_location_print_ (FILE *yyo, YYLTYPE const * const yylocp)
  128250. +{
  128251. + unsigned res = 0;
  128252. + int end_col = 0 != yylocp->last_column ? yylocp->last_column - 1 : 0;
  128253. + if (0 <= yylocp->first_line)
  128254. + {
  128255. + res += YYFPRINTF (yyo, "%d", yylocp->first_line);
  128256. + if (0 <= yylocp->first_column)
  128257. + res += YYFPRINTF (yyo, ".%d", yylocp->first_column);
  128258. + }
  128259. + if (0 <= yylocp->last_line)
  128260. + {
  128261. + if (yylocp->first_line < yylocp->last_line)
  128262. + {
  128263. + res += YYFPRINTF (yyo, "-%d", yylocp->last_line);
  128264. + if (0 <= end_col)
  128265. + res += YYFPRINTF (yyo, ".%d", end_col);
  128266. + }
  128267. + else if (0 <= end_col && yylocp->first_column < end_col)
  128268. + res += YYFPRINTF (yyo, "-%d", end_col);
  128269. + }
  128270. + return res;
  128271. + }
  128272. +
  128273. +# define YY_LOCATION_PRINT(File, Loc) \
  128274. + yy_location_print_ (File, &(Loc))
  128275. +
  128276. +# else
  128277. +# define YY_LOCATION_PRINT(File, Loc) ((void) 0)
  128278. +# endif
  128279. #endif
  128280. +
  128281. +
  128282. +# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
  128283. +do { \
  128284. + if (yydebug) \
  128285. + { \
  128286. + YYFPRINTF (stderr, "%s ", Title); \
  128287. + yy_symbol_print (stderr, \
  128288. + Type, Value, Location); \
  128289. + YYFPRINTF (stderr, "\n"); \
  128290. + } \
  128291. +} while (0)
  128292. +
  128293. +
  128294. +/*----------------------------------------.
  128295. +| Print this symbol's value on YYOUTPUT. |
  128296. +`----------------------------------------*/
  128297. +
  128298. +static void
  128299. +yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp)
  128300. {
  128301. FILE *yyo = yyoutput;
  128302. YYUSE (yyo);
  128303. + YYUSE (yylocationp);
  128304. if (!yyvaluep)
  128305. return;
  128306. # ifdef YYPRINT
  128307. if (yytype < YYNTOKENS)
  128308. YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
  128309. -# else
  128310. - YYUSE (yyoutput);
  128311. # endif
  128312. YYUSE (yytype);
  128313. }
  128314. @@ -851,24 +856,15 @@
  128315. | Print this symbol on YYOUTPUT. |
  128316. `--------------------------------*/
  128317. -#if (defined __STDC__ || defined __C99__FUNC__ \
  128318. - || defined __cplusplus || defined _MSC_VER)
  128319. -static void
  128320. -yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
  128321. -#else
  128322. static void
  128323. -yy_symbol_print (yyoutput, yytype, yyvaluep)
  128324. - FILE *yyoutput;
  128325. - int yytype;
  128326. - YYSTYPE const * const yyvaluep;
  128327. -#endif
  128328. +yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp)
  128329. {
  128330. - if (yytype < YYNTOKENS)
  128331. - YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
  128332. - else
  128333. - YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
  128334. + YYFPRINTF (yyoutput, "%s %s (",
  128335. + yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]);
  128336. - yy_symbol_value_print (yyoutput, yytype, yyvaluep);
  128337. + YY_LOCATION_PRINT (yyoutput, *yylocationp);
  128338. + YYFPRINTF (yyoutput, ": ");
  128339. + yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp);
  128340. YYFPRINTF (yyoutput, ")");
  128341. }
  128342. @@ -877,16 +873,8 @@
  128343. | TOP (included). |
  128344. `------------------------------------------------------------------*/
  128345. -#if (defined __STDC__ || defined __C99__FUNC__ \
  128346. - || defined __cplusplus || defined _MSC_VER)
  128347. static void
  128348. yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop)
  128349. -#else
  128350. -static void
  128351. -yy_stack_print (yybottom, yytop)
  128352. - yytype_int16 *yybottom;
  128353. - yytype_int16 *yytop;
  128354. -#endif
  128355. {
  128356. YYFPRINTF (stderr, "Stack now");
  128357. for (; yybottom <= yytop; yybottom++)
  128358. @@ -897,49 +885,42 @@
  128359. YYFPRINTF (stderr, "\n");
  128360. }
  128361. -# define YY_STACK_PRINT(Bottom, Top) \
  128362. -do { \
  128363. - if (yydebug) \
  128364. - yy_stack_print ((Bottom), (Top)); \
  128365. -} while (YYID (0))
  128366. +# define YY_STACK_PRINT(Bottom, Top) \
  128367. +do { \
  128368. + if (yydebug) \
  128369. + yy_stack_print ((Bottom), (Top)); \
  128370. +} while (0)
  128371. /*------------------------------------------------.
  128372. | Report that the YYRULE is going to be reduced. |
  128373. `------------------------------------------------*/
  128374. -#if (defined __STDC__ || defined __C99__FUNC__ \
  128375. - || defined __cplusplus || defined _MSC_VER)
  128376. -static void
  128377. -yy_reduce_print (YYSTYPE *yyvsp, int yyrule)
  128378. -#else
  128379. static void
  128380. -yy_reduce_print (yyvsp, yyrule)
  128381. - YYSTYPE *yyvsp;
  128382. - int yyrule;
  128383. -#endif
  128384. +yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, YYLTYPE *yylsp, int yyrule)
  128385. {
  128386. + unsigned long int yylno = yyrline[yyrule];
  128387. int yynrhs = yyr2[yyrule];
  128388. int yyi;
  128389. - unsigned long int yylno = yyrline[yyrule];
  128390. YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
  128391. - yyrule - 1, yylno);
  128392. + yyrule - 1, yylno);
  128393. /* The symbols being reduced. */
  128394. for (yyi = 0; yyi < yynrhs; yyi++)
  128395. {
  128396. YYFPRINTF (stderr, " $%d = ", yyi + 1);
  128397. - yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
  128398. - &(yyvsp[(yyi + 1) - (yynrhs)])
  128399. - );
  128400. + yy_symbol_print (stderr,
  128401. + yystos[yyssp[yyi + 1 - yynrhs]],
  128402. + &(yyvsp[(yyi + 1) - (yynrhs)])
  128403. + , &(yylsp[(yyi + 1) - (yynrhs)]) );
  128404. YYFPRINTF (stderr, "\n");
  128405. }
  128406. }
  128407. -# define YY_REDUCE_PRINT(Rule) \
  128408. -do { \
  128409. - if (yydebug) \
  128410. - yy_reduce_print (yyvsp, Rule); \
  128411. -} while (YYID (0))
  128412. +# define YY_REDUCE_PRINT(Rule) \
  128413. +do { \
  128414. + if (yydebug) \
  128415. + yy_reduce_print (yyssp, yyvsp, yylsp, Rule); \
  128416. +} while (0)
  128417. /* Nonzero means print parse trace. It is left uninitialized so that
  128418. multiple parsers can coexist. */
  128419. @@ -953,7 +934,7 @@
  128420. /* YYINITDEPTH -- initial size of the parser's stacks. */
  128421. -#ifndef YYINITDEPTH
  128422. +#ifndef YYINITDEPTH
  128423. # define YYINITDEPTH 200
  128424. #endif
  128425. @@ -976,15 +957,8 @@
  128426. # define yystrlen strlen
  128427. # else
  128428. /* Return the length of YYSTR. */
  128429. -#if (defined __STDC__ || defined __C99__FUNC__ \
  128430. - || defined __cplusplus || defined _MSC_VER)
  128431. static YYSIZE_T
  128432. yystrlen (const char *yystr)
  128433. -#else
  128434. -static YYSIZE_T
  128435. -yystrlen (yystr)
  128436. - const char *yystr;
  128437. -#endif
  128438. {
  128439. YYSIZE_T yylen;
  128440. for (yylen = 0; yystr[yylen]; yylen++)
  128441. @@ -1000,16 +974,8 @@
  128442. # else
  128443. /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
  128444. YYDEST. */
  128445. -#if (defined __STDC__ || defined __C99__FUNC__ \
  128446. - || defined __cplusplus || defined _MSC_VER)
  128447. static char *
  128448. yystpcpy (char *yydest, const char *yysrc)
  128449. -#else
  128450. -static char *
  128451. -yystpcpy (yydest, yysrc)
  128452. - char *yydest;
  128453. - const char *yysrc;
  128454. -#endif
  128455. {
  128456. char *yyd = yydest;
  128457. const char *yys = yysrc;
  128458. @@ -1039,27 +1005,27 @@
  128459. char const *yyp = yystr;
  128460. for (;;)
  128461. - switch (*++yyp)
  128462. - {
  128463. - case '\'':
  128464. - case ',':
  128465. - goto do_not_strip_quotes;
  128466. -
  128467. - case '\\':
  128468. - if (*++yyp != '\\')
  128469. - goto do_not_strip_quotes;
  128470. - /* Fall through. */
  128471. - default:
  128472. - if (yyres)
  128473. - yyres[yyn] = *yyp;
  128474. - yyn++;
  128475. - break;
  128476. -
  128477. - case '"':
  128478. - if (yyres)
  128479. - yyres[yyn] = '\0';
  128480. - return yyn;
  128481. - }
  128482. + switch (*++yyp)
  128483. + {
  128484. + case '\'':
  128485. + case ',':
  128486. + goto do_not_strip_quotes;
  128487. +
  128488. + case '\\':
  128489. + if (*++yyp != '\\')
  128490. + goto do_not_strip_quotes;
  128491. + /* Fall through. */
  128492. + default:
  128493. + if (yyres)
  128494. + yyres[yyn] = *yyp;
  128495. + yyn++;
  128496. + break;
  128497. +
  128498. + case '"':
  128499. + if (yyres)
  128500. + yyres[yyn] = '\0';
  128501. + return yyn;
  128502. + }
  128503. do_not_strip_quotes: ;
  128504. }
  128505. @@ -1082,11 +1048,11 @@
  128506. yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg,
  128507. yytype_int16 *yyssp, int yytoken)
  128508. {
  128509. - YYSIZE_T yysize0 = yytnamerr (YY_NULL, yytname[yytoken]);
  128510. + YYSIZE_T yysize0 = yytnamerr (YY_NULLPTR, yytname[yytoken]);
  128511. YYSIZE_T yysize = yysize0;
  128512. enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
  128513. /* Internationalized format string. */
  128514. - const char *yyformat = YY_NULL;
  128515. + const char *yyformat = YY_NULLPTR;
  128516. /* Arguments of yyformat. */
  128517. char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
  128518. /* Number of reported tokens (one for the "unexpected", one per
  128519. @@ -1094,10 +1060,6 @@
  128520. int yycount = 0;
  128521. /* There are many possibilities here to consider:
  128522. - - Assume YYFAIL is not used. It's too flawed to consider. See
  128523. - <http://lists.gnu.org/archive/html/bison-patches/2009-12/msg00024.html>
  128524. - for details. YYERROR is fine as it does not invoke this
  128525. - function.
  128526. - If this state is a consistent state with a default action, then
  128527. the only way this function was invoked is if the default action
  128528. is an error action. In that case, don't check for expected
  128529. @@ -1147,7 +1109,7 @@
  128530. }
  128531. yyarg[yycount++] = yytname[yyx];
  128532. {
  128533. - YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULL, yytname[yyx]);
  128534. + YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULLPTR, yytname[yyx]);
  128535. if (! (yysize <= yysize1
  128536. && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
  128537. return 2;
  128538. @@ -1214,26 +1176,18 @@
  128539. | Release the memory associated to this symbol. |
  128540. `-----------------------------------------------*/
  128541. -/*ARGSUSED*/
  128542. -#if (defined __STDC__ || defined __C99__FUNC__ \
  128543. - || defined __cplusplus || defined _MSC_VER)
  128544. -static void
  128545. -yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep)
  128546. -#else
  128547. static void
  128548. -yydestruct (yymsg, yytype, yyvaluep)
  128549. - const char *yymsg;
  128550. - int yytype;
  128551. - YYSTYPE *yyvaluep;
  128552. -#endif
  128553. +yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocationp)
  128554. {
  128555. YYUSE (yyvaluep);
  128556. -
  128557. + YYUSE (yylocationp);
  128558. if (!yymsg)
  128559. yymsg = "Deleting";
  128560. YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
  128561. + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
  128562. YYUSE (yytype);
  128563. + YY_IGNORE_MAYBE_UNINITIALIZED_END
  128564. }
  128565. @@ -1242,18 +1196,14 @@
  128566. /* The lookahead symbol. */
  128567. int yychar;
  128568. -
  128569. -#ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
  128570. -# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
  128571. -# define YY_IGNORE_MAYBE_UNINITIALIZED_END
  128572. -#endif
  128573. -#ifndef YY_INITIAL_VALUE
  128574. -# define YY_INITIAL_VALUE(Value) /* Nothing. */
  128575. -#endif
  128576. -
  128577. /* The semantic value of the lookahead symbol. */
  128578. -YYSTYPE yylval YY_INITIAL_VALUE(yyval_default);
  128579. -
  128580. +YYSTYPE yylval;
  128581. +/* Location data for the lookahead symbol. */
  128582. +YYLTYPE yylloc
  128583. +# if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
  128584. + = { 1, 1, 1, 1 }
  128585. +# endif
  128586. +;
  128587. /* Number of syntax errors so far. */
  128588. int yynerrs;
  128589. @@ -1262,35 +1212,17 @@
  128590. | yyparse. |
  128591. `----------*/
  128592. -#ifdef YYPARSE_PARAM
  128593. -#if (defined __STDC__ || defined __C99__FUNC__ \
  128594. - || defined __cplusplus || defined _MSC_VER)
  128595. -int
  128596. -yyparse (void *YYPARSE_PARAM)
  128597. -#else
  128598. -int
  128599. -yyparse (YYPARSE_PARAM)
  128600. - void *YYPARSE_PARAM;
  128601. -#endif
  128602. -#else /* ! YYPARSE_PARAM */
  128603. -#if (defined __STDC__ || defined __C99__FUNC__ \
  128604. - || defined __cplusplus || defined _MSC_VER)
  128605. int
  128606. yyparse (void)
  128607. -#else
  128608. -int
  128609. -yyparse ()
  128610. -
  128611. -#endif
  128612. -#endif
  128613. {
  128614. int yystate;
  128615. /* Number of tokens to shift before error messages enabled. */
  128616. int yyerrstatus;
  128617. /* The stacks and their tools:
  128618. - `yyss': related to states.
  128619. - `yyvs': related to semantic values.
  128620. + 'yyss': related to states.
  128621. + 'yyvs': related to semantic values.
  128622. + 'yyls': related to locations.
  128623. Refer to the stacks through separate pointers, to allow yyoverflow
  128624. to reallocate them elsewhere. */
  128625. @@ -1305,6 +1237,14 @@
  128626. YYSTYPE *yyvs;
  128627. YYSTYPE *yyvsp;
  128628. + /* The location stack. */
  128629. + YYLTYPE yylsa[YYINITDEPTH];
  128630. + YYLTYPE *yyls;
  128631. + YYLTYPE *yylsp;
  128632. +
  128633. + /* The locations where the error started and ended. */
  128634. + YYLTYPE yyerror_range[3];
  128635. +
  128636. YYSIZE_T yystacksize;
  128637. int yyn;
  128638. @@ -1314,6 +1254,7 @@
  128639. /* The variables used to return semantic value and location from the
  128640. action routines. */
  128641. YYSTYPE yyval;
  128642. + YYLTYPE yyloc;
  128643. #if YYERROR_VERBOSE
  128644. /* Buffer for error messages, and its allocated size. */
  128645. @@ -1322,7 +1263,7 @@
  128646. YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
  128647. #endif
  128648. -#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
  128649. +#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N), yylsp -= (N))
  128650. /* The number of symbols on the RHS of the reduced rule.
  128651. Keep to zero when no symbol should be popped. */
  128652. @@ -1330,6 +1271,7 @@
  128653. yyssp = yyss = yyssa;
  128654. yyvsp = yyvs = yyvsa;
  128655. + yylsp = yyls = yylsa;
  128656. yystacksize = YYINITDEPTH;
  128657. YYDPRINTF ((stderr, "Starting parse\n"));
  128658. @@ -1338,6 +1280,7 @@
  128659. yyerrstatus = 0;
  128660. yynerrs = 0;
  128661. yychar = YYEMPTY; /* Cause a token to be read. */
  128662. + yylsp[0] = yylloc;
  128663. goto yysetstate;
  128664. /*------------------------------------------------------------.
  128665. @@ -1358,23 +1301,26 @@
  128666. #ifdef yyoverflow
  128667. {
  128668. - /* Give user a chance to reallocate the stack. Use copies of
  128669. - these so that the &'s don't force the real ones into
  128670. - memory. */
  128671. - YYSTYPE *yyvs1 = yyvs;
  128672. - yytype_int16 *yyss1 = yyss;
  128673. -
  128674. - /* Each stack pointer address is followed by the size of the
  128675. - data in use in that stack, in bytes. This used to be a
  128676. - conditional around just the two extra args, but that might
  128677. - be undefined if yyoverflow is a macro. */
  128678. - yyoverflow (YY_("memory exhausted"),
  128679. - &yyss1, yysize * sizeof (*yyssp),
  128680. - &yyvs1, yysize * sizeof (*yyvsp),
  128681. - &yystacksize);
  128682. -
  128683. - yyss = yyss1;
  128684. - yyvs = yyvs1;
  128685. + /* Give user a chance to reallocate the stack. Use copies of
  128686. + these so that the &'s don't force the real ones into
  128687. + memory. */
  128688. + YYSTYPE *yyvs1 = yyvs;
  128689. + yytype_int16 *yyss1 = yyss;
  128690. + YYLTYPE *yyls1 = yyls;
  128691. +
  128692. + /* Each stack pointer address is followed by the size of the
  128693. + data in use in that stack, in bytes. This used to be a
  128694. + conditional around just the two extra args, but that might
  128695. + be undefined if yyoverflow is a macro. */
  128696. + yyoverflow (YY_("memory exhausted"),
  128697. + &yyss1, yysize * sizeof (*yyssp),
  128698. + &yyvs1, yysize * sizeof (*yyvsp),
  128699. + &yyls1, yysize * sizeof (*yylsp),
  128700. + &yystacksize);
  128701. +
  128702. + yyls = yyls1;
  128703. + yyss = yyss1;
  128704. + yyvs = yyvs1;
  128705. }
  128706. #else /* no yyoverflow */
  128707. # ifndef YYSTACK_RELOCATE
  128708. @@ -1382,34 +1328,36 @@
  128709. # else
  128710. /* Extend the stack our own way. */
  128711. if (YYMAXDEPTH <= yystacksize)
  128712. - goto yyexhaustedlab;
  128713. + goto yyexhaustedlab;
  128714. yystacksize *= 2;
  128715. if (YYMAXDEPTH < yystacksize)
  128716. - yystacksize = YYMAXDEPTH;
  128717. + yystacksize = YYMAXDEPTH;
  128718. {
  128719. - yytype_int16 *yyss1 = yyss;
  128720. - union yyalloc *yyptr =
  128721. - (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
  128722. - if (! yyptr)
  128723. - goto yyexhaustedlab;
  128724. - YYSTACK_RELOCATE (yyss_alloc, yyss);
  128725. - YYSTACK_RELOCATE (yyvs_alloc, yyvs);
  128726. + yytype_int16 *yyss1 = yyss;
  128727. + union yyalloc *yyptr =
  128728. + (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
  128729. + if (! yyptr)
  128730. + goto yyexhaustedlab;
  128731. + YYSTACK_RELOCATE (yyss_alloc, yyss);
  128732. + YYSTACK_RELOCATE (yyvs_alloc, yyvs);
  128733. + YYSTACK_RELOCATE (yyls_alloc, yyls);
  128734. # undef YYSTACK_RELOCATE
  128735. - if (yyss1 != yyssa)
  128736. - YYSTACK_FREE (yyss1);
  128737. + if (yyss1 != yyssa)
  128738. + YYSTACK_FREE (yyss1);
  128739. }
  128740. # endif
  128741. #endif /* no yyoverflow */
  128742. yyssp = yyss + yysize - 1;
  128743. yyvsp = yyvs + yysize - 1;
  128744. + yylsp = yyls + yysize - 1;
  128745. YYDPRINTF ((stderr, "Stack size increased to %lu\n",
  128746. - (unsigned long int) yystacksize));
  128747. + (unsigned long int) yystacksize));
  128748. if (yyss + yystacksize - 1 <= yyssp)
  128749. - YYABORT;
  128750. + YYABORT;
  128751. }
  128752. YYDPRINTF ((stderr, "Entering state %d\n", yystate));
  128753. @@ -1438,7 +1386,7 @@
  128754. if (yychar == YYEMPTY)
  128755. {
  128756. YYDPRINTF ((stderr, "Reading a token: "));
  128757. - yychar = YYLEX;
  128758. + yychar = yylex ();
  128759. }
  128760. if (yychar <= YYEOF)
  128761. @@ -1481,7 +1429,7 @@
  128762. YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
  128763. *++yyvsp = yylval;
  128764. YY_IGNORE_MAYBE_UNINITIALIZED_END
  128765. -
  128766. + *++yylsp = yylloc;
  128767. goto yynewstate;
  128768. @@ -1503,7 +1451,7 @@
  128769. yylen = yyr2[yyn];
  128770. /* If YYLEN is nonzero, implement the default value of the action:
  128771. - `$$ = $1'.
  128772. + '$$ = $1'.
  128773. Otherwise, the following line sets YYVAL to garbage.
  128774. This behavior is undocumented and Bison
  128775. @@ -1512,287 +1460,306 @@
  128776. GCC warning that YYVAL may be used uninitialized. */
  128777. yyval = yyvsp[1-yylen];
  128778. -
  128779. + /* Default location. */
  128780. + YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen);
  128781. YY_REDUCE_PRINT (yyn);
  128782. switch (yyn)
  128783. {
  128784. case 2:
  128785. -/* Line 1787 of yacc.c */
  128786. -#line 110 "dtc-parser.y"
  128787. +#line 109 "dtc-parser.y" /* yacc.c:1646 */
  128788. {
  128789. - the_boot_info = build_boot_info((yyvsp[(3) - (4)].re), (yyvsp[(4) - (4)].node),
  128790. - guess_boot_cpuid((yyvsp[(4) - (4)].node)));
  128791. + (yyvsp[0].node)->is_plugin = (yyvsp[-2].is_plugin);
  128792. + (yyvsp[0].node)->is_root = 1;
  128793. + the_boot_info = build_boot_info((yyvsp[-1].re), (yyvsp[0].node),
  128794. + guess_boot_cpuid((yyvsp[0].node)));
  128795. }
  128796. +#line 1477 "dtc-parser.tab.c" /* yacc.c:1646 */
  128797. break;
  128798. case 3:
  128799. -/* Line 1787 of yacc.c */
  128800. -#line 118 "dtc-parser.y"
  128801. +#line 119 "dtc-parser.y" /* yacc.c:1646 */
  128802. {
  128803. - (yyval.re) = NULL;
  128804. + (yyval.is_plugin) = 0;
  128805. }
  128806. +#line 1485 "dtc-parser.tab.c" /* yacc.c:1646 */
  128807. break;
  128808. case 4:
  128809. -/* Line 1787 of yacc.c */
  128810. -#line 122 "dtc-parser.y"
  128811. +#line 123 "dtc-parser.y" /* yacc.c:1646 */
  128812. {
  128813. - (yyval.re) = chain_reserve_entry((yyvsp[(1) - (2)].re), (yyvsp[(2) - (2)].re));
  128814. + (yyval.is_plugin) = 1;
  128815. }
  128816. +#line 1493 "dtc-parser.tab.c" /* yacc.c:1646 */
  128817. break;
  128818. case 5:
  128819. -/* Line 1787 of yacc.c */
  128820. -#line 129 "dtc-parser.y"
  128821. +#line 130 "dtc-parser.y" /* yacc.c:1646 */
  128822. {
  128823. - (yyval.re) = build_reserve_entry((yyvsp[(2) - (4)].integer), (yyvsp[(3) - (4)].integer));
  128824. + (yyval.re) = NULL;
  128825. }
  128826. +#line 1501 "dtc-parser.tab.c" /* yacc.c:1646 */
  128827. break;
  128828. case 6:
  128829. -/* Line 1787 of yacc.c */
  128830. -#line 133 "dtc-parser.y"
  128831. +#line 134 "dtc-parser.y" /* yacc.c:1646 */
  128832. {
  128833. - add_label(&(yyvsp[(2) - (2)].re)->labels, (yyvsp[(1) - (2)].labelref));
  128834. - (yyval.re) = (yyvsp[(2) - (2)].re);
  128835. + (yyval.re) = chain_reserve_entry((yyvsp[-1].re), (yyvsp[0].re));
  128836. }
  128837. +#line 1509 "dtc-parser.tab.c" /* yacc.c:1646 */
  128838. break;
  128839. case 7:
  128840. -/* Line 1787 of yacc.c */
  128841. -#line 141 "dtc-parser.y"
  128842. +#line 141 "dtc-parser.y" /* yacc.c:1646 */
  128843. {
  128844. - (yyval.node) = name_node((yyvsp[(2) - (2)].node), "");
  128845. + (yyval.re) = build_reserve_entry((yyvsp[-2].integer), (yyvsp[-1].integer));
  128846. }
  128847. +#line 1517 "dtc-parser.tab.c" /* yacc.c:1646 */
  128848. break;
  128849. case 8:
  128850. -/* Line 1787 of yacc.c */
  128851. -#line 145 "dtc-parser.y"
  128852. +#line 145 "dtc-parser.y" /* yacc.c:1646 */
  128853. {
  128854. - (yyval.node) = merge_nodes((yyvsp[(1) - (3)].node), (yyvsp[(3) - (3)].node));
  128855. + add_label(&(yyvsp[0].re)->labels, (yyvsp[-1].labelref));
  128856. + (yyval.re) = (yyvsp[0].re);
  128857. }
  128858. +#line 1526 "dtc-parser.tab.c" /* yacc.c:1646 */
  128859. break;
  128860. case 9:
  128861. -/* Line 1787 of yacc.c */
  128862. -#line 149 "dtc-parser.y"
  128863. +#line 153 "dtc-parser.y" /* yacc.c:1646 */
  128864. {
  128865. - struct node *target = get_node_by_ref((yyvsp[(1) - (3)].node), (yyvsp[(2) - (3)].labelref));
  128866. -
  128867. - if (target)
  128868. - merge_nodes(target, (yyvsp[(3) - (3)].node));
  128869. - else
  128870. - print_error("label or path, '%s', not found", (yyvsp[(2) - (3)].labelref));
  128871. - (yyval.node) = (yyvsp[(1) - (3)].node);
  128872. + (yyval.node) = name_node((yyvsp[0].node), "");
  128873. }
  128874. +#line 1534 "dtc-parser.tab.c" /* yacc.c:1646 */
  128875. break;
  128876. case 10:
  128877. -/* Line 1787 of yacc.c */
  128878. -#line 159 "dtc-parser.y"
  128879. +#line 157 "dtc-parser.y" /* yacc.c:1646 */
  128880. {
  128881. - struct node *target = get_node_by_ref((yyvsp[(1) - (4)].node), (yyvsp[(3) - (4)].labelref));
  128882. -
  128883. - if (!target)
  128884. - print_error("label or path, '%s', not found", (yyvsp[(3) - (4)].labelref));
  128885. - else
  128886. - delete_node(target);
  128887. -
  128888. - (yyval.node) = (yyvsp[(1) - (4)].node);
  128889. + (yyval.node) = merge_nodes((yyvsp[-2].node), (yyvsp[0].node));
  128890. }
  128891. +#line 1542 "dtc-parser.tab.c" /* yacc.c:1646 */
  128892. break;
  128893. case 11:
  128894. -/* Line 1787 of yacc.c */
  128895. -#line 173 "dtc-parser.y"
  128896. +#line 161 "dtc-parser.y" /* yacc.c:1646 */
  128897. {
  128898. - (yyval.node) = build_node((yyvsp[(2) - (5)].proplist), (yyvsp[(3) - (5)].nodelist));
  128899. + struct node *target = get_node_by_ref((yyvsp[-2].node), (yyvsp[-1].labelref));
  128900. +
  128901. + if (target)
  128902. + merge_nodes(target, (yyvsp[0].node));
  128903. + else
  128904. + ERROR(&(yylsp[-1]), "Label or path %s not found", (yyvsp[-1].labelref));
  128905. + (yyval.node) = (yyvsp[-2].node);
  128906. }
  128907. +#line 1556 "dtc-parser.tab.c" /* yacc.c:1646 */
  128908. break;
  128909. case 12:
  128910. -/* Line 1787 of yacc.c */
  128911. -#line 180 "dtc-parser.y"
  128912. +#line 171 "dtc-parser.y" /* yacc.c:1646 */
  128913. {
  128914. - (yyval.proplist) = NULL;
  128915. + struct node *target = get_node_by_ref((yyvsp[-3].node), (yyvsp[-1].labelref));
  128916. +
  128917. + if (target)
  128918. + delete_node(target);
  128919. + else
  128920. + ERROR(&(yylsp[-1]), "Label or path %s not found", (yyvsp[-1].labelref));
  128921. +
  128922. +
  128923. + (yyval.node) = (yyvsp[-3].node);
  128924. }
  128925. +#line 1572 "dtc-parser.tab.c" /* yacc.c:1646 */
  128926. break;
  128927. case 13:
  128928. -/* Line 1787 of yacc.c */
  128929. -#line 184 "dtc-parser.y"
  128930. +#line 186 "dtc-parser.y" /* yacc.c:1646 */
  128931. {
  128932. - (yyval.proplist) = chain_property((yyvsp[(2) - (2)].prop), (yyvsp[(1) - (2)].proplist));
  128933. + (yyval.node) = build_node((yyvsp[-3].proplist), (yyvsp[-2].nodelist));
  128934. }
  128935. +#line 1580 "dtc-parser.tab.c" /* yacc.c:1646 */
  128936. break;
  128937. case 14:
  128938. -/* Line 1787 of yacc.c */
  128939. -#line 191 "dtc-parser.y"
  128940. +#line 193 "dtc-parser.y" /* yacc.c:1646 */
  128941. {
  128942. - (yyval.prop) = build_property((yyvsp[(1) - (4)].propnodename), (yyvsp[(3) - (4)].data));
  128943. + (yyval.proplist) = NULL;
  128944. }
  128945. +#line 1588 "dtc-parser.tab.c" /* yacc.c:1646 */
  128946. break;
  128947. case 15:
  128948. -/* Line 1787 of yacc.c */
  128949. -#line 195 "dtc-parser.y"
  128950. +#line 197 "dtc-parser.y" /* yacc.c:1646 */
  128951. {
  128952. - (yyval.prop) = build_property((yyvsp[(1) - (2)].propnodename), empty_data);
  128953. + (yyval.proplist) = chain_property((yyvsp[0].prop), (yyvsp[-1].proplist));
  128954. }
  128955. +#line 1596 "dtc-parser.tab.c" /* yacc.c:1646 */
  128956. break;
  128957. case 16:
  128958. -/* Line 1787 of yacc.c */
  128959. -#line 199 "dtc-parser.y"
  128960. +#line 204 "dtc-parser.y" /* yacc.c:1646 */
  128961. {
  128962. - (yyval.prop) = build_property_delete((yyvsp[(2) - (3)].propnodename));
  128963. + (yyval.prop) = build_property((yyvsp[-3].propnodename), (yyvsp[-1].data));
  128964. }
  128965. +#line 1604 "dtc-parser.tab.c" /* yacc.c:1646 */
  128966. break;
  128967. case 17:
  128968. -/* Line 1787 of yacc.c */
  128969. -#line 203 "dtc-parser.y"
  128970. +#line 208 "dtc-parser.y" /* yacc.c:1646 */
  128971. {
  128972. - add_label(&(yyvsp[(2) - (2)].prop)->labels, (yyvsp[(1) - (2)].labelref));
  128973. - (yyval.prop) = (yyvsp[(2) - (2)].prop);
  128974. + (yyval.prop) = build_property((yyvsp[-1].propnodename), empty_data);
  128975. }
  128976. +#line 1612 "dtc-parser.tab.c" /* yacc.c:1646 */
  128977. break;
  128978. case 18:
  128979. -/* Line 1787 of yacc.c */
  128980. -#line 211 "dtc-parser.y"
  128981. +#line 212 "dtc-parser.y" /* yacc.c:1646 */
  128982. {
  128983. - (yyval.data) = data_merge((yyvsp[(1) - (2)].data), (yyvsp[(2) - (2)].data));
  128984. + (yyval.prop) = build_property_delete((yyvsp[-1].propnodename));
  128985. }
  128986. +#line 1620 "dtc-parser.tab.c" /* yacc.c:1646 */
  128987. break;
  128988. case 19:
  128989. -/* Line 1787 of yacc.c */
  128990. -#line 215 "dtc-parser.y"
  128991. +#line 216 "dtc-parser.y" /* yacc.c:1646 */
  128992. {
  128993. - (yyval.data) = data_merge((yyvsp[(1) - (3)].data), (yyvsp[(2) - (3)].array).data);
  128994. + add_label(&(yyvsp[0].prop)->labels, (yyvsp[-1].labelref));
  128995. + (yyval.prop) = (yyvsp[0].prop);
  128996. }
  128997. +#line 1629 "dtc-parser.tab.c" /* yacc.c:1646 */
  128998. break;
  128999. case 20:
  129000. -/* Line 1787 of yacc.c */
  129001. -#line 219 "dtc-parser.y"
  129002. +#line 224 "dtc-parser.y" /* yacc.c:1646 */
  129003. {
  129004. - (yyval.data) = data_merge((yyvsp[(1) - (4)].data), (yyvsp[(3) - (4)].data));
  129005. + (yyval.data) = data_merge((yyvsp[-1].data), (yyvsp[0].data));
  129006. }
  129007. +#line 1637 "dtc-parser.tab.c" /* yacc.c:1646 */
  129008. break;
  129009. case 21:
  129010. -/* Line 1787 of yacc.c */
  129011. -#line 223 "dtc-parser.y"
  129012. +#line 228 "dtc-parser.y" /* yacc.c:1646 */
  129013. {
  129014. - (yyval.data) = data_add_marker((yyvsp[(1) - (2)].data), REF_PATH, (yyvsp[(2) - (2)].labelref));
  129015. + (yyval.data) = data_merge((yyvsp[-2].data), (yyvsp[-1].array).data);
  129016. }
  129017. +#line 1645 "dtc-parser.tab.c" /* yacc.c:1646 */
  129018. break;
  129019. case 22:
  129020. -/* Line 1787 of yacc.c */
  129021. -#line 227 "dtc-parser.y"
  129022. +#line 232 "dtc-parser.y" /* yacc.c:1646 */
  129023. {
  129024. - FILE *f = srcfile_relative_open((yyvsp[(4) - (9)].data).val, NULL);
  129025. + (yyval.data) = data_merge((yyvsp[-3].data), (yyvsp[-1].data));
  129026. + }
  129027. +#line 1653 "dtc-parser.tab.c" /* yacc.c:1646 */
  129028. + break;
  129029. +
  129030. + case 23:
  129031. +#line 236 "dtc-parser.y" /* yacc.c:1646 */
  129032. + {
  129033. + (yyval.data) = data_add_marker((yyvsp[-1].data), REF_PATH, (yyvsp[0].labelref));
  129034. + }
  129035. +#line 1661 "dtc-parser.tab.c" /* yacc.c:1646 */
  129036. + break;
  129037. +
  129038. + case 24:
  129039. +#line 240 "dtc-parser.y" /* yacc.c:1646 */
  129040. + {
  129041. + FILE *f = srcfile_relative_open((yyvsp[-5].data).val, NULL);
  129042. struct data d;
  129043. - if ((yyvsp[(6) - (9)].integer) != 0)
  129044. - if (fseek(f, (yyvsp[(6) - (9)].integer), SEEK_SET) != 0)
  129045. - print_error("Couldn't seek to offset %llu in \"%s\": %s",
  129046. - (unsigned long long)(yyvsp[(6) - (9)].integer),
  129047. - (yyvsp[(4) - (9)].data).val,
  129048. - strerror(errno));
  129049. + if ((yyvsp[-3].integer) != 0)
  129050. + if (fseek(f, (yyvsp[-3].integer), SEEK_SET) != 0)
  129051. + die("Couldn't seek to offset %llu in \"%s\": %s",
  129052. + (unsigned long long)(yyvsp[-3].integer), (yyvsp[-5].data).val,
  129053. + strerror(errno));
  129054. - d = data_copy_file(f, (yyvsp[(8) - (9)].integer));
  129055. + d = data_copy_file(f, (yyvsp[-1].integer));
  129056. - (yyval.data) = data_merge((yyvsp[(1) - (9)].data), d);
  129057. + (yyval.data) = data_merge((yyvsp[-8].data), d);
  129058. fclose(f);
  129059. }
  129060. +#line 1681 "dtc-parser.tab.c" /* yacc.c:1646 */
  129061. break;
  129062. - case 23:
  129063. -/* Line 1787 of yacc.c */
  129064. -#line 244 "dtc-parser.y"
  129065. + case 25:
  129066. +#line 256 "dtc-parser.y" /* yacc.c:1646 */
  129067. {
  129068. - FILE *f = srcfile_relative_open((yyvsp[(4) - (5)].data).val, NULL);
  129069. + FILE *f = srcfile_relative_open((yyvsp[-1].data).val, NULL);
  129070. struct data d = empty_data;
  129071. d = data_copy_file(f, -1);
  129072. - (yyval.data) = data_merge((yyvsp[(1) - (5)].data), d);
  129073. + (yyval.data) = data_merge((yyvsp[-4].data), d);
  129074. fclose(f);
  129075. }
  129076. +#line 1695 "dtc-parser.tab.c" /* yacc.c:1646 */
  129077. break;
  129078. - case 24:
  129079. -/* Line 1787 of yacc.c */
  129080. -#line 254 "dtc-parser.y"
  129081. + case 26:
  129082. +#line 266 "dtc-parser.y" /* yacc.c:1646 */
  129083. {
  129084. - (yyval.data) = data_add_marker((yyvsp[(1) - (2)].data), LABEL, (yyvsp[(2) - (2)].labelref));
  129085. + (yyval.data) = data_add_marker((yyvsp[-1].data), LABEL, (yyvsp[0].labelref));
  129086. }
  129087. +#line 1703 "dtc-parser.tab.c" /* yacc.c:1646 */
  129088. break;
  129089. - case 25:
  129090. -/* Line 1787 of yacc.c */
  129091. -#line 261 "dtc-parser.y"
  129092. + case 27:
  129093. +#line 273 "dtc-parser.y" /* yacc.c:1646 */
  129094. {
  129095. (yyval.data) = empty_data;
  129096. }
  129097. +#line 1711 "dtc-parser.tab.c" /* yacc.c:1646 */
  129098. break;
  129099. - case 26:
  129100. -/* Line 1787 of yacc.c */
  129101. -#line 265 "dtc-parser.y"
  129102. + case 28:
  129103. +#line 277 "dtc-parser.y" /* yacc.c:1646 */
  129104. {
  129105. - (yyval.data) = (yyvsp[(1) - (2)].data);
  129106. + (yyval.data) = (yyvsp[-1].data);
  129107. }
  129108. +#line 1719 "dtc-parser.tab.c" /* yacc.c:1646 */
  129109. break;
  129110. - case 27:
  129111. -/* Line 1787 of yacc.c */
  129112. -#line 269 "dtc-parser.y"
  129113. + case 29:
  129114. +#line 281 "dtc-parser.y" /* yacc.c:1646 */
  129115. {
  129116. - (yyval.data) = data_add_marker((yyvsp[(1) - (2)].data), LABEL, (yyvsp[(2) - (2)].labelref));
  129117. + (yyval.data) = data_add_marker((yyvsp[-1].data), LABEL, (yyvsp[0].labelref));
  129118. }
  129119. +#line 1727 "dtc-parser.tab.c" /* yacc.c:1646 */
  129120. break;
  129121. - case 28:
  129122. -/* Line 1787 of yacc.c */
  129123. -#line 276 "dtc-parser.y"
  129124. + case 30:
  129125. +#line 288 "dtc-parser.y" /* yacc.c:1646 */
  129126. {
  129127. - (yyval.array).data = empty_data;
  129128. - (yyval.array).bits = eval_literal((yyvsp[(2) - (3)].literal), 0, 7);
  129129. + unsigned long long bits;
  129130. - if (((yyval.array).bits != 8) &&
  129131. - ((yyval.array).bits != 16) &&
  129132. - ((yyval.array).bits != 32) &&
  129133. - ((yyval.array).bits != 64))
  129134. - {
  129135. - print_error("Only 8, 16, 32 and 64-bit elements"
  129136. - " are currently supported");
  129137. - (yyval.array).bits = 32;
  129138. + bits = (yyvsp[-1].integer);
  129139. +
  129140. + if ((bits != 8) && (bits != 16) &&
  129141. + (bits != 32) && (bits != 64)) {
  129142. + ERROR(&(yylsp[-1]), "Array elements must be"
  129143. + " 8, 16, 32 or 64-bits");
  129144. + bits = 32;
  129145. }
  129146. +
  129147. + (yyval.array).data = empty_data;
  129148. + (yyval.array).bits = bits;
  129149. }
  129150. +#line 1747 "dtc-parser.tab.c" /* yacc.c:1646 */
  129151. break;
  129152. - case 29:
  129153. -/* Line 1787 of yacc.c */
  129154. -#line 291 "dtc-parser.y"
  129155. + case 31:
  129156. +#line 304 "dtc-parser.y" /* yacc.c:1646 */
  129157. {
  129158. (yyval.array).data = empty_data;
  129159. (yyval.array).bits = 32;
  129160. }
  129161. +#line 1756 "dtc-parser.tab.c" /* yacc.c:1646 */
  129162. break;
  129163. - case 30:
  129164. -/* Line 1787 of yacc.c */
  129165. -#line 296 "dtc-parser.y"
  129166. + case 32:
  129167. +#line 309 "dtc-parser.y" /* yacc.c:1646 */
  129168. {
  129169. - if ((yyvsp[(1) - (2)].array).bits < 64) {
  129170. - uint64_t mask = (1ULL << (yyvsp[(1) - (2)].array).bits) - 1;
  129171. + if ((yyvsp[-1].array).bits < 64) {
  129172. + uint64_t mask = (1ULL << (yyvsp[-1].array).bits) - 1;
  129173. /*
  129174. * Bits above mask must either be all zero
  129175. * (positive within range of mask) or all one
  129176. @@ -1801,275 +1768,258 @@
  129177. * within the mask to one (i.e. | in the
  129178. * mask), all bits are one.
  129179. */
  129180. - if (((yyvsp[(2) - (2)].integer) > mask) && (((yyvsp[(2) - (2)].integer) | mask) != -1ULL))
  129181. - print_error(
  129182. - "integer value out of range "
  129183. - "%016lx (%d bits)", (yyvsp[(1) - (2)].array).bits);
  129184. + if (((yyvsp[0].integer) > mask) && (((yyvsp[0].integer) | mask) != -1ULL))
  129185. + ERROR(&(yylsp[0]), "Value out of range for"
  129186. + " %d-bit array element", (yyvsp[-1].array).bits);
  129187. }
  129188. - (yyval.array).data = data_append_integer((yyvsp[(1) - (2)].array).data, (yyvsp[(2) - (2)].integer), (yyvsp[(1) - (2)].array).bits);
  129189. + (yyval.array).data = data_append_integer((yyvsp[-1].array).data, (yyvsp[0].integer), (yyvsp[-1].array).bits);
  129190. }
  129191. +#line 1779 "dtc-parser.tab.c" /* yacc.c:1646 */
  129192. break;
  129193. - case 31:
  129194. -/* Line 1787 of yacc.c */
  129195. -#line 316 "dtc-parser.y"
  129196. + case 33:
  129197. +#line 328 "dtc-parser.y" /* yacc.c:1646 */
  129198. {
  129199. - uint64_t val = ~0ULL >> (64 - (yyvsp[(1) - (2)].array).bits);
  129200. + uint64_t val = ~0ULL >> (64 - (yyvsp[-1].array).bits);
  129201. - if ((yyvsp[(1) - (2)].array).bits == 32)
  129202. - (yyvsp[(1) - (2)].array).data = data_add_marker((yyvsp[(1) - (2)].array).data,
  129203. + if ((yyvsp[-1].array).bits == 32)
  129204. + (yyvsp[-1].array).data = data_add_marker((yyvsp[-1].array).data,
  129205. REF_PHANDLE,
  129206. - (yyvsp[(2) - (2)].labelref));
  129207. + (yyvsp[0].labelref));
  129208. else
  129209. - print_error("References are only allowed in "
  129210. + ERROR(&(yylsp[0]), "References are only allowed in "
  129211. "arrays with 32-bit elements.");
  129212. - (yyval.array).data = data_append_integer((yyvsp[(1) - (2)].array).data, val, (yyvsp[(1) - (2)].array).bits);
  129213. - }
  129214. - break;
  129215. -
  129216. - case 32:
  129217. -/* Line 1787 of yacc.c */
  129218. -#line 330 "dtc-parser.y"
  129219. - {
  129220. - (yyval.array).data = data_add_marker((yyvsp[(1) - (2)].array).data, LABEL, (yyvsp[(2) - (2)].labelref));
  129221. - }
  129222. - break;
  129223. -
  129224. - case 33:
  129225. -/* Line 1787 of yacc.c */
  129226. -#line 337 "dtc-parser.y"
  129227. - {
  129228. - (yyval.integer) = eval_literal((yyvsp[(1) - (1)].literal), 0, 64);
  129229. + (yyval.array).data = data_append_integer((yyvsp[-1].array).data, val, (yyvsp[-1].array).bits);
  129230. }
  129231. +#line 1797 "dtc-parser.tab.c" /* yacc.c:1646 */
  129232. break;
  129233. case 34:
  129234. -/* Line 1787 of yacc.c */
  129235. -#line 341 "dtc-parser.y"
  129236. +#line 342 "dtc-parser.y" /* yacc.c:1646 */
  129237. {
  129238. - (yyval.integer) = eval_char_literal((yyvsp[(1) - (1)].literal));
  129239. + (yyval.array).data = data_add_marker((yyvsp[-1].array).data, LABEL, (yyvsp[0].labelref));
  129240. }
  129241. +#line 1805 "dtc-parser.tab.c" /* yacc.c:1646 */
  129242. break;
  129243. - case 35:
  129244. -/* Line 1787 of yacc.c */
  129245. -#line 345 "dtc-parser.y"
  129246. + case 37:
  129247. +#line 351 "dtc-parser.y" /* yacc.c:1646 */
  129248. {
  129249. - (yyval.integer) = (yyvsp[(2) - (3)].integer);
  129250. + (yyval.integer) = (yyvsp[-1].integer);
  129251. }
  129252. - break;
  129253. -
  129254. - case 38:
  129255. -/* Line 1787 of yacc.c */
  129256. -#line 356 "dtc-parser.y"
  129257. - { (yyval.integer) = (yyvsp[(1) - (5)].integer) ? (yyvsp[(3) - (5)].integer) : (yyvsp[(5) - (5)].integer); }
  129258. +#line 1813 "dtc-parser.tab.c" /* yacc.c:1646 */
  129259. break;
  129260. case 40:
  129261. -/* Line 1787 of yacc.c */
  129262. -#line 361 "dtc-parser.y"
  129263. - { (yyval.integer) = (yyvsp[(1) - (3)].integer) || (yyvsp[(3) - (3)].integer); }
  129264. +#line 362 "dtc-parser.y" /* yacc.c:1646 */
  129265. + { (yyval.integer) = (yyvsp[-4].integer) ? (yyvsp[-2].integer) : (yyvsp[0].integer); }
  129266. +#line 1819 "dtc-parser.tab.c" /* yacc.c:1646 */
  129267. break;
  129268. case 42:
  129269. -/* Line 1787 of yacc.c */
  129270. -#line 366 "dtc-parser.y"
  129271. - { (yyval.integer) = (yyvsp[(1) - (3)].integer) && (yyvsp[(3) - (3)].integer); }
  129272. +#line 367 "dtc-parser.y" /* yacc.c:1646 */
  129273. + { (yyval.integer) = (yyvsp[-2].integer) || (yyvsp[0].integer); }
  129274. +#line 1825 "dtc-parser.tab.c" /* yacc.c:1646 */
  129275. break;
  129276. case 44:
  129277. -/* Line 1787 of yacc.c */
  129278. -#line 371 "dtc-parser.y"
  129279. - { (yyval.integer) = (yyvsp[(1) - (3)].integer) | (yyvsp[(3) - (3)].integer); }
  129280. +#line 372 "dtc-parser.y" /* yacc.c:1646 */
  129281. + { (yyval.integer) = (yyvsp[-2].integer) && (yyvsp[0].integer); }
  129282. +#line 1831 "dtc-parser.tab.c" /* yacc.c:1646 */
  129283. break;
  129284. case 46:
  129285. -/* Line 1787 of yacc.c */
  129286. -#line 376 "dtc-parser.y"
  129287. - { (yyval.integer) = (yyvsp[(1) - (3)].integer) ^ (yyvsp[(3) - (3)].integer); }
  129288. +#line 377 "dtc-parser.y" /* yacc.c:1646 */
  129289. + { (yyval.integer) = (yyvsp[-2].integer) | (yyvsp[0].integer); }
  129290. +#line 1837 "dtc-parser.tab.c" /* yacc.c:1646 */
  129291. break;
  129292. case 48:
  129293. -/* Line 1787 of yacc.c */
  129294. -#line 381 "dtc-parser.y"
  129295. - { (yyval.integer) = (yyvsp[(1) - (3)].integer) & (yyvsp[(3) - (3)].integer); }
  129296. +#line 382 "dtc-parser.y" /* yacc.c:1646 */
  129297. + { (yyval.integer) = (yyvsp[-2].integer) ^ (yyvsp[0].integer); }
  129298. +#line 1843 "dtc-parser.tab.c" /* yacc.c:1646 */
  129299. break;
  129300. case 50:
  129301. -/* Line 1787 of yacc.c */
  129302. -#line 386 "dtc-parser.y"
  129303. - { (yyval.integer) = (yyvsp[(1) - (3)].integer) == (yyvsp[(3) - (3)].integer); }
  129304. +#line 387 "dtc-parser.y" /* yacc.c:1646 */
  129305. + { (yyval.integer) = (yyvsp[-2].integer) & (yyvsp[0].integer); }
  129306. +#line 1849 "dtc-parser.tab.c" /* yacc.c:1646 */
  129307. break;
  129308. - case 51:
  129309. -/* Line 1787 of yacc.c */
  129310. -#line 387 "dtc-parser.y"
  129311. - { (yyval.integer) = (yyvsp[(1) - (3)].integer) != (yyvsp[(3) - (3)].integer); }
  129312. + case 52:
  129313. +#line 392 "dtc-parser.y" /* yacc.c:1646 */
  129314. + { (yyval.integer) = (yyvsp[-2].integer) == (yyvsp[0].integer); }
  129315. +#line 1855 "dtc-parser.tab.c" /* yacc.c:1646 */
  129316. break;
  129317. case 53:
  129318. -/* Line 1787 of yacc.c */
  129319. -#line 392 "dtc-parser.y"
  129320. - { (yyval.integer) = (yyvsp[(1) - (3)].integer) < (yyvsp[(3) - (3)].integer); }
  129321. - break;
  129322. -
  129323. - case 54:
  129324. -/* Line 1787 of yacc.c */
  129325. -#line 393 "dtc-parser.y"
  129326. - { (yyval.integer) = (yyvsp[(1) - (3)].integer) > (yyvsp[(3) - (3)].integer); }
  129327. +#line 393 "dtc-parser.y" /* yacc.c:1646 */
  129328. + { (yyval.integer) = (yyvsp[-2].integer) != (yyvsp[0].integer); }
  129329. +#line 1861 "dtc-parser.tab.c" /* yacc.c:1646 */
  129330. break;
  129331. case 55:
  129332. -/* Line 1787 of yacc.c */
  129333. -#line 394 "dtc-parser.y"
  129334. - { (yyval.integer) = (yyvsp[(1) - (3)].integer) <= (yyvsp[(3) - (3)].integer); }
  129335. +#line 398 "dtc-parser.y" /* yacc.c:1646 */
  129336. + { (yyval.integer) = (yyvsp[-2].integer) < (yyvsp[0].integer); }
  129337. +#line 1867 "dtc-parser.tab.c" /* yacc.c:1646 */
  129338. break;
  129339. case 56:
  129340. -/* Line 1787 of yacc.c */
  129341. -#line 395 "dtc-parser.y"
  129342. - { (yyval.integer) = (yyvsp[(1) - (3)].integer) >= (yyvsp[(3) - (3)].integer); }
  129343. +#line 399 "dtc-parser.y" /* yacc.c:1646 */
  129344. + { (yyval.integer) = (yyvsp[-2].integer) > (yyvsp[0].integer); }
  129345. +#line 1873 "dtc-parser.tab.c" /* yacc.c:1646 */
  129346. break;
  129347. case 57:
  129348. -/* Line 1787 of yacc.c */
  129349. -#line 399 "dtc-parser.y"
  129350. - { (yyval.integer) = (yyvsp[(1) - (3)].integer) << (yyvsp[(3) - (3)].integer); }
  129351. +#line 400 "dtc-parser.y" /* yacc.c:1646 */
  129352. + { (yyval.integer) = (yyvsp[-2].integer) <= (yyvsp[0].integer); }
  129353. +#line 1879 "dtc-parser.tab.c" /* yacc.c:1646 */
  129354. break;
  129355. case 58:
  129356. -/* Line 1787 of yacc.c */
  129357. -#line 400 "dtc-parser.y"
  129358. - { (yyval.integer) = (yyvsp[(1) - (3)].integer) >> (yyvsp[(3) - (3)].integer); }
  129359. +#line 401 "dtc-parser.y" /* yacc.c:1646 */
  129360. + { (yyval.integer) = (yyvsp[-2].integer) >= (yyvsp[0].integer); }
  129361. +#line 1885 "dtc-parser.tab.c" /* yacc.c:1646 */
  129362. break;
  129363. - case 60:
  129364. -/* Line 1787 of yacc.c */
  129365. -#line 405 "dtc-parser.y"
  129366. - { (yyval.integer) = (yyvsp[(1) - (3)].integer) + (yyvsp[(3) - (3)].integer); }
  129367. + case 59:
  129368. +#line 405 "dtc-parser.y" /* yacc.c:1646 */
  129369. + { (yyval.integer) = (yyvsp[-2].integer) << (yyvsp[0].integer); }
  129370. +#line 1891 "dtc-parser.tab.c" /* yacc.c:1646 */
  129371. break;
  129372. - case 61:
  129373. -/* Line 1787 of yacc.c */
  129374. -#line 406 "dtc-parser.y"
  129375. - { (yyval.integer) = (yyvsp[(1) - (3)].integer) - (yyvsp[(3) - (3)].integer); }
  129376. + case 60:
  129377. +#line 406 "dtc-parser.y" /* yacc.c:1646 */
  129378. + { (yyval.integer) = (yyvsp[-2].integer) >> (yyvsp[0].integer); }
  129379. +#line 1897 "dtc-parser.tab.c" /* yacc.c:1646 */
  129380. break;
  129381. - case 63:
  129382. -/* Line 1787 of yacc.c */
  129383. -#line 411 "dtc-parser.y"
  129384. - { (yyval.integer) = (yyvsp[(1) - (3)].integer) * (yyvsp[(3) - (3)].integer); }
  129385. + case 62:
  129386. +#line 411 "dtc-parser.y" /* yacc.c:1646 */
  129387. + { (yyval.integer) = (yyvsp[-2].integer) + (yyvsp[0].integer); }
  129388. +#line 1903 "dtc-parser.tab.c" /* yacc.c:1646 */
  129389. break;
  129390. - case 64:
  129391. -/* Line 1787 of yacc.c */
  129392. -#line 412 "dtc-parser.y"
  129393. - { (yyval.integer) = (yyvsp[(1) - (3)].integer) / (yyvsp[(3) - (3)].integer); }
  129394. + case 63:
  129395. +#line 412 "dtc-parser.y" /* yacc.c:1646 */
  129396. + { (yyval.integer) = (yyvsp[-2].integer) - (yyvsp[0].integer); }
  129397. +#line 1909 "dtc-parser.tab.c" /* yacc.c:1646 */
  129398. break;
  129399. case 65:
  129400. -/* Line 1787 of yacc.c */
  129401. -#line 413 "dtc-parser.y"
  129402. - { (yyval.integer) = (yyvsp[(1) - (3)].integer) % (yyvsp[(3) - (3)].integer); }
  129403. +#line 417 "dtc-parser.y" /* yacc.c:1646 */
  129404. + { (yyval.integer) = (yyvsp[-2].integer) * (yyvsp[0].integer); }
  129405. +#line 1915 "dtc-parser.tab.c" /* yacc.c:1646 */
  129406. break;
  129407. - case 68:
  129408. -/* Line 1787 of yacc.c */
  129409. -#line 419 "dtc-parser.y"
  129410. - { (yyval.integer) = -(yyvsp[(2) - (2)].integer); }
  129411. + case 66:
  129412. +#line 418 "dtc-parser.y" /* yacc.c:1646 */
  129413. + { (yyval.integer) = (yyvsp[-2].integer) / (yyvsp[0].integer); }
  129414. +#line 1921 "dtc-parser.tab.c" /* yacc.c:1646 */
  129415. break;
  129416. - case 69:
  129417. -/* Line 1787 of yacc.c */
  129418. -#line 420 "dtc-parser.y"
  129419. - { (yyval.integer) = ~(yyvsp[(2) - (2)].integer); }
  129420. + case 67:
  129421. +#line 419 "dtc-parser.y" /* yacc.c:1646 */
  129422. + { (yyval.integer) = (yyvsp[-2].integer) % (yyvsp[0].integer); }
  129423. +#line 1927 "dtc-parser.tab.c" /* yacc.c:1646 */
  129424. break;
  129425. case 70:
  129426. -/* Line 1787 of yacc.c */
  129427. -#line 421 "dtc-parser.y"
  129428. - { (yyval.integer) = !(yyvsp[(2) - (2)].integer); }
  129429. +#line 425 "dtc-parser.y" /* yacc.c:1646 */
  129430. + { (yyval.integer) = -(yyvsp[0].integer); }
  129431. +#line 1933 "dtc-parser.tab.c" /* yacc.c:1646 */
  129432. break;
  129433. case 71:
  129434. -/* Line 1787 of yacc.c */
  129435. -#line 426 "dtc-parser.y"
  129436. - {
  129437. - (yyval.data) = empty_data;
  129438. - }
  129439. +#line 426 "dtc-parser.y" /* yacc.c:1646 */
  129440. + { (yyval.integer) = ~(yyvsp[0].integer); }
  129441. +#line 1939 "dtc-parser.tab.c" /* yacc.c:1646 */
  129442. break;
  129443. case 72:
  129444. -/* Line 1787 of yacc.c */
  129445. -#line 430 "dtc-parser.y"
  129446. - {
  129447. - (yyval.data) = data_append_byte((yyvsp[(1) - (2)].data), (yyvsp[(2) - (2)].byte));
  129448. - }
  129449. +#line 427 "dtc-parser.y" /* yacc.c:1646 */
  129450. + { (yyval.integer) = !(yyvsp[0].integer); }
  129451. +#line 1945 "dtc-parser.tab.c" /* yacc.c:1646 */
  129452. break;
  129453. case 73:
  129454. -/* Line 1787 of yacc.c */
  129455. -#line 434 "dtc-parser.y"
  129456. +#line 432 "dtc-parser.y" /* yacc.c:1646 */
  129457. {
  129458. - (yyval.data) = data_add_marker((yyvsp[(1) - (2)].data), LABEL, (yyvsp[(2) - (2)].labelref));
  129459. + (yyval.data) = empty_data;
  129460. }
  129461. +#line 1953 "dtc-parser.tab.c" /* yacc.c:1646 */
  129462. break;
  129463. case 74:
  129464. -/* Line 1787 of yacc.c */
  129465. -#line 441 "dtc-parser.y"
  129466. +#line 436 "dtc-parser.y" /* yacc.c:1646 */
  129467. {
  129468. - (yyval.nodelist) = NULL;
  129469. + (yyval.data) = data_append_byte((yyvsp[-1].data), (yyvsp[0].byte));
  129470. }
  129471. +#line 1961 "dtc-parser.tab.c" /* yacc.c:1646 */
  129472. break;
  129473. case 75:
  129474. -/* Line 1787 of yacc.c */
  129475. -#line 445 "dtc-parser.y"
  129476. +#line 440 "dtc-parser.y" /* yacc.c:1646 */
  129477. {
  129478. - (yyval.nodelist) = chain_node((yyvsp[(1) - (2)].node), (yyvsp[(2) - (2)].nodelist));
  129479. + (yyval.data) = data_add_marker((yyvsp[-1].data), LABEL, (yyvsp[0].labelref));
  129480. }
  129481. +#line 1969 "dtc-parser.tab.c" /* yacc.c:1646 */
  129482. break;
  129483. case 76:
  129484. -/* Line 1787 of yacc.c */
  129485. -#line 449 "dtc-parser.y"
  129486. +#line 447 "dtc-parser.y" /* yacc.c:1646 */
  129487. {
  129488. - print_error("syntax error: properties must precede subnodes");
  129489. - YYERROR;
  129490. + (yyval.nodelist) = NULL;
  129491. }
  129492. +#line 1977 "dtc-parser.tab.c" /* yacc.c:1646 */
  129493. break;
  129494. case 77:
  129495. -/* Line 1787 of yacc.c */
  129496. -#line 457 "dtc-parser.y"
  129497. +#line 451 "dtc-parser.y" /* yacc.c:1646 */
  129498. {
  129499. - (yyval.node) = name_node((yyvsp[(2) - (2)].node), (yyvsp[(1) - (2)].propnodename));
  129500. + (yyval.nodelist) = chain_node((yyvsp[-1].node), (yyvsp[0].nodelist));
  129501. }
  129502. +#line 1985 "dtc-parser.tab.c" /* yacc.c:1646 */
  129503. break;
  129504. case 78:
  129505. -/* Line 1787 of yacc.c */
  129506. -#line 461 "dtc-parser.y"
  129507. +#line 455 "dtc-parser.y" /* yacc.c:1646 */
  129508. {
  129509. - (yyval.node) = name_node(build_node_delete(), (yyvsp[(2) - (3)].propnodename));
  129510. + ERROR(&(yylsp[0]), "Properties must precede subnodes");
  129511. + YYERROR;
  129512. }
  129513. +#line 1994 "dtc-parser.tab.c" /* yacc.c:1646 */
  129514. break;
  129515. case 79:
  129516. -/* Line 1787 of yacc.c */
  129517. -#line 465 "dtc-parser.y"
  129518. +#line 463 "dtc-parser.y" /* yacc.c:1646 */
  129519. {
  129520. - add_label(&(yyvsp[(2) - (2)].node)->labels, (yyvsp[(1) - (2)].labelref));
  129521. - (yyval.node) = (yyvsp[(2) - (2)].node);
  129522. + (yyval.node) = name_node((yyvsp[0].node), (yyvsp[-1].propnodename));
  129523. }
  129524. +#line 2002 "dtc-parser.tab.c" /* yacc.c:1646 */
  129525. break;
  129526. + case 80:
  129527. +#line 467 "dtc-parser.y" /* yacc.c:1646 */
  129528. + {
  129529. + (yyval.node) = name_node(build_node_delete(), (yyvsp[-1].propnodename));
  129530. + }
  129531. +#line 2010 "dtc-parser.tab.c" /* yacc.c:1646 */
  129532. + break;
  129533. +
  129534. + case 81:
  129535. +#line 471 "dtc-parser.y" /* yacc.c:1646 */
  129536. + {
  129537. + add_label(&(yyvsp[0].node)->labels, (yyvsp[-1].labelref));
  129538. + (yyval.node) = (yyvsp[0].node);
  129539. + }
  129540. +#line 2019 "dtc-parser.tab.c" /* yacc.c:1646 */
  129541. + break;
  129542. -/* Line 1787 of yacc.c */
  129543. -#line 2073 "dtc-parser.tab.c"
  129544. +
  129545. +#line 2023 "dtc-parser.tab.c" /* yacc.c:1646 */
  129546. default: break;
  129547. }
  129548. /* User semantic actions sometimes alter yychar, and that requires
  129549. @@ -2090,8 +2040,9 @@
  129550. YY_STACK_PRINT (yyss, yyssp);
  129551. *++yyvsp = yyval;
  129552. + *++yylsp = yyloc;
  129553. - /* Now `shift' the result of the reduction. Determine what state
  129554. + /* Now 'shift' the result of the reduction. Determine what state
  129555. that goes to, based on the state we popped back to and the rule
  129556. number reduced by. */
  129557. @@ -2106,9 +2057,9 @@
  129558. goto yynewstate;
  129559. -/*------------------------------------.
  129560. -| yyerrlab -- here on detecting error |
  129561. -`------------------------------------*/
  129562. +/*--------------------------------------.
  129563. +| yyerrlab -- here on detecting error. |
  129564. +`--------------------------------------*/
  129565. yyerrlab:
  129566. /* Make sure we have latest lookahead translation. See comments at
  129567. user semantic actions for why this is necessary. */
  129568. @@ -2154,25 +2105,25 @@
  129569. #endif
  129570. }
  129571. -
  129572. + yyerror_range[1] = yylloc;
  129573. if (yyerrstatus == 3)
  129574. {
  129575. /* If just tried and failed to reuse lookahead token after an
  129576. - error, discard it. */
  129577. + error, discard it. */
  129578. if (yychar <= YYEOF)
  129579. - {
  129580. - /* Return failure if at end of input. */
  129581. - if (yychar == YYEOF)
  129582. - YYABORT;
  129583. - }
  129584. + {
  129585. + /* Return failure if at end of input. */
  129586. + if (yychar == YYEOF)
  129587. + YYABORT;
  129588. + }
  129589. else
  129590. - {
  129591. - yydestruct ("Error: discarding",
  129592. - yytoken, &yylval);
  129593. - yychar = YYEMPTY;
  129594. - }
  129595. + {
  129596. + yydestruct ("Error: discarding",
  129597. + yytoken, &yylval, &yylloc);
  129598. + yychar = YYEMPTY;
  129599. + }
  129600. }
  129601. /* Else will try to reuse lookahead token after shifting the error
  129602. @@ -2191,7 +2142,8 @@
  129603. if (/*CONSTCOND*/ 0)
  129604. goto yyerrorlab;
  129605. - /* Do not reclaim the symbols of the rule which action triggered
  129606. + yyerror_range[1] = yylsp[1-yylen];
  129607. + /* Do not reclaim the symbols of the rule whose action triggered
  129608. this YYERROR. */
  129609. YYPOPSTACK (yylen);
  129610. yylen = 0;
  129611. @@ -2204,29 +2156,29 @@
  129612. | yyerrlab1 -- common code for both syntax error and YYERROR. |
  129613. `-------------------------------------------------------------*/
  129614. yyerrlab1:
  129615. - yyerrstatus = 3; /* Each real token shifted decrements this. */
  129616. + yyerrstatus = 3; /* Each real token shifted decrements this. */
  129617. for (;;)
  129618. {
  129619. yyn = yypact[yystate];
  129620. if (!yypact_value_is_default (yyn))
  129621. - {
  129622. - yyn += YYTERROR;
  129623. - if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
  129624. - {
  129625. - yyn = yytable[yyn];
  129626. - if (0 < yyn)
  129627. - break;
  129628. - }
  129629. - }
  129630. + {
  129631. + yyn += YYTERROR;
  129632. + if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
  129633. + {
  129634. + yyn = yytable[yyn];
  129635. + if (0 < yyn)
  129636. + break;
  129637. + }
  129638. + }
  129639. /* Pop the current state because it cannot handle the error token. */
  129640. if (yyssp == yyss)
  129641. - YYABORT;
  129642. -
  129643. + YYABORT;
  129644. + yyerror_range[1] = *yylsp;
  129645. yydestruct ("Error: popping",
  129646. - yystos[yystate], yyvsp);
  129647. + yystos[yystate], yyvsp, yylsp);
  129648. YYPOPSTACK (1);
  129649. yystate = *yyssp;
  129650. YY_STACK_PRINT (yyss, yyssp);
  129651. @@ -2236,6 +2188,11 @@
  129652. *++yyvsp = yylval;
  129653. YY_IGNORE_MAYBE_UNINITIALIZED_END
  129654. + yyerror_range[2] = yylloc;
  129655. + /* Using YYLLOC is tempting, but would change the location of
  129656. + the lookahead. YYLOC is available though. */
  129657. + YYLLOC_DEFAULT (yyloc, yyerror_range, 2);
  129658. + *++yylsp = yyloc;
  129659. /* Shift the error token. */
  129660. YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
  129661. @@ -2275,16 +2232,16 @@
  129662. user semantic actions for why this is necessary. */
  129663. yytoken = YYTRANSLATE (yychar);
  129664. yydestruct ("Cleanup: discarding lookahead",
  129665. - yytoken, &yylval);
  129666. + yytoken, &yylval, &yylloc);
  129667. }
  129668. - /* Do not reclaim the symbols of the rule which action triggered
  129669. + /* Do not reclaim the symbols of the rule whose action triggered
  129670. this YYABORT or YYACCEPT. */
  129671. YYPOPSTACK (yylen);
  129672. YY_STACK_PRINT (yyss, yyssp);
  129673. while (yyssp != yyss)
  129674. {
  129675. yydestruct ("Cleanup: popping",
  129676. - yystos[*yyssp], yyvsp);
  129677. + yystos[*yyssp], yyvsp, yylsp);
  129678. YYPOPSTACK (1);
  129679. }
  129680. #ifndef yyoverflow
  129681. @@ -2295,72 +2252,12 @@
  129682. if (yymsg != yymsgbuf)
  129683. YYSTACK_FREE (yymsg);
  129684. #endif
  129685. - /* Make sure YYID is used. */
  129686. - return YYID (yyresult);
  129687. + return yyresult;
  129688. }
  129689. +#line 477 "dtc-parser.y" /* yacc.c:1906 */
  129690. -/* Line 2050 of yacc.c */
  129691. -#line 471 "dtc-parser.y"
  129692. -
  129693. -
  129694. -void print_error(char const *fmt, ...)
  129695. +void yyerror(char const *s)
  129696. {
  129697. - va_list va;
  129698. -
  129699. - va_start(va, fmt);
  129700. - srcpos_verror(&yylloc, fmt, va);
  129701. - va_end(va);
  129702. -
  129703. - treesource_error = 1;
  129704. -}
  129705. -
  129706. -void yyerror(char const *s) {
  129707. - print_error("%s", s);
  129708. -}
  129709. -
  129710. -static unsigned long long eval_literal(const char *s, int base, int bits)
  129711. -{
  129712. - unsigned long long val;
  129713. - char *e;
  129714. -
  129715. - errno = 0;
  129716. - val = strtoull(s, &e, base);
  129717. - if (*e) {
  129718. - size_t uls = strspn(e, "UL");
  129719. - if (e[uls])
  129720. - print_error("bad characters in literal");
  129721. - }
  129722. - if ((errno == ERANGE)
  129723. - || ((bits < 64) && (val >= (1ULL << bits))))
  129724. - print_error("literal out of range");
  129725. - else if (errno != 0)
  129726. - print_error("bad literal");
  129727. - return val;
  129728. -}
  129729. -
  129730. -static unsigned char eval_char_literal(const char *s)
  129731. -{
  129732. - int i = 1;
  129733. - char c = s[0];
  129734. -
  129735. - if (c == '\0')
  129736. - {
  129737. - print_error("empty character literal");
  129738. - return 0;
  129739. - }
  129740. -
  129741. - /*
  129742. - * If the first character in the character literal is a \ then process
  129743. - * the remaining characters as an escape encoding. If the first
  129744. - * character is neither an escape or a terminator it should be the only
  129745. - * character in the literal and will be returned.
  129746. - */
  129747. - if (c == '\\')
  129748. - c = get_escape_char(s, &i);
  129749. -
  129750. - if (s[i] != '\0')
  129751. - print_error("malformed character literal");
  129752. -
  129753. - return c;
  129754. + ERROR(&yylloc, "%s", s);
  129755. }
  129756. diff -Nur linux-3.18.8/scripts/dtc/dtc-parser.tab.h_shipped linux-rpi/scripts/dtc/dtc-parser.tab.h_shipped
  129757. --- linux-3.18.8/scripts/dtc/dtc-parser.tab.h_shipped 2015-02-27 02:49:36.000000000 +0100
  129758. +++ linux-rpi/scripts/dtc/dtc-parser.tab.h_shipped 2015-03-05 14:40:18.913715792 +0100
  129759. @@ -1,19 +1,19 @@
  129760. -/* A Bison parser, made by GNU Bison 2.7.12-4996. */
  129761. +/* A Bison parser, made by GNU Bison 3.0.2. */
  129762. /* Bison interface for Yacc-like parsers in C
  129763. -
  129764. - Copyright (C) 1984, 1989-1990, 2000-2013 Free Software Foundation, Inc.
  129765. -
  129766. +
  129767. + Copyright (C) 1984, 1989-1990, 2000-2013 Free Software Foundation, Inc.
  129768. +
  129769. This program is free software: you can redistribute it and/or modify
  129770. it under the terms of the GNU General Public License as published by
  129771. the Free Software Foundation, either version 3 of the License, or
  129772. (at your option) any later version.
  129773. -
  129774. +
  129775. This program is distributed in the hope that it will be useful,
  129776. but WITHOUT ANY WARRANTY; without even the implied warranty of
  129777. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  129778. GNU General Public License for more details.
  129779. -
  129780. +
  129781. You should have received a copy of the GNU General Public License
  129782. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  129783. @@ -26,13 +26,13 @@
  129784. special exception, which will cause the skeleton and the resulting
  129785. Bison output files to be licensed under the GNU General Public
  129786. License without this special exception.
  129787. -
  129788. +
  129789. This special exception was added by the Free Software Foundation in
  129790. version 2.2 of Bison. */
  129791. #ifndef YY_YY_DTC_PARSER_TAB_H_INCLUDED
  129792. # define YY_YY_DTC_PARSER_TAB_H_INCLUDED
  129793. -/* Enabling traces. */
  129794. +/* Debug traces. */
  129795. #ifndef YYDEBUG
  129796. # define YYDEBUG 0
  129797. #endif
  129798. @@ -40,48 +40,45 @@
  129799. extern int yydebug;
  129800. #endif
  129801. -/* Tokens. */
  129802. +/* Token type. */
  129803. #ifndef YYTOKENTYPE
  129804. # define YYTOKENTYPE
  129805. - /* Put the tokens into the symbol table, so that GDB and other debuggers
  129806. - know about them. */
  129807. - enum yytokentype {
  129808. - DT_V1 = 258,
  129809. - DT_MEMRESERVE = 259,
  129810. - DT_LSHIFT = 260,
  129811. - DT_RSHIFT = 261,
  129812. - DT_LE = 262,
  129813. - DT_GE = 263,
  129814. - DT_EQ = 264,
  129815. - DT_NE = 265,
  129816. - DT_AND = 266,
  129817. - DT_OR = 267,
  129818. - DT_BITS = 268,
  129819. - DT_DEL_PROP = 269,
  129820. - DT_DEL_NODE = 270,
  129821. - DT_PROPNODENAME = 271,
  129822. - DT_LITERAL = 272,
  129823. - DT_CHAR_LITERAL = 273,
  129824. - DT_BASE = 274,
  129825. - DT_BYTE = 275,
  129826. - DT_STRING = 276,
  129827. - DT_LABEL = 277,
  129828. - DT_REF = 278,
  129829. - DT_INCBIN = 279
  129830. - };
  129831. + enum yytokentype
  129832. + {
  129833. + DT_V1 = 258,
  129834. + DT_PLUGIN = 259,
  129835. + DT_MEMRESERVE = 260,
  129836. + DT_LSHIFT = 261,
  129837. + DT_RSHIFT = 262,
  129838. + DT_LE = 263,
  129839. + DT_GE = 264,
  129840. + DT_EQ = 265,
  129841. + DT_NE = 266,
  129842. + DT_AND = 267,
  129843. + DT_OR = 268,
  129844. + DT_BITS = 269,
  129845. + DT_DEL_PROP = 270,
  129846. + DT_DEL_NODE = 271,
  129847. + DT_PROPNODENAME = 272,
  129848. + DT_LITERAL = 273,
  129849. + DT_CHAR_LITERAL = 274,
  129850. + DT_BYTE = 275,
  129851. + DT_STRING = 276,
  129852. + DT_LABEL = 277,
  129853. + DT_REF = 278,
  129854. + DT_INCBIN = 279
  129855. + };
  129856. #endif
  129857. -
  129858. +/* Value type. */
  129859. #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
  129860. -typedef union YYSTYPE
  129861. +typedef union YYSTYPE YYSTYPE;
  129862. +union YYSTYPE
  129863. {
  129864. -/* Line 2053 of yacc.c */
  129865. -#line 40 "dtc-parser.y"
  129866. +#line 39 "dtc-parser.y" /* yacc.c:1909 */
  129867. char *propnodename;
  129868. - char *literal;
  129869. char *labelref;
  129870. - unsigned int cbase;
  129871. uint8_t byte;
  129872. struct data data;
  129873. @@ -96,30 +93,31 @@
  129874. struct node *nodelist;
  129875. struct reserve_info *re;
  129876. uint64_t integer;
  129877. + int is_plugin;
  129878. -
  129879. -/* Line 2053 of yacc.c */
  129880. -#line 103 "dtc-parser.tab.h"
  129881. -} YYSTYPE;
  129882. +#line 99 "dtc-parser.tab.h" /* yacc.c:1909 */
  129883. +};
  129884. # define YYSTYPE_IS_TRIVIAL 1
  129885. -# define yystype YYSTYPE /* obsolescent; will be withdrawn */
  129886. # define YYSTYPE_IS_DECLARED 1
  129887. #endif
  129888. -extern YYSTYPE yylval;
  129889. -
  129890. -#ifdef YYPARSE_PARAM
  129891. -#if defined __STDC__ || defined __cplusplus
  129892. -int yyparse (void *YYPARSE_PARAM);
  129893. -#else
  129894. -int yyparse ();
  129895. +/* Location type. */
  129896. +#if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
  129897. +typedef struct YYLTYPE YYLTYPE;
  129898. +struct YYLTYPE
  129899. +{
  129900. + int first_line;
  129901. + int first_column;
  129902. + int last_line;
  129903. + int last_column;
  129904. +};
  129905. +# define YYLTYPE_IS_DECLARED 1
  129906. +# define YYLTYPE_IS_TRIVIAL 1
  129907. #endif
  129908. -#else /* ! YYPARSE_PARAM */
  129909. -#if defined __STDC__ || defined __cplusplus
  129910. +
  129911. +
  129912. +extern YYSTYPE yylval;
  129913. +extern YYLTYPE yylloc;
  129914. int yyparse (void);
  129915. -#else
  129916. -int yyparse ();
  129917. -#endif
  129918. -#endif /* ! YYPARSE_PARAM */
  129919. #endif /* !YY_YY_DTC_PARSER_TAB_H_INCLUDED */
  129920. diff -Nur linux-3.18.8/scripts/dtc/dtc-parser.y linux-rpi/scripts/dtc/dtc-parser.y
  129921. --- linux-3.18.8/scripts/dtc/dtc-parser.y 2015-02-27 02:49:36.000000000 +0100
  129922. +++ linux-rpi/scripts/dtc/dtc-parser.y 2015-03-05 14:40:18.913715792 +0100
  129923. @@ -17,31 +17,28 @@
  129924. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  129925. * USA
  129926. */
  129927. -
  129928. %{
  129929. #include <stdio.h>
  129930. +#include <inttypes.h>
  129931. #include "dtc.h"
  129932. #include "srcpos.h"
  129933. -YYLTYPE yylloc;
  129934. -
  129935. extern int yylex(void);
  129936. -extern void print_error(char const *fmt, ...);
  129937. extern void yyerror(char const *s);
  129938. +#define ERROR(loc, ...) \
  129939. + do { \
  129940. + srcpos_error((loc), "Error", __VA_ARGS__); \
  129941. + treesource_error = true; \
  129942. + } while (0)
  129943. extern struct boot_info *the_boot_info;
  129944. -extern int treesource_error;
  129945. -
  129946. -static unsigned long long eval_literal(const char *s, int base, int bits);
  129947. -static unsigned char eval_char_literal(const char *s);
  129948. +extern bool treesource_error;
  129949. %}
  129950. %union {
  129951. char *propnodename;
  129952. - char *literal;
  129953. char *labelref;
  129954. - unsigned int cbase;
  129955. uint8_t byte;
  129956. struct data data;
  129957. @@ -56,18 +53,19 @@
  129958. struct node *nodelist;
  129959. struct reserve_info *re;
  129960. uint64_t integer;
  129961. + int is_plugin;
  129962. }
  129963. %token DT_V1
  129964. +%token DT_PLUGIN
  129965. %token DT_MEMRESERVE
  129966. %token DT_LSHIFT DT_RSHIFT DT_LE DT_GE DT_EQ DT_NE DT_AND DT_OR
  129967. %token DT_BITS
  129968. %token DT_DEL_PROP
  129969. %token DT_DEL_NODE
  129970. %token <propnodename> DT_PROPNODENAME
  129971. -%token <literal> DT_LITERAL
  129972. -%token <literal> DT_CHAR_LITERAL
  129973. -%token <cbase> DT_BASE
  129974. +%token <integer> DT_LITERAL
  129975. +%token <integer> DT_CHAR_LITERAL
  129976. %token <byte> DT_BYTE
  129977. %token <data> DT_STRING
  129978. %token <labelref> DT_LABEL
  129979. @@ -76,6 +74,7 @@
  129980. %type <data> propdata
  129981. %type <data> propdataprefix
  129982. +%type <is_plugin> plugindecl
  129983. %type <re> memreserve
  129984. %type <re> memreserves
  129985. %type <array> arrayprefix
  129986. @@ -106,10 +105,23 @@
  129987. %%
  129988. sourcefile:
  129989. - DT_V1 ';' memreserves devicetree
  129990. + DT_V1 ';' plugindecl memreserves devicetree
  129991. + {
  129992. + $5->is_plugin = $3;
  129993. + $5->is_root = 1;
  129994. + the_boot_info = build_boot_info($4, $5,
  129995. + guess_boot_cpuid($5));
  129996. + }
  129997. + ;
  129998. +
  129999. +plugindecl:
  130000. + /* empty */
  130001. + {
  130002. + $$ = 0;
  130003. + }
  130004. + | DT_PLUGIN ';'
  130005. {
  130006. - the_boot_info = build_boot_info($3, $4,
  130007. - guess_boot_cpuid($4));
  130008. + $$ = 1;
  130009. }
  130010. ;
  130011. @@ -152,17 +164,18 @@
  130012. if (target)
  130013. merge_nodes(target, $3);
  130014. else
  130015. - print_error("label or path, '%s', not found", $2);
  130016. + ERROR(&@2, "Label or path %s not found", $2);
  130017. $$ = $1;
  130018. }
  130019. | devicetree DT_DEL_NODE DT_REF ';'
  130020. {
  130021. struct node *target = get_node_by_ref($1, $3);
  130022. - if (!target)
  130023. - print_error("label or path, '%s', not found", $3);
  130024. - else
  130025. + if (target)
  130026. delete_node(target);
  130027. + else
  130028. + ERROR(&@3, "Label or path %s not found", $3);
  130029. +
  130030. $$ = $1;
  130031. }
  130032. @@ -230,10 +243,9 @@
  130033. if ($6 != 0)
  130034. if (fseek(f, $6, SEEK_SET) != 0)
  130035. - print_error("Couldn't seek to offset %llu in \"%s\": %s",
  130036. - (unsigned long long)$6,
  130037. - $4.val,
  130038. - strerror(errno));
  130039. + die("Couldn't seek to offset %llu in \"%s\": %s",
  130040. + (unsigned long long)$6, $4.val,
  130041. + strerror(errno));
  130042. d = data_copy_file(f, $8);
  130043. @@ -274,18 +286,19 @@
  130044. arrayprefix:
  130045. DT_BITS DT_LITERAL '<'
  130046. {
  130047. - $$.data = empty_data;
  130048. - $$.bits = eval_literal($2, 0, 7);
  130049. + unsigned long long bits;
  130050. - if (($$.bits != 8) &&
  130051. - ($$.bits != 16) &&
  130052. - ($$.bits != 32) &&
  130053. - ($$.bits != 64))
  130054. - {
  130055. - print_error("Only 8, 16, 32 and 64-bit elements"
  130056. - " are currently supported");
  130057. - $$.bits = 32;
  130058. + bits = $2;
  130059. +
  130060. + if ((bits != 8) && (bits != 16) &&
  130061. + (bits != 32) && (bits != 64)) {
  130062. + ERROR(&@2, "Array elements must be"
  130063. + " 8, 16, 32 or 64-bits");
  130064. + bits = 32;
  130065. }
  130066. +
  130067. + $$.data = empty_data;
  130068. + $$.bits = bits;
  130069. }
  130070. | '<'
  130071. {
  130072. @@ -305,9 +318,8 @@
  130073. * mask), all bits are one.
  130074. */
  130075. if (($2 > mask) && (($2 | mask) != -1ULL))
  130076. - print_error(
  130077. - "integer value out of range "
  130078. - "%016lx (%d bits)", $1.bits);
  130079. + ERROR(&@2, "Value out of range for"
  130080. + " %d-bit array element", $1.bits);
  130081. }
  130082. $$.data = data_append_integer($1.data, $2, $1.bits);
  130083. @@ -321,7 +333,7 @@
  130084. REF_PHANDLE,
  130085. $2);
  130086. else
  130087. - print_error("References are only allowed in "
  130088. + ERROR(&@2, "References are only allowed in "
  130089. "arrays with 32-bit elements.");
  130090. $$.data = data_append_integer($1.data, val, $1.bits);
  130091. @@ -334,13 +346,7 @@
  130092. integer_prim:
  130093. DT_LITERAL
  130094. - {
  130095. - $$ = eval_literal($1, 0, 64);
  130096. - }
  130097. | DT_CHAR_LITERAL
  130098. - {
  130099. - $$ = eval_char_literal($1);
  130100. - }
  130101. | '(' integer_expr ')'
  130102. {
  130103. $$ = $2;
  130104. @@ -447,7 +453,7 @@
  130105. }
  130106. | subnode propdef
  130107. {
  130108. - print_error("syntax error: properties must precede subnodes");
  130109. + ERROR(&@2, "Properties must precede subnodes");
  130110. YYERROR;
  130111. }
  130112. ;
  130113. @@ -470,63 +476,7 @@
  130114. %%
  130115. -void print_error(char const *fmt, ...)
  130116. +void yyerror(char const *s)
  130117. {
  130118. - va_list va;
  130119. -
  130120. - va_start(va, fmt);
  130121. - srcpos_verror(&yylloc, fmt, va);
  130122. - va_end(va);
  130123. -
  130124. - treesource_error = 1;
  130125. -}
  130126. -
  130127. -void yyerror(char const *s) {
  130128. - print_error("%s", s);
  130129. -}
  130130. -
  130131. -static unsigned long long eval_literal(const char *s, int base, int bits)
  130132. -{
  130133. - unsigned long long val;
  130134. - char *e;
  130135. -
  130136. - errno = 0;
  130137. - val = strtoull(s, &e, base);
  130138. - if (*e) {
  130139. - size_t uls = strspn(e, "UL");
  130140. - if (e[uls])
  130141. - print_error("bad characters in literal");
  130142. - }
  130143. - if ((errno == ERANGE)
  130144. - || ((bits < 64) && (val >= (1ULL << bits))))
  130145. - print_error("literal out of range");
  130146. - else if (errno != 0)
  130147. - print_error("bad literal");
  130148. - return val;
  130149. -}
  130150. -
  130151. -static unsigned char eval_char_literal(const char *s)
  130152. -{
  130153. - int i = 1;
  130154. - char c = s[0];
  130155. -
  130156. - if (c == '\0')
  130157. - {
  130158. - print_error("empty character literal");
  130159. - return 0;
  130160. - }
  130161. -
  130162. - /*
  130163. - * If the first character in the character literal is a \ then process
  130164. - * the remaining characters as an escape encoding. If the first
  130165. - * character is neither an escape or a terminator it should be the only
  130166. - * character in the literal and will be returned.
  130167. - */
  130168. - if (c == '\\')
  130169. - c = get_escape_char(s, &i);
  130170. -
  130171. - if (s[i] != '\0')
  130172. - print_error("malformed character literal");
  130173. -
  130174. - return c;
  130175. + ERROR(&yylloc, "%s", s);
  130176. }
  130177. diff -Nur linux-3.18.8/scripts/dtc/flattree.c linux-rpi/scripts/dtc/flattree.c
  130178. --- linux-3.18.8/scripts/dtc/flattree.c 2015-02-27 02:49:36.000000000 +0100
  130179. +++ linux-rpi/scripts/dtc/flattree.c 2015-03-05 14:40:18.913715792 +0100
  130180. @@ -261,7 +261,13 @@
  130181. {
  130182. struct property *prop;
  130183. struct node *child;
  130184. - int seen_name_prop = 0;
  130185. + bool seen_name_prop = false;
  130186. + struct symbol *sym;
  130187. + struct fixup *f;
  130188. + struct fixup_entry *fe;
  130189. + char *name, *s;
  130190. + const char *fullpath;
  130191. + int namesz, nameoff, vallen;
  130192. if (tree->deleted)
  130193. return;
  130194. @@ -276,10 +282,8 @@
  130195. emit->align(etarget, sizeof(cell_t));
  130196. for_each_property(tree, prop) {
  130197. - int nameoff;
  130198. -
  130199. if (streq(prop->name, "name"))
  130200. - seen_name_prop = 1;
  130201. + seen_name_prop = true;
  130202. nameoff = stringtable_insert(strbuf, prop->name);
  130203. @@ -310,6 +314,139 @@
  130204. flatten_tree(child, emit, etarget, strbuf, vi);
  130205. }
  130206. + if (!symbol_fixup_support)
  130207. + goto no_symbols;
  130208. +
  130209. + /* add the symbol nodes (if any) */
  130210. + if (tree->symbols) {
  130211. +
  130212. + emit->beginnode(etarget, NULL);
  130213. + emit->string(etarget, "__symbols__", 0);
  130214. + emit->align(etarget, sizeof(cell_t));
  130215. +
  130216. + for_each_symbol(tree, sym) {
  130217. +
  130218. + vallen = strlen(sym->node->fullpath);
  130219. +
  130220. + nameoff = stringtable_insert(strbuf, sym->label->label);
  130221. +
  130222. + emit->property(etarget, NULL);
  130223. + emit->cell(etarget, vallen + 1);
  130224. + emit->cell(etarget, nameoff);
  130225. +
  130226. + if ((vi->flags & FTF_VARALIGN) && vallen >= 8)
  130227. + emit->align(etarget, 8);
  130228. +
  130229. + emit->string(etarget, sym->node->fullpath,
  130230. + strlen(sym->node->fullpath));
  130231. + emit->align(etarget, sizeof(cell_t));
  130232. + }
  130233. +
  130234. + emit->endnode(etarget, NULL);
  130235. + }
  130236. +
  130237. + /* add the fixup nodes */
  130238. + if (tree->fixups) {
  130239. +
  130240. + /* emit the external fixups */
  130241. + emit->beginnode(etarget, NULL);
  130242. + emit->string(etarget, "__fixups__", 0);
  130243. + emit->align(etarget, sizeof(cell_t));
  130244. +
  130245. + for_each_fixup(tree, f) {
  130246. +
  130247. + namesz = 0;
  130248. + for_each_fixup_entry(f, fe) {
  130249. + fullpath = fe->node->fullpath;
  130250. + if (fullpath[0] == '\0')
  130251. + fullpath = "/";
  130252. + namesz += strlen(fullpath) + 1;
  130253. + namesz += strlen(fe->prop->name) + 1;
  130254. + namesz += 32; /* space for :<number> + '\0' */
  130255. + }
  130256. +
  130257. + name = xmalloc(namesz);
  130258. +
  130259. + s = name;
  130260. + for_each_fixup_entry(f, fe) {
  130261. + fullpath = fe->node->fullpath;
  130262. + if (fullpath[0] == '\0')
  130263. + fullpath = "/";
  130264. + snprintf(s, name + namesz - s, "%s:%s:%d",
  130265. + fullpath,
  130266. + fe->prop->name, fe->offset);
  130267. + s += strlen(s) + 1;
  130268. + }
  130269. +
  130270. + nameoff = stringtable_insert(strbuf, f->ref);
  130271. + vallen = s - name - 1;
  130272. +
  130273. + emit->property(etarget, NULL);
  130274. + emit->cell(etarget, vallen + 1);
  130275. + emit->cell(etarget, nameoff);
  130276. +
  130277. + if ((vi->flags & FTF_VARALIGN) && vallen >= 8)
  130278. + emit->align(etarget, 8);
  130279. +
  130280. + emit->string(etarget, name, vallen);
  130281. + emit->align(etarget, sizeof(cell_t));
  130282. +
  130283. + free(name);
  130284. + }
  130285. +
  130286. + emit->endnode(etarget, tree->labels);
  130287. + }
  130288. +
  130289. + /* add the local fixup property */
  130290. + if (tree->local_fixups) {
  130291. +
  130292. + /* emit the external fixups */
  130293. + emit->beginnode(etarget, NULL);
  130294. + emit->string(etarget, "__local_fixups__", 0);
  130295. + emit->align(etarget, sizeof(cell_t));
  130296. +
  130297. + namesz = 0;
  130298. + for_each_local_fixup_entry(tree, fe) {
  130299. + fullpath = fe->node->fullpath;
  130300. + if (fullpath[0] == '\0')
  130301. + fullpath = "/";
  130302. + namesz += strlen(fullpath) + 1;
  130303. + namesz += strlen(fe->prop->name) + 1;
  130304. + namesz += 32; /* space for :<number> + '\0' */
  130305. + }
  130306. +
  130307. + name = xmalloc(namesz);
  130308. +
  130309. + s = name;
  130310. + for_each_local_fixup_entry(tree, fe) {
  130311. + fullpath = fe->node->fullpath;
  130312. + if (fullpath[0] == '\0')
  130313. + fullpath = "/";
  130314. + snprintf(s, name + namesz - s, "%s:%s:%d",
  130315. + fullpath, fe->prop->name,
  130316. + fe->offset);
  130317. + s += strlen(s) + 1;
  130318. + }
  130319. +
  130320. + nameoff = stringtable_insert(strbuf, "fixup");
  130321. + vallen = s - name - 1;
  130322. +
  130323. + emit->property(etarget, NULL);
  130324. + emit->cell(etarget, vallen + 1);
  130325. + emit->cell(etarget, nameoff);
  130326. +
  130327. + if ((vi->flags & FTF_VARALIGN) && vallen >= 8)
  130328. + emit->align(etarget, 8);
  130329. +
  130330. + emit->string(etarget, name, vallen);
  130331. + emit->align(etarget, sizeof(cell_t));
  130332. +
  130333. + free(name);
  130334. +
  130335. + emit->endnode(etarget, tree->labels);
  130336. + }
  130337. +
  130338. +no_symbols:
  130339. emit->endnode(etarget, tree->labels);
  130340. }
  130341. diff -Nur linux-3.18.8/scripts/dtc/fstree.c linux-rpi/scripts/dtc/fstree.c
  130342. --- linux-3.18.8/scripts/dtc/fstree.c 2015-02-27 02:49:36.000000000 +0100
  130343. +++ linux-rpi/scripts/dtc/fstree.c 2015-03-05 14:40:18.913715792 +0100
  130344. @@ -37,26 +37,26 @@
  130345. tree = build_node(NULL, NULL);
  130346. while ((de = readdir(d)) != NULL) {
  130347. - char *tmpnam;
  130348. + char *tmpname;
  130349. if (streq(de->d_name, ".")
  130350. || streq(de->d_name, ".."))
  130351. continue;
  130352. - tmpnam = join_path(dirname, de->d_name);
  130353. + tmpname = join_path(dirname, de->d_name);
  130354. - if (lstat(tmpnam, &st) < 0)
  130355. - die("stat(%s): %s\n", tmpnam, strerror(errno));
  130356. + if (lstat(tmpname, &st) < 0)
  130357. + die("stat(%s): %s\n", tmpname, strerror(errno));
  130358. if (S_ISREG(st.st_mode)) {
  130359. struct property *prop;
  130360. FILE *pfile;
  130361. - pfile = fopen(tmpnam, "r");
  130362. + pfile = fopen(tmpname, "rb");
  130363. if (! pfile) {
  130364. fprintf(stderr,
  130365. "WARNING: Cannot open %s: %s\n",
  130366. - tmpnam, strerror(errno));
  130367. + tmpname, strerror(errno));
  130368. } else {
  130369. prop = build_property(xstrdup(de->d_name),
  130370. data_copy_file(pfile,
  130371. @@ -67,12 +67,12 @@
  130372. } else if (S_ISDIR(st.st_mode)) {
  130373. struct node *newchild;
  130374. - newchild = read_fstree(tmpnam);
  130375. + newchild = read_fstree(tmpname);
  130376. newchild = name_node(newchild, xstrdup(de->d_name));
  130377. add_child(tree, newchild);
  130378. }
  130379. - free(tmpnam);
  130380. + free(tmpname);
  130381. }
  130382. closedir(d);
  130383. diff -Nur linux-3.18.8/scripts/dtc/livetree.c linux-rpi/scripts/dtc/livetree.c
  130384. --- linux-3.18.8/scripts/dtc/livetree.c 2015-02-27 02:49:36.000000000 +0100
  130385. +++ linux-rpi/scripts/dtc/livetree.c 2015-03-05 14:40:18.913715792 +0100
  130386. @@ -511,7 +511,9 @@
  130387. struct node *get_node_by_ref(struct node *tree, const char *ref)
  130388. {
  130389. - if (ref[0] == '/')
  130390. + if (streq(ref, "/"))
  130391. + return tree;
  130392. + else if (ref[0] == '/')
  130393. return get_node_by_path(tree, ref);
  130394. else
  130395. return get_node_by_label(tree, ref);
  130396. diff -Nur linux-3.18.8/scripts/dtc/srcpos.c linux-rpi/scripts/dtc/srcpos.c
  130397. --- linux-3.18.8/scripts/dtc/srcpos.c 2015-02-27 02:49:36.000000000 +0100
  130398. +++ linux-rpi/scripts/dtc/srcpos.c 2015-03-05 14:40:18.913715792 +0100
  130399. @@ -34,7 +34,7 @@
  130400. static struct search_path *search_path_head, **search_path_tail;
  130401. -static char *dirname(const char *path)
  130402. +static char *get_dirname(const char *path)
  130403. {
  130404. const char *slash = strrchr(path, '/');
  130405. @@ -77,7 +77,7 @@
  130406. else
  130407. fullname = join_path(dirname, fname);
  130408. - *fp = fopen(fullname, "r");
  130409. + *fp = fopen(fullname, "rb");
  130410. if (!*fp) {
  130411. free(fullname);
  130412. fullname = NULL;
  130413. @@ -150,7 +150,7 @@
  130414. srcfile = xmalloc(sizeof(*srcfile));
  130415. srcfile->f = srcfile_relative_open(fname, &srcfile->name);
  130416. - srcfile->dir = dirname(srcfile->name);
  130417. + srcfile->dir = get_dirname(srcfile->name);
  130418. srcfile->prev = current_srcfile;
  130419. srcfile->lineno = 1;
  130420. @@ -159,7 +159,7 @@
  130421. current_srcfile = srcfile;
  130422. }
  130423. -int srcfile_pop(void)
  130424. +bool srcfile_pop(void)
  130425. {
  130426. struct srcfile_state *srcfile = current_srcfile;
  130427. @@ -177,7 +177,7 @@
  130428. * fix this we could either allocate all the files from a
  130429. * table, or use a pool allocator. */
  130430. - return current_srcfile ? 1 : 0;
  130431. + return current_srcfile ? true : false;
  130432. }
  130433. void srcfile_add_search_path(const char *dirname)
  130434. @@ -290,42 +290,27 @@
  130435. return pos_str;
  130436. }
  130437. -void
  130438. -srcpos_verror(struct srcpos *pos, char const *fmt, va_list va)
  130439. +void srcpos_verror(struct srcpos *pos, const char *prefix,
  130440. + const char *fmt, va_list va)
  130441. {
  130442. - const char *srcstr;
  130443. -
  130444. - srcstr = srcpos_string(pos);
  130445. + char *srcstr;
  130446. - fprintf(stderr, "Error: %s ", srcstr);
  130447. - vfprintf(stderr, fmt, va);
  130448. - fprintf(stderr, "\n");
  130449. -}
  130450. + srcstr = srcpos_string(pos);
  130451. -void
  130452. -srcpos_error(struct srcpos *pos, char const *fmt, ...)
  130453. -{
  130454. - va_list va;
  130455. + fprintf(stderr, "%s: %s ", prefix, srcstr);
  130456. + vfprintf(stderr, fmt, va);
  130457. + fprintf(stderr, "\n");
  130458. - va_start(va, fmt);
  130459. - srcpos_verror(pos, fmt, va);
  130460. - va_end(va);
  130461. + free(srcstr);
  130462. }
  130463. -
  130464. -void
  130465. -srcpos_warn(struct srcpos *pos, char const *fmt, ...)
  130466. +void srcpos_error(struct srcpos *pos, const char *prefix,
  130467. + const char *fmt, ...)
  130468. {
  130469. - const char *srcstr;
  130470. va_list va;
  130471. - va_start(va, fmt);
  130472. -
  130473. - srcstr = srcpos_string(pos);
  130474. -
  130475. - fprintf(stderr, "Warning: %s ", srcstr);
  130476. - vfprintf(stderr, fmt, va);
  130477. - fprintf(stderr, "\n");
  130478. + va_start(va, fmt);
  130479. + srcpos_verror(pos, prefix, fmt, va);
  130480. va_end(va);
  130481. }
  130482. diff -Nur linux-3.18.8/scripts/dtc/srcpos.h linux-rpi/scripts/dtc/srcpos.h
  130483. --- linux-3.18.8/scripts/dtc/srcpos.h 2015-02-27 02:49:36.000000000 +0100
  130484. +++ linux-rpi/scripts/dtc/srcpos.h 2015-03-05 14:40:18.913715792 +0100
  130485. @@ -21,6 +21,7 @@
  130486. #define _SRCPOS_H_
  130487. #include <stdio.h>
  130488. +#include <stdbool.h>
  130489. struct srcfile_state {
  130490. FILE *f;
  130491. @@ -55,7 +56,7 @@
  130492. FILE *srcfile_relative_open(const char *fname, char **fullnamep);
  130493. void srcfile_push(const char *fname);
  130494. -int srcfile_pop(void);
  130495. +bool srcfile_pop(void);
  130496. /**
  130497. * Add a new directory to the search path for input files
  130498. @@ -106,12 +107,12 @@
  130499. extern char *srcpos_string(struct srcpos *pos);
  130500. extern void srcpos_dump(struct srcpos *pos);
  130501. -extern void srcpos_verror(struct srcpos *pos, char const *, va_list va)
  130502. - __attribute__((format(printf, 2, 0)));
  130503. -extern void srcpos_error(struct srcpos *pos, char const *, ...)
  130504. - __attribute__((format(printf, 2, 3)));
  130505. -extern void srcpos_warn(struct srcpos *pos, char const *, ...)
  130506. - __attribute__((format(printf, 2, 3)));
  130507. +extern void srcpos_verror(struct srcpos *pos, const char *prefix,
  130508. + const char *fmt, va_list va)
  130509. + __attribute__((format(printf, 3, 0)));
  130510. +extern void srcpos_error(struct srcpos *pos, const char *prefix,
  130511. + const char *fmt, ...)
  130512. + __attribute__((format(printf, 3, 4)));
  130513. extern void srcpos_set_line(char *f, int l);
  130514. diff -Nur linux-3.18.8/scripts/dtc/treesource.c linux-rpi/scripts/dtc/treesource.c
  130515. --- linux-3.18.8/scripts/dtc/treesource.c 2015-02-27 02:49:36.000000000 +0100
  130516. +++ linux-rpi/scripts/dtc/treesource.c 2015-03-05 14:40:18.913715792 +0100
  130517. @@ -26,12 +26,12 @@
  130518. extern YYLTYPE yylloc;
  130519. struct boot_info *the_boot_info;
  130520. -int treesource_error;
  130521. +bool treesource_error;
  130522. struct boot_info *dt_from_source(const char *fname)
  130523. {
  130524. the_boot_info = NULL;
  130525. - treesource_error = 0;
  130526. + treesource_error = false;
  130527. srcfile_push(fname);
  130528. yyin = current_srcfile->f;
  130529. @@ -54,9 +54,9 @@
  130530. fputc('\t', f);
  130531. }
  130532. -static int isstring(char c)
  130533. +static bool isstring(char c)
  130534. {
  130535. - return (isprint(c)
  130536. + return (isprint((unsigned char)c)
  130537. || (c == '\0')
  130538. || strchr("\a\b\t\n\v\f\r", c));
  130539. }
  130540. @@ -109,7 +109,7 @@
  130541. break;
  130542. case '\0':
  130543. fprintf(f, "\", ");
  130544. - while (m && (m->offset < i)) {
  130545. + while (m && (m->offset <= (i + 1))) {
  130546. if (m->type == LABEL) {
  130547. assert(m->offset == (i+1));
  130548. fprintf(f, "%s: ", m->ref);
  130549. @@ -119,7 +119,7 @@
  130550. fprintf(f, "\"");
  130551. break;
  130552. default:
  130553. - if (isprint(c))
  130554. + if (isprint((unsigned char)c))
  130555. fprintf(f, "%c", c);
  130556. else
  130557. fprintf(f, "\\x%02hhx", c);
  130558. @@ -178,7 +178,7 @@
  130559. m = m->next;
  130560. }
  130561. - fprintf(f, "%02hhx", *bp++);
  130562. + fprintf(f, "%02hhx", (unsigned char)(*bp++));
  130563. if ((const void *)bp >= propend)
  130564. break;
  130565. fprintf(f, " ");
  130566. diff -Nur linux-3.18.8/scripts/dtc/util.c linux-rpi/scripts/dtc/util.c
  130567. --- linux-3.18.8/scripts/dtc/util.c 2015-02-27 02:49:36.000000000 +0100
  130568. +++ linux-rpi/scripts/dtc/util.c 2015-03-05 14:40:18.913715792 +0100
  130569. @@ -39,11 +39,11 @@
  130570. char *xstrdup(const char *s)
  130571. {
  130572. int len = strlen(s) + 1;
  130573. - char *dup = xmalloc(len);
  130574. + char *d = xmalloc(len);
  130575. - memcpy(dup, s, len);
  130576. + memcpy(d, s, len);
  130577. - return dup;
  130578. + return d;
  130579. }
  130580. char *join_path(const char *path, const char *name)
  130581. @@ -70,7 +70,7 @@
  130582. return str;
  130583. }
  130584. -int util_is_printable_string(const void *data, int len)
  130585. +bool util_is_printable_string(const void *data, int len)
  130586. {
  130587. const char *s = data;
  130588. const char *ss, *se;
  130589. @@ -87,7 +87,7 @@
  130590. while (s < se) {
  130591. ss = s;
  130592. - while (s < se && *s && isprint(*s))
  130593. + while (s < se && *s && isprint((unsigned char)*s))
  130594. s++;
  130595. /* not zero, or not done yet */
  130596. @@ -219,10 +219,6 @@
  130597. if (offset == bufsize) {
  130598. bufsize *= 2;
  130599. buf = xrealloc(buf, bufsize);
  130600. - if (!buf) {
  130601. - ret = ENOMEM;
  130602. - break;
  130603. - }
  130604. }
  130605. ret = read(fd, &buf[offset], bufsize - offset);
  130606. @@ -375,9 +371,9 @@
  130607. const uint32_t *cell = (const uint32_t *)data;
  130608. printf(" = <");
  130609. - for (i = 0; i < len; i += 4)
  130610. + for (i = 0, len /= 4; i < len; i++)
  130611. printf("0x%08x%s", fdt32_to_cpu(cell[i]),
  130612. - i < (len - 4) ? " " : "");
  130613. + i < (len - 1) ? " " : "");
  130614. printf(">");
  130615. } else {
  130616. printf(" = [");
  130617. diff -Nur linux-3.18.8/scripts/dtc/util.h linux-rpi/scripts/dtc/util.h
  130618. --- linux-3.18.8/scripts/dtc/util.h 2015-02-27 02:49:36.000000000 +0100
  130619. +++ linux-rpi/scripts/dtc/util.h 2015-03-05 14:40:18.913715792 +0100
  130620. @@ -2,6 +2,7 @@
  130621. #define _UTIL_H
  130622. #include <stdarg.h>
  130623. +#include <stdbool.h>
  130624. #include <getopt.h>
  130625. /*
  130626. @@ -33,6 +34,7 @@
  130627. va_start(ap, str);
  130628. fprintf(stderr, "FATAL ERROR: ");
  130629. vfprintf(stderr, str, ap);
  130630. + va_end(ap);
  130631. exit(1);
  130632. }
  130633. @@ -68,7 +70,7 @@
  130634. * @param len The string length including terminator
  130635. * @return 1 if a valid printable string, 0 if not
  130636. */
  130637. -int util_is_printable_string(const void *data, int len);
  130638. +bool util_is_printable_string(const void *data, int len);
  130639. /*
  130640. * Parse an escaped character starting at index i in string s. The resulting
  130641. diff -Nur linux-3.18.8/scripts/dtc/version_gen.h linux-rpi/scripts/dtc/version_gen.h
  130642. --- linux-3.18.8/scripts/dtc/version_gen.h 2015-02-27 02:49:36.000000000 +0100
  130643. +++ linux-rpi/scripts/dtc/version_gen.h 2015-03-05 14:40:18.913715792 +0100
  130644. @@ -1 +1 @@
  130645. -#define DTC_VERSION "DTC 1.4.0-dirty"
  130646. +#define DTC_VERSION "DTC 1.4.1-g36c70742"
  130647. diff -Nur linux-3.18.8/sound/arm/bcm2835.c linux-rpi/sound/arm/bcm2835.c
  130648. --- linux-3.18.8/sound/arm/bcm2835.c 1970-01-01 01:00:00.000000000 +0100
  130649. +++ linux-rpi/sound/arm/bcm2835.c 2015-03-05 14:40:19.021715791 +0100
  130650. @@ -0,0 +1,420 @@
  130651. +/*****************************************************************************
  130652. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  130653. +*
  130654. +* Unless you and Broadcom execute a separate written software license
  130655. +* agreement governing use of this software, this software is licensed to you
  130656. +* under the terms of the GNU General Public License version 2, available at
  130657. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  130658. +*
  130659. +* Notwithstanding the above, under no circumstances may you combine this
  130660. +* software in any way with any other Broadcom software provided under a
  130661. +* license other than the GPL, without Broadcom's express prior written
  130662. +* consent.
  130663. +*****************************************************************************/
  130664. +
  130665. +#include <linux/platform_device.h>
  130666. +
  130667. +#include <linux/init.h>
  130668. +#include <linux/slab.h>
  130669. +#include <linux/module.h>
  130670. +
  130671. +#include "bcm2835.h"
  130672. +
  130673. +/* module parameters (see "Module Parameters") */
  130674. +/* SNDRV_CARDS: maximum number of cards supported by this module */
  130675. +static int index[MAX_SUBSTREAMS] = {[0 ... (MAX_SUBSTREAMS - 1)] = -1 };
  130676. +static char *id[MAX_SUBSTREAMS] = {[0 ... (MAX_SUBSTREAMS - 1)] = NULL };
  130677. +static int enable[MAX_SUBSTREAMS] = {[0 ... (MAX_SUBSTREAMS - 1)] = 1 };
  130678. +
  130679. +/* HACKY global pointers needed for successive probes to work : ssp
  130680. + * But compared against the changes we will have to do in VC audio_ipc code
  130681. + * to export 8 audio_ipc devices as a single IPC device and then monitor all
  130682. + * four devices in a thread, this gets things done quickly and should be easier
  130683. + * to debug if we run into issues
  130684. + */
  130685. +
  130686. +static struct snd_card *g_card = NULL;
  130687. +static bcm2835_chip_t *g_chip = NULL;
  130688. +
  130689. +static int snd_bcm2835_free(bcm2835_chip_t * chip)
  130690. +{
  130691. + kfree(chip);
  130692. + return 0;
  130693. +}
  130694. +
  130695. +/* component-destructor
  130696. + * (see "Management of Cards and Components")
  130697. + */
  130698. +static int snd_bcm2835_dev_free(struct snd_device *device)
  130699. +{
  130700. + return snd_bcm2835_free(device->device_data);
  130701. +}
  130702. +
  130703. +/* chip-specific constructor
  130704. + * (see "Management of Cards and Components")
  130705. + */
  130706. +static int snd_bcm2835_create(struct snd_card *card,
  130707. + struct platform_device *pdev,
  130708. + bcm2835_chip_t ** rchip)
  130709. +{
  130710. + bcm2835_chip_t *chip;
  130711. + int err;
  130712. + static struct snd_device_ops ops = {
  130713. + .dev_free = snd_bcm2835_dev_free,
  130714. + };
  130715. +
  130716. + *rchip = NULL;
  130717. +
  130718. + chip = kzalloc(sizeof(*chip), GFP_KERNEL);
  130719. + if (chip == NULL)
  130720. + return -ENOMEM;
  130721. +
  130722. + chip->card = card;
  130723. +
  130724. + err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
  130725. + if (err < 0) {
  130726. + snd_bcm2835_free(chip);
  130727. + return err;
  130728. + }
  130729. +
  130730. + *rchip = chip;
  130731. + return 0;
  130732. +}
  130733. +
  130734. +static int snd_bcm2835_alsa_probe(struct platform_device *pdev)
  130735. +{
  130736. + static int dev;
  130737. + bcm2835_chip_t *chip;
  130738. + struct snd_card *card;
  130739. + int err;
  130740. +
  130741. + if (dev >= MAX_SUBSTREAMS)
  130742. + return -ENODEV;
  130743. +
  130744. + if (!enable[dev]) {
  130745. + dev++;
  130746. + return -ENOENT;
  130747. + }
  130748. +
  130749. + if (dev > 0)
  130750. + goto add_register_map;
  130751. +
  130752. + err = snd_card_new(NULL, index[dev], id[dev], THIS_MODULE, 0, &g_card);
  130753. + if (err < 0)
  130754. + goto out;
  130755. +
  130756. + snd_card_set_dev(g_card, &pdev->dev);
  130757. + strcpy(g_card->driver, "bcm2835");
  130758. + strcpy(g_card->shortname, "bcm2835 ALSA");
  130759. + sprintf(g_card->longname, "%s", g_card->shortname);
  130760. +
  130761. + err = snd_bcm2835_create(g_card, pdev, &chip);
  130762. + if (err < 0) {
  130763. + dev_err(&pdev->dev, "Failed to create bcm2835 chip\n");
  130764. + goto out_bcm2835_create;
  130765. + }
  130766. +
  130767. + g_chip = chip;
  130768. + err = snd_bcm2835_new_pcm(chip);
  130769. + if (err < 0) {
  130770. + dev_err(&pdev->dev, "Failed to create new BCM2835 pcm device\n");
  130771. + goto out_bcm2835_new_pcm;
  130772. + }
  130773. +
  130774. + err = snd_bcm2835_new_spdif_pcm(chip);
  130775. + if (err < 0) {
  130776. + dev_err(&pdev->dev, "Failed to create new BCM2835 spdif pcm device\n");
  130777. + goto out_bcm2835_new_spdif;
  130778. + }
  130779. +
  130780. + err = snd_bcm2835_new_ctl(chip);
  130781. + if (err < 0) {
  130782. + dev_err(&pdev->dev, "Failed to create new BCM2835 ctl\n");
  130783. + goto out_bcm2835_new_ctl;
  130784. + }
  130785. +
  130786. +add_register_map:
  130787. + card = g_card;
  130788. + chip = g_chip;
  130789. +
  130790. + BUG_ON(!(card && chip));
  130791. +
  130792. + chip->avail_substreams |= (1 << dev);
  130793. + chip->pdev[dev] = pdev;
  130794. +
  130795. + if (dev == 0) {
  130796. + err = snd_card_register(card);
  130797. + if (err < 0) {
  130798. + dev_err(&pdev->dev,
  130799. + "Failed to register bcm2835 ALSA card \n");
  130800. + goto out_card_register;
  130801. + }
  130802. + platform_set_drvdata(pdev, card);
  130803. + audio_info("bcm2835 ALSA card created!\n");
  130804. + } else {
  130805. + audio_info("bcm2835 ALSA chip created!\n");
  130806. + platform_set_drvdata(pdev, (void *)dev);
  130807. + }
  130808. +
  130809. + dev++;
  130810. +
  130811. + return 0;
  130812. +
  130813. +out_card_register:
  130814. +out_bcm2835_new_ctl:
  130815. +out_bcm2835_new_spdif:
  130816. +out_bcm2835_new_pcm:
  130817. +out_bcm2835_create:
  130818. + BUG_ON(!g_card);
  130819. + if (snd_card_free(g_card))
  130820. + dev_err(&pdev->dev, "Failed to free Registered alsa card\n");
  130821. + g_card = NULL;
  130822. +out:
  130823. + dev = SNDRV_CARDS; /* stop more avail_substreams from being probed */
  130824. + dev_err(&pdev->dev, "BCM2835 ALSA Probe failed !!\n");
  130825. + return err;
  130826. +}
  130827. +
  130828. +static int snd_bcm2835_alsa_remove(struct platform_device *pdev)
  130829. +{
  130830. + uint32_t idx;
  130831. + void *drv_data;
  130832. +
  130833. + drv_data = platform_get_drvdata(pdev);
  130834. +
  130835. + if (drv_data == (void *)g_card) {
  130836. + /* This is the card device */
  130837. + snd_card_free((struct snd_card *)drv_data);
  130838. + g_card = NULL;
  130839. + g_chip = NULL;
  130840. + } else {
  130841. + idx = (uint32_t) drv_data;
  130842. + if (g_card != NULL) {
  130843. + BUG_ON(!g_chip);
  130844. + /* We pass chip device numbers in audio ipc devices
  130845. + * other than the one we registered our card with
  130846. + */
  130847. + idx = (uint32_t) drv_data;
  130848. + BUG_ON(!idx || idx > MAX_SUBSTREAMS);
  130849. + g_chip->avail_substreams &= ~(1 << idx);
  130850. + /* There should be atleast one substream registered
  130851. + * after we are done here, as it wil be removed when
  130852. + * the *remove* is called for the card device
  130853. + */
  130854. + BUG_ON(!g_chip->avail_substreams);
  130855. + }
  130856. + }
  130857. +
  130858. + platform_set_drvdata(pdev, NULL);
  130859. +
  130860. + return 0;
  130861. +}
  130862. +
  130863. +#ifdef CONFIG_PM
  130864. +static int snd_bcm2835_alsa_suspend(struct platform_device *pdev,
  130865. + pm_message_t state)
  130866. +{
  130867. + return 0;
  130868. +}
  130869. +
  130870. +static int snd_bcm2835_alsa_resume(struct platform_device *pdev)
  130871. +{
  130872. + return 0;
  130873. +}
  130874. +
  130875. +#endif
  130876. +
  130877. +static struct platform_driver bcm2835_alsa0_driver = {
  130878. + .probe = snd_bcm2835_alsa_probe,
  130879. + .remove = snd_bcm2835_alsa_remove,
  130880. +#ifdef CONFIG_PM
  130881. + .suspend = snd_bcm2835_alsa_suspend,
  130882. + .resume = snd_bcm2835_alsa_resume,
  130883. +#endif
  130884. + .driver = {
  130885. + .name = "bcm2835_AUD0",
  130886. + .owner = THIS_MODULE,
  130887. + },
  130888. +};
  130889. +
  130890. +static struct platform_driver bcm2835_alsa1_driver = {
  130891. + .probe = snd_bcm2835_alsa_probe,
  130892. + .remove = snd_bcm2835_alsa_remove,
  130893. +#ifdef CONFIG_PM
  130894. + .suspend = snd_bcm2835_alsa_suspend,
  130895. + .resume = snd_bcm2835_alsa_resume,
  130896. +#endif
  130897. + .driver = {
  130898. + .name = "bcm2835_AUD1",
  130899. + .owner = THIS_MODULE,
  130900. + },
  130901. +};
  130902. +
  130903. +static struct platform_driver bcm2835_alsa2_driver = {
  130904. + .probe = snd_bcm2835_alsa_probe,
  130905. + .remove = snd_bcm2835_alsa_remove,
  130906. +#ifdef CONFIG_PM
  130907. + .suspend = snd_bcm2835_alsa_suspend,
  130908. + .resume = snd_bcm2835_alsa_resume,
  130909. +#endif
  130910. + .driver = {
  130911. + .name = "bcm2835_AUD2",
  130912. + .owner = THIS_MODULE,
  130913. + },
  130914. +};
  130915. +
  130916. +static struct platform_driver bcm2835_alsa3_driver = {
  130917. + .probe = snd_bcm2835_alsa_probe,
  130918. + .remove = snd_bcm2835_alsa_remove,
  130919. +#ifdef CONFIG_PM
  130920. + .suspend = snd_bcm2835_alsa_suspend,
  130921. + .resume = snd_bcm2835_alsa_resume,
  130922. +#endif
  130923. + .driver = {
  130924. + .name = "bcm2835_AUD3",
  130925. + .owner = THIS_MODULE,
  130926. + },
  130927. +};
  130928. +
  130929. +static struct platform_driver bcm2835_alsa4_driver = {
  130930. + .probe = snd_bcm2835_alsa_probe,
  130931. + .remove = snd_bcm2835_alsa_remove,
  130932. +#ifdef CONFIG_PM
  130933. + .suspend = snd_bcm2835_alsa_suspend,
  130934. + .resume = snd_bcm2835_alsa_resume,
  130935. +#endif
  130936. + .driver = {
  130937. + .name = "bcm2835_AUD4",
  130938. + .owner = THIS_MODULE,
  130939. + },
  130940. +};
  130941. +
  130942. +static struct platform_driver bcm2835_alsa5_driver = {
  130943. + .probe = snd_bcm2835_alsa_probe,
  130944. + .remove = snd_bcm2835_alsa_remove,
  130945. +#ifdef CONFIG_PM
  130946. + .suspend = snd_bcm2835_alsa_suspend,
  130947. + .resume = snd_bcm2835_alsa_resume,
  130948. +#endif
  130949. + .driver = {
  130950. + .name = "bcm2835_AUD5",
  130951. + .owner = THIS_MODULE,
  130952. + },
  130953. +};
  130954. +
  130955. +static struct platform_driver bcm2835_alsa6_driver = {
  130956. + .probe = snd_bcm2835_alsa_probe,
  130957. + .remove = snd_bcm2835_alsa_remove,
  130958. +#ifdef CONFIG_PM
  130959. + .suspend = snd_bcm2835_alsa_suspend,
  130960. + .resume = snd_bcm2835_alsa_resume,
  130961. +#endif
  130962. + .driver = {
  130963. + .name = "bcm2835_AUD6",
  130964. + .owner = THIS_MODULE,
  130965. + },
  130966. +};
  130967. +
  130968. +static struct platform_driver bcm2835_alsa7_driver = {
  130969. + .probe = snd_bcm2835_alsa_probe,
  130970. + .remove = snd_bcm2835_alsa_remove,
  130971. +#ifdef CONFIG_PM
  130972. + .suspend = snd_bcm2835_alsa_suspend,
  130973. + .resume = snd_bcm2835_alsa_resume,
  130974. +#endif
  130975. + .driver = {
  130976. + .name = "bcm2835_AUD7",
  130977. + .owner = THIS_MODULE,
  130978. + },
  130979. +};
  130980. +
  130981. +static int bcm2835_alsa_device_init(void)
  130982. +{
  130983. + int err;
  130984. + err = platform_driver_register(&bcm2835_alsa0_driver);
  130985. + if (err) {
  130986. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  130987. + goto out;
  130988. + }
  130989. +
  130990. + err = platform_driver_register(&bcm2835_alsa1_driver);
  130991. + if (err) {
  130992. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  130993. + goto unregister_0;
  130994. + }
  130995. +
  130996. + err = platform_driver_register(&bcm2835_alsa2_driver);
  130997. + if (err) {
  130998. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  130999. + goto unregister_1;
  131000. + }
  131001. +
  131002. + err = platform_driver_register(&bcm2835_alsa3_driver);
  131003. + if (err) {
  131004. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  131005. + goto unregister_2;
  131006. + }
  131007. +
  131008. + err = platform_driver_register(&bcm2835_alsa4_driver);
  131009. + if (err) {
  131010. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  131011. + goto unregister_3;
  131012. + }
  131013. +
  131014. + err = platform_driver_register(&bcm2835_alsa5_driver);
  131015. + if (err) {
  131016. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  131017. + goto unregister_4;
  131018. + }
  131019. +
  131020. + err = platform_driver_register(&bcm2835_alsa6_driver);
  131021. + if (err) {
  131022. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  131023. + goto unregister_5;
  131024. + }
  131025. +
  131026. + err = platform_driver_register(&bcm2835_alsa7_driver);
  131027. + if (err) {
  131028. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  131029. + goto unregister_6;
  131030. + }
  131031. +
  131032. + return 0;
  131033. +
  131034. +unregister_6:
  131035. + platform_driver_unregister(&bcm2835_alsa6_driver);
  131036. +unregister_5:
  131037. + platform_driver_unregister(&bcm2835_alsa5_driver);
  131038. +unregister_4:
  131039. + platform_driver_unregister(&bcm2835_alsa4_driver);
  131040. +unregister_3:
  131041. + platform_driver_unregister(&bcm2835_alsa3_driver);
  131042. +unregister_2:
  131043. + platform_driver_unregister(&bcm2835_alsa2_driver);
  131044. +unregister_1:
  131045. + platform_driver_unregister(&bcm2835_alsa1_driver);
  131046. +unregister_0:
  131047. + platform_driver_unregister(&bcm2835_alsa0_driver);
  131048. +out:
  131049. + return err;
  131050. +}
  131051. +
  131052. +static void bcm2835_alsa_device_exit(void)
  131053. +{
  131054. + platform_driver_unregister(&bcm2835_alsa0_driver);
  131055. + platform_driver_unregister(&bcm2835_alsa1_driver);
  131056. + platform_driver_unregister(&bcm2835_alsa2_driver);
  131057. + platform_driver_unregister(&bcm2835_alsa3_driver);
  131058. + platform_driver_unregister(&bcm2835_alsa4_driver);
  131059. + platform_driver_unregister(&bcm2835_alsa5_driver);
  131060. + platform_driver_unregister(&bcm2835_alsa6_driver);
  131061. + platform_driver_unregister(&bcm2835_alsa7_driver);
  131062. +}
  131063. +
  131064. +late_initcall(bcm2835_alsa_device_init);
  131065. +module_exit(bcm2835_alsa_device_exit);
  131066. +
  131067. +MODULE_AUTHOR("Dom Cobley");
  131068. +MODULE_DESCRIPTION("Alsa driver for BCM2835 chip");
  131069. +MODULE_LICENSE("GPL");
  131070. +MODULE_ALIAS("platform:bcm2835_alsa");
  131071. diff -Nur linux-3.18.8/sound/arm/bcm2835-ctl.c linux-rpi/sound/arm/bcm2835-ctl.c
  131072. --- linux-3.18.8/sound/arm/bcm2835-ctl.c 1970-01-01 01:00:00.000000000 +0100
  131073. +++ linux-rpi/sound/arm/bcm2835-ctl.c 2015-03-05 14:40:19.021715791 +0100
  131074. @@ -0,0 +1,323 @@
  131075. +/*****************************************************************************
  131076. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  131077. +*
  131078. +* Unless you and Broadcom execute a separate written software license
  131079. +* agreement governing use of this software, this software is licensed to you
  131080. +* under the terms of the GNU General Public License version 2, available at
  131081. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  131082. +*
  131083. +* Notwithstanding the above, under no circumstances may you combine this
  131084. +* software in any way with any other Broadcom software provided under a
  131085. +* license other than the GPL, without Broadcom's express prior written
  131086. +* consent.
  131087. +*****************************************************************************/
  131088. +
  131089. +#include <linux/platform_device.h>
  131090. +#include <linux/init.h>
  131091. +#include <linux/io.h>
  131092. +#include <linux/jiffies.h>
  131093. +#include <linux/slab.h>
  131094. +#include <linux/time.h>
  131095. +#include <linux/wait.h>
  131096. +#include <linux/delay.h>
  131097. +#include <linux/moduleparam.h>
  131098. +#include <linux/sched.h>
  131099. +
  131100. +#include <sound/core.h>
  131101. +#include <sound/control.h>
  131102. +#include <sound/pcm.h>
  131103. +#include <sound/pcm_params.h>
  131104. +#include <sound/rawmidi.h>
  131105. +#include <sound/initval.h>
  131106. +#include <sound/tlv.h>
  131107. +#include <sound/asoundef.h>
  131108. +
  131109. +#include "bcm2835.h"
  131110. +
  131111. +/* volume maximum and minimum in terms of 0.01dB */
  131112. +#define CTRL_VOL_MAX 400
  131113. +#define CTRL_VOL_MIN -10239 /* originally -10240 */
  131114. +
  131115. +
  131116. +static int snd_bcm2835_ctl_info(struct snd_kcontrol *kcontrol,
  131117. + struct snd_ctl_elem_info *uinfo)
  131118. +{
  131119. + audio_info(" ... IN\n");
  131120. + if (kcontrol->private_value == PCM_PLAYBACK_VOLUME) {
  131121. + uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  131122. + uinfo->count = 1;
  131123. + uinfo->value.integer.min = CTRL_VOL_MIN;
  131124. + uinfo->value.integer.max = CTRL_VOL_MAX; /* 2303 */
  131125. + } else if (kcontrol->private_value == PCM_PLAYBACK_MUTE) {
  131126. + uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  131127. + uinfo->count = 1;
  131128. + uinfo->value.integer.min = 0;
  131129. + uinfo->value.integer.max = 1;
  131130. + } else if (kcontrol->private_value == PCM_PLAYBACK_DEVICE) {
  131131. + uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  131132. + uinfo->count = 1;
  131133. + uinfo->value.integer.min = 0;
  131134. + uinfo->value.integer.max = AUDIO_DEST_MAX-1;
  131135. + }
  131136. + audio_info(" ... OUT\n");
  131137. + return 0;
  131138. +}
  131139. +
  131140. +/* toggles mute on or off depending on the value of nmute, and returns
  131141. + * 1 if the mute value was changed, otherwise 0
  131142. + */
  131143. +static int toggle_mute(struct bcm2835_chip *chip, int nmute)
  131144. +{
  131145. + /* if settings are ok, just return 0 */
  131146. + if(chip->mute == nmute)
  131147. + return 0;
  131148. +
  131149. + /* if the sound is muted then we need to unmute */
  131150. + if(chip->mute == CTRL_VOL_MUTE)
  131151. + {
  131152. + chip->volume = chip->old_volume; /* copy the old volume back */
  131153. + audio_info("Unmuting, old_volume = %d, volume = %d ...\n", chip->old_volume, chip->volume);
  131154. + }
  131155. + else /* otherwise we mute */
  131156. + {
  131157. + chip->old_volume = chip->volume;
  131158. + chip->volume = 26214; /* set volume to minimum level AKA mute */
  131159. + audio_info("Muting, old_volume = %d, volume = %d ...\n", chip->old_volume, chip->volume);
  131160. + }
  131161. +
  131162. + chip->mute = nmute;
  131163. + return 1;
  131164. +}
  131165. +
  131166. +static int snd_bcm2835_ctl_get(struct snd_kcontrol *kcontrol,
  131167. + struct snd_ctl_elem_value *ucontrol)
  131168. +{
  131169. + struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
  131170. +
  131171. + BUG_ON(!chip && !(chip->avail_substreams & AVAIL_SUBSTREAMS_MASK));
  131172. +
  131173. + if (kcontrol->private_value == PCM_PLAYBACK_VOLUME)
  131174. + ucontrol->value.integer.value[0] = chip2alsa(chip->volume);
  131175. + else if (kcontrol->private_value == PCM_PLAYBACK_MUTE)
  131176. + ucontrol->value.integer.value[0] = chip->mute;
  131177. + else if (kcontrol->private_value == PCM_PLAYBACK_DEVICE)
  131178. + ucontrol->value.integer.value[0] = chip->dest;
  131179. +
  131180. + return 0;
  131181. +}
  131182. +
  131183. +static int snd_bcm2835_ctl_put(struct snd_kcontrol *kcontrol,
  131184. + struct snd_ctl_elem_value *ucontrol)
  131185. +{
  131186. + struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
  131187. + int changed = 0;
  131188. +
  131189. + if (kcontrol->private_value == PCM_PLAYBACK_VOLUME) {
  131190. + audio_info("Volume change attempted.. volume = %d new_volume = %d\n", chip->volume, (int)ucontrol->value.integer.value[0]);
  131191. + if (chip->mute == CTRL_VOL_MUTE) {
  131192. + /* changed = toggle_mute(chip, CTRL_VOL_UNMUTE); */
  131193. + return 1; /* should return 0 to signify no change but the mixer takes this as the opposite sign (no idea why) */
  131194. + }
  131195. + if (changed
  131196. + || (ucontrol->value.integer.value[0] != chip2alsa(chip->volume))) {
  131197. +
  131198. + chip->volume = alsa2chip(ucontrol->value.integer.value[0]);
  131199. + changed = 1;
  131200. + }
  131201. +
  131202. + } else if (kcontrol->private_value == PCM_PLAYBACK_MUTE) {
  131203. + /* Now implemented */
  131204. + audio_info(" Mute attempted\n");
  131205. + changed = toggle_mute(chip, ucontrol->value.integer.value[0]);
  131206. +
  131207. + } else if (kcontrol->private_value == PCM_PLAYBACK_DEVICE) {
  131208. + if (ucontrol->value.integer.value[0] != chip->dest) {
  131209. + chip->dest = ucontrol->value.integer.value[0];
  131210. + changed = 1;
  131211. + }
  131212. + }
  131213. +
  131214. + if (changed) {
  131215. + if (bcm2835_audio_set_ctls(chip))
  131216. + printk(KERN_ERR "Failed to set ALSA controls..\n");
  131217. + }
  131218. +
  131219. + return changed;
  131220. +}
  131221. +
  131222. +static DECLARE_TLV_DB_SCALE(snd_bcm2835_db_scale, CTRL_VOL_MIN, 1, 1);
  131223. +
  131224. +static struct snd_kcontrol_new snd_bcm2835_ctl[] = {
  131225. + {
  131226. + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  131227. + .name = "PCM Playback Volume",
  131228. + .index = 0,
  131229. + .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ,
  131230. + .private_value = PCM_PLAYBACK_VOLUME,
  131231. + .info = snd_bcm2835_ctl_info,
  131232. + .get = snd_bcm2835_ctl_get,
  131233. + .put = snd_bcm2835_ctl_put,
  131234. + .count = 1,
  131235. + .tlv = {.p = snd_bcm2835_db_scale}
  131236. + },
  131237. + {
  131238. + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  131239. + .name = "PCM Playback Switch",
  131240. + .index = 0,
  131241. + .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  131242. + .private_value = PCM_PLAYBACK_MUTE,
  131243. + .info = snd_bcm2835_ctl_info,
  131244. + .get = snd_bcm2835_ctl_get,
  131245. + .put = snd_bcm2835_ctl_put,
  131246. + .count = 1,
  131247. + },
  131248. + {
  131249. + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  131250. + .name = "PCM Playback Route",
  131251. + .index = 0,
  131252. + .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  131253. + .private_value = PCM_PLAYBACK_DEVICE,
  131254. + .info = snd_bcm2835_ctl_info,
  131255. + .get = snd_bcm2835_ctl_get,
  131256. + .put = snd_bcm2835_ctl_put,
  131257. + .count = 1,
  131258. + },
  131259. +};
  131260. +
  131261. +static int snd_bcm2835_spdif_default_info(struct snd_kcontrol *kcontrol,
  131262. + struct snd_ctl_elem_info *uinfo)
  131263. +{
  131264. + uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
  131265. + uinfo->count = 1;
  131266. + return 0;
  131267. +}
  131268. +
  131269. +static int snd_bcm2835_spdif_default_get(struct snd_kcontrol *kcontrol,
  131270. + struct snd_ctl_elem_value *ucontrol)
  131271. +{
  131272. + struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
  131273. + int i;
  131274. +
  131275. + for (i = 0; i < 4; i++)
  131276. + ucontrol->value.iec958.status[i] =
  131277. + (chip->spdif_status >> (i * 8)) && 0xff;
  131278. +
  131279. + return 0;
  131280. +}
  131281. +
  131282. +static int snd_bcm2835_spdif_default_put(struct snd_kcontrol *kcontrol,
  131283. + struct snd_ctl_elem_value *ucontrol)
  131284. +{
  131285. + struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
  131286. + unsigned int val = 0;
  131287. + int i, change;
  131288. +
  131289. + for (i = 0; i < 4; i++)
  131290. + val |= (unsigned int)ucontrol->value.iec958.status[i] << (i * 8);
  131291. +
  131292. + change = val != chip->spdif_status;
  131293. + chip->spdif_status = val;
  131294. +
  131295. + return change;
  131296. +}
  131297. +
  131298. +static int snd_bcm2835_spdif_mask_info(struct snd_kcontrol *kcontrol,
  131299. + struct snd_ctl_elem_info *uinfo)
  131300. +{
  131301. + uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
  131302. + uinfo->count = 1;
  131303. + return 0;
  131304. +}
  131305. +
  131306. +static int snd_bcm2835_spdif_mask_get(struct snd_kcontrol *kcontrol,
  131307. + struct snd_ctl_elem_value *ucontrol)
  131308. +{
  131309. + /* bcm2835 supports only consumer mode and sets all other format flags
  131310. + * automatically. So the only thing left is signalling non-audio
  131311. + * content */
  131312. + ucontrol->value.iec958.status[0] = IEC958_AES0_NONAUDIO;
  131313. + return 0;
  131314. +}
  131315. +
  131316. +static int snd_bcm2835_spdif_stream_info(struct snd_kcontrol *kcontrol,
  131317. + struct snd_ctl_elem_info *uinfo)
  131318. +{
  131319. + uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
  131320. + uinfo->count = 1;
  131321. + return 0;
  131322. +}
  131323. +
  131324. +static int snd_bcm2835_spdif_stream_get(struct snd_kcontrol *kcontrol,
  131325. + struct snd_ctl_elem_value *ucontrol)
  131326. +{
  131327. + struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
  131328. + int i;
  131329. +
  131330. + for (i = 0; i < 4; i++)
  131331. + ucontrol->value.iec958.status[i] =
  131332. + (chip->spdif_status >> (i * 8)) & 0xff;
  131333. + return 0;
  131334. +}
  131335. +
  131336. +static int snd_bcm2835_spdif_stream_put(struct snd_kcontrol *kcontrol,
  131337. + struct snd_ctl_elem_value *ucontrol)
  131338. +{
  131339. + struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
  131340. + unsigned int val = 0;
  131341. + int i, change;
  131342. +
  131343. + for (i = 0; i < 4; i++)
  131344. + val |= (unsigned int)ucontrol->value.iec958.status[i] << (i * 8);
  131345. + change = val != chip->spdif_status;
  131346. + chip->spdif_status = val;
  131347. +
  131348. + return change;
  131349. +}
  131350. +
  131351. +static struct snd_kcontrol_new snd_bcm2835_spdif[] = {
  131352. + {
  131353. + .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  131354. + .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT),
  131355. + .info = snd_bcm2835_spdif_default_info,
  131356. + .get = snd_bcm2835_spdif_default_get,
  131357. + .put = snd_bcm2835_spdif_default_put
  131358. + },
  131359. + {
  131360. + .access = SNDRV_CTL_ELEM_ACCESS_READ,
  131361. + .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  131362. + .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, CON_MASK),
  131363. + .info = snd_bcm2835_spdif_mask_info,
  131364. + .get = snd_bcm2835_spdif_mask_get,
  131365. + },
  131366. + {
  131367. + .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
  131368. + SNDRV_CTL_ELEM_ACCESS_INACTIVE,
  131369. + .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  131370. + .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, PCM_STREAM),
  131371. + .info = snd_bcm2835_spdif_stream_info,
  131372. + .get = snd_bcm2835_spdif_stream_get,
  131373. + .put = snd_bcm2835_spdif_stream_put,
  131374. + },
  131375. +};
  131376. +
  131377. +int snd_bcm2835_new_ctl(bcm2835_chip_t * chip)
  131378. +{
  131379. + int err;
  131380. + unsigned int idx;
  131381. +
  131382. + strcpy(chip->card->mixername, "Broadcom Mixer");
  131383. + for (idx = 0; idx < ARRAY_SIZE(snd_bcm2835_ctl); idx++) {
  131384. + err =
  131385. + snd_ctl_add(chip->card,
  131386. + snd_ctl_new1(&snd_bcm2835_ctl[idx], chip));
  131387. + if (err < 0)
  131388. + return err;
  131389. + }
  131390. + for (idx = 0; idx < ARRAY_SIZE(snd_bcm2835_spdif); idx++) {
  131391. + err = snd_ctl_add(chip->card,
  131392. + snd_ctl_new1(&snd_bcm2835_spdif[idx], chip));
  131393. + if (err < 0)
  131394. + return err;
  131395. + }
  131396. + return 0;
  131397. +}
  131398. diff -Nur linux-3.18.8/sound/arm/bcm2835.h linux-rpi/sound/arm/bcm2835.h
  131399. --- linux-3.18.8/sound/arm/bcm2835.h 1970-01-01 01:00:00.000000000 +0100
  131400. +++ linux-rpi/sound/arm/bcm2835.h 2015-03-05 14:40:19.021715791 +0100
  131401. @@ -0,0 +1,167 @@
  131402. +/*****************************************************************************
  131403. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  131404. +*
  131405. +* Unless you and Broadcom execute a separate written software license
  131406. +* agreement governing use of this software, this software is licensed to you
  131407. +* under the terms of the GNU General Public License version 2, available at
  131408. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  131409. +*
  131410. +* Notwithstanding the above, under no circumstances may you combine this
  131411. +* software in any way with any other Broadcom software provided under a
  131412. +* license other than the GPL, without Broadcom's express prior written
  131413. +* consent.
  131414. +*****************************************************************************/
  131415. +
  131416. +#ifndef __SOUND_ARM_BCM2835_H
  131417. +#define __SOUND_ARM_BCM2835_H
  131418. +
  131419. +#include <linux/device.h>
  131420. +#include <linux/list.h>
  131421. +#include <linux/interrupt.h>
  131422. +#include <linux/wait.h>
  131423. +#include <sound/core.h>
  131424. +#include <sound/initval.h>
  131425. +#include <sound/pcm.h>
  131426. +#include <sound/pcm_params.h>
  131427. +#include <sound/pcm-indirect.h>
  131428. +#include <linux/workqueue.h>
  131429. +
  131430. +/*
  131431. +#define AUDIO_DEBUG_ENABLE
  131432. +#define AUDIO_VERBOSE_DEBUG_ENABLE
  131433. +*/
  131434. +
  131435. +/* Debug macros */
  131436. +
  131437. +#ifdef AUDIO_DEBUG_ENABLE
  131438. +#ifdef AUDIO_VERBOSE_DEBUG_ENABLE
  131439. +
  131440. +#define audio_debug(fmt, arg...) \
  131441. + printk(KERN_INFO"%s:%d " fmt, __func__, __LINE__, ##arg)
  131442. +
  131443. +#define audio_info(fmt, arg...) \
  131444. + printk(KERN_INFO"%s:%d " fmt, __func__, __LINE__, ##arg)
  131445. +
  131446. +#else
  131447. +
  131448. +#define audio_debug(fmt, arg...)
  131449. +
  131450. +#define audio_info(fmt, arg...)
  131451. +
  131452. +#endif /* AUDIO_VERBOSE_DEBUG_ENABLE */
  131453. +
  131454. +#else
  131455. +
  131456. +#define audio_debug(fmt, arg...)
  131457. +
  131458. +#define audio_info(fmt, arg...)
  131459. +
  131460. +#endif /* AUDIO_DEBUG_ENABLE */
  131461. +
  131462. +#define audio_error(fmt, arg...) \
  131463. + printk(KERN_ERR"%s:%d " fmt, __func__, __LINE__, ##arg)
  131464. +
  131465. +#define audio_warning(fmt, arg...) \
  131466. + printk(KERN_WARNING"%s:%d " fmt, __func__, __LINE__, ##arg)
  131467. +
  131468. +#define audio_alert(fmt, arg...) \
  131469. + printk(KERN_ALERT"%s:%d " fmt, __func__, __LINE__, ##arg)
  131470. +
  131471. +#define MAX_SUBSTREAMS (8)
  131472. +#define AVAIL_SUBSTREAMS_MASK (0xff)
  131473. +enum {
  131474. + CTRL_VOL_MUTE,
  131475. + CTRL_VOL_UNMUTE
  131476. +};
  131477. +
  131478. +/* macros for alsa2chip and chip2alsa, instead of functions */
  131479. +
  131480. +#define alsa2chip(vol) (uint)(-((vol << 8) / 100)) /* convert alsa to chip volume (defined as macro rather than function call) */
  131481. +#define chip2alsa(vol) -((vol * 100) >> 8) /* convert chip to alsa volume */
  131482. +
  131483. +/* Some constants for values .. */
  131484. +typedef enum {
  131485. + AUDIO_DEST_AUTO = 0,
  131486. + AUDIO_DEST_HEADPHONES = 1,
  131487. + AUDIO_DEST_HDMI = 2,
  131488. + AUDIO_DEST_MAX,
  131489. +} SND_BCM2835_ROUTE_T;
  131490. +
  131491. +typedef enum {
  131492. + PCM_PLAYBACK_VOLUME,
  131493. + PCM_PLAYBACK_MUTE,
  131494. + PCM_PLAYBACK_DEVICE,
  131495. +} SND_BCM2835_CTRL_T;
  131496. +
  131497. +/* definition of the chip-specific record */
  131498. +typedef struct bcm2835_chip {
  131499. + struct snd_card *card;
  131500. + struct snd_pcm *pcm;
  131501. + struct snd_pcm *pcm_spdif;
  131502. + /* Bitmat for valid reg_base and irq numbers */
  131503. + uint32_t avail_substreams;
  131504. + struct platform_device *pdev[MAX_SUBSTREAMS];
  131505. + struct bcm2835_alsa_stream *alsa_stream[MAX_SUBSTREAMS];
  131506. +
  131507. + int volume;
  131508. + int old_volume; /* stores the volume value whist muted */
  131509. + int dest;
  131510. + int mute;
  131511. +
  131512. + unsigned int opened;
  131513. + unsigned int spdif_status;
  131514. + struct mutex audio_mutex;
  131515. +} bcm2835_chip_t;
  131516. +
  131517. +typedef struct bcm2835_alsa_stream {
  131518. + bcm2835_chip_t *chip;
  131519. + struct snd_pcm_substream *substream;
  131520. + struct snd_pcm_indirect pcm_indirect;
  131521. +
  131522. + struct semaphore buffers_update_sem;
  131523. + struct semaphore control_sem;
  131524. + spinlock_t lock;
  131525. + volatile uint32_t control;
  131526. + volatile uint32_t status;
  131527. +
  131528. + int open;
  131529. + int running;
  131530. + int draining;
  131531. +
  131532. + int channels;
  131533. + int params_rate;
  131534. + int pcm_format_width;
  131535. +
  131536. + unsigned int pos;
  131537. + unsigned int buffer_size;
  131538. + unsigned int period_size;
  131539. +
  131540. + uint32_t enable_fifo_irq;
  131541. + irq_handler_t fifo_irq_handler;
  131542. +
  131543. + atomic_t retrieved;
  131544. + struct opaque_AUDIO_INSTANCE_T *instance;
  131545. + struct workqueue_struct *my_wq;
  131546. + int idx;
  131547. +} bcm2835_alsa_stream_t;
  131548. +
  131549. +int snd_bcm2835_new_ctl(bcm2835_chip_t * chip);
  131550. +int snd_bcm2835_new_pcm(bcm2835_chip_t * chip);
  131551. +int snd_bcm2835_new_spdif_pcm(bcm2835_chip_t * chip);
  131552. +
  131553. +int bcm2835_audio_open(bcm2835_alsa_stream_t * alsa_stream);
  131554. +int bcm2835_audio_close(bcm2835_alsa_stream_t * alsa_stream);
  131555. +int bcm2835_audio_set_params(bcm2835_alsa_stream_t * alsa_stream,
  131556. + uint32_t channels, uint32_t samplerate,
  131557. + uint32_t bps);
  131558. +int bcm2835_audio_setup(bcm2835_alsa_stream_t * alsa_stream);
  131559. +int bcm2835_audio_start(bcm2835_alsa_stream_t * alsa_stream);
  131560. +int bcm2835_audio_stop(bcm2835_alsa_stream_t * alsa_stream);
  131561. +int bcm2835_audio_set_ctls(bcm2835_chip_t * chip);
  131562. +int bcm2835_audio_write(bcm2835_alsa_stream_t * alsa_stream, uint32_t count,
  131563. + void *src);
  131564. +uint32_t bcm2835_audio_retrieve_buffers(bcm2835_alsa_stream_t * alsa_stream);
  131565. +void bcm2835_audio_flush_buffers(bcm2835_alsa_stream_t * alsa_stream);
  131566. +void bcm2835_audio_flush_playback_buffers(bcm2835_alsa_stream_t * alsa_stream);
  131567. +
  131568. +#endif /* __SOUND_ARM_BCM2835_H */
  131569. diff -Nur linux-3.18.8/sound/arm/bcm2835-pcm.c linux-rpi/sound/arm/bcm2835-pcm.c
  131570. --- linux-3.18.8/sound/arm/bcm2835-pcm.c 1970-01-01 01:00:00.000000000 +0100
  131571. +++ linux-rpi/sound/arm/bcm2835-pcm.c 2015-03-05 14:40:19.021715791 +0100
  131572. @@ -0,0 +1,552 @@
  131573. +/*****************************************************************************
  131574. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  131575. +*
  131576. +* Unless you and Broadcom execute a separate written software license
  131577. +* agreement governing use of this software, this software is licensed to you
  131578. +* under the terms of the GNU General Public License version 2, available at
  131579. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  131580. +*
  131581. +* Notwithstanding the above, under no circumstances may you combine this
  131582. +* software in any way with any other Broadcom software provided under a
  131583. +* license other than the GPL, without Broadcom's express prior written
  131584. +* consent.
  131585. +*****************************************************************************/
  131586. +
  131587. +#include <linux/interrupt.h>
  131588. +#include <linux/slab.h>
  131589. +
  131590. +#include <sound/asoundef.h>
  131591. +
  131592. +#include "bcm2835.h"
  131593. +
  131594. +/* hardware definition */
  131595. +static struct snd_pcm_hardware snd_bcm2835_playback_hw = {
  131596. + .info = (SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER |
  131597. + SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID),
  131598. + .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
  131599. + .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
  131600. + .rate_min = 8000,
  131601. + .rate_max = 48000,
  131602. + .channels_min = 1,
  131603. + .channels_max = 2,
  131604. + .buffer_bytes_max = 128 * 1024,
  131605. + .period_bytes_min = 1 * 1024,
  131606. + .period_bytes_max = 128 * 1024,
  131607. + .periods_min = 1,
  131608. + .periods_max = 128,
  131609. +};
  131610. +
  131611. +static struct snd_pcm_hardware snd_bcm2835_playback_spdif_hw = {
  131612. + .info = (SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER |
  131613. + SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID),
  131614. + .formats = SNDRV_PCM_FMTBIT_S16_LE,
  131615. + .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_44100 |
  131616. + SNDRV_PCM_RATE_48000,
  131617. + .rate_min = 44100,
  131618. + .rate_max = 48000,
  131619. + .channels_min = 2,
  131620. + .channels_max = 2,
  131621. + .buffer_bytes_max = 128 * 1024,
  131622. + .period_bytes_min = 1 * 1024,
  131623. + .period_bytes_max = 128 * 1024,
  131624. + .periods_min = 1,
  131625. + .periods_max = 128,
  131626. +};
  131627. +
  131628. +static void snd_bcm2835_playback_free(struct snd_pcm_runtime *runtime)
  131629. +{
  131630. + audio_info("Freeing up alsa stream here ..\n");
  131631. + if (runtime->private_data)
  131632. + kfree(runtime->private_data);
  131633. + runtime->private_data = NULL;
  131634. +}
  131635. +
  131636. +static irqreturn_t bcm2835_playback_fifo_irq(int irq, void *dev_id)
  131637. +{
  131638. + bcm2835_alsa_stream_t *alsa_stream = (bcm2835_alsa_stream_t *) dev_id;
  131639. + uint32_t consumed = 0;
  131640. + int new_period = 0;
  131641. +
  131642. + audio_info(" .. IN\n");
  131643. +
  131644. + audio_info("alsa_stream=%p substream=%p\n", alsa_stream,
  131645. + alsa_stream ? alsa_stream->substream : 0);
  131646. +
  131647. + if (alsa_stream->open)
  131648. + consumed = bcm2835_audio_retrieve_buffers(alsa_stream);
  131649. +
  131650. + /* We get called only if playback was triggered, So, the number of buffers we retrieve in
  131651. + * each iteration are the buffers that have been played out already
  131652. + */
  131653. +
  131654. + if (alsa_stream->period_size) {
  131655. + if ((alsa_stream->pos / alsa_stream->period_size) !=
  131656. + ((alsa_stream->pos + consumed) / alsa_stream->period_size))
  131657. + new_period = 1;
  131658. + }
  131659. + audio_debug("updating pos cur: %d + %d max:%d period_bytes:%d, hw_ptr: %d new_period:%d\n",
  131660. + alsa_stream->pos,
  131661. + consumed,
  131662. + alsa_stream->buffer_size,
  131663. + (int)(alsa_stream->period_size*alsa_stream->substream->runtime->periods),
  131664. + frames_to_bytes(alsa_stream->substream->runtime, alsa_stream->substream->runtime->status->hw_ptr),
  131665. + new_period);
  131666. + if (alsa_stream->buffer_size) {
  131667. + alsa_stream->pos += consumed &~ (1<<30);
  131668. + alsa_stream->pos %= alsa_stream->buffer_size;
  131669. + }
  131670. +
  131671. + if (alsa_stream->substream) {
  131672. + if (new_period)
  131673. + snd_pcm_period_elapsed(alsa_stream->substream);
  131674. + } else {
  131675. + audio_warning(" unexpected NULL substream\n");
  131676. + }
  131677. + audio_info(" .. OUT\n");
  131678. +
  131679. + return IRQ_HANDLED;
  131680. +}
  131681. +
  131682. +/* open callback */
  131683. +static int snd_bcm2835_playback_open_generic(
  131684. + struct snd_pcm_substream *substream, int spdif)
  131685. +{
  131686. + bcm2835_chip_t *chip = snd_pcm_substream_chip(substream);
  131687. + struct snd_pcm_runtime *runtime = substream->runtime;
  131688. + bcm2835_alsa_stream_t *alsa_stream;
  131689. + int idx;
  131690. + int err;
  131691. +
  131692. + audio_info(" .. IN (%d)\n", substream->number);
  131693. +
  131694. + if(mutex_lock_interruptible(&chip->audio_mutex))
  131695. + {
  131696. + audio_error("Interrupted whilst waiting for lock\n");
  131697. + return -EINTR;
  131698. + }
  131699. + audio_info("Alsa open (%d)\n", substream->number);
  131700. + idx = substream->number;
  131701. +
  131702. + if (spdif && chip->opened != 0)
  131703. + return -EBUSY;
  131704. + else if (!spdif && (chip->opened & (1 << idx)))
  131705. + return -EBUSY;
  131706. +
  131707. + if (idx > MAX_SUBSTREAMS) {
  131708. + audio_error
  131709. + ("substream(%d) device doesn't exist max(%d) substreams allowed\n",
  131710. + idx, MAX_SUBSTREAMS);
  131711. + err = -ENODEV;
  131712. + goto out;
  131713. + }
  131714. +
  131715. + /* Check if we are ready */
  131716. + if (!(chip->avail_substreams & (1 << idx))) {
  131717. + /* We are not ready yet */
  131718. + audio_error("substream(%d) device is not ready yet\n", idx);
  131719. + err = -EAGAIN;
  131720. + goto out;
  131721. + }
  131722. +
  131723. + alsa_stream = kzalloc(sizeof(bcm2835_alsa_stream_t), GFP_KERNEL);
  131724. + if (alsa_stream == NULL) {
  131725. + err = -ENOMEM;
  131726. + goto out;
  131727. + }
  131728. +
  131729. + /* Initialise alsa_stream */
  131730. + alsa_stream->chip = chip;
  131731. + alsa_stream->substream = substream;
  131732. + alsa_stream->idx = idx;
  131733. +
  131734. + sema_init(&alsa_stream->buffers_update_sem, 0);
  131735. + sema_init(&alsa_stream->control_sem, 0);
  131736. + spin_lock_init(&alsa_stream->lock);
  131737. +
  131738. + /* Enabled in start trigger, called on each "fifo irq" after that */
  131739. + alsa_stream->enable_fifo_irq = 0;
  131740. + alsa_stream->fifo_irq_handler = bcm2835_playback_fifo_irq;
  131741. +
  131742. + err = bcm2835_audio_open(alsa_stream);
  131743. + if (err != 0) {
  131744. + kfree(alsa_stream);
  131745. + return err;
  131746. + }
  131747. + runtime->private_data = alsa_stream;
  131748. + runtime->private_free = snd_bcm2835_playback_free;
  131749. + if (spdif) {
  131750. + runtime->hw = snd_bcm2835_playback_spdif_hw;
  131751. + } else {
  131752. + /* clear spdif status, as we are not in spdif mode */
  131753. + chip->spdif_status = 0;
  131754. + runtime->hw = snd_bcm2835_playback_hw;
  131755. + }
  131756. + /* minimum 16 bytes alignment (for vchiq bulk transfers) */
  131757. + snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
  131758. + 16);
  131759. +
  131760. + chip->alsa_stream[idx] = alsa_stream;
  131761. +
  131762. + chip->opened |= (1 << idx);
  131763. + alsa_stream->open = 1;
  131764. + alsa_stream->draining = 1;
  131765. +
  131766. +out:
  131767. + mutex_unlock(&chip->audio_mutex);
  131768. +
  131769. + audio_info(" .. OUT =%d\n", err);
  131770. +
  131771. + return err;
  131772. +}
  131773. +
  131774. +static int snd_bcm2835_playback_open(struct snd_pcm_substream *substream)
  131775. +{
  131776. + return snd_bcm2835_playback_open_generic(substream, 0);
  131777. +}
  131778. +
  131779. +static int snd_bcm2835_playback_spdif_open(struct snd_pcm_substream *substream)
  131780. +{
  131781. + return snd_bcm2835_playback_open_generic(substream, 1);
  131782. +}
  131783. +
  131784. +/* close callback */
  131785. +static int snd_bcm2835_playback_close(struct snd_pcm_substream *substream)
  131786. +{
  131787. + /* the hardware-specific codes will be here */
  131788. +
  131789. + bcm2835_chip_t *chip;
  131790. + struct snd_pcm_runtime *runtime;
  131791. + bcm2835_alsa_stream_t *alsa_stream;
  131792. +
  131793. + audio_info(" .. IN\n");
  131794. +
  131795. + chip = snd_pcm_substream_chip(substream);
  131796. + if(mutex_lock_interruptible(&chip->audio_mutex))
  131797. + {
  131798. + audio_error("Interrupted whilst waiting for lock\n");
  131799. + return -EINTR;
  131800. + }
  131801. + runtime = substream->runtime;
  131802. + alsa_stream = runtime->private_data;
  131803. +
  131804. + audio_info("Alsa close\n");
  131805. +
  131806. + /*
  131807. + * Call stop if it's still running. This happens when app
  131808. + * is force killed and we don't get a stop trigger.
  131809. + */
  131810. + if (alsa_stream->running) {
  131811. + int err;
  131812. + err = bcm2835_audio_stop(alsa_stream);
  131813. + alsa_stream->running = 0;
  131814. + if (err != 0)
  131815. + audio_error(" Failed to STOP alsa device\n");
  131816. + }
  131817. +
  131818. + alsa_stream->period_size = 0;
  131819. + alsa_stream->buffer_size = 0;
  131820. +
  131821. + if (alsa_stream->open) {
  131822. + alsa_stream->open = 0;
  131823. + bcm2835_audio_close(alsa_stream);
  131824. + }
  131825. + if (alsa_stream->chip)
  131826. + alsa_stream->chip->alsa_stream[alsa_stream->idx] = NULL;
  131827. + /*
  131828. + * Do not free up alsa_stream here, it will be freed up by
  131829. + * runtime->private_free callback we registered in *_open above
  131830. + */
  131831. +
  131832. + chip->opened &= ~(1 << substream->number);
  131833. +
  131834. + mutex_unlock(&chip->audio_mutex);
  131835. + audio_info(" .. OUT\n");
  131836. +
  131837. + return 0;
  131838. +}
  131839. +
  131840. +/* hw_params callback */
  131841. +static int snd_bcm2835_pcm_hw_params(struct snd_pcm_substream *substream,
  131842. + struct snd_pcm_hw_params *params)
  131843. +{
  131844. + struct snd_pcm_runtime *runtime = substream->runtime;
  131845. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  131846. + int err;
  131847. +
  131848. + audio_info(" .. IN\n");
  131849. +
  131850. + err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(params));
  131851. + if (err < 0) {
  131852. + audio_error
  131853. + (" pcm_lib_malloc failed to allocated pages for buffers\n");
  131854. + return err;
  131855. + }
  131856. +
  131857. + alsa_stream->channels = params_channels(params);
  131858. + alsa_stream->params_rate = params_rate(params);
  131859. + alsa_stream->pcm_format_width = snd_pcm_format_width(params_format (params));
  131860. + audio_info(" .. OUT\n");
  131861. +
  131862. + return err;
  131863. +}
  131864. +
  131865. +/* hw_free callback */
  131866. +static int snd_bcm2835_pcm_hw_free(struct snd_pcm_substream *substream)
  131867. +{
  131868. + audio_info(" .. IN\n");
  131869. + return snd_pcm_lib_free_pages(substream);
  131870. +}
  131871. +
  131872. +/* prepare callback */
  131873. +static int snd_bcm2835_pcm_prepare(struct snd_pcm_substream *substream)
  131874. +{
  131875. + bcm2835_chip_t *chip = snd_pcm_substream_chip(substream);
  131876. + struct snd_pcm_runtime *runtime = substream->runtime;
  131877. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  131878. + int channels;
  131879. + int err;
  131880. +
  131881. + audio_info(" .. IN\n");
  131882. +
  131883. + /* notify the vchiq that it should enter spdif passthrough mode by
  131884. + * setting channels=0 (see
  131885. + * https://github.com/raspberrypi/linux/issues/528) */
  131886. + if (chip->spdif_status & IEC958_AES0_NONAUDIO)
  131887. + channels = 0;
  131888. + else
  131889. + channels = alsa_stream->channels;
  131890. +
  131891. + err = bcm2835_audio_set_params(alsa_stream, channels,
  131892. + alsa_stream->params_rate,
  131893. + alsa_stream->pcm_format_width);
  131894. + if (err < 0) {
  131895. + audio_error(" error setting hw params\n");
  131896. + }
  131897. +
  131898. + bcm2835_audio_setup(alsa_stream);
  131899. +
  131900. + /* in preparation of the stream, set the controls (volume level) of the stream */
  131901. + bcm2835_audio_set_ctls(alsa_stream->chip);
  131902. +
  131903. +
  131904. + memset(&alsa_stream->pcm_indirect, 0, sizeof(alsa_stream->pcm_indirect));
  131905. +
  131906. + alsa_stream->pcm_indirect.hw_buffer_size =
  131907. + alsa_stream->pcm_indirect.sw_buffer_size =
  131908. + snd_pcm_lib_buffer_bytes(substream);
  131909. +
  131910. + alsa_stream->buffer_size = snd_pcm_lib_buffer_bytes(substream);
  131911. + alsa_stream->period_size = snd_pcm_lib_period_bytes(substream);
  131912. + alsa_stream->pos = 0;
  131913. +
  131914. + audio_debug("buffer_size=%d, period_size=%d pos=%d frame_bits=%d\n",
  131915. + alsa_stream->buffer_size, alsa_stream->period_size,
  131916. + alsa_stream->pos, runtime->frame_bits);
  131917. +
  131918. + audio_info(" .. OUT\n");
  131919. + return 0;
  131920. +}
  131921. +
  131922. +static void snd_bcm2835_pcm_transfer(struct snd_pcm_substream *substream,
  131923. + struct snd_pcm_indirect *rec, size_t bytes)
  131924. +{
  131925. + struct snd_pcm_runtime *runtime = substream->runtime;
  131926. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  131927. + void *src = (void *)(substream->runtime->dma_area + rec->sw_data);
  131928. + int err;
  131929. +
  131930. + err = bcm2835_audio_write(alsa_stream, bytes, src);
  131931. + if (err)
  131932. + audio_error(" Failed to transfer to alsa device (%d)\n", err);
  131933. +
  131934. +}
  131935. +
  131936. +static int snd_bcm2835_pcm_ack(struct snd_pcm_substream *substream)
  131937. +{
  131938. + struct snd_pcm_runtime *runtime = substream->runtime;
  131939. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  131940. + struct snd_pcm_indirect *pcm_indirect = &alsa_stream->pcm_indirect;
  131941. +
  131942. + pcm_indirect->hw_queue_size = runtime->hw.buffer_bytes_max;
  131943. + snd_pcm_indirect_playback_transfer(substream, pcm_indirect,
  131944. + snd_bcm2835_pcm_transfer);
  131945. + return 0;
  131946. +}
  131947. +
  131948. +/* trigger callback */
  131949. +static int snd_bcm2835_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
  131950. +{
  131951. + struct snd_pcm_runtime *runtime = substream->runtime;
  131952. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  131953. + int err = 0;
  131954. +
  131955. + audio_info(" .. IN\n");
  131956. +
  131957. + switch (cmd) {
  131958. + case SNDRV_PCM_TRIGGER_START:
  131959. + audio_debug("bcm2835_AUDIO_TRIGGER_START running=%d\n",
  131960. + alsa_stream->running);
  131961. + if (!alsa_stream->running) {
  131962. + err = bcm2835_audio_start(alsa_stream);
  131963. + if (err == 0) {
  131964. + alsa_stream->pcm_indirect.hw_io =
  131965. + alsa_stream->pcm_indirect.hw_data =
  131966. + bytes_to_frames(runtime,
  131967. + alsa_stream->pos);
  131968. + substream->ops->ack(substream);
  131969. + alsa_stream->running = 1;
  131970. + alsa_stream->draining = 1;
  131971. + } else {
  131972. + audio_error(" Failed to START alsa device (%d)\n", err);
  131973. + }
  131974. + }
  131975. + break;
  131976. + case SNDRV_PCM_TRIGGER_STOP:
  131977. + audio_debug
  131978. + ("bcm2835_AUDIO_TRIGGER_STOP running=%d draining=%d\n",
  131979. + alsa_stream->running, runtime->status->state == SNDRV_PCM_STATE_DRAINING);
  131980. + if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
  131981. + audio_info("DRAINING\n");
  131982. + alsa_stream->draining = 1;
  131983. + } else {
  131984. + audio_info("DROPPING\n");
  131985. + alsa_stream->draining = 0;
  131986. + }
  131987. + if (alsa_stream->running) {
  131988. + err = bcm2835_audio_stop(alsa_stream);
  131989. + if (err != 0)
  131990. + audio_error(" Failed to STOP alsa device (%d)\n", err);
  131991. + alsa_stream->running = 0;
  131992. + }
  131993. + break;
  131994. + default:
  131995. + err = -EINVAL;
  131996. + }
  131997. +
  131998. + audio_info(" .. OUT\n");
  131999. + return err;
  132000. +}
  132001. +
  132002. +/* pointer callback */
  132003. +static snd_pcm_uframes_t
  132004. +snd_bcm2835_pcm_pointer(struct snd_pcm_substream *substream)
  132005. +{
  132006. + struct snd_pcm_runtime *runtime = substream->runtime;
  132007. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  132008. +
  132009. + audio_info(" .. IN\n");
  132010. +
  132011. + audio_debug("pcm_pointer... (%d) hwptr=%d appl=%d pos=%d\n", 0,
  132012. + frames_to_bytes(runtime, runtime->status->hw_ptr),
  132013. + frames_to_bytes(runtime, runtime->control->appl_ptr),
  132014. + alsa_stream->pos);
  132015. +
  132016. + audio_info(" .. OUT\n");
  132017. + return snd_pcm_indirect_playback_pointer(substream,
  132018. + &alsa_stream->pcm_indirect,
  132019. + alsa_stream->pos);
  132020. +}
  132021. +
  132022. +static int snd_bcm2835_pcm_lib_ioctl(struct snd_pcm_substream *substream,
  132023. + unsigned int cmd, void *arg)
  132024. +{
  132025. + int ret = snd_pcm_lib_ioctl(substream, cmd, arg);
  132026. + audio_info(" .. substream=%p, cmd=%d, arg=%p (%x) ret=%d\n", substream,
  132027. + cmd, arg, arg ? *(unsigned *)arg : 0, ret);
  132028. + return ret;
  132029. +}
  132030. +
  132031. +/* operators */
  132032. +static struct snd_pcm_ops snd_bcm2835_playback_ops = {
  132033. + .open = snd_bcm2835_playback_open,
  132034. + .close = snd_bcm2835_playback_close,
  132035. + .ioctl = snd_bcm2835_pcm_lib_ioctl,
  132036. + .hw_params = snd_bcm2835_pcm_hw_params,
  132037. + .hw_free = snd_bcm2835_pcm_hw_free,
  132038. + .prepare = snd_bcm2835_pcm_prepare,
  132039. + .trigger = snd_bcm2835_pcm_trigger,
  132040. + .pointer = snd_bcm2835_pcm_pointer,
  132041. + .ack = snd_bcm2835_pcm_ack,
  132042. +};
  132043. +
  132044. +static struct snd_pcm_ops snd_bcm2835_playback_spdif_ops = {
  132045. + .open = snd_bcm2835_playback_spdif_open,
  132046. + .close = snd_bcm2835_playback_close,
  132047. + .ioctl = snd_bcm2835_pcm_lib_ioctl,
  132048. + .hw_params = snd_bcm2835_pcm_hw_params,
  132049. + .hw_free = snd_bcm2835_pcm_hw_free,
  132050. + .prepare = snd_bcm2835_pcm_prepare,
  132051. + .trigger = snd_bcm2835_pcm_trigger,
  132052. + .pointer = snd_bcm2835_pcm_pointer,
  132053. + .ack = snd_bcm2835_pcm_ack,
  132054. +};
  132055. +
  132056. +/* create a pcm device */
  132057. +int snd_bcm2835_new_pcm(bcm2835_chip_t * chip)
  132058. +{
  132059. + struct snd_pcm *pcm;
  132060. + int err;
  132061. +
  132062. + audio_info(" .. IN\n");
  132063. + mutex_init(&chip->audio_mutex);
  132064. + if(mutex_lock_interruptible(&chip->audio_mutex))
  132065. + {
  132066. + audio_error("Interrupted whilst waiting for lock\n");
  132067. + return -EINTR;
  132068. + }
  132069. + err =
  132070. + snd_pcm_new(chip->card, "bcm2835 ALSA", 0, MAX_SUBSTREAMS, 0, &pcm);
  132071. + if (err < 0)
  132072. + return err;
  132073. + pcm->private_data = chip;
  132074. + strcpy(pcm->name, "bcm2835 ALSA");
  132075. + chip->pcm = pcm;
  132076. + chip->dest = AUDIO_DEST_AUTO;
  132077. + chip->volume = alsa2chip(0);
  132078. + chip->mute = CTRL_VOL_UNMUTE; /*disable mute on startup */
  132079. + /* set operators */
  132080. + snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
  132081. + &snd_bcm2835_playback_ops);
  132082. +
  132083. + /* pre-allocation of buffers */
  132084. + /* NOTE: this may fail */
  132085. + snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS,
  132086. + snd_dma_continuous_data
  132087. + (GFP_KERNEL), 64 * 1024,
  132088. + 64 * 1024);
  132089. +
  132090. + mutex_unlock(&chip->audio_mutex);
  132091. + audio_info(" .. OUT\n");
  132092. +
  132093. + return 0;
  132094. +}
  132095. +
  132096. +int snd_bcm2835_new_spdif_pcm(bcm2835_chip_t * chip)
  132097. +{
  132098. + struct snd_pcm *pcm;
  132099. + int err;
  132100. +
  132101. + audio_info(" .. IN\n");
  132102. + if(mutex_lock_interruptible(&chip->audio_mutex))
  132103. + {
  132104. + audio_error("Interrupted whilst waiting for lock\n");
  132105. + return -EINTR;
  132106. + }
  132107. + err = snd_pcm_new(chip->card, "bcm2835 ALSA", 1, 1, 0, &pcm);
  132108. + if (err < 0)
  132109. + return err;
  132110. +
  132111. + pcm->private_data = chip;
  132112. + strcpy(pcm->name, "bcm2835 IEC958/HDMI");
  132113. + chip->pcm_spdif = pcm;
  132114. + snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
  132115. + &snd_bcm2835_playback_spdif_ops);
  132116. +
  132117. + snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS,
  132118. + snd_dma_continuous_data (GFP_KERNEL),
  132119. + 64 * 1024, 64 * 1024);
  132120. + mutex_unlock(&chip->audio_mutex);
  132121. + audio_info(" .. OUT\n");
  132122. +
  132123. + return 0;
  132124. +}
  132125. diff -Nur linux-3.18.8/sound/arm/bcm2835-vchiq.c linux-rpi/sound/arm/bcm2835-vchiq.c
  132126. --- linux-3.18.8/sound/arm/bcm2835-vchiq.c 1970-01-01 01:00:00.000000000 +0100
  132127. +++ linux-rpi/sound/arm/bcm2835-vchiq.c 2015-03-05 14:40:19.021715791 +0100
  132128. @@ -0,0 +1,902 @@
  132129. +/*****************************************************************************
  132130. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  132131. +*
  132132. +* Unless you and Broadcom execute a separate written software license
  132133. +* agreement governing use of this software, this software is licensed to you
  132134. +* under the terms of the GNU General Public License version 2, available at
  132135. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  132136. +*
  132137. +* Notwithstanding the above, under no circumstances may you combine this
  132138. +* software in any way with any other Broadcom software provided under a
  132139. +* license other than the GPL, without Broadcom's express prior written
  132140. +* consent.
  132141. +*****************************************************************************/
  132142. +
  132143. +#include <linux/device.h>
  132144. +#include <sound/core.h>
  132145. +#include <sound/initval.h>
  132146. +#include <sound/pcm.h>
  132147. +#include <linux/io.h>
  132148. +#include <linux/interrupt.h>
  132149. +#include <linux/fs.h>
  132150. +#include <linux/file.h>
  132151. +#include <linux/mm.h>
  132152. +#include <linux/syscalls.h>
  132153. +#include <asm/uaccess.h>
  132154. +#include <linux/slab.h>
  132155. +#include <linux/delay.h>
  132156. +#include <linux/atomic.h>
  132157. +#include <linux/module.h>
  132158. +#include <linux/completion.h>
  132159. +
  132160. +#include "bcm2835.h"
  132161. +
  132162. +/* ---- Include Files -------------------------------------------------------- */
  132163. +
  132164. +#include "interface/vchi/vchi.h"
  132165. +#include "vc_vchi_audioserv_defs.h"
  132166. +
  132167. +/* ---- Private Constants and Types ------------------------------------------ */
  132168. +
  132169. +#define BCM2835_AUDIO_STOP 0
  132170. +#define BCM2835_AUDIO_START 1
  132171. +#define BCM2835_AUDIO_WRITE 2
  132172. +
  132173. +/* Logging macros (for remapping to other logging mechanisms, i.e., printf) */
  132174. +#ifdef AUDIO_DEBUG_ENABLE
  132175. + #define LOG_ERR( fmt, arg... ) pr_err( "%s:%d " fmt, __func__, __LINE__, ##arg)
  132176. + #define LOG_WARN( fmt, arg... ) pr_info( "%s:%d " fmt, __func__, __LINE__, ##arg)
  132177. + #define LOG_INFO( fmt, arg... ) pr_info( "%s:%d " fmt, __func__, __LINE__, ##arg)
  132178. + #define LOG_DBG( fmt, arg... ) pr_info( "%s:%d " fmt, __func__, __LINE__, ##arg)
  132179. +#else
  132180. + #define LOG_ERR( fmt, arg... ) pr_err( "%s:%d " fmt, __func__, __LINE__, ##arg)
  132181. + #define LOG_WARN( fmt, arg... )
  132182. + #define LOG_INFO( fmt, arg... )
  132183. + #define LOG_DBG( fmt, arg... )
  132184. +#endif
  132185. +
  132186. +typedef struct opaque_AUDIO_INSTANCE_T {
  132187. + uint32_t num_connections;
  132188. + VCHI_SERVICE_HANDLE_T vchi_handle[VCHI_MAX_NUM_CONNECTIONS];
  132189. + struct completion msg_avail_comp;
  132190. + struct mutex vchi_mutex;
  132191. + bcm2835_alsa_stream_t *alsa_stream;
  132192. + int32_t result;
  132193. + short peer_version;
  132194. +} AUDIO_INSTANCE_T;
  132195. +
  132196. +bool force_bulk = false;
  132197. +
  132198. +/* ---- Private Variables ---------------------------------------------------- */
  132199. +
  132200. +/* ---- Private Function Prototypes ------------------------------------------ */
  132201. +
  132202. +/* ---- Private Functions ---------------------------------------------------- */
  132203. +
  132204. +static int bcm2835_audio_stop_worker(bcm2835_alsa_stream_t * alsa_stream);
  132205. +static int bcm2835_audio_start_worker(bcm2835_alsa_stream_t * alsa_stream);
  132206. +static int bcm2835_audio_write_worker(bcm2835_alsa_stream_t *alsa_stream,
  132207. + uint32_t count, void *src);
  132208. +
  132209. +typedef struct {
  132210. + struct work_struct my_work;
  132211. + bcm2835_alsa_stream_t *alsa_stream;
  132212. + int cmd;
  132213. + void *src;
  132214. + uint32_t count;
  132215. +} my_work_t;
  132216. +
  132217. +static void my_wq_function(struct work_struct *work)
  132218. +{
  132219. + my_work_t *w = (my_work_t *) work;
  132220. + int ret = -9;
  132221. + LOG_DBG(" .. IN %p:%d\n", w->alsa_stream, w->cmd);
  132222. + switch (w->cmd) {
  132223. + case BCM2835_AUDIO_START:
  132224. + ret = bcm2835_audio_start_worker(w->alsa_stream);
  132225. + break;
  132226. + case BCM2835_AUDIO_STOP:
  132227. + ret = bcm2835_audio_stop_worker(w->alsa_stream);
  132228. + break;
  132229. + case BCM2835_AUDIO_WRITE:
  132230. + ret = bcm2835_audio_write_worker(w->alsa_stream, w->count,
  132231. + w->src);
  132232. + break;
  132233. + default:
  132234. + LOG_ERR(" Unexpected work: %p:%d\n", w->alsa_stream, w->cmd);
  132235. + break;
  132236. + }
  132237. + kfree((void *)work);
  132238. + LOG_DBG(" .. OUT %d\n", ret);
  132239. +}
  132240. +
  132241. +int bcm2835_audio_start(bcm2835_alsa_stream_t * alsa_stream)
  132242. +{
  132243. + int ret = -1;
  132244. + LOG_DBG(" .. IN\n");
  132245. + if (alsa_stream->my_wq) {
  132246. + my_work_t *work = kmalloc(sizeof(my_work_t), GFP_ATOMIC);
  132247. + /*--- Queue some work (item 1) ---*/
  132248. + if (work) {
  132249. + INIT_WORK((struct work_struct *)work, my_wq_function);
  132250. + work->alsa_stream = alsa_stream;
  132251. + work->cmd = BCM2835_AUDIO_START;
  132252. + if (queue_work
  132253. + (alsa_stream->my_wq, (struct work_struct *)work))
  132254. + ret = 0;
  132255. + } else
  132256. + LOG_ERR(" .. Error: NULL work kmalloc\n");
  132257. + }
  132258. + LOG_DBG(" .. OUT %d\n", ret);
  132259. + return ret;
  132260. +}
  132261. +
  132262. +int bcm2835_audio_stop(bcm2835_alsa_stream_t * alsa_stream)
  132263. +{
  132264. + int ret = -1;
  132265. + LOG_DBG(" .. IN\n");
  132266. + if (alsa_stream->my_wq) {
  132267. + my_work_t *work = kmalloc(sizeof(my_work_t), GFP_ATOMIC);
  132268. + /*--- Queue some work (item 1) ---*/
  132269. + if (work) {
  132270. + INIT_WORK((struct work_struct *)work, my_wq_function);
  132271. + work->alsa_stream = alsa_stream;
  132272. + work->cmd = BCM2835_AUDIO_STOP;
  132273. + if (queue_work
  132274. + (alsa_stream->my_wq, (struct work_struct *)work))
  132275. + ret = 0;
  132276. + } else
  132277. + LOG_ERR(" .. Error: NULL work kmalloc\n");
  132278. + }
  132279. + LOG_DBG(" .. OUT %d\n", ret);
  132280. + return ret;
  132281. +}
  132282. +
  132283. +int bcm2835_audio_write(bcm2835_alsa_stream_t *alsa_stream,
  132284. + uint32_t count, void *src)
  132285. +{
  132286. + int ret = -1;
  132287. + LOG_DBG(" .. IN\n");
  132288. + if (alsa_stream->my_wq) {
  132289. + my_work_t *work = kmalloc(sizeof(my_work_t), GFP_ATOMIC);
  132290. + /*--- Queue some work (item 1) ---*/
  132291. + if (work) {
  132292. + INIT_WORK((struct work_struct *)work, my_wq_function);
  132293. + work->alsa_stream = alsa_stream;
  132294. + work->cmd = BCM2835_AUDIO_WRITE;
  132295. + work->src = src;
  132296. + work->count = count;
  132297. + if (queue_work
  132298. + (alsa_stream->my_wq, (struct work_struct *)work))
  132299. + ret = 0;
  132300. + } else
  132301. + LOG_ERR(" .. Error: NULL work kmalloc\n");
  132302. + }
  132303. + LOG_DBG(" .. OUT %d\n", ret);
  132304. + return ret;
  132305. +}
  132306. +
  132307. +void my_workqueue_init(bcm2835_alsa_stream_t * alsa_stream)
  132308. +{
  132309. + alsa_stream->my_wq = alloc_workqueue("my_queue", WQ_HIGHPRI, 1);
  132310. + return;
  132311. +}
  132312. +
  132313. +void my_workqueue_quit(bcm2835_alsa_stream_t * alsa_stream)
  132314. +{
  132315. + if (alsa_stream->my_wq) {
  132316. + flush_workqueue(alsa_stream->my_wq);
  132317. + destroy_workqueue(alsa_stream->my_wq);
  132318. + alsa_stream->my_wq = NULL;
  132319. + }
  132320. + return;
  132321. +}
  132322. +
  132323. +static void audio_vchi_callback(void *param,
  132324. + const VCHI_CALLBACK_REASON_T reason,
  132325. + void *msg_handle)
  132326. +{
  132327. + AUDIO_INSTANCE_T *instance = (AUDIO_INSTANCE_T *) param;
  132328. + int32_t status;
  132329. + int32_t msg_len;
  132330. + VC_AUDIO_MSG_T m;
  132331. + LOG_DBG(" .. IN instance=%p, handle=%p, alsa=%p, reason=%d, handle=%p\n",
  132332. + instance, instance ? instance->vchi_handle[0] : NULL, instance ? instance->alsa_stream : NULL, reason, msg_handle);
  132333. +
  132334. + if (reason != VCHI_CALLBACK_MSG_AVAILABLE) {
  132335. + return;
  132336. + }
  132337. + if (!instance) {
  132338. + LOG_ERR(" .. instance is null\n");
  132339. + BUG();
  132340. + return;
  132341. + }
  132342. + if (!instance->vchi_handle[0]) {
  132343. + LOG_ERR(" .. instance->vchi_handle[0] is null\n");
  132344. + BUG();
  132345. + return;
  132346. + }
  132347. + status = vchi_msg_dequeue(instance->vchi_handle[0],
  132348. + &m, sizeof m, &msg_len, VCHI_FLAGS_NONE);
  132349. + if (m.type == VC_AUDIO_MSG_TYPE_RESULT) {
  132350. + LOG_DBG
  132351. + (" .. instance=%p, m.type=VC_AUDIO_MSG_TYPE_RESULT, success=%d\n",
  132352. + instance, m.u.result.success);
  132353. + instance->result = m.u.result.success;
  132354. + complete(&instance->msg_avail_comp);
  132355. + } else if (m.type == VC_AUDIO_MSG_TYPE_COMPLETE) {
  132356. + bcm2835_alsa_stream_t *alsa_stream = instance->alsa_stream;
  132357. + irq_handler_t callback = (irq_handler_t) m.u.complete.callback;
  132358. + LOG_DBG
  132359. + (" .. instance=%p, m.type=VC_AUDIO_MSG_TYPE_COMPLETE, complete=%d\n",
  132360. + instance, m.u.complete.count);
  132361. + if (alsa_stream && callback) {
  132362. + atomic_add(m.u.complete.count, &alsa_stream->retrieved);
  132363. + callback(0, alsa_stream);
  132364. + } else {
  132365. + LOG_ERR(" .. unexpected alsa_stream=%p, callback=%p\n",
  132366. + alsa_stream, callback);
  132367. + }
  132368. + } else {
  132369. + LOG_ERR(" .. unexpected m.type=%d\n", m.type);
  132370. + }
  132371. + LOG_DBG(" .. OUT\n");
  132372. +}
  132373. +
  132374. +static AUDIO_INSTANCE_T *vc_vchi_audio_init(VCHI_INSTANCE_T vchi_instance,
  132375. + VCHI_CONNECTION_T **
  132376. + vchi_connections,
  132377. + uint32_t num_connections)
  132378. +{
  132379. + uint32_t i;
  132380. + AUDIO_INSTANCE_T *instance;
  132381. + int status;
  132382. +
  132383. + LOG_DBG("%s: start", __func__);
  132384. +
  132385. + if (num_connections > VCHI_MAX_NUM_CONNECTIONS) {
  132386. + LOG_ERR("%s: unsupported number of connections %u (max=%u)\n",
  132387. + __func__, num_connections, VCHI_MAX_NUM_CONNECTIONS);
  132388. +
  132389. + return NULL;
  132390. + }
  132391. + /* Allocate memory for this instance */
  132392. + instance = kmalloc(sizeof(*instance), GFP_KERNEL);
  132393. + if (!instance)
  132394. + return NULL;
  132395. +
  132396. + memset(instance, 0, sizeof(*instance));
  132397. + instance->num_connections = num_connections;
  132398. +
  132399. + /* Create a lock for exclusive, serialized VCHI connection access */
  132400. + mutex_init(&instance->vchi_mutex);
  132401. + /* Open the VCHI service connections */
  132402. + for (i = 0; i < num_connections; i++) {
  132403. + SERVICE_CREATION_T params = {
  132404. + VCHI_VERSION_EX(VC_AUDIOSERV_VER, VC_AUDIOSERV_MIN_VER),
  132405. + VC_AUDIO_SERVER_NAME, // 4cc service code
  132406. + vchi_connections[i], // passed in fn pointers
  132407. + 0, // rx fifo size (unused)
  132408. + 0, // tx fifo size (unused)
  132409. + audio_vchi_callback, // service callback
  132410. + instance, // service callback parameter
  132411. + 1, //TODO: remove VCOS_FALSE, // unaligned bulk recieves
  132412. + 1, //TODO: remove VCOS_FALSE, // unaligned bulk transmits
  132413. + 0 // want crc check on bulk transfers
  132414. + };
  132415. +
  132416. + LOG_DBG("%s: about to open %i\n", __func__, i);
  132417. + status = vchi_service_open(vchi_instance, &params,
  132418. + &instance->vchi_handle[i]);
  132419. + LOG_DBG("%s: opened %i: %p=%d\n", __func__, i, instance->vchi_handle[i], status);
  132420. + if (status) {
  132421. + LOG_ERR
  132422. + ("%s: failed to open VCHI service connection (status=%d)\n",
  132423. + __func__, status);
  132424. +
  132425. + goto err_close_services;
  132426. + }
  132427. + /* Finished with the service for now */
  132428. + vchi_service_release(instance->vchi_handle[i]);
  132429. + }
  132430. +
  132431. + LOG_DBG("%s: okay\n", __func__);
  132432. + return instance;
  132433. +
  132434. +err_close_services:
  132435. + for (i = 0; i < instance->num_connections; i++) {
  132436. + LOG_ERR("%s: closing %i: %p\n", __func__, i, instance->vchi_handle[i]);
  132437. + if (instance->vchi_handle[i])
  132438. + vchi_service_close(instance->vchi_handle[i]);
  132439. + }
  132440. +
  132441. + kfree(instance);
  132442. + LOG_ERR("%s: error\n", __func__);
  132443. +
  132444. + return NULL;
  132445. +}
  132446. +
  132447. +static int32_t vc_vchi_audio_deinit(AUDIO_INSTANCE_T * instance)
  132448. +{
  132449. + uint32_t i;
  132450. +
  132451. + LOG_DBG(" .. IN\n");
  132452. +
  132453. + if (instance == NULL) {
  132454. + LOG_ERR("%s: invalid handle %p\n", __func__, instance);
  132455. +
  132456. + return -1;
  132457. + }
  132458. +
  132459. + LOG_DBG(" .. about to lock (%d)\n", instance->num_connections);
  132460. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  132461. + {
  132462. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  132463. + return -EINTR;
  132464. + }
  132465. +
  132466. + /* Close all VCHI service connections */
  132467. + for (i = 0; i < instance->num_connections; i++) {
  132468. + int32_t success;
  132469. + LOG_DBG(" .. %i:closing %p\n", i, instance->vchi_handle[i]);
  132470. + vchi_service_use(instance->vchi_handle[i]);
  132471. +
  132472. + success = vchi_service_close(instance->vchi_handle[i]);
  132473. + if (success != 0) {
  132474. + LOG_ERR
  132475. + ("%s: failed to close VCHI service connection (status=%d)\n",
  132476. + __func__, success);
  132477. + }
  132478. + }
  132479. +
  132480. + mutex_unlock(&instance->vchi_mutex);
  132481. +
  132482. + kfree(instance);
  132483. +
  132484. + LOG_DBG(" .. OUT\n");
  132485. +
  132486. + return 0;
  132487. +}
  132488. +
  132489. +static int bcm2835_audio_open_connection(bcm2835_alsa_stream_t * alsa_stream)
  132490. +{
  132491. + static VCHI_INSTANCE_T vchi_instance;
  132492. + static VCHI_CONNECTION_T *vchi_connection;
  132493. + static int initted;
  132494. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  132495. + int ret;
  132496. + LOG_DBG(" .. IN\n");
  132497. +
  132498. + LOG_INFO("%s: start\n", __func__);
  132499. + BUG_ON(instance);
  132500. + if (instance) {
  132501. + LOG_ERR("%s: VCHI instance already open (%p)\n",
  132502. + __func__, instance);
  132503. + instance->alsa_stream = alsa_stream;
  132504. + alsa_stream->instance = instance;
  132505. + ret = 0; // xxx todo -1;
  132506. + goto err_free_mem;
  132507. + }
  132508. +
  132509. + /* Initialize and create a VCHI connection */
  132510. + if (!initted) {
  132511. + ret = vchi_initialise(&vchi_instance);
  132512. + if (ret != 0) {
  132513. + LOG_ERR("%s: failed to initialise VCHI instance (ret=%d)\n",
  132514. + __func__, ret);
  132515. +
  132516. + ret = -EIO;
  132517. + goto err_free_mem;
  132518. + }
  132519. + ret = vchi_connect(NULL, 0, vchi_instance);
  132520. + if (ret != 0) {
  132521. + LOG_ERR("%s: failed to connect VCHI instance (ret=%d)\n",
  132522. + __func__, ret);
  132523. +
  132524. + ret = -EIO;
  132525. + goto err_free_mem;
  132526. + }
  132527. + initted = 1;
  132528. + }
  132529. +
  132530. + /* Initialize an instance of the audio service */
  132531. + instance = vc_vchi_audio_init(vchi_instance, &vchi_connection, 1);
  132532. +
  132533. + if (instance == NULL) {
  132534. + LOG_ERR("%s: failed to initialize audio service\n", __func__);
  132535. +
  132536. + ret = -EPERM;
  132537. + goto err_free_mem;
  132538. + }
  132539. +
  132540. + instance->alsa_stream = alsa_stream;
  132541. + alsa_stream->instance = instance;
  132542. +
  132543. + LOG_DBG(" success !\n");
  132544. +err_free_mem:
  132545. + LOG_DBG(" .. OUT\n");
  132546. +
  132547. + return ret;
  132548. +}
  132549. +
  132550. +int bcm2835_audio_open(bcm2835_alsa_stream_t * alsa_stream)
  132551. +{
  132552. + AUDIO_INSTANCE_T *instance;
  132553. + VC_AUDIO_MSG_T m;
  132554. + int32_t success;
  132555. + int ret;
  132556. + LOG_DBG(" .. IN\n");
  132557. +
  132558. + my_workqueue_init(alsa_stream);
  132559. +
  132560. + ret = bcm2835_audio_open_connection(alsa_stream);
  132561. + if (ret != 0) {
  132562. + ret = -1;
  132563. + goto exit;
  132564. + }
  132565. + instance = alsa_stream->instance;
  132566. + LOG_DBG(" instance (%p)\n", instance);
  132567. +
  132568. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  132569. + {
  132570. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  132571. + return -EINTR;
  132572. + }
  132573. + vchi_service_use(instance->vchi_handle[0]);
  132574. +
  132575. + m.type = VC_AUDIO_MSG_TYPE_OPEN;
  132576. +
  132577. + /* Send the message to the videocore */
  132578. + success = vchi_msg_queue(instance->vchi_handle[0],
  132579. + &m, sizeof m,
  132580. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  132581. +
  132582. + if (success != 0) {
  132583. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)\n",
  132584. + __func__, success);
  132585. +
  132586. + ret = -1;
  132587. + goto unlock;
  132588. + }
  132589. +
  132590. + ret = 0;
  132591. +
  132592. +unlock:
  132593. + vchi_service_release(instance->vchi_handle[0]);
  132594. + mutex_unlock(&instance->vchi_mutex);
  132595. +exit:
  132596. + LOG_DBG(" .. OUT\n");
  132597. + return ret;
  132598. +}
  132599. +
  132600. +static int bcm2835_audio_set_ctls_chan(bcm2835_alsa_stream_t * alsa_stream,
  132601. + bcm2835_chip_t * chip)
  132602. +{
  132603. + VC_AUDIO_MSG_T m;
  132604. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  132605. + int32_t success;
  132606. + int ret;
  132607. + LOG_DBG(" .. IN\n");
  132608. +
  132609. + LOG_INFO
  132610. + (" Setting ALSA dest(%d), volume(%d)\n", chip->dest, chip->volume);
  132611. +
  132612. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  132613. + {
  132614. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  132615. + return -EINTR;
  132616. + }
  132617. + vchi_service_use(instance->vchi_handle[0]);
  132618. +
  132619. + instance->result = -1;
  132620. +
  132621. + m.type = VC_AUDIO_MSG_TYPE_CONTROL;
  132622. + m.u.control.dest = chip->dest;
  132623. + m.u.control.volume = chip->volume;
  132624. +
  132625. + /* Create the message available completion */
  132626. + init_completion(&instance->msg_avail_comp);
  132627. +
  132628. + /* Send the message to the videocore */
  132629. + success = vchi_msg_queue(instance->vchi_handle[0],
  132630. + &m, sizeof m,
  132631. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  132632. +
  132633. + if (success != 0) {
  132634. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)\n",
  132635. + __func__, success);
  132636. +
  132637. + ret = -1;
  132638. + goto unlock;
  132639. + }
  132640. +
  132641. + /* We are expecting a reply from the videocore */
  132642. + ret = wait_for_completion_interruptible(&instance->msg_avail_comp);
  132643. + if (ret) {
  132644. + LOG_ERR("%s: failed on waiting for event (status=%d)\n",
  132645. + __func__, success);
  132646. + goto unlock;
  132647. + }
  132648. +
  132649. + if (instance->result != 0) {
  132650. + LOG_ERR("%s: result=%d\n", __func__, instance->result);
  132651. +
  132652. + ret = -1;
  132653. + goto unlock;
  132654. + }
  132655. +
  132656. + ret = 0;
  132657. +
  132658. +unlock:
  132659. + vchi_service_release(instance->vchi_handle[0]);
  132660. + mutex_unlock(&instance->vchi_mutex);
  132661. +
  132662. + LOG_DBG(" .. OUT\n");
  132663. + return ret;
  132664. +}
  132665. +
  132666. +int bcm2835_audio_set_ctls(bcm2835_chip_t * chip)
  132667. +{
  132668. + int i;
  132669. + int ret = 0;
  132670. + LOG_DBG(" .. IN\n");
  132671. + LOG_DBG(" Setting ALSA dest(%d), volume(%d)\n", chip->dest, chip->volume);
  132672. +
  132673. + /* change ctls for all substreams */
  132674. + for (i = 0; i < MAX_SUBSTREAMS; i++) {
  132675. + if (chip->avail_substreams & (1 << i)) {
  132676. + if (!chip->alsa_stream[i])
  132677. + {
  132678. + LOG_DBG(" No ALSA stream available?! %i:%p (%x)\n", i, chip->alsa_stream[i], chip->avail_substreams);
  132679. + ret = 0;
  132680. + }
  132681. + else if (bcm2835_audio_set_ctls_chan /* returns 0 on success */
  132682. + (chip->alsa_stream[i], chip) != 0)
  132683. + {
  132684. + LOG_ERR("Couldn't set the controls for stream %d\n", i);
  132685. + ret = -1;
  132686. + }
  132687. + else LOG_DBG(" Controls set for stream %d\n", i);
  132688. + }
  132689. + }
  132690. + LOG_DBG(" .. OUT ret=%d\n", ret);
  132691. + return ret;
  132692. +}
  132693. +
  132694. +int bcm2835_audio_set_params(bcm2835_alsa_stream_t * alsa_stream,
  132695. + uint32_t channels, uint32_t samplerate,
  132696. + uint32_t bps)
  132697. +{
  132698. + VC_AUDIO_MSG_T m;
  132699. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  132700. + int32_t success;
  132701. + int ret;
  132702. + LOG_DBG(" .. IN\n");
  132703. +
  132704. + LOG_INFO
  132705. + (" Setting ALSA channels(%d), samplerate(%d), bits-per-sample(%d)\n",
  132706. + channels, samplerate, bps);
  132707. +
  132708. + /* resend ctls - alsa_stream may not have been open when first send */
  132709. + ret = bcm2835_audio_set_ctls_chan(alsa_stream, alsa_stream->chip);
  132710. + if (ret != 0) {
  132711. + LOG_ERR(" Alsa controls not supported\n");
  132712. + return -EINVAL;
  132713. + }
  132714. +
  132715. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  132716. + {
  132717. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  132718. + return -EINTR;
  132719. + }
  132720. + vchi_service_use(instance->vchi_handle[0]);
  132721. +
  132722. + instance->result = -1;
  132723. +
  132724. + m.type = VC_AUDIO_MSG_TYPE_CONFIG;
  132725. + m.u.config.channels = channels;
  132726. + m.u.config.samplerate = samplerate;
  132727. + m.u.config.bps = bps;
  132728. +
  132729. + /* Create the message available completion */
  132730. + init_completion(&instance->msg_avail_comp);
  132731. +
  132732. + /* Send the message to the videocore */
  132733. + success = vchi_msg_queue(instance->vchi_handle[0],
  132734. + &m, sizeof m,
  132735. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  132736. +
  132737. + if (success != 0) {
  132738. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)\n",
  132739. + __func__, success);
  132740. +
  132741. + ret = -1;
  132742. + goto unlock;
  132743. + }
  132744. +
  132745. + /* We are expecting a reply from the videocore */
  132746. + ret = wait_for_completion_interruptible(&instance->msg_avail_comp);
  132747. + if (ret) {
  132748. + LOG_ERR("%s: failed on waiting for event (status=%d)\n",
  132749. + __func__, success);
  132750. + goto unlock;
  132751. + }
  132752. +
  132753. + if (instance->result != 0) {
  132754. + LOG_ERR("%s: result=%d", __func__, instance->result);
  132755. +
  132756. + ret = -1;
  132757. + goto unlock;
  132758. + }
  132759. +
  132760. + ret = 0;
  132761. +
  132762. +unlock:
  132763. + vchi_service_release(instance->vchi_handle[0]);
  132764. + mutex_unlock(&instance->vchi_mutex);
  132765. +
  132766. + LOG_DBG(" .. OUT\n");
  132767. + return ret;
  132768. +}
  132769. +
  132770. +int bcm2835_audio_setup(bcm2835_alsa_stream_t * alsa_stream)
  132771. +{
  132772. + LOG_DBG(" .. IN\n");
  132773. +
  132774. + LOG_DBG(" .. OUT\n");
  132775. +
  132776. + return 0;
  132777. +}
  132778. +
  132779. +static int bcm2835_audio_start_worker(bcm2835_alsa_stream_t * alsa_stream)
  132780. +{
  132781. + VC_AUDIO_MSG_T m;
  132782. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  132783. + int32_t success;
  132784. + int ret;
  132785. + LOG_DBG(" .. IN\n");
  132786. +
  132787. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  132788. + {
  132789. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  132790. + return -EINTR;
  132791. + }
  132792. + vchi_service_use(instance->vchi_handle[0]);
  132793. +
  132794. + m.type = VC_AUDIO_MSG_TYPE_START;
  132795. +
  132796. + /* Send the message to the videocore */
  132797. + success = vchi_msg_queue(instance->vchi_handle[0],
  132798. + &m, sizeof m,
  132799. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  132800. +
  132801. + if (success != 0) {
  132802. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)\n",
  132803. + __func__, success);
  132804. +
  132805. + ret = -1;
  132806. + goto unlock;
  132807. + }
  132808. +
  132809. + ret = 0;
  132810. +
  132811. +unlock:
  132812. + vchi_service_release(instance->vchi_handle[0]);
  132813. + mutex_unlock(&instance->vchi_mutex);
  132814. + LOG_DBG(" .. OUT\n");
  132815. + return ret;
  132816. +}
  132817. +
  132818. +static int bcm2835_audio_stop_worker(bcm2835_alsa_stream_t * alsa_stream)
  132819. +{
  132820. + VC_AUDIO_MSG_T m;
  132821. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  132822. + int32_t success;
  132823. + int ret;
  132824. + LOG_DBG(" .. IN\n");
  132825. +
  132826. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  132827. + {
  132828. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  132829. + return -EINTR;
  132830. + }
  132831. + vchi_service_use(instance->vchi_handle[0]);
  132832. +
  132833. + m.type = VC_AUDIO_MSG_TYPE_STOP;
  132834. + m.u.stop.draining = alsa_stream->draining;
  132835. +
  132836. + /* Send the message to the videocore */
  132837. + success = vchi_msg_queue(instance->vchi_handle[0],
  132838. + &m, sizeof m,
  132839. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  132840. +
  132841. + if (success != 0) {
  132842. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)\n",
  132843. + __func__, success);
  132844. +
  132845. + ret = -1;
  132846. + goto unlock;
  132847. + }
  132848. +
  132849. + ret = 0;
  132850. +
  132851. +unlock:
  132852. + vchi_service_release(instance->vchi_handle[0]);
  132853. + mutex_unlock(&instance->vchi_mutex);
  132854. + LOG_DBG(" .. OUT\n");
  132855. + return ret;
  132856. +}
  132857. +
  132858. +int bcm2835_audio_close(bcm2835_alsa_stream_t * alsa_stream)
  132859. +{
  132860. + VC_AUDIO_MSG_T m;
  132861. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  132862. + int32_t success;
  132863. + int ret;
  132864. + LOG_DBG(" .. IN\n");
  132865. +
  132866. + my_workqueue_quit(alsa_stream);
  132867. +
  132868. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  132869. + {
  132870. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  132871. + return -EINTR;
  132872. + }
  132873. + vchi_service_use(instance->vchi_handle[0]);
  132874. +
  132875. + m.type = VC_AUDIO_MSG_TYPE_CLOSE;
  132876. +
  132877. + /* Create the message available completion */
  132878. + init_completion(&instance->msg_avail_comp);
  132879. +
  132880. + /* Send the message to the videocore */
  132881. + success = vchi_msg_queue(instance->vchi_handle[0],
  132882. + &m, sizeof m,
  132883. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  132884. +
  132885. + if (success != 0) {
  132886. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)\n",
  132887. + __func__, success);
  132888. + ret = -1;
  132889. + goto unlock;
  132890. + }
  132891. +
  132892. + ret = wait_for_completion_interruptible(&instance->msg_avail_comp);
  132893. + if (ret) {
  132894. + LOG_ERR("%s: failed on waiting for event (status=%d)\n",
  132895. + __func__, success);
  132896. + goto unlock;
  132897. + }
  132898. + if (instance->result != 0) {
  132899. + LOG_ERR("%s: failed result (status=%d)\n",
  132900. + __func__, instance->result);
  132901. +
  132902. + ret = -1;
  132903. + goto unlock;
  132904. + }
  132905. +
  132906. + ret = 0;
  132907. +
  132908. +unlock:
  132909. + vchi_service_release(instance->vchi_handle[0]);
  132910. + mutex_unlock(&instance->vchi_mutex);
  132911. +
  132912. + /* Stop the audio service */
  132913. + if (instance) {
  132914. + vc_vchi_audio_deinit(instance);
  132915. + alsa_stream->instance = NULL;
  132916. + }
  132917. + LOG_DBG(" .. OUT\n");
  132918. + return ret;
  132919. +}
  132920. +
  132921. +int bcm2835_audio_write_worker(bcm2835_alsa_stream_t *alsa_stream,
  132922. + uint32_t count, void *src)
  132923. +{
  132924. + VC_AUDIO_MSG_T m;
  132925. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  132926. + int32_t success;
  132927. + int ret;
  132928. +
  132929. + LOG_DBG(" .. IN\n");
  132930. +
  132931. + LOG_INFO(" Writing %d bytes from %p\n", count, src);
  132932. +
  132933. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  132934. + {
  132935. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  132936. + return -EINTR;
  132937. + }
  132938. + vchi_service_use(instance->vchi_handle[0]);
  132939. +
  132940. + if ( instance->peer_version==0 && vchi_get_peer_version(instance->vchi_handle[0], &instance->peer_version) == 0 ) {
  132941. + LOG_DBG("%s: client version %d connected\n", __func__, instance->peer_version);
  132942. + }
  132943. + m.type = VC_AUDIO_MSG_TYPE_WRITE;
  132944. + m.u.write.count = count;
  132945. + // old version uses bulk, new version uses control
  132946. + m.u.write.max_packet = instance->peer_version < 2 || force_bulk ? 0:4000;
  132947. + m.u.write.callback = alsa_stream->fifo_irq_handler;
  132948. + m.u.write.cookie = alsa_stream;
  132949. + m.u.write.silence = src == NULL;
  132950. +
  132951. + /* Send the message to the videocore */
  132952. + success = vchi_msg_queue(instance->vchi_handle[0],
  132953. + &m, sizeof m,
  132954. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  132955. +
  132956. + if (success != 0) {
  132957. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)\n",
  132958. + __func__, success);
  132959. +
  132960. + ret = -1;
  132961. + goto unlock;
  132962. + }
  132963. + if (!m.u.write.silence) {
  132964. + if (m.u.write.max_packet == 0) {
  132965. + /* Send the message to the videocore */
  132966. + success = vchi_bulk_queue_transmit(instance->vchi_handle[0],
  132967. + src, count,
  132968. + 0 *
  132969. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED
  132970. + +
  132971. + 1 *
  132972. + VCHI_FLAGS_BLOCK_UNTIL_DATA_READ,
  132973. + NULL);
  132974. + } else {
  132975. + while (count > 0) {
  132976. + int bytes = min((int)m.u.write.max_packet, (int)count);
  132977. + success = vchi_msg_queue(instance->vchi_handle[0],
  132978. + src, bytes,
  132979. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  132980. + src = (char *)src + bytes;
  132981. + count -= bytes;
  132982. + }
  132983. + }
  132984. + if (success != 0) {
  132985. + LOG_ERR
  132986. + ("%s: failed on vchi_bulk_queue_transmit (status=%d)\n",
  132987. + __func__, success);
  132988. +
  132989. + ret = -1;
  132990. + goto unlock;
  132991. + }
  132992. + }
  132993. + ret = 0;
  132994. +
  132995. +unlock:
  132996. + vchi_service_release(instance->vchi_handle[0]);
  132997. + mutex_unlock(&instance->vchi_mutex);
  132998. + LOG_DBG(" .. OUT\n");
  132999. + return ret;
  133000. +}
  133001. +
  133002. +/**
  133003. + * Returns all buffers from arm->vc
  133004. + */
  133005. +void bcm2835_audio_flush_buffers(bcm2835_alsa_stream_t * alsa_stream)
  133006. +{
  133007. + LOG_DBG(" .. IN\n");
  133008. + LOG_DBG(" .. OUT\n");
  133009. + return;
  133010. +}
  133011. +
  133012. +/**
  133013. + * Forces VC to flush(drop) its filled playback buffers and
  133014. + * return them the us. (VC->ARM)
  133015. + */
  133016. +void bcm2835_audio_flush_playback_buffers(bcm2835_alsa_stream_t * alsa_stream)
  133017. +{
  133018. + LOG_DBG(" .. IN\n");
  133019. + LOG_DBG(" .. OUT\n");
  133020. +}
  133021. +
  133022. +uint32_t bcm2835_audio_retrieve_buffers(bcm2835_alsa_stream_t * alsa_stream)
  133023. +{
  133024. + uint32_t count = atomic_read(&alsa_stream->retrieved);
  133025. + atomic_sub(count, &alsa_stream->retrieved);
  133026. + return count;
  133027. +}
  133028. +
  133029. +module_param(force_bulk, bool, 0444);
  133030. +MODULE_PARM_DESC(force_bulk, "Force use of vchiq bulk for audio");
  133031. diff -Nur linux-3.18.8/sound/arm/Kconfig linux-rpi/sound/arm/Kconfig
  133032. --- linux-3.18.8/sound/arm/Kconfig 2015-02-27 02:49:36.000000000 +0100
  133033. +++ linux-rpi/sound/arm/Kconfig 2015-03-05 14:40:19.021715791 +0100
  133034. @@ -39,5 +39,12 @@
  133035. Say Y or M if you want to support any AC97 codec attached to
  133036. the PXA2xx AC97 interface.
  133037. +config SND_BCM2835
  133038. + tristate "BCM2835 ALSA driver"
  133039. + depends on (ARCH_BCM2708 || ARCH_BCM2709) && BCM2708_VCHIQ && SND
  133040. + select SND_PCM
  133041. + help
  133042. + Say Y or M if you want to support BCM2835 Alsa pcm card driver
  133043. +
  133044. endif # SND_ARM
  133045. diff -Nur linux-3.18.8/sound/arm/Makefile linux-rpi/sound/arm/Makefile
  133046. --- linux-3.18.8/sound/arm/Makefile 2015-02-27 02:49:36.000000000 +0100
  133047. +++ linux-rpi/sound/arm/Makefile 2015-03-05 14:40:19.021715791 +0100
  133048. @@ -14,3 +14,8 @@
  133049. obj-$(CONFIG_SND_PXA2XX_AC97) += snd-pxa2xx-ac97.o
  133050. snd-pxa2xx-ac97-objs := pxa2xx-ac97.o
  133051. +
  133052. +obj-$(CONFIG_SND_BCM2835) += snd-bcm2835.o
  133053. +snd-bcm2835-objs := bcm2835.o bcm2835-ctl.o bcm2835-pcm.o bcm2835-vchiq.o
  133054. +
  133055. +ccflags-y += -Idrivers/misc/vc04_services -Idrivers/misc/vc04_services/interface/vcos/linuxkernel -D__VCCOREVER__=0x04000000
  133056. diff -Nur linux-3.18.8/sound/arm/vc_vchi_audioserv_defs.h linux-rpi/sound/arm/vc_vchi_audioserv_defs.h
  133057. --- linux-3.18.8/sound/arm/vc_vchi_audioserv_defs.h 1970-01-01 01:00:00.000000000 +0100
  133058. +++ linux-rpi/sound/arm/vc_vchi_audioserv_defs.h 2015-03-05 14:40:19.021715791 +0100
  133059. @@ -0,0 +1,116 @@
  133060. +/*****************************************************************************
  133061. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  133062. +*
  133063. +* Unless you and Broadcom execute a separate written software license
  133064. +* agreement governing use of this software, this software is licensed to you
  133065. +* under the terms of the GNU General Public License version 2, available at
  133066. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  133067. +*
  133068. +* Notwithstanding the above, under no circumstances may you combine this
  133069. +* software in any way with any other Broadcom software provided under a
  133070. +* license other than the GPL, without Broadcom's express prior written
  133071. +* consent.
  133072. +*****************************************************************************/
  133073. +
  133074. +#ifndef _VC_AUDIO_DEFS_H_
  133075. +#define _VC_AUDIO_DEFS_H_
  133076. +
  133077. +#define VC_AUDIOSERV_MIN_VER 1
  133078. +#define VC_AUDIOSERV_VER 2
  133079. +
  133080. +// FourCC code used for VCHI connection
  133081. +#define VC_AUDIO_SERVER_NAME MAKE_FOURCC("AUDS")
  133082. +
  133083. +// Maximum message length
  133084. +#define VC_AUDIO_MAX_MSG_LEN (sizeof( VC_AUDIO_MSG_T ))
  133085. +
  133086. +// List of screens that are currently supported
  133087. +// All message types supported for HOST->VC direction
  133088. +typedef enum {
  133089. + VC_AUDIO_MSG_TYPE_RESULT, // Generic result
  133090. + VC_AUDIO_MSG_TYPE_COMPLETE, // Generic result
  133091. + VC_AUDIO_MSG_TYPE_CONFIG, // Configure audio
  133092. + VC_AUDIO_MSG_TYPE_CONTROL, // Configure audio
  133093. + VC_AUDIO_MSG_TYPE_OPEN, // Configure audio
  133094. + VC_AUDIO_MSG_TYPE_CLOSE, // Configure audio
  133095. + VC_AUDIO_MSG_TYPE_START, // Configure audio
  133096. + VC_AUDIO_MSG_TYPE_STOP, // Configure audio
  133097. + VC_AUDIO_MSG_TYPE_WRITE, // Configure audio
  133098. + VC_AUDIO_MSG_TYPE_MAX
  133099. +} VC_AUDIO_MSG_TYPE;
  133100. +
  133101. +// configure the audio
  133102. +typedef struct {
  133103. + uint32_t channels;
  133104. + uint32_t samplerate;
  133105. + uint32_t bps;
  133106. +
  133107. +} VC_AUDIO_CONFIG_T;
  133108. +
  133109. +typedef struct {
  133110. + uint32_t volume;
  133111. + uint32_t dest;
  133112. +
  133113. +} VC_AUDIO_CONTROL_T;
  133114. +
  133115. +// audio
  133116. +typedef struct {
  133117. + uint32_t dummy;
  133118. +
  133119. +} VC_AUDIO_OPEN_T;
  133120. +
  133121. +// audio
  133122. +typedef struct {
  133123. + uint32_t dummy;
  133124. +
  133125. +} VC_AUDIO_CLOSE_T;
  133126. +// audio
  133127. +typedef struct {
  133128. + uint32_t dummy;
  133129. +
  133130. +} VC_AUDIO_START_T;
  133131. +// audio
  133132. +typedef struct {
  133133. + uint32_t draining;
  133134. +
  133135. +} VC_AUDIO_STOP_T;
  133136. +
  133137. +// configure the write audio samples
  133138. +typedef struct {
  133139. + uint32_t count; // in bytes
  133140. + void *callback;
  133141. + void *cookie;
  133142. + uint16_t silence;
  133143. + uint16_t max_packet;
  133144. +} VC_AUDIO_WRITE_T;
  133145. +
  133146. +// Generic result for a request (VC->HOST)
  133147. +typedef struct {
  133148. + int32_t success; // Success value
  133149. +
  133150. +} VC_AUDIO_RESULT_T;
  133151. +
  133152. +// Generic result for a request (VC->HOST)
  133153. +typedef struct {
  133154. + int32_t count; // Success value
  133155. + void *callback;
  133156. + void *cookie;
  133157. +} VC_AUDIO_COMPLETE_T;
  133158. +
  133159. +// Message header for all messages in HOST->VC direction
  133160. +typedef struct {
  133161. + int32_t type; // Message type (VC_AUDIO_MSG_TYPE)
  133162. + union {
  133163. + VC_AUDIO_CONFIG_T config;
  133164. + VC_AUDIO_CONTROL_T control;
  133165. + VC_AUDIO_OPEN_T open;
  133166. + VC_AUDIO_CLOSE_T close;
  133167. + VC_AUDIO_START_T start;
  133168. + VC_AUDIO_STOP_T stop;
  133169. + VC_AUDIO_WRITE_T write;
  133170. + VC_AUDIO_RESULT_T result;
  133171. + VC_AUDIO_COMPLETE_T complete;
  133172. + } u;
  133173. +} VC_AUDIO_MSG_T;
  133174. +
  133175. +#endif // _VC_AUDIO_DEFS_H_
  133176. diff -Nur linux-3.18.8/sound/soc/bcm/bcm2708-i2s.c linux-rpi/sound/soc/bcm/bcm2708-i2s.c
  133177. --- linux-3.18.8/sound/soc/bcm/bcm2708-i2s.c 1970-01-01 01:00:00.000000000 +0100
  133178. +++ linux-rpi/sound/soc/bcm/bcm2708-i2s.c 2015-03-05 14:40:19.313715789 +0100
  133179. @@ -0,0 +1,1009 @@
  133180. +/*
  133181. + * ALSA SoC I2S Audio Layer for Broadcom BCM2708 SoC
  133182. + *
  133183. + * Author: Florian Meier <florian.meier@koalo.de>
  133184. + * Copyright 2013
  133185. + *
  133186. + * Based on
  133187. + * Raspberry Pi PCM I2S ALSA Driver
  133188. + * Copyright (c) by Phil Poole 2013
  133189. + *
  133190. + * ALSA SoC I2S (McBSP) Audio Layer for TI DAVINCI processor
  133191. + * Vladimir Barinov, <vbarinov@embeddedalley.com>
  133192. + * Copyright (C) 2007 MontaVista Software, Inc., <source@mvista.com>
  133193. + *
  133194. + * OMAP ALSA SoC DAI driver using McBSP port
  133195. + * Copyright (C) 2008 Nokia Corporation
  133196. + * Contact: Jarkko Nikula <jarkko.nikula@bitmer.com>
  133197. + * Peter Ujfalusi <peter.ujfalusi@ti.com>
  133198. + *
  133199. + * Freescale SSI ALSA SoC Digital Audio Interface (DAI) driver
  133200. + * Author: Timur Tabi <timur@freescale.com>
  133201. + * Copyright 2007-2010 Freescale Semiconductor, Inc.
  133202. + *
  133203. + * This program is free software; you can redistribute it and/or
  133204. + * modify it under the terms of the GNU General Public License
  133205. + * version 2 as published by the Free Software Foundation.
  133206. + *
  133207. + * This program is distributed in the hope that it will be useful, but
  133208. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  133209. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  133210. + * General Public License for more details.
  133211. + */
  133212. +
  133213. +#include "bcm2708-i2s.h"
  133214. +
  133215. +#include <linux/init.h>
  133216. +#include <linux/module.h>
  133217. +#include <linux/device.h>
  133218. +#include <linux/slab.h>
  133219. +#include <linux/delay.h>
  133220. +#include <linux/io.h>
  133221. +#include <linux/clk.h>
  133222. +#include <mach/gpio.h>
  133223. +
  133224. +#include <sound/core.h>
  133225. +#include <sound/pcm.h>
  133226. +#include <sound/pcm_params.h>
  133227. +#include <sound/initval.h>
  133228. +#include <sound/soc.h>
  133229. +#include <sound/dmaengine_pcm.h>
  133230. +
  133231. +#include <asm/system_info.h>
  133232. +
  133233. +/* Clock registers */
  133234. +#define BCM2708_CLK_PCMCTL_REG 0x00
  133235. +#define BCM2708_CLK_PCMDIV_REG 0x04
  133236. +
  133237. +/* Clock register settings */
  133238. +#define BCM2708_CLK_PASSWD (0x5a000000)
  133239. +#define BCM2708_CLK_PASSWD_MASK (0xff000000)
  133240. +#define BCM2708_CLK_MASH(v) ((v) << 9)
  133241. +#define BCM2708_CLK_FLIP BIT(8)
  133242. +#define BCM2708_CLK_BUSY BIT(7)
  133243. +#define BCM2708_CLK_KILL BIT(5)
  133244. +#define BCM2708_CLK_ENAB BIT(4)
  133245. +#define BCM2708_CLK_SRC(v) (v)
  133246. +
  133247. +#define BCM2708_CLK_SHIFT (12)
  133248. +#define BCM2708_CLK_DIVI(v) ((v) << BCM2708_CLK_SHIFT)
  133249. +#define BCM2708_CLK_DIVF(v) (v)
  133250. +#define BCM2708_CLK_DIVF_MASK (0xFFF)
  133251. +
  133252. +enum {
  133253. + BCM2708_CLK_MASH_0 = 0,
  133254. + BCM2708_CLK_MASH_1,
  133255. + BCM2708_CLK_MASH_2,
  133256. + BCM2708_CLK_MASH_3,
  133257. +};
  133258. +
  133259. +enum {
  133260. + BCM2708_CLK_SRC_GND = 0,
  133261. + BCM2708_CLK_SRC_OSC,
  133262. + BCM2708_CLK_SRC_DBG0,
  133263. + BCM2708_CLK_SRC_DBG1,
  133264. + BCM2708_CLK_SRC_PLLA,
  133265. + BCM2708_CLK_SRC_PLLC,
  133266. + BCM2708_CLK_SRC_PLLD,
  133267. + BCM2708_CLK_SRC_HDMI,
  133268. +};
  133269. +
  133270. +/* Most clocks are not useable (freq = 0) */
  133271. +static const unsigned int bcm2708_clk_freq[BCM2708_CLK_SRC_HDMI+1] = {
  133272. + [BCM2708_CLK_SRC_GND] = 0,
  133273. + [BCM2708_CLK_SRC_OSC] = 19200000,
  133274. + [BCM2708_CLK_SRC_DBG0] = 0,
  133275. + [BCM2708_CLK_SRC_DBG1] = 0,
  133276. + [BCM2708_CLK_SRC_PLLA] = 0,
  133277. + [BCM2708_CLK_SRC_PLLC] = 0,
  133278. + [BCM2708_CLK_SRC_PLLD] = 500000000,
  133279. + [BCM2708_CLK_SRC_HDMI] = 0,
  133280. +};
  133281. +
  133282. +/* I2S registers */
  133283. +#define BCM2708_I2S_CS_A_REG 0x00
  133284. +#define BCM2708_I2S_FIFO_A_REG 0x04
  133285. +#define BCM2708_I2S_MODE_A_REG 0x08
  133286. +#define BCM2708_I2S_RXC_A_REG 0x0c
  133287. +#define BCM2708_I2S_TXC_A_REG 0x10
  133288. +#define BCM2708_I2S_DREQ_A_REG 0x14
  133289. +#define BCM2708_I2S_INTEN_A_REG 0x18
  133290. +#define BCM2708_I2S_INTSTC_A_REG 0x1c
  133291. +#define BCM2708_I2S_GRAY_REG 0x20
  133292. +
  133293. +/* I2S register settings */
  133294. +#define BCM2708_I2S_STBY BIT(25)
  133295. +#define BCM2708_I2S_SYNC BIT(24)
  133296. +#define BCM2708_I2S_RXSEX BIT(23)
  133297. +#define BCM2708_I2S_RXF BIT(22)
  133298. +#define BCM2708_I2S_TXE BIT(21)
  133299. +#define BCM2708_I2S_RXD BIT(20)
  133300. +#define BCM2708_I2S_TXD BIT(19)
  133301. +#define BCM2708_I2S_RXR BIT(18)
  133302. +#define BCM2708_I2S_TXW BIT(17)
  133303. +#define BCM2708_I2S_CS_RXERR BIT(16)
  133304. +#define BCM2708_I2S_CS_TXERR BIT(15)
  133305. +#define BCM2708_I2S_RXSYNC BIT(14)
  133306. +#define BCM2708_I2S_TXSYNC BIT(13)
  133307. +#define BCM2708_I2S_DMAEN BIT(9)
  133308. +#define BCM2708_I2S_RXTHR(v) ((v) << 7)
  133309. +#define BCM2708_I2S_TXTHR(v) ((v) << 5)
  133310. +#define BCM2708_I2S_RXCLR BIT(4)
  133311. +#define BCM2708_I2S_TXCLR BIT(3)
  133312. +#define BCM2708_I2S_TXON BIT(2)
  133313. +#define BCM2708_I2S_RXON BIT(1)
  133314. +#define BCM2708_I2S_EN (1)
  133315. +
  133316. +#define BCM2708_I2S_CLKDIS BIT(28)
  133317. +#define BCM2708_I2S_PDMN BIT(27)
  133318. +#define BCM2708_I2S_PDME BIT(26)
  133319. +#define BCM2708_I2S_FRXP BIT(25)
  133320. +#define BCM2708_I2S_FTXP BIT(24)
  133321. +#define BCM2708_I2S_CLKM BIT(23)
  133322. +#define BCM2708_I2S_CLKI BIT(22)
  133323. +#define BCM2708_I2S_FSM BIT(21)
  133324. +#define BCM2708_I2S_FSI BIT(20)
  133325. +#define BCM2708_I2S_FLEN(v) ((v) << 10)
  133326. +#define BCM2708_I2S_FSLEN(v) (v)
  133327. +
  133328. +#define BCM2708_I2S_CHWEX BIT(15)
  133329. +#define BCM2708_I2S_CHEN BIT(14)
  133330. +#define BCM2708_I2S_CHPOS(v) ((v) << 4)
  133331. +#define BCM2708_I2S_CHWID(v) (v)
  133332. +#define BCM2708_I2S_CH1(v) ((v) << 16)
  133333. +#define BCM2708_I2S_CH2(v) (v)
  133334. +
  133335. +#define BCM2708_I2S_TX_PANIC(v) ((v) << 24)
  133336. +#define BCM2708_I2S_RX_PANIC(v) ((v) << 16)
  133337. +#define BCM2708_I2S_TX(v) ((v) << 8)
  133338. +#define BCM2708_I2S_RX(v) (v)
  133339. +
  133340. +#define BCM2708_I2S_INT_RXERR BIT(3)
  133341. +#define BCM2708_I2S_INT_TXERR BIT(2)
  133342. +#define BCM2708_I2S_INT_RXR BIT(1)
  133343. +#define BCM2708_I2S_INT_TXW BIT(0)
  133344. +
  133345. +/* I2S DMA interface */
  133346. +#define BCM2708_I2S_FIFO_PHYSICAL_ADDR 0x7E203004
  133347. +#define BCM2708_DMA_DREQ_PCM_TX 2
  133348. +#define BCM2708_DMA_DREQ_PCM_RX 3
  133349. +
  133350. +/* I2S pin configuration */
  133351. +static int bcm2708_i2s_gpio=BCM2708_I2S_GPIO_AUTO;
  133352. +
  133353. +/* General device struct */
  133354. +struct bcm2708_i2s_dev {
  133355. + struct device *dev;
  133356. + struct snd_dmaengine_dai_dma_data dma_data[2];
  133357. + unsigned int fmt;
  133358. + unsigned int bclk_ratio;
  133359. +
  133360. + struct regmap *i2s_regmap;
  133361. + struct regmap *clk_regmap;
  133362. +};
  133363. +
  133364. +void bcm2708_i2s_set_gpio(int gpio) {
  133365. + bcm2708_i2s_gpio=gpio;
  133366. +}
  133367. +EXPORT_SYMBOL(bcm2708_i2s_set_gpio);
  133368. +
  133369. +
  133370. +static void bcm2708_i2s_start_clock(struct bcm2708_i2s_dev *dev)
  133371. +{
  133372. + /* Start the clock if in master mode */
  133373. + unsigned int master = dev->fmt & SND_SOC_DAIFMT_MASTER_MASK;
  133374. +
  133375. + switch (master) {
  133376. + case SND_SOC_DAIFMT_CBS_CFS:
  133377. + case SND_SOC_DAIFMT_CBS_CFM:
  133378. + regmap_update_bits(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG,
  133379. + BCM2708_CLK_PASSWD_MASK | BCM2708_CLK_ENAB,
  133380. + BCM2708_CLK_PASSWD | BCM2708_CLK_ENAB);
  133381. + break;
  133382. + default:
  133383. + break;
  133384. + }
  133385. +}
  133386. +
  133387. +static void bcm2708_i2s_stop_clock(struct bcm2708_i2s_dev *dev)
  133388. +{
  133389. + uint32_t clkreg;
  133390. + int timeout = 1000;
  133391. +
  133392. + /* Stop clock */
  133393. + regmap_update_bits(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG,
  133394. + BCM2708_CLK_PASSWD_MASK | BCM2708_CLK_ENAB,
  133395. + BCM2708_CLK_PASSWD);
  133396. +
  133397. + /* Wait for the BUSY flag going down */
  133398. + while (--timeout) {
  133399. + regmap_read(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG, &clkreg);
  133400. + if (!(clkreg & BCM2708_CLK_BUSY))
  133401. + break;
  133402. + }
  133403. +
  133404. + if (!timeout) {
  133405. + /* KILL the clock */
  133406. + dev_err(dev->dev, "I2S clock didn't stop. Kill the clock!\n");
  133407. + regmap_update_bits(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG,
  133408. + BCM2708_CLK_KILL | BCM2708_CLK_PASSWD_MASK,
  133409. + BCM2708_CLK_KILL | BCM2708_CLK_PASSWD);
  133410. + }
  133411. +}
  133412. +
  133413. +static void bcm2708_i2s_clear_fifos(struct bcm2708_i2s_dev *dev,
  133414. + bool tx, bool rx)
  133415. +{
  133416. + int timeout = 1000;
  133417. + uint32_t syncval;
  133418. + uint32_t csreg;
  133419. + uint32_t i2s_active_state;
  133420. + uint32_t clkreg;
  133421. + uint32_t clk_active_state;
  133422. + uint32_t off;
  133423. + uint32_t clr;
  133424. +
  133425. + off = tx ? BCM2708_I2S_TXON : 0;
  133426. + off |= rx ? BCM2708_I2S_RXON : 0;
  133427. +
  133428. + clr = tx ? BCM2708_I2S_TXCLR : 0;
  133429. + clr |= rx ? BCM2708_I2S_RXCLR : 0;
  133430. +
  133431. + /* Backup the current state */
  133432. + regmap_read(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, &csreg);
  133433. + i2s_active_state = csreg & (BCM2708_I2S_RXON | BCM2708_I2S_TXON);
  133434. +
  133435. + regmap_read(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG, &clkreg);
  133436. + clk_active_state = clkreg & BCM2708_CLK_ENAB;
  133437. +
  133438. + /* Start clock if not running */
  133439. + if (!clk_active_state) {
  133440. + regmap_update_bits(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG,
  133441. + BCM2708_CLK_PASSWD_MASK | BCM2708_CLK_ENAB,
  133442. + BCM2708_CLK_PASSWD | BCM2708_CLK_ENAB);
  133443. + }
  133444. +
  133445. + /* Stop I2S module */
  133446. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, off, 0);
  133447. +
  133448. + /*
  133449. + * Clear the FIFOs
  133450. + * Requires at least 2 PCM clock cycles to take effect
  133451. + */
  133452. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, clr, clr);
  133453. +
  133454. + /* Wait for 2 PCM clock cycles */
  133455. +
  133456. + /*
  133457. + * Toggle the SYNC flag. After 2 PCM clock cycles it can be read back
  133458. + * FIXME: This does not seem to work for slave mode!
  133459. + */
  133460. + regmap_read(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, &syncval);
  133461. + syncval &= BCM2708_I2S_SYNC;
  133462. +
  133463. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG,
  133464. + BCM2708_I2S_SYNC, ~syncval);
  133465. +
  133466. + /* Wait for the SYNC flag changing it's state */
  133467. + while (--timeout) {
  133468. + regmap_read(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, &csreg);
  133469. + if ((csreg & BCM2708_I2S_SYNC) != syncval)
  133470. + break;
  133471. + }
  133472. +
  133473. + if (!timeout)
  133474. + dev_err(dev->dev, "I2S SYNC error!\n");
  133475. +
  133476. + /* Stop clock if it was not running before */
  133477. + if (!clk_active_state)
  133478. + bcm2708_i2s_stop_clock(dev);
  133479. +
  133480. + /* Restore I2S state */
  133481. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG,
  133482. + BCM2708_I2S_RXON | BCM2708_I2S_TXON, i2s_active_state);
  133483. +}
  133484. +
  133485. +static int bcm2708_i2s_set_dai_fmt(struct snd_soc_dai *dai,
  133486. + unsigned int fmt)
  133487. +{
  133488. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  133489. + dev->fmt = fmt;
  133490. + return 0;
  133491. +}
  133492. +
  133493. +static int bcm2708_i2s_set_dai_bclk_ratio(struct snd_soc_dai *dai,
  133494. + unsigned int ratio)
  133495. +{
  133496. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  133497. + dev->bclk_ratio = ratio;
  133498. + return 0;
  133499. +}
  133500. +
  133501. +
  133502. +static int bcm2708_i2s_set_function(unsigned offset, int function)
  133503. +{
  133504. + #define GPIOFSEL(x) (0x00+(x)*4)
  133505. + void __iomem *gpio = __io_address(GPIO_BASE);
  133506. + unsigned alt = function <= 3 ? function + 4: function == 4 ? 3 : 2;
  133507. + unsigned gpiodir;
  133508. + unsigned gpio_bank = offset / 10;
  133509. + unsigned gpio_field_offset = (offset - 10 * gpio_bank) * 3;
  133510. +
  133511. + if (offset >= BCM2708_NR_GPIOS)
  133512. + return -EINVAL;
  133513. +
  133514. + gpiodir = readl(gpio + GPIOFSEL(gpio_bank));
  133515. + gpiodir &= ~(7 << gpio_field_offset);
  133516. + gpiodir |= alt << gpio_field_offset;
  133517. + writel(gpiodir, gpio + GPIOFSEL(gpio_bank));
  133518. + return 0;
  133519. +}
  133520. +
  133521. +static void bcm2708_i2s_setup_gpio(void)
  133522. +{
  133523. + /*
  133524. + * This is the common way to handle the GPIO pins for
  133525. + * the Raspberry Pi.
  133526. + * TODO Better way would be to handle
  133527. + * this in the device tree!
  133528. + */
  133529. + int pin,pinconfig,startpin,alt;
  133530. +
  133531. + /* SPI is on different GPIOs on different boards */
  133532. + /* for Raspberry Pi B+, this is pin GPIO18-21, for original on 28-31 */
  133533. + if (bcm2708_i2s_gpio==BCM2708_I2S_GPIO_AUTO) {
  133534. + if ((system_rev & 0xffffff) >= 0x10) {
  133535. + /* Model B+ */
  133536. + pinconfig=BCM2708_I2S_GPIO_PIN18;
  133537. + } else {
  133538. + /* original */
  133539. + pinconfig=BCM2708_I2S_GPIO_PIN28;
  133540. + }
  133541. + } else {
  133542. + pinconfig=bcm2708_i2s_gpio;
  133543. + }
  133544. +
  133545. + if (pinconfig==BCM2708_I2S_GPIO_PIN18) {
  133546. + startpin=18;
  133547. + alt=BCM2708_I2S_GPIO_PIN18_ALT;
  133548. + } else if (pinconfig==BCM2708_I2S_GPIO_PIN28) {
  133549. + startpin=28;
  133550. + alt=BCM2708_I2S_GPIO_PIN28_ALT;
  133551. + } else {
  133552. + printk(KERN_INFO "Can't configure I2S GPIOs, unknown pin mode for I2S: %i\n",pinconfig);
  133553. + return;
  133554. + }
  133555. +
  133556. + /* configure I2S pins to correct ALT mode */
  133557. + for (pin = startpin; pin <= startpin+3; pin++) {
  133558. + bcm2708_i2s_set_function(pin, alt);
  133559. + }
  133560. +}
  133561. +
  133562. +static int bcm2708_i2s_hw_params(struct snd_pcm_substream *substream,
  133563. + struct snd_pcm_hw_params *params,
  133564. + struct snd_soc_dai *dai)
  133565. +{
  133566. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  133567. +
  133568. + unsigned int sampling_rate = params_rate(params);
  133569. + unsigned int data_length, data_delay, bclk_ratio;
  133570. + unsigned int ch1pos, ch2pos, mode, format;
  133571. + unsigned int mash = BCM2708_CLK_MASH_1;
  133572. + unsigned int divi, divf, target_frequency;
  133573. + int clk_src = -1;
  133574. + unsigned int master = dev->fmt & SND_SOC_DAIFMT_MASTER_MASK;
  133575. + bool bit_master = (master == SND_SOC_DAIFMT_CBS_CFS
  133576. + || master == SND_SOC_DAIFMT_CBS_CFM);
  133577. +
  133578. + bool frame_master = (master == SND_SOC_DAIFMT_CBS_CFS
  133579. + || master == SND_SOC_DAIFMT_CBM_CFS);
  133580. + uint32_t csreg;
  133581. +
  133582. + /*
  133583. + * If a stream is already enabled,
  133584. + * the registers are already set properly.
  133585. + */
  133586. + regmap_read(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, &csreg);
  133587. +
  133588. + if (csreg & (BCM2708_I2S_TXON | BCM2708_I2S_RXON))
  133589. + return 0;
  133590. +
  133591. +
  133592. + bcm2708_i2s_setup_gpio();
  133593. +
  133594. + /*
  133595. + * Adjust the data length according to the format.
  133596. + * We prefill the half frame length with an integer
  133597. + * divider of 2400 as explained at the clock settings.
  133598. + * Maybe it is overwritten there, if the Integer mode
  133599. + * does not apply.
  133600. + */
  133601. + switch (params_format(params)) {
  133602. + case SNDRV_PCM_FORMAT_S16_LE:
  133603. + data_length = 16;
  133604. + bclk_ratio = 50;
  133605. + break;
  133606. + case SNDRV_PCM_FORMAT_S24_LE:
  133607. + data_length = 24;
  133608. + bclk_ratio = 50;
  133609. + break;
  133610. + case SNDRV_PCM_FORMAT_S32_LE:
  133611. + data_length = 32;
  133612. + bclk_ratio = 100;
  133613. + break;
  133614. + default:
  133615. + return -EINVAL;
  133616. + }
  133617. +
  133618. + /* If bclk_ratio already set, use that one. */
  133619. + if (dev->bclk_ratio)
  133620. + bclk_ratio = dev->bclk_ratio;
  133621. +
  133622. + /*
  133623. + * Clock Settings
  133624. + *
  133625. + * The target frequency of the bit clock is
  133626. + * sampling rate * frame length
  133627. + *
  133628. + * Integer mode:
  133629. + * Sampling rates that are multiples of 8000 kHz
  133630. + * can be driven by the oscillator of 19.2 MHz
  133631. + * with an integer divider as long as the frame length
  133632. + * is an integer divider of 19200000/8000=2400 as set up above.
  133633. + * This is no longer possible if the sampling rate
  133634. + * is too high (e.g. 192 kHz), because the oscillator is too slow.
  133635. + *
  133636. + * MASH mode:
  133637. + * For all other sampling rates, it is not possible to
  133638. + * have an integer divider. Approximate the clock
  133639. + * with the MASH module that induces a slight frequency
  133640. + * variance. To minimize that it is best to have the fastest
  133641. + * clock here. That is PLLD with 500 MHz.
  133642. + */
  133643. + target_frequency = sampling_rate * bclk_ratio;
  133644. + clk_src = BCM2708_CLK_SRC_OSC;
  133645. + mash = BCM2708_CLK_MASH_0;
  133646. +
  133647. + if (bcm2708_clk_freq[clk_src] % target_frequency == 0
  133648. + && bit_master && frame_master) {
  133649. + divi = bcm2708_clk_freq[clk_src] / target_frequency;
  133650. + divf = 0;
  133651. + } else {
  133652. + uint64_t dividend;
  133653. +
  133654. + if (!dev->bclk_ratio) {
  133655. + /*
  133656. + * Overwrite bclk_ratio, because the
  133657. + * above trick is not needed or can
  133658. + * not be used.
  133659. + */
  133660. + bclk_ratio = 2 * data_length;
  133661. + }
  133662. +
  133663. + target_frequency = sampling_rate * bclk_ratio;
  133664. +
  133665. + clk_src = BCM2708_CLK_SRC_PLLD;
  133666. + mash = BCM2708_CLK_MASH_1;
  133667. +
  133668. + dividend = bcm2708_clk_freq[clk_src];
  133669. + dividend <<= BCM2708_CLK_SHIFT;
  133670. + do_div(dividend, target_frequency);
  133671. + divi = dividend >> BCM2708_CLK_SHIFT;
  133672. + divf = dividend & BCM2708_CLK_DIVF_MASK;
  133673. + }
  133674. +
  133675. + /* Clock should only be set up here if CPU is clock master */
  133676. + if (((dev->fmt & SND_SOC_DAIFMT_MASTER_MASK) == SND_SOC_DAIFMT_CBS_CFS) ||
  133677. + ((dev->fmt & SND_SOC_DAIFMT_MASTER_MASK) == SND_SOC_DAIFMT_CBS_CFM)) {
  133678. + /* Set clock divider */
  133679. + regmap_write(dev->clk_regmap, BCM2708_CLK_PCMDIV_REG, BCM2708_CLK_PASSWD
  133680. + | BCM2708_CLK_DIVI(divi)
  133681. + | BCM2708_CLK_DIVF(divf));
  133682. +
  133683. + /* Setup clock, but don't start it yet */
  133684. + regmap_write(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG, BCM2708_CLK_PASSWD
  133685. + | BCM2708_CLK_MASH(mash)
  133686. + | BCM2708_CLK_SRC(clk_src));
  133687. + }
  133688. +
  133689. + /* Setup the frame format */
  133690. + format = BCM2708_I2S_CHEN;
  133691. +
  133692. + if (data_length >= 24)
  133693. + format |= BCM2708_I2S_CHWEX;
  133694. +
  133695. + format |= BCM2708_I2S_CHWID((data_length-8)&0xf);
  133696. +
  133697. + switch (dev->fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  133698. + case SND_SOC_DAIFMT_I2S:
  133699. + data_delay = 1;
  133700. + break;
  133701. + default:
  133702. + /*
  133703. + * TODO
  133704. + * Others are possible but are not implemented at the moment.
  133705. + */
  133706. + dev_err(dev->dev, "%s:bad format\n", __func__);
  133707. + return -EINVAL;
  133708. + }
  133709. +
  133710. + ch1pos = data_delay;
  133711. + ch2pos = bclk_ratio / 2 + data_delay;
  133712. +
  133713. + switch (params_channels(params)) {
  133714. + case 2:
  133715. + format = BCM2708_I2S_CH1(format) | BCM2708_I2S_CH2(format);
  133716. + format |= BCM2708_I2S_CH1(BCM2708_I2S_CHPOS(ch1pos));
  133717. + format |= BCM2708_I2S_CH2(BCM2708_I2S_CHPOS(ch2pos));
  133718. + break;
  133719. + default:
  133720. + return -EINVAL;
  133721. + }
  133722. +
  133723. + /*
  133724. + * Set format for both streams.
  133725. + * We cannot set another frame length
  133726. + * (and therefore word length) anyway,
  133727. + * so the format will be the same.
  133728. + */
  133729. + regmap_write(dev->i2s_regmap, BCM2708_I2S_RXC_A_REG, format);
  133730. + regmap_write(dev->i2s_regmap, BCM2708_I2S_TXC_A_REG, format);
  133731. +
  133732. + /* Setup the I2S mode */
  133733. + mode = 0;
  133734. +
  133735. + if (data_length <= 16) {
  133736. + /*
  133737. + * Use frame packed mode (2 channels per 32 bit word)
  133738. + * We cannot set another frame length in the second stream
  133739. + * (and therefore word length) anyway,
  133740. + * so the format will be the same.
  133741. + */
  133742. + mode |= BCM2708_I2S_FTXP | BCM2708_I2S_FRXP;
  133743. + }
  133744. +
  133745. + mode |= BCM2708_I2S_FLEN(bclk_ratio - 1);
  133746. + mode |= BCM2708_I2S_FSLEN(bclk_ratio / 2);
  133747. +
  133748. + /* Master or slave? */
  133749. + switch (dev->fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  133750. + case SND_SOC_DAIFMT_CBS_CFS:
  133751. + /* CPU is master */
  133752. + break;
  133753. + case SND_SOC_DAIFMT_CBM_CFS:
  133754. + /*
  133755. + * CODEC is bit clock master
  133756. + * CPU is frame master
  133757. + */
  133758. + mode |= BCM2708_I2S_CLKM;
  133759. + break;
  133760. + case SND_SOC_DAIFMT_CBS_CFM:
  133761. + /*
  133762. + * CODEC is frame master
  133763. + * CPU is bit clock master
  133764. + */
  133765. + mode |= BCM2708_I2S_FSM;
  133766. + break;
  133767. + case SND_SOC_DAIFMT_CBM_CFM:
  133768. + /* CODEC is master */
  133769. + mode |= BCM2708_I2S_CLKM;
  133770. + mode |= BCM2708_I2S_FSM;
  133771. + break;
  133772. + default:
  133773. + dev_err(dev->dev, "%s:bad master\n", __func__);
  133774. + return -EINVAL;
  133775. + }
  133776. +
  133777. + /*
  133778. + * Invert clocks?
  133779. + *
  133780. + * The BCM approach seems to be inverted to the classical I2S approach.
  133781. + */
  133782. + switch (dev->fmt & SND_SOC_DAIFMT_INV_MASK) {
  133783. + case SND_SOC_DAIFMT_NB_NF:
  133784. + /* None. Therefore, both for BCM */
  133785. + mode |= BCM2708_I2S_CLKI;
  133786. + mode |= BCM2708_I2S_FSI;
  133787. + break;
  133788. + case SND_SOC_DAIFMT_IB_IF:
  133789. + /* Both. Therefore, none for BCM */
  133790. + break;
  133791. + case SND_SOC_DAIFMT_NB_IF:
  133792. + /*
  133793. + * Invert only frame sync. Therefore,
  133794. + * invert only bit clock for BCM
  133795. + */
  133796. + mode |= BCM2708_I2S_CLKI;
  133797. + break;
  133798. + case SND_SOC_DAIFMT_IB_NF:
  133799. + /*
  133800. + * Invert only bit clock. Therefore,
  133801. + * invert only frame sync for BCM
  133802. + */
  133803. + mode |= BCM2708_I2S_FSI;
  133804. + break;
  133805. + default:
  133806. + return -EINVAL;
  133807. + }
  133808. +
  133809. + regmap_write(dev->i2s_regmap, BCM2708_I2S_MODE_A_REG, mode);
  133810. +
  133811. + /* Setup the DMA parameters */
  133812. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG,
  133813. + BCM2708_I2S_RXTHR(1)
  133814. + | BCM2708_I2S_TXTHR(1)
  133815. + | BCM2708_I2S_DMAEN, 0xffffffff);
  133816. +
  133817. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_DREQ_A_REG,
  133818. + BCM2708_I2S_TX_PANIC(0x10)
  133819. + | BCM2708_I2S_RX_PANIC(0x30)
  133820. + | BCM2708_I2S_TX(0x30)
  133821. + | BCM2708_I2S_RX(0x20), 0xffffffff);
  133822. +
  133823. + /* Clear FIFOs */
  133824. + bcm2708_i2s_clear_fifos(dev, true, true);
  133825. +
  133826. + return 0;
  133827. +}
  133828. +
  133829. +static int bcm2708_i2s_prepare(struct snd_pcm_substream *substream,
  133830. + struct snd_soc_dai *dai)
  133831. +{
  133832. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  133833. + uint32_t cs_reg;
  133834. +
  133835. + bcm2708_i2s_start_clock(dev);
  133836. +
  133837. + /*
  133838. + * Clear both FIFOs if the one that should be started
  133839. + * is not empty at the moment. This should only happen
  133840. + * after overrun. Otherwise, hw_params would have cleared
  133841. + * the FIFO.
  133842. + */
  133843. + regmap_read(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, &cs_reg);
  133844. +
  133845. + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK
  133846. + && !(cs_reg & BCM2708_I2S_TXE))
  133847. + bcm2708_i2s_clear_fifos(dev, true, false);
  133848. + else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE
  133849. + && (cs_reg & BCM2708_I2S_RXD))
  133850. + bcm2708_i2s_clear_fifos(dev, false, true);
  133851. +
  133852. + return 0;
  133853. +}
  133854. +
  133855. +static void bcm2708_i2s_stop(struct bcm2708_i2s_dev *dev,
  133856. + struct snd_pcm_substream *substream,
  133857. + struct snd_soc_dai *dai)
  133858. +{
  133859. + uint32_t mask;
  133860. +
  133861. + if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
  133862. + mask = BCM2708_I2S_RXON;
  133863. + else
  133864. + mask = BCM2708_I2S_TXON;
  133865. +
  133866. + regmap_update_bits(dev->i2s_regmap,
  133867. + BCM2708_I2S_CS_A_REG, mask, 0);
  133868. +
  133869. + /* Stop also the clock when not SND_SOC_DAIFMT_CONT */
  133870. + if (!dai->active && !(dev->fmt & SND_SOC_DAIFMT_CONT))
  133871. + bcm2708_i2s_stop_clock(dev);
  133872. +}
  133873. +
  133874. +static int bcm2708_i2s_trigger(struct snd_pcm_substream *substream, int cmd,
  133875. + struct snd_soc_dai *dai)
  133876. +{
  133877. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  133878. + uint32_t mask;
  133879. +
  133880. + switch (cmd) {
  133881. + case SNDRV_PCM_TRIGGER_START:
  133882. + case SNDRV_PCM_TRIGGER_RESUME:
  133883. + case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  133884. + bcm2708_i2s_start_clock(dev);
  133885. +
  133886. + if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
  133887. + mask = BCM2708_I2S_RXON;
  133888. + else
  133889. + mask = BCM2708_I2S_TXON;
  133890. +
  133891. + regmap_update_bits(dev->i2s_regmap,
  133892. + BCM2708_I2S_CS_A_REG, mask, mask);
  133893. + break;
  133894. +
  133895. + case SNDRV_PCM_TRIGGER_STOP:
  133896. + case SNDRV_PCM_TRIGGER_SUSPEND:
  133897. + case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  133898. + bcm2708_i2s_stop(dev, substream, dai);
  133899. + break;
  133900. + default:
  133901. + return -EINVAL;
  133902. + }
  133903. +
  133904. + return 0;
  133905. +}
  133906. +
  133907. +static int bcm2708_i2s_startup(struct snd_pcm_substream *substream,
  133908. + struct snd_soc_dai *dai)
  133909. +{
  133910. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  133911. +
  133912. + if (dai->active)
  133913. + return 0;
  133914. +
  133915. + /* Should this still be running stop it */
  133916. + bcm2708_i2s_stop_clock(dev);
  133917. +
  133918. + /* Enable PCM block */
  133919. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG,
  133920. + BCM2708_I2S_EN, BCM2708_I2S_EN);
  133921. +
  133922. + /*
  133923. + * Disable STBY.
  133924. + * Requires at least 4 PCM clock cycles to take effect.
  133925. + */
  133926. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG,
  133927. + BCM2708_I2S_STBY, BCM2708_I2S_STBY);
  133928. +
  133929. + return 0;
  133930. +}
  133931. +
  133932. +static void bcm2708_i2s_shutdown(struct snd_pcm_substream *substream,
  133933. + struct snd_soc_dai *dai)
  133934. +{
  133935. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  133936. +
  133937. + bcm2708_i2s_stop(dev, substream, dai);
  133938. +
  133939. + /* If both streams are stopped, disable module and clock */
  133940. + if (dai->active)
  133941. + return;
  133942. +
  133943. + /* Disable the module */
  133944. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG,
  133945. + BCM2708_I2S_EN, 0);
  133946. +
  133947. + /*
  133948. + * Stopping clock is necessary, because stop does
  133949. + * not stop the clock when SND_SOC_DAIFMT_CONT
  133950. + */
  133951. + bcm2708_i2s_stop_clock(dev);
  133952. +}
  133953. +
  133954. +static const struct snd_soc_dai_ops bcm2708_i2s_dai_ops = {
  133955. + .startup = bcm2708_i2s_startup,
  133956. + .shutdown = bcm2708_i2s_shutdown,
  133957. + .prepare = bcm2708_i2s_prepare,
  133958. + .trigger = bcm2708_i2s_trigger,
  133959. + .hw_params = bcm2708_i2s_hw_params,
  133960. + .set_fmt = bcm2708_i2s_set_dai_fmt,
  133961. + .set_bclk_ratio = bcm2708_i2s_set_dai_bclk_ratio
  133962. +};
  133963. +
  133964. +static int bcm2708_i2s_dai_probe(struct snd_soc_dai *dai)
  133965. +{
  133966. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  133967. +
  133968. + dai->playback_dma_data = &dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK];
  133969. + dai->capture_dma_data = &dev->dma_data[SNDRV_PCM_STREAM_CAPTURE];
  133970. +
  133971. + return 0;
  133972. +}
  133973. +
  133974. +static struct snd_soc_dai_driver bcm2708_i2s_dai = {
  133975. + .name = "bcm2708-i2s",
  133976. + .probe = bcm2708_i2s_dai_probe,
  133977. + .playback = {
  133978. + .channels_min = 2,
  133979. + .channels_max = 2,
  133980. + .rates = SNDRV_PCM_RATE_8000_192000,
  133981. + .formats = SNDRV_PCM_FMTBIT_S16_LE
  133982. + | SNDRV_PCM_FMTBIT_S24_LE
  133983. + | SNDRV_PCM_FMTBIT_S32_LE
  133984. + },
  133985. + .capture = {
  133986. + .channels_min = 2,
  133987. + .channels_max = 2,
  133988. + .rates = SNDRV_PCM_RATE_8000_192000,
  133989. + .formats = SNDRV_PCM_FMTBIT_S16_LE
  133990. + | SNDRV_PCM_FMTBIT_S24_LE
  133991. + | SNDRV_PCM_FMTBIT_S32_LE
  133992. + },
  133993. + .ops = &bcm2708_i2s_dai_ops,
  133994. + .symmetric_rates = 1
  133995. +};
  133996. +
  133997. +static bool bcm2708_i2s_volatile_reg(struct device *dev, unsigned int reg)
  133998. +{
  133999. + switch (reg) {
  134000. + case BCM2708_I2S_CS_A_REG:
  134001. + case BCM2708_I2S_FIFO_A_REG:
  134002. + case BCM2708_I2S_INTSTC_A_REG:
  134003. + case BCM2708_I2S_GRAY_REG:
  134004. + return true;
  134005. + default:
  134006. + return false;
  134007. + };
  134008. +}
  134009. +
  134010. +static bool bcm2708_i2s_precious_reg(struct device *dev, unsigned int reg)
  134011. +{
  134012. + switch (reg) {
  134013. + case BCM2708_I2S_FIFO_A_REG:
  134014. + return true;
  134015. + default:
  134016. + return false;
  134017. + };
  134018. +}
  134019. +
  134020. +static bool bcm2708_clk_volatile_reg(struct device *dev, unsigned int reg)
  134021. +{
  134022. + switch (reg) {
  134023. + case BCM2708_CLK_PCMCTL_REG:
  134024. + return true;
  134025. + default:
  134026. + return false;
  134027. + };
  134028. +}
  134029. +
  134030. +static const struct regmap_config bcm2708_regmap_config[] = {
  134031. + {
  134032. + .reg_bits = 32,
  134033. + .reg_stride = 4,
  134034. + .val_bits = 32,
  134035. + .max_register = BCM2708_I2S_GRAY_REG,
  134036. + .precious_reg = bcm2708_i2s_precious_reg,
  134037. + .volatile_reg = bcm2708_i2s_volatile_reg,
  134038. + .cache_type = REGCACHE_RBTREE,
  134039. + .name = "i2s",
  134040. + },
  134041. + {
  134042. + .reg_bits = 32,
  134043. + .reg_stride = 4,
  134044. + .val_bits = 32,
  134045. + .max_register = BCM2708_CLK_PCMDIV_REG,
  134046. + .volatile_reg = bcm2708_clk_volatile_reg,
  134047. + .cache_type = REGCACHE_RBTREE,
  134048. + .name = "clk",
  134049. + },
  134050. +};
  134051. +
  134052. +static const struct snd_soc_component_driver bcm2708_i2s_component = {
  134053. + .name = "bcm2708-i2s-comp",
  134054. +};
  134055. +
  134056. +static const struct snd_pcm_hardware bcm2708_pcm_hardware = {
  134057. + .info = SNDRV_PCM_INFO_INTERLEAVED |
  134058. + SNDRV_PCM_INFO_JOINT_DUPLEX,
  134059. + .formats = SNDRV_PCM_FMTBIT_S16_LE |
  134060. + SNDRV_PCM_FMTBIT_S24_LE |
  134061. + SNDRV_PCM_FMTBIT_S32_LE,
  134062. + .period_bytes_min = 32,
  134063. + .period_bytes_max = 64 * PAGE_SIZE,
  134064. + .periods_min = 2,
  134065. + .periods_max = 255,
  134066. + .buffer_bytes_max = 128 * PAGE_SIZE,
  134067. +};
  134068. +
  134069. +static const struct snd_dmaengine_pcm_config bcm2708_dmaengine_pcm_config = {
  134070. + .prepare_slave_config = snd_dmaengine_pcm_prepare_slave_config,
  134071. + .pcm_hardware = &bcm2708_pcm_hardware,
  134072. + .prealloc_buffer_size = 256 * PAGE_SIZE,
  134073. +};
  134074. +
  134075. +
  134076. +static int bcm2708_i2s_probe(struct platform_device *pdev)
  134077. +{
  134078. + struct bcm2708_i2s_dev *dev;
  134079. + int i;
  134080. + int ret;
  134081. + struct regmap *regmap[2];
  134082. + struct resource *mem[2];
  134083. +
  134084. + /* Request both ioareas */
  134085. + for (i = 0; i <= 1; i++) {
  134086. + void __iomem *base;
  134087. +
  134088. + mem[i] = platform_get_resource(pdev, IORESOURCE_MEM, i);
  134089. + base = devm_ioremap_resource(&pdev->dev, mem[i]);
  134090. + if (IS_ERR(base))
  134091. + return PTR_ERR(base);
  134092. +
  134093. + regmap[i] = devm_regmap_init_mmio(&pdev->dev, base,
  134094. + &bcm2708_regmap_config[i]);
  134095. + if (IS_ERR(regmap[i])) {
  134096. + dev_err(&pdev->dev, "I2S probe: regmap init failed\n");
  134097. + return PTR_ERR(regmap[i]);
  134098. + }
  134099. + }
  134100. +
  134101. + dev = devm_kzalloc(&pdev->dev, sizeof(*dev),
  134102. + GFP_KERNEL);
  134103. + if (IS_ERR(dev))
  134104. + return PTR_ERR(dev);
  134105. +
  134106. + dev->i2s_regmap = regmap[0];
  134107. + dev->clk_regmap = regmap[1];
  134108. +
  134109. + /* Set the DMA address */
  134110. + dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK].addr =
  134111. + (dma_addr_t)BCM2708_I2S_FIFO_PHYSICAL_ADDR;
  134112. +
  134113. + dev->dma_data[SNDRV_PCM_STREAM_CAPTURE].addr =
  134114. + (dma_addr_t)BCM2708_I2S_FIFO_PHYSICAL_ADDR;
  134115. +
  134116. + /* Set the DREQ */
  134117. + dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK].slave_id =
  134118. + BCM2708_DMA_DREQ_PCM_TX;
  134119. + dev->dma_data[SNDRV_PCM_STREAM_CAPTURE].slave_id =
  134120. + BCM2708_DMA_DREQ_PCM_RX;
  134121. +
  134122. + /* Set the bus width */
  134123. + dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK].addr_width =
  134124. + DMA_SLAVE_BUSWIDTH_4_BYTES;
  134125. + dev->dma_data[SNDRV_PCM_STREAM_CAPTURE].addr_width =
  134126. + DMA_SLAVE_BUSWIDTH_4_BYTES;
  134127. +
  134128. + /* Set burst */
  134129. + dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK].maxburst = 2;
  134130. + dev->dma_data[SNDRV_PCM_STREAM_CAPTURE].maxburst = 2;
  134131. +
  134132. + /* BCLK ratio - use default */
  134133. + dev->bclk_ratio = 0;
  134134. +
  134135. + /* Store the pdev */
  134136. + dev->dev = &pdev->dev;
  134137. + dev_set_drvdata(&pdev->dev, dev);
  134138. +
  134139. + ret = snd_soc_register_component(&pdev->dev,
  134140. + &bcm2708_i2s_component, &bcm2708_i2s_dai, 1);
  134141. +
  134142. + if (ret) {
  134143. + dev_err(&pdev->dev, "Could not register DAI: %d\n", ret);
  134144. + ret = -ENOMEM;
  134145. + return ret;
  134146. + }
  134147. +
  134148. + ret = snd_dmaengine_pcm_register(&pdev->dev,
  134149. + &bcm2708_dmaengine_pcm_config,
  134150. + SND_DMAENGINE_PCM_FLAG_COMPAT);
  134151. + if (ret) {
  134152. + dev_err(&pdev->dev, "Could not register PCM: %d\n", ret);
  134153. + snd_soc_unregister_component(&pdev->dev);
  134154. + return ret;
  134155. + }
  134156. +
  134157. + return 0;
  134158. +}
  134159. +
  134160. +static int bcm2708_i2s_remove(struct platform_device *pdev)
  134161. +{
  134162. + snd_dmaengine_pcm_unregister(&pdev->dev);
  134163. + snd_soc_unregister_component(&pdev->dev);
  134164. + return 0;
  134165. +}
  134166. +
  134167. +static const struct of_device_id bcm2708_i2s_of_match[] = {
  134168. + { .compatible = "brcm,bcm2708-i2s", },
  134169. + {},
  134170. +};
  134171. +MODULE_DEVICE_TABLE(of, bcm2708_i2s_of_match);
  134172. +
  134173. +static struct platform_driver bcm2708_i2s_driver = {
  134174. + .probe = bcm2708_i2s_probe,
  134175. + .remove = bcm2708_i2s_remove,
  134176. + .driver = {
  134177. + .name = "bcm2708-i2s",
  134178. + .owner = THIS_MODULE,
  134179. + .of_match_table = bcm2708_i2s_of_match,
  134180. + },
  134181. +};
  134182. +
  134183. +module_platform_driver(bcm2708_i2s_driver);
  134184. +
  134185. +MODULE_ALIAS("platform:bcm2708-i2s");
  134186. +MODULE_DESCRIPTION("BCM2708 I2S interface");
  134187. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  134188. +MODULE_LICENSE("GPL v2");
  134189. diff -Nur linux-3.18.8/sound/soc/bcm/bcm2708-i2s.h linux-rpi/sound/soc/bcm/bcm2708-i2s.h
  134190. --- linux-3.18.8/sound/soc/bcm/bcm2708-i2s.h 1970-01-01 01:00:00.000000000 +0100
  134191. +++ linux-rpi/sound/soc/bcm/bcm2708-i2s.h 2015-03-05 14:40:19.313715789 +0100
  134192. @@ -0,0 +1,35 @@
  134193. +/*
  134194. + * I2S configuration for sound cards.
  134195. + *
  134196. + * Copyright (c) 2014 Daniel Matuschek <daniel@hifiberry.com>
  134197. + *
  134198. + * This program is free software; you can redistribute it and/or modify
  134199. + * it under the terms of the GNU General Public License as published by
  134200. + * the Free Software Foundation; either version 2 of the License, or
  134201. + * (at your option) any later version.
  134202. + *
  134203. + * This program is distributed in the hope that it will be useful,
  134204. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  134205. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  134206. + * GNU General Public License for more details.
  134207. + *
  134208. + * You should have received a copy of the GNU General Public License
  134209. + * along with this program; if not, write to the Free Software
  134210. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  134211. + */
  134212. +
  134213. +#ifndef BCM2708_I2S_H
  134214. +#define BCM2708_I2S_H
  134215. +
  134216. +/* I2S pin assignment */
  134217. +#define BCM2708_I2S_GPIO_AUTO 0
  134218. +#define BCM2708_I2S_GPIO_PIN18 1
  134219. +#define BCM2708_I2S_GPIO_PIN28 2
  134220. +
  134221. +/* Alt mode to enable I2S */
  134222. +#define BCM2708_I2S_GPIO_PIN18_ALT 0
  134223. +#define BCM2708_I2S_GPIO_PIN28_ALT 2
  134224. +
  134225. +extern void bcm2708_i2s_set_gpio(int gpio);
  134226. +
  134227. +#endif
  134228. diff -Nur linux-3.18.8/sound/soc/bcm/bcm2835-i2s.c linux-rpi/sound/soc/bcm/bcm2835-i2s.c
  134229. --- linux-3.18.8/sound/soc/bcm/bcm2835-i2s.c 2015-02-27 02:49:36.000000000 +0100
  134230. +++ linux-rpi/sound/soc/bcm/bcm2835-i2s.c 2015-03-05 14:40:19.313715789 +0100
  134231. @@ -861,6 +861,7 @@
  134232. { .compatible = "brcm,bcm2835-i2s", },
  134233. {},
  134234. };
  134235. +MODULE_DEVICE_TABLE(of, bcm2835_i2s_of_match);
  134236. static struct platform_driver bcm2835_i2s_driver = {
  134237. .probe = bcm2835_i2s_probe,
  134238. diff -Nur linux-3.18.8/sound/soc/bcm/hifiberry_amp.c linux-rpi/sound/soc/bcm/hifiberry_amp.c
  134239. --- linux-3.18.8/sound/soc/bcm/hifiberry_amp.c 1970-01-01 01:00:00.000000000 +0100
  134240. +++ linux-rpi/sound/soc/bcm/hifiberry_amp.c 2015-03-05 14:40:19.317715789 +0100
  134241. @@ -0,0 +1,127 @@
  134242. +/*
  134243. + * ASoC Driver for HifiBerry AMP
  134244. + *
  134245. + * Author: Sebastian Eickhoff <basti.eickhoff@googlemail.com>
  134246. + * Copyright 2014
  134247. + *
  134248. + * This program is free software; you can redistribute it and/or
  134249. + * modify it under the terms of the GNU General Public License
  134250. + * version 2 as published by the Free Software Foundation.
  134251. + *
  134252. + * This program is distributed in the hope that it will be useful, but
  134253. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  134254. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  134255. + * General Public License for more details.
  134256. + */
  134257. +
  134258. +#include <linux/module.h>
  134259. +#include <linux/platform_device.h>
  134260. +
  134261. +#include <sound/core.h>
  134262. +#include <sound/pcm.h>
  134263. +#include <sound/pcm_params.h>
  134264. +#include <sound/soc.h>
  134265. +#include <sound/jack.h>
  134266. +
  134267. +static int snd_rpi_hifiberry_amp_init(struct snd_soc_pcm_runtime *rtd)
  134268. +{
  134269. + // ToDo: init of the dsp-registers.
  134270. + return 0;
  134271. +}
  134272. +
  134273. +static int snd_rpi_hifiberry_amp_hw_params( struct snd_pcm_substream *substream,
  134274. + struct snd_pcm_hw_params *params )
  134275. +{
  134276. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  134277. + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  134278. +
  134279. + return snd_soc_dai_set_bclk_ratio(cpu_dai, 64);
  134280. +}
  134281. +
  134282. +static struct snd_soc_ops snd_rpi_hifiberry_amp_ops = {
  134283. + .hw_params = snd_rpi_hifiberry_amp_hw_params,
  134284. +};
  134285. +
  134286. +static struct snd_soc_dai_link snd_rpi_hifiberry_amp_dai[] = {
  134287. + {
  134288. + .name = "HifiBerry AMP",
  134289. + .stream_name = "HifiBerry AMP HiFi",
  134290. + .cpu_dai_name = "bcm2708-i2s.0",
  134291. + .codec_dai_name = "tas5713-hifi",
  134292. + .platform_name = "bcm2708-i2s.0",
  134293. + .codec_name = "tas5713.1-001b",
  134294. + .dai_fmt = SND_SOC_DAIFMT_I2S |
  134295. + SND_SOC_DAIFMT_NB_NF |
  134296. + SND_SOC_DAIFMT_CBS_CFS,
  134297. + .ops = &snd_rpi_hifiberry_amp_ops,
  134298. + .init = snd_rpi_hifiberry_amp_init,
  134299. + },
  134300. +};
  134301. +
  134302. +
  134303. +static struct snd_soc_card snd_rpi_hifiberry_amp = {
  134304. + .name = "snd_rpi_hifiberry_amp",
  134305. + .dai_link = snd_rpi_hifiberry_amp_dai,
  134306. + .num_links = ARRAY_SIZE(snd_rpi_hifiberry_amp_dai),
  134307. +};
  134308. +
  134309. +static const struct of_device_id snd_rpi_hifiberry_amp_of_match[] = {
  134310. + { .compatible = "hifiberry,hifiberry-amp", },
  134311. + {},
  134312. +};
  134313. +MODULE_DEVICE_TABLE(of, snd_rpi_hifiberry_amp_of_match);
  134314. +
  134315. +
  134316. +static int snd_rpi_hifiberry_amp_probe(struct platform_device *pdev)
  134317. +{
  134318. + int ret = 0;
  134319. +
  134320. + snd_rpi_hifiberry_amp.dev = &pdev->dev;
  134321. +
  134322. + if (pdev->dev.of_node) {
  134323. + struct device_node *i2s_node;
  134324. + struct snd_soc_dai_link *dai = &snd_rpi_hifiberry_amp_dai[0];
  134325. + i2s_node = of_parse_phandle(pdev->dev.of_node,
  134326. + "i2s-controller", 0);
  134327. +
  134328. + if (i2s_node) {
  134329. + dai->cpu_dai_name = NULL;
  134330. + dai->cpu_of_node = i2s_node;
  134331. + dai->platform_name = NULL;
  134332. + dai->platform_of_node = i2s_node;
  134333. + }
  134334. + }
  134335. +
  134336. + ret = snd_soc_register_card(&snd_rpi_hifiberry_amp);
  134337. +
  134338. + if (ret != 0) {
  134339. + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret);
  134340. + }
  134341. +
  134342. + return ret;
  134343. +}
  134344. +
  134345. +
  134346. +static int snd_rpi_hifiberry_amp_remove(struct platform_device *pdev)
  134347. +{
  134348. + return snd_soc_unregister_card(&snd_rpi_hifiberry_amp);
  134349. +}
  134350. +
  134351. +
  134352. +static struct platform_driver snd_rpi_hifiberry_amp_driver = {
  134353. + .driver = {
  134354. + .name = "snd-hifiberry-amp",
  134355. + .owner = THIS_MODULE,
  134356. + .of_match_table = snd_rpi_hifiberry_amp_of_match,
  134357. + },
  134358. + .probe = snd_rpi_hifiberry_amp_probe,
  134359. + .remove = snd_rpi_hifiberry_amp_remove,
  134360. +};
  134361. +
  134362. +
  134363. +module_platform_driver(snd_rpi_hifiberry_amp_driver);
  134364. +
  134365. +
  134366. +MODULE_AUTHOR("Sebastian Eickhoff <basti.eickhoff@googlemail.com>");
  134367. +MODULE_DESCRIPTION("ASoC driver for HiFiBerry-AMP");
  134368. +MODULE_LICENSE("GPL v2");
  134369. diff -Nur linux-3.18.8/sound/soc/bcm/hifiberry_dac.c linux-rpi/sound/soc/bcm/hifiberry_dac.c
  134370. --- linux-3.18.8/sound/soc/bcm/hifiberry_dac.c 1970-01-01 01:00:00.000000000 +0100
  134371. +++ linux-rpi/sound/soc/bcm/hifiberry_dac.c 2015-03-05 14:40:19.317715789 +0100
  134372. @@ -0,0 +1,122 @@
  134373. +/*
  134374. + * ASoC Driver for HifiBerry DAC
  134375. + *
  134376. + * Author: Florian Meier <florian.meier@koalo.de>
  134377. + * Copyright 2013
  134378. + *
  134379. + * This program is free software; you can redistribute it and/or
  134380. + * modify it under the terms of the GNU General Public License
  134381. + * version 2 as published by the Free Software Foundation.
  134382. + *
  134383. + * This program is distributed in the hope that it will be useful, but
  134384. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  134385. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  134386. + * General Public License for more details.
  134387. + */
  134388. +
  134389. +#include <linux/module.h>
  134390. +#include <linux/platform_device.h>
  134391. +
  134392. +#include <sound/core.h>
  134393. +#include <sound/pcm.h>
  134394. +#include <sound/pcm_params.h>
  134395. +#include <sound/soc.h>
  134396. +#include <sound/jack.h>
  134397. +
  134398. +static int snd_rpi_hifiberry_dac_init(struct snd_soc_pcm_runtime *rtd)
  134399. +{
  134400. + return 0;
  134401. +}
  134402. +
  134403. +static int snd_rpi_hifiberry_dac_hw_params(struct snd_pcm_substream *substream,
  134404. + struct snd_pcm_hw_params *params)
  134405. +{
  134406. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  134407. + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  134408. +
  134409. + unsigned int sample_bits =
  134410. + snd_pcm_format_physical_width(params_format(params));
  134411. +
  134412. + return snd_soc_dai_set_bclk_ratio(cpu_dai, sample_bits * 2);
  134413. +}
  134414. +
  134415. +/* machine stream operations */
  134416. +static struct snd_soc_ops snd_rpi_hifiberry_dac_ops = {
  134417. + .hw_params = snd_rpi_hifiberry_dac_hw_params,
  134418. +};
  134419. +
  134420. +static struct snd_soc_dai_link snd_rpi_hifiberry_dac_dai[] = {
  134421. +{
  134422. + .name = "HifiBerry DAC",
  134423. + .stream_name = "HifiBerry DAC HiFi",
  134424. + .cpu_dai_name = "bcm2708-i2s.0",
  134425. + .codec_dai_name = "pcm5102a-hifi",
  134426. + .platform_name = "bcm2708-i2s.0",
  134427. + .codec_name = "pcm5102a-codec",
  134428. + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  134429. + SND_SOC_DAIFMT_CBS_CFS,
  134430. + .ops = &snd_rpi_hifiberry_dac_ops,
  134431. + .init = snd_rpi_hifiberry_dac_init,
  134432. +},
  134433. +};
  134434. +
  134435. +/* audio machine driver */
  134436. +static struct snd_soc_card snd_rpi_hifiberry_dac = {
  134437. + .name = "snd_rpi_hifiberry_dac",
  134438. + .dai_link = snd_rpi_hifiberry_dac_dai,
  134439. + .num_links = ARRAY_SIZE(snd_rpi_hifiberry_dac_dai),
  134440. +};
  134441. +
  134442. +static int snd_rpi_hifiberry_dac_probe(struct platform_device *pdev)
  134443. +{
  134444. + int ret = 0;
  134445. +
  134446. + snd_rpi_hifiberry_dac.dev = &pdev->dev;
  134447. +
  134448. + if (pdev->dev.of_node) {
  134449. + struct device_node *i2s_node;
  134450. + struct snd_soc_dai_link *dai = &snd_rpi_hifiberry_dac_dai[0];
  134451. + i2s_node = of_parse_phandle(pdev->dev.of_node,
  134452. + "i2s-controller", 0);
  134453. +
  134454. + if (i2s_node) {
  134455. + dai->cpu_dai_name = NULL;
  134456. + dai->cpu_of_node = i2s_node;
  134457. + dai->platform_name = NULL;
  134458. + dai->platform_of_node = i2s_node;
  134459. + }
  134460. + }
  134461. +
  134462. + ret = snd_soc_register_card(&snd_rpi_hifiberry_dac);
  134463. + if (ret)
  134464. + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret);
  134465. +
  134466. + return ret;
  134467. +}
  134468. +
  134469. +static int snd_rpi_hifiberry_dac_remove(struct platform_device *pdev)
  134470. +{
  134471. + return snd_soc_unregister_card(&snd_rpi_hifiberry_dac);
  134472. +}
  134473. +
  134474. +static const struct of_device_id snd_rpi_hifiberry_dac_of_match[] = {
  134475. + { .compatible = "hifiberry,hifiberry-dac", },
  134476. + {},
  134477. +};
  134478. +MODULE_DEVICE_TABLE(of, snd_rpi_hifiberry_dac_of_match);
  134479. +
  134480. +static struct platform_driver snd_rpi_hifiberry_dac_driver = {
  134481. + .driver = {
  134482. + .name = "snd-hifiberry-dac",
  134483. + .owner = THIS_MODULE,
  134484. + .of_match_table = snd_rpi_hifiberry_dac_of_match,
  134485. + },
  134486. + .probe = snd_rpi_hifiberry_dac_probe,
  134487. + .remove = snd_rpi_hifiberry_dac_remove,
  134488. +};
  134489. +
  134490. +module_platform_driver(snd_rpi_hifiberry_dac_driver);
  134491. +
  134492. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  134493. +MODULE_DESCRIPTION("ASoC Driver for HifiBerry DAC");
  134494. +MODULE_LICENSE("GPL v2");
  134495. diff -Nur linux-3.18.8/sound/soc/bcm/hifiberry_dacplus.c linux-rpi/sound/soc/bcm/hifiberry_dacplus.c
  134496. --- linux-3.18.8/sound/soc/bcm/hifiberry_dacplus.c 1970-01-01 01:00:00.000000000 +0100
  134497. +++ linux-rpi/sound/soc/bcm/hifiberry_dacplus.c 2015-03-05 14:40:19.317715789 +0100
  134498. @@ -0,0 +1,141 @@
  134499. +/*
  134500. + * ASoC Driver for HiFiBerry DAC+
  134501. + *
  134502. + * Author: Daniel Matuschek
  134503. + * Copyright 2014
  134504. + * based on code by Florian Meier <florian.meier@koalo.de>
  134505. + *
  134506. + * This program is free software; you can redistribute it and/or
  134507. + * modify it under the terms of the GNU General Public License
  134508. + * version 2 as published by the Free Software Foundation.
  134509. + *
  134510. + * This program is distributed in the hope that it will be useful, but
  134511. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  134512. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  134513. + * General Public License for more details.
  134514. + */
  134515. +
  134516. +#include <linux/module.h>
  134517. +#include <linux/platform_device.h>
  134518. +
  134519. +#include <sound/core.h>
  134520. +#include <sound/pcm.h>
  134521. +#include <sound/pcm_params.h>
  134522. +#include <sound/soc.h>
  134523. +#include <sound/jack.h>
  134524. +
  134525. +#include "../codecs/pcm512x.h"
  134526. +
  134527. +static int snd_rpi_hifiberry_dacplus_init(struct snd_soc_pcm_runtime *rtd)
  134528. +{
  134529. + struct snd_soc_codec *codec = rtd->codec;
  134530. + snd_soc_update_bits(codec, PCM512x_GPIO_EN, 0x08, 0x08);
  134531. + snd_soc_update_bits(codec, PCM512x_GPIO_OUTPUT_4, 0xf, 0x02);
  134532. + snd_soc_update_bits(codec, PCM512x_GPIO_CONTROL_1, 0x08,0x08);
  134533. + return 0;
  134534. +}
  134535. +
  134536. +static int snd_rpi_hifiberry_dacplus_hw_params(struct snd_pcm_substream *substream,
  134537. + struct snd_pcm_hw_params *params)
  134538. +{
  134539. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  134540. + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  134541. + return snd_soc_dai_set_bclk_ratio(cpu_dai, 64);
  134542. +}
  134543. +
  134544. +static int snd_rpi_hifiberry_dacplus_startup(struct snd_pcm_substream *substream) {
  134545. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  134546. + struct snd_soc_codec *codec = rtd->codec;
  134547. + snd_soc_update_bits(codec, PCM512x_GPIO_CONTROL_1, 0x08,0x08);
  134548. + return 0;
  134549. +}
  134550. +
  134551. +static void snd_rpi_hifiberry_dacplus_shutdown(struct snd_pcm_substream *substream) {
  134552. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  134553. + struct snd_soc_codec *codec = rtd->codec;
  134554. + snd_soc_update_bits(codec, PCM512x_GPIO_CONTROL_1, 0x08,0x00);
  134555. +}
  134556. +
  134557. +/* machine stream operations */
  134558. +static struct snd_soc_ops snd_rpi_hifiberry_dacplus_ops = {
  134559. + .hw_params = snd_rpi_hifiberry_dacplus_hw_params,
  134560. + .startup = snd_rpi_hifiberry_dacplus_startup,
  134561. + .shutdown = snd_rpi_hifiberry_dacplus_shutdown,
  134562. +};
  134563. +
  134564. +static struct snd_soc_dai_link snd_rpi_hifiberry_dacplus_dai[] = {
  134565. +{
  134566. + .name = "HiFiBerry DAC+",
  134567. + .stream_name = "HiFiBerry DAC+ HiFi",
  134568. + .cpu_dai_name = "bcm2708-i2s.0",
  134569. + .codec_dai_name = "pcm512x-hifi",
  134570. + .platform_name = "bcm2708-i2s.0",
  134571. + .codec_name = "pcm512x.1-004d",
  134572. + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  134573. + SND_SOC_DAIFMT_CBS_CFS,
  134574. + .ops = &snd_rpi_hifiberry_dacplus_ops,
  134575. + .init = snd_rpi_hifiberry_dacplus_init,
  134576. +},
  134577. +};
  134578. +
  134579. +/* audio machine driver */
  134580. +static struct snd_soc_card snd_rpi_hifiberry_dacplus = {
  134581. + .name = "snd_rpi_hifiberry_dacplus",
  134582. + .dai_link = snd_rpi_hifiberry_dacplus_dai,
  134583. + .num_links = ARRAY_SIZE(snd_rpi_hifiberry_dacplus_dai),
  134584. +};
  134585. +
  134586. +static int snd_rpi_hifiberry_dacplus_probe(struct platform_device *pdev)
  134587. +{
  134588. + int ret = 0;
  134589. +
  134590. + snd_rpi_hifiberry_dacplus.dev = &pdev->dev;
  134591. +
  134592. + if (pdev->dev.of_node) {
  134593. + struct device_node *i2s_node;
  134594. + struct snd_soc_dai_link *dai = &snd_rpi_hifiberry_dacplus_dai[0];
  134595. + i2s_node = of_parse_phandle(pdev->dev.of_node,
  134596. + "i2s-controller", 0);
  134597. +
  134598. + if (i2s_node) {
  134599. + dai->cpu_dai_name = NULL;
  134600. + dai->cpu_of_node = i2s_node;
  134601. + dai->platform_name = NULL;
  134602. + dai->platform_of_node = i2s_node;
  134603. + }
  134604. + }
  134605. +
  134606. + ret = snd_soc_register_card(&snd_rpi_hifiberry_dacplus);
  134607. + if (ret)
  134608. + dev_err(&pdev->dev,
  134609. + "snd_soc_register_card() failed: %d\n", ret);
  134610. +
  134611. + return ret;
  134612. +}
  134613. +
  134614. +static int snd_rpi_hifiberry_dacplus_remove(struct platform_device *pdev)
  134615. +{
  134616. + return snd_soc_unregister_card(&snd_rpi_hifiberry_dacplus);
  134617. +}
  134618. +
  134619. +static const struct of_device_id snd_rpi_hifiberry_dacplus_of_match[] = {
  134620. + { .compatible = "hifiberry,hifiberry-dacplus", },
  134621. + {},
  134622. +};
  134623. +MODULE_DEVICE_TABLE(of, snd_rpi_hifiberry_dacplus_of_match);
  134624. +
  134625. +static struct platform_driver snd_rpi_hifiberry_dacplus_driver = {
  134626. + .driver = {
  134627. + .name = "snd-rpi-hifiberry-dacplus",
  134628. + .owner = THIS_MODULE,
  134629. + .of_match_table = snd_rpi_hifiberry_dacplus_of_match,
  134630. + },
  134631. + .probe = snd_rpi_hifiberry_dacplus_probe,
  134632. + .remove = snd_rpi_hifiberry_dacplus_remove,
  134633. +};
  134634. +
  134635. +module_platform_driver(snd_rpi_hifiberry_dacplus_driver);
  134636. +
  134637. +MODULE_AUTHOR("Daniel Matuschek <daniel@hifiberry.com>");
  134638. +MODULE_DESCRIPTION("ASoC Driver for HiFiBerry DAC+");
  134639. +MODULE_LICENSE("GPL v2");
  134640. diff -Nur linux-3.18.8/sound/soc/bcm/hifiberry_digi.c linux-rpi/sound/soc/bcm/hifiberry_digi.c
  134641. --- linux-3.18.8/sound/soc/bcm/hifiberry_digi.c 1970-01-01 01:00:00.000000000 +0100
  134642. +++ linux-rpi/sound/soc/bcm/hifiberry_digi.c 2015-03-05 14:40:19.317715789 +0100
  134643. @@ -0,0 +1,203 @@
  134644. +/*
  134645. + * ASoC Driver for HifiBerry Digi
  134646. + *
  134647. + * Author: Daniel Matuschek <info@crazy-audio.com>
  134648. + * based on the HifiBerry DAC driver by Florian Meier <florian.meier@koalo.de>
  134649. + * Copyright 2013
  134650. + *
  134651. + * This program is free software; you can redistribute it and/or
  134652. + * modify it under the terms of the GNU General Public License
  134653. + * version 2 as published by the Free Software Foundation.
  134654. + *
  134655. + * This program is distributed in the hope that it will be useful, but
  134656. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  134657. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  134658. + * General Public License for more details.
  134659. + */
  134660. +
  134661. +#include <linux/module.h>
  134662. +#include <linux/platform_device.h>
  134663. +
  134664. +#include <sound/core.h>
  134665. +#include <sound/pcm.h>
  134666. +#include <sound/pcm_params.h>
  134667. +#include <sound/soc.h>
  134668. +#include <sound/jack.h>
  134669. +
  134670. +#include "../codecs/wm8804.h"
  134671. +
  134672. +static short int auto_shutdown_output = 0;
  134673. +module_param(auto_shutdown_output, short, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
  134674. +MODULE_PARM_DESC(auto_shutdown_output, "Shutdown SP/DIF output if playback is stopped");
  134675. +
  134676. +
  134677. +static int samplerate=44100;
  134678. +
  134679. +static int snd_rpi_hifiberry_digi_init(struct snd_soc_pcm_runtime *rtd)
  134680. +{
  134681. + struct snd_soc_codec *codec = rtd->codec;
  134682. +
  134683. + /* enable TX output */
  134684. + snd_soc_update_bits(codec, WM8804_PWRDN, 0x4, 0x0);
  134685. +
  134686. + return 0;
  134687. +}
  134688. +
  134689. +static int snd_rpi_hifiberry_digi_startup(struct snd_pcm_substream *substream) {
  134690. + /* turn on digital output */
  134691. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  134692. + struct snd_soc_codec *codec = rtd->codec;
  134693. + snd_soc_update_bits(codec, WM8804_PWRDN, 0x3c, 0x00);
  134694. + return 0;
  134695. +}
  134696. +
  134697. +static void snd_rpi_hifiberry_digi_shutdown(struct snd_pcm_substream *substream) {
  134698. + /* turn off output */
  134699. + if (auto_shutdown_output) {
  134700. + /* turn off output */
  134701. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  134702. + struct snd_soc_codec *codec = rtd->codec;
  134703. + snd_soc_update_bits(codec, WM8804_PWRDN, 0x3c, 0x3c);
  134704. + }
  134705. +}
  134706. +
  134707. +
  134708. +static int snd_rpi_hifiberry_digi_hw_params(struct snd_pcm_substream *substream,
  134709. + struct snd_pcm_hw_params *params)
  134710. +{
  134711. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  134712. + struct snd_soc_dai *codec_dai = rtd->codec_dai;
  134713. + struct snd_soc_codec *codec = rtd->codec;
  134714. + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  134715. +
  134716. + int sysclk = 27000000; /* This is fixed on this board */
  134717. +
  134718. + long mclk_freq=0;
  134719. + int mclk_div=1;
  134720. +
  134721. + int ret;
  134722. +
  134723. + samplerate = params_rate(params);
  134724. +
  134725. + switch (samplerate) {
  134726. + case 32000:
  134727. + case 44100:
  134728. + case 48000:
  134729. + case 88200:
  134730. + case 96000:
  134731. + mclk_freq=samplerate*256;
  134732. + mclk_div=WM8804_MCLKDIV_256FS;
  134733. + break;
  134734. + case 176400:
  134735. + case 192000:
  134736. + mclk_freq=samplerate*128;
  134737. + mclk_div=WM8804_MCLKDIV_128FS;
  134738. + break;
  134739. + default:
  134740. + dev_err(substream->pcm->dev,
  134741. + "Failed to set WM8804 SYSCLK, unsupported samplerate %d\n",
  134742. + samplerate);
  134743. + }
  134744. +
  134745. + snd_soc_dai_set_clkdiv(codec_dai, WM8804_MCLK_DIV, mclk_div);
  134746. + snd_soc_dai_set_pll(codec_dai, 0, 0, sysclk, mclk_freq);
  134747. +
  134748. + ret = snd_soc_dai_set_sysclk(codec_dai, WM8804_TX_CLKSRC_PLL,
  134749. + sysclk, SND_SOC_CLOCK_OUT);
  134750. + if (ret < 0) {
  134751. + dev_err(substream->pcm->dev,
  134752. + "Failed to set WM8804 SYSCLK: %d\n", ret);
  134753. + return ret;
  134754. + }
  134755. +
  134756. + /* Enable TX output */
  134757. + snd_soc_update_bits(codec, WM8804_PWRDN, 0x4, 0x0);
  134758. +
  134759. + /* Power on */
  134760. + snd_soc_update_bits(codec, WM8804_PWRDN, 0x9, 0);
  134761. +
  134762. + return snd_soc_dai_set_bclk_ratio(cpu_dai,64);
  134763. +}
  134764. +
  134765. +/* machine stream operations */
  134766. +static struct snd_soc_ops snd_rpi_hifiberry_digi_ops = {
  134767. + .hw_params = snd_rpi_hifiberry_digi_hw_params,
  134768. + .startup = snd_rpi_hifiberry_digi_startup,
  134769. + .shutdown = snd_rpi_hifiberry_digi_shutdown,
  134770. +};
  134771. +
  134772. +static struct snd_soc_dai_link snd_rpi_hifiberry_digi_dai[] = {
  134773. +{
  134774. + .name = "HifiBerry Digi",
  134775. + .stream_name = "HifiBerry Digi HiFi",
  134776. + .cpu_dai_name = "bcm2708-i2s.0",
  134777. + .codec_dai_name = "wm8804-spdif",
  134778. + .platform_name = "bcm2708-i2s.0",
  134779. + .codec_name = "wm8804.1-003b",
  134780. + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  134781. + SND_SOC_DAIFMT_CBM_CFM,
  134782. + .ops = &snd_rpi_hifiberry_digi_ops,
  134783. + .init = snd_rpi_hifiberry_digi_init,
  134784. +},
  134785. +};
  134786. +
  134787. +/* audio machine driver */
  134788. +static struct snd_soc_card snd_rpi_hifiberry_digi = {
  134789. + .name = "snd_rpi_hifiberry_digi",
  134790. + .dai_link = snd_rpi_hifiberry_digi_dai,
  134791. + .num_links = ARRAY_SIZE(snd_rpi_hifiberry_digi_dai),
  134792. +};
  134793. +
  134794. +static int snd_rpi_hifiberry_digi_probe(struct platform_device *pdev)
  134795. +{
  134796. + int ret = 0;
  134797. +
  134798. + snd_rpi_hifiberry_digi.dev = &pdev->dev;
  134799. +
  134800. + if (pdev->dev.of_node) {
  134801. + struct device_node *i2s_node;
  134802. + struct snd_soc_dai_link *dai = &snd_rpi_hifiberry_digi_dai[0];
  134803. + i2s_node = of_parse_phandle(pdev->dev.of_node,
  134804. + "i2s-controller", 0);
  134805. +
  134806. + if (i2s_node) {
  134807. + dai->cpu_dai_name = NULL;
  134808. + dai->cpu_of_node = i2s_node;
  134809. + dai->platform_name = NULL;
  134810. + dai->platform_of_node = i2s_node;
  134811. + }
  134812. + }
  134813. +
  134814. + ret = snd_soc_register_card(&snd_rpi_hifiberry_digi);
  134815. + if (ret)
  134816. + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret);
  134817. +
  134818. + return ret;
  134819. +}
  134820. +
  134821. +static int snd_rpi_hifiberry_digi_remove(struct platform_device *pdev)
  134822. +{
  134823. + return snd_soc_unregister_card(&snd_rpi_hifiberry_digi);
  134824. +}
  134825. +
  134826. +static const struct of_device_id snd_rpi_hifiberry_digi_of_match[] = {
  134827. + { .compatible = "hifiberry,hifiberry-digi", },
  134828. + {},
  134829. +};
  134830. +MODULE_DEVICE_TABLE(of, snd_rpi_hifiberry_digi_of_match);
  134831. +
  134832. +static struct platform_driver snd_rpi_hifiberry_digi_driver = {
  134833. + .driver = {
  134834. + .name = "snd-hifiberry-digi",
  134835. + .owner = THIS_MODULE,
  134836. + .of_match_table = snd_rpi_hifiberry_digi_of_match,
  134837. + },
  134838. + .probe = snd_rpi_hifiberry_digi_probe,
  134839. + .remove = snd_rpi_hifiberry_digi_remove,
  134840. +};
  134841. +
  134842. +module_platform_driver(snd_rpi_hifiberry_digi_driver);
  134843. +
  134844. +MODULE_AUTHOR("Daniel Matuschek <info@crazy-audio.com>");
  134845. +MODULE_DESCRIPTION("ASoC Driver for HifiBerry Digi");
  134846. +MODULE_LICENSE("GPL v2");
  134847. diff -Nur linux-3.18.8/sound/soc/bcm/iqaudio-dac.c linux-rpi/sound/soc/bcm/iqaudio-dac.c
  134848. --- linux-3.18.8/sound/soc/bcm/iqaudio-dac.c 1970-01-01 01:00:00.000000000 +0100
  134849. +++ linux-rpi/sound/soc/bcm/iqaudio-dac.c 2015-03-05 14:40:19.317715789 +0100
  134850. @@ -0,0 +1,127 @@
  134851. +/*
  134852. + * ASoC Driver for IQaudIO DAC
  134853. + *
  134854. + * Author: Florian Meier <florian.meier@koalo.de>
  134855. + * Copyright 2013
  134856. + *
  134857. + * This program is free software; you can redistribute it and/or
  134858. + * modify it under the terms of the GNU General Public License
  134859. + * version 2 as published by the Free Software Foundation.
  134860. + *
  134861. + * This program is distributed in the hope that it will be useful, but
  134862. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  134863. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  134864. + * General Public License for more details.
  134865. + */
  134866. +
  134867. +#include <linux/module.h>
  134868. +#include <linux/platform_device.h>
  134869. +
  134870. +#include <sound/core.h>
  134871. +#include <sound/pcm.h>
  134872. +#include <sound/pcm_params.h>
  134873. +#include <sound/soc.h>
  134874. +#include <sound/jack.h>
  134875. +
  134876. +static int snd_rpi_iqaudio_dac_init(struct snd_soc_pcm_runtime *rtd)
  134877. +{
  134878. +// NOT USED struct snd_soc_codec *codec = rtd->codec;
  134879. +
  134880. + return 0;
  134881. +}
  134882. +
  134883. +static int snd_rpi_iqaudio_dac_hw_params(struct snd_pcm_substream *substream,
  134884. + struct snd_pcm_hw_params *params)
  134885. +{
  134886. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  134887. +// NOT USED struct snd_soc_dai *codec_dai = rtd->codec_dai;
  134888. +// NOT USED struct snd_soc_codec *codec = rtd->codec;
  134889. + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  134890. +
  134891. + unsigned int sample_bits =
  134892. + snd_pcm_format_physical_width(params_format(params));
  134893. +
  134894. + return snd_soc_dai_set_bclk_ratio(cpu_dai, sample_bits * 2);
  134895. +}
  134896. +
  134897. +/* machine stream operations */
  134898. +static struct snd_soc_ops snd_rpi_iqaudio_dac_ops = {
  134899. + .hw_params = snd_rpi_iqaudio_dac_hw_params,
  134900. +};
  134901. +
  134902. +static struct snd_soc_dai_link snd_rpi_iqaudio_dac_dai[] = {
  134903. +{
  134904. + .name = "IQaudIO DAC",
  134905. + .stream_name = "IQaudIO DAC HiFi",
  134906. + .cpu_dai_name = "bcm2708-i2s.0",
  134907. + .codec_dai_name = "pcm512x-hifi",
  134908. + .platform_name = "bcm2708-i2s.0",
  134909. + .codec_name = "pcm512x.1-004c",
  134910. + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  134911. + SND_SOC_DAIFMT_CBS_CFS,
  134912. + .ops = &snd_rpi_iqaudio_dac_ops,
  134913. + .init = snd_rpi_iqaudio_dac_init,
  134914. +},
  134915. +};
  134916. +
  134917. +/* audio machine driver */
  134918. +static struct snd_soc_card snd_rpi_iqaudio_dac = {
  134919. + .name = "IQaudIODAC",
  134920. + .dai_link = snd_rpi_iqaudio_dac_dai,
  134921. + .num_links = ARRAY_SIZE(snd_rpi_iqaudio_dac_dai),
  134922. +};
  134923. +
  134924. +static int snd_rpi_iqaudio_dac_probe(struct platform_device *pdev)
  134925. +{
  134926. + int ret = 0;
  134927. +
  134928. + snd_rpi_iqaudio_dac.dev = &pdev->dev;
  134929. +
  134930. + if (pdev->dev.of_node) {
  134931. + struct device_node *i2s_node;
  134932. + struct snd_soc_dai_link *dai = &snd_rpi_iqaudio_dac_dai[0];
  134933. + i2s_node = of_parse_phandle(pdev->dev.of_node,
  134934. + "i2s-controller", 0);
  134935. +
  134936. + if (i2s_node) {
  134937. + dai->cpu_dai_name = NULL;
  134938. + dai->cpu_of_node = i2s_node;
  134939. + dai->platform_name = NULL;
  134940. + dai->platform_of_node = i2s_node;
  134941. + }
  134942. + }
  134943. +
  134944. + ret = snd_soc_register_card(&snd_rpi_iqaudio_dac);
  134945. + if (ret)
  134946. + dev_err(&pdev->dev,
  134947. + "snd_soc_register_card() failed: %d\n", ret);
  134948. +
  134949. + return ret;
  134950. +}
  134951. +
  134952. +static int snd_rpi_iqaudio_dac_remove(struct platform_device *pdev)
  134953. +{
  134954. + return snd_soc_unregister_card(&snd_rpi_iqaudio_dac);
  134955. +}
  134956. +
  134957. +static const struct of_device_id iqaudio_of_match[] = {
  134958. + { .compatible = "iqaudio,iqaudio-dac", },
  134959. + {},
  134960. +};
  134961. +MODULE_DEVICE_TABLE(of, iqaudio_of_match);
  134962. +
  134963. +static struct platform_driver snd_rpi_iqaudio_dac_driver = {
  134964. + .driver = {
  134965. + .name = "snd-rpi-iqaudio-dac",
  134966. + .owner = THIS_MODULE,
  134967. + .of_match_table = iqaudio_of_match,
  134968. + },
  134969. + .probe = snd_rpi_iqaudio_dac_probe,
  134970. + .remove = snd_rpi_iqaudio_dac_remove,
  134971. +};
  134972. +
  134973. +module_platform_driver(snd_rpi_iqaudio_dac_driver);
  134974. +
  134975. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  134976. +MODULE_DESCRIPTION("ASoC Driver for IQAudio DAC");
  134977. +MODULE_LICENSE("GPL v2");
  134978. diff -Nur linux-3.18.8/sound/soc/bcm/Kconfig linux-rpi/sound/soc/bcm/Kconfig
  134979. --- linux-3.18.8/sound/soc/bcm/Kconfig 2015-02-27 02:49:36.000000000 +0100
  134980. +++ linux-rpi/sound/soc/bcm/Kconfig 2015-03-05 14:40:19.313715789 +0100
  134981. @@ -7,3 +7,56 @@
  134982. Say Y or M if you want to add support for codecs attached to
  134983. the BCM2835 I2S interface. You will also need
  134984. to select the audio interfaces to support below.
  134985. +
  134986. +config SND_BCM2708_SOC_I2S
  134987. + tristate "SoC Audio support for the Broadcom BCM2708 I2S module"
  134988. + depends on MACH_BCM2708 || MACH_BCM2709
  134989. + select REGMAP_MMIO
  134990. + select SND_SOC_DMAENGINE_PCM
  134991. + select SND_SOC_GENERIC_DMAENGINE_PCM
  134992. + help
  134993. + Say Y or M if you want to add support for codecs attached to
  134994. + the BCM2708 I2S interface. You will also need
  134995. + to select the audio interfaces to support below.
  134996. +
  134997. +config SND_BCM2708_SOC_HIFIBERRY_DAC
  134998. + tristate "Support for HifiBerry DAC"
  134999. + depends on SND_BCM2708_SOC_I2S
  135000. + select SND_SOC_PCM5102A
  135001. + help
  135002. + Say Y or M if you want to add support for HifiBerry DAC.
  135003. +
  135004. +config SND_BCM2708_SOC_HIFIBERRY_DACPLUS
  135005. + tristate "Support for HifiBerry DAC+"
  135006. + depends on SND_BCM2708_SOC_I2S
  135007. + select SND_SOC_PCM512x
  135008. + help
  135009. + Say Y or M if you want to add support for HifiBerry DAC+.
  135010. +
  135011. +config SND_BCM2708_SOC_HIFIBERRY_DIGI
  135012. + tristate "Support for HifiBerry Digi"
  135013. + depends on SND_BCM2708_SOC_I2S
  135014. + select SND_SOC_WM8804
  135015. + help
  135016. + Say Y or M if you want to add support for HifiBerry Digi S/PDIF output board.
  135017. +
  135018. +config SND_BCM2708_SOC_HIFIBERRY_AMP
  135019. + tristate "Support for the HifiBerry Amp"
  135020. + depends on SND_BCM2708_SOC_I2S
  135021. + select SND_SOC_TAS5713
  135022. + help
  135023. + Say Y or M if you want to add support for the HifiBerry Amp amplifier board.
  135024. +
  135025. +config SND_BCM2708_SOC_RPI_DAC
  135026. + tristate "Support for RPi-DAC"
  135027. + depends on SND_BCM2708_SOC_I2S
  135028. + select SND_SOC_PCM1794A
  135029. + help
  135030. + Say Y or M if you want to add support for RPi-DAC.
  135031. +
  135032. +config SND_BCM2708_SOC_IQAUDIO_DAC
  135033. + tristate "Support for IQaudIO-DAC"
  135034. + depends on SND_BCM2708_SOC_I2S
  135035. + select SND_SOC_PCM512x_I2C
  135036. + help
  135037. + Say Y or M if you want to add support for IQaudIO-DAC.
  135038. diff -Nur linux-3.18.8/sound/soc/bcm/Makefile linux-rpi/sound/soc/bcm/Makefile
  135039. --- linux-3.18.8/sound/soc/bcm/Makefile 2015-02-27 02:49:36.000000000 +0100
  135040. +++ linux-rpi/sound/soc/bcm/Makefile 2015-03-05 14:40:19.313715789 +0100
  135041. @@ -3,3 +3,22 @@
  135042. obj-$(CONFIG_SND_BCM2835_SOC_I2S) += snd-soc-bcm2835-i2s.o
  135043. +# BCM2708 Platform Support
  135044. +snd-soc-bcm2708-i2s-objs := bcm2708-i2s.o
  135045. +
  135046. +obj-$(CONFIG_SND_BCM2708_SOC_I2S) += snd-soc-bcm2708-i2s.o
  135047. +
  135048. +# BCM2708 Machine Support
  135049. +snd-soc-hifiberry-dac-objs := hifiberry_dac.o
  135050. +snd-soc-hifiberry-dacplus-objs := hifiberry_dacplus.o
  135051. +snd-soc-hifiberry-digi-objs := hifiberry_digi.o
  135052. +snd-soc-hifiberry-amp-objs := hifiberry_amp.o
  135053. +snd-soc-rpi-dac-objs := rpi-dac.o
  135054. +snd-soc-iqaudio-dac-objs := iqaudio-dac.o
  135055. +
  135056. +obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) += snd-soc-hifiberry-dac.o
  135057. +obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS) += snd-soc-hifiberry-dacplus.o
  135058. +obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI) += snd-soc-hifiberry-digi.o
  135059. +obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_AMP) += snd-soc-hifiberry-amp.o
  135060. +obj-$(CONFIG_SND_BCM2708_SOC_RPI_DAC) += snd-soc-rpi-dac.o
  135061. +obj-$(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) += snd-soc-iqaudio-dac.o
  135062. diff -Nur linux-3.18.8/sound/soc/bcm/rpi-dac.c linux-rpi/sound/soc/bcm/rpi-dac.c
  135063. --- linux-3.18.8/sound/soc/bcm/rpi-dac.c 1970-01-01 01:00:00.000000000 +0100
  135064. +++ linux-rpi/sound/soc/bcm/rpi-dac.c 2015-03-05 14:40:19.317715789 +0100
  135065. @@ -0,0 +1,97 @@
  135066. +/*
  135067. + * ASoC Driver for RPi-DAC.
  135068. + *
  135069. + * Author: Florian Meier <florian.meier@koalo.de>
  135070. + * Copyright 2013
  135071. + *
  135072. + * This program is free software; you can redistribute it and/or
  135073. + * modify it under the terms of the GNU General Public License
  135074. + * version 2 as published by the Free Software Foundation.
  135075. + *
  135076. + * This program is distributed in the hope that it will be useful, but
  135077. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  135078. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  135079. + * General Public License for more details.
  135080. + */
  135081. +
  135082. +#include <linux/module.h>
  135083. +#include <linux/platform_device.h>
  135084. +
  135085. +#include <sound/core.h>
  135086. +#include <sound/pcm.h>
  135087. +#include <sound/pcm_params.h>
  135088. +#include <sound/soc.h>
  135089. +#include <sound/jack.h>
  135090. +
  135091. +static int snd_rpi_rpi_dac_init(struct snd_soc_pcm_runtime *rtd)
  135092. +{
  135093. + return 0;
  135094. +}
  135095. +
  135096. +static int snd_rpi_rpi_dac_hw_params(struct snd_pcm_substream *substream,
  135097. + struct snd_pcm_hw_params *params)
  135098. +{
  135099. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  135100. + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  135101. +
  135102. + return snd_soc_dai_set_bclk_ratio(cpu_dai, 32*2);
  135103. +}
  135104. +
  135105. +/* machine stream operations */
  135106. +static struct snd_soc_ops snd_rpi_rpi_dac_ops = {
  135107. + .hw_params = snd_rpi_rpi_dac_hw_params,
  135108. +};
  135109. +
  135110. +static struct snd_soc_dai_link snd_rpi_rpi_dac_dai[] = {
  135111. +{
  135112. + .name = "RPi-DAC",
  135113. + .stream_name = "RPi-DAC HiFi",
  135114. + .cpu_dai_name = "bcm2708-i2s.0",
  135115. + .codec_dai_name = "pcm1794a-hifi",
  135116. + .platform_name = "bcm2708-i2s.0",
  135117. + .codec_name = "pcm1794a-codec",
  135118. + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  135119. + SND_SOC_DAIFMT_CBS_CFS,
  135120. + .ops = &snd_rpi_rpi_dac_ops,
  135121. + .init = snd_rpi_rpi_dac_init,
  135122. +},
  135123. +};
  135124. +
  135125. +/* audio machine driver */
  135126. +static struct snd_soc_card snd_rpi_rpi_dac = {
  135127. + .name = "snd_rpi_rpi_dac",
  135128. + .dai_link = snd_rpi_rpi_dac_dai,
  135129. + .num_links = ARRAY_SIZE(snd_rpi_rpi_dac_dai),
  135130. +};
  135131. +
  135132. +static int snd_rpi_rpi_dac_probe(struct platform_device *pdev)
  135133. +{
  135134. + int ret = 0;
  135135. +
  135136. + snd_rpi_rpi_dac.dev = &pdev->dev;
  135137. + ret = snd_soc_register_card(&snd_rpi_rpi_dac);
  135138. + if (ret)
  135139. + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret);
  135140. +
  135141. + return ret;
  135142. +}
  135143. +
  135144. +static int snd_rpi_rpi_dac_remove(struct platform_device *pdev)
  135145. +{
  135146. + return snd_soc_unregister_card(&snd_rpi_rpi_dac);
  135147. +}
  135148. +
  135149. +static struct platform_driver snd_rpi_rpi_dac_driver = {
  135150. + .driver = {
  135151. + .name = "snd-rpi-dac",
  135152. + .owner = THIS_MODULE,
  135153. + },
  135154. + .probe = snd_rpi_rpi_dac_probe,
  135155. + .remove = snd_rpi_rpi_dac_remove,
  135156. +};
  135157. +
  135158. +module_platform_driver(snd_rpi_rpi_dac_driver);
  135159. +
  135160. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  135161. +MODULE_DESCRIPTION("ASoC Driver for RPi-DAC");
  135162. +MODULE_LICENSE("GPL v2");
  135163. diff -Nur linux-3.18.8/sound/soc/codecs/Kconfig linux-rpi/sound/soc/codecs/Kconfig
  135164. --- linux-3.18.8/sound/soc/codecs/Kconfig 2015-02-27 02:49:36.000000000 +0100
  135165. +++ linux-rpi/sound/soc/codecs/Kconfig 2015-03-05 14:40:19.317715789 +0100
  135166. @@ -80,6 +80,8 @@
  135167. select SND_SOC_PCM512x_I2C if I2C
  135168. select SND_SOC_PCM512x_SPI if SPI_MASTER
  135169. select SND_SOC_RT286 if I2C
  135170. + select SND_SOC_PCM5102A if I2C
  135171. + select SND_SOC_PCM1794A if I2C
  135172. select SND_SOC_RT5631 if I2C
  135173. select SND_SOC_RT5640 if I2C
  135174. select SND_SOC_RT5645 if I2C
  135175. @@ -103,6 +105,7 @@
  135176. select SND_SOC_TAS5086 if I2C
  135177. select SND_SOC_TLV320AIC23_I2C if I2C
  135178. select SND_SOC_TLV320AIC23_SPI if SPI_MASTER
  135179. + select SND_SOC_TAS5713 if I2C
  135180. select SND_SOC_TLV320AIC26 if SPI_MASTER
  135181. select SND_SOC_TLV320AIC31XX if I2C
  135182. select SND_SOC_TLV320AIC32X4 if I2C
  135183. @@ -486,6 +489,12 @@
  135184. tristate
  135185. depends on I2C
  135186. +config SND_SOC_PCM1794A
  135187. + tristate
  135188. +
  135189. +config SND_SOC_PCM5102A
  135190. + tristate
  135191. +
  135192. config SND_SOC_RT5631
  135193. tristate
  135194. @@ -577,6 +586,9 @@
  135195. tristate "Texas Instruments TAS5086 speaker amplifier"
  135196. depends on I2C
  135197. +config SND_SOC_TAS5713
  135198. + tristate
  135199. +
  135200. config SND_SOC_TLV320AIC23
  135201. tristate
  135202. diff -Nur linux-3.18.8/sound/soc/codecs/Makefile linux-rpi/sound/soc/codecs/Makefile
  135203. --- linux-3.18.8/sound/soc/codecs/Makefile 2015-02-27 02:49:36.000000000 +0100
  135204. +++ linux-rpi/sound/soc/codecs/Makefile 2015-03-05 14:40:19.317715789 +0100
  135205. @@ -74,6 +74,8 @@
  135206. snd-soc-pcm512x-spi-objs := pcm512x-spi.o
  135207. snd-soc-rl6231-objs := rl6231.o
  135208. snd-soc-rt286-objs := rt286.o
  135209. +snd-soc-pcm1794a-objs := pcm1794a.o
  135210. +snd-soc-pcm5102a-objs := pcm5102a.o
  135211. snd-soc-rt5631-objs := rt5631.o
  135212. snd-soc-rt5640-objs := rt5640.o
  135213. snd-soc-rt5645-objs := rt5645.o
  135214. @@ -101,6 +103,7 @@
  135215. snd-soc-sta529-objs := sta529.o
  135216. snd-soc-stac9766-objs := stac9766.o
  135217. snd-soc-tas5086-objs := tas5086.o
  135218. +snd-soc-tas5713-objs := tas5713.o
  135219. snd-soc-tlv320aic23-objs := tlv320aic23.o
  135220. snd-soc-tlv320aic23-i2c-objs := tlv320aic23-i2c.o
  135221. snd-soc-tlv320aic23-spi-objs := tlv320aic23-spi.o
  135222. @@ -250,6 +253,8 @@
  135223. obj-$(CONFIG_SND_SOC_PCM512x_SPI) += snd-soc-pcm512x-spi.o
  135224. obj-$(CONFIG_SND_SOC_RL6231) += snd-soc-rl6231.o
  135225. obj-$(CONFIG_SND_SOC_RT286) += snd-soc-rt286.o
  135226. +obj-$(CONFIG_SND_SOC_PCM1794A) += snd-soc-pcm1794a.o
  135227. +obj-$(CONFIG_SND_SOC_PCM5102A) += snd-soc-pcm5102a.o
  135228. obj-$(CONFIG_SND_SOC_RT5631) += snd-soc-rt5631.o
  135229. obj-$(CONFIG_SND_SOC_RT5640) += snd-soc-rt5640.o
  135230. obj-$(CONFIG_SND_SOC_RT5645) += snd-soc-rt5645.o
  135231. @@ -274,6 +279,7 @@
  135232. obj-$(CONFIG_SND_SOC_STAC9766) += snd-soc-stac9766.o
  135233. obj-$(CONFIG_SND_SOC_TAS2552) += snd-soc-tas2552.o
  135234. obj-$(CONFIG_SND_SOC_TAS5086) += snd-soc-tas5086.o
  135235. +obj-$(CONFIG_SND_SOC_TAS5713) += snd-soc-tas5713.o
  135236. obj-$(CONFIG_SND_SOC_TLV320AIC23) += snd-soc-tlv320aic23.o
  135237. obj-$(CONFIG_SND_SOC_TLV320AIC23_I2C) += snd-soc-tlv320aic23-i2c.o
  135238. obj-$(CONFIG_SND_SOC_TLV320AIC23_SPI) += snd-soc-tlv320aic23-spi.o
  135239. diff -Nur linux-3.18.8/sound/soc/codecs/pcm1794a.c linux-rpi/sound/soc/codecs/pcm1794a.c
  135240. --- linux-3.18.8/sound/soc/codecs/pcm1794a.c 1970-01-01 01:00:00.000000000 +0100
  135241. +++ linux-rpi/sound/soc/codecs/pcm1794a.c 2015-03-05 14:40:19.325715789 +0100
  135242. @@ -0,0 +1,62 @@
  135243. +/*
  135244. + * Driver for the PCM1794A codec
  135245. + *
  135246. + * Author: Florian Meier <florian.meier@koalo.de>
  135247. + * Copyright 2013
  135248. + *
  135249. + * This program is free software; you can redistribute it and/or
  135250. + * modify it under the terms of the GNU General Public License
  135251. + * version 2 as published by the Free Software Foundation.
  135252. + *
  135253. + * This program is distributed in the hope that it will be useful, but
  135254. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  135255. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  135256. + * General Public License for more details.
  135257. + */
  135258. +
  135259. +
  135260. +#include <linux/init.h>
  135261. +#include <linux/module.h>
  135262. +#include <linux/platform_device.h>
  135263. +
  135264. +#include <sound/soc.h>
  135265. +
  135266. +static struct snd_soc_dai_driver pcm1794a_dai = {
  135267. + .name = "pcm1794a-hifi",
  135268. + .playback = {
  135269. + .channels_min = 2,
  135270. + .channels_max = 2,
  135271. + .rates = SNDRV_PCM_RATE_8000_192000,
  135272. + .formats = SNDRV_PCM_FMTBIT_S16_LE |
  135273. + SNDRV_PCM_FMTBIT_S24_LE
  135274. + },
  135275. +};
  135276. +
  135277. +static struct snd_soc_codec_driver soc_codec_dev_pcm1794a;
  135278. +
  135279. +static int pcm1794a_probe(struct platform_device *pdev)
  135280. +{
  135281. + return snd_soc_register_codec(&pdev->dev, &soc_codec_dev_pcm1794a,
  135282. + &pcm1794a_dai, 1);
  135283. +}
  135284. +
  135285. +static int pcm1794a_remove(struct platform_device *pdev)
  135286. +{
  135287. + snd_soc_unregister_codec(&pdev->dev);
  135288. + return 0;
  135289. +}
  135290. +
  135291. +static struct platform_driver pcm1794a_codec_driver = {
  135292. + .probe = pcm1794a_probe,
  135293. + .remove = pcm1794a_remove,
  135294. + .driver = {
  135295. + .name = "pcm1794a-codec",
  135296. + .owner = THIS_MODULE,
  135297. + },
  135298. +};
  135299. +
  135300. +module_platform_driver(pcm1794a_codec_driver);
  135301. +
  135302. +MODULE_DESCRIPTION("ASoC PCM1794A codec driver");
  135303. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  135304. +MODULE_LICENSE("GPL v2");
  135305. diff -Nur linux-3.18.8/sound/soc/codecs/pcm5102a.c linux-rpi/sound/soc/codecs/pcm5102a.c
  135306. --- linux-3.18.8/sound/soc/codecs/pcm5102a.c 1970-01-01 01:00:00.000000000 +0100
  135307. +++ linux-rpi/sound/soc/codecs/pcm5102a.c 2015-03-05 14:40:19.325715789 +0100
  135308. @@ -0,0 +1,70 @@
  135309. +/*
  135310. + * Driver for the PCM5102A codec
  135311. + *
  135312. + * Author: Florian Meier <florian.meier@koalo.de>
  135313. + * Copyright 2013
  135314. + *
  135315. + * This program is free software; you can redistribute it and/or
  135316. + * modify it under the terms of the GNU General Public License
  135317. + * version 2 as published by the Free Software Foundation.
  135318. + *
  135319. + * This program is distributed in the hope that it will be useful, but
  135320. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  135321. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  135322. + * General Public License for more details.
  135323. + */
  135324. +
  135325. +
  135326. +#include <linux/init.h>
  135327. +#include <linux/module.h>
  135328. +#include <linux/platform_device.h>
  135329. +
  135330. +#include <sound/soc.h>
  135331. +
  135332. +static struct snd_soc_dai_driver pcm5102a_dai = {
  135333. + .name = "pcm5102a-hifi",
  135334. + .playback = {
  135335. + .channels_min = 2,
  135336. + .channels_max = 2,
  135337. + .rates = SNDRV_PCM_RATE_8000_192000,
  135338. + .formats = SNDRV_PCM_FMTBIT_S16_LE |
  135339. + SNDRV_PCM_FMTBIT_S24_LE |
  135340. + SNDRV_PCM_FMTBIT_S32_LE
  135341. + },
  135342. +};
  135343. +
  135344. +static struct snd_soc_codec_driver soc_codec_dev_pcm5102a;
  135345. +
  135346. +static int pcm5102a_probe(struct platform_device *pdev)
  135347. +{
  135348. + return snd_soc_register_codec(&pdev->dev, &soc_codec_dev_pcm5102a,
  135349. + &pcm5102a_dai, 1);
  135350. +}
  135351. +
  135352. +static int pcm5102a_remove(struct platform_device *pdev)
  135353. +{
  135354. + snd_soc_unregister_codec(&pdev->dev);
  135355. + return 0;
  135356. +}
  135357. +
  135358. +static const struct of_device_id pcm5102a_of_match[] = {
  135359. + { .compatible = "ti,pcm5102a", },
  135360. + { }
  135361. +};
  135362. +MODULE_DEVICE_TABLE(of, pcm5102a_of_match);
  135363. +
  135364. +static struct platform_driver pcm5102a_codec_driver = {
  135365. + .probe = pcm5102a_probe,
  135366. + .remove = pcm5102a_remove,
  135367. + .driver = {
  135368. + .name = "pcm5102a-codec",
  135369. + .owner = THIS_MODULE,
  135370. + .of_match_table = pcm5102a_of_match,
  135371. + },
  135372. +};
  135373. +
  135374. +module_platform_driver(pcm5102a_codec_driver);
  135375. +
  135376. +MODULE_DESCRIPTION("ASoC PCM5102A codec driver");
  135377. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  135378. +MODULE_LICENSE("GPL v2");
  135379. diff -Nur linux-3.18.8/sound/soc/codecs/pcm512x.c linux-rpi/sound/soc/codecs/pcm512x.c
  135380. --- linux-3.18.8/sound/soc/codecs/pcm512x.c 2015-02-27 02:49:36.000000000 +0100
  135381. +++ linux-rpi/sound/soc/codecs/pcm512x.c 2015-03-05 14:40:19.325715789 +0100
  135382. @@ -259,8 +259,8 @@
  135383. pcm512x_ramp_step_text);
  135384. static const struct snd_kcontrol_new pcm512x_controls[] = {
  135385. -SOC_DOUBLE_R_TLV("Digital Playback Volume", PCM512x_DIGITAL_VOLUME_2,
  135386. - PCM512x_DIGITAL_VOLUME_3, 0, 255, 1, digital_tlv),
  135387. +SOC_DOUBLE_R_RANGE_TLV("PCM", PCM512x_DIGITAL_VOLUME_2,
  135388. + PCM512x_DIGITAL_VOLUME_3, 0, 40, 255, 1, digital_tlv),
  135389. SOC_DOUBLE_TLV("Playback Volume", PCM512x_ANALOG_GAIN_CTRL,
  135390. PCM512x_LAGN_SHIFT, PCM512x_RAGN_SHIFT, 1, 1, analog_tlv),
  135391. SOC_DOUBLE_TLV("Playback Boost Volume", PCM512x_ANALOG_GAIN_BOOST,
  135392. diff -Nur linux-3.18.8/sound/soc/codecs/tas5713.c linux-rpi/sound/soc/codecs/tas5713.c
  135393. --- linux-3.18.8/sound/soc/codecs/tas5713.c 1970-01-01 01:00:00.000000000 +0100
  135394. +++ linux-rpi/sound/soc/codecs/tas5713.c 2015-03-05 14:40:19.333715789 +0100
  135395. @@ -0,0 +1,369 @@
  135396. +/*
  135397. + * ASoC Driver for TAS5713
  135398. + *
  135399. + * Author: Sebastian Eickhoff <basti.eickhoff@googlemail.com>
  135400. + * Copyright 2014
  135401. + *
  135402. + * This program is free software; you can redistribute it and/or
  135403. + * modify it under the terms of the GNU General Public License
  135404. + * version 2 as published by the Free Software Foundation.
  135405. + *
  135406. + * This program is distributed in the hope that it will be useful, but
  135407. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  135408. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  135409. + * General Public License for more details.
  135410. + */
  135411. +
  135412. +#include <linux/module.h>
  135413. +#include <linux/moduleparam.h>
  135414. +#include <linux/init.h>
  135415. +#include <linux/delay.h>
  135416. +#include <linux/pm.h>
  135417. +#include <linux/i2c.h>
  135418. +#include <linux/of_device.h>
  135419. +#include <linux/spi/spi.h>
  135420. +#include <linux/regmap.h>
  135421. +#include <linux/regulator/consumer.h>
  135422. +#include <linux/slab.h>
  135423. +#include <sound/core.h>
  135424. +#include <sound/pcm.h>
  135425. +#include <sound/pcm_params.h>
  135426. +#include <sound/soc.h>
  135427. +#include <sound/initval.h>
  135428. +#include <sound/tlv.h>
  135429. +
  135430. +#include <linux/kernel.h>
  135431. +#include <linux/string.h>
  135432. +#include <linux/fs.h>
  135433. +#include <asm/uaccess.h>
  135434. +
  135435. +#include "tas5713.h"
  135436. +
  135437. +
  135438. +static struct i2c_client *i2c;
  135439. +
  135440. +struct tas5713_priv {
  135441. + struct regmap *regmap;
  135442. + int mclk_div;
  135443. + struct snd_soc_codec *codec;
  135444. +};
  135445. +
  135446. +static struct tas5713_priv *priv_data;
  135447. +
  135448. +
  135449. +
  135450. +
  135451. +/*
  135452. + * _ _ ___ _ ___ _ _
  135453. + * /_\ | | / __| /_\ / __|___ _ _| |_ _ _ ___| |___
  135454. + * / _ \| |__\__ \/ _ \ | (__/ _ \ ' \ _| '_/ _ \ (_-<
  135455. + * /_/ \_\____|___/_/ \_\ \___\___/_||_\__|_| \___/_/__/
  135456. + *
  135457. + */
  135458. +
  135459. +static const DECLARE_TLV_DB_SCALE(tas5713_vol_tlv, -10000, 50, 1);
  135460. +
  135461. +
  135462. +static const struct snd_kcontrol_new tas5713_snd_controls[] = {
  135463. + SOC_SINGLE_TLV ("Master" , TAS5713_VOL_MASTER, 0, 248, 1, tas5713_vol_tlv),
  135464. + SOC_DOUBLE_R_TLV("Channels" , TAS5713_VOL_CH1, TAS5713_VOL_CH2, 0, 248, 1, tas5713_vol_tlv)
  135465. +};
  135466. +
  135467. +
  135468. +
  135469. +
  135470. +/*
  135471. + * __ __ _ _ ___ _
  135472. + * | \/ |__ _ __| |_ (_)_ _ ___ | \ _ _(_)_ _____ _ _
  135473. + * | |\/| / _` / _| ' \| | ' \/ -_) | |) | '_| \ V / -_) '_|
  135474. + * |_| |_\__,_\__|_||_|_|_||_\___| |___/|_| |_|\_/\___|_|
  135475. + *
  135476. + */
  135477. +
  135478. +static int tas5713_hw_params(struct snd_pcm_substream *substream,
  135479. + struct snd_pcm_hw_params *params,
  135480. + struct snd_soc_dai *dai)
  135481. +{
  135482. + u16 blen = 0x00;
  135483. +
  135484. + struct snd_soc_codec *codec;
  135485. + codec = dai->codec;
  135486. + priv_data->codec = dai->codec;
  135487. +
  135488. + switch (params_format(params)) {
  135489. + case SNDRV_PCM_FORMAT_S16_LE:
  135490. + blen = 0x03;
  135491. + break;
  135492. + case SNDRV_PCM_FORMAT_S20_3LE:
  135493. + blen = 0x1;
  135494. + break;
  135495. + case SNDRV_PCM_FORMAT_S24_LE:
  135496. + blen = 0x04;
  135497. + break;
  135498. + case SNDRV_PCM_FORMAT_S32_LE:
  135499. + blen = 0x05;
  135500. + break;
  135501. + default:
  135502. + dev_err(dai->dev, "Unsupported word length: %u\n",
  135503. + params_format(params));
  135504. + return -EINVAL;
  135505. + }
  135506. +
  135507. + // set word length
  135508. + snd_soc_update_bits(codec, TAS5713_SERIAL_DATA_INTERFACE, 0x7, blen);
  135509. +
  135510. + return 0;
  135511. +}
  135512. +
  135513. +
  135514. +static int tas5713_mute_stream(struct snd_soc_dai *dai, int mute, int stream)
  135515. +{
  135516. + unsigned int val = 0;
  135517. +
  135518. + struct tas5713_priv *tas5713;
  135519. + struct snd_soc_codec *codec = dai->codec;
  135520. + tas5713 = snd_soc_codec_get_drvdata(codec);
  135521. +
  135522. + if (mute) {
  135523. + val = TAS5713_SOFT_MUTE_ALL;
  135524. + }
  135525. +
  135526. + return regmap_write(tas5713->regmap, TAS5713_SOFT_MUTE, val);
  135527. +}
  135528. +
  135529. +
  135530. +static const struct snd_soc_dai_ops tas5713_dai_ops = {
  135531. + .hw_params = tas5713_hw_params,
  135532. + .mute_stream = tas5713_mute_stream,
  135533. +};
  135534. +
  135535. +
  135536. +static struct snd_soc_dai_driver tas5713_dai = {
  135537. + .name = "tas5713-hifi",
  135538. + .playback = {
  135539. + .stream_name = "Playback",
  135540. + .channels_min = 2,
  135541. + .channels_max = 2,
  135542. + .rates = SNDRV_PCM_RATE_8000_48000,
  135543. + .formats = (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE ),
  135544. + },
  135545. + .ops = &tas5713_dai_ops,
  135546. +};
  135547. +
  135548. +
  135549. +
  135550. +
  135551. +/*
  135552. + * ___ _ ___ _
  135553. + * / __|___ __| |___ __ | \ _ _(_)_ _____ _ _
  135554. + * | (__/ _ \/ _` / -_) _| | |) | '_| \ V / -_) '_|
  135555. + * \___\___/\__,_\___\__| |___/|_| |_|\_/\___|_|
  135556. + *
  135557. + */
  135558. +
  135559. +static int tas5713_remove(struct snd_soc_codec *codec)
  135560. +{
  135561. + struct tas5713_priv *tas5713;
  135562. +
  135563. + tas5713 = snd_soc_codec_get_drvdata(codec);
  135564. +
  135565. + return 0;
  135566. +}
  135567. +
  135568. +
  135569. +static int tas5713_probe(struct snd_soc_codec *codec)
  135570. +{
  135571. + struct tas5713_priv *tas5713;
  135572. + int i, ret;
  135573. +
  135574. + i2c = container_of(codec->dev, struct i2c_client, dev);
  135575. +
  135576. + tas5713 = snd_soc_codec_get_drvdata(codec);
  135577. +
  135578. + // Reset error
  135579. + ret = snd_soc_write(codec, TAS5713_ERROR_STATUS, 0x00);
  135580. + if (ret < 0) return ret;
  135581. +
  135582. + // Trim oscillator
  135583. + ret = snd_soc_write(codec, TAS5713_OSC_TRIM, 0x00);
  135584. + if (ret < 0) return ret;
  135585. + msleep(1000);
  135586. +
  135587. + // Reset error
  135588. + ret = snd_soc_write(codec, TAS5713_ERROR_STATUS, 0x00);
  135589. + if (ret < 0) return ret;
  135590. +
  135591. + // Clock mode: 44/48kHz, MCLK=64xfs
  135592. + ret = snd_soc_write(codec, TAS5713_CLOCK_CTRL, 0x60);
  135593. + if (ret < 0) return ret;
  135594. +
  135595. + // I2S 24bit
  135596. + ret = snd_soc_write(codec, TAS5713_SERIAL_DATA_INTERFACE, 0x05);
  135597. + if (ret < 0) return ret;
  135598. +
  135599. + // Unmute
  135600. + ret = snd_soc_write(codec, TAS5713_SYSTEM_CTRL2, 0x00);
  135601. + if (ret < 0) return ret;
  135602. + ret = snd_soc_write(codec, TAS5713_SOFT_MUTE, 0x00);
  135603. + if (ret < 0) return ret;
  135604. +
  135605. + // Set volume to 0db
  135606. + ret = snd_soc_write(codec, TAS5713_VOL_MASTER, 0x00);
  135607. + if (ret < 0) return ret;
  135608. +
  135609. + // Now start programming the default initialization sequence
  135610. + for (i = 0; i < ARRAY_SIZE(tas5713_init_sequence); ++i) {
  135611. + ret = i2c_master_send(i2c,
  135612. + tas5713_init_sequence[i].data,
  135613. + tas5713_init_sequence[i].size);
  135614. + if (ret < 0) {
  135615. + printk(KERN_INFO "TAS5713 CODEC PROBE: InitSeq returns: %d\n", ret);
  135616. + }
  135617. + }
  135618. +
  135619. + // Unmute
  135620. + ret = snd_soc_write(codec, TAS5713_SYSTEM_CTRL2, 0x00);
  135621. + if (ret < 0) return ret;
  135622. +
  135623. + return 0;
  135624. +}
  135625. +
  135626. +
  135627. +static struct snd_soc_codec_driver soc_codec_dev_tas5713 = {
  135628. + .probe = tas5713_probe,
  135629. + .remove = tas5713_remove,
  135630. + .controls = tas5713_snd_controls,
  135631. + .num_controls = ARRAY_SIZE(tas5713_snd_controls),
  135632. +};
  135633. +
  135634. +
  135635. +
  135636. +
  135637. +/*
  135638. + * ___ ___ ___ ___ _
  135639. + * |_ _|_ ) __| | \ _ _(_)_ _____ _ _
  135640. + * | | / / (__ | |) | '_| \ V / -_) '_|
  135641. + * |___/___\___| |___/|_| |_|\_/\___|_|
  135642. + *
  135643. + */
  135644. +
  135645. +static const struct reg_default tas5713_reg_defaults[] = {
  135646. + { 0x07 ,0x80 }, // R7 - VOL_MASTER - -40dB
  135647. + { 0x08 , 30 }, // R8 - VOL_CH1 - 0dB
  135648. + { 0x09 , 30 }, // R9 - VOL_CH2 - 0dB
  135649. + { 0x0A ,0x80 }, // R10 - VOL_HEADPHONE - -40dB
  135650. +};
  135651. +
  135652. +
  135653. +static bool tas5713_reg_volatile(struct device *dev, unsigned int reg)
  135654. +{
  135655. + switch (reg) {
  135656. + case TAS5713_DEVICE_ID:
  135657. + case TAS5713_ERROR_STATUS:
  135658. + return true;
  135659. + default:
  135660. + return false;
  135661. + }
  135662. +}
  135663. +
  135664. +
  135665. +static const struct of_device_id tas5713_of_match[] = {
  135666. + { .compatible = "ti,tas5713", },
  135667. + { }
  135668. +};
  135669. +MODULE_DEVICE_TABLE(of, tas5713_of_match);
  135670. +
  135671. +
  135672. +static struct regmap_config tas5713_regmap_config = {
  135673. + .reg_bits = 8,
  135674. + .val_bits = 8,
  135675. +
  135676. + .max_register = TAS5713_MAX_REGISTER,
  135677. + .volatile_reg = tas5713_reg_volatile,
  135678. +
  135679. + .cache_type = REGCACHE_RBTREE,
  135680. + .reg_defaults = tas5713_reg_defaults,
  135681. + .num_reg_defaults = ARRAY_SIZE(tas5713_reg_defaults),
  135682. +};
  135683. +
  135684. +
  135685. +static int tas5713_i2c_probe(struct i2c_client *i2c,
  135686. + const struct i2c_device_id *id)
  135687. +{
  135688. + int ret;
  135689. +
  135690. + priv_data = devm_kzalloc(&i2c->dev, sizeof *priv_data, GFP_KERNEL);
  135691. + if (!priv_data)
  135692. + return -ENOMEM;
  135693. +
  135694. + priv_data->regmap = devm_regmap_init_i2c(i2c, &tas5713_regmap_config);
  135695. + if (IS_ERR(priv_data->regmap)) {
  135696. + ret = PTR_ERR(priv_data->regmap);
  135697. + return ret;
  135698. + }
  135699. +
  135700. + i2c_set_clientdata(i2c, priv_data);
  135701. +
  135702. + ret = snd_soc_register_codec(&i2c->dev,
  135703. + &soc_codec_dev_tas5713, &tas5713_dai, 1);
  135704. +
  135705. + return ret;
  135706. +}
  135707. +
  135708. +
  135709. +static int tas5713_i2c_remove(struct i2c_client *i2c)
  135710. +{
  135711. + snd_soc_unregister_codec(&i2c->dev);
  135712. + i2c_set_clientdata(i2c, NULL);
  135713. +
  135714. + kfree(priv_data);
  135715. +
  135716. + return 0;
  135717. +}
  135718. +
  135719. +
  135720. +static const struct i2c_device_id tas5713_i2c_id[] = {
  135721. + { "tas5713", 0 },
  135722. + { }
  135723. +};
  135724. +
  135725. +MODULE_DEVICE_TABLE(i2c, tas5713_i2c_id);
  135726. +
  135727. +
  135728. +static struct i2c_driver tas5713_i2c_driver = {
  135729. + .driver = {
  135730. + .name = "tas5713",
  135731. + .owner = THIS_MODULE,
  135732. + .of_match_table = tas5713_of_match,
  135733. + },
  135734. + .probe = tas5713_i2c_probe,
  135735. + .remove = tas5713_i2c_remove,
  135736. + .id_table = tas5713_i2c_id
  135737. +};
  135738. +
  135739. +
  135740. +static int __init tas5713_modinit(void)
  135741. +{
  135742. + int ret = 0;
  135743. +
  135744. + ret = i2c_add_driver(&tas5713_i2c_driver);
  135745. + if (ret) {
  135746. + printk(KERN_ERR "Failed to register tas5713 I2C driver: %d\n",
  135747. + ret);
  135748. + }
  135749. +
  135750. + return ret;
  135751. +}
  135752. +module_init(tas5713_modinit);
  135753. +
  135754. +
  135755. +static void __exit tas5713_exit(void)
  135756. +{
  135757. + i2c_del_driver(&tas5713_i2c_driver);
  135758. +}
  135759. +module_exit(tas5713_exit);
  135760. +
  135761. +
  135762. +MODULE_AUTHOR("Sebastian Eickhoff <basti.eickhoff@googlemail.com>");
  135763. +MODULE_DESCRIPTION("ASoC driver for TAS5713");
  135764. +MODULE_LICENSE("GPL v2");
  135765. diff -Nur linux-3.18.8/sound/soc/codecs/tas5713.h linux-rpi/sound/soc/codecs/tas5713.h
  135766. --- linux-3.18.8/sound/soc/codecs/tas5713.h 1970-01-01 01:00:00.000000000 +0100
  135767. +++ linux-rpi/sound/soc/codecs/tas5713.h 2015-03-05 14:40:19.333715789 +0100
  135768. @@ -0,0 +1,210 @@
  135769. +/*
  135770. + * ASoC Driver for TAS5713
  135771. + *
  135772. + * Author: Sebastian Eickhoff <basti.eickhoff@googlemail.com>
  135773. + * Copyright 2014
  135774. + *
  135775. + * This program is free software; you can redistribute it and/or
  135776. + * modify it under the terms of the GNU General Public License
  135777. + * version 2 as published by the Free Software Foundation.
  135778. + *
  135779. + * This program is distributed in the hope that it will be useful, but
  135780. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  135781. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  135782. + * General Public License for more details.
  135783. + */
  135784. +
  135785. +#ifndef _TAS5713_H
  135786. +#define _TAS5713_H
  135787. +
  135788. +
  135789. +// TAS5713 I2C-bus register addresses
  135790. +
  135791. +#define TAS5713_CLOCK_CTRL 0x00
  135792. +#define TAS5713_DEVICE_ID 0x01
  135793. +#define TAS5713_ERROR_STATUS 0x02
  135794. +#define TAS5713_SYSTEM_CTRL1 0x03
  135795. +#define TAS5713_SERIAL_DATA_INTERFACE 0x04
  135796. +#define TAS5713_SYSTEM_CTRL2 0x05
  135797. +#define TAS5713_SOFT_MUTE 0x06
  135798. +#define TAS5713_VOL_MASTER 0x07
  135799. +#define TAS5713_VOL_CH1 0x08
  135800. +#define TAS5713_VOL_CH2 0x09
  135801. +#define TAS5713_VOL_HEADPHONE 0x0A
  135802. +#define TAS5713_VOL_CONFIG 0x0E
  135803. +#define TAS5713_MODULATION_LIMIT 0x10
  135804. +#define TAS5713_IC_DLY_CH1 0x11
  135805. +#define TAS5713_IC_DLY_CH2 0x12
  135806. +#define TAS5713_IC_DLY_CH3 0x13
  135807. +#define TAS5713_IC_DLY_CH4 0x14
  135808. +
  135809. +#define TAS5713_START_STOP_PERIOD 0x1A
  135810. +#define TAS5713_OSC_TRIM 0x1B
  135811. +#define TAS5713_BKND_ERR 0x1C
  135812. +
  135813. +#define TAS5713_INPUT_MUX 0x20
  135814. +#define TAS5713_SRC_SELECT_CH4 0x21
  135815. +#define TAS5713_PWM_MUX 0x25
  135816. +
  135817. +#define TAS5713_CH1_BQ0 0x29
  135818. +#define TAS5713_CH1_BQ1 0x2A
  135819. +#define TAS5713_CH1_BQ2 0x2B
  135820. +#define TAS5713_CH1_BQ3 0x2C
  135821. +#define TAS5713_CH1_BQ4 0x2D
  135822. +#define TAS5713_CH1_BQ5 0x2E
  135823. +#define TAS5713_CH1_BQ6 0x2F
  135824. +#define TAS5713_CH1_BQ7 0x58
  135825. +#define TAS5713_CH1_BQ8 0x59
  135826. +
  135827. +#define TAS5713_CH2_BQ0 0x30
  135828. +#define TAS5713_CH2_BQ1 0x31
  135829. +#define TAS5713_CH2_BQ2 0x32
  135830. +#define TAS5713_CH2_BQ3 0x33
  135831. +#define TAS5713_CH2_BQ4 0x34
  135832. +#define TAS5713_CH2_BQ5 0x35
  135833. +#define TAS5713_CH2_BQ6 0x36
  135834. +#define TAS5713_CH2_BQ7 0x5C
  135835. +#define TAS5713_CH2_BQ8 0x5D
  135836. +
  135837. +#define TAS5713_CH4_BQ0 0x5A
  135838. +#define TAS5713_CH4_BQ1 0x5B
  135839. +#define TAS5713_CH3_BQ0 0x5E
  135840. +#define TAS5713_CH3_BQ1 0x5F
  135841. +
  135842. +#define TAS5713_DRC1_SOFTENING_FILTER_ALPHA_OMEGA 0x3B
  135843. +#define TAS5713_DRC1_ATTACK_RELEASE_RATE 0x3C
  135844. +#define TAS5713_DRC2_SOFTENING_FILTER_ALPHA_OMEGA 0x3E
  135845. +#define TAS5713_DRC2_ATTACK_RELEASE_RATE 0x3F
  135846. +#define TAS5713_DRC1_ATTACK_RELEASE_THRES 0x40
  135847. +#define TAS5713_DRC2_ATTACK_RELEASE_THRES 0x43
  135848. +#define TAS5713_DRC_CTRL 0x46
  135849. +
  135850. +#define TAS5713_BANK_SW_CTRL 0x50
  135851. +#define TAS5713_CH1_OUTPUT_MIXER 0x51
  135852. +#define TAS5713_CH2_OUTPUT_MIXER 0x52
  135853. +#define TAS5713_CH1_INPUT_MIXER 0x53
  135854. +#define TAS5713_CH2_INPUT_MIXER 0x54
  135855. +#define TAS5713_OUTPUT_POST_SCALE 0x56
  135856. +#define TAS5713_OUTPUT_PRESCALE 0x57
  135857. +
  135858. +#define TAS5713_IDF_POST_SCALE 0x62
  135859. +
  135860. +#define TAS5713_CH1_INLINE_MIXER 0x70
  135861. +#define TAS5713_CH1_INLINE_DRC_EN_MIXER 0x71
  135862. +#define TAS5713_CH1_R_CHANNEL_MIXER 0x72
  135863. +#define TAS5713_CH1_L_CHANNEL_MIXER 0x73
  135864. +#define TAS5713_CH2_INLINE_MIXER 0x74
  135865. +#define TAS5713_CH2_INLINE_DRC_EN_MIXER 0x75
  135866. +#define TAS5713_CH2_L_CHANNEL_MIXER 0x76
  135867. +#define TAS5713_CH2_R_CHANNEL_MIXER 0x77
  135868. +
  135869. +#define TAS5713_UPDATE_DEV_ADDR_KEY 0xF8
  135870. +#define TAS5713_UPDATE_DEV_ADDR_REG 0xF9
  135871. +
  135872. +#define TAS5713_REGISTER_COUNT 0x46
  135873. +#define TAS5713_MAX_REGISTER 0xF9
  135874. +
  135875. +
  135876. +// Bitmasks for registers
  135877. +#define TAS5713_SOFT_MUTE_ALL 0x07
  135878. +
  135879. +
  135880. +
  135881. +struct tas5713_init_command {
  135882. + const int size;
  135883. + const char *const data;
  135884. +};
  135885. +
  135886. +static const struct tas5713_init_command tas5713_init_sequence[] = {
  135887. +
  135888. + // Trim oscillator
  135889. + { .size = 2, .data = "\x1B\x00" },
  135890. + // System control register 1 (0x03): block DC
  135891. + { .size = 2, .data = "\x03\x80" },
  135892. + // Mute everything
  135893. + { .size = 2, .data = "\x05\x40" },
  135894. + // Modulation limit register (0x10): 97.7%
  135895. + { .size = 2, .data = "\x10\x02" },
  135896. + // Interchannel delay registers
  135897. + // (0x11, 0x12, 0x13, and 0x14): BD mode
  135898. + { .size = 2, .data = "\x11\xB8" },
  135899. + { .size = 2, .data = "\x12\x60" },
  135900. + { .size = 2, .data = "\x13\xA0" },
  135901. + { .size = 2, .data = "\x14\x48" },
  135902. + // PWM shutdown group register (0x19): no shutdown
  135903. + { .size = 2, .data = "\x19\x00" },
  135904. + // Input multiplexer register (0x20): BD mode
  135905. + { .size = 2, .data = "\x20\x00\x89\x77\x72" },
  135906. + // PWM output mux register (0x25)
  135907. + // Channel 1 --> OUTA, channel 1 neg --> OUTB
  135908. + // Channel 2 --> OUTC, channel 2 neg --> OUTD
  135909. + { .size = 5, .data = "\x25\x01\x02\x13\x45" },
  135910. + // DRC control (0x46): DRC off
  135911. + { .size = 5, .data = "\x46\x00\x00\x00\x00" },
  135912. + // BKND_ERR register (0x1C): 299ms reset period
  135913. + { .size = 2, .data = "\x1C\x07" },
  135914. + // Mute channel 3
  135915. + { .size = 2, .data = "\x0A\xFF" },
  135916. + // Volume configuration register (0x0E): volume slew 512 steps
  135917. + { .size = 2, .data = "\x0E\x90" },
  135918. + // Clock control register (0x00): 44/48kHz, MCLK=64xfs
  135919. + { .size = 2, .data = "\x00\x60" },
  135920. + // Bank switch and eq control (0x50): no bank switching
  135921. + { .size = 5, .data = "\x50\x00\x00\x00\x00" },
  135922. + // Volume registers (0x07, 0x08, 0x09, 0x0A)
  135923. + { .size = 2, .data = "\x07\x20" },
  135924. + { .size = 2, .data = "\x08\x30" },
  135925. + { .size = 2, .data = "\x09\x30" },
  135926. + { .size = 2, .data = "\x0A\xFF" },
  135927. + // 0x72, 0x73, 0x76, 0x77 input mixer:
  135928. + // no intermix between channels
  135929. + { .size = 5, .data = "\x72\x00\x00\x00\x00" },
  135930. + { .size = 5, .data = "\x73\x00\x80\x00\x00" },
  135931. + { .size = 5, .data = "\x76\x00\x00\x00\x00" },
  135932. + { .size = 5, .data = "\x77\x00\x80\x00\x00" },
  135933. + // 0x70, 0x71, 0x74, 0x75 inline DRC mixer:
  135934. + // no inline DRC inmix
  135935. + { .size = 5, .data = "\x70\x00\x80\x00\x00" },
  135936. + { .size = 5, .data = "\x71\x00\x00\x00\x00" },
  135937. + { .size = 5, .data = "\x74\x00\x80\x00\x00" },
  135938. + { .size = 5, .data = "\x75\x00\x00\x00\x00" },
  135939. + // 0x56, 0x57 Output scale
  135940. + { .size = 5, .data = "\x56\x00\x80\x00\x00" },
  135941. + { .size = 5, .data = "\x57\x00\x02\x00\x00" },
  135942. + // 0x3B, 0x3c
  135943. + { .size = 9, .data = "\x3B\x00\x08\x00\x00\x00\x78\x00\x00" },
  135944. + { .size = 9, .data = "\x3C\x00\x00\x01\x00\xFF\xFF\xFF\x00" },
  135945. + { .size = 9, .data = "\x3E\x00\x08\x00\x00\x00\x78\x00\x00" },
  135946. + { .size = 9, .data = "\x3F\x00\x00\x01\x00\xFF\xFF\xFF\x00" },
  135947. + { .size = 9, .data = "\x40\x00\x00\x01\x00\xFF\xFF\xFF\x00" },
  135948. + { .size = 9, .data = "\x43\x00\x00\x01\x00\xFF\xFF\xFF\x00" },
  135949. + // 0x51, 0x52: output mixer
  135950. + { .size = 9, .data = "\x51\x00\x80\x00\x00\x00\x00\x00\x00" },
  135951. + { .size = 9, .data = "\x52\x00\x80\x00\x00\x00\x00\x00\x00" },
  135952. + // PEQ defaults
  135953. + { .size = 21, .data = "\x29\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
  135954. + { .size = 21, .data = "\x2A\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
  135955. + { .size = 21, .data = "\x2B\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
  135956. + { .size = 21, .data = "\x2C\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
  135957. + { .size = 21, .data = "\x2D\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
  135958. + { .size = 21, .data = "\x2E\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
  135959. + { .size = 21, .data = "\x2F\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
  135960. + { .size = 21, .data = "\x30\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
  135961. + { .size = 21, .data = "\x31\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
  135962. + { .size = 21, .data = "\x32\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
  135963. + { .size = 21, .data = "\x33\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
  135964. + { .size = 21, .data = "\x34\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
  135965. + { .size = 21, .data = "\x35\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
  135966. + { .size = 21, .data = "\x36\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
  135967. + { .size = 21, .data = "\x58\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
  135968. + { .size = 21, .data = "\x59\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
  135969. + { .size = 21, .data = "\x5C\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
  135970. + { .size = 21, .data = "\x5D\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
  135971. + { .size = 21, .data = "\x5E\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
  135972. + { .size = 21, .data = "\x5F\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
  135973. + { .size = 21, .data = "\x5A\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
  135974. + { .size = 21, .data = "\x5B\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
  135975. +};
  135976. +
  135977. +
  135978. +#endif /* _TAS5713_H */
  135979. diff -Nur linux-3.18.8/sound/soc/codecs/wm8804.c linux-rpi/sound/soc/codecs/wm8804.c
  135980. --- linux-3.18.8/sound/soc/codecs/wm8804.c 2015-02-27 02:49:36.000000000 +0100
  135981. +++ linux-rpi/sound/soc/codecs/wm8804.c 2015-03-05 14:40:19.341715789 +0100
  135982. @@ -278,6 +278,7 @@
  135983. blen = 0x1;
  135984. break;
  135985. case 24:
  135986. + case 32:
  135987. blen = 0x2;
  135988. break;
  135989. default:
  135990. @@ -624,7 +625,7 @@
  135991. };
  135992. #define WM8804_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \
  135993. - SNDRV_PCM_FMTBIT_S24_LE)
  135994. + SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S32_LE)
  135995. #define WM8804_RATES (SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
  135996. SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_64000 | \
  135997. @@ -655,7 +656,7 @@
  135998. .probe = wm8804_probe,
  135999. .remove = wm8804_remove,
  136000. .set_bias_level = wm8804_set_bias_level,
  136001. - .idle_bias_off = true,
  136002. + .idle_bias_off = false,
  136003. .controls = wm8804_snd_controls,
  136004. .num_controls = ARRAY_SIZE(wm8804_snd_controls),