dwc_otg_cil.c 205 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104
  1. /* ==========================================================================
  2. * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_cil.c $
  3. * $Revision: #189 $
  4. * $Date: 2011/10/24 $
  5. * $Change: 1871160 $
  6. *
  7. * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  8. * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  9. * otherwise expressly agreed to in writing between Synopsys and you.
  10. *
  11. * The Software IS NOT an item of Licensed Software or Licensed Product under
  12. * any End User Software License Agreement or Agreement for Licensed Product
  13. * with Synopsys or any supplement thereto. You are permitted to use and
  14. * redistribute this Software in source and binary forms, with or without
  15. * modification, provided that redistributions of source code must retain this
  16. * notice. You may not view, use, disclose, copy or distribute this file or
  17. * any information contained herein except pursuant to this license grant from
  18. * Synopsys. If you do not agree with this notice, including the disclaimer
  19. * below, then you are not authorized to use the Software.
  20. *
  21. * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  22. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24. * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  25. * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  26. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  27. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  28. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  29. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  30. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  31. * DAMAGE.
  32. * ========================================================================== */
  33. /** @file
  34. *
  35. * The Core Interface Layer provides basic services for accessing and
  36. * managing the DWC_otg hardware. These services are used by both the
  37. * Host Controller Driver and the Peripheral Controller Driver.
  38. *
  39. * The CIL manages the memory map for the core so that the HCD and PCD
  40. * don't have to do this separately. It also handles basic tasks like
  41. * reading/writing the registers and data FIFOs in the controller.
  42. * Some of the data access functions provide encapsulation of several
  43. * operations required to perform a task, such as writing multiple
  44. * registers to start a transfer. Finally, the CIL performs basic
  45. * services that are not specific to either the host or device modes
  46. * of operation. These services include management of the OTG Host
  47. * Negotiation Protocol (HNP) and Session Request Protocol (SRP). A
  48. * Diagnostic API is also provided to allow testing of the controller
  49. * hardware.
  50. *
  51. * The Core Interface Layer has the following requirements:
  52. * - Provides basic controller operations.
  53. * - Minimal use of OS services.
  54. * - The OS services used will be abstracted by using inline functions
  55. * or macros.
  56. *
  57. */
  58. #include "dwc_os.h"
  59. #include "dwc_otg_regs.h"
  60. #include "dwc_otg_cil.h"
  61. #include <asm/system.h>
  62. static int dwc_otg_setup_params(dwc_otg_core_if_t * core_if);
  63. /* ------------------------------------------------------- */
  64. /*
  65. Tool functions
  66. */
  67. void dwc_otg_set_vbus_power(dwc_otg_core_if_t * _core_if, char is_power_on)
  68. {
  69. if (_core_if->set_vbus_power)
  70. _core_if->set_vbus_power(is_power_on);
  71. }
  72. /**
  73. * This function is called to initialize the DWC_otg CSR data
  74. * structures. The register addresses in the device and host
  75. * structures are initialized from the base address supplied by the
  76. * caller. The calling function must make the OS calls to get the
  77. * base address of the DWC_otg controller registers. The core_params
  78. * argument holds the parameters that specify how the core should be
  79. * configured.
  80. *
  81. * @param reg_base_addr Base address of DWC_otg core registers
  82. *
  83. */
  84. dwc_otg_core_if_t *dwc_otg_cil_init(const uint32_t * reg_base_addr)
  85. {
  86. dwc_otg_core_if_t *core_if = 0;
  87. dwc_otg_dev_if_t *dev_if = 0;
  88. dwc_otg_host_if_t *host_if = 0;
  89. uint8_t *reg_base = (uint8_t *) reg_base_addr;
  90. int i = 0;
  91. DWC_DEBUGPL(DBG_CILV, "%s(%p)\n", __func__, reg_base_addr);
  92. core_if = DWC_ALLOC(sizeof(dwc_otg_core_if_t));
  93. if (core_if == NULL) {
  94. DWC_DEBUGPL(DBG_CIL,
  95. "Allocation of dwc_otg_core_if_t failed\n");
  96. return 0;
  97. }
  98. core_if->core_global_regs = (dwc_otg_core_global_regs_t *) reg_base;
  99. /*
  100. * Allocate the Device Mode structures.
  101. */
  102. dev_if = DWC_ALLOC(sizeof(dwc_otg_dev_if_t));
  103. if (dev_if == NULL) {
  104. DWC_DEBUGPL(DBG_CIL, "Allocation of dwc_otg_dev_if_t failed\n");
  105. DWC_FREE(core_if);
  106. return 0;
  107. }
  108. dev_if->dev_global_regs =
  109. (dwc_otg_device_global_regs_t *) (reg_base +
  110. DWC_DEV_GLOBAL_REG_OFFSET);
  111. for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  112. dev_if->in_ep_regs[i] = (dwc_otg_dev_in_ep_regs_t *)
  113. (reg_base + DWC_DEV_IN_EP_REG_OFFSET +
  114. (i * DWC_EP_REG_OFFSET));
  115. dev_if->out_ep_regs[i] = (dwc_otg_dev_out_ep_regs_t *)
  116. (reg_base + DWC_DEV_OUT_EP_REG_OFFSET +
  117. (i * DWC_EP_REG_OFFSET));
  118. DWC_DEBUGPL(DBG_CILV, "in_ep_regs[%d]->diepctl=%p\n",
  119. i, &dev_if->in_ep_regs[i]->diepctl);
  120. DWC_DEBUGPL(DBG_CILV, "out_ep_regs[%d]->doepctl=%p\n",
  121. i, &dev_if->out_ep_regs[i]->doepctl);
  122. }
  123. dev_if->speed = 0; // unknown
  124. core_if->dev_if = dev_if;
  125. /*
  126. * Allocate the Host Mode structures.
  127. */
  128. host_if = DWC_ALLOC(sizeof(dwc_otg_host_if_t));
  129. if (host_if == NULL) {
  130. DWC_DEBUGPL(DBG_CIL,
  131. "Allocation of dwc_otg_host_if_t failed\n");
  132. DWC_FREE(dev_if);
  133. DWC_FREE(core_if);
  134. return 0;
  135. }
  136. host_if->host_global_regs = (dwc_otg_host_global_regs_t *)
  137. (reg_base + DWC_OTG_HOST_GLOBAL_REG_OFFSET);
  138. host_if->hprt0 =
  139. (uint32_t *) (reg_base + DWC_OTG_HOST_PORT_REGS_OFFSET);
  140. for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  141. host_if->hc_regs[i] = (dwc_otg_hc_regs_t *)
  142. (reg_base + DWC_OTG_HOST_CHAN_REGS_OFFSET +
  143. (i * DWC_OTG_CHAN_REGS_OFFSET));
  144. DWC_DEBUGPL(DBG_CILV, "hc_reg[%d]->hcchar=%p\n",
  145. i, &host_if->hc_regs[i]->hcchar);
  146. }
  147. host_if->num_host_channels = MAX_EPS_CHANNELS;
  148. core_if->host_if = host_if;
  149. for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  150. core_if->data_fifo[i] =
  151. (uint32_t *) (reg_base + DWC_OTG_DATA_FIFO_OFFSET +
  152. (i * DWC_OTG_DATA_FIFO_SIZE));
  153. DWC_DEBUGPL(DBG_CILV, "data_fifo[%d]=0x%08lx\n",
  154. i, (unsigned long)core_if->data_fifo[i]);
  155. }
  156. core_if->pcgcctl = (uint32_t *) (reg_base + DWC_OTG_PCGCCTL_OFFSET);
  157. /* Initiate lx_state to L3 disconnected state */
  158. core_if->lx_state = DWC_OTG_L3;
  159. /*
  160. * Store the contents of the hardware configuration registers here for
  161. * easy access later.
  162. */
  163. core_if->hwcfg1.d32 =
  164. DWC_READ_REG32(&core_if->core_global_regs->ghwcfg1);
  165. core_if->hwcfg2.d32 =
  166. DWC_READ_REG32(&core_if->core_global_regs->ghwcfg2);
  167. core_if->hwcfg3.d32 =
  168. DWC_READ_REG32(&core_if->core_global_regs->ghwcfg3);
  169. core_if->hwcfg4.d32 =
  170. DWC_READ_REG32(&core_if->core_global_regs->ghwcfg4);
  171. /* Force host mode to get HPTXFSIZ exact power on value */
  172. {
  173. gusbcfg_data_t gusbcfg = {.d32 = 0 };
  174. gusbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  175. gusbcfg.b.force_host_mode = 1;
  176. DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, gusbcfg.d32);
  177. dwc_mdelay(100);
  178. core_if->hptxfsiz.d32 =
  179. DWC_READ_REG32(&core_if->core_global_regs->hptxfsiz);
  180. gusbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  181. gusbcfg.b.force_host_mode = 0;
  182. DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, gusbcfg.d32);
  183. dwc_mdelay(100);
  184. }
  185. DWC_DEBUGPL(DBG_CILV, "hwcfg1=%08x\n", core_if->hwcfg1.d32);
  186. DWC_DEBUGPL(DBG_CILV, "hwcfg2=%08x\n", core_if->hwcfg2.d32);
  187. DWC_DEBUGPL(DBG_CILV, "hwcfg3=%08x\n", core_if->hwcfg3.d32);
  188. DWC_DEBUGPL(DBG_CILV, "hwcfg4=%08x\n", core_if->hwcfg4.d32);
  189. core_if->hcfg.d32 =
  190. DWC_READ_REG32(&core_if->host_if->host_global_regs->hcfg);
  191. core_if->dcfg.d32 =
  192. DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  193. DWC_DEBUGPL(DBG_CILV, "hcfg=%08x\n", core_if->hcfg.d32);
  194. DWC_DEBUGPL(DBG_CILV, "dcfg=%08x\n", core_if->dcfg.d32);
  195. DWC_DEBUGPL(DBG_CILV, "op_mode=%0x\n", core_if->hwcfg2.b.op_mode);
  196. DWC_DEBUGPL(DBG_CILV, "arch=%0x\n", core_if->hwcfg2.b.architecture);
  197. DWC_DEBUGPL(DBG_CILV, "num_dev_ep=%d\n", core_if->hwcfg2.b.num_dev_ep);
  198. DWC_DEBUGPL(DBG_CILV, "num_host_chan=%d\n",
  199. core_if->hwcfg2.b.num_host_chan);
  200. DWC_DEBUGPL(DBG_CILV, "nonperio_tx_q_depth=0x%0x\n",
  201. core_if->hwcfg2.b.nonperio_tx_q_depth);
  202. DWC_DEBUGPL(DBG_CILV, "host_perio_tx_q_depth=0x%0x\n",
  203. core_if->hwcfg2.b.host_perio_tx_q_depth);
  204. DWC_DEBUGPL(DBG_CILV, "dev_token_q_depth=0x%0x\n",
  205. core_if->hwcfg2.b.dev_token_q_depth);
  206. DWC_DEBUGPL(DBG_CILV, "Total FIFO SZ=%d\n",
  207. core_if->hwcfg3.b.dfifo_depth);
  208. DWC_DEBUGPL(DBG_CILV, "xfer_size_cntr_width=%0x\n",
  209. core_if->hwcfg3.b.xfer_size_cntr_width);
  210. /*
  211. * Set the SRP sucess bit for FS-I2c
  212. */
  213. core_if->srp_success = 0;
  214. core_if->srp_timer_started = 0;
  215. /*
  216. * Create new workqueue and init works
  217. */
  218. core_if->wq_otg = DWC_WORKQ_ALLOC("dwc_otg");
  219. if (core_if->wq_otg == 0) {
  220. DWC_WARN("DWC_WORKQ_ALLOC failed\n");
  221. DWC_FREE(host_if);
  222. DWC_FREE(dev_if);
  223. DWC_FREE(core_if);
  224. return 0;
  225. }
  226. core_if->snpsid = DWC_READ_REG32(&core_if->core_global_regs->gsnpsid);
  227. DWC_PRINTF("Core Release: %x.%x%x%x\n",
  228. (core_if->snpsid >> 12 & 0xF),
  229. (core_if->snpsid >> 8 & 0xF),
  230. (core_if->snpsid >> 4 & 0xF), (core_if->snpsid & 0xF));
  231. core_if->wkp_timer = DWC_TIMER_ALLOC("Wake Up Timer",
  232. w_wakeup_detected, core_if);
  233. if (core_if->wkp_timer == 0) {
  234. DWC_WARN("DWC_TIMER_ALLOC failed\n");
  235. DWC_FREE(host_if);
  236. DWC_FREE(dev_if);
  237. DWC_WORKQ_FREE(core_if->wq_otg);
  238. DWC_FREE(core_if);
  239. return 0;
  240. }
  241. if (dwc_otg_setup_params(core_if)) {
  242. DWC_WARN("Error while setting core params\n");
  243. }
  244. core_if->hibernation_suspend = 0;
  245. /** ADP initialization */
  246. dwc_otg_adp_init(core_if);
  247. return core_if;
  248. }
  249. /**
  250. * This function frees the structures allocated by dwc_otg_cil_init().
  251. *
  252. * @param core_if The core interface pointer returned from
  253. * dwc_otg_cil_init().
  254. *
  255. */
  256. void dwc_otg_cil_remove(dwc_otg_core_if_t * core_if)
  257. {
  258. /* Disable all interrupts */
  259. DWC_MODIFY_REG32(&core_if->core_global_regs->gahbcfg, 1, 0);
  260. DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, 0);
  261. if (core_if->wq_otg) {
  262. DWC_WORKQ_WAIT_WORK_DONE(core_if->wq_otg, 500);
  263. DWC_WORKQ_FREE(core_if->wq_otg);
  264. }
  265. if (core_if->dev_if) {
  266. DWC_FREE(core_if->dev_if);
  267. }
  268. if (core_if->host_if) {
  269. DWC_FREE(core_if->host_if);
  270. }
  271. /** Remove ADP Stuff */
  272. dwc_otg_adp_remove(core_if);
  273. if (core_if->core_params) {
  274. DWC_FREE(core_if->core_params);
  275. }
  276. if (core_if->wkp_timer) {
  277. DWC_TIMER_FREE(core_if->wkp_timer);
  278. }
  279. if (core_if->srp_timer) {
  280. DWC_TIMER_FREE(core_if->srp_timer);
  281. }
  282. DWC_FREE(core_if);
  283. }
  284. /**
  285. * This function enables the controller's Global Interrupt in the AHB Config
  286. * register.
  287. *
  288. * @param core_if Programming view of DWC_otg controller.
  289. */
  290. void dwc_otg_enable_global_interrupts(dwc_otg_core_if_t * core_if)
  291. {
  292. gahbcfg_data_t ahbcfg = {.d32 = 0 };
  293. ahbcfg.b.glblintrmsk = 1; /* Enable interrupts */
  294. DWC_MODIFY_REG32(&core_if->core_global_regs->gahbcfg, 0, ahbcfg.d32);
  295. }
  296. /**
  297. * This function disables the controller's Global Interrupt in the AHB Config
  298. * register.
  299. *
  300. * @param core_if Programming view of DWC_otg controller.
  301. */
  302. void dwc_otg_disable_global_interrupts(dwc_otg_core_if_t * core_if)
  303. {
  304. gahbcfg_data_t ahbcfg = {.d32 = 0 };
  305. ahbcfg.b.glblintrmsk = 1; /* Disable interrupts */
  306. DWC_MODIFY_REG32(&core_if->core_global_regs->gahbcfg, ahbcfg.d32, 0);
  307. }
  308. /**
  309. * This function initializes the commmon interrupts, used in both
  310. * device and host modes.
  311. *
  312. * @param core_if Programming view of the DWC_otg controller
  313. *
  314. */
  315. static void dwc_otg_enable_common_interrupts(dwc_otg_core_if_t * core_if)
  316. {
  317. dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  318. gintmsk_data_t intr_mask = {.d32 = 0 };
  319. /* Clear any pending OTG Interrupts */
  320. DWC_WRITE_REG32(&global_regs->gotgint, 0xFFFFFFFF);
  321. /* Clear any pending interrupts */
  322. DWC_WRITE_REG32(&global_regs->gintsts, 0xFFFFFFFF);
  323. /*
  324. * Enable the interrupts in the GINTMSK.
  325. */
  326. intr_mask.b.modemismatch = 1;
  327. intr_mask.b.otgintr = 1;
  328. if (!core_if->dma_enable) {
  329. intr_mask.b.rxstsqlvl = 1;
  330. }
  331. intr_mask.b.conidstschng = 1;
  332. intr_mask.b.wkupintr = 1;
  333. intr_mask.b.disconnect = 0;
  334. intr_mask.b.usbsuspend = 1;
  335. intr_mask.b.sessreqintr = 1;
  336. #ifdef CONFIG_USB_DWC_OTG_LPM
  337. if (core_if->core_params->lpm_enable) {
  338. intr_mask.b.lpmtranrcvd = 1;
  339. }
  340. #endif
  341. DWC_WRITE_REG32(&global_regs->gintmsk, intr_mask.d32);
  342. }
  343. /*
  344. * The restore operation is modified to support Synopsys Emulated Powerdown and
  345. * Hibernation. This function is for exiting from Device mode hibernation by
  346. * Host Initiated Resume/Reset and Device Initiated Remote-Wakeup.
  347. * @param core_if Programming view of DWC_otg controller.
  348. * @param rem_wakeup - indicates whether resume is initiated by Device or Host.
  349. * @param reset - indicates whether resume is initiated by Reset.
  350. */
  351. int dwc_otg_device_hibernation_restore(dwc_otg_core_if_t * core_if,
  352. int rem_wakeup, int reset)
  353. {
  354. gpwrdn_data_t gpwrdn = {.d32 = 0 };
  355. pcgcctl_data_t pcgcctl = {.d32 = 0 };
  356. dctl_data_t dctl = {.d32 = 0 };
  357. int timeout = 2000;
  358. if (!core_if->hibernation_suspend) {
  359. DWC_PRINTF("Already exited from Hibernation\n");
  360. return 1;
  361. }
  362. DWC_DEBUGPL(DBG_PCD, "%s called\n", __FUNCTION__);
  363. /* Switch-on voltage to the core */
  364. gpwrdn.b.pwrdnswtch = 1;
  365. DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  366. dwc_udelay(10);
  367. /* Reset core */
  368. gpwrdn.d32 = 0;
  369. gpwrdn.b.pwrdnrstn = 1;
  370. DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  371. dwc_udelay(10);
  372. /* Assert Restore signal */
  373. gpwrdn.d32 = 0;
  374. gpwrdn.b.restore = 1;
  375. DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  376. dwc_udelay(10);
  377. /* Disable power clamps */
  378. gpwrdn.d32 = 0;
  379. gpwrdn.b.pwrdnclmp = 1;
  380. DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  381. if (rem_wakeup) {
  382. dwc_udelay(70);
  383. }
  384. /* Deassert Reset core */
  385. gpwrdn.d32 = 0;
  386. gpwrdn.b.pwrdnrstn = 1;
  387. DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  388. dwc_udelay(10);
  389. /* Disable PMU interrupt */
  390. gpwrdn.d32 = 0;
  391. gpwrdn.b.pmuintsel = 1;
  392. DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  393. /* Mask interrupts from gpwrdn */
  394. gpwrdn.d32 = 0;
  395. gpwrdn.b.connect_det_msk = 1;
  396. gpwrdn.b.srp_det_msk = 1;
  397. gpwrdn.b.disconn_det_msk = 1;
  398. gpwrdn.b.rst_det_msk = 1;
  399. gpwrdn.b.lnstchng_msk = 1;
  400. DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  401. /* Indicates that we are going out from hibernation */
  402. core_if->hibernation_suspend = 0;
  403. /*
  404. * Set Restore Essential Regs bit in PCGCCTL register, restore_mode = 1
  405. * indicates restore from remote_wakeup
  406. */
  407. restore_essential_regs(core_if, rem_wakeup, 0);
  408. /*
  409. * Wait a little for seeing new value of variable hibernation_suspend if
  410. * Restore done interrupt received before polling
  411. */
  412. dwc_udelay(10);
  413. if (core_if->hibernation_suspend == 0) {
  414. /*
  415. * Wait For Restore_done Interrupt. This mechanism of polling the
  416. * interrupt is introduced to avoid any possible race conditions
  417. */
  418. do {
  419. gintsts_data_t gintsts;
  420. gintsts.d32 =
  421. DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  422. if (gintsts.b.restoredone) {
  423. gintsts.d32 = 0;
  424. gintsts.b.restoredone = 1;
  425. DWC_WRITE_REG32(&core_if->core_global_regs->
  426. gintsts, gintsts.d32);
  427. DWC_PRINTF("Restore Done Interrupt seen\n");
  428. break;
  429. }
  430. dwc_udelay(10);
  431. } while (--timeout);
  432. if (!timeout) {
  433. DWC_PRINTF("Restore Done interrupt wasn't generated here\n");
  434. }
  435. }
  436. /* Clear all pending interupts */
  437. DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  438. /* De-assert Restore */
  439. gpwrdn.d32 = 0;
  440. gpwrdn.b.restore = 1;
  441. DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  442. dwc_udelay(10);
  443. if (!rem_wakeup) {
  444. pcgcctl.d32 = 0;
  445. pcgcctl.b.rstpdwnmodule = 1;
  446. DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  447. }
  448. /* Restore GUSBCFG and DCFG */
  449. DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg,
  450. core_if->gr_backup->gusbcfg_local);
  451. DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg,
  452. core_if->dr_backup->dcfg);
  453. /* De-assert Wakeup Logic */
  454. gpwrdn.d32 = 0;
  455. gpwrdn.b.pmuactv = 1;
  456. DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  457. dwc_udelay(10);
  458. if (!rem_wakeup) {
  459. /* Set Device programming done bit */
  460. dctl.b.pwronprgdone = 1;
  461. DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0, dctl.d32);
  462. } else {
  463. /* Start Remote Wakeup Signaling */
  464. dctl.d32 = core_if->dr_backup->dctl;
  465. dctl.b.rmtwkupsig = 1;
  466. DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32);
  467. }
  468. dwc_mdelay(2);
  469. /* Clear all pending interupts */
  470. DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  471. /* Restore global registers */
  472. dwc_otg_restore_global_regs(core_if);
  473. /* Restore device global registers */
  474. dwc_otg_restore_dev_regs(core_if, rem_wakeup);
  475. if (rem_wakeup) {
  476. dwc_mdelay(7);
  477. dctl.d32 = 0;
  478. dctl.b.rmtwkupsig = 1;
  479. DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32, 0);
  480. }
  481. core_if->hibernation_suspend = 0;
  482. /* The core will be in ON STATE */
  483. core_if->lx_state = DWC_OTG_L0;
  484. DWC_PRINTF("Hibernation recovery completes here\n");
  485. return 1;
  486. }
  487. /*
  488. * The restore operation is modified to support Synopsys Emulated Powerdown and
  489. * Hibernation. This function is for exiting from Host mode hibernation by
  490. * Host Initiated Resume/Reset and Device Initiated Remote-Wakeup.
  491. * @param core_if Programming view of DWC_otg controller.
  492. * @param rem_wakeup - indicates whether resume is initiated by Device or Host.
  493. * @param reset - indicates whether resume is initiated by Reset.
  494. */
  495. int dwc_otg_host_hibernation_restore(dwc_otg_core_if_t * core_if,
  496. int rem_wakeup, int reset)
  497. {
  498. gpwrdn_data_t gpwrdn = {.d32 = 0 };
  499. hprt0_data_t hprt0 = {.d32 = 0 };
  500. int timeout = 2000;
  501. DWC_DEBUGPL(DBG_HCD, "%s called\n", __FUNCTION__);
  502. /* Switch-on voltage to the core */
  503. gpwrdn.b.pwrdnswtch = 1;
  504. DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  505. dwc_udelay(10);
  506. /* Reset core */
  507. gpwrdn.d32 = 0;
  508. gpwrdn.b.pwrdnrstn = 1;
  509. DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  510. dwc_udelay(10);
  511. /* Assert Restore signal */
  512. gpwrdn.d32 = 0;
  513. gpwrdn.b.restore = 1;
  514. DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  515. dwc_udelay(10);
  516. /* Disable power clamps */
  517. gpwrdn.d32 = 0;
  518. gpwrdn.b.pwrdnclmp = 1;
  519. DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  520. if (!rem_wakeup) {
  521. dwc_udelay(50);
  522. }
  523. /* Deassert Reset core */
  524. gpwrdn.d32 = 0;
  525. gpwrdn.b.pwrdnrstn = 1;
  526. DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  527. dwc_udelay(10);
  528. /* Disable PMU interrupt */
  529. gpwrdn.d32 = 0;
  530. gpwrdn.b.pmuintsel = 1;
  531. DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  532. gpwrdn.d32 = 0;
  533. gpwrdn.b.connect_det_msk = 1;
  534. gpwrdn.b.srp_det_msk = 1;
  535. gpwrdn.b.disconn_det_msk = 1;
  536. gpwrdn.b.rst_det_msk = 1;
  537. gpwrdn.b.lnstchng_msk = 1;
  538. DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  539. /* Indicates that we are going out from hibernation */
  540. core_if->hibernation_suspend = 0;
  541. /* Set Restore Essential Regs bit in PCGCCTL register */
  542. restore_essential_regs(core_if, rem_wakeup, 1);
  543. /* Wait a little for seeing new value of variable hibernation_suspend if
  544. * Restore done interrupt received before polling */
  545. dwc_udelay(10);
  546. if (core_if->hibernation_suspend == 0) {
  547. /* Wait For Restore_done Interrupt. This mechanism of polling the
  548. * interrupt is introduced to avoid any possible race conditions
  549. */
  550. do {
  551. gintsts_data_t gintsts;
  552. gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  553. if (gintsts.b.restoredone) {
  554. gintsts.d32 = 0;
  555. gintsts.b.restoredone = 1;
  556. DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  557. DWC_DEBUGPL(DBG_HCD,"Restore Done Interrupt seen\n");
  558. break;
  559. }
  560. dwc_udelay(10);
  561. } while (--timeout);
  562. if (!timeout) {
  563. DWC_WARN("Restore Done interrupt wasn't generated\n");
  564. }
  565. }
  566. /* Set the flag's value to 0 again after receiving restore done interrupt */
  567. core_if->hibernation_suspend = 0;
  568. /* This step is not described in functional spec but if not wait for this
  569. * delay, mismatch interrupts occurred because just after restore core is
  570. * in Device mode(gintsts.curmode == 0) */
  571. dwc_mdelay(100);
  572. /* Clear all pending interrupts */
  573. DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  574. /* De-assert Restore */
  575. gpwrdn.d32 = 0;
  576. gpwrdn.b.restore = 1;
  577. DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  578. dwc_udelay(10);
  579. /* Restore GUSBCFG and HCFG */
  580. DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg,
  581. core_if->gr_backup->gusbcfg_local);
  582. DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hcfg,
  583. core_if->hr_backup->hcfg_local);
  584. /* De-assert Wakeup Logic */
  585. gpwrdn.d32 = 0;
  586. gpwrdn.b.pmuactv = 1;
  587. DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  588. dwc_udelay(10);
  589. /* Start the Resume operation by programming HPRT0 */
  590. hprt0.d32 = core_if->hr_backup->hprt0_local;
  591. hprt0.b.prtpwr = 1;
  592. hprt0.b.prtena = 0;
  593. hprt0.b.prtsusp = 0;
  594. DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  595. DWC_PRINTF("Resume Starts Now\n");
  596. if (!reset) { // Indicates it is Resume Operation
  597. hprt0.d32 = core_if->hr_backup->hprt0_local;
  598. hprt0.b.prtres = 1;
  599. hprt0.b.prtpwr = 1;
  600. hprt0.b.prtena = 0;
  601. hprt0.b.prtsusp = 0;
  602. DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  603. if (!rem_wakeup)
  604. hprt0.b.prtres = 0;
  605. /* Wait for Resume time and then program HPRT again */
  606. dwc_mdelay(100);
  607. DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  608. } else { // Indicates it is Reset Operation
  609. hprt0.d32 = core_if->hr_backup->hprt0_local;
  610. hprt0.b.prtrst = 1;
  611. hprt0.b.prtpwr = 1;
  612. hprt0.b.prtena = 0;
  613. hprt0.b.prtsusp = 0;
  614. DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  615. /* Wait for Reset time and then program HPRT again */
  616. dwc_mdelay(60);
  617. hprt0.b.prtrst = 0;
  618. DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  619. }
  620. /* Clear all interrupt status */
  621. hprt0.d32 = dwc_otg_read_hprt0(core_if);
  622. hprt0.b.prtconndet = 1;
  623. hprt0.b.prtenchng = 1;
  624. DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  625. /* Clear all pending interupts */
  626. DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  627. /* Restore global registers */
  628. dwc_otg_restore_global_regs(core_if);
  629. /* Restore host global registers */
  630. dwc_otg_restore_host_regs(core_if, reset);
  631. /* The core will be in ON STATE */
  632. core_if->lx_state = DWC_OTG_L0;
  633. DWC_PRINTF("Hibernation recovery is complete here\n");
  634. return 0;
  635. }
  636. /** Saves some register values into system memory. */
  637. int dwc_otg_save_global_regs(dwc_otg_core_if_t * core_if)
  638. {
  639. struct dwc_otg_global_regs_backup *gr;
  640. int i;
  641. gr = core_if->gr_backup;
  642. if (!gr) {
  643. gr = DWC_ALLOC(sizeof(*gr));
  644. if (!gr) {
  645. return -DWC_E_NO_MEMORY;
  646. }
  647. core_if->gr_backup = gr;
  648. }
  649. gr->gotgctl_local = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  650. gr->gintmsk_local = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
  651. gr->gahbcfg_local = DWC_READ_REG32(&core_if->core_global_regs->gahbcfg);
  652. gr->gusbcfg_local = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  653. gr->grxfsiz_local = DWC_READ_REG32(&core_if->core_global_regs->grxfsiz);
  654. gr->gnptxfsiz_local = DWC_READ_REG32(&core_if->core_global_regs->gnptxfsiz);
  655. gr->hptxfsiz_local = DWC_READ_REG32(&core_if->core_global_regs->hptxfsiz);
  656. #ifdef CONFIG_USB_DWC_OTG_LPM
  657. gr->glpmcfg_local = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  658. #endif
  659. gr->gi2cctl_local = DWC_READ_REG32(&core_if->core_global_regs->gi2cctl);
  660. gr->pcgcctl_local = DWC_READ_REG32(core_if->pcgcctl);
  661. gr->gdfifocfg_local =
  662. DWC_READ_REG32(&core_if->core_global_regs->gdfifocfg);
  663. for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  664. gr->dtxfsiz_local[i] =
  665. DWC_READ_REG32(&(core_if->core_global_regs->dtxfsiz[i]));
  666. }
  667. DWC_DEBUGPL(DBG_ANY, "===========Backing Global registers==========\n");
  668. DWC_DEBUGPL(DBG_ANY, "Backed up gotgctl = %08x\n", gr->gotgctl_local);
  669. DWC_DEBUGPL(DBG_ANY, "Backed up gintmsk = %08x\n", gr->gintmsk_local);
  670. DWC_DEBUGPL(DBG_ANY, "Backed up gahbcfg = %08x\n", gr->gahbcfg_local);
  671. DWC_DEBUGPL(DBG_ANY, "Backed up gusbcfg = %08x\n", gr->gusbcfg_local);
  672. DWC_DEBUGPL(DBG_ANY, "Backed up grxfsiz = %08x\n", gr->grxfsiz_local);
  673. DWC_DEBUGPL(DBG_ANY, "Backed up gnptxfsiz = %08x\n",
  674. gr->gnptxfsiz_local);
  675. DWC_DEBUGPL(DBG_ANY, "Backed up hptxfsiz = %08x\n",
  676. gr->hptxfsiz_local);
  677. #ifdef CONFIG_USB_DWC_OTG_LPM
  678. DWC_DEBUGPL(DBG_ANY, "Backed up glpmcfg = %08x\n", gr->glpmcfg_local);
  679. #endif
  680. DWC_DEBUGPL(DBG_ANY, "Backed up gi2cctl = %08x\n", gr->gi2cctl_local);
  681. DWC_DEBUGPL(DBG_ANY, "Backed up pcgcctl = %08x\n", gr->pcgcctl_local);
  682. DWC_DEBUGPL(DBG_ANY,"Backed up gdfifocfg = %08x\n",gr->gdfifocfg_local);
  683. return 0;
  684. }
  685. /** Saves GINTMSK register before setting the msk bits. */
  686. int dwc_otg_save_gintmsk_reg(dwc_otg_core_if_t * core_if)
  687. {
  688. struct dwc_otg_global_regs_backup *gr;
  689. gr = core_if->gr_backup;
  690. if (!gr) {
  691. gr = DWC_ALLOC(sizeof(*gr));
  692. if (!gr) {
  693. return -DWC_E_NO_MEMORY;
  694. }
  695. core_if->gr_backup = gr;
  696. }
  697. gr->gintmsk_local = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
  698. DWC_DEBUGPL(DBG_ANY,"=============Backing GINTMSK registers============\n");
  699. DWC_DEBUGPL(DBG_ANY, "Backed up gintmsk = %08x\n", gr->gintmsk_local);
  700. return 0;
  701. }
  702. int dwc_otg_save_dev_regs(dwc_otg_core_if_t * core_if)
  703. {
  704. struct dwc_otg_dev_regs_backup *dr;
  705. int i;
  706. dr = core_if->dr_backup;
  707. if (!dr) {
  708. dr = DWC_ALLOC(sizeof(*dr));
  709. if (!dr) {
  710. return -DWC_E_NO_MEMORY;
  711. }
  712. core_if->dr_backup = dr;
  713. }
  714. dr->dcfg = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  715. dr->dctl = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dctl);
  716. dr->daintmsk =
  717. DWC_READ_REG32(&core_if->dev_if->dev_global_regs->daintmsk);
  718. dr->diepmsk =
  719. DWC_READ_REG32(&core_if->dev_if->dev_global_regs->diepmsk);
  720. dr->doepmsk =
  721. DWC_READ_REG32(&core_if->dev_if->dev_global_regs->doepmsk);
  722. for (i = 0; i < core_if->dev_if->num_in_eps; ++i) {
  723. dr->diepctl[i] =
  724. DWC_READ_REG32(&core_if->dev_if->in_ep_regs[i]->diepctl);
  725. dr->dieptsiz[i] =
  726. DWC_READ_REG32(&core_if->dev_if->in_ep_regs[i]->dieptsiz);
  727. dr->diepdma[i] =
  728. DWC_READ_REG32(&core_if->dev_if->in_ep_regs[i]->diepdma);
  729. }
  730. DWC_DEBUGPL(DBG_ANY,
  731. "=============Backing Host registers==============\n");
  732. DWC_DEBUGPL(DBG_ANY, "Backed up dcfg = %08x\n", dr->dcfg);
  733. DWC_DEBUGPL(DBG_ANY, "Backed up dctl = %08x\n", dr->dctl);
  734. DWC_DEBUGPL(DBG_ANY, "Backed up daintmsk = %08x\n",
  735. dr->daintmsk);
  736. DWC_DEBUGPL(DBG_ANY, "Backed up diepmsk = %08x\n", dr->diepmsk);
  737. DWC_DEBUGPL(DBG_ANY, "Backed up doepmsk = %08x\n", dr->doepmsk);
  738. for (i = 0; i < core_if->dev_if->num_in_eps; ++i) {
  739. DWC_DEBUGPL(DBG_ANY, "Backed up diepctl[%d] = %08x\n", i,
  740. dr->diepctl[i]);
  741. DWC_DEBUGPL(DBG_ANY, "Backed up dieptsiz[%d] = %08x\n",
  742. i, dr->dieptsiz[i]);
  743. DWC_DEBUGPL(DBG_ANY, "Backed up diepdma[%d] = %08x\n", i,
  744. dr->diepdma[i]);
  745. }
  746. return 0;
  747. }
  748. int dwc_otg_save_host_regs(dwc_otg_core_if_t * core_if)
  749. {
  750. struct dwc_otg_host_regs_backup *hr;
  751. int i;
  752. hr = core_if->hr_backup;
  753. if (!hr) {
  754. hr = DWC_ALLOC(sizeof(*hr));
  755. if (!hr) {
  756. return -DWC_E_NO_MEMORY;
  757. }
  758. core_if->hr_backup = hr;
  759. }
  760. hr->hcfg_local =
  761. DWC_READ_REG32(&core_if->host_if->host_global_regs->hcfg);
  762. hr->haintmsk_local =
  763. DWC_READ_REG32(&core_if->host_if->host_global_regs->haintmsk);
  764. for (i = 0; i < dwc_otg_get_param_host_channels(core_if); ++i) {
  765. hr->hcintmsk_local[i] =
  766. DWC_READ_REG32(&core_if->host_if->hc_regs[i]->hcintmsk);
  767. }
  768. hr->hprt0_local = DWC_READ_REG32(core_if->host_if->hprt0);
  769. hr->hfir_local =
  770. DWC_READ_REG32(&core_if->host_if->host_global_regs->hfir);
  771. DWC_DEBUGPL(DBG_ANY,
  772. "=============Backing Host registers===============\n");
  773. DWC_DEBUGPL(DBG_ANY, "Backed up hcfg = %08x\n",
  774. hr->hcfg_local);
  775. DWC_DEBUGPL(DBG_ANY, "Backed up haintmsk = %08x\n", hr->haintmsk_local);
  776. for (i = 0; i < dwc_otg_get_param_host_channels(core_if); ++i) {
  777. DWC_DEBUGPL(DBG_ANY, "Backed up hcintmsk[%02d]=%08x\n", i,
  778. hr->hcintmsk_local[i]);
  779. }
  780. DWC_DEBUGPL(DBG_ANY, "Backed up hprt0 = %08x\n",
  781. hr->hprt0_local);
  782. DWC_DEBUGPL(DBG_ANY, "Backed up hfir = %08x\n",
  783. hr->hfir_local);
  784. return 0;
  785. }
  786. int dwc_otg_restore_global_regs(dwc_otg_core_if_t *core_if)
  787. {
  788. struct dwc_otg_global_regs_backup *gr;
  789. int i;
  790. gr = core_if->gr_backup;
  791. if (!gr) {
  792. return -DWC_E_INVALID;
  793. }
  794. DWC_WRITE_REG32(&core_if->core_global_regs->gotgctl, gr->gotgctl_local);
  795. DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, gr->gintmsk_local);
  796. DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, gr->gusbcfg_local);
  797. DWC_WRITE_REG32(&core_if->core_global_regs->gahbcfg, gr->gahbcfg_local);
  798. DWC_WRITE_REG32(&core_if->core_global_regs->grxfsiz, gr->grxfsiz_local);
  799. DWC_WRITE_REG32(&core_if->core_global_regs->gnptxfsiz,
  800. gr->gnptxfsiz_local);
  801. DWC_WRITE_REG32(&core_if->core_global_regs->hptxfsiz,
  802. gr->hptxfsiz_local);
  803. DWC_WRITE_REG32(&core_if->core_global_regs->gdfifocfg,
  804. gr->gdfifocfg_local);
  805. for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  806. DWC_WRITE_REG32(&core_if->core_global_regs->dtxfsiz[i],
  807. gr->dtxfsiz_local[i]);
  808. }
  809. DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  810. DWC_WRITE_REG32(core_if->host_if->hprt0, 0x0000100A);
  811. DWC_WRITE_REG32(&core_if->core_global_regs->gahbcfg,
  812. (gr->gahbcfg_local));
  813. return 0;
  814. }
  815. int dwc_otg_restore_dev_regs(dwc_otg_core_if_t * core_if, int rem_wakeup)
  816. {
  817. struct dwc_otg_dev_regs_backup *dr;
  818. int i;
  819. dr = core_if->dr_backup;
  820. if (!dr) {
  821. return -DWC_E_INVALID;
  822. }
  823. if (!rem_wakeup)
  824. {
  825. DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl, dr->dctl);
  826. }
  827. DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->daintmsk, dr->daintmsk);
  828. DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->diepmsk, dr->diepmsk);
  829. DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->doepmsk, dr->doepmsk);
  830. for (i = 0; i < core_if->dev_if->num_in_eps; ++i) {
  831. DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[i]->diepctl, dr->diepctl[i]);
  832. DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[i]->dieptsiz, dr->dieptsiz[i]);
  833. DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[i]->diepdma, dr->diepdma[i]);
  834. }
  835. return 0;
  836. }
  837. int dwc_otg_restore_host_regs(dwc_otg_core_if_t * core_if, int reset)
  838. {
  839. struct dwc_otg_host_regs_backup *hr;
  840. int i;
  841. hr = core_if->hr_backup;
  842. if (!hr) {
  843. return -DWC_E_INVALID;
  844. }
  845. DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hcfg, hr->hcfg_local);
  846. //if (!reset)
  847. //{
  848. // DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hfir, hr->hfir_local);
  849. //}
  850. DWC_WRITE_REG32(&core_if->host_if->host_global_regs->haintmsk,
  851. hr->haintmsk_local);
  852. for (i = 0; i < dwc_otg_get_param_host_channels(core_if); ++i) {
  853. DWC_WRITE_REG32(&core_if->host_if->hc_regs[i]->hcintmsk,
  854. hr->hcintmsk_local[i]);
  855. }
  856. return 0;
  857. }
  858. int restore_lpm_i2c_regs(dwc_otg_core_if_t * core_if)
  859. {
  860. struct dwc_otg_global_regs_backup *gr;
  861. gr = core_if->gr_backup;
  862. /* Restore values for LPM and I2C */
  863. #ifdef CONFIG_USB_DWC_OTG_LPM
  864. DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg, gr->glpmcfg_local);
  865. #endif
  866. DWC_WRITE_REG32(&core_if->core_global_regs->gi2cctl, gr->gi2cctl_local);
  867. return 0;
  868. }
  869. int restore_essential_regs(dwc_otg_core_if_t * core_if, int rmode, int is_host)
  870. {
  871. struct dwc_otg_global_regs_backup *gr;
  872. pcgcctl_data_t pcgcctl = {.d32 = 0 };
  873. gahbcfg_data_t gahbcfg = {.d32 = 0 };
  874. gusbcfg_data_t gusbcfg = {.d32 = 0 };
  875. gintmsk_data_t gintmsk = {.d32 = 0 };
  876. /* Restore LPM and I2C registers */
  877. restore_lpm_i2c_regs(core_if);
  878. /* Set PCGCCTL to 0 */
  879. DWC_WRITE_REG32(core_if->pcgcctl, 0x00000000);
  880. gr = core_if->gr_backup;
  881. /* Load restore values for [31:14] bits */
  882. DWC_WRITE_REG32(core_if->pcgcctl,
  883. ((gr->pcgcctl_local & 0xffffc000) | 0x00020000));
  884. /* Umnask global Interrupt in GAHBCFG and restore it */
  885. gahbcfg.d32 = gr->gahbcfg_local;
  886. gahbcfg.b.glblintrmsk = 1;
  887. DWC_WRITE_REG32(&core_if->core_global_regs->gahbcfg, gahbcfg.d32);
  888. /* Clear all pending interupts */
  889. DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  890. /* Unmask restore done interrupt */
  891. gintmsk.b.restoredone = 1;
  892. DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, gintmsk.d32);
  893. /* Restore GUSBCFG and HCFG/DCFG */
  894. gusbcfg.d32 = core_if->gr_backup->gusbcfg_local;
  895. DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, gusbcfg.d32);
  896. if (is_host) {
  897. hcfg_data_t hcfg = {.d32 = 0 };
  898. hcfg.d32 = core_if->hr_backup->hcfg_local;
  899. DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hcfg,
  900. hcfg.d32);
  901. /* Load restore values for [31:14] bits */
  902. pcgcctl.d32 = gr->pcgcctl_local & 0xffffc000;
  903. pcgcctl.d32 = gr->pcgcctl_local | 0x00020000;
  904. if (rmode)
  905. pcgcctl.b.restoremode = 1;
  906. DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  907. dwc_udelay(10);
  908. /* Load restore values for [31:14] bits and set EssRegRestored bit */
  909. pcgcctl.d32 = gr->pcgcctl_local | 0xffffc000;
  910. pcgcctl.d32 = gr->pcgcctl_local & 0xffffc000;
  911. pcgcctl.b.ess_reg_restored = 1;
  912. if (rmode)
  913. pcgcctl.b.restoremode = 1;
  914. DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  915. } else {
  916. dcfg_data_t dcfg = {.d32 = 0 };
  917. dcfg.d32 = core_if->dr_backup->dcfg;
  918. DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg, dcfg.d32);
  919. /* Load restore values for [31:14] bits */
  920. pcgcctl.d32 = gr->pcgcctl_local & 0xffffc000;
  921. pcgcctl.d32 = gr->pcgcctl_local | 0x00020000;
  922. if (!rmode) {
  923. pcgcctl.d32 |= 0x208;
  924. }
  925. DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  926. dwc_udelay(10);
  927. /* Load restore values for [31:14] bits */
  928. pcgcctl.d32 = gr->pcgcctl_local & 0xffffc000;
  929. pcgcctl.d32 = gr->pcgcctl_local | 0x00020000;
  930. pcgcctl.b.ess_reg_restored = 1;
  931. if (!rmode)
  932. pcgcctl.d32 |= 0x208;
  933. DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  934. }
  935. return 0;
  936. }
  937. /**
  938. * Initializes the FSLSPClkSel field of the HCFG register depending on the PHY
  939. * type.
  940. */
  941. static void init_fslspclksel(dwc_otg_core_if_t * core_if)
  942. {
  943. uint32_t val;
  944. hcfg_data_t hcfg;
  945. if (((core_if->hwcfg2.b.hs_phy_type == 2) &&
  946. (core_if->hwcfg2.b.fs_phy_type == 1) &&
  947. (core_if->core_params->ulpi_fs_ls)) ||
  948. (core_if->core_params->phy_type == DWC_PHY_TYPE_PARAM_FS)) {
  949. /* Full speed PHY */
  950. val = DWC_HCFG_48_MHZ;
  951. } else {
  952. /* High speed PHY running at full speed or high speed */
  953. val = DWC_HCFG_30_60_MHZ;
  954. }
  955. DWC_DEBUGPL(DBG_CIL, "Initializing HCFG.FSLSPClkSel to 0x%1x\n", val);
  956. hcfg.d32 = DWC_READ_REG32(&core_if->host_if->host_global_regs->hcfg);
  957. hcfg.b.fslspclksel = val;
  958. DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hcfg, hcfg.d32);
  959. }
  960. /**
  961. * Initializes the DevSpd field of the DCFG register depending on the PHY type
  962. * and the enumeration speed of the device.
  963. */
  964. static void init_devspd(dwc_otg_core_if_t * core_if)
  965. {
  966. uint32_t val;
  967. dcfg_data_t dcfg;
  968. if (((core_if->hwcfg2.b.hs_phy_type == 2) &&
  969. (core_if->hwcfg2.b.fs_phy_type == 1) &&
  970. (core_if->core_params->ulpi_fs_ls)) ||
  971. (core_if->core_params->phy_type == DWC_PHY_TYPE_PARAM_FS)) {
  972. /* Full speed PHY */
  973. val = 0x3;
  974. } else if (core_if->core_params->speed == DWC_SPEED_PARAM_FULL) {
  975. /* High speed PHY running at full speed */
  976. val = 0x1;
  977. } else {
  978. /* High speed PHY running at high speed */
  979. val = 0x0;
  980. }
  981. DWC_DEBUGPL(DBG_CIL, "Initializing DCFG.DevSpd to 0x%1x\n", val);
  982. dcfg.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  983. dcfg.b.devspd = val;
  984. DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg, dcfg.d32);
  985. }
  986. /**
  987. * This function calculates the number of IN EPS
  988. * using GHWCFG1 and GHWCFG2 registers values
  989. *
  990. * @param core_if Programming view of the DWC_otg controller
  991. */
  992. static uint32_t calc_num_in_eps(dwc_otg_core_if_t * core_if)
  993. {
  994. uint32_t num_in_eps = 0;
  995. uint32_t num_eps = core_if->hwcfg2.b.num_dev_ep;
  996. uint32_t hwcfg1 = core_if->hwcfg1.d32 >> 3;
  997. uint32_t num_tx_fifos = core_if->hwcfg4.b.num_in_eps;
  998. int i;
  999. for (i = 0; i < num_eps; ++i) {
  1000. if (!(hwcfg1 & 0x1))
  1001. num_in_eps++;
  1002. hwcfg1 >>= 2;
  1003. }
  1004. if (core_if->hwcfg4.b.ded_fifo_en) {
  1005. num_in_eps =
  1006. (num_in_eps > num_tx_fifos) ? num_tx_fifos : num_in_eps;
  1007. }
  1008. return num_in_eps;
  1009. }
  1010. /**
  1011. * This function calculates the number of OUT EPS
  1012. * using GHWCFG1 and GHWCFG2 registers values
  1013. *
  1014. * @param core_if Programming view of the DWC_otg controller
  1015. */
  1016. static uint32_t calc_num_out_eps(dwc_otg_core_if_t * core_if)
  1017. {
  1018. uint32_t num_out_eps = 0;
  1019. uint32_t num_eps = core_if->hwcfg2.b.num_dev_ep;
  1020. uint32_t hwcfg1 = core_if->hwcfg1.d32 >> 2;
  1021. int i;
  1022. for (i = 0; i < num_eps; ++i) {
  1023. if (!(hwcfg1 & 0x1))
  1024. num_out_eps++;
  1025. hwcfg1 >>= 2;
  1026. }
  1027. return num_out_eps;
  1028. }
  1029. /**
  1030. * This function initializes the DWC_otg controller registers and
  1031. * prepares the core for device mode or host mode operation.
  1032. *
  1033. * @param core_if Programming view of the DWC_otg controller
  1034. *
  1035. */
  1036. void dwc_otg_core_init(dwc_otg_core_if_t * core_if)
  1037. {
  1038. int i = 0;
  1039. dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  1040. dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  1041. gahbcfg_data_t ahbcfg = {.d32 = 0 };
  1042. gusbcfg_data_t usbcfg = {.d32 = 0 };
  1043. gi2cctl_data_t i2cctl = {.d32 = 0 };
  1044. DWC_DEBUGPL(DBG_CILV, "dwc_otg_core_init(%p)\n", core_if);
  1045. /* Common Initialization */
  1046. usbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  1047. /* Program the ULPI External VBUS bit if needed */
  1048. usbcfg.b.ulpi_ext_vbus_drv =
  1049. (core_if->core_params->phy_ulpi_ext_vbus ==
  1050. DWC_PHY_ULPI_EXTERNAL_VBUS) ? 1 : 0;
  1051. /* Set external TS Dline pulsing */
  1052. usbcfg.b.term_sel_dl_pulse =
  1053. (core_if->core_params->ts_dline == 1) ? 1 : 0;
  1054. DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  1055. /* Reset the Controller */
  1056. dwc_otg_core_reset(core_if);
  1057. core_if->adp_enable = core_if->core_params->adp_supp_enable;
  1058. core_if->power_down = core_if->core_params->power_down;
  1059. core_if->otg_sts = 0;
  1060. /* Initialize parameters from Hardware configuration registers. */
  1061. dev_if->num_in_eps = calc_num_in_eps(core_if);
  1062. dev_if->num_out_eps = calc_num_out_eps(core_if);
  1063. DWC_DEBUGPL(DBG_CIL, "num_dev_perio_in_ep=%d\n",
  1064. core_if->hwcfg4.b.num_dev_perio_in_ep);
  1065. for (i = 0; i < core_if->hwcfg4.b.num_dev_perio_in_ep; i++) {
  1066. dev_if->perio_tx_fifo_size[i] =
  1067. DWC_READ_REG32(&global_regs->dtxfsiz[i]) >> 16;
  1068. DWC_DEBUGPL(DBG_CIL, "Periodic Tx FIFO SZ #%d=0x%0x\n",
  1069. i, dev_if->perio_tx_fifo_size[i]);
  1070. }
  1071. for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  1072. dev_if->tx_fifo_size[i] =
  1073. DWC_READ_REG32(&global_regs->dtxfsiz[i]) >> 16;
  1074. DWC_DEBUGPL(DBG_CIL, "Tx FIFO SZ #%d=0x%0x\n",
  1075. i, dev_if->tx_fifo_size[i]);
  1076. }
  1077. core_if->total_fifo_size = core_if->hwcfg3.b.dfifo_depth;
  1078. core_if->rx_fifo_size = DWC_READ_REG32(&global_regs->grxfsiz);
  1079. core_if->nperio_tx_fifo_size =
  1080. DWC_READ_REG32(&global_regs->gnptxfsiz) >> 16;
  1081. DWC_DEBUGPL(DBG_CIL, "Total FIFO SZ=%d\n", core_if->total_fifo_size);
  1082. DWC_DEBUGPL(DBG_CIL, "Rx FIFO SZ=%d\n", core_if->rx_fifo_size);
  1083. DWC_DEBUGPL(DBG_CIL, "NP Tx FIFO SZ=%d\n",
  1084. core_if->nperio_tx_fifo_size);
  1085. /* This programming sequence needs to happen in FS mode before any other
  1086. * programming occurs */
  1087. if ((core_if->core_params->speed == DWC_SPEED_PARAM_FULL) &&
  1088. (core_if->core_params->phy_type == DWC_PHY_TYPE_PARAM_FS)) {
  1089. /* If FS mode with FS PHY */
  1090. /* core_init() is now called on every switch so only call the
  1091. * following for the first time through. */
  1092. if (!core_if->phy_init_done) {
  1093. core_if->phy_init_done = 1;
  1094. DWC_DEBUGPL(DBG_CIL, "FS_PHY detected\n");
  1095. usbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  1096. usbcfg.b.physel = 1;
  1097. DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  1098. /* Reset after a PHY select */
  1099. dwc_otg_core_reset(core_if);
  1100. }
  1101. /* Program DCFG.DevSpd or HCFG.FSLSPclkSel to 48Mhz in FS. Also
  1102. * do this on HNP Dev/Host mode switches (done in dev_init and
  1103. * host_init). */
  1104. if (dwc_otg_is_host_mode(core_if)) {
  1105. init_fslspclksel(core_if);
  1106. } else {
  1107. init_devspd(core_if);
  1108. }
  1109. if (core_if->core_params->i2c_enable) {
  1110. DWC_DEBUGPL(DBG_CIL, "FS_PHY Enabling I2c\n");
  1111. /* Program GUSBCFG.OtgUtmifsSel to I2C */
  1112. usbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  1113. usbcfg.b.otgutmifssel = 1;
  1114. DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  1115. /* Program GI2CCTL.I2CEn */
  1116. i2cctl.d32 = DWC_READ_REG32(&global_regs->gi2cctl);
  1117. i2cctl.b.i2cdevaddr = 1;
  1118. i2cctl.b.i2cen = 0;
  1119. DWC_WRITE_REG32(&global_regs->gi2cctl, i2cctl.d32);
  1120. i2cctl.b.i2cen = 1;
  1121. DWC_WRITE_REG32(&global_regs->gi2cctl, i2cctl.d32);
  1122. }
  1123. } /* endif speed == DWC_SPEED_PARAM_FULL */
  1124. else {
  1125. /* High speed PHY. */
  1126. if (!core_if->phy_init_done) {
  1127. core_if->phy_init_done = 1;
  1128. /* HS PHY parameters. These parameters are preserved
  1129. * during soft reset so only program the first time. Do
  1130. * a soft reset immediately after setting phyif. */
  1131. if (core_if->core_params->phy_type == 2) {
  1132. /* ULPI interface */
  1133. usbcfg.b.ulpi_utmi_sel = 1;
  1134. usbcfg.b.phyif = 0;
  1135. usbcfg.b.ddrsel =
  1136. core_if->core_params->phy_ulpi_ddr;
  1137. } else if (core_if->core_params->phy_type == 1) {
  1138. /* UTMI+ interface */
  1139. usbcfg.b.ulpi_utmi_sel = 0;
  1140. if (core_if->core_params->phy_utmi_width == 16) {
  1141. usbcfg.b.phyif = 1;
  1142. } else {
  1143. usbcfg.b.phyif = 0;
  1144. }
  1145. } else {
  1146. DWC_ERROR("FS PHY TYPE\n");
  1147. }
  1148. DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  1149. /* Reset after setting the PHY parameters */
  1150. dwc_otg_core_reset(core_if);
  1151. }
  1152. }
  1153. if ((core_if->hwcfg2.b.hs_phy_type == 2) &&
  1154. (core_if->hwcfg2.b.fs_phy_type == 1) &&
  1155. (core_if->core_params->ulpi_fs_ls)) {
  1156. DWC_DEBUGPL(DBG_CIL, "Setting ULPI FSLS\n");
  1157. usbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  1158. usbcfg.b.ulpi_fsls = 1;
  1159. usbcfg.b.ulpi_clk_sus_m = 1;
  1160. DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  1161. } else {
  1162. usbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  1163. usbcfg.b.ulpi_fsls = 0;
  1164. usbcfg.b.ulpi_clk_sus_m = 0;
  1165. DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  1166. }
  1167. /* Program the GAHBCFG Register. */
  1168. switch (core_if->hwcfg2.b.architecture) {
  1169. case DWC_SLAVE_ONLY_ARCH:
  1170. DWC_DEBUGPL(DBG_CIL, "Slave Only Mode\n");
  1171. ahbcfg.b.nptxfemplvl_txfemplvl =
  1172. DWC_GAHBCFG_TXFEMPTYLVL_HALFEMPTY;
  1173. ahbcfg.b.ptxfemplvl = DWC_GAHBCFG_TXFEMPTYLVL_HALFEMPTY;
  1174. core_if->dma_enable = 0;
  1175. core_if->dma_desc_enable = 0;
  1176. break;
  1177. case DWC_EXT_DMA_ARCH:
  1178. DWC_DEBUGPL(DBG_CIL, "External DMA Mode\n");
  1179. {
  1180. uint8_t brst_sz = core_if->core_params->dma_burst_size;
  1181. ahbcfg.b.hburstlen = 0;
  1182. while (brst_sz > 1) {
  1183. ahbcfg.b.hburstlen++;
  1184. brst_sz >>= 1;
  1185. }
  1186. }
  1187. core_if->dma_enable = (core_if->core_params->dma_enable != 0);
  1188. core_if->dma_desc_enable =
  1189. (core_if->core_params->dma_desc_enable != 0);
  1190. break;
  1191. case DWC_INT_DMA_ARCH:
  1192. DWC_DEBUGPL(DBG_CIL, "Internal DMA Mode\n");
  1193. /* Old value was DWC_GAHBCFG_INT_DMA_BURST_INCR - done for
  1194. Host mode ISOC in issue fix - vahrama */
  1195. ahbcfg.b.hburstlen = DWC_GAHBCFG_INT_DMA_BURST_INCR4;
  1196. core_if->dma_enable = (core_if->core_params->dma_enable != 0);
  1197. core_if->dma_desc_enable =
  1198. (core_if->core_params->dma_desc_enable != 0);
  1199. break;
  1200. }
  1201. if (core_if->dma_enable) {
  1202. if (core_if->dma_desc_enable) {
  1203. DWC_PRINTF("Using Descriptor DMA mode\n");
  1204. } else {
  1205. DWC_PRINTF("Using Buffer DMA mode\n");
  1206. }
  1207. } else {
  1208. DWC_PRINTF("Using Slave mode\n");
  1209. core_if->dma_desc_enable = 0;
  1210. }
  1211. if (core_if->core_params->ahb_single) {
  1212. ahbcfg.b.ahbsingle = 1;
  1213. }
  1214. ahbcfg.b.dmaenable = core_if->dma_enable;
  1215. DWC_WRITE_REG32(&global_regs->gahbcfg, ahbcfg.d32);
  1216. core_if->en_multiple_tx_fifo = core_if->hwcfg4.b.ded_fifo_en;
  1217. core_if->pti_enh_enable = core_if->core_params->pti_enable != 0;
  1218. core_if->multiproc_int_enable = core_if->core_params->mpi_enable;
  1219. DWC_DEBUGPL(DBG_CIL,"Periodic Transfer Interrupt Enhancement - %s\n",
  1220. ((core_if->pti_enh_enable) ? "enabled" : "disabled"));
  1221. DWC_DEBUGPL(DBG_CIL,"Multiprocessor Interrupt Enhancement - %s\n",
  1222. ((core_if->multiproc_int_enable) ? "enabled" : "disabled"));
  1223. /*
  1224. * Program the GUSBCFG register.
  1225. */
  1226. usbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  1227. switch (core_if->hwcfg2.b.op_mode) {
  1228. case DWC_MODE_HNP_SRP_CAPABLE:
  1229. usbcfg.b.hnpcap = (core_if->core_params->otg_cap ==
  1230. DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE);
  1231. usbcfg.b.srpcap = (core_if->core_params->otg_cap !=
  1232. DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
  1233. break;
  1234. case DWC_MODE_SRP_ONLY_CAPABLE:
  1235. usbcfg.b.hnpcap = 0;
  1236. usbcfg.b.srpcap = (core_if->core_params->otg_cap !=
  1237. DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
  1238. break;
  1239. case DWC_MODE_NO_HNP_SRP_CAPABLE:
  1240. usbcfg.b.hnpcap = 0;
  1241. usbcfg.b.srpcap = 0;
  1242. break;
  1243. case DWC_MODE_SRP_CAPABLE_DEVICE:
  1244. usbcfg.b.hnpcap = 0;
  1245. usbcfg.b.srpcap = (core_if->core_params->otg_cap !=
  1246. DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
  1247. break;
  1248. case DWC_MODE_NO_SRP_CAPABLE_DEVICE:
  1249. usbcfg.b.hnpcap = 0;
  1250. usbcfg.b.srpcap = 0;
  1251. break;
  1252. case DWC_MODE_SRP_CAPABLE_HOST:
  1253. usbcfg.b.hnpcap = 0;
  1254. usbcfg.b.srpcap = (core_if->core_params->otg_cap !=
  1255. DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
  1256. break;
  1257. case DWC_MODE_NO_SRP_CAPABLE_HOST:
  1258. usbcfg.b.hnpcap = 0;
  1259. usbcfg.b.srpcap = 0;
  1260. break;
  1261. }
  1262. DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  1263. #ifdef CONFIG_USB_DWC_OTG_LPM
  1264. if (core_if->core_params->lpm_enable) {
  1265. glpmcfg_data_t lpmcfg = {.d32 = 0 };
  1266. /* To enable LPM support set lpm_cap_en bit */
  1267. lpmcfg.b.lpm_cap_en = 1;
  1268. /* Make AppL1Res ACK */
  1269. lpmcfg.b.appl_resp = 1;
  1270. /* Retry 3 times */
  1271. lpmcfg.b.retry_count = 3;
  1272. DWC_MODIFY_REG32(&core_if->core_global_regs->glpmcfg,
  1273. 0, lpmcfg.d32);
  1274. }
  1275. #endif
  1276. if (core_if->core_params->ic_usb_cap) {
  1277. gusbcfg_data_t gusbcfg = {.d32 = 0 };
  1278. gusbcfg.b.ic_usb_cap = 1;
  1279. DWC_MODIFY_REG32(&core_if->core_global_regs->gusbcfg,
  1280. 0, gusbcfg.d32);
  1281. }
  1282. {
  1283. gotgctl_data_t gotgctl = {.d32 = 0 };
  1284. gotgctl.b.otgver = core_if->core_params->otg_ver;
  1285. DWC_MODIFY_REG32(&core_if->core_global_regs->gotgctl, 0,
  1286. gotgctl.d32);
  1287. /* Set OTG version supported */
  1288. core_if->otg_ver = core_if->core_params->otg_ver;
  1289. DWC_PRINTF("OTG VER PARAM: %d, OTG VER FLAG: %d\n",
  1290. core_if->core_params->otg_ver, core_if->otg_ver);
  1291. }
  1292. /* Enable common interrupts */
  1293. dwc_otg_enable_common_interrupts(core_if);
  1294. /* Do device or host intialization based on mode during PCD
  1295. * and HCD initialization */
  1296. if (dwc_otg_is_host_mode(core_if)) {
  1297. DWC_DEBUGPL(DBG_ANY, "Host Mode\n");
  1298. core_if->op_state = A_HOST;
  1299. } else {
  1300. DWC_DEBUGPL(DBG_ANY, "Device Mode\n");
  1301. core_if->op_state = B_PERIPHERAL;
  1302. #ifdef DWC_DEVICE_ONLY
  1303. dwc_otg_core_dev_init(core_if);
  1304. #endif
  1305. }
  1306. }
  1307. /**
  1308. * This function enables the Device mode interrupts.
  1309. *
  1310. * @param core_if Programming view of DWC_otg controller
  1311. */
  1312. void dwc_otg_enable_device_interrupts(dwc_otg_core_if_t * core_if)
  1313. {
  1314. gintmsk_data_t intr_mask = {.d32 = 0 };
  1315. dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  1316. DWC_DEBUGPL(DBG_CIL, "%s()\n", __func__);
  1317. /* Disable all interrupts. */
  1318. DWC_WRITE_REG32(&global_regs->gintmsk, 0);
  1319. /* Clear any pending interrupts */
  1320. DWC_WRITE_REG32(&global_regs->gintsts, 0xFFFFFFFF);
  1321. /* Enable the common interrupts */
  1322. dwc_otg_enable_common_interrupts(core_if);
  1323. /* Enable interrupts */
  1324. intr_mask.b.usbreset = 1;
  1325. intr_mask.b.enumdone = 1;
  1326. /* Disable Disconnect interrupt in Device mode */
  1327. intr_mask.b.disconnect = 0;
  1328. if (!core_if->multiproc_int_enable) {
  1329. intr_mask.b.inepintr = 1;
  1330. intr_mask.b.outepintr = 1;
  1331. }
  1332. intr_mask.b.erlysuspend = 1;
  1333. if (core_if->en_multiple_tx_fifo == 0) {
  1334. intr_mask.b.epmismatch = 1;
  1335. }
  1336. //intr_mask.b.incomplisoout = 1;
  1337. intr_mask.b.incomplisoin = 1;
  1338. /* Enable the ignore frame number for ISOC xfers - MAS */
  1339. /* Disable to support high bandwith ISOC transfers - manukz */
  1340. #if 0
  1341. #ifdef DWC_UTE_PER_IO
  1342. if (core_if->dma_enable) {
  1343. if (core_if->dma_desc_enable) {
  1344. dctl_data_t dctl1 = {.d32 = 0 };
  1345. dctl1.b.ifrmnum = 1;
  1346. DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  1347. dctl, 0, dctl1.d32);
  1348. DWC_DEBUG("----Enabled Ignore frame number (0x%08x)",
  1349. DWC_READ_REG32(&core_if->dev_if->
  1350. dev_global_regs->dctl));
  1351. }
  1352. }
  1353. #endif
  1354. #endif
  1355. #ifdef DWC_EN_ISOC
  1356. if (core_if->dma_enable) {
  1357. if (core_if->dma_desc_enable == 0) {
  1358. if (core_if->pti_enh_enable) {
  1359. dctl_data_t dctl = {.d32 = 0 };
  1360. dctl.b.ifrmnum = 1;
  1361. DWC_MODIFY_REG32(&core_if->
  1362. dev_if->dev_global_regs->dctl,
  1363. 0, dctl.d32);
  1364. } else {
  1365. intr_mask.b.incomplisoin = 1;
  1366. intr_mask.b.incomplisoout = 1;
  1367. }
  1368. }
  1369. } else {
  1370. intr_mask.b.incomplisoin = 1;
  1371. intr_mask.b.incomplisoout = 1;
  1372. }
  1373. #endif /* DWC_EN_ISOC */
  1374. /** @todo NGS: Should this be a module parameter? */
  1375. #ifdef USE_PERIODIC_EP
  1376. intr_mask.b.isooutdrop = 1;
  1377. intr_mask.b.eopframe = 1;
  1378. intr_mask.b.incomplisoin = 1;
  1379. intr_mask.b.incomplisoout = 1;
  1380. #endif
  1381. DWC_MODIFY_REG32(&global_regs->gintmsk, intr_mask.d32, intr_mask.d32);
  1382. DWC_DEBUGPL(DBG_CIL, "%s() gintmsk=%0x\n", __func__,
  1383. DWC_READ_REG32(&global_regs->gintmsk));
  1384. }
  1385. /**
  1386. * This function initializes the DWC_otg controller registers for
  1387. * device mode.
  1388. *
  1389. * @param core_if Programming view of DWC_otg controller
  1390. *
  1391. */
  1392. void dwc_otg_core_dev_init(dwc_otg_core_if_t * core_if)
  1393. {
  1394. int i;
  1395. dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  1396. dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  1397. dwc_otg_core_params_t *params = core_if->core_params;
  1398. dcfg_data_t dcfg = {.d32 = 0 };
  1399. depctl_data_t diepctl = {.d32 = 0 };
  1400. grstctl_t resetctl = {.d32 = 0 };
  1401. uint32_t rx_fifo_size;
  1402. fifosize_data_t nptxfifosize;
  1403. fifosize_data_t txfifosize;
  1404. dthrctl_data_t dthrctl;
  1405. fifosize_data_t ptxfifosize;
  1406. uint16_t rxfsiz, nptxfsiz;
  1407. gdfifocfg_data_t gdfifocfg = {.d32 = 0 };
  1408. //hwcfg3_data_t hwcfg3 = {.d32 = 0 };
  1409. /* Restart the Phy Clock */
  1410. DWC_WRITE_REG32(core_if->pcgcctl, 0);
  1411. /* Device configuration register */
  1412. init_devspd(core_if);
  1413. dcfg.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dcfg);
  1414. dcfg.b.descdma = (core_if->dma_desc_enable) ? 1 : 0;
  1415. dcfg.b.perfrint = DWC_DCFG_FRAME_INTERVAL_80;
  1416. /* Enable Device OUT NAK in case of DDMA mode*/
  1417. if (core_if->core_params->dev_out_nak) {
  1418. dcfg.b.endevoutnak = 1;
  1419. }
  1420. if (core_if->core_params->cont_on_bna) {
  1421. dctl_data_t dctl = {.d32 = 0 };
  1422. dctl.b.encontonbna = 1;
  1423. DWC_MODIFY_REG32(&dev_if->dev_global_regs->dctl, 0, dctl.d32);
  1424. }
  1425. DWC_WRITE_REG32(&dev_if->dev_global_regs->dcfg, dcfg.d32);
  1426. /* Configure data FIFO sizes */
  1427. if (core_if->hwcfg2.b.dynamic_fifo && params->enable_dynamic_fifo) {
  1428. DWC_DEBUGPL(DBG_CIL, "Total FIFO Size=%d\n",
  1429. core_if->total_fifo_size);
  1430. DWC_DEBUGPL(DBG_CIL, "Rx FIFO Size=%d\n",
  1431. params->dev_rx_fifo_size);
  1432. DWC_DEBUGPL(DBG_CIL, "NP Tx FIFO Size=%d\n",
  1433. params->dev_nperio_tx_fifo_size);
  1434. /* Rx FIFO */
  1435. DWC_DEBUGPL(DBG_CIL, "initial grxfsiz=%08x\n",
  1436. DWC_READ_REG32(&global_regs->grxfsiz));
  1437. #ifdef DWC_UTE_CFI
  1438. core_if->pwron_rxfsiz = DWC_READ_REG32(&global_regs->grxfsiz);
  1439. core_if->init_rxfsiz = params->dev_rx_fifo_size;
  1440. #endif
  1441. rx_fifo_size = params->dev_rx_fifo_size;
  1442. DWC_WRITE_REG32(&global_regs->grxfsiz, rx_fifo_size);
  1443. DWC_DEBUGPL(DBG_CIL, "new grxfsiz=%08x\n",
  1444. DWC_READ_REG32(&global_regs->grxfsiz));
  1445. /** Set Periodic Tx FIFO Mask all bits 0 */
  1446. core_if->p_tx_msk = 0;
  1447. /** Set Tx FIFO Mask all bits 0 */
  1448. core_if->tx_msk = 0;
  1449. if (core_if->en_multiple_tx_fifo == 0) {
  1450. /* Non-periodic Tx FIFO */
  1451. DWC_DEBUGPL(DBG_CIL, "initial gnptxfsiz=%08x\n",
  1452. DWC_READ_REG32(&global_regs->gnptxfsiz));
  1453. nptxfifosize.b.depth = params->dev_nperio_tx_fifo_size;
  1454. nptxfifosize.b.startaddr = params->dev_rx_fifo_size;
  1455. DWC_WRITE_REG32(&global_regs->gnptxfsiz,
  1456. nptxfifosize.d32);
  1457. DWC_DEBUGPL(DBG_CIL, "new gnptxfsiz=%08x\n",
  1458. DWC_READ_REG32(&global_regs->gnptxfsiz));
  1459. /**@todo NGS: Fix Periodic FIFO Sizing! */
  1460. /*
  1461. * Periodic Tx FIFOs These FIFOs are numbered from 1 to 15.
  1462. * Indexes of the FIFO size module parameters in the
  1463. * dev_perio_tx_fifo_size array and the FIFO size registers in
  1464. * the dptxfsiz array run from 0 to 14.
  1465. */
  1466. /** @todo Finish debug of this */
  1467. ptxfifosize.b.startaddr =
  1468. nptxfifosize.b.startaddr + nptxfifosize.b.depth;
  1469. for (i = 0; i < core_if->hwcfg4.b.num_dev_perio_in_ep; i++) {
  1470. ptxfifosize.b.depth =
  1471. params->dev_perio_tx_fifo_size[i];
  1472. DWC_DEBUGPL(DBG_CIL,
  1473. "initial dtxfsiz[%d]=%08x\n", i,
  1474. DWC_READ_REG32(&global_regs->dtxfsiz
  1475. [i]));
  1476. DWC_WRITE_REG32(&global_regs->dtxfsiz[i],
  1477. ptxfifosize.d32);
  1478. DWC_DEBUGPL(DBG_CIL, "new dtxfsiz[%d]=%08x\n",
  1479. i,
  1480. DWC_READ_REG32(&global_regs->dtxfsiz
  1481. [i]));
  1482. ptxfifosize.b.startaddr += ptxfifosize.b.depth;
  1483. }
  1484. } else {
  1485. /*
  1486. * Tx FIFOs These FIFOs are numbered from 1 to 15.
  1487. * Indexes of the FIFO size module parameters in the
  1488. * dev_tx_fifo_size array and the FIFO size registers in
  1489. * the dtxfsiz array run from 0 to 14.
  1490. */
  1491. /* Non-periodic Tx FIFO */
  1492. DWC_DEBUGPL(DBG_CIL, "initial gnptxfsiz=%08x\n",
  1493. DWC_READ_REG32(&global_regs->gnptxfsiz));
  1494. #ifdef DWC_UTE_CFI
  1495. core_if->pwron_gnptxfsiz =
  1496. (DWC_READ_REG32(&global_regs->gnptxfsiz) >> 16);
  1497. core_if->init_gnptxfsiz =
  1498. params->dev_nperio_tx_fifo_size;
  1499. #endif
  1500. nptxfifosize.b.depth = params->dev_nperio_tx_fifo_size;
  1501. nptxfifosize.b.startaddr = params->dev_rx_fifo_size;
  1502. DWC_WRITE_REG32(&global_regs->gnptxfsiz,
  1503. nptxfifosize.d32);
  1504. DWC_DEBUGPL(DBG_CIL, "new gnptxfsiz=%08x\n",
  1505. DWC_READ_REG32(&global_regs->gnptxfsiz));
  1506. txfifosize.b.startaddr =
  1507. nptxfifosize.b.startaddr + nptxfifosize.b.depth;
  1508. for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  1509. txfifosize.b.depth =
  1510. params->dev_tx_fifo_size[i];
  1511. DWC_DEBUGPL(DBG_CIL,
  1512. "initial dtxfsiz[%d]=%08x\n",
  1513. i,
  1514. DWC_READ_REG32(&global_regs->dtxfsiz
  1515. [i]));
  1516. #ifdef DWC_UTE_CFI
  1517. core_if->pwron_txfsiz[i] =
  1518. (DWC_READ_REG32
  1519. (&global_regs->dtxfsiz[i]) >> 16);
  1520. core_if->init_txfsiz[i] =
  1521. params->dev_tx_fifo_size[i];
  1522. #endif
  1523. DWC_WRITE_REG32(&global_regs->dtxfsiz[i],
  1524. txfifosize.d32);
  1525. DWC_DEBUGPL(DBG_CIL,
  1526. "new dtxfsiz[%d]=%08x\n",
  1527. i,
  1528. DWC_READ_REG32(&global_regs->dtxfsiz
  1529. [i]));
  1530. txfifosize.b.startaddr += txfifosize.b.depth;
  1531. }
  1532. /* Calculating DFIFOCFG for Device mode to include RxFIFO and NPTXFIFO */
  1533. gdfifocfg.d32 = DWC_READ_REG32(&global_regs->gdfifocfg);
  1534. //hwcfg3.d32 = DWC_READ_REG32(&global_regs->ghwcfg3);
  1535. //gdfifocfg.b.gdfifocfg = (DWC_READ_REG32(&global_regs->ghwcfg3) >> 16);
  1536. gdfifocfg.b.gdfifocfg = params->data_fifo_size;
  1537. DWC_WRITE_REG32(&global_regs->gdfifocfg, gdfifocfg.d32);
  1538. rxfsiz = (DWC_READ_REG32(&global_regs->grxfsiz) & 0x0000ffff);
  1539. nptxfsiz = (DWC_READ_REG32(&global_regs->gnptxfsiz) >> 16);
  1540. gdfifocfg.b.epinfobase = rxfsiz + nptxfsiz;
  1541. DWC_WRITE_REG32(&global_regs->gdfifocfg, gdfifocfg.d32);
  1542. }
  1543. }
  1544. /* Flush the FIFOs */
  1545. dwc_otg_flush_tx_fifo(core_if, 0x10); /* all Tx FIFOs */
  1546. dwc_otg_flush_rx_fifo(core_if);
  1547. /* Flush the Learning Queue. */
  1548. resetctl.b.intknqflsh = 1;
  1549. DWC_WRITE_REG32(&core_if->core_global_regs->grstctl, resetctl.d32);
  1550. if (!core_if->core_params->en_multiple_tx_fifo && core_if->dma_enable) {
  1551. core_if->start_predict = 0;
  1552. for (i = 0; i<= core_if->dev_if->num_in_eps; ++i) {
  1553. core_if->nextep_seq[i] = 0xff; // 0xff - EP not active
  1554. }
  1555. core_if->nextep_seq[0] = 0;
  1556. core_if->first_in_nextep_seq = 0;
  1557. diepctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[0]->diepctl);
  1558. diepctl.b.nextep = 0;
  1559. DWC_WRITE_REG32(&dev_if->in_ep_regs[0]->diepctl, diepctl.d32);
  1560. /* Update IN Endpoint Mismatch Count by active IN NP EP count + 1 */
  1561. dcfg.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dcfg);
  1562. dcfg.b.epmscnt = 2;
  1563. DWC_WRITE_REG32(&dev_if->dev_global_regs->dcfg, dcfg.d32);
  1564. DWC_DEBUGPL(DBG_CILV,"%s first_in_nextep_seq= %2d; nextep_seq[]:\n",
  1565. __func__, core_if->first_in_nextep_seq);
  1566. for (i=0; i <= core_if->dev_if->num_in_eps; i++) {
  1567. DWC_DEBUGPL(DBG_CILV, "%2d ", core_if->nextep_seq[i]);
  1568. }
  1569. DWC_DEBUGPL(DBG_CILV,"\n");
  1570. }
  1571. /* Clear all pending Device Interrupts */
  1572. /** @todo - if the condition needed to be checked
  1573. * or in any case all pending interrutps should be cleared?
  1574. */
  1575. if (core_if->multiproc_int_enable) {
  1576. for (i = 0; i < core_if->dev_if->num_in_eps; ++i) {
  1577. DWC_WRITE_REG32(&dev_if->
  1578. dev_global_regs->diepeachintmsk[i], 0);
  1579. }
  1580. for (i = 0; i < core_if->dev_if->num_out_eps; ++i) {
  1581. DWC_WRITE_REG32(&dev_if->
  1582. dev_global_regs->doepeachintmsk[i], 0);
  1583. }
  1584. DWC_WRITE_REG32(&dev_if->dev_global_regs->deachint, 0xFFFFFFFF);
  1585. DWC_WRITE_REG32(&dev_if->dev_global_regs->deachintmsk, 0);
  1586. } else {
  1587. DWC_WRITE_REG32(&dev_if->dev_global_regs->diepmsk, 0);
  1588. DWC_WRITE_REG32(&dev_if->dev_global_regs->doepmsk, 0);
  1589. DWC_WRITE_REG32(&dev_if->dev_global_regs->daint, 0xFFFFFFFF);
  1590. DWC_WRITE_REG32(&dev_if->dev_global_regs->daintmsk, 0);
  1591. }
  1592. for (i = 0; i <= dev_if->num_in_eps; i++) {
  1593. depctl_data_t depctl;
  1594. depctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  1595. if (depctl.b.epena) {
  1596. depctl.d32 = 0;
  1597. depctl.b.epdis = 1;
  1598. depctl.b.snak = 1;
  1599. } else {
  1600. depctl.d32 = 0;
  1601. }
  1602. DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepctl, depctl.d32);
  1603. DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->dieptsiz, 0);
  1604. DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepdma, 0);
  1605. DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepint, 0xFF);
  1606. }
  1607. for (i = 0; i <= dev_if->num_out_eps; i++) {
  1608. depctl_data_t depctl;
  1609. depctl.d32 = DWC_READ_REG32(&dev_if->out_ep_regs[i]->doepctl);
  1610. if (depctl.b.epena) {
  1611. depctl.d32 = 0;
  1612. depctl.b.epdis = 1;
  1613. depctl.b.snak = 1;
  1614. } else {
  1615. depctl.d32 = 0;
  1616. }
  1617. DWC_WRITE_REG32(&dev_if->out_ep_regs[i]->doepctl, depctl.d32);
  1618. DWC_WRITE_REG32(&dev_if->out_ep_regs[i]->doeptsiz, 0);
  1619. DWC_WRITE_REG32(&dev_if->out_ep_regs[i]->doepdma, 0);
  1620. DWC_WRITE_REG32(&dev_if->out_ep_regs[i]->doepint, 0xFF);
  1621. }
  1622. if (core_if->en_multiple_tx_fifo && core_if->dma_enable) {
  1623. dev_if->non_iso_tx_thr_en = params->thr_ctl & 0x1;
  1624. dev_if->iso_tx_thr_en = (params->thr_ctl >> 1) & 0x1;
  1625. dev_if->rx_thr_en = (params->thr_ctl >> 2) & 0x1;
  1626. dev_if->rx_thr_length = params->rx_thr_length;
  1627. dev_if->tx_thr_length = params->tx_thr_length;
  1628. dev_if->setup_desc_index = 0;
  1629. dthrctl.d32 = 0;
  1630. dthrctl.b.non_iso_thr_en = dev_if->non_iso_tx_thr_en;
  1631. dthrctl.b.iso_thr_en = dev_if->iso_tx_thr_en;
  1632. dthrctl.b.tx_thr_len = dev_if->tx_thr_length;
  1633. dthrctl.b.rx_thr_en = dev_if->rx_thr_en;
  1634. dthrctl.b.rx_thr_len = dev_if->rx_thr_length;
  1635. dthrctl.b.ahb_thr_ratio = params->ahb_thr_ratio;
  1636. DWC_WRITE_REG32(&dev_if->dev_global_regs->dtknqr3_dthrctl,
  1637. dthrctl.d32);
  1638. DWC_DEBUGPL(DBG_CIL,
  1639. "Non ISO Tx Thr - %d\nISO Tx Thr - %d\nRx Thr - %d\nTx Thr Len - %d\nRx Thr Len - %d\n",
  1640. dthrctl.b.non_iso_thr_en, dthrctl.b.iso_thr_en,
  1641. dthrctl.b.rx_thr_en, dthrctl.b.tx_thr_len,
  1642. dthrctl.b.rx_thr_len);
  1643. }
  1644. dwc_otg_enable_device_interrupts(core_if);
  1645. {
  1646. diepmsk_data_t msk = {.d32 = 0 };
  1647. msk.b.txfifoundrn = 1;
  1648. if (core_if->multiproc_int_enable) {
  1649. DWC_MODIFY_REG32(&dev_if->
  1650. dev_global_regs->diepeachintmsk[0],
  1651. msk.d32, msk.d32);
  1652. } else {
  1653. DWC_MODIFY_REG32(&dev_if->dev_global_regs->diepmsk,
  1654. msk.d32, msk.d32);
  1655. }
  1656. }
  1657. if (core_if->multiproc_int_enable) {
  1658. /* Set NAK on Babble */
  1659. dctl_data_t dctl = {.d32 = 0 };
  1660. dctl.b.nakonbble = 1;
  1661. DWC_MODIFY_REG32(&dev_if->dev_global_regs->dctl, 0, dctl.d32);
  1662. }
  1663. if (core_if->snpsid >= OTG_CORE_REV_2_94a) {
  1664. /*
  1665. * In 2.94a, pull_up is disabled after reset/power on.
  1666. * Gadget must call pull_up() to enable the connection.
  1667. * Here is the workarond code for BC detection changes
  1668. */
  1669. usb_peri_reg_t *peri;
  1670. usb_adp_bc_data_t adp_bc;
  1671. /* Workaround for boot in a live connection*/
  1672. peri = core_if->usb_peri_reg;
  1673. adp_bc.d32 = DWC_READ_REG32(&peri->adp_bc);
  1674. if(adp_bc.b.device_sess_vld){
  1675. core_if->session_valid = 1;
  1676. core_if->dev_if->vbus_on = 1;
  1677. }
  1678. }
  1679. }
  1680. /**
  1681. * This function enables the Host mode interrupts.
  1682. *
  1683. * @param core_if Programming view of DWC_otg controller
  1684. */
  1685. void dwc_otg_enable_host_interrupts(dwc_otg_core_if_t * core_if)
  1686. {
  1687. dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  1688. gintmsk_data_t intr_mask = {.d32 = 0 };
  1689. DWC_DEBUGPL(DBG_CIL, "%s()\n", __func__);
  1690. /* Disable all interrupts. */
  1691. DWC_WRITE_REG32(&global_regs->gintmsk, 0);
  1692. /* Clear any pending interrupts. */
  1693. DWC_WRITE_REG32(&global_regs->gintsts, 0xFFFFFFFF);
  1694. /* Enable the common interrupts */
  1695. dwc_otg_enable_common_interrupts(core_if);
  1696. /*
  1697. * Enable host mode interrupts without disturbing common
  1698. * interrupts.
  1699. */
  1700. intr_mask.b.disconnect = 1;
  1701. intr_mask.b.portintr = 1;
  1702. intr_mask.b.hcintr = 1;
  1703. DWC_MODIFY_REG32(&global_regs->gintmsk, intr_mask.d32, intr_mask.d32);
  1704. }
  1705. /**
  1706. * This function disables the Host Mode interrupts.
  1707. *
  1708. * @param core_if Programming view of DWC_otg controller
  1709. */
  1710. void dwc_otg_disable_host_interrupts(dwc_otg_core_if_t * core_if)
  1711. {
  1712. dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  1713. gintmsk_data_t intr_mask = {.d32 = 0 };
  1714. DWC_DEBUGPL(DBG_CILV, "%s()\n", __func__);
  1715. /*
  1716. * Disable host mode interrupts without disturbing common
  1717. * interrupts.
  1718. */
  1719. intr_mask.b.sofintr = 1;
  1720. intr_mask.b.portintr = 1;
  1721. intr_mask.b.hcintr = 1;
  1722. intr_mask.b.ptxfempty = 1;
  1723. intr_mask.b.nptxfempty = 1;
  1724. DWC_MODIFY_REG32(&global_regs->gintmsk, intr_mask.d32, 0);
  1725. }
  1726. /**
  1727. * This function initializes the DWC_otg controller registers for
  1728. * host mode.
  1729. *
  1730. * This function flushes the Tx and Rx FIFOs and it flushes any entries in the
  1731. * request queues. Host channels are reset to ensure that they are ready for
  1732. * performing transfers.
  1733. *
  1734. * @param core_if Programming view of DWC_otg controller
  1735. *
  1736. */
  1737. void dwc_otg_core_host_init(dwc_otg_core_if_t * core_if)
  1738. {
  1739. dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  1740. dwc_otg_host_if_t *host_if = core_if->host_if;
  1741. dwc_otg_core_params_t *params = core_if->core_params;
  1742. hprt0_data_t hprt0 = {.d32 = 0 };
  1743. fifosize_data_t nptxfifosize;
  1744. fifosize_data_t ptxfifosize;
  1745. uint16_t rxfsiz, nptxfsiz, hptxfsiz;
  1746. gdfifocfg_data_t gdfifocfg = {.d32 = 0 };
  1747. int i;
  1748. hcchar_data_t hcchar;
  1749. hcfg_data_t hcfg;
  1750. hfir_data_t hfir;
  1751. dwc_otg_hc_regs_t *hc_regs;
  1752. int num_channels;
  1753. gotgctl_data_t gotgctl = {.d32 = 0 };
  1754. DWC_DEBUGPL(DBG_CILV, "%s(%p)\n", __func__, core_if);
  1755. /* Restart the Phy Clock */
  1756. DWC_WRITE_REG32(core_if->pcgcctl, 0);
  1757. /* Initialize Host Configuration Register */
  1758. init_fslspclksel(core_if);
  1759. if (core_if->core_params->speed == DWC_SPEED_PARAM_FULL) {
  1760. hcfg.d32 = DWC_READ_REG32(&host_if->host_global_regs->hcfg);
  1761. hcfg.b.fslssupp = 1;
  1762. DWC_WRITE_REG32(&host_if->host_global_regs->hcfg, hcfg.d32);
  1763. }
  1764. /* This bit allows dynamic reloading of the HFIR register
  1765. * during runtime. This bit needs to be programmed during
  1766. * initial configuration and its value must not be changed
  1767. * during runtime.*/
  1768. if (core_if->core_params->reload_ctl == 1) {
  1769. hfir.d32 = DWC_READ_REG32(&host_if->host_global_regs->hfir);
  1770. hfir.b.hfirrldctrl = 1;
  1771. DWC_WRITE_REG32(&host_if->host_global_regs->hfir, hfir.d32);
  1772. }
  1773. if (core_if->core_params->dma_desc_enable) {
  1774. uint8_t op_mode = core_if->hwcfg2.b.op_mode;
  1775. if (!
  1776. (core_if->hwcfg4.b.desc_dma
  1777. && (core_if->snpsid >= OTG_CORE_REV_2_90a)
  1778. && ((op_mode == DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG)
  1779. || (op_mode == DWC_HWCFG2_OP_MODE_SRP_ONLY_CAPABLE_OTG)
  1780. || (op_mode ==
  1781. DWC_HWCFG2_OP_MODE_NO_HNP_SRP_CAPABLE_OTG)
  1782. || (op_mode == DWC_HWCFG2_OP_MODE_SRP_CAPABLE_HOST)
  1783. || (op_mode ==
  1784. DWC_HWCFG2_OP_MODE_NO_SRP_CAPABLE_HOST)))) {
  1785. DWC_ERROR("Host can't operate in Descriptor DMA mode.\n"
  1786. "Either core version is below 2.90a or "
  1787. "GHWCFG2, GHWCFG4 registers' values do not allow Descriptor DMA in host mode.\n"
  1788. "To run the driver in Buffer DMA host mode set dma_desc_enable "
  1789. "module parameter to 0.\n");
  1790. return;
  1791. }
  1792. hcfg.d32 = DWC_READ_REG32(&host_if->host_global_regs->hcfg);
  1793. hcfg.b.descdma = 1;
  1794. DWC_WRITE_REG32(&host_if->host_global_regs->hcfg, hcfg.d32);
  1795. }
  1796. /* Configure data FIFO sizes */
  1797. if (core_if->hwcfg2.b.dynamic_fifo && params->enable_dynamic_fifo) {
  1798. DWC_DEBUGPL(DBG_CIL, "Total FIFO Size=%d\n",
  1799. core_if->total_fifo_size);
  1800. DWC_DEBUGPL(DBG_CIL, "Rx FIFO Size=%d\n",
  1801. params->host_rx_fifo_size);
  1802. DWC_DEBUGPL(DBG_CIL, "NP Tx FIFO Size=%d\n",
  1803. params->host_nperio_tx_fifo_size);
  1804. DWC_DEBUGPL(DBG_CIL, "P Tx FIFO Size=%d\n",
  1805. params->host_perio_tx_fifo_size);
  1806. /* Rx FIFO */
  1807. DWC_DEBUGPL(DBG_CIL, "initial grxfsiz=%08x\n",
  1808. DWC_READ_REG32(&global_regs->grxfsiz));
  1809. DWC_WRITE_REG32(&global_regs->grxfsiz,
  1810. params->host_rx_fifo_size);
  1811. DWC_DEBUGPL(DBG_CIL, "new grxfsiz=%08x\n",
  1812. DWC_READ_REG32(&global_regs->grxfsiz));
  1813. /* Non-periodic Tx FIFO */
  1814. DWC_DEBUGPL(DBG_CIL, "initial gnptxfsiz=%08x\n",
  1815. DWC_READ_REG32(&global_regs->gnptxfsiz));
  1816. nptxfifosize.b.depth = params->host_nperio_tx_fifo_size;
  1817. nptxfifosize.b.startaddr = params->host_rx_fifo_size;
  1818. DWC_WRITE_REG32(&global_regs->gnptxfsiz, nptxfifosize.d32);
  1819. DWC_DEBUGPL(DBG_CIL, "new gnptxfsiz=%08x\n",
  1820. DWC_READ_REG32(&global_regs->gnptxfsiz));
  1821. /* Periodic Tx FIFO */
  1822. DWC_DEBUGPL(DBG_CIL, "initial hptxfsiz=%08x\n",
  1823. DWC_READ_REG32(&global_regs->hptxfsiz));
  1824. ptxfifosize.b.depth = params->host_perio_tx_fifo_size;
  1825. ptxfifosize.b.startaddr =
  1826. nptxfifosize.b.startaddr + nptxfifosize.b.depth;
  1827. DWC_WRITE_REG32(&global_regs->hptxfsiz, ptxfifosize.d32);
  1828. DWC_DEBUGPL(DBG_CIL, "new hptxfsiz=%08x\n",
  1829. DWC_READ_REG32(&global_regs->hptxfsiz));
  1830. if (core_if->en_multiple_tx_fifo) {
  1831. /* Global DFIFOCFG calculation for Host mode - include RxFIFO, NPTXFIFO and HPTXFIFO */
  1832. gdfifocfg.d32 = DWC_READ_REG32(&global_regs->gdfifocfg);
  1833. rxfsiz = (DWC_READ_REG32(&global_regs->grxfsiz) & 0x0000ffff);
  1834. nptxfsiz = (DWC_READ_REG32(&global_regs->gnptxfsiz) >> 16);
  1835. hptxfsiz = (DWC_READ_REG32(&global_regs->hptxfsiz) >> 16);
  1836. gdfifocfg.b.epinfobase = rxfsiz + nptxfsiz + hptxfsiz;
  1837. DWC_WRITE_REG32(&global_regs->gdfifocfg, gdfifocfg.d32);
  1838. }
  1839. }
  1840. /* TODO - check this */
  1841. /* Clear Host Set HNP Enable in the OTG Control Register */
  1842. gotgctl.b.hstsethnpen = 1;
  1843. DWC_MODIFY_REG32(&global_regs->gotgctl, gotgctl.d32, 0);
  1844. /* Make sure the FIFOs are flushed. */
  1845. dwc_otg_flush_tx_fifo(core_if, 0x10 /* all TX FIFOs */ );
  1846. dwc_otg_flush_rx_fifo(core_if);
  1847. /* Clear Host Set HNP Enable in the OTG Control Register */
  1848. gotgctl.b.hstsethnpen = 1;
  1849. DWC_MODIFY_REG32(&global_regs->gotgctl, gotgctl.d32, 0);
  1850. if (!core_if->core_params->dma_desc_enable) {
  1851. /* Flush out any leftover queued requests. */
  1852. num_channels = core_if->core_params->host_channels;
  1853. for (i = 0; i < num_channels; i++) {
  1854. hc_regs = core_if->host_if->hc_regs[i];
  1855. hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  1856. hcchar.b.chen = 0;
  1857. hcchar.b.chdis = 1;
  1858. hcchar.b.epdir = 0;
  1859. DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  1860. }
  1861. /* Halt all channels to put them into a known state. */
  1862. for (i = 0; i < num_channels; i++) {
  1863. int count = 0;
  1864. hc_regs = core_if->host_if->hc_regs[i];
  1865. hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  1866. hcchar.b.chen = 1;
  1867. hcchar.b.chdis = 1;
  1868. hcchar.b.epdir = 0;
  1869. DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  1870. DWC_DEBUGPL(DBG_HCDV, "%s: Halt channel %d\n", __func__, i);
  1871. do {
  1872. hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  1873. if (++count > 1000) {
  1874. DWC_ERROR
  1875. ("%s: Unable to clear halt on channel %d\n",
  1876. __func__, i);
  1877. break;
  1878. }
  1879. dwc_udelay(1);
  1880. } while (hcchar.b.chen);
  1881. }
  1882. }
  1883. /* Turn on the vbus power. */
  1884. DWC_PRINTF("Init: Port Power? op_state=%d\n", core_if->op_state);
  1885. if (core_if->op_state == A_HOST) {
  1886. hprt0.d32 = dwc_otg_read_hprt0(core_if);
  1887. DWC_PRINTF("Init: Power Port (%d)\n", hprt0.b.prtpwr);
  1888. if (hprt0.b.prtpwr == 0) {
  1889. hprt0.b.prtpwr = 1;
  1890. DWC_WRITE_REG32(host_if->hprt0, hprt0.d32);
  1891. }
  1892. dwc_otg_set_vbus_power(core_if, 1);
  1893. }
  1894. dwc_otg_enable_host_interrupts(core_if);
  1895. }
  1896. /**
  1897. * Prepares a host channel for transferring packets to/from a specific
  1898. * endpoint. The HCCHARn register is set up with the characteristics specified
  1899. * in _hc. Host channel interrupts that may need to be serviced while this
  1900. * transfer is in progress are enabled.
  1901. *
  1902. * @param core_if Programming view of DWC_otg controller
  1903. * @param hc Information needed to initialize the host channel
  1904. */
  1905. void dwc_otg_hc_init(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  1906. {
  1907. uint32_t intr_enable;
  1908. hcintmsk_data_t hc_intr_mask;
  1909. gintmsk_data_t gintmsk = {.d32 = 0 };
  1910. hcchar_data_t hcchar;
  1911. hcsplt_data_t hcsplt;
  1912. uint8_t hc_num = hc->hc_num;
  1913. dwc_otg_host_if_t *host_if = core_if->host_if;
  1914. dwc_otg_hc_regs_t *hc_regs = host_if->hc_regs[hc_num];
  1915. /* Clear old interrupt conditions for this host channel. */
  1916. hc_intr_mask.d32 = 0xFFFFFFFF;
  1917. hc_intr_mask.b.reserved14_31 = 0;
  1918. DWC_WRITE_REG32(&hc_regs->hcint, hc_intr_mask.d32);
  1919. /* Enable channel interrupts required for this transfer. */
  1920. hc_intr_mask.d32 = 0;
  1921. hc_intr_mask.b.chhltd = 1;
  1922. if (core_if->dma_enable) {
  1923. /* For Descriptor DMA mode core halts the channel on AHB error. Interrupt is not required */
  1924. if (!core_if->dma_desc_enable)
  1925. hc_intr_mask.b.ahberr = 1;
  1926. else {
  1927. if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC)
  1928. hc_intr_mask.b.xfercompl = 1;
  1929. }
  1930. if (hc->error_state && !hc->do_split &&
  1931. hc->ep_type != DWC_OTG_EP_TYPE_ISOC) {
  1932. hc_intr_mask.b.ack = 1;
  1933. if (hc->ep_is_in) {
  1934. hc_intr_mask.b.datatglerr = 1;
  1935. if (hc->ep_type != DWC_OTG_EP_TYPE_INTR) {
  1936. hc_intr_mask.b.nak = 1;
  1937. }
  1938. }
  1939. }
  1940. } else {
  1941. switch (hc->ep_type) {
  1942. case DWC_OTG_EP_TYPE_CONTROL:
  1943. case DWC_OTG_EP_TYPE_BULK:
  1944. hc_intr_mask.b.xfercompl = 1;
  1945. hc_intr_mask.b.stall = 1;
  1946. hc_intr_mask.b.xacterr = 1;
  1947. hc_intr_mask.b.datatglerr = 1;
  1948. if (hc->ep_is_in) {
  1949. hc_intr_mask.b.bblerr = 1;
  1950. } else {
  1951. hc_intr_mask.b.nak = 1;
  1952. hc_intr_mask.b.nyet = 1;
  1953. if (hc->do_ping) {
  1954. hc_intr_mask.b.ack = 1;
  1955. }
  1956. }
  1957. if (hc->do_split) {
  1958. hc_intr_mask.b.nak = 1;
  1959. if (hc->complete_split) {
  1960. hc_intr_mask.b.nyet = 1;
  1961. } else {
  1962. hc_intr_mask.b.ack = 1;
  1963. }
  1964. }
  1965. if (hc->error_state) {
  1966. hc_intr_mask.b.ack = 1;
  1967. }
  1968. break;
  1969. case DWC_OTG_EP_TYPE_INTR:
  1970. hc_intr_mask.b.xfercompl = 1;
  1971. hc_intr_mask.b.nak = 1;
  1972. hc_intr_mask.b.stall = 1;
  1973. hc_intr_mask.b.xacterr = 1;
  1974. hc_intr_mask.b.datatglerr = 1;
  1975. hc_intr_mask.b.frmovrun = 1;
  1976. if (hc->ep_is_in) {
  1977. hc_intr_mask.b.bblerr = 1;
  1978. }
  1979. if (hc->error_state) {
  1980. hc_intr_mask.b.ack = 1;
  1981. }
  1982. if (hc->do_split) {
  1983. if (hc->complete_split) {
  1984. hc_intr_mask.b.nyet = 1;
  1985. } else {
  1986. hc_intr_mask.b.ack = 1;
  1987. }
  1988. }
  1989. break;
  1990. case DWC_OTG_EP_TYPE_ISOC:
  1991. hc_intr_mask.b.xfercompl = 1;
  1992. hc_intr_mask.b.frmovrun = 1;
  1993. hc_intr_mask.b.ack = 1;
  1994. if (hc->ep_is_in) {
  1995. hc_intr_mask.b.xacterr = 1;
  1996. hc_intr_mask.b.bblerr = 1;
  1997. }
  1998. break;
  1999. }
  2000. }
  2001. DWC_WRITE_REG32(&hc_regs->hcintmsk, hc_intr_mask.d32);
  2002. /* Enable the top level host channel interrupt. */
  2003. intr_enable = (1 << hc_num);
  2004. DWC_MODIFY_REG32(&host_if->host_global_regs->haintmsk, 0, intr_enable);
  2005. /* Make sure host channel interrupts are enabled. */
  2006. gintmsk.b.hcintr = 1;
  2007. DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, 0, gintmsk.d32);
  2008. /*
  2009. * Program the HCCHARn register with the endpoint characteristics for
  2010. * the current transfer.
  2011. */
  2012. hcchar.d32 = 0;
  2013. hcchar.b.devaddr = hc->dev_addr;
  2014. hcchar.b.epnum = hc->ep_num;
  2015. hcchar.b.epdir = hc->ep_is_in;
  2016. hcchar.b.lspddev = (hc->speed == DWC_OTG_EP_SPEED_LOW);
  2017. hcchar.b.eptype = hc->ep_type;
  2018. hcchar.b.mps = hc->max_packet;
  2019. DWC_WRITE_REG32(&host_if->hc_regs[hc_num]->hcchar, hcchar.d32);
  2020. DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, hc->hc_num);
  2021. DWC_DEBUGPL(DBG_HCDV, " Dev Addr: %d\n", hcchar.b.devaddr);
  2022. DWC_DEBUGPL(DBG_HCDV, " Ep Num: %d\n", hcchar.b.epnum);
  2023. DWC_DEBUGPL(DBG_HCDV, " Is In: %d\n", hcchar.b.epdir);
  2024. DWC_DEBUGPL(DBG_HCDV, " Is Low Speed: %d\n", hcchar.b.lspddev);
  2025. DWC_DEBUGPL(DBG_HCDV, " Ep Type: %d\n", hcchar.b.eptype);
  2026. DWC_DEBUGPL(DBG_HCDV, " Max Pkt: %d\n", hcchar.b.mps);
  2027. DWC_DEBUGPL(DBG_HCDV, " Multi Cnt: %d\n", hcchar.b.multicnt);
  2028. /*
  2029. * Program the HCSPLIT register for SPLITs
  2030. */
  2031. hcsplt.d32 = 0;
  2032. if (hc->do_split) {
  2033. DWC_DEBUGPL(DBG_HCDV, "Programming HC %d with split --> %s\n",
  2034. hc->hc_num,
  2035. hc->complete_split ? "CSPLIT" : "SSPLIT");
  2036. hcsplt.b.compsplt = hc->complete_split;
  2037. hcsplt.b.xactpos = hc->xact_pos;
  2038. hcsplt.b.hubaddr = hc->hub_addr;
  2039. hcsplt.b.prtaddr = hc->port_addr;
  2040. DWC_DEBUGPL(DBG_HCDV, " comp split %d\n", hc->complete_split);
  2041. DWC_DEBUGPL(DBG_HCDV, " xact pos %d\n", hc->xact_pos);
  2042. DWC_DEBUGPL(DBG_HCDV, " hub addr %d\n", hc->hub_addr);
  2043. DWC_DEBUGPL(DBG_HCDV, " port addr %d\n", hc->port_addr);
  2044. DWC_DEBUGPL(DBG_HCDV, " is_in %d\n", hc->ep_is_in);
  2045. DWC_DEBUGPL(DBG_HCDV, " Max Pkt: %d\n", hcchar.b.mps);
  2046. DWC_DEBUGPL(DBG_HCDV, " xferlen: %d\n", hc->xfer_len);
  2047. }
  2048. DWC_WRITE_REG32(&host_if->hc_regs[hc_num]->hcsplt, hcsplt.d32);
  2049. }
  2050. /**
  2051. * Attempts to halt a host channel. This function should only be called in
  2052. * Slave mode or to abort a transfer in either Slave mode or DMA mode. Under
  2053. * normal circumstances in DMA mode, the controller halts the channel when the
  2054. * transfer is complete or a condition occurs that requires application
  2055. * intervention.
  2056. *
  2057. * In slave mode, checks for a free request queue entry, then sets the Channel
  2058. * Enable and Channel Disable bits of the Host Channel Characteristics
  2059. * register of the specified channel to intiate the halt. If there is no free
  2060. * request queue entry, sets only the Channel Disable bit of the HCCHARn
  2061. * register to flush requests for this channel. In the latter case, sets a
  2062. * flag to indicate that the host channel needs to be halted when a request
  2063. * queue slot is open.
  2064. *
  2065. * In DMA mode, always sets the Channel Enable and Channel Disable bits of the
  2066. * HCCHARn register. The controller ensures there is space in the request
  2067. * queue before submitting the halt request.
  2068. *
  2069. * Some time may elapse before the core flushes any posted requests for this
  2070. * host channel and halts. The Channel Halted interrupt handler completes the
  2071. * deactivation of the host channel.
  2072. *
  2073. * @param core_if Controller register interface.
  2074. * @param hc Host channel to halt.
  2075. * @param halt_status Reason for halting the channel.
  2076. */
  2077. void dwc_otg_hc_halt(dwc_otg_core_if_t * core_if,
  2078. dwc_hc_t * hc, dwc_otg_halt_status_e halt_status)
  2079. {
  2080. gnptxsts_data_t nptxsts;
  2081. hptxsts_data_t hptxsts;
  2082. hcchar_data_t hcchar;
  2083. dwc_otg_hc_regs_t *hc_regs;
  2084. dwc_otg_core_global_regs_t *global_regs;
  2085. dwc_otg_host_global_regs_t *host_global_regs;
  2086. hc_regs = core_if->host_if->hc_regs[hc->hc_num];
  2087. global_regs = core_if->core_global_regs;
  2088. host_global_regs = core_if->host_if->host_global_regs;
  2089. DWC_ASSERT(!(halt_status == DWC_OTG_HC_XFER_NO_HALT_STATUS),
  2090. "halt_status = %d\n", halt_status);
  2091. if (halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE ||
  2092. halt_status == DWC_OTG_HC_XFER_AHB_ERR) {
  2093. /*
  2094. * Disable all channel interrupts except Ch Halted. The QTD
  2095. * and QH state associated with this transfer has been cleared
  2096. * (in the case of URB_DEQUEUE), so the channel needs to be
  2097. * shut down carefully to prevent crashes.
  2098. */
  2099. hcintmsk_data_t hcintmsk;
  2100. hcintmsk.d32 = 0;
  2101. hcintmsk.b.chhltd = 1;
  2102. DWC_WRITE_REG32(&hc_regs->hcintmsk, hcintmsk.d32);
  2103. /*
  2104. * Make sure no other interrupts besides halt are currently
  2105. * pending. Handling another interrupt could cause a crash due
  2106. * to the QTD and QH state.
  2107. */
  2108. DWC_WRITE_REG32(&hc_regs->hcint, ~hcintmsk.d32);
  2109. /*
  2110. * Make sure the halt status is set to URB_DEQUEUE or AHB_ERR
  2111. * even if the channel was already halted for some other
  2112. * reason.
  2113. */
  2114. hc->halt_status = halt_status;
  2115. hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  2116. if (hcchar.b.chen == 0) {
  2117. /*
  2118. * The channel is either already halted or it hasn't
  2119. * started yet. In DMA mode, the transfer may halt if
  2120. * it finishes normally or a condition occurs that
  2121. * requires driver intervention. Don't want to halt
  2122. * the channel again. In either Slave or DMA mode,
  2123. * it's possible that the transfer has been assigned
  2124. * to a channel, but not started yet when an URB is
  2125. * dequeued. Don't want to halt a channel that hasn't
  2126. * started yet.
  2127. */
  2128. return;
  2129. }
  2130. }
  2131. if (hc->halt_pending) {
  2132. /*
  2133. * A halt has already been issued for this channel. This might
  2134. * happen when a transfer is aborted by a higher level in
  2135. * the stack.
  2136. */
  2137. #ifdef DEBUG
  2138. DWC_PRINTF
  2139. ("*** %s: Channel %d, _hc->halt_pending already set ***\n",
  2140. __func__, hc->hc_num);
  2141. #endif
  2142. return;
  2143. }
  2144. hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  2145. /* No need to set the bit in DDMA for disabling the channel */
  2146. //TODO check it everywhere channel is disabled
  2147. if (!core_if->core_params->dma_desc_enable)
  2148. hcchar.b.chen = 1;
  2149. hcchar.b.chdis = 1;
  2150. if (!core_if->dma_enable) {
  2151. /* Check for space in the request queue to issue the halt. */
  2152. if (hc->ep_type == DWC_OTG_EP_TYPE_CONTROL ||
  2153. hc->ep_type == DWC_OTG_EP_TYPE_BULK) {
  2154. nptxsts.d32 = DWC_READ_REG32(&global_regs->gnptxsts);
  2155. if (nptxsts.b.nptxqspcavail == 0) {
  2156. hcchar.b.chen = 0;
  2157. }
  2158. } else {
  2159. hptxsts.d32 =
  2160. DWC_READ_REG32(&host_global_regs->hptxsts);
  2161. if ((hptxsts.b.ptxqspcavail == 0)
  2162. || (core_if->queuing_high_bandwidth)) {
  2163. hcchar.b.chen = 0;
  2164. }
  2165. }
  2166. }
  2167. DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  2168. hc->halt_status = halt_status;
  2169. if (hcchar.b.chen) {
  2170. hc->halt_pending = 1;
  2171. hc->halt_on_queue = 0;
  2172. } else {
  2173. hc->halt_on_queue = 1;
  2174. }
  2175. DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, hc->hc_num);
  2176. DWC_DEBUGPL(DBG_HCDV, " hcchar: 0x%08x\n", hcchar.d32);
  2177. DWC_DEBUGPL(DBG_HCDV, " halt_pending: %d\n", hc->halt_pending);
  2178. DWC_DEBUGPL(DBG_HCDV, " halt_on_queue: %d\n", hc->halt_on_queue);
  2179. DWC_DEBUGPL(DBG_HCDV, " halt_status: %d\n", hc->halt_status);
  2180. return;
  2181. }
  2182. /**
  2183. * Clears the transfer state for a host channel. This function is normally
  2184. * called after a transfer is done and the host channel is being released.
  2185. *
  2186. * @param core_if Programming view of DWC_otg controller.
  2187. * @param hc Identifies the host channel to clean up.
  2188. */
  2189. void dwc_otg_hc_cleanup(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  2190. {
  2191. dwc_otg_hc_regs_t *hc_regs;
  2192. hc->xfer_started = 0;
  2193. /*
  2194. * Clear channel interrupt enables and any unhandled channel interrupt
  2195. * conditions.
  2196. */
  2197. hc_regs = core_if->host_if->hc_regs[hc->hc_num];
  2198. DWC_WRITE_REG32(&hc_regs->hcintmsk, 0);
  2199. DWC_WRITE_REG32(&hc_regs->hcint, 0xFFFFFFFF);
  2200. #ifdef DEBUG
  2201. DWC_TIMER_CANCEL(core_if->hc_xfer_timer[hc->hc_num]);
  2202. #endif
  2203. }
  2204. /**
  2205. * Sets the channel property that indicates in which frame a periodic transfer
  2206. * should occur. This is always set to the _next_ frame. This function has no
  2207. * effect on non-periodic transfers.
  2208. *
  2209. * @param core_if Programming view of DWC_otg controller.
  2210. * @param hc Identifies the host channel to set up and its properties.
  2211. * @param hcchar Current value of the HCCHAR register for the specified host
  2212. * channel.
  2213. */
  2214. static inline void hc_set_even_odd_frame(dwc_otg_core_if_t * core_if,
  2215. dwc_hc_t * hc, hcchar_data_t * hcchar)
  2216. {
  2217. if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  2218. hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  2219. hfnum_data_t hfnum;
  2220. hfnum.d32 =
  2221. DWC_READ_REG32(&core_if->host_if->host_global_regs->hfnum);
  2222. /* 1 if _next_ frame is odd, 0 if it's even */
  2223. hcchar->b.oddfrm = (hfnum.b.frnum & 0x1) ? 0 : 1;
  2224. #ifdef DEBUG
  2225. if (hc->ep_type == DWC_OTG_EP_TYPE_INTR && hc->do_split
  2226. && !hc->complete_split) {
  2227. switch (hfnum.b.frnum & 0x7) {
  2228. case 7:
  2229. core_if->hfnum_7_samples++;
  2230. core_if->hfnum_7_frrem_accum += hfnum.b.frrem;
  2231. break;
  2232. case 0:
  2233. core_if->hfnum_0_samples++;
  2234. core_if->hfnum_0_frrem_accum += hfnum.b.frrem;
  2235. break;
  2236. default:
  2237. core_if->hfnum_other_samples++;
  2238. core_if->hfnum_other_frrem_accum +=
  2239. hfnum.b.frrem;
  2240. break;
  2241. }
  2242. }
  2243. #endif
  2244. }
  2245. }
  2246. #ifdef DEBUG
  2247. void hc_xfer_timeout(void *ptr)
  2248. {
  2249. hc_xfer_info_t *xfer_info = NULL;
  2250. int hc_num = 0;
  2251. if (ptr)
  2252. xfer_info = (hc_xfer_info_t *) ptr;
  2253. if (!xfer_info->hc) {
  2254. DWC_ERROR("xfer_info->hc = %p\n", xfer_info->hc);
  2255. return;
  2256. }
  2257. hc_num = xfer_info->hc->hc_num;
  2258. DWC_WARN("%s: timeout on channel %d\n", __func__, hc_num);
  2259. DWC_WARN(" start_hcchar_val 0x%08x\n",
  2260. xfer_info->core_if->start_hcchar_val[hc_num]);
  2261. }
  2262. #endif
  2263. void ep_xfer_timeout(void *ptr)
  2264. {
  2265. ep_xfer_info_t *xfer_info = NULL;
  2266. int ep_num = 0;
  2267. dctl_data_t dctl = {.d32 = 0 };
  2268. gintsts_data_t gintsts = {.d32 = 0 };
  2269. gintmsk_data_t gintmsk = {.d32 = 0 };
  2270. if (ptr)
  2271. xfer_info = (ep_xfer_info_t *) ptr;
  2272. if (!xfer_info->ep) {
  2273. DWC_ERROR("xfer_info->ep = %p\n", xfer_info->ep);
  2274. return;
  2275. }
  2276. ep_num = xfer_info->ep->num;
  2277. DWC_WARN("%s: timeout on endpoit %d\n", __func__, ep_num);
  2278. /* Put the sate to 2 as it was time outed */
  2279. xfer_info->state = 2;
  2280. dctl.d32 = DWC_READ_REG32(&xfer_info->core_if->
  2281. dev_if->dev_global_regs->dctl);
  2282. gintsts.d32 = DWC_READ_REG32(&xfer_info->core_if->
  2283. core_global_regs->gintsts);
  2284. gintmsk.d32 = DWC_READ_REG32(&xfer_info->core_if->
  2285. core_global_regs->gintmsk);
  2286. if (!gintmsk.b.goutnakeff) {
  2287. /* Unmask it */
  2288. gintmsk.b.goutnakeff = 1;
  2289. DWC_WRITE_REG32(&xfer_info->core_if->
  2290. core_global_regs->gintmsk, gintmsk.d32);
  2291. }
  2292. if (!gintsts.b.goutnakeff) {
  2293. dctl.b.sgoutnak = 1;
  2294. }
  2295. DWC_WRITE_REG32(&xfer_info->core_if->dev_if->
  2296. dev_global_regs->dctl, dctl.d32);
  2297. }
  2298. void set_pid_isoc(dwc_hc_t * hc)
  2299. {
  2300. /* Set up the initial PID for the transfer. */
  2301. if (hc->speed == DWC_OTG_EP_SPEED_HIGH) {
  2302. if (hc->ep_is_in) {
  2303. if (hc->multi_count == 1) {
  2304. hc->data_pid_start = DWC_OTG_HC_PID_DATA0;
  2305. } else if (hc->multi_count == 2) {
  2306. hc->data_pid_start = DWC_OTG_HC_PID_DATA1;
  2307. } else {
  2308. hc->data_pid_start = DWC_OTG_HC_PID_DATA2;
  2309. }
  2310. } else {
  2311. if (hc->multi_count == 1) {
  2312. hc->data_pid_start = DWC_OTG_HC_PID_DATA0;
  2313. } else {
  2314. hc->data_pid_start = DWC_OTG_HC_PID_MDATA;
  2315. }
  2316. }
  2317. } else {
  2318. hc->data_pid_start = DWC_OTG_HC_PID_DATA0;
  2319. }
  2320. }
  2321. /**
  2322. * This function does the setup for a data transfer for a host channel and
  2323. * starts the transfer. May be called in either Slave mode or DMA mode. In
  2324. * Slave mode, the caller must ensure that there is sufficient space in the
  2325. * request queue and Tx Data FIFO.
  2326. *
  2327. * For an OUT transfer in Slave mode, it loads a data packet into the
  2328. * appropriate FIFO. If necessary, additional data packets will be loaded in
  2329. * the Host ISR.
  2330. *
  2331. * For an IN transfer in Slave mode, a data packet is requested. The data
  2332. * packets are unloaded from the Rx FIFO in the Host ISR. If necessary,
  2333. * additional data packets are requested in the Host ISR.
  2334. *
  2335. * For a PING transfer in Slave mode, the Do Ping bit is set in the HCTSIZ
  2336. * register along with a packet count of 1 and the channel is enabled. This
  2337. * causes a single PING transaction to occur. Other fields in HCTSIZ are
  2338. * simply set to 0 since no data transfer occurs in this case.
  2339. *
  2340. * For a PING transfer in DMA mode, the HCTSIZ register is initialized with
  2341. * all the information required to perform the subsequent data transfer. In
  2342. * addition, the Do Ping bit is set in the HCTSIZ register. In this case, the
  2343. * controller performs the entire PING protocol, then starts the data
  2344. * transfer.
  2345. *
  2346. * @param core_if Programming view of DWC_otg controller.
  2347. * @param hc Information needed to initialize the host channel. The xfer_len
  2348. * value may be reduced to accommodate the max widths of the XferSize and
  2349. * PktCnt fields in the HCTSIZn register. The multi_count value may be changed
  2350. * to reflect the final xfer_len value.
  2351. */
  2352. void dwc_otg_hc_start_transfer(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  2353. {
  2354. hcchar_data_t hcchar;
  2355. hctsiz_data_t hctsiz;
  2356. uint16_t num_packets;
  2357. uint32_t max_hc_xfer_size = core_if->core_params->max_transfer_size;
  2358. uint16_t max_hc_pkt_count = core_if->core_params->max_packet_count;
  2359. dwc_otg_hc_regs_t *hc_regs = core_if->host_if->hc_regs[hc->hc_num];
  2360. hctsiz.d32 = 0;
  2361. if (hc->do_ping) {
  2362. if (!core_if->dma_enable) {
  2363. dwc_otg_hc_do_ping(core_if, hc);
  2364. hc->xfer_started = 1;
  2365. return;
  2366. } else {
  2367. hctsiz.b.dopng = 1;
  2368. }
  2369. }
  2370. if (hc->do_split) {
  2371. num_packets = 1;
  2372. if (hc->complete_split && !hc->ep_is_in) {
  2373. /* For CSPLIT OUT Transfer, set the size to 0 so the
  2374. * core doesn't expect any data written to the FIFO */
  2375. hc->xfer_len = 0;
  2376. } else if (hc->ep_is_in || (hc->xfer_len > hc->max_packet)) {
  2377. hc->xfer_len = hc->max_packet;
  2378. } else if (!hc->ep_is_in && (hc->xfer_len > 188)) {
  2379. hc->xfer_len = 188;
  2380. }
  2381. hctsiz.b.xfersize = hc->xfer_len;
  2382. } else {
  2383. /*
  2384. * Ensure that the transfer length and packet count will fit
  2385. * in the widths allocated for them in the HCTSIZn register.
  2386. */
  2387. if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  2388. hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  2389. /*
  2390. * Make sure the transfer size is no larger than one
  2391. * (micro)frame's worth of data. (A check was done
  2392. * when the periodic transfer was accepted to ensure
  2393. * that a (micro)frame's worth of data can be
  2394. * programmed into a channel.)
  2395. */
  2396. uint32_t max_periodic_len =
  2397. hc->multi_count * hc->max_packet;
  2398. if (hc->xfer_len > max_periodic_len) {
  2399. hc->xfer_len = max_periodic_len;
  2400. } else {
  2401. }
  2402. } else if (hc->xfer_len > max_hc_xfer_size) {
  2403. /* Make sure that xfer_len is a multiple of max packet size. */
  2404. hc->xfer_len = max_hc_xfer_size - hc->max_packet + 1;
  2405. }
  2406. if (hc->xfer_len > 0) {
  2407. num_packets =
  2408. (hc->xfer_len + hc->max_packet -
  2409. 1) / hc->max_packet;
  2410. if (num_packets > max_hc_pkt_count) {
  2411. num_packets = max_hc_pkt_count;
  2412. hc->xfer_len = num_packets * hc->max_packet;
  2413. }
  2414. } else {
  2415. /* Need 1 packet for transfer length of 0. */
  2416. num_packets = 1;
  2417. }
  2418. if (hc->ep_is_in) {
  2419. /* Always program an integral # of max packets for IN transfers. */
  2420. hc->xfer_len = num_packets * hc->max_packet;
  2421. }
  2422. if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  2423. hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  2424. /*
  2425. * Make sure that the multi_count field matches the
  2426. * actual transfer length.
  2427. */
  2428. hc->multi_count = num_packets;
  2429. }
  2430. if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC)
  2431. set_pid_isoc(hc);
  2432. hctsiz.b.xfersize = hc->xfer_len;
  2433. }
  2434. hc->start_pkt_count = num_packets;
  2435. hctsiz.b.pktcnt = num_packets;
  2436. hctsiz.b.pid = hc->data_pid_start;
  2437. DWC_WRITE_REG32(&hc_regs->hctsiz, hctsiz.d32);
  2438. DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, hc->hc_num);
  2439. DWC_DEBUGPL(DBG_HCDV, " Xfer Size: %d\n", hctsiz.b.xfersize);
  2440. DWC_DEBUGPL(DBG_HCDV, " Num Pkts: %d\n", hctsiz.b.pktcnt);
  2441. DWC_DEBUGPL(DBG_HCDV, " Start PID: %d\n", hctsiz.b.pid);
  2442. if (core_if->dma_enable) {
  2443. dwc_dma_t dma_addr;
  2444. if (hc->align_buff) {
  2445. dma_addr = hc->align_buff;
  2446. } else {
  2447. dma_addr = ((unsigned long)hc->xfer_buff & 0xffffffff);
  2448. }
  2449. DWC_WRITE_REG32(&hc_regs->hcdma, dma_addr);
  2450. }
  2451. /* Start the split */
  2452. if (hc->do_split) {
  2453. hcsplt_data_t hcsplt;
  2454. hcsplt.d32 = DWC_READ_REG32(&hc_regs->hcsplt);
  2455. hcsplt.b.spltena = 1;
  2456. DWC_WRITE_REG32(&hc_regs->hcsplt, hcsplt.d32);
  2457. }
  2458. hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  2459. hcchar.b.multicnt = hc->multi_count;
  2460. hc_set_even_odd_frame(core_if, hc, &hcchar);
  2461. #ifdef DEBUG
  2462. core_if->start_hcchar_val[hc->hc_num] = hcchar.d32;
  2463. if (hcchar.b.chdis) {
  2464. DWC_WARN("%s: chdis set, channel %d, hcchar 0x%08x\n",
  2465. __func__, hc->hc_num, hcchar.d32);
  2466. }
  2467. #endif
  2468. /* Set host channel enable after all other setup is complete. */
  2469. hcchar.b.chen = 1;
  2470. hcchar.b.chdis = 0;
  2471. DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  2472. hc->xfer_started = 1;
  2473. hc->requests++;
  2474. if (!core_if->dma_enable && !hc->ep_is_in && hc->xfer_len > 0) {
  2475. /* Load OUT packet into the appropriate Tx FIFO. */
  2476. dwc_otg_hc_write_packet(core_if, hc);
  2477. }
  2478. #ifdef DEBUG
  2479. if (hc->ep_type != DWC_OTG_EP_TYPE_INTR) {
  2480. core_if->hc_xfer_info[hc->hc_num].core_if = core_if;
  2481. core_if->hc_xfer_info[hc->hc_num].hc = hc;
  2482. /* Start a timer for this transfer. */
  2483. DWC_TIMER_SCHEDULE(core_if->hc_xfer_timer[hc->hc_num], 10000);
  2484. }
  2485. #endif
  2486. }
  2487. /**
  2488. * This function does the setup for a data transfer for a host channel
  2489. * and starts the transfer in Descriptor DMA mode.
  2490. *
  2491. * Initializes HCTSIZ register. For a PING transfer the Do Ping bit is set.
  2492. * Sets PID and NTD values. For periodic transfers
  2493. * initializes SCHED_INFO field with micro-frame bitmap.
  2494. *
  2495. * Initializes HCDMA register with descriptor list address and CTD value
  2496. * then starts the transfer via enabling the channel.
  2497. *
  2498. * @param core_if Programming view of DWC_otg controller.
  2499. * @param hc Information needed to initialize the host channel.
  2500. */
  2501. void dwc_otg_hc_start_transfer_ddma(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  2502. {
  2503. dwc_otg_hc_regs_t *hc_regs = core_if->host_if->hc_regs[hc->hc_num];
  2504. hcchar_data_t hcchar;
  2505. hctsiz_data_t hctsiz;
  2506. hcdma_data_t hcdma;
  2507. hctsiz.d32 = 0;
  2508. if (hc->do_ping)
  2509. hctsiz.b_ddma.dopng = 1;
  2510. if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC)
  2511. set_pid_isoc(hc);
  2512. /* Packet Count and Xfer Size are not used in Descriptor DMA mode */
  2513. hctsiz.b_ddma.pid = hc->data_pid_start;
  2514. hctsiz.b_ddma.ntd = hc->ntd - 1; /* 0 - 1 descriptor, 1 - 2 descriptors, etc. */
  2515. hctsiz.b_ddma.schinfo = hc->schinfo; /* Non-zero only for high-speed interrupt endpoints */
  2516. DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, hc->hc_num);
  2517. DWC_DEBUGPL(DBG_HCDV, " Start PID: %d\n", hctsiz.b.pid);
  2518. DWC_DEBUGPL(DBG_HCDV, " NTD: %d\n", hctsiz.b_ddma.ntd);
  2519. DWC_WRITE_REG32(&hc_regs->hctsiz, hctsiz.d32);
  2520. hcdma.d32 = 0;
  2521. hcdma.b.dma_addr = ((uint32_t) hc->desc_list_addr) >> 11;
  2522. /* Always start from first descriptor. */
  2523. hcdma.b.ctd = 0;
  2524. DWC_WRITE_REG32(&hc_regs->hcdma, hcdma.d32);
  2525. hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  2526. hcchar.b.multicnt = hc->multi_count;
  2527. #ifdef DEBUG
  2528. core_if->start_hcchar_val[hc->hc_num] = hcchar.d32;
  2529. if (hcchar.b.chdis) {
  2530. DWC_WARN("%s: chdis set, channel %d, hcchar 0x%08x\n",
  2531. __func__, hc->hc_num, hcchar.d32);
  2532. }
  2533. #endif
  2534. /* Set host channel enable after all other setup is complete. */
  2535. hcchar.b.chen = 1;
  2536. hcchar.b.chdis = 0;
  2537. DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  2538. DWC_WMB();
  2539. hc->xfer_started = 1;
  2540. hc->requests++;
  2541. #ifdef DEBUG
  2542. if ((hc->ep_type != DWC_OTG_EP_TYPE_INTR)
  2543. && (hc->ep_type != DWC_OTG_EP_TYPE_ISOC)) {
  2544. core_if->hc_xfer_info[hc->hc_num].core_if = core_if;
  2545. core_if->hc_xfer_info[hc->hc_num].hc = hc;
  2546. /* Start a timer for this transfer. */
  2547. DWC_TIMER_SCHEDULE(core_if->hc_xfer_timer[hc->hc_num], 10000);
  2548. }
  2549. #endif
  2550. }
  2551. /**
  2552. * This function continues a data transfer that was started by previous call
  2553. * to <code>dwc_otg_hc_start_transfer</code>. The caller must ensure there is
  2554. * sufficient space in the request queue and Tx Data FIFO. This function
  2555. * should only be called in Slave mode. In DMA mode, the controller acts
  2556. * autonomously to complete transfers programmed to a host channel.
  2557. *
  2558. * For an OUT transfer, a new data packet is loaded into the appropriate FIFO
  2559. * if there is any data remaining to be queued. For an IN transfer, another
  2560. * data packet is always requested. For the SETUP phase of a control transfer,
  2561. * this function does nothing.
  2562. *
  2563. * @return 1 if a new request is queued, 0 if no more requests are required
  2564. * for this transfer.
  2565. */
  2566. int dwc_otg_hc_continue_transfer(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  2567. {
  2568. DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, hc->hc_num);
  2569. if (hc->do_split) {
  2570. /* SPLITs always queue just once per channel */
  2571. return 0;
  2572. } else if (hc->data_pid_start == DWC_OTG_HC_PID_SETUP) {
  2573. /* SETUPs are queued only once since they can't be NAKed. */
  2574. return 0;
  2575. } else if (hc->ep_is_in) {
  2576. /*
  2577. * Always queue another request for other IN transfers. If
  2578. * back-to-back INs are issued and NAKs are received for both,
  2579. * the driver may still be processing the first NAK when the
  2580. * second NAK is received. When the interrupt handler clears
  2581. * the NAK interrupt for the first NAK, the second NAK will
  2582. * not be seen. So we can't depend on the NAK interrupt
  2583. * handler to requeue a NAKed request. Instead, IN requests
  2584. * are issued each time this function is called. When the
  2585. * transfer completes, the extra requests for the channel will
  2586. * be flushed.
  2587. */
  2588. hcchar_data_t hcchar;
  2589. dwc_otg_hc_regs_t *hc_regs =
  2590. core_if->host_if->hc_regs[hc->hc_num];
  2591. hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  2592. hc_set_even_odd_frame(core_if, hc, &hcchar);
  2593. hcchar.b.chen = 1;
  2594. hcchar.b.chdis = 0;
  2595. DWC_DEBUGPL(DBG_HCDV, " IN xfer: hcchar = 0x%08x\n",
  2596. hcchar.d32);
  2597. DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  2598. hc->requests++;
  2599. return 1;
  2600. } else {
  2601. /* OUT transfers. */
  2602. if (hc->xfer_count < hc->xfer_len) {
  2603. if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  2604. hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  2605. hcchar_data_t hcchar;
  2606. dwc_otg_hc_regs_t *hc_regs;
  2607. hc_regs = core_if->host_if->hc_regs[hc->hc_num];
  2608. hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  2609. hc_set_even_odd_frame(core_if, hc, &hcchar);
  2610. }
  2611. /* Load OUT packet into the appropriate Tx FIFO. */
  2612. dwc_otg_hc_write_packet(core_if, hc);
  2613. hc->requests++;
  2614. return 1;
  2615. } else {
  2616. return 0;
  2617. }
  2618. }
  2619. }
  2620. /**
  2621. * Starts a PING transfer. This function should only be called in Slave mode.
  2622. * The Do Ping bit is set in the HCTSIZ register, then the channel is enabled.
  2623. */
  2624. void dwc_otg_hc_do_ping(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  2625. {
  2626. hcchar_data_t hcchar;
  2627. hctsiz_data_t hctsiz;
  2628. dwc_otg_hc_regs_t *hc_regs = core_if->host_if->hc_regs[hc->hc_num];
  2629. DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, hc->hc_num);
  2630. hctsiz.d32 = 0;
  2631. hctsiz.b.dopng = 1;
  2632. hctsiz.b.pktcnt = 1;
  2633. DWC_WRITE_REG32(&hc_regs->hctsiz, hctsiz.d32);
  2634. hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  2635. hcchar.b.chen = 1;
  2636. hcchar.b.chdis = 0;
  2637. DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  2638. }
  2639. /*
  2640. * This function writes a packet into the Tx FIFO associated with the Host
  2641. * Channel. For a channel associated with a non-periodic EP, the non-periodic
  2642. * Tx FIFO is written. For a channel associated with a periodic EP, the
  2643. * periodic Tx FIFO is written. This function should only be called in Slave
  2644. * mode.
  2645. *
  2646. * Upon return the xfer_buff and xfer_count fields in _hc are incremented by
  2647. * then number of bytes written to the Tx FIFO.
  2648. */
  2649. void dwc_otg_hc_write_packet(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  2650. {
  2651. uint32_t i;
  2652. uint32_t remaining_count;
  2653. uint32_t byte_count;
  2654. uint32_t dword_count;
  2655. uint32_t *data_buff = (uint32_t *) (hc->xfer_buff);
  2656. uint32_t *data_fifo = core_if->data_fifo[hc->hc_num];
  2657. remaining_count = hc->xfer_len - hc->xfer_count;
  2658. if (remaining_count > hc->max_packet) {
  2659. byte_count = hc->max_packet;
  2660. } else {
  2661. byte_count = remaining_count;
  2662. }
  2663. dword_count = (byte_count + 3) / 4;
  2664. if ((((unsigned long)data_buff) & 0x3) == 0) {
  2665. /* xfer_buff is DWORD aligned. */
  2666. for (i = 0; i < dword_count; i++, data_buff++) {
  2667. DWC_WRITE_REG32(data_fifo, *data_buff);
  2668. }
  2669. } else {
  2670. /* xfer_buff is not DWORD aligned. */
  2671. for (i = 0; i < dword_count; i++, data_buff++) {
  2672. uint32_t data;
  2673. data =
  2674. (data_buff[0] | data_buff[1] << 8 | data_buff[2] <<
  2675. 16 | data_buff[3] << 24);
  2676. DWC_WRITE_REG32(data_fifo, data);
  2677. }
  2678. }
  2679. hc->xfer_count += byte_count;
  2680. hc->xfer_buff += byte_count;
  2681. }
  2682. /**
  2683. * Gets the current USB frame number. This is the frame number from the last
  2684. * SOF packet.
  2685. */
  2686. uint32_t dwc_otg_get_frame_number(dwc_otg_core_if_t * core_if)
  2687. {
  2688. dsts_data_t dsts;
  2689. dsts.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  2690. /* read current frame/microframe number from DSTS register */
  2691. return dsts.b.soffn;
  2692. }
  2693. /**
  2694. * Calculates and gets the frame Interval value of HFIR register according PHY
  2695. * type and speed.The application can modify a value of HFIR register only after
  2696. * the Port Enable bit of the Host Port Control and Status register
  2697. * (HPRT.PrtEnaPort) has been set.
  2698. */
  2699. uint32_t calc_frame_interval(dwc_otg_core_if_t * core_if)
  2700. {
  2701. gusbcfg_data_t usbcfg;
  2702. hwcfg2_data_t hwcfg2;
  2703. hprt0_data_t hprt0;
  2704. int clock = 60; // default value
  2705. usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  2706. hwcfg2.d32 = DWC_READ_REG32(&core_if->core_global_regs->ghwcfg2);
  2707. hprt0.d32 = DWC_READ_REG32(core_if->host_if->hprt0);
  2708. if (!usbcfg.b.physel && usbcfg.b.ulpi_utmi_sel && !usbcfg.b.phyif)
  2709. clock = 60;
  2710. if (usbcfg.b.physel && hwcfg2.b.fs_phy_type == 3)
  2711. clock = 48;
  2712. if (!usbcfg.b.phylpwrclksel && !usbcfg.b.physel &&
  2713. !usbcfg.b.ulpi_utmi_sel && usbcfg.b.phyif)
  2714. clock = 30;
  2715. if (!usbcfg.b.phylpwrclksel && !usbcfg.b.physel &&
  2716. !usbcfg.b.ulpi_utmi_sel && !usbcfg.b.phyif)
  2717. clock = 60;
  2718. if (usbcfg.b.phylpwrclksel && !usbcfg.b.physel &&
  2719. !usbcfg.b.ulpi_utmi_sel && usbcfg.b.phyif)
  2720. clock = 48;
  2721. if (usbcfg.b.physel && !usbcfg.b.phyif && hwcfg2.b.fs_phy_type == 2)
  2722. clock = 48;
  2723. if (usbcfg.b.physel && hwcfg2.b.fs_phy_type == 1)
  2724. clock = 48;
  2725. if (hprt0.b.prtspd == 0)
  2726. /* High speed case */
  2727. return 125 * clock;
  2728. else
  2729. /* FS/LS case */
  2730. return 1000 * clock;
  2731. }
  2732. /**
  2733. * This function reads a setup packet from the Rx FIFO into the destination
  2734. * buffer. This function is called from the Rx Status Queue Level (RxStsQLvl)
  2735. * Interrupt routine when a SETUP packet has been received in Slave mode.
  2736. *
  2737. * @param core_if Programming view of DWC_otg controller.
  2738. * @param dest Destination buffer for packet data.
  2739. */
  2740. void dwc_otg_read_setup_packet(dwc_otg_core_if_t * core_if, uint32_t * dest)
  2741. {
  2742. /* Get the 8 bytes of a setup transaction data */
  2743. /* Pop 2 DWORDS off the receive data FIFO into memory */
  2744. dest[0] = DWC_READ_REG32(core_if->data_fifo[0]);
  2745. dest[1] = DWC_READ_REG32(core_if->data_fifo[0]);
  2746. }
  2747. /**
  2748. * This function enables EP0 OUT to receive SETUP packets and configures EP0
  2749. * IN for transmitting packets. It is normally called when the
  2750. * "Enumeration Done" interrupt occurs.
  2751. *
  2752. * @param core_if Programming view of DWC_otg controller.
  2753. * @param ep The EP0 data.
  2754. */
  2755. void dwc_otg_ep0_activate(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  2756. {
  2757. dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  2758. dsts_data_t dsts;
  2759. depctl_data_t diepctl;
  2760. depctl_data_t doepctl;
  2761. dctl_data_t dctl = {.d32 = 0 };
  2762. /* Read the Device Status and Endpoint 0 Control registers */
  2763. dsts.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dsts);
  2764. diepctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[0]->diepctl);
  2765. doepctl.d32 = DWC_READ_REG32(&dev_if->out_ep_regs[0]->doepctl);
  2766. /* Set the MPS of the IN EP based on the enumeration speed */
  2767. switch (dsts.b.enumspd) {
  2768. case DWC_DSTS_ENUMSPD_HS_PHY_30MHZ_OR_60MHZ:
  2769. case DWC_DSTS_ENUMSPD_FS_PHY_30MHZ_OR_60MHZ:
  2770. case DWC_DSTS_ENUMSPD_FS_PHY_48MHZ:
  2771. diepctl.b.mps = DWC_DEP0CTL_MPS_64;
  2772. break;
  2773. case DWC_DSTS_ENUMSPD_LS_PHY_6MHZ:
  2774. diepctl.b.mps = DWC_DEP0CTL_MPS_8;
  2775. break;
  2776. }
  2777. DWC_WRITE_REG32(&dev_if->in_ep_regs[0]->diepctl, diepctl.d32);
  2778. /* Enable OUT EP for receive */
  2779. doepctl.b.epena = 1;
  2780. DWC_WRITE_REG32(&dev_if->out_ep_regs[0]->doepctl, doepctl.d32);
  2781. #ifdef VERBOSE
  2782. DWC_DEBUGPL(DBG_PCDV, "doepctl0=%0x\n",
  2783. DWC_READ_REG32(&dev_if->out_ep_regs[0]->doepctl));
  2784. DWC_DEBUGPL(DBG_PCDV, "diepctl0=%0x\n",
  2785. DWC_READ_REG32(&dev_if->in_ep_regs[0]->diepctl));
  2786. #endif
  2787. dctl.b.cgnpinnak = 1;
  2788. DWC_MODIFY_REG32(&dev_if->dev_global_regs->dctl, dctl.d32, dctl.d32);
  2789. DWC_DEBUGPL(DBG_PCDV, "dctl=%0x\n",
  2790. DWC_READ_REG32(&dev_if->dev_global_regs->dctl));
  2791. }
  2792. /**
  2793. * This function activates an EP. The Device EP control register for
  2794. * the EP is configured as defined in the ep structure. Note: This
  2795. * function is not used for EP0.
  2796. *
  2797. * @param core_if Programming view of DWC_otg controller.
  2798. * @param ep The EP to activate.
  2799. */
  2800. void dwc_otg_ep_activate(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  2801. {
  2802. dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  2803. depctl_data_t depctl;
  2804. volatile uint32_t *addr;
  2805. daint_data_t daintmsk = {.d32 = 0 };
  2806. dcfg_data_t dcfg;
  2807. uint8_t i;
  2808. DWC_DEBUGPL(DBG_PCDV, "%s() EP%d-%s\n", __func__, ep->num,
  2809. (ep->is_in ? "IN" : "OUT"));
  2810. #ifdef DWC_UTE_PER_IO
  2811. ep->xiso_frame_num = 0xFFFFFFFF;
  2812. ep->xiso_active_xfers = 0;
  2813. ep->xiso_queued_xfers = 0;
  2814. #endif
  2815. /* Read DEPCTLn register */
  2816. if (ep->is_in == 1) {
  2817. addr = &dev_if->in_ep_regs[ep->num]->diepctl;
  2818. daintmsk.ep.in = 1 << ep->num;
  2819. } else {
  2820. addr = &dev_if->out_ep_regs[ep->num]->doepctl;
  2821. daintmsk.ep.out = 1 << ep->num;
  2822. }
  2823. /* If the EP is already active don't change the EP Control
  2824. * register. */
  2825. depctl.d32 = DWC_READ_REG32(addr);
  2826. if (!depctl.b.usbactep) {
  2827. depctl.b.mps = ep->maxpacket;
  2828. depctl.b.eptype = ep->type;
  2829. depctl.b.txfnum = ep->tx_fifo_num;
  2830. if (ep->type == DWC_OTG_EP_TYPE_ISOC) {
  2831. depctl.b.setd0pid = 1; // ???
  2832. } else {
  2833. depctl.b.setd0pid = 1;
  2834. }
  2835. depctl.b.usbactep = 1;
  2836. /* Update nextep_seq array and EPMSCNT in DCFG*/
  2837. if (!(depctl.b.eptype & 1) && (ep->is_in == 1)) { // NP IN EP
  2838. for (i = 0; i <= core_if->dev_if->num_in_eps; i++) {
  2839. if (core_if->nextep_seq[i] == core_if->first_in_nextep_seq)
  2840. break;
  2841. }
  2842. core_if->nextep_seq[i] = ep->num;
  2843. core_if->nextep_seq[ep->num] = core_if->first_in_nextep_seq;
  2844. depctl.b.nextep = core_if->nextep_seq[ep->num];
  2845. dcfg.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dcfg);
  2846. dcfg.b.epmscnt++;
  2847. DWC_WRITE_REG32(&dev_if->dev_global_regs->dcfg, dcfg.d32);
  2848. DWC_DEBUGPL(DBG_PCDV,"%s first_in_nextep_seq= %2d; nextep_seq[]:\n",
  2849. __func__, core_if->first_in_nextep_seq);
  2850. for (i=0; i <= core_if->dev_if->num_in_eps; i++) {
  2851. DWC_DEBUGPL(DBG_PCDV, "%2d\n", core_if->nextep_seq[i]);
  2852. }
  2853. }
  2854. DWC_WRITE_REG32(addr, depctl.d32);
  2855. DWC_DEBUGPL(DBG_PCDV, "DEPCTL=%08x\n", DWC_READ_REG32(addr));
  2856. }
  2857. /* Enable the Interrupt for this EP */
  2858. if (core_if->multiproc_int_enable) {
  2859. if (ep->is_in == 1) {
  2860. diepmsk_data_t diepmsk = {.d32 = 0 };
  2861. diepmsk.b.xfercompl = 1;
  2862. diepmsk.b.timeout = 1;
  2863. diepmsk.b.epdisabled = 1;
  2864. diepmsk.b.ahberr = 1;
  2865. diepmsk.b.intknepmis = 1;
  2866. if (!core_if->en_multiple_tx_fifo && core_if->dma_enable)
  2867. diepmsk.b.intknepmis = 0;
  2868. diepmsk.b.txfifoundrn = 1; //?????
  2869. if (ep->type == DWC_OTG_EP_TYPE_ISOC) {
  2870. diepmsk.b.nak = 1;
  2871. }
  2872. /*
  2873. if (core_if->dma_desc_enable) {
  2874. diepmsk.b.bna = 1;
  2875. }
  2876. */
  2877. /*
  2878. if (core_if->dma_enable) {
  2879. doepmsk.b.nak = 1;
  2880. }
  2881. */
  2882. DWC_WRITE_REG32(&dev_if->dev_global_regs->
  2883. diepeachintmsk[ep->num], diepmsk.d32);
  2884. } else {
  2885. doepmsk_data_t doepmsk = {.d32 = 0 };
  2886. doepmsk.b.xfercompl = 1;
  2887. doepmsk.b.ahberr = 1;
  2888. doepmsk.b.epdisabled = 1;
  2889. if (ep->type == DWC_OTG_EP_TYPE_ISOC)
  2890. doepmsk.b.outtknepdis = 1;
  2891. /*
  2892. if (core_if->dma_desc_enable) {
  2893. doepmsk.b.bna = 1;
  2894. }
  2895. */
  2896. /*
  2897. doepmsk.b.babble = 1;
  2898. doepmsk.b.nyet = 1;
  2899. doepmsk.b.nak = 1;
  2900. */
  2901. DWC_WRITE_REG32(&dev_if->dev_global_regs->
  2902. doepeachintmsk[ep->num], doepmsk.d32);
  2903. }
  2904. DWC_MODIFY_REG32(&dev_if->dev_global_regs->deachintmsk,
  2905. 0, daintmsk.d32);
  2906. } else {
  2907. if (ep->type == DWC_OTG_EP_TYPE_ISOC) {
  2908. if (ep->is_in)
  2909. {
  2910. diepmsk_data_t diepmsk = {.d32 = 0 };
  2911. diepmsk.b.nak = 1;
  2912. DWC_MODIFY_REG32(&dev_if->dev_global_regs->diepmsk, 0, diepmsk.d32);
  2913. } else {
  2914. doepmsk_data_t doepmsk = {.d32 = 0 };
  2915. doepmsk.b.outtknepdis = 1;
  2916. DWC_MODIFY_REG32(&dev_if->dev_global_regs->doepmsk, 0, doepmsk.d32);
  2917. }
  2918. }
  2919. DWC_MODIFY_REG32(&dev_if->dev_global_regs->daintmsk,
  2920. 0, daintmsk.d32);
  2921. }
  2922. DWC_DEBUGPL(DBG_PCDV, "DAINTMSK=%0x\n",
  2923. DWC_READ_REG32(&dev_if->dev_global_regs->daintmsk));
  2924. ep->stall_clear_flag = 0;
  2925. return;
  2926. }
  2927. /**
  2928. * This function deactivates an EP. This is done by clearing the USB Active
  2929. * EP bit in the Device EP control register. Note: This function is not used
  2930. * for EP0. EP0 cannot be deactivated.
  2931. *
  2932. * @param core_if Programming view of DWC_otg controller.
  2933. * @param ep The EP to deactivate.
  2934. */
  2935. void dwc_otg_ep_deactivate(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  2936. {
  2937. depctl_data_t depctl = {.d32 = 0 };
  2938. volatile uint32_t *addr;
  2939. daint_data_t daintmsk = {.d32 = 0 };
  2940. dcfg_data_t dcfg;
  2941. uint8_t i = 0;
  2942. #ifdef DWC_UTE_PER_IO
  2943. ep->xiso_frame_num = 0xFFFFFFFF;
  2944. ep->xiso_active_xfers = 0;
  2945. ep->xiso_queued_xfers = 0;
  2946. #endif
  2947. /* Read DEPCTLn register */
  2948. if (ep->is_in == 1) {
  2949. addr = &core_if->dev_if->in_ep_regs[ep->num]->diepctl;
  2950. daintmsk.ep.in = 1 << ep->num;
  2951. } else {
  2952. addr = &core_if->dev_if->out_ep_regs[ep->num]->doepctl;
  2953. daintmsk.ep.out = 1 << ep->num;
  2954. }
  2955. depctl.d32 = DWC_READ_REG32(addr);
  2956. depctl.b.usbactep = 0;
  2957. /* Update nextep_seq array and EPMSCNT in DCFG*/
  2958. if (!(depctl.b.eptype & 1) && ep->is_in == 1) { // NP EP IN
  2959. for (i = 0; i <= core_if->dev_if->num_in_eps; i++) {
  2960. if (core_if->nextep_seq[i] == ep->num)
  2961. break;
  2962. }
  2963. core_if->nextep_seq[i] = core_if->nextep_seq[ep->num];
  2964. if (core_if->first_in_nextep_seq == ep->num)
  2965. core_if->first_in_nextep_seq = i;
  2966. core_if->nextep_seq[ep->num] = 0xff;
  2967. depctl.b.nextep = 0;
  2968. dcfg.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  2969. dcfg.b.epmscnt--;
  2970. DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg, dcfg.d32);
  2971. DWC_DEBUGPL(DBG_PCDV,"%s first_in_nextep_seq= %2d; nextep_seq[]:\n",
  2972. __func__, core_if->first_in_nextep_seq);
  2973. for (i=0; i <= core_if->dev_if->num_in_eps; i++) {
  2974. DWC_DEBUGPL(DBG_PCDV, "%2d\n", core_if->nextep_seq[i]);
  2975. }
  2976. }
  2977. if (ep->is_in == 1)
  2978. depctl.b.txfnum = 0;
  2979. if (core_if->dma_desc_enable)
  2980. depctl.b.epdis = 1;
  2981. DWC_WRITE_REG32(addr, depctl.d32);
  2982. depctl.d32 = DWC_READ_REG32(addr);
  2983. if (core_if->dma_enable && ep->type == DWC_OTG_EP_TYPE_ISOC && depctl.b.epena)
  2984. {
  2985. depctl_data_t depctl = {.d32 = 0};
  2986. if (ep->is_in)
  2987. {
  2988. diepint_data_t diepint = {.d32 = 0};
  2989. depctl.b.snak = 1;
  2990. DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[ep->num]->diepctl, depctl.d32);
  2991. do
  2992. {
  2993. dwc_udelay(10);
  2994. diepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  2995. in_ep_regs[ep->num]->diepint);
  2996. } while (!diepint.b.inepnakeff);
  2997. diepint.b.inepnakeff = 1;
  2998. DWC_WRITE_REG32(&core_if->dev_if->
  2999. in_ep_regs[ep->num]->diepint, diepint.d32);
  3000. depctl.d32 = 0;
  3001. depctl.b.epdis = 1;
  3002. DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[ep->num]->diepctl, depctl.d32);
  3003. do
  3004. {
  3005. dwc_udelay(10);
  3006. diepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  3007. in_ep_regs[ep->num]->diepint);
  3008. } while (!diepint.b.epdisabled);
  3009. diepint.b.epdisabled = 1;
  3010. DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[ep->num]->diepint, diepint.d32);
  3011. } else {
  3012. dctl_data_t dctl = {.d32 = 0};
  3013. gintmsk_data_t gintsts = {.d32 = 0};
  3014. doepint_data_t doepint = {.d32 = 0};
  3015. dctl.b.sgoutnak = 1;
  3016. DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0, dctl.d32);
  3017. do
  3018. {
  3019. dwc_udelay(10);
  3020. gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  3021. } while (!gintsts.b.goutnakeff);
  3022. gintsts.d32 = 0;
  3023. gintsts.b.goutnakeff = 1;
  3024. DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  3025. depctl.d32 = 0;
  3026. depctl.b.epdis = 1;
  3027. depctl.b.snak = 1;
  3028. DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[ep->num]->doepctl, depctl.d32);
  3029. do
  3030. {
  3031. dwc_udelay(10);
  3032. doepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  3033. out_ep_regs[ep->num]->doepint);
  3034. } while (!doepint.b.epdisabled);
  3035. doepint.b.epdisabled = 1;
  3036. DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[ep->num]->doepint, doepint.d32);
  3037. dctl.d32 = 0;
  3038. dctl.b.cgoutnak = 1;
  3039. DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0, dctl.d32);
  3040. }
  3041. }
  3042. /* Disable the Interrupt for this EP */
  3043. if (core_if->multiproc_int_enable) {
  3044. DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->deachintmsk,
  3045. daintmsk.d32, 0);
  3046. if (ep->is_in == 1) {
  3047. DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->
  3048. diepeachintmsk[ep->num], 0);
  3049. } else {
  3050. DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->
  3051. doepeachintmsk[ep->num], 0);
  3052. }
  3053. } else {
  3054. DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->daintmsk,
  3055. daintmsk.d32, 0);
  3056. }
  3057. }
  3058. /**
  3059. * This function initializes dma descriptor chain.
  3060. *
  3061. * @param core_if Programming view of DWC_otg controller.
  3062. * @param ep The EP to start the transfer on.
  3063. */
  3064. static void init_dma_desc_chain(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  3065. {
  3066. dwc_otg_dev_dma_desc_t *dma_desc;
  3067. uint32_t offset;
  3068. uint32_t xfer_est;
  3069. int i;
  3070. unsigned maxxfer_local, total_len;
  3071. if (!ep->is_in && ep->type == DWC_OTG_EP_TYPE_INTR &&
  3072. (ep->maxpacket%4)) {
  3073. maxxfer_local = ep->maxpacket;
  3074. total_len = ep->xfer_len;
  3075. } else {
  3076. maxxfer_local = ep->maxxfer;
  3077. total_len = ep->total_len;
  3078. }
  3079. ep->desc_cnt = (total_len / maxxfer_local) +
  3080. ((total_len % maxxfer_local) ? 1 : 0);
  3081. if (!ep->desc_cnt)
  3082. ep->desc_cnt = 1;
  3083. if (ep->desc_cnt > MAX_DMA_DESC_CNT)
  3084. ep->desc_cnt = MAX_DMA_DESC_CNT;
  3085. dma_desc = ep->desc_addr;
  3086. if (maxxfer_local == ep->maxpacket) {
  3087. if ((total_len % maxxfer_local) &&
  3088. (total_len/maxxfer_local < MAX_DMA_DESC_CNT)) {
  3089. xfer_est = (ep->desc_cnt - 1) * maxxfer_local +
  3090. (total_len % maxxfer_local);
  3091. } else
  3092. xfer_est = ep->desc_cnt * maxxfer_local;
  3093. }
  3094. else
  3095. xfer_est = total_len;
  3096. offset = 0;
  3097. for (i = 0; i < ep->desc_cnt; ++i) {
  3098. /** DMA Descriptor Setup */
  3099. if (xfer_est > maxxfer_local) {
  3100. dma_desc->status.b.bs = BS_HOST_BUSY;
  3101. dma_desc->status.b.l = 0;
  3102. dma_desc->status.b.ioc = 0;
  3103. dma_desc->status.b.sp = 0;
  3104. dma_desc->status.b.bytes = maxxfer_local;
  3105. dma_desc->buf = ep->dma_addr + offset;
  3106. dma_desc->status.b.sts = 0;
  3107. dma_desc->status.b.bs = BS_HOST_READY;
  3108. xfer_est -= maxxfer_local;
  3109. offset += maxxfer_local;
  3110. } else {
  3111. dma_desc->status.b.bs = BS_HOST_BUSY;
  3112. dma_desc->status.b.l = 1;
  3113. dma_desc->status.b.ioc = 1;
  3114. if (ep->is_in) {
  3115. dma_desc->status.b.sp =
  3116. (xfer_est %
  3117. ep->maxpacket) ? 1 : ((ep->
  3118. sent_zlp) ? 1 : 0);
  3119. dma_desc->status.b.bytes = xfer_est;
  3120. } else {
  3121. if (maxxfer_local == ep->maxpacket)
  3122. dma_desc->status.b.bytes = xfer_est;
  3123. else
  3124. dma_desc->status.b.bytes =
  3125. xfer_est + ((4 - (xfer_est & 0x3)) & 0x3);
  3126. }
  3127. dma_desc->buf = ep->dma_addr + offset;
  3128. dma_desc->status.b.sts = 0;
  3129. dma_desc->status.b.bs = BS_HOST_READY;
  3130. }
  3131. dma_desc++;
  3132. }
  3133. }
  3134. /**
  3135. * This function is called when to write ISOC data into appropriate dedicated
  3136. * periodic FIFO.
  3137. */
  3138. static int32_t write_isoc_tx_fifo(dwc_otg_core_if_t * core_if, dwc_ep_t * dwc_ep)
  3139. {
  3140. dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  3141. dwc_otg_dev_in_ep_regs_t *ep_regs;
  3142. dtxfsts_data_t txstatus = {.d32 = 0 };
  3143. uint32_t len = 0;
  3144. int epnum = dwc_ep->num;
  3145. int dwords;
  3146. DWC_DEBUGPL(DBG_PCD, "Dedicated TxFifo Empty: %d \n", epnum);
  3147. ep_regs = core_if->dev_if->in_ep_regs[epnum];
  3148. len = dwc_ep->xfer_len - dwc_ep->xfer_count;
  3149. if (len > dwc_ep->maxpacket) {
  3150. len = dwc_ep->maxpacket;
  3151. }
  3152. dwords = (len + 3) / 4;
  3153. /* While there is space in the queue and space in the FIFO and
  3154. * More data to tranfer, Write packets to the Tx FIFO */
  3155. txstatus.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dtxfsts);
  3156. DWC_DEBUGPL(DBG_PCDV, "b4 dtxfsts[%d]=0x%08x\n", epnum, txstatus.d32);
  3157. while (txstatus.b.txfspcavail > dwords &&
  3158. dwc_ep->xfer_count < dwc_ep->xfer_len &&
  3159. dwc_ep->xfer_len != 0) {
  3160. /* Write the FIFO */
  3161. dwc_otg_ep_write_packet(core_if, dwc_ep, 0);
  3162. len = dwc_ep->xfer_len - dwc_ep->xfer_count;
  3163. if (len > dwc_ep->maxpacket) {
  3164. len = dwc_ep->maxpacket;
  3165. }
  3166. dwords = (len + 3) / 4;
  3167. txstatus.d32 =
  3168. DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dtxfsts);
  3169. DWC_DEBUGPL(DBG_PCDV, "dtxfsts[%d]=0x%08x\n", epnum,
  3170. txstatus.d32);
  3171. }
  3172. DWC_DEBUGPL(DBG_PCDV, "b4 dtxfsts[%d]=0x%08x\n", epnum,
  3173. DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dtxfsts));
  3174. return 1;
  3175. }
  3176. /**
  3177. * This function does the setup for a data transfer for an EP and
  3178. * starts the transfer. For an IN transfer, the packets will be
  3179. * loaded into the appropriate Tx FIFO in the ISR. For OUT transfers,
  3180. * the packets are unloaded from the Rx FIFO in the ISR. the ISR.
  3181. *
  3182. * @param core_if Programming view of DWC_otg controller.
  3183. * @param ep The EP to start the transfer on.
  3184. */
  3185. void dwc_otg_ep_start_transfer(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  3186. {
  3187. depctl_data_t depctl;
  3188. deptsiz_data_t deptsiz;
  3189. gintmsk_data_t intr_mask = {.d32 = 0 };
  3190. DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "%s()\n", __func__);
  3191. DWC_DEBUGPL(DBG_PCD, "ep%d-%s xfer_len=%d xfer_cnt=%d "
  3192. "xfer_buff=%p start_xfer_buff=%p, total_len = %d\n",
  3193. ep->num, (ep->is_in ? "IN" : "OUT"), ep->xfer_len,
  3194. ep->xfer_count, ep->xfer_buff, ep->start_xfer_buff,
  3195. ep->total_len);
  3196. /* IN endpoint */
  3197. if (ep->is_in == 1) {
  3198. dwc_otg_dev_in_ep_regs_t *in_regs =
  3199. core_if->dev_if->in_ep_regs[ep->num];
  3200. gnptxsts_data_t gtxstatus;
  3201. gtxstatus.d32 =
  3202. DWC_READ_REG32(&core_if->core_global_regs->gnptxsts);
  3203. if (core_if->en_multiple_tx_fifo == 0
  3204. && gtxstatus.b.nptxqspcavail == 0
  3205. && !core_if->dma_enable) {
  3206. #ifdef DEBUG
  3207. DWC_PRINTF("TX Queue Full (0x%0x)\n", gtxstatus.d32);
  3208. #endif
  3209. return;
  3210. }
  3211. depctl.d32 = DWC_READ_REG32(&(in_regs->diepctl));
  3212. deptsiz.d32 = DWC_READ_REG32(&(in_regs->dieptsiz));
  3213. if (ep->maxpacket > ep->maxxfer / MAX_PKT_CNT)
  3214. ep->xfer_len += (ep->maxxfer < (ep->total_len - ep->xfer_len)) ?
  3215. ep->maxxfer : (ep->total_len - ep->xfer_len);
  3216. else
  3217. ep->xfer_len += (MAX_PKT_CNT * ep->maxpacket < (ep->total_len - ep->xfer_len)) ?
  3218. MAX_PKT_CNT * ep->maxpacket : (ep->total_len - ep->xfer_len);
  3219. /* Zero Length Packet? */
  3220. if ((ep->xfer_len - ep->xfer_count) == 0) {
  3221. deptsiz.b.xfersize = 0;
  3222. deptsiz.b.pktcnt = 1;
  3223. } else {
  3224. /* Program the transfer size and packet count
  3225. * as follows: xfersize = N * maxpacket +
  3226. * short_packet pktcnt = N + (short_packet
  3227. * exist ? 1 : 0)
  3228. */
  3229. deptsiz.b.xfersize = ep->xfer_len - ep->xfer_count;
  3230. deptsiz.b.pktcnt =
  3231. (ep->xfer_len - ep->xfer_count - 1 +
  3232. ep->maxpacket) / ep->maxpacket;
  3233. if (deptsiz.b.pktcnt > MAX_PKT_CNT) {
  3234. deptsiz.b.pktcnt = MAX_PKT_CNT;
  3235. deptsiz.b.xfersize = deptsiz.b.pktcnt * ep->maxpacket;
  3236. }
  3237. if (ep->type == DWC_OTG_EP_TYPE_ISOC)
  3238. deptsiz.b.mc = deptsiz.b.pktcnt;
  3239. }
  3240. /* Write the DMA register */
  3241. if (core_if->dma_enable) {
  3242. if (core_if->dma_desc_enable == 0) {
  3243. if (ep->type != DWC_OTG_EP_TYPE_ISOC)
  3244. deptsiz.b.mc = 1;
  3245. DWC_WRITE_REG32(&in_regs->dieptsiz,
  3246. deptsiz.d32);
  3247. DWC_WRITE_REG32(&(in_regs->diepdma),
  3248. (uint32_t) ep->dma_addr);
  3249. } else {
  3250. #ifdef DWC_UTE_CFI
  3251. /* The descriptor chain should be already initialized by now */
  3252. if (ep->buff_mode != BM_STANDARD) {
  3253. DWC_WRITE_REG32(&in_regs->diepdma,
  3254. ep->descs_dma_addr);
  3255. } else {
  3256. #endif
  3257. init_dma_desc_chain(core_if, ep);
  3258. /** DIEPDMAn Register write */
  3259. DWC_WRITE_REG32(&in_regs->diepdma,
  3260. ep->dma_desc_addr);
  3261. #ifdef DWC_UTE_CFI
  3262. }
  3263. #endif
  3264. }
  3265. } else {
  3266. DWC_WRITE_REG32(&in_regs->dieptsiz, deptsiz.d32);
  3267. if (ep->type != DWC_OTG_EP_TYPE_ISOC) {
  3268. /**
  3269. * Enable the Non-Periodic Tx FIFO empty interrupt,
  3270. * or the Tx FIFO epmty interrupt in dedicated Tx FIFO mode,
  3271. * the data will be written into the fifo by the ISR.
  3272. */
  3273. if (core_if->en_multiple_tx_fifo == 0) {
  3274. intr_mask.b.nptxfempty = 1;
  3275. DWC_MODIFY_REG32
  3276. (&core_if->core_global_regs->gintmsk,
  3277. intr_mask.d32, intr_mask.d32);
  3278. } else {
  3279. /* Enable the Tx FIFO Empty Interrupt for this EP */
  3280. if (ep->xfer_len > 0) {
  3281. uint32_t fifoemptymsk = 0;
  3282. fifoemptymsk = 1 << ep->num;
  3283. DWC_MODIFY_REG32
  3284. (&core_if->dev_if->dev_global_regs->dtknqr4_fifoemptymsk,
  3285. 0, fifoemptymsk);
  3286. }
  3287. }
  3288. } else {
  3289. write_isoc_tx_fifo(core_if, ep);
  3290. }
  3291. }
  3292. if (!core_if->core_params->en_multiple_tx_fifo && core_if->dma_enable)
  3293. depctl.b.nextep = core_if->nextep_seq[ep->num];
  3294. if (ep->type == DWC_OTG_EP_TYPE_ISOC)
  3295. {
  3296. dsts_data_t dsts = {.d32 = 0};
  3297. if (ep->bInterval == 1) {
  3298. dsts.d32 =
  3299. DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  3300. ep->frame_num = dsts.b.soffn + ep->bInterval;
  3301. if (ep->frame_num > 0x3FFF)
  3302. {
  3303. ep->frm_overrun = 1;
  3304. ep->frame_num &= 0x3FFF;
  3305. } else
  3306. ep->frm_overrun = 0;
  3307. if (ep->frame_num & 0x1) {
  3308. depctl.b.setd1pid = 1;
  3309. } else {
  3310. depctl.b.setd0pid = 1;
  3311. }
  3312. }
  3313. }
  3314. /* EP enable, IN data in FIFO */
  3315. depctl.b.cnak = 1;
  3316. depctl.b.epena = 1;
  3317. DWC_WRITE_REG32(&in_regs->diepctl, depctl.d32);
  3318. DWC_WMB();
  3319. } else {
  3320. /* OUT endpoint */
  3321. dwc_otg_dev_out_ep_regs_t *out_regs =
  3322. core_if->dev_if->out_ep_regs[ep->num];
  3323. depctl.d32 = DWC_READ_REG32(&(out_regs->doepctl));
  3324. deptsiz.d32 = DWC_READ_REG32(&(out_regs->doeptsiz));
  3325. if (!core_if->dma_desc_enable) {
  3326. if (ep->maxpacket > ep->maxxfer / MAX_PKT_CNT)
  3327. ep->xfer_len += (ep->maxxfer < (ep->total_len - ep->xfer_len)) ?
  3328. ep->maxxfer : (ep->total_len - ep->xfer_len);
  3329. else
  3330. ep->xfer_len += (MAX_PKT_CNT * ep->maxpacket < (ep->total_len
  3331. - ep->xfer_len)) ? MAX_PKT_CNT * ep->maxpacket : (ep->total_len - ep->xfer_len);
  3332. }
  3333. /* Program the transfer size and packet count as follows:
  3334. *
  3335. * pktcnt = N
  3336. * xfersize = N * maxpacket
  3337. */
  3338. if ((ep->xfer_len - ep->xfer_count) == 0) {
  3339. /* Zero Length Packet */
  3340. deptsiz.b.xfersize = ep->maxpacket;
  3341. deptsiz.b.pktcnt = 1;
  3342. } else {
  3343. deptsiz.b.pktcnt =
  3344. (ep->xfer_len - ep->xfer_count +
  3345. (ep->maxpacket - 1)) / ep->maxpacket;
  3346. if (deptsiz.b.pktcnt > MAX_PKT_CNT) {
  3347. deptsiz.b.pktcnt = MAX_PKT_CNT;
  3348. }
  3349. if (!core_if->dma_desc_enable) {
  3350. ep->xfer_len =
  3351. deptsiz.b.pktcnt * ep->maxpacket + ep->xfer_count;
  3352. }
  3353. deptsiz.b.xfersize = ep->xfer_len - ep->xfer_count;
  3354. }
  3355. DWC_DEBUGPL(DBG_PCDV, "ep%d xfersize=%d pktcnt=%d\n",
  3356. ep->num, deptsiz.b.xfersize, deptsiz.b.pktcnt);
  3357. if (core_if->dma_enable) {
  3358. if (!core_if->dma_desc_enable) {
  3359. DWC_WRITE_REG32(&out_regs->doeptsiz,
  3360. deptsiz.d32);
  3361. DWC_WRITE_REG32(&(out_regs->doepdma),
  3362. (uint32_t) ep->dma_addr);
  3363. } else {
  3364. #ifdef DWC_UTE_CFI
  3365. /* The descriptor chain should be already initialized by now */
  3366. if (ep->buff_mode != BM_STANDARD) {
  3367. DWC_WRITE_REG32(&out_regs->doepdma,
  3368. ep->descs_dma_addr);
  3369. } else {
  3370. #endif
  3371. /** This is used for interrupt out transfers*/
  3372. if (!ep->xfer_len)
  3373. ep->xfer_len = ep->total_len;
  3374. init_dma_desc_chain(core_if, ep);
  3375. if (core_if->core_params->dev_out_nak) {
  3376. if (ep->type == DWC_OTG_EP_TYPE_BULK) {
  3377. deptsiz.b.pktcnt = (ep->total_len +
  3378. (ep->maxpacket - 1)) / ep->maxpacket;
  3379. deptsiz.b.xfersize = ep->total_len;
  3380. /* Remember initial value of doeptsiz */
  3381. core_if->start_doeptsiz_val[ep->num] = deptsiz.d32;
  3382. DWC_WRITE_REG32(&out_regs->doeptsiz,
  3383. deptsiz.d32);
  3384. }
  3385. }
  3386. /** DOEPDMAn Register write */
  3387. DWC_WRITE_REG32(&out_regs->doepdma,
  3388. ep->dma_desc_addr);
  3389. #ifdef DWC_UTE_CFI
  3390. }
  3391. #endif
  3392. }
  3393. } else {
  3394. DWC_WRITE_REG32(&out_regs->doeptsiz, deptsiz.d32);
  3395. }
  3396. if (ep->type == DWC_OTG_EP_TYPE_ISOC)
  3397. {
  3398. dsts_data_t dsts = {.d32 = 0};
  3399. if (ep->bInterval == 1) {
  3400. dsts.d32 =
  3401. DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  3402. ep->frame_num = dsts.b.soffn + ep->bInterval;
  3403. if (ep->frame_num > 0x3FFF)
  3404. {
  3405. ep->frm_overrun = 1;
  3406. ep->frame_num &= 0x3FFF;
  3407. } else
  3408. ep->frm_overrun = 0;
  3409. if (ep->frame_num & 0x1) {
  3410. depctl.b.setd1pid = 1;
  3411. } else {
  3412. depctl.b.setd0pid = 1;
  3413. }
  3414. }
  3415. }
  3416. /* EP enable */
  3417. depctl.b.cnak = 1;
  3418. depctl.b.epena = 1;
  3419. DWC_WRITE_REG32(&out_regs->doepctl, depctl.d32);
  3420. DWC_WMB();
  3421. DWC_DEBUGPL(DBG_PCD, "DOEPCTL=%08x DOEPTSIZ=%08x\n",
  3422. DWC_READ_REG32(&out_regs->doepctl),
  3423. DWC_READ_REG32(&out_regs->doeptsiz));
  3424. DWC_DEBUGPL(DBG_PCD, "DAINTMSK=%08x GINTMSK=%08x\n",
  3425. DWC_READ_REG32(&core_if->dev_if->
  3426. dev_global_regs->daintmsk),
  3427. DWC_READ_REG32(&core_if->
  3428. core_global_regs->gintmsk));
  3429. /* Timer is scheduling only for out bulk transfers for
  3430. * "Device DDMA OUT NAK Enhancement" feature to inform user
  3431. * about received data payload in case of timeout
  3432. */
  3433. if (core_if->core_params->dev_out_nak) {
  3434. if (ep->type == DWC_OTG_EP_TYPE_BULK) {
  3435. core_if->ep_xfer_info[ep->num].core_if = core_if;
  3436. core_if->ep_xfer_info[ep->num].ep = ep;
  3437. core_if->ep_xfer_info[ep->num].state = 1;
  3438. /* Start a timer for this transfer. */
  3439. DWC_TIMER_SCHEDULE(core_if->ep_xfer_timer[ep->num], 10000);
  3440. }
  3441. }
  3442. }
  3443. }
  3444. /**
  3445. * This function setup a zero length transfer in Buffer DMA and
  3446. * Slave modes for usb requests with zero field set
  3447. *
  3448. * @param core_if Programming view of DWC_otg controller.
  3449. * @param ep The EP to start the transfer on.
  3450. *
  3451. */
  3452. void dwc_otg_ep_start_zl_transfer(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  3453. {
  3454. depctl_data_t depctl;
  3455. deptsiz_data_t deptsiz;
  3456. gintmsk_data_t intr_mask = {.d32 = 0 };
  3457. DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "%s()\n", __func__);
  3458. DWC_PRINTF("zero length transfer is called\n");
  3459. /* IN endpoint */
  3460. if (ep->is_in == 1) {
  3461. dwc_otg_dev_in_ep_regs_t *in_regs =
  3462. core_if->dev_if->in_ep_regs[ep->num];
  3463. depctl.d32 = DWC_READ_REG32(&(in_regs->diepctl));
  3464. deptsiz.d32 = DWC_READ_REG32(&(in_regs->dieptsiz));
  3465. deptsiz.b.xfersize = 0;
  3466. deptsiz.b.pktcnt = 1;
  3467. /* Write the DMA register */
  3468. if (core_if->dma_enable) {
  3469. if (core_if->dma_desc_enable == 0) {
  3470. deptsiz.b.mc = 1;
  3471. DWC_WRITE_REG32(&in_regs->dieptsiz,
  3472. deptsiz.d32);
  3473. DWC_WRITE_REG32(&(in_regs->diepdma),
  3474. (uint32_t) ep->dma_addr);
  3475. }
  3476. } else {
  3477. DWC_WRITE_REG32(&in_regs->dieptsiz, deptsiz.d32);
  3478. /**
  3479. * Enable the Non-Periodic Tx FIFO empty interrupt,
  3480. * or the Tx FIFO epmty interrupt in dedicated Tx FIFO mode,
  3481. * the data will be written into the fifo by the ISR.
  3482. */
  3483. if (core_if->en_multiple_tx_fifo == 0) {
  3484. intr_mask.b.nptxfempty = 1;
  3485. DWC_MODIFY_REG32(&core_if->
  3486. core_global_regs->gintmsk,
  3487. intr_mask.d32, intr_mask.d32);
  3488. } else {
  3489. /* Enable the Tx FIFO Empty Interrupt for this EP */
  3490. if (ep->xfer_len > 0) {
  3491. uint32_t fifoemptymsk = 0;
  3492. fifoemptymsk = 1 << ep->num;
  3493. DWC_MODIFY_REG32(&core_if->
  3494. dev_if->dev_global_regs->dtknqr4_fifoemptymsk,
  3495. 0, fifoemptymsk);
  3496. }
  3497. }
  3498. }
  3499. if (!core_if->core_params->en_multiple_tx_fifo && core_if->dma_enable)
  3500. depctl.b.nextep = core_if->nextep_seq[ep->num];
  3501. /* EP enable, IN data in FIFO */
  3502. depctl.b.cnak = 1;
  3503. depctl.b.epena = 1;
  3504. DWC_WRITE_REG32(&in_regs->diepctl, depctl.d32);
  3505. DWC_WMB();
  3506. } else {
  3507. /* OUT endpoint */
  3508. dwc_otg_dev_out_ep_regs_t *out_regs =
  3509. core_if->dev_if->out_ep_regs[ep->num];
  3510. depctl.d32 = DWC_READ_REG32(&(out_regs->doepctl));
  3511. deptsiz.d32 = DWC_READ_REG32(&(out_regs->doeptsiz));
  3512. /* Zero Length Packet */
  3513. deptsiz.b.xfersize = ep->maxpacket;
  3514. deptsiz.b.pktcnt = 1;
  3515. if (core_if->dma_enable) {
  3516. if (!core_if->dma_desc_enable) {
  3517. DWC_WRITE_REG32(&out_regs->doeptsiz,
  3518. deptsiz.d32);
  3519. DWC_WRITE_REG32(&(out_regs->doepdma),
  3520. (uint32_t) ep->dma_addr);
  3521. }
  3522. } else {
  3523. DWC_WRITE_REG32(&out_regs->doeptsiz, deptsiz.d32);
  3524. }
  3525. /* EP enable */
  3526. depctl.b.cnak = 1;
  3527. depctl.b.epena = 1;
  3528. DWC_WRITE_REG32(&out_regs->doepctl, depctl.d32);
  3529. DWC_WMB();
  3530. }
  3531. }
  3532. /**
  3533. * This function does the setup for a data transfer for EP0 and starts
  3534. * the transfer. For an IN transfer, the packets will be loaded into
  3535. * the appropriate Tx FIFO in the ISR. For OUT transfers, the packets are
  3536. * unloaded from the Rx FIFO in the ISR.
  3537. *
  3538. * @param core_if Programming view of DWC_otg controller.
  3539. * @param ep The EP0 data.
  3540. */
  3541. void dwc_otg_ep0_start_transfer(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  3542. {
  3543. depctl_data_t depctl;
  3544. deptsiz0_data_t deptsiz;
  3545. gintmsk_data_t intr_mask = {.d32 = 0 };
  3546. dwc_otg_dev_dma_desc_t *dma_desc;
  3547. DWC_DEBUGPL(DBG_PCD, "ep%d-%s xfer_len=%d xfer_cnt=%d "
  3548. "xfer_buff=%p start_xfer_buff=%p \n",
  3549. ep->num, (ep->is_in ? "IN" : "OUT"), ep->xfer_len,
  3550. ep->xfer_count, ep->xfer_buff, ep->start_xfer_buff);
  3551. ep->total_len = ep->xfer_len;
  3552. /* IN endpoint */
  3553. if (ep->is_in == 1) {
  3554. dwc_otg_dev_in_ep_regs_t *in_regs =
  3555. core_if->dev_if->in_ep_regs[0];
  3556. gnptxsts_data_t gtxstatus;
  3557. gtxstatus.d32 =
  3558. DWC_READ_REG32(&core_if->core_global_regs->gnptxsts);
  3559. if (core_if->en_multiple_tx_fifo == 0
  3560. && gtxstatus.b.nptxqspcavail == 0
  3561. && !core_if->dma_enable) {
  3562. #ifdef DEBUG
  3563. deptsiz.d32 = DWC_READ_REG32(&in_regs->dieptsiz);
  3564. DWC_DEBUGPL(DBG_PCD, "DIEPCTL0=%0x\n",
  3565. DWC_READ_REG32(&in_regs->diepctl));
  3566. DWC_DEBUGPL(DBG_PCD, "DIEPTSIZ0=%0x (sz=%d, pcnt=%d)\n",
  3567. deptsiz.d32,
  3568. deptsiz.b.xfersize, deptsiz.b.pktcnt);
  3569. DWC_PRINTF("TX Queue or FIFO Full (0x%0x)\n",
  3570. gtxstatus.d32);
  3571. #endif
  3572. return;
  3573. }
  3574. depctl.d32 = DWC_READ_REG32(&in_regs->diepctl);
  3575. deptsiz.d32 = DWC_READ_REG32(&in_regs->dieptsiz);
  3576. /* Zero Length Packet? */
  3577. if (ep->xfer_len == 0) {
  3578. deptsiz.b.xfersize = 0;
  3579. deptsiz.b.pktcnt = 1;
  3580. } else {
  3581. /* Program the transfer size and packet count
  3582. * as follows: xfersize = N * maxpacket +
  3583. * short_packet pktcnt = N + (short_packet
  3584. * exist ? 1 : 0)
  3585. */
  3586. if (ep->xfer_len > ep->maxpacket) {
  3587. ep->xfer_len = ep->maxpacket;
  3588. deptsiz.b.xfersize = ep->maxpacket;
  3589. } else {
  3590. deptsiz.b.xfersize = ep->xfer_len;
  3591. }
  3592. deptsiz.b.pktcnt = 1;
  3593. }
  3594. DWC_DEBUGPL(DBG_PCDV,
  3595. "IN len=%d xfersize=%d pktcnt=%d [%08x]\n",
  3596. ep->xfer_len, deptsiz.b.xfersize, deptsiz.b.pktcnt,
  3597. deptsiz.d32);
  3598. /* Write the DMA register */
  3599. if (core_if->dma_enable) {
  3600. if (core_if->dma_desc_enable == 0) {
  3601. DWC_WRITE_REG32(&in_regs->dieptsiz,
  3602. deptsiz.d32);
  3603. DWC_WRITE_REG32(&(in_regs->diepdma),
  3604. (uint32_t) ep->dma_addr);
  3605. } else {
  3606. dma_desc = core_if->dev_if->in_desc_addr;
  3607. /** DMA Descriptor Setup */
  3608. dma_desc->status.b.bs = BS_HOST_BUSY;
  3609. dma_desc->status.b.l = 1;
  3610. dma_desc->status.b.ioc = 1;
  3611. dma_desc->status.b.sp =
  3612. (ep->xfer_len == ep->maxpacket) ? 0 : 1;
  3613. dma_desc->status.b.bytes = ep->xfer_len;
  3614. dma_desc->buf = ep->dma_addr;
  3615. dma_desc->status.b.sts = 0;
  3616. dma_desc->status.b.bs = BS_HOST_READY;
  3617. /** DIEPDMA0 Register write */
  3618. DWC_WRITE_REG32(&in_regs->diepdma,
  3619. core_if->
  3620. dev_if->dma_in_desc_addr);
  3621. }
  3622. } else {
  3623. DWC_WRITE_REG32(&in_regs->dieptsiz, deptsiz.d32);
  3624. }
  3625. if (!core_if->core_params->en_multiple_tx_fifo && core_if->dma_enable)
  3626. depctl.b.nextep = core_if->nextep_seq[ep->num];
  3627. /* EP enable, IN data in FIFO */
  3628. depctl.b.cnak = 1;
  3629. depctl.b.epena = 1;
  3630. DWC_WRITE_REG32(&in_regs->diepctl, depctl.d32);
  3631. DWC_WMB();
  3632. /**
  3633. * Enable the Non-Periodic Tx FIFO empty interrupt, the
  3634. * data will be written into the fifo by the ISR.
  3635. */
  3636. if (!core_if->dma_enable) {
  3637. if (core_if->en_multiple_tx_fifo == 0) {
  3638. intr_mask.b.nptxfempty = 1;
  3639. DWC_MODIFY_REG32(&core_if->
  3640. core_global_regs->gintmsk,
  3641. intr_mask.d32, intr_mask.d32);
  3642. } else {
  3643. /* Enable the Tx FIFO Empty Interrupt for this EP */
  3644. if (ep->xfer_len > 0) {
  3645. uint32_t fifoemptymsk = 0;
  3646. fifoemptymsk |= 1 << ep->num;
  3647. DWC_MODIFY_REG32(&core_if->
  3648. dev_if->dev_global_regs->dtknqr4_fifoemptymsk,
  3649. 0, fifoemptymsk);
  3650. }
  3651. }
  3652. }
  3653. } else {
  3654. /* OUT endpoint */
  3655. dwc_otg_dev_out_ep_regs_t *out_regs =
  3656. core_if->dev_if->out_ep_regs[0];
  3657. depctl.d32 = DWC_READ_REG32(&out_regs->doepctl);
  3658. deptsiz.d32 = DWC_READ_REG32(&out_regs->doeptsiz);
  3659. /* Program the transfer size and packet count as follows:
  3660. * xfersize = N * (maxpacket + 4 - (maxpacket % 4))
  3661. * pktcnt = N */
  3662. /* Zero Length Packet */
  3663. deptsiz.b.xfersize = ep->maxpacket;
  3664. deptsiz.b.pktcnt = 1;
  3665. DWC_DEBUGPL(DBG_PCDV, "len=%d xfersize=%d pktcnt=%d\n",
  3666. ep->xfer_len, deptsiz.b.xfersize, deptsiz.b.pktcnt);
  3667. if (core_if->dma_enable) {
  3668. if (!core_if->dma_desc_enable) {
  3669. DWC_WRITE_REG32(&out_regs->doeptsiz,
  3670. deptsiz.d32);
  3671. DWC_WRITE_REG32(&(out_regs->doepdma),
  3672. (uint32_t) ep->dma_addr);
  3673. } else {
  3674. dma_desc = core_if->dev_if->out_desc_addr;
  3675. /** DMA Descriptor Setup */
  3676. dma_desc->status.b.bs = BS_HOST_BUSY;
  3677. dma_desc->status.b.l = 1;
  3678. dma_desc->status.b.ioc = 1;
  3679. dma_desc->status.b.bytes = ep->maxpacket;
  3680. dma_desc->buf = ep->dma_addr;
  3681. dma_desc->status.b.sts = 0;
  3682. dma_desc->status.b.bs = BS_HOST_READY;
  3683. /** DOEPDMA0 Register write */
  3684. DWC_WRITE_REG32(&out_regs->doepdma,
  3685. core_if->
  3686. dev_if->dma_out_desc_addr);
  3687. }
  3688. } else {
  3689. DWC_WRITE_REG32(&out_regs->doeptsiz, deptsiz.d32);
  3690. }
  3691. /* EP enable */
  3692. depctl.b.cnak = 1;
  3693. depctl.b.epena = 1;
  3694. DWC_WRITE_REG32(&(out_regs->doepctl), depctl.d32);
  3695. DWC_WMB();
  3696. }
  3697. }
  3698. /**
  3699. * This function continues control IN transfers started by
  3700. * dwc_otg_ep0_start_transfer, when the transfer does not fit in a
  3701. * single packet. NOTE: The DIEPCTL0/DOEPCTL0 registers only have one
  3702. * bit for the packet count.
  3703. *
  3704. * @param core_if Programming view of DWC_otg controller.
  3705. * @param ep The EP0 data.
  3706. */
  3707. void dwc_otg_ep0_continue_transfer(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  3708. {
  3709. depctl_data_t depctl;
  3710. deptsiz0_data_t deptsiz;
  3711. gintmsk_data_t intr_mask = {.d32 = 0 };
  3712. dwc_otg_dev_dma_desc_t *dma_desc;
  3713. if (ep->is_in == 1) {
  3714. dwc_otg_dev_in_ep_regs_t *in_regs =
  3715. core_if->dev_if->in_ep_regs[0];
  3716. gnptxsts_data_t tx_status = {.d32 = 0 };
  3717. tx_status.d32 =
  3718. DWC_READ_REG32(&core_if->core_global_regs->gnptxsts);
  3719. /** @todo Should there be check for room in the Tx
  3720. * Status Queue. If not remove the code above this comment. */
  3721. depctl.d32 = DWC_READ_REG32(&in_regs->diepctl);
  3722. deptsiz.d32 = DWC_READ_REG32(&in_regs->dieptsiz);
  3723. /* Program the transfer size and packet count
  3724. * as follows: xfersize = N * maxpacket +
  3725. * short_packet pktcnt = N + (short_packet
  3726. * exist ? 1 : 0)
  3727. */
  3728. if (core_if->dma_desc_enable == 0) {
  3729. deptsiz.b.xfersize =
  3730. (ep->total_len - ep->xfer_count) >
  3731. ep->maxpacket ? ep->maxpacket : (ep->total_len -
  3732. ep->xfer_count);
  3733. deptsiz.b.pktcnt = 1;
  3734. if (core_if->dma_enable == 0) {
  3735. ep->xfer_len += deptsiz.b.xfersize;
  3736. } else {
  3737. ep->xfer_len = deptsiz.b.xfersize;
  3738. }
  3739. DWC_WRITE_REG32(&in_regs->dieptsiz, deptsiz.d32);
  3740. } else {
  3741. ep->xfer_len =
  3742. (ep->total_len - ep->xfer_count) >
  3743. ep->maxpacket ? ep->maxpacket : (ep->total_len -
  3744. ep->xfer_count);
  3745. dma_desc = core_if->dev_if->in_desc_addr;
  3746. /** DMA Descriptor Setup */
  3747. dma_desc->status.b.bs = BS_HOST_BUSY;
  3748. dma_desc->status.b.l = 1;
  3749. dma_desc->status.b.ioc = 1;
  3750. dma_desc->status.b.sp =
  3751. (ep->xfer_len == ep->maxpacket) ? 0 : 1;
  3752. dma_desc->status.b.bytes = ep->xfer_len;
  3753. dma_desc->buf = ep->dma_addr;
  3754. dma_desc->status.b.sts = 0;
  3755. dma_desc->status.b.bs = BS_HOST_READY;
  3756. /** DIEPDMA0 Register write */
  3757. DWC_WRITE_REG32(&in_regs->diepdma,
  3758. core_if->dev_if->dma_in_desc_addr);
  3759. }
  3760. DWC_DEBUGPL(DBG_PCDV,
  3761. "IN len=%d xfersize=%d pktcnt=%d [%08x]\n",
  3762. ep->xfer_len, deptsiz.b.xfersize, deptsiz.b.pktcnt,
  3763. deptsiz.d32);
  3764. /* Write the DMA register */
  3765. if (core_if->hwcfg2.b.architecture == DWC_INT_DMA_ARCH) {
  3766. if (core_if->dma_desc_enable == 0)
  3767. DWC_WRITE_REG32(&(in_regs->diepdma),
  3768. (uint32_t) ep->dma_addr);
  3769. }
  3770. if (!core_if->core_params->en_multiple_tx_fifo && core_if->dma_enable)
  3771. depctl.b.nextep = core_if->nextep_seq[ep->num];
  3772. /* EP enable, IN data in FIFO */
  3773. depctl.b.cnak = 1;
  3774. depctl.b.epena = 1;
  3775. DWC_WRITE_REG32(&in_regs->diepctl, depctl.d32);
  3776. DWC_WMB();
  3777. /**
  3778. * Enable the Non-Periodic Tx FIFO empty interrupt, the
  3779. * data will be written into the fifo by the ISR.
  3780. */
  3781. if (!core_if->dma_enable) {
  3782. if (core_if->en_multiple_tx_fifo == 0) {
  3783. /* First clear it from GINTSTS */
  3784. intr_mask.b.nptxfempty = 1;
  3785. DWC_MODIFY_REG32(&core_if->
  3786. core_global_regs->gintmsk,
  3787. intr_mask.d32, intr_mask.d32);
  3788. } else {
  3789. /* Enable the Tx FIFO Empty Interrupt for this EP */
  3790. if (ep->xfer_len > 0) {
  3791. uint32_t fifoemptymsk = 0;
  3792. fifoemptymsk |= 1 << ep->num;
  3793. DWC_MODIFY_REG32(&core_if->
  3794. dev_if->dev_global_regs->dtknqr4_fifoemptymsk,
  3795. 0, fifoemptymsk);
  3796. }
  3797. }
  3798. }
  3799. } else {
  3800. dwc_otg_dev_out_ep_regs_t *out_regs =
  3801. core_if->dev_if->out_ep_regs[0];
  3802. depctl.d32 = DWC_READ_REG32(&out_regs->doepctl);
  3803. deptsiz.d32 = DWC_READ_REG32(&out_regs->doeptsiz);
  3804. /* Program the transfer size and packet count
  3805. * as follows: xfersize = N * maxpacket +
  3806. * short_packet pktcnt = N + (short_packet
  3807. * exist ? 1 : 0)
  3808. */
  3809. deptsiz.b.xfersize = ep->maxpacket;
  3810. deptsiz.b.pktcnt = 1;
  3811. if (core_if->dma_desc_enable == 0) {
  3812. DWC_WRITE_REG32(&out_regs->doeptsiz, deptsiz.d32);
  3813. } else {
  3814. dma_desc = core_if->dev_if->out_desc_addr;
  3815. /** DMA Descriptor Setup */
  3816. dma_desc->status.b.bs = BS_HOST_BUSY;
  3817. dma_desc->status.b.l = 1;
  3818. dma_desc->status.b.ioc = 1;
  3819. dma_desc->status.b.bytes = ep->maxpacket;
  3820. dma_desc->buf = ep->dma_addr;
  3821. dma_desc->status.b.sts = 0;
  3822. dma_desc->status.b.bs = BS_HOST_READY;
  3823. /** DOEPDMA0 Register write */
  3824. DWC_WRITE_REG32(&out_regs->doepdma,
  3825. core_if->dev_if->dma_out_desc_addr);
  3826. }
  3827. DWC_DEBUGPL(DBG_PCDV,
  3828. "IN len=%d xfersize=%d pktcnt=%d [%08x]\n",
  3829. ep->xfer_len, deptsiz.b.xfersize, deptsiz.b.pktcnt,
  3830. deptsiz.d32);
  3831. /* Write the DMA register */
  3832. if (core_if->hwcfg2.b.architecture == DWC_INT_DMA_ARCH) {
  3833. if (core_if->dma_desc_enable == 0)
  3834. DWC_WRITE_REG32(&(out_regs->doepdma),
  3835. (uint32_t) ep->dma_addr);
  3836. }
  3837. /* EP enable, IN data in FIFO */
  3838. depctl.b.cnak = 1;
  3839. depctl.b.epena = 1;
  3840. DWC_WRITE_REG32(&out_regs->doepctl, depctl.d32);
  3841. DWC_WMB();
  3842. }
  3843. }
  3844. #ifdef DEBUG
  3845. void dump_msg(const u8 * buf, unsigned int length)
  3846. {
  3847. unsigned int start, num, i;
  3848. char line[52], *p;
  3849. if (length >= 512)
  3850. return;
  3851. start = 0;
  3852. while (length > 0) {
  3853. num = length < 16u ? length : 16u;
  3854. p = line;
  3855. for (i = 0; i < num; ++i) {
  3856. if (i == 8)
  3857. *p++ = ' ';
  3858. DWC_SPRINTF(p, " %02x", buf[i]);
  3859. p += 3;
  3860. }
  3861. *p = 0;
  3862. DWC_PRINTF("%6x: %s\n", start, line);
  3863. buf += num;
  3864. start += num;
  3865. length -= num;
  3866. }
  3867. }
  3868. #else
  3869. static inline void dump_msg(const u8 * buf, unsigned int length)
  3870. {
  3871. }
  3872. #endif
  3873. /**
  3874. * This function writes a packet into the Tx FIFO associated with the
  3875. * EP. For non-periodic EPs the non-periodic Tx FIFO is written. For
  3876. * periodic EPs the periodic Tx FIFO associated with the EP is written
  3877. * with all packets for the next micro-frame.
  3878. *
  3879. * @param core_if Programming view of DWC_otg controller.
  3880. * @param ep The EP to write packet for.
  3881. * @param dma Indicates if DMA is being used.
  3882. */
  3883. void dwc_otg_ep_write_packet(dwc_otg_core_if_t * core_if, dwc_ep_t * ep,
  3884. int dma)
  3885. {
  3886. /**
  3887. * The buffer is padded to DWORD on a per packet basis in
  3888. * slave/dma mode if the MPS is not DWORD aligned. The last
  3889. * packet, if short, is also padded to a multiple of DWORD.
  3890. *
  3891. * ep->xfer_buff always starts DWORD aligned in memory and is a
  3892. * multiple of DWORD in length
  3893. *
  3894. * ep->xfer_len can be any number of bytes
  3895. *
  3896. * ep->xfer_count is a multiple of ep->maxpacket until the last
  3897. * packet
  3898. *
  3899. * FIFO access is DWORD */
  3900. uint32_t i;
  3901. uint32_t byte_count;
  3902. uint32_t dword_count;
  3903. uint32_t *fifo;
  3904. uint32_t *data_buff = (uint32_t *) ep->xfer_buff;
  3905. DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "%s(%p,%p)\n", __func__, core_if,
  3906. ep);
  3907. if (ep->xfer_count >= ep->xfer_len) {
  3908. DWC_WARN("%s() No data for EP%d!!!\n", __func__, ep->num);
  3909. return;
  3910. }
  3911. /* Find the byte length of the packet either short packet or MPS */
  3912. if ((ep->xfer_len - ep->xfer_count) < ep->maxpacket) {
  3913. byte_count = ep->xfer_len - ep->xfer_count;
  3914. } else {
  3915. byte_count = ep->maxpacket;
  3916. }
  3917. /* Find the DWORD length, padded by extra bytes as neccessary if MPS
  3918. * is not a multiple of DWORD */
  3919. dword_count = (byte_count + 3) / 4;
  3920. #ifdef VERBOSE
  3921. dump_msg(ep->xfer_buff, byte_count);
  3922. #endif
  3923. /**@todo NGS Where are the Periodic Tx FIFO addresses
  3924. * intialized? What should this be? */
  3925. fifo = core_if->data_fifo[ep->num];
  3926. DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "fifo=%p buff=%p *p=%08x bc=%d\n",
  3927. fifo, data_buff, *data_buff, byte_count);
  3928. if (!dma) {
  3929. for (i = 0; i < dword_count; i++, data_buff++) {
  3930. DWC_WRITE_REG32(fifo, *data_buff);
  3931. }
  3932. }
  3933. ep->xfer_count += byte_count;
  3934. ep->xfer_buff += byte_count;
  3935. ep->dma_addr += byte_count;
  3936. }
  3937. /**
  3938. * Set the EP STALL.
  3939. *
  3940. * @param core_if Programming view of DWC_otg controller.
  3941. * @param ep The EP to set the stall on.
  3942. */
  3943. void dwc_otg_ep_set_stall(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  3944. {
  3945. depctl_data_t depctl;
  3946. volatile uint32_t *depctl_addr;
  3947. DWC_DEBUGPL(DBG_PCD, "%s ep%d-%s\n", __func__, ep->num,
  3948. (ep->is_in ? "IN" : "OUT"));
  3949. if (ep->is_in == 1) {
  3950. depctl_addr = &(core_if->dev_if->in_ep_regs[ep->num]->diepctl);
  3951. depctl.d32 = DWC_READ_REG32(depctl_addr);
  3952. /* set the disable and stall bits */
  3953. if (depctl.b.epena) {
  3954. depctl.b.epdis = 1;
  3955. }
  3956. depctl.b.stall = 1;
  3957. DWC_WRITE_REG32(depctl_addr, depctl.d32);
  3958. } else {
  3959. depctl_addr = &(core_if->dev_if->out_ep_regs[ep->num]->doepctl);
  3960. depctl.d32 = DWC_READ_REG32(depctl_addr);
  3961. /* set the stall bit */
  3962. depctl.b.stall = 1;
  3963. DWC_WRITE_REG32(depctl_addr, depctl.d32);
  3964. }
  3965. DWC_DEBUGPL(DBG_PCD, "DEPCTL=%0x\n", DWC_READ_REG32(depctl_addr));
  3966. return;
  3967. }
  3968. /**
  3969. * Clear the EP STALL.
  3970. *
  3971. * @param core_if Programming view of DWC_otg controller.
  3972. * @param ep The EP to clear stall from.
  3973. */
  3974. void dwc_otg_ep_clear_stall(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  3975. {
  3976. depctl_data_t depctl;
  3977. volatile uint32_t *depctl_addr;
  3978. DWC_DEBUGPL(DBG_PCD, "%s ep%d-%s\n", __func__, ep->num,
  3979. (ep->is_in ? "IN" : "OUT"));
  3980. if (ep->is_in == 1) {
  3981. depctl_addr = &(core_if->dev_if->in_ep_regs[ep->num]->diepctl);
  3982. } else {
  3983. depctl_addr = &(core_if->dev_if->out_ep_regs[ep->num]->doepctl);
  3984. }
  3985. depctl.d32 = DWC_READ_REG32(depctl_addr);
  3986. /* clear the stall bits */
  3987. depctl.b.stall = 0;
  3988. /*
  3989. * USB Spec 9.4.5: For endpoints using data toggle, regardless
  3990. * of whether an endpoint has the Halt feature set, a
  3991. * ClearFeature(ENDPOINT_HALT) request always results in the
  3992. * data toggle being reinitialized to DATA0.
  3993. */
  3994. if (ep->type == DWC_OTG_EP_TYPE_INTR ||
  3995. ep->type == DWC_OTG_EP_TYPE_BULK) {
  3996. depctl.b.setd0pid = 1; /* DATA0 */
  3997. }
  3998. DWC_WRITE_REG32(depctl_addr, depctl.d32);
  3999. DWC_DEBUGPL(DBG_PCD, "DEPCTL=%0x\n", DWC_READ_REG32(depctl_addr));
  4000. return;
  4001. }
  4002. /**
  4003. * This function reads a packet from the Rx FIFO into the destination
  4004. * buffer. To read SETUP data use dwc_otg_read_setup_packet.
  4005. *
  4006. * @param core_if Programming view of DWC_otg controller.
  4007. * @param dest Destination buffer for the packet.
  4008. * @param bytes Number of bytes to copy to the destination.
  4009. */
  4010. void dwc_otg_read_packet(dwc_otg_core_if_t * core_if,
  4011. uint8_t * dest, uint16_t bytes)
  4012. {
  4013. int i;
  4014. int word_count = (bytes + 3) / 4;
  4015. volatile uint32_t *fifo = core_if->data_fifo[0];
  4016. uint32_t *data_buff = (uint32_t *) dest;
  4017. /**
  4018. * @todo Account for the case where _dest is not dword aligned. This
  4019. * requires reading data from the FIFO into a uint32_t temp buffer,
  4020. * then moving it into the data buffer.
  4021. */
  4022. DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "%s(%p,%p,%d)\n", __func__,
  4023. core_if, dest, bytes);
  4024. for (i = 0; i < word_count; i++, data_buff++) {
  4025. *data_buff = DWC_READ_REG32(fifo);
  4026. }
  4027. return;
  4028. }
  4029. /**
  4030. * This functions reads the device registers and prints them
  4031. *
  4032. * @param core_if Programming view of DWC_otg controller.
  4033. */
  4034. void dwc_otg_dump_dev_registers(dwc_otg_core_if_t * core_if)
  4035. {
  4036. int i;
  4037. volatile uint32_t *addr;
  4038. DWC_PRINTF("Device Global Registers\n");
  4039. addr = &core_if->dev_if->dev_global_regs->dcfg;
  4040. DWC_PRINTF("DCFG @0x%08lX : 0x%08X\n", (unsigned long) addr,
  4041. DWC_READ_REG32(addr));
  4042. addr = &core_if->dev_if->dev_global_regs->dctl;
  4043. DWC_PRINTF("DCTL @0x%08lX : 0x%08X\n", (unsigned long) addr,
  4044. DWC_READ_REG32(addr));
  4045. addr = &core_if->dev_if->dev_global_regs->dsts;
  4046. DWC_PRINTF("DSTS @0x%08lX : 0x%08X\n", (unsigned long) addr,
  4047. DWC_READ_REG32(addr));
  4048. addr = &core_if->dev_if->dev_global_regs->diepmsk;
  4049. DWC_PRINTF("DIEPMSK @0x%08lX : 0x%08X\n", (unsigned long)addr,
  4050. DWC_READ_REG32(addr));
  4051. addr = &core_if->dev_if->dev_global_regs->doepmsk;
  4052. DWC_PRINTF("DOEPMSK @0x%08lX : 0x%08X\n", (unsigned long)addr,
  4053. DWC_READ_REG32(addr));
  4054. addr = &core_if->dev_if->dev_global_regs->daint;
  4055. DWC_PRINTF("DAINT @0x%08lX : 0x%08X\n", (unsigned long)addr,
  4056. DWC_READ_REG32(addr));
  4057. addr = &core_if->dev_if->dev_global_regs->daintmsk;
  4058. DWC_PRINTF("DAINTMSK @0x%08lX : 0x%08X\n", (unsigned long)addr,
  4059. DWC_READ_REG32(addr));
  4060. addr = &core_if->dev_if->dev_global_regs->dtknqr1;
  4061. DWC_PRINTF("DTKNQR1 @0x%08lX : 0x%08X\n", (unsigned long)addr,
  4062. DWC_READ_REG32(addr));
  4063. if (core_if->hwcfg2.b.dev_token_q_depth > 6) {
  4064. addr = &core_if->dev_if->dev_global_regs->dtknqr2;
  4065. DWC_PRINTF("DTKNQR2 @0x%08lX : 0x%08X\n",
  4066. (unsigned long)addr, DWC_READ_REG32(addr));
  4067. }
  4068. addr = &core_if->dev_if->dev_global_regs->dvbusdis;
  4069. DWC_PRINTF("DVBUSID @0x%08lX : 0x%08X\n", (unsigned long)addr,
  4070. DWC_READ_REG32(addr));
  4071. addr = &core_if->dev_if->dev_global_regs->dvbuspulse;
  4072. DWC_PRINTF("DVBUSPULSE @0x%08lX : 0x%08X\n",
  4073. (unsigned long)addr, DWC_READ_REG32(addr));
  4074. addr = &core_if->dev_if->dev_global_regs->dtknqr3_dthrctl;
  4075. DWC_PRINTF("DTKNQR3_DTHRCTL @0x%08lX : 0x%08X\n",
  4076. (unsigned long)addr, DWC_READ_REG32(addr));
  4077. if (core_if->hwcfg2.b.dev_token_q_depth > 22) {
  4078. addr = &core_if->dev_if->dev_global_regs->dtknqr4_fifoemptymsk;
  4079. DWC_PRINTF("DTKNQR4 @0x%08lX : 0x%08X\n",
  4080. (unsigned long)addr, DWC_READ_REG32(addr));
  4081. }
  4082. addr = &core_if->dev_if->dev_global_regs->dtknqr4_fifoemptymsk;
  4083. DWC_PRINTF("FIFOEMPMSK @0x%08lX : 0x%08X\n", (unsigned long)addr,
  4084. DWC_READ_REG32(addr));
  4085. if (core_if->hwcfg2.b.multi_proc_int) {
  4086. addr = &core_if->dev_if->dev_global_regs->deachint;
  4087. DWC_PRINTF("DEACHINT @0x%08lX : 0x%08X\n",
  4088. (unsigned long)addr, DWC_READ_REG32(addr));
  4089. addr = &core_if->dev_if->dev_global_regs->deachintmsk;
  4090. DWC_PRINTF("DEACHINTMSK @0x%08lX : 0x%08X\n",
  4091. (unsigned long)addr, DWC_READ_REG32(addr));
  4092. for (i = 0; i <= core_if->dev_if->num_in_eps; i++) {
  4093. addr =
  4094. &core_if->dev_if->dev_global_regs->
  4095. diepeachintmsk[i];
  4096. DWC_PRINTF("DIEPEACHINTMSK[%d] @0x%08lX : 0x%08X\n",
  4097. i, (unsigned long)addr,
  4098. DWC_READ_REG32(addr));
  4099. }
  4100. for (i = 0; i <= core_if->dev_if->num_out_eps; i++) {
  4101. addr =
  4102. &core_if->dev_if->dev_global_regs->
  4103. doepeachintmsk[i];
  4104. DWC_PRINTF("DOEPEACHINTMSK[%d] @0x%08lX : 0x%08X\n",
  4105. i, (unsigned long)addr,
  4106. DWC_READ_REG32(addr));
  4107. }
  4108. }
  4109. for (i = 0; i <= core_if->dev_if->num_in_eps; i++) {
  4110. DWC_PRINTF("Device IN EP %d Registers\n", i);
  4111. addr = &core_if->dev_if->in_ep_regs[i]->diepctl;
  4112. DWC_PRINTF("DIEPCTL @0x%08lX : 0x%08X\n",
  4113. (unsigned long)addr, DWC_READ_REG32(addr));
  4114. addr = &core_if->dev_if->in_ep_regs[i]->diepint;
  4115. DWC_PRINTF("DIEPINT @0x%08lX : 0x%08X\n",
  4116. (unsigned long)addr, DWC_READ_REG32(addr));
  4117. addr = &core_if->dev_if->in_ep_regs[i]->dieptsiz;
  4118. DWC_PRINTF("DIETSIZ @0x%08lX : 0x%08X\n",
  4119. (unsigned long)addr, DWC_READ_REG32(addr));
  4120. addr = &core_if->dev_if->in_ep_regs[i]->diepdma;
  4121. DWC_PRINTF("DIEPDMA @0x%08lX : 0x%08X\n",
  4122. (unsigned long)addr, DWC_READ_REG32(addr));
  4123. addr = &core_if->dev_if->in_ep_regs[i]->dtxfsts;
  4124. DWC_PRINTF("DTXFSTS @0x%08lX : 0x%08X\n",
  4125. (unsigned long)addr, DWC_READ_REG32(addr));
  4126. addr = &core_if->dev_if->in_ep_regs[i]->diepdmab;
  4127. DWC_PRINTF("DIEPDMAB @0x%08lX : 0x%08X\n",
  4128. (unsigned long)addr, 0 /*DWC_READ_REG32(addr) */ );
  4129. }
  4130. for (i = 0; i <= core_if->dev_if->num_out_eps; i++) {
  4131. DWC_PRINTF("Device OUT EP %d Registers\n", i);
  4132. addr = &core_if->dev_if->out_ep_regs[i]->doepctl;
  4133. DWC_PRINTF("DOEPCTL @0x%08lX : 0x%08X\n",
  4134. (unsigned long)addr, DWC_READ_REG32(addr));
  4135. addr = &core_if->dev_if->out_ep_regs[i]->doepint;
  4136. DWC_PRINTF("DOEPINT @0x%08lX : 0x%08X\n",
  4137. (unsigned long)addr, DWC_READ_REG32(addr));
  4138. addr = &core_if->dev_if->out_ep_regs[i]->doeptsiz;
  4139. DWC_PRINTF("DOETSIZ @0x%08lX : 0x%08X\n",
  4140. (unsigned long)addr, DWC_READ_REG32(addr));
  4141. addr = &core_if->dev_if->out_ep_regs[i]->doepdma;
  4142. DWC_PRINTF("DOEPDMA @0x%08lX : 0x%08X\n",
  4143. (unsigned long)addr, DWC_READ_REG32(addr));
  4144. if (core_if->dma_enable) { /* Don't access this register in SLAVE mode */
  4145. addr = &core_if->dev_if->out_ep_regs[i]->doepdmab;
  4146. DWC_PRINTF("DOEPDMAB @0x%08lX : 0x%08X\n",
  4147. (unsigned long)addr, DWC_READ_REG32(addr));
  4148. }
  4149. }
  4150. }
  4151. /**
  4152. * This functions reads the SPRAM and prints its content
  4153. *
  4154. * @param core_if Programming view of DWC_otg controller.
  4155. */
  4156. void dwc_otg_dump_spram(dwc_otg_core_if_t * core_if)
  4157. {
  4158. volatile uint8_t *addr, *start_addr, *end_addr;
  4159. DWC_PRINTF("SPRAM Data:\n");
  4160. start_addr = (void *)core_if->core_global_regs;
  4161. DWC_PRINTF("Base Address: 0x%8lX\n", (unsigned long)start_addr);
  4162. start_addr += 0x00028000;
  4163. end_addr = (void *)core_if->core_global_regs;
  4164. end_addr += 0x000280e0;
  4165. for (addr = start_addr; addr < end_addr; addr += 16) {
  4166. DWC_PRINTF
  4167. ("0x%8lX:\t%2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X\n",
  4168. (unsigned long)addr, addr[0], addr[1], addr[2], addr[3],
  4169. addr[4], addr[5], addr[6], addr[7], addr[8], addr[9],
  4170. addr[10], addr[11], addr[12], addr[13], addr[14], addr[15]
  4171. );
  4172. }
  4173. return;
  4174. }
  4175. /**
  4176. * This function reads the host registers and prints them
  4177. *
  4178. * @param core_if Programming view of DWC_otg controller.
  4179. */
  4180. void dwc_otg_dump_host_registers(dwc_otg_core_if_t * core_if)
  4181. {
  4182. int i;
  4183. volatile uint32_t *addr;
  4184. DWC_PRINTF("Host Global Registers\n");
  4185. addr = &core_if->host_if->host_global_regs->hcfg;
  4186. DWC_PRINTF("HCFG @0x%08lX : 0x%08X\n",
  4187. (unsigned long)addr, DWC_READ_REG32(addr));
  4188. addr = &core_if->host_if->host_global_regs->hfir;
  4189. DWC_PRINTF("HFIR @0x%08lX : 0x%08X\n",
  4190. (unsigned long)addr, DWC_READ_REG32(addr));
  4191. addr = &core_if->host_if->host_global_regs->hfnum;
  4192. DWC_PRINTF("HFNUM @0x%08lX : 0x%08X\n", (unsigned long)addr,
  4193. DWC_READ_REG32(addr));
  4194. addr = &core_if->host_if->host_global_regs->hptxsts;
  4195. DWC_PRINTF("HPTXSTS @0x%08lX : 0x%08X\n", (unsigned long)addr,
  4196. DWC_READ_REG32(addr));
  4197. addr = &core_if->host_if->host_global_regs->haint;
  4198. DWC_PRINTF("HAINT @0x%08lX : 0x%08X\n", (unsigned long)addr,
  4199. DWC_READ_REG32(addr));
  4200. addr = &core_if->host_if->host_global_regs->haintmsk;
  4201. DWC_PRINTF("HAINTMSK @0x%08lX : 0x%08X\n", (unsigned long)addr,
  4202. DWC_READ_REG32(addr));
  4203. if (core_if->dma_desc_enable) {
  4204. addr = &core_if->host_if->host_global_regs->hflbaddr;
  4205. DWC_PRINTF("HFLBADDR @0x%08lX : 0x%08X\n",
  4206. (unsigned long)addr, DWC_READ_REG32(addr));
  4207. }
  4208. addr = core_if->host_if->hprt0;
  4209. DWC_PRINTF("HPRT0 @0x%08lX : 0x%08X\n", (unsigned long)addr,
  4210. DWC_READ_REG32(addr));
  4211. for (i = 0; i < core_if->core_params->host_channels; i++) {
  4212. DWC_PRINTF("Host Channel %d Specific Registers\n", i);
  4213. addr = &core_if->host_if->hc_regs[i]->hcchar;
  4214. DWC_PRINTF("HCCHAR @0x%08lX : 0x%08X\n",
  4215. (unsigned long)addr, DWC_READ_REG32(addr));
  4216. addr = &core_if->host_if->hc_regs[i]->hcsplt;
  4217. DWC_PRINTF("HCSPLT @0x%08lX : 0x%08X\n",
  4218. (unsigned long)addr, DWC_READ_REG32(addr));
  4219. addr = &core_if->host_if->hc_regs[i]->hcint;
  4220. DWC_PRINTF("HCINT @0x%08lX : 0x%08X\n",
  4221. (unsigned long)addr, DWC_READ_REG32(addr));
  4222. addr = &core_if->host_if->hc_regs[i]->hcintmsk;
  4223. DWC_PRINTF("HCINTMSK @0x%08lX : 0x%08X\n",
  4224. (unsigned long)addr, DWC_READ_REG32(addr));
  4225. addr = &core_if->host_if->hc_regs[i]->hctsiz;
  4226. DWC_PRINTF("HCTSIZ @0x%08lX : 0x%08X\n",
  4227. (unsigned long)addr, DWC_READ_REG32(addr));
  4228. addr = &core_if->host_if->hc_regs[i]->hcdma;
  4229. DWC_PRINTF("HCDMA @0x%08lX : 0x%08X\n",
  4230. (unsigned long)addr, DWC_READ_REG32(addr));
  4231. if (core_if->dma_desc_enable) {
  4232. addr = &core_if->host_if->hc_regs[i]->hcdmab;
  4233. DWC_PRINTF("HCDMAB @0x%08lX : 0x%08X\n",
  4234. (unsigned long)addr, DWC_READ_REG32(addr));
  4235. }
  4236. }
  4237. return;
  4238. }
  4239. /**
  4240. * This function reads the core global registers and prints them
  4241. *
  4242. * @param core_if Programming view of DWC_otg controller.
  4243. */
  4244. void dwc_otg_dump_global_registers(dwc_otg_core_if_t * core_if)
  4245. {
  4246. int i, ep_num;
  4247. volatile uint32_t *addr;
  4248. char *txfsiz;
  4249. DWC_PRINTF("Core Global Registers\n");
  4250. addr = &core_if->core_global_regs->gotgctl;
  4251. DWC_PRINTF("GOTGCTL @0x%08lX : 0x%08X\n", (unsigned long)addr,
  4252. DWC_READ_REG32(addr));
  4253. addr = &core_if->core_global_regs->gotgint;
  4254. DWC_PRINTF("GOTGINT @0x%08lX : 0x%08X\n", (unsigned long)addr,
  4255. DWC_READ_REG32(addr));
  4256. addr = &core_if->core_global_regs->gahbcfg;
  4257. DWC_PRINTF("GAHBCFG @0x%08lX : 0x%08X\n", (unsigned long)addr,
  4258. DWC_READ_REG32(addr));
  4259. addr = &core_if->core_global_regs->gusbcfg;
  4260. DWC_PRINTF("GUSBCFG @0x%08lX : 0x%08X\n", (unsigned long)addr,
  4261. DWC_READ_REG32(addr));
  4262. addr = &core_if->core_global_regs->grstctl;
  4263. DWC_PRINTF("GRSTCTL @0x%08lX : 0x%08X\n", (unsigned long)addr,
  4264. DWC_READ_REG32(addr));
  4265. addr = &core_if->core_global_regs->gintsts;
  4266. DWC_PRINTF("GINTSTS @0x%08lX : 0x%08X\n", (unsigned long)addr,
  4267. DWC_READ_REG32(addr));
  4268. addr = &core_if->core_global_regs->gintmsk;
  4269. DWC_PRINTF("GINTMSK @0x%08lX : 0x%08X\n", (unsigned long)addr,
  4270. DWC_READ_REG32(addr));
  4271. addr = &core_if->core_global_regs->grxstsr;
  4272. DWC_PRINTF("GRXSTSR @0x%08lX : 0x%08X\n", (unsigned long)addr,
  4273. DWC_READ_REG32(addr));
  4274. addr = &core_if->core_global_regs->grxfsiz;
  4275. DWC_PRINTF("GRXFSIZ @0x%08lX : 0x%08X\n", (unsigned long)addr,
  4276. DWC_READ_REG32(addr));
  4277. addr = &core_if->core_global_regs->gnptxfsiz;
  4278. DWC_PRINTF("GNPTXFSIZ @0x%08lX : 0x%08X\n", (unsigned long)addr,
  4279. DWC_READ_REG32(addr));
  4280. addr = &core_if->core_global_regs->gnptxsts;
  4281. DWC_PRINTF("GNPTXSTS @0x%08lX : 0x%08X\n", (unsigned long)addr,
  4282. DWC_READ_REG32(addr));
  4283. addr = &core_if->core_global_regs->gi2cctl;
  4284. DWC_PRINTF("GI2CCTL @0x%08lX : 0x%08X\n", (unsigned long)addr,
  4285. DWC_READ_REG32(addr));
  4286. addr = &core_if->core_global_regs->gpvndctl;
  4287. DWC_PRINTF("GPVNDCTL @0x%08lX : 0x%08X\n", (unsigned long)addr,
  4288. DWC_READ_REG32(addr));
  4289. addr = &core_if->core_global_regs->ggpio;
  4290. DWC_PRINTF("GGPIO @0x%08lX : 0x%08X\n", (unsigned long)addr,
  4291. DWC_READ_REG32(addr));
  4292. addr = &core_if->core_global_regs->guid;
  4293. DWC_PRINTF("GUID @0x%08lX : 0x%08X\n",
  4294. (unsigned long)addr, DWC_READ_REG32(addr));
  4295. addr = &core_if->core_global_regs->gsnpsid;
  4296. DWC_PRINTF("GSNPSID @0x%08lX : 0x%08X\n", (unsigned long)addr,
  4297. DWC_READ_REG32(addr));
  4298. addr = &core_if->core_global_regs->ghwcfg1;
  4299. DWC_PRINTF("GHWCFG1 @0x%08lX : 0x%08X\n", (unsigned long)addr,
  4300. DWC_READ_REG32(addr));
  4301. addr = &core_if->core_global_regs->ghwcfg2;
  4302. DWC_PRINTF("GHWCFG2 @0x%08lX : 0x%08X\n", (unsigned long)addr,
  4303. DWC_READ_REG32(addr));
  4304. addr = &core_if->core_global_regs->ghwcfg3;
  4305. DWC_PRINTF("GHWCFG3 @0x%08lX : 0x%08X\n", (unsigned long)addr,
  4306. DWC_READ_REG32(addr));
  4307. addr = &core_if->core_global_regs->ghwcfg4;
  4308. DWC_PRINTF("GHWCFG4 @0x%08lX : 0x%08X\n", (unsigned long)addr,
  4309. DWC_READ_REG32(addr));
  4310. addr = &core_if->core_global_regs->glpmcfg;
  4311. DWC_PRINTF("GLPMCFG @0x%08lX : 0x%08X\n", (unsigned long)addr,
  4312. DWC_READ_REG32(addr));
  4313. addr = &core_if->core_global_regs->gpwrdn;
  4314. DWC_PRINTF("GPWRDN @0x%08lX : 0x%08X\n", (unsigned long)addr,
  4315. DWC_READ_REG32(addr));
  4316. addr = &core_if->core_global_regs->gdfifocfg;
  4317. DWC_PRINTF("GDFIFOCFG @0x%08lX : 0x%08X\n", (unsigned long)addr,
  4318. DWC_READ_REG32(addr));
  4319. addr = &core_if->core_global_regs->adpctl;
  4320. DWC_PRINTF("ADPCTL @0x%08lX : 0x%08X\n", (unsigned long)addr,
  4321. dwc_otg_adp_read_reg(core_if));
  4322. addr = &core_if->core_global_regs->hptxfsiz;
  4323. DWC_PRINTF("HPTXFSIZ @0x%08lX : 0x%08X\n", (unsigned long)addr,
  4324. DWC_READ_REG32(addr));
  4325. if (core_if->en_multiple_tx_fifo == 0) {
  4326. ep_num = core_if->hwcfg4.b.num_dev_perio_in_ep;
  4327. txfsiz = "DPTXFSIZ";
  4328. } else {
  4329. ep_num = core_if->hwcfg4.b.num_in_eps;
  4330. txfsiz = "DIENPTXF";
  4331. }
  4332. for (i = 0; i < ep_num; i++) {
  4333. addr = &core_if->core_global_regs->dtxfsiz[i];
  4334. DWC_PRINTF("%s[%d] @0x%08lX : 0x%08X\n", txfsiz, i + 1,
  4335. (unsigned long)addr, DWC_READ_REG32(addr));
  4336. }
  4337. addr = core_if->pcgcctl;
  4338. DWC_PRINTF("PCGCCTL @0x%08lX : 0x%08X\n", (unsigned long)addr,
  4339. DWC_READ_REG32(addr));
  4340. }
  4341. /**
  4342. * Flush a Tx FIFO.
  4343. *
  4344. * @param core_if Programming view of DWC_otg controller.
  4345. * @param num Tx FIFO to flush.
  4346. */
  4347. void dwc_otg_flush_tx_fifo(dwc_otg_core_if_t * core_if, const int num)
  4348. {
  4349. dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  4350. volatile grstctl_t greset = {.d32 = 0 };
  4351. int count = 0;
  4352. DWC_DEBUGPL((DBG_CIL | DBG_PCDV), "Flush Tx FIFO %d\n", num);
  4353. greset.b.txfflsh = 1;
  4354. greset.b.txfnum = num;
  4355. DWC_WRITE_REG32(&global_regs->grstctl, greset.d32);
  4356. do {
  4357. greset.d32 = DWC_READ_REG32(&global_regs->grstctl);
  4358. if (++count > 10000) {
  4359. DWC_WARN("%s() HANG! GRSTCTL=%0x GNPTXSTS=0x%08x\n",
  4360. __func__, greset.d32,
  4361. DWC_READ_REG32(&global_regs->gnptxsts));
  4362. break;
  4363. }
  4364. dwc_udelay(1);
  4365. } while (greset.b.txfflsh == 1);
  4366. /* Wait for 3 PHY Clocks */
  4367. dwc_udelay(1);
  4368. }
  4369. /**
  4370. * Flush Rx FIFO.
  4371. *
  4372. * @param core_if Programming view of DWC_otg controller.
  4373. */
  4374. void dwc_otg_flush_rx_fifo(dwc_otg_core_if_t * core_if)
  4375. {
  4376. dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  4377. volatile grstctl_t greset = {.d32 = 0 };
  4378. int count = 0;
  4379. DWC_DEBUGPL((DBG_CIL | DBG_PCDV), "%s\n", __func__);
  4380. /*
  4381. *
  4382. */
  4383. greset.b.rxfflsh = 1;
  4384. DWC_WRITE_REG32(&global_regs->grstctl, greset.d32);
  4385. do {
  4386. greset.d32 = DWC_READ_REG32(&global_regs->grstctl);
  4387. if (++count > 10000) {
  4388. DWC_WARN("%s() HANG! GRSTCTL=%0x\n", __func__,
  4389. greset.d32);
  4390. break;
  4391. }
  4392. dwc_udelay(1);
  4393. } while (greset.b.rxfflsh == 1);
  4394. /* Wait for 3 PHY Clocks */
  4395. dwc_udelay(1);
  4396. }
  4397. /**
  4398. * Do core a soft reset of the core. Be careful with this because it
  4399. * resets all the internal state machines of the core.
  4400. */
  4401. void dwc_otg_core_reset(dwc_otg_core_if_t * core_if)
  4402. {
  4403. dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  4404. volatile grstctl_t greset = {.d32 = 0 };
  4405. int count = 0;
  4406. DWC_DEBUGPL(DBG_CILV, "%s\n", __func__);
  4407. /* Wait for AHB master IDLE state. */
  4408. do {
  4409. dwc_udelay(10);
  4410. greset.d32 = DWC_READ_REG32(&global_regs->grstctl);
  4411. if (++count > 100000) {
  4412. DWC_WARN("%s() HANG! AHB Idle GRSTCTL=%0x\n", __func__,
  4413. greset.d32);
  4414. return;
  4415. }
  4416. }
  4417. while (greset.b.ahbidle == 0);
  4418. /* Core Soft Reset */
  4419. count = 0;
  4420. greset.b.csftrst = 1;
  4421. DWC_WRITE_REG32(&global_regs->grstctl, greset.d32);
  4422. do {
  4423. greset.d32 = DWC_READ_REG32(&global_regs->grstctl);
  4424. if (++count > 10000) {
  4425. DWC_WARN("%s() HANG! Soft Reset GRSTCTL=%0x\n",
  4426. __func__, greset.d32);
  4427. break;
  4428. }
  4429. dwc_udelay(1);
  4430. }
  4431. while (greset.b.csftrst == 1);
  4432. /* Wait for 3 PHY Clocks */
  4433. dwc_mdelay(100);
  4434. }
  4435. uint8_t dwc_otg_is_device_mode(dwc_otg_core_if_t * _core_if)
  4436. {
  4437. return (dwc_otg_mode(_core_if) != DWC_HOST_MODE);
  4438. }
  4439. uint8_t dwc_otg_is_host_mode(dwc_otg_core_if_t * _core_if)
  4440. {
  4441. return (dwc_otg_mode(_core_if) == DWC_HOST_MODE);
  4442. }
  4443. /**
  4444. * Register HCD callbacks. The callbacks are used to start and stop
  4445. * the HCD for interrupt processing.
  4446. *
  4447. * @param core_if Programming view of DWC_otg controller.
  4448. * @param cb the HCD callback structure.
  4449. * @param p pointer to be passed to callback function (usb_hcd*).
  4450. */
  4451. void dwc_otg_cil_register_hcd_callbacks(dwc_otg_core_if_t * core_if,
  4452. dwc_otg_cil_callbacks_t * cb, void *p)
  4453. {
  4454. core_if->hcd_cb = cb;
  4455. core_if->hcd_cb_p = p;
  4456. }
  4457. /**
  4458. * Register PCD callbacks. The callbacks are used to start and stop
  4459. * the PCD for interrupt processing.
  4460. *
  4461. * @param core_if Programming view of DWC_otg controller.
  4462. * @param cb the PCD callback structure.
  4463. * @param p pointer to be passed to callback function (pcd*).
  4464. */
  4465. void dwc_otg_cil_register_pcd_callbacks(dwc_otg_core_if_t * core_if,
  4466. dwc_otg_cil_callbacks_t * cb, void *p)
  4467. {
  4468. core_if->pcd_cb = cb;
  4469. core_if->pcd_cb_p = p;
  4470. }
  4471. #ifdef DWC_EN_ISOC
  4472. /**
  4473. * This function writes isoc data per 1 (micro)frame into tx fifo
  4474. *
  4475. * @param core_if Programming view of DWC_otg controller.
  4476. * @param ep The EP to start the transfer on.
  4477. *
  4478. */
  4479. void write_isoc_frame_data(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  4480. {
  4481. dwc_otg_dev_in_ep_regs_t *ep_regs;
  4482. dtxfsts_data_t txstatus = {.d32 = 0 };
  4483. uint32_t len = 0;
  4484. uint32_t dwords;
  4485. ep->xfer_len = ep->data_per_frame;
  4486. ep->xfer_count = 0;
  4487. ep_regs = core_if->dev_if->in_ep_regs[ep->num];
  4488. len = ep->xfer_len - ep->xfer_count;
  4489. if (len > ep->maxpacket) {
  4490. len = ep->maxpacket;
  4491. }
  4492. dwords = (len + 3) / 4;
  4493. /* While there is space in the queue and space in the FIFO and
  4494. * More data to tranfer, Write packets to the Tx FIFO */
  4495. txstatus.d32 =
  4496. DWC_READ_REG32(&core_if->dev_if->in_ep_regs[ep->num]->dtxfsts);
  4497. DWC_DEBUGPL(DBG_PCDV, "b4 dtxfsts[%d]=0x%08x\n", ep->num, txstatus.d32);
  4498. while (txstatus.b.txfspcavail > dwords &&
  4499. ep->xfer_count < ep->xfer_len && ep->xfer_len != 0) {
  4500. /* Write the FIFO */
  4501. dwc_otg_ep_write_packet(core_if, ep, 0);
  4502. len = ep->xfer_len - ep->xfer_count;
  4503. if (len > ep->maxpacket) {
  4504. len = ep->maxpacket;
  4505. }
  4506. dwords = (len + 3) / 4;
  4507. txstatus.d32 =
  4508. DWC_READ_REG32(&core_if->dev_if->
  4509. in_ep_regs[ep->num]->dtxfsts);
  4510. DWC_DEBUGPL(DBG_PCDV, "dtxfsts[%d]=0x%08x\n", ep->num,
  4511. txstatus.d32);
  4512. }
  4513. }
  4514. /**
  4515. * This function initializes a descriptor chain for Isochronous transfer
  4516. *
  4517. * @param core_if Programming view of DWC_otg controller.
  4518. * @param ep The EP to start the transfer on.
  4519. *
  4520. */
  4521. void dwc_otg_iso_ep_start_frm_transfer(dwc_otg_core_if_t * core_if,
  4522. dwc_ep_t * ep)
  4523. {
  4524. deptsiz_data_t deptsiz = {.d32 = 0 };
  4525. depctl_data_t depctl = {.d32 = 0 };
  4526. dsts_data_t dsts = {.d32 = 0 };
  4527. volatile uint32_t *addr;
  4528. if (ep->is_in) {
  4529. addr = &core_if->dev_if->in_ep_regs[ep->num]->diepctl;
  4530. } else {
  4531. addr = &core_if->dev_if->out_ep_regs[ep->num]->doepctl;
  4532. }
  4533. ep->xfer_len = ep->data_per_frame;
  4534. ep->xfer_count = 0;
  4535. ep->xfer_buff = ep->cur_pkt_addr;
  4536. ep->dma_addr = ep->cur_pkt_dma_addr;
  4537. if (ep->is_in) {
  4538. /* Program the transfer size and packet count
  4539. * as follows: xfersize = N * maxpacket +
  4540. * short_packet pktcnt = N + (short_packet
  4541. * exist ? 1 : 0)
  4542. */
  4543. deptsiz.b.xfersize = ep->xfer_len;
  4544. deptsiz.b.pktcnt =
  4545. (ep->xfer_len - 1 + ep->maxpacket) / ep->maxpacket;
  4546. deptsiz.b.mc = deptsiz.b.pktcnt;
  4547. DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[ep->num]->dieptsiz,
  4548. deptsiz.d32);
  4549. /* Write the DMA register */
  4550. if (core_if->dma_enable) {
  4551. DWC_WRITE_REG32(&
  4552. (core_if->dev_if->in_ep_regs[ep->num]->
  4553. diepdma), (uint32_t) ep->dma_addr);
  4554. }
  4555. } else {
  4556. deptsiz.b.pktcnt =
  4557. (ep->xfer_len + (ep->maxpacket - 1)) / ep->maxpacket;
  4558. deptsiz.b.xfersize = deptsiz.b.pktcnt * ep->maxpacket;
  4559. DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[ep->num]->
  4560. doeptsiz, deptsiz.d32);
  4561. if (core_if->dma_enable) {
  4562. DWC_WRITE_REG32(&
  4563. (core_if->dev_if->out_ep_regs[ep->num]->
  4564. doepdma), (uint32_t) ep->dma_addr);
  4565. }
  4566. }
  4567. /** Enable endpoint, clear nak */
  4568. depctl.d32 = 0;
  4569. if (ep->bInterval == 1) {
  4570. dsts.d32 =
  4571. DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  4572. ep->next_frame = dsts.b.soffn + ep->bInterval;
  4573. if (ep->next_frame & 0x1) {
  4574. depctl.b.setd1pid = 1;
  4575. } else {
  4576. depctl.b.setd0pid = 1;
  4577. }
  4578. } else {
  4579. ep->next_frame += ep->bInterval;
  4580. if (ep->next_frame & 0x1) {
  4581. depctl.b.setd1pid = 1;
  4582. } else {
  4583. depctl.b.setd0pid = 1;
  4584. }
  4585. }
  4586. depctl.b.epena = 1;
  4587. depctl.b.cnak = 1;
  4588. DWC_MODIFY_REG32(addr, 0, depctl.d32);
  4589. depctl.d32 = DWC_READ_REG32(addr);
  4590. if (ep->is_in && core_if->dma_enable == 0) {
  4591. write_isoc_frame_data(core_if, ep);
  4592. }
  4593. DWC_WMB();
  4594. }
  4595. #endif /* DWC_EN_ISOC */
  4596. static void dwc_otg_set_uninitialized(int32_t * p, int size)
  4597. {
  4598. int i;
  4599. for (i = 0; i < size; i++) {
  4600. p[i] = -1;
  4601. }
  4602. }
  4603. static int dwc_otg_param_initialized(int32_t val)
  4604. {
  4605. return val != -1;
  4606. }
  4607. static int dwc_otg_setup_params(dwc_otg_core_if_t * core_if)
  4608. {
  4609. int i;
  4610. core_if->core_params = DWC_ALLOC(sizeof(*core_if->core_params));
  4611. if (!core_if->core_params) {
  4612. return -DWC_E_NO_MEMORY;
  4613. }
  4614. dwc_otg_set_uninitialized((int32_t *) core_if->core_params,
  4615. sizeof(*core_if->core_params) /
  4616. sizeof(int32_t));
  4617. DWC_PRINTF("Setting default values for core params\n");
  4618. dwc_otg_set_param_otg_cap(core_if, dwc_param_otg_cap_default);
  4619. dwc_otg_set_param_dma_enable(core_if, dwc_param_dma_enable_default);
  4620. dwc_otg_set_param_dma_desc_enable(core_if,
  4621. dwc_param_dma_desc_enable_default);
  4622. dwc_otg_set_param_opt(core_if, dwc_param_opt_default);
  4623. dwc_otg_set_param_dma_burst_size(core_if,
  4624. dwc_param_dma_burst_size_default);
  4625. dwc_otg_set_param_host_support_fs_ls_low_power(core_if,
  4626. dwc_param_host_support_fs_ls_low_power_default);
  4627. dwc_otg_set_param_enable_dynamic_fifo(core_if,
  4628. dwc_param_enable_dynamic_fifo_default);
  4629. dwc_otg_set_param_data_fifo_size(core_if,
  4630. dwc_param_data_fifo_size_default);
  4631. dwc_otg_set_param_dev_rx_fifo_size(core_if,
  4632. dwc_param_dev_rx_fifo_size_default);
  4633. dwc_otg_set_param_dev_nperio_tx_fifo_size(core_if,
  4634. dwc_param_dev_nperio_tx_fifo_size_default);
  4635. dwc_otg_set_param_host_rx_fifo_size(core_if,
  4636. dwc_param_host_rx_fifo_size_default);
  4637. dwc_otg_set_param_host_nperio_tx_fifo_size(core_if,
  4638. dwc_param_host_nperio_tx_fifo_size_default);
  4639. dwc_otg_set_param_host_perio_tx_fifo_size(core_if,
  4640. dwc_param_host_perio_tx_fifo_size_default);
  4641. dwc_otg_set_param_max_transfer_size(core_if,
  4642. dwc_param_max_transfer_size_default);
  4643. dwc_otg_set_param_max_packet_count(core_if,
  4644. dwc_param_max_packet_count_default);
  4645. dwc_otg_set_param_host_channels(core_if,
  4646. dwc_param_host_channels_default);
  4647. dwc_otg_set_param_dev_endpoints(core_if,
  4648. dwc_param_dev_endpoints_default);
  4649. dwc_otg_set_param_phy_type(core_if, dwc_param_phy_type_default);
  4650. dwc_otg_set_param_speed(core_if, dwc_param_speed_default);
  4651. dwc_otg_set_param_host_ls_low_power_phy_clk(core_if,
  4652. dwc_param_host_ls_low_power_phy_clk_default);
  4653. dwc_otg_set_param_phy_ulpi_ddr(core_if, dwc_param_phy_ulpi_ddr_default);
  4654. dwc_otg_set_param_phy_ulpi_ext_vbus(core_if,
  4655. dwc_param_phy_ulpi_ext_vbus_default);
  4656. dwc_otg_set_param_phy_utmi_width(core_if,
  4657. dwc_param_phy_utmi_width_default);
  4658. dwc_otg_set_param_ts_dline(core_if, dwc_param_ts_dline_default);
  4659. dwc_otg_set_param_i2c_enable(core_if, dwc_param_i2c_enable_default);
  4660. dwc_otg_set_param_ulpi_fs_ls(core_if, dwc_param_ulpi_fs_ls_default);
  4661. dwc_otg_set_param_en_multiple_tx_fifo(core_if,
  4662. dwc_param_en_multiple_tx_fifo_default);
  4663. for (i = 0; i < 15; i++) {
  4664. dwc_otg_set_param_dev_perio_tx_fifo_size(core_if,
  4665. dwc_param_dev_perio_tx_fifo_size_default,
  4666. i);
  4667. }
  4668. for (i = 0; i < 15; i++) {
  4669. dwc_otg_set_param_dev_tx_fifo_size(core_if,
  4670. dwc_param_dev_tx_fifo_size_default,
  4671. i);
  4672. }
  4673. dwc_otg_set_param_thr_ctl(core_if, dwc_param_thr_ctl_default);
  4674. dwc_otg_set_param_mpi_enable(core_if, dwc_param_mpi_enable_default);
  4675. dwc_otg_set_param_pti_enable(core_if, dwc_param_pti_enable_default);
  4676. dwc_otg_set_param_lpm_enable(core_if, dwc_param_lpm_enable_default);
  4677. dwc_otg_set_param_ic_usb_cap(core_if, dwc_param_ic_usb_cap_default);
  4678. dwc_otg_set_param_tx_thr_length(core_if,
  4679. dwc_param_tx_thr_length_default);
  4680. dwc_otg_set_param_rx_thr_length(core_if,
  4681. dwc_param_rx_thr_length_default);
  4682. dwc_otg_set_param_ahb_thr_ratio(core_if,
  4683. dwc_param_ahb_thr_ratio_default);
  4684. dwc_otg_set_param_power_down(core_if, dwc_param_power_down_default);
  4685. dwc_otg_set_param_reload_ctl(core_if, dwc_param_reload_ctl_default);
  4686. dwc_otg_set_param_dev_out_nak(core_if, dwc_param_dev_out_nak_default);
  4687. dwc_otg_set_param_cont_on_bna(core_if, dwc_param_cont_on_bna_default);
  4688. dwc_otg_set_param_ahb_single(core_if, dwc_param_ahb_single_default);
  4689. dwc_otg_set_param_otg_ver(core_if, dwc_param_otg_ver_default);
  4690. dwc_otg_set_param_adp_enable(core_if, dwc_param_adp_enable_default);
  4691. return 0;
  4692. }
  4693. uint8_t dwc_otg_is_dma_enable(dwc_otg_core_if_t * core_if)
  4694. {
  4695. return core_if->dma_enable;
  4696. }
  4697. /* Checks if the parameter is outside of its valid range of values */
  4698. #define DWC_OTG_PARAM_TEST(_param_, _low_, _high_) \
  4699. (((_param_) < (_low_)) || \
  4700. ((_param_) > (_high_)))
  4701. /* Parameter access functions */
  4702. int dwc_otg_set_param_otg_cap(dwc_otg_core_if_t * core_if, int32_t val)
  4703. {
  4704. int valid;
  4705. int retval = 0;
  4706. if (DWC_OTG_PARAM_TEST(val, 0, 2)) {
  4707. DWC_WARN("Wrong value for otg_cap parameter\n");
  4708. DWC_WARN("otg_cap parameter must be 0,1 or 2\n");
  4709. retval = -DWC_E_INVALID;
  4710. goto out;
  4711. }
  4712. valid = 1;
  4713. switch (val) {
  4714. case DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE:
  4715. if (core_if->hwcfg2.b.op_mode !=
  4716. DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG)
  4717. valid = 0;
  4718. break;
  4719. case DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE:
  4720. if ((core_if->hwcfg2.b.op_mode !=
  4721. DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG)
  4722. && (core_if->hwcfg2.b.op_mode !=
  4723. DWC_HWCFG2_OP_MODE_SRP_ONLY_CAPABLE_OTG)
  4724. && (core_if->hwcfg2.b.op_mode !=
  4725. DWC_HWCFG2_OP_MODE_SRP_CAPABLE_DEVICE)
  4726. && (core_if->hwcfg2.b.op_mode !=
  4727. DWC_HWCFG2_OP_MODE_SRP_CAPABLE_HOST)) {
  4728. valid = 0;
  4729. }
  4730. break;
  4731. case DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE:
  4732. /* always valid */
  4733. break;
  4734. }
  4735. if (!valid) {
  4736. if (dwc_otg_param_initialized(core_if->core_params->otg_cap)) {
  4737. DWC_ERROR
  4738. ("%d invalid for otg_cap paremter. Check HW configuration.\n",
  4739. val);
  4740. }
  4741. val =
  4742. (((core_if->hwcfg2.b.op_mode ==
  4743. DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG)
  4744. || (core_if->hwcfg2.b.op_mode ==
  4745. DWC_HWCFG2_OP_MODE_SRP_ONLY_CAPABLE_OTG)
  4746. || (core_if->hwcfg2.b.op_mode ==
  4747. DWC_HWCFG2_OP_MODE_SRP_CAPABLE_DEVICE)
  4748. || (core_if->hwcfg2.b.op_mode ==
  4749. DWC_HWCFG2_OP_MODE_SRP_CAPABLE_HOST)) ?
  4750. DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE :
  4751. DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
  4752. retval = -DWC_E_INVALID;
  4753. }
  4754. core_if->core_params->otg_cap = val;
  4755. out:
  4756. return retval;
  4757. }
  4758. int32_t dwc_otg_get_param_otg_cap(dwc_otg_core_if_t * core_if)
  4759. {
  4760. return core_if->core_params->otg_cap;
  4761. }
  4762. int dwc_otg_set_param_opt(dwc_otg_core_if_t * core_if, int32_t val)
  4763. {
  4764. if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  4765. DWC_WARN("Wrong value for opt parameter\n");
  4766. return -DWC_E_INVALID;
  4767. }
  4768. core_if->core_params->opt = val;
  4769. return 0;
  4770. }
  4771. int32_t dwc_otg_get_param_opt(dwc_otg_core_if_t * core_if)
  4772. {
  4773. return core_if->core_params->opt;
  4774. }
  4775. int dwc_otg_set_param_dma_enable(dwc_otg_core_if_t * core_if, int32_t val)
  4776. {
  4777. int retval = 0;
  4778. if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  4779. DWC_WARN("Wrong value for dma enable\n");
  4780. return -DWC_E_INVALID;
  4781. }
  4782. if ((val == 1) && (core_if->hwcfg2.b.architecture == 0)) {
  4783. if (dwc_otg_param_initialized(core_if->core_params->dma_enable)) {
  4784. DWC_ERROR
  4785. ("%d invalid for dma_enable paremter. Check HW configuration.\n",
  4786. val);
  4787. }
  4788. val = 0;
  4789. retval = -DWC_E_INVALID;
  4790. }
  4791. core_if->core_params->dma_enable = val;
  4792. if (val == 0) {
  4793. dwc_otg_set_param_dma_desc_enable(core_if, 0);
  4794. }
  4795. return retval;
  4796. }
  4797. int32_t dwc_otg_get_param_dma_enable(dwc_otg_core_if_t * core_if)
  4798. {
  4799. return core_if->core_params->dma_enable;
  4800. }
  4801. int dwc_otg_set_param_dma_desc_enable(dwc_otg_core_if_t * core_if, int32_t val)
  4802. {
  4803. int retval = 0;
  4804. if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  4805. DWC_WARN("Wrong value for dma_enable\n");
  4806. DWC_WARN("dma_desc_enable must be 0 or 1\n");
  4807. return -DWC_E_INVALID;
  4808. }
  4809. if ((val == 1)
  4810. && ((dwc_otg_get_param_dma_enable(core_if) == 0)
  4811. || (core_if->hwcfg4.b.desc_dma == 0))) {
  4812. if (dwc_otg_param_initialized
  4813. (core_if->core_params->dma_desc_enable)) {
  4814. DWC_ERROR
  4815. ("%d invalid for dma_desc_enable paremter. Check HW configuration.\n",
  4816. val);
  4817. }
  4818. val = 0;
  4819. retval = -DWC_E_INVALID;
  4820. }
  4821. core_if->core_params->dma_desc_enable = val;
  4822. return retval;
  4823. }
  4824. int32_t dwc_otg_get_param_dma_desc_enable(dwc_otg_core_if_t * core_if)
  4825. {
  4826. return core_if->core_params->dma_desc_enable;
  4827. }
  4828. int dwc_otg_set_param_host_support_fs_ls_low_power(dwc_otg_core_if_t * core_if,
  4829. int32_t val)
  4830. {
  4831. if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  4832. DWC_WARN("Wrong value for host_support_fs_low_power\n");
  4833. DWC_WARN("host_support_fs_low_power must be 0 or 1\n");
  4834. return -DWC_E_INVALID;
  4835. }
  4836. core_if->core_params->host_support_fs_ls_low_power = val;
  4837. return 0;
  4838. }
  4839. int32_t dwc_otg_get_param_host_support_fs_ls_low_power(dwc_otg_core_if_t *
  4840. core_if)
  4841. {
  4842. return core_if->core_params->host_support_fs_ls_low_power;
  4843. }
  4844. int dwc_otg_set_param_enable_dynamic_fifo(dwc_otg_core_if_t * core_if,
  4845. int32_t val)
  4846. {
  4847. int retval = 0;
  4848. if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  4849. DWC_WARN("Wrong value for enable_dynamic_fifo\n");
  4850. DWC_WARN("enable_dynamic_fifo must be 0 or 1\n");
  4851. return -DWC_E_INVALID;
  4852. }
  4853. if ((val == 1) && (core_if->hwcfg2.b.dynamic_fifo == 0)) {
  4854. if (dwc_otg_param_initialized
  4855. (core_if->core_params->enable_dynamic_fifo)) {
  4856. DWC_ERROR
  4857. ("%d invalid for enable_dynamic_fifo paremter. Check HW configuration.\n",
  4858. val);
  4859. }
  4860. val = 0;
  4861. retval = -DWC_E_INVALID;
  4862. }
  4863. core_if->core_params->enable_dynamic_fifo = val;
  4864. return retval;
  4865. }
  4866. int32_t dwc_otg_get_param_enable_dynamic_fifo(dwc_otg_core_if_t * core_if)
  4867. {
  4868. return core_if->core_params->enable_dynamic_fifo;
  4869. }
  4870. int dwc_otg_set_param_data_fifo_size(dwc_otg_core_if_t * core_if, int32_t val)
  4871. {
  4872. int retval = 0;
  4873. if (DWC_OTG_PARAM_TEST(val, 32, 32768)) {
  4874. DWC_WARN("Wrong value for data_fifo_size\n");
  4875. DWC_WARN("data_fifo_size must be 32-32768\n");
  4876. return -DWC_E_INVALID;
  4877. }
  4878. if (val > core_if->hwcfg3.b.dfifo_depth) {
  4879. if (dwc_otg_param_initialized
  4880. (core_if->core_params->data_fifo_size)) {
  4881. DWC_ERROR
  4882. ("%d invalid for data_fifo_size parameter. Check HW configuration.\n",
  4883. val);
  4884. }
  4885. val = core_if->hwcfg3.b.dfifo_depth;
  4886. retval = -DWC_E_INVALID;
  4887. }
  4888. core_if->core_params->data_fifo_size = val;
  4889. return retval;
  4890. }
  4891. int32_t dwc_otg_get_param_data_fifo_size(dwc_otg_core_if_t * core_if)
  4892. {
  4893. return core_if->core_params->data_fifo_size;
  4894. }
  4895. int dwc_otg_set_param_dev_rx_fifo_size(dwc_otg_core_if_t * core_if, int32_t val)
  4896. {
  4897. int retval = 0;
  4898. if (DWC_OTG_PARAM_TEST(val, 16, 32768)) {
  4899. DWC_WARN("Wrong value for dev_rx_fifo_size\n");
  4900. DWC_WARN("dev_rx_fifo_size must be 16-32768\n");
  4901. return -DWC_E_INVALID;
  4902. }
  4903. if (val > DWC_READ_REG32(&core_if->core_global_regs->grxfsiz)) {
  4904. if (dwc_otg_param_initialized(core_if->core_params->dev_rx_fifo_size)) {
  4905. DWC_WARN("%d invalid for dev_rx_fifo_size parameter\n", val);
  4906. }
  4907. val = DWC_READ_REG32(&core_if->core_global_regs->grxfsiz);
  4908. retval = -DWC_E_INVALID;
  4909. }
  4910. core_if->core_params->dev_rx_fifo_size = val;
  4911. return retval;
  4912. }
  4913. int32_t dwc_otg_get_param_dev_rx_fifo_size(dwc_otg_core_if_t * core_if)
  4914. {
  4915. return core_if->core_params->dev_rx_fifo_size;
  4916. }
  4917. int dwc_otg_set_param_dev_nperio_tx_fifo_size(dwc_otg_core_if_t * core_if,
  4918. int32_t val)
  4919. {
  4920. int retval = 0;
  4921. if (DWC_OTG_PARAM_TEST(val, 16, 32768)) {
  4922. DWC_WARN("Wrong value for dev_nperio_tx_fifo\n");
  4923. DWC_WARN("dev_nperio_tx_fifo must be 16-32768\n");
  4924. return -DWC_E_INVALID;
  4925. }
  4926. if (val > (DWC_READ_REG32(&core_if->core_global_regs->gnptxfsiz) >> 16)) {
  4927. if (dwc_otg_param_initialized
  4928. (core_if->core_params->dev_nperio_tx_fifo_size)) {
  4929. DWC_ERROR
  4930. ("%d invalid for dev_nperio_tx_fifo_size. Check HW configuration.\n",
  4931. val);
  4932. }
  4933. val =
  4934. (DWC_READ_REG32(&core_if->core_global_regs->gnptxfsiz) >>
  4935. 16);
  4936. retval = -DWC_E_INVALID;
  4937. }
  4938. core_if->core_params->dev_nperio_tx_fifo_size = val;
  4939. return retval;
  4940. }
  4941. int32_t dwc_otg_get_param_dev_nperio_tx_fifo_size(dwc_otg_core_if_t * core_if)
  4942. {
  4943. return core_if->core_params->dev_nperio_tx_fifo_size;
  4944. }
  4945. int dwc_otg_set_param_host_rx_fifo_size(dwc_otg_core_if_t * core_if,
  4946. int32_t val)
  4947. {
  4948. int retval = 0;
  4949. if (DWC_OTG_PARAM_TEST(val, 16, 32768)) {
  4950. DWC_WARN("Wrong value for host_rx_fifo_size\n");
  4951. DWC_WARN("host_rx_fifo_size must be 16-32768\n");
  4952. return -DWC_E_INVALID;
  4953. }
  4954. if (val > DWC_READ_REG32(&core_if->core_global_regs->grxfsiz)) {
  4955. if (dwc_otg_param_initialized
  4956. (core_if->core_params->host_rx_fifo_size)) {
  4957. DWC_ERROR
  4958. ("%d invalid for host_rx_fifo_size. Check HW configuration.\n",
  4959. val);
  4960. }
  4961. val = DWC_READ_REG32(&core_if->core_global_regs->grxfsiz);
  4962. retval = -DWC_E_INVALID;
  4963. }
  4964. core_if->core_params->host_rx_fifo_size = val;
  4965. return retval;
  4966. }
  4967. int32_t dwc_otg_get_param_host_rx_fifo_size(dwc_otg_core_if_t * core_if)
  4968. {
  4969. return core_if->core_params->host_rx_fifo_size;
  4970. }
  4971. int dwc_otg_set_param_host_nperio_tx_fifo_size(dwc_otg_core_if_t * core_if,
  4972. int32_t val)
  4973. {
  4974. int retval = 0;
  4975. if (DWC_OTG_PARAM_TEST(val, 16, 32768)) {
  4976. DWC_WARN("Wrong value for host_nperio_tx_fifo_size\n");
  4977. DWC_WARN("host_nperio_tx_fifo_size must be 16-32768\n");
  4978. return -DWC_E_INVALID;
  4979. }
  4980. if (val > (DWC_READ_REG32(&core_if->core_global_regs->gnptxfsiz) >> 16)) {
  4981. if (dwc_otg_param_initialized
  4982. (core_if->core_params->host_nperio_tx_fifo_size)) {
  4983. DWC_ERROR
  4984. ("%d invalid for host_nperio_tx_fifo_size. Check HW configuration.\n",
  4985. val);
  4986. }
  4987. val =
  4988. (DWC_READ_REG32(&core_if->core_global_regs->gnptxfsiz) >>
  4989. 16);
  4990. retval = -DWC_E_INVALID;
  4991. }
  4992. core_if->core_params->host_nperio_tx_fifo_size = val;
  4993. return retval;
  4994. }
  4995. int32_t dwc_otg_get_param_host_nperio_tx_fifo_size(dwc_otg_core_if_t * core_if)
  4996. {
  4997. return core_if->core_params->host_nperio_tx_fifo_size;
  4998. }
  4999. int dwc_otg_set_param_host_perio_tx_fifo_size(dwc_otg_core_if_t * core_if,
  5000. int32_t val)
  5001. {
  5002. int retval = 0;
  5003. if (DWC_OTG_PARAM_TEST(val, 16, 32768)) {
  5004. DWC_WARN("Wrong value for host_perio_tx_fifo_size\n");
  5005. DWC_WARN("host_perio_tx_fifo_size must be 16-32768\n");
  5006. return -DWC_E_INVALID;
  5007. }
  5008. if (val >
  5009. ((core_if->hptxfsiz.d32)>> 16)) {
  5010. if (dwc_otg_param_initialized
  5011. (core_if->core_params->host_perio_tx_fifo_size)) {
  5012. DWC_ERROR
  5013. ("%d invalid for host_perio_tx_fifo_size. Check HW configuration.\n",
  5014. val);
  5015. }
  5016. val = (core_if->hptxfsiz.d32) >> 16;
  5017. retval = -DWC_E_INVALID;
  5018. }
  5019. core_if->core_params->host_perio_tx_fifo_size = val;
  5020. return retval;
  5021. }
  5022. int32_t dwc_otg_get_param_host_perio_tx_fifo_size(dwc_otg_core_if_t * core_if)
  5023. {
  5024. return core_if->core_params->host_perio_tx_fifo_size;
  5025. }
  5026. int dwc_otg_set_param_max_transfer_size(dwc_otg_core_if_t * core_if,
  5027. int32_t val)
  5028. {
  5029. int retval = 0;
  5030. if (DWC_OTG_PARAM_TEST(val, 2047, 524288)) {
  5031. DWC_WARN("Wrong value for max_transfer_size\n");
  5032. DWC_WARN("max_transfer_size must be 2047-524288\n");
  5033. return -DWC_E_INVALID;
  5034. }
  5035. if (val >= (1 << (core_if->hwcfg3.b.xfer_size_cntr_width + 11))) {
  5036. if (dwc_otg_param_initialized
  5037. (core_if->core_params->max_transfer_size)) {
  5038. DWC_ERROR
  5039. ("%d invalid for max_transfer_size. Check HW configuration.\n",
  5040. val);
  5041. }
  5042. val =
  5043. ((1 << (core_if->hwcfg3.b.packet_size_cntr_width + 11)) -
  5044. 1);
  5045. retval = -DWC_E_INVALID;
  5046. }
  5047. core_if->core_params->max_transfer_size = val;
  5048. return retval;
  5049. }
  5050. int32_t dwc_otg_get_param_max_transfer_size(dwc_otg_core_if_t * core_if)
  5051. {
  5052. return core_if->core_params->max_transfer_size;
  5053. }
  5054. int dwc_otg_set_param_max_packet_count(dwc_otg_core_if_t * core_if, int32_t val)
  5055. {
  5056. int retval = 0;
  5057. if (DWC_OTG_PARAM_TEST(val, 15, 511)) {
  5058. DWC_WARN("Wrong value for max_packet_count\n");
  5059. DWC_WARN("max_packet_count must be 15-511\n");
  5060. return -DWC_E_INVALID;
  5061. }
  5062. if (val > (1 << (core_if->hwcfg3.b.packet_size_cntr_width + 4))) {
  5063. if (dwc_otg_param_initialized
  5064. (core_if->core_params->max_packet_count)) {
  5065. DWC_ERROR
  5066. ("%d invalid for max_packet_count. Check HW configuration.\n",
  5067. val);
  5068. }
  5069. val =
  5070. ((1 << (core_if->hwcfg3.b.packet_size_cntr_width + 4)) - 1);
  5071. retval = -DWC_E_INVALID;
  5072. }
  5073. core_if->core_params->max_packet_count = val;
  5074. return retval;
  5075. }
  5076. int32_t dwc_otg_get_param_max_packet_count(dwc_otg_core_if_t * core_if)
  5077. {
  5078. return core_if->core_params->max_packet_count;
  5079. }
  5080. int dwc_otg_set_param_host_channels(dwc_otg_core_if_t * core_if, int32_t val)
  5081. {
  5082. int retval = 0;
  5083. if (DWC_OTG_PARAM_TEST(val, 1, 16)) {
  5084. DWC_WARN("Wrong value for host_channels\n");
  5085. DWC_WARN("host_channels must be 1-16\n");
  5086. return -DWC_E_INVALID;
  5087. }
  5088. if (val > (core_if->hwcfg2.b.num_host_chan + 1)) {
  5089. if (dwc_otg_param_initialized
  5090. (core_if->core_params->host_channels)) {
  5091. DWC_ERROR
  5092. ("%d invalid for host_channels. Check HW configurations.\n",
  5093. val);
  5094. }
  5095. val = (core_if->hwcfg2.b.num_host_chan + 1);
  5096. retval = -DWC_E_INVALID;
  5097. }
  5098. core_if->core_params->host_channels = val;
  5099. return retval;
  5100. }
  5101. int32_t dwc_otg_get_param_host_channels(dwc_otg_core_if_t * core_if)
  5102. {
  5103. return core_if->core_params->host_channels;
  5104. }
  5105. int dwc_otg_set_param_dev_endpoints(dwc_otg_core_if_t * core_if, int32_t val)
  5106. {
  5107. int retval = 0;
  5108. if (DWC_OTG_PARAM_TEST(val, 1, 15)) {
  5109. DWC_WARN("Wrong value for dev_endpoints\n");
  5110. DWC_WARN("dev_endpoints must be 1-15\n");
  5111. return -DWC_E_INVALID;
  5112. }
  5113. if (val > (core_if->hwcfg2.b.num_dev_ep)) {
  5114. if (dwc_otg_param_initialized
  5115. (core_if->core_params->dev_endpoints)) {
  5116. DWC_ERROR
  5117. ("%d invalid for dev_endpoints. Check HW configurations.\n",
  5118. val);
  5119. }
  5120. val = core_if->hwcfg2.b.num_dev_ep;
  5121. retval = -DWC_E_INVALID;
  5122. }
  5123. core_if->core_params->dev_endpoints = val;
  5124. return retval;
  5125. }
  5126. int32_t dwc_otg_get_param_dev_endpoints(dwc_otg_core_if_t * core_if)
  5127. {
  5128. return core_if->core_params->dev_endpoints;
  5129. }
  5130. int dwc_otg_set_param_phy_type(dwc_otg_core_if_t * core_if, int32_t val)
  5131. {
  5132. int retval = 0;
  5133. int valid = 0;
  5134. if (DWC_OTG_PARAM_TEST(val, 0, 2)) {
  5135. DWC_WARN("Wrong value for phy_type\n");
  5136. DWC_WARN("phy_type must be 0,1 or 2\n");
  5137. return -DWC_E_INVALID;
  5138. }
  5139. #ifndef NO_FS_PHY_HW_CHECKS
  5140. if ((val == DWC_PHY_TYPE_PARAM_UTMI) &&
  5141. ((core_if->hwcfg2.b.hs_phy_type == 1) ||
  5142. (core_if->hwcfg2.b.hs_phy_type == 3))) {
  5143. valid = 1;
  5144. } else if ((val == DWC_PHY_TYPE_PARAM_ULPI) &&
  5145. ((core_if->hwcfg2.b.hs_phy_type == 2) ||
  5146. (core_if->hwcfg2.b.hs_phy_type == 3))) {
  5147. valid = 1;
  5148. } else if ((val == DWC_PHY_TYPE_PARAM_FS) &&
  5149. (core_if->hwcfg2.b.fs_phy_type == 1)) {
  5150. valid = 1;
  5151. }
  5152. if (!valid) {
  5153. if (dwc_otg_param_initialized(core_if->core_params->phy_type)) {
  5154. DWC_ERROR
  5155. ("%d invalid for phy_type. Check HW configurations.\n",
  5156. val);
  5157. }
  5158. if (core_if->hwcfg2.b.hs_phy_type) {
  5159. if ((core_if->hwcfg2.b.hs_phy_type == 3) ||
  5160. (core_if->hwcfg2.b.hs_phy_type == 1)) {
  5161. val = DWC_PHY_TYPE_PARAM_UTMI;
  5162. } else {
  5163. val = DWC_PHY_TYPE_PARAM_ULPI;
  5164. }
  5165. }
  5166. retval = -DWC_E_INVALID;
  5167. }
  5168. #endif
  5169. core_if->core_params->phy_type = val;
  5170. return retval;
  5171. }
  5172. int32_t dwc_otg_get_param_phy_type(dwc_otg_core_if_t * core_if)
  5173. {
  5174. return core_if->core_params->phy_type;
  5175. }
  5176. int dwc_otg_set_param_speed(dwc_otg_core_if_t * core_if, int32_t val)
  5177. {
  5178. int retval = 0;
  5179. if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  5180. DWC_WARN("Wrong value for speed parameter\n");
  5181. DWC_WARN("max_speed parameter must be 0 or 1\n");
  5182. return -DWC_E_INVALID;
  5183. }
  5184. if ((val == 0)
  5185. && dwc_otg_get_param_phy_type(core_if) == DWC_PHY_TYPE_PARAM_FS) {
  5186. if (dwc_otg_param_initialized(core_if->core_params->speed)) {
  5187. DWC_ERROR
  5188. ("%d invalid for speed paremter. Check HW configuration.\n",
  5189. val);
  5190. }
  5191. val =
  5192. (dwc_otg_get_param_phy_type(core_if) ==
  5193. DWC_PHY_TYPE_PARAM_FS ? 1 : 0);
  5194. retval = -DWC_E_INVALID;
  5195. }
  5196. core_if->core_params->speed = val;
  5197. return retval;
  5198. }
  5199. int32_t dwc_otg_get_param_speed(dwc_otg_core_if_t * core_if)
  5200. {
  5201. return core_if->core_params->speed;
  5202. }
  5203. int dwc_otg_set_param_host_ls_low_power_phy_clk(dwc_otg_core_if_t * core_if,
  5204. int32_t val)
  5205. {
  5206. int retval = 0;
  5207. if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  5208. DWC_WARN
  5209. ("Wrong value for host_ls_low_power_phy_clk parameter\n");
  5210. DWC_WARN("host_ls_low_power_phy_clk must be 0 or 1\n");
  5211. return -DWC_E_INVALID;
  5212. }
  5213. if ((val == DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ)
  5214. && (dwc_otg_get_param_phy_type(core_if) == DWC_PHY_TYPE_PARAM_FS)) {
  5215. if (dwc_otg_param_initialized
  5216. (core_if->core_params->host_ls_low_power_phy_clk)) {
  5217. DWC_ERROR
  5218. ("%d invalid for host_ls_low_power_phy_clk. Check HW configuration.\n",
  5219. val);
  5220. }
  5221. val =
  5222. (dwc_otg_get_param_phy_type(core_if) ==
  5223. DWC_PHY_TYPE_PARAM_FS) ?
  5224. DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ :
  5225. DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ;
  5226. retval = -DWC_E_INVALID;
  5227. }
  5228. core_if->core_params->host_ls_low_power_phy_clk = val;
  5229. return retval;
  5230. }
  5231. int32_t dwc_otg_get_param_host_ls_low_power_phy_clk(dwc_otg_core_if_t * core_if)
  5232. {
  5233. return core_if->core_params->host_ls_low_power_phy_clk;
  5234. }
  5235. int dwc_otg_set_param_phy_ulpi_ddr(dwc_otg_core_if_t * core_if, int32_t val)
  5236. {
  5237. if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  5238. DWC_WARN("Wrong value for phy_ulpi_ddr\n");
  5239. DWC_WARN("phy_upli_ddr must be 0 or 1\n");
  5240. return -DWC_E_INVALID;
  5241. }
  5242. core_if->core_params->phy_ulpi_ddr = val;
  5243. return 0;
  5244. }
  5245. int32_t dwc_otg_get_param_phy_ulpi_ddr(dwc_otg_core_if_t * core_if)
  5246. {
  5247. return core_if->core_params->phy_ulpi_ddr;
  5248. }
  5249. int dwc_otg_set_param_phy_ulpi_ext_vbus(dwc_otg_core_if_t * core_if,
  5250. int32_t val)
  5251. {
  5252. if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  5253. DWC_WARN("Wrong valaue for phy_ulpi_ext_vbus\n");
  5254. DWC_WARN("phy_ulpi_ext_vbus must be 0 or 1\n");
  5255. return -DWC_E_INVALID;
  5256. }
  5257. core_if->core_params->phy_ulpi_ext_vbus = val;
  5258. return 0;
  5259. }
  5260. int32_t dwc_otg_get_param_phy_ulpi_ext_vbus(dwc_otg_core_if_t * core_if)
  5261. {
  5262. return core_if->core_params->phy_ulpi_ext_vbus;
  5263. }
  5264. int dwc_otg_set_param_phy_utmi_width(dwc_otg_core_if_t * core_if, int32_t val)
  5265. {
  5266. if (DWC_OTG_PARAM_TEST(val, 8, 8) && DWC_OTG_PARAM_TEST(val, 16, 16)) {
  5267. DWC_WARN("Wrong valaue for phy_utmi_width\n");
  5268. DWC_WARN("phy_utmi_width must be 8 or 16\n");
  5269. return -DWC_E_INVALID;
  5270. }
  5271. core_if->core_params->phy_utmi_width = val;
  5272. return 0;
  5273. }
  5274. int32_t dwc_otg_get_param_phy_utmi_width(dwc_otg_core_if_t * core_if)
  5275. {
  5276. return core_if->core_params->phy_utmi_width;
  5277. }
  5278. int dwc_otg_set_param_ulpi_fs_ls(dwc_otg_core_if_t * core_if, int32_t val)
  5279. {
  5280. if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  5281. DWC_WARN("Wrong valaue for ulpi_fs_ls\n");
  5282. DWC_WARN("ulpi_fs_ls must be 0 or 1\n");
  5283. return -DWC_E_INVALID;
  5284. }
  5285. core_if->core_params->ulpi_fs_ls = val;
  5286. return 0;
  5287. }
  5288. int32_t dwc_otg_get_param_ulpi_fs_ls(dwc_otg_core_if_t * core_if)
  5289. {
  5290. return core_if->core_params->ulpi_fs_ls;
  5291. }
  5292. int dwc_otg_set_param_ts_dline(dwc_otg_core_if_t * core_if, int32_t val)
  5293. {
  5294. if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  5295. DWC_WARN("Wrong valaue for ts_dline\n");
  5296. DWC_WARN("ts_dline must be 0 or 1\n");
  5297. return -DWC_E_INVALID;
  5298. }
  5299. core_if->core_params->ts_dline = val;
  5300. return 0;
  5301. }
  5302. int32_t dwc_otg_get_param_ts_dline(dwc_otg_core_if_t * core_if)
  5303. {
  5304. return core_if->core_params->ts_dline;
  5305. }
  5306. int dwc_otg_set_param_i2c_enable(dwc_otg_core_if_t * core_if, int32_t val)
  5307. {
  5308. int retval = 0;
  5309. if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  5310. DWC_WARN("Wrong valaue for i2c_enable\n");
  5311. DWC_WARN("i2c_enable must be 0 or 1\n");
  5312. return -DWC_E_INVALID;
  5313. }
  5314. #ifndef NO_FS_PHY_HW_CHECK
  5315. if (val == 1 && core_if->hwcfg3.b.i2c == 0) {
  5316. if (dwc_otg_param_initialized(core_if->core_params->i2c_enable)) {
  5317. DWC_ERROR
  5318. ("%d invalid for i2c_enable. Check HW configuration.\n",
  5319. val);
  5320. }
  5321. val = 0;
  5322. retval = -DWC_E_INVALID;
  5323. }
  5324. #endif
  5325. core_if->core_params->i2c_enable = val;
  5326. return retval;
  5327. }
  5328. int32_t dwc_otg_get_param_i2c_enable(dwc_otg_core_if_t * core_if)
  5329. {
  5330. return core_if->core_params->i2c_enable;
  5331. }
  5332. int dwc_otg_set_param_dev_perio_tx_fifo_size(dwc_otg_core_if_t * core_if,
  5333. int32_t val, int fifo_num)
  5334. {
  5335. int retval = 0;
  5336. if (DWC_OTG_PARAM_TEST(val, 4, 768)) {
  5337. DWC_WARN("Wrong value for dev_perio_tx_fifo_size\n");
  5338. DWC_WARN("dev_perio_tx_fifo_size must be 4-768\n");
  5339. return -DWC_E_INVALID;
  5340. }
  5341. if (val >
  5342. (DWC_READ_REG32(&core_if->core_global_regs->dtxfsiz[fifo_num]))) {
  5343. if (dwc_otg_param_initialized
  5344. (core_if->core_params->dev_perio_tx_fifo_size[fifo_num])) {
  5345. DWC_ERROR
  5346. ("`%d' invalid for parameter `dev_perio_fifo_size_%d'. Check HW configuration.\n",
  5347. val, fifo_num);
  5348. }
  5349. val = (DWC_READ_REG32(&core_if->core_global_regs->dtxfsiz[fifo_num]));
  5350. retval = -DWC_E_INVALID;
  5351. }
  5352. core_if->core_params->dev_perio_tx_fifo_size[fifo_num] = val;
  5353. return retval;
  5354. }
  5355. int32_t dwc_otg_get_param_dev_perio_tx_fifo_size(dwc_otg_core_if_t * core_if,
  5356. int fifo_num)
  5357. {
  5358. return core_if->core_params->dev_perio_tx_fifo_size[fifo_num];
  5359. }
  5360. int dwc_otg_set_param_en_multiple_tx_fifo(dwc_otg_core_if_t * core_if,
  5361. int32_t val)
  5362. {
  5363. int retval = 0;
  5364. if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  5365. DWC_WARN("Wrong valaue for en_multiple_tx_fifo,\n");
  5366. DWC_WARN("en_multiple_tx_fifo must be 0 or 1\n");
  5367. return -DWC_E_INVALID;
  5368. }
  5369. if (val == 1 && core_if->hwcfg4.b.ded_fifo_en == 0) {
  5370. if (dwc_otg_param_initialized
  5371. (core_if->core_params->en_multiple_tx_fifo)) {
  5372. DWC_ERROR
  5373. ("%d invalid for parameter en_multiple_tx_fifo. Check HW configuration.\n",
  5374. val);
  5375. }
  5376. val = 0;
  5377. retval = -DWC_E_INVALID;
  5378. }
  5379. core_if->core_params->en_multiple_tx_fifo = val;
  5380. return retval;
  5381. }
  5382. int32_t dwc_otg_get_param_en_multiple_tx_fifo(dwc_otg_core_if_t * core_if)
  5383. {
  5384. return core_if->core_params->en_multiple_tx_fifo;
  5385. }
  5386. int dwc_otg_set_param_dev_tx_fifo_size(dwc_otg_core_if_t * core_if, int32_t val,
  5387. int fifo_num)
  5388. {
  5389. int retval = 0;
  5390. if (DWC_OTG_PARAM_TEST(val, 4, 768)) {
  5391. DWC_WARN("Wrong value for dev_tx_fifo_size\n");
  5392. DWC_WARN("dev_tx_fifo_size must be 4-768\n");
  5393. return -DWC_E_INVALID;
  5394. }
  5395. if (val >
  5396. (DWC_READ_REG32(&core_if->core_global_regs->dtxfsiz[fifo_num]))) {
  5397. if (dwc_otg_param_initialized
  5398. (core_if->core_params->dev_tx_fifo_size[fifo_num])) {
  5399. DWC_ERROR
  5400. ("`%d' invalid for parameter `dev_tx_fifo_size_%d'. Check HW configuration.\n",
  5401. val, fifo_num);
  5402. }
  5403. val = (DWC_READ_REG32(&core_if->core_global_regs->dtxfsiz[fifo_num]));
  5404. retval = -DWC_E_INVALID;
  5405. }
  5406. core_if->core_params->dev_tx_fifo_size[fifo_num] = val;
  5407. return retval;
  5408. }
  5409. int32_t dwc_otg_get_param_dev_tx_fifo_size(dwc_otg_core_if_t * core_if,
  5410. int fifo_num)
  5411. {
  5412. return core_if->core_params->dev_tx_fifo_size[fifo_num];
  5413. }
  5414. int dwc_otg_set_param_thr_ctl(dwc_otg_core_if_t * core_if, int32_t val)
  5415. {
  5416. int retval = 0;
  5417. if (DWC_OTG_PARAM_TEST(val, 0, 7)) {
  5418. DWC_WARN("Wrong value for thr_ctl\n");
  5419. DWC_WARN("thr_ctl must be 0-7\n");
  5420. return -DWC_E_INVALID;
  5421. }
  5422. if ((val != 0) &&
  5423. (!dwc_otg_get_param_dma_enable(core_if) ||
  5424. !core_if->hwcfg4.b.ded_fifo_en)) {
  5425. if (dwc_otg_param_initialized(core_if->core_params->thr_ctl)) {
  5426. DWC_ERROR
  5427. ("%d invalid for parameter thr_ctl. Check HW configuration.\n",
  5428. val);
  5429. }
  5430. val = 0;
  5431. retval = -DWC_E_INVALID;
  5432. }
  5433. core_if->core_params->thr_ctl = val;
  5434. return retval;
  5435. }
  5436. int32_t dwc_otg_get_param_thr_ctl(dwc_otg_core_if_t * core_if)
  5437. {
  5438. return core_if->core_params->thr_ctl;
  5439. }
  5440. int dwc_otg_set_param_lpm_enable(dwc_otg_core_if_t * core_if, int32_t val)
  5441. {
  5442. int retval = 0;
  5443. if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  5444. DWC_WARN("Wrong value for lpm_enable\n");
  5445. DWC_WARN("lpm_enable must be 0 or 1\n");
  5446. return -DWC_E_INVALID;
  5447. }
  5448. if (val && !core_if->hwcfg3.b.otg_lpm_en) {
  5449. if (dwc_otg_param_initialized(core_if->core_params->lpm_enable)) {
  5450. DWC_ERROR
  5451. ("%d invalid for parameter lpm_enable. Check HW configuration.\n",
  5452. val);
  5453. }
  5454. val = 0;
  5455. retval = -DWC_E_INVALID;
  5456. }
  5457. core_if->core_params->lpm_enable = val;
  5458. return retval;
  5459. }
  5460. int32_t dwc_otg_get_param_lpm_enable(dwc_otg_core_if_t * core_if)
  5461. {
  5462. return core_if->core_params->lpm_enable;
  5463. }
  5464. int dwc_otg_set_param_tx_thr_length(dwc_otg_core_if_t * core_if, int32_t val)
  5465. {
  5466. if (DWC_OTG_PARAM_TEST(val, 8, 128)) {
  5467. DWC_WARN("Wrong valaue for tx_thr_length\n");
  5468. DWC_WARN("tx_thr_length must be 8 - 128\n");
  5469. return -DWC_E_INVALID;
  5470. }
  5471. core_if->core_params->tx_thr_length = val;
  5472. return 0;
  5473. }
  5474. int32_t dwc_otg_get_param_tx_thr_length(dwc_otg_core_if_t * core_if)
  5475. {
  5476. return core_if->core_params->tx_thr_length;
  5477. }
  5478. int dwc_otg_set_param_rx_thr_length(dwc_otg_core_if_t * core_if, int32_t val)
  5479. {
  5480. if (DWC_OTG_PARAM_TEST(val, 8, 128)) {
  5481. DWC_WARN("Wrong valaue for rx_thr_length\n");
  5482. DWC_WARN("rx_thr_length must be 8 - 128\n");
  5483. return -DWC_E_INVALID;
  5484. }
  5485. core_if->core_params->rx_thr_length = val;
  5486. return 0;
  5487. }
  5488. int32_t dwc_otg_get_param_rx_thr_length(dwc_otg_core_if_t * core_if)
  5489. {
  5490. return core_if->core_params->rx_thr_length;
  5491. }
  5492. int dwc_otg_set_param_dma_burst_size(dwc_otg_core_if_t * core_if, int32_t val)
  5493. {
  5494. /* This is for EXT DMA
  5495. if (DWC_OTG_PARAM_TEST(val, 1, 1) &&
  5496. DWC_OTG_PARAM_TEST(val, 4, 4) &&
  5497. DWC_OTG_PARAM_TEST(val, 8, 8) &&
  5498. DWC_OTG_PARAM_TEST(val, 16, 16) &&
  5499. DWC_OTG_PARAM_TEST(val, 32, 32) &&
  5500. DWC_OTG_PARAM_TEST(val, 64, 64) &&
  5501. DWC_OTG_PARAM_TEST(val, 128, 128) &&
  5502. DWC_OTG_PARAM_TEST(val, 256, 256)) {
  5503. DWC_WARN("`%d' invalid for parameter `dma_burst_size'\n", val);
  5504. return -DWC_E_INVALID;
  5505. }
  5506. */
  5507. if (DWC_OTG_PARAM_TEST
  5508. (val, DWC_GAHBCFG_INT_DMA_BURST_SINGLE,
  5509. DWC_GAHBCFG_INT_DMA_BURST_SINGLE)
  5510. && DWC_OTG_PARAM_TEST(val,
  5511. DWC_GAHBCFG_INT_DMA_BURST_INCR,
  5512. DWC_GAHBCFG_INT_DMA_BURST_INCR)
  5513. && DWC_OTG_PARAM_TEST(val,
  5514. DWC_GAHBCFG_INT_DMA_BURST_INCR4,
  5515. DWC_GAHBCFG_INT_DMA_BURST_INCR4)
  5516. && DWC_OTG_PARAM_TEST(val,
  5517. DWC_GAHBCFG_INT_DMA_BURST_INCR8,
  5518. DWC_GAHBCFG_INT_DMA_BURST_INCR8)
  5519. && DWC_OTG_PARAM_TEST(val,
  5520. DWC_GAHBCFG_INT_DMA_BURST_INCR16,
  5521. DWC_GAHBCFG_INT_DMA_BURST_INCR16)) {
  5522. DWC_WARN("`%d' invalid for parameter `dma_burst_size'\n", val);
  5523. return -DWC_E_INVALID;
  5524. }
  5525. core_if->core_params->dma_burst_size = val;
  5526. return 0;
  5527. }
  5528. int32_t dwc_otg_get_param_dma_burst_size(dwc_otg_core_if_t * core_if)
  5529. {
  5530. return core_if->core_params->dma_burst_size;
  5531. }
  5532. int dwc_otg_set_param_pti_enable(dwc_otg_core_if_t * core_if, int32_t val)
  5533. {
  5534. int retval = 0;
  5535. if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  5536. DWC_WARN("`%d' invalid for parameter `pti_enable'\n", val);
  5537. return -DWC_E_INVALID;
  5538. }
  5539. if (val && (core_if->snpsid < OTG_CORE_REV_2_72a)) {
  5540. if (dwc_otg_param_initialized(core_if->core_params->pti_enable)) {
  5541. DWC_ERROR
  5542. ("%d invalid for parameter pti_enable. Check HW configuration.\n",
  5543. val);
  5544. }
  5545. retval = -DWC_E_INVALID;
  5546. val = 0;
  5547. }
  5548. core_if->core_params->pti_enable = val;
  5549. return retval;
  5550. }
  5551. int32_t dwc_otg_get_param_pti_enable(dwc_otg_core_if_t * core_if)
  5552. {
  5553. return core_if->core_params->pti_enable;
  5554. }
  5555. int dwc_otg_set_param_mpi_enable(dwc_otg_core_if_t * core_if, int32_t val)
  5556. {
  5557. int retval = 0;
  5558. if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  5559. DWC_WARN("`%d' invalid for parameter `mpi_enable'\n", val);
  5560. return -DWC_E_INVALID;
  5561. }
  5562. if (val && (core_if->hwcfg2.b.multi_proc_int == 0)) {
  5563. if (dwc_otg_param_initialized(core_if->core_params->mpi_enable)) {
  5564. DWC_ERROR
  5565. ("%d invalid for parameter mpi_enable. Check HW configuration.\n",
  5566. val);
  5567. }
  5568. retval = -DWC_E_INVALID;
  5569. val = 0;
  5570. }
  5571. core_if->core_params->mpi_enable = val;
  5572. return retval;
  5573. }
  5574. int32_t dwc_otg_get_param_mpi_enable(dwc_otg_core_if_t * core_if)
  5575. {
  5576. return core_if->core_params->mpi_enable;
  5577. }
  5578. int dwc_otg_set_param_adp_enable(dwc_otg_core_if_t * core_if, int32_t val)
  5579. {
  5580. int retval = 0;
  5581. if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  5582. DWC_WARN("`%d' invalid for parameter `adp_enable'\n", val);
  5583. return -DWC_E_INVALID;
  5584. }
  5585. if (val && (core_if->hwcfg3.b.adp_supp == 0)) {
  5586. if (dwc_otg_param_initialized
  5587. (core_if->core_params->adp_supp_enable)) {
  5588. DWC_ERROR
  5589. ("%d invalid for parameter adp_enable. Check HW configuration.\n",
  5590. val);
  5591. }
  5592. retval = -DWC_E_INVALID;
  5593. val = 0;
  5594. }
  5595. core_if->core_params->adp_supp_enable = val;
  5596. /*Set OTG version 2.0 in case of enabling ADP*/
  5597. if (val)
  5598. dwc_otg_set_param_otg_ver(core_if, 1);
  5599. return retval;
  5600. }
  5601. int32_t dwc_otg_get_param_adp_enable(dwc_otg_core_if_t * core_if)
  5602. {
  5603. return core_if->core_params->adp_supp_enable;
  5604. }
  5605. int dwc_otg_set_param_ic_usb_cap(dwc_otg_core_if_t * core_if, int32_t val)
  5606. {
  5607. int retval = 0;
  5608. if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  5609. DWC_WARN("`%d' invalid for parameter `ic_usb_cap'\n", val);
  5610. DWC_WARN("ic_usb_cap must be 0 or 1\n");
  5611. return -DWC_E_INVALID;
  5612. }
  5613. if (val && (core_if->hwcfg2.b.otg_enable_ic_usb == 0)) {
  5614. if (dwc_otg_param_initialized(core_if->core_params->ic_usb_cap)) {
  5615. DWC_ERROR
  5616. ("%d invalid for parameter ic_usb_cap. Check HW configuration.\n",
  5617. val);
  5618. }
  5619. retval = -DWC_E_INVALID;
  5620. val = 0;
  5621. }
  5622. core_if->core_params->ic_usb_cap = val;
  5623. return retval;
  5624. }
  5625. int32_t dwc_otg_get_param_ic_usb_cap(dwc_otg_core_if_t * core_if)
  5626. {
  5627. return core_if->core_params->ic_usb_cap;
  5628. }
  5629. int dwc_otg_set_param_ahb_thr_ratio(dwc_otg_core_if_t * core_if, int32_t val)
  5630. {
  5631. int retval = 0;
  5632. int valid = 1;
  5633. if (DWC_OTG_PARAM_TEST(val, 0, 3)) {
  5634. DWC_WARN("`%d' invalid for parameter `ahb_thr_ratio'\n", val);
  5635. DWC_WARN("ahb_thr_ratio must be 0 - 3\n");
  5636. return -DWC_E_INVALID;
  5637. }
  5638. if (val
  5639. && (core_if->snpsid < OTG_CORE_REV_2_81a
  5640. || !dwc_otg_get_param_thr_ctl(core_if))) {
  5641. valid = 0;
  5642. } else if (val
  5643. && ((dwc_otg_get_param_tx_thr_length(core_if) / (1 << val)) <
  5644. 4)) {
  5645. valid = 0;
  5646. }
  5647. if (valid == 0) {
  5648. if (dwc_otg_param_initialized
  5649. (core_if->core_params->ahb_thr_ratio)) {
  5650. DWC_ERROR
  5651. ("%d invalid for parameter ahb_thr_ratio. Check HW configuration.\n",
  5652. val);
  5653. }
  5654. retval = -DWC_E_INVALID;
  5655. val = 0;
  5656. }
  5657. core_if->core_params->ahb_thr_ratio = val;
  5658. return retval;
  5659. }
  5660. int32_t dwc_otg_get_param_ahb_thr_ratio(dwc_otg_core_if_t * core_if)
  5661. {
  5662. return core_if->core_params->ahb_thr_ratio;
  5663. }
  5664. int dwc_otg_set_param_power_down(dwc_otg_core_if_t * core_if, int32_t val)
  5665. {
  5666. int retval = 0;
  5667. int valid = 1;
  5668. if (DWC_OTG_PARAM_TEST(val, 0, 2)) {
  5669. DWC_WARN("`%d' invalid for parameter `power_down'\n", val);
  5670. DWC_WARN("power_down must be 0 - 2\n");
  5671. return -DWC_E_INVALID;
  5672. }
  5673. if ((val == 2) && (core_if->snpsid < OTG_CORE_REV_2_91a)) {
  5674. valid = 0;
  5675. }
  5676. if (valid == 0) {
  5677. if (dwc_otg_param_initialized(core_if->core_params->power_down)) {
  5678. DWC_ERROR
  5679. ("%d invalid for parameter power_down. Check HW configuration.\n",
  5680. val);
  5681. }
  5682. retval = -DWC_E_INVALID;
  5683. val = 0;
  5684. }
  5685. core_if->core_params->power_down = val;
  5686. return retval;
  5687. }
  5688. int32_t dwc_otg_get_param_power_down(dwc_otg_core_if_t * core_if)
  5689. {
  5690. return core_if->core_params->power_down;
  5691. }
  5692. int dwc_otg_set_param_reload_ctl(dwc_otg_core_if_t * core_if, int32_t val)
  5693. {
  5694. int retval = 0;
  5695. int valid = 1;
  5696. if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  5697. DWC_WARN("`%d' invalid for parameter `reload_ctl'\n", val);
  5698. DWC_WARN("reload_ctl must be 0 or 1\n");
  5699. return -DWC_E_INVALID;
  5700. }
  5701. if ((val == 1) && (core_if->snpsid < OTG_CORE_REV_2_92a)) {
  5702. valid = 0;
  5703. }
  5704. if (valid == 0) {
  5705. if (dwc_otg_param_initialized(core_if->core_params->reload_ctl)) {
  5706. DWC_ERROR("%d invalid for parameter reload_ctl."
  5707. "Check HW configuration.\n", val);
  5708. }
  5709. retval = -DWC_E_INVALID;
  5710. val = 0;
  5711. }
  5712. core_if->core_params->reload_ctl = val;
  5713. return retval;
  5714. }
  5715. int32_t dwc_otg_get_param_reload_ctl(dwc_otg_core_if_t * core_if)
  5716. {
  5717. return core_if->core_params->reload_ctl;
  5718. }
  5719. int dwc_otg_set_param_dev_out_nak(dwc_otg_core_if_t * core_if, int32_t val)
  5720. {
  5721. int retval = 0;
  5722. int valid = 1;
  5723. if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  5724. DWC_WARN("`%d' invalid for parameter `dev_out_nak'\n", val);
  5725. DWC_WARN("dev_out_nak must be 0 or 1\n");
  5726. return -DWC_E_INVALID;
  5727. }
  5728. if ((val == 1) && ((core_if->snpsid < OTG_CORE_REV_2_93a) ||
  5729. !(core_if->core_params->dma_desc_enable))) {
  5730. valid = 0;
  5731. }
  5732. if (valid == 0) {
  5733. if (dwc_otg_param_initialized(core_if->core_params->dev_out_nak)) {
  5734. DWC_ERROR("%d invalid for parameter dev_out_nak."
  5735. "Check HW configuration.\n", val);
  5736. }
  5737. retval = -DWC_E_INVALID;
  5738. val = 0;
  5739. }
  5740. core_if->core_params->dev_out_nak = val;
  5741. return retval;
  5742. }
  5743. int32_t dwc_otg_get_param_dev_out_nak(dwc_otg_core_if_t * core_if)
  5744. {
  5745. return core_if->core_params->dev_out_nak;
  5746. }
  5747. int dwc_otg_set_param_cont_on_bna(dwc_otg_core_if_t * core_if, int32_t val)
  5748. {
  5749. int retval = 0;
  5750. int valid = 1;
  5751. if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  5752. DWC_WARN("`%d' invalid for parameter `cont_on_bna'\n", val);
  5753. DWC_WARN("cont_on_bna must be 0 or 1\n");
  5754. return -DWC_E_INVALID;
  5755. }
  5756. if ((val == 1) && ((core_if->snpsid < OTG_CORE_REV_2_94a) ||
  5757. !(core_if->core_params->dma_desc_enable))) {
  5758. valid = 0;
  5759. }
  5760. if (valid == 0) {
  5761. if (dwc_otg_param_initialized(core_if->core_params->cont_on_bna)) {
  5762. DWC_ERROR("%d invalid for parameter cont_on_bna."
  5763. "Check HW configuration.\n", val);
  5764. }
  5765. retval = -DWC_E_INVALID;
  5766. val = 0;
  5767. }
  5768. core_if->core_params->cont_on_bna = val;
  5769. return retval;
  5770. }
  5771. int32_t dwc_otg_get_param_cont_on_bna(dwc_otg_core_if_t * core_if)
  5772. {
  5773. return core_if->core_params->cont_on_bna;
  5774. }
  5775. int dwc_otg_set_param_ahb_single(dwc_otg_core_if_t * core_if, int32_t val)
  5776. {
  5777. int retval = 0;
  5778. int valid = 1;
  5779. if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  5780. DWC_WARN("`%d' invalid for parameter `ahb_single'\n", val);
  5781. DWC_WARN("ahb_single must be 0 or 1\n");
  5782. return -DWC_E_INVALID;
  5783. }
  5784. if ((val == 1) && (core_if->snpsid < OTG_CORE_REV_2_94a)) {
  5785. valid = 0;
  5786. }
  5787. if (valid == 0) {
  5788. if (dwc_otg_param_initialized(core_if->core_params->ahb_single)) {
  5789. DWC_ERROR("%d invalid for parameter ahb_single."
  5790. "Check HW configuration.\n", val);
  5791. }
  5792. retval = -DWC_E_INVALID;
  5793. val = 0;
  5794. }
  5795. core_if->core_params->ahb_single = val;
  5796. return retval;
  5797. }
  5798. int32_t dwc_otg_get_param_ahb_single(dwc_otg_core_if_t * core_if)
  5799. {
  5800. return core_if->core_params->ahb_single;
  5801. }
  5802. int dwc_otg_set_param_otg_ver(dwc_otg_core_if_t * core_if, int32_t val)
  5803. {
  5804. int retval = 0;
  5805. if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  5806. DWC_WARN("`%d' invalid for parameter `otg_ver'\n", val);
  5807. DWC_WARN
  5808. ("otg_ver must be 0(for OTG 1.3 support) or 1(for OTG 2.0 support)\n");
  5809. return -DWC_E_INVALID;
  5810. }
  5811. core_if->core_params->otg_ver = val;
  5812. return retval;
  5813. }
  5814. int32_t dwc_otg_get_param_otg_ver(dwc_otg_core_if_t * core_if)
  5815. {
  5816. return core_if->core_params->otg_ver;
  5817. }
  5818. uint32_t dwc_otg_get_hnpstatus(dwc_otg_core_if_t * core_if)
  5819. {
  5820. gotgctl_data_t otgctl;
  5821. otgctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  5822. return otgctl.b.hstnegscs;
  5823. }
  5824. uint32_t dwc_otg_get_srpstatus(dwc_otg_core_if_t * core_if)
  5825. {
  5826. gotgctl_data_t otgctl;
  5827. otgctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  5828. return otgctl.b.sesreqscs;
  5829. }
  5830. void dwc_otg_set_hnpreq(dwc_otg_core_if_t * core_if, uint32_t val)
  5831. {
  5832. if(core_if->otg_ver == 0) {
  5833. gotgctl_data_t otgctl;
  5834. otgctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  5835. otgctl.b.hnpreq = val;
  5836. DWC_WRITE_REG32(&core_if->core_global_regs->gotgctl, otgctl.d32);
  5837. } else {
  5838. core_if->otg_sts = val;
  5839. }
  5840. }
  5841. uint32_t dwc_otg_get_gsnpsid(dwc_otg_core_if_t * core_if)
  5842. {
  5843. return core_if->snpsid;
  5844. }
  5845. uint32_t dwc_otg_get_mode(dwc_otg_core_if_t * core_if)
  5846. {
  5847. gintsts_data_t gintsts;
  5848. gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  5849. return gintsts.b.curmode;
  5850. }
  5851. uint32_t dwc_otg_get_hnpcapable(dwc_otg_core_if_t * core_if)
  5852. {
  5853. gusbcfg_data_t usbcfg;
  5854. usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  5855. return usbcfg.b.hnpcap;
  5856. }
  5857. void dwc_otg_set_hnpcapable(dwc_otg_core_if_t * core_if, uint32_t val)
  5858. {
  5859. gusbcfg_data_t usbcfg;
  5860. usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  5861. usbcfg.b.hnpcap = val;
  5862. DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, usbcfg.d32);
  5863. }
  5864. uint32_t dwc_otg_get_srpcapable(dwc_otg_core_if_t * core_if)
  5865. {
  5866. gusbcfg_data_t usbcfg;
  5867. usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  5868. return usbcfg.b.srpcap;
  5869. }
  5870. void dwc_otg_set_srpcapable(dwc_otg_core_if_t * core_if, uint32_t val)
  5871. {
  5872. gusbcfg_data_t usbcfg;
  5873. usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  5874. usbcfg.b.srpcap = val;
  5875. DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, usbcfg.d32);
  5876. }
  5877. uint32_t dwc_otg_get_devspeed(dwc_otg_core_if_t * core_if)
  5878. {
  5879. dcfg_data_t dcfg;
  5880. dcfg.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  5881. return dcfg.b.devspd;
  5882. }
  5883. void dwc_otg_set_devspeed(dwc_otg_core_if_t * core_if, uint32_t val)
  5884. {
  5885. dcfg_data_t dcfg;
  5886. dcfg.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  5887. dcfg.b.devspd = val;
  5888. DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg, dcfg.d32);
  5889. }
  5890. uint32_t dwc_otg_get_busconnected(dwc_otg_core_if_t * core_if)
  5891. {
  5892. hprt0_data_t hprt0;
  5893. hprt0.d32 = DWC_READ_REG32(core_if->host_if->hprt0);
  5894. return hprt0.b.prtconnsts;
  5895. }
  5896. uint32_t dwc_otg_get_enumspeed(dwc_otg_core_if_t * core_if)
  5897. {
  5898. dsts_data_t dsts;
  5899. dsts.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  5900. return dsts.b.enumspd;
  5901. }
  5902. uint32_t dwc_otg_get_prtpower(dwc_otg_core_if_t * core_if)
  5903. {
  5904. hprt0_data_t hprt0;
  5905. hprt0.d32 = DWC_READ_REG32(core_if->host_if->hprt0);
  5906. return hprt0.b.prtpwr;
  5907. }
  5908. uint32_t dwc_otg_get_core_state(dwc_otg_core_if_t * core_if)
  5909. {
  5910. return core_if->hibernation_suspend;
  5911. }
  5912. void dwc_otg_set_prtpower(dwc_otg_core_if_t * core_if, uint32_t val)
  5913. {
  5914. hprt0_data_t hprt0;
  5915. hprt0.d32 = dwc_otg_read_hprt0(core_if);
  5916. hprt0.b.prtpwr = val;
  5917. DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  5918. }
  5919. uint32_t dwc_otg_get_prtsuspend(dwc_otg_core_if_t * core_if)
  5920. {
  5921. hprt0_data_t hprt0;
  5922. hprt0.d32 = DWC_READ_REG32(core_if->host_if->hprt0);
  5923. return hprt0.b.prtsusp;
  5924. }
  5925. void dwc_otg_set_prtsuspend(dwc_otg_core_if_t * core_if, uint32_t val)
  5926. {
  5927. hprt0_data_t hprt0;
  5928. hprt0.d32 = dwc_otg_read_hprt0(core_if);
  5929. hprt0.b.prtsusp = val;
  5930. DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  5931. }
  5932. uint32_t dwc_otg_get_fr_interval(dwc_otg_core_if_t * core_if)
  5933. {
  5934. hfir_data_t hfir;
  5935. hfir.d32 = DWC_READ_REG32(&core_if->host_if->host_global_regs->hfir);
  5936. return hfir.b.frint;
  5937. }
  5938. void dwc_otg_set_fr_interval(dwc_otg_core_if_t * core_if, uint32_t val)
  5939. {
  5940. hfir_data_t hfir;
  5941. uint32_t fram_int;
  5942. fram_int = calc_frame_interval(core_if);
  5943. hfir.d32 = DWC_READ_REG32(&core_if->host_if->host_global_regs->hfir);
  5944. if (!core_if->core_params->reload_ctl) {
  5945. DWC_WARN("\nCannot reload HFIR register.HFIR.HFIRRldCtrl bit is"
  5946. "not set to 1.\nShould load driver with reload_ctl=1"
  5947. " module parameter\n");
  5948. return;
  5949. }
  5950. switch (fram_int) {
  5951. case 3750:
  5952. if ((val < 3350) || (val > 4150)) {
  5953. DWC_WARN("HFIR interval for HS core and 30 MHz"
  5954. "clock freq should be from 3350 to 4150\n");
  5955. return;
  5956. }
  5957. break;
  5958. case 30000:
  5959. if ((val < 26820) || (val > 33180)) {
  5960. DWC_WARN("HFIR interval for FS/LS core and 30 MHz"
  5961. "clock freq should be from 26820 to 33180\n");
  5962. return;
  5963. }
  5964. break;
  5965. case 6000:
  5966. if ((val < 5360) || (val > 6640)) {
  5967. DWC_WARN("HFIR interval for HS core and 48 MHz"
  5968. "clock freq should be from 5360 to 6640\n");
  5969. return;
  5970. }
  5971. break;
  5972. case 48000:
  5973. if ((val < 42912) || (val > 53088)) {
  5974. DWC_WARN("HFIR interval for FS/LS core and 48 MHz"
  5975. "clock freq should be from 42912 to 53088\n");
  5976. return;
  5977. }
  5978. break;
  5979. case 7500:
  5980. if ((val < 6700) || (val > 8300)) {
  5981. DWC_WARN("HFIR interval for HS core and 60 MHz"
  5982. "clock freq should be from 6700 to 8300\n");
  5983. return;
  5984. }
  5985. break;
  5986. case 60000:
  5987. if ((val < 53640) || (val > 65536)) {
  5988. DWC_WARN("HFIR interval for FS/LS core and 60 MHz"
  5989. "clock freq should be from 53640 to 65536\n");
  5990. return;
  5991. }
  5992. break;
  5993. default:
  5994. DWC_WARN("Unknown frame interval\n");
  5995. return;
  5996. break;
  5997. }
  5998. hfir.b.frint = val;
  5999. DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hfir, hfir.d32);
  6000. }
  6001. uint32_t dwc_otg_get_mode_ch_tim(dwc_otg_core_if_t * core_if)
  6002. {
  6003. hcfg_data_t hcfg;
  6004. hcfg.d32 = DWC_READ_REG32(&core_if->host_if->host_global_regs->hcfg);
  6005. return hcfg.b.modechtimen;
  6006. }
  6007. void dwc_otg_set_mode_ch_tim(dwc_otg_core_if_t * core_if, uint32_t val)
  6008. {
  6009. hcfg_data_t hcfg;
  6010. hcfg.d32 = DWC_READ_REG32(&core_if->host_if->host_global_regs->hcfg);
  6011. hcfg.b.modechtimen = val;
  6012. DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hcfg, hcfg.d32);
  6013. }
  6014. void dwc_otg_set_prtresume(dwc_otg_core_if_t * core_if, uint32_t val)
  6015. {
  6016. hprt0_data_t hprt0;
  6017. hprt0.d32 = dwc_otg_read_hprt0(core_if);
  6018. hprt0.b.prtres = val;
  6019. DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  6020. }
  6021. uint32_t dwc_otg_get_remotewakesig(dwc_otg_core_if_t * core_if)
  6022. {
  6023. dctl_data_t dctl;
  6024. dctl.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dctl);
  6025. return dctl.b.rmtwkupsig;
  6026. }
  6027. uint32_t dwc_otg_get_lpm_portsleepstatus(dwc_otg_core_if_t * core_if)
  6028. {
  6029. glpmcfg_data_t lpmcfg;
  6030. lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  6031. DWC_ASSERT(!
  6032. ((core_if->lx_state == DWC_OTG_L1) ^ lpmcfg.b.prt_sleep_sts),
  6033. "lx_state = %d, lmpcfg.prt_sleep_sts = %d\n",
  6034. core_if->lx_state, lpmcfg.b.prt_sleep_sts);
  6035. return lpmcfg.b.prt_sleep_sts;
  6036. }
  6037. uint32_t dwc_otg_get_lpm_remotewakeenabled(dwc_otg_core_if_t * core_if)
  6038. {
  6039. glpmcfg_data_t lpmcfg;
  6040. lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  6041. return lpmcfg.b.rem_wkup_en;
  6042. }
  6043. uint32_t dwc_otg_get_lpmresponse(dwc_otg_core_if_t * core_if)
  6044. {
  6045. glpmcfg_data_t lpmcfg;
  6046. lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  6047. return lpmcfg.b.appl_resp;
  6048. }
  6049. void dwc_otg_set_lpmresponse(dwc_otg_core_if_t * core_if, uint32_t val)
  6050. {
  6051. glpmcfg_data_t lpmcfg;
  6052. lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  6053. lpmcfg.b.appl_resp = val;
  6054. DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg, lpmcfg.d32);
  6055. }
  6056. uint32_t dwc_otg_get_hsic_connect(dwc_otg_core_if_t * core_if)
  6057. {
  6058. glpmcfg_data_t lpmcfg;
  6059. lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  6060. return lpmcfg.b.hsic_connect;
  6061. }
  6062. void dwc_otg_set_hsic_connect(dwc_otg_core_if_t * core_if, uint32_t val)
  6063. {
  6064. glpmcfg_data_t lpmcfg;
  6065. lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  6066. lpmcfg.b.hsic_connect = val;
  6067. DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg, lpmcfg.d32);
  6068. }
  6069. uint32_t dwc_otg_get_inv_sel_hsic(dwc_otg_core_if_t * core_if)
  6070. {
  6071. glpmcfg_data_t lpmcfg;
  6072. lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  6073. return lpmcfg.b.inv_sel_hsic;
  6074. }
  6075. void dwc_otg_set_inv_sel_hsic(dwc_otg_core_if_t * core_if, uint32_t val)
  6076. {
  6077. glpmcfg_data_t lpmcfg;
  6078. lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  6079. lpmcfg.b.inv_sel_hsic = val;
  6080. DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg, lpmcfg.d32);
  6081. }
  6082. uint32_t dwc_otg_get_gotgctl(dwc_otg_core_if_t * core_if)
  6083. {
  6084. return DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  6085. }
  6086. void dwc_otg_set_gotgctl(dwc_otg_core_if_t * core_if, uint32_t val)
  6087. {
  6088. DWC_WRITE_REG32(&core_if->core_global_regs->gotgctl, val);
  6089. }
  6090. uint32_t dwc_otg_get_gusbcfg(dwc_otg_core_if_t * core_if)
  6091. {
  6092. return DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  6093. }
  6094. void dwc_otg_set_gusbcfg(dwc_otg_core_if_t * core_if, uint32_t val)
  6095. {
  6096. DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, val);
  6097. }
  6098. uint32_t dwc_otg_get_grxfsiz(dwc_otg_core_if_t * core_if)
  6099. {
  6100. return DWC_READ_REG32(&core_if->core_global_regs->grxfsiz);
  6101. }
  6102. void dwc_otg_set_grxfsiz(dwc_otg_core_if_t * core_if, uint32_t val)
  6103. {
  6104. DWC_WRITE_REG32(&core_if->core_global_regs->grxfsiz, val);
  6105. }
  6106. uint32_t dwc_otg_get_gnptxfsiz(dwc_otg_core_if_t * core_if)
  6107. {
  6108. return DWC_READ_REG32(&core_if->core_global_regs->gnptxfsiz);
  6109. }
  6110. void dwc_otg_set_gnptxfsiz(dwc_otg_core_if_t * core_if, uint32_t val)
  6111. {
  6112. DWC_WRITE_REG32(&core_if->core_global_regs->gnptxfsiz, val);
  6113. }
  6114. uint32_t dwc_otg_get_gpvndctl(dwc_otg_core_if_t * core_if)
  6115. {
  6116. return DWC_READ_REG32(&core_if->core_global_regs->gpvndctl);
  6117. }
  6118. void dwc_otg_set_gpvndctl(dwc_otg_core_if_t * core_if, uint32_t val)
  6119. {
  6120. DWC_WRITE_REG32(&core_if->core_global_regs->gpvndctl, val);
  6121. }
  6122. uint32_t dwc_otg_get_ggpio(dwc_otg_core_if_t * core_if)
  6123. {
  6124. return DWC_READ_REG32(&core_if->core_global_regs->ggpio);
  6125. }
  6126. void dwc_otg_set_ggpio(dwc_otg_core_if_t * core_if, uint32_t val)
  6127. {
  6128. DWC_WRITE_REG32(&core_if->core_global_regs->ggpio, val);
  6129. }
  6130. uint32_t dwc_otg_get_hprt0(dwc_otg_core_if_t * core_if)
  6131. {
  6132. return DWC_READ_REG32(core_if->host_if->hprt0);
  6133. }
  6134. void dwc_otg_set_hprt0(dwc_otg_core_if_t * core_if, uint32_t val)
  6135. {
  6136. DWC_WRITE_REG32(core_if->host_if->hprt0, val);
  6137. }
  6138. uint32_t dwc_otg_get_guid(dwc_otg_core_if_t * core_if)
  6139. {
  6140. return DWC_READ_REG32(&core_if->core_global_regs->guid);
  6141. }
  6142. void dwc_otg_set_guid(dwc_otg_core_if_t * core_if, uint32_t val)
  6143. {
  6144. DWC_WRITE_REG32(&core_if->core_global_regs->guid, val);
  6145. }
  6146. uint32_t dwc_otg_get_hptxfsiz(dwc_otg_core_if_t * core_if)
  6147. {
  6148. return DWC_READ_REG32(&core_if->core_global_regs->hptxfsiz);
  6149. }
  6150. uint16_t dwc_otg_get_otg_version(dwc_otg_core_if_t * core_if)
  6151. {
  6152. return ((core_if->otg_ver == 1) ? (uint16_t)0x0200 : (uint16_t)0x0103);
  6153. }
  6154. /**
  6155. * Start the SRP timer to detect when the SRP does not complete within
  6156. * 6 seconds.
  6157. *
  6158. * @param core_if the pointer to core_if strucure.
  6159. */
  6160. void dwc_otg_pcd_start_srp_timer(dwc_otg_core_if_t * core_if)
  6161. {
  6162. core_if->srp_timer_started = 1;
  6163. DWC_TIMER_SCHEDULE(core_if->srp_timer, 6000 /* 6 secs */ );
  6164. }
  6165. void dwc_otg_initiate_srp(dwc_otg_core_if_t * core_if)
  6166. {
  6167. uint32_t *addr = (uint32_t *) & (core_if->core_global_regs->gotgctl);
  6168. gotgctl_data_t mem;
  6169. gotgctl_data_t val;
  6170. val.d32 = DWC_READ_REG32(addr);
  6171. if (val.b.sesreq) {
  6172. DWC_ERROR("Session Request Already active!\n");
  6173. return;
  6174. }
  6175. DWC_INFO("Session Request Initated\n"); //NOTICE
  6176. mem.d32 = DWC_READ_REG32(addr);
  6177. mem.b.sesreq = 1;
  6178. DWC_WRITE_REG32(addr, mem.d32);
  6179. /* Start the SRP timer */
  6180. dwc_otg_pcd_start_srp_timer(core_if);
  6181. return;
  6182. }